// JavaScript Document
caminho_template = "08";

// INCLUDES

$(document).ready(function(){
	//$('<script language="javascript" type="text/javascript" src="templates/'+caminho_template+'/js/mask.js"></script>').appendTo('head');
	$('<script language="javascript" type="text/javascript" src="templates/'+caminho_template+'/js/lightbox.js"></script>').appendTo('head');
	$('<script language="javascript" type="text/javascript" src="templates/'+caminho_template+'/js/script.js"></script>').appendTo('head');
	$('<script language="javascript" type="text/javascript" src="templates/'+caminho_template+'/js/jquery.colorbox.js"></script>').appendTo('head');
	
	$("a[rel='example1']").colorbox();
	$("a.openTable").colorbox();
	
	$(function() {
		$('.galeria-de-imagens a').lightBox();
		
		/*$("#celular").mask("(999) 9999-9999");
		$("#telefone").mask("(999) 9999-9999")*/;
	});
	
	$(".envia-amigo").click(function(){
		$(".detalhes-checkout").hide();
		$(".envia-amigo-checkin").show();
		$(".solicite-checkin").hide();
	});
	
	$(".envia-amigo-fechar").click(function(){
		$(".detalhes-checkout").show();
		$(".envia-amigo-checkin").hide();
	});
	
	$(".solicite-info").click(function(){
		$(".detalhes-checkout").hide();
		$(".solicite-checkin").show();
		$(".envia-amigo-checkin").hide();
	});
	
	$(".recebe-info-fechar").click(function(){
		$(".detalhes-checkout").show();
		$(".solicite-checkin").hide();
	});
	
	
	if($("#social_network").html() == ""){
		$("#table_social").hide();
	}
});
/*
 *
 * Copyright (c) 2007 Tulio Faria (http://www.tuliofaria.net - http://www.iwtech.com.br)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Version 1.0
 * Demo: http://www.tuliofaria.net/jquery-floatnumber/
 *
 * $LastChangedDate$
 * $Rev$
 */
(function($) {
		
	//Main Method
	$.fn.floatnumber = function(separator,precision) {	
		
		return this.each(function(){		
			var input=$(this);
			var valid=false;   
						
			function blur(){
        var re = new RegExp(",", "g");
        s = input.val();
        s = s.replace(re, ".");

        if (s=="")
            s = "0";

        if (!isNaN(s)){
          n = parseFloat(s);

          s = n.toFixed(precision);

          re2 = new RegExp("\\.", "g");
          s = s.replace(re2, separator);

          input.val(s);

        }

      }
			input.bind("blur", blur);
		});
		
		
	};
})(jQuery);

var attribCorOnline;
var srcImageCorOnline;

$(document).ready(function(){
	
	$(".envia-amigo").click(function(){
		$(".detalhes-checkout").hide();
		$(".envia-amigo-checkin").show();
		$(".solicite-checkin").hide();
	});
	
	$(".envia-amigo-fechar").click(function(){
		$(".detalhes-checkout").show();
		$(".envia-amigo-checkin").hide();
	});
	
	$(".solicite-info").click(function(){
		$(".detalhes-checkout").hide();
		$(".solicite-checkin").show();
		$(".envia-amigo-checkin").hide();
	});
	
	$(".envia-amigo-fechar").click(function(){
		$(".detalhes-checkout").show();
		$(".solicite-checkin").hide();
	});
	
	
	$('span[identifier=fb]:first').remove();
	if ($('.banners').height() < 10) $('.banners').remove();
	
	$('div[thumb_lanc=1]').click(function(){
		var f = $(this).attr('src').replace('t_','');
		mostraFotoLancamento(f);
	}).mouseover(function(){
		$(this).addClass('corBordaSite1');
	}).mouseout(function(){
		$(this).removeClass('corBordaSite1');
	}).css('cursor','pointer');
	
	$('body').append('<script id="scriptTagCorretorOnline" src="' + attribCorOnline + '"></script>');
	
	setTimeout('intChat()',1000);
});

function intChat() {
	if (srcImageCorOnline) {
		var imgTag = retorna_banner();
		$('#divRecebeScriptCorOnline').prepend('<div attrib="imobex">' + imgTag + '</div>');
	}else{
		setTimeout('intChat()',1000);
	}
}

function tempOnLoad() {
	if (document.getElementById('frameBannersChilds') && document.getElementById('frameBanners')) {
		if (document.getElementById('frameBannersChilds').innerHTML.length > 1) {
			document.getElementById('frameBanners').style.display = "";
		}
	}
}



function pesquisaSelecionaCombo(sItem,input) {
	if (sItem.className == "pesquisaPaginasComboItem") {
		input.checked = true;
		sItem.className = "pesquisaPaginasComboItemOn corSite1 corFonte2";
	}else{
		input.checked = false;
		sItem.className = "pesquisaPaginasComboItem";
	}
}

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_imoveis_on.png';
		document.getElementById('abaPesquisaLanc').src = 'templates/'+caminho_template+'/'+idioma+'/img/aba_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_imoveis_off.png';
		document.getElementById('abaPesquisaLanc').src = 'templates/'+caminho_template+'/'+idioma+'/img/aba_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 concatFormValues(objForm) {
	var formElements = objForm.elements;
	var concatValues = "";
	
	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)+"###";
				}
			}
		} 
	}
	
	return concatValues;
}

function clearForm(objForm,objCaptcha) {
	var formElements = objForm.elements;
	
	for( var i=0; i < formElements.length; i++)
	{
		switch (formElements[i].type)
		{
			case 'hidden': break;
			case 'select-multiple':
				for (var j=0; j<formElements[i].length; j++) formElements[i].options[j].selected = false;
				formElements[i].options[0].selected = true;
				break;
			case 'radio':
			case 'checkbox':
				formElements[i].checked = false;
				break;
			default:
				formElements[i].value = '';
				break;
		}
	}
	
	if (objCaptcha) {
		objCaptcha.src = '';
		objCaptcha.src = 'captcha.php?cachebuster=' + Math.floor(Math.random()*100000);
	}
}

function enviaSolicite() {
//	document.getElementById('detalhesSoliciteTopo').style.display = "none";
	document.getElementById('detalhesSoliciteInfo').style.display = "none";
	document.getElementById('detalhesSoliciteDados').style.display = "none";
//	document.getElementById('detalhesSoliciteMsgErr1').style.display = "none";
	document.getElementById('detalhesSoliciteMsgErr2').style.display = "none";
	document.getElementById('detalhesSoliciteMsgOk').style.display = "none";
	document.getElementById('detalhesSoliciteDadosEnviando').style.display = "";

	var objForm = document.getElementById('formSolicite');
	var concatValues = concatFormValues(objForm);
	
	document.documentElement.scrollTop = 0;
	document.body.scrollTop = 0;

	xajax_enviaSoliciteInformacoes(concatValues);

}

function detalhesSoliciteAjaxReturn(resp,tipo) {
	if (resp == 'tipo_err') {
		document.getElementById('detalhesSoliciteTopo').style.display = "";
		document.getElementById('detalhesSoliciteInfo').style.display = "";
		document.getElementById('detalhesSoliciteDados').style.display = "";
	}else{
		switch (resp)
		{
			case 'captcha_err':
			case 'captcha_nok':
				//document.getElementById('captchaSourceSolicite').src = '';
				document.getElementById('captchaSourceSolicite').src = 'captcha.php?cachebuster=' + Math.floor(Math.random()*100000);
				document.getElementById('captchaSolicite').value = '';
				document.getElementById('captchaSolicite').src = '';
				document.getElementById('detalhesSoliciteTopo').style.display = "";
				document.getElementById('detalhesSoliciteInfo').style.display = "";
				document.getElementById('detalhesSoliciteDados').style.display = "";
				document.getElementById('detalhesSoliciteMsgErr1').style.display = "";
				document.getElementById('detalhesSoliciteMsgErr2').style.display = "none";
				break;
			case 'info_err':
			case 'email_err':
				//document.getElementById('captchaSourceSolicite').src = '';
				document.getElementById('captchaSourceSolicite').src = 'captcha.php?cachebuster=' + Math.floor(Math.random()*100000);
				document.getElementById('captchaSolicite').value = '';
				document.getElementById('captchaSolicite').src = '';
				document.getElementById('detalhesSoliciteTopo').style.display = "";
				document.getElementById('detalhesSoliciteInfo').style.display = "";
				document.getElementById('detalhesSoliciteDados').style.display = "";
				document.getElementById('detalhesSoliciteMsgErr1').style.display = "none";
				document.getElementById('detalhesSoliciteMsgErr2').style.display = "";
				//document.getElementById('detalhesSoliciteDadosEnviando').style.display = "none";
				break;
			case 'ok':
				clearForm(document.getElementById('formSolicite'),document.getElementById('captchaSourceSolicite'));
				document.getElementById('detalhesSoliciteTopo').style.display = "none";
				document.getElementById('detalhesSoliciteInfo').style.display = "none";
				document.getElementById('detalhesSoliciteDados').style.display = "none";
				document.getElementById('detalhesSoliciteMsgErr1').style.display = "none";
				document.getElementById('detalhesSoliciteMsgErr2').style.display = "none";
				document.getElementById('detalhesSoliciteMsgOk').style.display = "";
				break;
		}
		document.getElementById('detalhesSoliciteDadosEnviando').style.display = "none";
	}
}

function enviaEnviarAmigo() {
//	document.getElementById('detalhesEnviarAmigoTopo').style.display = "none";
	document.getElementById('detalhesEnviarAmigoInfo').style.display = "none";
	document.getElementById('detalhesEnviarAmigoDados').style.display = "none";
	document.getElementById('detalhesEnviarAmigoMsgErr1').style.display = "none";
	document.getElementById('detalhesEnviarAmigoMsgErr2').style.display = "none";
	document.getElementById('detalhesEnviarAmigoMsgOk').style.display = "none";
	document.getElementById('detalhesEnviarAmigoDadosEnviando').style.display = "";

	var objForm = document.getElementById('formEnviarAmigo');
	var concatValues = concatFormValues(objForm);
	document.documentElement.scrollTop = 0;
	document.body.scrollTop = 0;
	xajax_enviaEnviarParaAmigo(concatValues);
}

function detalhesEnvieAjaxReturn(resp,tipo) {
	if (resp == 'tipo_err') {
//		document.getElementById('detalhesEnviarAmigoTopo').style.display = "";
		document.getElementById('detalhesEnviarAmigoInformacoes').style.display = "";
		document.getElementById('detalhesEnviarAmigoDados').style.display = "";
	}else{
		switch (resp)
		{
			case 'captcha_err':
			case 'captcha_nok':
				//document.getElementById('captchaSourceEnviarAmigo').src = '';
				document.getElementById('captchaSourceEnviarAmigo').src = 'captcha.php?cachebuster=' + Math.floor(Math.random()*100000);
				document.getElementById('captchaEnviarAmigo').value = '';
				document.getElementById('captchaEnviarAmigo').src = '';
//				document.getElementById('detalhesEnviarAmigoTopo').style.display = "";
				document.getElementById('detalhesEnviarAmigoMsgErr1').style.display = "";
				document.getElementById('detalhesEnviarAmigoMsgErr2').style.display = "none";
				document.getElementById('detalhesEnviarAmigoInfo').style.display = "";
				document.getElementById('detalhesEnviarAmigoDados').style.display = "";
				document.getElementById('detalhesEnviarAmigoDadosEnviando').style.display = "none";
			break;
			case 'info_err':
			case 'email_err':
				//document.getElementById('captchaSourceEnviarAmigo').src = '';
				document.getElementById('captchaSourceEnviarAmigo').src = 'captcha.php?cachebuster=' + Math.floor(Math.random()*100000);
				document.getElementById('captchaEnviarAmigo').value = '';
				document.getElementById('captchaEnviarAmigo').src = '';
				document.getElementById('detalhesEnviarAmigoMsgErr1').style.display = "none";
				document.getElementById('detalhesEnviarAmigoMsgErr2').style.display = "";
//				document.getElementById('detalhesEnviarAmigoTopo').style.display = "";
				document.getElementById('detalhesEnviarAmigoInfo').style.display = "";
				document.getElementById('detalhesEnviarAmigoDados').style.display = "";
				document.getElementById('detalhesEnviarAmigoDadosEnviando').style.display = "none";
			break;
			case 'ok':
				clearForm(document.getElementById('formEnviarAmigo'),document.getElementById('captchaSourceEnviarAmigo'));
//				document.getElementById('detalhesEnviarAmigoTopo').style.display = "none";
				document.getElementById('detalhesEnviarAmigoInfo').style.display = "none";
				document.getElementById('detalhesEnviarAmigoDados').style.display = "none";
				document.getElementById('detalhesEnviarAmigoMsgErr1').style.display = "none";
				document.getElementById('detalhesEnviarAmigoMsgErr2').style.display = "none";
				document.getElementById('detalhesEnviarAmigoMsgOk').style.display = "";
				document.getElementById('detalhesEnviarAmigoDadosEnviando').style.display = "none";
			break;
		}
	}
}

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) {
	if (elem) {
		var left = elem.offsetLeft;
		var top = elem.offsetTop;
		var handlerElem = elem.offsetParent;
		while (handlerElem) {
			left += handlerElem.offsetLeft;
			top += handlerElem.offsetTop;
			handlerElem = handlerElem.offsetParent;
		}
	}
	
	var retorno = new Array();
	retorno[0] = left;
	retorno[1] = top;
	
	return retorno;
}

function abreComboSecoes() {
	
	mouseOutComboSecoes = 1;
	taFechandoComboSecoes = 0;
	
	var left = $('#topoItemMaisPaginas').position().left;
	var top = $('#frameCabecalho').position().top;
	
	$('#topoComboMaisPaginas').css('left',left);
	$('#topoComboMaisPaginas').css('top','8px');
	$('#topoComboMaisPaginas').show(50);
	
}

var hand = $('<div></div>');

var mouseOutComboSecoes = 0;
var taFechandoComboSecoes = 1;
function fechaComboSecoes() {
	if (mouseOutComboSecoes == 0 && taFechandoComboSecoes == 0) {
		taFechandoComboSecoes = 1;
		$('#topoComboMaisPaginas').hide(0);
	}
}

function verificaMouseOut() {
	mouseOutComboSecoes = 0;
	setTimeout("fechaComboSecoes()",1000);
}

function topoComboMouseOver(obj) {
	mouseOutComboSecoes = 1;
	obj.className = "topoComboItemOn corSite1 corFonte1";
}

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 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 = 520;
		var tweenScroll = new Tween(document.getElementById('calendarioInner'),'scrollLeft',Tween.regularEaseOut,inicioTween,finalTween,0.5,'');
		tweenScroll.start();
	}
}

function rolaCalendarioEsquerda() {
	if (document.getElementById('calendarioInner').scrollLeft == 520) {
		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();
	}
}

function secaoMenuMouseOver(obj) {
	obj.style.backgroundPosition = "0px -30px";
}

function secaoMenuMouseOut(obj) {
	obj.style.backgroundPosition = "0px 0px";
}
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] = "celular";
	formEncomende[5] = "mensagem";
	formEncomende[6] = "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 mostraFotoLancamento(f) {
//	$('object').css('visibility','hidden');
//	
//	var fThumb = f.replace('lanc','t_lanc');
//	var legendaAtual = '';
//	var indiceAtual;
//	$('div[thumb_lanc=1]').each(function(){
//		if ($(this).attr('src') == fThumb) {
//			indiceAtual = $(this).attr('indice');
//			legendaAtual = $(this).attr('legenda');
//		}
//	});
//	
//	$('body').prepend('<div id="layerUp" style="display:none;"></div><div id="layerUpCortina"></div><div class="layerUpLegenda"><div>'+legendaAtual+'</div></div><div class="layerUpAbaFecha" title="Fechar" alt="Fechar"></div>').attr('scroll','no').css('overflow','hidden');
//	
//	if ($('div[thumb_lanc=1]').size() > 1) {
//		$('body').prepend('<div class="layerUpNavegaLeft" title="Visualizar foto anterior" alt="Visualizar foto anterior"></div><div class="layerUpNavegaRight" title="Visualizar foto seguinte" alt="Visualizar foto seguinte"></div>');
//	}
//	
//	$('.layerUpNavegaLeft,.layerUpNavegaRight,.layerUpLegenda,.layerUpAbaFecha').hide();
//	
//	$('#layerUpCortina').addClass('layerUpCortina').width($('html').width()).height($('html').height()).css('opacity',0).fadeTo('slow',.75);
//	
//	var l = $('body').width() / 2 - $('#layerUp').width() / 2;
//	var t = $('#tamanhoTela').height() / 2 - $('#layerUp').height() / 2;
//	
////	if(t < 0){t=0;$('#layerUp > img').attr('height',$('#tamanhoTela').height()-(2*$('#layerUp').css('padding')))}
//	
//	t += $('body').scrollTop();
//	
//	var novaH;
//	var novaW;
//	var fv = $('div[thumb_lanc=1][indice='+indiceAtual+']').attr('fv');
//	if($('div[thumb_lanc=1][indice='+indiceAtual+']').attr('h') > document.body.clientHeight) {
//		novaH = parseInt(document.body.clientHeight - 10);
//		novaW = parseInt((novaH * parseInt($('div[thumb_lanc=1][indice='+indiceAtual+']').attr('w')) / parseInt($('div[thumb_lanc=1][indice='+indiceAtual+']').attr('h'))) - 10);
//		if(novaW > document.body.clientWidth) {
//			novaH = novaH*(document.body.clientWidth - 110) / novaW;
//			novaW = document.body.clientWidth - 110;
//		}
//		fv = fv.replace('fvHeight='+$('div[thumb_lanc=1][indice='+indiceAtual+']').attr('h'),'fvHeight='+novaH);
//		fv = fv.replace('fvWidth='+$('div[thumb_lanc=1][indice='+indiceAtual+']').attr('w'),'fvWidth='+novaW);
//	} else {
//		novaH = parseInt($('div[thumb_lanc=1][indice='+indiceAtual+']').attr('h'));
//		novaW = parseInt($('div[thumb_lanc=1][indice='+indiceAtual+']').attr('w'));
//	}
//	
//	var flashObj = returnFlash(novaW,novaH,'img.swf',fv,'objFlashFotoLanc' + indiceAtual);
//	
//	$('#layerUp').addClass('layerUp').html(flashObj).css({left:l,top:t}).fadeIn();
//
//	$('#layerUp').css('height', novaH);
//	$('#layerUp').css('width', novaW);
//
//	posicionaLayerUp(indiceAtual,novaW,novaH);
//	
//	$('.layerUpAbaFecha').click(function(){
//		$('#layerUp,#layerUpCortina,.layerUpNavegaLeft,.layerUpNavegaRight,.layerUpLegenda,.layerUpAbaFecha').remove();
//		$('body').attr('scroll','auto').css('overflow','auto');
//		$('object').css('visibility','visible');
//	});
//	
//	$('.layerUpNavegaLeft').click(function(){
//		$('.layerUpLegenda').hide();
//		var velhaFoto = parseInt($('#layerUp > object').attr('id').replace('objFlashFotoLanc',''));
//		fThumb = $('div[thumb_lanc=1][indice='+velhaFoto+']').attr('src');
//		var novaFoto = '';
//		if ($('div[thumb_lanc=1]:first').attr('src') == fThumb) {
//			novaFoto = $('div[thumb_lanc=1]:last').attr('indice');
//		}else{
//			var handIndice = new Array();
//			var posAtual;
//			var i = 0;
//			$('div[thumb_lanc=1]').each(function(){
//				handIndice[i] = $(this).attr('indice');
//				if ($(this).attr('src') == fThumb) posAtual = i;
//				i++;
//			});
//			novaFoto = handIndice[posAtual - 1];
//		}
//		
//		var novaLegenda = $('div[thumb_lanc=1][indice='+novaFoto+']').attr('legenda');
//		var novaFlashVars = $('div[thumb_lanc=1][indice='+novaFoto+']').attr('fv');
//
//	if($('div[thumb_lanc=1][indice='+novaFoto+']').attr('h') > document.body.clientHeight) {
//		novaH = parseInt(document.body.clientHeight - 10);
//		novaW = parseInt((novaH * parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('w')) / parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('h'))) - 10);
//		if(novaW > document.body.clientWidth) {
//			novaH = novaH*(document.body.clientWidth - 110) / novaW;
//			novaW = document.body.clientWidth - 110;
//		}
//		novaFlashVars = fv.replace('fvHeight='+$('div[thumb_lanc=1][indice='+novaFoto+']').attr('h'),'fvHeight='+novaH);
//		novaFlashVars = fv.replace('fvWidth='+$('div[thumb_lanc=1][indice='+novaFoto+']').attr('w'),'fvWidth='+novaW);
//	} else {
//		novaH = parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('h'));
//		novaW = parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('w'));
//	}
//		
//		flashObj = returnFlash(novaW,novaH,'img.swf',novaFlashVars,'objFlashFotoLanc'+novaFoto);
//		
//		$('.layerUpLegenda').html('<div>'+novaLegenda+'</div>');
//		
//		$('#layerUp').html(flashObj);
//		posicionaLayerUp(novaFoto,novaW,novaH);
//	});
//	
//	$('.layerUpNavegaRight').click(function(){
//		$('.layerUpLegenda').hide();
//		var velhaFoto = parseInt($('#layerUp > object').attr('id').replace('objFlashFotoLanc',''));
//		fThumb = $('div[thumb_lanc=1][indice='+velhaFoto+']').attr('src');
//		var novaFoto = '';
//		if ($('div[thumb_lanc=1]:last').attr('src') == fThumb) {
//			novaFoto = $('div[thumb_lanc=1]:first').attr('indice');
//		}else{
//			var handIndice = new Array();
//			var posAtual;
//			var i = 0;
//			$('div[thumb_lanc=1]').each(function(){
//				handIndice[i] = $(this).attr('indice');
//				if ($(this).attr('src') == fThumb) posAtual = i;
//				i++;
//			});
//			novaFoto = handIndice[posAtual + 1];
//		}
//		
//		var novaLegenda = $('div[thumb_lanc=1][indice='+novaFoto+']').attr('legenda');
//		var novaFlashVars = $('div[thumb_lanc=1][indice='+novaFoto+']').attr('fv');
//
//	if($('div[thumb_lanc=1][indice='+novaFoto+']').attr('h') > document.body.clientHeight) {
//		novaH = parseInt(document.body.clientHeight - 10);
//		novaW = parseInt((novaH * parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('w')) / parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('h'))) - 10);
//		if(novaW > document.body.clientWidth) {
//			novaH = novaH*(document.body.clientWidth - 110) / novaW;
//			novaW = document.body.clientWidth - 110;
//		}
//		novaFlashVars = fv.replace('fvHeight='+$('div[thumb_lanc=1][indice='+novaFoto+']').attr('h'),'fvHeight='+novaH);
//		novaFlashVars = fv.replace('fvWidth='+$('div[thumb_lanc=1][indice='+novaFoto+']').attr('w'),'fvWidth='+novaW);
//	} else {
//		novaH = parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('h'));
//		novaW = parseInt($('div[thumb_lanc=1][indice='+novaFoto+']').attr('w'));
//	}
//		
//		flashObj = returnFlash(novaW,novaH,'img.swf',novaFlashVars,'objFlashFotoLanc'+novaFoto);
//		
//		$('.layerUpLegenda').html('<div>'+novaLegenda+'</div>');
//		
//		$('#layerUp').html(flashObj);
//		posicionaLayerUp(novaFoto,novaW,novaH);
//	});
//	
//}

//function posicionaLayerUp(par_indice,layerWidth,layerHeight) {
//	var newWidth = layerWidth;
//	var newHeight = layerHeight;
//
//	$('.layerUpNavegaLeft,.layerUpNavegaRight,.layerUpLegenda,.layerUpAbaFecha').hide();
//	$('#layerUp').animate({'width':newWidth+10},250,function(){
//		$('#layerUp').animate({'height':newHeight+10},250,function(){
//			var l = $('body').width() / 2 - $('#layerUp').width() / 2;
//			var t = $('#tamanhoTela').height() / 2 - $('#layerUp').height() / 2;
//			t += $('body').scrollTop();
//			$('#layerUp').animate({left:l,top:t},200,function(){
//				var ll = l-$('.layerUpNavegaLeft').width();
//				var tl = $('#tamanhoTela').height() / 2 - $('.layerUpNavegaLeft').height() / 2;
//				$('.layerUpNavegaLeft').css({left:ll,top:tl+$('body').scrollTop()});
//				var lr = l+$('#layerUp').width();
//				var tr = $('#tamanhoTela').height() / 2 - $('.layerUpNavegaRight').height() / 2;
//				$('.layerUpNavegaRight').css({left:lr,top:tr+$('body').scrollTop()});
//				var tleg = $('#layerUp').height() + t;
//				$('.layerUpLegenda').width($('#layerUp').width()).css({left:l,top:tleg});
//				$('.layerUpAbaFecha').css({left:lr,top:t});
//				
//				$('.layerUpNavegaLeft,.layerUpNavegaRight,.layerUpAbaFecha').show();
//				if ($('.layerUpLegenda > div').html() != '' && $('.layerUpLegenda > div').html() != 'undefined') $('.layerUpLegenda').show();
//			});
//		});
//	});
//}

function mostraFavoritos() {
	if (window.parent.document.getElementById('boxFavoritos'))
		window.parent.document.getElementById('boxFavoritos').style.display = "";
}

function mostraIndicadores() {
	document.getElementById('boxIndicadores').style.display = "";
}

function mostraClima() {
	document.getElementById('boxClimatempo').style.display = "";
}

$(document).ready(function(){
	if ($('#whenOff').height() < 50) $('.whenOffRemover').remove();
});
