


function exibeTipo(){
	document.getElementById("tipo_imovel").disabled=false;
	x = document.getElementById("id_cidade").value;
	chamaTipo(x);
}
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, {
  	onComplete: function() {
  	$$(function(){			
	$$('select#id_cidade').selectmenu({
		style:'popup', 
		width: 140
	});			
	$$('select#tipo_imovel').selectmenu({
		style:'popup', 
		width: 230
	});			
	$$('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("tipo_imovel").value == "empty"){
		alert('Selecione o tipo do imóvel!');
		return false
	}
	else{
		return true
	}
}
function seleciona(){
	$$(function(){					
	$$('select#tipo_imovel').selectmenu({
		style:'popup', 
		width: 230
	});			
});
}
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);
		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);}
}
document.observe('dom:loaded', function() 
{    
	Ajax.Responders.register(
	{    
	    onCreate: function() {
	     	document.getElementById("loader").style.display="block";  
	    },	    
	    onComplete: setInterval(function() {
	      	document.getElementById("loader").style.display="none";  
	    },600)
	});
});
$$(function(){			
	$$('select#id_cidade').selectmenu({
		style:'popup', 
		width: 140
	});			
	$$('select#tipo_imovel').selectmenu({
		style:'popup', 
		width: 230
	});			
	$$('select#valor_imovel').selectmenu({
		style:'popup', 
		width: 165
	});
});
tog=0;
$$(document).ready(function(){
	$$(".btn-slide").click(function(){
		$$("#mcmv").slideToggle(320, function() {
    if (tog == 0){ 
		new Ajax.Updater('mcmv','ajax/mcmv.asp');
		tog = 1;
	}
	else{
		tog = 0;	
	}
  });
		$$(this).toggleClass("active"); return false;
	});	 
});
tog1=0;
$$(document).ready(function(){
	$$(".btn-slide1").click(function(){
		$$("#imoveisFinanciados").slideToggle(320, function() {
    if (tog1 == 0){ 
		new Ajax.Updater('imoveisFinanciados','ajax/financiados.asp',
	{
	evalScripts:true
	});
		tog1 = 1;
	}
	else{
		tog1 = 0;	
	}
  });
		$$(this).toggleClass("active"); return false;
	});	 
});
