// This file simply adds more form validators to the mootools Form.Validator class
//
// See the mootools documentation for usage of the Form.Validator class and how
// to specify the type of form validation for a form field
//
// Usage:
/*
    <script type="text/javascript" src="gtLib/GtFormValidators/GtFormValidators-en-US.js"></script>
    <script type="text/javascript" src="gtLib/GtFormValidators/GtFormValidators.js"></script>
*/
// NOTE: it is essential that GtFormValidatos-en-US.js is loaded before this
//       file
//
// NOTE: When creating new form validators, it is essential that an empty field
//       is treated as valid so that it can only fail when empty if "required" is included
//
// $Log: GtFormValidators.js $
// Revision 1.3  2011-02-24 14:37:44-04  Battersby
// - added postal code
//
// Revision 1.2  2010-10-26 11:33:29-04  Battersby
// - corrected usage documentation
//
// Revision 1.1  2010-10-25 11:40:31-04  Battersby
// Initial revision
//
//
Form.Validator.addAllThese([
  // characters that are valid for a name including " " and "-"
  ['lvalidate-name', {
    errorMsg: MooTools.lang.get("GtFormValidators","lvalidate-name"),
    test: function(field) {
      if (Form.Validator.getValidator('IsEmpty').test(field) ||
        field.value.match(/^[a-z \-]+$/i) ) {
        return true;
      }
      return false;
    }
  }],

  ['lvalidate-phone', {
    errorMsg: MooTools.lang.get("GtFormValidators","lvalidate-phone"),
    test: function(field) {
      // if the phone number is not in this format
      // 1-111-222-3333
      // or 1 111 222 3333
      // or 111-222-3333
      // or 111 222 3333
      // or 111 222 3333 x123
      // or 111 222 3333 ext 123 etc
      if (Form.Validator.getValidator('IsEmpty').test(field) ||
        field.value.match(/^(1[- \.])?\(?\d{3}\)?[- \.]\d{3}[- \.]\d{4}(\s+([xX ]|(ext)|(EXT)|(ex)|(EX))?\s*\d+)?$/) ) {
        return true;
      }
      return false;
    }
  }],

  // characters that are valid for a postal code
  ['lvalidate-postalCode', {
    errorMsg: MooTools.lang.get("GtFormValidators","lvalidate-postalCode"),
    test: function(field) {
      if (Form.Validator.getValidator('IsEmpty').test(field) ||
        field.value.match(/^[a-zA-Z]\d[a-zA-Z]\s*\d[a-zA-z]\d$/) ) {
        return true;
      }
      return false;
    }
  }]

]);


