/**********************************************************************************
***********************************************************************************
******************************** HELPER FUNCTIONS *********************************
***********************************************************************************
**********************************************************************************/

/*====================================================================================================================================================
|                                                                                                                                                    |
|   WW  WW  WW  IIIIII  NN    NN  DDDDD     OOOOO   WW  WW  WW       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   WW  WW  WW    II    NNN   NN  DD   DD  OO   OO  WW  WW  WW       FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   WW  WW  WW    II    NN NN NN  DD   DD  OO   OO  WW  WW  WW       FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|    WWWWWWWW     II    NN   NNN  DD   DD  OO   OO   WWWWWWWW        FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|     WW  WW    IIIIII  NN    NN  DDDDD     OOOOO     WW  WW         FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                    |
====================================================================================================================================================*/
	// Allows you to programatically add a function to the onload procedure without overwriting that current onload
	var onLoadCount = (window.onload) ? 1 : 0;
	function addToWindowOnLoad(codeToAdd)
		{
		if (!(window.onload))
			{ window.onload = new Function("",codeToAdd); }
		else
			{
			eval("onLoadFunction"+onLoadCount+" = window.onload;");
			window.onload = new Function("","onLoadFunction"+onLoadCount+"(); "+codeToAdd);
			onLoadCount++;
			}
		}
		
	// Allows you to programatically add a function to the onunload procedure without overwriting that current onload
	var onUnLoadCount = (window.onunload) ? 1 : 0;
	function addToWindowOnUnLoad(codeToAdd)
		{
		if (!(window.onunload))
			{ window.onunload = new Function("",codeToAdd); }
		else
			{
			eval("onUnLoadFunction"+onUnLoadCount+" = window.onunload;");
			window.onunload = new Function("","onUnLoadFunction"+onUnLoadCount+"(); "+codeToAdd);
			onUnLoadCount++;
			}
		}
	
	// Get the styleSheet from the current page
	function getStyleSheet()
		{
		var linkObj;
		for(var linkIndex=0; (linkObj = document.getElementsByTagName("link")[linkIndex]); linkIndex++)
			{
			if ((linkObj.getAttribute("rel").indexOf("style")!= -1) && (linkObj.getAttribute("href")))
				{ return linkObj.getAttribute("href"); }
			}
		// If we didn't find one, send back nothing
		return "";
		}
	
	// Resizes a top frame with ID topFrameset, to the height of a table with an ID of containerTable
	var infiniteLoopCounter = 0;
	function resizeTopFrameToTable()
		{
		var minFrameHeight = 75;
		
		var containerTable = document.getElementById('containerTable');
		var topFrameset = top.document.getElementById('topFrameset');
		
		if (containerTable == null) { window.status = "resizeTopFrameToTable(): containerTable not defined"; return void(0); }
		if (topFrameset == null) { window.status = "resizeTopFrameToTable(): topFrameset not defined"; return void(0); }
		
		if (containerTable.clientHeight > 0)
			{
			var newHeight = (containerTable.clientHeight+2);
			if (newHeight < minFrameHeight)
				{ newHeight = minFrameHeight; }
			
			if (topFrameset.rows != newHeight + ",*")
				{ topFrameset.rows = newHeight + ",*"; }
			}
		else if (infiniteLoopCounter++ < 50)
			{ self.setTimeout("resizeTopFrameToTable()", 50); }
		}

/*===============================================================================================================================================
|                                                                                                                                               |
|   PPPPPP   RRRRRR    OOOOO   MM     MM  PPPPPP   TTTTTT       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   PP   PP  RR   RR  OO   OO  MMM   MMM  PP   PP    TT         FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   PPPPP    RRRRR    OO   OO  MM MMM MM  PPPPP      TT         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   PP       RR  RR   OO   OO  MM  M  MM  PP         TT         FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   PP       RR   RR   OOOOO   MM     MM  PP         TT         FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                               |
===============================================================================================================================================*/
	function centeredPopup(windowURL,windowName,windowWidth,windowHeight,windowProperties)
		{
		if (windowProperties == null) { windowProperties = "status,outerHeight=5,innerHeight=5,innerWidth=5,outerWidth=5,resizable=yes"; }
		if (windowWidth == null) { windowWidth = 450; } // width of the new window
		if (windowHeight == null) {  windowHeight = 150; } // height of the new window
	    windowLeft = (screen.width / 2) - (windowWidth / 2); // center the window right to left
	    windowTop = (screen.height / 2) - (windowHeight / 2); // center the window top to bottom
		
		// Do some handling for Netscape
		var heightAttribute = (navigator.appName == 'Netscape') ? "outerHeight" : "height";
		var widthAttribute = (navigator.appName == 'Netscape') ? "outerWidth" : "width";
		if (navigator.appName == 'Netscape') { windowHeight += 75; }
		
		// the values get inserted into the features parameter of the window.open command...
		var windowPosition = "top=" + windowTop + ",left=" + windowLeft + "," + heightAttribute + "=" + windowHeight + "," + widthAttribute + "=" + windowWidth;
		windowProperties = listAppend(windowProperties,windowPosition);
		
		return window.open(windowURL,windowName,windowProperties);
		}
	
	function promptPopup(messageToPrompt,promptValue,functionToCall,windowWidth,windowHeight,inputType,inputAttributes,buttonList)
		{
		if (inputType == null) { inputType = "text"; }
		if (inputAttributes == null) { inputAttributes = ((listFindNoCase("text,hidden",inputType) >= 0) ? '' : 'rows="3" cols="55"'); }
		if (buttonList == null) { buttonList = "OK,Cancel"; }

		promptPopupWindow = centeredPopup("","promptPopupWindow",windowWidth,windowHeight,null);
		
		promptPopupWindow.document.write('<ht'+'ml>\n<he'+'ad><link rel="stylesheet" href="' + getStyleSheet() + '" type="text/css"><title>' + stripHTML(messageToPrompt) + '</title></he'+'ad>');
		promptPopupWindow.document.write('\n<bo'+'dy>\n<div align="center"><form name="promptForm" onsubmit="return false;">');
		
		promptPopupWindow.document.write('\n<table cellspacing="1" cellpadding="1" border="0" width="100%" class="small">');
		promptPopupWindow.document.write('\n	<tr><td align="center" class="smallbold">' + messageToPrompt + '</td></tr><tr><td height="5"></td></tr>');
		promptPopupWindow.document.write('\n	<tr><td align="center"><table width="85%">');
		if (listFindNoCase("text,hidden",inputType) >= 0)
			{ promptPopupWindow.document.write('\n	<tr><td align="center"><input type="' + inputType + '" name="promptValue" value="' + promptValue + '" ' + inputAttributes + ' class="small"></td></tr>'); }
		else if (inputType == "textarea")
			{ promptPopupWindow.document.write('\n	<tr><td align="center"><textarea name="promptValue" class="small" ' + inputAttributes + '>' + promptValue + '</textarea></td></tr>'); }
		promptPopupWindow.document.write('\n	</table></td></tr><tr><td height="' + ((inputType == "text") ? 8 : 1) + '"></td></tr><tr><td align="center">');
		
		// Loop through the buttons and output
		for (var buttonIndex=0; buttonIndex<buttonList.split(",").length; buttonIndex++)
			{
			var buttonValue = buttonList.split(",")[buttonIndex];
			if (listFindNoCase("Close,Cancel",buttonValue) >= 0)
				{ promptPopupWindow.document.write('\n		<input type="button" value="' + buttonValue + '" class="styleButton" onclick="{ window.close(); } ">'); }
			else
				{ promptPopupWindow.document.write('\n		<input type="button" value="' + buttonValue + '" class="styleButton" onclick="with(window.opener){' + functionToCall + '}">'); }
			}
		promptPopupWindow.document.write('\n	</td></tr>');
		promptPopupWindow.document.write('\n</table>');
	
		promptPopupWindow.document.write('\n</form></div></bo'+'dy>\n</ht'+'ml>');
		promptPopupWindow.document.close();
		}
		
	function messagePopup(messageToShow,windowTitle,windowWidth,windowHeight)
		{
		if (windowTitle == null) { windowTitle = "Information"; } // width of the new window
		
		var windowProperties = "status,outerHeight=3,innerHeight=3,innerWidth=3,outerWidth=3,resizable=yes";
		promptPopupWindow = centeredPopup("","promptPopupWindow",windowWidth,windowHeight,windowProperties);
		
		promptPopupWindow.document.write('<ht'+'ml>\n<he'+'ad><link rel="stylesheet" href="' + getStyleSheet() + '" type="text/css"><title>' + stripHTML(windowTitle) + '</title></he'+'ad>');
		promptPopupWindow.document.write('\n<bo'+'dy>\n<div align="center">');
		
		promptPopupWindow.document.write('\n<table cellspacing="1" cellpadding="1" border="0" width="100%" class="small">');
		promptPopupWindow.document.write('\n	<tr><td>' + messageToShow + '</td></tr><tr><td height="5"></td></tr>');
		promptPopupWindow.document.write('\n	<tr><td align="center"><table width="85%">');
		promptPopupWindow.document.write('\n	</table></td></tr><tr><td height="8"></td></tr><tr><td align="center">');
		promptPopupWindow.document.write('\n		<input type="button" value="Close" class="styleButton" onclick="{ window.close(); } ">');
		promptPopupWindow.document.write('\n	</td></tr>');
		promptPopupWindow.document.write('\n</table>');
	
		promptPopupWindow.document.write('\n</form></div></bo'+'dy>\n</ht'+'ml>');
		promptPopupWindow.document.close();
		}

/*=================================================================================================================
|                                                                                                                 |
|   UU  UU  RRRRRR   LL           FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   UU  UU  RR   RR  LL           FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   UU  UU  RRRRR    LL           FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   UU  UU  RR  RR   LL           FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|    UUUU   RR   RR  LLLLLL       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                 |
=================================================================================================================*/
	// *******************************************************************
	// ** Adds a query variable to a URL and returns it. If the variable
	// ** is already in the URL, it replaces the value with the one supplied
	// *******************************************************************
	function addToURL(PageUrl,VarName,VarValue)
		{
		// Set new VarString to add to URL
		var new_VarString = VarName + "=" + VarValue;
		
		// First, check if it's already in the string
		if(PageUrl.indexOf(VarName) >= 0)
			{
			// If so, get start and end of the VarName
			VarValueStart = PageUrl.indexOf(VarName);
			VarValueEnd = PageUrl.indexOf("&",VarValueStart+1);
			
			// if a "&" was not found after the orderBy url variable, 
			// then end point should be the last character of the string
			if (VarValueEnd < 0) {VarValueEnd = PageUrl.length}
			
			// Get the old URL variable
			var old_VarString = PageUrl.substring(VarValueStart,VarValueEnd);
			
			// Replace the old VarName with the new one
			PageUrl = PageUrl.replace(old_VarString,new_VarString);
			}
		
		// The variable isn't already in the URL, so add it
		else
			{
			// If there's no "?" in the string, add one and the VarName=VarValue
			if(PageUrl.indexOf("?") < 0)
				{ PageUrl = PageUrl + "?" + new_VarString; }
			
			// Else, if there is a "?" and it's the last element in the string, add VarName=VarValue
			else if(PageUrl.indexOf("?") == PageUrl.length)
				{ PageUrl = PageUrl + new_VarString; }
				
			// Else, if there is a "?" and it's not the last element in the string, add &VarName=VarValue
			else if(PageUrl.indexOf("?") != PageUrl.length)
				{ PageUrl = PageUrl + "&" + new_VarString; }
			}
		
		return PageUrl;
		}
	
	function openWindow(theURL,winName,features) 
		{ window.open(theURL,winName,features); }
	
/*=========================================================================================================================================================================
|                                                                                                                                                                         |
|   MM     MM  IIIIII   SSSSS   CCCCC           FFFFFF   OOOOO   RRRRRR   MM     MM       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   MMM   MMM    II    SS      CC               FF      OO   OO  RR   RR  MMM   MMM       FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   MM MMM MM    II     SSSS   CC               FFFF    OO   OO  RRRRR    MM MMM MM       FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   MM  M  MM    II        SS  CC               FF      OO   OO  RR  RR   MM  M  MM       FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   MM     MM  IIIIII  SSSSS    CCCCC  ..       FF       OOOOO   RR   RR  MM     MM       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                         |
=========================================================================================================================================================================*/
	// alerts the supplied message, highlights the field in question, and returns false
	function returnError(message,fieldObj)
		{
		if (message.length > 0) { alert(message); }
		if ((fieldObj != null) && (!fieldObj.disabled) && (fieldObj.focus))
			{ fieldObj.focus(); }
		return false;
		}
		
	function isType(element, what)
		{ return (element.type.toUpperCase() == what.toUpperCase()); }
	
	function flipFlopButtonValues(buttonObj,value1,value2)
		{ buttonObj.value = (buttonObj.value != value1) ? value1 : value2; }
	
	function clickSelectAll(checkboxToSelect,basedOnCheckbox)
		{
		// Determine if there is anything to select
		if ( (typeof(checkboxToSelect) == 'undefined') )
			{ alert("No items available to select"); }
		else
			{ selectAll(checkboxToSelect,basedOnCheckbox.checked); }
		}
		
	function selectAll(formElement,isChecked)
		{
		if ( (formElement != 'undefined') && (typeof(formElement) != 'undefined') )
			{
			if (formElement.length)
				{
				for (var i = 0; i < formElement.length; i++)
					if (isType(formElement[i], "CHECKBOX"))
						{
						formElement[i].checked = isChecked;
						if (formElement[i].onclick) { formElement[i].onclick(); }
						}
				}
			else if (isType(formElement, "CHECKBOX"))
				{
				formElement.checked = isChecked;
				if ((typeof(formElement.onclick) != 'undefined') && (formElement.onclick != null)) { formElement.onclick(); }
				}
			}
		}
		
	// Get the currently selected radio option
	function GetSelectedRadio(RadioToGet)
		{
		if (RadioToGet.length)
			{
			for (RadioIndex=0; RadioIndex<RadioToGet.length; RadioIndex++)
				{
				if (RadioToGet[RadioIndex].checked)
					{ return RadioToGet[RadioIndex]; }
				}
			}
		else if (RadioToGet.checked)
			{ return RadioToGet; }
		
		return false;
		}
	
	// Counts the number of checked checkboxes
	function countChecked(ElementObj)
		{
		var checkedCount = 0;
		
		if (!(ElementObj.length))
			{ checkedCount = (ElementObj.checked) ? 1 : 0; }
		else
			{
			for (var elementCount=0; elementCount<ElementObj.length; elementCount++)
				{
				if (ElementObj[elementCount].checked)
					{ checkedCount++; }
				}
			}
		return checkedCount;
		}

	function getSelectedList(elementObj)
		{
		var SelectedArray = new Array();
		
		// Handle radio and checkbox by getting parent element, and looping through options
		if ( (elementObj.type == "radio") || (elementObj.type == "checkbox") || (typeof(elementObj.type) == 'undefined'))
			{
			if (typeof(elementObj.length) != 'undefined')
				{
				for (var element_index=0; element_index<elementObj.length; element_index++)
					if ( elementObj[element_index].checked )
						{ SelectedArray[SelectedArray.length] = elementObj[element_index].value; }
				}
			else if (elementObj.checked) { SelectedArray[SelectedArray.length] = elementObj.value; }
			}
		// Handle selects by looping through options
		if ( (elementObj.type == "select-one") || (elementObj.type == "select-multiple") )
			{
			for (var option_index=0; option_index<elementObj.options.length; option_index++)
				if ( elementObj.options[option_index].selected && ((option_index > 0) || (elementObj.options[option_index].value != "")) )
					{ SelectedArray[SelectedArray.length] = elementObj.options[option_index].value; }
			}
		// Handle text and hidden by appending the value
		else if ( (elementObj.type == "text") || (elementObj.type == "hidden") || (elementObj.type == "textarea") || (elementObj.type == "password") )
			{
			if (elementObj.value != "")
				{ SelectedArray[SelectedArray.length] = elementObj.value; }
			}
		
		// Return array as a string;
		return (SelectedArray.length) ? SelectedArray.join(",") : "";
		}
		
	function buildQueryString(FormName)
		{
		var queryString = new Array();
		for( var elementIndex=0; elementIndex<FormName.elements.length; elementIndex++)
			{
			var thisElement = FormName.elements[elementIndex];
			var thisValue = getSelectedList(thisElement);
			
			if (thisValue != "")
				{ queryString[queryString.length] = thisElement.name + "=" + thisValue; }
			}
		return queryString.join("&");
		}

	// *******************************************************************
	// ** Allows a user to unCheck a radio element simply by clicking
	// ** the radio again...
	// *******************************************************************
	function checkUncheckRadio(radioObject)
		{
		var FormName = radioObject.form;
		var RadioParentObject = (typeof(radioObject.length) == 'undefined') ? eval("FormName." + radioObject.name) : radioObject;
		
		// If the item that was previously checked is the same object that we are looking at, uncheck it and set the previouslyCheck to undefined
		if (RadioParentObject.getAttribute("previouslyChecked") == radioObject)
			{
			radioObject.checked = false;
			RadioParentObject.previouslyChecked = "undefined";
			}
		// Otherwise, set the previouslyChecked attribute to the current option
		else
			{ RadioParentObject.previouslyChecked = radioObject; }
		}
	
	function checkMaxSelectedCheckboxes(checkboxObj, maxSelections)
		{
		// First, get the parent object, we don't want to deal with just the individual checkbox
		var formName = checkboxObj.form;
		var checkboxObj = (typeof(checkboxObj.length) == 'undefined') ? eval("formName." + checkboxObj.name) : checkboxObj;
		
		// Count the number of checkboxes that the user has selected
		selectedCount = countChecked(checkboxObj);
		
		// Determine if we should doDisable the unselected checkboxes
		doDisable = (selectedCount >= maxSelections);
		
		// Now loop through the checkboxes and set the disabled attribute
		for (var checkboxIndex=0; checkboxIndex<checkboxObj.length; checkboxIndex++)
			{ checkboxObj[checkboxIndex].disabled = (doDisable && (!checkboxObj[checkboxIndex].checked)); }
		}
	
	function enableDisableCheckboxes(checkboxObj,doDisable)
		{
		// First, get the parent object, we don't want to deal with just the individual checkbox
		var formName = checkboxObj.form;
		var checkboxObj = (typeof(checkboxObj.length) == 'undefined') ? eval("formName." + checkboxObj.name) : checkboxObj;
		
		// Now loop through the checkboxes and set the disabled attribute
		for (var checkboxIndex=0; checkboxIndex<checkboxObj.length; checkboxIndex++)
			{ checkboxObj[checkboxIndex].disabled = (doDisable); }
		}
	
	// Enables of disables phone inputs
	function enableDisablePhoneInputs(phoneInputPrefix,selectObj)
		{
		var formName = selectObj.form;
		var phoneObj1 = eval("formName." + phoneInputPrefix + "_1");
		var phoneObj2 = eval("formName." + phoneInputPrefix + "_2");
		var phoneObj3 = eval("formName." + phoneInputPrefix + "_3");
		
		phoneObj1.disabled = (selectObj.value == "");
		phoneObj2.disabled = (selectObj.value == "");
		phoneObj3.disabled = (selectObj.value == "");
		}

/*========================================================================================================================================================================================================
|                                                                                                                                                                                                        |
|   FFFFFF   OOOOO   RRRRRR   MM     MM       MM     MM   OOOOO   DDDDD    IIIIII  FFFFFF  IIIIII  EEEEEE  DDDDD         FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   FF      OO   OO  RR   RR  MMM   MMM       MMM   MMM  OO   OO  DD   DD    II    FF        II    EE      DD   DD       FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   FFFF    OO   OO  RRRRR    MM MMM MM       MM MMM MM  OO   OO  DD   DD    II    FFFF      II    EEEE    DD   DD       FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   FF      OO   OO  RR  RR   MM  M  MM       MM  M  MM  OO   OO  DD   DD    II    FF        II    EE      DD   DD       FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   FF       OOOOO   RR   RR  MM     MM       MM     MM   OOOOO   DDDDD    IIIIII  FF      IIIIII  EEEEEE  DDDDD         FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                                                        |
========================================================================================================================================================================================================*/
	// Determines if an element has been modified by checking it defaultValue against it's current value
	function IsElementModified(ElementObj)
		{
		if ((typeof(ElementObj.type) == 'undefined') && (ElementObj.length))
			{ ElementObj.type = ElementObj[0].type; }
	
		if (typeof(ElementObj.ignoreIsModified) == 'undefined')
			{
			switch(ElementObj.type)
				{
				case "text": case "textarea": case "password":
					return ElementObj.defaultValue != ElementObj.value; break;
				case "checkbox": case "radio":
					if (!(ElementObj.length))
						{ return (ElementObj.checked != ElementObj.defaultChecked); }
					else
						for (var elementCount=0; elementCount<ElementObj.length; elementCount++)
							if (ElementObj[elementCount].checked != ElementObj[elementCount].defaultChecked)
								{ return true; }
					break;
				case "select-one": case "select-multiple":
					// First, we want to find out if there was anything selected by default
					var defaultSelectedOption = -1;
					for (var optionCount=0; optionCount<ElementObj.options.length; optionCount++)
						if (ElementObj.options[optionCount].defaultSelected)
							{ defaultSelectedOption = optionCount; break; }
							
					for (var optionCount=0;  optionCount<ElementObj.options.length; optionCount++)
						if (ElementObj.options[optionCount].selected != ElementObj.options[optionCount].defaultSelected)
							{
							// OK, so we found a record that doesn't match, if we're dealing with blank options and nothing selected, ignore and continue
							if ((ElementObj.type == "select-one") && (defaultSelectedOption <= 0) && (optionCount == 0) && ((ElementObj.selectedIndex == 0) || (ElementObj.selectedIndex == -1)) && (ElementObj.options[optionCount].value == ""))
								{} // If there was nothing selected by default, and they've selected the first blank option, then ignore it
							else { return true; }
							}
					return false;
					break;
				case "file":
					return (ElementObj.value.length > 0); break;
				case "hidden":
					if ( (typeof(ElementObj.checkIsModified) != 'undefined') && (ElementObj.checkIsModified) )
						{ return ElementObj.defaultValue != ElementObj.value; }
					else { return false; }
					break;
				}
			}
		return false;
		}
	
	// Loop through all the elements of a form, checking if any were modified
	function IsFormModified(FormName)
		{
		for (var elementIndex=0; elementIndex<FormName.elements.length; elementIndex++)
			if (IsElementModified(FormName.elements[elementIndex]))
				{ return true; }
		return false;
		}
		
	// Alerts users if a form has been modified, otherwise returns true
	function ConfirmUnSavedChanges(FormName,ConfirmMsg)
		{
		var ConfirmMsg = (ConfirmMsg != null) ? ConfirmMsg : "You have not saved your changes. To continue anyway, click 'OK', all unsaved changes will be lost. \n\nOtherwise, click 'Cancel' to return where you may save your changes.";
		var formHasBeenModified = IsFormModified(FormName);
		return ( !(formHasBeenModified) || (formHasBeenModified && confirm(ConfirmMsg)) )
		}

/*===========================================================================================================================================================================
|                                                                                                                                                                           |
|   FFFFFF   OOOOO   RRRRRR   MM     MM       RRRRRR   EEEEEE   SSSSS  EEEEEE  TTTTTT       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   FF      OO   OO  RR   RR  MMM   MMM       RR   RR  EE      SS      EE        TT         FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   FFFF    OO   OO  RRRRR    MM MMM MM       RRRRR    EEEE     SSSS   EEEE      TT         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   FF      OO   OO  RR  RR   MM  M  MM       RR  RR   EE          SS  EE        TT         FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   FF       OOOOO   RR   RR  MM     MM       RR   RR  EEEEEE  SSSSS   EEEEEE    TT         FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                           |
===========================================================================================================================================================================*/
	// returns form to inital values, or clears completly with clearForm flag
	function resetForm(FormName,clearForm)
		{
		clearForm = (clearForm == 'null') ? false : clearForm;
		for( var elementIndex=0; elementIndex<FormName.elements.length; elementIndex++)
			{
			var thisElement = FormName.elements[elementIndex];
			switch (thisElement.type)
				{
				case "select-one": case "select-multiple":
					thisElement.selectedIndex = -1;
					for (var optionIndex=0; optionIndex<thisElement.options.length; optionIndex++)
						{ thisElement.options[optionIndex].selected = (clearForm) ? false : thisElement.options[optionIndex].defaultSelected; }
					
					// If nothing is selected, and the first option has a blank value, select it
					if ((thisElement.selectedIndex == -1) && (thisElement.options[0].value == ""))
						{ thisElement.options[0].selected = true; }
					break; break;
					
				case "text": case "password": case "textarea":
					thisElement.value = (clearForm) ? "" : thisElement.defaultValue;
					break; break; break;
					
				case "radio": case "checkbox":
					thisElement.checked = (clearForm) ? false : thisElement.defaultChecked;
					break; break;
				}
			}
		}
	
	// calls resetForm with clearFlag set
	function clearForm(FormName)
		{ resetForm(FormName,true); }

/*============================================================================================================================================
|                                                                                                                                            |
|    SSSSS  TTTTTT  RRRRRR   IIIIII  NN    NN   GGGGG        FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   SS        TT    RR   RR    II    NNN   NN  GG            FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|    SSSS     TT    RRRRR      II    NN NN NN  GG  GGG       FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|       SS    TT    RR  RR     II    NN   NNN  GG   GG       FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   SSSSS     TT    RR   RR  IIIIII  NN    NN   GGGGG        FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                            |
============================================================================================================================================*/
	// Strips HTML tags from a string
	function stripHTML(StringToStrip)
		{
		var pattern = new RegExp("<[^>]*>","ig");
		return StringToStrip.replace(pattern,"");
		}
	
	function stripLeadingZeros(StringToStrip)
		{
		// Loop through and remove the first character if it's a zero
		while (StringToStrip.substring(0,1) == "0")
			{ StringToStrip = StringToStrip.substring(1,StringToStrip.length); }
			
		return StringToStrip;
		}
		
	// Trims a string
	function trim(s) 
		{
		// Remove leading spaces and carriage returns
		while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
			{ s = s.substring(1,s.length); }
		
		// Remove trailing spaces and carriage returns
		while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
			{  s = s.substring(0,s.length-1); }
			
		return s;
		}
	
	function isNull(stringtoCheckForNull,stringToReturnIfNull)
		{ return ((stringtoCheckForNull == "") || (stringtoCheckForNull == null)) ? stringToReturnIfNull : stringtoCheckForNull; }
	
	function left(string, count)
		{
		if (count <= 0)
			{ return ""; }
		else if (string.length <= count)
			{ return string; }
		else
			{ return string.substr(0,count); }
		}
	
	function right(string, count)
		{
		if (count <= 0)
			{ return ""; }
		else if (string.length <= count)
			{ return string; }
		else
			{ return string.substr((string.length-count),count); }
		}
	
/*========================================================================================================================================================================
|                                                                                                                                                                        |
|   MM     MM   AAAA   XX   XX  LL      EEEEEE  NN    NN   GGGGG   TTTTTT  HH   HH       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   MMM   MMM  AA  AA   XX XX   LL      EE      NNN   NN  GG         TT    HH   HH       FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   MM MMM MM  AAAAAA    XXX    LL      EEEE    NN NN NN  GG  GGG    TT    HHHHHHH       FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   MM  M  MM  AA  AA   XX XX   LL      EE      NN   NNN  GG   GG    TT    HH   HH       FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   MM     MM  AA  AA  XX   XX  LLLLLL  EEEEEE  NN    NN   GGGGG     TT    HH   HH       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                        |
========================================================================================================================================================================*/
	// Displays the current length of the input along with the maxlength if it can be determined
	function showMaxLengthStatus(InputName)
		{
		if ( (typeof(InputName.getAttribute) != 'undefined') && (InputName.getAttribute("maxlength") > 0) )
			{
			window.status = InputName.value.length + "/" + InputName.getAttribute("maxlength") + " characters";
			checkMaxLength(InputName);
			}
		else
			{ window.status = InputName.value.length + " characters"; }
		}
	
	// Compares the length of a string against it's maxlength
	function checkMaxLength(InputName)
		{
		if ( (typeof(InputName.getAttribute) != 'undefined') && (InputName.getAttribute("maxlength") > 0) && (InputName.value.length > InputName.getAttribute("maxlength")) )
			{
			InputName.value = InputName.value.substring(0,InputName.getAttribute("maxlength"));
			showMaxLengthStatus(InputName);
			window.status = window.status + "  Maximum field length reached";
			}
		}
	
	// Crops a string at a defined length and appends a filler to the end if supplied
	function MaxStringLen(thisString,desiredLength,stringFiller)
		{
		if (stringFiller == null) { stringFiller = "..."; }
		return (thisString.length <= desiredLength) ? thisString : thisString.substr(0,desiredLength-2) + stringFiller;
		}
		
/*==========================================================================================================================================================================
|                                                                                                                                                                          |
|    AAAA   RRRRRR   RRRRRR    AAAA   YY  YY      //  LL      IIIIII   SSSSS  TTTTTT       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   AA  AA  RR   RR  RR   RR  AA  AA   Y  Y      //   LL        II    SS        TT         FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   AAAAAA  RRRRR    RRRRR    AAAAAA    YY      //    LL        II     SSSS     TT         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   AA  AA  RR  RR   RR  RR   AA  AA    YY     //     LL        II        SS    TT         FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   AA  AA  RR   RR  RR   RR  AA  AA    YY    //      LLLLLL  IIIIII  SSSSS     TT         FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                          |
==========================================================================================================================================================================*/
	// If an item exists in a list remove it, otherwise add it
	function toggleListItem(listToLookThrough,itemToToggle)
		{
		var foundIndex = -1;
		var arrayToLookThrough = (listToLookThrough+"").split(",");
		for (var listIndex = 0; listIndex < arrayToLookThrough.length; listIndex++)
			if (arrayToLookThrough[listIndex] == itemToToggle)
				{ foundIndex = listIndex; break; }
		
		// If we didn't find it, then add it to the list
		if (foundIndex == -1)
			{ arrayToLookThrough[arrayToLookThrough.length] = itemToToggle; }
		// If we did find it, remove it from the array
		else
			{ arrayToLookThrough = arrayDeleteAt(arrayToLookThrough,foundIndex); }
		
		listToLookThrough = arrayToLookThrough.join(",");
		
		// If the first character is a comma, remove it
		if (listToLookThrough.indexOf(",") == 0)
			{ listToLookThrough = listToLookThrough.substring(1); }
			
		return listToLookThrough;
		}
	
	// Return the index of an item if it is found in the list
	function listFind(listToSeach,valueToSearchFor)
		{ return arrayFind((listToSeach+"").split(","),valueToSearchFor); }
	
	function listFindNoCase(listToSeach,valueToSearchFor)
		{ return listFind(listToSeach.toLowerCase(),valueToSearchFor.toLowerCase()); }
	
	// Return the index of an item if it is found in the array
	function arrayFind(arrayToSearch,valueToSearchFor)
		{
		var foundIndex = -1;
		for (var listIndex = 0; listIndex < arrayToSearch.length; listIndex++)
			{
			if (arrayToSearch[listIndex] == valueToSearchFor)
				{ foundIndex = listIndex; break; }
			}
		return foundIndex;
		}
	
	// Delete an array element at a specified position
	function arrayDeleteAt(arrayToDeleteFrom,indexToDeleteAt)
		{
		switch(indexToDeleteAt)
			{
			case -1:
				return arrayToDeleteFrom;
			case 0:
				return arrayToDeleteFrom.slice(1);
			case arrayToDeleteFrom.length - 1:
				return arrayToDeleteFrom.slice(0, indexToDeleteAt);
			default:
				return arrayToDeleteFrom.slice(0, indexToDeleteAt).concat(arrayToDeleteFrom.slice(indexToDeleteAt + 1));
			}
		}
	
	function listGetAt(list,position,delimiter)
		{
		delimiter = (delimiter == null) ? "," : delimiter;
		return list.split(delimiter)[position];
		}
	
	function listLen(list,delimiter)
		{
		delimiter = (delimiter == null) ? "," : delimiter;
		return (list.length) ? list.split(delimiter).length : 0;
		}
	
	// Delete a list element at a specified position
	function listDeleteAt(listDeleteAt,indexToDeleteAt)
		{ return arrayDeleteAt((listDeleteAt+"").split(","),indexToDeleteAt); }
	
	function listAppend(list,value,delimiter)
		{
		delimiter = (delimiter == null) ? "," : delimiter;
		return (list != "") ? list + delimiter + value : value + "";
		}
	
	function listPrepend(list,value,delimiter)
		{
		delimiter = (delimiter == null) ? "," : delimiter;
		return (list != "") ? value + delimiter + list : value + "";
		}
	
	// Adds an item to the list if it doesn't exist, or moves it to the front if it does
	function addToList(listToAddTo, valueToAdd)
		{
		// List is blank, return value to add
		if (listToAddTo == "")
			{ listToAddTo = valueToAdd; }
			
		// Otherwise, loop through the valueToAdd BACKWARDS and add each item to the list if it doesn't exist, or move it to the front if it does
		else
			{
			valueToAddArray = valueToAdd.split(",");
			
			for (var valueIndex=(valueToAddArray.length-1); valueIndex>=0; valueIndex--)
				{
				valueToAdd = valueToAddArray[valueIndex];
			
				// If it's not in the list, add it to the front
				if (listFind(listToAddTo, valueToAdd) < 0)
					{ listToAddTo = listPrepend(listToAddTo, valueToAdd); }
				// Otherwise, it's already in the list, so remove it, then add it to the front of the list
				else
					{
					listToAddTo = listDeleteAt(listToAddTo,listFind(listToAddTo,valueToAdd));
					listToAddTo = listPrepend(listToAddTo, valueToAdd);
					}
				}
			}
		return listToAddTo;
		}

/*================================================================================================================================================================================
|                                                                                                                                                                                |
|   FFFFFF   OOOOO   RRRRRR   MM     MM   AAAA   TTTTTT  TTTTTT  IIIIII  NN    NN   GGGGG        FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   FF      OO   OO  RR   RR  MMM   MMM  AA  AA    TT      TT      II    NNN   NN  GG            FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   FFFF    OO   OO  RRRRR    MM MMM MM  AAAAAA    TT      TT      II    NN NN NN  GG  GGG       FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   FF      OO   OO  RR  RR   MM  M  MM  AA  AA    TT      TT      II    NN   NNN  GG   GG       FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   FF       OOOOO   RR   RR  MM     MM  AA  AA    TT      TT    IIIIII  NN    NN   GGGGG        FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                                |
================================================================================================================================================================================*/
	function decimalFormat(valueToConvert)
		{
		// Get rid of excess decimal places beyond 2
		valueToConvert = (Math.round(valueToConvert*100)/100) + "";
	
		// If it doesn't already have a decimal point, add one
		if (valueToConvert.indexOf(".") < 0)
			{ valueToConvert = valueToConvert + "" + ".00"; }
	
		// Make sure it still has a 2 digit decimal. If not, strip off the excess zeros
		if (valueToConvert.split(".")[1].length != 2)
			{ valueToConvert = valueToConvert.split(".")[0] + "." + (valueToConvert.split(".")[1] + "00").substr(0,2); }
	
		return valueToConvert;
		}
	
	function floatToMoney(valueToConvert)
		{ return decimalFormat(valueToConvert); }
	
	function moneyToFloat(valueToConvert)
		{ return valueToConvert.replace(/,|\$/gi,""); }
	
/*========================================================================================================================================================================
|                                                                                                                                                                        |
|    SSSSS  HH   HH   OOOOO   WW  WW  WW      //  HH   HH  IIIIII  DDDDD    EEEEEE       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   SS      HH   HH  OO   OO  WW  WW  WW     //   HH   HH    II    DD   DD  EE           FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|    SSSS   HHHHHHH  OO   OO  WW  WW  WW    //    HHHHHHH    II    DD   DD  EEEE         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|       SS  HH   HH  OO   OO   WWWWWWWW    //     HH   HH    II    DD   DD  EE           FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   SSSSS   HH   HH   OOOOO     WW  WW    //      HH   HH  IIIIII  DDDDD    EEEEEE       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                        |
========================================================================================================================================================================*/
	function showObject(objectToShow)
		{ objectToShow.style.display = ''; }
	
	function hideObject(objectToHide)
		{ objectToHide.style.display = 'none'; }
		
	function showHideObject(objectToShowHide)
		{ objectToShowHide.style.display = (objectToShowHide.style.display == '') ? 'none' : ''; }
		
	function setDHTMLBackground(objectToSetTo)
		{
		if (windowToShowWaitMessageIn.document.getElementById('DHTMLBackground') != null)
			{
			backgroundObj = windowToShowWaitMessageIn.document.getElementById('DHTMLBackground');
			
		    backgroundObj.style.width = objectToSetTo.offsetWidth;
		    backgroundObj.style.height = objectToSetTo.offsetHeight;
		    backgroundObj.style.top = objectToSetTo.style.top;
		    backgroundObj.style.left = objectToSetTo.style.left;
		    // backgroundObj.style.zIndex = objectToSetTo.style.zIndex - 1;
		    showObject(backgroundObj);
			}
		}
	
	/* These functions allow us to follow the tooltip with a DHTML background that can show over select boxes */
	var backgroundTimeoutId = "";
	function followTooltipWithBackground()
		{
		setDHTMLBackground(document.getElementById('navtxt'));
		backgroundTimeoutId = setTimeout('followTooltipWithBackground()',10);
		}
	
	function clearTooltipBackground()
		{
		clearTimeout(backgroundTimeoutId);
		hideObject(document.getElementById('DHTMLBackground'));
		}
	
/*=============================================================================================================================================================================================
|                                                                                                                                                                                             |
|   WW  WW  WW   AAAA   IIIIII  TTTTTT       MM     MM  EEEEEE   SSSSS   SSSSS   AAAA    GGGGG   EEEEEE       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   WW  WW  WW  AA  AA    II      TT         MMM   MMM  EE      SS      SS      AA  AA  GG       EE           FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   WW  WW  WW  AAAAAA    II      TT         MM MMM MM  EEEE     SSSS    SSSS   AAAAAA  GG  GGG  EEEE         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|    WWWWWWWW   AA  AA    II      TT         MM  M  MM  EE          SS      SS  AA  AA  GG   GG  EE           FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|     WW  WW    AA  AA  IIIIII    TT         MM     MM  EEEEEE  SSSSS   SSSSS   AA  AA   GGGGG   EEEEEE       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                                             |
=============================================================================================================================================================================================*/
	var windowToShowWaitMessageIn;
	function showWaitMessage(windowToShowIn,messageToShow,offsetLeft,offsetTop)
		{
		// Default to self
		if (windowToShowIn == null) { windowToShowIn = self; }
		windowToShowWaitMessageIn = windowToShowIn;
		
		// Make sure the page is loaded
		if (typeof(windowToShowIn) != 'undefined')
			{
			if (typeof(windowToShowIn.document) != 'undefined')
				{
					
				// If these is something to hide, hide it
				if (windowToShowIn.document.getElementById('pageContentsToHide'))
					{ hideObject(windowToShowIn.document.getElementById('pageContentsToHide')); }
				
				// Scroll to the top of the page so they can see the message
				windowToShowIn.scrollTo(0,0);
				
				// Look for the waitMsg DIV tag
				if (windowToShowIn.document.getElementById('waitMessage'))
					{
					var thisWaitMsg = windowToShowIn.document.getElementById('waitMessage');
					messageToShow = (messageToShow != null) ? messageToShow : "Please Wait While Loading...";
					
					// Default the message to say 'Loading...'
					thisWaitMsg.innerHTML = messageToShow;
					thisWaitMsg.style.width = (messageToShow.length * 9);
					thisWaitMsg.style.left = (offsetLeft != null) ? offsetLeft : 250;
					thisWaitMsg.style.top = (offsetTop != null) ? offsetTop : 175;
					thisWaitMsg.style.padding = "0px; 5px; 0px; 5px;";
					thisWaitMsg.align = "left";
					
					// Hide anything under the DHTML with an iframe
					setDHTMLBackground(thisWaitMsg);
					
					// Make the message visible
					thisWaitMsg.style.zIndex = 100;
					thisWaitMsg.style.visibility = "visible";
					
					// Disable the submit button
					disableSubmitButton(windowToShowIn);
					
					// Cycle the elipses
					cycleWaitMessageElipses();
					}
				}
			}
		}
		
	function cycleWaitMessageElipses()
		{if (typeof(windowToShowWaitMessageIn) != 'undefined')
			if (typeof(windowToShowWaitMessageIn.document) != 'undefined')
				if (windowToShowWaitMessageIn.document.getElementById('waitMessage'))
					if (windowToShowWaitMessageIn.document.getElementById('waitMessage').style.visibility == "visible")
						{
						var waitMsgObj = windowToShowWaitMessageIn.document.getElementById('waitMessage');
						elipseStart = waitMsgObj.innerHTML.search(/([\.]+$|$)/);
						elipseEnd = waitMsgObj.innerHTML.length;
						
						newElipses = ((elipseEnd-elipseStart+1) % 4);
						newMsgText = waitMsgObj.innerHTML.substr(0,elipseStart);
						
						for (var elipseIndex=0; elipseIndex<newElipses; elipseIndex++)
							{ newMsgText += '.'; }
						
						waitMsgObj.innerHTML = newMsgText;
						
						setTimeout('cycleWaitMessageElipses()',250);
						}
		}

/*=============================================================================================================================================================================================================
|                                                                                                                                                                                                             |
|   EEEEEE  NN    NN   AAAA   BBBBBB   LL      EEEEEE      //  DDDDD    IIIIII   SSSSS   AAAA   BBBBBB   LL      EEEEEE       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   EE      NNN   NN  AA  AA  BB   BB  LL      EE         //   DD   DD    II    SS      AA  AA  BB   BB  LL      EE           FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   EEEE    NN NN NN  AAAAAA  BBBBB    LL      EEEE      //    DD   DD    II     SSSS   AAAAAA  BBBBB    LL      EEEE         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   EE      NN   NNN  AA  AA  BB   BB  LL      EE       //     DD   DD    II        SS  AA  AA  BB   BB  LL      EE           FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   EEEEEE  NN    NN  AA  AA  BBBBBB   LLLLLL  EEEEEE  //      DDDDD    IIIIII  SSSSS   AA  AA  BBBBBB   LLLLLL  EEEEEE       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                                                             |
=============================================================================================================================================================================================================*/
	function enableDisableButton(buttonToEnableDisable,enableDisable)
		{
		if (enableDisable == 'disable')
			{
			if (listFindNoCase("styleButtonSelected,styleButtonSmallSelected",buttonToEnableDisable.className) == -1)
				{
				// backup and disable the onclick
				buttonToEnableDisable.defaultOnclick = buttonToEnableDisable.onclick;
				buttonToEnableDisable.onclick = "";
			
				// Change the sytle to styleButtonSelected
				buttonToEnableDisable.className = (buttonToEnableDisable.className == 'styleButton') ? "styleButtonSelected" : "styleButtonSmallSelected";
				}
			}
		else if (typeof(buttonToEnableDisable.defaultOnclick) != 'undefined')
			{
			if (listFindNoCase("styleButton,styleButtonSmall",buttonToEnableDisable.className) == -1)
				{
				buttonToEnableDisable.onclick = buttonToEnableDisable.defaultOnclick;
			
				// Change the sytle to styleButton
				buttonToEnableDisable.className = (buttonToEnableDisable.className == 'styleButtonSelected') ? "styleButton" : "styleButtonSmall";
				}
			}
		
		// Disable the button
		buttonToEnableDisable.disabled = (enableDisable == 'disable');
		buttonToEnableDisable.readonly = (enableDisable == 'disable');
		}
		
	var enable_disable_all_buttons_on_submit = true;
	function disableSubmitButton(windowToShowIn,enableDisable,submitButtonId)
		{
		// Default to self
		if (windowToShowIn == null) { windowToShowIn = self; }
		if (enableDisable == null) { enableDisable = 'disable'; }
		if (submitButtonId == null) { submitButtonId = 'submitButton'; }
		
		if (windowToShowIn.document.getElementById(submitButtonId))
			{
			submitButtonToDisable = windowToShowIn.document.getElementById(submitButtonId);
			enableDisableButton(submitButtonToDisable,enableDisable);
			
			// When the page unload, re-enable everything
			if (enableDisable != 'enable') { addToWindowOnUnLoad("disableSubmitButton(null,'enable','" + submitButtonId + "')") }
			}
		}
	
/*======================================================================================================================================================================================================
|                                                                                                                                                                                                      |
|   NN    NN  EEEEEE  XX   XX  TTTTTT      //  PPPPPP   RRRRRR   EEEEEE  VV  VV  IIIIII   OOOOO   UU  UU   SSSSS       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   NNN   NN  EE       XX XX     TT       //   PP   PP  RR   RR  EE      VV  VV    II    OO   OO  UU  UU  SS           FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   NN NN NN  EEEE      XXX      TT      //    PPPPP    RRRRR    EEEE    VV  VV    II    OO   OO  UU  UU   SSSS        FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   NN   NNN  EE       XX XX     TT     //     PP       RR  RR   EE       VVVV     II    OO   OO  UU  UU      SS       FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   NN    NN  EEEEEE  XX   XX    TT    //      PP       RR   RR  EEEEEE    VV    IIIIII   OOOOO    UUUU   SSSSS        FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                                                      |
======================================================================================================================================================================================================*/
	function showNextPreviousRecords(startRow,FormName)
		{
		FormName = (FormName != null) ? FormName : document.maxRecordsForm;
		if ( typeof(FormName.startRow) != 'undefined')
			{ FormName.startRow.value = startRow; }
		if ( typeof(FormName.STARTROW) != 'undefined')
			{ FormName.STARTROW.value = startRow; }
		showWaitMessage();
		FormName.submit();
		}
	
/*===========================================================================================================
|                                                                                                           |
|   IIIIII  MM     MM   AAAA    GGGGG   EEEEEE       PPPPPP    OOOOO   PPPPPP   UU  UU  PPPPPP    SSSSS     |
|     II    MMM   MMM  AA  AA  GG       EE           PP   PP  OO   OO  PP   PP  UU  UU  PP   PP  SS         |
|     II    MM MMM MM  AAAAAA  GG  GGG  EEEE         PPPPP    OO   OO  PPPPP    UU  UU  PPPPP     SSSS      |
|     II    MM  M  MM  AA  AA  GG   GG  EE           PP       OO   OO  PP       UU  UU  PP           SS     |
|   IIIIII  MM     MM  AA  AA   GGGGG   EEEEEE       PP        OOOOO   PP        UUUU   PP       SSSSS      |
|                                                                                                           |
===========================================================================================================*/
	// Popup a window and put the fullsized image into it
	function showImage(imageObj)
		{
		// If we're sent an image URL, then use it as the imageSRC
		var imageSRC = (typeof(imageObj) == 'object') ? imageObj.src : imageObj;
		
		if (imageSRC.indexOf("images/spacer.gif") > 0)
			{ alert("Image not set"); }
		else
			{
			// If the URL contains "_thumbnail", remove to display the full image
			if (imageSRC.indexOf("_thumbnail") > 0)
				{ imageSRC = imageSRC.replace("_thumbnail",""); }
				
			var imageObj = new Image();
			imageObj.src = imageSRC;
			
			imageWindow = window.open("","imageWindow","height=" + (imageObj.height+20) + ",width=" + (imageObj.width+20));
			imageWindow.document.write("<html><head><title>Image</title><body marginheight='1' marginwidth='1' topmargin='1' leftmargin='1' onclick='window.close()'>");
			imageWindow.document.write("<img src='" + imageSRC + "' border='0' onload='window.opener.resizeImageWindow(this.height,this.width)' onclick='window.close()'>");
			imageWindow.document.write("</body></head></html>");
			imageWindow.document.close();
			}
		}
		
	// Resize the image window to 20px over the size of the image
	function resizeImageWindow(imageHeight,imageWidth)
		{
		if ( (typeof(imageWindow) != 'undefined') && (imageWindow != null) )
			{ imageWindow.resizeTo(imageWidth+20,imageHeight+20); }
		}
		
	// Take the URL in the form input, and set the associated preview to it
	function previewFormImage(imageInputObj)
		{ previewImage(imageInputObj,'image_' + imageInputObj.name); }
	
	// Preview an image in an imageObj of the same name, or allow the user to specify the ID of the image to preview within
	function previewImage(imageInputObj,previewImageId)
		{
		if (previewImageId == null) { previewImageId = imageInputObj.name; }
		document.images[previewImageId].src = (imageInputObj.value.length) ? imageInputObj.value : '/retirementcalc/images/spacer.gif';
		}
		
	// Resize the image to the maximum sizes supplied while keeping the proportions
	var infiniteCounterMaxImageResize = 0;
	function maxImageResize(imageObj,maxWidth,maxHeight)
		{
		// Make a copy of the image to get the actual image size unrestricted by it's original IMG tag
		var originalImage = new Image();
		originalImage.src = imageObj.src;
		
		// If the dimensions of the image say that it is a combination of 0 or 1, and it's not the spacer.gif, recall this procedure shortly
		if ( ((originalImage.width == 0) || (originalImage.width == 1)) && ((originalImage.height == 0) || (originalImage.height == 1)) )
			{
			if ((imageObj.src.indexOf('spacer.gif') <= 0) && (infiniteCounterMaxImageResize++ < 100))
				{
				timeoutString = "maxImageResize(document.getElementById('" + imageObj.getAttribute("id") + "')," + maxWidth + "," + maxHeight + ");";
				window.setTimeout(timeoutString,100);
				}
			}
		else if ( (originalImage.width != maxWidth) || (originalImage.height != maxHeight) )
			{
			infiniteCounterMaxImageResize = 0;
			var proportionByHeight = (maxHeight/originalImage.height);
			var proportionByWidth = (maxWidth/originalImage.width);
			
			// Use which ever proprtion allows the other dimension to fit
			var proportion = ((originalImage.width * proportionByHeight) <= maxWidth) ? proportionByHeight : proportionByWidth;
				
			// Resize the image;
			imageObj.height = (originalImage.height * proportion);
			imageObj.width = (originalImage.width * proportion);
			}
		else
			{
			// Set the image block to be equal to the maxWidth and maxHeight if they aren't already so
			infiniteCounterMaxImageResize = 0;
			if (imageObj.height != maxHeight) { imageObj.height = maxHeight; }
			if (imageObj.width != maxWidth) { imageObj.width = maxWidth; }
			}
		}
		
	function isValidImageType(inputObj)
		{
		var inputValue = inputObj.value.toLowerCase();
		return ( (inputValue.length == 0) || (inputValue.match(/\.jpg$/)) || (inputValue.match(/\.jpeg$/)) )
		}
	
/*=========================================================================================================================
|                                                                                                                         |
|   DDDDD     AAAA   TTTTTT  EEEEEE       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   DD   DD  AA  AA    TT    EE           FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   DD   DD  AAAAAA    TT    EEEE         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|   DD   DD  AA  AA    TT    EE           FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|   DDDDD    AA  AA    TT    EEEEEE       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                         |
=========================================================================================================================*/
/*
Desc: VBScript native Date functions emulated for Javascript
Author: Rob Eberhardt, Slingshot Solutions - http://slingfive.com/
*/
var DaysPerMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var DaysPerMonthLeapYear = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function isValidYear(thisYear)
	{ return ( is_integer(thisYear) && ((thisYear.length == 2) || (thisYear.length == 4)) ); }

function isValidMonth(thisMonth)
	{ return ( is_integer(thisMonth) && checkRange(thisMonth,1,12) ); }

function isValidDay(thisDay, thisMonth, thisYear)
	{
	// Handle leap year
	daysthisMonth = ((thisYear % 4) != 0) ? DaysPerMonth[thisMonth-1] : DaysPerMonthLeapYear[thisMonth-1];
	// Check that the day is an integer, and is between 1 and the number of days in that month
	return ( is_integer(thisDay) && checkRange(thisDay,1,daysthisMonth) );
	}

// used by dateAdd, dateDiff, datePart, weekdayName, and monthName
// note: less strict than VBScript's isDate, since JS allows invalid dates to overflow (e.g. Jan 32 transparently becomes Feb 1)
function isDate(dateValue)
	{
	// If the dateVlue is a string, it will have a length, so check it as a string
	if (typeof(dateValue.length) != 'undefined')
		{
		// If there is a space in the date, separate on the first space, and set the left side to the dateValue and the right to the timeValue
		if (dateValue.indexOf(" ") > 0)
			{
			timeValue = dateValue.split(" ")[1];
			dateValue = dateValue.split(" ")[0];
			}
		else { timeValue = ""; }
		
		// Make sure that there are 3 parts to the date separated by slashes
		if ( (dateValue.length < 6) || (dateValue.indexOf("/") <= 0) || (dateValue.split("/").length != 3) )
			{ return false; }
		
		// Validate the date parts
		var day = dateValue.split('/')[1];
		var month = dateValue.split('/')[0];
		var year = dateValue.split('/')[2];
		
		// Validate the parts of teh date
		if ( !isValidYear(year) || !isValidMonth(month) || !isValidDay(day,month,year) )
			{ return false; }
		
		// If we have a time, validate it
		if (timeValue.length && !isValidTime(timeValue,true))
			{ return false; }
		}
					
	// Make sure that we can convert the date
	if (isNaN(new Date(dateValue)))
		{ return false; }
	
	// Otherwise, return true
	return true;
	}

function dateAdd(p_Interval, p_Number, p_Date){
	if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
	if(isNaN(p_Number)){return "invalid number: '" + p_Number + "'";}	

	p_Number = new Number(p_Number);
	var dt = new Date(p_Date);
	switch(p_Interval.toLowerCase()){
		case "yyyy": {// year
			dt.setFullYear(dt.getFullYear() + p_Number);
			break;
		}
		case "q": {		// quarter
			dt.setMonth(dt.getMonth() + (p_Number*3));
			break;
		}
		case "m": {		// month
			dt.setMonth(dt.getMonth() + p_Number);
			break;
		}
		case "y":		// day of year
		case "d":		// day
		case "w": {		// weekday
			dt.setDate(dt.getDate() + p_Number);
			break;
		}
		case "ww": {	// week of year
			dt.setDate(dt.getDate() + (p_Number*7));
			break;
		}
		case "h": {		// hour
			dt.setHours(dt.getHours() + p_Number);
			break;
		}
		case "n": {		// minute
			dt.setMinutes(dt.getMinutes() + p_Number);
			break;
		}
		case "s": {		// second
			dt.setSeconds(dt.getSeconds() + p_Number);
			break;
		}
		case "ms": {		// second
			dt.setMilliseconds(dt.getMilliseconds() + p_Number);
			break;
		}
		default: {
			return "invalid interval: '" + p_Interval + "'";
		}
	}
	return dt;
}

function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear){
	if(!isDate(p_Date1)){return "invalid date: '" + p_Date1 + "'";}
	if(!isDate(p_Date2)){return "invalid date: '" + p_Date2 + "'";}
	var dt1 = new Date(p_Date1);
	var dt2 = new Date(p_Date2);
	
	// If the year is less than 1950, make sure that they actually entered '1949' and not '49', otherwise add 100 years
	if ((dt1.getUTCFullYear() < 1950) && (p_Date1.indexOf(dt1.getUTCFullYear()) < 0))
		{ dt1.setFullYear(dt1.getUTCFullYear() + 100); }
	if ((dt2.getUTCFullYear() < 1950) && (p_Date2.indexOf(dt1.getUTCFullYear()) < 0))
		{ dt2.setFullYear(dt2.getUTCFullYear() + 100); }

	// get ms between dates (UTC) and make into "difference" date
	var iDiffMS = dt2.valueOf() - dt1.valueOf();
	var dtDiff = new Date(iDiffMS);

	// calc the number of years
	var nYears  = dt2.getUTCFullYear() - dt1.getUTCFullYear();
	
	// calc various diffs
	var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
	var nQuarters = parseInt(nMonths/3);	//<<-- different than VBScript, which watches rollover not completion
	
	// If the years is greater than or equal to 1, double check by comparing the month and date.
	// If the month and date in dt2 isn't greater than that of dt1, subtract one year
	// We do this after we calculate the number of months and quarters since the year does affect their calculations correctly
	if ((nYears >= 1) && ((dt2.getUTCMonth() < dt1.getUTCMonth()) || ((dt2.getUTCMonth() == dt1.getUTCMonth()) && (dt2.getUTCDate() < dt1.getUTCDate()))))
		{ nYears--; }
	
	var nMilliseconds = iDiffMS;
	var nSeconds = parseInt(iDiffMS/1000);
	var nMinutes = parseInt(nSeconds/60);
	var nHours = parseInt(nMinutes/60);
	var nDays  = parseInt(nHours/24);
	var nWeeks = parseInt(nDays/7);
	
	// return requested difference
	var iDiff = 0;		
	switch(p_Interval.toLowerCase()){
		case "yyyy": return nYears;
		case "q": return nQuarters;
		case "m": return nMonths;
		case "y": 		// day of year
		case "d": return nDays;
		case "w": return nDays;
		case "ww":return nWeeks;		// week of year	// <-- inaccurate, WW should count calendar weeks (# of sundays) between
		case "h": return nHours;
		case "n": return nMinutes;
		case "s": return nSeconds;
		case "ms":return nMilliseconds;	// millisecond	// <-- extension for JS, NOT available in VBScript
		default: return "invalid interval: '" + p_Interval + "'";
	}
}

function datePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear){
	if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}

	var dtPart = new Date(p_Date);
	switch(p_Interval.toLowerCase()){
		case "yyyy": return dtPart.getFullYear();
		case "q": return parseInt(dtPart.getMonth()/3)+1;
		case "m": return dtPart.getMonth()+1;
		case "y": return dateDiff("y", "1/1/" + dtPart.getFullYear(), dtPart);			// day of year
		case "d": return dtPart.getDate();
		case "w": return dtPart.getDay();	// weekday
		case "ww":return dateDiff("ww", "1/1/" + dtPart.getFullYear(), dtPart);		// week of year
		case "h": return dtPart.getHours();
		case "n": return dtPart.getMinutes();
		case "s": return dtPart.getSeconds();
		case "ms":return dtPart.getMilliseconds();	// millisecond	// <-- extension for JS, NOT available in VBScript
		default: return "invalid interval: '" + p_Interval + "'";
	}
}

function weekdayName(p_Date, p_abbreviate){
	if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
	var dt = new Date(p_Date);
	var retVal = dt.toString().split(' ')[0];
	var retVal = Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[dt.getDay()];
	if(p_abbreviate==true){retVal = retVal.substring(0, 3)}	// abbr to 1st 3 chars
	return retVal;
}

function monthName(p_Date, p_abbreviate){
	if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
	var dt = new Date(p_Date);	
	var retVal = Array('January','February','March','April','May','June','July','August','September','October','November','December')[dt.getMonth()];
	if(p_abbreviate==true){retVal = retVal.substring(0, 3)}	// abbr to 1st 3 chars
	return retVal;
}

// ====================================
// bootstrap different capitalizations
function IsDate(p_Expression)
	{ return isDate(p_Expression); }
function DateAdd(p_Interval, p_Number, p_Date)
	{ return dateAdd(p_Interval, p_Number, p_Date); }
function DateDiff(p_interval, p_date1, p_date2, p_firstdayofweek, p_firstweekofyear)
	{ return dateDiff(p_interval, p_date1, p_date2, p_firstdayofweek, p_firstweekofyear); }
function DatePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear)
	{ return datePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear); }
function WeekdayName(p_Date)
	{ return weekdayName(p_Date); }
function MonthName(p_Date)
	{ return monthName(p_Date); }

function getFourDigitYear(yearVar)
	{
	if (yearVar.length == 4)
		{ return yearVar; }
	else
		{ return ((yearVar > 50) ? 1900 : 2000) + (yearVar*1); }
	}
	
// datetime parsing and formatting routimes. modify them if you wish other datetime format
function stringToDate(dateString)
	{
	var dateRegExp = /^(\d+)\/(\d+)\/(\d+)$/;
	if (!dateRegExp.exec(dateString))
		{ return returnError("Invalid Date format: " + dateString); }
	return (new Date (getFourDigitYear(RegExp.$3), ((RegExp.$1*1)-1), (RegExp.$2*1)));
	}

function dateToString(jsDateObj)
	{ return (new String ((jsDateObj.getMonth()+1)+"/"+jsDateObj.getDate()+"/"+jsDateObj.getFullYear())); }
	
function listFindDate(listOfDates,dateToFind)
	{
	var arrayToSearch = listOfDates.split(",");
	
	// Loop through the list and see if any of the values match the date sent through. If so, return the index of that list item, otherwise -1
	var foundIndex = -1;
	for (var listIndex = 0; listIndex < arrayToSearch.length; listIndex++)
		{
		if (stringToDate(arrayToSearch[listIndex]).valueOf() == stringToDate(dateToFind).valueOf())
			{ foundIndex = listIndex; break; }
		}
	return foundIndex;
	}
	
/*===========================================================================================================================
|                                                                                                                           |
|   TTTTTT  IIIIII  MM     MM  EEEEEE       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|     TT      II    MMM   MMM  EE           FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|     TT      II    MM MMM MM  EEEE         FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|     TT      II    MM  M  MM  EE           FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|     TT    IIIIII  MM     MM  EEEEEE       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                           |
===========================================================================================================================*/
function checkRange(this_number, this_min, this_max)
	{ return ( (parseInt(this_number * 1) >= this_min) && (parseInt(this_number * 1) <= this_max) ); }
function isValidHours(hours,allowMilitaryTime)
	{
	if (allowMilitaryTime == null) { allowMilitaryTime = false; }
	return ( is_integer(hours) && ((allowMilitaryTime && checkRange(hours,0,24)) || (!allowMilitaryTime && checkRange(hours,0,12))) );
	}

function isValidMinutes(minutes)
	{ return ( is_integer(minutes) && checkRange(minutes,0,59) && (minutes.length == 2) ); }

function isValidSeconds(seconds)
	{ return ( is_integer(seconds) && checkRange(seconds,0,59) && (seconds.length == 2) ); }
	
function isValidTime(timeValue,allowMilitaryTime)
	{
	if (allowMilitaryTime == null) { allowMilitaryTime = false; }
	
	if (timeValue == "")
		{ return true; }
		
	// Validate HH:MM:SS
	else if ( (timeValue.length >= 5) && (timeValue.indexOf(':') >= 0) && (timeValue.split(':').length == 3) )
		{
		var hours = timeValue.split(':')[0];
		var minutes = timeValue.split(':')[1];
		var seconds = timeValue.split(':')[2];
		
		return (isValidHours(hours,allowMilitaryTime) && isValidMinutes(minutes) && isValidSeconds(seconds));
		}
		
	// Validate HH:MM
	else if ( (timeValue.length >= 4) && (timeValue.indexOf(':') >= 0) && (timeValue.split(':').length == 2) )
		{
		var hours = timeValue.split(':')[0];
		var minutes = timeValue.split(':')[1];
		
		return (isValidHours(hours,allowMilitaryTime) && isValidMinutes(minutes));
		}
	
	else { return false; }
	}
	
function isValidDuration(timeValue,durationFormat)
	{
	// Validate HH:MM:SS
	if ( (timeValue.length >= 5) && (timeValue.indexOf(':') >= 0) && (timeValue.split(':').length == 3) && ((durationFormat == null) || (durationFormat != "HH:MM")) )
		{
		var hours = timeValue.split(':')[0];
		var minutes = timeValue.split(':')[1];
		var seconds = timeValue.split(':')[2];
		
		return (is_integer(hours) && isValidMinutes(minutes) && isValidSeconds(seconds));
		}
		
	// Validate HH:MM
	else if ( (timeValue.length >= 4) && (timeValue.indexOf(':') >= 0) && (timeValue.split(':').length == 2) )
		{
		var hours = timeValue.split(':')[0];
		var minutes = timeValue.split(':')[1];
		
		return (is_integer(hours) && isValidMinutes(minutes));
		}
	
	else { return false; }
	}
	
function timeToMinutes(timeValue)
	{
	// Split on spaces and find out if we have an AMPM value
	if (timeValue.split(" ").length == 2)
		{
		AMPM = timeValue.split(" ")[1];
		timeValue = timeValue.split(" ")[0];
		}
	else { AMPM = ""; }
	
	// Make sure it's a valid duration
	if (!isValidDuration(timeValue,"HH:MM"))
		{ return; }
	
	// Grab the hours and minutes
	var hourCount = stripLeadingZeros(timeValue.split(":")[0]);
	var minuteCount = stripLeadingZeros(timeValue.split(":")[1]);
	
	// If the hours and minutes don't have length, default to 0, otherwise parseInt
	hourCount = ((hourCount == "") ? 0 : parseInt(hourCount));
	minuteCount = ((minuteCount == "") ? 0 : parseInt(minuteCount));
	
	// If we have an AMPM value of PM, and the hours is not already set to 12, add 12 hours to it
	if ((AMPM.substr(0,1).toUpperCase() == "P") && (hourCount != 12))
		{ hourCount += 12; }
	
	// Convert to minutes.seconds and return
	return (hourCount*60)+minuteCount;
	}
	
/*============================================================================================================================================================================
|                                                                                                                                                                            |
|   VV  VV   AAAA   LL      IIIIII  DDDDD     AAAA   TTTTTT  IIIIII   OOOOO   NN    NN       FFFFFF  UU  UU  NN    NN   CCCCC  TTTTTT  IIIIII   OOOOO   NN    NN   SSSSS     |
|   VV  VV  AA  AA  LL        II    DD   DD  AA  AA    TT      II    OO   OO  NNN   NN       FF      UU  UU  NNN   NN  CC        TT      II    OO   OO  NNN   NN  SS         |
|   VV  VV  AAAAAA  LL        II    DD   DD  AAAAAA    TT      II    OO   OO  NN NN NN       FFFF    UU  UU  NN NN NN  CC        TT      II    OO   OO  NN NN NN   SSSS      |
|    VVVV   AA  AA  LL        II    DD   DD  AA  AA    TT      II    OO   OO  NN   NNN       FF      UU  UU  NN   NNN  CC        TT      II    OO   OO  NN   NNN      SS     |
|     VV    AA  AA  LLLLLL  IIIIII  DDDDD    AA  AA    TT    IIIIII   OOOOO   NN    NN       FF       UUUU   NN    NN   CCCCC    TT    IIIIII   OOOOO   NN    NN  SSSSS      |
|                                                                                                                                                                            |
============================================================================================================================================================================*/
// Validate US and Canadian zipcodes
function isValidZip(zip,country)
	{
	var regExp_US = /^\d{5}(-\d{4})?$/
	var regExp_CA = /^[a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d$/i
	
	return (
		( ((country == null) || (country == 'US')) && (zip.search(regExp_US) == 0))
		|| ( ((country == null) || (country == 'CN')) && (zip.search(regExp_CA) == 0))
		);
	}

// check for proper email format
function isValidEmail(emailAddressToCheck)
	{
    var emailRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return emailRegExp.test(emailAddressToCheck);
	}

/******************************************************************
** Functions to help format numbers as floats and dollar amounts **
******************************************************************/
var isIntegerKey = "0123456789";
var isFloatKey = "." + isIntegerKey;
var isHexKey = "ABCDEFabcdef" + isIntegerKey;
var isIntegerValue = /(^-?\d\d*$)/;
var isFloatValue = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	
function is_integer(this_number)
	{
	for (var char_index=0; char_index<this_number.length; char_index++)
		{
		if (parseInt(this_number.charAt(char_index)) != this_number.charAt(char_index))
			{ return false; }
		}
	return true;
	}

function is_float(this_number)
	{
	var float_array = this_number.split(".");
	
	// Make sure that there are no more than on period by splitting on periods
	if (float_array.length > 2)
		{ return false; }
	// Make sure that there is more than just a period
	else if (this_number == ".")
		{ return false; }
	// Look at the data before and after the period and make sure that both are valid integer values
	else
		{
		for (var float_index=0; float_index<float_array.length; float_index++)
			if ( !(is_integer(float_array[float_index])) )
				{ return false; }
		}
	return true;
	}
	
function is_hex(this_number)
	{
	for (var char_index=0; char_index<this_number.length; char_index++)
		{
		if (!(isHexKey.indexOf(this_number.charAt(char_index)) >= 0))
			{ return false; }
		}
	return true;
	}

function hasFloatValue(InputObj)
	{ return ( (InputObj.value.length > 0) && is_float(InputObj.value) ); }

function hasIntValue(InputObj)
	{ return ( (InputObj.value.length > 0) && is_integer(InputObj.value) ); }

function validateKey(inputObj,keySet,e)
	{
	var key;
	var keychar;
	var eventWindow = inputObj.document.parentWindow;

	// Get the event
	if (eventWindow.event)
	   { key = eventWindow.event.keyCode; }
	else if (e)
	   { key = e.which; }
	else
	   { return true; }
	keychar = String.fromCharCode(key);

	// Validate the key
	if ((keychar == ".") && (keySet == isFloatKey) && (inputObj.value.indexOf(".") > 0))
		{ return false; }
	else if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   { return true; }
	else
		{ return (keySet.indexOf(keychar) >= 0);  }
	}
	
// Return if a formInput has a value or not
function inputHasValue(ElementObj)
	{
	if ((typeof(ElementObj.type) == 'undefined') && (ElementObj.length))
		{ ElementObj.type = ElementObj[0].type; }
		
	switch(ElementObj.type)
		{
		case "text": case "textarea": case "password":
			return (ElementObj.value.length > 0); break;
		case "checkbox": case "radio":
			if (!(ElementObj.length))
				{ return (ElementObj.checked); }
			else
				{
				for (var elementCount=0; elementCount<ElementObj.length; elementCount++)
					{
					if (ElementObj[elementCount].checked)
						{ return true; }
					}
				}
				return false;
			break;
		case "select-one": case "select-multiple":
			return (ElementObj.selectedIndex > 0); break;
		}
	}

