$(document).ready(function(){

  $(".warning").remove();
      
  //**********************************************SEND TO A FRIEND
  $("#sendtofriend").submit(function(event){  
    var yourNameVal = $("#yourName").val();
    var emailFromVal = $("#emailFrom").val();
    var emailToVal = $("#emailTo").val();
    if((yourNameVal == "") || (yourNameVal == "Your name")){
      $("#error_send").fadeIn().html("Please enter your name.");
      $("#yourName").focus();
      return false;
    }
    
    if((emailFromVal == "")||(!checkEmail(emailFromVal))){
			$("#error_send").fadeIn().html("Please enter a valid e-mail address to send from.");
      $("#emailFrom").focus();
			return false;
		}
    if((emailToVal == "")||(!checkEmail(emailToVal))){
			$("#error_send").fadeIn().html("Please enter a valid e-mail address to send to.");
      $("#emailTo").focus();
			return false;
		}
    $("#error_send:visible").fadeOut();
    
    $.post(def_path+"processors/p_friend.php",
  	  {yourname: yourNameVal, 
       emailto: emailToVal, 
       emailfrom: emailFromVal, 
       shareurl: $("#shareUrl").val(), 
       sharetitle: $("#shareTitle").val(), 
       shareleadin: $("#shareLeadIn").val(), 
       ip: $("#ip").val(),
       ts:$("#ts").val()},
      function(data){//callback function
  		  $("#error_send").fadeIn().html(data);
        $("#emailTo").val("").focus();
      }
    );
    return false;    
  });
  
  //**********************************************SUBSCRIBE
  $("#subscribe").submit(function(event){
    var emailSubscribeVal = $("#subscribeEmail").val();
    if((emailSubscribeVal == "")||(!checkEmail(emailSubscribeVal))){
      $("#error_subscribe").fadeIn().html("Please enter a valid e-mail address");
      return false;
    }
    $("#error_subscribe:visible").fadeOut();
    $.post(def_path+"processors/p_subscribe.php",
      {subscribeEmail:emailSubscribeVal},
      function(data){
        $("#error_subscribe").fadeIn().html(data);
      }
    );
    return false;
  });

});
