function ob_ajax()
 { 
 var objXMLHttp=null
 if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest()
  }
 else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  ajax = objXMLHttp
 return ajax
 }
function get_content($destino){
    ajax = ob_ajax();
	//ajax = new XMLHttpRequest();
	var ncep = document.getElementById('txtCep').value;
    ajax.open("get", "../buscaCep.php?cep="+ncep, true);
            //ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
					if(ajax.readyState == 1) {
						document.getElementById($destino).innerHTML= 'Aguarde....';
						}
                if(ajax.readyState == 4 ) {
                    XMLdoc = ajax.responseXML;
					var uf = null;
					var cidade = null;
					var bairro = null;
					var tipoLogradouro = null;
					var logradouro = null;
					try {
						uf = XMLdoc.getElementsByTagName('webservicecep')[0].childNodes[5].childNodes[0].nodeValue;
						cidade = XMLdoc.getElementsByTagName('webservicecep')[0].childNodes[7].childNodes[0].nodeValue;
						bairro = XMLdoc.getElementsByTagName('webservicecep')[0].childNodes[9].childNodes[0].nodeValue;
						tipoLogradouro = XMLdoc.getElementsByTagName('webservicecep')[0].childNodes[11].childNodes[0].nodeValue;
						logradouro = XMLdoc.getElementsByTagName('webservicecep')[0].childNodes[13].childNodes[0].nodeValue;
					}
					catch (e){
						alert('Seu CEP esta incorreto ou incompleto, preencha manualmente o endereço.');
					}
					document.frmOcorrencia.txtEndereco.value = "";
					if (tipoLogradouro != null){
						document.frmOcorrencia.txtEndereco.value += tipoLogradouro + ' ';
					}
					if (logradouro != null){
						document.frmOcorrencia.txtEndereco.value += logradouro;
					}
					if (bairro != null){
						document.frmOcorrencia.txtBairro.value = bairro;
					}
					if (cidade != null){
						document.frmOcorrencia.txtCidade.value = cidade;
					}
					if (uf != null){
						//document.frmOcorrencia.txtEstado.value = uf;
						estados = new Array('AC','AL','AP','AM','BA','CE','DF','ES','GO','MA','MT','MS','MG','PA','PB','PR','PE','PI','RJ','RN','RS','RO','RR','SC','SP','SE','TO');
						for (i = 0 ; i < estados.length ; i++){
							if (estados[i] == uf){
								document.frmOcorrencia.txtEstado.selectedIndex = i+1;
							}
						}
					}					
					
					
            		}
               else {
                  $destino.innerHTML = "";
                   }
                   }

             	     var params = null;
             		  ajax.send(params);
}