$(document).ready(function() {

  // get their email from the cookie
  var emailVal = $.cookie("username");
    
  // if their email is there
  if (emailVal != null && emailVal != "")
  {  
     // put it in the email field
     $("#email").val(emailVal);     
     
     // then use the email to look up their DB information and fill in the fields
     $.post("jsp/lookup_user.jsp", {email:emailVal }, function(data){
     
        if (data.result == "SUCCESS")
        {        
          $("#yourName").val(data.name);
     
          // put the focus on the text area
          $("#recipient_list").focus();
        }   
     }, "json");  
  
  }
  else
  {
     // if their email isn't there, put the focus on the email field
     $("#email").focus();
  }



    $("#sendFriends").click(function(){
          
      $(".error").text("");
	  var isError = false;
	  
	  if ($("#yourName").val()=="") 
	  {
	     $("#yourName").next().text(" Name cannot be blank");
	     isError = true;
	  }     
	  if ($("#email").val()=="")
	  {
	     $("#email").next().text(" Email cannot be blank");
	     isError = true;
	  }
	  if ($("#recipient_list").val()=="")
	  {
	     $("#recipient_list").next().text(" Recipients cannot be blank");
	     isError = true;
	  }
	  if (isError)
	      return;  
	      
      $("#form3").submit();
    });


});
