//<![CDATA[
/***************************************************************************/
/* Copyright © 2005 Alex Garcia                                            */
/* University of Michigan                                                  */
/* Web Development, Technology Services                                    */
/*                                                                         */
/* Most of these JavaScripts are useful for validating form input.         */
/* For more information please email agarc@umich.edu                       */
/*                                                                         */
/* Function List with arguments*:                                          */
/*    flip(imageName, onOrOff, jpeg)                                       */
/*    ro(imageName, onOrOff, remotePath, fileNameSuffix)                   */
/*    flipdelay(imageName, onOrOff, delay)                                 */
/*    killFocus(elementName)                                               */
/*    closeWindow()                                                        */
/*    stat(someMessage)                                                    */
/*    setElement(elementName, someValue, formName)                         */
/*    getElement(elementName, formName)                                    */
/*    toggleCheck(elementName, formName)                                   */
/*    remoteCheck(checkerID, valueHolderID)                                */
/*    selfCheck(checkboxObj, valueHolderiD)                                */
/*    isChecked(elementName, formName)                                     */
/*    setDisabled(elementName, formName)                                   */
/*    setEnabled(elementName, formName)                                    */
/*    setFocus(elementName, formName)                                      */
/*    setBlur(elementName, formName)                                       */
/*    setSelect(elementName, formName)                                     */
/*    disableAll(formName)                                                 */
/*    enableAll(formName)                                                  */
/*    setChecked(elementName, formName)                                    */
/*    setUnchecked(elementName, formName)                                  */
/*    zapWhitespace(stringValue)                                           */
/*    zapExtraWhitespace(stringValue)                                      */
/*    requireData(elementName, formName)                                   */
/*    checkLength(elementName, lengthLimit, outputElement, formName)       */
/*    checkMinLength(elementName, minLengthRequirement, formName)          */
/*    isData(elementName, formName)                                        */
/*    isNumber(elementName, formName)     [planned]                        */
/*    isAlpha(elementName, formName)      [planned]                        */
/*    formatCase(elementName, formName)                                    */
/*    checkValidTime(elementName, formName)                                */
/*    fixTime(elementName, standardOrMilitary, formName)                   */
/*    checkValidDate(elementName, formName)                                */
/*    checkDate(elementName, isRequired, noisy, formName)                  */
/*    checkData(elementName, noisy, formName)                              */
/*    checkForQuotes(elementName, formName)                                */
/*    removeQuotes(elementName, formName)                                  */
/*    replaceQuotes(elementName, formName)                                 */
/*    checkPhone(elementName, formName)                                    */
/*    checkURL(elementName, formName)                                      */
/*    checkEmail(elementName, formName)                                    */
/*    setVisibility(elementID, visibilityValue)                            */
/*    showHide(elementName, displayProperty)                               */
/*    resizeWindow(canvasWidth, canvasHeight)                              */
/*    preventLinkBoxes()                                                   */
/*    smartLinks()                                                         */
/*    disableTooltips()                                                    */
/*    setFonts(fontFamilyName, fontSize, container, fontWeight)            */
/*    cacheImages()                                                        */
/*    restrictInput(e, validCharacters)                                    */
/*    preventInput(e, validCharacters)                                     */
/*    preventQuotes(e, andSingle)                                          */
/*    highlightSearchTerms(searchTerm)                                     */
/*                                                                         */
/*    convertToCurrency(stringValue)                                       */
/*    formatCurrency(elementName, formName)                                */
/*    updateTotalPrice(elementArrayName, outputElement, formName)          */
/*                                                                         */
/*    setCookie(cookieName, someValue, numberOfDays)                       */
/*    getCookie(cookieName)                                                */
/*    getCookieVal(offset)                                                 */
/*    deleteCookie(cookieName)                                             */
/*    isCookie(cookieName)                                                 */
/*                                                                         */
/*  *In most of these functions, the formName argument is optional (except */
/*   where the formName is the only argument).                             */
/*                                                                         */
/*                                                                         */
/* This file was last updated on 5/13/2005                                 */
/*                                                                         */
/***************************************************************************/


// MODIFY THE Date OBJECT
// add these custom functions:
//		Date.standardFormatString()	: mm/dd/yyyy
//		Date.addDay(n)						: add [n] days to Date
//		Date.addMonth(n)					: add [n] months to Date
//		Date.addYear(n)					: add [n] years to Date
//												([n] can be a positive or negative integer)

// create a formated date method for all Date objects
function my_standardFormatString()
{
	var theMonth = eval(this.getMonth() + 1) + "";
	var theDate = this.getDate();
	var theYear = this.getFullYear();
	
	var str = theMonth + '/' + theDate + '/' + theYear;
	return str;
}

function my_dashFormatString()
{
	var theMonth = eval(this.getMonth() + 1) + "";
	var theDate = this.getDate();
	var theYear = this.getFullYear();
	
	var str = theMonth + '-' + theDate + '-' + theYear;
	return str;
}

function my_addDay(n)
{
	var theDate = eval(this.getDate() + n);
	
	var theNewDate = new Date(this.getFullYear(), this.getMonth(), theDate);
	return theNewDate;
}

function my_addMonth(n)
{
	var theMonth = eval(this.getMonth() + n);
	
	var theNewDate = new Date(this.getFullYear(), theMonth, this.getDate());
	return theNewDate;
}

function my_addYear(n)
{
	var theYear = eval(this.getFullYear() + n);
	
	var theNewDate = new Date(theYear, this.getMonth(), this.getDate());
	return theNewDate;
}

function my_isWeekend()
{
	var theDay = this.getDay();
	
	if ((theDay == 0) || (theDay == 6))
		return true;
	else
		return false;
}

function my_isWeekday()
{
	var theDay = this.getDay();
	
	if ((theDay == 0) || (theDay == 6))
		return false;
	else
		return true;
}

function my_isSaturday()
{
	var theDay = this.getDay();
	
	if (theDay == 6)
		return true;
	else
		return false;
}

function my_isSunday()
{
	var theDay = this.getDay();
	
	if (theDay == 0)
		return true;
	else
		return false;
}


// apply the new methods to all Date objects!
Date.prototype.toStandardFormatString = my_standardFormatString;
Date.prototype.toDashFormatString = my_dashFormatString;
Date.prototype.addDay = my_addDay;
Date.prototype.addMonth = my_addMonth;
Date.prototype.addYear = my_addYear;
Date.prototype.isWeekend = my_isWeekend;
Date.prototype.isWeekday = my_isWeekday;
Date.prototype.isSaturday = my_isSaturday;
Date.prototype.isSunday = my_isSunday;


// This function swaps an image once (on or off).
// image file name must be in this format: "imageName.gif" and "imageName2.gif"
//
// OPTIONAL: by adding a third argument (the value is arbitrary), this function
// has a third action - useful for buttons with the onMouseDown() event. The
// third image follows the same format as before: "imageName3.gif"
//
// *** DEPRECATED 7/29/2004 ***
function flip(imageName, onOrOff, jpeg)
{
	if (!jpeg)
		ro(imageName, onOrOff, "images/");
	else
		ro(imageName, onOrOff, "images/", "jpg");
}

function ro(imageName, onOrOff, remotePath, fileNameSuffix)
{
	if (!fileNameSuffix) var fileNameSuffix = "gif"
	if (!remotePath) var remotePath = "images/"
	if (!onOrOff) var onOrOff = "off"
	
	if (document.images[imageName])
	{
		if (onOrOff == "on")
		{
			var tmp = new Image()
			tmp.src = remotePath + imageName + "2." + fileNameSuffix
			document.images[imageName].src = tmp.src
		}
		else if (onOrOff == "off")
		{
			var tmp = new Image()
			tmp.src = remotePath + imageName + "." + fileNameSuffix
			document.images[imageName].src = tmp.src
		}
		else
		{
			var tmp = new Image()
			tmp.src = remotePath + imageName + "3." + fileNameSuffix
			document.images[imageName].src = tmp.src
		}
	}
}

function flipdelay(imageName, onOrOff, delay)
{
	if (!delay)
		var delay = 0;
//	alert("setTimeout(flip, " + delay + ", " + imageName + ", " + onOrOff + ");");
	setTimeout(flip, delay, imageName, onOrOff);
}

// This function removes those annoying focus boxes around links and buttons.
// You can also use setBlur(elementName, formName) to do the same thing.
function killFocus(elementName)
{
	if (document.getElementById) // only standard browsers recognize this method
		elementName.blur();
}

// This function attempts to close a window. It does not matter whether the function
// is being called from a popup window, a frame, or a frame inside a popup window.
function closeWindow()
{
	if (document.getElementById)
	{
		if (navigator.appName == "Microsoft Internet Explorer")
			top.window.close();
		else
		{
			if (top.window)
				top.window.close();
			else
				window.close();
		}
	}
	else
	{
		if (top.window)
			top.window.close();
		else if (parent.window)
			parent.window.close();
		else
			window.close();
	}
}

// This function sets a value of an element.
//
// REQUIRED: elementName, someValue
function setElement(elementName, someValue, formName)
{
	if (elementName && someValue)	// ARG1 and ARG2 are required
	{
		if (!formName)					// ARG3 is optional
			formName = 0;

		if (document.forms[formName][elementName])	// make sure object exists
		{
			if (someValue)		// if ARG2, set a value; otherwise clear the data
				document.forms[formName][elementName].value = someValue;
			else
				document.forms[formName][elementName].value = "";
		}
	}
}

// This function returns the value of an element.
// ARG1 required; use ARG2 if more than one form on the page.
function getElement(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName][elementName])
		return document.forms[formName][elementName].value;
}

// This function toggles the checked status of a checkbox element.
// ARG1 required; ARG2 only if more than one form on the page.
// UPDATED 16/12/2003 - better coding; now only works on non-disabled elements
function toggleCheck(elementName, formName)
{
	if (!formName)
		var formName = 0;
	
	if (document.forms[formName][elementName].disabled == false)
		document.forms[formName][elementName].checked = !(document.forms[formName][elementName].checked);
}

// ADDED 13/5/2005
function remoteCheck(checkerID, valueHolderID)
{
	if (document.getElementById && document.getElementById(checkerID))
	{
		var theChecker = document.getElementById(checkerID)
		
		if (theChecker.disabled == false) theChecker.checked = !(theChecker.checked)
		
		if (valueHolderID && document.getElementById(valueHolderID))
		{
			theHolder = document.getElementById(valueHolderID)
			
			theHolder.value = theChecker.checked ? '1' : '0'
		}
	}
}
// ADDED 13/5/2005
function selfCheck(thecheckboxObject, valueHolderID)
{
	/*
	if (thecheckboxObject && document.getElementById && valueHolderID)
	{
		*/
		if (thecheckboxObject.checked) document.getElementById(valueHolderID).value = '1'
		else document.getElementById(valueHolderID).value = '0'
	/*}*/
}


// This function returns a Boolean value depending on if an element is checked or not.
// ARG1 required; ARG2 only if more than one form on the page.
function isChecked(elementName, formName)
{
	if (!formName)
		var formName = 0;
	
	if (document.forms[formName][elementName])
	{
		if (document.forms[formName][elementName].checked)
			return true;
		else
			return false;
	}
	else
		return false;
}

// This function disables an element.
function setDisabled(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName][elementName])
		document.forms[formName][elementName].disabled = true;
}

// This function enables an element.
function setEnabled(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName][elementName])
		document.forms[formName][elementName].disabled = false;
}

// This function applies focus to an element.
// ARG1 required; ARG2 only if more than one form on the page.
function setFocus(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName][elementName])
		document.forms[formName][elementName].focus();
}

// This function removes focus from an element.
function setBlur(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName][elementName])
		document.forms[formName][elementName].blur();
}

// This function applies focus and hilights an element.
function setSelect(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName][elementName])
	{
		document.forms[formName][elementName].focus();
		document.forms[formName][elementName].select();
	}
}

// This function disables all elements of a form.
function disableAll(formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName])
	{
		for (var i = 0; i < document.forms[formName].elements.length; i++)
			document.forms[formName][i].disabled = true;
	}
}

// This function enables all elements of a form.
function enableAll(formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName])
	{
		for (var i = 0; i < document.forms[formName].elements.length; i++)
			document.forms[formName][i].disabled = false;
	}
}

// This function checks a checkbox
function setChecked(elementName, formName)
{
	if (!formName)
		formName = 0;

	document.forms[formName][elementName].checked = true;
}

// This function unchecks a checkbox.
function setUnchecked(elementName, formName)
{
	if (!formName)
		formName = 0;

	document.forms[formName][elementName].checked = false;
}

// This function eliminates extraneous whitespace. Returns a string value.
// NOTE: This function eliminates ALL whitespace (even between two words)
function zapWhitespace(stringValue)
{
	if (stringValue)
	{
		var reWhitespace = /\ +/;			// one or more whitespace characters

		for (var i = 0; i < stringValue.length; i++)
			stringValue = stringValue.replace(reWhitespace, "");

		var reWhitespaceEOL = /\ +$/;		// whitespace at End Of Line
		stringValue = stringValue.replace(reWhitespaceEOL, "");
		return stringValue;
	}
}

// This function eliminates extraneous whitespace at the beginning, and end of
// a string (multiple words). Also converts 2 or more spaces into 1 space.
// NOTE: This function preserves word separation.
function zapExtraWhitespace(stringValue)
{
	if (stringValue)
	{
		var reWhitespaceBOL = /^\ +/;		// one or more ws characters at Beginning Of Line
		var reWhitespaceEOL = /\ +$/;		// whitespace characters at End Of Line
		var reWhitespaceEx = /\ {2,}/;	// EXtra whitespace between words

		stringValue = stringValue.replace(reWhitespaceBOL, "");
		stringValue = stringValue.replace(reWhitespaceEOL, "");
		stringValue = stringValue.replace(reWhitespaceEx, " "); // convert multiple spaces to one
		return stringValue;
	}
}

// This function sets a text field with something or nothing.
// For example, if a user sees that the field is required and
// they try typing in whitespace, this function resets that
// whitespace to nothing (Null) so that the field is empty.
// This function also eliminates extra whitespace when
// valid data has been entered. ie: "some text  " ==> "some text"
function requireData(elementName, formName)
{
	if (!formName)
		var formName = 0;

	var re = /\w/;
	if (re.test(document.forms[formName][elementName].value))
	{
		var tmp = getElement(elementName, formName);
		tmp = zapExtraWhitespace(tmp);
		setElement(elementName, tmp, formName);
	}
	else
	{
		var clearedString = '\0';
		setElement(elementName, clearedString, formName);
	}
}


// This function checks the length of a string. If an output is given, it displays the string length.
function checkLength(elementName, lengthLimit, outputElement, formName)
{
	if (!lengthLimit)
		var lengthLimit = 255;

	if (!formName)
		var formName = 0;

	var tmp = getElement(elementName, formName);

	if ((tmp == "") || (!tmp))
	{
		if (outputElement)
			setElement(outputElement, '0', formName);
		return true;
	}
	else
	{
		if (tmp.length > lengthLimit)
		{
			alert("This field cannot contain more than " + lengthLimit + " characters.");
			return false;
		}
		
		if (outputElement)
			setElement(outputElement, tmp.length, formName);
		return true;
	}
}

function checkMinLength(elementName, minLengthRequirement, noisy, formName)
{
	if (!minLengthRequirement)
		return false;

	if (!formName)
		var formName = 0;

	var tmp = getElement(elementName, formName);

	if ((tmp == "") || (!tmp))
		return true;
	else
	{
		if (tmp.length < minLengthRequirement)
		{
			if (noisy)
				alert("This field must contain at least " + minLengthRequirement + " characters.");
			return false;
		}
		return true;
	}
}

function checkMaxLength(elementName, maxLengthRequirement, noisy, formName)
{
	if (!maxLengthRequirement)
		return false;

	if (!formName)
		var formName = 0;

	var tmp = getElement(elementName, formName);

	if ((tmp == "") || (!tmp))
		return true;
	else
	{
		if (tmp.length > maxLengthRequirement)
		{
			if (noisy)
				alert("This field must contain no more than " + maxLengthRequirement + " characters.");
			return false;
		}
		return true;
	}
}


// This function returns true if the element contains data.
function isData(elementName, formName)
{
	if (!formName)
		var formName = 0;

	re = /\w/;
	if (re.test(document.forms[formName][elementName].value))
		return true;
	else
		return false;
}


// This function returns true if the element contains numeric data.
function isNumber(elementName, formName)
{
	if (!formName)
		var formName = 0;

	var re = /\w/;
	var reAlpha = /[a-z]/i;
	var reNum = /[0-9]+/;
	var theData = getElement(elementName, formName);

	if (re.test(theData))
	{
		theData = zapWhitespace(theData);

		if ((!reAlpha.test(theData)) && (reNum.test(theData)))
			return true;
		else
			return false;
	}
	else
		return false;
}

// This function returns true if the element contains alpha data.
function isAlpha(elementName, formName)
{
	if (!formName)
		var formName = 0;

	var re = /\w/;
	var reAlpha = /[a-z]+/;
	var reNum = /[0-9]+/;
	var theData = "asdf";
	alert(theData);
	if (re.test(theData))
	{
		theData = zapWhitespace(theData);

		if ((reAlpha.test(theData)) && (!reNum.test(theData)))
			return true;
		else
			return false;
	}
	else
		return false;
}

// This function takes a string from a form and "formats" it - capitalizing
// things that need to be capitalized. The first section capitalizes all words,
// the second part of the function uses regular expressions to capitalize only
// the words that need to be capitalized.
function formatCase(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (elementName && document.forms[formName][elementName])
	{
		var tmpStr;
		var tmpChar;
		var prevStr;
		var nextStr;
		var tmpStrLen;
		tmpStr = document.forms[formName][elementName].value.toLowerCase();
		tmpStrLen = tmpStr.length;
		if (tmpStrLen > 0)
		{
			for (var i = 0; i < tmpStrLen; i++)
			{
				if (i == 0)
				{
					tmpChar = tmpStr.substring(0, 1).toUpperCase();
					nextStr = tmpStr.substring(1, tmpStrLen);
					tmpStr = tmpChar + nextStr;
				}
				else
				{
					tmpChar = tmpStr.substring(i, i+1);
					if (tmpChar == " " && i < (tmpStrLen-1))
					{
						tmpChar = tmpStr.substring(i+1, i+2).toUpperCase();
						prevStr = tmpStr.substring(0, i+1);
						nextStr = tmpStr.substring(i+2, tmpStrLen);
						tmpStr = prevStr + tmpChar + nextStr;
					}
				}
			}
		}
		var newStr = tmpStr;

		/********* CUSTOMIZATIONS *********************************************/
		/* Replacing substrings using Regular expressions (like grep in Unix) */
		/**********************************************************************/
		//
		// The code below may look confusing, but it really isn't
		// This code uses regular expressions to search for substrings
		// to replace. For instance, in the following strings:
		//       "art/performances"    "argus ii"
		// In order to correctly capitalize these strings you have to
		// use regular expressions to search for a '/' character and a
		// letter, or a sequence of 'i' characters (a Roman numeral).
		// The code below will turn the above strings to these:
		//       "Art/Performances"    "Argus II"

		// never capitalize "and"
		newStr = newStr.replace(/and /i, "and ");

		// CIC is never "Cic"
		newStr = newStr.replace(/cic /i, "CIC ");

		// recognize these words: UM, UofM, GG
		reUM = /(\W)(\U\M)(\W)/i;
		reUM.exec(newStr);
		newStr = newStr.replace(reUM, RegExp.$1 + RegExp.$2.toUpperCase() + RegExp.$3);

		newStr = newStr.replace(/uofm/i, "UofM");

		// never capitalize "of"
		newStr = newStr.replace(/of /i, "of ");

		// cp&p = CP&P
		newStr = newStr.replace(/cp&p/i, "CP&P");

		// don't capitalize "the" between words
		newStr = newStr.replace(/ the /i, " the ");
		newStr = newStr.replace(/^the/i, "The");

		// only capitalize "the" if it starts a name (like "Diag, The")
		newStr = newStr.replace(/\,\sthe/i, ", The");

		// set up some regular expression objects
		re = /(\/)(\w)/;
		re2 = /(\()(\w)/;
		re3 = /(\-)(\w)/;
		re4 = /(\I{2,})/i;

		// The code below uses the above RegExp objects. The re.exec
		// line generates the objects RegExp.$1 and RegExp.$2 which
		// represent characters. Once these characters are generated,
		// the String function replace() is called to replace those
		// characters with the appropriate ones. (the replace() function
		// of a String object replaces a RegExp object with a String and
		// returns a new string)
		// NOTE: Nothing happens to the string when nothing is found

		re.exec(newStr);
		newStr = newStr.replace(re, RegExp.$1 + RegExp.$2.toUpperCase());

		re2.exec(newStr);
		newStr = newStr.replace(re2, RegExp.$1 + RegExp.$2.toUpperCase());

		re3.exec(newStr);
		newStr = newStr.replace(re3, RegExp.$1 + RegExp.$2.toUpperCase());

		re4.exec(newStr);
		newStr = newStr.replace(re4, RegExp.$1.toUpperCase());

		// Now write the formatted string to the form field.
		document.forms[formName][elementName].value = newStr;
	}
}

// this function takes an element value and tests to see if it is a valid
// time. Valid times are either Regular (3:00pm), Military (15:00), or
// in short-hand format (3pm or 3p). Function returns FALSE if time
// is not valid. Function returns FALSE if the elementName is invalid.
function checkValidTime(elementName, formName)
{
	// if user enters an invalid time, they will see this message:
	var errorMessage = "Error: This is not a valid time.\nPlease use either regular or military time format.";

	if (!formName)
		formName = 0;
	if (document.forms[formName][elementName])		// test if the element exists
	{
		re = /\w/;

		if (re.test(document.forms[formName][elementName].value))	// test if something was entered
		{
			var aTime = document.forms[formName][elementName].value; // store the value

			reMilTime = /^[0]?\d{1}\:[0-5][0-9]\ ?$|^[1][0-9]\:[0-5][0-9]\ ?$|^[2][0-3]\:[0-5][0-9]\ ?$|^[0][0-9]\:[0-5][0-9]\ ?$/;
			reRegTime = /^[0]?[1-9]{1}\:[0-5][0-9](\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)|^[0-1]?[0-2]{1}\:[0-5][0-9](\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)/i;
			reQckTime = /^[0]?[1-9]{1}(\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)|^[0-1]?[0-2]{1}(\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)/i;

			var milTime = reMilTime.test(aTime);	// check if its a military time
			var regTime = reRegTime.test(aTime);	// check if its a regular time
			var qckTime = reQckTime.test(aTime);	// check if its a quick-entry time ("3pm" or "2p")

			if (milTime ^ regTime ^ qckTime)		// if 1 of these formats match (exclusive-or)
				return true;
			else
			{
				alert(errorMessage);
				document.forms[formName][elementName].focus();
				document.forms[formName][elementName].select();
				return false;
			}
		}
		else
		{
			if (elementName == 'StartTime')
				return false;
			else
				return true;
		}
	}
	else
		return false;			// function returns FALSE if the element doesn't exist
}


// this function takes an element value and tests to see if it is a valid
// time. Valid times are either Regular (3:00pm), Military (15:00), or
// in short-hand format (3pm or 3p). Function returns FALSE if time
// is not valid. Function returns FALSE if the elementName is invalid.
function fixTime(elementName, standardOrMilitary, formName)
{
	// if user enters an invalid time, they will see this message:
	var errorMessage = "[fixTime] Error: This is not a valid time.\nPlease use either regular or military time format.";

	if (!formName)
		formName = 0;
	if (document.forms[formName][elementName])		// test if the element exists
	{
		re = /\w/;

		if (re.test(document.forms[formName][elementName].value))	// test if something was entered
		{
			var aTime = document.forms[formName][elementName].value; // store the value

			var reMilTime = /^[0]?\d{1}\:[0-5][0-9]\ ?$|^[1][0-9]\:[0-5][0-9]\ ?$|^[2][0-3]\:[0-5][0-9]\ ?$|^[0][0-9]\:[0-5][0-9]\ ?$/;
			var reRegTime = /^[0]?[1-9]{1}\:[0-5][0-9](\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)|^[0-1]?[0-2]{1}\:[0-5][0-9](\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)/i;
			var reQckTime = /^[0]?[1-9]{1}(\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)|^[0-1]?[0-2]{1}(\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)/i;

			var milTime = reMilTime.test(aTime);	// check if its a military time
			var regTime = reRegTime.test(aTime);	// check if its a regular time
			var qckTime = reQckTime.test(aTime);	// check if its a quick-entry time ("3pm" or "2p")
			
			if (!standardOrMilitary)
				var standardOrMilitary = "standard";
			
			
			if (milTime ^ regTime ^ qckTime)		// if 1 of these formats match (^ = exclusive-or)
			{
				// find numbers, find a colon, find am/pm, test if number is greater than 12....
				
				if (milTime)
				{
					
					var reBC = /^[0]?\d{1}\:|^[1][0-9]\:|^[2][0-3]\:|^[0][0-9]\:/;
					var reAC = /\:[0-5][0-9]/;

					var tmp = aTime;
					var tmpIndex = tmp.search(/\:/);
					var beforeColon = tmp.slice(0, tmpIndex);
					var afterColon = tmp.slice(tmpIndex+1, tmp.length);
					var newTimeOutput = "";
					var amPM = "";

					if (standardOrMilitary == "standard")
					{
						if (beforeColon >= 12)
						{
							if (beforeColon > 12)
								beforeColon -= 12;
							amPM = " PM";
						}
						else
							amPM = " AM";
						
						if ((beforeColon == "0") || (beforeColon == "00"))
						{
							beforeColon = "12";
							amPM = " AM";
						}
						
						newTimeOutput = beforeColon + ':' + afterColon + amPM;
						document.forms[formName][elementName].value = newTimeOutput;
											
					}
					else
					{
						if ((beforeColon <= 9) && (beforeColon.length <= 1))
							beforeColon = '0' + beforeColon;

						newTimeOutput = beforeColon + ':' + afterColon;
						document.forms[formName][elementName].value = newTimeOutput;
					}
				}
				
				if (regTime)
				{
					
					var reBC = /^[0]?[1-9]{1}\:|^[0-1]?[0-2]{1}\:/;
					var reAC = /\:[0-5][0-9]/;
					var reTT = /(\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)/i;

					var tmp = aTime;
					var tmpIndex = tmp.search(/\:/);
					var tmpIndex2 = tmp.search(reTT);
					var beforeColon = tmp.slice(0, tmpIndex);
					var afterColon = tmp.slice(tmpIndex+1, tmpIndex2);
					var amPM = tmp.slice(tmpIndex2, tmp.length);
					var newTimeOutput = "";

					if (standardOrMilitary == "standard")
					{
						var amPM = zapWhitespace(amPM.toLowerCase());
						
						if ((amPM == "a") || (amPM == "am"))
							amPM = " AM";
						else
							amPM = " PM";
						
						if (beforeColon <= 9)
							if (beforeColon.length > 1)
								beforeColon = beforeColon.charAt(1);
						
						newTimeOutput = beforeColon + ':' + afterColon + amPM;
						document.forms[formName][elementName].value = newTimeOutput;
					}
					else
					{
						var amPM = zapWhitespace(amPM.toLowerCase());
						
						if ((amPM == "a") || (amPM == "am"))
						{
							if (beforeColon <= 9)
								beforeColon = '0' + beforeColon;
						}
						else
							beforeColon = eval(beforeColon) + 12;
						
						newTimeOutput = beforeColon + ':' + afterColon;
						document.forms[formName][elementName].value = newTimeOutput;
						
					}
				}
				
				if (qckTime)
				{
					
					var reBTT = /^[0]?[1-9]{1}|^[0-1]?[0-2]{1}/;
					var reTT = /(\ ?[a]\ ?$|\ ?[p]\ ?$|\ ?[a][m]\ ?$|\ ?[p][m]\ ?$)/i;

					var tmp = aTime;
					var tmpIndex = tmp.search(reTT);
					var beforeTT = tmp.slice(0, tmpIndex);
					var amPM = tmp.slice(tmpIndex, tmp.length);
					var newTimeOutput = "";

					if (standardOrMilitary == "standard")
					{
						var amPM = zapWhitespace(amPM.toLowerCase());
						
						//alert("amPM: " + amPM);
						
						if ((amPM == "a") || (amPM == "am"))
							amPM = " AM";
						else
							amPM = " PM";
						
						newTimeOutput = beforeTT + ":00" + amPM;
						document.forms[formName][elementName].value = newTimeOutput;
					}
					else
					{
						if ((amPM == "a") || (amPM == "am"))
						{
							if (beforeTT <= 9)
								beforeTT = '0' + beforeTT;
							if (beforeTT == 12)
								beforeTT = "24";
						}
						else
						{
							if (beforeTT < 12)
								beforeTT = eval(beforeTT) + 12;
						}
						
						newTimeOutput = beforeTT + ":00";
						document.forms[formName][elementName].value = newTimeOutput;
						
					}
				}
				
				return true;	
			}
			else
			{
				alert(errorMessage);
				document.forms[formName][elementName].focus();
				document.forms[formName][elementName].select();
				return false;
			}
			
			
		}
	}
	else
		return false;			// function returns FALSE if the element doesn't exist
}


// This function checks to make sure that a date was entered in the correct format.
// Also checks to make sure dates are valid: 30days in certain months; 28/29 days in Feb...
function checkValidDate(elementName, formName)
{
	if (!formName)
		formName = 0;

	var re = /\w/;

	if (re.test(document.forms[formName][elementName].value))
	{
		var valid = "true";
		var theDate = document.forms[formName][elementName].value;
		var reDate = /^([0]?[1-9]{1}|[1]{1}[0-2]{1})(\/|\-)([3]?[0-1]{1}|[2]?[0-9]{1}|[1]?[0-9]{1}|[0]?[1-9]{1}|\d{1})\2(\d{2}|\d{4})\s?$/;
		var reFebCheck = /^[0]?[2]{1}(\/|\-)[3]{1}\d{1}/;	// valid only if this is false
		var reDayCheck = /^([0]?[4]{1}|[0]?[6]{1}|[0]?[9]{1}|[1]{1}[1]{1})(\/|\-)[3]{1}[1-9]{1}/; // valid only if this is false

		var reDot = /\./;
		var reDash = /\-/;

		// remove all unnecessary spaces
		theDate = zapWhitespace(theDate);

		// convert '-' and '.' to '/' (mm.dd.yyyy or mm-dd-yyyy ==> m/d/yyyy)
		for (var i = 0; i < theDate.length; i++)
		{
			theDate = theDate.replace(reDot, '/');
			theDate = theDate.replace(reDash, '/');
		}

		setElement(elementName, theDate, formName);


		if ((reFebCheck.test(theDate)) || (reDayCheck.test(theDate)))
			valid = "false";
		else
			valid = "true";

		if ((reDate.test(theDate)) && (valid == "true"))
			return true;
		else
		{
			document.forms[formName][elementName].focus();
			document.forms[formName][elementName].select();
			return false;
		}
	}
	else
		return true;
}

// This function checks to make sure that a date was entered in the correct format.
// Also checks to make sure dates are valid: 30days in certain months; 28/29 days in Feb...
// NOTE: This is the "Noisy" function, that allows for an alert() popup message and a requirement option
// (the date is a required field)
// WARNING: If the user clicks off of a field that is required and the noisy feature is set to "true",
// an alert box will pop up for each time that the user clicks somewhere besides the required field. It
// can be an annoying, nagging feature.
function checkDate(elementName, isRequired, isNoisy, formName)
{
	if (!formName)
		var formName = 0;

	if ((!isNoisy) || (isNoisy == "false"))
		var isNoisy = 0;

	if ((!isRequired) || (isRequired == "false"))
		var isRequired = 0;

	var re = /\w/;

	if (re.test(document.forms[formName][elementName].value))
	{
		var valid = "true";
		var theDate = document.forms[formName][elementName].value;
		var reDate = /^([0]?[1-9]{1}|[1]{1}[0-2]{1})(\/|\-)([3]?[0-1]{1}|[2]?[0-9]{1}|[1]?[0-9]{1}|[0]?[1-9]{1}|\d{1})\2(\d{2}|\d{4})\s?$/;
		var reFebCheck = /^[0]?[2]{1}(\/|\-)[3]{1}\d{1}/;	// valid only if this is false
		var reDayCheck = /^([0]?[4]{1}|[0]?[6]{1}|[0]?[9]{1}|[1]{1}[1]{1})(\/|\-)[3]{1}[1-9]{1}/; // valid only if this is false

		var reDot = /\./;
		var reDash = /\-/;

		// remove all unnecessary spaces
		theDate = zapWhitespace(theDate);

		// convert '-' and '.' to '/' (mm.dd.yyyy or mm-dd-yyyy ==> m/d/yyyy)
		for (var i = 0; i < theDate.length; i++)
		{
			theDate = theDate.replace(reDot, '/');
			theDate = theDate.replace(reDash, '/');
		}

		setElement(elementName, theDate, formName);


		if ((reFebCheck.test(theDate)) || (reDayCheck.test(theDate)))
			valid = "false";
		else
			valid = "true";

		if ((reDate.test(theDate)) && (valid == "true"))
			return true;
		else
		{
			if (isNoisy == 0)
				return false;
			else
			{
				if (isRequired != 0)
					alert("Error: Invalid date. A valid date is required.\nPlease enter a valid date to continue.");
				else
					alert("Error: Invalid date. Either leave this field blank, or enter a valid date to continue.");
			}
			document.forms[formName][elementName].focus();
			document.forms[formName][elementName].select();

			return false;
		}
	}
	else
	{
		if (isRequired != 0)
		{
			if (isNoisy != 0)
				alert("Error: A valid date is required.\nPlease enter a valid date to continue.");

			document.forms[formName][elementName].focus();
			document.forms[formName][elementName].select();
			return false;
		}
		else
			return true;
	}
}


function checkData(elementName, noisy, formName)
{
	if (!formName)
		var formName = 0;
	var re = /\w/;
	var theData = getElement(elementName, formName);
	if (re.test(theData))
	{
		return true;
	}
	else
	{
		if (noisy)
			alert("Error: This field is required.")
		setFocus(elementName, formName);
		return false;
	}
}

// This function returns true if there are no double quotes.
function checkForQuotes(elementName, formName)
{
	if (!formName)
		formName = 0;
	re = /\"/;
	if (re.test(document.forms[formName][elementName].value))
	{
		var tmpStr = document.forms[formName][elementName].value;

		while (re.test(tmpStr))
			tmpStr = tmpStr.replace(/\"/, "'");
		document.forms[formName][elementName].value = tmpStr;
		return true;
	}
	else
		return true;
}

// This function removes double quotes.
function removeQuotes(elementName, formName)
{
	if (!formName)
		formName = 0;
	re = /\"/;
	if (re.test(document.forms[formName][elementName].value))
	{
		var tmpStr = document.forms[formName][elementName].value;

		var replaceYes = confirm("You cannot use double-quotation marks in this field.\nDo you wish to replace them with single quotes?\n\nClick \"OK\" to replace, \"Cancel\" to remove...");

		if (replaceYes)
		{
			while (re.test(tmpStr))
				tmpStr = tmpStr.replace(/\"/, "'");
		}
		else
		{
			while (re.test(tmpStr))
				tmpStr = tmpStr.replace(/\"/, "");
		}
		document.forms[formName][elementName].value = tmpStr;

		document.forms[formName][elementName].focus();
		document.forms[formName][elementName].select();
		return true;
	}
	else
		return true;
}

// This function replaces double quotes with single quotes (no prompts).
function replaceQuotes(elementName, formName)
{
	if (!formName)
		formName = 0;
	re = /\"/;
	if (re.test(document.forms[formName][elementName].value))
	{
		var tmpStr = document.forms[formName][elementName].value;

		while (re.test(tmpStr))
			tmpStr = tmpStr.replace(/\"/, "'");

		document.forms[formName][elementName].value = tmpStr;

		return true;
	}
	else
		return true;
}

// This function checks to make sure that a phone number was entered in the correct format.
//
// ASSUMPTION: If only 7 digits are entered, area code is set to 734
function checkPhone(elementName, formName, notNoisy)
{
	if (!formName)
		formName = 0;
	if (document.forms[formName][elementName])
	{
		re = /\w/;
		if (re.test(document.forms[formName][elementName].value))
		{
			var tmp = document.forms[formName][elementName].value;

			var returnString = "";
			var removeThese = " \t\n\r()[]-.;";
			for (var i = 0; i < tmp.length; i++)
			{
				// Check that current character isn't whitespace.
				var c = tmp.charAt(i);
				if (removeThese.indexOf(c) == -1)
					returnString += c;
			}
			tmp = returnString.toUpperCase();

			var reElvnNums = /^(\d{1})(\d{3})(\d{3})(\d{4})$/;
			var reElvnChrs = /^(\d{1})(\d{3})(\w{3})(\w{4})$/;
			var reTenNumbs = /^(\d{3})(\d{3})(\d{4})$/;
			var reSevenNum = /^(\d{3})(\d{4})$/;
			var reSevenChr = /^(\w{3})(\w{4})$/;
			var reTenChars = /^(\d{3})(\w{3})(\w{4})$/;

			if (tmp.length == 5)
			{
				if (!notNoisy)
					alert("Error: Only 5 digits entered.\nIf you are entering a campus number, you must include the complete 7-digit number.");
				document.forms[formName][elementName].focus();
				document.forms[formName][elementName].select();
				if (!notNoisy)
					return false;
				else
					return true;
			}
			else if (reElvnNums.test(tmp))
			{
				reElvnNums.exec(tmp);
				if (RegExp.$1 == 1)
				{
					var newNum = RegExp.$2 + " " + RegExp.$3 + "-" + RegExp.$4;
					document.forms[formName][elementName].value = newNum;
					return true;
				}
				else
				{
					var reFaxNum = /fax/i;
					if (!notNoisy)
					{
						if (reFaxNum.test(elementName))
							alert("Warning: This does not appear to be a valid fax number.\nPlease make sure the number is correct.");
						else
							alert("Warning: This does not appear to be a valid phone number.\nPlease make sure the number is correct.");
						setFocus(elementName, formName);
						return true;
					}
					else
						return true;
				}
			}
			else if (reElvnChrs.test(tmp))
			{
				reElvnChrs.exec(tmp);
				var newNum = RegExp.$2 + " " + RegExp.$3 + "-" + RegExp.$4;
				document.forms[formName][elementName].value = newNum;
				return true;
			}
			else if (reSevenNum.test(tmp))
			{
				reSevenNum.exec(tmp);
				var newNum = "734 " + RegExp.$1 + "-" + RegExp.$2;
				document.forms[formName][elementName].value = newNum;
				return true;
			}
			else if (reTenNumbs.test(tmp))
			{
				reTenNumbs.exec(tmp);
				var newNum = RegExp.$1 + " " + RegExp.$2 + "-" + RegExp.$3;
				document.forms[formName][elementName].value = newNum;
				return true;
			}
			else if (reSevenChr.test(tmp))
			{
				reSevenChr.exec(tmp);
				var newNum = "734 " + RegExp.$1 + "-" + RegExp.$2;
				document.forms[formName][elementName].value = newNum;
				return true;
			}
			else if (reTenChars.test(tmp))
			{
				reTenChars.exec(tmp);
				var newNum = RegExp.$1 + " " + RegExp.$2 + "-" + RegExp.$3;
				document.forms[formName][elementName].value = newNum;
				return true;
			}
			else
			{
				var reFax = /fax/i;
				if (!notNoisy)
				{
					if (reFax.test(elementName))
						alert("Warning: This does not appear to be a valid fax number.\nPlease make sure the number is correct.");
					else
						alert("Warning: This does not appear to be a valid phone number.\nPlease make sure the number is correct.");
				}
				document.forms[formName][elementName].focus();
				document.forms[formName][elementName].select();
				return true;
			}
		}
		else
		{
			if (elementName == 'TelephoneNumber')
			{
				alert("Error: A telephone number is required.");
				return false;
			}
			else
				return true;
		}
	}
}

// This function is used to only format a phone number, rather than checking it like
// checkPhone() does. It uses the checkPhone() function with its "notNoisy" option
// turned on, which prevents alert boxes and returned false values.
function formatPhone(elementName, formName)
{
	if (!formName)
		var formName = 0;

	// using the checkPhone() function with the "notNoisy" option turned on (prevents alert boxes)
	checkPhone(elementName, formName, "true");
}

// This function finds text links in a string and replaces them with HTML links.
// This function returns the updated string.
function insideReplaceFunction (string1, string2, string3)
{
	var str = string1.substring(1,string1.length); 
	// remove trailing dots, if any
	while ((str.length > 0) && (str.charAt(str.length - 1) == '.')) 
		str = str.substring(0, str.length - 1);
	
	// special case for School of Music...
	remusic = /purchase\.tickets\.com/
	
	reht = /(http|https|ftp)\:\/\//
	if (reht.test(str))
	{
		if (remusic.test(str))
			return " <a target=\"blank\" href=\"" + str + "\">Buy tickets online!</a>"
		else
			return " <a target=\"blank\" href=\"" + str + "\">" + str + "</a>"
	}
	else
	{
		if (remusic.test(str))
			return " <a target=\"blank\" href=\"http://" + str + "\">Buy tickets online!</a>"
		else
			return " <a target=\"blank\" href=\"http://" + str + "\">" + str + "</a>"
	}
}

function parseLinks(s) 
{   
  	var userAgent = navigator.userAgent;
	if (((userAgent.indexOf("MSIE") != -1) && (userAgent.indexOf("Mac") != -1)) || (userAgent.indexOf("Safari") != -1)) 
	{
		// SAFARI DIFFERENCES:
		// 	- in the pattern linkpattern, the \v was removed. Mac recognizes the '_' with \v (vertical tab?).
		//		- the Mac apparently doesn't support a function inside the string.replace() method. Hence the function
		//		insdideReplaceFunction() above.
		var linkpattern = /\s(http:\/\/|ftp:\/\/|https:\/\/|www\.)([^ \,\:\)\(\"\'\<\>\f\n\r\t])+/g;
		
		//return ("testArray.length: " + testArray.length + "<br>\$0: " + testArray[0] + "<br>\$1: " + testArray[1] + "<br>\$2: " + testArray[2]);
		/*return (
			s.replace(linkpattern, insideReplaceFunction(testArray[0], testArray[1], testArray[2]))
		);*/
		
		while (linkpattern.test(s))
		{
			testArray = linkpattern.exec(s);
			s = s.replace(linkpattern, insideReplaceFunction(testArray[0], testArray[1], testArray[2]))
		}
		return s;
	}
	else
	{
		var linkpattern = /\s(http:\/\/|ftp:\/\/|https:\/\/|www\.)([^ \,\:\)\(\"\'\<\>\f\n\r\t\v])+/g;
		return (
			s.replace(linkpattern, function ($0, $1, $2) {
				s = $0.substring(1,$0.length); 
				// remove trailing dots, if any
				while ((s.length > 0) && (s.charAt(s.length - 1) == '.')) 
					s = s.substring(0, s.length - 1);
				
				// special case for School of Music...
				remusic = /purchase\.tickets\.com/
							
				reht = /(ht|f)tp:\/\//
				if (reht.test(s))
				{
					if (remusic.test(s))
						return " <br \/><strong><a style=\"text-decoration: underline;\" target=\"blank\" href=\"" + s + "\">Buy tickets online!</a></strong>"
					else
						return " <a target=\"blank\" href=\"" + s + "\">" + s + "</a>"
				}
				else
				{
					if (remusic.test(s))
						return " <br \/><a target=\"blank\" href=\"http://" + s + "\">Buy tickets online!</a>"
					else
						return " <a target=\"blank\" href=\"http://" + s + "\">" + s + "</a>"
				}
				/* return " " + s.link(s); */
			})
		);
	}
}

// This function checks to make sure that the URL was entered in a valid format.
//
// ASSUMPTION: entering "~something" resolves to "http://www.umich.edu/~something"
function checkURL(elementName, formName)
{
	if (!formName)
		formName = 0;

	if (document.forms[formName][elementName])
	{
		re = /(\w|\W)/;
		if (re.test(document.forms[formName][elementName].value))
		{
			var tmp = document.forms[formName][elementName].value;

			tmp = zapWhitespace(tmp);
			setElement(elementName, tmp, formName);

			reWhitespace = /\ /;
			while(reWhitespace.test(tmp))
				tmp = tmp.replace(reWhitespace, "%20");

			reTest = /(^(http:\/\/)|^(https:\/\/)|^(ftp:\/\/))/;
			if (reTest.test(tmp))
				return true;
			else
			{
				re2 = /^\~[a-z]{2,}/;
				re3 = /\.([a-z]{2,}|[0-9]{2,})/;
				if (re2.test(tmp))
				{
					var newStr = "http://www.umich.edu/" + tmp;
					document.forms[formName][elementName].value = newStr;
					return true;
				}
				else if (re3.test(tmp))
				{
					var newStr = "http://" + tmp;
					document.forms[formName][elementName].value = newStr;
					return true;
				}
				else
				{
					document.forms[formName][elementName].focus();
					document.forms[formName][elementName].select();
					return false;
				}
			}
		}
		else
			return true;
	}
}

// This function checks to make sure that the email address is in a valid format
//
// NOTE: if the elementName is "from", the field is treated as required (ie: in a
// form with HTMail, from is a required field name, therefore this function will
// cause an error message if no value is entered)
function checkEmail(elementName, formName, isRequired)
{
	if (!formName)
		var formName = 0;

	if (document.forms[formName][elementName])
	{
		re = /\w/;
		if (re.test(document.forms[formName][elementName].value))
		{
			var tmp = document.forms[formName][elementName].value;

			tmp = zapWhitespace(tmp);
			setElement(elementName, tmp, formName);

			reEmail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

			if (reEmail.test(tmp))
				return true;
			else
			{
				re2 = /^[a-z]{2,8}$/;
				if (re2.test(tmp))
				{
					document.forms[formName][elementName].value = tmp + "@umich.edu";
					return true;
				}
				else
				{
					alert("Error: This does not appear to be a valid email address.");
					document.forms[formName][elementName].focus();
					document.forms[formName][elementName].select();
					return false;
				}
			}
		}
		else
		{
			if (elementName == 'from')
			{
				alert("Error: An email address is required.");
				return false;
			}
			else
			{
				if (isRequired)
					return false;
				else
					return true;
			}
		}
	}
}

// This function sets an object's visibility setting to either
// 'visible' or 'hidden'. This only applies to browsers that support
// the document.getElementById() function. Both the elementID and
// visibilityValue arguments are required.
// This function is most useful for DIVs and SPANs (layers).
function setVisibility(elementName, displayProperty)
{
	if ((elementName) && (displayProperty))
	{
		if (document.getElementById)
		{
			if (displayProperty == "visible")
				document.getElementById(elementName).style.visibility = "visible";
			else
				document.getElementById(elementName).style.visibility = "hidden";
		}
	}
}

// This function shows or hides an element (anything with an ID tag).
// Identifying an element with a NAME tag WILL NOT WORK!
// ASSUMPTIONS: There must be a style sheet of some sort that
// sets a position attribute (either 'absolute' or 'relative') otherwise
// the display property is ignored.
// Valid displayProperties are "block", "inline", "list-item" and "none"
function showHide(elementName, displayProperty)
{
	if (elementName)
	{
		// valid displayProperties: "block", "inline", "list-item" (and "none")
		// setting default to "block" (if no displayProperty is given)
		if (!displayProperty)
			displayProperty = "block";

		if (document.getElementById)
		{
			if (document.getElementById(elementName).style.display != displayProperty)
				document.getElementById(elementName).style.display = displayProperty;
			else
			{
				if (displayProperty == "block")
					document.getElementById(elementName).style.display = "block";
				else
					document.getElementById(elementName).style.display = "none";
			}
		}
	}
}

// Global variable initialized to False, used (required) for resizeWindow() function
var sized = 0;

// This function is used (required) for teh resizeWindow() function
function resetSizedVar()
{
	sized = 0;
}

// This function resizes a window using animation (if the browser is capable
// of using the getElementById() method). The window either grows or shrinks
// to the specified size, two numbers: new width and new height.
// This function affects the size of the usable HTML space, not the window
// itself.
function resizeWindow(canvasWidth, canvasHeight, noAnimation)
{
	if ((document.getElementById) && (!noAnimation))
	{
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			var outerWidth = top.document.body.clientWidth;
			var outerHeight = top.document.body.clientHeight;

			if (window == top.window)
			{
				var theWidth = top.document.body.scrollWidth;
				var theHeight = outerHeight;
			}
			else
			{
				var theWidth = top.document.body.scrollWidth;
				var theHeight = top.document.body.scrollHeight;
			}
		}
		else
		{
			var theWidth = top.window.innerWidth;
			var theHeight = top.window.innerHeight;
			var outerWidth = top.window.outerWidth;
			var outerHeight = top.window.outerHeight;
		}


		// SHRINK THE WINDOW
		while ((theWidth > (canvasWidth + 100)) && (sized == 0))
		{
			top.window.resizeBy(-20, 0);
			theWidth -= 20;
		}

		while ((theWidth >= (canvasWidth + 20)) && (sized == 0))
		{
			top.window.resizeBy(-5, 0);
			theWidth -= 5;
		}
		while ((theWidth > canvasWidth) && (theWidth < (canvasWidth + 20)) && (sized == 0))
		{
			top.window.resizeBy(-1, 0);
			theWidth--;
		}

		while ((theHeight > (canvasHeight + 75)) && (sized == 0))
		{
			top.window.resizeBy(0, -10);
			theHeight -= 10;
		}

		while ((theHeight >= (canvasHeight + 40)) && (sized == 0))
		{
			top.window.resizeBy(0, -5);
			theHeight -= 5;
		}
		while ((theHeight > (canvasHeight)) && (sized == 0))
		{
			top.window.resizeBy(0, -1);
			theHeight--;
		}



		// GROW THE WINDOW
		while ((theWidth < (canvasWidth - 100)) && (sized == 0))
		{
			top.window.resizeBy(20, 0);
			theWidth += 20;
		}

		while ((theWidth <= (canvasWidth - 40)) && (sized == 0))
		{
			top.window.resizeBy(5, 0);
			theWidth += 5;
		}
		while ((theWidth < canvasWidth) && (theWidth > (canvasWidth - 40)) && (sized == 0))
		{
			top.window.resizeBy(1, 0);
			theWidth++;
		}


		while ((theHeight < (canvasHeight - 125)) && (sized == 0))
		{
			top.window.resizeBy(0, 10);
			theHeight += 10;
		}

		while ((theHeight <= (canvasHeight - 25)) && (sized == 0))
		{
			top.window.resizeBy(0, 5);
			theHeight += 5;
		}
		while ((theHeight < (canvasHeight)) && (sized == 0))
		{
			top.window.resizeBy(0, 1);
			theHeight++;
		}
		sized = 1;
	}
	else
		top.window.resizeTo(canvasWidth,canvasHeight);
}

// This function returns the dimensions of the usable HTML
// space inside the borders of the browser window. The value
// is returned as a string in this format:  "width,height"
// The returned value is most useful for the resizeWindow(canvasWidth, canvasHeight) function
function getCanvasSize()
{
	if (document.getElementById)
	{
		var widthByHeight = "";

		if (navigator.appName == "Microsoft Internet Explorer")
		{
			var outerWidth = top.document.body.clientWidth;
			var outerHeight = top.document.body.clientHeight;

			if (window == top.window)
			{
				var theWidth = top.document.body.scrollWidth;
				var theHeight = outerHeight;
			}
			else
			{
				var theWidth = top.document.body.scrollWidth;
				var theHeight = top.document.body.scrollHeight;
			}
		}
		else
		{
			var theWidth = top.window.innerWidth;
			var theHeight = top.window.innerHeight;
			var outerWidth = top.window.outerWidth;
			var outerHeight = top.window.outerHeight;
		}

		widthByHeight = theWidth + "," + theHeight;
		return widthByHeight;
	}
	else
		return "";
}

// This function returns the size, in pixels, of the width of the space
// inside the borders of the web browser (the usable HTML space). This
// function can be called from any page/frame.
function getCanvasWidth()
{
	if (document.getElementById)
	{

		if (navigator.appName == "Microsoft Internet Explorer")
		{
			var outerWidth = top.document.body.clientWidth;

			if (window == top.window)
			{
				var theWidth = top.document.body.scrollWidth;
			}
			else
			{
				var theWidth = top.document.body.scrollWidth;
			}
		}
		else
		{
			var theWidth = top.window.innerWidth;
			var outerWidth = top.window.outerWidth;
		}

		return theWidth;
	}
	else
		return "";
}

// This function returns the size, in pixels, of the height of the space
// inside the borders of the web browser (the usable HTML space). This
// function can be called from any page/frame.
function getCanvasHeight()
{
	if (document.getElementById)
	{

		if (navigator.appName == "Microsoft Internet Explorer")
		{
			var outerHeight = top.document.body.clientHeight;

			if (window == top.window)
			{
				var theHeight = outerHeight;
			}
			else
			{
				var theHeight = top.document.body.scrollHeight;
			}
		}
		else
		{
			var theHeight = top.window.innerHeight;
			var outerHeight = top.window.outerHeight;
		}

		return theHeight;
	}
	else
		return "";
}


// This function must be called in the body tag's onLoad attribute. It's a direct
// replacement of the killFocus() function which prevents the annoying link
// boxes in IE and Netscape 6.x
function preventLinkBoxes()
{
	if (document.getElementById)
	{
		var theLinks = document.getElementsByTagName('a');	// get all <a> tags
		for (var i = 0; i < theLinks.length; i++) // loop through the tags
			theLinks[i].onfocus = new Function("if (this.blur) this.blur()"); // apply a blur() function to each one

		var theAreas = document.getElementsByTagName("area"); // don't forget <area> tags for image map links
		for (var i = 0; i < theAreas.length; i++)
			theAreas[i].onfocus = new Function("if (this.blur) this.blur()");
	}
}


// This function does a lot of things. It removes the onClick focus boxes that are on by default in new
// browsers. It also dynamically creates title, onMouseOver, and onMouseOut attributes. If mouse over and out
// events aren't specified, this function will call set the status bar to display the title of the link as well.
// This function applies to all links on the page.
function smartLinks(notips)
{
	if (document.getElementById)
	{
		var re = /\w/;
		var reImage = /<img/i;
		var reNbsp = /\&nbsp\;/;
		var reAmp = /\&amp\;/;
		var isImage = 0;
		
		if (!notips)
		{
			var theLinks = document.getElementsByTagName('a');
			for (var i = 0; i < theLinks.length; i++)
			{
				var theHTML = theLinks[i].innerHTML;

				if (reImage.test(theHTML))
					isImage = 1;

				// whatever the link is (inside the a tag), set it to the title
				var newTitle = theLinks[i].innerHTML;

				// Replace all "&nbsp;" with " " where appropriate
				while (reNbsp.test(newTitle))
					newTitle = newTitle.replace(reNbsp, " ");

				// Replace all "&amp;" with "&" where appropriate
				while (reAmp.test(newTitle))
					newTitle = newTitle.replace(reAmp, "&");

				// if the onMouseOver and onMouseOut attributes aren't specified, set up the stat() function
				if ((!theLinks[i].onmouseover) && (!theLinks[i].onmouseout))
				{
					if (theLinks[i].title)
						theLinks[i].onmouseover = new Function("stat(this.title); return true;");
					else
						theLinks[i].onmouseover = new Function("stat(this.innerHTML); return true;");
					theLinks[i].onmouseout = new Function("stat(); return true;");
				}

				// if there's no title attribute specified, set it to the inner html
				if (!theLinks[i].title)
					theLinks[i].title = newTitle;

				// if there's no onFocus attribute already specified, apply the blur() function
				if (!theLinks[i].onfocus)
					theLinks[i].onfocus = new Function("if (this.blur) this.blur();");

				// if the href is a javascript void() and there's no onClick attribute specified, set
				// the stat() function to "" for onClick
				if ((theLinks[i].href == "javascript:void(0);") && (!theLinks[i].onclick))
					theLinks[i].onclick = new Function("stat(); return true;");

				// if the href is a javascript void(), then set the title to the inner html
				if ((theLinks[i].href == "javascript:void(0);") && (!re.test(theLinks[i].title)))
					theLinks[i].title = theHTML;
			}

			var theAreas = document.getElementsByTagName("area");
			for (var i = 0; i < theAreas.length; i++)
			{
				var theHTML = theAreas[i].innerHTML;

				if (reImage.test(theHTML))
					isImage = 1;

				var newTitle = theAreas[i].innerHTML;
				while (reNbsp.test(newTitle))
					newTitle = newTitle.replace(reNbsp, " ");

				while (reAmp.test(newTitle))
					newTitle = newTitle.replace(reAmp, "&");

				if ((!theAreas[i].onmouseover) && (!theAreas[i].onmouseout))
				{
					if (theAreas[i].title)
						theAreas[i].onmouseover = new Function("stat(this.title); return true;");
					else
						theAreas[i].onmouseover = new Function("stat(this.innerHTML); return true;");
					theAreas[i].onmouseout = new Function("stat(); return true;");
				}

				if (!theAreas[i].title)
					theAreas[i].title = newTitle;

				if (!theAreas[i].onfocus)
					theAreas[i].onfocus = new Function("if (this.blur) this.blur();");

				if ((theAreas[i].href == "javascript:void(0);") && (!theAreas[i].onclick))
					theAreas[i].onclick = new Function("stat(); return true;");

				// if the href is a javascript void(), then set the title to the inner html
				if ((theAreas[i].href == "javascript:void(0);") && (!re.test(theAreas[i].title)))
					theAreas[i].title = theHTML;

			}
		}
		else // ------------------DISABLED TOOLTIPS----------------------
		{
			var theLinks = document.getElementsByTagName('a');
			for (var i = 0; i < theLinks.length; i++)
			{
				var theHTML = theLinks[i].innerHTML;

				if (reImage.test(theHTML))
					isImage = 1;

				// whatever the link is (inside the a tag), set it to the title
				var newTitle = theLinks[i].innerHTML;

				// Replace all "&nbsp;" with " " where appropriate
				while (reNbsp.test(newTitle))
					newTitle = newTitle.replace(reNbsp, " ");

				// Replace all "&amp;" with "&" where appropriate
				while (reAmp.test(newTitle))
					newTitle = newTitle.replace(reAmp, "&");

				// if the onMouseOver and onMouseOut attributes aren't specified, set up the stat() function
				if ((!theLinks[i].onmouseover) && (!theLinks[i].onmouseout))
				{
					if (theLinks[i].title)
						theLinks[i].onmouseover = new Function("stat(this.title); return true;");
					else
						theLinks[i].onmouseover = new Function("stat(this.innerHTML); return true;");
					theLinks[i].onmouseout = new Function("stat(); return true;");
				}
				
				// if there's no title attribute specified, set it to NOTHING
				if (!theLinks[i].title)
					theLinks[i].title = "";

				// if there's no onFocus attribute already specified, apply the blur() function
				if (!theLinks[i].onfocus)
					theLinks[i].onfocus = new Function("if (this.blur) this.blur();");

				// if the href is a javascript void() and there's no onClick attribute specified, set
				// the stat() function to "" for onClick
				if ((theLinks[i].href == "javascript:void(0);") && (!theLinks[i].onclick))
					theLinks[i].onclick = new Function("stat(); return true;");
			}

			var theAreas = document.getElementsByTagName("area");
			for (var i = 0; i < theAreas.length; i++)
			{
				var theHTML = theAreas[i].innerHTML;

				if (reImage.test(theHTML))
					isImage = 1;

				var newTitle = theAreas[i].innerHTML;
				while (reNbsp.test(newTitle))
					newTitle = newTitle.replace(reNbsp, " ");

				while (reAmp.test(newTitle))
					newTitle = newTitle.replace(reAmp, "&");

				if ((!theAreas[i].onmouseover) && (!theAreas[i].onmouseout))
				{
					if (theAreas[i].title)
						theAreas[i].onmouseover = new Function("stat(this.title); return true;");
					else
						theAreas[i].onmouseover = new Function("stat(this.innerHTML); return true;");
					theAreas[i].onmouseout = new Function("stat(); return true;");
				}

				if (!theAreas[i].title)
					theAreas[i].title = "";

				if (!theAreas[i].onfocus)
					theAreas[i].onfocus = new Function("if (this.blur) this.blur();");

				if ((theAreas[i].href == "javascript:void(0);") && (!theAreas[i].onclick))
					theAreas[i].onclick = new Function("stat(); return true;");
			}
		}
	}
}

function disableTooltips()
{
	if (document.getElementById)
	{
		var theLinks = document.getElementsByTagName('a');
		var theAreas = document.getElementsByTagName('area');
		
		for (var i = 0; i < theLinks.length; i++)
			theLinks[i].title = "";
		
		for (var i = 0; i < theAreas.length; i++)
			theAreas[i].title = "";
	}
}




// This function loops through all the tags with the name
// that is specified by the container argument.
// ie: to change all fonts in <TD> tags:
//     setFonts("Verdana, Arial, sans-serif", "12pt", "td", "medium");
//
// The fontWeight argument is optional.
function setFonts(fontFamilyName, fontSize, container, fontWeight)
{
	if (document.getElementById)
	{
		var theContainers = document.getElementsByTagName(container);
		for (var i = 0; i < theContainers.length; i++)
		{
			theContainers[i].style.fontFamily = fontFamilyName;
			theContainers[i].style.fontSize = fontSize;
			if (fontWeight)
				theContainers[i].style.fontWeight = fontWeight;
		}
	}
}

function cacheImages()
{
	if (document.getElementById)
	{
		var theImages = document.getElementsByTagName("img");
		var theImgNames = new Array();

		for (var k = 0; k < theImages.length; k++)
		{
			theImgNames[k] = new Image();
			theImgNames[k].src = theImages[k].src;
		}
	}
}



// This function converts a string value into US currency format.
// This function was found at http://javascript.internet.com and
// has been slightly modified. ("formatCurrency(num)")
function convertToCurrency(stringValue)
{
   stringValue = stringValue.toString().replace(/\$|\,/g,'');

   if (isNaN(stringValue))
      stringValue = "0";
   var sign = (stringValue == (stringValue = Math.abs(stringValue)));
   stringValue = Math.floor(stringValue * 100 + 0.50000000001);
   var cents = stringValue % 100;
   stringValue = Math.floor(stringValue / 100).toString();

   if (cents < 10)
      cents = "0" + cents;

   for (var i = 0; i < Math.floor((stringValue.length - (1 + i)) / 3); i++)
      stringValue = stringValue.substring(0, stringValue.length - (4 * i + 3)) + ',' + stringValue.substring(stringValue.length - (4 * i + 3));
   return (((sign) ? '' : '-') + '$' + stringValue + '.' + cents);
}

// This function gets a string from an element and converts the value
// into US currency. If the input value is not a number, the returned
// value is "$0.00". Uses the function convertToCurrency().
function formatCurrency(elementName, formName)
{
	if (!formName)
		var formName = 0;

	var re = /\w/;
	var theNumber = getElement(elementName, formName);
	if (re.test(theNumber))
	{
		theNumber = convertToCurrency(theNumber);
		setElement(elementName, theNumber, formName);
	}
}

// This function calculates the total price from price values stored
// in form elements.
// ASSUMPTIONS: Each element that should be calculated must have its
// name listed into an Array. The name of this array must be passed
// to this function.
// If the outputElement is not given, this function will attempt to send
// the output (the total price) to a form element with the name "totalPrice".
//
// This function is most useful when called from each element's onChange event.
// The output price is formated as US currency (using convertToCurrency())
function updateTotalPrice(elementArrayName, outputElement, formName)
{
	if (elementArrayName && outputElement)
	{
		if (!formName)
			var formName = 0;

		if (!outputElement)
			var outputElement = "totalPrice";

		var formElementIntegrity = new Boolean(true);

		var thePrices = new Array();
		var reDollarSign = /\$/;
		var reNonNumber = /\D/;

		// put values into an array of prices
		for (var i = 0; i < elementArrayName.length; i++)
		{
			var tmp = getElement(elementArrayName[i], formName);
			tmp = tmp.replace(reDollarSign, "");

			thePrices[i] = parseFloat(tmp.toString(tmp));
		}

		// all form elements from the array exist, so now calculate the prices
		if (formElementIntegrity)
		{
			var theTotal = 0;

			for (var i = 0; i < thePrices.length; i++)
			{
				if (!isNaN(thePrices[i]))
					theTotal += thePrices[i];
			}
			theTotal = convertToCurrency(theTotal);
			setElement(outputElement, theTotal, formName);
		}
	}
}










/******************************************************************
*	Script name: Link fader (http://design64.net/js/linkfader.html)
*	Version: 1.0
*	Date: 12.05.02
*	Usage: Freeware - You may modify this script as you wish,
*		as long as you don't remove this header comment.
*
*	Script by: Fayez Zaheer (viol8r on #webdesign [irc.zanet.org.za])
*	Email: fayez@design64.net
*	Web site: http://design64.net
* 	Original idea: http://anarchos.xs.mw/fade.phtml
******************************************************************/
// This script will not overwrite current onmouseover and
// onmouseout attributes - it will instead skip those links. If you would
// still like to fade them, add findLink(this.id) to your onmouseover
// and clearFade() to your onmouseout, like so -
// <a href="#" onmouseover="findLink(this.id); yourFunction()"
// onmouseout="clearFade(); yourSecondFunction()">
// Make sure to put it BEFORE any "return" statements otherwise
// the fade will not execute.

// Fade-to colour without the # (6 character value only!)
var fadeTo = "FF6600";

// Fade in colour increment/decrement by
var fiBy = 6;

// Fade out colour increment/decrement by
var foBy = 10;

// Speed - milliseconds between each colour change in the fade
// Less than 10ms doesn't really make all that much difference, so
// 10 is the minimum effective value.
var speed = 10;

// Class name of links to NOT fade (i.e. ignore)
// var ignoreClass = "somebogusvalue" if you don't want to
// use this feature. Alternatively, add onmouseover="clearFade()"
// to the link you do not wish to fade.
var ignoreClass = "ignore";


var opera, ie, dom, x = 0, oc, fader, ocs = new Array();

if (navigator.userAgent.indexOf("Opera") != -1)
	opera = true;
else if (document.all && !opera)
	ie = true;
else if (!document.all && document.getElementById)
	dom = true;

function convertRGB(z)
{
	var newfcS = "", splitter = "";
	splitter = z.split(",");
	splitter[0] = parseInt(splitter[0].substring(4, splitter[0].length));
	splitter[1] = parseInt(splitter[1]);
	splitter[2] = parseInt(splitter[2].substring(0, splitter[2].length-1));
	
	for (var q = 0; q < 3; q++)
	{
		splitter[q] = splitter[q].toString(16);
		if (splitter[q].length == 1) splitter[q] = "0" + splitter[q];
		newfcS += splitter[q];
	}
	
	return newfcS;
}

function currentColour(index)
{
	var temp, cc;
	if (opera)
		cc = document.links[index].style.color;
	else if (ie)
		cc = document.links[index].currentStyle.color;
	else if (dom)
		cc = document.defaultView.getComputedStyle(document.links[index], '').getPropertyValue("color");
	
	if (cc.length == 4 && cc.substring(0, 1) == "#")
	{
		temp = "";
		for (var a = 0; a < 3; a++)
			temp += cc.substring(a+1, a+2) + cc.substring(a+1, a+2);
		cc = temp;
	}
	else if (cc.indexOf("rgb") != -1)
		cc = convertRGB(cc)
	else if (cc.length == 7)
		cc = cc.substring(1, 7)
	else
		cc = fadeTo;
	
	return cc;
}

function convert2Dec(hex)
{	
	var rgb = new Array();
	for (var u = 0; u < 3; u++)
		rgb[u] = parseInt(hex.substring(u*2, u*2+2), 16);
	return rgb;
}

function newRGB(f, n, d)
{
	var change;
	if (d == 1)
		change = fiBy
	else
		change = foBy;
	for (var g = 0; g < 3; g++)
	{
		if (n[g] > f[g] && n[g] - change >= 0) n[g] -= change;
		if (n[g] < f[g] && n[g] + change <= 255) n[g] += change;
	}
	return n;
}

function fade(index, d)
{
	var fc, nc, temp = new Array(), finished = false;
	nc = convert2Dec(currentColour(index));
	
	if (d == 1)
		fc = convert2Dec(fadeTo)
	else
		fc = convert2Dec(ocs[x]);
	
	temp = convert2Dec(currentColour(index));
	nc = newRGB(fc, nc, d);
	
	if ((nc[0] == temp[0]) && (nc[1] == temp[1]) && (nc[2] == temp[2]))
		finished = true;
	
	if (!finished)
		document.links[x].style.color = "rgb(" + nc[0] + "," + nc[1] + "," + nc[2] + ")";
	else
		clearInterval(fader);
}

function findLink(over)
{
	if (document.layers)
		return;
	if (fader)
	{
		clearInterval(fader);
		document.links[x].style.color = "#" + ocs[x];
	}
	
	if (over && !this.id) this.id = over;
	x = 0;
	
	while (!(this.id == document.links[x].id) && (x < document.links.length))
		x++;
	
	if (this.id == document.links[x].id)
	{
		oc = currentColour(x);
		fader = setInterval("fade(" + x  + ", 1)", speed);
	}
}

function clearFade()
	{
		if (document.layers)
			return;
		if (fader)
			clearInterval(fader);
		fader = setInterval("fade(" + x + ", 0)", speed);
	}

function faderInit()
{
	for (var i = 0; i < document.links.length; i++)
	{
		ocs[i] = currentColour(i);
		var currentOver = document.links[i].onmouseover;
		var currentOut = document.links[i].onmouseout;
		var ignoreIt = document.links[i].className == ignoreClass;
		if (!ignoreIt)
			document.links[i].id = "link" + i;
		if (!currentOver && !currentOut && !ignoreIt)
		{
			document.links[i].onmouseover = findLink;
			document.links[i].onmouseout = clearFade;
		}
	}		
}



// this function minimizes a window to an appropriate size (not a complete minimize)
function minimize()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		
		var minWidth = screen.width / 2;			// set width to half the screen size
		var minHeight = screen.height / 2;		// set height to half the screen size
		window.resizeTo(minWidth, minHeight);	// resize it
	}
	else
	{
		window.innerWidth = 100;					// set page (not browser window) to 100
		window.innerHeight = 100;					// 
		window.screenX = screen.width;			
		window.screenY = screen.height;
		alwaysLowered = true;
	}
}

// this function maximizes a window to an appropriate size (not a complete maximize)
function maximize() 
{
	
	if (document.getElementById)
	{
		var maxWidth = screen.width - 10;		// set width so that there is 10px space on right
		var maxHeight = screen.height - 20;		// set height so there is room below (ie: win taskbar)
		window.resizeTo(maxWidth, maxHeight);	// resize it
		window.moveTo(0,0);							// move it to the top left corner
	}
	else
	{
		var maxWidth = screen.width - 30;
		var maxHeight = screen.height - 100;
		window.innerWidth = maxWidth;
		window.innerHeight = maxHeight;
		window.screenX = 0;
		window.screenY = 0;
		alwaysLowered = false;
	}
}



/////////////////////////////////////////////////// COOKIE FUNCTIONS //////////////////////////////////////////

// function that sets a cookie named [cookieName]
// takes two arguments; the name of the cookie and the expiration date in DAYS
function setCookie(cookieName, someValue, numberOfDays)
{
	if ((!someValue) || (someValue == ""))
		deleteCookie(cookieName);						// if value of cookie is null or "", delete the cookie (make sure it doesn't exist)
	else
	{
		if (document.cookie != document.cookie)
			index = document.cookie.indexOf(cookieName);
		else
			index = -1;

		if (index == -1)
		{
			var expirationDate = new Date();

			if (!numberOfDays)		// if numberOfDays was not specified, set to 1 year (365)
				expirationDate.setTime(expirationDate.getTime() + (365 * 24 * 60 * 60 * 1000));
			else
				expirationDate.setTime(expirationDate.getTime() + (numberOfDays * 24 * 60 * 60 * 1000));

			document.cookie = cookieName + "=" + someValue + "; expires=" + expirationDate.toGMTString();;
		}
	} // if (!someValue) || (some...
}

// function that gets a cookie named [cookieName]
function getCookie(cookieName)
{
	var arg = cookieName + "=";
	var argLength = arg.length;
	var cookieLength = document.cookie.length;
	var i = 0;

	while (i < cookieLength)
	{
		var j = i + argLength;

		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0)
			break;
	}

	return null;
}

// function used by getCookie(cookieName) to actually get the cookie data
function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);

	if (endstr == -1)
		endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}

// function that deletes a cookie named [cookieName]
function deleteCookie(cookieName)
{
	var expirationDate = new Date();
	expirationDate.setTime(expirationDate.getTime() - 1);		// set the expiration date to yesterday
	var cookieValue = getCookie(cookieName);						// get the cookie data
	document.cookie = cookieName + "=" + cookieValue + "; expires=" + expirationDate.toGMTString();	// expire the new cookie
}

// function that returns true or false
function isCookie(cookieName)
{
	if (getCookie(cookieName))
		return 1;
	else
		return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////



// This function is useful with the onKeyPress event handler
function getkey(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

// this function should be called from an input field like this:
//			<input type="text" onKeyPress="return restrictInput(event, '0123456789');">
//
//		That example only allows integers to be typed in the input field.
function restrictInput(e, validCharacters)
{
	var key, keychar;
	key = getkey(e);

	if (key == null)
		return true;

	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validCharacters = validCharacters.toLowerCase();

	// check valid characters
	if (validCharacters.indexOf(keychar) != -1)
		return true;

	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;

	// else return false
	return false;
}

function preventInput(e, invalidCharacters, quotes)
{
	var key, keychar;
	key = getkey(e);

	if (key == null)
		return true;

	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	invalidCharacters = invalidCharacters.toLowerCase();
	
	if (quotes)
	{
		if (quotes == "double")
			invalidCharacters += '"';
		if (quotes == "single")
			invalidCharacters += "'";
		if (quotes == "all")
		{
			invalidCharacters += '"';
			invalidCharacters += "'";
		}
	}
		
	// check valid characters
	if (invalidCharacters.indexOf(keychar) != -1)
		return false;

	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;

	// else return false
	return true;
	
}

function preventQuotes(e, andSingle)
{
	var key, keychar;
	key = getkey(e);
	
	var invalidCharacters = '"';
	
	if (andSingle)
		invalidCharacters += "'";
	
	if (key == null)
		return true;

	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	invalidCharacters = invalidCharacters.toLowerCase();

	// check valid characters
	if (invalidCharacters.indexOf(keychar) != -1)
		return false;

	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;

	// else return false
	return true;
	
}



/*	############## Originally from: http://www.nsftools.com/misc/SearchAndHighlight.htm
 * ############## Modified by Alex Garcia, 2004
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, startingTag, closingTag)
{


	if (document.getElementById)
	{
		if ((!startingTag) || (!closingTag))
		{
			var highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
			var highlightEndTag = "</font>";
		}
		else
		{
			var highlightStartTag = startingTag;
			var highlightEndTag = closingTag;
		}

		// find all occurences of the search term in the given text,
		// and add some "highlight" tags to them (we're not using a
		// regular expression search, because we want to filter out
		// matches that occur within HTML tags and script blocks, so
		// we have to do a little extra validation)

		var newText = "";
		var i = -1;
		var theSearchTerm = searchTerm.toLowerCase();
		var theBodyText = bodyText.toLowerCase();

		while (bodyText.length > 0)
		{
			i = theBodyText.indexOf(theSearchTerm, i+1);

			if (i < 0)
			{
				newText += bodyText;
				bodyText = "";
			}
			else
			{
				// skip anything inside an HTML tag
				if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i))
				{
					// skip anything inside a <script> block
					if (theBodyText.lastIndexOf("/script>", i) >= theBodyText.lastIndexOf("<script", i))
					{
						newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
						bodyText = bodyText.substr(i + searchTerm.length);
						theBodyText = bodyText.toLowerCase();
						i = -1;
					}
				}
			}
		}
		return newText;
	} // if document.getElementById
}


/*	############## Originally from: http://www.nsftools.com/misc/SearchAndHighlight.htm
 * ############## Modified by Alex Garcia, 2004
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function hilightSearchTerms(searchText, startingTag, closingTag)
{
	highlightSearchTerms(searchText, startingTag, closingTag);
}

function highlightSearchTerms(searchText, startingTag, closingTag)
{
	if (document.getElementById)
	{
		// if the treatAsPhrase parameter is true, then we should search for
		// the entire phrase that was entered; otherwise, we will split the
		// search string so that each word is searched for and highlighted
		// individually

		searchArray = searchText.split(" ");
		
		if ((!startingTag) || (!closingTag))
		{
			var highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
			var highlightEndTag = "</font>";
		}
		else
		{
			var highlightStartTag = startingTag;
			var highlightEndTag = closingTag;
		}

		if (!document.body || typeof(document.body.innerHTML) == "undefined")
		{
			return false;
		}

		var bodyText = document.body.innerHTML;
		for (var i = 0; i < searchArray.length; i++)
		{
			bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
		}

		document.body.innerHTML = bodyText;
		return true;

	} // if document.getElementById
}

function keystrokeCopy(theValue, elementOneID, elementTwoID, elementThreeID)
{
	if (document.getElementById)
	{
		var re = /\w/;
		if ((theValue) && re.test(elementOneID))
		{
			if (elementThreeID && document.getElementById(elementThreeID)) document.getElementById(elementThreeID).value = theValue;
			if (elementTwoID && document.getElementById(elementTwoID)) document.getElementById(elementTwoID).value = theValue;
			document.getElementById(elementOneID).value = theValue;
		}
	}
}

function onchangeCopy(theValue, elementOneID, elementTwoID, elementThreeID)
{
	if (document.getElementById)
	{
		var re = /\w/;
		if ((theValue) && re.test(elementOneID))
		{
			if (elementThreeID && document.getElementById(elementThreeID)) document.getElementById(elementThreeID).value = theValue;
			if (elementTwoID && document.getElementById(elementTwoID)) document.getElementById(elementTwoID).value = theValue;
			document.getElementById(elementOneID).value = theValue;
		}
	}
}

function stat(theText)
{
	void(0);
}

//]]>
