﻿var evento = [];
$(document).ready(function (event) {
    //Abre e fecha menu

    $(".menuPrincipal ul.box").addClass("invisivel");
    $(".menuPrincipal h3 a").each(function () {
        if ($(this).attr('href') == "javascript:void(0);") {
            $(this).parent().addClass("link-titulo-seta");
            $(this).parent().click(function () {
                $(this).next("ul.box").slideToggle("slow").siblings("ul.box:visible").slideUp("slow");
                return false;
            });
        }
    });

    $('.menuPrincipal a').each(function () {
        if (this.href.toUpperCase() == location.href.toUpperCase()) {
            $(this).parent().parent().prev().click();
            $(this).parent().parent().prev().attr('onmouseout', 'link-titulo-seta-hover');
            $(this).parent().parent().prev().attr('onmouseover', 'link-titulo-seta-hover');
            $(this).parent().parent().prev().addClass('link-titulo-seta-hover');
            $(this).css('font-weight', 'bold');
        }
    });

    $("input[id$=nome]").focus(function () {
        $("input[id$=nome]").val("");
    });

    $("input[id$=email]").focus(function () {
        $("input[id$=email]").val("");
    });

    $("#EnviarLembrete").click(function () {
        enviaAlerta();

    });

    $(".inputBusca").focus(function () {

        $(".inputBusca").val("");
    });

    $(".inputBusca").keypress(function (event) {
        var e = event || window.event;

        if (e.keyCode == '13') {
            Buscar();

            event.preventDefault();
        }
    });

    $(".inputOk").click(function (event) {
        Buscar();
        event.preventDefault();
    });
});

function Buscar() {
    //window.event.preventDefault();

    buscada = $(".inputBusca").val().replace(/"/g, "");
    window.location = "ListaBusca.aspx?busca=" + buscada;
}

function Marcar() {
    if (document.getElementById('controlMailingPort').checked != true && document.getElementById('controlMailingIng').checked != true) {
        alert("Selecione pelo menos um marcador.")
        return false;
    }
    if((document.getElementById('nome_modal').value == "") && ($(".hidLinguagem").val() == "ptg") ){
        alert("É necessário um nome.");
        return false;
    }
    else if(document.getElementById('nome_modal').value == "")
    {
        alert("Insert a name.");
        return false;
    }
        
    
    if( (document.getElementById('email_modal').value == "") && ($(".hidLinguagem").val() == "ptg") ) {
        alert("É necessário um email.");
        return false;
    }
    else if(document.getElementById('email_modal').value == "")
    {
        alert("Insert a email.");
        return false;
    }
    return true;
}

function enviaAlerta() {

    if (Marcar()) {
        var MailingPort = "";
        var MailingIng = "";

        var nomeAlerta = $('#nome_modal').val();
        var emailAlerta = $('#email_modal').val();
        var telefone = $('#controlTelefone').val();
        var empresa = $('#controlEmpresa').val();
        var cargo = $('#controlCargo').val();
        var perfil = $('#controlPerfil').val();

        if (document.getElementById('controlMailingPort').checked == true) {
            var MailingPort = $('#controlMailingPort').val();
        }
        if (document.getElementById('controlMailingIng').checked == true) {
            var MailingIng = $('#controlMailingIng').val();
        }

        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (!filter.test(emailAlerta)) {
            if ($(".hidLinguagem").val() == "ptg") {
                alert('E-mail Inválido!');
            } else {
                alert("Invalid E-mail!");
            }
            return false;
        }

        CallServer("alerta;" + nomeAlerta + ";" + emailAlerta + ";" + telefone + ";" + empresa + ";" + cargo + ";" + perfil + ";" + MailingPort + ";" + MailingIng);
    }
}

function abreBoxMailing() {
    var nome = $("input[id$=nome]").val();
    var email = $("input[id$=email]").val();
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;


    if (filter.test(email) && Trim(nome) != "") {
        document.getElementById('nome_modal').value = nome;
        document.getElementById('email_modal').value = email;
        $('#fade').show();
        $('#conteudoAlertasRi').attr('style', '');
        $('#conteudoAlertasRi').show();
    }
    else if (Trim(nome) == "") {
        if ($(".hidLinguagem").val() == "ptg") {
            alert('Digite um nome!')
        }
        else {
            alert('Enter a name!')
        }
        document.getElementById('nome').value = "";
        document.getElementById('nome').focus();
    }
    else if (!filter.test(email)) {
        if ($(".hidLinguagem").val() == "ptg") {
            alert('E-mail Inválido!')
        }
        else {
            alert('Invalid E-mail!')
        }
        document.getElementById('email').value = "";
        document.getElementById('email').focus();
    }
}

function Trim(str) { return str.replace(/^\s+|\s+$/g, ""); }

function fechaBoxAlerta() {
    $('#fade').hide();
    $('#conteudoAlertasRi').hide();
}

function c_Mascara() {
    this.Mascara = function (o, f) {
        this.setFun(f);
        this.setObj(o);
        setTimeout("classMascara.exe()", 1);
    }

    this.exe = function () {
        switch (this.getFun()) {
            case "Telefone": obj = this.getObj();
                obj.value = this.Telefone(this.getObj());
                break;
        }
    }

    this.Telefone = function (o) {
        valor = o.value;
        valor = valor.replace(/\D/g, "")
        valor = valor.replace(/^(\d\d)(\d)/g, "($1) $2")
        valor = valor.replace(/(\d{4})(\d)/, "$1-$2")
        return valor;
    }

    this.getObj = function () { return ob; }
    this.setObj = function (o) { ob = o; }
    this.getFun = function () { return fun; }
    this.setFun = function (f) { fun = f; }
}
classMascara = new c_Mascara();

function irParaTopo() { $('html, body').animate({ scrollTop: 0 }, 'slow') };

function retornoCallback(arg, context) {
    var args = arg.split(';');
    var imagem;

    switch (args[0]) {
        case "impressao":
            {
                executaImpressao(args[1]);
                break;
            }
        case "buscarShow":
            {
                alert(args[1]);
                break;
            }
        case "email":
            {
                if (args[1] == "success") {
                    alert(args[2]);
                    fechaBoxEmail();
                }
                else
                    alert(args[2]);
                break;
            }
        case "novaDescricaoTriResponse":
            exibirNovaDescricao(args[1], args[2]);
            break;
        case "lembreteAgenda":
            limparDados();
            var alertagenda = $('input[id$=MsgLembreteAgenda]').val();
            alert(alertagenda);
            break;
        case "paginarResponse":
            efetuarPaginacaoResponse(args[1], args[2]);
            break;
        case "alerta":
            var alertari = $('input[id$=MsgSucessoRi]').val();
            alert(alertari);
            fechaBoxAlerta();
            break;
        case "alertaContatoExiste":
            var mensagem = unescape(args[1]);
            eval(mensagem);
            fechaBoxAlerta();
            break;
        case "EventosAnteriores":
            {
                carregarEventosAnteriores(args);
                break;
            }
        case "EventosProximos":
            {
                carregarEventosProximos(args);
                break;
            }
        default:
            break;
    }
}

function erroCallback(err) {
    alert("erro:" + err);
}

function AfterExcluirFavorito() {
    //metodo disponivel pelo webcontrol meus favoritos
    if (urlsMeusFavoritos.length == 1) {
        $('span[id$=lblTextoSemFavoritosInnerHtml]').show();
    }
}



// função para esconder ou mostrar, sempre o inverso
function showHiden(obj, obj2) {
    var txtMostrarRodape = $('input[id$=TxtMostrarRodape]').val();
    var txtEsconderRodape = $('input[id$=TxtEsconderRodape]').val();
    if (document.getElementById(obj).style.display == 'block') {
        document.getElementById(obj).style.display = 'none';
        document.getElementById(obj2).innerHTML = txtMostrarRodape; // + '  <img src="img/icoSetaBaixo.jpg" align="top"  />';
    } else {
        document.getElementById(obj).style.display = 'block';
        document.getElementById(obj2).innerHTML = txtEsconderRodape; // + '  <img src="img/icoSetaCima.jpg" align="top"  />';

    }
}


function abrirPopUpMailling() {
    var inputNome = $("input[id$=nome]").val();
    var inputEmail = $("input[id$=email]").val();
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (inputNome == "" || inputNome == "Nome:") {

        alert('Digite um nome!')
        $("input[id$=nome]").val("");
        $("input[id$=nome]").focus();
        return false;
    }
    else if (!filter.test(inputEmail)) {

        alert('E-mail Inválido!')
        $("input[id$=email]").val("");
        $("input[id$=email]").focus();
        return false;
    }

    $("#emailLink").attr("inputNome", inputNome);
    $("#emailLink").attr("inputEmail", inputEmail);
    
    window.location.href = 'Mailing.aspx?nome=' + inputNome + '&email=' + inputEmail;

    return true;
}
