//------------------------------------------------------------------------
// Web Service CEP, desenvolvido por Evanil Rosano de Paula.
// Este Web Service está habilitado para funcionar em qualquer servidor, 
// no entanto terá melhor desempenho em sites hospedados pela Via Virtual.
// Visite nosso site e conheça nossos serviços.
// Via Virtual - Solucões WEB
// http://www.viavirtual.com.br
//-------------------------------------------------------------------------

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
        xmlhttp = false;
        }
      }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
    }
  return xmlhttp;
  }
var http = getHTTPObject();

function busca_endereco()
{
	var cep		=	document.getElementById('cep').value.replace('-',''); // remove o hífen(-)
	
	document.getElementById('divCarregando').style.display		= '';
	document.getElementById('form2').style.display				= 'none';
	
	http.open("GET", ajax_path_shared + '_ajax.cep.busca_endereco.php?a=1&cep='+cep, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);

	var arr; //array com os dados retornados
	function handleHttpResponse() 
	{
		if (http.readyState == 4) 
		{
			var response = http.responseText;
			eval("var arr = "+response); //cria objeto com o resultado
			
			document.getElementById('uf').value			= arr.uf;
			document.getElementById('cidade').value		= arr.cidade;
			document.getElementById('bairro').value		= arr.bairro;
			document.getElementById('endereco').value	= arr.rua;			
			
			document.getElementById('form11').style.display					= 'block';
			document.getElementById('divCarregando').style.display			= 'none';
			document.getElementById('form2').style.display					= 'none';
			
		}
	}	
	
	
}
