try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}
function query(url){
 	window.scroll(0,0);
	load = document.getElementById("transAjax");
	load.innerHTML = "";
	load.style.backgroundColor = '#fff';
	load.innerHTML = '<div id="loader"><img src="images/load.gif"><br>carregando...</div>';
	
	if(url.indexOf("phptoajax") == -1){
	  url = url + ".php"
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
	     		load.style.backgroundColor = '#fff';
				load.innerHTML = "";
		        load.innerHTML = xmlhttp.responseText;
	    }
	}
	 xmlhttp.send(null)
}
function queryContato(codim){
 	window.scroll(0,0);
	load = document.getElementById("transAjax");
	load.innerHTML = "";
	load.style.backgroundColor = '#fff';
	load.innerHTML = '<div id="loader"><img src="images/load.gif"><br>carregando...</div>';
	
	url = "contato.php?codim="+codim;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
	     		load.style.backgroundColor = '#fff';
				load.innerHTML = "";
		        load.innerHTML = xmlhttp.responseText;
			   	
	    }
	}
	 xmlhttp.send(null)
}
function queryd(url,codim){
 	window.scroll(0,0);
	load = document.getElementById("transAjax");
	load.innerHTML = "";
	load.style.backgroundColor = '#fff';
	load.innerHTML = '<div id="loader"><img src="images/load.gif"><br>carregando...</div>';
	
	url = url;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
	     		load.style.backgroundColor = '#fff';
				load.innerHTML = "";
		        load.innerHTML = xmlhttp.responseText;
				//load.innerHTML += "<div id=\"divPfotos\" style=\"border:1px solid #333\"></div>";
				
				queryfeed()				
	    }
	}
	 xmlhttp.send(null)
	
}
function queryfeed(){
	qload = document.getElementById("qfeed");
    qload.innerHTML = '<center><img src="images/load.gif"><br><br>carregando news...</center>';	
	url = "feeds/feeds.php";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		        qload.innerHTML = xmlhttp.responseText;
				qload.innerHTML += " &nbsp;&nbsp; <a class=\"link\" href=\"javascript:query('feeds/feeds.php?limite=20')\">...mais</a>";
	    }
	}
	 xmlhttp.send(null)
}
function printObj(elm,cor){
	obj = document.getElementById(elm);
	obj.style.backgroundColor = '#ded';
}
function LoadTipo(){
 window.scroll(0,250)
 div_load_tipo = document.getElementById("div_tipo");
 div_load_tipo.innerHTML = "<p>carregando...</p>";
 
 if(document.formbusca.listafins[document.formbusca.listafins.selectedIndex].value == 0){
	document.getElementById("div_bairros").innerHTML = "";
	document.getElementById("div_cidades").innerHTML = "";
	document.getElementById("div_imoveis").innerHTML = "";
	document.getElementById("div_tipo").innerHTML = "";
    document.getElementById("div_preco").innerHTML = "";	
	return false;
}
	document.getElementById("div_bairros").innerHTML = "";
	document.getElementById("div_cidades").innerHTML = "";
	document.getElementById("div_imoveis").innerHTML = "";
	document.getElementById("div_preco").innerHTML = "";
	
	url = "phptoajax.php?fn=loadTipos";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		        div_load_tipo.innerHTML = xmlhttp.responseText;
	    }
	}
	 xmlhttp.send(null)		
	 
}
function LoadCidade(){
   div_load_cidade = document.getElementById("div_cidades");
   document.getElementById("div_cidades").innerHTML = "<p>carregando...</p>";
   	     		
  if(document.formbusca.listatipos[document.formbusca.listatipos.selectedIndex].value == 0){
	document.getElementById("div_bairros").innerHTML = "";
	document.getElementById("div_cidades").innerHTML = "";
	document.getElementById("div_imoveis").innerHTML = "";
	document.getElementById("div_preco").innerHTML = "";
	//document.getElementById("div_tipo").innerHTML = "";
	return false;
}
	document.getElementById("div_bairros").innerHTML = "";
	//document.getElementById("div_cidades").innerHTML = "";
	document.getElementById("div_imoveis").innerHTML = "";
	
	url = "phptoajax.php?fn=loadCidades";
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		        div_load_cidade.innerHTML = xmlhttp.responseText;
	    }
	}
	
	 xmlhttp.send(null)	
	 		
}
function LoadBairros(){
	document.getElementById("div_imoveis").innerHTML = "";
	document.getElementById("div_bairros").innerHTML = "<p>carregando...</p>";
	
 	div_load_bairro = document.getElementById("div_bairros");
	cidade = document.formbusca.listacidades[document.formbusca.listacidades.selectedIndex].value;
	
	
	if(cidade == 0){
	 div_load_bairro.innerHTML ="";
	 return false;
	 }
	 
	url = "phptoajax.php?fn=loadBairros&cidade="+cidade;
	
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		        div_load_bairro.innerHTML = xmlhttp.responseText;
	    }
	}
	 xmlhttp.send(null)
	
}
function LoadImoveis(){
 	div_load_imoveis = document.getElementById("div_imoveis");
	div_load_imoveis.innerHTML = "<p style=\"font:bold 12px verdana; color:red\"> &nbsp;  &nbsp;  carregando os imóveis da base de dados, por favor aguarde...</p>";
		        
 	div_load_bairro = document.getElementById("div_bairros");
 	cidade = document.formbusca.listacidades[document.formbusca.listacidades.selectedIndex].id;
 	cidade_cod = document.formbusca.listacidades[document.formbusca.listacidades.selectedIndex].value;
	bairro = document.formbusca.listabairros[document.formbusca.listabairros.selectedIndex].value;
	fins   = document.formbusca.listafins[document.formbusca.listafins.selectedIndex].value;
	tipo   = document.formbusca.listatipos[document.formbusca.listatipos.selectedIndex].id;
	if(bairro == 0 || fins == 0){
	 LoadBairros()
	 return false;
	 }
	 
	 window.scroll(0,250)
	 
	nav = navigator.appName;
    if(nav == "Microsoft Internet Explorer"){nav = "IE";}else{nav = "NS";}	
	url = "loadimoveis.php?cidade="+cidade+"&cidade_cod="+cidade_cod+"&bairro="+bairro+"&fins="+fins+"&tipo="+tipo+"&nav="+nav;
	
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		        div_load_imoveis.innerHTML = xmlhttp.responseText;
		        document.news.email.focus();
	    }
	}
	 xmlhttp.send(null)
	
}
resp = "";
isflag = 0;
function setValueEquente(valor){
 resp = valor; 
}
function responderEnquete(){
	if(resp == ""){
		//Ext.MessageBox.alert('Erro','Por favor, escolha uma resposta!')
		//Ext.example.msg('Alerta!','Você precisa escolher uma resposta\npara votar na enquete.')
		alert('Você precisa escolher uma resposta\npara votar na enquete.')
		isflag = 1;
	}
	else{
	isflag =0;
	}
	if(isflag ==0){
	xload = document.getElementById("enquete");
	//xload.innerHTML = '<div style="margin-top:90px; text-align:center;"><img src="images/load.gif"><p> carregando...</p></div>';	
		
	url = "votoenquete.php?resposta="+resp;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		        xload.innerHTML = xmlhttp.responseText;
	    }
	}
	 xmlhttp.send(null)
   }
}
function cadastraEmail(){// NEWS
	
	email = document.news.email.value;
	
	if(email == ""){alert('por favor, preencha o campo e-mail!'); return false;}
	if(email.indexOf("@") == -1){alert('por favor, informe um e-mail válido!'); return false;}
	if(email.indexOf(".") == -1){alert('por favor, informe um e-mail válido!'); return false;}
	
	xload = document.getElementById("cadastraemail");
	//xload.innerHTML = '<div style="margin-top:90px; text-align:center;"><img src="images/load.gif"><p> carregando...</p></div>';	
		
	url = "phptoajax.php?fn=cadastraEmail&email="+email;
	
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		        xload.innerHTML = xmlhttp.responseText;
				//alert('Para Adicionar ou Remover seu e-mail \nda lista basta digitá-lo pressionar ok')
	    }
	}
	 xmlhttp.send(null)
}
function cadastraImovel(){
	tipo     = document.cadastraim.tipo.value;
	suites   = document.cadastraim.suites.value;
	dorms    = document.cadastraim.dorms.value;
	vagas    = document.cadastraim.vagas.value;
	cidade   = document.cadastraim.cidade.value;
	bairro   = document.cadastraim.bairro.value;
	nome     = document.cadastraim.nome.value;
	telefone = document.cadastraim.telefone.value;
	email    = document.cadastraim.email.value;
	
	 if(tipo == "" || cidade == "" || telefone == "" || dorms == "" || bairro == "" || nome == "" ){
		alert('Por favor, preencha todos os campos!')
		return false;
	}
	load = document.getElementById("transAjax");
	load.innerHTML = "";
	load.style.height = '590px'
	load.style.backgroundColor = '#fff';
	load.innerHTML = '<div id="loader"><img src="images/load.gif"><br>carregando...</div>';
	url = "mail/enviaCadastroIm.php?tipo="+tipo+"&dorms="+dorms+"&suites="+suites+"&vagas="+vagas+"&cidade="+cidade+"&bairro="+bairro+"&nome="+nome+"&telefone="+telefone+"&email="+email;
	
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
				load.style.backgroundColor = '#fff';
				load.innerHTML = xmlhttp.responseText;
				window.scroll(0,0)
		}
	}
	 xmlhttp.send(null)
}
function corretorV(){
	tipo       = document.cadastraim.tipo.value;
	suites     = document.cadastraim.suites.value;
	dorms      = document.cadastraim.dorms.value;
	vagas      = document.cadastraim.vagas.value;
	cidade     = document.cadastraim.cidade.value;
	bairro     = document.cadastraim.bairro.value;
	nome       = document.cadastraim.nome.value;
	telefone   = document.cadastraim.telefone.value;
	email      = document.cadastraim.email.value;
	valor      = document.cadastraim.valor.value;
	
	if(tipo == "" || cidade == "" || telefone == "" || dorms == "" ){
		alert('Por favor, preencha todos os campos!')
		return false;
	}
 	 	load = document.getElementById("transAjax");
		load.innerHTML = "";
		load.style.height = '590px'
		load.style.backgroundColor = '#fff';
		load.innerHTML = '<div id="loader"><img src="images/load.gif"><br>carregando...</div>';
		url = "mail/enviaCorretorv.php?valor="+valor+"&tipo="+tipo+"&dorms="+dorms+"&suites="+suites+"&vagas="+vagas+"&cidade="+cidade+"&bairro="+bairro+"&nome="+nome+"&telefone="+telefone+"&email="+email;

		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange=function() {
		    if (xmlhttp.readyState==4){
		     		load.style.backgroundColor = '#fff';
			        load.innerHTML = xmlhttp.responseText;
					window.scroll(0,0)
		    }
		}
		 xmlhttp.send(null)
}
function ibusca(){
	tipo    = document.getElementById("busca").itipo[document.getElementById("busca").itipo.selectedIndex].id;
	fins    = document.getElementById("busca").ifim.value;
	cidade  = document.getElementById("busca").icidade.value;
	
	
	if(tipo == "." || tipo == "" ){
		alert('Por favor, selecione o "tipo" de imóvel!')
		//Ext.getCmp('itipo').focus(); // EXT Lib em myExt.js
		//Ext.example.msg('Busca','Por favor, selecione o <b>tipo</b> de imóvel.')
		return false;
	}
	
	
	if(fins == "."){
		alert('Por favor, selecione a "finalidade" do imóvel!'); 
		//Ext.example.msg('Busca','Por favor, selecione a <b>finalidade</b> do imóvel!'); 
		return false;
	}
	
	if(cidade == "."){
		alert('Por favor, selecione a "cidade" desejada!'); 
		//Ext.example.msg('Busca','Por favor, selecione a <b>cidade</b> desejada!'); 
		//Ext.example.msg('Busca','Por favor, selecione a <b>cidade</b> desejada!'); 
		return false;
	}
	
	window.scroll(0,200);
	
 	load = document.getElementById("transAjax");
	load.innerHTML = "";
	load.style.backgroundColor = '#fff';
	load.innerHTML = '<div id="loader"><img src="images/load.gif"><br>carregando...</div>';
	
	nav = navigator.appName;
    if(nav == "Microsoft Internet Explorer"){nav = "IE";}else{nav = "NS";}	
		
	url = "ibuscaresult.php?tipo="+tipo+"&cidade="+cidade+"&fins="+fins+"&nav="+nav;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
				load.style.backgroundColor = '#fff';
		        load.innerHTML = xmlhttp.responseText;
	    }
	}
	 xmlhttp.send(null)
	 
    return false;
}

function detalhes(codim,site,win){
	if(win == 0){
		window.location = "viewdetais.php?codim="+codim;
		return false;
	}
	
	if(confirm('Deseja abrir em uma nova janela para evitar refazer a busca? \nSe sim, desabilite o bloqueador de pop-up!')){
		windetail = site+"viewdetais.php?codim="+codim;
		window.open(windetail,'','')
	}
	else{
		window.location = "viewdetais.php?codim="+codim;
	}
}  
function descript(codim){
		load = document.getElementById("transAjax");
		load.innerHTML = "";
		load.innerHTML = '<div id="loader"><img src="images/load.gif"><br>carregando...</div>';
		url = "detalhes.php?codim="+codim;
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange=function() {
		    if (xmlhttp.readyState==4){
				load.innerHTML = "";
				load.innerHTML = xmlhttp.responseText;
		    }
		}
		 xmlhttp.send(null)	
}
function simulador(banco){
	caixa = "http://www1.caixa.gov.br/casa/simulador/asp/FrmEntrada.asp?CodTabela=2&TipoModalidade=2";
    banespa = "http://www.santanderbanespa.com.br/portal/gsb/script/templates/GCMRequest.do?page=496&entryID=592";
    nossacaixa = "http://www.nossacaixa.com.br/imobiliario/imofp001.htm";
	boston = "http://www.bankboston.com.br/voce/cred_imobiliario/simulacao.asp";
	santander = "http://www.santanderbanespa.com.br/portal/gsb/script/templates/GCMRequest.do?page=496&entryID=592";
	bradesco = "http://www.shopcredit.com.br/shopcredit/br/stsm/stsmcredimobsimulador0.asp?layout=F&retorno=simulado";
	real = "https://wwws.bancoreal.com.br/sim/Scripts/engine_sim.dll?OPERA=sci.ar.Simulacao&ORI=1";
	itau = "https://ww3.itau.com.br/imobline/pre/simuladores/index.aspx?IDENT_bkl=pre&IMOB_tipobkl=";
	unibanco = "http://www1.unibanco.com.br/asp/pfisica/simuladores/imobiliario/asp/default.asp";
   
    switch(banco){
		case 'banespa': window.open(banespa,'new','')
		break;
		
		case 'caixa': window.open(caixa,'new','')
		break;
		
		case 'nossacaixa': window.open(nossacaixa,'new','')
		break;		
		case 'boston': window.open(boston,'new','')
		break;		
		case 'santander': window.open(santander,'new','')
		break;		
		
		case 'bradesco': window.open(bradesco,'new','')
		break;		
		
		case 'real': window.open(real,'new','')
		break;		
		
		case 'itau': window.open(itau,'new','')
		break;		
		case 'unibanco': window.open(unibanco,'new','')
		break;		
		
    }
}
function jober(){
 nome = document.jobs.nome.value;
 cpf = document.jobs.cpf.value;
 nasc = document.jobs.aniversario.value;
 telefone = document.jobs.telefone.value;
 empresa = document.jobs.empresa.value;
 email = document.jobs.email.value;
 if(nome == "" || cpf == "" || nasc == "" || telefone == "" ){
	alert('Por Favor, preencha os campos!')
 }
 else{
	 load = document.getElementById("transAjax");
	 load.innerHTML = '<div id="loader"><br /><img src="images/load.gif"><br>carregando...</div>';
	 
	 window.scroll(0,0);
	 pagejobs = "mail/enviajobs.php?nome="+nome+"&cpf="+cpf+"&nasc="+nasc+"&telefone="+telefone+"&empresa="+empresa+"&email="+email;
	 
		xmlhttp.open("GET", pagejobs, true);
		xmlhttp.onreadystatechange=function() {
		    if (xmlhttp.readyState==4){
			     load.innerHTML = xmlhttp.responseText;
		    }
		}
		 xmlhttp.send(null)
  }
}
function ampliafoto(img){
	amp = document.getElementById("fotoamp");
	amp.innerHTML = '<div id="loader"><br /><img src="images/load.gif"><br>carregando...</div>';
	 
	amp = document.getElementById("fotoamp");
	nimage = '<img src="'+img+'" width="400" height="400">';
	amp.innerHTML = nimage;
	//window.scroll(0,590)
}
function fwamigo(codim){
	obj = document.getElementById("fwamigo");
	if(obj.style.display == 'block')
	{
		obj.style.display = 'none';
	}
	else{
	  obj.style.display = 'block';
	}
	page = "mail/fwamigo.php?codim="+codim;
	xmlhttp.open("GET", page, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		     obj.innerHTML = xmlhttp.responseText;
		    }
	}
	 xmlhttp.send(null);	
	
}
function fwsend(codim){
	obj = document.getElementById("fwamigo");
	amigo = document.fw.amigo.value;
	email = document.fw.email.value;
 
	if(amigo == "" || email == ""){
		alert('Por favor, preencha os campos!')
	}
	
	if(amigo.indexOf("@") == -1 || email.indexOf("@") == -1){
	  alert('Por favor, digte um e-mail válido');
	}
	else{
		page = "mail/fwamigo.php?send=ok&amigo="+amigo+"&email="+email+"&codIM="+codim;
		obj.style.width = "400px";
		obj.innerHTML = "<p>&nbsp;</p>";
	    obj.innerHTML += "<p><b>Enviando, por favor aguarde...</b></p><Br>";
		
		xmlhttp.open("GET", page, true);
		xmlhttp.onreadystatechange=function() {
		    if (xmlhttp.readyState==4){
			     obj.innerHTML = xmlhttp.responseText;
			    }
		}
		 xmlhttp.send(null);
	}
}
function favoritos(codim,cidade,valor,site,sitenome){
	 desc = sitenome + " - Imóvel cód. " + codim + " em " +cidade+ " por " +valor+ "!"; 
	 url = site + "viewdetais.php?codim="+codim;
	 window.external.AddFavorite(url,desc)	
}

