﻿$(document).ready(function () {

    $('.btnComoChegar').click(function () {
        setTimeout(function () {
            $('.mapa iframe').show();
        }, 2000)
    });

    // LINK ATIVO
    paginaAtiva = window.location + '';
    paginaAtiva = paginaAtiva.split('/').pop();
    if (paginaAtiva != '') {
        var classe = $('#menu a[href="' + paginaAtiva + '"]').attr('class')
        $('#menu a[href="' + paginaAtiva + '"]').addClass(classe + '_ativo');
        $('.submenu a[href="' + paginaAtiva + '"]').addClass('ativo');
        $('.menuEquipe a[href="' + paginaAtiva + '"]').addClass('ativo');
    }

    $('.listaEquipe dt:first').css('background', 'none');
    $('.resultEnquete tbody tr:first-child').addClass('first')

    // PRE-LOAD DE IMG's
    var img = new Array();

    img[0] = 'menu-over-1.png';
    img[1] = 'menu-over-2.png';
    img[2] = 'menu-over-3.png';
    img[3] = 'menu-over-4.png';
    img[4] = 'menu-over-5.png';
    img[5] = 'menu-over-6.png';
    img[6] = 'menu-over-7.png';
    img[7] = 'radio-btn-over.gif';
    img[8] = 'bullet-menos.gif';
    img[9] = 'modal-bg.png';
    img[10] = 'modal-top.png';
    img[11] = 'modal-bottom.png';
    img[12] = 'btn-fechar.gif';
    img[13] = 'ico-como-chegar.gif';
    img[14] = 'modal-canto-1.png';
    img[15] = 'modal-canto-2.png';
    img[16] = 'modal-canto-3.png';
    img[17] = 'modal-canto-4.png';
    img[18] = 'menu-listas-over.gif';

    if ($('.select').is('div')) {
        img[20] = 'bg-options.png';
        img[21] = 'bg-options-bottom.png';
        img[22] = 'bg-options-top.png';
        img[23] = 'marcador-select.gif';
        img[24] = 'bg-options-top-2.png';
        img[25] = 'bg-options-bottom-2.png';
    }

    if ($('.modalGaleria').is('div')) {
        img[30] = 'modal-bg-2.png';
        img[31] = 'modal-top-2.png';
        img[32] = 'modal-bottom-2.png';
        img[33] = 'nav-galeria-left.gif';
        img[34] = 'nav-galeria-right.gif';
        img[35] = 'nav-galeria-inativo-left.gif';
        img[36] = 'nav-galeria-inativo-right.gif';
    }

    var load = new Array();
    for (var imagem in img) {
        load[imagem] = new Image;
        load[imagem].src = '_img/' + img[imagem];
    }


    // SELECT
    var timeSelect;
    $('.select a.selected')
        .click(function () {
            var _this = $(this);
            var options = $(this).siblings('.options');

            if ($(options).is(':visible')) {
                $(options).slideUp(200);
                $(_this).removeClass('selectAtivo');
                return false;
            }

            $(_this).addClass('selectAtivo');
            $(options).unbind().show()
                .mouseover(function () {
                    clearTimeout(timeSelect);
                    $(options).show();
                    $(_this).addClass('selectAtivo');
                })
                .mouseout(function () {
                    timeSelect = setTimeout(function () {
                        $(options).hide();
                        $(_this).removeClass('selectAtivo');
                    }, 200)
                });
        })

        .mouseout(function () {
            var _this = $(this);
            var options = $(this).siblings('.options');
            timeSelect = setTimeout(function () {
                $(options).hide();
                $(_this).removeClass('selectAtivo');
            }, 200)
        })

        .mouseover(function () {
            clearTimeout(timeSelect)
        })

        .siblings('div.options').find('a').click(function () {
            var obj = $(this).parents('.select');
            var txt = $(this).text();
            $('.options a', obj).removeClass('ativo')
            $(this).addClass('ativo');
            $('.selected', obj).text(txt);
            $('input:hidden', obj).val(txt);
            $('#ContentPlaceHolder1_txtSerie', obj).val(txt);
            $('.options', obj).slideUp(200);
        })

    // NOTICIAS OVER
//    $('.noticias li')
//        .hover(
//            function () {
//                $(this).addClass('over');
//            },
//            function () {
//                $(this).removeClass('over');
//            })
//        .click(
//            function () {
//                var dest = $('a:first', this).attr('href');
//                location.href = dest;
//            });

    // ACCORDION
    $('.listaEquipe dt a').click(function () {
        var dt = $(this).parent();
        var dd = $(this).parent().next();

        if ($(dt).hasClass('aberto')) {
            $(dd).slideUp('slow');
            $(dt).removeClass('aberto');
        } else {
            $('.listaEquipe dt.aberto').removeClass('aberto').next().slideUp('slow');
            $(dt).addClass('aberto');
            $(dd).slideDown('fast');
        }

    })


    // TOOLTIP CALENDARIO
    $('.calendario table').removeAttr('title');

    $('.calendario .calendarLink')
        .each(function () {
            var obj = $(this).parent();
            var pos = $(obj).position();
            var total = 0;
            var larg = $('.tooltip .conteudo', obj).outerWidth()

            $('.tooltip', obj).css({ width: larg });
            $('.tooltip .meio', obj).css({ width: larg - 6 });

            if ($.browser.msie && parseInt($.browser.version) == 6) {
                pos.top -= $('.tooltip', obj).height() - 15;
                pos.left -= $('.tooltip', obj).width() / 2;
                total += 20;
            } else {
                pos.top -= $('.tooltip', obj).height() - 6;
                pos.left -= $('.tooltip', obj).width() / 2 - 20;
            }

            $('.tooltip', obj).css(pos);

            if ($(this).parents('.colunaApoio').is('div')) {
                total += pos.left + $('.tooltip .conteudo', obj).outerWidth();

                if (total > 310) {
                    $('.tooltip', obj).css({ left: 'auto', right: 5 })
                    $('.tooltip .seta', obj).css({ marginRight: 310 - $(obj).position().left - 30 })
                }

            }

            $(this).removeAttr('title');

        })
        .parent().hover(
            function () {
                $('.tooltip').css({ visibility: 'hidden' });
                $('.tooltip', this).css({ visibility: 'visible' });
            },
            function () {
                $('.tooltip', this).css({ visibility: 'hidden' });
            }
        );


    // FORMULARIO
    $('input.campo').before('<span class="canto1" />').after('<span class="canto2" />')


})
function votarEnquete() {

    // ENQUETE
    $('.boxEnquete li a:not(.btnResp)').click(function () {

        if ($(this).hasClass('ativo')) {

            $(this).removeClass('ativo');
            $(this).siblings('.btnResp').css('visibility', 'hidden');

        } else {
            $('.boxEnquete li a').removeClass('ativo');
            $('.boxEnquete li .btnResp').css('visibility', 'hidden');
            $(this).addClass('ativo');
            $(this).siblings('.btnResp').css('visibility', 'visible');
        }

    })
}

function enquete() {       
    alert('Você já respondeu esta enquete.');
    return false;
}

//function VerificarSerie() {

//    var itemSelecionado = document.getElementById('ContentPlaceHolder1_linkItemSelecionado').text;
//   
//    if (itemSelecionado == "Selecione") {
//        alert('Obrigatório selecionar a Série do próximo ano letivo');
//        //return false;
//    }

//    //return true;
//    
//}

function tirarBorda() {
    $('.resultEnquete table tr:first td').css('background', 'none');
}

//Aceita apenas números
function SoNumeros(event)//Aceita apenas números
{
    var tecla;

    tecla = (window.event) ? 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 (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 ($) {    
    $(".ddd").mask("99", { placeholder: " " });
    $(".tel").mask("9999-9999", { placeholder: " " });
    $(".txtCep").mask("99999-999", { placeholder: " " });
});



function validarCPF(oSrc, args) {

    var cpf = args.Value;
    cpf = cpf.replace('.', '');
    cpf = cpf.replace('.', '');
    cpf = cpf.replace('/', '');
    cpf = cpf.replace('-', '');


    return args.IsValid = validaCPF(cpf);

}


function validaCPF(cpf) {

    cpf = cpf.replace('.', '');
    cpf = cpf.replace('.', '');
    cpf = cpf.replace('-', '');


    if (cpf.length != 11 || cpf == "12345678909" || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
        return false;

    add = 0;
    for (i = 0; i < 9; i++)
        add += parseInt(cpf.charAt(i)) * (10 - i);

    rev = 11 - (add % 11);

    if (rev == 10 || rev == 11)
        rev = 0;

    if (rev != parseInt(cpf.charAt(9)))
        return false;

    add = 0;

    for (i = 0; i < 10; i++)
        add += parseInt(cpf.charAt(i)) * (11 - i);

    rev = 11 - (add % 11);

    if (rev == 10 || rev == 11)
        rev = 0;

    if (rev != parseInt(cpf.charAt(10)))
        return false;

    return true;

}
