// JavaScript Document

	function getPageScroll()
	{
	
		var yScroll;
	
		if (self.pageYOffset) 
		{
			yScroll = self.pageYOffset;
		} 
		else if (document.documentElement && document.documentElement.scrollTop)
		{	// Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} 
		else if (document.body) 
		{	// all other Explorers
			yScroll = document.body.scrollTop;
		}

		var margin_top = '-255'; // aqui vai a metade da altura do div q deseja centralizar na tela verticalmente
		
		var correcao=0;
		
		if("vendas"==pg) 
		{
			correcao=-340;
			//alert(correcao);
		}
		else if ("aluguel"==pg)
		{
			correcao=-280;
			//alert(correcao);	
		}
		else if ("filtro"==pg)
		{
			correcao=-220;
			//alert(correcao);	
		}
		
		document.getElementById('imovel_open').style.marginTop = String(parseInt(margin_top) + parseInt(yScroll) + correcao) + 'px';
	}
	
	function MM_reloadPage(init) {  //reloads the window if Nav4 resized (essa funcao tem a v com o div com scroll)
  	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4))
 	{
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
	}
	MM_reloadPage(true);
	
	//-----------------------------------------------------------------------------
	
	function OpenImovel(codigo_imovel)
	{
		var req = null; 
		
			if (window.XMLHttpRequest){
			
				req = new XMLHttpRequest();
				if (req.overrideMimeType){
					req.overrideMimeType('text/xml');
				}
			} else if (window.ActiveXObject){
			
				try {
					req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e){
				
					try {
						req = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
				}
			}
		
			req.onreadystatechange = function() { 
			
				if(req.readyState == 4)	{
					
					if(req.status == 200) {
						
						//var doc = req.responseText;
						var doc = req.responseXML;
						//window.alert(doc);
						document.getElementById("imovel_open").innerHTML=doc.getElementsByTagName("retorno").item(0).firstChild.data;
						getPageScroll(); // chamando função acima q posiciona o div
						document.getElementById("fundo").style.visibility='visible';
						document.getElementById("imovel_open").style.visibility='visible';
						document.getElementById("banner").style.visibility='hidden';
					}
				} 
			};
			
			var args = "&codigo_imovel="+codigo_imovel+"&";
			
			req.open("POST", "visualiza_imovel_div.php", true);
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			req.send(args);	

	}
	
	
	function fnAmplia(imagem)
	{
		
		
		conteudo="<table width=\"540\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
        conteudo+="<tr height=\"20\">";
        conteudo+="<td colspan=\"2\" background=\"imagens/barra_imoveis.jpg\">&nbsp;</td>";
        conteudo+="<td>";
        conteudo+="<img src=\"imagens/x_fechar.jpg\" title=\"Fechar\" style=\"cursor:pointer;\" onclick=\"javascript: document.getElementById('imagem_imovel').style.visibility='hidden', document.getElementById('overlay_ante_images_imoveis').style.visibility='hidden'\" />";
        conteudo+="</td>";
        conteudo+="</tr>";
        conteudo+="<tr height=\"20\">";
        conteudo+="<td>&nbsp;</td>";
        conteudo+="<td>&nbsp;</td>";
        conteudo+="<td>&nbsp;</td>";
        conteudo+="</tr>";
        conteudo+="<tr height=\"375\">";
        conteudo+="<td width=\"20\">&nbsp;</td>";
        conteudo+="<td width=\"500\" style=\"text-align:center\">";
        conteudo+="<div style='width:500px; height:375px; background: #333 url(imagens/loading.gif) no-repeat center;'><img src=\"resources/imagens/"+imagem+".jpg\" style=\"border:1px solid #666666;\" width='500' height='375' /></div>";
        conteudo+="</td>";
        conteudo+="<td width=\"20\">&nbsp;</td>";
        conteudo+="</tr>";
        conteudo+="<tr height=\"20\">";
        conteudo+="<td>&nbsp;</td>";
        conteudo+="<td>&nbsp;</td>";
        conteudo+="<td>&nbsp;</td>";
        conteudo+="</tr>";
        conteudo+="</table>";
		document.getElementById('imagem_imovel').innerHTML=conteudo;
		document.getElementById('imagem_imovel').style.visibility='visible';
		document.getElementById('overlay_ante_images_imoveis').style.visibility='visible';
		
	}
	
	
	//////////////////////////////////////////////////////////////////
	
	
	function list_dados(valor)
	{
		http.open("GET", "result.php?id=" + valor, true);
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
	}

	function handleHttpResponse()
    {
		campo_select = document.forms[0].subcategoria;
		if (http.readyState == 4) 
		{
	    	campo_select.options.length = 0;
			results = http.responseText.split(",");
			
			for( i = 0; i < results.length; i++ )
			{
				string = results[i].split( "|" );
				campo_select.options[i] = new Option( string[0], string[1] );
      		}
		}
	}


	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();
	
	
	/////////////////////////////////////////////////////////
	
	//////////////////////////////////////////////////////////////////
	
	
	

	


	

	
	
	/////////////////////////////////////////////////////////
	
	
	//////////////////////////////////////////////////////////////////
	
	
	
	
	
	/////////////////////////////////////////////////////////
	
	
	function fnSubmitFiltro()
	{
	
		var form = document.getElementById("form_filtro");
		
		var tipo_negocio = document.getElementById("tipo_negocio");
		var tipo_imovel = document.getElementById("tipo_imovel");
		var codigo_imovel = document.getElementById("codigo_imovel");
		var flag;
		
		if ((codigo_imovel.value!="Informe o código do imóvel") && (codigo_imovel.value!=""))
		{
			flag=1;
			//alert(codigo_imovel.value);
			//alert("condicao1");
			form.submit();
		}
		else 
		{		
			//alert(flag);
			//alert("condicao2");
			if((tipo_negocio.value=="selecione") && (flag!=1))
			{
				//alert(flag);
				window.alert("Selecione o tipo de negócio!");
				tipo_negocio.focus();
			}
			else if((tipo_imovel.value=="selecione") && (flag!=1))
			{
				window.alert("Selecione o tipo de imóvel!");
				tipo_imovel.focus();
			}
			else
			{
				form.submit();	
			}
		}
	}
	
	function fnOnFocusCodigoImovel()
	{
		var codigo_imovel = document.getElementById("codigo_imovel");
		
		codigo_imovel.value = "";
	}
	
	function fnOnBlurCodigoImovel()
	{
		var codigo_imovel = document.getElementById("codigo_imovel");
		
		if(codigo_imovel.value=="")
		{
			codigo_imovel.value = "Informe o código do imóvel";
		}
	}
	
	
	function fnOnFocusValorMaximo()
	{
		var valor_maximo = document.getElementById("valor_maximo");
		
		//alert('teste');
		
		valor_maximo.value = "";
	}
	
	function fnOnBlurValorMaximo()
	{
		var valor_maximo = document.getElementById("valor_maximo");
		
		if(valor_maximo.value=="")
		{
			valor_maximo.value = "Informe o valor máximo";
		}
	}
	
	
	function fnOnFocusValorMinimo()
	{
		var valor_minimo = document.getElementById("valor_minimo");
		
		//alert('teste');
		
		valor_minimo.value = "";
	}
	
	function fnOnBlurValorMinimo()
	{
		var valor_minimo = document.getElementById("valor_minimo");
		
		if(valor_minimo.value=="")
		{
			valor_minimo.value = "Informe o valor mínimo";
		}
	}
