﻿$(document).ready(function() {
    $(".jbs").mouseover(function() {
        $(".sub-jbs").show();
        $(".jbs a").css("background-position", "0 -29px");
    }).mouseout(function() {
        $(".sub-jbs").hide();
        $(".jbs a").css("background-position", "0 0");
    });
    $(".prod").mouseover(function() {
        $(".sub-prod").show();
        $(".prod a").css("background-position", "0 -29px");
    }).mouseout(function() {
        $(".sub-prod").hide();
        $(".prod a").css("background-position", "0 0");
    });

    $(".sust").mouseover(function() {
        $(".sub-sust").show();
        $(".sust a").css("background-position", "0 -29px");
    }).mouseout(function() {
        $(".sub-sust").hide();
        $(".sust a").css("background-position", "0 0");
    });

    $(".imprensa").mouseover(function() {
        $(".sub-imprensa").show();
        $(".imprensa a").css("background-position", "0 -29px");
    }).mouseout(function() {
        $(".sub-imprensa").hide();
        $(".imprensa a").css("background-position", "0 0");
    });
    $('.lst-nossa-cultura li:first').addClass("first");

    $('.hr:last').addClass("hr-none");

    /*$('.lnk-jbs-mundo').click(function(){
    window.open('_popup/Global.aspx','mywin','width=1100,height=600');
    return false;   
    });*/
    //    if (!$(".lst-marcas").children("LI").html) {
    //        $(".lst-marcas").children("LI").css("display", "none");
    //    }

    $('.lista-videos li:nth-child(4n)').css('clear', 'both');
    $('.lista-videos-2 li:nth-child(4n+1)').css('clear', 'left');
    
    $('.lista-videos a, .lista-videos-2 a').click(function() {
        var clip = $(this).attr('rel');
        var so = new SWFObject("_swf/video.swf", "mymovie", "580", "300", "8", "#ffffff");
        so.addParam("flashVars", "vidLink=../_flv/" + clip + "");
        so.write("video");
        return false;
    });


});

(function(a) { var c = (a.browser.msie ? "paste" : "input") + ".mask"; var b = (window.orientation != undefined); a.mask = { definitions: { "9": "[0-9]", a: "[A-Za-z]", "*": "[A-Za-z0-9]"} }; a.fn.extend({ caret: function(e, f) { if (this.length == 0) { return } if (typeof e == "number") { f = (typeof f == "number") ? f : e; return this.each(function() { if (this.setSelectionRange) { this.focus(); this.setSelectionRange(e, f) } else { if (this.createTextRange) { var g = this.createTextRange(); g.collapse(true); g.moveEnd("character", f); g.moveStart("character", e); g.select() } } }) } else { if (this[0].setSelectionRange) { e = this[0].selectionStart; f = this[0].selectionEnd } else { if (document.selection && document.selection.createRange) { var d = document.selection.createRange(); e = 0 - d.duplicate().moveStart("character", -100000); f = e + d.text.length } } return { begin: e, end: f} } }, unmask: function() { return this.trigger("unmask") }, mask: function(j, d) { if (!j && this.length > 0) { var f = a(this[0]); var g = f.data("tests"); return a.map(f.data("buffer"), function(l, m) { return g[m] ? l : null }).join("") } d = a.extend({ placeholder: "_", completed: null }, d); var k = a.mask.definitions; var g = []; var e = j.length; var i = null; var h = j.length; a.each(j.split(""), function(m, l) { if (l == "?") { h--; e = m } else { if (k[l]) { g.push(new RegExp(k[l])); if (i == null) { i = g.length - 1 } } else { g.push(null) } } }); return this.each(function() { var r = a(this); var m = a.map(j.split(""), function(x, y) { if (x != "?") { return k[x] ? d.placeholder : x } }); var n = false; var q = r.val(); r.data("buffer", m).data("tests", g); function v(x) { while (++x <= h && !g[x]) { } return x } function t(x) { while (!g[x] && --x >= 0) { } for (var y = x; y < h; y++) { if (g[y]) { m[y] = d.placeholder; var z = v(y); if (z < h && g[y].test(m[z])) { m[y] = m[z] } else { break } } } s(); r.caret(Math.max(i, x)) } function u(y) { for (var A = y, z = d.placeholder; A < h; A++) { if (g[A]) { var B = v(A); var x = m[A]; m[A] = z; if (B < h && g[B].test(x)) { z = x } else { break } } } } function l(y) { var x = a(this).caret(); var z = y.keyCode; n = (z < 16 || (z > 16 && z < 32) || (z > 32 && z < 41)); if ((x.begin - x.end) != 0 && (!n || z == 8 || z == 46)) { w(x.begin, x.end) } if (z == 8 || z == 46 || (b && z == 127)) { t(x.begin + (z == 46 ? 0 : -1)); return false } else { if (z == 27) { r.val(q); r.caret(0, p()); return false } } } function o(B) { if (n) { n = false; return (B.keyCode == 8) ? false : null } B = B || window.event; var C = B.charCode || B.keyCode || B.which; var z = a(this).caret(); if (B.ctrlKey || B.altKey || B.metaKey) { return true } else { if ((C >= 32 && C <= 125) || C > 186) { var x = v(z.begin - 1); if (x < h) { var A = String.fromCharCode(C); if (g[x].test(A)) { u(x); m[x] = A; s(); var y = v(x); a(this).caret(y); if (d.completed && y == h) { d.completed.call(r) } } } } } return false } function w(x, y) { for (var z = x; z < y && z < h; z++) { if (g[z]) { m[z] = d.placeholder } } } function s() { return r.val(m.join("")).val() } function p(y) { var z = r.val(); var C = -1; for (var B = 0, x = 0; B < h; B++) { if (g[B]) { m[B] = d.placeholder; while (x++ < z.length) { var A = z.charAt(x - 1); if (g[B].test(A)) { m[B] = A; C = B; break } } if (x > z.length) { break } } else { if (m[B] == z[x] && B != e) { x++; C = B } } } if (!y && C + 1 < e) { r.val(""); w(0, h) } else { if (y || C + 1 >= e) { s(); if (!y) { r.val(r.val().substring(0, C + 1)) } } } return (e ? B : i) } if (!r.attr("readonly")) { r.one("unmask", function() { r.unbind(".mask").removeData("buffer").removeData("tests") }).bind("focus.mask", function() { q = r.val(); var x = p(); s(); setTimeout(function() { if (x == j.length) { r.caret(0, x) } else { r.caret(x) } }, 0) }).bind("blur.mask", function() { p(); if (r.val() != q) { r.change() } }).bind("keydown.mask", l).bind("keypress.mask", o).bind(c, function() { setTimeout(function() { r.caret(p(true)) }, 0) }) } p() }) } }) })(jQuery);
jQuery(function($) {
    $(".maskDDD").mask("99", { placeholder: " " });
    $(".maskTel").mask("9999-9999", { placeholder: " " });
    $(".maskCEP").mask("99999", { placeholder: " " });
    $(".maskDig").mask("999", { placeholder: " " });
    $(".maskANO").mask("9999", { placeholder: " " });
    $(".maskCEPComp").mask("99999-999", { placeholder: " " });
    $(".maskCPF").mask("999.999.999-99", { placeholder: " " });
    $(".maskCNPJ").mask("99.999.999/9999-99", { placeholder: " " });
    $(".maskTelComp").mask("(99)9999-9999", { placeholder: " " });
});

function redirectMundo(opcao){
    var lnkMundo = document.getElementById('Topo_slcMundo');
    if(lnkMundo.value == 'Default.aspx') { window.location = 'Default.aspx'; }
    else window.open(opcao,'_blank');
}

function redirectSite(opcao){
    var lnkSite = document.getElementById('Topo_slcSite');
    if(lnkSite.value == 'Default.aspx') { window.location = 'Default.aspx'; }
    else window.open(opcao,'_blank');
}



//----------------------------------------- Valida CNPJ --------------------------------------------//

function validarCNPJ(oSrc, args) {

    return args.IsValid = valida_cnpj(args.Value);

}

function valida_cnpj(cnpj) {

    cnpj = cnpj.replace("/", "");
    cnpj = cnpj.replace("/", "");
    cnpj = cnpj.replace("/", "");
    cnpj = cnpj.replace(",", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace(".", "");
    cnpj = cnpj.replace("-", "");
    cnpj = cnpj.replace("-", "");
    cnpj = cnpj.replace("-", "");
    cnpj = cnpj.replace("-", "");
    cnpj = cnpj.replace("-", "");

    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
    digitos_iguais = 1;
    if (cnpj.length < 14 && cnpj.length < 15)
        return false;
    for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
        digitos_iguais = 0;
        break;
    }
    if (!digitos_iguais) {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0, tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--) {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0)) {
            return false;
        }

        tamanho = tamanho + 1;
        numeros = cnpj.substring(0, tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--) {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1)) {
            return false;
        }
        return true;
    }
    else
        return false;
}


// Função que valida a data com tres campos
function VerificandoData(dia, mes, ano) {

    var bissexto = 0;

    var myDate = new Date();
    myDate.setFullYear(ano, mes - 1, dia);
    var today = new Date();
    if (myDate > today) {
        return false;
    }

    if (dia > 0 && dia < 32 && mes > 0 && mes < 13) {
        if ((ano > 1900) && (ano < 2100)) {
            switch (mes) {
                case '01':
                case '03':
                case '05':
                case '07':
                case '08':
                case '10':
                case '12':
                    if (dia <= 31) {
                        return true;
                    }
                    break

                case '04':
                case '06':
                case '09':
                case '11':
                    if (dia <= 30) {
                        return true;
                    }
                    break
                case '02':
                    /* Validando ano Bissexto / fevereiro / dia */
                    if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) {
                        bissexto = 1;
                    }
                    if ((bissexto == 1) && (dia <= 29)) {
                        return true;
                    }
                    if ((bissexto != 1) && (dia <= 28)) {
                        return true;
                    }
                    break
            }
        }
    }

    return false;    
}


function validarDtaNasc(oSrc, args) {
    var dia = document.getElementById('ctl00_ContentPlaceHolder1_txtDead1_2').value;
    var mes = document.getElementById('ctl00_ContentPlaceHolder1_txtDead2_2').value;
    var ano = document.getElementById('ctl00_ContentPlaceHolder1_txtDead3_2').value;
    return args.IsValid = VerificandoData(dia, mes, ano);
}

function SetFocus() {    
    document.getElementById("ctl00_ContentPlaceHolder1_txtPalavraChave").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_textdata_inicio").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_textdata_termino").value = "";
}

function SetRadioPeriodo() {    
    document.getElementById("ctl00_ContentPlaceHolder1_txtPalavraChave").value = "";
    $("#ctl00_ContentPlaceHolder1_RadioPeriodo").attr("checked", "checked");
    $("#ctl00_ContentPlaceHolder1_RadioPalavraChave").removeAttr("checked");
}

function SetPalavraChave() {
    
        SetFocus();
        $("#ctl00_ContentPlaceHolder1_RadioPalavraChave").attr("checked", "checked");
        $("#ctl00_ContentPlaceHolder1_RadioPeriodo").removeAttr("checked");    
}

function ValidarBusca() {
    if (document.getElementById("ctl00_ContentPlaceHolder1_RadioPeriodo").checked == true) {
        if (document.getElementById("ctl00_ContentPlaceHolder1_textdata_inicio").value != "") {
            return true;
        }
        else {
            alert("É necessário escolher uma data para pesquisa.");
            return false;
        }
    }
    else if (document.getElementById("ctl00_ContentPlaceHolder1_RadioPalavraChave").checked == true) {
        if (document.getElementById("ctl00_ContentPlaceHolder1_txtPalavraChave").value != "") {
            return true;
        }
        else {
            alert("É necessário digitar uma palavra para pesquisa.");
            return false;
        }
    }
    else {       
        return true;
    }
}


//Aceita apenas números
function SoNumeros(event)//Aceita apenas números
{
    var tecla;

    tecla = (event.keyCode) ? event.keyCode : event.which;

    var teclaAux = String.fromCharCode(tecla);

    if (!((teclaAux >= 0) && (teclaAux <= 9)) || teclaAux == ' ') {
        if (tecla == 13 || tecla == 8) {
            return true;
        } else {

            if (window.event) {
                window.event.keyCode = 0;

            }
            event.returnValue = false;
            return false;
        }
    }
}

function validate(evt) {
    var theEvent = evt || window.event;
    var key = (theEvent.which) ? theEvent.which : theEvent.keyCode
    key = String.fromCharCode(key);
    var regex = /[0-9]|\,|\./;
    if ([evt.keyCode || evt.which] == 8 || evt.keyCode == 22 || evt.keyCode == 23) //this is to allow backspace  
        return true;
    if (!regex.test(key)) {
        theEvent.returnValue = false;
        theEvent.preventDefault();
    }
}  

//Moeda
function MascaraMoeda(objTextBox, SeparadorDecimal, e) {
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    //alert(whichCode);

/*
    alert(whichCode);
    if (whichCode == 0) {
        
    }
*/    
    if(whichCode == 0 || whichCode == 8) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave  
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    if (len >= objTextBox.maxLength) { return false; }
    
    for (i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for (; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i)) != -1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0' + SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0' + SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += "";
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
            objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}  

// mmoeda
//function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e) {
//    var sep = 0;
//    var key = '';
//    var i = j = 0;
//    var len = len2 = 0;
//    var strCheck = '0123456789';
//    var aux = aux2 = '';
//    var whichCode = (window.Event) ? e.which : e.keyCode;
//    if (whichCode == 13) return true;
//    key = String.fromCharCode(whichCode); // Valor para o código da Chave  
//    if (strCheck.indexOf(key) == -1) return false; // Chave inválida  
//    len = objTextBox.value.length;
//    for (i = 0; i < len; i++)
//        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
//    aux = '';
//    for (; i < len; i++)
//        if (strCheck.indexOf(objTextBox.value.charAt(i)) != -1) aux += objTextBox.value.charAt(i);
//    aux += key;
//    len = aux.length;
//    if (len == 0) objTextBox.value = '';
//    if (len == 1) objTextBox.value = '0' + SeparadorDecimal + '0' + aux;
//    if (len == 2) objTextBox.value = '0' + SeparadorDecimal + aux;
//    if (len > 2) {
//        aux2 = '';
//        for (j = 0, i = len - 3; i >= 0; i--) {
//            if (j == 3) {
//                aux2 += SeparadorMilesimo;
//                j = 0;
//            }
//            aux2 += aux.charAt(i);
//            j++;
//        }
//        objTextBox.value = '';
//        len2 = aux2.length;
//        for (i = len2 - 1; i >= 0; i--)
//            objTextBox.value += aux2.charAt(i);
//        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
//    }
//    return false;
//}  
