var vglobal_array=new Array(50)
var vindex = 0
//Verifica qual o browser do visitante e armazena na variável púbica clientNavigator,
//Caso Internet Explorer(IE) outros (Other)

if (navigator.appName.indexOf('Microsoft') != -1){
    clientNavigator = "IE";   
}else{   
    clientNavigator = "Other";   
}   

function RetornoTipo(cod_cidade)
{
  var xmlHttp=GetXmlHttpObject()

  if (xmlHttp==null)
  {
       alert ("Este browser não suporta HTTP Request")
       return
  }

  var url="gettiposimoveis.php";
  url=url+"?pcod_cidade="+cod_cidade;
  url=url+"&sid="+Aleatorio();

  if (cod_cidade=="DESTAQUES"){
           document.getElementById("idlabeltipo").innerHTML=""
           document.getElementById("idtipo").innerHTML=""
           document.getElementById("idlabelbairro").innerHTML=""
           document.getElementById("idbairro").innerHTML=""
           return
  }
  else {
           document.getElementById("idlabeltipo").innerHTML="<br>Tipo de Imóvel:"
           document.getElementById("idtipo").innerHTML="<select id='pcod_tipo_imovel' name='pcod_tipo_imovel'><option>Aguarde...</option></select>"
           document.getElementById("idlabelbairro").innerHTML=""
           document.getElementById("idbairro").innerHTML=""
  }

  xmlHttp.onreadystatechange=function()
  {
       if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
       {
           document.getElementById("idlabeltipo").innerHTML="<br>Tipo de Imóvel:"
           document.getElementById("idtipo").innerHTML=xmlHttp.responseText

           document.getElementById("idlabelbairro").innerHTML=""
           document.getElementById("idbairro").innerHTML=""


       }
  }
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function RetornoBairros(cod_cidade, cod_tipo)
{
var xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
     alert ("Este browser não suporta HTTP Request")
     return
}

var url="getbairros.php";
url=url+"?pcod_cidade="+cod_cidade;
url=url+"&pcod_tipo="+cod_tipo;
url=url+"&sid="+Aleatorio();

         document.getElementById("idlabelbairro").innerHTML="<br>Bairro:"
         document.getElementById("idbairro").innerHTML="<select id='pcod_bairro' name='pcod_bairro'><option>Aguarde...</option></select>"


xmlHttp.onreadystatechange=function()
{
     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
         document.getElementById("idlabelbairro").innerHTML="<br>Bairro:"
         document.getElementById("idbairro").innerHTML=xmlHttp.responseText
     }
}
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}





function GetXmlHttpObject()
{
var objXMLHttp=null

/*******************************************************/
   if (window.XMLHttpRequest) {
       objXMLHttp=new XMLHttpRequest(); } //Objeto nativo (FF/Safari/Opera7.6+)
   else {
        try {
           objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");  //activeX (IE5.5+/MSXML2+)
        }
        catch(e) {
                  try {
                       objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); //activeX (IE5+/MSXML1)
                      }
                      catch(e) { /* O navegador nÃ£o tem suporte */
                                objXMLHttp=false;
                               }
        }
   }
   return objXMLHttp;

/*     if (window.XMLHttpRequest)
         objXMLHttp=new XMLHttpRequest()
     else if (window.ActiveXObject)
         objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

return objXMLHttp
*/
}

function Aleatorio(){
   aleat = Math.random() * 5000;
   aleat = Math.round(aleat);
   return aleat;
}

function Bloqueia_Caracteres(evnt){
//Função permite digitação de números
    if (clientNavigator == "IE"){
        if (evnt.keyCode < 48 || evnt.keyCode > 57){
            return false
        }
    }else{
        if ((evnt.charCode < 48 || evnt.charCode > 57) && evnt.keyCode == 0){
            return false
        }
    }
}

function RetornoPesquisa()
{
var xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
     alert ("Este browser não suporta HTTP Request")
     return
}

var vcod_tipo="";
var vcod_bairro="";

var vcod_cidade=document.getElementById("pcod_cidade").value;


if (document.getElementById("idtipo").innerHTML=='') {
   vcod_tipo="";
}
else {
     vcod_tipo=document.getElementById("pcod_tipo_imovel").value;
}

if (document.getElementById("idbairro").innerHTML=='') {
   vcod_bairro="";
}
else {
     vcod_bairro=document.getElementById("pcod_bairro").value;
}

var url="pesquisa.php";
url=url+"?pcod_cidade="+vcod_cidade;
url=url+"&pcod_tipo_imovel="+vcod_tipo;
url=url+"&pcod_bairro="+vcod_bairro;
url=url+"&sid="+Aleatorio();

xmlHttp.onreadystatechange=function()
{
     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
         document.getElementById("content-right").innerHTML=xmlHttp.responseText
     }
}


xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function RetornoDetalhesImovel(i_cod_imovel)
{
var xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
     alert ("Este browser não suporta HTTP Request")
     return
}

var vcod_imovel=null;

if (i_cod_imovel == null) {
   var vcod_imovel=document.getElementById("pcod_imovel").value;
}
else {
     var vcod_imovel=i_cod_imovel;
}

var url="detalhesimovel.php";
url=url+"?pcod_imovel="+vcod_imovel;
url=url+"&sid="+Aleatorio();

document.getElementById("pcod_imovel").value='';

xmlHttp.onreadystatechange=function()
{
     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
         document.getElementById("content-right").innerHTML=xmlHttp.responseText
     }
}
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function VerificaCampo() {
   if (document.getElementById("pcod_imovel").value == "") {
       alert( "Por favor, informe número do imóvel!" );
       FormPesquisaCodigo.pcod_imovel.focus();
       return false;
   }
   else {
      Guardar();
      RetornoDetalhesImovel();
      return true;
   }
}

function Guardar() {
	   vglobal_array[vindex]=document.getElementById("content-right").innerHTML;
	   vindex=vindex+1;
	   return true;
}

function Devolver() {
	   vindex=vindex-1;
	   document.getElementById("content-right").innerHTML=vglobal_array[vindex];
	   return true;
}

function PesquisaDestaques()
{
var xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
     alert ("Este browser não suporta HTTP Request")
     return
}

var vcod_tipo="";
var vcod_bairro="";
var vcod_cidade="";


var url="pesquisa.php";
url=url+"?pcod_cidade=";
url=url+"&pcod_tipo_imovel=";
url=url+"&pcod_bairro=";
url=url+"&pvoltar=N";
url=url+"&sid="+Aleatorio();

xmlHttp.onreadystatechange=function()
{
     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     {
         document.getElementById("content-right").innerHTML=xmlHttp.responseText
     }
}

xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

