// JavaScript Document
caminho_template = "07";

$(document).ready(function(){
//	$('.thumbSelected').click();
});

var concecValidate = 0;
function tempOnLoad() {
	var tamanhoTela = document.getElementById('totTela').offsetWidth;
	var tamanhoCont = 960;
	var tamanhoEspa = Math.floor((tamanhoTela/2)-(tamanhoCont/2));
	
	if (tamanhoEspa > 0) {
		var posicaoBanners = tamanhoEspa + tamanhoCont + 5;
	}else{
		var posicaoBanners = tamanhoCont + 5;
	}
	
	document.getElementById('frameBanners').style.left = posicaoBanners+"px";
	document.getElementById('boxClimatempo').style.left = posicaoBanners+"px";
	document.getElementById('frameBanners').style.display = "";
	
	document.getElementById('boxFavoritos').style.left = (posicaoBanners-5)+"px";
	if (window.frames['favoritos'].document.getElementById('frameFavoritos')) {
		document.getElementById('favoritos').style.height = window.frames['favoritos'].document.getElementById('frameFavoritos').offsetHeight+"px";
		var yBanners = document.getElementById('boxFavoritos').offsetTop + document.getElementById('boxFavoritos').offsetHeight + 10;
	}else{
		var yBanners = 200;
	}
	
	document.getElementById('frameBanners').style.top = yBanners+"px";
	document.getElementById('boxClimatempo').style.top = (yBanners+document.getElementById('frameBanners').offsetHeight)+"px";
	
	if (tamanhoTela < 965 || concecValidate < 5) { setTimeout("tempOnLoad()",1000);concecValidate++; }
}
function pesquisaSelecionaCombo(sItem,input) {
	if (sItem.className == "pesquisaPaginasComboItemOn") {
		input.checked = false;
		sItem.className = "pesquisaPaginasComboItem";
	}else{
		input.checked = true;
		sItem.className = "pesquisaPaginasComboItemOn";
	}
}

function enviaEscolheBairro(cod,tipo,cliente,caminho,msg) {
	if (tipo == "imo") {
		document.getElementById('recebe_cd_bairro').innerHTML = "<div style='margin:3px'>"+msg+"...</div>";
	}else{
		document.getElementById('recebe_cd_bairro_lanc').innerHTML = "<div style='margin:3px'>"+msg+"...</div>";
	}
	xajax_escolheBairro(cod,tipo,cliente,caminho);
}

function trocaAbaPesquisa(tipo) {
	if (tipo == "I") {
		document.getElementById('pesquisaImoveisEsc').style.display = '';
		document.getElementById('pesquisaLancamentosEsc').style.display = 'none';
		document.getElementById('abaPesquisaImoveis').className = 'abasPesquisaOn';
		document.getElementById('abaPesquisaLanc').className = 'abasPesquisaOff';
		document.getElementById('abaPesquisaImoveis').src = 'templates/'+caminho_template+'/'+idioma+'/img/aba_pesquisa_imoveis_on.png';
		document.getElementById('abaPesquisaLanc').src = 'templates/'+caminho_template+'/'+idioma+'/img/aba_pesquisa_lanc_off.png';
	}else{
		document.getElementById('pesquisaImoveisEsc').style.display = 'none';
		document.getElementById('pesquisaLancamentosEsc').style.display = '';
		document.getElementById('abaPesquisaImoveis').className = 'abasPesquisaOff';
		document.getElementById('abaPesquisaLanc').className = 'abasPesquisaOn';
		document.getElementById('abaPesquisaImoveis').src = 'templates/'+caminho_template+'/'+idioma+'/img/aba_pesquisa_imoveis_off.png';
		document.getElementById('abaPesquisaLanc').src = 'templates/'+caminho_template+'/'+idioma+'/img/aba_pesquisa_lanc_on.png';
	}
	document.getElementById('tipoPesq').value = tipo;
}

function trocaTransacaoPesquisa(valor,caminho) {
	document.getElementById('pesquisaTransacoesTexto1').className = "pesquisaTransacoesTexto";
	document.getElementById('pesquisaTransacoesTexto2').className = "pesquisaTransacoesTexto";
	document.getElementById('pesquisaTransacoesTexto3').className = "pesquisaTransacoesTexto";
	document.getElementById('pesquisaTransacoesTexto'+valor).className = "pesquisaTransacoesTextoOn";
	document.getElementById('selectFaixaPreco').style.visibility='hidden';
	xajax_faixaPreco(valor,caminho);
}

function verifica_pesquisa() {
	var tipo = document.getElementById('tipoPesq').value;
	if (tipo == "I") {
		var texto = document.getElementById('cd_referencia').value;
		if (texto != "") {
			document.getElementById('tipoPesqI').value = "ref";
			document.fpesc.submit();
		}else{
			document.getElementById('tipoPesqI').value = "";
			document.fpesc.submit();
		}
	}else{
		document.fpesc.submit();
	}
}

function enviaSolicite() {
	document.getElementById('detalhesSoliciteDados').style.visibility = "hidden";
	var objForm = document.getElementById('formSolicite');
	var formElements = objForm.elements;
	var concatValues = "";
	
	document.documentElement.scrollTop = 0;
	document.body.scrollTop = 0;
	
	for( var i=0; i < formElements.length; i++)
	{
		var name = formElements[i].name;
		if (name)
		{
			if(formElements[i].type=='select-multiple')
			{
				for (var j = 0; j < formElements[i].length; j++)
				{
					if (formElements[i].options[j].selected == true)
						concatValues += name+"="+encodeURI(formElements[i].options[j].value)+"###";
				}
			}
			else
			{
				if (formElements[i].type=='radio')
				{
					if (formElements[i].checked == true)
						concatValues += name+"="+encodeURI(formElements[i].value)+"###";
				}
				else
				{
					concatValues += name+"="+encodeURI(formElements[i].value)+"###";
				}
			}
		} 
	}
	
	xajax_enviaSoliciteInformacoes(concatValues);
	
}

function enviaEnviarAmigo() {
	document.getElementById('detalhesEnviarAmigoDados').style.visibility = "hidden";
	document.getElementById('detalhesEnviarAmigoDadosEnviando').style.display = "";
	var objForm = document.getElementById('formEnviarAmigo');
	var formElements = objForm.elements;
	var concatValues = "";
	
	document.documentElement.scrollTop = 0;
	document.body.scrollTop = 0;
	
	for( var i=0; i < formElements.length; i++)
	{
		var name = formElements[i].name;
		if (name)
		{
			if(formElements[i].type=='select-multiple')
			{
				for (var j = 0; j < formElements[i].length; j++)
				{
					if (formElements[i].options[j].selected == true)
						concatValues += name+"="+encodeURI(formElements[i].options[j].value)+"###";
				}
			}
			else
			{
				if (formElements[i].type=='radio')
				{
					if (formElements[i].checked == true)
						concatValues += name+"="+encodeURI(formElements[i].value)+"###";
				}
				else
				{
					concatValues += name+"="+encodeURI(formElements[i].value)+"###";
				}
			}
		} 
	}
	
	xajax_enviaEnviarParaAmigo(concatValues);
	
}

function enviaFinanciamento() {
	document.getElementById('financiamentoFormFrame').style.display = "none";
	document.getElementById('financiamentoRetorno').style.display = "";
	var objForm = document.getElementById('formFinanciamento');
	var formElements = objForm.elements;
	var concatValues = "";
	
	document.documentElement.scrollTop = 0;
	document.body.scrollTop = 0;
	
	for( var i=0; i < formElements.length; i++)
	{
		var name = formElements[i].name;
		if (name)
		{
			if(formElements[i].type=='select-multiple')
			{
				for (var j = 0; j < formElements[i].length; j++)
				{
					if (formElements[i].options[j].selected == true)
						concatValues += name+"="+encodeURI(formElements[i].options[j].value)+"###";
				}
			}
			else
			{
				if (formElements[i].type=='radio')
				{
					if (formElements[i].checked == true)
						concatValues += name+"="+encodeURI(formElements[i].value)+"###";
				}
				else
				{
					concatValues += name+"="+encodeURI(formElements[i].value)+"###";
				}
			}
		} 
	}
	
	xajax_enviaFinanciamento(concatValues);
	
}

function some(elem) {
	document.getElementById(elem).style.display = "none";
}

function returnElementPosition(elem) {
	var left = elem.offsetLeft;
	var handlerLeft = elem.offsetParent;
	while (handlerLeft) {
		left += handlerLeft.offsetLeft;
		handlerLeft = handlerLeft.offsetParent;
	}
	
	var top = elem.offsetTop;
	var handlerTop = elem.offsetParent;
	while (handlerTop) {
		top += handlerTop.offsetTop;
		handlerTop = handlerTop.offsetParent;
	}
	
	var retorno = new Array();
	retorno[0] = left;
	retorno[1] = top;
	
	return retorno;
}

function abreComboSecoes() {
	mouseOutComboSecoes = 1;
	var botao = document.getElementById('topoItemMaisPaginas');
	var combo = document.getElementById('topoComboMaisPaginas');
	var cabec = document.getElementById('frameCabecalho');

	var left = returnElementPosition(botao);
	var top = returnElementPosition(cabec);

	botao.className = "topoItemPlus";
	combo.style.display = "block";
	combo.style.left = left[0]+"px";
	combo.style.top = top[1]+"px";
}

var mouseOutComboSecoes = 0;
function fechaComboSecoes() {
	if (mouseOutComboSecoes == 0) {
		document.getElementById('topoComboMaisPaginas').style.display = "none";
		document.getElementById('topoItemMaisPaginas').className = "topoItem";
	}
}

function verificaMouseOut() {
	mouseOutComboSecoes = 0;
	setTimeout("fechaComboSecoes()",1000);
}

function topoComboMouseOver(obj) {
	mouseOutComboSecoes = 1;
	obj.className = "topoComboItemOn";
}

function topoComboMouseOut(obj) {
	obj.className = "topoComboItemOff";
}

function abreComboIdioma() {
	mouseOutComboIdioma = 1;
	var botao = document.getElementById('abaIdioma');
	var combo = document.getElementById('idiomaAbaCombo');
	var cabec = document.getElementById('frameCabecalho');

	var left = returnElementPosition(botao);
	var top = returnElementPosition(cabec);

	combo.style.display = "block";
	combo.style.left = left[0]+"px";
	combo.style.top = top[1]+"px";
}

var mouseOutComboIdioma = 0;
function fechaComboIdioma() {
	if (mouseOutComboIdioma == 0) {
		document.getElementById('idiomaAbaCombo').style.display = "none";
	}
}

function verificaMouseOutIdioma() {
	mouseOutComboIdioma = 0;
	setTimeout("fechaComboIdioma()",1000);
}

function topoComboMouseOver(obj) {
	mouseOutComboSecoes = 1;
	obj.className = "topoComboItemOn";
}

function topoComboMouseOut(obj) {
	obj.className = "topoComboItemOff";
}

function change_detalhe(v,param) {
	var elemAtual = document.getElementById(v);
	var abas = new Array();
	abas[0] = "detalhesAbaGeral";
	abas[1] = "detalhesAbaFotos";
	abas[2] = "detalhesAbaVideo";
	abas[3] = "detalhesAbaLocalizacao";
	
	if (elemAtual.className == 'detalhesAbasOn' && v != "detalhesAbaGeral") {
		return true;
	}else{
		for(i=0;i<abas.length;i++) {
			document.getElementById(abas[i]).className = 'detalhesAbasOff';
		}
		
		elemAtual.className = 'detalhesAbasOn';
		
		jah(param,'detalhesRecebe');
	}
}

function change_detalhe_lanc(param) {

	var arrAbas = new Array();
	arrAbas[0] = "emp";
	arrAbas[1] = "uni";
	arrAbas[2] = "img";
	arrAbas[3] = "vid";
	arrAbas[4] = "map";
	
	for (i=0; i<arrAbas.length; i++) {
		document.getElementById("lancdetalhe_"+arrAbas[i]).className = 'detalhesAbasOff';
		document.getElementById("lancdetalhecont_"+arrAbas[i]).style.display = 'none';
	}
	
	if (param == 'emp') {
		$('div[aba_emp=1]').show();
	}else{
		$('div[aba_emp=1]').hide();
	}
	
	document.getElementById("lancdetalhe_"+param).className = 'detalhesAbasOn';
	document.getElementById("lancdetalhecont_"+param).style.display = '';
}

function destalhesLanc(valor,id) {
	if (valor != 0 && valor != "0") {
		window.location = "engine.php?id="+id+"&page=lancamento_detalhe&cd_lancamento="+valor;
	}
}

function rolaCalendarioDireita() {
	if (document.getElementById('calendarioInner').scrollLeft == 0) {
		var inicioTween = 0;
		var finalTween = 350;
		var tweenScroll = new Tween(document.getElementById('calendarioInner'),'scrollLeft',Tween.regularEaseOut,inicioTween,finalTween,0.5,'');
		tweenScroll.start();
	}
}

function rolaCalendarioEsquerda() {
	if (document.getElementById('calendarioInner').scrollLeft == 350) {
		var inicioTween = document.getElementById('calendarioInner').scrollLeft;
		var finalTween = 0;
		var tweenScroll = new Tween(document.getElementById('calendarioInner'),'scrollLeft',Tween.regularEaseOut,inicioTween,finalTween,0.5,'');
		tweenScroll.start();
	}
}

var intSlideFotos;
function slideFotos() {
	if (document.getElementById('detalhesFotosSlideBotao').style.backgroundPosition == "0px 0px") {
		slideFotosStop();
	}else{
		slideFotosStart();
	}
}

function slideFotosStart() {
	document.getElementById('detalhesFotosSlideBotao').style.backgroundPosition = "0px 0px";
	document.getElementById('detalhesFotosSlideProgress').style.display = "";
	document.getElementById('detalhesFotosSlideProgressBar').style.display = "";
	document.getElementById('detalhesFotosSlideProgressBar').style.height = "41px";
	intSlideFotos = setInterval("slideFotosProgress()",250);
}

function slideFotosStop() {
	clearInterval(intSlideFotos);
	document.getElementById('detalhesFotosSlideBotao').style.backgroundPosition = "0px -23px";
	document.getElementById('detalhesFotosSlideProgress').style.display = "none";
	document.getElementById('detalhesFotosSlideProgressBar').style.height = "41px";
}

function slideFotosInterval() {
	var count = foto_atual + 1;
	
	if (foto_detalhe.length > count) {
		var alturaThumb = 66;
		var posThumb = (count*alturaThumb)-(2*alturaThumb);
		document.getElementById('detalhesFotosThumbsFrame').scrollTop = posThumb;
		troca_foto_detalhes(count);
	}else{
		document.getElementById('detalhesFotosThumbsFrame').scrollTop = 0;
		troca_foto_detalhes(0);
	}
	
	document.getElementById('detalhesFotosSlideProgress').style.display = "";
	document.getElementById('detalhesFotosSlideProgressBar').style.display = "";
	document.getElementById('detalhesFotosSlideProgressBar').style.height = "41px";
	intSlideFotos = setInterval("slideFotosProgress()",200);
}

function slideFotosProgress() {
	var elem = document.getElementById('detalhesFotosSlideProgressBar');
	var atual = elem.offsetHeight;

	if (atual == 2) {
		elem.style.display = "none";
		clearInterval(intSlideFotos);
		slideFotosInterval();
	}else{
		var valor = atual-1;
		elem.style.height = valor+"px";
	}
}

function secaoMenuMouseOver(obj) {
	obj.style.backgroundPosition = "0px -30px";
}

function secaoMenuMouseOut(obj) {
	obj.style.backgroundPosition = "0px 0px";
}

function verTabelaUnid(unid,lanc,id) {
	document.getElementById('cortinaPopup').style.display = "";
	document.getElementById('popup').style.display = "";
	verificaPopup();
	jah('detlanc_uni_tab.php?lanc='+unid+'&unid='+unid+'&id='+id,'popup');
}

function deleteFavorito(cod,tipo,id) {
	var formContato = new Array();
	formContato[0] = "nome";
	formContato[1] = "email";
	formContato[2] = "ddd";
	formContato[3] = "telefone";
	formContato[4] = "mensagem";
	formContato[5] = "tipo_recebe_indiferente";
	formContato[6] = "tipo_recebe_email";
	formContato[7] = "tipo_recebe_telefone";
	
	var locacao = "del_favoritos.php?"; 
	
	if (tipo == "Empreendimento") {
		locacao += "cd_lancamento=";
	}else{
		locacao += "cd_imovel=";
	}
	
	locacao += cod;
	locacao += "&id="+id+"&page=contato&info=1";
	
	for (i=0;i<formContato.length;i++) {
		if (document.getElementById(formContato[i])) {
			if (document.getElementById(formContato[i]).type == "text") {
				locacao += "&"+formContato[i]+"="+encodeURIComponent(document.getElementById(formContato[i]).value);
			}
			if ((document.getElementById(formContato[i]).type == "checkbox" || document.getElementById(formContato[i]).type == "radio") && document.getElementById(formContato[i]).checked == true) {
				locacao += "&"+formContato[i]+"=checked";
			}
			if (formContato[i] == "mensagem") {
				locacao += "&"+formContato[i]+"="+encodeURIComponent(document.getElementById(formContato[i]).innerHTML);
			}
		}
	}
	
	window.location=locacao;
}

function validate_encomende() {
	var formEncomende = new Array();
	formEncomende[0] = "nome";
	formEncomende[1] = "email";
	formEncomende[2] = "ddd";
	formEncomende[3] = "telefone";
	formEncomende[4] = "mensagem";
	formEncomende[5] = "valor";
	
	var objForm = document.getElementById('formEncomende');
	var formElements = objForm.elements;
	
	var validaCheckbox = new Array();
	validaCheckbox['cd_negocio'] = false;
	validaCheckbox['cd_tipo'] = false;
	validaCheckbox['cd_bairro'] = false;
	
	for( var i=0; i < formElements.length; i++)
	{
		var name = formElements[i].name;
		var nameHandler = name.substring(0,name.length-2);
		if (name)
		{
			if (formElements[i].type == 'checkbox')
			{
				if (formElements[i].checked == true)
				{
					validaCheckbox[nameHandler] = true;
				}
			}
			if (formElements[i].type == 'text' || formElements[i].type == 'textarea')
			{
				if (formElements[i].name == "captcha")
				{
					var valoresPossiveis = "bcdfghjklmnpqrstvwxyz";
					var captcha = formElements[i].value;
					if ((captcha.length != 4)||(valoresPossiveis.indexOf(captcha.charAt(0))==-1)||(valoresPossiveis.indexOf(captcha.charAt(1))==-1)||(valoresPossiveis.indexOf(captcha.charAt(2))==-1)||(valoresPossiveis.indexOf(captcha.charAt(3))==-1))
					{
						alert('Digite as quatro consoantes da imagem no campo de validação!');
						formElements[i].focus();
						return false;
					}
				}
				else
				{
					if (formElements[i].value == "")
					{
						alert('Preencha corretamente os campos obrigatórios!');
						formElements[i].focus();
						return false;
					}
				}
			}
		}
	}
	
	if ( validaCheckbox['cd_negocio'] != true ) {
		alert('É necessário escolher pelo menos uma das opções de negociação');
		return false;
	}
	
	if ( validaCheckbox['cd_tipo'] != true ) {
		alert('É necessário escolher pelo menos uma das opções de tipos de imóvel');
		return false;
	}
	
	objForm.submit();
}

function validate_cadastre() {
	var formCadastre = new Array();
	formCadastre[0] = "cd_tipo_padrao";
	formCadastre[1] = "estado_imovel";
	formCadastre[2] = "cidade_imovel";
	formCadastre[3] = "bairro_imovel";
	formCadastre[4] = "nome";
	formCadastre[5] = "ddd";
	formCadastre[6] = "telefone";
	formCadastre[7] = "real_email";
	
	
	var objForm = document.getElementById('formCadastre');
	var formElements = objForm.elements;
	
	var validaCheckbox = new Array();
	validaCheckbox['cd_negocio'] = false;
	
	for( var i=0; i < formElements.length; i++)
	{
		var name = formElements[i].name;
		var nameHandler = name.substring(0,name.length-2);
		if (name)
		{
			if (formElements[i].type == 'checkbox')
			{
				if (formElements[i].checked == true)
				{
					validaCheckbox[nameHandler] = true;
				}
			}
			else
			{
				if (formElements[i].name == "captcha")
				{
					var valoresPossiveis = "bcdfghjklmnpqrstvwxyz";
					var captcha = formElements[i].value;
					if ((captcha.length != 4)||(valoresPossiveis.indexOf(captcha.charAt(0))==-1)||(valoresPossiveis.indexOf(captcha.charAt(1))==-1)||(valoresPossiveis.indexOf(captcha.charAt(2))==-1)||(valoresPossiveis.indexOf(captcha.charAt(3))==-1))
					{
						alert('Digite as quatro consoantes da imagem no campo de validação!');
						formElements[i].focus();
						return false;
					}
				}
				else
				{
					if (formElements[i].value == "" && formCadastre.in_array(name))
					{
						alert('Preencha corretamente os campos obrigatórios!');
						formElements[i].focus();
						return false;
					}
				}
			}
		}
	}
	
	if ( validaCheckbox['cd_negocio'] != true ) {
		alert('É necessário escolher pelo menos uma das opções de negociação');
		return false;
	}
	
	objForm.submit();
}

function selectBairroEncomende(cd_bairro,status) {
	var obj = document.getElementById("encomendeBairroItem"+cd_bairro);
	
	if (obj.className == "encomendeBairroItem") {
		obj.className = "encomendeBairroItemSelected";
	}else{
		obj.className = "encomendeBairroItem";
	}
}

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

function mostraFavoritos() {
	window.parent.document.getElementById('boxFavoritos').style.display = "";
}

function mostraIndicadores() {
	document.getElementById('boxIndicadores').style.display = "";
}

function mostraClima() {
	document.getElementById('boxClimatempo').style.display = "";
}