function TrytoControlButtonByID (ctrlID, disabling)
	{
		try
			{
				if (disabling)
					document.getElementById(ctrlID).disabled = true;
				else
					document.getElementById(ctrlID).disabled = false;
			}
		catch (err)
			{
				// Do nothing.
			}
	}

function TrBGOver(inCtrl)
	{
		inCtrl.style.background = '#99CCFF';
	}

function TrBGOut(inCtrl)
	{
		inCtrl.style.background = '#ffffff' ;
	}

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 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)
	{
		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 (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 ProcessLogoff ()
	{
		document.forms[0].thingToDo.value = "Logoff";
		document.forms[0].submit();
		return true;
	}

function GoToMenu()
	{
		document.forms[0].action = "menu.php";
		document.forms[0].submit();
	}

function AtLeastOneFieldListedMustBeFilled (inStr, msg)
	{
		// inStr takes a bar-delimited string containing field names in a given form.
		// We break up the string by bars, then see if at least one of the fields
		// contains non-whitespace text.

		var pieceToCheck = "";
		var offendingObjectName = "";
		
		// If no bars are in the string then we check the single field.
		if (-1 == inStr.indexOf ("|"))
			{
				pieceToCheck = Trim(eval ("document.forms[0]." + inStr + ".value"));
				if ("" == pieceToCheck)
					{
						offendingObjectName = "document.forms[0]." + inStr;
						return FocusOnFieldAndDie (eval (offendingObjectName), msg)
					}
				return true;
			}

		var pieces = inStr.split ("|");
		var allBlank = true;
		var x = 0;
		
		while (allBlank && (x < pieces.length))
			{
				pieceToCheck = Trim(eval ("document.forms[0]." + pieces[x] + ".value"));
				if ("" != Trim (pieceToCheck))
					allBlank = false;
				x++;
			} // while (allBlank && (x < pieces.length))
		if (allBlank)
			{
				offendingObjectName = "document.forms[0]." + pieces[0];
				return FocusOnFieldAndDie (eval (offendingObjectName), msg)
			}
		return true;
	}

function FieldsListedByNameHaveUniqueValues (allowBlankFields, inStr, msg)
	{
		// inStr takes a bar-delimited string containing field names in a given form.
		// We break up the string by bars, then see if the value in that string is 
		// unique for all the fields listed.

		if (-1 == inStr.indexOf ("|"))
			return true;

		var pieces = inStr.split ("|");
		
		var allUnique = true;
		var x = 0;
		var pieceToCompare = "";
		var otherPiece = "";
		var offendingObjectName = "";
		while (allUnique && (x < pieces.length))
			{
				pieceToCompare = Trim(eval ("document.forms[0]." + pieces[x] + ".value"));
				var y = 0;
				while (allUnique && (y < pieces.length))
					{
						if (x != y)
							{
								otherPiece = Trim(eval ("document.forms[0]." + pieces[y] + ".value"));
								if (otherPiece == pieceToCompare)
									{
										if ((allowBlankFields) && ("" == otherPiece) && ("" == pieceToCompare))
											{
												// Do nothing ...
											}
										else // if ((allowBlankFields) && ("" == otherPiece) && ("" == pieceToCompare))
											{
												allUnique = false;
												offendingObjectName = "document.forms[0]." + pieces[y];
											} // if ((allowBlankFields) && ("" == otherPiece) && ("" == pieceToCompare))
									} // if (otherPiece == pieceToCompare)
							} // if (x != y)
						y++;
					} // while (allUnique && (y < pieces.length))
				x++;
			} // while (allUnique && (x < pieces.length))
		if (allUnique)
			return true;
		return FocusOnFieldAndDie (eval (offendingObjectName), msg)
	}

function IfCheckboxCheckedThenSelectValueCantBeThis (checkboxCtrl, selectCtrl, illegalValue, msg)
	{
		if ( (checkboxCtrl.checked) && (illegalValue == selectCtrl[selectCtrl.selectedIndex].value) )
			return FocusOnFieldAndDie (selectCtrl, msg);
		return true;
	}