function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function selecionaGaleria(id){
	open('?g='+id,'_top');
}

function preloadImagens(){
	var args = preloadImagens.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++) {
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

function mostraImagens(){
	document.getElementById('divImagens').style.display = 'Block';
}


function enviaMensagem(){
	if(document.frmGeral.txtNome.value==""){
		alert("O Nome deve ser Preenchido!!");
		document.frmGeral.txtNome.focus();
		return false;	
	}
	if(document.frmGeral.txtEmail.value==""){
		alert("O Email de Contato deve ser Preenchido!!");
		document.frmGeral.txtEmail.focus();
		return false;	
	}
	
	if(!validaEmail(document.frmGeral.txtEmail)){
		alert("Endereço de Email Inválido!!");
		document.frmGeral.txtEmail.focus();
		return false;	
	}

	if(document.frmGeral.txtMensagem.value==""){
		alert("A Mensagem deve ser Preenchida!!");
		document.frmGeral.txtMensagem.focus();
		return false;	
	}

	document.frmGeral.action = "enviaEmail.php";
	document.frmGeral.target = "_top";
	document.frmGeral.method = "post";
	document.frmGeral.submit();
}

function validaEmail(email){
	valor = email.value
	Arroba= valor.indexOf("@");
	Ponto= valor.lastIndexOf(".");
	espaco= valor.indexOf(" ");

	if (valor == '')
		return false;

	if  ((Arroba != -1) && (Ponto > Arroba +1) && (espaco==-1)){
		return true;
	}else{
		email.focus();
		return false;
	}
}

function mostraImovelVendas(iID,tipo){
	document.frmGeral.hdImovel.value = iID;
	document.frmGeral.hdBuscaTipo.value = tipo;
	document.frmGeral.action = 'vendas-dados-torre-blanca.php';
	document.frmGeral.submit();
}

function mostraImovelLocacao(iID,tipo){
	document.frmGeral.hdImovel.value = iID;
	document.frmGeral.hdBuscaTipo.value = tipo;
	document.frmGeral.action = 'locacao-dados-torre-blanca.php';
	document.frmGeral.submit();
}

function buscaDetalhada(){
	operacao = document.frmGeral.slcOperacao.value;
	if(operacao==2)
		document.frmGeral.action = 'vendas-torre-blanca.php';
	else
		document.frmGeral.action = 'locacao-torre-blanca.php';

	document.frmGeral.submit();
}


function localizaImoveisVenda(){
	document.frmGeral.action = 'vendas-resultado-torre-blanca.php';
	document.frmGeral.submit();
}

function localizaImoveisVendaSimples(){
	if(document.frmGeral.slcOperacao.value == 2){
		document.frmGeral.action = 'vendas-resultado-torre-blanca.php?i='+document.frmGeral.slcImovelR.value;
		document.frmGeral.submit();
	}
	if(document.frmGeral.slcOperacao.value == 1){
		document.frmGeral.action = 'locacao-resultado-torre-blanca.php?i='+document.frmGeral.slcImovelR.value;
		document.frmGeral.submit();
	}
}

function localizaImoveisLocacao(){
	document.frmGeral.action = 'locacao-resultado-torre-blanca.php';
	document.frmGeral.submit();
}



var ajax = null;
if(window.XMLHttpRequest)	var ajax = new XMLHttpRequest();
else if(window.ActiveXObject)	var ajax = new ActiveXObject("Microsoft.XMLHTTP");
else alert("Este navegador não suporta ajax");

function ajaxGeral(pagina, div){
	ajax.open("get", pagina, true);
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4) { 
			if(ajax.status == 200){
				document.getElementById(div).innerHTML = ajax.responseText;
			}else{
				alert(ajax.status);			
			}		
		}
	}
	ajax.send(null);
}

var ajaxAux = null;
if(window.XMLHttpRequest)	var ajaxAux = new XMLHttpRequest();
else if(window.ActiveXObject)	var ajaxAux = new ActiveXObject("Microsoft.XMLHTTP");
else alert("Este navegador não suporta ajax");

function ajaxAuxiliar(pagina, div){
	ajaxAux.open("get", pagina, true);
	ajaxAux.onreadystatechange = function() {
		if(ajaxAux.readyState == 4) { 
			if(ajaxAux.status == 200){
				document.getElementById(div).innerHTML = ajaxAux.responseText;
			}else{
				alert(ajaxAux.status);			
			}		
		}
	}
	ajaxAux.send(null);
}

function filtrosBusca(tipo){
	ajaxGeral('includes/buscaAdicionais.php?sd='+tipo, 'divAdicionais')
}


function mostraDiv(mostra, esconde){
	document.getElementById(mostra).style.display = "block";
	document.getElementById(esconde).style.display = "none";

}

function refinaBusca(id, campo, tipo){
	ajaxGeral('includes/buscaRefinaVendas.php?aID='+id+'&tipo='+tipo, 'divRetornaBusca')
	ajaxAuxiliar('includes/buscaAdicionaisAtualiza.php?sd='+tipo, 'divAdicionais')
}

function mostraImagemCentro(imovelID,imagem, titulo, descricao){
	document.getElementById('tdImgCentro').innerHTML = "<img src='imagens/imoveis/"+imovelID+"/grande_"+imagem+"' border='0' title='Visualizar em Tamanho Maior'>";
//	document.getElementById('linkPrincipal').href  = "imagens/imoveis/"+imovelID+"/"+imagem;
	document.getElementById('linkPrincipal').setAttribute("title",titulo);
	document.getElementById('linkPrincipal').setAttribute("caption",descricao);

}


function voltaImovelBuscaVendas(tipo){
	if(tipo==1)
		open('./', '_top')
	else{
		document.frmGeral.action = 'vendas-resultado-torre-blanca.php';
		document.frmGeral.submit();
	}
}


function voltaImovelBuscaLocacao(tipo){
	if(tipo==1)
		open('./', '_top')
	else{
		document.frmGeral.action = 'locacao-resultado-torre-blanca.php';
		document.frmGeral.submit();
	}
}


function trocaImovelDestaqueVendas(fator){
	total 	= document.frmGeral.hdTotalV.value;
	inicial	= eval(document.frmGeral.hdAtualVIni.value) + fator
	if(inicial==-1)	return false;
	if(total < 3)	return false;
	
	j = 0
	for(i=1;i<=3;i++){
		referencia = eval(inicial) + i
		ref	= eval('document.frmGeral.hdRefV'+referencia).value;
		imagem	= eval('document.frmGeral.hdImagemV'+referencia).value;
		id	= eval('document.frmGeral.hdIDV'+referencia).value;
		document.getElementById('divV'+i).innerHTML = "<img src='imagens/imoveis/"+id+"/media_"+imagem+"' width='137' height='156'  onclick='mostraImovelVendas("+id+",2)' Style='cursor:pointer'/>";
		document.getElementById('divVR'+i).innerHTML = "Ref.: "+ref;

	}
	if(referencia==total) 	return false;
	if(fator==0)		document.frmGeral.hdAtualVIni.value = eval(document.frmGeral.hdAtualVIni.value) + 1;
	if(fator==-1)		document.frmGeral.hdAtualVIni.value = eval(document.frmGeral.hdAtualVIni.value) - 1;
}

function trocaImovelDestaqueLocacao(fator){
	total 	= document.frmGeral.hdTotalL.value;
	inicial	= eval(document.frmGeral.hdAtualLIni.value) + fator
	if(inicial==-1) 	return false;
	if(total < 3)	return false;
	j = 0
	for(i=1;i<=3;i++){
		referencia = eval(inicial) + i
		ref	= eval('document.frmGeral.hdRefL'+referencia).value;
		imagem	= eval('document.frmGeral.hdImagemL'+referencia).value;
		id	= eval('document.frmGeral.hdIDL'+referencia).value;
		document.getElementById('divL'+i).innerHTML = "<img src='imagens/imoveis/"+id+"/media_"+imagem+"' width='137' height='156'  onclick='mostraImovelLocacao("+id+",1)' Style='cursor:pointer'/>";
		document.getElementById('divLR'+i).innerHTML = "Ref.: "+ref;

	}
	if(referencia==total) 	return false;
	if(fator==0)		document.frmGeral.hdAtualLIni.value = eval(document.frmGeral.hdAtualLIni.value) + 1;
	if(fator==-1)		document.frmGeral.hdAtualLIni.value = eval(document.frmGeral.hdAtualLIni.value) - 1;
}



function bannersInicio(){
	setInterval("bannerTimer()", 6000)
}

function bannerTimer(){

	total  	     = document.getElementById("hdTotalBanner").value
	if(total<=1){
		return false
	}else{
		posicao = document.getElementById("hdPosicaoTimer").value;
		if(posicao == total)
			document.getElementById("hdPosicaoTimer").value = 1;
		else
			document.getElementById("hdPosicaoTimer").value = eval(document.getElementById("hdPosicaoTimer").value)+1;
		
		campo = "hdBanner"+document.getElementById("hdPosicaoTimer").value;
		objeto = document.getElementById(campo).value;
		document.getElementById("tdTrocaBanner").innerHTML = objeto;

	}
}

