// wForms - a javascript extension to web forms.
// Customization Example (wForms v0.94 - April 26 2005)
// Copyright (c) 2005 Cédric Savarese <pro@4213miles.com>
// This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>


//The Repeat behavior preserves the name attribute of radio inputs 
// accross repeated elements, effectively expanding the radio group. 
// Set to ‘false’ to make repeated radio inputs independant.
wf.preserveRadioName = true; // default: true.

// The validation routine will display an alert box if there’s an error, with the message in wf.arrErrorMsg[8]
wf.showAlertOnError = false; // default: true. 
// Error message displayed in the alert box.
wf.arrErrorMsg[8] = "%% error(s) detected. Your form has not been submitted yet.\nPlease check the information you provided."; // %% will be replaced by the actual number of errors.

// overwrite the default form submission handler with a custom one.
wf.functionName_formValidation = "customValidation";

//evt : onSubmit event
function customValidation(evt) {
	
	if(wf.formValidation(evt)) {	// call the default error management.

		// basic wForms Validation Ok... can do other stuff here
		// if validation not ok, use return wf.utilities.XBrowserPreventEventDefault(e);  
		
	} else {
		return wf.utilities.XBrowserPreventEventDefault(evt);  // will prevent the form from being submitted.
	}
}

wFORMS.functionName_formValidation = "doPostBack";
function doPostBack(e) { 
    if(!e) e = window.event;    
    
    //  call the default error management.  
    if(wFORMS.behaviors['validation'].run(e)) {            
      //  doing our custom validation here:

      // if needed, the form element can be obtained with:
      // var f = wFORMS.helpers.getSourceElement(e);

      var eMailField = document.getElementById('eMail');
      var confirmField  = document.getElementById('confirmeMail');
              
      if(eMailField.value != confirmField.value) {
        // eMails don't match, show error message:
        var errorMessage = "The eMails don't match.";
        wFORMS.behaviors['validation'].showError(confirmField, errorMessage);
        // we need to prevent the submission:
        return wFORMS.helpers.preventEvent(e);     
      }
      // otherwise all is good, 
      return true;                        
     }
}
