/* FUNÇÃO ABA */
function MudaEstilo(pId, pEstilo, pEstiloNAlter){
	var objAba = document.getElementById(pId);
	if (objAba.className!=pEstiloNAlter){
		document.getElementById(pId).className=pEstilo;
	}
}

$(document).ready(function() {
   $("div#fotos_do_imovel").slideView();
	$("#btn_buscacod").hide();
	$("#loading").hide();
	$("#codigo").keyup(function(){
		$("#btn_buscacod").show("slow");
	if($(this).val() =="")
		$("#btn_buscacod").hide();
	});
    $(".hotimg").hover(
		  function () {
			$(this).toggleClass("hotimghover");
		  }, 
		  function () {
			$(this).toggleClass("hotimghover");
		  }
    );
	
	$("#btn_buscacod").click(function() {
		$("#loading").show();
		$.ajax({
			type: "POST",
			url: "includes/checa_codigo.php",
			data: "codrede="+$("#codigo").val(),
			dataType: "html",
			success: function(msg) {
				if(msg=='ok') {
					window.location="/imovel.php?codigo="+$("#codigo").val();
					return false;
				} else {
					alert('O imóvel '+$("#codigo").val()+' não foi encontrado, para obter mais detalhes entre em contato conosco.');
					$("#loading").hide();
				}
			}
		});
		return false;
	});
	

	$("#abas").tabs();
});


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();
}
function janelaSecundaria (URL){ 
   window.open(URL,"janela1","width=600,height=450,scrollbars=NO") 
} 


