
//
//	For each column (col01, col02 etc) change the class when rolled over.
//
function trHover(idNumber, column_no) {
	if (column_no != 0) {
		if (column_no >= 1) {
			var col01OffObj = document.getElementById("col01Off"+idNumber);
			col01OffObj.className = "hover";
		}
		if (column_no >= 2) {
			var col02OffObj = document.getElementById("col02Off"+idNumber);
			col02OffObj.className = "hover";
		}
		if (column_no >= 3) {
			var col03OffObj = document.getElementById("col03Off"+idNumber);
			col03OffObj.className = "hover";
		}
		if (column_no >= 4) {
			var col04OffObj = document.getElementById("col04Off"+idNumber);
			col04OffObj.className = "hover";
		}
		if (column_no >= 5) {
			var col05OffObj = document.getElementById("col05Off"+idNumber);
			col05OffObj.className = "hover";
		}
		if (column_no >= 6) {
			var col06OffObj = document.getElementById("col06Off"+idNumber);
			col06OffObj.className = "hover";
		}
		if (column_no >= 7) {
			var col07OffObj = document.getElementById("col07Off"+idNumber);
			col07OffObj.className = "hover";
		}
		if (column_no >= 8) {
			var col08OffObj = document.getElementById("col08Off"+idNumber);
			col08OffObj.className = "hover";
		}
		if (column_no >= 9) {
			var col09OffObj = document.getElementById("col09Off"+idNumber);
			col09OffObj.className = "hover";
		}
		if (column_no >= 10) {
			var col10OffObj = document.getElementById("col10Off"+idNumber);
			col10OffObj.className = "hover";
		}
		if (column_no >= 11) {
			var col11OffObj = document.getElementById("col11Off"+idNumber);
			col11OffObj.className = "hover";
		}
		if (column_no >= 12) {
			var col12OffObj = document.getElementById("col12Off"+idNumber);
			col12OffObj.className = "hover";
		}
	}
}

//
//	For each column (col01, col02 etc) change the class when rolled out.
//
function trHoverOut(idNumber, column_no) {
	if (column_no != 0) {
		if (column_no >= 1) {
			var col01OffObj = document.getElementById("col01Off"+idNumber);
			col01OffObj.className = "off";
		}
		if (column_no >= 2) {
			var col02OffObj = document.getElementById("col02Off"+idNumber);
			col02OffObj.className = "off";
		}
		if (column_no >= 3) {
			var col03OffObj = document.getElementById("col03Off"+idNumber);
			col03OffObj.className = "off";
		}
		if (column_no >= 4) {	
			var col04OffObj = document.getElementById("col04Off"+idNumber);
			col04OffObj.className = "off";
		}
		if (column_no >= 5) {	
			var col05OffObj = document.getElementById("col05Off"+idNumber);
			col05OffObj.className = "off";
		}
		if (column_no >= 6) {	
			var col06OffObj = document.getElementById("col06Off"+idNumber);
			col06OffObj.className = "off";
		}
		if (column_no >= 7) {	
			var col07OffObj = document.getElementById("col07Off"+idNumber);
			col07OffObj.className = "off";
		}
		if (column_no >= 8) {
			var col08OffObj = document.getElementById("col08Off"+idNumber);
			col08OffObj.className = "off";
		}
		if (column_no >= 9) {	
			var col09OffObj = document.getElementById("col09Off"+idNumber);
			col09OffObj.className = "off";
		}
		if (column_no >= 10) {	
			var col10OffObj = document.getElementById("col10Off"+idNumber);
			col10OffObj.className = "off";
		}
		if (column_no >= 11) {	
			var col11OffObj = document.getElementById("col11Off"+idNumber);
			col11OffObj.className = "off";
		}
		if (column_no >= 12) {	
			var col12OffObj = document.getElementById("col12Off"+idNumber);
			col12OffObj.className = "off";
		}
	}
}

//
//	Returns true if the given variable is blank:
//
function IsBlank(value) {
	// cast to string.
	var str = "" + value;
	return ((str == "") || (str == " ") || (str == "undefined") || (str == "null") || (str == null));
}

//
//	Checks whether the user has entered data in the given field, displaying the given message,
//	focusing the field and returning false if not:
//
function CheckMandatory(field, msg) {
	if (IsBlank(field.value)) {
		alert(msg);
		field.focus();
		return false;
	}
	return true;
}	

//
//	Clears the default text from the search box when the field is clicked, but leaves any other text as is,
//	in case the user wants to amend a current search keyword:
//
function ClickSearch(field) {
	if (field.value == 'Search...') {
		field.value='';
	}
}

//
// Validates the form:
//
function ValidateFormLogin(form) {
	if (!CheckMandatory(form.emailaddress, "Please enter your email address to login to your account.")) return false;
	if (!CheckMandatory(form.password, "Please enter your password. If you cannot remember it, please click on the 'Forgot Your Password?' link.")) return false;
	return true;
}

//
//	Checks to see if the year is a leap year, returning true if it is.
//
function IsLeapYear(theyear) {
	if (theyear % 4 == 0) {
		if (theyear % 100 == 0) {
			if (theyear % 400 == 0) {
	    	LeapYear = true;
			}
			else {
	    	LeapYear = false;
			}
		}
		else {
			LeapYear = true;
		}
	}
	else {
		LeapYear = false;
	}
	return LeapYear;
}


//
// Update the date to select box automatically based on date from selection.
// Note: the date to select box isnt changed if the date is greater than the date from value.
//
function ChangedTheDate() {
	fromdate = new Date(document.all.theyear.value, document.all.themonth.value, document.all.theday.value);
	todate = new Date(document.all.theyear2.value, document.all.themonth2.value, document.all.theday2.value);
	var updatedate = false;
	if (fromdate.getTime() > todate.getTime()) {
		updatedate = true;
	}
	if (updatedate == true) {
		var thedayval = document.all.theday.value - 1;
		var themonthval = document.all.themonth.value - 1;
		var theyearval = document.all.theyear.selectedIndex;
		document.all.theday2.options[thedayval].selected = true
		document.all.themonth2.options[themonthval].selected = true
		document.all.theyear2.options[theyearval].selected = true
	}
}

//
// Changes the number of days listed in the given 'day' list according to the month chosen in the given 'month' list:
// Takes into account leap years where february is one day longer in length.
//
function ChangeDateSelect(theday, themonth, theyear, title) {
	if (title == true) {
		if (document.all[themonth].value == "2" || document.all[themonth].value == "4" || document.all[themonth].value == "6"
			|| document.all[themonth].value == "9" || document.all[themonth].value == "11") {
			if (document.all[themonth].value == "2") {
				if (IsLeapYear(document.all[theyear].value )) {
					document.all[theday].length = "30";
					document.all[theday].options[29].value = "29";
					document.all[theday].options[29].text = "29th";
				}
				else {
					document.all[theday].length = "29";
				}
			}
			else {
				document.all[theday].length = "31";
				document.all[theday].options[29].value = "29";
				document.all[theday].options[29].text = "29th";
				document.all[theday].options[30].value = "30";
				document.all[theday].options[30].text = "30th";
			}												
		}
		else {
			document.all[theday].length = "32";
			document.all[theday].options[29].value = "29";
			document.all[theday].options[29].text = "29th";
			document.all[theday].options[30].value = "30";
			document.all[theday].options[30].text = "30th";
			document.all[theday].options[31].value = "31";
			document.all[theday].options[31].text = "31st";
		}
	}
	else {
		if (document.all[themonth].value == "2" || document.all[themonth].value == "4" || document.all[themonth].value == "6"
			|| document.all[themonth].value == "9" || document.all[themonth].value == "11") {
			if (document.all[themonth].value == "2") {
				if (IsLeapYear(document.all[theyear].value )) {
					document.all[theday].length = "29";
					document.all[theday].options[28].value = "29";
					document.all[theday].options[28].text = "29th";
				}
				else {
					document.all[theday].length = "28";
				}
			}
			else {
				document.all[theday].length = "30";
				document.all[theday].options[28].value = "29";
				document.all[theday].options[28].text = "29th";
				document.all[theday].options[29].value = "30";
				document.all[theday].options[29].text = "30th";
			}												
		}
		else {
			document.all[theday].length = "31";
			document.all[theday].options[28].value = "29";
			document.all[theday].options[28].text = "29th";
			document.all[theday].options[29].value = "30";
			document.all[theday].options[29].text = "30th";
			document.all[theday].options[30].value = "31";
			document.all[theday].options[30].text = "31st";
		}
	}
}
