function atualizaDestaques(x,y){
	ir = (x * 9) - 9
	new Ajax.Updater('imvDestaques', 'ajax/ajax_destaques.asp?limit=' + ir)
	for (i=1; i<=y;i++){
		document.getElementById("li" + i).className="";
		document.getElementById("lia" + i).className="";		
	}
	document.getElementById("li" + x).className="current";
	document.getElementById("lia" + x).className="current";
}
function exibeTipo(){
	document.getElementById("tipo_imovel").disabled=false;
	x = document.getElementById("id_cidade").value;
	chamaTipo(x);
	chamaBairro(0,'empty');
	chamaValor(0,0,0);
}
function chama_imoveis(x){
	new Ajax.Updater('imoveis-mongagua-homecenter', 'ajax_imoveis.asp?id_cat=' + x)
}
function chamaTipo(x){
	new Ajax.Updater('ajax_tipo','ajax/tipo_imovel.asp?id_cidade=' + x, {
	evalscripts: true,
  	onComplete: function() {		
	$$('select#tipo_imovel').selectmenu({
		style:'popup', 
		width: 230
	});	
  }})	
}
function chamaBairro(v,x){
	new Ajax.Updater('ajax_bairro','ajax/bairro.asp?id_cidade=' + v + '&id_categoria=' + x, {
	evalscripts: true,
  	onComplete: function() {
	$$('select#id_bairro').selectmenu({
		style:'popup', 
		width: 175
	});
	chamaValor(0,0,0);
  }})	
}
function chamaValor(x,y,z){
	new Ajax.Updater('ajax_valor','ajax/valor.asp?bairro=' + z + '&id_cidade=' + x + '&id_categoria=' + y , {
  	onComplete: function() {
	$$('select#valor_imovel').selectmenu({
		style:'popup', 
		width: 165
	});
  }})	
}
function exibeValor(){
	if (document.getElementById("tipo_imovel").value == "empty"){
		document.getElementById("btnValor").disabled=true
	}
	else{
		document.getElementById("ate").disabled=false
	}
}
function exibeBotao(){
	document.getElementById("ate").disabled=false
}
function validaBusca(){
	if (document.getElementById("id_cidade").value == "0"){
		alert('Selecione uma Cidade');
		return false;
	}	
	if (document.getElementById("tipo_imovel").value == "empty"){
		alert('Selecione o tipo do imóvel!');
		return false;
	}
	else if(document.getElementById("id_bairro").value == '-1'){
		alert('Selecione o Bairro!');
		return false;
	}
	else{
		return true
	}
}
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function limpaCampo(x){
	
	document.getElementById(x).value="";	
}
function valueCampo(x){
	
	tag = document.getElementById(x).value;	
	if (tag == ""){
		document.getElementById(x).value="Referência";
	}
}
function preview(x){
	document.getElementById(x).style.display="block";
	new Ajax.Updater(x,'ajax/preview.asp?id_imovel='+x);	
}

function escreve_flash(nome,width,height){
   document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" style="width: ' + width + 'px; height: ' + height + 'px;">');
   document.write('<param name="movie" value="swf/' + nome + '" />');
   document.write('<param name="quality" value="high" />');
   document.write('<param name="wmode" value="transparent" />');
   document.write('<param name="allowScriptAccess" value="always" />');
   document.write('<embed allowScriptAccess="always" wmode="transparent" src="swf/' + nome + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" style="width: ' + width + 'px; height: ' + height + 'px;" /></embed>');
   document.write('</object>');
}
xyu = 0;
function bal(x,y){
	if (xyu == 0){
		document.getElementById(x).style.display="block";
		new Ajax.Updater(x,'ajax/baloes/'+y,{
		evalScripts: true	
		});
		xyu += 1;
	}
}
function bal1(x){
	xyu -= 1
	document.getElementById(x).style.display="none";
	new Ajax.Updater(x,'ajax/baloes/x.asp');
}
function imoveisEmVista(x){
	new Ajax.Updater('onlycount','ajax/emvista.asp?id_imovel=' + x, {
  	onSuccess: function(response) {
	atualizaContador();	
  }
});
}
function excluirEmVista(x){
	new Ajax.Updater('atualizaEmVista','ajax/atualizaemvista.asp?id_imovel=' + x);
	atualizaContador();
}
function atualizaFavoritos(){
	new Ajax.Updater('atualizaEmVista','ajax/atualizaemvista.asp',{
	evalscripts: true	
	});
}
function atualizaContador(){
	new Ajax.Updater('favoritos','ajax/atualizaContador.asp');	
}
function abrir(URL) {

  var width = 430;
  var height = 378;

  var left = 99;
  var top = 99;

  window.open(URL,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

function limpaCampo(x){
	
	document.getElementById(x).value="";	
}
function valueCampo(x){
	
	tag = document.getElementById(x).value;	
	if (tag == ""){
		document.getElementById(x).value="Referência";
	}
}

function fecharPopUp2() {
	document.getElementById('apDiv1').style.visibility = 'hidden';
}
function addFav(){
			var url  = "http://www.casabrancaconsultoria.com.br";
			var title    = "CasaBranca Consultoria Imobiliária - Mongaguá/SP";
			if (window.sidebar) window.sidebar.addPanel(title, url,"");
			else if(window.opera && window.print){
				var mbm = document.createElement('a');
				mbm.setAttribute('rel','sidebar');
				mbm.setAttribute('href',url);
				mbm.setAttribute('title',title);
				mbm.click();
			}
			else if(document.all){window.external.AddFavorite(url, title);}
}
//Formata número tipo moeda usando o evento onKeyDown
function Limpar(valor, validos) {
// retira caracteres invalidos da string
var result = "";
var aux;
for (var i=0; i < valor.length; i++) {
aux = validos.indexOf(valor.substring(i, i+1));
if (aux>=0) {
result += aux;
}
}
return result;
}

function Formata(campo,tammax,teclapres,decimal) {
var tecla = teclapres.keyCode;
vr = Limpar(campo.value,"0123456789");
tam = vr.length;
dec=decimal

if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

if (tecla == 8 )
{ tam = tam - 1 ; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
{

if ( tam <= dec )
{ campo.value = vr ; }

if ( (tam > dec) && (tam <= 5) ){
campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 6) && (tam <= 8) ){
campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
}
if ( (tam >= 9) && (tam <= 11) ){
campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 12) && (tam <= 14) ){
campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; }
if ( (tam >= 15) && (tam <= 17) ){
campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;}
} 

}

	//var a;
function ocultaMsg(){
	document.getElementById('mensagem').style.display="none";	
}
function fncMcmv(x,sit){
	new Ajax.Updater('mcmv' + x, 'ajax/ajax_mcmv.asp?id_imovel=' + x + '&sit=' + sit,
	{
	evalScripts:true
	})	
}
function fncDestaque(x,sit){
	new Ajax.Updater('destaque' + x, 'ajax/ajax_destaque.asp?id_imovel=' + x + '&sit=' + sit,
	{
	evalScripts:true
	})	
}
function fncLancamento(x,sit){
	new Ajax.Updater('lancamento' + x, 'ajax/ajax_lancamento.asp?id_imovel=' + x + '&sit=' + sit);
}
function fncPermuta(x,sit){
	new Ajax.Updater('permuta' + x, 'ajax/ajax_permuta.asp?id_imovel=' + x + '&sit=' + sit);
}
function fncFinanciado(x,sit){
	new Ajax.Updater('financiado' + x, 'ajax/ajax_financiado.asp?id_imovel=' + x + '&sit=' + sit);
}
function fncApaga(x){
	new Ajax.Request('ajax/ajax_excluir.asp?id_imovel=' + x);
}
function addFav(){
	var url      = "http://www.casabrancaconsultoria.com.br";
    var title    = "CASA BRANCA - Imobiliária em Mongaguá";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}
