var SendATest = {

  send_feedback: function ( form ) {
      form = $( form );
      var form_contents = form.serialize(true);

      // Indicate that we are sending the feedback.
      form.submit.value = "Sending feedback...";
      
      new Ajax.Request(
           form.action,
          {
              parameters: form_contents,
              onSuccess: function () {
                  form.feedback.clear();
                  form.feedback.focus();
                  form.submit.value = "Feedback received - thank you!";

                  // Add a smily face as a thank you.
                  new Insertion.Bottom(
                      form,
                      "<img src='/static/8/icons/emoticon_smile.png'>"
                  );
                  
                  setTimeout(
                      function () { 
                           form.submit.value   = "Send more feedback";
                      },
                      5000  // 5 seconds
                  ); 
              },
              onFailure: function () {
                  form.submit.value =
                    "something went wrong, will try again soon...";
                  setTimeout(
                      function () { SendATest.send_feedback( form ); },
                      10000 // 10 seconds
                  ); 
                  
              }
          }
      );
      
  }
  
};

