/**
 * Form helper functions.
 */
MSGI.form = {

	/**
	 * Validates an email.
	 * @param {string} email the email address
	 * @returns {boolean} true if valid; otherwise, false.
	 */
	validateEmail: function(email) {
		return (/^[a-zA-Z0-9._%+-]+\@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/).test(email);
	},

	/**
	 * Validate that the value is at least the minimum amount of characters
	 * @param {string} value the value of the field
	 * @param {string} minimum the minimum length for the value
	 * @returns {boolean} true if at least the minimum; otherwise, false
	 */
	validateMinimumLength: function(value, minimum) {
		return ((typeof value == "string") && (value.length >= minimum));
	},

	/**
	 * Validate that the value is at most the maximum amount of characters
	 * @param {string} value the value of the field
	 * @param {string} maximum the maximum length for the value
	 * @returns {boolean} true if at least the minimum; otherwise, false
	 */
	validateMaximumLength: function(value, maximum) {
		return ((typeof value == "string") && (value.length <= maximum));
	},


	/**
	 * Validate that the password and password confirmation are the same
	 * @param {string} password the password
	 * @param {string} passwordConfirmation the password confirmation
	 * @returns {boolean} true if the same; otherwise, false
	 */
	validatePasswordConfirmation: function(password, passwordConfirmation) {
		return (typeof password == "string" && typeof passwordConfirmation == "string") && (password == passwordConfirmation);
	},

	/**
	 * Validate that the value is not blank
	 * @param {string} value the value of the field
	 * @returns {boolean} true if present; otherwise, false
	 */
	validatePresenceOfValue: function(value) {
		return (typeof value == "string") && value != '';
	},

	/**
	 * Validate that the item is checked
	 * @param {boolean} checked the value of the checkbox
	 * @returns {boolean} true if checked; otherwise, false
	 */
	validatePresenceOfChecked: function(checked) {
		return (typeof checked == "boolean") && checked;
	},

	/**
	 * List of states
	 * @returns {object} list of states
	 */
	stateList: {
		"AL": "ALABAMA",
		"AK": "ALASKA",
		"AZ": "ARIZONA",
		"AR": "ARKANSAS",
		"CA": "CALIFORNIA",
		"CO": "COLORADO",
		"CT": "CONNECTICUT",
		"DE": "DELAWARE",
		"DC": "DISTRICT OF COLUMBIA",
		"FL": "FLORIDA",
		"GA": "GEORGIA",
		"HI": "HAWAII",
		"ID": "IDAHO",
		"IL": "ILLINOIS",
		"IN": "INDIANA",
		"IA": "IOWA",
		"KS": "KANSAS",
		"KY": "KENTUCKY",
		"LA": "LOUISIANA",
		"ME": "MAINE",
		"MD": "MARYLAND",
		"MA": "MASSACHUSETTS",
		"MI": "MICHIGAN",
		"MN": "MINNESOTA",
		"MS": "MISSISSIPPI",
		"MO": "MISSOURI",
		"MT": "MONTANA",
		"NE": "NEBRASKA",
		"NV": "NEVADA",
		"NH": "NEW HAMPSHIRE",
		"NJ": "NEW JERSEY",
		"NM": "NEW MEXICO",
		"NY": "NEW YORK",
		"NC": "NORTH CAROLINA",
		"ND": "NORTH DAKOTA",
		"OH": "OHIO",
		"OK": "OKLAHOMA",
		"OR": "OREGON",
		"PA": "PENNSYLVANIA",
		"RI": "RHODE ISLAND",
		"SC": "SOUTH CAROLINA",
		"SD": "SOUTH DAKOTA",
		"TN": "TENNESSEE",
		"TX": "TEXAS",
		"UT": "UTAH",
		"VT": "VERMONT",
		"VA": "VIRGINIA",
		"WA": "WASHINGTON",
		"WV": "WEST VIRGINIA",
		"WI": "WISCONSIN",
		"WY": "WYOMING"
	},

	/**
	 * List of provinces
	 * @returns {array} list of provinces
	 */
	provinceList: [
		"Alberta",
		"British Columbia",
		"Manitoba",
		"New Brunswick",
		"Newfoundland and Labrador",
		"Northwest Territories",
		"Nova Scotia",
		"Nunavut",
		"Ontario",
		"Prince Edward Island",
		"Québec",
		"Saskatchewan",
		"Yukon"
	],

	/**
	 * List of countries
	 * @returns {array} list of countries
	 */
	countryList_short: [
		"United States",
		"Canada",
		"France",
		"Spain",
		"United Kingdom"
	],


	/**
	 * List of countries
	 * @returns {array} list of countries
	 */
	countryList: [
		"United States",
		"Afghanistan",
		"Albania",
		"Algeria",
		"Andorra",
		"Angola",
		"Antigua and Barbuda",
		"Argentina",
		"Armenia",
		"Australia",
		"Austria",
		"Azerbaijan",
		"Bahamas, The",
		"Bahrain",
		"Bangladesh",
		"Barbados",
		"Belarus",
		"Belgium",
		"Belize",
		"Benin",
		"Bhutan",
		"Bolivia",
		"Bosnia and Herzegovina",
		"Botswana",
		"Brazil",
		"Brunei",
		"Bulgaria",
		"Burkina Faso",
		"Burma",
		"Burundi",
		"Cambodia",
		"Cameroon",
		"Canada",
		"Cape Verde",
		"Central African Republic",
		"Chad",
		"Chile",
		"China",
		"Colombia",
		"Comoros",
		"Congo (Brazzaville)",
		"Congo (Kinshasa)",
		"Costa Rica",
		"Cote d'Ivoire",
		"Croatia",
		"Cuba",
		"Cyprus",
		"Czech Republic",
		"Denmark",
		"Djibouti",
		"Dominica",
		"Dominican Republic",
		"East Timor (see Timor-Leste)",
		"Ecuador",
		"Egypt",
		"El Salvador",
		"Equatorial Guinea",
		"Eritrea",
		"Estonia",
		"Ethiopia",
		"Fiji",
		"Finland",
		"France",
		"Gabon",
		"Gambia, The",
		"Georgia",
		"Germany",
		"Ghana",
		"Greece",
		"Grenada",
		"Guatemala",
		"Guinea",
		"Guinea-Bissau",
		"Guyana",
		"Haiti",
		"Holy See",
		"Honduras",
		"Hong Kong",
		"Hungary",
		"Iceland",
		"India",
		"Indonesia",
		"Iran",
		"Iraq",
		"Ireland",
		"Israel",
		"Italy",
		"Jamaica",
		"Japan",
		"Jordan",
		"Kazakhstan",
		"Kenya",
		"Kiribati",
		"Korea, North",
		"Korea, South",
		"Kosovo",
		"Kuwait",
		"Kyrgyzstan",
		"Laos",
		"Latvia",
		"Lebanon",
		"Lesotho",
		"Liberia",
		"Libya",
		"Liechtenstein",
		"Lithuania",
		"Luxembourg",
		"Macau",
		"Macedonia",
		"Madagascar",
		"Malawi",
		"Malaysia",
		"Maldives",
		"Mali",
		"Malta",
		"Marshall Islands",
		"Mauritania",
		"Mauritius",
		"Mexico",
		"Micronesia",
		"Moldova",
		"Monaco",
		"Mongolia",
		"Montenegro",
		"Morocco",
		"Mozambique",
		"Namibia",
		"Nauru",
		"Nepal",
		"Netherlands",
		"Netherlands Antilles",
		"New Zealand",
		"Nicaragua",
		"Niger",
		"Nigeria",
		"North Korea",
		"Norway",
		"Oman",
		"Pakistan",
		"Palau",
		"Palestinian Territories",
		"Panama",
		"Papua New Guinea",
		"Paraguay",
		"Peru",
		"Philippines",
		"Poland",
		"Portugal",
		"Qatar",
		"Romania",
		"Russia",
		"Rwanda",
		"Saint Kitts and Nevis",
		"Saint Lucia",
		"Saint Vincent and the Grenadines",
		"Samoa",
		"San Marino",
		"Sao Tome and Principe",
		"Saudi Arabia",
		"Senegal",
		"Serbia",
		"Seychelles",
		"Sierra Leone",
		"Singapore",
		"Slovakia",
		"Slovenia",
		"Solomon Islands",
		"Somalia",
		"South Africa",
		"South Korea",
		"Spain",
		"Sri Lanka",
		"Sudan",
		"Suriname",
		"Swaziland",
		"Sweden",
		"Switzerland",
		"Syria",
		"Taiwan",
		"Tajikistan",
		"Tanzania",
		"Thailand",
		"Timor-Leste",
		"Togo",
		"Tonga",
		"Trinidad and Tobago",
		"Tunisia",
		"Turkey",
		"Turkmenistan",
		"Tuvalu",
		"Uganda",
		"Ukraine",
		"United Arab Emirates",
		"United Kingdom",
		"Uruguay",
		"Uzbekistan",
		"Vanuatu",
		"Venezuela",
		"Vietnam",
		"Yemen",
		"Zambia",
		"Zimbabwe"
	]
};
