// JavaScript Document
function Load_xml(url) 
{ 
    $.ajax({
        url:url,
        cache:false,
        success:function(data){
             data= '<option value="99" selected="selected">Escolha</option>' + data; 
             
            $("#trasnsacao").html(data).attr("disabled","");
        }
    });
	/*var div_finalidade = '<select disabled="disabled" name="transacao" class="frm_busca_drop"><option value="99" selected="selected">Aguarde ...</option></select>';
	//document.getElementById('finalidade').innerHTML = div_finalidade;
	req = null; 
    // Procura por um objeto nativo (Mozilla/Safari) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = Load_resultado; 
        req.open("GET", url, true); 
        req.send(null); 
    // Procura por uma versao ActiveX (IE) 
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) { 
            req.onreadystatechange = Load_resultado; 
            req.open("GET", url, true);
            req.send();

        } 
    }    */
} 
           /*
function Load_resultado() 
{ 
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) 
	{ 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200)
		{ 
            // procura pela div id="atualiza" e insere o conteudo 
            // retornado nela, como texto HTML
		alert(req.responseText);
		document.getElementById('finalidade').innerHTML = req.responseText;
		//document.getElementById('finalidade').enabled;
		//document.getElementById('botao').innerHTML = '<input type="image" src="slices/buscar.gif" value="Submit"/>';
		} else { 
            alert("Houve um problema ao obter os dados:\n" + req.statusText); 
        } 
    } 
} 
*/
function Load_xml02(url) 
{ 
    
    $.ajax({
        url:url,
        cache:false,
        success: Load_pag
    });/*
	req = null; 
    // Procura por um objeto nativo (Mozilla/Safari) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = Load_pag; 
        req.open("GET", url, true); 
        req.send(null); 
    // Procura por uma versao ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) { 
            req.onreadystatechange = Load_pag; 
            req.open("GET", url, true);
            req.send(); 
        } 
    }  */
} 

function Load_pag(htmlText) 
{ 
    
    saida = htmlText.split("%");  
    
    saida[0]= '<option value="99" selected="selected">Escolha</option>' + saida[0];
    saida[1]= '<option value="99" selected="selected">Escolha</option>' + saida[1]; 

    if($("#tipo").val() == 4 || $("#tipo").val() == 2)  {
        $("#dormit").html(saida[0]).attr("disabled","disabled");
    }
    else            
        $("#dormit").html(saida[0]).attr("disabled","");
    
    
    $("#Valor_maximo").html(saida[1]).attr("disabled","");/*
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) 
	{ 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200)
		{ 
            // procura pela div id="atualiza" e insere o conteudo 
            // retornado nela, como texto HTML 
		retorno = req.responseText;
		saida = retorno.split('%');
		//document.getElementById('botao').innerHTML = '<input type="image" src="slices/buscar.gif" value="Submit"/>';
		document.getElementById('Dorms').innerHTML = saida[0];
		document.getElementById('Valor').innerHTML = saida[1];
		} else { 
            alert("Houve um problema ao obter os dados:\n" + req.statusText); 
        } 
    }*/ 
} 
function Load_xml03(url) 
{    
    $.ajax({
        url:url,
        cache:false,
        success:function(data){
            $("#Valor_maximo").html(data);
        }
    });
    /*
	req = null; 
    // Procura por um objeto nativo (Mozilla/Safari) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = Load_pag01; 
        req.open("GET", url, true); 
        req.send(null); 
    // Procura por uma versao ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) { 
            req.onreadystatechange = Load_pag01; 
            req.open("GET", url, true);
            req.send(); 
        } 
    }   */
} 
   /*
function Load_pag01() 
{ 
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) 
	{ 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200)
				{ 
								// procura pela div id="atualiza" e insere o conteudo 
								// retornado nela, como texto HTML
				//document.getElementById('botao').innerHTML = '<input type="image" src="slices/buscar.gif" value="Submit"/>';
				document.getElementById('Valor').innerHTML = req.responseText;
				} else { 
								alert("Houve um problema ao obter os dados:\n" + req.statusText); 
        }
    } 
}   */
function Load_xml04(url) 
{ 
    $.ajax({
        url:url,
        cache:false,
        success: Load_pag 
    });
    /*
	req = null; 
    // Procura por um objeto nativo (Mozilla/Safari) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = Load_pag02; 
        req.open("GET", url, true); 
        req.send(null); 
    // Procura por uma versao ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) { 
            req.onreadystatechange = Load_pag02; 
            req.open("GET", url, true);
            req.send(); 
        } 
    }*/ 
} 
/*
function Load_pag02() 
{ 
    // apenas quando o estado for "completado" 
    if (req.readyState == 4) 
	{ 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200)
		{ 
            // procura pela div id="atualiza" e insere o conteudo 
            // retornado nela, como texto HTML 
		retorno = req.responseText;
		saida = retorno.split('%');
		//document.getElementById('botao').innerHTML = '<input type="image" src="slices/buscar.gif" value="Submit"/>';
		document.getElementById('Dorms').innerHTML =saida[0];
		document.getElementById('Valor').innerHTML =saida[1] ;
		} else { 
            alert("Houve um problema ao obter os dados:\n" + req.statusText); 
        } 
    } 
} 
    */
function Verifica_Tipo(input)
{
	var valor = input.value; /*
	var div_finalidade = '<select disabled="disabled" name="transacao" class="frm_busca_drop"><option value="99" selected="selected">Escolha</option></select>';
	if (valor == 2 || valor == 4){
		var div_dorms ='<select disabled="disabled" name="dormit" class="frm_busca_drop"><option value="0" selected="selected">Indisponível</option></select>';
	}else{
		var div_dorms ='<select disabled="disabled" name="dormit" class="frm_busca_drop"><option value="0" selected="selected">Indiferente</option></select>';
	}
	var div_valor = '<select disabled="disabled" name="Valor_maximo" class="frm_busca_drop"><option value="0" selected="selected">Indiferente</option></select>';
		
		//document.getElementById('botao').innerHTML = '<img src="slices/aguarde.gif" width="70" height="17" />';
		//document.getElementById('finalidade').innerHTML = div_finalidade;
		document.getElementById('Dorms').innerHTML = div_dorms;
		document.getElementById('Valor').innerHTML = div_valor;    */   
		Load_xml('consulta.php?tipo='+valor);
}


function Verifica_Dorm(input)
{
	var valor = input.value;

	var tipo = $("#tipo").val();   /*
	var div_valor = '<select disabled="disabled" name="Valor_maximo" class="frm_busca_drop"><option value="0" selected="selected">Escolha</option></select>';
	//document.getElementById('botao').innerHTML = '<img src="slices/aguarde.gif" width="70" height="17" />';
	document.getElementById('Valor').innerHTML = div_valor;  */

	if(tipo == '2')
	{                  
		Load_xml04('consulta04.php?dispo='+valor+'&tipo='+tipo);		
	}else if(tipo == '4'){
		Load_xml04('consulta05.php?dispo='+valor+'&tipo='+tipo);
	}else{
		Load_xml02('consulta02.php?dispo='+valor+'&tipo='+tipo);
	}
}

function Verifica_Valor(input)
{
	var dorms = input.value;
	var tipo = $("#tipo").val();
	var dispo = document.getElementById('transacao').value;
	//document.getElementById('botao').innerHTML = '<img src="slices/aguarde.gif" width="70" height="17" />';
	Load_xml03('consulta03.php?dispo='+dispo+'&tipo='+tipo+'&dorms='+dorms);
}
