﻿function VerDados(expositor) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('expositorform.aspx?expositor=" + expositor + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=450');");
}

function AbrirGaleria(galeria) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('galeria.aspx?pG=" + galeria + "', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568,left=440,top=312');");
}

function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
    if (!oldElm || !oldElm.parentNode || (iType.length < 4) ||
    !document.getElementById || !document.createElement) return;
    var newElm = document.createElement('input');
    newElm.type = iType;
    if (oldElm.name) newElm.name = oldElm.name;
    if (oldElm.id) newElm.id = oldElm.id;
    if (oldElm.className) newElm.className = oldElm.className;
    if (oldElm.style.width) newElm.style.width = oldElm.style.width;
    if (oldElm.size) newElm.size = oldElm.size;
    if (oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
    if (oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
    newElm.onfocus = function() {
        return function() {
            if (this.hasFocus) return;
            var newElm = changeInputType(this, 'password', iValue,
      (this.value.toLowerCase() == iValue.toLowerCase()) ? true : false);
            if (newElm) newElm.hasFocus = true;
        } 
    } ();
    newElm.onblur = function() {
        return function() {
            if (this.hasFocus)
                if (this.value == '' || (this.value.toLowerCase() == iValue.toLowerCase())) {
                changeInputType(this, 'text', iValue, false, true);
            }
        } 
    } ();
    // hasFocus is to prevent a loop where onfocus is triggered over and over again
    newElm.hasFocus = false;
    oldElm.parentNode.replaceChild(newElm, oldElm);
    if (!blankValue) newElm.value = iValue;
    if (!noFocus || typeof (noFocus) == 'undefined') {
        window.tempElm = newElm;
        setTimeout("tempElm.hasFocus=true;tempElm.focus();", 1);
    }
    return newElm;
}

function checkMail(mail) {
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if (typeof (mail) == "string") {
        if (er.test(mail)) { return true; }
    }
    else if (typeof (mail) == "object") {
        if (er.test(mail.value)) { return true; }
    }
    else {
        return false;
    }
}

function checkCenso(censo) {
    var er = new RegExp(/^[3]{2}[0-9]{6}/);
    if (typeof (censo) == "string") {
        if (er.test(censo)) { return true; }
    }
    else if (typeof (censo) == "object") {
        if (er.test(censo.value)) { return true; }
    }
    else {
        return false;
    }
}

function replaceAll(string, token, newtoken) {
    while (string.indexOf(token) != -1) {
        string = string.replace(token, newtoken);
    }
    return string;
}

function validaCPF(cpf) {
    var nonNumbers = /\D/;
    cpf = replaceAll(cpf, ".", "");
    cpf = cpf.replace("-", "");
    if (cpf.length < 11) {
        return false;
    }
    if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
        return false;
    }
    var a = [];
    var b = new Number;
    var c = 11;
    for (i = 0; i < 11; i++) {
        a[i] = cpf.charAt(i);
        if (i < 9) b += (a[i] * --c);
    }
    if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11 - x }
    b = 0;
    c = 11;
    for (y = 0; y < 10; y++) b += (a[y] * c--);
    if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11 - x; }
    if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])) {
        return false;
    }
    return true;
}

function validaCNPJ(CNPJ) {
    if (CNPJ.length < 18) { return false; }
    if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")) {
        return false;
    }

    if (document.layers && parseInt(navigator.appVersion) == 4) {
        x = CNPJ.substr(0, 2);
        x += CNPJ.substr(3, 3);
        x += CNPJ.substr(7, 3);
        x += CNPJ.substr(11, 4);
        x += CNPJ.substr(16, 2);
        CNPJ = x;
    } else {
        CNPJ = CNPJ.replace(".", "");
        CNPJ = CNPJ.replace(".", "");
        CNPJ = CNPJ.replace("-", "");
        CNPJ = CNPJ.replace("/", "");
    }
    var nonNumbers = /\D/;
    if (nonNumbers.test(CNPJ)) { return false; }
    var a = [];
    var b = new Number;
    var c = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
    for (i = 0; i < 12; i++) {
        a[i] = CNPJ.charAt(i);
        b += a[i] * c[i + 1];
    }
    if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11 - x }
    b = 0;
    for (y = 0; y < 13; y++) {
        b += (a[y] * c[y]);
    }
    if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11 - x; }
    if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])) {
        return false;
    }
    return true;
}

function validaTelefone(telefone) {
    var regExpAllowChars = /^((\+?\d{1,4}|\(\+?\d{1,4}\))?[ -.])?(([\d\*]{1,5}|\([\d\*]{1,5}\))[ -]?)?\d{1,5}[ -.]?\d{4}$/;

    if (typeof (telefone) == "string")
        if (regExpAllowChars.test(telefone))
        return true;
    else
        if (typeof (telefone) == "object")
        if (regExpAllowChars.test(telefone.value))
        return true;

    return false;
}

function validaCep(cep) {
    var regExpAllowChars = /^\d+[\-\. ]?\d+[\-\. ]?\d+$/

    if (typeof (cep) == "string")
        if (regExpAllowChars.test(cep))
        return true;
    else
        if (typeof (cep) == "object")
        if (regExpAllowChars.test(cep.value))
        return true;
    return false;
}

function configurar_nome(oElem, iValue, blankValue) {
    if (oElem.value == iValue || oElem.value == '') {
        oElem.value = (blankValue) ? '' : iValue;
    }
}

function configurar_nome_senha() {
    if (document.getElementById("pS").value == 'senha') {
        changeInputType(document.getElementById("pS"), 'password', 'senha', true, false)
    }
}

function limiteTexto(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
    } else {
        $('#' + countfield).val(maxlimit - field.value.length);
    }
}

function AbrirPlantaFeira() {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imagem.aspx', '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=665,height=498,top=20,left=20');");
}

function ImprimirProg() {
    expositor = $('#h_expositor').val();
    data = $('#h_data').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_progexpositores.aspx?pE=" + expositor + "&pD=" + data + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function ImprimirProgInfantil() {
    expositor = $('#h_expositor').val();
    data = $('#h_data').val();
    hora = $('#h_hora').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_proginfantil.aspx?pE=" + expositor + "&pD=" + data + "&pH=" + hora + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function ImprimirProgCult() {
    local = $('#h_local').val();
    data = $('#h_data').val();
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_progcultural.aspx?pL=" + local + "&pD=" + data + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function ImprimirExpositores() {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir_expositores.aspx', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568');");
}

function Imprimir(escola) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('imprimir.aspx?pP=" + escola + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=568,left=440,top=312');");
}

function VerDados(expositor) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('expositorform.aspx?expositor=" + expositor + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=450');");
}

function validar_visitas() {
    if (document.getElementById('h_totalvisitas').value == 0) {
        alert("Adicione uma visita para a escola!");
        return false;
    }
    return true;
}

function validar_add() {
    if (document.getElementById('d_data').value == 0) {
        alert("Selecione uma data!");
        return false;
    }
    if (document.getElementById('d_hora').value == 0) {
        alert("Selecione uma hora!");
        return false;
    }
    if (document.getElementById('t_qtdealunos').value == 0 || document.getElementById('t_qtdealunos').value == "") {
        alert("Digite a quantidade de alunos!");
        return false;
    }
    if (document.getElementById('t_qtdealunos').value < 40) {
        alert("Quantidade mínima: 40 alunos");
        return false;
    }
    if (document.getElementById('t_qtdeveiculos').value == 0 || document.getElementById('t_qtdeveiculos').value == "") {
        alert("Digite a quantidade de veículos!");
        return false;
    }
    return true;
}

function isNum(event) {
    var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (Key == 8 || Key == 13 || Key == 127 || (Key >= 48 && Key <= 57)) return true;
    else return false;
}

function onTopPage() {
    document.body.scrollTop = 0;
}

function configurar_comosoube() {
    if (document.getElementById('d_como_soube').value == 99) {
        document.getElementById('dvComoSoube').style.display = 'block';
    }
    else {
        document.getElementById('dvComoSoube').style.display = 'none';
    }
}

/* ###################### VALIDAR FORMULARIO ############################################# */

function validar_contato() {
    if (document.getElementById('t_nome').value == '') {
        alert("O campo nome é obrigatório!");
        return false;
    }
    if (document.getElementById('t_email').value == '') {
        alert("O campo e-mail é obrigatório!");
        return false;
    }
    if (document.getElementById('t_empresa').value == '') {
        alert("O campo empresa é obrigatório!");
        return false;
    }
    if (document.getElementById('t_cargo').value == '') {
        alert("O campo cargo é obrigatório!");
        return false;
    }
    if (document.getElementById('t_endereco').value == '') {
        alert("O campo endereço é obrigatório!");
        return false;
    }
    if (document.getElementById('t_cidade').value == '') {
        alert("O campo cidade é obrigatório!");
        return false;
    }
    if (document.getElementById('t_bairro').value == '') {
        alert("O campo t_bairro é obrigatório!");
        return false;
    }
    if (document.getElementById('t_estado').value == '') {
        alert("O campo estado é obrigatório!");
        return false;
    }
    if (document.getElementById('t_pais').value == '') {
        alert("O campo país é obrigatório!");
        return false;
    }
    if (document.getElementById('t_cep').value == '') {
        alert("O campo CEP é obrigatório!");
        return false;
    }
    if (document.getElementById('t_telefone').value == '') {
        alert("O campo telefone é obrigatório!");
        return false;
    }

    return true;
}


function validar_expor() {
    if (document.getElementById('t_nome').value == '') {
        alert("O campo nome é obrigatório!");
        return false;
    }
    if (document.getElementById('t_email').value == '') {
        alert("O campo e-mail é obrigatório!");
        return false;
    }
    if (document.getElementById('t_empresa').value == '') {
        alert("O campo empresa é obrigatório!");
        return false;
    }
    if (document.getElementById('t_cargo').value == '') {
        alert("O campo cargo é obrigatório!");
        return false;
    }
    if (document.getElementById('t_endereco').value == '') {
        alert("O campo endereço é obrigatório!");
        return false;
    }
    if (document.getElementById('t_cidade').value == '') {
        alert("O campo cidade é obrigatório!");
        return false;
    }
    if (document.getElementById('t_bairro').value == '') {
        alert("O campo t_bairro é obrigatório!");
        return false;
    }
    if (document.getElementById('t_estado').value == '') {
        alert("O campo estado é obrigatório!");
        return false;
    }
    if (document.getElementById('t_pais').value == '') {
        alert("O campo país é obrigatório!");
        return false;
    }
    if (document.getElementById('t_cep').value == '') {
        alert("O campo CEP é obrigatório!");
        return false;
    }
    if (document.getElementById('t_telefone').value == '') {
        alert("O campo telefone é obrigatório!");
        return false;
    }

    return true;
}

function validar_newsletter() {
    if (document.getElementById('t_nome').value == '') {
        alert('O campo nome é obrigatório!');
        document.getElementById('t_nome').focus();
        return false;
    }
    if (document.getElementById('t_email').value == '') {
        alert('O campo e-mail é obrigatório!');
        document.getElementById('t_email').focus();
        return false;
    }
    if (!checkMail(document.getElementById('t_email').value)) {
        alert('O e-mail é inválido!');
        document.getElementById('t_email').focus();
        return false;
    }
    if (document.getElementById('t_sms').value == 1 && document.getElementById('t_celular').value == '') {
        alert('O campo celular é obrigatório para receber novidades no seu celular!');
        document.getElementById('t_celular').focus();
        return false;
    }    
    return true;
}

function validar_indicar() {
    if (document.getElementById('t_nome').value == '') {
        alert('O campo seu nome é obrigatório!');
        document.getElementById('t_nome').focus();
        return false;
    }
    if (document.getElementById('t_email').value == '') {
        alert('O campo seu e-mail é obrigatório!');
        document.getElementById('t_email').focus();
        return false;
    }
    if (!checkMail(document.getElementById('t_email').value)) {
        alert('O seu e-mail é inválido!');
        document.getElementById('t_email').focus();
        return false;
    }
    if (document.getElementById('t_nome_amigo').value == '') {
        alert('O campo nome do amigo é obrigatório!');
        document.getElementById('t_nome_amigo').focus();
        return false;
    }
    if (document.getElementById('t_email_amigo').value == '') {
        alert('O campo e-mail do amigo é obrigatório!');
        document.getElementById('t_email_amigo').focus();
        return false;
    }
    if (!checkMail(document.getElementById('t_email_amigo').value)) {
        alert('O e-mail do amigo é inválido!');
        document.getElementById('t_email_amigo').focus();
        return false;
    }    
    return true;
}

function imprime_cadastro(v_id, v_cat) {
    window.open("credform.aspx?pP=" + v_id + "&pC=" + v_cat, '', 'toolbar=0,location=0,directories=0,status=no,menubar=0,scrollbars=1,resizable=1,width=600,height=800,top=20,left=30');
}


function verificaNum() {
    if ((event.keyCode < 44) || (event.keyCode > 57)) {
        if ((event.keyCode < 96) || (event.keyCode > 106)) {
            alert("Somente números são permitidos");
            event.returnValue = false;
        }
    }
}

function validar_credencial() {

    if (document.getElementById('t_nome_completo').value == '') {
        alert('O campo nome completo é obrigatório!');
        document.getElementById('t_nome_completo').focus();
        return false;
    }

    //validaCpfComMascara();

    cpf = document.getElementById("t_cpf")
    if (cpf.value == "") {
        alert('O Campo CPF é obrigatório!');
        cpf.focus();
        return false
    }
    else {
        if (cpf.value.length != 11) {
            alert("O campo CPF não está no formato correto. Por favor verifique o valor digitado!");
            cpf.focus();
            return false;
        }
    }

    if (document.getElementById("t_rg").value == "") {
        alert("O campo RG é obrigatório!");
        document.getElementById("t_rg").focus();
        return false;
    }
    if (document.getElementById('t_email').value == '') {
        alert('O campo e-mail é obrigatório!');
        document.getElementById('t_email').focus();
        return false;
    }
    if (!checkMail(document.getElementById("t_email").value)) {
        alert('O e-mail é inválido!');
        document.getElementById("t_email").focus();
        return false;
    }
    if (document.getElementById('t_empresa').value == '') {
        alert('O campo empresa é obrigatório!');
        document.getElementById('t_empresa').focus();
        return false;
    }
    /*if(document.getElementById("t_ramo").value=="") {
    alert("O campo ramo é obrigatório!");
    document.getElementById("t_ramo").focus();
    return false;
    }*/
    if (document.getElementById("t_cargo").value == "") {
        alert("O campo cargo é obrigatório!");
        document.getElementById("t_cargo").focus();
        return false;
    }
    if (document.getElementById('t_endereco').value == '') {
        alert('O campo endereço é obrigatório!');
        document.getElementById('t_endereco').focus();
        return false;
    }
    if (document.getElementById('t_cidade').value == '') {
        alert('O campo cidade é obrigatório!');
        document.getElementById('t_cidade').focus();
        return false;
    }

    pais = document.getElementById("t_pais")
    if (pais.value == "") {
        alert('O Campo país é obrigatório!');
        pais.focus();
        return false
    }

    cep = document.getElementById("t_cep")
    if (cep.value == "") {
        alert('O Campo CEP é obrigatório!');
        cep.focus();
        return false
    }
    else {
        if (cep.value.length != 9) {
            alert("O campo CEP não está no formato correto. Por favor verifique o valor digitado!");
            cep.focus();
            return false
        }
    }

    telefone = document.getElementById("t_telefone")
    if (telefone.value == "") {
        alert('O Campo Telefone é obrigatório!');
        telefone.focus();
        return false
    }
    else {
        if (telefone.value.length != 13) {
            alert("O campo Telefone não está no formato correto. Por favor verifique o valor digitado!");
            telefone.focus();
            return false;
        }
    }

    //Validando Celular (Campo não obrigatório)
    celular = document.getElementById("t_celular")
    if (celular.value != "") {
        if (celular.value.length != 13) {
            alert("O campo Celular não está no formato correto. Por favor verifique o valor digitado!");
            celular.focus();
            return false;
        }
    }

    sms = document.getElementById("chkSMS")

    if (sms.checked) {
        if (celular.value == "") {
            alert("Para receber novidades no seu celular, por favor digite o número");
            celular.focus();
            return false;
        } 
    }

}