// 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 == 'ccc_contactcustcare') {
       successDiv = 'ccc_emailSuccess';
       formAction = 'php/ccc_sendmail.php';
       opt = {
          onLoading: function(request) {
			 document.getElementById("ccc_submit").disabled = true; 
             sendmail_onLoading('ccc_loadBar');
          },
          onComplete: function(request) {
             sendmail_onComplete('ccc_loadBar', successDiv);
             clearForm(srcForm.name);
			 document.getElementById("ccc_submit").disabled = false; 
          },
          parameters: Form.serialize(srcForm),
          insertion: Insertion.Bottom,
          asynchronous: true
       }
	}
    if (srcForm.name == 'nsn_quoterequest') {
       successDiv = 'nsn_emailSuccess';
       formAction = 'php/nsn_sendmail.php';
       opt = {
          onLoading: function(request) {
		     document.getElementById("nsn_submit").disabled = true; 
             sendmail_onLoading('nsn_loadBar');
          },
          onComplete: function(request) {
             sendmail_onComplete('nsn_loadBar', successDiv);
			 clearForm(srcForm.name);
			 document.getElementById("nsn_submit").disabled = false; 
		  },
          parameters: Form.serialize(srcForm),
          insertion: Insertion.Bottom,
          asynchronous: true
       }
    }
    if (srcForm.name == 'rosr_servicerequest') {
       successDiv = 'rosr_emailSuccess';
       formAction = 'php/rosr_sendmail.php';
       opt = {
          onLoading: function(request) {
			 document.getElementById("rosr_submit").disabled = true; 
             sendmail_onLoading('rosr_loadBar');
          },
          onComplete: function(request) {
             sendmail_onComplete('rosr_loadBar', successDiv);
			 clearForm(srcForm.name);
			 document.getElementById("rosr_submit").disabled = false; 
          },
          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);
}
function sendmail_onComplete(theLoadingDiv, theSuccessDiv) {
    // Fade the Progress Bar
    new Effect.Fade(theLoadingDiv);
    // Show the result!
    new Effect.Appear(theSuccessDiv, {queue: 'end'});
}

function clearForm(formIdent) 
{ 
  var form, elements, i, elm; 
  form = document.getElementById 
    ? document.getElementById(formIdent) 
    : document.forms[formIdent]; 

	if (document.getElementsByTagName)
	{
		elements = form.getElementsByTagName('input');
		for( i=0, elm; elm=elements.item(i++); )
		{
			if (elm.getAttribute('type') == "text")
			{
				elm.value = '';
			}
		}
		elements = form.getElementsByTagName('textarea');
		for( i=0, elm; elm=elements.item(i++); )
		{
			elm.value = '';
		}
		elements = form.getElementsByTagName('select');
		for( i=0, elm; elm=elements.item(i++); )
		{
			elm.options.selectedIndex=0;
		}
	}

	// Actually looking through more elements here
	// but the result is the same.
	else
	{
		elements = form.elements;
		for( i=0, elm; elm=elements[i++]; )
		{
			if (elm.type == "text")
			{
				elm.value ='';
			}
		}
	}
}