$(window).load(function() {
	$('#wrapper').fadeIn();
});

$(document).ready(function(){
  $('#news_nome').val("NOME");
  $('#news_nome').focus(function() {
     if ($(this).val()=="NOME"){
        $(this).removeClass("campo_02");
        $(this).val("");
     }else{
       $(this).removeClass("campo_00");
     }
     $(this).addClass("campo_01");
  });
  $('#news_nome').blur(function() {
     $(this).removeClass("campo_01");
     if ($(this).val()==""){
        $(this).val("NOME");
       $(this).addClass("campo_02");
     }else{
       $(this).addClass("campo_00");
     }
  });

  $('#news_email').val("EMAIL");
  $('#news_email').focus(function() {
     if ($(this).val()=="EMAIL"){
        $(this).removeClass("campo_02");
        $(this).val("");
     }else{
       $(this).removeClass("campo_00");
     }
     $(this).addClass("campo_01");
  });
  $('#news_email').blur(function() {
     $(this).removeClass("campo_01");
     if ($(this).val()==""){
        $(this).val("EMAIL");
        $(this).addClass("campo_02");
     }else{
       $(this).addClass("campo_00");
     }
  });
});

function sendNewsletter(){
     $("#status").html("<img src='media/loader.gif' />");
     var email = $("#news_email").val();
     var nome = $("#news_nome").val();
     if (nome == "" || nome == "NOME"){
        $("#status").text("Por favor, informe o nome.");
     }
     else if (!/[A-Za-z0-9_.-]+@([A-Za-z0-9_]+\.)+[A-Za-z]{2,4}/.test(email)){
        $("#status").text("Por favor, informe um e-mail válido.");
     }
     else{
        $.post('newsletter.php', {email: email,nome: nome}, function(resposta) {
          if (resposta != false) {
             $("#status").text(resposta);
          }
          else {
             $("#status").text("E-mail cadastrado com sucesso!");
             $("#news_nome").val("NOME");
             $("#news_email").val("EMAIL");
             $("#news_nome").removeClass("campo_00");
             $("#news_nome").addClass("campo_02");
             $("#news_email").removeClass("campo_00");
             $("#news_email").addClass("campo_02");
          }
        });
     }
}

