/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function() {
    if($("#msg").val() == "sucesso"){
        $("#alertSucesso").html("Obrigado por cadastrar-se em nossa newsletter.");
        $("#alertSucesso").show();
    }else if($("#msg").val() == "consta"){
        $("#alertSucesso").html("O email informado já está cadastrado em nossa newsletter.");
        $("#alertSucesso").show();
    }else if($("#msg").val() == "erro"){
        $("#alertCadastro").html("Erro no cadastro, por favor tente novamente mais tarde.");
        $("#alertCadastro").show();
    }
    $("#newsBtnEnviar").click(function(){return validaCadastro()});
});


function validaCadastro(){
    try{
        limpaAlert();
        if($("#newsNome").val() == ""){
            $("#alertCadastro").html("Informe o nome");
            $("#alertCadastro").show();
            $("#newsNome").focus();
            return false;
        }else if($("#newsEmail").val() == ""){
            $("#alertCadastro").html("Infome seu email");
            $("#alertCadastro").show();
            $("#newsEmail").focus();
            return false;
        }else if(!isEmail($("#newsEmail").val())){
            $("#alertCadastro").html("O email é inválido");
            $("#alertCadastro").show();
            $("#newsEmail").focus();
            return false;
        }else if($("#newsUF").val() == ""){
            $("#alertCadastro").html("Informe a uf");
            $("#alertCadastro").show();
            $("#newsUF").focus();
            return false;
        }else{
            return true;
        }
    }catch(err){
        alert(err.description);
        return false;
    }
}

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

