// Turn off the alert pop up
wf.showAlertOnError = false;

// Replace the standard validation routine and do our Ajax stuff
wf.functionName_formValidation = "myCustomValidation";
function myCustomValidation (evt) {
    // Determine which form we're dealing with
    var srcForm = wf.utilities.getSrcElement(evt);
    while (srcForm && srcForm.tagName.toUpperCase() != 'FORM') {
       srcForm = srcForm.parentNode;
    }
    var opt;
    var successDiv;
    var formAction;
    if (srcForm.name == 'rosr_servicerequest') {
       successDiv = 'rosr_emailSuccess';
       formAction = '../php/rosr_sendmail.php';
       opt = {
          onLoading: function(request) {
             sendmail_onLoading('rosr_loadBar');
          },
          onComplete: function(request) {
             sendmail_onComplete('rosr_loadBar', successDiv);
          },
          parameters: Form.serialize(srcForm),
          insertion: Insertion.Bottom,
          asynchronous: true
       }
    }
    if(wf.formValidation(evt)) {
       if (!(successDiv == undefined || formAction == undefined)) {
          new Ajax.Updater(successDiv, formAction, opt);
          return wf.utilities.XBrowserPreventEventDefault(evt);
       }
    }
}
function sendmail_onLoading(theLoadingDiv) {
    // Make the Progress Bar Appear
    new Effect.Appear(theLoadingDiv, {queue: 'front'});
}
function sendmail_onComplete(theLoadingDiv, theSuccessDiv) {
    // Fade the Progress Bar
    new Effect.Fade(theLoadingDiv);
    // Show the result!
    new Effect.Appear(theSuccessDiv, {queue: 'end'});
}
