$(document).ready(function(){
  
  // set up
  $("#send_extras").hide();
  $("#send_sent").hide();
  
  // Show the hidden fields if you click on any of the fields
  $(".send_form").focus(function(){
    $("#send_extras").slideDown(60);
    $(".send_sent").hide();
     return false;
   });

   // Clean up the form fields
  $("#send_to_email").focus(function(){
    if (this.value == "Friend's Email Address"){
      this.value = '';
    }
    return false;
  });
  
  $("#send_from_email").focus(function(){
    if (this.value == "Your Email"){
      this.value = '';
    }    
    return false;
  });
  
  $("#send_from_name").focus(function(){
    if (this.value == "Your Name"){
      this.value = '';
    }
    
    return false;
  });
  
  $("#send_message").focus(function(){
    if (this.value == "Your personal message"){
      this.value = '';
    }    
    return false;
  });
  
  // ajax form submit
  
  $("#send_form").submit( function() {
    $.post("/a/sendtoafriend",{
           to: $("#send_to_email").val(),
           from: $("#send_from_email").val(),
           from_name: $("#send_from_name").val(),
           message: $("#send_message").val()
          },
          function(data){
                if (data == 'Sent!' || data == 0){
                   $("#send_extras").slideUp(60);
                   $("#send_sent").show();
                   $("#send_sent").fadeOut(3000);

                   

                }
              }
    );
    return false;
  } );        
}); 
