  // *******************  Begin Form Validator Class  ***************************************
  // Form validation code created by Hawk Innovations
  function FormValidator () {
    this.RequiredFields = new Object(); // associative array

    //methods
    this.isFormValid = private_validator_isFormValid;
    this.addField = private_validator_addField;
    this.displayError = private_validator_displayError;

    return this;
  }

  function private_validator_isFormValid () {
    for (field in this.RequiredFields) {
        var ref = eval(this.RequiredFields[field]['field']);
        if ( this.RequiredFields[field]['params'] ) {
	        var params = this.RequiredFields[field]['params'].split(',');	        
	    }
        if ( this.RequiredFields[field]['validationType'] == 'empty') {
              if (ref.type == 'text' || ref.type == 'textarea' || ref.type == 'password' || ref.type == 'hidden') {
                      if (isEmpty(ref.value) == true) {
                              this.displayError(ref, this.RequiredFields[field]['errorMsg']);
                              return false;
                      }
              }
        }
        else if ( this.RequiredFields[field]['validationType'] == 'email') {
              if (ref.type == 'text' || ref.type == 'textarea') {
                    if (!isEmail(ref.value) == true) {
                            this.displayError(ref, this.RequiredFields[field]['errorMsg']);
                            return false;
                    }
              }
        }
        else if ( this.RequiredFields[field]['validationType'] == 'emailDomainMatch') {
              if (ref.type == 'text' || ref.type == 'textarea') {
              		for (var i=0; i<params.length; i++){
              			if (emailDomain(ref.value) == params[i].toLowerCase()) break;
                    }
                    
                    if (i==params.length && emailDomain(ref.value) != params[i-1].toLowerCase()){
	                    this.displayError(ref, this.RequiredFields[field]['errorMsg']);
	                    return false;
	                }
              }
        }
	    else if ( this.RequiredFields[field]['validationType'] == 'number') {
	            if (ref.type == 'text' || ref.type == 'textarea') {
	                  if (!isNumber(ref.value) == true) {
	                          this.displayError(ref, this.RequiredFields[field]['errorMsg']);
	                          return false;
	                  }
	            }
	    }
   	    else if ( this.RequiredFields[field]['validationType'] == 'length') {
	            if (ref.type == 'text' || ref.type == 'textarea' || ref.type == 'password') {
	            	  var theCondition = params[0];
	            	  var theLimit = params[1];
	                  if ( eval(ref.value.length + theCondition + theLimit) ) {
	                          this.displayError(ref, this.RequiredFields[field]['errorMsg']);
	                          return false;
	                  }
	            }
	    }
        else if ( this.RequiredFields[field]['validationType'] == 'select') {
              if (ref.type == 'select-one') {
                      var displayErr = false;
                      if (ref.selectedIndex == -1) {
                          displayErr = true;
                      }
                      if (ref.options[ref.selectedIndex].selected == true && ref.options[ref.selectedIndex].defaultSelected == true) {
                          displayErr = true;
                      }
                      if (displayErr == true) {
                          this.displayError(ref, this.RequiredFields[field]['errorMsg']);
                          return false;
                      }
              }
        }
     }
     return true;
  }

  function private_validator_addField (objName, objRef, validationType, errorMsg, params) {
          this.RequiredFields[objName] = new Object();
          this.RequiredFields[objName]['field'] = objRef;
          this.RequiredFields[objName]['validationType'] = validationType;
          this.RequiredFields[objName]['errorMsg'] = errorMsg;
          this.RequiredFields[objName]['params'] = params;
  }

  function private_validator_displayError (field, errorMsg) {
          alert(errorMsg);
          if (field.type == 'text' || field.type == 'textarea' || field.type == 'password') field.select();
          if (field.type != 'hidden') field.focus();
  }
  // *******************  End Form Validator Class  *****************************************

  // *************  Begin Form Validator Support Functions  *********************************
  function isEmpty (theValue) {
		var whitespace = " \t\n\r";
    if (theValue == "" || theValue == null) {
      return true;
    }
    else {
	    for (i = 0; i < theValue.length; i++){
	        // Check that current character isn't whitespace.
	        var c = theValue.charAt(i);
	        if (whitespace.indexOf(c) == -1) return false;
	    }
			return true;
    }
  }

  function isEmail (objInputValue) {
          var email = objInputValue;

          if (email == "") return false;
          if (email.indexOf('@') == -1) return false; // no @ symbol (bob)
          if (email.indexOf('@') != email.lastIndexOf('@')) return false; // more than 1 @ symbol (bob@aol@aol)
          if (email.indexOf('.') == -1) return false; // no periods (bob@aol)
          if (email.lastIndexOf('.') < email.indexOf('@')) return false; // no periods after the @ symbol (aol.com@bob)
          if (email.indexOf('@') == 0) return false; // nothing before the @ symbol (@aol.com)
          if (email.indexOf('@') == email.length - 1) return false; // nothing after the @ symbol (bob@)
          if (email.indexOf('@.') != -1 || email.indexOf('.@') != -1) return false; // no characters between @ and period (bob@. or bob.@)
          if (email.lastIndexOf('.') == email.length - 1) return false; // nothing after the last period (bob@aol.)
          if (email.indexOf('..') != -1) return false; // no double periods (bob@aol..com)
          if (email.lastIndexOf('.') != email.length - 3 && email.lastIndexOf('.') != email.length - 4 && email.lastIndexOf('.') != email.length - 5) return false; // suffix 2 or 3 or 4 characters max

          var username = email.substring(0, email.indexOf('@'));
          var domain = email.substring(email.indexOf('@') + 1, email.length);

          //check username for bad characters
          for (i = 0; i < username.length; i++) {
                  var current = username.charAt(i);
                  var acceptableChars = '!"#$%&\'()*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
                  if (acceptableChars.indexOf(current) == -1) return false;
          }

          //check domain for bad characters
          for (j = 0; j < domain.length; j++) {
                  var current = domain.charAt(j);
                  var acceptableChars = '.-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
                  if (acceptableChars.indexOf(current) == -1) return false;
          }

          return true; // if we get here, all's fine...
  }

	function isNumber (theValue) {
	  return !isNaN(theValue);
	}
	
  function emailDomain(email){
    return email.substring(email.indexOf('@') + 1, email.length).toLowerCase();
  }
  // *************  End Form Validator Support Functions  *********************************

