/* Called to check that a required field is present */
// Returns true/false depending on if data present
function CheckForInput(inp, value2check){
	// Check that there is data
	if(stripWhitespace(inp.value) == value2check){
		// Highlight the background color if fail
		inp.style.backgroundColor = 'lightpink';
		return false;
	}else{
		// Remove the background color if ok
		inp.style.backgroundColor = 'white';
		return true;
	}
}

/* Remove white space from start & end of string */
function stripWhitespace(str) {
	str = this != window ? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

/* Function to validate an email address */
function validateEmail(email) {
	var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	return regex.test(email);
}

/* Function to validate a date */
function IsDate(month, day, year) {
	if (month < 1 || month > 12) { 
		// check month range
		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) { 
		// check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day == 29 && !isleap)) {
			return false;
		}
	}
	return true;
}