// Create Days Array
var theDays = new Array()
	theDays[0]="Sunday";
	theDays[1]="Monday";
	theDays[2]="Tuesday";
	theDays[3]="Wednesday";
	theDays[4]="Thursday";
	theDays[5]="Friday";
	theDays[6]="Saturday";

// Check Date
function checkDate(theField) {
var theDate = theField.value;
var theSplit = theDate.split("/");
if (theSplit.length - 1 == 2) {
	var theMonth = theSplit[0];
	var theDay = theSplit[1];
	var theYear = theSplit[2];
	if (!(theDate.length < 6 || (isNaN(theMonth) || theMonth < 1 || theMonth > 12) || (isNaN(theDay) || theDay < 1 || theDay > 31) || isNaN(theYear) || theYear.length < 2)) {
		return true;
		}
	}
	alert("You must enter a valid Date.\n(mm/dd/yyyy)");
	theField.focus();
	return false;
}

// Check Time
function checkTime(theField) {
var theTime = theField.value;
var theSplit = theTime.split(":");
if (theSplit.length - 1 == 1) {
	var theHours = theSplit[0];
	var theMinutes = theSplit[1];
	if (!(theTime.length < 4 || (isNaN(theHours) || theHours < 0 || theHours > 24) || (isNaN(theMinutes) || theMinutes < 0 || theMinutes > 59) || theMinutes.length < 2)) {
		return true;
		}
	}
	alert("You must enter a valid Time in 24-hour format.\n(hh:mm)");
	theField.focus();
	return false;
}

// Round Time
function roundTime(theField) {
var theTime = theField.value;
var theSplit = theTime.split(":");
if (theSplit.length -1 == 1) {
	var theHours = theSplit[0];
	var theMinutes = theSplit[1];
	if (theMinutes <= 7) {
		theMinutes = "00";
		}
	else if (theMinutes > 7 && theMinutes <= 22) {
		theMinutes = "15";
		}
	else if (theMinutes > 22 && theMinutes <= 37) {
		theMinutes = "30";
		}
	else if (theMinutes > 37 && theMinutes <= 52) {
		theMinutes = "45";
		}
	else if (theMinutes > 52 && theMinutes <= 59) {
		theHours = parseFloat(theHours) + 1;
		theMinutes = "00";
		}
		return theHours + ":" + theMinutes;
	}
}

// Round Decimal
function roundDecimal(theField) {
var theValue = "" + Math.round(theField.value * 100) / 100;
var theSplit = theValue.split(".");
if (theSplit.length -1 == 1) {
	var theNumber = theSplit[0];
	var theDecimal = theSplit[1];
	if (theDecimal.length < 2) {
		theDecimal = theDecimal + "0";
		}
	if (theDecimal <= 12) {
		theDecimal = 0;
		}
	else if (theDecimal > 12 && theDecimal <= 37) {
		theDecimal = 25;
		}
	else if (theDecimal > 37 && theDecimal <= 62) {
		theDecimal = 50;
		}
	else if (theDecimal > 62 && theDecimal <= 87) {
		theDecimal = 75;
		}
	else if (theDecimal > 87 && theDecimal <= 99) {
		theNumber = eval(parseInt(theNumber) + 1);
		theDecimal = 0;
		}
		theValue = parseInt(theNumber) + "." + parseInt(theDecimal);
	}
	return parseFloat(theValue);
}

// Calculate Time
function calculateTime(theStartTime, theStopTime) {
var theStartDate = new Date("01/01/2009 " + theStartTime);
var theStopDate = new Date("01/01/2009 " + theStopTime);
var theDifference = new Date();
	theDifference.setTime(theStopDate - theStartDate);
	alert(theStartDate);
	alert(theStopDate);
	alert(theDifference.getHours() + ":" + theDifference.getMinutes())
}

// Left Trim
function leftTrim(theString) {
	return theString.replace(/^\s*/, "");
}

// Right Trim
function rightTrim(theString) {
	return theString.replace(/\s*$/, "");
}