	function checaSuporteAjax(){
	  try {
         ajax_instance = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax_instance = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax_instance = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax_instance = null;
            }
         }
      }	
	  return ajax_instance;
	}


function carregaBairro(valor) {

	  var ajax = new checaSuporteAjax();
	  if(ajax) {
		 document.busca.bairro.options.length = 1;
		 idOpcao  = document.getElementById("opcoes");
	     ajax.open("POST", "./filtraBairro.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 ajax.onreadystatechange = function() {
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...!";   
	        }
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXMLBairro(ajax.responseXML);
			   }
			   else{
					alert("Este município não possui bairro cadastrado.");
					idOpcao.innerHTML = "Selecione outro.";
					document.busca.bairro.disabled = true;
			   }
            }
         }
	     var params = "mun="+valor;
         ajax.send(params);
      }
   }

   function processXMLBairro(obj){

      var dataArray   = obj.getElementsByTagName("Bairro");
	  idOpcao.innerHTML = "Selecione o bairro";
	  if(dataArray.length > 0) {
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			var codigo    =  item.getElementsByTagName("codigo_bairro")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("nome_bairro")[0].firstChild.nodeValue;
			
			var novo = document.createElement("option");
			    novo.setAttribute("id", "opcoes");
			    novo.value = codigo;
			    novo.text = descricao;
				document.busca.bairro.options.add(novo);
				document.busca.bairro.disabled=false;
		 }
	  }
	  else {
		document.busca.bairro.disabled=true;
	  }	
   }

function Busca(){
  document.busca.action="buscar.php";
  document.busca.submit();
}

function Buscar(){
  document.busca.action="../buscar.php";
  document.busca.submit();
}