/// <reference path="MetafuseFunctions.js" />
//GLOBAL SYSTEM FUNCTIONS
//Set Hidden Input On Form
function SHV(hiddenInput, hiddenValue)
{
	f = document.forms[0];
	f[hiddenInput].value = hiddenValue;
};
//DEPRICATED
function SID(hiddenInput, guidArrayIndex)
{
	SHV(hiddenInput, GuidArray[guidArrayIndex]);
};

//Generic Link Creator Makes ReturnUrl and Scroll Position
var metafuseGlobalCancelAppendReturnUrl = false;
var metafuseGlobalHttpProtocolAndServerName = "";
function L(scriptPath, excludeReturnUrl)
{
	//alert(Root + scriptPath);
	//alert(AppendReturnUrl(Root + scriptPath));
	var hyperLink = AppendAdditionalHiddenElementNamesToHyperLink(scriptPath);


	//if the HTTP protocol wasn't supplied then add the root and any global HTTP Protocol and Server Name to invoke through JS Links
	if (hyperLink.indexOf("http://", 0) != 0 && hyperLink.indexOf("https://", 0) != 0)
	{
		hyperLink = metafuseGlobalHttpProtocolAndServerName + Root + hyperLink;
	}


	if (excludeReturnUrl || metafuseGlobalCancelAppendReturnUrl)
	{
		window.location.href = hyperLink;
	}
	else
	{
		try
		{
			window.location.href = AppendReturnUrl(hyperLink);
		}
		catch (e)
		{
			window.location.href = hyperLink;
		}

	}

	return false;
};

function ConfirmAndPostBack(confirmMessage, target, args)
{
	if (confirm(confirmMessage))
	{
		__doPostBack(target, args);
	}
};

//generic link object, takes script path and concatenates id to path.
function LO(scriptPath, guidArrayIndex, optionalNameString)
{

	if (scriptPath.indexOf("?") >= 0)
	{
		scriptPath += "&";
	}
	else
	{
		scriptPath += "?";
	}

	if (!optionalNameString)
	{
		optionalNameString = "Id";
	}

	return L(scriptPath + optionalNameString + "=" + GuidArray[guidArrayIndex]);

};
//generic link object, takes script path and concatenates id to path.
function LI(scriptPath, id, optionalNameString)
{

	if (scriptPath.indexOf("?") >= 0)
	{
		scriptPath += "&";
	}
	else
	{
		scriptPath += "?";
	}

	if (!optionalNameString)
	{
		optionalNameString = "Id";
	}

	return L(scriptPath + optionalNameString + "=" + id);

};
//Appends the ReturnUrl to the Link
function AppendReturnUrl(scriptPath, returnUrl)
{
	if (!returnUrl)
	{
		returnUrl = ReturnUrl;
	}

	returnUrl = AppendScrollLocation(returnUrl);

	if (scriptPath.indexOf("?") >= 0)
	{
		scriptPath += "&";
	}
	else
	{
		scriptPath += "?";
	}
	scriptPath += "ReturnUrl=" + escape(returnUrl);

	return scriptPath;
};
//Appends the Scroll Position to the ReturnUrl
function AppendScrollLocation(returnUrl)
{
	f = document.forms[0];
	if (f["__sx"])
	{
		if (returnUrl.indexOf("?") >= 0)
		{
			returnUrl += "&_sx=" + f["__sx"].value;
		}
		else
		{
			returnUrl += "?_sx=" + f["__sx"].value;
		}
	}
	if (f["__sy"])
	{
		returnUrl += "&_sy=" + f["__sy"].value;
	}

	if (AdditionalHiddenElementNamesToAppendToReturnUrl != null)
	{
		for (var i = 0; i < AdditionalHiddenElementNamesToAppendToReturnUrl.length; i++)
		{
			var elementName = AdditionalHiddenElementNamesToAppendToReturnUrl[i]
			var element = GetElementById(elementName);
			if (element)
			{
				if (element.value != "")
				{
					//add extra "_" for these columns (backward from scrolling);
					//we may want to move the prefix out of here and into the base and supply the prefix
					//in the element name, this prevents it from being added continuously into the return url.
					returnUrl += "&" + "_00_" + elementName + "=" + element.value;
				}
			}
		}
	}

	return returnUrl;
};
//appends additional parameters to the hyperlink before adding the return url.
function AppendAdditionalHiddenElementNamesToHyperLink(hyperLink)
{
	if (AdditionalHiddenElementNamesToAppendToHyperLink != null)
	{
		for (var i = 0; i < AdditionalHiddenElementNamesToAppendToHyperLink.length; i++)
		{
			var elementName = AdditionalHiddenElementNamesToAppendToHyperLink[i];
			var element = GetElementById(elementName);
			if (element)
			{
				var elementValue = element.value;
				if (elementValue != "")
				{
					//add extra "_" for these columns (backward from scrolling);
					//we may want to move the prefix out of here and into the base and supply the prefix
					//in the element name, this prevents it from being added continuously into the return url
					//and also helps the program tell the difference between parameters of control sent from
					//another script vs. the current script.
					if (hyperLink.indexOf("?") >= 0)
					{
						hyperLink += "&" + "_00_" + elementName + "=" + element.value;
					}
					else
					{
						hyperLink += "?" + "_00_" + elementName + "=" + element.value;
					}
				}
			}
		}
	}
	return hyperLink;
};


//takes checkbox name and creates a comma separated list of the ids of these checkboxes.
function CreateGuidStringFromCheckBoxIndexes(checkBoxName)
{
	f = document.forms[0];
	var ids = "";


	if (f[checkBoxName])
	{
		if (f[checkBoxName].length)
		{
			for (i = 0; i < f[checkBoxName].length; i++)
			{
				if (f[checkBoxName][i].checked)
				{
					if (ids != "")
					{
						ids += ",";
					}

					ids += GuidArray[f[checkBoxName][i].value];
				}
			}
		}
		else
		{
			if (f[checkBoxName].checked)
			{
				ids = GuidArray[f[checkBoxName].value];
			}
		}
	}

	return ids;
};

function CreateGuidStringFromIndexArray(indexArray)
{
	var ids = "";

	for (i = 0; i < indexArray.length; i++)
	{
		if (ids != "")
		{
			ids += ",";
		}
		if (GuidArray[indexArray[i]])
		{
			ids += GuidArray[indexArray[i]];
		}
	}
	return ids;
};
function CreateCommaSeparatedStringFromArrayMembers(array)
{
	var s = "";

	if (array)
	{
		for (var i = 0; i < array.length; i++)
		{
			if (s != "")
			{
				s += ",";
			}
			var a = array[i];

			if (a != null)
			{
				s += a;
			}
		}
	}
	return s;
};

/**********************************************************
On Load Hookup
**********************************************************/
var OnLoad =
{
	/*
	aFunctions :
	[],
	*/
	AddFunction:

		function(oFunctionPointer)
		{
			var oldonload = window.onload;
			if (typeof window.onload == 'function')
			{
				window.onload = function()
				{
					oldonload();
					oFunctionPointer();
				}
			}
			else
			{
				window.onload = oFunctionPointer;
			}

		}
};

//onload = function(){ OnLoad.CallFunctions(); };
/**********************************************************
On Scroll Hookup
**********************************************************/
var OnScrollFunctions =
{
	aFunctions:
		[],
	AddFunction:
		function(oFunctionPointer)
		{
			if (!this.Loaded)
			{
				this.aFunctions[this.aFunctions.length] = oFunctionPointer;
			}
			else
			{
				oFunctionPointer();
			}
		},
	CallFunctions:
		function()
		{
			for (oFunctionPointer in this.aFunctions)
			{
				this.aFunctions[oFunctionPointer]();
			}
			this.Loaded = true;
		},
	Loaded:
		false
};

window.onscroll = function() { OnScrollFunctions.CallFunctions(); };
/**********************************************************
On Window Resize
***********************************************************/
var OnWindowResizeFunctions =
{
	aFunctions:
		[],
	AddFunction:
		function(oFunctionPointer)
		{
			if (!this.Loaded)
			{
				this.aFunctions[this.aFunctions.length] = oFunctionPointer;
			}
			else
			{
				oFunctionPointer();
			}
		},
	CallFunctions:
		function()
		{
			for (oFunctionPointer in this.aFunctions)
			{
				this.aFunctions[oFunctionPointer]();
			}
			this.Loaded = true;
		},
	Loaded:
		false
};
function WindowResize()
{
	OnWindowResizeFunctions.CallFunctions();
};
window.onresize = function() { OnWindowResizeFunctions.CallFunctions(); };

/**********************************************************
On Window Resize
***********************************************************/
var OnDocumentUnloadFunctions =
{
	aFunctions:
		[],
	AddFunction:
		function(oFunctionPointer)
		{
			var dupe = false;
			for (var i = 0; i < this.aFunctions.length; i++)
			{
				if (this.aFunctions[i] == oFunctionPointer)
				{
					dupe = true;
				}
			}
			if (dupe == false)
			{
				this.aFunctions[this.aFunctions.length] = oFunctionPointer;
			}
		},
	CallFunctions:
		function()
		{
			for (oFunctionPointer in this.aFunctions)
			{
				this.aFunctions[oFunctionPointer]();
			}
		}
};
function OnDocumentUnload()
{
	OnDocumentUnloadFunctions.CallFunctions();
};
//set in body to enable
//document.body.onunload = function(){ OnDocumentUnload.CallFunctions(); };

/***********************************************************
Get Element By Id (Cross Browser)
************************************************************/
function GetElementById(elementId)
{
	//alert("elementId: " + elementId + " type: " + typeof elementId);

	//if the elementId passed in is a string, lookup the element object
	if (typeof elementId == 'string')
	{
		if (elementId == "")
		{
			return null;
		}
		else
		{
			var element = document.getElementById(elementId)

			if (!element)
			{
				element = document.forms[0][elementId];
			}
			return element;
		}
	}
	//elementId was not a string return the element object
	//this allows most methods to take either the element id or the element in a single parameter to functions
	else
	{
		return elementId;
	}
};


//Creates a simulated guid for use in JavaScript methods
function NewGuid()
{
	//dont use ActiveX any longer since it doesn't work on IE7 without a warning
	//try
	//{
	//	var x = new ActiveXObject("Scriptlet.TypeLib");

	//	return (x.guid);
	//}
	//catch (e)
	//{
	//create GUID here
	var g = "";
	for (var i = 0; i < 32; i++)
	{
		//random character for the guid
		var chr = Math.floor(Math.random() * 0xF).toString(0xF);

		//if we don't get a char for some reason just make it 0
		if (chr == null || chr == "" || chr.length > 1)
		{
			chr == "0";
		}

		//add the dash in to format the GUID correctly
		if (i == 7 || i == 11 || i == 15 || i == 19)
		{
			chr += "-";
		}

		//add the character to the GUID
		g += chr;

		//comment out old
		//g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "");
	}
	return g;

	//}
};



/**********************************************************
Change element class name (USED IN HEADER)
***********************************************************/
function ChangeElementClassName(element, className)
{
	element = GetElementById(element);
	if (element)
	{
		element.className = className;
	}
};
/**********************************************************
Image Changing Functions (Depricate?)
**********************************************************/

//STW 2003-04-27 override the previous one, which does not work on Tree's for whatever reason.  
function ChangeImage(sImageId, sImageName)
{
	if (document.images && document[sImageId] && eval("window." + sImageName))
	{
		document[sImageId].src = eval(sImageName + ".src");
	}
};
function ChangeInputImage(inputImage, imgObjName)
{
	//If the browser supports rollovers then change the image.
	if (document.getElementById)
	{
		inputImage.src = eval(imgObjName + ".src");
	}
};
//swaps an image inside a hyperlink
function HyperLinkSwapImage(element, imageUrl)
{
	element = GetElementById(element);
	if (element)
	{
		element.src = imageUrl;
	}
};
/**********************************************************
Enter Postback Functions
**********************************************************/
//move to base tools...
function IsEnterKey(localEvent)
{
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4)
	{
		if (localEvent.which)
		{
			return (localEvent.which == 13)
		}
		else
		{
			return false;
		}
	}
	else
	{
		if (!localEvent)
		{
			localEvent = window.event;
		}
		return (localEvent.keyCode == 13);
	}
};

function EKH(localEvent, key)
{

	if (IsEnterKey(localEvent))
	{
		FormTools.FocusAndClickElementUsingSetTimeout(key);
		return false;
	}

	return true;
};






/**********************************************************
Context Help Functions
**********************************************************/
var metafuseBaseShowHelpFromDelayShowHelp = null;
function DSHlp(localEvent, helpText, helpWidth)
{
	if (!localEvent)
	{
		return false;
	}
	if (helpText != "")
	{
		//copied from show Div and IFrame At Event
		var x;
		var y;


		//get event coordinates
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4)
		{
			x = localEvent.pageX;
			y = localEvent.pageY;
		}
		else
		{
			x = event.clientX + UITools.GetScrollLeft();  //document.body.scrollLeft;
			y = event.clientY + UITools.GetScrollTop();   //document.body.scrollTop;
		}

		x = x + 20;

		y = y + 20;

		//MetafuseBase_ShowContextHelp

		var timestamp = new Date().valueOf();

		metafuseBaseShowHelpFromDelayShowHelp = timestamp;
		//UITools.ShowDivAndIFrameAtEvent(localEvent, contextHelp, UITools.GetElementShim("ContextHelp_MetafuseBase_Div"), offsetX, offsetY);

		//return this.ShowDivAndIFrameAtXY(x, y, divElement, iframe, offsetX, offsetY);

		//alert(helpText);
		setTimeout("MetafuseBase_ShowContextHelp(" + x + "," + y + ",'" + helpText.split("'").join("\\'") + "'," + helpWidth + ", '" + timestamp + "')", 750);
	}

};

//show context help
function SHlp(localEvent, helpText, helpWidth, offsetX, offsetY)
{


	if (helpText != "")
	{
		/*
		var contextHelp = GetElementById("ContextHelp_MetafuseBase_Div");
	
		if(contextHelp == null)
		{
		InsertHTML('<div id="ContextHelp_MetafuseBase_Div" class="ContextHelp" style="position: absolute; z-index: 20000;display:none;"></div>');
		contextHelp = GetElementById("ContextHelp_MetafuseBase_Div");
		}
		var helpHtml;
		if(helpWidth)
		{
		helpHtml = "<table width=\"" + helpWidth + "\"><tr><td>" + helpText + "</td></tr></table>";
		}
		else
		{
		helpHtml = "<table><tr><td>" + helpText + "</td></tr></table>";
		}
		contextHelp.innerHTML = helpHtml;
		*/

		//copied from show Div and IFrame At Event
		var x;
		var y;


		//get event coordinates
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4)
		{
			x = localEvent.pageX;
			y = localEvent.pageY;
		}
		else
		{
			x = event.clientX + UITools.GetScrollLeft(); //document.body.scrollLeft;
			y = event.clientY + UITools.GetScrollTop(); //document.body.scrollTop; //STW 2009-12-23 Fixes IE8 Bug with XHTML getting the wrong scroll top
		}

		x = x + 20;

		y = y + 20;


		//call the common base method for showing help
		MetafuseBase_ShowContextHelp(x, y, helpText, helpWidth);

		//UITools.ShowDivAndIFrameAtEvent(localEvent, contextHelp, UITools.GetElementShim("ContextHelp_MetafuseBase_Div"), offsetX, offsetY);
	}

};

function MetafuseBase_ShowContextHelp(x, y, helpText, helpWidth, timestamp)
{
	if (timestamp != null && metafuseBaseShowHelpFromDelayShowHelp != timestamp)
	{
		return false;
	}

	if (helpText != "")
	{
		var contextHelp = GetElementById("ContextHelp_MetafuseBase_Div");
		//contextHelp.style.width = null;

		if (contextHelp == null)
		{
			InsertHTML('<div id="ContextHelp_MetafuseBase_Div" class="ContextHelp" style="position: absolute; z-index: 20000;display:none;width:300px;"></div>');
			contextHelp = GetElementById("ContextHelp_MetafuseBase_Div");
		}
		var helpHtml;
		if (helpWidth)
		{
			helpHtml = "<table width=\"" + helpWidth + "\"><tr><td>" + helpText + "</td></tr></table>";
		}
		else
		{
			helpHtml = "<table><tr><td>" + helpText + "</td></tr></table>";
		}
		contextHelp.innerHTML = helpHtml;

		UITools.ShowDivAndIFrameAtXY(x, y, contextHelp);

		//make sure the context width isn't too wide
		if (helpWidth == null || helpWidth <= 0)
		{
			if (contextHelp.firstChild.offsetWidth >= 300)
			{

				contextHelp.style.width = 300;

				var shim = UITools.GetElementShim("ContextHelp_MetafuseBase_Div");
				if (shim)
				{
					shim.style.width = 300;
				}
				//UITools.ShowDivAndIFrameAtXY(x, y, contextHelp);

			}
			else
			{

				//contextHelp.style.width = null;
				var shim = UITools.GetElementShim("ContextHelp_MetafuseBase_Div");
				if (shim)
				{

					shim.style.width = contextHelp.firstChild.offsetWidth;
				}

			}
		}
		else
		{
			//contextHelp.style.width = null;
			var shim = UITools.GetElementShim("ContextHelp_MetafuseBase_Div");
			if (shim)
			{

				shim.style.width = contextHelp.firstChild.offsetWidth;
			}
		}

	}
	return true;
};


//hide context help
function HHlp()
{
	metafuseBaseShowHelpFromDelayShowHelp = null;
	var contextHelp = GetElementById("ContextHelp_MetafuseBase_Div");
	if (contextHelp)
	{
		UITools.HideDivAndIFrame(GetElementById("ContextHelp_MetafuseBase_Div"), UITools.GetElementShim("ContextHelp_MetafuseBase_Div"));
	}
};






/*********************************************************************
Anchor elements to window sides
**********************************************************************/
function AnchorElementOnRight(elementName)
{
	var element = GetElementById(elementName);
	if (element)
	{
		var scrollLeft;
		var elementWidth;
		if (navigator.appName == "Netscape")
		{
			element.style.position = "fixed";
		}
		else
		{
			scrollLeft = document.body.scrollLeft;
			var windowWidth = GetWindowWidth();
			//var left = (document.body.clientWidth - element.offsetWidth) + scrollLeft;
			var left = (windowWidth - element.offsetWidth) + scrollLeft;

			//window.status = left;
			element.style.position = "absolute";
			element.style.left = left;
		}

	}
};




/***********************************************************************
* 
*/
//parses the string testing for 1 or 0 to return, otherwise returns the supplied value
//USED IN MetafuseTableColumnSelector.
function ParseBoolValueFromShortString(s)
{
	if (s.toString() == "1")
	{
		return true;
	}
	else if (s.toString() == "0")
	{
		return false;
	}
	else
	{
		return s;
	}
};


/***********************************************************************
* Numbers and Other Items
*************************************************************************/
//TO DEPRICATE -- Ensures whole number entered into the system replacing
function EnsureWholeNumber(element)
{
	element = GetElementById(element);
	if (element)
	{
		var elementId = element.id;


		var v = new Number();
		v = parseFloat(element.value);
		v = Round(v, 0);

		if (v.toString() == "NaN")
		{
			SetValueUsingSetTimeout(elementId, "");


		}
		else if (v < 0)
		{
			var absNumber = Math.abs(v);
			SetValueUsingSetTimeout(elementId, absNumber.toString());

		}
		else if (v.toString() != element.value.toString())
		{
			SetValueUsingSetTimeout(elementId, v.toString());
		}
	}
};
//TO DEPRICATE //ensures positive decimal to specified decimal places (default = 2)
function EnsurePositiveDecimal(element, decimalPlaces, setNanToZero)
{
	element = GetElementById(element);
	if (element)
	{
		var elementId = element.id;

		if (!decimalPlaces)
		{
			decimalPlaces = 2;
		}

		var v = new Number();
		v = parseFloat(element.value);

		if (v.toString() == "NaN")
		{
			if (setNanToZero)
			{
				SetValueUsingSetTimeout(elementId, "0");
			}
			else
			{
				SetValueUsingSetTimeout(elementId, "");
			}
			return;
		}

		v = Round(v, decimalPlaces, true);

		if (v < 0)
		{
			var roundedValue = Round(Math.abs(v), decimalPlaces, true);
			SetValueUsingSetTimeout(elementId, roundedValue.toString());
		}
		else if (v.toString() != element.value.toString())
		{
			SetValueUsingSetTimeout(elementId, v.toString());
		}
	}
};






//determines if a number is even or odd



/*************************************************************************
Basic Object Manipulation Functions
**************************************************************************/
function isAlien(a) { return isObject(a) && typeof a.constructor != 'function'; };
function isArray(a) { return isObject(a) && a.constructor == Array; };
function isBoolean(a) { return typeof a == 'boolean'; };
function isFunction(a) { return typeof a == 'function'; };
function isNull(a) { return typeof a == 'object' && !a; };
function isNumber(a) { return typeof a == 'number' && isFinite(a); };
function isObject(a) { return ((a != null) && typeof a == 'object') || isFunction(a); };
function isString(a) { return typeof a == 'string'; };
function isUndefined(a) { return typeof a == 'undefined'; };
function isEmpty(o)
{
	var i, v;
	if (isObject(o))
	{
		for (i in o)
		{
			v = o[i];
			if (isUndefined(v) && isFunction(v))
			{
				return false;
			}
		}
	}
	return true;
};










//inserts html into the document body x-browser //move to UITools


//move to UITools...
function UpdateOuterHTML(elementId, outerHTML, insertElementIfNonExistent)
{
	var element = GetElementById(elementId);


	if (element != null)
	{
		if (element.nodeName != null && element.nodeName == "TR")
		{
			alert("You cannot replace the outerHTML of a table row");
		}
		else
		{

			if (document.all)
			{
				try
				{
					element.outerHTML = outerHTML;
				}
				catch (e)
				{
					alert("Unable to update the outer HTML for the element supplied " + elementId + ".  The error message will be dumped");
					__Dump(e);
				}
			}
			else
			{
				//element.outerHTML = outerHTML;
				//alert(element);

				try
				{



					var tmpElement = document.createElement("DIV");
					tmpElement.style.display = "none";
					element.parentNode.insertBefore(tmpElement, element);
					element.parentNode.removeChild(element);
					tmpElement.innerHTML = outerHTML;

					var firstChild = null;
					for (var i = 0; i < tmpElement.childNodes.length; i++)
					{
						firstChild = tmpElement.childNodes[i];
						if (firstChild.nodeType == 1)
						{
							break;
						}
					}
					if (firstChild.nodeType == 1)
					{
						tmpElement.parentNode.insertBefore(firstChild, tmpElement);
						tmpElement.parentNode.removeChild(tmpElement);
					}



				}
				catch (e)
				{
					alert("Unable to update the outer HTML for the element supplied " + elementId + ".  The error message will be dumped");
					__Dump(e);
				}


			}

		}
	}
	//insert the HTML if it is not there
	else if (insertElementIfNonExistent)
	{
		UITools.InsertHTML(outerHTML);
	}

};

//gets the HTML recursively for an element
//MOVE TO UI TOOLS
function GetInnerHTMLRecursive(element)
{
	var html = "";

	element = GetElementById(element);

	if (element != null)
	{
		if (element.outerHTML)
		{
			html = element.innerHTML + "\n\n\n";


			if (element.childNodes != null)
			{

				for (var i = 0; i < element.childNodes.length; i++)
				{
					var cn = element.childNodes[i];
					html += GetInnerHTMLRecursive(cn);
				}


			}
		}

	}
	return html;

};


//adds an event handler to an element (like mouse down/mouse up)
function AddEventHandlerToElement(element, eventName, eventMethod, useCapture)
{
	element = GetElementById(element);

	if (element.attachEvent)
	{
		return element.attachEvent(eventName, eventMethod);
	}
	else if (element.addEventListener)
	{
		if (useCapture == null)
		{
			useCapture = false;
		}
		element.addEventListener(eventName.replace("on", ""), eventMethod, useCapture);
		return true;
	}
	return false;
};
//adds an event handler to an element (like mouse down/mouse up)
function RemoveEventHandlerFromElement(element, eventName, eventMethod)
{
	element = GetElementById(element);

	if (element.detachEvent)
	{
		return element.detachEvent(eventName, eventMethod);
	}
	else if (element.removeEventListener)
	{
		element.removeEventListener(eventName.replace("on", ""), eventMethod, false);
		return true;
	}
	return false;
};




//delay javascript execution in milliseconds
//THIS MAY BE ABLE TO BE DEPRICATED
function Delay(milliseconds)
{
	d = new Date() //today's date
	while (1)
	{
		mill = new Date() // Date Now
		diff = mill - d //difference in milliseconds
		if (diff > milliseconds)
		{
			break;
		}
	}
};

//CAN THIS BE DEPRICATED?? ADDED TO FORM TOOLS??
function MenuConfirmAndPostBack(confirmMessage, target, args)
{
	if (confirm(confirmMessage))
	{
		__doPostBack(target, args);
	}

};

/***************************
*Row Highlighting for table row -- keep global
***************************/
function HOn(element, arrayOfAdditionalRows)
{
	if (element)
	{

		var arrayOfAdditionalToReset = null;

		if (arrayOfAdditionalRows)
		{
			arrayOfAdditionalToReset = new Array();

			for (var i = 0; i < arrayOfAdditionalRows.length; i++)
			{
				var row = GetElementById(arrayOfAdditionalRows[i]);

				if (row)
				{

					var object = new Object();
					object.id = row.id;
					object.className = row.className;
					arrayOfAdditionalToReset[i] = object;

				}
				else
				{
					arrayOfAdditionalToReset[i] = null;
				}

			}
		}

		var element = GetElementById(element);
		if (element)
		{
			var className = element.className;

			if (element.onmouseout == null)
			{
				element.onmouseout = function()
				{
					element.className = className;
					element.onmouseout = null;


					if (arrayOfAdditionalToReset)
					{
						for (var i = 0; i < arrayOfAdditionalToReset.length; i++)
						{
							var object = arrayOfAdditionalToReset[i];

							if (object)
							{
								var row = GetElementById(object.id);
								if (row)
								{
									row.className = object.className;
								}
							}
						}
					}
				};
			};


			element.className += " RowHighlight";

			if (arrayOfAdditionalRows)
			{
				for (var i = 0; i < arrayOfAdditionalRows.length; i++)
				{
					var row = GetElementById(arrayOfAdditionalRows[i]);

					if (row)
					{

						row.className += " RowHighlight";
						row.onmouseout = element.onmouseout;



					}

				}
			}
		}

	}
};


//Preferred method is HOn this method performs a similar function using positions instead of offset
//Hover Highlight On with Multiple Rows
function HOnM(element, numberOfRowsBefore, numberOfRowsAfter)
{

	if ((numberOfRowsBefore == null && numberOfRowsAfter == null) || (numberOfRowsBefore == 0 && numberOfRowsAfter == 0))
	{
		HOn(element);
	}
	else
	{
		var className = element.className;

		var additionalRows = new Array();
		var additionalRowsClassName = new Array();
		var rowIndex = 0;

		var previousSibling = GetPreviousSibling(element);
		var t = previousSibling.tagName;

		for (var i = 1; i <= numberOfRowsBefore; i++)
		{
			additionalRows[rowIndex] = previousSibling;
			additionalRowsClassName[rowIndex] = previousSibling.className;
			rowIndex++;

			previousSibling.className += " RowHighlight";

			previousSibling = GetPreviousSibling(previousSibling);
		}

		var nextSibling = GetNextSibling(element);

		for (var k = 1; k <= numberOfRowsAfter; k++)
		{
			additionalRows[rowIndex] = nextSibling;
			additionalRowsClassName[rowIndex] = nextSibling.className;
			rowIndex++;

			nextSibling.className += " RowHighlight";
			nextSibling = GetNextSibling(nextSibling);
		}

		if (element.onmouseout == null)
		{
			element.onmouseout = function() { element.className = className; element.onmouseout = null; for (var j = 0; j < rowIndex; j++) { additionalRows[j].className = additionalRowsClassName[j]; } };
		}

		element.className += " RowHighlight";
	}

};

function GetPreviousSibling(element)
{
	if (element.previousSibling == null)
	{
		return null;
	}
	if (element.previousSibling.nodeType == 1)
	{
		return element.previousSibling;
	}
	return GetPreviousSibling(element.previousSibling);
};
function GetNextSibling(element)
{
	if (element.nextSibling == null)
	{
		return null;
	}
	if (element.nextSibling.nodeType == 1)
	{
		return element.nextSibling;
	}
	return GetNextSibling(element.nextSibling);
};


//Update class
function UC(element, className)
{
	if (className == null)
	{
		className = "";
	}
	element.className = className;
};
//hover over element
function HOf(element, className)
{
	UC(element, className);
};



/***************************************
TO DEPRICATE -- DHTML Select List Methods -- MOVE TO AJAX TOOLS AND REPLACE
****************************************/
function DHTMLSelectListDisplayLoading(selectElement, keepSelected)
{
	selectElement = GetElementById(selectElement);
	if (selectElement)
	{
		SelectOptionsClear(selectElement, keepSelected);

		if (selectElement.options.length == 1)
		{
			selectElement.options[0].text = "Loading...";
		}
		else
		{
			selectElement.options[0] = new Option("Loading...", "");
		}
	}
};
function DHTMLSelectListDisplayNoneSelected(selectElement, noneSelectedString)
{
	selectElement = GetElementById(selectElement);
	if (selectElement)
	{
		if (!noneSelectedString)
		{
			noneSelectedString = "None Selected";
		}

		SelectOptionsClear(selectElement);
		selectElement.options[selectElement.options.length] = new Option(noneSelectedString, "");
	}
};
//to be depricated use UpdateSelectOptions
function DHTMLSelectListPopulateSelect(selectElement, selectListArray)
{
	selectElement = GetElementById(selectElement);
	if (selectElement)
	{
		SelectOptionsClear(selectElement);

		if (selectListArray)
		{
			for (var i = 0; i < selectListArray.length; i++)
			{
				var e = selectListArray[i];
				var o = new Option(e.Text, e.Value);

				if (e.Selected == "true")
				{
					o.selected = true;
				}
				selectElement.options[selectElement.options.length] = o;
			}
		}
	}
};






/****************************************************************************************
Namespace objects to hold various functions for javascript
*****************************************************************************************/
//constructor for the math tools used for doing math related functions
function MathTools()
{
	//default currency formatting settings (can be overridden by function calls)
	this.CurrencySymbol = "$" // British Pound = String.fromCharCode(163); 
	this.CurrencySymbolAtEnd = false;
	this.CurrencyCommaDecimalReversed = false;

	this.CurrencyScale = 2;
	this.CurrencyExcludeCommas = false;
	this.CurrencyExcludeLeadingZero = false;
	this.CurrencyExcludeTrailingZeros = false;

	//default decimal settings (can be overridden by function calls)
	this.DecimalScale = 2;
	this.DecimalExcludeCommas = false;
	this.DecimalExcludeLeadingZero = false;
	this.DecimalExcludeTrailingZeros = false;

	this.DecimalCommaAndDecimalReversed = false;

	//default percent settings (can be overridden by function calls)
	this.PercentScale = 2;
	this.PercentExcludeLeadingZero = false;
	this.PercentExcludeTrailingZeros = false;



	//determines whether or not a string is numeric so it can be converted to a number successfully
	this.IsNumeric = function(inputString)
	{
		var sNumber;
		var fNumber;
		if (inputString != null)
		{
			sNumber = inputString.toString();
			fNumber = parseFloat(inputString);
			if (sNumber == fNumber && fNumber != Number.POSITIVE_INFINITY && fNumber != Number.NEGATIVE_INFINITY)
			{
				return true;
			}
		}
		return false;
	};


	//this formats the string into a decimal string with the following options
	this.FormatDecimalString = function(stringValue, returnEmptyStringWhenNaN, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale, positiveOnly, commaAndDecimalReversed)
	{

		if (excludeCommas == null)
		{
			excludeCommas = this.DecimalExcludeCommas;
		}
		if (excludeLeadingZero == null)
		{
			excludeLeadingZero = this.DecimalExcludeLeadingZero;
		}
		if (excludeTrailingZeros == null)
		{
			excludeTrailingZeros = this.DecimalExcludeTrailingZeros;
		}
		if (scale == null)
		{
			scale = this.DecimalScale;
		}

		//determine if the commaAndDecimal are reversed for decimals
		if (commaAndDecimalReversed == null)
		{
			commaAndDecimalReversed = this.DecimalCommaAndDecimalReversed;
		}


		//parse the float to make sure it's a number
		var decimalValue = this.ParseFloat(stringValue, true, commaAndDecimalReversed);

		if (decimalValue == null)
		{
			if (returnEmptyStringWhenNaN)
			{
				return "";
			}
			else
			{
				decimalValue = 0;
			}
		}


		//round the number to the appropriate scale
		//Already converted to a decimal value, so don't reconvert it.
		decimalValue = this.Round(decimalValue, scale, commaAndDecimalReversed);


		//put the decimal value into a string for formatting
		var decimalString = new String(decimalValue.toString());


		//if there isn't a decimal place in the string then put one on the end

		if (decimalString.indexOf(".") < 0)
		{
			decimalString += ".";
		}


		//split the string into 2 parts
		var decimalStringArray = decimalString.split(".");

		//set the left side of the string
		var decimalLeftSide = new String(decimalStringArray[0]);
		//set the right side of the string
		var decimalRightSide = new String(decimalStringArray[1]);
		//setup the decimal sign
		var decimalSign = new String("");

		//if a negative number strip the negative sign off temporarily
		if (decimalValue < 0)
		{
			if (!positiveOnly)
			{
				decimalSign = "-";
			}
			decimalLeftSide = decimalLeftSide.replace("-", "");
		}



		if (scale > 0 && decimalValue < 1 && decimalValue > -1)
		{
			if (excludeLeadingZero)
			{
				if (decimalValue > 0)
				{
					decimalLeftSide = "";
				}
				else
				{
					decimalLeftSide = "-";
				}
			}
			else if (decimalLeftSide.length == 0)
			{
				decimalLeftSide = "0";
			}
		}



		//if we aren't excluding the commas then we need to include them back in
		if (!excludeCommas && (decimalValue >= 1000 || decimalValue <= -1000))
		{

			var start = decimalLeftSide.length;
			start -= 3;

			while (start >= 1)
			{
				decimalLeftSide = decimalLeftSide.substring(0, start) + "," + decimalLeftSide.substring(start, decimalLeftSide.length)
				start -= 3;
			}
		}

		//if the scale is greater than zero then we need to include the trailing zeros
		if (!excludeTrailingZeros && scale > 0 && decimalRightSide.length < scale)
		{
			//add the trailing zeros
			for (var i = decimalRightSide.length; i < scale; i++)
			{
				decimalRightSide += "0";
			}
		}



		var returnDecimalString = new String(decimalLeftSide);

		if (decimalRightSide.length > 0)
		{
			returnDecimalString = decimalLeftSide + "." + decimalRightSide;
		}


		//if the comma and decimal are reversed, then we need to swap the values
		if (commaAndDecimalReversed)
		{
			//swap out periods and commas

			if (!excludeCommas)
			{
				//replace the period with a pipe
				returnDecimalString = returnDecimalString.replace(".", "|");
				//replace the commas with a period
				returnDecimalString = returnDecimalString.replace(",", ".");
				//replaec the piple with a comma
				returnDecimalString = returnDecimalString.replace("|", ",");
			}
			else
			{
				//replace the period with a comma
				returnDecimalString = returnDecimalString.replace(".", ",");
			}
		}



		return decimalSign + returnDecimalString;


	};


	//formats the string into currency
	this.FormatCurrencyString = function(numberString, returnEmptyStringWhenNaN, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale, positiveOnly, currencySymbol, currencySymbolAtEnd, currencyCommaDecimalReversed)
	{

		if (excludeCommas == null)
		{
			excludeCommas = this.CurrencyExcludeCommas;
		}
		if (excludeCommas == null)
		{
			excludeCommas = this.CurrencyExcludeCommas;
		}
		if (excludeLeadingZero == null)
		{
			excludeLeadingZero = this.CurrencyExcludeLeadingZero;
		}
		if (excludeTrailingZeros == null)
		{
			excludeTrailingZeros = this.CurrencyExcludeTrailingZeros;
		}
		if (scale == null)
		{
			scale = this.CurrencyScale;

		}

		if (currencyCommaDecimalReversed == null)
		{
			currencyCommaDecimalReversed = this.CurrencyCommaDecimalReversed;
		}

		//get currency formatted as a decimal first
		var decimalString = this.FormatDecimalString(numberString, returnEmptyStringWhenNaN, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale, positiveOnly, currencyCommaDecimalReversed);

		if (decimalString == "")
		{
			return decimalString;
		}


		//now format the decimal as currency with the preferences
		if (currencySymbol == null)
		{
			currencySymbol = this.CurrencySymbol;
		}
		if (currencySymbolAtEnd == null)
		{
			currencySymbolAtEnd = this.CurrencySymbolAtEnd;
		}



		var symbolStart = currencySymbol;
		var symbolEnd = "";

		if (currencySymbolAtEnd)
		{
			symbolStart = "";
			symbolEnd = currencySymbol;
		}

		var negativeSign = "";
		if (decimalString.indexOf("-") >= 0)
		{
			negativeSign = "-";
			decimalString = decimalString.replace("-", "");
		}


		/* moved to FormatDecimalString 
		if(currencyCommaDecimalReversed)
		{
		//swap out periods and commas
			
		if(!excludeCommas)
		{
		//replace the period with a pipe
		decimalString = decimalString.replace(".","|");
		//replace the commas with a period
		decimalString = decimalString.replace(",",".");
		//replaec the piple with a comma
		decimalString = decimalString.replace("|",",");
		}
		else
		{
		//replace the period with a comma
		decimalString = decimalString.replace(".",",");
		}
		}
		*/

		return negativeSign + symbolStart + decimalString + symbolEnd;

	};

	//formats the string
	this.FormatPercentString = function(stringValue, returnEmptyStringWhenNaN, excludeLeadingZero, excludeTrailingZeros, scale)
	{

		if (excludeLeadingZero == null)
		{
			excludeLeadingZero = this.PercentExcludeLeadingZero;
		}
		if (excludeTrailingZeros == null)
		{
			excludeTrailingZeros = this.PercentExcludeTrailingZeros;
		}
		if (scale == null)
		{
			scale = this.PercentScale;
		}

		//parse the float to make sure it's a number
		var decimalValue = this.ParseFloat(stringValue, true);

		if (decimalValue < 0)
		{
			decimalValue = 0;
		}
		else if (decimalValue > 100)
		{
			decimalValue = 100;
		}

		decimalValue = this.FormatDecimalString(decimalValue, returnEmptyStringWhenNaN, true, excludeLeadingZero, excludeTrailingZeros, scale);

		return decimalValue.toString() + "%";

	};





	//parse the string into a valid float (if possible), returns 0 or null if NaN depending on returnNullWhenNaN
	this.ParseFloat = function(string, returnNullWhenNaN, commaAndDecimalReversed)
	{
		if (string == null)
		{
			if (returnNullWhenNaN)
			{
				return null;
			}
			else
			{
				return 0;
			}
		}
		else if (isNumber(string))
		{
			return string;
		}
		else
		{

			var stringInput = string.toString();




			//determine if the commaAndDecimal are reversed for decimals
			if (commaAndDecimalReversed == null)
			{
				commaAndDecimalReversed = this.DecimalCommaAndDecimalReversed;
			}


			//if the comma and decimal is reversed we need to normalize it to US format before processing under US format
			if (commaAndDecimalReversed == true && stringInput && stringInput != "")
			{

				//if there is a period in front of the comma then we need to remove the periods
				if (stringInput.indexOf(".") < stringInput.indexOf(","))
				{
					//strip periods
					stringInput = stringInput.replace(".", "");
					//swap comma with periods (decimals)
					stringInput = stringInput.replace(",", ".");

				}
				//if there are no periods, but commas then we need to replace them (would normally only happen in
				else if (stringInput.indexOf(".") < 0 && stringInput.indexOf(",") >= 0)
				{
					//swap comma with periods (decimals)
					stringInput = stringInput.replace(",", ".");
				}



			}

			//Now strip the number down to just digits and decimal point.
			var stripNotNumbers = /[^0-9.-]/g;

			stringInput = stringInput.replace(stripNotNumbers, "");

			var number = new Number();
			number = parseFloat(stringInput);

			if (number.toString() == "NaN")
			{
				if (returnNullWhenNaN)
				{
					return null;
				}
				else
				{
					return 0;
				}
			}
			else
			{
				return number;
			}
		}

	};



	//rounds the number supplied, returns a number with the appropriate scale
	this.Round = function(number, scale, commaAndDecimalReversed)
	{
		var inNum = number;
		var sign = 1;

		if (inNum < 0)
		{
			sign = -1;
		}

		if (scale == null)
		{
			scale = this.DecimalScale;
		}

		//make sure the number is a float..
		inNum = this.ParseFloat(inNum, false, commaAndDecimalReversed);
		inNum = Math.abs(inNum);
		scale = parseInt(scale);

		var n = new Number(sign * Math.round(inNum * Math.pow(10, scale)) / Math.pow(10, scale));

		return n;
	};

	//determines whether or not the number is even
	this.IsEven = function(integer) { return (1 - (integer % 2)); };



};
var MathTools = new MathTools();

//constructor for the layout tools page position moving items around etc.
function UITools()
{
	//gets the page x coordinate of the element
	this.GetPageXCoordinate = function(element)
	{
		var elementId = element;
		element = GetElementById(element);

		if (element)
		{
			var offsetParent = element.offsetParent;

			if (!offsetParent)
			{
				if (element.parentNode)
				{
					offsetParent = element.parentNode;
				}
				else
				{
					alert("Able to find element, but unable to find the offsetParent for the element supplied to UITools.GetPageXCoordinate.  The next alert will dump the object");
					__Dump(element)
				}
			}

			var offsetLeft = element.offsetLeft - element.scrollLeft;


			while (offsetParent != null && offsetParent.tagName != "BODY" && offsetParent.tagName != "HTML")
			{
				offsetLeft += offsetParent.offsetLeft - offsetParent.scrollLeft;

				if (offsetParent.offsetParent)
				{
					offsetParent = offsetParent.offsetParent;
				}
				///else if(offsetParent.parentNode)
				//{
				//	offsetParent = offsetParent.parentNode;
				//}
				else
				{
					offsetParent = null;
				}
			}

			return parseInt(offsetLeft);
		}
		else
		{
			alert("Unable to locate the element supplied to the UITools.GetPageXCoordinate");
			__Dump(elementId);
		}
	};
	//gets the page y coordinate of the element
	this.GetPageYCoordinate = function(element)
	{
		var elementId = element;
		element = GetElementById(element);


		if (element)
		{
			var offsetParent = element.offsetParent; // - element.scrollTop;
			var offsetTop = element.offsetTop;

			//if this is safari and the item is TR with 0 offsetTop we need to get the offset top from the first child (TD)
			if (offsetTop == 0 && element.tagName == "TR" && BrowserTools.IsSafari() && element.firstChild != null)
			{
				offsetTop = element.firstChild.offsetTop;
			}

			if (!offsetParent)
			{
				if (element.parentNode)
				{
					offsetParent = element.parentNode;
				}
				else
				{
					alert("Able to find element, but unable to find the offsetParent for the element supplied to UITools.GetPageYCoordinate.  The next alert will dump the object");
					__Dump(element)
				}
			}

			while (offsetParent != null && offsetParent.tagName != "BODY" && offsetParent.tagName != "HTML")
			{
				//if(offsetParent.scrollTop != 0)
				//{
				//	alert("offsetParent id: " + offsetParent.id + " scroll " + offsetParent.scrollTop + " offsetTop " + offsetParent.offsetTop);
				//	__Dump(offsetParent);
				//}
				offsetTop += offsetParent.offsetTop - offsetParent.scrollTop;
				offsetParent = offsetParent.offsetParent;
			}


			return parseInt(offsetTop);
			//return parseInt(0);
		}
		else
		{
			alert("Unable to locate the element supplied to the UITools.GetPageYCoordinate");
			__Dump(elementId);
		}
	};


	//gets the event page x coordiante
	this.GetEventPageXCoordinate = function(localEvent)
	{

		var x;
		//all netscape based browsers
		if (navigator.appName == "Netscape")
		{
			x = parseInt(localEvent.pageX);
		}
		//ie (target browser)
		else
		{
			x = parseInt(localEvent.clientX + GetScrollLeft());
		}

		return x;

	};
	//gets the event page y coordinate
	this.GetEventPageYCoordinate = function(localEvent)
	{
		var x;

		//all netscape based browsers
		if (navigator.appName == "Netscape")
		{
			y = parseInt(localEvent.pageY);
		}
		//ie (target browser)
		else
		{
			y = parseInt(localEvent.clientY + GetScrollTop());
		}

		return y;

	};
	//gets the window height
	this.GetWindowHeight = function()
	{
		if (IsSafari())
		{
			return parseInt(window.innerHeight);
		}
		else
		{
			return parseInt(document.body.clientHeight);
		}
	};
	//gets the window width
	this.GetWindowWidth = function()
	{
		if (IsSafari())
		{
			return parseInt(window.innerWidth);
		}
		else
		{
			return parseInt(document.body.clientWidth);
		}
	};

	//gets the window scroll left pixels
	this.GetScrollLeft = function()
	{
		if (navigator.appName == "Netscape")
		{
			return parseInt(window.pageXOffset);
		}
		else
		{
			var scrollLeft = document.body.scrollLeft;
			var scrollLeftDocElement = 0;
			if (document.documentElement != null)
			{
				scrollTopDocElement = document.documentElement.scrollLeft;
			}
			return parseInt(Math.max(scrollLeft, scrollLeftDocElement));
		}
	};
	//gets the window scroll top pixels
	this.GetScrollTop = function()
	{
		if (navigator.appName == "Netscape")
		{
			return parseInt(window.pageYOffset);
		}
		else
		{
			var scrollTop = document.body.scrollTop;
			var scrollTopDocElement = 0;
			if (document.documentElement != null)
			{
				scrollTopDocElement = document.documentElement.scrollTop;
			}
			return parseInt(Math.max(scrollTop, scrollTopDocElement));
		}
	};

	//gets the width of the element
	this.GetElementWidth = function(element)
	{
		element = GetElementById(element);

		if (element)
		{
			return parseInt(element.offsetWidth);
		}
		else
		{
			alert("Unable to locate the element supplied to the UITools.GetElementWidth - 0 returned");
		}

		return 0;
	};
	//gets the height of the element
	this.GetElementHeight = function(element)
	{
		element = GetElementById(element);

		if (element)
		{
			return parseInt(element.offsetHeight);
		}
		else
		{
			alert("Unable to locate the element supplied to the UITools.GetElementHeight - 0 returned");

		}
		return 0;

	};



	/***************************************************************************************
	Div and I Frame Display
	****************************************************************************************/

	//shows the div and iframe at the specified local event
	this.ShowDivAndIFrameAtEvent = function(localEvent, divElement, iframe, offsetX, offsetY)
	{

		if (!localEvent)
		{
			return false;
		}

		//var x = this.GetPageXCoordinate(localEvent);
		//var y = this.GetPageYCoordinate(localEvent);

		var x;
		var y;


		//get event coordinates
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 4)
		{
			x = localEvent.pageX;
			y = localEvent.pageY;
		}
		else
		{
			x = event.clientX + UITools.GetScrollLeft(); // document.body.scrollLeft;
			y = event.clientY + UITools.GetScrollTop(); // document.body.scrollTop;
		}


		return this.ShowDivAndIFrameAtXY(x, y, divElement, iframe, offsetX, offsetY);
	};


	//shows the div and i frame (if ie) at the element location specified
	this.ShowDivAndIFrameAtCenterScreen = function(divElement, iframe, offsetX, offsetY, showVeil)
	{
		var divElement = GetElementById(divElement);


		var x = 0;
		var y = 0;

		divElement.style.display = "block";
		divElement.style.visibility = "visible";
		var width = divElement.offsetWidth;
		var height = divElement.offsetHeight;
		divElement.style.display = "none";
		divElement.style.visibility = "";

		var windowWidth = UITools.GetWindowWidth();
		var windowHeight = UITools.GetWindowHeight();
		if (windowWidth > width)
		{
			x = (windowWidth - width) / 2;
		}
		x = x + UITools.GetScrollLeft();

		if (windowHeight > height)
		{
			y = (windowHeight - height) / 2;
		}
		y = y + UITools.GetScrollTop();


		if (offsetX)
		{
			x += offsetX;
		}
		if (offsetY)
		{
			y += offsetY;
		}


		//show the tip
		return UITools.ShowDivAndIFrameAtXY(x, y, divElement, iframe, offsetX, offsetY, showVeil);

	};

	//shows the div and i frame (if ie) at the element location specified
	this.ShowDivAndIFrameAtElement = function(elementNear, divElement, iframe, offsetX, offsetY, showVeil, outofWindowAllowed)
	{
		return this.ShowDivAndIFrameAtXY(this.GetPageXCoordinate(elementNear), this.GetPageYCoordinate(elementNear), divElement, iframe, offsetX, offsetY, showVeil, outofWindowAllowed);
	};

	//shows the div and i frame (if ie) at the x-y location specified
	this.ShowDivAndIFrameAtXY = function(x, y, divElement, iframe, offsetX, offsetY, showVeil, outofWindowAllowed)
	{
		divElement = GetElementById(divElement);

		if (divElement)
		{

			if (divElement.parentNode.tagName != "BODY" && divElement.parentNode.tagName != "FORM")
			{
				divElement.parentNode.removeChild(divElement);
				document.forms[0].appendChild(divElement);
				//alert('moved element to body');
			}

			divElement.style.display = "block";
			divElement.style.visibility = "visible";

			if (!offsetX)
			{
				offsetX = 0;
			}
			if (!offsetY)
			{
				offsetY = 0;
			}

			x = x + offsetX;
			y = y + offsetY;


			if (!outofWindowAllowed)
			{
				x = this.GetPageXCoordinateAdjustedElementWithinWindow(x, divElement);
				y = this.GetPageYCoordinateAdjustedElementWithinWindow(y, divElement);

				//ensure we are always under the window (this will hook it up)
				if (divElement.onresize == null)
				{
					//IE is the only browser that supports the onresize, so use IE method to attach event handler
					//AddEventHandlerToElement(divElement, "onresize", function() { UITools.EnsureElementAndIFrameDisplayedWithinWindow(divElement, iframe) });
					//AddEventHandlerToElement(divElement, "onresize", function() { alert('in resize') }, true);

					divElement.onresize = function() { UITools.EnsureElementAndIFrameDisplayedWithinWindow(divElement, iframe) };
				}
			}


			/* if element is child of relative position
			var offsetParentX = 0;
			var offsetParentY = 0;
			if(divElement.offsetParent != null)
			{
			offsetParentX = UITools.GetPageXCoordinate(divElement.offsetParent);
			offsetParentY = UITools.GetPageYCoordinate(divElement.offsetParent);
			}
			x = x - offsetParentX;
			y = y - offsetParentY;
			*/

			divElement.style.left = x;
			divElement.style.top = y;



			//if an iframe was supplied then 
			if (iframe)
			{
				iframe = GetElementById(iframe);
			}

			if (iframe == null)
			{
				iframe = UITools.GetElementShim(divElement);
			}


			//i frame underneath so
			if (iframe != null)
			{
				//show the i frame under the div
				this.ShowIFrameUnderDiv(divElement, iframe);
			}


			//if the veil element was supplied then send it in.
			if (showVeil)
			{
				metafuseVeil.ShowVeilUnderElement(divElement, iframe);
			}

		}
		else
		{
			alert("Unable to locate the div specified in the UITools.ShowDivAndIFrameAtXY function");
		}

		return false;
	};
	//shows the i frame directly under the div
	this.ShowIFrameUnderDiv = function(divElement, iframe)
	{
		divElement = GetElementById(divElement);
		iframe = GetElementById(iframe);

		if (divElement && iframe)
		{
			iframe.display = "";



			iframe.style.width = divElement.offsetWidth;
			iframe.style.height = divElement.offsetHeight;

			//make sure the iframe gets sized with the div it is hiding under
			if (divElement.onresize == null)
			{
				divElement.onresize = function() { iframe.style.width = divElement.offsetWidth; iframe.style.height = divElement.offsetHeight; };
			}

			//var y = divElement.style.top;
			//if(!y)
			//{
			var y = this.GetPageYCoordinate(divElement);
			//}
			//var x = divElement.style.left;
			//if(!x)
			//{
			var x = this.GetPageXCoordinate(divElement);
			//}
			//x = this.GetPageXCoordinateAdjustedElementWithinWindow(x, divElement);
			//y = this.GetPageYCoordinateAdjustedElementWithinWindow(y, divElement);

			iframe.style.top = y;
			iframe.style.left = x;
			if (divElement.style.zIndex)
			{
				iframe.style.zIndex = divElement.style.zIndex - 1;
			}

			iframe.style.display = "";



		}
		else
		{
			alert("Unable to locate either the element or the div at specified in the UITools.ShowIFrameUnderDiv function");
		}
	};

	//ensures the element and i frame are displayed in the window
	this.EnsureElementAndIFrameDisplayedWithinWindow = function(element, iframe)
	{

		//window.status = new Date().valueOf();
		element = GetElementById(element);

		if (element)
		{

			var x = this.GetPageXCoordinate(element);
			var y = this.GetPageYCoordinate(element);

			var xC = this.GetPageXCoordinateAdjustedElementWithinWindow(x, element);
			var yC = this.GetPageYCoordinateAdjustedElementWithinWindow(y, element);

			if (x != xC)
			{
				element.style.left = xC;
			}
			if (y != yC)
			{
				element.style.top = yC;
			}

			iframe = GetElementById(iframe);
			if (iframe)
			{
				//make sure the sizes are correct
				iframe.style.width = element.offsetWidth;
				iframe.style.height = element.offsetHeight;
				if (x != xC)
				{
					iframe.style.left = xC;
				}
				if (y != yC)
				{
					iframe.style.top = yC;
				}

			}
		}
	};

	//gets the x coordinate adjusted element within the window
	this.GetPageXCoordinateAdjustedElementWithinWindow = function(x, element)
	{
		var scrollLeft = UITools.GetScrollLeft();
		var windowWidth = UITools.GetWindowWidth();

		//alert(x);
		//if we go too far right then move it back

		var xOver = (x + element.offsetWidth) - (windowWidth + scrollLeft);

		if (xOver > 0)
		{
			x = x - xOver;
		}
		//alert(xOver);
		//keep it from too far left second
		if (x < scrollLeft)
		{
			x = scrollLeft;
		}
		return x;
	};

	//gets the y coordinate adjusted element within the window
	this.GetPageYCoordinateAdjustedElementWithinWindow = function(y, element)
	{
		var scrollTop = UITools.GetScrollTop();
		var windowHeight = UITools.GetWindowHeight();

		//alert(y);
		//if we go too far down move it up
		var yOver = (y + element.offsetHeight) - (windowHeight + scrollTop);
		if (yOver > 0)
		{
			y = y - yOver;
		}
		//alert(yOver);
		//if we go to far up move it back down
		if (y < scrollTop)
		{
			y = scrollTop;
		}
		return y;
	};

	//hides the div and iframe (if ie)
	this.HideDivAndIFrame = function(divElement, iframe)
	{
		divElement = GetElementById(divElement);
		if (divElement)
		{
			divElement.style.display = "none";
		}
		if (BrowserTools.IsInternetExplorer() || this.AlwaysCreateShim)
		{
			iframe = GetElementById(iframe);

			//if no iframe supplied, get the shim
			if (iframe == null)
			{
				iframe = this.GetElementShim(divElement);
			}
			else
			{
				//temporary use this to help if one was supplied make sure that the shim is also done
				//in case the open method doesn't send the shim, but the close call does
				var iframeShim = this.GetElementShim(divElement);
				if (iframeShim)
				{
					iframeShim.style.width = 0;
					iframeShim.style.height = 0;
					iframeShim.style.display = "none";
				}
			}

			if (iframe)
			{
				iframe.style.width = 0;
				iframe.style.height = 0;
				iframe.style.display = "none";
			}
		}
		metafuseVeil.HideVeilUnderElement(divElement);

	};

	//gets the iframe that goes with a particular element takes the id the iframe should be
	//THIS is an older function the preferred method is to use GetElementShim(element) it takes the
	//element and creates a shim for that element
	this.GetIFrameForShim = function(iframeId)
	{
		var iframe = GetElementById(iframeId);

		if (iframe == null)
		{
			this.InsertHTML("<iframe id=\"" + iframeId + "\" src=\"javascript:false;\" scrolling=\"no\" frameborder=\"0\" style=\"position:absolute; top:0px; left:0px; display:none;\"></iframe>");
			iframe = GetElementById(iframeId);
		}
		return iframe;
	};

	this.AlwaysCreateShim = false;

	//preferred method to get a shim when necessary, handles naming for the element and
	//whether the browser even needs the shim.
	this.GetElementShim = function(element)
	{
		if (BrowserTools.IsInternetExplorer() || this.AlwaysCreateShim)
		{
			element = GetElementById(element);

			if (element == null)
			{
				return null;
			}
			else
			{
				return UITools.GetIFrameForShim(element.id + "_Shim_erspw");
			}
		}
		else
		{
			return null;
		}
	};

	/*
	//the method gets the element parent div that with the document body as the parent so that this
	//element can be dragged or positioned.  This essentially moves an element that starts as a child of a table or
	//other div that is not absolute positioned and moves it out into a div that has the body as the parent
	this.GetElementParentDivWithBodyAsParent = function(element)
	{
	//make sure we have the element handle
	element = GetElementById(element);

	//creates an outer div
	var outerDivId = element.id + "_OuterDiv_esqjizw";

	//see if we can get the element from the body, if not there then it's not there
	var outerDiv = GetElementById(outerDivId);

	if(outerDiv == null)
	{
	var outerDivHTML = "<div id=\"" + outerDivId + "\" style=\"position:absolute;z-index:801;display:none;\"></div>";
	UITools.InsertHTML(outerDivHTML);

	//get the object that was just inserted
	outerDiv = GetElementById(outerDivId);

	element.style.display = "block";
	element.style.visibility = "visible";

	//get the width and height of the edit form
	var height = element.offsetHeight;
	var width = element.offsetWidth;

	//STW I don't think this is necessary
	//element.parentNode.removeChild(element);// = null;

	//add the div to the outer div
	outerDiv.appendChild(element);
	outerDiv.style.height = height;
	outerDiv.style.width = width;
	//alert('here');
	}
	return outerDiv;
	};
	*/

	/*******************************************************************************
	Focus On Element, Toggle Display Etc
	********************************************************************************/
	this.FocusOnElement = function(elementToFocus)
	{
		var focusElement = GetElementById(elementToFocus);
		if (focusElement)
		{
			if (focusElement.style)
			{
				if (focusElement.style.display != "none")
				{
					try
					{
						focusElement.focus();
					}
					catch (e)
					{
					}
				}
			}

		}
	};


	//clicks an element (does not work in safari
	this.ClickElement = function(element)
	{

		element = GetElementById(element);

		if (element)
		{
			//if the browser is IE we can do this
			if (BrowserTools.IsInternetExplorer() || BrowserTools.IsSafari())
			{
				element.click();
			}
			else
			{

				var evt = document.createEvent('MouseEvents');

				try
				{
					evt.initMouseEvent('click', true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
					element.dispatchEvent(evt);
				}
				catch (ex)
				{
					try
					{
						element.click();
					}
					catch (ex2) { };
				};



			}
		}
	};

	//disables an element (tested on link button on TaskAddEdit)
	this.DisableElement = function(elementNameToDisable) { ToggleElementDisable(elementNameToDisable, false); };
	//enables an element (tested on link button on TaskAddEdit)
	this.EnableElement = function(elementNameToEnable) { ToggleElementDisable(elementNameToEnable, true); };
	this.ToggleElementDisable = function(elementName, enable)
	{
		var element = GetElementById(elementName);
		if (element)
		{
			if (enable)
			{

				if (element.tagName == "A" && (BrowserTools.IsInternetExplorer() == false || isUndefined(element.disabled) == true))
				{

					var href_previous = element.getAttribute("href_previous");
					if (href_previous && href_previous != null && href_previous != "")
					{
						element.setAttribute("href", href_previous);
					}

					var onclick_previous = element.getAttribute("onclick_previous");
					if (onclick_previous && onclick_previous != null && onclick_previous != "")
					{
						element.setAttribute("onclick", onclick_previous);
					}
					var onmousedown_previous = element.getAttribute("onmousedown_previous");
					if (onmousedown_previous && onmousedown_previous != null && onmousedown_previous != "")
					{
						element.setAttribute("onmousedown", onmousedown_previous);
					}
					var onmouseover_previous = element.getAttribute("onmouseover_previous");
					if (onmouseover_previous && onmouseover_previous != null && onmouseover_previous != "")
					{
						element.setAttribute("onmouseover", onmouseover_previous);
					}
					var color_previous = element.getAttribute("color_previous");
					if (color_previous && color_previous != null && color_previous != "")
					{
						element.style.color = color_previous;
					}
					else
					{
						element.style.color = "";
					}
				}
				else
				{
					if (isUndefined(element.disabled) == false)
					{
						element.disabled = false;
					}
				}

				//possibly add drill up you can drill up inside out and it works (checkbox control needs it).
			}
			else
			{

				if (element.tagName == "A" && (BrowserTools.IsInternetExplorer() == false || isUndefined(element.disabled) == true))
				{

					var href = element.getAttribute("href");
					if (href && href != null && href != "")
					{
						element.setAttribute("href_previous", href);
						element.setAttribute("href", "javascript:;");
					}

					var onclick = element.getAttribute("onclick");
					if (onclick && onclick != null && onclick != "")
					{
						element.setAttribute("onclick_previous", onclick);
						element.setAttribute("onclick", "void(0);");
					}
					var onmousedown = element.getAttribute("onmousedown");
					if (onmousedown && onmousedown != null && onmousedown != "")
					{
						element.setAttribute("onmousedown_previous", onmousedown);
						element.setAttribute("onmousedown", "return false;");
					}

					var onmouseover = element.getAttribute("onmouseover");
					if (onmouseover && onmouseover != null && onmouseover != "")
					{
						element.setAttribute("onmouseover_previous", onmouseover);
						element.setAttribute("onmouseover", "return false;");
					}

					if (element.style.color)
					{
						element.setAttribute("color_previous", element.style.color);
					}
					element.style.color = "gray";


				}
				else
				{
					if (isUndefined(element.disabled) == false)
					{
						element.disabled = true;
					}
				}

			}
		}
	};
	//toggle display of a layer
	this.ToggleDisplay = function(element, hide)
	{
		//make so we can use element or element id.
		element = GetElementById(element);

		if (element)
		{
			if (hide)
			{
				if (element.style.display == "" || element.style.display == "block")
				{
					element.style.display = "none";
				}
			}
			else
			{
				if (element.style.display == "none")
				{
					element.style.display = "";
				}
			}

			/*
			//if this is a checkbox, then toggle the label for the checkbox too
			var type = FormTools.GetFormElementType(element);
			if (type == "checkbox" && element.nextSibling && element.nextSibling.tagName == "LABEL")
			{
				UITools.ToggleDisplay(element.nextSibling, hide);
			}
			*/

		}
		return false;
	};


	//gets the key down 
	this.GetKeyDown = function(localEvent)
	{
		var keyCode =
			document.layers ? localEvent.which :
			document.all ? event.keyCode :
			document.getElementById ? localEvent.keyCode : 0;

		return keyCode;
	};


	//inserts html into the page
	this.InsertHTML = function(html)
	{
		if (html != null && html != "")
		{
			if (document.body && document.body.insertAdjacentHTML)
			{
				//document.body.insertAdjacentHTML('AfterBegin', html);
				//document.body.insertAdjacentHTML('BeforeBegin', html);
				//document.body.insertAdjacentHTML('AfterEnd', html);
				document.forms[0].insertAdjacentHTML('BeforeEnd', html);
			}
			else if (document.createRange)
			{
				var range = document.createRange();
				if (range.createContextualFragment)
				{
					range.selectNodeContents(document.body);
					var docFrag = range.createContextualFragment(html);
					document.forms[0].appendChild(docFrag);
				}
			}
			else if (document.layers)
			{
				var layer = new Layer(window.innerWidth);
				layer.document.open();
				layer.document.write(html);
				layer.document.close();
				layer.top = document.height;
				document.height += layer.document.height;
				layer.visibility = 'show';
			}
		}
	};

	//updates the inner html of the element.
	this.UpdateInnerHTML = function(element, html)
	{
		element = GetElementById(element);

		if (element)
		{
			element.innerHTML = html;
		}
	};
	this.UpdateOuterHTML = function(elementId, html)
	{
		UpdateOuterHTML(elementId, html);
	};


	this.CancelBubble = function(localEvent)
	{
		localEvent.cancelBubble = true;
		localEvent.returnValue = false;

		if (localEvent.stopPropagation)
		{
			localEvent.stopPropagation();
			localEvent.preventDefault();
		}

		return false;
	};

	//Drags an element (requires drag and drop libary present)
	//The MetafuseLayer control uses this method
	this.DragElement = function(localEvent, elementId)
	{
		var element = GetElementById(elementId);



		if (element.parentNode != "BODY" && element.parentNode != "FORM")
		{
			//make sure the element is shown where it is shown
			//if(element.style.top == null || element.style.left == null)
			//{
			this.ShowDivAndIFrameAtElement(element, element);
			//}
			element.parentNode.removeChild(element);
			document.forms[0].appendChild(element);
		}

		//__Dump(element, true);
		//__Dump(element.parentNode, true);
		//__Dump(element.parentNode.parentNode, true);

		var dragObject = new MetafuseGenericDragObject();
		dragObject.StartDrag(localEvent, GetElementById(elementId));
		return false;
	};

	//finds the first instance of the particular type of parent node for the element
	this.GetParentNodeByTagName = function(elementId, tagName)
	{
		var element = GetElementById(elementId);
		var parentNode = element;
		while (parentNode != null)
		{
			//if the node matches the tag name we're looking for (like a row)
			if (parentNode.nodeName == tagName)
			{
				return parentNode;
			}

			parentNode = parentNode.parentNode;
		}
		//if it can't be found then null
		return null;
	}



};
//construct the namespace and object
var UITools = new UITools();



//constructor for form tools
function FormTools()
{
	//updates the select options for a select input
	this.UpdateSelectOptions = function(selectClientID, selectListArray)
	{
		var selectElement = GetElementById(selectClientID);

		if (selectElement)
		{
			this.SelectOptionsClear(selectElement);

			if (selectListArray)
			{
				for (var i = 0; i < selectListArray.length; i++)
				{
					var e = selectListArray[i];
					var o = new Option(e.Text, e.Value);

					if (e.Selected == "true")
					{
						o.selected = true;
					}
					selectElement.options[selectElement.options.length] = o;
				}
			}
		}
	};

	this.SelectMultipleCheckNoneSelected = function(element)
	{
		element = GetElementById(element);
		if (element)
		{
			if (element.length)
			{
				if (element[0].selected == true)
				{
					for (var i = 1; i < element.length; i++)
					{
						element[i].selected = false;
					}
				}
			}
		}
	};

	//clears the select options
	this.SelectOptionsClear = function(selectElement, keepSelected)
	{
		selectElement = GetElementById(selectElement);

		if (selectElement)
		{
			var selectedExists = false;
			var i = 0;

			while (selectElement.options && selectElement.options.length > i)
			{

				if (keepSelected == true && selectElement.options[i].selected == true)
				{
					i += 1;
					continue;
				}
				else
				{
					selectElement.options[i] = null;
				}
			}
		}
	};
	//removes a single option from the select options returns if succesful or not
	this.SelectOptionsRemoveOption = function(selectElement, optionValue)
	{
		selectElement = GetElementById(selectElement);

		if (selectElement)
		{
			for (var i = 0; i < selectElement.options.length; i++)
			{
				var option = selectElement.options[i];

				if (option.value == optionValue)
				{
					selectElement.options[i] = null;
					return true;
					break;
				}
			}
		}
		return false;
	};

	this.GetFormElementType = function(element)
	{
		var type = null;

		if (element)
		{
			//get the type of element so we now how to get the form element value
			type = element.type;


			if (type == null)
			{
				if (element.length)
				{
					type = element[0].type;
				}
				else
				{
					if (element.nodeName == "DIV")
					{
						var comboBox = eval(element.id);
						if (comboBox.DropDownID)
						{
							type = "combobox";
						}
					}
				}
			}
		}

		return type;
	};

	this.GetFormElementValue = function(element)
	{

		var element = GetElementById(element);

		if (element)
		{
			//get the type of element so we now how to get the form element value
			var type = this.GetFormElementType(element);

			if (type == null)
			{
				elementForm = document.forms[0][element.id];

				type = this.GetFormElementType(elementForm);

				if (type == null)
				{

					alert("Unable to detect the type of form element for element id: " + element.id + " in GetFormElementValue");

				}
			}


			if (type == "select-multiple" || type == "select-one")
			{
				var values = "";


				//make this work with empty values
				if (element.options)
				{
					var useValue = true;

					if (element.options.length > 1)
					{
						var option1 = element.options[0];
						var option2 = element.options[1];

						if ((option1.value == null || option1.value == "") && (option2.value == null || option2.value == ""))
						{
							useValue = false;
						}
					}


					for (var i = 0; i < element.options.length; i++)
					{
						if (element.options[i].selected == true)
						{
							if (values.length > 0)
							{
								values += ",";
							}
							if (useValue)
							{
								values += element.options[i].value;
							}
							else
							{
								values += element.options[i].text;
							}
						}
					}
				}
				return values;
			}
			else if (type == "checkbox")
			{



				if (element.checked)
				{
					//2007-04-13 STW (this may not be the right thing to do but it is needed for multiple checkbox so the element would return the
					//value if one is specified.  
					if (element.value != null && element.value != "")
					{
						return element.value;
					}
					else
					{
						return "on";
					}
				}
			}
			else if (type == "radio")
			{
				//get the element by name so we can loop through it
				var radio = null;

				//newer firefox and safari use the same method as IE
				//if(BrowserTools.IsInternetExplorer())
				//{

				if (element.name)
				{
					var name = new String(element.name);
					radio = document.forms[0][name];
				}

				//try to get the radio by id
				if (radio == null)
				{
					radio = document.forms[0][element.id];
				}

				//if no radio
				if (radio == null)
				{
					//if we don't have an element either then return "" else try the element passed in
					if (element == null)
					{
						return "";
					}
					else
					{
						radio = element;
					}
					//element = document.forms[0][element.id];
				}

				if (radio)
				{
					if (radio.length == null)
					{
						if (radio.checked)
						{
							return radio.value;
						}
					}
					else
					{
						for (var i = 0; i < radio.length; i++)
						{
							var r = radio[i];

							if (r.checked)
							{
								return r.value;
							}
						}
					}
				}
			}
			//STW 2009-07-07 I don't believe we're using this anywhere, this was Telerik control
			else if (type == "combobox")
			{
				var comboBox = eval(element.id);

				var currentValue = comboBox.GetValue();

				if (currentValue == null)
				{
					currentValue = "";
				}

				//find out if all values are empty then return the text
				if (currentValue == null || currentValue == "" && comboBox.Items.length > 1)
				{
					var item1 = comboBox.Items[0];
					var item2 = comboBox.Items[1];

					if ((item1.Value == null || item1.Value == "") && (item2.Value == null || item2.Value == ""))
					{
						return comboBox.GetText();
					}
				}
				return currentValue;
			}
			else
			{
				return element.value;
			}
		}
		return "";
	};

	this.GetFormElementText = function(clientId)
	{
		element = GetElementById(clientId);

		if (element)
		{
			//get the type of element so we now how to get the form element value
			var type = this.GetFormElementType(element);


			if (type == null)
			{

				elementForm = document.forms[0][element.id];

				type = this.GetFormElementType(elementForm);

				if (type == null)
				{
					alert("Unable to detect the type of form element for element id: " + element.id + " in GetFormElementText");
				}
			}


			if (type == "select-multiple" || type == "select-one")
			{
				var values = "";

				if (element.options)
				{
					for (var i = 0; i < element.options.length; i++)
					{
						if (element.options[i].selected == true)
						{
							if (values.length > 0)
							{
								values += ", ";
							}
							values += element.options[i].text;
						}
					}
				}
				return values;
			}
			else if (type == "checkbox")
			{
				if (element.checked)
				{
					//2008-05-17 STW -- I copied this from GetFormElementValue -- may not be right for this as well
					//2007-04-13 STW (this may not be the right thing to do but it is needed for multiple checkbox so the element would return the
					//value if one is specified.  
					//if(element.value != null && element.value != "")
					//{
					//	return element.value;
					//}
					//else
					//{
					return "Yes";
					//}
				}
				else
				{
					return "No";
				}
			}

			else if (type == "radio")
			{
				//get the element by name so we can loop through it
				var radio = null;

				//newer firefox and safari use the same method as IE
				//if(BrowserTools.IsInternetExplorer())
				//{

				if (element.name)
				{
					var name = new String(element.name);
					radio = document.forms[0][name];
				}

				//try to get the radio by id
				if (radio == null)
				{
					radio = document.forms[0][element.id];
				}

				//if no radio
				if (radio == null)
				{
					//if we don't have an element either then return "" else try the element passed in
					if (element == null)
					{
						return "";
					}
					else
					{
						radio = element;
					}
					//element = document.forms[0][element.id];
				}

				if (radio)
				{
					var selectedRadio = null;

					if (radio.length == null)
					{
						if (radio.checked)
						{
							selectedRadio = radio;
						}
					}
					else
					{
						for (var i = 0; i < radio.length; i++)
						{
							var r = radio[i];

							if (r.checked)
							{
								selectedRadio = r;
							}
						}
					}

					if (selectedRadio != null && selectedRadio.parentNode != null)
					{
						var parentNode = selectedRadio.parentNode;

						var labels = parentNode.getElementsByTagName('label');

						if (labels != null && labels.length > 0)
						{
							return labels[0].innerHTML;
						}
						else
						{
							//couldn't find return value
							return this.GetFormElementValue(element);
						}

					}
					else
					{
						//couldn't find, so return value
						return this.GetFormElementValue(element);
					}

				}
			}


			/*STW 2009-07-08, I don't believe we're using the telerik combo box, which is what this would be */
			else if (type == "combobox")
			{
				var comboBox = eval(element.id);
				var text = comboBox.GetText();
				if (text == null)
				{
					text = "";
				}
				return text;
			}
			else
			{
				//get the form element value unless we can figure out the text
				return this.GetFormElementValue(element);
			}
		}
		return "";
	};

	this.GetFormElementOptionText = function(element, value)
	{
		element = GetElementById(element);
		if (element)
		{
			//get the type of element so we now how to get the form element value
			var type = this.GetFormElementType(element);


			if (type == null)
			{

				elementForm = document.forms[0][element.id];

				type = this.GetFormElementType(elementForm);

				if (type == null)
				{
					alert("Unable to detect the type of form element for element id: " + element.id + " in GetFormElementOptionText");
				}
			}

			if (type == "select-multiple" || "select-one")
			{


				if (element.options)
				{
					for (var i = 0; i < element.options.length; i++)
					{
						if (element.options[i].value.toString() == value.toString())
						{
							return element.options[i].text;
						}
					}
				}

			}
			else
			{
				alert("Unable to get the form element option text for the element supplied " + element.id + " type not supported in GetFormElementOptionText");
			}
		}
		return "";
	};

	//sets the form element value of any form element
	this.SetFormElementValue = function(clientId, value, dropDownSelectWithMatchingValueOrText)
	{

		if (value == null)
		{
			return false;
		}

		var element = GetElementById(clientId);

		var success = false;

		if (element)
		{
			//get the type of element so we now how to get the form element value
			var type = this.GetFormElementType(element);



			if (type == null)
			{
				elementForm = document.forms[0][element.id];

				type = this.GetFormElementType(elementForm);

				if (type == null)
				{
					alert("Unable to detect the type of form element for element id: " + element.id + " in GetFormElementValue");
					//__Dump(elementForm);
				}
			}



			if (type == "select-multiple")
			{
				//to-do do multiple set
				if (element.options.length)
				{

					var valueArray = value.split(",");

					for (var i = 0; i < element.options.length; i++)
					{

						var o = element.options[i];
						o.selected = false;
						for (var ii = 0; ii < valueArray.length; ii++)
						{
							if (o.value == valueArray[ii])
							{
								o.selected = true;
								success = true;
								break;
							}
							else if (o.value == "" && valueArray[ii] == "")
							{
								o.selected = true;
								success = true;
								break;
							}
						}

					}

				}

			}
			else if (type == "select-one")
			{

				if (element.options.length)
				{

					//select the drop down with the value
					var useValue = true;

					//if there is more than one element then this is important, if only one element, that element is selected by default
					if (element.options.length > 1)
					{
						var option1 = element.options[0];
						var option2 = element.options[1];

						//if neither the first nor second element has a value
						if ((option1.value == null || option1.value == "") && (option2.value == null || option2.value == ""))
						{
							useValue = false;
						}
					}

					//loop through the values to find selected ones
					for (var i = 0; i < element.options.length; i++)
					{
						var o = element.options[i];

						//using the value
						if (useValue)
						{

							if (o.value.toString() == value.toString())
							{
								o.selected = true;
								success = true;
							}
							else if (o.value == "" && value == "")
							{
								o.selected = true;
								success = true;
							}
							//if we're using the text or the value then see if the text matches the value, if so select
							//this is used by the MetafuseTable with CustomFields that have GUIDs in them, the metafuse table
							//outputs the text into the table, but the drop down for users, companies, groups etc have guids
							//used for the value property... which is what we want for selected, but to select it we want to match the text here
							else if (dropDownSelectWithMatchingValueOrText && o.text == value)
							{
								o.selected = true;
								success = true;
							}
							else
							{

								o.selected = false;
							}
						}
						else
						{

							if (o.text.toString() == value.toString())
							{
								o.selected = true;
								success = true;
							}
							else if (o.text == "" && value == "")
							{
								o.selected = true;
								success = true;
							}
							else
							{
								o.selected = false;
							}
						}
					}
				}
			}
			else if (type == "checkbox")
			{
				value = value.toLowerCase();

				if (value == "on" || value == "true" || value == "1" || value == "checked" || value == "yes" || value == "active")
				{
					element.checked = true;
					success = true;
				}
				else
				{
					element.checked = false;
					success = true;
				}
			}
			else if (type == "radio")
			{

				var radio = null;

				//STW 2006-12-28 
				//changed to reflect the GetFormElementValue method, safari and firefox now follow IE rules here
				if (element.name)
				{
					var name = new String(element.name);
					radio = document.forms[0][name];
				}

				if (radio == null)
				{
					//try to get the radio by id
					radio = document.forms[0][element.id];

					if (radio == null && element != null)
					{
						radio = element;
					}
				}

				if (radio)
				{
					if (radio.length == null)
					{
						if (radio.value == value)
						{
							radio.checked = true;
							success = true;
						}
					}
					else
					{
						for (var i = 0; i < radio.length; i++)
						{
							var r = radio[i];

							if (r.value == value)
							{
								r.checked = true;
								success = true;
							}
						}
					}
				}
			}
			else if (type == "combobox")
			{

				var radComboBox = eval(element.id);

				var comboItem;
				var useValue = true;

				if (radComboBox.Items.length > 1)
				{
					var item1 = radComboBox.Items[0];
					var item2 = radComboBox.Items[1];
					//if the first and second items don't have values then we aren't using values
					if ((item1.Value == null || item1.Value == "") && (item2.Value == null || item2.Value == ""))
					{
						useValue = false;
					}
				}


				if (value != "")
				{
					if (useValue)
					{
						comboItem = radComboBox.FindItemByValue(value);

						if (comboItem == null)
						{
							comboItem = radComboBox.FindItemByText(value);
						}
					}
					else
					{
						comboItem = radComboBox.FindItemByText(value);
					}


					//select the combo item
					if (comboItem != null)
					{
						comboItem.Select();
						success = true;
					}
				}
				else
				{
					var firstEmptyValue = null;
					var firstEmptyText = null;
					var multipleValuesEmpty = false;



					//since you can't select empty string in the combo box we need to find the first empty one
					for (var i = 0; i < radComboBox.Items.length; i++)
					{
						comboItem = radComboBox.Items[i];

						if (useValue)
						{
							if (comboItem.Value == null || comboItem.Value == "")
							{
								comboItem.Select();
								success = true;
								break;
							}
						}
						else
						{
							if (comboItem.Text == null || comboItem.Text == "")
							{
								comboItem.Select();
								success = true;
								break;
							}
						}
					}
				}


			}
			else
			{
				element.value = value;

				//element.value = value;
				success = true;
			}
		}


		return success;
	};

	//inserts the value and text from a control
	this.InsertFormElementValueAndText = function(elementId, value, text, defaultSelected, index)
	{
		var element = GetElementById(elementId);


		if (element)
		{
			//get the type of element so we now how to get the form element value
			var type = this.GetFormElementType(element);

			if (type == null)
			{
				elementForm = document.forms[0][element.id];

				type = this.GetFormElementType(elementForm);

				if (type == null)
				{
					alert("Unable to detect the type of form element for element id: " + element.id + " in GetFormElementValue");
					//__Dump(elementForm);
				}
			}
			//if(type == "select-multiple")
			//{
			//to-do do multiple set
			//	alert("The select value currently set is not in the list for the element id " + element.id + ".  The currently selected value \"" + value + "\" will not be able to be selected.");


			//}
			else if (type == "select-one" || type == "select-multiple")
			{

				var newOption = new Option(text, value);
				if (defaultSelected)
				{
					newOption.selected = true;
				}

				if (element.length > 0)
				{
					if (index == null || index < 0)
					{
						index = 0;
					}
					else if (index > element.length)
					{
						index = element.options.length;
					}

					var existingOption = element.options[index];

					try
					{
						element.add(newOption, existingOption);
					}
					catch (ex)
					{
						element.add(newOption, index);
					}

				}
				else
				{
					//add one to the end
					element.options[0] = newOption;
				}
			}
			/*
			else if(type == "combobox__notimplemented")
			{
			var radComboBox = eval(element.id);

				var useValue = true;

				if(radComboBox.Items.length > 1)
			{
			var item1 = radComboBox.Items[0];
			var item2 = radComboBox.Items[1];

					if((item1.Value == null || item1.Value == "") && (item2.Value == null || item2.Value == ""))
			{
			useValue = false;
			}
			}

				var radComboBoxItem = new RadComboBoxItem();

				radComboBoxItem.ComboBox = radComboBox;
			radComboBoxItem.Highlighted = true;
			radComboBoxItem.Index = radComboBox.Items.length;
			radComboBoxItem.Text = text;

				if(useValue)
			{
			radComboBoxItem.Value = value;
			}

				radComboBox.Items[radComboBox.Items.length] = radComboBoxItem;



			}
			*/
			else
			{
				alert("insert form field and text not implemented for element type: " + type + " id: " + element.id + " value: " + value + " text: " + text);
			}
		}
	};

	//removes the value and text from a control (select)
	this.RemoveFormElementValueAndText = function(elementId, value, text)
	{
		var element = GetElementById(elementId);

		if (element)
		{
			//get the type of element so we now how to get the form element value
			var type = this.GetFormElementType(element);

			if (type == null)
			{
				elementForm = document.forms[0][element.id];

				type = this.GetFormElementType(elementForm);

				if (type == null)
				{
					alert("Unable to detect the type of form element for element id: " + element.id + " in GetFormElementValue");
					//__Dump(elementForm);
				}
			}

			//if(type == "select-multiple")
			//{
			//alert("Need to add select multiple capabilities to remove form element value and text");
			//to-do do multiple set
			//}
			else if (type == "select-one" || type == "select-multiple")
			{
				var start = element.options.length - 1;
				for (var i = start; i >= 0; i--)
				{
					var o = element.options[i];

					if (o)
					{
						//if we have a value check the value
						if (value != null)
						{
							if (o.value != null && o.value == value)
							{
								element.options[i] = null;
							}
						}
						//if we have text but no value check the text 
						else if (text != null)
						{
							if (o.text != null && o.text == text)
							{
								element.options[i] = null;
							}
						}
					}
				}
			}
			else
			{
				alert("remove form field and text not implemented for element type: " + type);
			}
		}
	};

	//sets the value using set timeout so that the onchange will still be recongized (like user input)
	this.SetValueUsingSetTimeout = function(elementId, value)
	{

		var element = GetElementById(elementId);

		if (element)
		{
			var s = new String("");
			if (value)
			{
				s = value.toString();
			}
			//setTimeout("GetElementById('" + element.id + "').value=\"" + s.replace(/\"/g, "\\\"") + "\"", 0);
			setTimeout("FormTools.SetFormElementValue('" + element.id + "',\"" + s.replace(/\"/g, "\\\"") + "\")", 0);

		}
	};


	//focuses and clicks an element using set timeout (does not work with Safari)
	this.FocusAndClickElementUsingSetTimeout = function(element)
	{
		var element = GetElementById(element);
		if (element)
		{
			setTimeout("GetElementById('" + element.id + "').focus()", 0);
			//delay here so that javascript functions can get completed before submitting 
			//STW 2008-11-21 Changed timeout time to 300, from 500.
			setTimeout("UITools.ClickElement('" + element.id + "')", 300);
		}
	};



	/********************************************************************
	* Form Element Formatting (Ensure in Format called after onChange);
	*********************************************************************/

	//ensures that the element has a valid currency (normally text boxes)
	this.EnsureCurrency = function(element, blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale)
	{
		var value = FormTools.GetFormElementValue(element);

		//get the decimal string
		var currencyString = MathTools.FormatCurrencyString(value, !blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale);

		if (value != currencyString)
		{
			FormTools.SetValueUsingSetTimeout(element, currencyString);
		}
	};

	//ensures that the element has a valid currency (normally text boxes)
	this.EnsurePositiveCurrency = function(element, blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale)
	{
		var value = FormTools.GetFormElementValue(element);

		//get the decimal string
		var currencyString = MathTools.FormatCurrencyString(value, !blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale, true);

		if (value != currencyString)
		{
			FormTools.SetValueUsingSetTimeout(element, currencyString);
		}
	};

	//ensures the element input is a decimal (normally text boxes)
	this.EnsureDecimal = function(element, blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale)
	{
		//get the form element value
		var value = FormTools.GetFormElementValue(element);

		//get the decimal string
		var decimalString = MathTools.FormatDecimalString(value, !blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale);

		//if it's different then update it
		if (value != decimalString)
		{
			FormTools.SetValueUsingSetTimeout(element, decimalString);
		}

	};

	//ensures the element input is a positive decimal (normally text boxes)
	this.EnsurePositiveDecimal = function(element, blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale)
	{
		var value = FormTools.GetFormElementValue(element);

		//get the form element value
		var value = FormTools.GetFormElementValue(element);

		//get the decimal string
		var decimalString = MathTools.FormatDecimalString(value, !blankNotAllowed, excludeCommas, excludeLeadingZero, excludeTrailingZeros, scale, true);

		//if it's different then update it
		if (value != decimalString)
		{
			FormTools.SetValueUsingSetTimeout(element, decimalString);
		}
	};

	//ensures the element input is an integer (normally text boxes)
	this.EnsureInteger = function(element, blankNotAllowed, excludeCommas)
	{
		//get the form element value
		var value = FormTools.GetFormElementValue(element);

		//get the decimal string
		var integerString = MathTools.FormatDecimalString(value, !blankNotAllowed, excludeCommas, false, false, 0);

		//if it's different then update it
		if (value != integerString)
		{
			FormTools.SetValueUsingSetTimeout(element, integerString);
		}
	};

	//ensures the element input is a positive integer (normally text boxes)
	this.EnsurePositiveInteger = function(element, blankNotAllowed, excludeCommas)
	{
		//get the form element value
		var value = FormTools.GetFormElementValue(element);

		//get the decimal string
		var integerString = MathTools.FormatDecimalString(value, !blankNotAllowed, excludeCommas, false, false, 0, true);

		//if it's different then update it
		if (value != integerString)
		{
			FormTools.SetValueUsingSetTimeout(element, integerString);
		}
	};


	//ensures the element input is a percent (normally text boxes)
	this.EnsurePercent = function(element, blankNotAllowed, excludeLeadingZero, excludeTrailingZeros, scale)
	{
		var value = FormTools.GetFormElementValue(element);

		var percentString = MathTools.FormatPercentString(value, !blankNotAllowed, excludeLeadingZero, excludeTrailingZeros, scale);

		if (value != percentString)
		{
			FormTools.SetValueUsingSetTimeout(element, percentString);
		}
	};


	//moves the items in the list up
	this.SelectBoxMoveSelectedItemsUp = function(selectElement)
	{
		//get the select element
		selectElement = GetElementById(selectElement);
		var optionsToMove = new Array();
		var firstMoveOptionIndex = -1;
		var optionOrder = new Array();
		var optionMoved = false;

		for (var i = selectElement.options.length - 1; i >= 0; i--)
		{

			var currentOption = selectElement.options[i];

			if (currentOption.selected == true && (i > 0))
			{
				if (optionsToMove.length == 0)
				{
					firstMoveOptionIndex = i;
				}
				optionsToMove[optionsToMove.length] = currentOption;

			}
			else if (optionsToMove.length > 0)
			{
				optionMoved = true;
				optionOrder[optionOrder.length] = currentOption;

				for (var ii = 0; ii < optionsToMove.length; ii++)
				{
					optionOrder[optionOrder.length] = optionsToMove[ii];
				}

				//clear the options to move
				optionsToMove = new Array();
			}
			else
			{
				optionOrder[optionOrder.length] = currentOption;
			}
		}

		//if any were moved, rebind the list
		if (optionMoved == true)
		{
			while (selectElement.options.length > 0)
			{
				selectElement.options[0] = null;
			}
			for (var i = optionOrder.length - 1; i >= 0; i--)
			{
				selectElement.options[selectElement.options.length] = optionOrder[i];
			}
		}
	};


	this.SelectBoxMoveSelectedItemsDown = function(selectElement)
	{
		selectElement = GetElementById(selectElement);
		var optionsToMove = new Array();
		var firstMoveOptionIndex = -1;
		var optionOrder = new Array();
		var optionMoved = false;

		for (var i = 0; i < selectElement.options.length; i++)
		{

			var currentOption = selectElement.options[i];

			if (currentOption.selected == true && (i + 1 < selectElement.options.length))
			{
				if (optionsToMove.length == 0)
				{
					firstMoveOptionIndex = i;
				}
				optionsToMove[optionsToMove.length] = currentOption;

			}
			else if (optionsToMove.length > 0)
			{
				optionMoved = true;

				optionOrder[optionOrder.length] = currentOption;

				for (var ii = 0; ii < optionsToMove.length; ii++)
				{
					optionOrder[optionOrder.length] = optionsToMove[ii];
				}

				//clear the options to move
				optionsToMove = new Array();
			}
			else
			{
				optionOrder[optionOrder.length] = currentOption
			}
		}

		//if any were moved, rebind the list
		if (optionMoved == true)
		{
			while (selectElement.options.length > 0)
			{
				selectElement.options[0] = null;
			}
			for (var i = 0; i < optionOrder.length; i++)
			{
				selectElement.options[selectElement.options.length] = optionOrder[i];
			}
		}
	};

	//sorts a select box by the text as string
	this.SortSelectByTextAsString = function(selectElement)
	{
		selectElement = GetElementById(selectElement);
		if (selectElement.options.length > 1)
		{
			//load the array
			var a = new Array();
			for (var i = 0; i < selectElement.options.length; i++)
			{
				a[a.length] = selectElement.options[i];
			}

			//sort the array by text
			a.sort(FormTools.CompareSelectTextAsString);

			//clear the select box elements
			while (selectElement.options.length > 0)
			{
				selectElement.options[0] = null;
			}
			//add the sorted array back to the select	
			for (var i = 0; i < a.length; i++)
			{

				selectElement.options[selectElement.options.length] = a[i];
			}
		}
	};

	this.CompareSelectTextAsString = function(optionA, optionB)
	{
		// text comparison
		if (optionA.text == optionB.text)
		{
			return 0;
		}
		else
		{
			if (optionA.text < optionB.text)
			{
				return -1;
			}
			else
			{
				return 1;
			}
		}
	};

	this.Trim = function(stringToTrim)
	{
		return stringToTrim.replace(/^\s+|\s+$/g, "");
	};
	this.LTrim = function(stringToTrim)
	{
		return stringToTrim.replace(/^\s+/, "");
	};
	this.RTrim = function(stringToTrim)
	{
		return stringToTrim.replace(/\s+$/, "");
	};
	this.StripHTML = function(stringToStrip)
	{
		return stringToStrip.replace(/<[^<|>]+?>/gi, '').replace(/&gt;/gi, ">").replace(/&lt;/gi, "<").replace(/&amp;/gi, "&").replace(/&nbsp;/gi, " ");
	};

	//sets the checkbox label text dynamically.
	this.SetCheckboxLabelText = function(checkbox, text)
	{
		checkbox = GetElementById(checkbox);

		if (checkbox && FormTools.GetFormElementType(checkbox) == "checkbox" && checkbox.nextSibling && checkbox.nextSibling.tagName == "LABEL")
		{
			checkbox.nextSibling.innerHTML = text;
		}
	};

};

//create the form tools namespace
var FormTools = new FormTools();

/******************************************************
Utilities
*******************************************************/
function Utils()
{
	this.DateTime = new Utils.DateTime();
}
Utils.DateTime = function()
{
	//not really used other than attempting to determine the date data.
	//this.ShortDateFormat = "M/d/yyyy";

	this.GetDayOfWeekDescription = function(date)
	{
		date = new Date(date);
		var day = date.getDay();

		if (day == 0) { return "Sunday"; }
		else if (day == 1) { return "Monday"; }
		else if (day == 2) { return "Tuesday"; }
		else if (day == 3) { return "Wednesday"; }
		else if (day == 4) { return "Thursday"; }
		else if (day == 5) { return "Friday"; }
		else { return "Saturday"; }
	};
	this.AddDays = function(date, daysToAdd)
	{
		date = new Date(date);
		date.setDate(date.getDate() + 1);
		return date;
	};

};

var Utils = new Utils();


function BrowserTools()
{

	//detects if the browser is IE
	this.IsInternetExplorer = function()
	{
		if (navigator.userAgent.indexOf("MSIE") >= 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	};
	//detects if the browser is netscape
	this.IsNetscape = function()
	{
		if (this.IsSafari())
		{
			return false;
		}
		else if (this.IsFirefox())
		{
			return false;
		}
		else
		{
			if (navigator.appName.toLowerCase().indexOf("netscape") > -1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	};
	//detects if the browser is safari
	this.IsSafari = function()
	{
		if (navigator.userAgent.toLowerCase().indexOf("safari") > -1)
		{
			return true;
		}
		else
		{
			return false;
		}
	};
	this.IsFirefox = function()
	{
		if (navigator.userAgent.indexOf("Firefox") > -1)
		{
			return true;
		}
		else
		{
			return false;
		}
	};
	this.GetMajorVersion = function()
	{
		var userAgt = navigator.userAgent
		if (this.IsInternetExplorer())
		{

			var verOffset = userAgt.indexOf("MSIE");

			return parseFloat(userAgt.substring(verOffset + 5, userAgt.length));

		}
		else
		{
			alert("Unsupported for the browser");
		}
		return parseFloat(navigator.appVersion);
	};
};
var BrowserTools = new BrowserTools();


/***************************
//dump properties for dev
*****************************/
function __Dump(object, insertIntoPage)
{

	if (insertIntoPage)
	{
		InsertHTML("<p><textarea style=\"width:100%\" rows=\"10\">" + __GetObjectProperties(object) + "</textarea></p>");
	}
	else
	{
		alert(__GetObjectProperties(object));
	}
}

function __GetObjectProperties(obj)
{
	// Go through all the properties of the passed-in object 

	var properties = new String();

	for (var i in obj)
	{
		var msg = i + ": " + obj[i] + "\t";
		var msgString = new String();
		msgString = msg.toString()
		msgString = msgString.substring(0, 100);

		properties += msgString;
	}

	return properties;
}


/********************************************************
Veil Object
*********************************************************/

function MetafuseModalVeil()
{
	this.ElementQueue = null;
	this.VeilElement = null;
	this.VeilElementShim = null;
	this.VeilZIndex = 0;



	this.ShowVeilUnderElement = function(element, elementShim)
	{
		element = GetElementById(element)

		if (element)
		{
			//if the element is not queued then go ahead and set it
			if (this.ElementQueue == null)
			{
				this.ElementQueue = new Array();
				UITools.InsertHTML("<div id=\"metafuseVeilObjectDiv\" class=\"Veil\"></div>");
				this.VeilElement = GetElementById("metafuseVeilObjectDiv");

				/*
				if(BrowserTools.IsInternetExplorer())
				{
				this.InsertHTML("<iframe id=\"metafuseVeilObjectShim\" class=\"Veil\" allowtransparency=\"false\" scrolling=\"no\" frameborder=\"0\" style=\"position:absolute; top:0px; left:0px; display:none;\"></iframe>");
				this.VeilElementShim = GetElementById("metafuseVeilObjectShim");
				}
				*/

				//set resize 
				var self = this;
				OnWindowResizeFunctions.AddFunction(function() { self.SetDimensions(); });
				OnScrollFunctions.AddFunction(function() { self.SetDimensions(); });

				//set the veil size
				this.SetDimensions();



			}

			//see if the veil is already shown and if so, we need to make sure that the veil div element is above the veil.
			if (this.VeilElement != null && this.VeilElement.style.zIndex > element.style.zIndex)
			{
				var veilElementzIndex = this.VeilElement.style.zIndex + 5;

				element.style.zIndex = veilElementzIndex;

				if (elementShim)
				{
					elementShim.style.zIndex = veilElementzIndex - 1;
				}
			}


			//now set the veil z index and show it
			this.VeilElement.style.zIndex = element.style.zIndex - 2;
			this.VeilElement.style.display = "";

			if (this.VeilElementShim)
			{
				this.VeilElementShim.style.zIndex = this.VeilElement.style.zIndex - 1;
				this.VeilElementShim.style.display = "";
			}

			//add this element to the queue of elements that are 
			this.ElementQueue[this.ElementQueue.length] = element;


		}

	};

	this.HideVeilUnderElement = function(element)
	{

		if (this.ElementQueue != null)
		{

			var elementHadVeil = false;

			element = GetElementById(element);

			for (var i = 0; i < this.ElementQueue.length; i++)
			{
				if (this.ElementQueue[i].id == element.id)
				{
					this.ElementQueue.splice(i, 1);
					elementHadVeil = true;
					break;

				}
			}
			//if the element had a veil then move the veil down
			if (elementHadVeil)
			{
				//if there are elements that have shown the veil then keep the veil up
				if (this.ElementQueue.length > 0)
				{
					var lastElement = this.ElementQueue[this.ElementQueue.length - 1];
					this.VeilElement.style.zIndex = lastElement.style.zIndex - 1;
					if (this.VeilElementShim)
					{
						this.VeilElementShim.style.zIndex = this.VeilElement.style.zIndex - 1;
					}

				}
				else
				{
					//hide the veil, no elements using it
					this.VeilElement.style.display = "none";
					this.VeilElement.style.zIndex = 0;
					if (this.VeilElementShim)
					{
						this.VeilElementShim.style.display = "none";
						this.VeilElementShim.style.zIndex = 0;
					}
				}
			}

		}


	};

	this.SetDimensions = function()
	{
		if (this.VeilElement != null)
		{
			if (this.VeilElement.style.display == "")
			{
				var w = UITools.GetWindowWidth() + UITools.GetScrollLeft();
				var h = UITools.GetWindowHeight() + UITools.GetScrollTop();



				//if(this.VeilElement.offsetWidth < w)
				//{
				this.VeilElement.style.width = w;
				//}
				//if(this.VeilElement.offsetHeight < h)
				//{
				this.VeilElement.style.height = h;
				//}

				//window.status = "w: " + w + " h: " + h;

				//window.status = "scrollLeft: " + window.scrollLeft;
				if (this.VeilElementShim)
				{
					this.VeilElementShim.style.width = w;
					this.VeilElementShim.style.height = h;
				}

			}
		}
	};
};
//create the basic veil
var metafuseVeil = new MetafuseModalVeil();


/***************************************************
Depricated/Replaced Functions
****************************************************/


//REPLACED IN FORM TOOLS
//depricated use FormTools.SetValueUsingSetTimeout
function SetValueUsingSetTimeout(elementId, value) { FormTools.SetValueUsingSetTimeout(elementId, value); };
//depricated use FormTools.SelectOptionsClear
function SelectOptionsClear(selectElement, keepSelected) { FormTools.SelectOptionsClear(selectElement, keepSelected); };
//DEPRICATED Use FormTools.SelectMultipleCheckNoneSelected(element);
function ListBoxCheckNoneSelected(element) { FormTools.SelectMultipleCheckNoneSelected(element); };
//depricated use FormTools.FocusAndClickElementUsingSetTimeout(element);
function SubmitUsingSetTimeout(element) { FormTools.FocusAndClickElementUsingSetTimeout(element); };


//REPLACED IN UI TOOLS
//depricated use UITools.GetPageXCoordinate
function GetPageXCoordinate(element) { return UITools.GetPageXCoordinate(element); };
//depricated use UITools.GetPageYCoordinate
function GetPageYCoordinate(element) { return UITools.GetPageYCoordinate(element); };
//depricated use UITools.GetEventPageXCoordinate
function GetEventPageXCoordinate(localEvent) { return UITools.GetEventPageXCoordinate(localEvent); };
//depricated use UITools.GetEventPageYCoordinate
function GetEventPageYCoordinate(localEvent) { return UITools.GetEventPageYCoordinate(localEvent); };
//depricated use UITools.GetWindowHeight
function GetWindowHeight() { return UITools.GetWindowHeight(); };
//depricated use UITools.GetWindowWidth
function GetWindowWidth() { return UITools.GetWindowWidth(); };
//depricated use UITools.GetScrollLeft
function GetScrollLeft() { return UITools.GetScrollLeft(); };
//depricated use UITools.GetScrollTop
function GetScrollTop() { return UITools.GetScrollTop(); };
//depricated use UITools.ShowDivAndIFrameAtEvent
function ShowDivAndIFrameAtEvent(localEvent, divElement, iframe, offsetX, offsetY) { UITools.ShowDivAndIFrameAtEvent(localEvent, divElement, iframe, offsetX, offsetY); };
//depricated use UITools.ShowDivAndIFrameAtXY
function ShowDivAndIFrameAtXY(x, y, divElement, iframe, offsetX, offsetY) { UITools.ShowDivAndIFrameAtXY(x, y, divElement, iframe, offsetX, offsetY); };
//depricated use UITools.HideDivAndIFrame
function HideDivAndIFrame(divElement, iframe) { UITools.HideDivAndIFrame(divElement, iframe); };
//depricated use UITools.FocusOnElement
function FocusOnElement(elementToFocus) { UITools.FocusOnElement(elementToFocus); };
//depricated use UITools.DisableElement
function DisableElement(elementNameToDisable) { UITools.DisableElement(elementNameToDisable); };
//depricated use UITools.EnableElement
function EnableElement(elementNameToEnable) { UITools.EnableElement(elementNameToEnable); };
//depricated use UITools.ToggleElemenetDisable
function ToggleElementDisable(elementName, enable) { UITools.ToggleElementDisable(elementName, enable); };
//depricated use UITools.ToggleDisplay
function ToggleDisplay(element, hide) { return UITools.ToggleDisplay(element, hide); };
//depricated use UITools.InsertHTML
function InsertHTML(html) { UITools.InsertHTML(html); };


//REPLACED IN MathTools
//depricated use MathTools.IsNumeric
function IsNumeric(inputString) { return MathTools.IsNumeric(inputString); };
//depricated use MathTools.FormatCurrencyString
function FormatCurrency(num) { return MathTools.FormatCurrencyString(num); };
//depricated use MathTools.Round //notice the change from include trailing zeros to exclude trailing zeros
function Round(dNumber, iDecimalPlaces, includeTrailingZeros)
{
	if (iDecimalPlaces > 0 && !includeTrailingZeros)
	{
		alert("depricated functionality, check the function");
	}
	return MathTools.Round(dNumber, iDecimalPlaces);
};
//depricated use MathTools.IsEven
function IsEven(integer) { return MathTools.IsEven(integer); };
//depricated converts a number to a float or 0 if Nan
function ConvertToFloat(value) { return MathTools.ParseFloat(value); };
//depricated use MathTools.ParseFloat
function ParseFloatReturnsZeroIfNaN(inValue) { return MathTools.ParseFloat(inValue); };



//REPLACED IN BROWSER TOOLS
//depricated use BrowserTools.IsNetscape()
function IsNetscape() { return IsBrowserNetscape(); };
function IsBrowserNetscape() { return BrowserTools.IsNetscape(); };
//depricated use BrowserTools.IsSafari
function IsSafari() { return IsBrowserSafari(); };
function IsBrowserSafari() { return BrowserTools.IsSafari(); };
//depricated use BrowserTools.IsInternetExplorer
function IsBrowserInternetExplorer() { return BrowserTools.IsInternetExplorer(); };



/**********************************************************
Show/Hide Loading... Div (Move to Ajax Library??);
***********************************************************/
function ShowAjaxLoadingDiv(localEvent, offsetX, offsetY)
{
	alert("ShowAjaxLoadingDiv DEPRICATED");
	//ShowDivAndIFrameAtEvent(localEvent, GetElementById("AjaxLoadingDiv"),GetElementById("AjaxLoadingDivShim"), offsetX, offsetY);
};

function HideAjaxLoadingDiv()
{
	alert("HIDEAjaxLoadingDiv DEPRICATED");
	//HideDivAndIFrame(GetElementById("AjaxLoadingDiv"),GetElementById("AjaxLoadingDivShim"));
};


//DEPRICATED USE FormTools.EnsurePercent
function EnsurePercent(element, decimalPlaces)
{
	element = GetElementById(element);
	if (element)
	{
		var elementId = element.id;

		if (!decimalPlaces)
		{
			decimalPlaces = 2;
		}

		var v = new Number();
		v = parseFloat(element.value);

		if (v.toString() == "NaN")
		{
			SetValueUsingSetTimeout(elementId, "");
			return;
		}

		v = Round(v, decimalPlaces, true);

		if (v < 0)
		{
			SetValueUsingSetTimeout(elementId, "0");
		}
		else if (v > 100)
		{
			SetValueUsingSetTimeout(elementId, "100");
		}
		else if (v.toString() != element.value.toString())
		{
			SetValueUsingSetTimeout(elementId, v.toString());
		}
	}
};
