/**
 * matches US phone number format 
 * 
 * where the area code may not start with 1 and the prefix may not start with 1 
 * allows '-' or ' ' as a separator and allows parens around area code 
 * some people may want to put a '1' in front of their number 
 * 
 * 1(212)-999-2345
 * or
 * 212 999 2344
 * or
 * 212-999-0983
 * 
 * but not
 * 111-123-5434
 * and not
 * 212 123 4567
 */
jQuery.validator.addMethod("zipcode", function(zip, element) {
	var valid = "0123456789-";
	var hyphencount = 0;
	
	if (zip.length != 5 && zip.length != 10) {
		return false;
	}
	for (var i=0; i < zip.length; i++) {
		temp = "" + zip.substring(i, i+1);
		if (temp == "-") { hyphencount++; }
		if (valid.indexOf(temp) == "-1") {
			return false;
		}
		if ((hyphencount > 1) || ((zip.length==10) && ""+zip.charAt(5)!="-")) {
			return false;
		}
	}
	return true;
}, "ZIP code does not appear to be valid");

/**
 * matches US ZIP code format 
 */
jQuery.validator.addMethod("phone", function(phonenumber, element) {
	return this.optional(element) || phonenumber.match(/^[ ]*[+]{0,1}[ ]*[1]{0,1}[-|.]{0,1}[ ]*[(]{0,1}[ ]*[0-9]{3,3}[ ]*[)]{0,1}[-|.]{0,1}[ ]*[0-9]{3,3}[ ]*[-|.]{0,1}[ ]*[0-9]{4,4}[ ]*$/);
}, "Phone number does not appear to be valid");
