function BuildError(msg) {
	return "<table><tr><td class=\"errorcell\"><img src=\"assets/images/icon_err.gif\" /><\/td><td>"+msg+"<\/td><\/tr><\/table>"
}
function CheckCondition(ConditionValue,FieldID,ErrorMessage) {
	if (ConditionValue) {
		document.getElementById('Error_'+FieldID).innerHTML = BuildError(ErrorMessage);
		document.getElementById(FieldID).focus();
		return false;
	} else {
		return true;
	}
}
function ValidateDate(MonthElement,DayElement) {
	MonthValue = parseInt(MonthElement.value);
	DayValue   = parseInt(DayElement.value,10);
	result = ((MonthValue == 1 || MonthValue == 3 || MonthValue == 5 || MonthValue == 7 || MonthValue == 8 || MonthValue == 10 || MonthValue == 12) && (isNaN(DayValue) || DayValue < 1 || DayValue > 31)) ||
	         ((MonthValue == 4 || MonthValue == 6 || MonthValue == 9 || MonthValue == 11) && (isNaN(DayValue) || DayValue < 1 || DayValue > 30)) ||
	         ((MonthValue == 2) && (isNaN(DayValue) || DayValue < 1 || DayValue > 29)) ||
	         ((MonthValue == 0 || isNaN(MonthValue)) && isFinite(DayValue));
	return result;
}
function Validate() {
	if (!document.getElementById) { return true; };
	valid = true;
	document.getElementById('Error_Name').innerHTML = "";
	document.getElementById('Error_EmailAddress').innerHTML = "";
	document.getElementById('Error_AnnivMonth').innerHTML = "";
	document.getElementById('Error_HisMonth').innerHTML = "";
	document.getElementById('Error_HerMonth').innerHTML = "";
	valid = CheckCondition(
		ValidateDate(document.getElementById('form').HerMonth,document.getElementById('form').HerDay),
		"HerMonth","The date you entered for her birthday is not valid.") && valid;
	valid = CheckCondition(
		ValidateDate(document.getElementById('form').HisMonth,document.getElementById('form').HisDay),
		"HisMonth","The date you entered for his birthday is not valid.") && valid;
	valid = CheckCondition(
		ValidateDate(document.getElementById('form').AnnivMonth,document.getElementById('form').AnnivDay),
		"AnnivMonth","The anniversary date you entered is not valid.") && valid;
	valid = CheckCondition(
		document.getElementById('form').EmailAddress.value == "" && document.getElementById('form').PhoneNumber.value == "",
		"EmailAddress","You must enter either an email address or telephone number.") && valid;
	valid = CheckCondition(
		document.getElementById('form').EmailAddress.value == "" && document.getElementById('form').Newsletter.checked == true,
		"EmailAddress","You must enter your email address to sign up for the Black Swan Inn newsletter.") && valid;
	valid = CheckCondition(
		document.getElementById('form').Name.value == "",
		"Name","You must enter your name.") && valid;
	return valid;
}

