var msg = "";

// Expansão Mapa
$(function()
{
    $("#trigger").click(function(event) {
    event.preventDefault();
    $("#mapa").slideToggle();
    });
    $("#mapa a").click(function(event) {
    event.preventDefault();
    $("#mapa").slideUp();
    });
});
//Expand Financiamento
$(document).ready(function()
{
  $(".txt_caixa").hide().filter(':first').show();
  $(".msg_head").click(function()//click
  {
      $(this).next(".txt_caixa").slideToggle(400);
  });
});

//Expand Mapa do Site
$(document).ready(function()
{
  $(".txt_caixa2").hide().filter(':first').show();
  $(".msg_head2").mouseover(function()//click
  {
      $(this).next(".txt_caixa2").slideToggle(0);
  });
});

//CAROUSEL
jQuery(document).ready(function() {

    jQuery('#mycarouselEmp').jcarousel({ scroll: 1 });
    jQuery('#mycarouselPlantas').jcarousel({ scroll: 1 });
    jQuery('#mycarouselAmbientes').jcarousel({ scroll: 1 });
    jQuery('#mycarouselFaereas').jcarousel({ scroll: 1 });
    jQuery('#mycarouselLocalizacao').jcarousel({ scroll: 1 });
    jQuery('#mycarouselcozinha').jcarousel({ scroll: 1 });
    jQuery('#mycarouselquartos').jcarousel({ scroll: 1 });
    jQuery('#mycarouselbanheiros').jcarousel({ scroll: 1 });
    jQuery('#mycarouselsala').jcarousel({ scroll: 1 });
    jQuery('#mycarouselexterno').jcarousel({ scroll: 1 });

    //############################### MARCOS NOVO CARROUSEL #####################
    function carrossel(tipo, tam) {
        $('#destaqueHome' + tipo).jcarousel({
            scroll: 1,
            size: tam
        });
    }
    //Carousel Load
    $('#destaquesTipo li a').each(function(i) {
        var tipo = $(this).attr('class');
        var qtd = $('#destaquematriz').find('li.' + tipo).length;

        $('#destaquematriz').after('<div id="caixa' + tipo + '"><ul id="destaqueHome' + tipo + '" class="jcarousel-skin-imoveis"></ul></div>');
        $('#destaquematriz li.' + tipo).clone(true).appendTo('#destaqueHome' + tipo);
        carrossel(tipo, qtd);

    });
    $('#destaquematriz').remove();

    //Tabs
    $('ul#destaquesTipo').tabs();
    $('ul.tabCarouselHoME a').click(function() {
        $('ul.tabCarouselHoME a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();


    //REMOVE ABAS QUE NÃO TEM CONTEUDO NA HOME BY MARCOS

    var lancamento = -1;
    var pronto = -1;
    var pre = -1;
    var semi = -1;
    //lancamentos
    $('div#destaqueHome ul#destaqueHomelanc_carousel_home li').each(function(i) {
        lancamento = i;
    });

    if (lancamento < 0) {
        if (document.getElementById("ctl00_cph_hlkLancamento")) {
            document.getElementById("ctl00_cph_hlkLancamento").className = "pre_lancamento";
            $('div.tabsHome ul#caixalanc_carousel_home').remove();
            $('div.tabsHome #liLancamento a').remove();
            $('div.tabsHome ul.tabCarouselHoME a').removeClass('selected');
            $('div.tabsHome ul.tabCarouselHoME li#liPreLancamento a').addClass(' selected');
            $('div.tabsHome div#caixapre_carousel_home').removeClass('ui-tabs-hide');
            $('div.tabsHome ul#destaqueHomepre_carousel_home').show();
        }
    }

    //pre
    $('div#destaqueHome ul#destaqueHomepre_carousel_home li').each(function(i) {
        pre = i;
    });
    if (pre < 0) {

        $('div.tabsHome ul#caixapre_carousel_home').remove();
        $('div.tabsHome #liPreLancamento a').remove();

        if (lancamento < 0) {
            if (document.getElementById("ctl00_cph_hlkLancamento")) {
                document.getElementById("ctl00_cph_hlkLancamento").className = "semiprontos";
                $('div.tabsHome ul.tabCarouselHoME a').removeClass('selected');
                $('div.tabsHome ul.tabCarouselHoME li#liSemiProntos a').addClass(' selected');
                $('div.tabsHome div#caixasemi_carousel_home').removeClass('ui-tabs-hide');
                $('div.tabsHome ul#destaqueHomesemi_carousel_home').show();
            }
        }
    }

    //semi-prontos
    $('div#destaqueHome ul#destaqueHomesemi_carousel_home li').each(function(i) {
        semi = i;
    });
    if (semi < 0) {

        $('div.tabsHome ul#caixasemi_carousel_home').remove();
        $('div.tabsHome #liSemiProntos a').remove();
        if (pre < 0 && lancamento < 0) {
            if (document.getElementById("ctl00_cph_hlkLancamento")) {
                document.getElementById("ctl00_cph_hlkLancamento").className = "prontospramorar";
                $('div.tabsHome ul.tabCarouselHoME a').removeClass('selected');
                $('div.tabsHome ul.tabCarouselHoME li#liProntos a').addClass(' selected');
                $('div.tabsHome div#caixaprontos_carousel_home').removeClass('ui-tabs-hide');
                $('div.tabsHome ul#destaqueHomeprontos_carousel_home').show();
            }
        }
    }

    //prontos
    $('div#destaqueHome ul#destaqueHomeprontos_carousel_home li').each(function(i) {
        pronto = i;

    });

    if (pronto < 0) {
        $('div.tabsHome ul#caixaprotnos_carousel_home').remove();
        $('div.tabsHome #liProntos a').remove();
    }
});

//ABAS INTERNAS
jQuery(document).ready(function() {
    var emp = 0;
    var pla = 0;
    var amb = 0;
    var aer = 0;
    var loc = 0;
    //fotos do imovel
    $('div.tabsInt div#empinterna ul li div').each(function(i){
        emp = i;
    });
    if(emp < 1)
    {
        $('div.tabsInt div#empinterna').remove(); 
        $('div.tabsInt #liEmp a').remove();
        $('div.tabsInt ul.tabsIntNavigation a').removeClass('selected');
        $('div.tabsInt ul.tabsIntNavigation li#liPlan a').addClass(' selected');
        $('div.tabsInt #plantas').show();
    }
    
    //plantas
    $('div.tabsInt div#plantas ul li div').each(function(i){
        pla = i;
    });
    if(pla < 1)
    {
        $('div.tabsInt div#plantas').remove(); 
        $('div.tabsInt #liPlan a').remove();
        if(emp < 1 && pla < 1)
        {
            $('div.tabsInt ul.tabsIntNavigation a').removeClass('selected');
            $('div.tabsInt ul.tabsIntNavigation li#liAmb a').addClass(' selected');
            $('div.tabsInt #ambientes').show();
        }
    }
    //ambientes
    amb = 0;
    $('div.tabsInt div#ambientes ul li div').each(function(i){
        amb = i;
    });
    if(amb < 1)
    {
        $('div.tabsInt div#ambientes').remove(); 
        $('div.tabsInt #liAmb a').remove();
        if(emp < 1 && pla < 1 && amb < 1)
        {
            $('div.tabsInt ul.tabsIntNavigation a').removeClass('selected');
            $('div.tabsInt ul.tabsIntNavigation li#liAer a').addClass(' selected');
            $('div.tabsInt #faereas').show();
        }
    }
    //fotos aéreas
    $('div.tabsInt div#faereas ul li div').each(function(i){
        aer = i;
    });
    if(aer < 1)
    {
        $('div.tabsInt div#faereas').remove(); 
        $('div.tabsInt #liAer a').remove();
        if(emp < 1 && pla < 1 && amb < 1 && aer < 1)
        {
            $('div.tabsInt ul.tabsIntNavigation a').removeClass('selected');
            $('div.tabsInt ul.tabsIntNavigation li#liLoc a').addClass(' selected');
            $('div.tabsInt #localizacao').show();
        }
    }
    //localizacao
    $('div.tabsHome div#localizacao ul li div').each(function(i){
        loc = i;
    });
    if(loc < 1)
    {
        $('div.tabsHome div#localizacao').remove(); 
        $('div.tabsHome #liLoc a').remove();
    }
});

//TABS Carousel Interna_Empreendimento
$(function () {
	var tabContainers = $('div.tabsInt > div');
	tabContainers.hide().filter(':first').show();
	$('div.tabsInt ul.tabsIntNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabsInt ul.tabsIntNavigation a').removeClass('selectedInt');
		$(this).addClass('selectedInt');
		return false;
	}).filter(':first').click();
});
//TABS Carousel Interna_Acabamento
$(function () {
	var tabContainers = $('div.tabsIntAC > div');
	tabContainers.hide().filter(':first').show();
	$('div.tabsIntAC ul.tabsIntACNavigation a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).show();
		$('div.tabsIntAC ul.tabsIntACNavigation a').removeClass('selectedInt');
		$(this).addClass('selectedInt');
		return false;
	}).filter(':first').click();
});
//tabs busca
$(function () {
		var tabContainers = $('div.tabs > div');
		tabContainers.hide().filter(':first').show();
		$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
		}).filter(':first').click();
});
//tabs busca voltar_cep
$(function () {
		var tabContainers = $('div.tabs > div');
		tabContainers.hide().filter(':first').show();
		$('div..bt_voltar_a a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a#b_cep').removeClass('selected');
				$('div.tabs ul.tabNavigation a#b_rapida').addClass('selected');
				return false;
		}).filter(':first').click();
});
//tabs busca voltar_emp
$(function () {
		var tabContainers = $('div.tabs > div');
		tabContainers.hide().filter(':first').show();
		$('div..bt_voltar_b a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a#b_emp').removeClass('selected');
				$('div.tabs ul.tabNavigation a#b_rapida').addClass('selected');
				return false;
		}).filter(':first').click();
});
//tabs busca voltar_avancada
$(function () {
		var tabContainers = $('div.tabs > div');
		tabContainers.hide().filter(':first').show();
		$('div..bt_voltar_c a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('div.tabs ul.tabNavigation a#b_avancada').removeClass('selected');
				$('div.tabs ul.tabNavigation a#b_rapida').addClass('selected');
				return false;
		}).filter(':first').click();
});

//dock
$(document).ready(function() {
	//Tooltip
	$('#linkTooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		extraClass: "right"
	});
	//jqDock
	var opts = {
		   align: 'middle',
		   size: 64,
		   distance: 100,
		   coefficient: 1.5,
		   labels: 'bc',
		   duration: 150//,
		   //source: function(i){ return this.src.replace(/gif$/,'png'); }
	};
	$('#dock').jqDock(opts);
});

function gravaCookie(id, sigla, nome, url){
    var date = new Date();
    date.setTime(date.getTime()+(355*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    document.cookie = "UF="+sigla+expires+"; path=/";
    document.cookie = "idEstado="+id+expires+"; path=/";
    document.cookie = "Estado="+nome+expires+"; path=/";
    document.getElementById("mapa").style.display = 'none';
    location.href = '/' + url;
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


// FACEBOX
//jQuery(document).ready(function($) {
//    $('a[rel*=facebox]').facebox()
//}) 

function abrir(strMensagem)
{
	$(document).ready(function(){
		 jQuery.facebox(strMensagem);
	})
}


function validaBuscaRapida(){
    msg = "";
    if(document.getElementById("ctl00_ddlCidade").value == "0"){
        msg = "Selecione uma Cidade para realizar a busca!";
    }
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}
function validaBuscaCep(){
    msg = "";
    if(document.getElementById("ctl00_txtInicioCep").value == "" || document.getElementById("ctl00_txtFimCep").value == ""){
        msg = "Preencha o CEP corretamente para realizar a busca!";
    }
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}
function validaBuscaEmpreendimento(){
    msg = "";
    if(document.getElementById("ctl00_txtNomeBusca").value == "" && document.getElementById("ctl00_txtPalavraBusca").value == ""){
        msg = "Preencha o Nome do empreendimento ou uma palavra-chave para realizar a busca!";
    }
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}
function validaBuscaAvancada(){
    msg = "";
    if(document.getElementById("ctl00_ddlEstadoAvancado").value == "0" && document.getElementById("ctl00_txtInicioCepAvancado").value == "" && document.getElementById("ctl00_txtPalavraAvancada").value == ""){
        msg = "Selecione uma localiza&ccedil;&atilde;o ou preencha o campo CEP ou uma palavra-chave para realizar a busca!";
    }
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}
function validaCadastrese(){
    msg = "";
    if(document.getElementById("ctl00_cph_txtNome").value == ""){
        msg = "Preencha o campo <strong>Nome</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_rblPais_0").checked == false && document.getElementById("ctl00_cph_rblPais_1").checked == false){
        msg += "Selecione o local onde sua <strong>resid&ecirc;cia est&aacute; localizada</strong>.<br />";
    }
    else
    {
        if(document.getElementById("ctl00_cph_rblPais_1").checked)
        {
            if(document.getElementById("ctl00_cph_txtDdi").value == "" || document.getElementById("ctl00_cph_txtDdi").value == "DDI"){
                msg += "Preencha o campo <strong>Ddi</strong>!<br />";
            }
        }
        if(document.getElementById("ctl00_cph_txtDdd").value == "" || document.getElementById("ctl00_cph_txtDdd").value == "DDD"){
            msg += "Preencha o campo <strong>Ddd</strong>!<br />";
        }
        if(document.getElementById("ctl00_cph_txtTelefone").value == "" || document.getElementById("ctl00_cph_txtTelefone").value == "FONE"){
            msg += "Preencha o campo <strong>Telefone</strong>!<br />";
        }
    }
    if(document.getElementById("ctl00_cph_txtEmail").value == ""){
        msg += "Preencha o campo <strong>E-mail</strong>!<br />";
    }
    else
    {
        if(!VerificaEmail(document.getElementById("ctl00_cph_txtEmail").value))
        {
            msg += "<strong>E-mail inv&aacute;lido</strong>!<br />";
        }
    }
    if(document.getElementById("ctl00_cph_txtMensagem").value == ""){
        msg += "Preencha o campo <strong>Mensagem</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_rblContato_0").checked == false && document.getElementById("ctl00_cph_rblContato_1").checked == false){
        msg += "Selecione uma forma de <strong>receber nosso Contato!</strong><br />";
    }
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}

function validaNovidades(){
    msg = "";
    if(document.getElementById("ctl00_cph_txtNome").value == ""){
        msg = "Preencha o campo <strong>Nome</strong>!<br />";
    }
    
    if(document.getElementById("ctl00_cph_txtEmail").value == ""){
        msg += "Preencha o campo <strong>E-mail</strong>!<br />";
    }
    else
    {
        if(!VerificaEmail(document.getElementById("ctl00_cph_txtEmail").value))
        {
            msg += "<strong>E-mail inv&aacute;lido</strong>!<br />";
        }
    }
    
    if(document.getElementById("ctl00_cph_txtDddCelular").value == "" && document.getElementById("ctl00_cph_txttelefoneCelular").value == "" && document.getElementById("ctl00_cph_txtDddResidencial").value == "" && document.getElementById("ctl00_cph_txtTelefoneResidencial").value == "" && document.getElementById("ctl00_cph_txtDddComercial").value == "" && document.getElementById("ctl00_cph_txtTelefoneComercial").value == ""){
        
        msg += "Preencha um <strong>Telefone com Ddd para contato</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddCelular").value == "" && document.getElementById("ctl00_cph_txttelefoneCelular").value != "")
    {
        msg += "Preencha o campo <strong>Ddd do telefone Celullar</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddCelular").value != "" && document.getElementById("ctl00_cph_txttelefoneCelular").value == "")
    {
        msg += "Preencha o campo <strong>telefone Celullar</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddResidencial").value == "" && document.getElementById("ctl00_cph_txtTelefoneResidencial").value != "")
    {
        msg += "Preencha o campo <strong>Ddd do telefone Residencial</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddResidencial").value != "" && document.getElementById("ctl00_cph_txtTelefoneResidencial").value == "")
    {
        msg += "Preencha o campo <strong>telefone Residencial</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddComercial").value == "" && document.getElementById("ctl00_cph_txtTelefoneComercial").value != "")
    {
        msg += "Preencha o campo <strong>Ddd do telefone Comercial</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddComercial").value != "" && document.getElementById("ctl00_cph_txtTelefoneComercial").value == "")
    {
        msg += "Preencha o campo <strong>telefone Comercial</strong>!<br />";
    }
    //cidades de interesse
    inttotal = document.getElementById("ctl00_cph_hndTotalCidade").value;
    var contador = 0;
    for(i = 0 ;i < inttotal; i++)
    {
        if(document.getElementById("ctl00_cph_cblCidades_" + i).checked == true)
        {
            contador ++;
        }
    }    
    if(contador == 0)
    {
        msg += "Selecione a(s) <strong>Cidade(s) de interesse</strong>!<br />";
    }
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}


function validaFale(){
    msg = "";
    if(document.getElementById("ctl00_cph_txtNome").value == ""){
        msg = "Preencha o campo <strong>Nome</strong>!<br />";
    }
    
    if(document.getElementById("ctl00_cph_txtEmail").value == ""){
        msg += "Preencha o campo <strong>E-mail</strong>!<br />";
    }
    else
    {
        if(!VerificaEmail(document.getElementById("ctl00_cph_txtEmail").value))
        {
            msg += "<strong>E-mail inv&aacute;lido</strong>!<br />";
        }
    }
    if(document.getElementById("ctl00_cph_rblPais_0").checked == false && document.getElementById("ctl00_cph_rblPais_1").checked == false){
        msg += "Selecione o local onde sua <strong>resid&ecirc;cia est&aacute; localizada</strong>.<br />";
    }
    else
    {
        if(document.getElementById("ctl00_cph_rblPais_0").checked == true)
        {
           if(document.getElementById("ctl00_cph_ddlEstados").value == "0"){
                msg += "Selecione o <strong>Estado</strong> onde mora!<br />";
           } 
           if(document.getElementById("ctl00_cph_ddlCidades").value == "0"){
                msg += "Selecione a <strong>Cidade</strong> onde mora!<br />";
           }  
        }
        if(document.getElementById("ctl00_cph_rblPais_1").checked == true)
        {
           if(document.getElementById("ctl00_cph_txtPais").value == ""){
                msg += "Preencha o campo <strong>Pa&iacute;s</strong> onde mora!<br />";
           }  
           if(document.getElementById("ctl00_cph_txtEstado").value == ""){
                msg += "Preencha o campo <strong>Cidade</strong> onde mora!<br />";
           }  
           if(document.getElementById("ctl00_cph_txtCidade").value == ""){
                msg += "Preencha o campo <strong>Cidade</strong> onde mora!<br />";
           }  
        }
    }
    if(document.getElementById("ctl00_cph_txtDddCelular").value == "" && document.getElementById("ctl00_cph_txttelefoneCelular").value == "" && document.getElementById("ctl00_cph_txtDddResidencial").value == "" && document.getElementById("ctl00_cph_txtTelefoneResidencial").value == "" && document.getElementById("ctl00_cph_txtDddComercial").value == "" && document.getElementById("ctl00_cph_txtTelefoneComercial").value == ""){
        
        msg += "Preencha um <strong>Telefone com Ddd para contato</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddCelular").value == "" && document.getElementById("ctl00_cph_txttelefoneCelular").value != "")
    {
        msg += "Preencha o campo <strong>Ddd do telefone Celullar</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddCelular").value != "" && document.getElementById("ctl00_cph_txttelefoneCelular").value == "")
    {
        msg += "Preencha o campo <strong>telefone Celullar</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddResidencial").value == "" && document.getElementById("ctl00_cph_txtTelefoneResidencial").value != "")
    {
        msg += "Preencha o campo <strong>Ddd do telefone Residencial</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddResidencial").value != "" && document.getElementById("ctl00_cph_txtTelefoneResidencial").value == "")
    {
        msg += "Preencha o campo <strong>telefone Residencial</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddComercial").value == "" && document.getElementById("ctl00_cph_txtTelefoneComercial").value != "")
    {
        msg += "Preencha o campo <strong>Ddd do telefone Comercial</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtDddComercial").value != "" && document.getElementById("ctl00_cph_txtTelefoneComercial").value == "")
    {
        msg += "Preencha o campo <strong>telefone Comercial</strong>!<br />";
    }
    //cidades de interesse
    inttotal = document.getElementById("ctl00_cph_hndTotalCidade").value;
    var contador = 0;
    for(i = 0 ;i < inttotal; i++)
    {
        if(document.getElementById("ctl00_cph_cblCidades_" + i).checked == true)
        {
            contador ++;
        }
    }    
    if(contador == 0)
    {
        msg += "Selecione a(s) <strong>Cidade(s) de interesse</strong>!<br />";
    }
    
    if(document.getElementById("ctl00_cph_rblContato_0").checked == false && document.getElementById("ctl00_cph_rblContato_1").checked == false){
        msg += "Selecione uma forma de <strong>receber nosso Contato!</strong><br />";
    }
   
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}

function validaFormBusca(){

    msg = "";
    if(document.getElementById("ctl00_cph_txtNome").value == ""){
        msg = "Preencha o campo <strong>Nome</strong>!<br />";
    }
    
    if(document.getElementById("ctl00_cph_txtEmail").value == ""){
        msg += "Preencha o campo <strong>E-mail</strong>!<br />";
    }
    else
    {
        if(!VerificaEmail(document.getElementById("ctl00_cph_txtEmail").value))
        {
            msg += "<strong>E-mail inv&aacute;lido</strong>!<br />";
        }
    }
    
    if(document.getElementById("ctl00_cph_txtDddResidencial").value == "" || document.getElementById("ctl00_cph_txtDddResidencial").value == "DDD"){
        msg += "Preencha o campo <strong>Ddd</strong>!<br />";
    }
    if(document.getElementById("ctl00_cph_txtTelefoneResidencial").value == "" || document.getElementById("ctl00_cph_txtTelefoneResidencial").value == "FONE"){
        msg += "Preencha o campo <strong>Telefone</strong>!<br />";
    }
    
    if(document.getElementById("ctl00_cph_rblContato_0").checked == false && document.getElementById("ctl00_cph_rblContato_1").checked == false){
        msg += "Selecione uma forma de <strong>receber nosso Contato!</strong><br />";
    }
   
    if(msg != ""){
        msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
        abrir(msg);
        return false;
    }
}

function PopChatDT( url, cidade, bairro, origem ) {
    var popchat = window.open( "http://www.mrv.com.br/corretores/chat/" + url + "?cidade=" + cidade + "&bairro=" + bairro + "&origem=" + origem, "Pop_Chat", "top=25,left=50,width=505,height=590,scrollbars=no,resizable=yes" );
	popchat.focus();
}

var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail = reEmail3;
function VerificaEmail(stremail)
{
	if (reEmail.test(stremail)) {
		return true;
	} else if (stremail != null && stremail != "") {
		return false
	}
}

//marca checbox
function MarcaCheckBox(total, campo, local)
{
    inttotal = document.getElementById(total).value;
    for(i = 0 ;i < inttotal; i++)
    {
        if(local.checked){
            document.getElementById(campo + i).checked = true;
        }
        else{
            document.getElementById(campo + i).checked = false;
        }        
    }    
}

var _font_min = 10;  
var _font_max = 18;
var _tags = ['div', 'p', 'h1', 'h2', 'span', 'a', 'i', 'b', 'li', 'td', 'strong', 'f5', 'dd'];
function Aumentar(idDiv) {
    // validacoes      
    var e_corpo_noticia = document.getElementById(idDiv);
    if (typeof(e_corpo_noticia) != 'object') return; 
    var atual_size = e_corpo_noticia.style.fontSize;             
    // apanhando o tamanho atual
    if(!atual_size) atual_size = 14;
    else atual_size = parseInt(atual_size.replace('px'));
    if(atual_size >= _font_max) return;            
    modificar_geral(e_corpo_noticia, atual_size + 1);            
}
        
function Diminuir(idDiv) {
    var e_corpo_noticia = document.getElementById(idDiv);
    if (typeof(e_corpo_noticia) != 'object') return; 
    var atual_size = e_corpo_noticia.style.fontSize;             
    if(!atual_size) atual_size = 14;
    else atual_size = parseInt(atual_size.replace('px'));
    if(atual_size <= _font_min) return;             
    modificar_geral(e_corpo_noticia, atual_size - 1);            
}
        
function modificar_geral(el, size) { 
    el.style.fontSize = size + 'px';
    var tags = _tags;
    for(var i in tags) {
        var l_els = el.getElementsByTagName(tags[i]);
        for(var i=0; i< l_els.length; i++) {
            l_els[i].style.fontSize = size + 'px';
        }
    }

}

//TEXTO JURIDICO
function exibir(){    
    document.getElementById("text_juridico").style.display = "block";
}
function esconder(){    
    document.getElementById("text_juridico").style.display = "none";
}


//EXPAND FINANCIAMENTO
$(document).ready(function()
{
  $(".abrir2").hide();
  $(".abrir").click(function()
  {
    $(this).next(".abrir2").slideToggle(1);
	
  });
  
  //$('div .tabsInt div.conteudo_carouselInt ul li a').attr('title').style.display = 'none';
  //
});


//###################### NOVOS COMBOS DE BUSCA MARCOS ##########################################
$(document).ready(function()
{
    //Busca Rapida
	listar('','Estado','Rapida','','','','','','');

	$('#rapida a[href="javascript:void(0);"]:eq(0), #avancada a[href="javascript:void(0);"]:eq(0)').addClass('active');
	$('#rapida a[href="javascript:void(0);"], #avancada a[href="javascript:void(0);"]').click(function(){
		$(this).next().css('display','block');

		$(this).bind("mouseleave", function(){ //oculta drop
			$(this).next().css('display','none');
		});

		$(this).next().bind("mouseenter", function(){ //mostra drop
			$(this).css('display','block');
		});
		
		$(this).next().bind("mouseleave click", function(){ //oculta drop
			$(this).css('display','none');
		});
		
		$('ul a').click(function(){
		    
		    var tipo;// = $('ul.used a').parent().parent().attr('id');
		    if(document.getElementById('avancada').style.display == 'none'){tipo = 'Rapida';}else{tipo = 'Avancada';}

			var quem = $(this).parent().parent().attr('id');
			var cidade = $('a#linkCidade' + tipo).attr('class');
			var bairro = $('a#linkBairro' + tipo).attr('class');
			var produto = $('a#linkProduto' + tipo).attr('class');
			var tipologia = $('a#linkTiplogia' + tipo).attr('class');
			var faixa = $('a#linkFaixa' + tipo).attr('class');
			var rev = $(this).attr('rev');
            
            if ( quem == 'listaEstado' + tipo ) {
			 
				$('a#linkCidade' + tipo).attr({rel: ''});
				$('a#linkCidade' + tipo).text('Cidades');
				
				$('a#linkCidade' + tipo).removeClass('active');
				$('ul#listaCidade' + tipo).remove();
				$('a#linkCidade' + tipo).after('<ul id="listaCidade' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Selecione um Estado</a></li></ul>');
                //bairro				
				$('a#linkBairro' + tipo).attr({rel: ''});
				$('a#linkBairro' + tipo).removeClass('active');
				$('a#linkBairro' + tipo).text('Bairro');
				$('ul#listaBairro' + tipo).remove();
				$('a#linkBairro' + tipo).after('<ul id="listaBairro' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Selecione uma Cidade</a></li></ul>');
                //produto
                $('a#linkProduto' + tipo).attr({rel: ''});
				$('a#linkProduto' + tipo).removeClass('active');
				$('a#linkProduto' + tipo).text('Produto');
				$('ul#listaProduto' + tipo).remove();
				$('a#linkProduto' + tipo).after('<ul id="listaProduto' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Selecione um Estado</a></li></ul>');	
                //tipologia
                $('a#linkTipologia' + tipo).attr({rel: ''});
				$('a#linkTipologia' + tipo).removeClass('active');
				$('a#linkTipologia' + tipo).text('Tipologia');
				$('ul#listaTipologia' + tipo).remove();
				$('a#linkTipologia' + tipo).after('<ul id="listaTipologia' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Selecione um Estado</a></li></ul>');
                //faixa de preço
			    $('a#linkFaixa' + tipo).attr({rel: ''});
				$('a#linkFaixa' + tipo).removeClass('active');
				$('a#linkFaixa' + tipo).text(unescape( decodeURIComponent('Faixa de Pre%C3%A7o')));
				$('ul#listaFaixa' + tipo).remove();
				$('a#linkFaixa' + tipo).after('<ul id="listaFaixa' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Selecione um Estado</a></li></ul>');	
	
	            if(tipo	== 'Avancada')
	            {
	                //metragem
			        $('a#linkMetragem' + tipo).attr({rel: ''});
				    $('a#linkMetragem' + tipo).removeClass('active');
				    $('a#linkMetragem' + tipo).text('Metragem');
				    $('ul#listaMetragem' + tipo).remove();
				    $('a#linkMetragem' + tipo).after('<ul id="listaMetragem' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
	            }											
				//}
			}
			if ( quem == 'listaCidade' + tipo) {
				
				//Bairro
				$('a#linkBairro' + tipo).attr({rel: ''});
				$('a#linkBairro' + tipo).removeClass('active');
				$('a#linkBairro' + tipo).text('Bairro');
				$('ul#listaBairro' + tipo).remove();
				$('a#linkBairro' + tipo).after('<ul id="listaBairro' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Selecione uma Cidade</a></li></ul>');
	            //Produto
	            $('a#linkProduto' + tipo).attr({rel: ''});
				$('a#linkProduto' + tipo).removeClass('active');
				$('a#linkProduto' + tipo).text('Produto');
				$('ul#listaProduto' + tipo).remove();
				$('a#linkProduto' + tipo).after('<ul id="listaProduto' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todos</a></li></ul>');	
	
	            //tipologia
                $('a#linkTipologia' + tipo).attr({rel: ''});
				$('a#linkTipologia' + tipo).removeClass('active');
				$('a#linkTipologia' + tipo).text('Tipologia');
				$('ul#listaTipologia' + tipo).remove();
				$('a#linkTipologia' + tipo).after('<ul id="listaTipologia' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
                //faixa de preço
			    $('a#linkFaixa' + tipo).attr({rel: ''});
				$('a#linkFaixa' + tipo).removeClass('active');
				$('a#linkFaixa' + tipo).text(unescape( decodeURIComponent('Faixa de Pre%C3%A7o')));
				$('ul#listaFaixa' + tipo).remove();
				$('a#linkFaixa' + tipo).after('<ul id="listaFaixa' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');	
	
	            if(tipo	== 'Avancada')
	            {
	                //metragem
			        $('a#linkMetragem' + tipo).attr({rel: ''});
				    $('a#linkMetragem' + tipo).removeClass('active');
				    $('a#linkMetragem' + tipo).text('Metragem');
				    $('ul#listaMetragem' + tipo).remove();
				    $('a#linkMetragem' + tipo).after('<ul id="listaMetragem' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
	            }									
								
			}
			if (quem == 'listaBairro' + tipo) {
				 //Produto				 
	            $('a#linkProduto' + tipo).attr({rel: ''});
				$('a#linkProduto' + tipo).removeClass('active');
				$('a#linkProduto' + tipo).text('Produto');
				$('ul#listaProduto' + tipo).remove();
				$('a#linkProduto' + tipo).after('<ul id="listaProduto' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todos</a></li></ul>');	
	
	            //tipologia
                $('a#linkTipologia' + tipo).attr({rel: ''});
				$('a#linkTipologia' + tipo).removeClass('active');
				$('a#linkTipologia' + tipo).text('Tipologia');
				$('ul#listaTipologia' + tipo).remove();
				$('a#linkTipologia' + tipo).after('<ul id="listaTipologia' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
                //faixa de preço
			    $('a#linkFaixa' + tipo).attr({rel: ''});
				$('a#linkFaixa' + tipo).removeClass('active');
				$('a#linkFaixa' + tipo).text(unescape( decodeURIComponent('Faixa de Pre%C3%A7o')));
				$('ul#listaFaixa' + tipo).remove();
				$('a#linkFaixa' + tipo).after('<ul id="listaFaixa' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');	
	            
	            if(tipo	== 'Avancada')
	            {
	                //metragem
			        $('a#linkMetragem' + tipo).attr({rel: ''});
				    $('a#linkMetragem' + tipo).removeClass('active');
				    $('a#linkMetragem' + tipo).text('Metragem');
				    $('ul#listaMetragem' + tipo).remove();
				    $('a#linkMetragem' + tipo).after('<ul id="listaMetragem' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
	            }			
			}
			
			if (quem == 'listaProduto' + tipo) {
					
	            //tipologia
                $('a#linkTipologia' + tipo).attr({rel: ''});
				$('a#linkTipologia' + tipo).removeClass('active');
				$('a#linkTipologia' + tipo).text('Tipologia');
				$('ul#listaTipologia' + tipo).remove();
				$('a#linkTipologia' + tipo).after('<ul id="listaTipologia' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
                //faixa de preço
			    $('a#linkFaixa' + tipo).attr({rel: ''});
				$('a#linkFaixa' + tipo).removeClass('active');
				$('a#linkFaixa' + tipo).text(unescape( decodeURIComponent('Faixa de Pre%C3%A7o')));
				$('ul#listaFaixa' + tipo).remove();
				$('a#linkFaixa' + tipo).after('<ul id="listaFaixa' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');	
	
	            if(tipo	== 'Avancada')
	            {
	                //metragem
			        $('a#linkMetragem' + tipo).attr({rel: ''});
				    $('a#linkMetragem' + tipo).removeClass('active');
				    $('a#linkMetragem' + tipo).text('Metragem');
				    $('ul#listaMetragem' + tipo).remove();
				    $('a#linkMetragem' + tipo).after('<ul id="listaMetragem' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
	            }			
			}
			if (quem == 'listaTipologia' + tipo && tipologia == 'linkLista active used') {
				
	            //faixa de preço
			    $('a#linkFaixa' + tipo).attr({rel: ''});
				$('a#linkFaixa' + tipo).removeClass('active');
				$('a#linkFaixa' + tipo).text(unescape( decodeURIComponent('Faixa de Pre%C3%A7o')));
				$('ul#listaFaixa' + tipo).remove();
				$('a#linkFaixa' + tipo).after('<ul id="listaFaixa' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');	
	
	            if(tipo	== 'Avancada')
	            {
	                //metragem
			        $('a#linkMetragem' + tipo).attr({rel: ''});
				    $('a#linkMetragem' + tipo).removeClass('active');
				    $('a#linkMetragem' + tipo).text('Metragem');
				    $('ul#listaMetragem' + tipo).remove();
				    $('a#linkMetragem' + tipo).after('<ul id="listaMetragem' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
	            }			
			}
			if (quem == 'listaFaixa' + tipo) {
				
	            if(tipo	== 'Avancada')
	            {
	                //metragem
			        $('a#linkMetragem' + tipo).attr({rel: ''});
				    $('a#linkMetragem' + tipo).removeClass('active');
				    $('a#linkMetragem' + tipo).text('Metragem');
				    $('ul#listaMetragem' + tipo).remove();
				    $('a#linkMetragem' + tipo).after('<ul id="listaMetragem' + tipo + '" class="buscaLista" style="display: none;"><li><a href="javascript:;">Todas</a></li></ul>');
	            }
			}
			
			
		});
	});
	//Busca Avancada
	listar('0','Estado','Avancada','','','','','','');
	$('ul.opt a').click(function () {
		var titulo = $(this).attr('title');
		var relative = $(this).attr('rel');
		$(this).parent().parent().prev().text(titulo);
		$(this).parent().parent().prev().attr({rel: relative});
	});
});

function listar(id, tipo , busca, idestado, idcidade, idbairro, idproduto, idtipologia, idfaixa){
	
	$('#lista' + tipo + busca).remove();
	$('#link' + tipo + busca).after('<ul id="lista' + tipo + busca + '" class="buscaLista" style="display: none;"></ul>');
	
	if(busca == 'Avancada')
	{
	    $('#itensLazer').load('/itens.aspx?e=' + idestado + '&c=' + idcidade + '&b=' + idbairro + '&p=' +idproduto,{}, function() {});
	}
	
	$('#lista' + tipo + busca).load('/vars.aspx?id=' + id + '&e=' + idestado + '&c=' + idcidade + '&b=' + idbairro + '&p=' +idproduto + '&t='+ idtipologia + '&f=' + idfaixa + '&tipo=' + tipo + '&busca=' +busca,{}, function() {
		
		$('a', this).click(function () {
			var titulo = $(this).attr('title');
			var relative = $(this).attr('rel');
			if(relative == '0') {
				$('#link' + tipo + busca).text(titulo);
				$('#link' + tipo + busca).attr({rel: relative});
			} else {				
				$('#link' + tipo + busca).text(titulo);
				$('#link' + tipo + busca).addClass('used');
				$('#link' + tipo + busca).attr({rel: relative});
				$('#lista' + tipo + busca).addClass('used');
				$('#lista' + tipo + busca).next().filter('a').addClass('active');
			}
		});
		
		
	});
}

function enviarBusca(tipo) {

	var estado = $('a#linkEstado' + tipo).attr('rel');
	var cidade = $('a#linkCidade' + tipo).attr('rel');
	var bairro = $('a#linkBairro' + tipo).attr('rel');
	var tipologia = $('a#linkTipologia' + tipo).attr('rel');
	var produto = $('a#linkProduto' + tipo).attr('rel');
	var faixa = $('a#linkFaixa' + tipo).attr('rel')
	var cep = document.getElementById("ctl00_txtInicioCepAvancado").value + document.getElementById("ctl00_txtFimCepAvancado").value ;
	var palavra = document.getElementById("ctl00_txtPalavraAvancada").value;
	var suite = 0;
	if( document.getElementById("ctl00_chkSuite").checked){suite = 1;}      
	var cobertura = 0;
	if( document.getElementById("ctl00_chkCobertura").checked){cobertura = 1;}      
	var areapriv = 0;
	if( document.getElementById("ctl00_chkArea").checked){areapriv = 1;}      
	var metragem = $('a#linkFaixa' + tipo).attr('rel');
	var itens = "";
	$('#itensLazer input').each(function (i) {				
		if(this.checked)
		{
		    itens += this.value + ',';
		}
	});
	//itens de lazer
	if(itens.length > 1){itens = itens.substr(0,itens.length -1);}

	var url = "";
	var msg = "";
    if(tipo == 'Rapida')
    {
	    url = '/busca.aspx?e=' + estado + '&c=' + cidade + '&b=' + bairro + '&p=' + produto + '&t=' + tipologia + '&f=' + faixa + '&tb=R';
	    

        if(estado == "0" || estado == ""){
            msg = "Selecione um Estado para realizar a busca!";
        }
        if(msg != ""){
            msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
            abrir(msg);
            return false;
        }
        else
        {
            window.location.href = url;  
        }
    }
    else
    {
	    url = '/busca.aspx?e=' + estado + '&c=' + cidade + '&b=' + bairro + '&p=' + produto + '&t=' + tipologia + '&f=' + faixa + '&m=' + metragem + '&tb=A&cep=' + cep + '&palavra=' + palavra + '&suite=' + suite + '&area=' + areapriv + '&cobertura=' + cobertura + '&itens='+ itens;		
	
	    if((estado == "0" || estado == "") && cep == "" && palavra == ""){
            msg = "Selecione um Estado ou uma palavra-chave para realizar a busca!";
        }
        
        if(msg != ""){
            msg = "<h2 class='Aamerelo Aalerta'>Aten&ccedil;&atilde;o:</h2>\n<p>" + msg + "</p>";
            abrir(msg);
            return false;
        }
        else {            
            window.location.href = url;    
        }		        
    }		

}

function VerTodos(status, cidade)
{
    var estado = readCookie('UF')
    
    switch(status)
    {
        case 1:
            document.getElementById("ctl00_cph_hlkLancamento").className = "lancamento";
            //document.getElementById("ctl00_cph_hlkLancamento").href = "/busca.asp?e=" + estado + "&s=" + status;
            document.getElementById("ctl00_cph_hlkLancamento").href = "/busca.aspx?e=" + estado + "&status=" + status + "&c=" + cidade;
            break;
            
        case 2:
            document.getElementById("ctl00_cph_hlkLancamento").className= "prontospramorar";
            document.getElementById("ctl00_cph_hlkLancamento").href = "/busca.aspx?e=" + estado + "&status=" + status + "&c=" + cidade;
            //document.getElementById("ctl00_cph_hlkLancamento").href = "http://imoveis.mrv.com.br/imoveis/1/8/2/" + estado + "/imoveis.aspx";
            break;

        case 3:
            document.getElementById("ctl00_cph_hlkLancamento").className = "semiprontos";
            document.getElementById("ctl00_cph_hlkLancamento").href = "/busca.aspx?e=" + estado + "&status=" + status + "&c=" + cidade;
            //document.getElementById("ctl00_cph_hlkLancamento").href = "http://imoveis.mrv.com.br/imoveis/1/8/3/" + estado + "/imoveis.aspx";
            break;
            
        case 12:
            document.getElementById("ctl00_cph_hlkLancamento").className = "pre_lancamento";
            document.getElementById("ctl00_cph_hlkLancamento").href = "/busca.aspx?e=" + estado + "&status=" + status + "&c=" + cidade;
            //document.getElementById("ctl00_cph_hlkLancamento").href = "http://imoveis.mrv.com.br/imoveis/1/8/12/" + estado + "/imoveis.aspx";
            break;
    }
}

function movewindow(){
    this.scroll(0, 0);
}
