///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MudaBusca
function BuscaCidade(Pagina,Acao,Valor,Id)
{ 

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Seu browser não suporta AJAX!");
  return;
  } 
	x = document.getElementById(Id);

	x.style.display = "block";

var url=Pagina+"?Acao="+Acao+"&Valor="+Valor;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged_ajax;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MudaBusca
function MarcaTodos()
{ 

    var NumBairros = document.getElementById("NumBairros").value;
	
	if (document.getElementById("Todos").checked == true ){
		var Status = 1 } 
	
	if (document.getElementById("Todos").checked == false ){
		var Status = 0 } 

	
	if (Status == 1 )
	{   
		for (i=0;i <= NumBairros; i++)
	   { document.getElementById("CodBairro"+i).checked = true;
		 document.getElementById("CodBairro"+i).disabled = true;
	   }
	   
	}

	if (Status == 0 )
	{  
		for (i=0;i <= NumBairros; i++)
	   { document.getElementById("CodBairro"+i).checked = false;
		document.getElementById("CodBairro"+i).disabled = false;
	   }
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ValidaEnvio
function ValidaEnvio(Pagina,Acao,Nome,Email,Cidade,Telefone,Mensagem,Id,CodImovel,CodCorretor,CodImobiliaria)
{ 

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Seu browser não suporta AJAX!");
  return;
  } 
	x = document.getElementById(Id);


var url=Pagina+"?Acao="+Acao+"&Nome="+Nome+"&Email="+Email+"&Cidade="+Cidade+"&Telefone="+Telefone+"&Mensagem="+Mensagem+"&CodImovel="+CodImovel+"&CodCorretor="+CodCorretor+"&CodImobiliaria="+CodImobiliaria;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged_ajax;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MudaBusca
function AdicionaCidade(Valor,Id,Cidade)
{document.getElementById(Id).value = Valor;
document.getElementById("Cidade").value = Cidade;
 document.getElementById("ResultCidade").style.display = "none";

 var tempo = window.setTimeout("BuscaBairros('ajaxPesquisa.asp','Bairros','"+Valor+"','MostraBairros')",200)
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BuscaBairros
function BuscaBairros(Pagina,Acao,Valor,Id)
{ 

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Seu browser não suporta AJAX!");
  return;
  } 
	x = document.getElementById(Id);

	x.style.display = "block";

var url=Pagina+"?Acao="+Acao+"&Valor="+Valor;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged_ajax;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//FUNÇÃO stateChanged_ajax
function stateChanged_ajax() 
{ 
if (xmlHttp.readyState==1)
{ 

x.innerHTML="<div style='float:left;width:auto;height:auto;font-size:7pt;text-align:center;'><IMG SRC='IMAGES/LOADING.GIF' Style='float:center;'></div>";
}
if (xmlHttp.readyState==4)
{ 

x.innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
};
