/**
 * Additional jQuery validator methods that are likely to be reusable
 * across multiple projects. Feel free to use the entire file or just
 * individual methods. If you add new methods, please add them to the
 * central custom methods file.
 *
 * @author Josh Justice <josh.justice@northpoint.org>
 */

/**
 * Add any custom validation rules here.
 *
 * For details, see http://jqueryvalidation.org/jQuery.validator.addMethod
 */
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, "");
        return this.optional(element) || phone_number.length > 9 &&
                phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");

jQuery.validator.addMethod("postalcode", function(postalcode, element) {
	return this.optional(element) || postalcode.match(/^\d{5}(-\d{4})?$/);
}, "Please specify a valid postal/zip code");

jQuery.validator.addMethod("before_now", function(value, element) {
	if(this.optional(element)) { return true; }
	var mydate = new Date(value);
	// TODO: this doesn't handle times well. probably best to use
	// moment.js for parsing, but didn't want to add that dependency yet
	if( typeof mydate === 'undefined' ) {
		return false;
	}
	return mydate < new Date(); // today
}, "Please specify a date that is in the past");


@@ -1370,12 +1370,547 @@
 he past%22);%0A%0A
+jQuery.validator.addMethod(%22required_if%22, function(value, element, extras) %7B%0A%09console.dir(element);%0A%09%0A%09if(value == '') %7Breturn false; %7D%0A%09%0A%09var value_arr = extras.split(',');%0A%09var element_to_access = value_arr%5B0%5D;%0A%09var values_to_access =value_arr%5B1%5D.split(%22%7C%22);%0A%09%0A%09var value_of_element_to_access = $('%5Bname=' + element_to_access + '%5D').val();%0A%09%0A%09var valid = false;%0A%09%0A%09for (var key in values_to_access) %7B%0A%09%09if (values_to_access%5Bkey%5D == value_of_element_to_access) %7B%0A%09%09%09valid = true;%0A%09%09%7D%0A%09%7D%0A%09%0A%09return valid;%0A%7D, %22This Field is required.%22);

Add required_if