var evento = [];

$(document).ready(function () {
    $("input[id$=nome]").focus(function () {
        $("input[id$=nome]").val("");
    });

    $("input[id$=email]").focus(function () {
        $("input[id$=email]").val("");
    });
    $("#EnviarLembrete").click(function () {
        enviaAlerta();

    });
});


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 == "") {
        alert("É necessário um nome.")
        return false;
    }
    if (document.getElementById('email_modal').value == "") {
        alert("É necessário um 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();
        }


        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 incorreto!')
    }
    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') };
