function pesquisar_dados( valor )
{
  http.open("GET", "/js/busca/consultar.php?estado=" + valor, true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}

function pesquisar_bairros( valor )
{
  http.open("GET", "/js/busca/consultar_sub.php?cidade=" + valor, true);
  http.onreadystatechange = handleHttpResponse2;
  http.send(null);
}


function getHTTPObject() {
  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();



function handleHttpResponse()
{
  campo_select = document.forms[0].cidade;
  if (http.readyState == 4) {
    campo_select.options.length = 0;
    results = http.responseText.split(",");
    for( i = 0; i < results.length; i++ )
    { 
		string = results[i].split( "|" );
		if(string[0] != undefined || string[1] != undefined) { 
			campo_select.options[i] = new Option( string[0], string[1] );
		}
		if(i == 0) {
			var buscabairro = string[0];	
		}
    } 
  }
  if(buscabairro != undefined) {
  	pesquisar_bairros(buscabairro);
  }
}

function handleHttpResponse2()
{
  campo_select = document.forms[0].bairro;
  if (http.readyState == 4) {
    campo_select.options.length = 0;
    results = http.responseText.split(",");
    for( i = 0; i < results.length; i++ )
    { 
      string = results[i].split( "|" );
      campo_select.options[i] = new Option( string[0], string[1] );
    } 
  }
}
