$(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")
        {        
          $("#Name").val(data.name);
          $("#Zip").val(data.zip);
          $("#City").val(data.city);
          $("#State").val(data.state);
          $("#Phone").val(data.phone);
     
        }   
     }, "json");  
  
  }

   $("#submitForm").click(function(){
   
      $(".error").text("");
	  var isError = false;
	  
	  if ($("#Email").val()=="") 
	  {
	     $("#Email").next().text(" Email cannot be blank");
	     isError = true;
	  }    	  
	  if ($("#Name").val()=="") 
	  {
	     $("#Name").next().text(" Name cannot be blank");
	     isError = true;
	  }    	  
	  if ($("#Zip").val()=="") 
	  {
	     $("#Zip").next().text(" Zip cannot be blank");
	     isError = true;
	  }     
	  
	  if (isError)
	      return;  
	      
      $("#form3").submit();
   
   });

});
