var HttpReq = null;
var dest_combo = null;


function Procurar (){

   passou1 = false;
   passou2 = false;
		
   // CEP1
   if (!valida_nulo(document.form_int.cep1, 'Preencha o CEP.')) {
	return (false);
   } else {
        passou1 = true; 
   }

   // CEP2
   if (!valida_nulo(document.form_int.cep2, 'Preencha complemento do  CEP.')) {
	return (false);
   } else {
        passou2 = true;
   }
		

   if ((passou1) || (passou2)) {
			document.form_int.cep.value = document.form_int.cep1.value + '' +  document.form_int.cep2.value;
			// alert("cep ="  + document.form_int.cep.value );
   }	

  
   document.form_int.endereco.disabled = false;
   document.form_int.bairro.disabled   = false;
   document.form_int.cidade.disabled   = false;
   document.form_int.estado.disabled   = false;


   document.form_int.endereco.style.backgroundColor = '#FFFFFF';
   document.form_int.bairro.style.backgroundColor   = '#FFFFFF';
   document.form_int.cidade.style.backgroundColor   = '#FFFFFF';
   document.form_int.estado.style.backgroundColor   = '#FFFFFF';
    


    var url = "xml/cep.asp?cep=";
    url = url + document.form_int.cep.value;
    //alert("url = " + url )
    if (document.getElementById) { //Verifica se o Browser suporta DHTML.
        if (window.XMLHttpRequest) {
            HttpReq = new XMLHttpRequest();
            HttpReq.onreadystatechange = XMLHttpRequestChange;
            HttpReq.open("GET", url, true);
            HttpReq.send(null);
            
        } else if (window.ActiveXObject) {
            HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            if (HttpReq) {
                HttpReq.onreadystatechange = XMLHttpRequestChange;
                HttpReq.open("GET", url, true);
                HttpReq.send();
	    
            }
        }
    }
}


function XMLHttpRequestChange() {
    // if (HttpReq.readyState == 1){  
        // document.write("<strong>Carregando...</strong>");
    // }

    if (HttpReq.readyState == 4 ){  
    	document.form_int.bairro.value = "";
    	document.form_int.endereco.value = "";
    	document.form_int.cidade.value = "";
    	document.form_int.estado.value = "";
    	// document.form_int.status.value = "";	

        var result = HttpReq.responseXML;
        var webservice = result.getElementsByTagName("webservicecep");

        for (var i = 0;i< webservice[0].childNodes.length; i++) {
	    // BAIRRO
	    if (webservice[0].childNodes[i].nodeName =="bairro") {
	    	document.form_int.bairro.value = webservice[0].childNodes[i].firstChild.nodeValue;	
	    }
	    // LOGRADOURO
	    if (webservice[0].childNodes[i].nodeName =="logradouro") {
	    	document.form_int.endereco.value = webservice[0].childNodes[i-1].firstChild.nodeValue + ' ' +  webservice[0].childNodes[i].firstChild.nodeValue;	
	    }
	    // CIDADE
 	    if (webservice[0].childNodes[i].nodeName =="cidade") {
	    	document.form_int.cidade.value = webservice[0].childNodes[i].firstChild.nodeValue;	
	    }
	    // UF
 	    if (webservice[0].childNodes[i].nodeName =="uf") {
	    	document.form_int.estado.value = webservice[0].childNodes[i].firstChild.nodeValue;	
	    }
	    // Status
 	    // if (webservice[0].childNodes[i].nodeName =="resultado_txt") {
	    	// document.form_int.status.value = webservice[0].childNodes[i].firstChild.nodeValue;	
	    // }
        }
   }
   

}
