$(document).ready(function(){

  $("#submit").click(function(){

    $(".error").hide();

    var hasError = false;

    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;


/*
    var emailToVal = $("#emailTo").val();

    if(emailToVal == '') {

      $("#emailTo").after('<span class="error">You forgot to enter the email address to send to.</span>');

      hasError = true;

    } else if(!emailReg.test(emailToVal)) {

      $("#emailTo").after('<span class="error">Enter a valid email address to send to.</span>');

      hasError = true;

    }

*/

    var emailFromVal = $("#emailFrom").val();

    if(emailFromVal == '') {

      $("#emailFrom").after('<span class="error">You forgot to enter the email address to send from.</span>');

      hasError = true;

    } else if(!emailReg.test(emailFromVal)) {

      $("#emailFrom").after('<span class="error">Enter a valid email address to send from.</span>');

      hasError = true;

    }






    if(hasError == false) {

      $(this).hide();

      $("#sendEmail li.buttons").append('<img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" />');



      $.post("/lessons/includes/sendemail.php",
//emailTo: emailToVal, 
           { emailFrom: emailFromVal },

             function(data){

            $("#sendEmail").slideUp("normal", function() {



              $("#sendEmail").before('<h3 class="register2">Success</h3><p>You are on the lesson email list.</p>');

            });

             }

         );

    }



    return false;

  });

});
