﻿$(function(){
	// ========== Coloca o tamanho na paginação ==========
	var numLiPag = $('.listaPaginacao ol li:not(.sep)').length;
	var wPag = numLiPag * 22 + (numLiPag - 1);
	$('.listaPaginacao ol').css('width',wPag+'px');

	var external = '<span class="lnkExternal">Link Externo</span>';
	$("a[rel='external']").each(function(){
		$(this).attr('target','_blank');
		$(this).after(external);
	});
	
	$("div"+ $("div.boxAbas li.on a").attr("href")).show();
	$("div.boxAbas > ul > li").click(function (event){
	    event.preventDefault();
	    var id = $(this).find("a").attr("href");
	    $("div.boxAbas li").removeClass("on");    
	    $("div.conteudo:visible").not(id).each(function (){
	        $(this).hide();
	        $("div"+ id).fadeIn("slow");    
	    });
	    $(this).addClass("on");
		var idVT = '#vt_' + id.replace('#','');
		$("div.box1:visible").not(idVT).each(function (){
	        $(this).hide();
	        $("div"+ idVT).fadeIn("slow");    
	    });
	});
	
	var href = location.href;
	if(href.indexOf("#") > 0){
		var arrHref = href.split('#');
		$("a[href='#"+arrHref[1]+"']").parent().click()
	}

    $('.comboLine select').combobox( { 
        comboboxContainerClass: "comboboxContainer", 
        comboboxValueContainerClass: "comboboxValueContainer", 
        comboboxValueContentClass: "comboboxValueContent", 
        comboboxDropDownClass: "comboboxDropDownContainer", 
        comboboxDropDownButtonClass: "comboboxDropDownButton", 
        comboboxDropDownItemClass: "comboboxItem", 
        comboboxDropDownItemHoverClass: "comboboxItemHover", 
        comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader", 
        comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer", 
        animationType: "fadeIn", 
        width: "110px"
    });
    
    $('.comboLine2 select').combobox( { 
        comboboxContainerClass: "comboboxContainer", 
        comboboxValueContainerClass: "comboboxValueContainer", 
        comboboxValueContentClass: "comboboxValueContent", 
        comboboxDropDownClass: "comboboxDropDownContainer", 
        comboboxDropDownButtonClass: "comboboxDropDownButton", 
        comboboxDropDownItemClass: "comboboxItem", 
        comboboxDropDownItemHoverClass: "comboboxItemHover", 
        comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader", 
        comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer", 
        animationType: "fadeIn", 
        width: "155px"
    });
    
    $('.combolineAuto select').each(function() {
        $(this).combobox( { 
            comboboxContainerClass: "comboboxContainer", 
            comboboxValueContainerClass: "comboboxValueContainer", 
            comboboxValueContentClass: "comboboxValueContent", 
            comboboxDropDownClass: "comboboxDropDownContainer", 
            comboboxDropDownButtonClass: "comboboxDropDownButton", 
            comboboxDropDownItemClass: "comboboxItem", 
            comboboxDropDownItemHoverClass: "comboboxItemHover", 
            comboboxDropDownGroupItemHeaderClass: "comboboxGroupItemHeader", 
            comboboxDropDownGroupItemContainerClass: "comboboxGroupItemContainer", 
            animationType: "fadeIn", 
            width: $(this).width()
        })
    })
    
    $('.lstAccordion dd, .listaAutoLine dd').hide();
    $('.lstAccordion dt a, .listaAutoLine dt a').click(function(){
        $(this).toggleClass('on').parent().next().slideToggle();
    })
    
    $('#boxBusca input')
        .focus(function(){
            if($(this).val() == 'O que você Procura')
                $(this).val('');
        })
        .blur(function(){
            if($(this).val() == '' || $(this).val() == ' ')
                $(this).val('O que você Procura');
        })
        
    /* TAMANHO DA FONTE */    
    if( $.cookie('FontSize') > 1)
        var fonteAtual = $.cookie('FontSize');
    else
        var fonteAtual = 1;
    	
    var fontMin = 1;
    var fontMax = 3;
    var elements = new Array();
    var flag = null;
    
    var strElementos = "#conteudo p, #conteudo h2, #conteudo td, #conteudo dt *, #conteudo dd ul *"
    
    $(strElementos).each(function(i){
	    var fontSize = $(this).css("font-size");			
	    elements[i] = parseInt(fontSize.substr(0,2));
    });
	
    if(fonteAtual > 1){
	    $(".zoomOutFont").removeClass("btnOff");
	    $(strElementos).each(function(i){
		    var n = parseInt(elements[i],10) + ( parseInt(fonteAtual,10) - 1 );
		    $(this).css("font-size", n + "px");
		    elements[i] = n;
	    });
	    if(fonteAtual == fontMax){
		    $(".zoomInFont").addClass("btnOff");
	    }
    }

    $(".fontSize .menos").click(function(){
	    $(".zoomInFont").removeClass("btnOff");
	    if(fonteAtual > fontMin){
		    $(strElementos).each(function(i){
			    var n = parseInt(elements[i],10) - 1;
			    $(this).css("font-size", n + "px");
			    elements[i] = n;
		    });
		    fonteAtual = parseInt(fonteAtual,10) - 1;
		    if(fonteAtual == fontMin){
			    $(".zoomOutFont").addClass("btnOff");
		    }
	    }
	    var dataExpCookie = new Date();
	    var min = dataExpCookie.getMinutes();
	    min = min + 5;
	    dataExpCookie.setMinutes(min);
	    $.cookie('FontSize',fonteAtual,{path:'/',expires:dataExpCookie});
    });
    $(".fontSize .mais").click(function(){
	    $(".zoomOutFont").removeClass("btnOff");
	    if(fonteAtual < fontMax){
		    $(strElementos).each(function(i){
			    var n = parseInt(elements[i],10) + 1;
			    $(this).css("font-size", n + "px");
			    elements[i] = n;
		    });
		    fonteAtual = parseInt(fonteAtual,10) + 1;
		    if(fonteAtual == fontMax){
			    $(".zoomInFont").addClass("btnOff");
		    }
	    }
	    var dataExpCookie = new Date();
	    var min = dataExpCookie.getMinutes();
	    min = min + 5;
	    dataExpCookie.setMinutes(min);
	    $.cookie('FontSize',fonteAtual,{path:'/',expires:dataExpCookie});
    });
    
    $('.boxRound input').click(function(event){    
        event.preventDefault();        
        var strLink = $(this).siblings().find('select').val();        
        window.open('../popup/popup_autoline.aspx?'+strLink,'popup','top=60,width=775,height=550,directories=0,location=0,menubar=1,resizable=0,scrollbars=0,status=0,toolbar=0,marginleft=0,margintop=0');
    })
    
    $('#modRegulamento , #modCG , #modCG2 , #modCG3').jqm();
    
    $('#modLogin').jqm({
        onShow: function(hash){
            hash.w.show()
            parent.barra.fieldFocus('txtUsuario');
        }
    })
	$('#modLogin').jqmAddTrigger('.lnkModLogin');
	$('#modCG').jqmAddTrigger('.lnkModCG');
	$('#modCG2').jqmAddTrigger('.lnkModCG2');
	$('#modCG3').jqmAddTrigger('.lnkModCG3');	
    
    /* TABELA PADRÃO */
	$('.tableAlternateCol tr th:last-child, .tableAlternateCol tr td:last-child').addClass('colRight');
	$('.tableAlternateCol tbody tr:odd').addClass('odd');
	$('.boxResultado table').each(function (){
	    $(this).find('tr:not(.ultimo):even').addClass('even');
	});

	$("#caminhopao li a[href='']").each(function(){
		var t = $(this).text();
		$(this).parent().append(t);
		$(this).remove();
	});
	
	/* SEÇÃO TROCA DE GARANTIA - DOCUMENTOS */
	$('.lnkCDC').next().hide();
	$('.lnkCDC').addClass('prodSubBullet01');
    $('.lnkCDC').click(function(){
        if($(this).next().is(':hidden')){
            $(this).next().slideDown('fast');
            $(this).addClass('prodSubBullet02');
        }
        else{
            $(this).next().slideUp('fast');
            $(this).removeClass('prodSubBullet02');
        };  
     });
    $('.lnkLeasing').next().hide();
	$('.lnkLeasing').addClass('prodSubBullet01');
    $('.lnkLeasing').click(function(){
        if($(this).next().is(':hidden')){
            $(this).next().slideDown('fast');
            $(this).addClass('prodSubBullet02');
        }
        else{
            $(this).next().slideUp('fast');
            $(this).removeClass('prodSubBullet02');
        };  
     });
     /* SEGUROS ABA 1 */
     $('.boxContent1, .boxContent2, .boxContent3, .boxContent5').hide();
     $('.lnkProdSegurosProtecaoPessoalAba1').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba2').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba3').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPessoalAba8').parent().removeClass('selected');
        $('.boxContent').hide();
        $('.boxContent1').fadeIn("slow");
        $('.boxContent2').hide();
        $('.boxContent3').hide();
		$('.boxContent5').hide();
     });
     $('.lnkProdSegurosProtecaoPessoalAba2').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba1').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba3').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPessoalAba8').parent().removeClass('selected');
        $('.boxContent').hide();
        $('.boxContent1').hide();
        $('.boxContent2').fadeIn("slow");
        $('.boxContent3').hide();
		$('.boxContent5').hide();
     });
     $('.lnkProdSegurosProtecaoPessoalAba3').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba1').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba2').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPessoalAba8').parent().removeClass('selected');
        $('.boxContent').hide();
        $('.boxContent1').hide();
        $('.boxContent2').hide();
        $('.boxContent3').fadeIn("slow");
		$('.boxContent5').hide();
     });
	 $('.lnkProdSegurosProtecaoPessoalAba8').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba1').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba2').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPessoalAba3').parent().removeClass('selected');
        $('.boxContent').hide();
        $('.boxContent1').hide();
        $('.boxContent2').hide();
        $('.boxContent3').hide();
		$('.boxContent5').fadeIn("slow");
     });
     /* SEGUROS ABA 2 */
     $('.boxContent6, .boxContent7, .boxContent8, .boxContent9, .boxContent10').hide();
     $('.lnkProdSegurosProtecaoPremiadaAba4').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba5').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba6').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba7').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPremiadaAba9').parent().removeClass('selected');
        $('.boxContent4').hide();
        $('.boxContent6').fadeIn("slow");
        $('.boxContent7').hide();
        $('.boxContent8').hide();
        $('.boxContent9').hide();
		$('.boxContent10').hide();
     });
     $('.lnkProdSegurosProtecaoPremiadaAba5').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba4').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba6').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba7').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPremiadaAba9').parent().removeClass('selected');
        $('.boxContent4').hide();
        $('.boxContent6').hide();
        $('.boxContent7').fadeIn("slow");
        $('.boxContent8').hide();
        $('.boxContent9').hide();
		$('.boxContent10').hide();
     });
     $('.lnkProdSegurosProtecaoPremiadaAba6').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba4').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba5').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba7').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPremiadaAba9').parent().removeClass('selected');
        $('.boxContent4').hide();
        $('.boxContent6').hide();
        $('.boxContent7').hide();
        $('.boxContent8').fadeIn("slow");
        $('.boxContent9').hide();
		$('.boxContent10').hide();
     });
     $('.lnkProdSegurosProtecaoPremiadaAba7').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba4').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba5').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba6').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPremiadaAba9').parent().removeClass('selected');
        $('.boxContent4').hide();
        $('.boxContent6').hide();
        $('.boxContent7').hide();
        $('.boxContent8').hide();
        $('.boxContent9').fadeIn("slow");
		$('.boxContent10').hide();
     });
	 $('.lnkProdSegurosProtecaoPremiadaAba9').click(function(){
        $(this).parent().addClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba4').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba5').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba6').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPremiadaAba7').parent().removeClass('selected');
        $('.boxContent4').hide();
        $('.boxContent6').hide();
        $('.boxContent7').hide();
        $('.boxContent8').hide();
        $('.boxContent9').hide();
		$('.boxContent10').fadeIn("slow");
     });
     $('.aba01').click(function(){
        $('.lnkProdSegurosProtecaoPessoalAba1').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba2').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPessoalAba3').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPessoalAba8').parent().removeClass('selected');
        $('.boxContent').fadeIn("slow");
        $('.boxContent1').hide();
        $('.boxContent2').hide();
        $('.boxContent3').hide();
		$('.boxContent5').hide();
     });
     $('.aba02').click(function(){
        $('.lnkProdSegurosProtecaoPremiadaAba4').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba5').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba6').parent().removeClass('selected');
        $('.lnkProdSegurosProtecaoPremiadaAba7').parent().removeClass('selected');
		$('.lnkProdSegurosProtecaoPremiadaAba9').parent().removeClass('selected');
        $('.boxContent4').fadeIn("slow");
        $('.boxContent6').hide();
        $('.boxContent7').hide();
        $('.boxContent8').hide();
        $('.boxContent9').hide();
		$('.boxContent10').hide();
     });
});

function showFinasaClique() {
    $('#acessoRapidoDrop').show();
}

function hideFinasaClique() {
    $('#acessoRapidoDrop').hide();
}

function showAjuda() {
	$('#ajudaLogin').show();
}

function hideAjuda() {
    $('#ajudaLogin').hide();
}


// MASCARAS
/*
    onkeypress="mascara(this,soNumeros)"
    onkeypress="mascara(this,telefone)" maxlength="14"
    onkeypress="mascara(this,cpf)" maxlength="14"
    onkeypress="mascara(this,cep)" maxlength="9" 
*/

function mascara(o,f)
{
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara()
{
    v_obj.value=v_fun(v_obj.value)
}

function soNumeros(v){
    v = v.replace(/\D/g,"")
    return v;
}

function cep(v){
    v = v.replace(/\D/g,"")                //Remove tudo o que não é dígito
    v = v.replace(/(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function data(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos

    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1.$2")       //Coloca um ponto entre o segundo e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1/$2")       //Coloca uma barra entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{4})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o quarto e o quinto dígitos
    return v
}

function popup(url, width, height) {
    window.open(url, 'popup', 'top=200, left=200,width=' + width + ',height=' + height + ',directories=0,location=0,menubar=1,resizable=0,scrollbars=1,status=0,toolbar=0,marginleft=0,margintop=0');
}
function troca(str, strsai, strentra) {
    while (str.indexOf(strsai) > -1) {
        str = str.replace(strsai, strentra);
    }
    return str;
}
function FormataMoeda(w,e,m,r,a){

// Cancela se o evento for Backspace
if (!e) var e = window.event
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;

// Variáveis da função
var txt = (!r) ? w.value.replace(/[^\d]+/gi,'') : w.value.replace(/[^\d]+/gi,'').reverse();
var mask = (!r) ? m : m.reverse();
var pre = (a ) ? a.pre : "";
var pos = (a ) ? a.pos : "";
var ret = "";

if(code == 9 || code == 8 || txt.length == mask.replace(/[^#]+/g,'').length) return false;

// Loop na máscara para aplicar os caracteres
for(var x=0,y=0, z=mask.length;x<z && y<txt.length;){
if(mask.charAt(x)!='#'){
ret += mask.charAt(x); x++;
} else{
ret += txt.charAt(y); y++; x++;
}
}

// Retorno da função
ret = (!r) ? ret : ret.reverse()
w.value = pre+ret;
}

// Novo método para o objeto 'String'
String.prototype.reverse = function(){
return this.split('').reverse().join('');
}
    
    
    //

function identFrames() {
    var nomesf = new Array();
    nomesf[0] = "barra";
    nomesf[1] = "conteudo";
    nomesf[2] = "barraBottom";
    var nframes = 3;
    var endsite = "http://www.finasa.com.br"

    try 
    {
        if(parent.frames.length > 0)
        {
            if(parent.frames.length != nframes)
            {
                top.location.href=endsite;
            }
            for(x=0;x<parent.frames.length;x++)
            {
                if(nomesf[x] != parent.frames[x].name)
                {
                    top.location.href=endsite;
                };
            };
        };
    }
    catch(e)
    {
        var detect = navigator.userAgent.toLowerCase();
        if(detect.indexOf('mac') < 1)
        {
            top.location.href=endsite;
        };
    };
};
identFrames();