function TrBGOver(inCtrl)
	{
		inCtrl.style.background = '#99CCFF';
	}

function TrBGOut(inCtrl)
	{
//		inCtrl.style.background = '#ffffff' ;
		inCtrl.style.background = 'none' ;
	}

function NoEnterAllowed (inCtrl)
	{
		// N.B. This function only works withe onkeypress event.
//		alert ("Keycode is [" + keyCode + "]");

		if (13 == window.event.keyCode)
			{
//				alert ("Enter Pressed");
				window.event.keyCode = 0;
			}
	}

function Trim (inStr)
	{
		// This function takes a string and removes all the *spaces* from either side.
		var outStr = "";
		var x, ch;
		
		// Trim left side spaces
		for (x = 0; x < inStr.length; x++)
			{
				ch = inStr.substring(x, x+1);
				if (" " != ch)
					{
						outStr = inStr.substring(x, inStr.length);
						break;
					}
			}
			
		// Trim right side spaces
		
		for (x = outStr.length - 1; x >= 0; x--)
			{
				ch = outStr.substring(x, x + 1);
				if (" " != ch)
					{
						//alert ("x + 1 is [" + (x + 1) + "]");
						outStr = outStr.substring (0, x + 1);
						break;
					}
			}
		//alert ("inStr was [" + inStr + "], outStr is [" + outStr + "]");
		return outStr;
	}

function NoOp ()
	{
		return true;
	}

function FocusOnFieldAndDie (fieldCtrl, msg)
	{
		alert (msg);
		try
			{
				fieldCtrl.focus();
				fieldCtrl.select();
			}
		catch (err)
			{
			}
		return false;
	}

function FieldNotEmpty (fieldCtrl, msg)
	{
		if ("" == Trim (fieldCtrl.value))
			return FocusOnFieldAndDie (fieldCtrl, msg);
		return true;
	}

function AtLeastOneFieldNotBlank (fieldCtrl1, fieldCtrl2, msg)
	{
		if ("" != Trim (fieldCtrl1.value))
			return true;
		if ("" != Trim (fieldCtrl2.value))
			return true;
		return FocusOnFieldAndDie (fieldCtrl1, msg);	
	}

function IsCharNumeric (inChar)
	{
		var ch = inChar;
		if (("0" == ch) || ("1" == ch) || ("2" == ch) || ("3" == ch) || ("4" == ch) || ("5" == ch) || ("6" == ch) || ("7" == ch) || ("8" == ch) || ("9" == ch))
			return true;
		return false;
	}

function IsNumeric (fieldCtrl, msg, allowBlanks)
	{
		var possibleNumber = Trim(fieldCtrl.value);

		if (allowBlanks && ("" == possibleNumber))
			return true;

		var dotCount = 0;
		var x = 0;
		var ch = "";

		while (x < possibleNumber.length)
			{
				ch = possibleNumber.substring (x, x+1);
				if ("." == ch)
					{
						if (dotCount < 1)
							dotCount++;
						else
							return FocusOnFieldAndDie (fieldCtrl, msg);
					}
				else
					{
						if ((0 == x) && ("-" == ch))
							{
								// This is OK.  Do nothing.
							}
						else if (!IsCharNumeric (ch))
							return FocusOnFieldAndDie (fieldCtrl, msg);
					}
				x++;
			}
		return true;
	}

function IsNonNegativeNumber (fieldCtrl, msg, integerOnly)
	{
		var possibleNumber = Trim(fieldCtrl.value);

		if ("" == possibleNumber)
			return true;

		var dotCount = 0;
		var x = 0;
		var ch = "";

		while (x < possibleNumber.length)
			{
				ch = possibleNumber.substring (x, x+1);
				if ("." == ch)
					{
						if (integerOnly)
							return FocusOnFieldAndDie (fieldCtrl, msg);
						else
							{
								if (dotCount < 1)
									dotCount++;
								else
									return FocusOnFieldAndDie (fieldCtrl, msg);
							}
					}
				else
					{
						if (!IsCharNumeric (ch))
							return FocusOnFieldAndDie (fieldCtrl, msg);
					}
				x++;
			}
		return true;
	}

function IsValidPhoneNumber (areaCodeCtrl, prefixCtrl, lastFourCtrl, msg)
	{
		// Don't bother if all fields are blank.
		if (("" == areaCodeCtrl.value) && ("" == prefixCtrl.value) && ("" == lastFourCtrl.value))
			return true;

		// At this point, we know at least one field is filled in.  All 3 must be filled in, now
		// check if at least one field is blank, if this is the case, then return an error.
		// Check each control separately to ensure we focus on the appropriate field if there is
		// a problem.
		if (("" == areaCodeCtrl.value) || (3 != Trim (areaCodeCtrl.value).length))
			return FocusOnFieldAndDie (areaCodeCtrl, msg);
		if (("" == prefixCtrl.value) || (3 != Trim (prefixCtrl.value).length))
			return FocusOnFieldAndDie (prefixCtrl, msg);
		if (("" == lastFourCtrl.value) || (4 != Trim (lastFourCtrl.value).length))
			return FocusOnFieldAndDie (lastFourCtrl, msg);

		// At this point, we know all 3 fields are not blank.  Check if the characters in each
		// are numeric.
		var x = 0;
		var ch = "";
		while (x < areaCodeCtrl.value.length)
			{
				ch = areaCodeCtrl.value.substring (x, x+1);
				if (!IsCharNumeric (ch))
					return FocusOnFieldAndDie (areaCodeCtrl, msg);
				x++;
			}

		x = 0;
		ch = "";
		while (x < prefixCtrl.value.length)
			{
				ch = prefixCtrl.value.substring (x, x+1);
				if (!IsCharNumeric (ch))
					return FocusOnFieldAndDie (prefixCtrl, msg);
				x++;
			}

		x = 0;
		ch = "";
		while (x < lastFourCtrl.value.length)
			{
				ch = lastFourCtrl.value.substring (x, x+1);
				if (!IsCharNumeric (ch))
					return FocusOnFieldAndDie (lastFourCtrl, msg);
				x++;
			}
		return true;
	}

function IsValidPassword (fieldCtrl, msg)
	{
		if ("" == fieldCtrl.value.replace(" ", ""))
			return true; 
		if (fieldCtrl.value.length < 8)
			return FocusOnFieldAndDie (fieldCtrl, msg);
		var x = 0;
		var ch = "";
		var foundNum = false;
		while ( !foundNum && (x < fieldCtrl.value.length) )
			{
				ch = fieldCtrl.value.substring (x, x+1);
				if (IsCharNumeric (ch))
					foundNum = true;
				x++;
			}
		if (!foundNum)
			return FocusOnFieldAndDie (fieldCtrl, msg);
		return true;
	}

function ContainsDisallowedText (forbiddenText, fieldCtrl, msg)
	{
		if (-1 == fieldCtrl.value.indexOf (forbiddenText))
			return true;
		return FocusOnFieldAndDie (fieldCtrl, msg);
	}

function StringFieldsEqual (fieldCtrl1, fieldCtrl2, msg)
	{
		if ((fieldCtrl1.value) == (fieldCtrl2.value))
			return true;
		return FocusOnFieldAndDie (fieldCtrl1, msg);
	}

function DisableAllButtons (thisFormObject)
	{
		var agt=navigator.userAgent.toLowerCase();
		if ((-1 != agt.indexOf("firefox")) || (-1 != agt.indexOf("safari")))
			{
				// Do nothing... firefox and safari hate when you disable the same button that
				// calls this function.  Until we come up with a better workaround, just do nothing
				// here.  Maybe window.event might help?
			}
		else
			{
				var temp = "";
				for (var x = 0; x < thisFormObject.length; x++)
					{
						// In Firefox, anything defined as a <button> is always of type "submit".
						// In IE, anything defined as a <button> is always of type "button".
						if (("button" == thisFormObject.elements[x].type) || ("submit" == thisFormObject.elements[x].type))
								thisFormObject.elements[x].disabled = true;
					}
			}
	}

function StringIsExactlyXCharsLong (fieldCtrl, requiredLength, msg)
	{
		if (requiredLength == fieldCtrl.value.length)
			return true;
		return FocusOnFieldAndDie (fieldCtrl, msg);
	}

function ProcessLogoff ()
	{
		document.forms[0].thingToDo.value = "Logoff";
		document.forms[0].submit();
		return true;
	}

function GoToMenu()
	{
		document.forms[0].action = "sh_menu.php";
		document.forms[0].submit();
	}

function AtLeastOneRadioButtonPicked (radioCtrl, msg)
	{
		var x = 0;
		while (x < radioCtrl.length)
			{
				if (radioCtrl[x].checked)
					return true;
				x++;
			}
		return FocusOnFieldAndDie (radioCtrl, msg);
	}

function LimitText (textAreaCtrl, maxCharsAllowed)
	{
		if (textAreaCtrl.value.length > maxCharsAllowed)
			textAreaCtrl.value = textAreaCtrl.value.substring (0, maxCharsAllowed);
	}

function IfRadioButtonClickedFieldCantBeEmpty (radioCtrl, selectedValue, fieldCtrl, msg)
	{
		var found = false;
		var x = 0;
		while (!found && (x < radioCtrl.length))
			{
				if ((radioCtrl[x].checked) && (selectedValue == radioCtrl[x].value))
					found = true;
				x++;
			}
		if (found)
			{
				if ("" == Trim(fieldCtrl.value))
					return FocusOnFieldAndDie (fieldCtrl, msg);
			}
		return true;
	}

function IfRadioButtonClickedFieldMustBeEmpty (radioButtonCtrl, fieldCtrl, msg)
	{
		if (radioButtonCtrl.checked)
			{
				if ("" != Trim(fieldCtrl.value))
					return FocusOnFieldAndDie (fieldCtrl, msg);
			}
		return true;
	}

function SelectOptionNotBlank (selectCtrl, msg)
	{
		if ("" == Trim (selectCtrl[selectCtrl.selectedIndex].value))
			return FocusOnFieldAndDie (selectCtrl, msg);
		return true;
	}

function ReturnSelectedRadioOption (inCtrl)
	{
		// selectedIndex property does not exist for radio buttons... quit forgetting that!
		var found = false;
		var valueToShow = "";
		var x = 0;
		while ((!found) && (x < inCtrl.length))
			{
				if (inCtrl[x].checked)
					{
						valueToShow = inCtrl[x].value;
						found = true;
					}
				x++;
			}
		return valueToShow;
	}

function IfCertainValueSelectedFieldCantBeBlank (selectCtrl, selectedValueRequiringFieldValue, fieldCtrl, msg)
	{
		var currentSelectValue = Trim (selectCtrl[selectCtrl.selectedIndex].value);

		if (currentSelectValue == selectedValueRequiringFieldValue)
			{
				if ("" == Trim (fieldCtrl.value))
					return FocusOnFieldAndDie (fieldCtrl, msg);
			}
		return true;
	}

function IfCertainValueNOTSelectedFieldMustBeBlank (selectCtrl, selectedValueRequiringFieldValue, fieldCtrl, msg)
	{
		var currentSelectValue = Trim (selectCtrl[selectCtrl.selectedIndex].value);

		if (currentSelectValue != selectedValueRequiringFieldValue)
			{
				if ("" != Trim (fieldCtrl.value))
					return FocusOnFieldAndDie (fieldCtrl, msg);
			}
		return true;
	}

function SilentIsValidEmail (possibleEmailAddress)
	{
		var str = possibleEmailAddress;
		
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);

		if (str.indexOf(at)==-1)
			return false;

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
			return false;

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
			return false;

		if (str.indexOf(at,(lat+1))!=-1)
			return false;

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
			return false;

		if (str.indexOf(dot,(lat+2))==-1)
			return false;

		if ((str.indexOf(" ")!=-1) || (str.indexOf(";")!=-1))
			return false;

		return true;
	}

function IsValidEmail (fieldCtrl, msg)
	{
		var str = fieldCtrl.value;

		if ("" == Trim(str))
			return true;

		if (!SilentIsValidEmail (str))
			return FocusOnFieldAndDie (fieldCtrl, msg);

		return true;
	}

function CheckboxIsChecked (checkboxCtrl, msg)
	{
		if (checkboxCtrl.checked)
			return true;
		return FocusOnFieldAndDie (checkboxCtrl, msg);
	}

function IsValidStudentID (fieldCtrl, msg)
	{
		if (fieldCtrl.value.length != 9)
			return FocusOnFieldAndDie (fieldCtrl, msg);

		var x = 0;
		if (9 == fieldCtrl.value.length)
			{
				fieldCtrl.value = fieldCtrl.value.toUpperCase();
				while (x < fieldCtrl.value.length)
					{
						var ch = fieldCtrl.value.substring (x, x+1);
						if ((0 == x) && ("M" != ch))
							return FocusOnFieldAndDie (fieldCtrl, msg);
						if ((1 == x) && ("2" != ch))
							return FocusOnFieldAndDie (fieldCtrl, msg);
						else if ((1 != x) && (0 != x))
							{
								if (!IsCharNumeric (ch))
									return FocusOnFieldAndDie (fieldCtrl, msg);
							}
						x++;
					} // while (x < fieldCtrl.value.length)
			} // if (9 == fieldCtrl.value.length)
		return true;
	}

function FocusOnFieldAndDieReplaceOldValue (desiredDefaultValue, fieldCtrl, msg)
	{
		alert (msg);
		try
			{
				fieldCtrl.value = desiredDefaultValue;
				fieldCtrl.focus();
				fieldCtrl.select();
			}
		catch (err)
			{
			}
		return false;
	}

function DateComparer (returnTrueOnBlankDates, dateField1, dateField2, operator, msg)
	{
		if (returnTrueOnBlankDates)
			{
				if ("" == Trim (dateField1.value))
					return true;
				if ("" == Trim (dateField2.value))
					return true;
			}

		if (!SilentIsValidDateWithDashes (dateField1))
			return FocusOnFieldAndDie (dateField1, msg);
		if (!SilentIsValidDateWithDashes (dateField2))
			return FocusOnFieldAndDie (dateField2, msg);

		var date1 = new Date();
		var date2 = new Date();
			
		var dateParts = dateField1.value.split("-");
		var mm = dateParts[0] - 0;
		var dd = dateParts[1] - 0;
		var yy = dateParts[2] - 0;
		date1.setFullYear (yy, mm-1, dd);

		dateParts = dateField2.value.split("-");
		mm = dateParts[0] - 0;
		dd = dateParts[1] - 0;
		yy = dateParts[2] - 0;
		date2.setFullYear (yy, mm-1, dd);
		
		switch (operator)
			{
				case "==" :
					if (date1 == date2)
						return true;
					break;
				case ">" :
					if (date1 > date2)
						return true;
					break;
				case "<" :
					if (date1 < date2)
						return true;
					break;
				case ">=" :
					if (date1 >= date2)
						return true;
					break;
				case "<=" :
					if (date1 <= date2)
						return true;
					break;
				case "!=" :
					if (date1 != date2)
						return true;
					break;
			} //switch (operator)
		return FocusOnFieldAndDie (dateField1, msg);
	}

function SilentIsValidDateWithDashes (dateFieldCtrl)
	{
		// Simply returns true or false if the specified date is a valid MM-DD-YYYY date. 
		// This allows for date validation to be embedded into other functions.
		var dateParts = dateFieldCtrl.value.split("-");
		if (3 != dateParts.length)
			return false;

		var foundNonNum = false;
		var x = 0;
		var ch = "";
		while ((!foundNonNum) && (x < dateParts[0].length))
			{
				ch = dateParts[0].substring (x, x+1);
				if (!IsCharNumeric (ch))
					return false;
				x++;
			}

		x = 0;
		foundNonNum = false;
		while ((!foundNonNum) && (x < dateParts[1].length))
			{
				ch = dateParts[1].substring (x, x+1);
				if (!IsCharNumeric (ch))
					return false;
				x++;
			}

		x = 0;
		foundNonNum = false;
		while ((!foundNonNum) && (x < dateParts[2].length))
			{
				ch = dateParts[2].substring (x, x+1);
				if (!IsCharNumeric (ch))
					return false;
				x++;
			}

		var mm = dateParts[0] - 0;
		var dd = dateParts[1] - 0;
		var yy = dateParts[2] - 0;

		if ((mm < 1) || (mm > 12))
			return false;

		var daysInMonths = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

		if (((0 == (yy % 4)) && (0 != (yy % 100))) || (0 == (yy % 400)))
			daysInMonths[1] = 29;

		if ((dd < 1) || (dd > daysInMonths[mm-1]))
			return false;
		return true;
	}

function IsValidDateWithDashesAndFixValue (allowBlankField, desiredDefaultDate, inDateCtrl, msg)
	{
		if ( (allowBlankField) && ("" == Trim (inDateCtrl.value)) )
			return true;

		if (!SilentIsValidDateWithDashes (inDateCtrl))
			return FocusOnFieldAndDieReplaceOldValue (desiredDefaultDate, inDateCtrl, msg);

		return true;
	}

function IsValidDuration (fieldCtrl, msg)
	{
		// Returns true if fieldCtrl's value is in the format HH:MM:SS or blank.

		if ("" == Trim (fieldCtrl.value))
			return true;

		// Note that a time duration can have an unlimited number of hours.  What we 
		// need to do is check the 6 rightmost characters are in the format :MM:SS and 
		// everything to the left of the leftmost : is numeric.
		
		var strlen = fieldCtrl.value.length;
		
		var rightMostColon = fieldCtrl.value.substring (strlen - 3, strlen - 2);
		var leftMostColon = fieldCtrl.value.substring (strlen - 6, strlen - 5);
//		alert ("Character at postion 2 from end (3 chars in) is [" + rightMostColon+ "].\nCharacter at postion 5 from end (6 chars in) is [" + leftMostColon + "].");
		if ((":" != rightMostColon) && (":" != leftMostColon))
			return FocusOnFieldAndDie (fieldCtrl, msg);

		// Verify that the minutes are numeric and range between 0 and 59.
		mLeft = fieldCtrl.value.substring (strlen - 5, strlen - 4);
		mRight = fieldCtrl.value.substring (strlen - 4, strlen - 3);
		
//		alert ("Left minute digit is [" + mLeft + "], Right minute digit is [" + mRight + "]");
		if ( (!IsCharNumeric (mLeft)) && (!IsCharNumeric (mRight)) )
			return FocusOnFieldAndDie (fieldCtrl, msg);

		var mm = fieldCtrl.value.substring (strlen - 5, strlen - 3) - 0;  // Force cast to integer
		if ((mm < 0) || (mm > 59))
			return FocusOnFieldAndDie (fieldCtrl, msg);

		// Verify that the  seconds are numeric and range between 0 and 59.
		sLeft = fieldCtrl.value.substring (strlen - 2, strlen - 1);
		sRight = fieldCtrl.value.substring (strlen - 1, strlen - 0);
		
//		alert ("Left second digit is [" + sLeft + "], Right second digit is [" + sRight + "]");
		if ( (!IsCharNumeric (sLeft)) && (!IsCharNumeric (sRight)) )
			return FocusOnFieldAndDie (fieldCtrl, msg);

		var ss = fieldCtrl.value.substring (strlen - 2, strlen - 0) - 0;  // Force cast to integer
		if ((ss < 0) || (ss > 59))
			return FocusOnFieldAndDie (fieldCtrl, msg);

		// Now verify that the hours are an integer.
		
		var hours = fieldCtrl.value.substring (0, strlen - 6);
//		alert ("Hours is [" + hours + "]");

		var x = 0;
		while (x < hours.length)
			{
				var ch = hours.substring (x, x+1);
				if (!IsCharNumeric (ch))
					return FocusOnFieldAndDie (fieldCtrl, msg);
				x++;
			}

		return true;
	}

function AtMostXSubWords (fieldCtrl, delimeter, maxPieces, msg)
	{
		if ("" == Trim (fieldCtrl.value))
			return true;

		var textPieces = fieldCtrl.value.split (delimeter);
		
		if (textPieces.length > maxPieces)
			return FocusOnFieldAndDie (fieldCtrl, msg);
		return true;
	}

function FileIsOfType (fileCtrl, allowedExts, msg)
	{
		if ("" == Trim (fileCtrl.value))
			return true;
		var filename = Trim (fileCtrl.value.toLowerCase());
		//alert ("File name is [" + filename + "]");

		validExts = "|" + allowedExts + "|";

		var x = filename.length - 1;
		var found = false;
		var fileExt = "";
		while (!found && (x >= 0))
			{
				var ch = filename.substring (x, x+1);
				if ("." == ch)
					{
						fileExt = filename.substring (x + 1, filename.length);
						found = true;
					}
				x--;
			}
		//alert ("File extension is [" + fileExt + "]");
		if (-1 != validExts.indexOf ("|" + fileExt + "|"))
			return true;
		return FocusOnFieldAndDie (fileCtrl, msg);	
	}

function FileNameOfTypeHasNoSpecificCharacter (badChar, fileCtrl, matchingExt, msg)
	{
		if ("" == Trim (fileCtrl.value))
			return true;
		var filename = Trim (fileCtrl.value.toLowerCase());

		var x = filename.length - 1;
		var found = false;
		var fileExt = "";
		while (!found && (x >= 0))
			{
				var ch = filename.substring (x, x+1);
				if ("." == ch)
					{
						fileExt = filename.substring (x + 1, filename.length);
						found = true;
					}
				x--;
			}
		if (fileExt == matchingExt)
			{
				// Note that the filename PATH can contain spaces but the filename itself cannot.
				var actualFile = "";
				if ((-1 == filename.indexOf ("/")) && (-1 == filename.indexOf ("\\")))
					actualFile = filename;
				else
					{
						found = false;
						var x = filename.length - 1;
						while (!found && (x >= 0))
							{
								var ch = filename.substring (x, x+1);
								if (("/" == ch) || ("\\" == ch))
									{
										actualFile = filename.substring (x + 1, filename.length);
										found = true;
									}
								x--;
							}
					} // if ((-1 == filename.indexOf ("/")) && (-1 == filename.indexOf ("\\")))
				//alert ("filename is [" + filename + "] matchingExt is [" + matchingExt + "] actual file is [" + actualFile + "]");
				if (actualFile.indexOf(badChar) != -1)
					return FocusOnFieldAndDie (fileCtrl, msg);	
			}
		return true;
	}

function AtLeastOneSelectOptionSelected (selectCtrl, msg)
	{
		// This function is differentiated from the one that checks if the select value is not blank.  This function can be used if a blank value is desirable.
		var x = 0;
		while (x < selectCtrl.length)
			{
				if (selectCtrl[x].selected)
					return true;
				x++;
			}
		return FocusOnFieldAndDie (selectCtrl, msg);	
	}