if (typeof(Page) != "undefined")
{
	alert("default.js should NOT be loaded more than once!")
}
var Page = [];
Page.RR_divs = [];
Page.InitTimer = null;
Page.Started = false;
Page.InitTimer2 = null;
Page.FoundStyles = [];
function Browser()
{
	var ua, s, i;
	this.isIE	= false;
	this.isIE6  = false;
	this.isIE7  = false;
	this.isIE8  = false;
	this.isOpera = false;
	this.isNS	= false;
	this.isFF   = false;
	this.version = null;
	ua = navigator.userAgent;
	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		this.isIE6 = (this.version > 5) && (this.version < 7);
		this.isIE7 = (this.version > 6) && (this.version < 8);
		this.isIE8 = (this.version > 8) && (this.version < 9);
		return;
	}
	s = "Opera";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isOpera = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	s = "Netscape/";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	s = "firefox"
	if ((i = ua.toLowerCase().indexOf(s)) >= 0)
	{
		this.isFF = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}
	// Treat any other "Gecko" browser as NS 6.1.
	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isNS = true;
		this.version = 6.1;
		return;
	}
}
Page.Browser = new Browser();
Page.ErrMessages = "";
function btnMO(objOrId, bMO)
{
	var objBtn = getObj(objOrId);
	InitBtn(objBtn);
	if (Page.InSubmit || objBtn.disabled) return;
	btnMOExec(objBtn, bMO);
}
function btnMOExec(objBtn, bMO)
{
	if (objBtn.stub == "") return;
	if (IsImgBtn(objBtn))
	{
		objBtn.src = objBtn.stub + (bMO ? "_mo" : "") +  objBtn.stubExt
		objBtn.style.cursor = (bMO ? (Page.Browser.isIE ? "hand" : "pointer") : "default");
	}
	else
	{
		objBtn.className = objBtn.stub + (bMO ? "_mo" : "");
	}
	if (typeof(objBtn.btnL) != "undefined")
	{
		objBtn.btnL.className = objBtn.stub + "L" + (bMO ? "_mo" : "");
		objBtn.btnR.className = objBtn.stub + "R" + (bMO ? "_mo" : "");
	}
}
function InitBtn(objBtn)
{
	if (typeof(objBtn.stub) != "undefined" && objBtn.stub != null) return;
	var Stub;
	if (IsImgBtn(objBtn))
	{	
		var src = objBtn.src;
		var aT = src.split(".")
		objBtn.stubExt = "." + aT[aT.length-1];
		Stub = src.substr(0, src.length-objBtn.stubExt.length);
	}
	else
	{
		Stub = objBtn.className;
	}
	var aT = Stub.split("_")
	objBtn.disabled = (aT.length > 1) && (aT[aT.length-1].toLowerCase()=="dis");
	objBtn.stub = (objBtn.disabled ? Stub.substr(0, Stub.length-5) : Stub);
}
function IsImgBtn(objBtn)
{
	if (typeof(objBtn.IsImg) != "undefined") return objBtn.IsImg;
	var tn = objBtn.tagName.toUpperCase();
	objBtn.IsImg = (  (tn == "IMG") || ( (tn == "INPUT") && (objBtn.type.toUpperCase() == "IMAGE") )  )
	return objBtn.IsImg;
}
function dbgMsg(x)
{
	alert(x);
}
function getObj(objOrId, bIgnoreNull)
{
	// If you get an alert with this function, fix the actual error instead of modifying this function, which works as intended.
	// This function is designed to return an "Id has no Object" error UNLESS it is is called with bIgnoreNull == true
	// If you get an alert, that means that the code is broken elsewhere and is requesting an object that doesn't exist.
	if (typeof(bIgnoreNull) == "undefined") var bIgnoreNull = false;
	var obj = (typeof(objOrId) == "object" ? objOrId : document.getElementById(objOrId) );
	if (obj == null && !bIgnoreNull)
	{
		alert("getObj: Id has no Object [" + objOrId + "]");
	}
	return obj;
}
function btnDisable(objOrId, bDisabled)
{
	if (objOrId == null)
	{
		dbgMsg("Passed null button");
		return;
	}
	var objBtn = getObj(objOrId);
	if (objBtn == null)
	{
		Message("Could not find button: " + objOrId);
		return;
	}
	InitBtn(objBtn)
	if (typeof(objBtn.inMO) == "undefined") objBtn.inMO = false
	if (IsImgBtn(objBtn))
	{
		objBtn.src = objBtn.stub + (bDisabled  ? "_dis" : "") + objBtn.stubExt
	}
	else
	{
		objBtn.className = objBtn.stub + (bDisabled ?  "_dis" : (objBtn.inMO ? "_mo" : ""));
	}
	if (typeof(objBtn.btnL) != "undefined")
	{
		objBtn.btnL.className = "btnL" + (bDisabled ? "_dis" : "");
		objBtn.btnR.className = "btnR" + (bDisabled ? "_dis" : "");
	}
	objBtn.disabled = bDisabled;
	if (bDisabled) objBtn.inMO = false;  // a disabled button can't be inMO.
	objBtn.disabled = (objBtn.tagName.toUpperCase() == "INPUT" ? bDisabled : false);  //disable postback for disabled input buttons.
}
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function Trim( value )
{
	return LTrim(RTrim(value));
}
function TrapEnterKey(e, szEvalIfEnter)
{
	var iAsc = (window.event ? e.keyCode : e.which);
	if (iAsc == 13)
	{
		eval(szEvalIfEnter);
		return false;
	}
}
function closeTimeout(obj)
{
	if (obj == null) return;
	self.clearTimeout(obj);
	obj = null;
}
function removeElement(objOrId)
{
	var obj = getObj(objOrId);
	obj.parentNode.removeChild(obj);
}
function ResizeRR()
{
	if (!Page.Started)
	{
		 return;
	}
	if (Page.RR_divs.length > 0)
	{	
		for (var i=1; i < Page.RR_divs.length; i++)
		{
			if (Page.RR_divs[i-1].AbsTop == Page.RR_divs[i].AbsTop)
			{
				var h = Math.max(Page.RR_divs[i-1].getElementsByTagName("div")[1].offsetHeight, Page.RR_divs[i].getElementsByTagName("div")[1].offsetHeight) + 15 + "px";
				Page.RR_divs[i-1].style.height = h;
				Page.RR_divs[i].style.height = h;
			}
		}
	}
	if (Page.Setting.HotBoxCornerRadius == 0) return;
	var imgs = document.getElementsByTagName("img");
	if (imgs != null)
	{
		for (var i=0; i< imgs.length; i++)
		{
			if (imgs[i].alt) imgs[i].title = imgs[i].alt;
			if (typeof(imgs[i].rrType) != "undefined")
			{
				setRRpos(imgs[i]);
			}
		}
	}
}
function setRRpos(rr)
{
	var rrDiv = rr.parentNode.parentNode;
	var offset = Page.Setting.HotBoxBorderColor == "none" ? 0 : -1;
	if (rr.rrType.substr(0,1) == "T")
	{
		rr.style.top = offset + "px";
	}
	else
	{
		rr.style.top = (rrDiv.offsetHeight-Page.Setting.HotBoxCornerRadius + offset) + "px";
	}
	if (rr.rrType.substr(1,1) == "L")
	{
		rr.style.left = offset + "px";
	}
	else
	{
		rr.style.left = (rrDiv.offsetWidth-Page.Setting.HotBoxCornerRadius + offset) + "px";
	}
}
function createRR(rrType, rp)
{
	var rr = document.createElement("img");
	rr.src = "/images/corners/" + Page.Setting.BackgroundColor + "_" + Page.Setting.HotBoxBackgroundColor + "_" + Page.Setting.HotBoxBorderColor + "_" + Page.Setting.HotBoxCornerRadius + "_" + rrType + ".gif";
	rr.style.position = "absolute";
	rr.style.zIndex = 10;
	rr.rrType = rrType;
	rp.appendChild(rr);
	setRRpos(rr);
}
function CreateCorner(Button, btnDis, direction)
{
	var btn = document.createElement("div")
	btn.btn = Button;
	Button.stub = "btn"
	btn.onClick = function() { getObj(this.id).click(); };
	btn.onmouseover = function() { btnMO(this.btn,true); };
	btn.onmouseout = function() { btnMO(this.btn,false); };
	btn.stub = "btn" + direction
	btn.className = "btn" + direction + btnDis;
	Button.style.marginLeft = "0px";
	Button.style.marginRight = "0px";
	switch (direction)
	{
		case "L":
			Button.btnL = btn;
			Button.parentNode.insertBefore(btn, Button);
			break;
		case "R":
			Button.btnR = btn;
			var ns = Button.nextSibling;
			Button.parentNode.appendChild(btn);
			break;
	}
	var pNode = Button.parentNode;
	return btn.scrollWidth;
}
function getNextSib(obj)
{
	if (obj == null) return null;
	return FFNextSib(obj.nextSibling);
}
function FFNextSib(obj)
{
	while (obj != null && obj.nodeType == 3)
	{
		obj = obj.nextSibling;
	}
	return obj;
}
function getPrevSib(obj)
{
	if (obj == null) return null;
	return FFPrevSib(obj.previousSibling);
}
function FFPrevSib(obj)
{
	while (obj != null && obj.nodeType == 3)
	{
		obj = obj.previousSibling;
	}
	return obj;
}
//gets the absolute XY position of a control as an array
function AbsPos(objOrId)
{
	var objElement = getObj(objOrId);
	iTop = objElement.offsetTop			// Get top position from the parent object
	iLeft = objElement.offsetLeft		   // Get left position from the parent object
	while(objElement.offsetParent!=null)
	{
		// Parse the parent hierarchy up to the document element
		objParent = objElement.offsetParent // Get parent object reference
		iTop += objParent.offsetTop			// Add parent top position
		iLeft += objParent.offsetLeft		// Add parent left position
		objElement = objParent
	}
	// Return Position as an array
	var arrRet = new Array(2);
	arrRet["left"] = iLeft;
	arrRet["top"] = iTop;
	return arrRet;
}
function AbsTop(objOrId)
{
	var objElement = getObj(objOrId);
	iTop = objElement.offsetTop			// Get top position from the parent object
	while(objElement.offsetParent!=null)
	{
		// Parse the parent hierarchy up to the document element
		objParent = objElement.offsetParent // Get parent object reference
		iTop += objParent.offsetTop			// Add parent top position
		objElement = objParent
	}
	return iTop;
}
function AbsLeft(objOrId)
{
	var objElement = getObj(objOrId);
	iLeft = objElement.offsetLeft			// Get Left position from the parent object
	while(objElement.offsetParent!=null)
	{
		// Parse the parent hierarchy up to the document element
		objParent = objElement.offsetParent	// Get parent object reference
		iLeft += objParent.offsetLeft		// Add parent Left position
		objElement = objParent
	}
	return iLeft;
}
function RegisterValidator(f)
{
	Page.Validator = f;
}
function ReadCookies()
{
	if (typeof(Page.Setting) != "undefined" ) return;
	Page.Setting = [];
	var arrSetting = ReadCookie("PortalSettings").split("|");
	if (arrSetting.length > 0)
	{
		for (i=0; i < arrSetting.length; i++)
		{
			var t = arrSetting[i].split("~");
			Page.Setting[t[0]] = t[1];
		}
	}
}
function PageInit(bLoadStyleSheet)
{
	ReadCookies()
	if (typeof(bLoadStyleSheet) == "undefined" ? false : bLoadStyleSheet)
	{
		LoadStyleSheet(Page.Setting.StyleSheet);
	}
	if (Page.Setting.HotBoxBorder == "F") Page.Setting.HotBoxBorderColor = "none";
	if (typeof(document.body.onresize) == "undefined"  || document.body.onresize == null)
	{
		document.body.onresize = function (){ ResizeRR(); };
	}
	Page.InitTimer = self.setTimeout("PageInitExec()", 200);
}
function PageInitExec()
{
	closeTimeout(Page.InitTimer);
	if (!Page.Browser.isIE6)
	{
		var btn = document.getElementsByTagName("input");
		if (btn != null)
		{
			for (var i = 0; i < btn.length; i++)
			{
				switch (btn[i].type.toLowerCase())
				{
					case "submit": case "button":
					var Button = btn[i];
					var id = Button.id;
					var btnDis = (Button.disabled ? "_dis" : "");
					Button.className = "";
					Button.className = "btn" + btnDis;
					var Width = Button.offsetWidth;
					Width += CreateCorner(Button, btnDis, "L");
					Width += CreateCorner(Button, btnDis, "R");
					Button.onmouseover = function() { btnMO(this,true); };
					Button.onmouseout = function() { btnMO(this,false); };
					Button.value = Trim(Button.value);
					Button.parentNode.style.width = (Width + 4) + "px";
					break;
				}
			}
		}
	}
	var divs = document.getElementsByTagName("div");
	if (divs != null)
	{
		for (var i=0; i < divs.length; i++)
		{
			if (divs[i].className.split(' ')[0] == "SD_RR")
			{
				var rp = document.createElement("div");
				rp.className = "SD_rp";
				divs[i].insertBefore(rp, divs[i].childNodes[0])
				if (Page.Setting.HotBoxCornerRadius > 0)
				{
					createRR("TL", rp);
					createRR("TR", rp);
					createRR("BL", rp);
					createRR("BR", rp);
				}
				divs[i].AbsTop = AbsTop(divs[i]);
				Page.RR_divs.push(divs[i]);
				if (typeof(Page.Setting.HotBoxBorder) != "undefined" && Page.Setting.HotBoxBorder != "F")
				{
					divs[i].style.borderWidth = "1px";
					divs[i].style.borderColor = "#" + Page.Setting.HotBoxBorderColor;
					divs[i].style.borderStyle = "solid";
				}
			}
			else if (divs[i].className != "")
			{
				if (divs[i].className.split(" ")[0] == "NDE")
				{
					if ( Trim(divs[i].innerHTML) == "")
					{
						divs[i].style.display = "none";
					}
				}
			}
		}
	}
	if (Page.RR_divs.length > 0)
	{
		var z = Page.RR_divs.sort(ByAbsTop);
		Page.RR_divs = z;
	}
	Page.Started = true;
	Page.InitTimer2 = self.setTimeout("ResizeRR();SetRR_Visible()", 200);
}
function SetRR_Visible()
{
	if (Page.RR_divs.length == 0) return;
	for (var i=0; i < Page.RR_divs.length; i++)
	{
		Page.RR_divs[i].style.visibility = "visible";
	}
	closeTimeout(Page.InitTimer2);
}
function ByAbsTop(a, b)
{
	if (a.AbsTop == b.AbsTop) return 0;
	if (a.AbsTop < b.AbsTop) return -1;
	return 1;
}
function getCSSRules(ruleName)
{
	ruleName = ruleName;
	var OutRules = [];
	if (document.styleSheets)
	{
		for (var i=document.styleSheets.length-1; i > -1; i--)
		{
			var styleSheet=document.styleSheets[i];
			var ii=0;
			var cssRule=false;
			do
			{
				if (styleSheet.cssRules)
				{
					cssRule = styleSheet.cssRules[ii];
				}
				else
				{
					cssRule = styleSheet.rules[ii];
				}
				if (cssRule)
				{
					var arrST = cssRule.selectorText.split(",");
					for (var iST = 0; iST < arrST.length; iST++)
					{
						if (Trim(arrST[iST]) == ruleName)
						{
							OutRules.push(cssRule);
						}
					}
				}
				ii++;
			}
			while (cssRule)
		}
	}
	return OutRules;
}
function InsertStyleRule(name, style)
{
	var mySheet=document.styleSheets[0];
	var totalRules = (mySheet.cssRules ? mySheet.cssRules.length : mySheet.rules.length );
	if (mySheet.insertRule)
	{
		mySheet.insertRule(name + "{" + style + "}", totalRules);
		return mySheet.cssRules[totalRules]
	}
	else if (mySheet.addRule)
	{
		mySheet.addRule(name, style);
		return mySheet.rules[totalRules];
	}
}
function StyleExists(name)
{
	if (typeof(Page.FoundStyles[name]) == "undefined")
	{
		Page.FoundStyles[name] = (getCSSRules(name).length != 0)
	}
	return Page.FoundStyles[name];
}
function setCSS(css, tryAgain)
{
	try
	{
		document.getElementsByTagName("head")[0].appendChild(css);
	}
	catch (e)
	{
		if (tryAgain)
		{
			setTimeout(function(){setCSS(css, false)}, 200);
		}
	}
}
function ReadCookie(cookieName)
{
	var theCookie = "" + document.cookie;
	var ind = theCookie.indexOf(cookieName);
	if (ind == -1 || cookieName == "") return "";
	var ind1 = theCookie.indexOf(';', ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function LoadStyleSheet(href)
{
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = href;
	cssNode.media = 'screen';
	cssNode.title = 'dynamicLoadedSheet';
	document.getElementsByTagName("head")[0].appendChild(cssNode);
}
function addElement(szType, Parent, ChildId, szHtml, CssClass, bDisplay)
{
	var objParent = getObj(Parent);
	var objChild = getObj(ChildId, true);
	if (typeof(bDisplay) == "undefined") var bDisplay = false;
	if (objChild == null)
	{
		objChild = document.createElement(szType);
		if (ChildId != null)
		{
			objChild.setAttribute('id', ChildId);
		}
	}
	if (! bDisplay)
	{
		objChild.style.display = "none";
	}
	if (CssClass != null && CssClass != "")
	{
		objChild.className = CssClass;
	}
	objParent.appendChild(objChild);
	if (szHtml != null && szHtml != "")
	{
		objChild.innerHTML = szHtml;
	}
	return objChild;
}
function PositionPopUp(element, relatedElement, margin, xOffset, yOffset)
{
	if (!margin) var margin=5;
	if (!xOffset) var xOffset = 5;
	if (!yOffset) var yOffset = 5;
	var Result = GetScrollAndPosition(element.offsetWidth, element.offsetHeight, getObj(relatedElement), margin, xOffset, yOffset)
	element.style.left = Result.left + "px";
	element.style.top  = Result.top + "px";
	if (Result.scroll)
	{
		window.scrollTo(Result.ScrollLeft, Result.ScrollTop);
	}
}
function GetScrollAndPosition(ElementWidth, ElementHeight, relatedElement, margin, xOffset, yOffset)
{
	if (!margin) var margin=5;
	if (!xOffset) var xOffset = 5;
	if (!yOffset) var yOffset = 5;
	var posRelated = AbsPos(relatedElement);
	var ScrollTop = GetScrollTop();
	var ScrollLeft = GetScrollLeft();
	var NewScrollTop;
	var NewScrollLeft;
	var yPosAB = [];
	yPosAB[0] = posRelated.top + relatedElement.offsetHeight + yOffset;
	yPosAB[1] = posRelated.top - ElementHeight - yOffset;
	var xPosAB = [];
	xPosAB[0] = posRelated.left + relatedElement.offsetWidth + xOffset;
	xPosAB[1] = posRelated.left - ElementWidth - xOffset;
	var WindowHeight = GetWindowHeight();
	var WindowWidth = GetWindowWidth();
	var PosY = -1;
	var iEnd = (   ( (yPosAB[1] - margin) < 0 ) ? 1 : 2 );
	var bYScroll = true;
	for (var i=0; i < 2 && PosY < 0 == true; i++)
	{
		if (  ( yPosAB[i] < (ScrollTop + margin) ) || ( yPosAB[i] > (ScrollTop + WindowHeight - ElementHeight - margin) )  )
		{
			PosY = - yPosAB[i];
			NewScrollTop = yPosAB[i] + ElementHeight + margin - GetWindowHeight();
		}
		else
		{
			bYScroll = false;
			NewScrollTop = ScrollTop;
			PosY = yPosAB[i];
		}
	}
	PosY = Math.abs(PosY);
	var PosX = -1;
	iEnd = (xPosAB[1] - margin < 0 ? 1 : 2);
	var bXScroll = true;
	for (var i=0; i < iEnd && PosX < 0 == true; i++)
	{
		if (  ( xPosAB[i] < (ScrollLeft + margin) ) || ( xPosAB[i] > (ScrollLeft + WindowWidth - ElementWidth - margin) )  )
		{
			PosX = - xPosAB[i];
			NewScrollLeft = xPosAB[i] + ElementWidth + margin - GetWindowWidth();
		}
		else
		{
			NewScrollLeft = ScrollLeft;
			bXScroll = false;
			PosX = xPosAB[i];
		}
	}
	PosX = Math.abs(PosX);
	var Result = [];
	Result["scroll"] = (bYScroll || bXScroll);
	Result["top"] = PosY;
	Result["left"] = PosX;
	Result["ScrollLeft"] = NewScrollLeft;
	Result["ScrollTop"] = NewScrollTop;
	return Result;
}
function GetWindowHeight()
{
	return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight || 0;
}
function GetWindowWidth()
{
	return window.innerWidth || document.documentElement && document.documentElement.clientWidth || document.body.clientWidth || 0;
}
function GetScrollTop()
{
	return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop || 0;
}
function GetScrollLeft()
{
	return window.pageXOffset || document.documentElement && document.documentElement.scrollLeft || document.body.scrollLeft || 0;
}
function TabClick(tab)
{
	for (var iChild = 0; iChild < tab.childNodes.length; iChild++)
	{
		var a = tab.childNodes[iChild];
		if (a.tagName.toLowerCase() == "a")
		{
			var f = Trim(a.href);
			var arrF = f.split(":");
			if (Trim(arrF[0]).toLowerCase() == "javascript")
			{	
				eval(f.substring(f.indexOf(":")+1));
			}
			else
			{
				var x = window;
				var lastName = "";
				var loopLimit = 6;
				while (x != null && a.target != x.name)
				{
					if (lastName != x.name)
					{
						lastName = x.name;
						x = window.parent;
					}
					else
					{
						break;
					}
					loopLimit--;
					if (loopLimit == 0) return;
				}
				x.location.href  = f;
				break;
			}
			break;
		}
	}
}
function SetFocus(objOrId)
{
	var o=getObj(objOrId, true)
	if (o == null) return;
	try
	{
		o.focus();
	}
	catch(ex){}
}
Page.ButtonsFixed = false
function FixButtons()
{
	if (!Page.ButtonsFixed)
	{
		var btn = document.getElementsByTagName("input");
		if (btn != null)
		{
			for (var i = 0; i < btn.length; i++)
			{
				switch (btn[i].type.toLowerCase())
				{
					case "submit": case "button":
						btn[i].parentNode.style.width = (btn[i].offsetWidth + btn[i].btnL.offsetWidth + btn[i].btnR.offsetWidth + 6) + "px";
						break;
				}
			}
		}
		Page.ButtonsFixed = true;
	}
}
function bookmark(url,title) 
{
	try
	{
		if ( window.external ) 
		{ 
			// IE Favorite
			window.external.AddFavorite( url, title);
		}
		else if (window.sidebar) 
		{ 
			// Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} 
		else
		{
			BMsg()
		}
	}
	catch(ex)
	{
		BMsg()
	}
	function BMsg()
	{
		alert("Press Ctrl-D to set Bookmark");
	}
}
//lookup array and string for keycodes. Negative keycodes are for shift values. Positive keycodes are for unshifted values. Unsigned are both.
//the array index is determined by the index of the character in CCI.
//         `      ~     '      -      ,      .      /       ;     \     [        ]     =    spc   a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t   u    v    w    x    y     z      0       1         2       3         4         5         6         7         8          9       !     @     #     $     %    ^     &     *     (      )     "      _      <       >      ?      :      |      {      }     +
var cc= ["-192","192","+222","+189","+188","+190","+191","+186","+220","+219","+221","+187","32","65","66","67","68","69","70","71","72","73","74","75","76","77","78","79","80","81","82","83","84","85","86","87","88","89","90","+48,96","+49,97","+50,98","+51,99","+52,100","+53,101","+54,102","+55,103","+56,104","+57,105","-49","-50","-51","-52","-53","-54","-55","-56","-57","-48","-222","-189","-188","-190","-191","-186","-220","-219","-221","-187"];
var cci = "`~'-,./;\\[]= abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()\"_<>?:|{}+";
//
Page.AlphaKeyCodes = GetKeyCodes("abcdefghijklmnopqrstuvwxyz");
Page.IfValidButtons = [];
function MarkError(objOrId, bError)
{
	if (objOrId == null)
	{
		dbgMsg("Passed null button");
		return;
	}
	var obj = getObj(objOrId);
	if (obj == null)
	{
		Message("Could not find button: " + objOrId);
		return;
	}
	InitBtn(obj)
	obj.className = obj.stub + (bError ? "_err" : "");
}
function LTrim( value )
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value )
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function Trim( value )
{
	return LTrim(RTrim(value));
}
function TrapEnterKey(e, szEvalIfEnter)
{
	var iAsc = (window.event ? e.keyCode : e.which);
	if (iAsc == 13)
	{
		eval(szEvalIfEnter);
		return false;
	}
}
function isEmail(field)
{
	if (isValidEmail(field.value))
	{
		alert(default_4);
		field.focus();
		field.select();
		return false;
	}
	else
	{
		return true;
	}
}
function isValidEmail(text, bValidIfNull)
{
	if (text == "") return (typeof(bValidIfNull) == "undefined" ? false : bValidIfNull);
	var reEmail = /(^$|^([a-zA-Z0-9_\-\.!#$%&'*+\-/=?^_`{|}~]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$)/;
	return reEmail.test(text);
}
function GetKeyCodes(chars)
{
	chars = chars.toLowerCase()
	var x = [];
	for (i = 0; i < chars.length; i++)
	{
		var fc = chars.substr(i,1);
		var index = cci.indexOf(fc);
		if (index > -1)
		{
			var n = cc[index].split(",");
			x.push(n[0])
			//if character has two possible key codes
			if (n.length==2) x.push(n[1]);
		}
	}
	return x;
}
function KeyCodeMatch(iCode, e, KeyCodes)
{
	if (iCode == 16) return true;
	var ShiftedKey = (e.shiftKey ? "-" : "+") + iCode;
	//alert(e.shiftKey + ":" + iCode);
	for (var i=0; i< KeyCodes.length; i++)
	{
		switch (KeyCodes[i].substring(0,1))
		{
			case "+" : case "-":
				if (KeyCodes[i] == ShiftedKey) return true;
				break;
			default:
				if (KeyCodes[i] == iCode) return true;
				break;
		}
	}
	return false;
}
function inputNumeric(e, OtherChars)
{
	if (e == null) return;
	var iCode = (window.event ? e.keyCode : e.which);
	if (typeof(OtherChars) != "undefined" && CharListMatch(iCode, e, OtherChars)) return true;
	return NumberKeysOnly(iCode, e);
	if (TestNavChars(iCode)) return true;
}
function CharListMatch(iCode, e, CharList)
{
	//a lert(iCode);
	return KeyCodeMatch(iCode, e, GetKeyCodes(CharList));
	//a lert(acc.join(","));
}
function reformatPhone(obj)
{
	var val = obj.value;
	if (isNumeric(val) && val.length == 10)
	{
		obj.value = val.substr(0,3) + " " + val.substr(3,3) + "-" + val.substr(6,4);
	}
	return "";
}
Page.NumLockStatus = null;
function TestNavChars(iCode)
{
	switch (iCode)
	{
		case  8:  //backspace
		case  9:  //tab
		case 35:  //end
		case 36:  //home
		case 37:  //left cursor
		case 38:  //up cursor
		case 39:  //right cursor
		case 40:  //down cursor
		case 46:  //delete
		case 144: //numlock
		 return true; break;
	}
	return false;
}
function inputPhone(e, szExtId)
{
	var iCode = (window.event ? e.keyCode : e.which);
	var bIsPhone = (szExtId != null);
	if (TestNavChars(iCode)) return true;
	switch (iCode)
	{
		case 109: case 189: //dash
		case 32: return true; break; //space
		case 189:
			return KeySubstitute(bIsPhone ? " " : ""); break;  //dash
		case 191:
			return KeySubstitute(bIsPhone ? " " : ""); break; //slash
		case 88:
			if (bIsPhone)
			{
				getObj(szExtId).focus();
				return false;
			} break;
	}
	return NumberKeysOnly(iCode, e);
}
var NumberCodes = GetKeyCodes("0123456789")
function NumberKeysOnly(iCode, e)
{
	if (TestNavChars(iCode)) return true;
	return KeyCodeMatch(iCode, e, NumberCodes);
}
function KeySubstitute(NewKey)
{
	if (NewKey == "") return false;
	var range=document.selection.createRange();
	range.length = 0;
	range.text = NewKey;
	return false;
}
function inputText(e, OtherChars)
{
	var iCode = (window.event ? e.keyCode : e.which);
	if (typeof(OtherChars) != "undefined" && CharListMatch(iCode, e, OtherChars)) return true;
	if (TestNavChars(iCode)) return true;
	return TestTextChar(iCode);
}
function inputAlpha(e, OtherChars)
{
	var iCode = (window.event ? e.keyCode : e.which);
	if (typeof(OtherChars) != "undefined" && CharListMatch(iCode, e, OtherChars)) return true;
	if (TestNavChars(iCode)) return true;
	if (iCode > 64 && iCode < 91) return true; //A-Z
	if (iCode > 95 && iCode < 123) return true; //a-z'
	return false;
}
function inputAlphaNumeric(e, OtherChars)
{
	var iCode = (window.event ? e.keyCode : e.which);
	if (typeof(OtherChars) != "undefined" && CharListMatch(iCode, e, OtherChars)) return true;
	if (TestNavChars(iCode)) return true;
	if (iCode == 191) return true;
	//if (iCode == 32) return true; // space
	if (NumberKeysOnly(iCode,e)) return true;
	if (AlphaKeysOnly(iCode,e)) return true;
	return false;
}
function AlphaKeysOnly(iCode,e)
{
	return KeyCodeMatch(iCode, e, Page.AlphaKeyCodes);
}
function InputEmail(e)
{
	return inputAlphaNumeric(event,"@!#$%&'*+-/=?^_`{|}~.");
}
function InputDate(e)
{
	var iCode = (window.event ? e.keyCode : e.which);
	if (NumberKeysOnly(iCode,e)) return true;
	if (TestNavChars(iCode)) return true;
	if (iCode == 32 || iCode == 45 || iCode == 46) return KeySubstitute("/");
	//alert(iCode);
	if (iCode == 191 || iCode == 111) return true;
	return false;
}
function GetKeyCodes(chars)
{
	chars = chars.toLowerCase()
	var x = [];
	for (i = 0; i < chars.length; i++)
	{
		var fc = chars.substr(i,1);
		var index = cci.indexOf(fc);
		if (index > -1)
		{
			var n = cc[index].split(",");
			x.push(n[0])
			//if character has two possible key codes
			if (n.length==2) x.push(n[1]);
		}
	}
	return x;
}
function GetFrame(strFrame, framePath)
{
	var po = (typeof(framePath) == "undefined" ? parent : getObj(framePath));
	var f = po.document.getElementById(strFrame);
	if (f != null) return f;
	return (po == top ?  null : GetFrame(strFrame, po.parent));
}

Page.fixBtnTimer = null
function TryToFixButtons(fun, tries)
{
	closeTimeout(Page.fixBtnTimer);
	tries++;
	try
	{
		eval(fun);
	}
	catch (ex)
	{	
		if (tries < 20)
		{
			Page.fixBtnTimer = self.setTimeout("TryToFixButtons(\"" + fun  + "\"," + tries + ");", 200);
		}
	}
}

