// JavaScript Document
var dados="";

function buscaRap(){
	http.open("POST","result_busca.php",true);
	makeDatRap();
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
	http.send(dados);
	http.onreadystatechange = HandleResp;
}

function makeDatRap(){
	frm = document.form1;
	num = frm.elements.length;
	str= new Array(num);
	for(i=0;i<num;i++){
		str[i]=frm.elements[i].name+"="+ encodeURIComponent(frm.elements[i].value);
	}
	dados = str.join("&");
}

function buscaAv(){
	document.getElementById('buscaRap').style.display="none";
	http.open("POST","result_busca.php",true);
	makeDatA();
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
	http.send(dados);
	http.onreadystatechange = HandleResp;
}

function makeDatA(){
	frm = document.form2;
	num = frm.elements.length;
	str= new Array(num);
	for(i=0;i<num;i++){
		str[i]=frm.elements[i].name+"="+ encodeURIComponent(frm.elements[i].value);
	}
	dados = str.join("&");
}


function buscaRP(pag){
	http.open('GET','result_busca.php?pag='+pag,true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function getPagina(pag){
	var dp="block";
	if(pag=="buscaA.php"){
		dp="none";
	}
	document.getElementById('buscaRap').style.display=dp;
	http.open("GET",pag,true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function getHome(){
	http.open("GET","home.php?func=1",true);
	document.getElementById('buscaRap').style.display="block";
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function getSession(ref){
	http.open("GET","sec.php?ref="+ref,true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function backSession(id){
	http.open("GET","detalhesImovel.php?id="+id,true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function excSession(id){
	http.open("GET","exc.php?id="+id,true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function getCidade(){
	http.open("GET","cidade.php",true);
	document.getElementById('buscaRap').style.display="block";
	http.onreadystatechange = HandleRespCit;
	http.send(null);
}

function HandleRespCit(){
  var dvs = document.getElementById('destaques');
  if (http.readyState == 4){
	  dvs.innerHTML = http.responseText;
	  loadAccordions();
  }
}

function HandleResp(){
  var dvs = document.getElementById('destaques');
  if (http.readyState == 4){
	  dvs.innerHTML = http.responseText;
	  binder();
  }
}


function getBairro(cit){
	http.open("GET","getBairro.php?cit="+cit,true);
	http.onreadystatechange = fazBairro;
	http.send(null);
}

function fazBairro(){
	campo = document.getElementById("bairro");
	if (http.readyState==4){
		campo.options.length=1;
		resultado = http.responseText.split(",");
		for (i=0; i<(resultado.length-1); i++){
			string = resultado[i].split( "|" );
			campo.options[i] = new Option( string[0], string[1]);
		}
	}
}


function getDet(id){
  http.open("GET","detalhesImovel.php?id="+id,true);
  http.onreadystatechange = HandleResp;
  http.send(null);
}

function troca(idc){
	v = document.getElementById(idc);
	d = document.getElementById('fotogr');
	fa = d.src;
	d.src=v.src;
	v.src=fa;
}

function abrePopup(){
	var pag = document.getElementById('pag').value;
	window.open('indique_amigo.php?pg='+pag,'Indicacao','width=200,height=300');
}


function valor(tipo){
	vmin = document.getElementById('valor_min');
	vmax = document.getElementById('valor_max');
	
	vmin.options.length = 1;
	vmax.options.length = 1;
	
	pminA = new Array('0|Indiferente','100|R$ 100,00','200|R$ 200,00','300|R$ 300,00','400|R$ 400,00','500|R$ 500,00','600|R$ 600,00','700|R$ 700,00','800|R$ 800,00');
	
	pmaxA = new Array('9999999|Indiferente','250|R$ 250,00','400|R$ 400,00','1000|R$ 1.000,00','1500|R$ 1.500,00','2000|R$ 2.000,00','3000|R$ 3.000,00');
	
	pminV = new Array( '0|Indiferente','10000|R$ 10.000,00','30000|R$ 30.000,00','50000|R$ 50.000,00','100000|R$ 100.000,00','150000|R$ 150.000,00','300000|R$ 300.000,00');
	
	pmaxV = new Array( '9999999|Indiferente','50000|R$ 50.000,00','100000|R$ 100.000,00','150000|R$ 150.000,00','200000|R$ 200.000,00','300000|R$ 300.000,00','500000|R$ 500.000,00','700000|R$ 700.000,00','1000000|R$ 1.000.000,00');
					  


	if(tipo=="V"){
	 
	 for( i = 0; i<(pminV.length); i++ ){ 
         string = pminV[i].split( "|" );
         vmin.options[i] = new Option( string[1], string[0] );
     }
	 
	  for( i = 0; i<(pmaxV.length); i++ ){ 
         string = pmaxV[i].split( "|" );
         vmax.options[i] = new Option( string[1], string[0] );
     }
		
	}else if(tipo=="L"){
		for( i = 0; i<(pminA.length); i++ ){ 
         string = pminA[i].split( "|" );
         vmin.options[i] = new Option( string[1], string[0] );
     	 }
	 
	    for( i = 0; i<(pmaxA.length); i++ ){ 
          string = pmaxA[i].split( "|" );
          vmax.options[i] = new Option( string[1], string[0] );
        }
	}else{
		vmin.options[0] = new Option('Indiferente',0);
	}
}






function enviar(){
	http.open("POST","naoEncE.php",true);
	makeDatA();
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
	http.send(dados);
	http.onreadystatechange = retorna;
}

function retorna(){
	if (http.readyState == 4) {
    window.location="naoEncE.php";
  }
}

function getCarrinho(id){
	http.open("GET","sec.php?ref="+id,true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function getExcSession(id){
	http.open("GET","exc.php?id="+id,true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function DetVolta(){
	http.open("GET","sess.php",true);
	http.onreadystatechange = HandleResp;
	http.send(null);
}

function buscaR(){
	http.open("POST","resultSearch.php",true);
	makeDatB();
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=iso-8859-1');
	http.send(dados);
	http.onreadystatechange = HandleResp;
	
}

function makeDatB(){
	frm = document.formb;
	num = frm.elements.length;
	str= new Array(num);
	for(i=0;i<num;i++){
		str[i]=frm.elements[i].name+"="+ encodeURIComponent(frm.elements[i].value);
	}
	dados = str.join("&");
}

function testeQ(){
	frm = document.formb;
	num = frm.elements.length;
	str= new Array(num);
	for(i=0;i<num;i++){
		str[i]=frm.elements[i].name+"="+ encodeURIComponent(frm.elements[i].value);
	}
	
	dados = str.join("&");
	alert(dados);
}


function getVenp(valor){
  http.open("GET","imoveis_venda.php?pag="+valor,true);
  http.onreadystatechange = HandleResp;
  http.send(null);
}


function getLocp(valor){
  http.open("GET","imoveis_locacao.php?pag="+valor,true);
  http.onreadystatechange = HandleResp;
  http.send(null);
}


function getCadastro(){
  http.open("GET", "cadastre_imovel.php", true);
  http.onreadystatechange = HandleResp;
  http.send(null);
}

function getDocs(){
   http.open("GET", "documentos_locacao.php", true);
  http.onreadystatechange = HandleResp;
  http.send(null);
}

function getVend(){
   http.open("GET", "imoveis_venda.php", true);
  http.onreadystatechange = HandleResp;
  http.send(null);
}
function getLocs(){
   http.open("GET", "imoveis_locacao.php", true);
  http.onreadystatechange = HandleResp;
  http.send(null);
}
function getSomos(){
	http.open("GET", "quem_somos.php", true);
	http.onreadystatechange = HandleResp;
	http.send(null);
	}
function getInfoSoro(){
	http.open("GET", "info_sorocaba.php", true);
	http.onreadystatechange = HandleResp;
	http.send(null);
	}
function getMapaSoro(){
	http.open("GET", "mapa_sorocaba.php", true);
	http.onreadystatechange = HandleResp;
	http.send(null);
	}


function getCadImovel(){
	http.open("GET","cadastre_imovel.php",true);	
	http.onreadystatechange = mudadestaque;
	http.send(null);
}
function getSorocaba(){
	http.open("GET","info_sorocaba.php",true);
	http.onreadystatechange = mudadestaque;
	http.send(null);
	}
function mudadestaque(){
	if(http.readyState==4){
		document.getElementById('destaques').innerHTML = http.responseText;
		}	
}

function binder(){
	$('#valor_min, #valor_max').priceFormat({
		prefix: '',
		centsSeparator: ',',
		thousandsSeparator: '.'
	});
}

//Criar XMLHTTPRequest
function getHTTPObject() {
var req;

try {
 if (window.XMLHttpRequest) {
  req = new XMLHttpRequest();

  if (req.readyState == null) {
   req.readyState = 1;
   req.addEventListener("load", function () {
   req.readyState = 4;

   if (typeof req.onReadyStateChange == "function")
    req.onReadyStateChange();
   }, false);
  }

  return req;
 }

 if (window.ActiveXObject) {
  var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];

  for (var i = 0; i < prefixes.length; i++) {
   try {
    req = new ActiveXObject(prefixes[i] + ".XmlHttp");
    return req;
   } catch (ex) {};

  }
 }
} catch (ex) {}

alert("XmlHttp Objects not supported by client browser");
}
var http = getHTTPObject();

// Logo após fazer a verificação, é chamada a função e passada 
// o valor à variável global http.



