if (typeof(Page) != "undefined")
{
	alert("default.js should NOT be loaded more than once!")
}
var Page = new Array();
Page.RR_divs = [];

function Browser()
{
	var ua, s, i;
	this.isIE	= false;
	this.isIE6  = false;
	this.isIE7  = false;
	this.isOpera = false;
	this.isChrome = 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);
		return;
	}
	s = "Chrome";
	if ((i = ua.indexOf(s)) >= 0)
	{
		this.isChrome = true;
		this.version = parseFloat(ua.substr(i + s.length));
		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") 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
	{
		var moName = "." + objBtn.className + "_mo"
		if (!StyleExists(moName))
		{
			Stub = "";
		}
		else
		{
			Stub = objBtn.className;
		}
		try
		{
			if (objBtn.className == "inactiveTab" || objBtn.className == "activeTab")
			{
				for (var iChild = 0; iChild < objBtn.childNodes.length; iChild++)
				{
					var a = objBtn.childNodes[iChild];
					if (a.tagName == "A")
					{
						var f = Trim(a.href);
						var arrF = f.split(":");
						if (Trim(arrF[0]).toLowerCase() == "javascript")
						{	
							objBtn.clickAction = f.substring(f.indexOf(":")+1);
							objBtn.onclick = function () { eval(this.clickAction) };
						}
						else
						{
							objBtn.clickAction = f;
							var x = window;
							var lastName = "";
							var c = 0;
							while (x != null && a.target != x.name && c < 20)
							{
								if (lastName != x.name)
								{
									lastName = x.name;
									x = window.parent;
								}
								else
								{
									break;
								}
								c++;
							}
							objBtn.clickTarget = x;
							objBtn.onclick = function () { this.clickTarget.location.href  = this.clickAction; };
						}
						break;
					}
				}
			}
		}
		catch(ex)
		{
			//do nothing
		}
	}
	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.inMO ? "_mo" : "")) + ".gif";
	}
	else
	{
		objBtn.className = objBtn.stub + (bDisabled ?  "_dis" : (objBtn.inMO ? "_mo" : ""));
	}
	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); 
}
Page.IsStarted = false
function ResizeRR()
{
	if (!Page.Started) return;
	if (Page.CornerSize == 0) 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;
			}
		}
	}
	var imgs = document.getElementsByTagName("img");
	if (imgs != null)
	{
		for (var i=0; i< imgs.length; i++)
		{
			if (typeof(imgs[i].rrType) != "undefined")
			{
				setRRpos(imgs[i]);
			}
		}
	}
}
function setRRpos(rr)
{
	var rrDiv = rr.parentNode.parentNode;
	if (rr.rrType.substr(0,1) == "T")
	{
		rr.style.top = "0px";
	}
	else
	{
		rr.style.top = (rrDiv.offsetHeight-Page.CornerSize) + "px";
	}
	if (rr.rrType.substr(1,1) == "L")
	{
		rr.style.left = "0px";
	}
	else
	{
		rr.style.left = (rrDiv.offsetWidth-Page.CornerSize) + "px";
	}
}
function createRR(rrType, rp)
{
	var rr = document.createElement("img");
	rr.src = "/images/corners/" + Page.bg + "_" + Page.fg + "_" + Page.CornerSize + "_" + 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;
	btn.onClick = function() { getObj(this.id).click(); };
	btn.onmouseover = function() { btnMO(this.btn,true); };
	btn.onmouseout = function() { btnMO(this.btn,false); };
	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;
}
Page.InitTimer = null;
Page.Started = false;
function PageInit(bg, fg, CornerSize)
{
	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];
		}
	}
	if (typeof(bg) != "undefined")
	{
		Page.bg = bg;
		Page.fg = fg;
		Page.CornerSize = CornerSize
	}
	Page.InitTimer = self.setTimeout("PageInitExec()", 500);
}
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 + "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")
			{
				if (Page.CornerSize > 0)
				{
					var rp = document.createElement("div");
					rp.className = "SD_rp";
					divs[i].insertBefore(rp, divs[i].childNodes[0])
					createRR("TL", rp);
					createRR("TR", rp);
					createRR("BL", rp);
					createRR("BR", rp);
					divs[i].AbsTop = AbsTop(divs[i]);
				}
				else
				{
					divs[i].style.padding = "7px 12px 3px 12px";
				}
				Page.RR_divs.push(divs[i]);
				divs[i].style.backgroundColor = "#" + Page.fg;
			}
			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)
	{
		Page.RR_divs.sort(ByAbsTop)
		if (typeof(window.onresize) == "undefined" || window.onresize == null || window.onresize == "")
		{
			window.onresize = function () { ResizeRR(); };
		}
	}
	Page.Started = true;
	Page.InitTimer2 = self.setTimeout("ResizeRR(); SetRR_Visible()", 200);
}
Page.InitTimer2 = null;
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 = new Array();
	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]; 
	}
}
Page.FoundStyles = new Array();
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 LoadStyleSheet(cssHref)
{
	var css = document.createElement("link");
	css.setAttribute("href", cssHref);
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	setCSS(css, true);
}
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 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 = new Array();
	yPosAB[0] = posRelated.top + relatedElement.offsetHeight + yOffset;
	yPosAB[1] = posRelated.top - ElementHeight - yOffset;
	var xPosAB = new Array();
	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 = new Array();
	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 isValidEmail(text)
{
	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);
}
