/**
 * $Rev: 60 $:
 * $LastChangedDate: 2009-04-20 09:00:29 -0600 (Mon, 20 Apr 2009) $:
 * $Author: danolsen $:
 */

/**
 * isBlank checks if the value of an HTML element is blank. If it is then it
 * returns true, if not, it returns false.
 * 
 * @param element
 *            This is an HTML element that you want to check the value of.
 * @return
 */
function isBlank(value) {
	if (value == "") {
		return true;
	}
	return false;
}

/**
 * isZip takes a string and checks if it is a value zip code. It checks for the
 * following formats: XXXXX or XXXXX-XXXX
 * 
 * @param zip
 *            The string that you want to test whether or not it is a zip code.
 * @return
 */
function isZip(zip) {
	reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

	if (!reZip.test(zip)) {
		return false;
	}

	return true;
}

function isEmail(email) {
	reEmail = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
	
	if (!reEmail.test(email)) {
		return false;
	}
	return true;
}

/**
 * isValidPhoneNumberThreeAttr is a function that takes three attributes and
 * determines if you have a valid phone number. Each attribute you pass in is a
 * string.
 * 
 * @param areaCode
 *            A string that represents the area code.
 * @param first
 *            A string that represents the first three digits in the phone
 *            number.
 * @param second
 *            A string that represents the last four digits in the phone number.
 * @return
 */
function isValidPhoneNumberThreeAttr(areaCode, prefix, suffix) {
	var re3digit = new RegExp(/^\d{3}$/);
	var re4digit = new RegExp(/^\d{4}$/);

	if (!re3digit.test(areaCode) || !re3digit.test(prefix)
			|| !re4digit.test(suffix)) {
		return false;
	}

	return true;
}

function isValidDate(val) {
	var pieces = val.split("/");
	if (pieces.length != 3) {
		return false;
	}
	
	var month = parseInt(parseFloat(pieces[0]));
	var day = parseInt(parseFloat(pieces[1]));
	var yearStr = pieces[2];
	var year = parseInt(parseFloat(pieces[2]));
	var isLeap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	
	if (month < 0 || month > 12) {
		return false;
	}
	
	if (yearStr.length != 4) {
		return false;
	}
	
	if (day < 1 || day > 31) {
		return false;
	}
	
	if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
		return false;
	}
	
	if (month == 2 && (day > 29 || (day == 29 && !isLeap))) {
		return false;
	}
	
	return true;
}
