//**PUT EVERYTHING AFTER THIS IF STATEMENT**
if (window.imodules_common_loaded == null) { //Load first time only
window.imodules_common_loaded = true;

window.loaded = false;

function imod_DebugWrite(s, i) {
	if (window.__DebugWrite != null)
		__DebugWrite(s, i);
}

//this is stop an annoying error I only get on dev
if (window.generate_mainitems == null) {
	function generate_mainitems() {}
}


if (window.imod == null)
	var imod = {}; //new namespace to put stuff in

if (imod.Fancy == null)
	imod.Fancy = {}; //DHTML frillies

if (imod.Fancy.Handlers == null)
	imod.Fancy.Handlers = {};

if (imod.dom == null)
	imod.dom = {}; //DOM manipulation
	
imod.Browser = {}; //browser related stuff like size, cookies, querystring
imod.Browser.Request = {};
imod.Form = {};
imod.Element = {};
imod.General = {};

imod.General.StringBuilder = function () {
	var Items = new Array();
	
	this.Append = Append;
	this.ToString = ToString;
	
	function Append(s) {
		Items[Items.length++] = s;
	}
	
	function ToString() {
		return Items.join("");
	}
}

imod.Browser.ScreenWidth = function() {
	return screen.availWidth;
}

imod.Browser.ScreenHeight = function() {
	return screen.availHeight;
}

imod.Browser.ParseQuerystring = function() {
	var qs = {};
	var s = window.location.search.replace(/^\?/, "");
	var aryQS = s.split("&");
	for (var i = 0; i < aryQS.length; i++) {
		var aryPair = aryQS[i].split("=");
		qs[aryPair[0]] = aryPair[1];
	}
	return qs;
}
imod.Browser.Request.Querystring = imod.Browser.ParseQuerystring();
imod.Browser.Request.QueryString = imod.Browser.Request.Querystring;

imod.Browser.IE = (window.attachEvent != null);
imod.Browser.IE7 = false;
imod.Browser.IE6 = false;
if (imod.Browser.IE) {
	if (window.XMLHttpRequest) {
		imod.Browser.IE7 = true;
	}	
	else {
		imod.Browser.IE6 = true;
	}
}


imod.dom.DisableSelect = function(o) {
	o.style.MozUserSelect = "none";
	o.onselectstart = function() {
		return false;
	}
	o.unselectable = "on";
}

imod.dom.ConfirmPageExit = function(sPrmMessage, prmConfirmDelegate) {
	var f = function(e) {
		if (window.event != null) e = window.event;
		var bDoIt = true;
		if (prmConfirmDelegate != null)
			bDoIt = prmConfirmDelegate();
		if (bDoIt) {
			e.returnValue = sPrmMessage.replace(/<br[^>]*>/gi, "\n");
			e.cancelBubble = true;
		}
	}
	imod.dom.AddHandler(window, "beforeunload", f);
}


imod.dom.PreventDefault = function(e) {
	if (e.preventDefault != null)
		e.preventDefault();
	else
		window.event.returnValue = false;
}

imod.dom.DisableMouseSelect = function(o) {
	o.style.MozUserSelect = "none";
	o.onselectstart = function() { return false; };
}

imod.dom.GetSender = function(e) {
	if (e != null && e.target != null)
		return e.target;
	if (window.event != null && window.event.srcElement != null)
		return window.event.srcElement;
	return null;
}

imod.dom.InsertAfter = function(oPrmInsert, oPrmAfter) {
	if (oPrmAfter.nextSibling != null) {
		oPrmAfter.parentNode.insertBefore(oPrmInsert, oPrmAfter.nextSibling);
	}
	else {
		oPrmAfter.parentNode.appendChild(oPrmInsert);
	}
}

imod.dom.GenerateId = function(sPrmRoot) {
	var sRoot = sPrmRoot;
	var sId = null;
	if (sRoot == null)
		sRoot = "element";
	while (sId == null || $(sId) != null)
		sId = sRoot + Math.random().toString().replace(/\./gi, "");
	return sId;	
}

imod.dom.CenterElement = function(o) {
	var x = imod_ClientWidth() - o.offsetWidth;
	var y = imod_ClientHeight() - o.offsetHeight;

	o.style.left = imod.dom.MakePixel((x / 2) + imod.Browser.DocumentScrollLeft());
	o.style.top = imod.dom.MakePixel((y / 2) + imod.Browser.DocumentScrollTop());
}

imod.dom.PositionElement = function(o, iPrmX, iPrmY) {
	var x = iPrmX;
	var y = iPrmY;
	var w = o.offsetWidth;
	var h = o.offsetHeight;

	if (x + w > imod_ClientWidth() + imod_DocumentScrollLeft())
		x -= (x + w - imod_ClientWidth() - imod_DocumentScrollLeft());
	if (x < imod_DocumentScrollLeft())
		x = imod_DocumentScrollLeft();

	if (y + h > imod_ClientHeight() + imod_DocumentScrollTop())
		y -= (y + h - imod_ClientHeight() - imod_DocumentScrollTop());
	if (y < imod_DocumentScrollTop())
		y = imod_DocumentScrollTop();

	o.style.left = x + "px";
	o.style.top = y + "px";	
}

imod.Fancy.BouncyImage = function(o) {
	/*
	var div = document.createElement("span");
	var PaddingProperty = "padding";
	if (imod.Browser.IE)
		PaddingProperty = "margin";

	o.style[PaddingProperty] = "1px";

	o.onmouseover = function() {
		this.style[PaddingProperty] = "0px 2px 2px 0px";
	}
	
	o.onmouseout = function() {
		this.style[PaddingProperty] = "1px";
	}
	*/
}

imod.Fancy.GlobalFastTitle2 = function(oPrmRoot) {
		//alert("fast title2 disabled");
	var oRoot = oPrmRoot;
	if (oRoot == null)
		oRoot = document.body;
	
	imod.dom.AddHandler(oRoot, "mouseover", imod.Fancy.FastTitleHandler2);
	imod.dom.AddHandler(oRoot, "mouseout", imod.Fancy.FastTitleCloseHandler2);
	imod.dom.AddHandler(oRoot, "mousemove", imod.Fancy.FastTitleMoveHandler2);
	
	imod.Fancy.BuildFastTitleDiv();
}

imod.Fancy.FastTitleMoveHandler2 = function(e) {
	if (imod.Fancy.FastTitleOn) {
		imod.Fancy.ShowFastTitle(imod.Fancy.FastTitleCurrent, e);
	}
}

imod.Fancy.ShowFastTitle = function(sender, e) {
	if (sender.FastTitle != null) {
		var divFastTitle = $("divFastTitle55378008");
		var divFastTitleContent = $("divFastTitleContent55378008");
		var divShadow = $("divFastTitleShadow55378008");
		//sender.FastTitle = sender.title;
		//divFastTitle.innerHTML = sender.FastTitle;
		divFastTitleContent.innerHTML = sender.FastTitle;
		divFastTitle.style.display = "";
		//alert();
		
		var iOffsetY = 0;
		//alert(imod.dom.OffsetLeft(divFastTitle) + " + " + divFastTitle.offsetWidth);
		if (imod.Browser.MouseX(e) + 15 + divFastTitle.offsetWidth > imod_ClientWidth() + imod_DocumentScrollLeft())
			iOffsetY = 15


		imod.dom.PositionElement(divFastTitle, imod.Browser.MouseX(e) + 15, imod.Browser.MouseY(e) + iOffsetY);
		
		divShadow.style.width = divFastTitle.offsetWidth + "px";
		divShadow.style.height = divFastTitle.offsetHeight + "px";
		divShadow.style.display = "";
		
		imod.dom.PositionElement(divShadow, 3 + imod.dom.OffsetLeft(divFastTitle), 3 + imod.dom.OffsetTop(divFastTitle));
		//divShadow.style.left = (3 + imod.dom.OffsetLeft(divFastTitle)) + "px";
		//divShadow.style.top = (3 + imod.dom.OffsetTop(divFastTitle)) + "px";

	}
}

imod.Fancy.FastTitleHandler2 = function(e) {
	var sender = ((e.target != null) ? e.target : window.event.srcElement);
	if (! sender.FastTitleCached) {
		var oCurrent = sender;
		var bNotFound = true;
	
		while (bNotFound) {
			if (oCurrent == document || oCurrent == document.body) {
				sender.FastTitle = null;
				sender.title = "";
			}
			else {
				if (oCurrent.FastTitle != null)
					sender.FastTitle = oCurrent.FastTitle;
				else if (oCurrent.title != null && oCurrent.title.length > 0)
					sender.FastTitle = oCurrent.title;
				else if (oCurrent.alt != null && oCurrent.alt.length > 0)
					sender.FastTitle = oCurrent.alt;
				else {
					oCurrent = oCurrent.parentNode;
				}
			}
			if (sender.FastTitle != null || oCurrent == null || oCurrent == document.body) {
				bNotFound = false;
				if (oCurrent != null && oCurrent != document.body)
					oCurrent.title = "";
			}	
		}
		if (sender.FastTitle != null)
			sender.title = "";
		sender.FastTitleCached = true;
	}
	if (imod.Fancy.FastTitle != null) {
		imod.Fancy.FastTitleOn = true;
		imod.Fancy.FastTitleCurrent = sender;
		imod.Fancy.ShowFastTitle(sender, e);
	}
}

imod.Fancy.FastTitleCloseHandler2 = function(e) {
	if (imod.Fancy.FastTitleOn) {
		//alert("close start");
		var sender = ((e.target != null) ? this : window.event.srcElement);
		var divFastTitle = $("divFastTitle55378008");
		//sender.title = sender.FastTitle;
		divFastTitle.style.display = "none";
		$("divFastTitleShadow55378008").style.display = "none";
		imod.Fancy.FastTitleOn = false;
		imod.Fancy.FastTitleCurrent = null;
		//alert("close done");
	}
}

imod.Fancy.GlobalFastTitle = function(o) {
	//alert("fast title disabled");
	return;
	var oRoot = o;
	if (oRoot == null)
		oRoot = document.body;
	var aryElements = imod.dom.GetElementsByTagNames(oRoot, "img", "span", "a", "td", "div"); //"input", 
	for (var i = 0; i < aryElements.length; i++) {
		if (aryElements[i].title != null && aryElements[i].title.length > 0)
			imod.Fancy.FastTitle(aryElements[i]);
	}
	
}

imod.Fancy.BuildFastTitleDiv = function() {
	var divFastTitle = document.createElement("div");
	//var sSkin = "RoundedShadowBorder";
	//var w = "7px";
	//var h = "7px";
	var sSkin = "RoundedBorder";
	var w = "5px";
	var h = "5px";
	divFastTitle.id = "divFastTitle55378008";
	divFastTitle.style.position = "absolute";
	divFastTitle.style.display = "none";
	
	var t, r, c //table, row, cell
	var img;
	t = document.createElement("table");
	t.style.position = "";
	//t.style.position = "absolute";
	t.cellPadding = 0;
	t.cellSpacing = 0;
	t.border = 0;
	
	
	r = t.insertRow(0);
	
	c = r.insertCell(0);
	c.width = w;
	c.height = h;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/top-left.gif";
	c.appendChild(img);
	
	c = r.insertCell(1);
	c.height = h;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/top.gif";
	c.style.backgroundImage = "url(" + img.src + ")";
	//c.appendChild(document.createTextNode("a"));

	c = r.insertCell(2);
	c.width = w;
	c.height = h;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/top-right.gif";
	c.appendChild(img);
	


	r = t.insertRow(1);
	
	c = r.insertCell(0);
	c.height = h;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/left.gif";
	c.style.backgroundImage = "url(" + img.src + ")";
	//c.appendChild(document.createTextNode("a"));
		
	c = r.insertCell(1);
	var div = document.createElement("div");
	div.id = "divFastTitleContent55378008";
	c.appendChild(div);

	c = r.insertCell(2);
	c.height = h;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/right.gif";
	c.style.backgroundImage = "url(" + img.src + ")";
	//c.appendChild(document.createTextNode("a"));


	r = t.insertRow(2);
	
	c = r.insertCell(0);
	c.width = w;
	c.height = h;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/bottom-left.gif";
	c.appendChild(img);
	
	c = r.insertCell(1);
	c.height = h;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/bottom.gif";
	c.style.backgroundImage = "url(" + img.src + ")";
	//c.appendChild(document.createTextNode("a"));

	c = r.insertCell(2);
	c.width = w;
	c.height = h ;
	img = document.createElement("img");
	img.src = "/images/FastTitle/" + sSkin + "/bottom-right.gif";
	c.appendChild(img);
	
	//divFastTitle.className = "divFastTitle";
	divFastTitle.appendChild(t);
	document.body.appendChild(divFastTitle);
	
	//Shadow
	var divShadow = divFastTitle.cloneNode(true);
	document.body.appendChild(divShadow);
		
	var re = new RegExp(sSkin, "gi");
	//tShadow.innerHTML = tShadow.innerHTML.replace(re, sSkin + "/Shadow");
	divShadow.innerHTML = divShadow.innerHTML.replace(re, sSkin + "/Shadow");
	var tShadow = divShadow.firstChild;//t.cloneNode(true);
	tShadow.width = "100%";
	tShadow.height = "100%";

	
	//tShadow.style.position = "absolute";
	//tShadow.style.left = "3px";
	//tShadow.style.top = "3px";
	tShadow.rows[1].cells[1].firstChild.innerHTML = "&nbsp;";
	tShadow.rows[1].cells[1].firstChild.style.backgroundColor = "black";
	//tShadow.rows[1].cells[1].firstChild.id = "divFastTitleShadowContent55378008";
	//tShadow.id = "tableFastTitleShadow55378008";
	//imod.dom.SetOpacity(tShadow, .3);
	//divFastTitle.appendChild(tShadow);	
	imod.dom.SetOpacity(divShadow, .3);
	divShadow.id = "divFastTitleShadow55378008";
	divShadow.style.zIndex = "99999998";

	


	return divFastTitle;

}

imod.Fancy.FastTitle = function(o, s) {
	var divFastTitle = $("divFastTitle55378008");
	if (divFastTitle == null) {
		divFastTitle = imod.Fancy.BuildFastTitleDiv();
		//divFastTitle = document.createElement("div");
		//divFastTitle.id = "divFastTitle55378008";
		//divFastTitle.style.position = "absolute";
		//divFastTitle.style.display = "none";
		//divFastTitle.className = "divFastTitle";
		//document.body.appendChild(divFastTitle);
	}
	//var bNeedsHandlers = (o.FastTitle == null);

	if (o.FastTitle == null) {
		imod.dom.AddHandler(o, "mousemove", imod.Fancy.FastTitleHandler);
		imod.dom.AddHandler(o, "mouseout", imod.Fancy.FastTitleCloseHandler);
	}
	
	if (s == null) {
		if (o.title != null && o.title.length > 0)
			o.FastTitle = o.title;
		else 
			o.FastTitle = o.alt;
		o.title = "";
	}
	else {
		o.FastTitle = s;
	}
	o.FastTitleEnabled = true;
}

imod.Fancy.FastTitleHandler = function(e) {
	var sender = ((e.target != null) ? this : window.event.srcElement);
	if (sender.FastTitleEnabled) {
		var divFastTitle = $("divFastTitle55378008");
		var divFastTitleContent = $("divFastTitleContent55378008");
		var divShadow = $("divFastTitleShadow55378008");
		//sender.FastTitle = sender.title;
		//divFastTitle.innerHTML = sender.FastTitle;
		divFastTitleContent.innerHTML = sender.FastTitle;
		divFastTitle.style.display = "";
		//alert();
		
		var iOffsetY = 0;
		//alert(imod.dom.OffsetLeft(divFastTitle) + " + " + divFastTitle.offsetWidth);
		if (imod.Browser.MouseX(e) + 15 + divFastTitle.offsetWidth > imod_ClientWidth() + imod_DocumentScrollLeft())
			iOffsetY = 15
		imod.dom.PositionElement(divFastTitle, imod.Browser.MouseX(e) + 15, imod.Browser.MouseY(e) + iOffsetY);
		
		divShadow.style.left = (3 + imod.dom.OffsetLeft(divFastTitle)) + "px";
		divShadow.style.top = (3 + imod.dom.OffsetTop(divFastTitle)) + "px";
		divShadow.style.width = divFastTitle.offsetWidth + "px";
		divShadow.style.height = divFastTitle.offsetHeight + "px";
		divShadow.style.display = "";
	}	
	//sender.title = "";
}

imod.Fancy.FastTitleCloseHandler = function(e) {
	var sender = ((e.target != null) ? this : window.event.srcElement);
	var divFastTitle = $("divFastTitle55378008");
	//sender.title = sender.FastTitle;
	divFastTitle.style.display = "none";
	$("divFastTitleShadow55378008").style.display = "none";
}

imod.Fancy.MakeDraggable = function(oPrmDrag, oPrmTarget) {
	var oDrag = oPrmDrag;
	var oTarget = oPrmTarget;
	if (oTarget == null)
		oTarget = oDrag;

	imod.dom.DisableMouseSelect(oTarget);
	imod.dom.AddHandler(oTarget, "mousedown", MouseDown);
	imod.dom.AddHandler(document.body, "mousemove", MouseMove);
	imod.dom.AddHandler(document.body, "mouseup", MouseUp);
	
	function MouseDown(e) {
		oDrag.Dragging = true;
		oDrag.DragOffsetX = imod.Browser.MouseX(e) - imod.dom.OffsetLeft(oDrag);
		oDrag.DragOffsetY = imod.Browser.MouseY(e) - imod.dom.OffsetTop(oDrag);
	}
	
	function MouseMove(e) {
		if (oDrag.Dragging)
			imod.dom.PositionElement(oDrag, imod.Browser.MouseX(e) - oDrag.DragOffsetX, imod.Browser.MouseY(e) - oDrag.DragOffsetY);
	}
	
	function MouseUp() {
		oDrag.Dragging = false;
	}
}

imod.Fancy.MakeNifty = function(sPrmId, bPrmLoaded) {
	//alert("make nifty: " + $(sPrmId));
	imod_RemoveHandler(window, "load", imod.Fancy.MakeNifty_Check);
	imod_AddHandler(window, "load", imod.Fancy.MakeNifty_Check);
	if (bPrmLoaded) {
		Rounded("div#" + sPrmId, "all", "transparent", "#fff", "smooth border #ccc");
	}
	else
		imod_AddHandler(window, "load", function() { Rounded("div#" + sPrmId, "all", "transparent", "#fff", "smooth border #ccc"); });
	
}

imod.Fancy.MakeNifty_Check = function() {
	if (! NiftyCheck()) 
		return;
}

imod.Fancy.ActivateFancyInputFocus = function() {
	var inputs = null;
	if (arguments != null && arguments.length > 0)
		inputs = arguments;
	else
		inputs = imod_GetElementsByTagNames(document.body, "input", "textarea", "select");

	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type != "radio" && inputs[i].type != "checkbox" && inputs[i].type != "button" && inputs[i].type != "submit" && inputs[i].type != "reset") {
			imod_AddHandler(inputs[i], "focus", imod.Fancy.HighlightInput);
			imod_AddHandler(inputs[i], "blur", imod.Fancy.UnHighlightInput);
		}
	}
}

imod.Fancy.HighlightInput = function(e) {
	var sender = this;
	if (window.event != null) sender = window.event.srcElement;
	sender._backgroundColor = sender.style.backgroundColor;
	sender.style.backgroundColor = "beige";
}

imod.Fancy.UnHighlightInput = function(e) {
	var sender = this;
	if (window.event != null) sender = window.event.srcElement;
	if (sender._backgroundColor != null)
		sender.style.backgroundColor = sender._backgroundColor;
	else
		sender.style.backgroundColor = "";
}

imod.Fancy.ActivateFancyLabels = function() {
	var inputs = null;
	if (arguments != null && arguments.length > 0)
		inputs = arguments;
	else
		inputs = imod_GetElementsByTagNames(document.body, "input", "textarea", "select");
	//var inputs = imod_GetElementsByTagNames(document.body, "input", "textarea", "select");
	for (var i = 0; i < inputs.length; i++) {
		if (inputs[i].type != "checkbox" && inputs[i].type != "radio" && inputs[i].type != "button" && inputs[i].type != "submit" && inputs[i].type != "reset") {
			imod_AddHandler(inputs[i], "focus", imod.Fancy.HighlightInputLabel);
			imod_AddHandler(inputs[i], "blur", imod.Fancy.UnHighlightInputLabel);
		}
	}
}

imod.Fancy.HighlightInputLabel = function(e) {
	var sender = this;
	if (window.event != null) sender = window.event.srcElement;
	l = imod_GetLabelForInput(sender);
	if (l != null) {
		l._fontWeight = l.style.fontWeight;
		l.style.fontWeight = "bold";
	}
}

imod.Fancy.UnHighlightInputLabel = function(e) {
	var sender = this;
	if (window.event != null) sender = window.event.srcElement;
	l = imod_GetLabelForInput(sender);
	if (l != null) {
		if (l._fontWeight != null)
			l.style.fontWeight = l._fontWeight;
		else
			l.style.fontWeight = "";
	}
}

imod.Fancy.ActivateFancyCheckBoxes = function() {
	var cbs = imod_GetElementsByTagNames(document.body, "input");
	for (var i = 0; i < cbs.length; i++) {
		if (cbs[i].type == "checkbox") {
			imod_AddHandler(cbs[i], "click", imod.Fancy.Handlers.FancyRadioCheckBoxClickHandler);
			if (cbs[i].checked)
				imod.Fancy.SelectFancyCheckBox(cbs[i]);
		}
	}
}

imod.Fancy.ActivateFancyRadioButtons = function () {
	var rbs = imod_GetElementsByTagNames(document.body, "input");
	for (var i = 0; i < rbs.length; i++) {
		if (rbs[i].type == "radio") {
			imod_AddHandler(rbs[i], "click", imod.Fancy.Handlers.FancyRadioCheckBoxClickHandler);
			if (rbs[i].checked)
				imod.Fancy.SelectFancyCheckBox(rbs[i]);

		}
	}	
}

imod.Fancy.Handlers.FancyRadioCheckBoxClickHandler = function(e) {
	var sender = this;
	if (window.event != null) sender = window.event.srcElement;
	imod.Fancy.SelectFancyCheckBox(sender);
}

imod.Fancy.SelectFancyCheckBox = function(sender) {
	//var SelectedItemCssText = "text-decoration:underline;font-weight:bold;";
	var SelectedItemCssText = "font-weight:bold;";
	var l = null;
	if (sender.type == "radio") {
		var radios = document.forms[0].elements[sender.name];
		for (var i = 0; i < radios.length; i++) {
			l = imod_GetLabelForInput(radios[i]);
			if (l != null) {
				l.style.cssText = l.style._cssText;
			}	
		}
		
	}
	l = imod_GetLabelForInput(sender);
	if (l != null) {
		if (sender.checked) {
			l.style._cssText = l.style.cssText;
			l.style.cssText = SelectedItemCssText;
		}	
		else {
			l.style.cssText = l.style._cssText;
		}
	}
}

function imod_GetLabelForInput(o) {
	var labels = document.body.getElementsByTagName("label");
	for (var i = 0; i < labels.length; i++) {
		if (labels[i].htmlFor == o.id)
			return labels[i];
	}
	return null;

}

function imod_ParseInt(sPrmInt) {
	if (! isNaN(sPrmInt))
		return parseInt(sPrmInt);
	if (typeof(sPrmInt) == "string" && sPrmInt.length > 0) {
		var s = sPrmInt.split("");
		var sValid = "0123456789";
		var sSkip = ",-";
		var sInt = "";
		var bGetting = false;
		for (var i = 0; i < s.length; i++) {
			if (sValid.indexOf(s[i]) > -1) {
				sInt += s[i];
				bGetting = true;
			}
			else if (sSkip.indexOf(s[i]) > -1) {
				//do nothing
			}
			else {
				if (bGetting)
					break;
			}
		}
		if (s[0] == "-")
			sInt = "-" + sInt;
		if (! isNaN(sInt))
			return parseInt(sInt);
	}
	return 0;
}

function imod_GetRadioButtonValue(sPrmName) {
	var rbs = document.forms[0].elements[sPrmName];
	for (var i = 0; i < rbs.length; i++) {
		if (rbs[i].checked)
			return rbs[i].value;		
	}
	return null;
}


function imod_SetTableRowBackgroundColors(oPrmTable, sPrmColor, sPrmColorAlt, bPrmSkipHeader) {
	if (sPrmColor == null)
		sPrmColor = "#f7f6eb";
	if (sPrmColorAlt == null)
		sPrmColorAlt = "#e5e7d8";
	if (oPrmTable == null) {
		alert("imod_SetTableRowBackgroundColors::oPrmTable is null");
		return;
	}
	if (oPrmTable.rows == null) {
		alert("imod_SetTableRowBackgroundColors::oPrmTable is not a table");
		return;
	}
	var iStart = 0;
	if (bPrmSkipHeader)
		iStart = 1;
	for (var i = iStart; i < oPrmTable.rows.length; i++) {
		if (i % 2 == 0)
			oPrmTable.rows[i].style.backgroundColor = sPrmColor;
		else
			oPrmTable.rows[i].style.backgroundColor = sPrmColorAlt;
	}
}
imod.Fancy.SetTableRowBackgroundColors = imod_SetTableRowBackgroundColors;

function imod_Pixel(i) {
	if (isNaN(i) && i.indexOf != null && i.indexOf("px") > -1)
		return i;
	var s = i + "px";
	if (s == "px")
		s = "";

	return s;
}

function imod_ASCX(sPrmUniqueId) {
	var UniqueId;
	if (sPrmUniqueId) { SetUniqueId(sPrmUniqueId); }
	this.Verbiage = new imod_Verbiage();
	//this.Verbiage.Items = {};
	
	this.$ = GetElement;
	this.O = GetObject;
	
	this.SetUniqueId = SetUniqueId;
	
	/*
	this.Verbiage.Add = function(sPrmKey, sPrmValue) {
		this.Verbiage.Items[sPrmKey] = sPrmValue;
	}
	
	this.Verbiage.Get = function(sPrmKey) {
		if (this.Verbiage.Items[sPrmKey] == null)
			return sPrmKey;
		return this.Verbiage.Items[sPrmKey];
	}
	*/

	function SetUniqueId(sPrmUniqueId) {
		UniqueId = sPrmUniqueId.replace(/:/gi, "_");
	}
	
	function GetElement(sPrmId) {
		return $(UniqueId + "_" + sPrmId);
	}
	
	function GetObject(sPrmName) {
		return window[UniqueId + "_" + sPrmName];
	}
}

function imod_Verbiage() {
	var Items = {};
	
	this.Add = Add;
	this.Set = Add;
	this.Get = Get;
	
	function Add(sPrmKey, sPrmValue) {
		Items[sPrmKey] = sPrmValue;
	}
	
	function Get(sPrmKey) {
		if (Items[sPrmKey] == null)
			return sPrmKey;
		return Items[sPrmKey];

	}
}

function imod_CreateElement(sPrmElement, sPrmFrame) {
	var dummy = null;
	if (sPrmFrame != null) {
		if (sPrmElement.indexOf("<") > -1) {
			dummy = window.frames[sPrmFrame].document.createElement("div");
			dummy.innerHTML = sPrmElement;
			return dummy.firstChild;
		}
		return window.frames[sPrmFrame].document.createElement(sPrmElement);
	}
	else {
		if (sPrmElement.indexOf("<") > -1) {
			dummy = document.createElement("div");
			dummy.innerHTML = sPrmElement;
			return dummy.firstChild;
		}
		return document.createElement(sPrmElement);
	}
}

function $() {
	if (arguments.length == 0)
		return null;
	if (arguments.length == 1)
		return document.getElementById(arguments[0]);
	var aryReturn = new Array(arguments.length);
	for (var i = 0; i < arguments.length; i++)
		aryReturn[i] = document.getElementById(arguments[i]);
	return aryReturn;
}

function imod_ASCX$(sPrmId) {
	return $(this.UniqueId + "_" + sPrmId);
}

function imod_GetCookie(sPrmName, sPrmKey) {
	//alert(document.cookie);
	//alert("get cookie: " + sPrmName + " -> " + sPrmKey + " = " + document.cookie);
	var aryCookies = document.cookie.replace(/;\s/gi, ";").split(";");
	for (var i = 0; i < aryCookies.length; i++) {
		var sCookie = aryCookies[i];
		if (sCookie.indexOf(sPrmName + "=") == 0) {
			if (sPrmKey != null) {
				var sNewPairs = "";
				//var sValues = window.unescape(sCookie.substring(sPrmName.length + 1, sCookie.length));
				var sValues = sCookie.substring(sPrmName.length + 1, sCookie.length);
				var aryValues = sValues.split("&");
				for (var j = 0; j < aryValues.length; j++) {
					var sPair = aryValues[j];
					if (sPair.indexOf(sPrmKey + "=") == 0) {
						//alert("value: " + window.unescape(sPair.substring(sPrmKey.length + 1, sPair.length)));
						return window.unescape(sPair.substring(sPrmKey.length + 1, sPair.length));
					}
				}
			}
			else {
				//alert("value: " + window.unescape(sCookie.substring(sPrmName.length + 1, sCookie.length)));
				return window.unescape(sCookie.substring(sPrmName.length + 1, sCookie.length));
			}
		}
	}
	//alert("value: null");
	return null;
}

//Expiration NYI, Domain NYI
function imod_SetCookie(sPrmName, sPrmKey, sPrmValue, iPrmDaysToLive, sPrmDomain) {
	//var DateExpires = new Date("12/11/2009");
	var sDomain = "domain=" + window.location.host + ";";
	//var sExpires = "expires=" + DateExpires.toGMTString() + ";"; //" expires=;";
	var sPath = "path=/;"
	//var sCookieFooter = sExpires + sPath + sDomain;
	var sCookieFooter = sDomain;
	
	var aryCookies = document.cookie.replace(/;\s/gi, ";").split(";");
	for (var i = 0; i < aryCookies.length; i++) {
		var sCookie = aryCookies[i];
		if (sCookie.indexOf(sPrmName + "=") == 0) {
			var sNewPairs = "";
			var sValues = window.unescape(sCookie.substring(sPrmName.length + 1, sCookie.length));
			var aryValues = sValues.split("&");
			var bExists = false;
			for (var j = 0; j < aryValues.length; j++) {
				var sPair = aryValues[j];
				if (sPair.indexOf(sPrmKey + "=") == 0) {
					sNewPairs += "&" + sPrmKey + "=" + window.escape(sPrmValue);
					bExists = true;
				}
				else {
					sNewPairs += "&" + sPair;
				}
			}
			if (! bExists) {
				sNewPairs += "&" + sPrmKey + "=" + window.escape(sPrmValue);
			}
			if (sNewPairs.length > 0 && sNewPairs[0] == "&")
				sNewPairs = sNewPairs.substring(1);
			//document.cookie = sPrmName + "=" + window.escape(sNewPairs) + ";";
			//alert("write:\n" + sPrmName + "=" + sNewPairs + ";" + sCookieFooter);
			document.cookie = sPrmName + "=" + sNewPairs + ";" + sCookieFooter; // + " expires=" + DateExpires.toGMTString() + "; path=/";
			//alert(imod_GetCookie(sPrmName, sPrmKey));
			return;
		}
	}
	//document.cookie = sPrmName + "=" + window.escape(sPrmKey + "=" + window.escape(sPrmValue)) + ";";
	//alert("write:\n" + sPrmName + "=" + sPrmKey + "=" + window.escape(sPrmValue) + ";" + sCookieFooter);
	document.cookie = sPrmName + "=" + sPrmKey + "=" + window.escape(sPrmValue) + ";" + sCookieFooter; // + ";" + " expires=" + DateExpires.toGMTString() + "; path=/";
	//alert(imod_GetCookie(sPrmName, sPrmKey));
}

function imod_GetElementsByTagNames(oPrmTarget) {
	var aryReturn = new Array();
	for (var i = 1; i < arguments.length; i++) {
		var aryElements = oPrmTarget.getElementsByTagName(arguments[i]);
		for (var j = 0; j < aryElements.length; j++)
			aryReturn.push(aryElements[j]);
			//aryReturn[aryReturn.length++] = aryElements[j];
	}
	return aryReturn;
}

function imod_RollUp(sPrmId, iPrmDelay, iPrmAmount, prmDoneAction) {
	var Amount = iPrmAmount;
	var Delay = ((iPrmDelay != null) ? iPrmDelay : 35);
	var Done = false;
	var o = document.getElementById(sPrmId);
	o.style.display = "";
	var i = o.offsetHeight;
	if (Amount == null)
		Amount = i / 12;
	Deflate();
	
	function Deflate() {
		i -= Amount;
		if (i <= 0) {
			i = 0;
			Done = true;
		}
		o.style.height = i + "px";
		if (! Done) {
			setTimeout(Deflate, Delay);
		}
		else {
			o.style.display = "none";
			o.style.height = "";
			if (prmDoneAction != null)
				prmDoneAction();
		}	
	}
}

function imod_RollOut(sPrmId, iPrmDelay, iPrmAmount, prmDoneAction) {
	var Amount = iPrmAmount;
	var Delay = ((iPrmDelay != null) ? iPrmDelay : 35);
	var i = 0;
	var Done = false;
	var o = document.getElementById(sPrmId);
	o.style.visibility = "hidden";
	o.style.display = "";
	var Max = o.offsetHeight;
	if (Amount == null)
		Amount = Max / 12;
	o.style.height = "0px";
	o.style.visibility = "visible";
	Expand();
	
	function Expand() {
		i += Amount;
		if (i >= Max) {
			i = Max;
			Done = true;
		}
		o.style.height = i + "px";
		if (! Done) {
			setTimeout(Expand, Delay);
		}
		else {
			if (prmDoneAction != null)
				prmDoneAction();
		}
	}
}

function imod_SetOpacity(o, iPrmOpacity) {
	if (iPrmOpacity != null) {
		o.style.opacity = iPrmOpacity;
		o.style.MozOpacity = iPrmOpacity;
		o.style.filter = "alpha(opacity=" + iPrmOpacity * 100 + ")";
	}
	else {
		o.style.opacity = "";
		o.style.MozOpacity = "";
		o.style.filter = "";
	}	
}

function imod_IsPaired(sPrmTagName) {
	switch(sPrmTagName) {
		case "br":
		case "hr":
		case "input":
		case "link":
		case "img":
			return false;
	}
	return true;
}


function imod_GetHTML(o, bPrmInnerOnly) {
	var ProcessedKey = Math.random();
	return imod_GetHTML_R(o, bPrmInnerOnly, ProcessedKey);
}

function imod_GetHTML_R(o, bPrmInnerOnly, prmProcessedKey) {
	var s = "";
	if (o.HeyIEThisHasBeenProcessed == prmProcessedKey) {
		//o.HeyIEThisHasBeenProcessed = null; //Hoping this only gets duped once
		return "";
	}
	else {	
		if (o.tagName != null) {
			var sTag = o.tagName.toLowerCase();
			var bPaired = imod_IsPaired(sTag);
			if (! bPrmInnerOnly) {
				s += "<" + sTag;
				if (o.attributes != null) {
					for (var i = 0; i < o.attributes.length; i++) {
						if ((o.attributes[i].nodeValue != null && o.attributes[i].nodeValue != "" && typeof(o.attributes[i].nodeValue) != "object") || (o.attributes[i].nodeName.toLowerCase() == "style" && o.style.cssText.length > 0)) {
							if (o.attributes[i].specified == null || o.attributes[i].specified == true || (o.attributes[i].nodeName.toLowerCase() == "style" && o.style.cssText.length > 0)) {
								switch (o.attributes[i].nodeName.toLowerCase()) {
									case "fasttitle": //Exclude these attributes because IE is stupid
									case "fasttitlecached":
									case "heyiethishasbeenprocessed":
										break;
									default:
										s += " " + o.attributes[i].nodeName.toLowerCase() + "=\"";
										if (o.attributes[i].nodeName.toLowerCase() == "style") //IE hack
											s += o.style.cssText;
										else
											s += o.attributes[i].nodeValue;
										s += "\"";
										break;
								}
							}	
						}
					}
				}
			}
			o.HeyIEThisHasBeenProcessed = prmProcessedKey;
			if (! bPaired) {
				s += " />";
			}
			else {
				if (! bPrmInnerOnly)
					s += ">";
				if (o.text != null && window.attachEvent != null) //IE hack
					if (! bPrmInnerOnly)
						s += o.text;
				if (o.childNodes != null) {
					for (var i = 0; i < o.childNodes.length; i++)
						s += imod_GetHTML_R(o.childNodes[i], false, prmProcessedKey);
				}
				if (! bPrmInnerOnly)
					s += "</" + sTag + ">";
			}
			//imod_DebugWrite("DONE: " + sTag);
		}
		else {
			s += o.data;
		}
		return s;
	}
}

function imod_SelectText(oPrmContainer, sPrmTextProperty) {
	if (oPrmContainer.setSelectionRange != null) {
		oPrmContainer.setSelectionRange(0, oPrmContainer[sPrmTextProperty].length);
	}
	else if (oPrmContainer.createTextRange != null) {
		var oRange = oPrmContainer.createTextRange();		
		oRange.moveStart("character", 0);
		oRange.moveEnd("character", oPrmContainer[sPrmTextProperty].length);
		oRange.select();
	}
	else {
		alert("Element does not support selecting text");	
	}
}

function imod_RemoveChildNodes(o) {
	//you will lose your events and custom properties.
	//Proper usage: foo = imod_RemoveChildNodes(foo);
	//This is due to how JS handles pointers in method parameters.
	var oReturn = o.cloneNode(false);
	o.parentNode.replaceChild(oReturn, o);
	return oReturn;
}

function imod_StopPropagation(e, sPrmFrameName) {
	//Stops events from bubbling up.
	//e: the event object.  Currently needed for Mozilla
	//sPrmFrameName:  If you are stopping propagation of an event in a frame by a method declared outside the frame
	//	this should be set so in IE it knows which event object to use.
	if (e == null) {
		if (sPrmFrameName != null)
			e = window.frames[sPrmFrameName].event;
		else
			e = window.event;
	}
	if (e.stopPropagation != null) {
		e.stopPropagation();
	}	
	else {
		e.cancelBubble = true;
	}
}

function imod_ResizeTreeView(sPrmClientId, prmWidth, prmHeight) {
	//Quick and convient way to resize a RadTreeView clientside.
	var tv = document.getElementById(sPrmClient);
	if (tv == null)
		tv = document.getElementById(sPrmClientId + "Div");
	if (prmWidth != null)
		tv.style.width = prmWidth + "px";
	if (prmHeight != null)
		tv.style.height = prmHeight + "px";
}

function imod_Alert(sPrmMessage, sPrmTitle, iPrmButtons) {
	//Create a div based window alert message.
	//Requires the following CSS classes: IModAlert, IModAlertTitle, IModAlertMessage.
	//sPrmMessage: The message body
	//sPrmTitle: alert title, optional, but looks ugly without it.
	//iPrmButtons: NYI
	var divAlert = document.createElement("div");
	//var sID = "divAlert" + Math.random();
	//divAlert.id = sID;
	divAlert.className = "IModAlert";
	if (sPrmTitle != null) {
		var divTitle = document.createElement("div");
		divTitle.className = "IModAlertTitle";
		divTitle.innerHTML = sPrmTitle;
		divAlert.appendChild(divTitle);
	}
	var divMessage = document.createElement("div");
	divMessage.innerHTML = sPrmMessage;
	divMessage.className = "IModAlertMessage";
	divAlert.appendChild(divMessage);
	divAlert.appendChild(document.createElement("br"));
	var btnOkay = document.createElement("input");
	btnOkay.type = "button";
	btnOkay.className = "button";
	btnOkay.value = "Okay";
	btnOkay.style.textAlign = "center";
	btnOkay.onclick = function() {
		if (divAlert != null)
			document.body.removeChild(divAlert);
	}
	divAlert.appendChild(btnOkay);
	
	divAlert.style.zIndex = -9999;
	document.body.appendChild(divAlert);
	var x = (document.body.offsetWidth - 300) / 2;
	var y = (imod_ClientHeight() - divAlert.offsetHeight) / 2;
	divAlert.style.left = x + "px";
	divAlert.style.top = y + "px";
	divAlert.style.zIndex = 9999;
	btnOkay.focus();

	return divAlert;
}

//iPrmCenterMode: 0 - none, 1 - browser, 2 = screen, null - none, 3 = full screen
function imod_OpenWindow(sPrmUrl, iPrmWidth, iPrmHeight, sPrmWindowProperties, iPrmCenterMode, iPrmLeft, iPrmTop) {
	var sWindowProperties = "";
	if (iPrmCenterMode == 3)
		sWindowProperties = "width=" + imod.Browser.ScreenWidth() + ",height=" + imod.Browser.ScreenHeight();
	else
		sWindowProperties = "width=" + iPrmWidth + ",height=" + iPrmHeight;
	if (sPrmWindowProperties != null && sPrmWindowProperties.length > 0)
		sWindowProperties += "," + sPrmWindowProperties;
		
	if (iPrmCenterMode != null) {
		if (iPrmCenterMode == true)
			iPrmCenterMode = 1;
		else if (iPrmCenterMode == false)
			iPrmCenterMode = 2;
	}
	if (iPrmCenterMode != null && iPrmCenterMode != 0) {
		var x = 0;
		var y = 0;
		switch (iPrmCenterMode) {
			case 1: //browser
				x = (document.body.clientWidth - iPrmWidth) / 2;
				y = (imod_ClientHeight() - iPrmHeight) /2;
				if (window.screenX != null) {
					x += window.screenX;
					y += window.screenY;
				}
				else if (window.screenLeft != null) {
					x += window.screenLeft;
					y += window.screenTop;
				}
				break;
			case 2: //
				x = (screen.availWidth - iPrmWidth) / 2;
				y = (screen.availHeight - iPrmHeight) /2;
				break;
		}
		if (x < 0)
			x = 0;
		if (y < 0)
			y = 0;
		sWindowProperties += ",left=" + x + ",top=" + y;
	}
	else {
		if (iPrmLeft != null)
			sWindowProperties += ",left=" + iPrmLeft;
		if (iPrmTop != null)
			sWindowProperties += ",top=" + iPrmTop;
	}
	return window.open(sPrmUrl, "", sWindowProperties);
}

function imod_ClientHeight() {
	//Get the avaialable height inside the browser window.  Avoids a bug in Mozilla.
	/*
	if (self != null && self.innerHeight != null)
		return self.innerHeight;
	if (document.documentElement != null && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	return document.body.clientHeight;
	*/
	if (document.documentElement != null && document.documentElement.clientHeight && document.documentElement.clientHeight != document.documentElement.scrollHeight)
		return document.documentElement.clientHeight;
	if (document.body.clientHeight)
		return document.body.clientHeight;
	if (self != null && self.innerHeight != null)
		return self.innerHeight;
	return document.body.clientHeight;

}

function imod_ClientWidth() {
	/*
	if (self != null && self.innerWidth != null)
		return self.innerWidth;
	if (document.documentElement != null && document.documentElement.clientWidth)
		return document.documentElement.clientWidth;
	return document.body.clientWidth;
	*/
	if (document.documentElement != null && document.documentElement.clientWidth && document.documentElement.clientWidth != document.documentElement.scrollWidth)
		return document.documentElement.clientWidth;
	if (document.body.clientWidth)
		return document.body.clientWidth;
	if (self != null && self.innerWidth != null)
		return self.innerWidth;
	return document.body.clientWidth;
}


function imod_Bool(sPrmBool) {
	//Convert sPrmBool to boolean true or false.
	switch (sPrmBool) {
		case "true":
		case "True":
		case "T":
		case "t":
		case "1":
		case "-1":
		case true:
		case 1:
		case -1:
			return true;
	}
	return false;
}

function imod_VerticalScrollBarWidth() {
	var iScrollHeight = 0;
	if (document.documentElement != null && document.documentElement.scrollHeight)
		iScrollHeight = document.documentElement.scrollHeight;
	else
		iScrollHeight = document.body.scrollHeight;
	if (iScrollHeight != imod_ClientHeight())
		return 16;
	return 0;
}

function imod_HorizontalScrollBarHeight() {
	var iScrollWidth = 0;
	if (document.documentElement != null && document.documentElement.scrollWidth)
		iScrollWidth = document.documentElement.scrollWidth;
	else
		iScrollWidth = document.body.scrollWidth;
	//alert();
	//alert(iScrollWidth + " != " + imod_ClientWidth());
	if (iScrollWidth != imod_ClientWidth())
		return 16;
	return 0;
}

//Methods for the pixel location of elements on a page.  These versions attempt to factor in scroll offsets.
function imod_DocumentScrollTop(iPrmScroll) {
	if (iPrmScroll != null) {
		if (document.documentElement != null && document.documentElement.scrollTop != null)
			document.documentElement.scrollTop += iPrmScroll;
		document.body.scrollTop += iPrmScroll;
	}
	if (document.documentElement != null && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	return document.body.scrollTop;
}

function imod_DocumentScrollLeft(iPrmScroll) {
	if (iPrmScroll != null) {
		if (document.documentElement != null && document.documentElement.scrollLeft != null)
			document.documentElement.scrollLeft += iPrmScroll;
		document.body.scrollLeft += iPrmScroll;
	}
	if (document.documentElement != null && document.documentElement.scrollLeft)
		return document.documentElement.scrollLeft;
	return document.body.scrollLeft;
}

function imod_OffsetLeft(o) {
	//Get the exact left pixel position of element o.
	var iReturn = 0;
	var iOffset = imod_ScrollLeft(o);
	while (o != null) { //while (o.offsetParent) {
		iReturn += o.offsetLeft;
		o = o.offsetParent;
	}
	if (document.documentElement != null && document.documentElement.scrollLeft)
		iReturn += document.documentElement.scrollLeft;
	return iReturn - iOffset;
}

function imod_OffsetTop(o) {
	//Get the exact top pixel position of element o.
	var iReturn = 0;
	var iOffset = imod_ScrollTop(o);
	while (o != null) { //while (o.offsetParent) {
		iReturn += o.offsetTop;
		o = o.offsetParent;
	}
	if (document.documentElement != null && document.documentElement.scrollTop)
		iReturn += document.documentElement.scrollTop;
	return iReturn - iOffset;
}

imod.dom.OffsetPosition = function(o) {
	var x = 0;
	var y = 0;
	while (o != null) {
		x += o.offsetLeft;
		y += o.offsetTop;
		o = o.offsetParent;
	}
	return {"x":x, "y":y};
}

function imod_MouseX(e) {
	if (e.clientX != null)
		return e.clientX + imod_DocumentScrollLeft();
	else if (e.pageX != null)
		return e.pageX;
	else if (e.x != null)
		return e.x + imod_DocumentScrollLeft();
	return 0;
}

function imod_MouseY(e) {
	if (e.clientY != null)
		return e.clientY + imod_DocumentScrollTop();
	else if (e.pageY != null)
		return e.pageY;
	else if (e.y != null)
		return e.y + imod_DocumentScrollTop();
	return 0;
}

function imod_ScrollLeft(o) {
	var iReturn = 0;
	while (o.parentNode) {
		if (o.parentNode.scrollLeft)
			if (o.parentNode != document.body) //don't factor window scroll bars
				iReturn += o.parentNode.scrollLeft;
		o = o.parentNode;
	}
	return iReturn;
}

function imod_ScrollTop(o) {
	var iReturn = 0;
	if (o != null) {
		while (o.parentNode) {
			if (o.parentNode.scrollTop)
				if (o.parentNode != document.body) //don't factor window scroll bars
					iReturn += o.parentNode.scrollTop;
			o = o.parentNode;
		}
	}
	return iReturn;
}

//Methods to add/remove event handlers
if (window.EventHandlers == null)
	var EventHandlers = new Array();

var LogHandlers = true;
function imod_ReportHandlers() {
	alert("Handlers: " + EventHandlers.length);
}

function imod_HandlerCleanUp() {
	//alert("removing " + EventHandlers.length + " handlers");
	for (var i = 0; i < EventHandlers.length; i++) {
		if (EventHandlers[i].Event != "unload") {
			imod_RemoveHandler(EventHandlers[i].Object, EventHandlers[i].Event, EventHandlers[i].Handler);
			EventHandlers[i].Object = null;
			EventHandlers[i].Handler = null;
			EventHandlers[i] = null;
		}
	}
	EventHandlers = null;
	imod_RemoveHandler(window, "unload", imod_HandlerCleanUp);
	
	//Remove everything!
	/*
	var aryEvents = new Array("click", "mouseover", "mouseout", "mousedown", "mouseup", "mousemove");
	for (var i = 0; i < document.all.length; i++) {
		for (var j = 0; j < aryEvents.length; j++)
			imod_RemoveHandler(document.all[i], aryEvents[j]);
	}
	*/
	//alert("done");
}

function imod_RemoveHandlersOnUnload() {
	imod_AddHandler(window, "unload", imod_HandlerCleanUp);
}

imod.dom.AddHandler2 = function(o, sPrmEvent, prmMethod, bPrmOnCapture) {
	var f = function(e) {
		if (window.event != null) e = window.event;
		var target = e.target;
		if (target == null && e.srcElement != null)
			target = e.srcElement;
		prmMethod(o, e, target);
	}
	imod.dom.AddHandler(o, sPrmEvent, f, bPrmOnCapture);
}

function imod_AddHandler(o, sPrmEvent, functionDelegate, bPrmOnCapture) {
	var bOnCapture = false;
	if (bPrmOnCapture) bOnCapture = true;
	bReturn = false;
	if (o) {
		if (o.addEventListener != null) {
			o.addEventListener(sPrmEvent, functionDelegate, bOnCapture);
			bReturn = true;
		}
		else if (o.attachEvent) {
			o.attachEvent("on" + sPrmEvent, functionDelegate);
			bReturn = true;
		}
		else {
			/*
			o["on" + sPrmEvent] = function(e) {
				if (o["on" + sPrmEvent] != null)
					o["on" + sPrmEvent](e);
				functionDelegate(e);
			}
			*/
		}
	} // o is not null
	if (LogHandlers)
		EventHandlers[EventHandlers.length++] = {"Object":o, "Event":sPrmEvent, "Handler":functionDelegate};
	//__DebugWrite(EventHandlers.length);
	return bReturn;
}

function imod_RemoveHandler(o, sPrmEvent, functionDelegate) {
	var bReturn = false;
	if (o == null) {
		//alert("object destroyed before event cleanup for event: " + sPrmEvent + "\nmethod:\n" + functionDelegate);
		return bReturn;
	}
	if (o.removeEventListener != null) {
		o.removeEventListener(sPrmEvent, functionDelegate, false);
		bReturn = true;
	}
	else if (o.detachEvent) {
		o.detachEvent("on" + sPrmEvent, functionDelegate);
		bReturn = true;
	}
	else {
	//	o["on" + sPrmEvent] = null;
	}
	return bReturn;
}
imod_RemoveHandlersOnUnload();

//FIXES RadEditor's HTML issues
function imod_FixRadEditorHtml(sPrmClientID) {
	var bHasFail = true;
	if (window.GetRadEditor != null) {
		var RadEditor1 = GetRadEditor(sPrmClientID);
		if (RadEditor1 != null) {
			bHasFail = false;
			RadEditor1.FiltersManager.Add(new imod_RadEditorFix_CustomFilter());
		}
	}
	if (bHasFail)
		setTimeout(function() { imod_FixRadEditorHtml(sPrmClientID); }, 100);
}

function imod_RadEditorFix_CustomFilter() {          
	this.GetHtmlContent = imod_RadEditorFix;
}

function imod_RadEditorFix(sPrmHtml) {
	var sReturn = sPrmHtml;
	
	sReturn = sReturn.replace(/&amp;/gi, "&");
	sReturn = sReturn.replace(/&gt;/gi, ">");
	sReturn = sReturn.replace(/&lt;$/i, "<");
	sReturn = sReturn.replace(/&lt;([\s"'])/gi, "<$1");
	sReturn = sReturn.replace(/&lt;([<])/gi, "<<");
	sReturn = sReturn.replace(/%5B/gi, "[");
	sReturn = sReturn.replace(/%5D/gi, "]");
	
	//Fix token spacing	
	var reTokens = new Array(/\[[^\]]*\]/gi, /##[^#]*##/gi);
	for (var i = 0; i < reTokens.length; i++) {
		var mcToken = sReturn.match(reTokens[i]);
		if (mcToken != null) {
			for (var m = 0; m < mcToken.length; m++) {
				var mToken = mcToken[m];
				var sFixed = "";
				if (mToken != null) {
					sFixed = mToken.replace(/[\s]+/g, " ");
					sReturn = sReturn.replace(mToken, sFixed);
				}
			}
		}
	}
	return sReturn;
}

//WARNING:  This will not work when Peter's Date Package v1.1.10 is released!!!
//WARNING:  This will not work when Peter's Date Package v1.1.10 is released!!!
//WARNING:  This will not work when Peter's Date Package v1.1.10 is released!!!
//DJ 2005-0927 :: This method can be used to fix CS_Calendar's that are hidden.
//Also, this requires you know what width the calendar should be, if you don't know then ask me to make another fix.
function imod_FixCSCalendarWidth(sPrmCalendarId, iPrmCommonWidth) {
	var pCField = PDP_GetById(sPrmCalendarId);
	var vCId = pCField.id;
	var vWRTbl = PDP_GetById(vCId + "_WeekRows");
	var vCommonWidth = vWRTbl.offsetWidth;
	
	var vDayHeaderTable = PDP_GetById(vCId + "_DayHeader");
	var vHeaderTable1 = PDP_GetById(vCId + "_Header1");
	var vHeaderTable2 = PDP_GetById(vCId + "_Header2");
	var vHeaderTable3 = PDP_GetById(vCId + "_Header3");
	var vFooterTable1 = PDP_GetById(vCId + "_Footer1");
	var vFooterTable2 = PDP_GetById(vCId + "_Footer2");
	var vFooterTable3 = PDP_GetById(vCId + "_Footer3");
	
	var vCalendarClientWidth = 0;
	if (pCField.clientWidth)
		vCalendarClientWidth = pCField.clientWidth;
	else
		vCalendarClientWidth = pCField.offsetWidth;
	
	vCommonWidth = iPrmCommonWidth;
	if (vCalendarClientWidth > vCommonWidth) {
		vCommonWidth = vCalendarClientWidth;
		pCField.style.width = vCommonWidth + "px";
	}
	else 
		pCField.style.width = vCommonWidth + "px";
	vWRTbl.style.width = vCommonWidth + "px";
	
	if (vDayHeaderTable != null)
		vDayHeaderTable.style.width = vCommonWidth + "px";
	if (vHeaderTable1 != null)
		vHeaderTable1.style.width = vCommonWidth + "px";
	if (vHeaderTable2 != null)
		vHeaderTable2.style.width = vCommonWidth + "px";
	if (vHeaderTable3 != null)
		vHeaderTable3.style.width = vCommonWidth + "px";
	if (vFooterTable1 != null)
		vFooterTable1.style.width = vCommonWidth + "px";
	if (vFooterTable2 != null)
		vFooterTable2.style.width = vCommonWidth + "px";
	if (vFooterTable3 != null)
		vFooterTable3.style.width = vCommonWidth + "px";
	PDP_SetAtt(pCField, 'InitSize', true);
}

imod.General.divDarkScreen = null;
imod.General.DarkScreen = function(iPrmOpacity, sPrmColor, iPrmZIndex) {
	if (! imod.General.divDarkScreen) {
		imod.General.divDarkScreen = document.createElement("div");
		imod.General.divDarkScreen.style.display = "none";
		imod.General.divDarkScreen.style.background = "#000";
		imod.General.divDarkScreen.style.opacity = .5;
		imod.General.divDarkScreen.style.filter = "alpha(opacity=50)";
		imod.General.divDarkScreen.style.zIndex = 1000;
		imod.General.divDarkScreen.style.position = "absolute";
		imod.General.divDarkScreen.style.left = "0px";
		imod.General.divDarkScreen.style.top = "0px";
		document.body.appendChild(imod.General.divDarkScreen);
	}
	if (iPrmOpacity)
		imod.dom.SetOpacity(imod.General.divDarkScreen, iPrmOpacity);
	if (sPrmColor)
		imod.General.divDarkScreen.style.background = sPrmColor;
	if (iPrmZIndex)
		imod.General.divDarkScreen.style.zIndex = iPrmZIndex;

	imod.General.divDarkScreen.style.width = document.body.scrollWidth + "px";
	imod.General.divDarkScreen.style.height = document.body.scrollHeight + "px";

	imod.General.divDarkScreen.style.display = "block";
}

imod.General.NormalScreen = function() {
	if (imod.General.divDarkScreen)
		imod.General.divDarkScreen.style.display = "none";
}

//Adds trim function to the string object
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
	
//KD 2006-0808 added common function to show/hide an html element based on the checked status of a checkbox passed in
function imod_ShowHide(oPrmCheckBox, sPrmElementId)
{
	var oElement = document.getElementById(sPrmElementId);
	if (oPrmCheckBox && oElement)
	{
		if (oPrmCheckBox.checked)
			oElement.style.display = '';
		else
			oElement.style.display = 'none';
	}
} //imod_ShowHide

//KD 2006-0822 added common function to show/hide an html element based on a bool passed in
function imod_ForceShowHide(bShow, sPrmId)
{
	var element = document.getElementById(sPrmId);
	if (element && element.style)
	{
		if (bShow)
			element.style.display = '';
		else
			element.style.display = 'none';
	}
} //imod_ForceShowHide


function imod_ToggleDisplay(sPrmId)
{
	var element = document.getElementById(sPrmId);
	if (element && element.style)
	{
		if (element.style.display == 'none')
			element.style.display = '';
		else
			element.style.display = 'none';
	}
} // imod_ToggleDisplay


// JP 2006-0818 - calls stripID with current URL
function stripQueryStringID(prmKey)
{
   		var currentURL = window.location.href;
		if (currentURL.indexOf(prmKey) > -1) 
		{
	   		currentURL = stripID(prmKey, currentURL);
		}
		return currentURL;
}

// JP 2006-0818 - given a key and string, finds QS key within string and removes it, returning modified string
function stripID(prmKey, prmRemoveItFrom)
{
	var retString = prmRemoveItFrom

	if (prmKey && prmRemoveItFrom)
	{
		var markerStart = prmRemoveItFrom.indexOf("&" + prmKey + "=");
		if (markerStart == -1) markerStart = prmRemoveItFrom.indexOf("?" + prmKey + "=");
		if (markerStart > -1)
		{
			var markerEnd = prmRemoveItFrom.indexOf("&", markerStart+1);
			if (markerEnd > -1)
			{
				retString = prmRemoveItFrom.substring(0, markerStart) + prmRemoveItFrom.substring(markerEnd);
			}
			else
			{
				retString = prmRemoveItFrom.substring(0, markerStart);
			}
		}
	}

	return retString;
} // stripID

// KD 2006-0915 - the following 2 functions allow you to add a javascript file or css file to the head tag of the page
var arLoadedFiles = [];

function imod_LoadScriptFile(prmFullPath)
{
	if (!arLoadedFiles[prmFullPath])
	{
		var el = document.createElement("script");
		el.src = prmFullPath;
		el.type = "text/javascript";
		if (document.getElementsByTagName("head") && document.getElementsByTagName("head")[0])
		{
			//alert('loading script ' + prmFullPath);
			document.getElementsByTagName("head")[0].appendChild(el);
			arLoadedFiles[prmFullPath] = true;
		}
		el = null;
	}
} //imod_LoadScriptFile


function imod_LoadStyleFile(prmFullPath)
{
	if (!arLoadedFiles[prmFullPath])
	{
		var el = document.createElement("link");
		el.href = prmFullPath;
		el.rel = "stylesheet";
		el.type = "text/css";
		if (document.getElementsByTagName("head") && document.getElementsByTagName("head")[0])
		{
			//alert('loading style ' + prmFullPath);
			document.getElementsByTagName("head")[0].appendChild(el);
			arLoadedFiles[prmFullPath] = true;
		}
		el = null;
	}
} //imod_LoadStyleFile


/*
imod_AddHandler(window, "load", imod.Fancy.ActivateFancyInputFocus);
imod_AddHandler(window, "load", imod.Fancy.ActivateFancyCheckBoxes);
imod_AddHandler(window, "load", imod.Fancy.ActivateFancyRadioButtons);
*/


imod.dom.AddHandler = imod_AddHandler;
imod.dom.RemoveHandler = imod_RemoveHandler;
imod.dom.StopPropagation = imod_StopPropagation;
imod.dom.OffsetTop = imod_OffsetTop;
imod.dom.OffsetLeft = imod_OffsetLeft;
imod.dom.MakePixel = imod_Pixel;
imod.dom.GetElementsByTagNames = imod_GetElementsByTagNames;
imod.dom.SetOpacity = imod_SetOpacity;
imod.dom.CreateElement = imod_CreateElement;

imod.Browser.MouseX = imod_MouseX;
imod.Browser.MouseY = imod_MouseY;
imod.Browser.ClientWidth = imod_ClientWidth;
imod.Browser.ClientHeight = imod_ClientHeight;
imod.Browser.OpenWindow = imod_OpenWindow;
imod.Browser.OpenFullWindow = function(sPrmUrl) {
	imod.Browser.OpenWindow(sPrmUrl, 0, 0, "location=yes,menubar=yes,toolbar=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes", 3);
}
imod.Browser.DocumentScrollLeft = imod_DocumentScrollLeft;
imod.Browser.DocumentScrollTop = imod_DocumentScrollTop;

imod.Form.GetRadioButtonValue = imod_GetRadioButtonValue;
imod.Form.SelectText = imod_SelectText;

imod.General.ParseInt = imod_ParseInt;

imod.Fancy.SetTableRowBackgroundColors = imod_SetTableRowBackgroundColors;


imod.dom.AddHandler(window, "load", function() { window.loaded = true; });
//imod.dom.AddHandler(window, "load", function() { imod.Fancy.GlobalFastTitle() });
//**DO NOT PUT ANYTHING BELOW THIS LINE**
}//Load first time only


// source: quirksmode.com
function imod_findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {"x" : curleft, "y" : curtop};
}
