// JavaScript Document

var browser;
var ficha;
var empreendimento;

var filtroCid = "";
var filtroTp = "";
var filtroBairro = "";
var filtroDorm= "";
var filtroVlr="";
var filtroBai = "";
var filtroLista = "";
var filtroOrdem = "";
var fotoindice = 0;
var listafoto = new Array();
var salto;
var idx;
var cod;

function trocaFotosTop(){
	var trocaFotos = new Array();
	
	trocaFotos[0] = '<img src="fotos/foto1.jpg">';
	trocaFotos[1] = '<img src="fotos/foto2.jpg">';
}

function zeraFotoIndice(){
	fotoindice = 0;
}

function recebeVar(idx,cod){
	listafoto[idx] = cod;
	/*alert(idx+'  '+cod);*/
}

var tEmpr;

function abreIndique() {
//	alert(document.body.innerHTML);
	ajaxFunction(document.getElementById('mail'),'indique.php?ficha='); //ajaxFunction(document.getElementById('detalhe'),'indique.php?ficha=<? echo $r[9]; ?>&foto=<? echo $r[8]; ?>');
}

function ajaxFunction(elemento,pagina) {
elemento.style.visibility = 'visible';
elemento.innerHTML = '<img src="img/aguarde.gif">';
var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
	}
	else 
	if (window.ActiveXObject){ // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else{
			alert("Your browser does not support XMLHTTP!");
			}
xmlhttp.onreadystatechange=function(){
									if (xmlhttp.readyState==4){
										elemento.innerHTML = xmlhttp.responseText;
										}
									}
xmlhttp.open("GET",pagina,true);
xmlhttp.send(null);
}

function moveEmpreend(obj,x,y) {
if (x > 80) {
	x -=1;
	y -=1;
   	document.getElementById(obj).style.top = x+'px';
   	document.getElementById(obj).style.left = y+'px';
  	setTimeout('moveEmpreend("'+obj+'",'+x+','+y+')',0);
   	}
}



function fadeIn(obj) {
var bodyStyle=document.getElementById(obj).style;
if ((bodyStyle.visibility == 'hidden')) {
    bodyStyle.opacity = 0;
	bodyStyle.visibility = 'visible';
	}
if ( bodyStyle.opacity < 1) {
	bodyStyle.opacity=((bodyStyle.opacity*10)+1)/10; //Add 0.1
	setTimeout("fadeIn('"+obj+"')",150);
	}
}

function resetFadeOut(obj) {
if (document.getElementById(obj) != null)
	if ( document.getElementById(obj).archive == null)
    	document.getElementById(obj).archive = '100';
}


function fadeInIE(obj) {
if (document.getElementById(obj) != null) {
var bodyStyle=document.getElementById(obj).style;
if ((bodyStyle.visibility == 'hidden') || (document.getElementById(obj).archive == null)) {
    document.getElementById(obj).archive = '0';
    if (document.getElementById('frm'+obj) != null )
	    document.getElementById('frm'+obj).archive = '0';
	bodyStyle.visibility = 'visible';
	}
if ( Number(document.getElementById(obj).archive) < 100) {
	document.getElementById(obj).archive =  Number(document.getElementById(obj).archive)+10;
	document.getElementById(obj).className = 't'+document.getElementById(obj).archive;
	setTimeout("fadeInIE('"+obj+"')",150);
	}
}
}

function fadeOut(obj) {

var bodyStyle=document.getElementById(obj).style;
if ( bodyStyle.opacity >0 ) {
	bodyStyle.opacity=((bodyStyle.opacity*10)-1)/10; 
	setTimeout('fadeOut("'+obj+'");',150);
	}
}


function fadeOutIE(obj,lim) {
if (document.getElementById(obj) != null)  {
var bodyStyle=document.getElementById(obj).style;
if ( Number(document.getElementById(obj).archive) >lim) {
	document.getElementById(obj).archive =  Number(document.getElementById(obj).archive)-10;
	document.getElementById(obj).className = 't'+document.getElementById(obj).archive;
	setTimeout("fadeOutIE('"+obj+"',"+lim+")",150);
	}
}
}

function desabilitaBotao(){
	
	document.getElementById('contato_7').style.visibility = 'hidden';
	//document.getElementById('contato_7').onclick = '';
}



//window.parent.document.getElementById('r').innerHTML = "<div class='resultadoBuscaTopo'> Fechar [X]</div><div class='resultadoBuscaCorpo'> <iframe src='resultado.php' frameborder='0' scrolling='No' width='560' height='550'></iframe></div><div class='resultadoBuscaBase'> &nbsp;</div> ";
//imoveis_venda.php?pag=0"+filtro_tp+filtro_cid+filtro_dorm+filtro_vlr;

function bai() {
  cnd = "0";
  if (! document.getElementById('bairros').options[0].selected)
 		 for(i=1;i < document.getElementById('bairros').length; i++)
		 {if (document.getElementById('bairros').options[i].selected)
		    cnd += ','+document.getElementById('bairros').options[i].value;
		 }
if (cnd == '0')
filtroBai = ''
else
filtroBai = '&bai=('+cnd+')';
//		 document.getElementById('tb_miolo').src = "imoveis_venda.php?pag=0"+filtro_tp+filtro_cid+filtro_dorm+filtro_vlr+filtro_bai;

}

function Bairros(valor) {
      //verifica se o browser tem suporte a ajax
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
	  }
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //se tiver suporte ajax
	  if(ajax) {
	     //deixa apenas o elemento 1 no option, os outros são excluídos
		 if (valor != "sem") 
		 filtroCid = "&cidade="+valor;
		 else
		 filtroCid = '';


//		 document.getElementById('tb_miolo').src = "imoveis_venda.php?pag=0"+filtro_tp+filtro_cid+filtro_dorm+filtro_vlr;

         for (var r = document.getElementById("bairros").length-1; r >=0 ; r--)
                 document.getElementById("bairros").remove(document.getElementById("bairros").options[r]);

		 idOpcao  = document.getElementById("bairros");
			
	     ajax.open("POST", "bairros_xml.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			
			
		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
//			   idOpcao.innerHTML = "Carregando...!";
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
                              processXML(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "--Primeiro selecione o município--";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "cidade="+valor;
         ajax.send(params);
		 
      }
	
   }

function processXML(obj){
//pega a tag cidade

	var dataArray   = obj.getElementsByTagName("bairro");
	//total de elementos contidos na tag cidade
		if(dataArray.length > 0) {
		//percorre o arquivo XML paara extrair os dados
		for(var i = 0 ; i < dataArray.length ; i++) {
		var item = dataArray[i];
		//contéudo dos campos no arquivo XML
		var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
		var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;

		var y=document.createElement('option');
		y.text=descricao;
		y.value = codigo;
		y.id = "b"+(i+1);
		var x=document.getElementById("bairros");
		try
			{
				x.add(y,null); // standards compliant
			}
			catch(ex)
				{
					x.add(y); // IE only
				}
		
		}
	}   
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "--Sem Bairros--";
	}
	  habilitaBotao();
}

function trocaPagina(pag,busca){
	
	ajaxFunction(document.getElementById('conteudo_detalhe_p'),'miolo_pesquisa.php?pagina='+pag+'&busca='+busca);
	
}


function fazbusca(num) {
	
	
	
	if (document.getElementById('cidade').value != 'sem') 
		filtroCid='&cidade='+(document.getElementById('cidade').value);
		else
		filtroCid='';
		filtroBai='';
	
	if (document.getElementById('bairros').value != 'sem')
		filtroBairro='&bairro='+(document.getElementById('bairros').value);
		else
		filtroBairro='';
		
		if (document.getElementById('bairros').value == 'todos')
			filtroBairro='';
	if (document.getElementById('dorm').value != 'sem') 
		filtroDorm='&dorm='+(document.getElementById('dorm').value);
		else
		filtroDorm='';
	if (document.getElementById('tipo').value != 'sem') 
		filtroTp='&tipo='+(document.getElementById('tipo').value);
		else
		filtroTp='';
	if (document.getElementById('valor_d').value != '0')
		filtroVlr_d='&vlr_d='+(document.getElementById('valor_d').value);
		else
		filtroVlr_d='';
	
	if (document.getElementById('valor_ate').value != '0')
		filtroVlr_ate='&vlr_ate='+(document.getElementById('valor_ate').value);
		else
		filtroVlr_ate='';
		
		if (document.getElementById('priv_max').value != 'sem')
		filtroVlr_priv_max='&priv_max='+(document.getElementById('priv_max').value);
		else
		filtroVlr_priv_max='';
		
		if (document.getElementById('priv_min').value != 'sem')
		filtroVlr_priv_min='&priv_min='+(document.getElementById('priv_min').value);
		else
		filtroVlr_priv_min='';
	
	if (document.getElementById('garagem').value != 'sem')
		filtroGar='&gar='+(document.getElementById('garagem').value);
		else
		filtroGar='';
	
	filtroLista = filtroTp+filtroDorm+filtroCid+filtroBairro+filtroVlr_d+filtroVlr_ate+filtroGar+filtroVlr_priv_max+filtroVlr_priv_min;
	if(num==1){
		
		window.location.href="pesquisa.php?="+filtroLista;	
	}
	if(num==2){
	ajaxFunction(document.getElementById('conteudo_detalhe_p'),'miolo_pesquisa.php?'+filtroLista);
	


	}
}



function buscaCod(){
	
	if (document.getElementById('ficha').value != 'sem'){
	  ficha=document.getElementById('ficha').value;
		ajaxFunction(document.getElementById('conteudo_geral'),'detalhe.php?ficha='+ficha);	
	}
	
}
function limpaCampo(){
	
	document.getElementById('ficha').value="";
}

function buscaEmpreendimento(ficha){
	
	ajaxFunction(document.getElementById('conteudo_geral'),'detalhe-empreendimento.php?ficha='+ficha);

}
function buscaDetalhe(ficha){
	ajaxFunction(document.getElementById('conteudo_geral'),'detalhe.php?ficha='+ficha);
}

function changePage(url){
	
	ajaxFunction(document.getElementById('conteudo_geral'),url);
	
}
function abreDetalhe(ficha){
	ajaxFunction(document.getElementById('conteudo_geral'),'detalhe.php?ficha='+ficha);
	
}

function buscaRapida() {
	
	
	
	if (document.getElementById('cidade').value != 'sem') 
		filtroCid='&cidade='+(document.getElementById('cidade').value);
		else
		filtroCid='';
		filtroBai='';
	
	
	if (document.getElementById('tipoImovel').value != 'sem') 
		filtroTp='&tipo='+(document.getElementById('tipoImovel').value);
		else
		filtroTp='';
	if (document.getElementById('valorImovel').value != 'sem')
		filtroVlr='&vlr_d='+(document.getElementById('valorImovel').value);
		else
		filtroVlr='';
		
	if (document.getElementById('valorImovelAte').value != 'sem')
		filtroVlrAte='&vlr_ate='+(document.getElementById('valorImovelAte').value);
		else
		filtroVlrAte='';
	
	
	filtroLista = filtroTp+filtroCid+filtroVlrAte+filtroVlr;
	
		ajaxFunction(document.getElementById('conteudo_geral'),'pesquisa.php?'+filtroLista);

	
}

function voltaPesquisa(pagina){
	
	ajaxFunction(document.getElementById('conteudo_detalhe_p'),'pesquisa1.php?'+filtroLista+'&pagina='+pagina);

}
function abreDetalhe(ficha){
	
	ajaxFunction(document.getElementById('conteudo_detalhe_p'),'detalhe1.php?ficha='+ficha);
	
}
function minhaLista(ficha,p){
	ajaxFunction(document.getElementById('ml'),'gravasessaobrowser.php?nalista='+ficha);
	ajaxFunction(document.getElementById('menu_r'),'area_menu.php?lista=sim');
	
	alert('Imovel ficha: '+ficha+' adicionado a lista');
	if(p!=""){
	ajaxFunction(document.getElementById('resultado_legenda_lista'),'link_lista.php');
	}
	
}

function avisoLista(){
	alert('Sua lista esta vazia')
}
function abreLista(){
	
	ajaxFunction(document.getElementById('conteudo_geral'),'miolo_lista.php');
	//ajaxFunction(document.getElementById('conteudo_geral'),'detalhe.php?ficha='+ficha);
	
}
function esconde_pesquisar() {
if (document.getElementById('lanc1').checked) {
   document.getElementById('ficha').style.visibility = 'visible';
   document.getElementById('tipo').style.visibility = 'visible';
   document.getElementById('select').style.visibility = 'visible';
   document.getElementById('select2').style.visibility = 'visible';
} else  {
   document.getElementById('ficha').style.visibility = 'hidden';
   document.getElementById('tipo').style.visibility = 'hidden';
   document.getElementById('select').style.visibility = 'hidden';
   document.getElementById('select2').style.visibility = 'hidden';
         }
}
function pesquisar() {
	
if (document.getElementById('ficha').value != '')  {
	destaque(9,Number(document.getElementById('ficha').value));
	}
	else
	{
window.parent.document.getElementById("resultado").style.visibility='visible';
ficha=-4;
salto=0;
grow();

if (document.getElementById('tipo').value != 'sem') 
	filtroTp='&tipo='+(document.getElementById('tipo').value);
	else
	filtroTp='';
if (document.getElementById('cidade').value != 'sem') 
	filtroCid='&cidade='+(document.getElementById('cidade').value);
	else
	filtroCid='';
filtroBai = '';
try {
bai();
} catch (e) {}
if (filtroBai != '') 
    filtroBairro='&bairro='+filtroBai;
	else
	filtroBairro='';

if (document.getElementById('select').value != 'sem') 
	filtroDorm='&dorm='+(document.getElementById('select').value);
	else
	filtroDorm='';
if (document.getElementById('select2').value != 'sem') 
	filtroVlr='&vlr='+(document.getElementById('select2').value);
	else
	filtroVlr='';

filtroLista = filtroDorm+filtroCid+filtroBairro+filtroTp+filtroVlr;
if (document.getElementById('lanc1').checked)
   ajaxFunction1();

if (document.getElementById('lanc2').checked)
   ajaxFunction2();

	}
//window.parent.document.getElementById('r').innerHTML = "<div class='resultadoBuscaTopo'> Fechar [X]</div><div class='resultadoBuscaCorpo'> <iframe src='resultado.php' frameborder='0' scrolling='No' width='560' height='550'></iframe></div><div class='resultadoBuscaBase'> &nbsp;</div> ";
//imoveis_venda.php?pag=0"+filtro_tp+filtro_cid+filtro_dorm+filtro_vlr;
} 


function ajaxFunction1()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  window.parent.document.getElementById('resultado').innerHTML = xmlhttp.responseText;
  }
}

xmlhttp.open("GET","resultado.php?salto=0"+filtroLista,true);
xmlhttp.send(null);
}


function ajaxFunction2()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
  window.parent.document.getElementById('resultado').innerHTML = xmlhttp.responseText;
  }
}

xmlhttp.open("GET","resultado_empreend.php?salto=0"+filtroLista,true);
xmlhttp.send(null);
}

function ajaxFunctionMail(params)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function() {
									if(xmlhttp.readyState==4) {
									   window.parent.document.getElementById('frente').innerHTML = xmlhttp.responseText;
  										}
									  }

xmlhttp.open("POST","envia_email.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", params.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(params);
}


function giraEmpreend() {
tempoPar   = 1500;
if (browser != 'IE7') {
	fadeInIE('empr1');
	setTimeout("fadeOutIE('empr1',0);",6000);
	setTimeout("fadeOutIE('empr1F',0);",6000);
	for (i = 2;i <=nEmpreendimentos;i++) { //
		setTimeout("fadeInIE('empr"+i+"');",tempoPar);
		setTimeout("fadeInIE('empr"+i+"F');",tempoPar);
		setTimeout("fadeOutIE('empr"+i+"',0);",tempoPar+6000);
		setTimeout("fadeOutIE('empr"+i+"F',0);",tempoPar+6000);
		if (i % 2 != 0) 
			tempoPar +=1500;
			else
			tempoPar += 7000;
		}
	}
	else
	{
	document.getElementById('empr1').style.visibility = 'visible';
	document.getElementById('empr1F').style.visibility = 'visible';
	setTimeout("document.getElementById('empr1').style.visibility = 'hidden';",6000);
	setTimeout("document.getElementById('empr1F').style.visibility = 'hidden';",6000);
for (i = 2;i <=nEmpreendimentos;i++) { //
setTimeout("document.getElementById('empr"+i+"').style.visibility = 'visible';",tempoPar);
setTimeout("document.getElementById('empr"+i+"F').style.visibility = 'visible';",tempoPar);
setTimeout("document.getElementById('empr"+i+"').style.visibility = 'hidden';",tempoPar+6000);
setTimeout("document.getElementById('empr"+i+"F').style.visibility = 'hidden';",tempoPar+6000);
if (i % 2 != 0) 
	tempoPar +=1500;
	else
	tempoPar += 7000;
}
		
	}
/*setTimeout("fadeOutIE('empr1',0);",6000);
setTimeout("fadeOutIE('empr2',0);",7500);
setTimeout("fadeOutIE('empr1F',0);",6000);
setTimeout("fadeOutIE('empr2F',0);",7500);
setTimeout("fadeInIE('empr3');",7000);
setTimeout("fadeInIE('empr4');",8500);
setTimeout("fadeInIE('empr3F');",7000);
setTimeout("fadeInIE('empr4F');",8500);
setTimeout("fadeOutIE('empr3',0);",13000);
setTimeout("fadeOutIE('empr4',0);",14500);
setTimeout("fadeOutIE('empr3F',0);",13000);
setTimeout("fadeOutIE('empr4F',0);",14500);
ajaxFunction(document.getElementById('corpo'),'empreendimentos_c.php?browser='+browser);
*/
tEmpr = setTimeout("ajaxFunction(document.getElementById('corpo'),'empreendimentos_c.php?browser="+browser+"');",tempoPar);
tEmpr1 = setTimeout("iniciaEmpreend();",tempoPar+400);

//tEmpr = setTimeout('giraEmpreend();',tempoPar);
}


function iniciaEmpreend() {
if (document.getElementById('empr1') == null)
    setTimeout('iniciaEmpreend()',1000);
	else
	giraEmpreend();
}

function destaque(sel,f) {

ficha = f;
if (sel > 0) {
	for (i=1;i<=8;i++) resetFadeOut('imov'+i);
	for (i=1;i<=8;i++) if (i != sel) fadeOutIE('imov'+i,30);
	fadeInIE('imov'+sel);
	}
//x = Number( document.getElementById('imov'+sel).style.left.substr(0,document.getElementById('imov'+sel).style.left.indexOf('px')))+750;
//y = Number( document.getElementById('imov'+sel).style.top.substr( 0,document.getElementById('imov'+sel).style.top.indexOf('px')))+80;

//  tirar a imagem que crescia     document.getElementById('detalhe').style.visibility = 'visible';
//  tirar a imagem que crescia     document.getElementById('detFoto').src = foto;
//  tirar a imagem que crescia     document.getElementById('detalhe').style.top = y+'px';
//  tirar a imagem que crescia     document.getElementById('detalhe').style.left= x+'px';
//  tirar a imagem que crescia     document.getElementById('detalhe').style.width= 120+'px';
//  tirar a imagem que crescia     document.getElementById('detalhe').style.height= 90+'px';

document.getElementById('fundo').style.visibility = 'visible';
grow();
}

function destaque1(f) {
document.getElementById('fundo1').style.visibility = 'visible';
document.getElementById('frente1').style.visibility = 'visible';
ficha = f;
ajaxFunction(document.getElementById('frente1'),'detalhe_c.php?ficha='+ficha);


}

function destaque2(f) {
document.getElementById('fundo1').style.visibility = 'visible';
document.getElementById('frente1').style.visibility = 'visible';
ficha = f;
ajaxFunction(document.getElementById('frente1'),'detalhe_empreend.php?empreend='+ficha+'&pesquisa=1');
setTimeout('empreendBarraFotos('+ficha+')',1000);
}
function empreendBarraFotos(f) {
if (document.getElementById('barraFotosEmpreend') != null)  {
    ajaxFunction(document.getElementById('barraFotosEmpreend'),'barra_fotos_empreend.php?empreend='+f);
//    ajaxFunction(document.getElementById('imoveisEmpreend'),'imoveis_empreend.php?empreend='+f);
   }
   else
setTimeout('empreendBarraFotos('+f+')',1000);
}
function grow1() {
if (navigator.appName != 'Microsoft Internet Explorer') {	
x = Number( document.getElementById('fundo').style.left.substr(0,document.getElementById('fundo').style.left.indexOf('px')));
y = Number( document.getElementById('fundo').style.top.substr( 0,document.getElementById('fundo').style.top.indexOf('px')));
w = Number( document.getElementById('fundo').style.width.substr(0,document.getElementById('fundo').style.width.indexOf('px')));
h = Number( document.getElementById('fundo').style.height.substr(0,document.getElementById('fundo').style.height.indexOf('px')));
if (x > 150) x-=50;
if (y > 80) y-=20;
if (w < 660) w+=40;
if (h < 500) h+=20;
} else
{
	x = 150;
	y = 80;
	w = 660;
	h = 500;
}
document.getElementById('detalhe').style.width  = w+'px';
document.getElementById('detalhe').style.height = h+'px';
document.getElementById('detalhe').style.left   = x+'px';
document.getElementById('detalhe').style.top    = y+'px';

if (!((x==150)&&(y==80)&&(w==800)&&(h==600)))
   setTimeout('grow1();',1);

}
function grow() {
if (ficha != -4) 
    document.getElementById('frente').innerHTML = '';
lw=660;
if (ficha == -1) lw = 300;
if (ficha == -4) lw = 960;
if (ficha > 0) lw = 960;
x = Number( document.getElementById('fundo').style.left.substr(0,document.getElementById('fundo').style.left.indexOf('px')));
y = Number( document.getElementById('fundo').style.top.substr( 0,document.getElementById('fundo').style.top.indexOf('px')));
w = Number( document.getElementById('fundo').style.width.substr(0,document.getElementById('fundo').style.width.indexOf('px')));
h = Number( document.getElementById('fundo').style.height.substr(0,document.getElementById('fundo').style.height.indexOf('px')));

if (navigator.appName != 'Microsoft Internet Explorer') {	
if (x > 100) x-=10;
if (y > 80) y-=10;

if (w < lw) w+=30;
   else
   if (w > lw) w-=30;
if (h < 450) h+=30;
}
else
{
	x = 100;
	y = 80;
	w = lw;
	h = 450;
}
document.getElementById('fundo').style.left   = x+'px';
document.getElementById('fundo').style.top    = y+'px';
document.getElementById('fundo').style.width  = w+'px';
document.getElementById('fundo').style.height = h+'px';
if (!((x<=100)&&(y<=80)&&(w==lw)&&(h>=450)))
   setTimeout('grow();',0);
   else
   {
	document.getElementById('frente').style.left   = x+'px';
	document.getElementById('frente').style.top    = y+'px';
	document.getElementById('frente').style.width  = w+'px';
	document.getElementById('frente').style.height = h+'px';

    if (ficha > 0)
       detalhe();
	   else
	   if (ficha == -1)
	      pesquisa();
	      else
	      if (ficha == -2)
	         contato();
	      else
	      if (ficha == -3)
	         sobre();
	      else
	      if (ficha == -5)
	         cadastre();
	      else
	      if (ficha == -6)
	         links();
	      else
	      if (ficha == -7)
	         corretores();
	}
}

function detalhe(ficha) {
document.getElementById('frente').style.visibility = 'visible';
ajaxFunction(document.getElementById('frente'),'detalhe_c.php?ficha='+ficha);

}

function pesquisa() {
document.getElementById('frente').style.visibility = 'visible';
ajaxFunction(document.getElementById('frente'),'pesquisa.php?browser='+browser);

}

function links() {
document.getElementById('frente').style.visibility = 'visible';
ajaxFunction(document.getElementById('frente'),'links.html');
}

function corretores() {
document.getElementById('frente').style.visibility = 'visible';
ajaxFunction(document.getElementById('frente'),'corretores.html');
}

function contato() {
document.getElementById('frente').style.visibility = 'visible';
ajaxFunction(document.getElementById('frente'),'contato.html');

}
function sobre() {
document.getElementById('frente').style.visibility = 'visible';
ajaxFunction(document.getElementById('frente'),'sobre.html');

}
function cadastre() {
document.getElementById('frente').style.visibility = 'visible';
ajaxFunction(document.getElementById('frente'),'cadastre.html');
}

function mostraPesquisa() {
ficha=-1;
if (document.getElementById('fundo').style.visibility == 'hidden') {
	document.getElementById('fundo').style.left = '210px';
	}
document.getElementById('fundo').style.visibility = 'visible';
grow();
}

function mostraSobre() {
ficha=-3;
document.getElementById('fundo').style.visibility = 'visible';
grow();
}

function mostraCadastre() {
ficha=-5;
document.getElementById('fundo').style.visibility = 'visible';
grow();
}

function mostraFinanc() {
alert('Será aberta uma nova janela/guia com o simulador de financiamento da Caixa.');
window.open('http://www8.caixa.gov.br/siopiinternet/simulaOperacaoInternet.do?method=inicializarCasoUso','_financ');
//;
}

function mostraLinks() {
ficha=-6;
document.getElementById('fundo').style.visibility = 'visible';
grow();
}

function mostraCorretores() {
ficha=-7;
document.getElementById('fundo').style.visibility = 'visible';
grow();
}

function mostraContato() {
ficha=-2;
document.getElementById('fundo').style.visibility = 'visible';
grow();
}

function resetFadeIn() {
for (i=1;i<=8;i++) fadeInIE('imov'+i);
}

function fechaDetalhe() {
resetFadeIn();
if (document.getElementById('frente1').style.visibility =='visible') {
	document.getElementById('frente1').style.visibility ='hidden';
	document.getElementById('frente1').innerHTML = '';
	document.getElementById('fundo1').style.visibility ='hidden';
	}
	else
	{
	document.getElementById('frente').style.visibility ='hidden';
	document.getElementById('frente').innerHTML = '';
	document.getElementById('fundo').style.visibility ='hidden';
	document.getElementById('fundo').style.top ='220px';
	document.getElementById('fundo').style.left= '320px';
	document.getElementById('fundo').style.width= '0px';
	document.getElementById('fundo').style.height='0px';
    }
}



function anterior() {
if (salto >0) salto--;
ajaxFunction(document.getElementById('divImoveis'),'resultado.php?salto='+salto+filtroLista+'&ordem='+document.getElementById('ordenacao').value);
}

function posterior() {
salto++;
ajaxFunction(document.getElementById('divImoveis'),'resultado.php?salto='+salto+filtroLista+'&ordem='+document.getElementById('ordenacao').value);
}


function anterior_empreend() {
if (salto >0) salto--;
ajaxFunction(document.getElementById('resultado'),'resultado_empreend.php?salto='+salto+filtroLista);
}
function posterior_empreend() {
salto++;
ajaxFunction(document.getElementById('resultado'),'resultado_empreend.php?salto='+salto+filtroLista);

}


function clareia(elemento) {
	document.getElementById('texto'+elemento).style.background = '#aaaaaa'; //'#FF5600';
	document.getElementById('foto'+elemento).style.background =  '#aaaaaa';//'#FF5600';
}

function escurece(elemento) {
	document.getElementById('texto'+elemento).style.background =  '';
	document.getElementById('foto'+elemento).style.background =  '';
}

function enviarAnuncie() {
alert('tipo='+document.getElementById('tipo').value+
			     '&nome='+document.getElementById('nome').value+
				 '&email='+document.getElementById('email').value+
				 '&fone='+document.getElementById('fone').value+
				 '&municipio='+document.getElementById('municipio').value+
				 '&bairro='+document.getElementById('bairro').value+
				 '&mensagem='+document.getElementById('mensagem').value);

ajaxFunctionMail('tipo='+document.getElementById('tipo').value+
			     '&nome='+document.getElementById('nome').value+
				 '&email='+document.getElementById('email').value+
				 '&fone='+document.getElementById('fone').value+
				 '&municipio='+document.getElementById('municipio').value+
				 '&bairro='+document.getElementById('bairro').value+
				 '&mensagem='+document.getElementById('mensagem').value);
}

function enviarContato() {

alert('tipo='+document.getElementById('tipo_form').value+
			     '&nome='+document.getElementById('contatoNome').value+
				 '&email='+document.getElementById('contatoEmail').value+
				 '&fone='+document.getElementById('contatoTelefone').value+
				 '&assunto='+document.getElementById('contatoAssunto').value+
				 '&texto='+document.getElementById('contatoMemo').value);
ajaxFunctionMail('tipo='+document.getElementById('tipo').value+
			     '&nome='+document.getElementById('contatoNome').value+
				 '&email='+document.getElementById('contatoEmail').value+
				 '&fone='+document.getElementById('contatoTelefone').value+
				 '&assunto='+document.getElementById('contatoAssunto').value+
				 '&texto='+document.getElementById('contatoMemo').value);
}


function enviarMaisInfo() {
alert('tipo='+document.getElementById('tipo').value+
			     '&nome='+document.getElementById('infoNome').value+
				 '&email='+document.getElementById('infoEmail').value+
				 '&fone='+document.getElementById('infoTelefone').value+
				 '&texto='+document.getElementById('infoMemo').value+
				 '&ficha='+document.getElementById('ficha').value);

ajaxFunctionMail('tipo='+document.getElementById('tipo').value+
			     '&nome='+document.getElementById('infoNome').value+
				 '&email='+document.getElementById('infoEmail').value+
				 '&fone='+document.getElementById('infoTelefone').value+
				 '&texto='+document.getElementById('infoMemo').value+
				 '&ficha='+document.getElementById('ficha').value);
}

function enviarIndique() {

alert('tipo='+document.getElementById('tipo_amigo').value+
			     '&nome='+document.getElementById('nome').value+
				 '&email='+document.getElementById('email').value+
				 '&amigo='+document.getElementById('amigo').value+
				 '&amigoEmail='+document.getElementById('amigoEmail').value+
				 '&texto='+document.getElementById('texto').value+
				 '&ficha='+document.getElementById('ficha').value);
	
ajaxFunctionMail('tipo='+document.getElementById('tipo_amigo').value+
			     '&nome='+document.getElementById('nome').value+
				 '&email='+document.getElementById('email').value+
				 '&amigo='+document.getElementById('amigo').value+
				 '&amigoEmail='+document.getElementById('amigoEmail').value+
				 '&texto='+document.getElementById('texto').value+
				 '&ficha='+document.getElementById('ficha').value);
}

function fechaDetalheMaisInformacaoMail() {
	document.getElementById('divmail').style.visibility = 'hidden';
	document.getElementById('divmail').innerHTML = '';
}



function aparece() {
setTimeout("fadeInIE('espec');",2000);
setTimeout('fadeOutIE("espec",0);',4000);
setTimeout('aparece()',6000);
}

function detalheEmpreend(empreend) {
clearTimeout(tEmpr);
ajaxFunction(document.getElementById('corpo'),'detalhe_empreend.php?empreend='+empreend);
ajaxFunction(document.getElementById('imoveis'),'imoveis_empreend.php?empreend='+empreend);
ficha = empreend;
aguardaEmpreend();
//setTimeout("alert('disiparar o ajxaFunction');ajaxFunction(document.getElementById('barraFotosEmpreend'),'barra_fotos_empreend.php?empreend="+empreend+"');",6000);
}

function aguardaEmpreend() {
if (document.getElementById('barraFotosEmpreend') == null) 
  	setTimeout('aguardaEmpreend()',500);
  else
  	ajaxFunction(document.getElementById('barraFotosEmpreend'),'barra_fotos_empreend.php?empreend='+ficha);
	
}


function fotoEmpreend(foto) {
document.getElementById('fotoEmpreend').innerHTML = '<img src="image.php?id='+foto+'" width="640px" height="480"> <div style="position:absolute;top:0px;left:0px;">';
if (browser!='IE7')
	document.getElementById('fotoEmpreend').innerHTML += '<img src="imagens/layoutc/frame_320x240.png" width="660" height="500" />  ';
document.getElementById('fotoEmpreend').innerHTML += '</div> <div class="fechar" onclick="fechaFotoEmpreend();" style="color:#000000;">Fechar [x]</div>';
document.getElementById('fotoEmpreend').style.visibility = 'visible';
}

function fechaFotoEmpreend() {
	document.getElementById('fotoEmpreend').style.visibility = 'hidden';
}

function fechaDetalheEmpreend() {
ajaxFunction(document.getElementById('corpo'),'empreendimentos_c.php');
ajaxFunction(document.getElementById('imoveis'),'imoveis_c.php');
setTimeout('iniciaEmpreend()',1000);
}

function fechaDetalheEmpreend1() {
document.getElementById('fundo1').style.visibility = 'hidden';
document.getElementById('frente1').style.visibility = 'hidden';
document.getElementById('frente1').innerHTML = '';
document.getElementById('fundo1').innerHTML = '';
}



function ordenar(sql,ordem) {
// alert(sql);
ajaxFunction(document.getElementById('divImoveis'),'resultado.php?salto=0&ordem='+ordem+'&'+sql);

}

function zoomDetalheAbre() {
	document.getElementById('detalheFotoZoom').style.display = 'block';
}


function zoomDetalheFecha() {
	document.getElementById('detalheFotoZoom').style.display = 'none';
}

/*function passaFotoZoomDetalhe() {
	var pFotos = new Array();
	var i;
	
	for(i=0; i<pFotos.length; i++){
		alert('pFotos[i]');
	}
}*/

/* BARRA_FOTOS_C.PHP */

function click_imagem(img,txt) {
//if (navigator.appName == 'Microsoft Internet Explorer') 
//window.parent.document.getElementById('imagem').width="120";
//window.parent.document.getElementById('imagem').height="115";
//window.parent.document.getElementById('imagem').src = ('./imagens/aguarde.gif');
window.parent.document.getElementById('imagem').src = ('image.php?id='+img+'&alta=1');
//window.parent.document.getElementById('imagem').width="420";
//window.parent.document.getElementById('imagem').height="315";
window.parent.document.getElementById('legenda').innerHTML = txt;
}

var t;
var l = 0;
         
function roda_dir() {
	
if (l > -largura)
    {
    l = l - 10;
        //alert(largura);
    }
//document.getElementById('seta_dir').className='dir';
document.getElementById('barra').style.left = l+'px';
if (navigator.appName != 'Microsoft Internet Explorer') 
	t = setTimeout('roda_dir()',80);
	else
	t = setTimeout('roda_dir()',10);
	
}

function roda_esq() {
//document.getElementById('seta_esq').className='esq';
if (l < 0 ) {
l = l + 10;
document.getElementById('barra').style.left = l+'px';
if (navigator.appName != 'Microsoft Internet Explorer') 
	t = setTimeout('roda_esq()',80);
	else
	t = setTimeout('roda_esq()',10);
}
}

function pararoda() {
document.getElementById('seta_dir').className='dir_40';
document.getElementById('seta_esq').className='esq_40';
clearTimeout(t);
}



function habilitaBotao(){
	
	//document.getElementById('contato_7').onclick = 'fazbusca(2)';
	
	document.getElementById('contato_7').style.visibility = 'visible';
	
	
}

/* BARRA_FOTOS_C.PHP end*/
