function getRandomNum(lbound, ubound)
{
	return (Math.round(Math.random() * (ubound - lbound)) + lbound);
}

// AUTHOR:		Jason Noftall
// DATE:		Aug. 16, 2003
// DESCRIPTION:	Trims any leading/trailing spaces from the incoming string.
// PARAMETERS:	strIn = string that needs to be trimmed
// RETURNS:		String, input string less any leading/trailing spaces.
function trimString(strIn)
{
	var strOut = new String(strIn);						// Return value

	// If there are trailing spaces, instantiate a new
	// String object with the original string less the spaces...
	while (strOut.charAt(strOut.length - 1) == ' ')
	{
		strOut = new String(strOut.substring(0, strOut.length - 1));
	}

	// If there are leading spaces, instantiate a new
	// String object with the original string less the spaces...
	while (strOut.charAt(0) == ' ')
	{
		strOut = new String(strOut.substring(1, strOut.length));
	}

	return strOut;
}

// AUTHOR:		Jason Noftall
// DATE:		Aug. 16, 2003
// DESCRIPTION:	Validates strings to check for certain numeric attributes.
// PARAMETERS:	strIn = string that needs numeric validation
//				intFormat = numeric value indicating the type of
//				validation to perform.
// 				1 = Whole numbers, positive only
// 				2 = Whole numbers, positive and negative
// 				3 = Decimal numbers, positive only
// 				4 = Decimal numbers, positive and negative
// RETURNS:		Boolean, True if valid...False if otherwise.
function ensureNumeric(strIn, intFormat)
{
	blnReturn = false;					// Return value
	strNew = trimString(strIn);				// Trim spaces from input string
	var strChar;						// Get 1 char at a time
	var intDecCount = 0;					// Decimal count

	// intFormat
	// ---------
	// 1 = Whole numbers, positive only
	// 2 = Whole numbers, positive and negative
	// 3 = Decimal numbers, positive only
	// 4 = Decimal numbers, positive and negative

	for (var i=0; i < strNew.length; i++)
	{
		// Get 1 char at a time...
		strChar = strNew.substring(i,i+1);

		switch (intFormat)
		{
			case 1:
			{
				// whole positive numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 1:

			case 2:
			{
				// whole positive or negative numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					case "-":
						if (i == 0)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 2:

			case 3:
			{
				// decimal positive numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					case ".":
						intDecCount++;
						if (intDecCount == 1)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 3:

			case 4:
			{
				// decimal positive numbers only
				switch (strChar)
				{
					case "0":
					case "1":
					case "2":
					case "3":
					case "4":
					case "5":
					case "6":
					case "7":
					case "8":
					case "9":
						blnReturn = true;
						break;
					case "-":
						if (i == 0)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}

					case ".":
						intDecCount++;
						if (intDecCount == 1)
						{
							blnReturn = true;
							break;
						}
						else
						{
							return false;
						}
					default:
						return false;
				} // switch (strChar)

				break;
			} // case 4:

		} // switch (intFormat)
	} // (var i=0; i < strNew.length; i++)

	return blnReturn;
}

// AUTHOR:		Jason Noftall
// DATE:		Aug. 16, 2003
// DESCRIPTION:	Counts the number of occurences of one string within another.
// PARAMETERS:	1. strText = String to be searched
//				2. strChar = Character/String to be found
// RETURNS:		int, count of number of occurences found.
function countChars(strText, strChar)
{
	var ptr = strText.indexOf(strChar);			// Pointer to current character
	var i = 0;						// Iteration
	
	while (ptr != -1)
	{
		ptr = strText.indexOf(strChar, ptr + 1);
		i++;
	}
	
	return i;
}

// AUTHOR:		Jason Noftall
// DATE:		Aug. 16, 2003
// DESCRIPTION:	Validates a string for a valid e-mail address.
// PARAMETERS:	strIn = e-mail address to be validated
// RETURNS:		bool, true for valid address...false if otherwise.
function validEmail(strIn)
{
	var strEmail = trimString(strIn);			// Trim the e-mail address
	var intLen = strEmail.length;				// Get the length of e-mail
	var intAtCount = countChars(strEmail, "@");		// Count occurences of "@"
	var intAtLoc = strEmail.indexOf("@");			// Find a "@"
	var intDotLoc = strEmail.lastIndexOf(".");		// Find the last "."
	var blnReturn = true;					// Return value
	
	if (intLen == 0)
	{
		// No e-mail address specified...
		blnReturn = false;
	}
	else if (intAtLoc == 0)
	{
		// Ensure the "@" is not the first character in the string...
		blnReturn = false;
	}
	else if (intAtCount > 1)
	{
		// More than 1 "@" symbol found...
		blnReturn = false;
	}
	else if (intAtCount == 0)
	{
		// More than 1 "@" symbol found...
		blnReturn = false;
	}
	else if (intAtCount == 0)
	{
		// More than 1 "@" symbol found...
		blnReturn = false;
	}
	else if (intDotLoc == -1)
	{
		// Ensure the last "." is located after the "@"...
		blnReturn = false;
	}

	return blnReturn;
}

// AUTHOR:		Jason Noftall
// DATE:		Aug. 20, 2003
// DESCRIPTION:	Updates a hidden textfield based on a checkbox click.
// PARAMETERS:	1. chk = reference to the checkbox object
//				2. txtfield = reference to the hidden textrfield to update.
//				3. onvalue = string representing the "checked" value.
//				4. offvalue = string representing the "not checked" value.
// RETURNS:		<void>
function SetHiddenWithCheckbox(chk, txtfield, onvalue, offvalue)
{
	if (chk.checked)
	{
		// Checked value...
		txtfield.value = onvalue;
	}
	else
	{
		// Not Checked value...
		txtfield.value = offvalue;
	}
}

// AUTHOR:		Jason Noftall
// DATE:		Aug. 21, 2003
// DESCRIPTION:	Replaces a specified character with one (or more) character(s).
// PARAMETERS:	1. strOriginal = original string containing characters to replace.
//				2. strChar = character being sought.
//				3. strReplace = character(s) to replace occurences of "strChar" with.
// RETURNS:		string, original string with all occurences of "strChar" replaced with "strReplace".
function replaceChar(strOriginal, strChar, strReplace)
{
	return strOriginal.split(strChar).join(strReplace);
}

// <summary>
// Displays a url in a popup window.
// </summary>
// <param name="url">string, url to display in the window.</param>
// <param name="handleName">string, a handle name to assign to the window.</param>
// <param name="height">int, height (in pixels) of the window.</param>
// <param name="width">int, width (in pixels) of the window.</param>
// <param name="appearance">string, window's options, i.e. scrollbars, etc.  If this value isn't specified, default options are used.</param>
function PopupWindow(url, handleName, height, width, appearance)
{
	// If "appearance" hasn't been defined, use the default one below...
	if (typeof(appearance) == "undefined")
	{
		appearance = "scrollbars=yes,status=no,toolbar=no,menubar=no,resizable=yes";
	}

	// Pop up a window...
	var win = window.open(url, handleName, "width=" + width + ",height=" + height + "," + appearance);
	win.window.focus();
}

// <summary>
// Builds either an <img> or <a> element based on file extension.
// </summary>
// <param name="fileName" type="string">The filename for which to build an HTML element for.</param>
// <returns type="string">A fully-qualified <img> or <a> element based on specified file extension.</returns>
function GetHtmlElementFromFile(fileName)
{
	// Get the location of the last "." (if present)...
	var token = fileName.lastIndexOf(".");
	var htmlElement;

	// Was a "." found?
	if (token != -1)
	{
		// Parse the filename at the last "."...
		var extension = fileName.substring(token + 1).toLowerCase();
		switch (extension)
		{
			// Images...
			case "jpg":
			case "jpeg":
			case "gif":
			case "png":
			case "bmp":
			{
				htmlElement = "<img src=\"" + fileName + "\" border=\"0\" />";
				break;
			}
			// All other file types...
			default:
			{
				htmlElement = "<a href=\"" + fileName + "\">" + fileName + "</a>";
				break;
			}
		} // switch (extension)
	}
	else
	{
		// No file extension found, assume it is a file.
		htmlElement = "<a href=\"" + fileName + "\">" + fileName + "</a>";
	}

	return htmlElement;
}

// <summary>
// Parses an Internal Link string (generated in FreeTextBox)
// and just returns the last item following separator (if present).
// </summary>
// <param name="internalLinkTitle" type="string">The fully qualified internal link string (i.e parent/child/grandchild names).</param>
// <param name="separator" type="string">The separator of each item.</param>
// <returns type="string">The last page name (following the separator).</returns>
function GetLastPageName(internalLinkTitle, separator)
{
	// Get the location of the last separator (if present)...
	var token = internalLinkTitle.lastIndexOf(separator);

	// Was a separator found?
	if (token != -1)
	{
		// Parse the page name at the last separator...
		return trimString(internalLinkTitle.substring(token + 1));
	}
	else
	{
		// Separator not found, return original string...
		return trimString(internalLinkTitle);
	}
}

// <summary>
// Depending on browser type, displays either the Printer dialog or
// and alert instructing the user how to display the Printer dialog.
// </summary>
function printThisPage()
{
	var browserName = navigator.appName;
	if (window.print)
	{
		window.print();
	}
	else if (browserName.indexOf("mac") != -1)
	{
		alert("To print this page, press Command-P.");
	}
	else
	{
		alert("To print this page press Control-P.")
	}
}