
window.onerror = null;
var topMargin = 100;
var slideTime = 1200;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);
function layerObject(id,left) {
if (ns6) {
this.obj = document.getElementById(id).style;
this.obj.left = left;
return this.obj;
}
else if(ie4) {
this.obj = document.all[id].style;
this.obj.left = left;
return this.obj;
}
else if(ns4) {
this.obj = document.layers[id];
this.obj.left = left;
return this.obj;
   }
}
function layerSetup() {
floatLyr = new layerObject('floatLayer', pageWidth * .5);
window.setInterval("main()", 10)
}
function floatObject() {
if (ns4 || ns6) {
findHt = window.innerHeight;
} else if(ie4) {
findHt = document.body.clientHeight;
   }
} 
function main() {
if (ns4) {
this.currentY = document.layers["floatLayer"].top;
this.scrollTop = window.pageYOffset;
mainTrigger();
}
else if(ns6) {
this.currentY = parseInt(document.getElementById('floatLayer').style.top);
this.scrollTop = scrollY;
mainTrigger();
} else if(ie4) {
this.currentY = floatLayer.style.pixelTop;
this.scrollTop = document.body.scrollTop;
mainTrigger();
   }
}
function mainTrigger() {
var newTargetY = this.scrollTop + this.topMargin;
if ( this.currentY != newTargetY ) {
if ( newTargetY != this.targetY ) {
this.targetY = newTargetY;
floatStart();
}
animator();
   }
}
function floatStart() {
var now = new Date();
this.A = this.targetY - this.currentY;
this.B = Math.PI / ( 2 * this.slideTime );
this.C = now.getTime();
if (Math.abs(this.A) > this.findHt) {
this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
this.A = this.A > 0 ? this.findHt : -this.findHt;
}
else {
this.D = this.currentY;
   }
}
function animator() {
var now = new Date();
var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
newY = Math.round(newY);
if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
if ( ns4 )document.layers["floatLayer"].top = newY;
if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
   }
}
function start() {
if(ns6||ns4) {
pageWidth = innerWidth;
pageHeight = innerHeight;
layerSetup();
floatObject();
}
else if(ie4) {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
layerSetup();
floatObject();
   }
   
$("#floatLayer").css('display','block');
}
function fecha_convite (){
   $.cookie('convite', '1', { expires: 1});
	$("#floatLayer").fadeOut();
}
//  End -->

/* FUNÇÃO ABA */
$(window).bind("load", function() {
	$("div#fotos_do_imovel").slideView()
}); 

$(document).ready(function() {


    $(".hotimg").hover(
		  function () {
			$(this).toggleClass("hotimghover");
		  }, 
		  function () {
			$(this).toggleClass("hotimghover");
		  }
    );
	

	$.cookie('convite', $.cookie('convite')==null ? "0" : $.cookie('convite'), { expires: 1 });

	
		$.ajax({
			url: "status-chat.php",
			cache: false,
			success: function(status_chat) {
				if(status_chat=='online') {
					if($.cookie('convite') == "0")
						setTimeout("start();", 5000);
					$('#bigLink').fadeIn();
				//	$.cookie('convite', '1', { expires: 1});
				
				}
				
			}
			   });	
	
	$("#frmbuscacod").submit(function() {
		$.ajax({
			type: "POST",
			url: "includes/checa_codigo.php",
			data: "codrede="+$("#codigo").val(),
			dataType: "html",
			success: function(msg) {
				if(msg=='ok') {
					window.location="/imovel-"+$("#codigo").val()+".html";
					return true;					
				}
				else{
					alert('O imóvel '+$("#codigo").val()+' não foi encontrado, para obter mais detalhes entre em contato conosco.');
					}
			}
		});

		return false;
	});
	

});


function geraCidade(objEstado, nomeDiv) {
	qryStr = "";
	$("#loading").show();
	if(!nomeDiv)  {
		nomeDiv = "comboCidade";
	} else qryStr+="&pesquisa_detalhada=true"; 

	var numQuartos = $("#num_quartos").val();
	if(numQuartos !="") qryStr+="&num_quartos="+numQuartos;

	var tipoImovel = $("#tipo_imovel").val();
	if(tipoImovel !="") qryStr+="&tipo_imovel="+tipoImovel;
	
	var codAluguelVenda = $("#transacao").val();
	if(codAluguelVenda !="") qryStr+="&aluguel_venda="+codAluguelVenda;
	if($(objEstado).val() =="") return 0;
	
	$.ajax({
		type: "POST",
		url: "includes/monta_combos.php",
		data: "nomecombo=cidade&estado="+$(objEstado).val()+qryStr,
		dataType: "html",
		success: function(msg) {
			//alert(msg);
			$("#loading").hide();
			$("#"+nomeDiv).html(msg);
		}
	});
}

$(function() {
	$("#valor_max").maskMoney();
	$("#frmbuscarapida").validate({
		submitHandler: function() {
			ie6 = false;
			jQuery.each(jQuery.browser, function(i, val) {
				if(i == "msie6" && val) ie6 = true;		
		    });

			vlr="";
			$("#tipo_imovel option:selected").each(function() {
			    vlr = this.value;
			});	
			
			if(vlr == "") {
				alert('Você deve preencher o campo "Tipo de imovel" antes de pesquisar.');
				return false;
			}
			
			vlr="";
			$("#estado option:selected").each(function() {
			    if(this.value!=0) {
			        vlr = this.value;
			    }
			});
			
			vlr="";
			$("#cidade option:selected").each(function() {
			    if(this.value!=0) {
			        vlr = this.value;
			    }
			});
			if(vlr == "" && !(ie6 || $("#cidade").val() != "")) {
				alert('Você deve preencher o campo "Cidade" antes de pesquisar.');
				return false;
			}
			
			document.getElementById('frmbuscarapida').submit();
		}
	});
	
		$("#formSac").validate({ //Formulario do Sac
					errorLabelContainer: $("div.container"),
					rules: {
						PHORM_FROM: { 
							required: true,
							email: true
						},
						nome: "required",
						telefone: "required",
						celular: "required",
						PHORM_SUBJECT: "required",
						mensagem: "required"
					}
		});	
	
	$("#frmMinhaLista").validate({
		rules: {
			name: "required",
			PHORM_FROM: {
				required: true,
				email: true
			},
			telefone: "required",
			mensagem: "required"
		},
		messages: {
			name: "Por favor informe seu nome",
			PHORM_FROM: "Por favor informe um e-mail válido",
			telefone: "Por favor informe pelo menos um telefone",
			mensagem: "Por favor digite uma mensagem"
		}
	});
});

jQuery(function($){
   $("#telefone").mask("(99) 9999-9999",{placeholder:" "});
   $("#celular").mask("(99) 9999-9999",{placeholder:" "});
});

function geraBairros(objCidade, nomeDiv) {
	qryStr = "";
	$("#loading").show();
	if(!nomeDiv) nomeDiv = "bairros";
	else qryStr+="&pesquisa_detalhada=true";
	 
	var numQuartos = $("#num_quartos").val();
	if(numQuartos !="") qryStr+="&num_quartos="+numQuartos;

	var tipoImovel = $("#tipo_imovel").val();
	if(tipoImovel !="") qryStr+="&tipo_imovel="+tipoImovel;
	
	var codAluguelVenda = $("#transacao").val();
	if(codAluguelVenda !="") qryStr+="&aluguel_venda="+codAluguelVenda;
	
	if($(objCidade).val()=="") return 0;
		
	$.ajax({
		type: "POST",
		url: "includes/monta_combos.php",
		data: "nomecombo=bairros&estado="+$("#estados").val()+"&cidade="+$(objCidade).val()+qryStr,
		dataType: "html",
		success: function(msg) {
			$("#loading").hide();
			$("."+nomeDiv).html(msg);
		}
	});
}

function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}