// FONTE SIZE 
if (!$('#home').length) { var fonteAtual = $.cookie('FontSize'); }


// onload
$(function() {
    var validadorForm;
    // Chamada de plugins
    if (!$('#home').length) {
        $(':text.cpf').setMask('cpf');
        $(':text.cnpj').setMask('cnpj');
        $(':text.rg').setMask({ mask: '9999999999' });
        $(':text.cep').setMask('cep');
        $(':text.ddd').setMask({ mask: '99' });
        $(':text.telefone').setMask({ mask: '99999999' });
        $(':text.dia, :text.mes').setMask({ mask: '99' });
        $(':text.ano').setMask({ mask: '9999' });
        $(':text.numero').setMask({ mask: '999999999' });
        $(':text.rendaMensal, :text.valorFaturamento').setMask('decimal');
    }

    //SOMENTE LETRA
    $(':text.letras').keypress(function(event) {
        var teclaCode = event.keyCode;
        if (teclaCode > 47 && teclaCode < 58) 
            return false;
        else
            return true;
    });

    // Lista com conteudo expansivel
    $('.lstExpand dt').click(function() {
        $(this).find("a").blur();
        if (!$(this).hasClass('on')) {
            $('.lstExpand dd.on').slideUp(300, function() {
                $(this).prev('dt').removeClass('on');
                $(this).removeClass('on');
            });
            $(this).next('dd').slideDown(300, function() {
                $(this).prev('dt').addClass('on');
                $(this).addClass('on');
            });
        } else {
            $('.lstExpand dd.on').slideUp(300, function() {
                $(this).prev('dt').removeClass('on');
                $(this).removeClass('on');
            });
        }
    });

    // combo de troca de tipo de conta
    $('#boxPerfilConta select').change(function() {
        var location = $(this).val();
        if (location != '') {
            window.location.href = location;
        }
    })

    var $parentDiv = $('div#boxCont');

    // FONTE SIZE
    if (fonteAtual == 'fS1' || !fonteAtual) {
        $parentDiv.attr('class', '');
        $parentDiv.addClass('fS1');
        $parentDiv.css('font-size', '100%');
        $('.lnkTxtDec').addClass('fsNone');
    } else if (fonteAtual == 'fS2') {
        $parentDiv.attr('class', '');
        $parentDiv.addClass('fS2');
        $parentDiv.css('font-size', '110%');
    } else if (fonteAtual == 'fS3') {
        $parentDiv.attr('class', '');
        $parentDiv.addClass('fS3');
        $parentDiv.css('font-size', '120%');
        $('.lnkTxtInc').addClass('fsNone');
    }
    $("a.lnkTxtDec,a.lnkTxtInc").click(function() {
        fontSize($(this).attr('class'));
    });
    $('.lstTpHDA li').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
    $('.lstTpHDA li ul').wrap("<div class='boxW'></div>");
    $('.boxW').prepend("<div class='cntTL'></div><div class='cntTR'></div><div class='bgT'></div>");
    $('.lstTpHDA li ul').wrap("<div class='bgL'><div class='bgR'><div class='bgC'></div></div></div>");
    $('.boxW').append("<div class='cntBL'></div><div class='cntBR'></div><div class='bgB'></div>");
    $('.lstTpHDA li ul').show();
    // Link de impressão
    $('.lnkPrint').click(function() {
        var ttlPrint = $(this).attr('rel');
        var contPrint = $(this).attr('rev');
        imprimir(ttlPrint, contPrint, window.location.href);
        return false;
    });
    // Links para expandir conteudo escondido
    $('.lnkContHidden').click(function() {
        var contHidden = $(this).attr('href');
        $(contHidden).animate({ "height": "toggle", "opacity": "toggle" }, "slow");
        return false;
    });
});

function LimpaCamposPasso1() {
    ResetPasso1();
    document.forms[0].reset();
    $(".boxErro").fadeOut();
    $(".boxMsgAgencias").fadeOut();
    $(".boxAgenciasEncontradas").fadeOut();
    $(".boxIn :text.frmTxt, .boxIn :select.frmSel, .inputRadio div").removeClass("fieldErro");
    $(":text:first:not(:hidden)").focus();
    validadorForm = true;
    return false;
}

function LimpaCamposPasso2() {
    document.forms[0].reset();
    $(".boxErro").fadeOut();
    $(".boxErro2").fadeOut();
    $(".boxIn :text.frmTxt, .boxIn :select.frmSel, .inputRadio div").removeClass("fieldErro");
    $(":text:first:not(:hidden)").focus();
    validadorForm = true;
    return false;
}

// Funcao Font size
function fontSize(btnTp) {
    var $parentDiv = $('div#boxCont');
    if (btnTp == 'lnkTxtInc') {
        fonteAtual = $parentDiv.attr('class');
        if (fonteAtual == 'fS1') {
            $parentDiv.attr('class', '');
            $parentDiv.addClass('fS2');
            $parentDiv.css('font-size', '110%');
            $('.fsNone').removeClass('fsNone');
        } else if (fonteAtual == 'fS2') {
            $parentDiv.attr('class', '');
            $parentDiv.addClass('fS3');
            $parentDiv.css('font-size', '120%');
            $('.lnkTxtInc').addClass('fsNone');
        }
    }
    if (btnTp == 'lnkTxtDec') {
        fonteAtual = $parentDiv.attr('class');
        if (fonteAtual == 'fS3') {
            $parentDiv.attr('class', '');
            $parentDiv.addClass('fS2');
            $parentDiv.css('font-size', '110%');
            $('.fsNone').removeClass('fsNone');
        } else if (fonteAtual == 'fS2') {
            $parentDiv.attr('class', '');
            $parentDiv.addClass('fS1');
            $parentDiv.css('font-size', '100%');
            $('.lnkTxtDec').addClass('fsNone');
        }
    }
    $.cookie('FontSize', $parentDiv.attr('class'), { path: '/', expires: 30 });
}

function popups(pg, nome, fs, w, h, rolagem) {
    if (fs) { // fullscreen
        var w = screen.availWidth, h = screen.availHeight;
        var winObj = window.open(pg, nome, 'width=' + w + ',height=' + h + ',directories=0,location=0,menubar=0,resizable=0,scrollbars=' + rolagem + ',status=0,toolbar=0,marginleft=0,margintop=0,left=0,top=0');
        with (winObj) { moveTo(0, 0); resizeTo(w, h); focus(); }
    } else { // popup normal
        var winObj = window.open(pg, nome, 'width=' + w + ',height=' + h + ',directories=0,location=0,menubar=0,resizable=0,scrollbars=' + rolagem + ',status=0,toolbar=0,marginleft=0,margintop=0,left=' + (((screen.width - w) / 2) + -10) + ',top=' + (((screen.height - h) / 2) + -30));
        winObj.focus();
    }
}

function Mapa(cod, tipo) {
    popups('http://webservices.maplink2.com.br/Bradesco/VerMapa.aspx?id=' + cod + '&shapeP=' + tipo, 'Mapa', '', 550, 500, 'yes');
}

//FUNCAO QUE VALIDA DATA
function DataValida(objValue) {
    var expReg = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    var resultado = objValue.match(expReg);
    return (resultado != null);
}


//Impressão
var Today = new Date();
var MonthAtual = (Today.getMonth() + 1);
if (MonthAtual < 10) { MonthAtual = '0' + MonthAtual; }
function imprimir(ttlElement, printElement, urlElement) {
    popimpressao = window.open('', '', 'width=740,height=450,left=0,top=0,scrollbars=yes,resizable=yes,menubar=no,toolbar=no');
    var txtTtl = 'Bradesco Abra Sua Conta';
    var printFooter = Today.getDate() + '/' + MonthAtual + '/' + Today.getFullYear() + '<br />Site: ' + urlElement;
    with (popimpressao.document) {
        write('<html><head><title>' + txtTtl + '</title>');
        write('<link rel="stylesheet" href="../css/print.css" type="text/css">');
        write('</head>');
        write('<body>');
        write('<img src="../../imagens/geral/logo_impressao.gif" alt="Bradesco | Abra sua Conta" borde="0" />');
        write('<div id="printContent">');
        write('<h2>' + ttlElement + '</h2>');
        write($(printElement).html());
        write('<div id="printFooter">Impresso em: ' + printFooter + '</div>');
        write('</div></body></html>');
        close();
    }
    popimpressao.print();
    popimpressao.close();
}
