/*
 * by pls
 */

$(document).ready(function() {
    $("#enviar").click(function(){return validaCadastro()});
    $('#ddd').setMask("99");
    $('#telefone').setMask("99999999");
    if($('#msg').val() == "erro"){
        $("#alertCadastro").html("Ocorreu um erro interno ao enviar seu artigo, por favor tente novamente mais tarde.");
        $("#alertCadastro").show();
    }

});


function validaCadastro(){
    try{
        limpaAlert();
        if($("#nome").val() == ""){
            $("#alertCadastro").html("Informe seu nome");
            $("#alertCadastro").show();
            $("#nome").focus();
            return false;
        }else if($("#email").val() == ""){
            $("#alertCadastro").html("Informe seu email");
            $("#alertCadastro").show();
            $("#email").focus();
            return false;
        }else if(!isEmail($("#email").val())){
            $("#alertCadastro").html("O email informado não é válido.");
            $("#alertCadastro").show();
            $("#email").focus();
            return false;
        }else if($("#ddd").val() == ""){
            $("#alertCadastro").html("Informe o ddd");
            $("#alertCadastro").show();
            $("#ddd").focus();
            return false;
        }else if($("#telefone").val() == ""){
            $("#alertCadastro").html("Informe o telefone");
            $("#alertCadastro").show();
            $("#telefone").focus();
            return false;
        }else if($("#especialidade").val() == ""){
            $("#alertCadastro").html("Selecione a especialidade");
            $("#alertCadastro").show();
            $("#especialidade").focus();
            return false;
        }else if($("#titulo").val() == "") {
            $("#alertCadastro").html("Informe o título");
            $("#alertCadastro").show();
            $("#titulo").focus();
            return false;
        }else if($("#arquivo").val() == "") {
            $("#alertCadastro").html("Selecione arquivo contendo o artigo");
            $("#alertCadastro").show();
            $("#arquivo").focus();
            return false;
        }else{
            return true;
        }
    }catch(err){
        alert(err.description);
        return false;
    }
}

function limpaAlert() {
   $("#alertCadastro").hide();
}
