var NumAbas = 2;
var Figuras = new Array(NumAbas);

Figuras[0] = new Array(2);
Figuras[1] = new Array(2);

var Ativo = 1;
var Inativo = 0;

Figuras[0][0] = "templates/site/A0016/imagens/aba_buscacod_i.gif";
Figuras[0][1] = "templates/site/A0016/imagens/aba_buscacod_a.gif";
Figuras[1][0] = "templates/site/A0016/imagens/aba_acessorestrito_i.gif";
Figuras[1][1] = "templates/site/A0016/imagens/aba_acessorestrito_a.gif";

	
function TrocaAba(idAba){
	DesabilitaTudo();
	//alert(NomeObj);
	document.getElementById("AbaImg" + idAba).src=Figuras[idAba-1][Ativo];
	MudaEstilo("textaba" + idAba, "divcx1sel","");
}
function DesabilitaTudo() {
	for (var i=1; i<=NumAbas; i++){
		//alert("Aba" + i);
		document.getElementById("AbaImg" + i).src=Figuras[i-1][Inativo];
		MudaEstilo("textaba" + i, "divcx1unsel","");
	}
}
function MudaEstilo(pId, pEstilo, pEstiloNAlter){
	var objAba = document.getElementById(pId);
	if (objAba.className!=pEstiloNAlter){
		document.getElementById(pId).className=pEstilo;
	}
}

function selecionaTodas() {
	if($("#bairros input").attr('checked')==true) { $("#bairros input").attr('checked', false); } else { $("#bairros input").attr('checked', true); }
}

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() {
	$("#telefone").mask("(99) 9999-9999",{placeholder:" "});
	$("#celular").mask("(99) 9999-9999",{placeholder:" "});
	$("#valor_max").maskMoney();
	$("#formBusca").validate({
		submitHandler: function() {
			vlr="";
			$("#tipo_imovel option:selected").each(function() {
			    vlr = this.value;
			});	
			
			if(vlr == "" || vlr == 0) {
				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 == "") {
				alert('Você deve preencher o campo "Cidade" antes de pesquisar.');
				return false;
			}
			
			document.getElementById('formBusca').submit();
		}
	});
	
	$("#frmMinhaLista").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			telefone: "required",
			mensagem: "required"
		},
		messages: {
			name: "Por favor informe seu nome",
			email: "Por favor informe um e-mail válido",
			telefone: "Por favor informe pelo menos um telefone",
			mensagem: "Por favor digite uma mensagem"
		}
	});
});	
function geraCidade(objEstado, nomeDiv) {
	qryStr = "";
	
	if(!nomeDiv)  {
		nomeDiv = "comboCidade";
	} else qryStr+="&pesquisa_detalhada=true"; 


	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) {
			$("#"+nomeDiv).html(msg);
			if($("#cidade").val()=="")
				$(".bairros").html("<label>Selecione uma cidade.</label>");
			else
				$(".bairros").html("<label>Não há bairros a serem exibidos, verifique suas restrições</label>");
		}
	});
}

$(window).bind("load", function() {
	$("div#fotos_do_imovel").slideView()
}); 

function geraBairros(objCidade, nomeDiv) {
	qryStr = "";
	
	if(!nomeDiv) nomeDiv = "bairros";
	else qryStr+="&pesquisa_detalhada=true";
	
	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) {
			$("."+nomeDiv).html(msg);
		}
	});
}

function LoadGallery(pictureName,imageFile)
{
  if (document.all)
  {	
    document.getElementById(pictureName).style.filter="blendTrans(duration=1)";
    document.getElementById(pictureName).filters.blendTrans.Apply();
  }
  document.getElementById(pictureName).src = imageFile;
  if (document.all)
  {
    document.getElementById(pictureName).filters.blendTrans.Play();
  }
}

function popitup(url)
{
	newwindow=window.open("about:blank",'name','height=480,width=700,titlebar=no,scroll=yes');
	if (window.focus) {newwindow.focus()}
	newwindow.document.write("<img src='"+url+"' />");
	

}