﻿var isNN = (navigator.appName.indexOf("Netscape") != -1);

var exibir = false;

$j(document).ready(function () {

    //prepend span tag
    $j(".jquery h1").prepend("<span></span>");

});

 function AbrirFecharNewsLetter(id) {
    var newsletter = document.getElementById(id);
    if (newsletter.style.display == "none")
        newsletter.style.display = "block";
    else
        newsletter.style.display = "none";
}



$j(function () {

    //run the currently selected effect
    function runEffect() {
        //most effect types need no options passed by default
        var options = {};

        //run the effect
        $j("#login").show("blind", options, 300);

        $j('#button_login').unbind('click');

        //set effect from select menu value
        $j("#button_login").click(function () {
            runEscondeEffect();
            return false;
        });
    };

    //run the currently selected effect
    function runEscondeEffect() {
        //most effect types need no options passed by default
        var options = {};

        //run the effect
        $j("#login").hide("blind", options, 300);

        $j('#button_login').unbind('click');

        //set effect from select menu value
        $j("#button_login").click(function () {
            runEffect();
            return false;
        });
    };

    //set effect from select menu value
    $j("#button_login").click(function () {
        runEffect();
        return false;
    });

    $j("#login").hide();

    if (exibir) runEffect();
});


function LoginAcesso() {
    exibir = true;
}
function ValidaContato() {

    var msgerro = "";
    var campo = "";

    if (document.getElementById("ctl00_ContentPlaceHolder1_txbNome").value == "") {
        msgerro += 'Digite o seu nome!<br/>';
        campo = document.getElementById("ctl00_ContentPlaceHolder1_txbNome");
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_txbEmail").value == "") {
        msgerro += 'Digite o seu e-mail!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_txbEmail");
    }

    if (!valida_mail(document.getElementById("ctl00_ContentPlaceHolder1_txbEmail").value) && document.getElementById("ctl00_ContentPlaceHolder1_txbEmail").value != "") {
        msgerro += 'Digite um e-mail válido!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_txbEmail");
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_ddlDepartamento").value == "") {
        msgerro += 'Selecione o departamento!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_ddlDepartamento");
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_ddlAssunto").value == "") {
        msgerro += 'Selecione o assunto!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_ddlAssunto");
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_txbMensagem").value == "") {
        msgerro += 'Digite a mensagem!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_txbMensagem");
    }

    if (msgerro != "") {
        jAlert(msgerro, 'Atenção', function(r) {
            if (r) {
                campo.focus();
            }
        });
        return false;
    }
    return true;
}

function ValidaLogin(CampoForm) {

    var msgerro = "";
    var campo = "";

    if (document.getElementById(CampoForm +"_txbCnpj").value == "") {
        msgerro += 'Digite o seu CNPJ!<br/>';
        campo = document.getElementById(CampoForm + "_txbCnpj");
    }

    if (document.getElementById(CampoForm + "_txbSenha").value == "") {
        msgerro += 'Digite a sua Senha!<br/>';
        if (campo == "")
            campo = document.getElementById(CampoForm + "_txbSenha");
    }

    if (msgerro != "") {
        jAlert(msgerro, 'Atenção', function (r) {
            if (r) {
                campo.focus();
            }
        });
        return false;
    }
    return true;
}

function ValidaSenha(CampoForm) {

    var msgerro = "";
    var campo = "";

    if (document.getElementById(CampoForm + "_txbCnpj").value == "") {
        msgerro += 'Digite o seu CNPJ!<br/>';
        campo = document.getElementById(CampoForm + "_txbCnpj");
    }

    if (msgerro != "") {
        jAlert(msgerro, 'Atenção', function (r) {
            if (r) {
                campo.focus();
            }
        });
        return false;
    }
    return true;
}

function ValidaCNPJCadastro(CampoForm) {

    var msgerro = "";
    var campo = "";

    if (document.getElementById(CampoForm + "_txbCnpjCadastro").value == "") {
        msgerro += 'Digite o seu CNPJ!<br/>';
        campo = document.getElementById(CampoForm + "_txbCnpjCadastro");
    }

    if (msgerro != "") {
        jAlert(msgerro, 'Atenção', function (r) {
            if (r) {
                campo.focus();
            }
        });
        return false;
    }
    return true;
}

function ValidaCadastro() {

    var msgerro = "";
    var campo = "";

    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbSenha")) {
        if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbSenha").value == "") {
            msgerro += 'Informe a sua senha!<br/>';
            if (campo == "")
                campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbSenha");
        }

        if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbConfirmacaoSenha").value != document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbSenha").value) {
            msgerro += 'A confirmação da senha deve ser igual à senha!<br/>';
            if (campo == "")
                campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbConfirmacaoSenha");
        }
    }

//    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbRazaoSocial").value == "") {
//        msgerro += 'Digite o sua razão social!<br/>';
//        campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbRazaoSocial");
//    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmail").value == "") {
        msgerro += 'Digite o seu e-mail!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmail");
    }

    if (!valida_mail(document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmail").value) && document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmail").value != "") {
        msgerro += 'Digite um e-mail válido!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmail");
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmailConf").value != document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmail").value) {
        msgerro += 'A confirmação do e-mail deve ser igual ao e-mail!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbEmailConf");
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbTelefone").value == "") {
        msgerro += 'Digite o seu telefone!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbTelefone");
    }

//    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbNumero").value == "") {
//        msgerro += 'Digite o seu número do endereço!<br/>';
//        if (campo == "")
//            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbNumero");
//    }

//    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP").value != document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEPValida").value) {
//        msgerro += 'Valide o CEP!<br/>';
//        if (campo == "")
//            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP");
//    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_ddlLojaShopping").value == "") {
        msgerro += 'Informe se possui loja no shopping ou não!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_ddlLojaShopping");
    }

    if (!ValidaShopping("ctl00_ContentPlaceHolder1_CadastroAssociado1_cblShopping") && document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_ddlLojaShopping").value == "SIM") {
        msgerro += 'Informe o(s) shopping(s) que possui loja(s)!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_cblShopping_0");
    }

    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_cbAceito"))
    {
        if (!document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_cbAceito").checked ) {
            msgerro += 'Leia e aceita o regulamento!<br/>';
            if (campo == "")
                campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_cbAceito");
        }
    }    

    if (msgerro != "") {
        jAlert(msgerro, 'Atenção', function (r) {
            if (r) {
                campo.focus();
            }
        });
        return false;
    }
    return true;
}


function ValidaCEP() {

    var msgerro = "";
    var campo = "";

    if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP").value == "") {
        msgerro += 'Digite o seu CEP!<br/>';
        campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP");
    }
    
    if ((!validaInteiro(document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP").value) || document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP").value.length != 8) && document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP").value != "") {
        msgerro += 'Digite um cep válido!<br/>';
        if (campo == "")
            campo = document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_txbCEP");
    }

    if (msgerro != "") {
        jAlert(msgerro, 'Atenção', function (r) {
            if (r) {
                campo.focus();
            }
        });
        return false;
    }
    return true;
}

function LojaShopping(Valor) {
    if (Valor == "SIM")
        document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_shopping").style.display = "block";
    else
        document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_shopping").style.display = "none";
}

function ValidaShopping(Campo) {
    var i = 0;
    while (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_cblShopping_" + i) != null) {

        if (document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_cblShopping_" + i).checked) return true;

        i++;
    }

    return false;
}

function LerAceito() {
    document.getElementById("ctl00_ContentPlaceHolder1_CadastroAssociado1_ValidaAceito").value = "true";
}

function valida_mail(valor) {
    prim = valor.indexOf("@")
    if (prim < 1) return false;
    if (valor.indexOf("@", prim + 1) != -1) return false;
    if (valor.indexOf(".") < 1) return false;
    if (valor.indexOf("zipmeil.com") > 0) return false;
    if (valor.indexOf("hotmeil.com") > 0) return false;
    if (valor.indexOf(".@") > 0) return false;
    if (valor.indexOf("@.") > 0) return false;
    if (valor.indexOf(".com.br.") > 0) return false;
    if (valor.indexOf("/") > 0) return false;
    if (valor.indexOf("[") > 0) return false;
    if (valor.indexOf("]") > 0) return false;
    if (valor.indexOf("(") > 0) return false;
    if (valor.indexOf(")") > 0) return false;
    if (valor.indexOf("..") > 0) return false;
    if (valor.indexOf(",") > 0) return false;
    parte1 = valor.indexOf("@");
    parte3 = valor.length;
    if (!(parte1 >= 1 && parte3 >= 6)) return false;
    return true;
}

function validaInteiro(valor) {
    var strNumeros = '0123456789';

    for (i = 0; i < valor.length; i++)
        if ((strNumeros.indexOf(valor.substr(i, 1)) == -1) && !((i == 0) && (valor.substr(i, 1) == '-')))
            return false;
    return true;
}

function FormataInteiro(campo, evento) {
    var keyCode = (isNN) ? evento.which : evento.keyCode;
    if ((!(keyCode >= 48 && keyCode <= 57)) && keyCode != 0 && keyCode != 13 && keyCode != 8) return false;
}
