function GetElement(sID, sTag) {
	var aEle = document.getElementsByTagName(sTag)
	for (var i=0; i<aEle.length; i++) {
		sTID = aEle[i].id
		var nPos = sTID.indexOf(sID)
		if (nPos > -1) {
			sTID = sTID.substr(nPos)
			if (sTID == sID) {return aEle[i]}
		}
	}
}
var bChangedFlag = false;
function FieldChange(oField) {
	oField.style.color = "red"
	if (! bChangedFlag) {
		bChangedFlag = true;
		GetElement("btnSave", "INPUT").style.fontWeight = "bold";
		BlinkSaveButton();
	}
}
var nBSBTimerID
function BlinkSaveButton() {
	if (GetElement("btnSave", "INPUT").style.color == "red") {
		GetElement("btnSave", "INPUT").style.color = "";
	} else {
		GetElement("btnSave", "INPUT").style.color = "red";
	}
	nBSBTimerID = window.setTimeout("BlinkSaveButton()", 500);
}

function NoBlinkSaveButton() {
	bChangedFlag = false;
	GetElement("btnSave", "INPUT").style.fontWeight = "normal";
	GetElement("btnSave", "INPUT").style.color = "black"
	window.clearTimeout(nBSBTimerID)
	$(".StdInput").css("color", "black")
}

function ReplaceSelOptions(oSelect, sOptions) {
	if (navigator.userAgent.indexOf( "MSIE " ) > 0) {
		var sHTML = oSelect.outerHTML;
		var sStart = sHTML.substr(0, sHTML.search(">") + 1);
		oSelect.outerHTML = sStart + sOptions + "</select>";
	} else {
		oSelect.innerHTML = sOptions
	}
}
function eleMouseOver(oEle, sOverOut, sClassName) {
	if (sOverOut == "Over") {
//		oEle.className += " " + sClassName;
		oEle.className = oEle.className + " " + sClassName;
	} else {
		oEle.className = oEle.className.replace(sClassName, "");
	}
}
var eleLastClick
function eleMouseClick(oEle, sClassName) {
	try {eleLastClick.className = eleLastClick.className.replace(sClassName, "")}
	catch(e) {}
	oEle.className += " " + sClassName;
	eleLastClick = oEle;
}
var tabArray = new Array()
function tabCreate(sName, sButton, sDiv) {
	this.name = sName;
	this.button = sButton;
	this.div = sDiv;
}
function tabSelect(sTabName) {
	for (var i = 0; i < tabArray.length; i++) {
		oDiv = document.getElementById(tabArray[i].div);
		oButton = document.getElementById(tabArray[i].button);
		oTab = document.getElementById("tbTab");
		oDiv.style.display = "none"; oDiv.style.visibility = "visible";
		oButton.className = oButton.className.replace(" tabButtonInset", "");
		if (tabArray[i].name == sTabName) {
			oDiv.style.display = ""; oButton.className += " tabButtonInset";
			oTab.tabNo = i; oTab.value = sTabName;
		}
	}
}
function tabResize() {
		var nTab = document.getElementById("tbTab").tabNo;
		var nHeight = document.getElementsByTagName("body")[0].clientHeight - (document.getElementById(tabArray[nTab].div).offsetTop + 15);
		var nWidth = document.getElementsByTagName("body")[0].clientWidth - (document.getElementById(tabArray[nTab].div).offsetLeft + 15);
		document.getElementById("divTabButtons").style.width = nWidth;
		for (var i = 0; i < tabArray.length; i++) {
			document.getElementById(tabArray[i].div).style.height = nHeight;
			document.getElementById(tabArray[i].div).style.width = nWidth;
		}
}
function CallServerFunc(sCall) {
	var xmlRequest;
	try { xmlRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { xmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlRequest = new XMLHttpRequest(); }
	catch (e) { xmlRequest = false; }}}
	if (!xmlRequest) {return null;}
	xmlRequest.open("GET", sCall, false);
	xmlRequest.send(null);
	return xmlRequest.responseText;
}
function CallServerPostFunc(sPage, sParams) {
	var xmlRequest;
	try { xmlRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { xmlRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlRequest = new XMLHttpRequest(); }
	catch (e) { xmlRequest = false; }}}
	if (!xmlRequest) {return null;}
	xmlRequest.open("POST", sPage, false);
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
	xmlRequest.send(sParams);
	return xmlRequest.responseText;
}
function GetStyleSheetRule(oSS, sSelector) {
	var oRules, oRule
	if (oSS.cssRules) {oRules = oSS.cssRules} else {oRules = oSS.rules}
	for (var i = 0; i < oRules.length; i++) {
		if (oRules[i].selectorText == sSelector) {
			oRule = oRules[i]
			break
		}
	}
	return oRule
}
function PopUpEditor(sText, bReadOnly, bHTMLView, bTEXTView) {
	var oEditParams = new Object();
	oEditParams.Text = sText;
	oEditParams.ReadOnly = bReadOnly; 
	oEditParams.HTMLView = bHTMLView; 
	oEditParams.TEXTView = bTEXTView;
	return window.showModalDialog("sysEditor.aspx", oEditParams, "dialogHeight:350pt; dialogWidth:500pt; center:yes; resizable:yes; scroll:no; help:no; status:no;");
}
function getAbsoluteLeft(oNode){
	var oCurrentNode = oNode;
	var iLeft = 0;
	var sTagName = "";
	var iOffsetLeft = 0;
	try {
		sTagName = oCurrentNode.tagName;
		iOffsetLeft = oCurrentNode.offsetLeft;
		}
	catch(e) {
		sTagName = "BODY";
		iOffsetLeft = 0;
		}
	while(sTagName !== "BODY"){
		iLeft += iOffsetLeft;
		oCurrentNode = oCurrentNode.offsetParent;
		try {
			sTagName = oCurrentNode.tagName;
			iOffsetLeft = oCurrentNode.offsetLeft
			}
		catch(e) {
			sTagName = "BODY";
			iOffsetLeft = 0;
			}
	}
	return iLeft
}
function getAbsoluteTop(oNode){
	var oCurrentNode = oNode;
	var iTop = 0;
	var sTagName = "";
	var iOffsetTop = 0;
	try {
		sTagName = oCurrentNode.tagName;
		iOffsetTop = oCurrentNode.offsetTop;
		}
	catch(e) {
		sTagName = "BODY";
		iOffsetTop = 0;
		}
	while(sTagName !== "BODY"){
		iTop += iOffsetTop;
		oCurrentNode = oCurrentNode.offsetParent;
		try {
			sTagName = oCurrentNode.tagName;
			iOffsetTop = oCurrentNode.offsetTop
			}
		catch(e) {
			sTagName = "BODY";
			iOffsetTop = 0;
			}
	}
	return iTop
}
function ViewItemClickByID(sViewItemID) {
	//window.top.frames["menubar"].ClickView(sViewItemID)
	window.top.frames[2].ClickView(sViewItemID)
}
function MenuItemClickByID(sMenuItemID) {
	//window.top.frames["menubar"].ClickMenu(sMenuItemID)
	window.top.frames[2].ClickMenu(sMenuItemID)
}
function NewsItemClickByID(sNewsItemID) {
	//window.top.frames["main"].NewsItemClick(window.top.frames["main"].document.getElementById("NewsItem" + sNewsItemID));
}
function NewsItemSetByID(sNewsItemID) {
	//window.top.frames["menubar"].sNewsItemIDToLoad = sNewsItemID
}
function LinkItemClickByID(sLinkItemID) {
	//window.top.frames["main"].LinkItemClick(window.top.frames["main"].document.getElementById("LinkItem" + sLinkItemID));
}
function SimpleListAdd(sCode, sShowMessage) {
	if(sShowMessage===undefined){sShowMessage="Y"}
	var tbl = GetElement("tbl" + sCode, "TABLE")
	var sID = GetElement("sel" + sCode, "SELECT").value
	var sText = GetElement("sel" + sCode, "SELECT").options[GetElement("sel" + sCode, "SELECT").selectedIndex].text
	for (var i=0; i < tbl.rows.length; i++) {
		if (tbl.rows[i].cells[0].innerHTML == sID) {
			if (sShowMessage=="Y"){window.alert(sText + " already exists!")}
			return
		}
	}
	var trNew = tbl.rows[0].cloneNode(true);
	var trNewE = tbl.insertRow(-1)
	trNewE.swapNode(trNew)
	tbl.rows(tbl.rows.length-1).style.display = ""
	tbl.rows(tbl.rows.length-1).cells[0].innerHTML = sID
	tbl.rows(tbl.rows.length-1).cells[1].innerHTML = sText
	tbl.rows(tbl.rows.length-1).scrollIntoView()
	GetElement("sel" + sCode, "SELECT").style.display = "none";
	GetElement("div" + sCode, "DIV").style.borderColor = "red"
	FieldChange(GetElement("div" + sCode, "DIV"))
	window.event.clearBubble=true
}
function SimpleListAdd2Key(sKey, sCode, bCheckDup) {
	var tbl = GetElement("tbl" + sCode, "TABLE")
	var sID = GetElement("sel" + sCode, "SELECT").value
	var sText = GetElement("sel" + sCode, "SELECT").options[GetElement("sel" + sCode, "SELECT").selectedIndex].text
	if (bCheckDup) {
		for (var i=0; i < tbl.rows.length; i++) {
			if (tbl.rows[i].cells[0].innerHTML == sKey && tbl.rows[i].cells[1].innerHTML == sID) {
				window.alert(sText + " already exists!")
				return
			}
		}
	}
	var trNew = tbl.rows[0].cloneNode(true);
	var trNewE = tbl.insertRow(-1)
	trNewE.swapNode(trNew)
	tbl.rows(tbl.rows.length-1).style.display = ""
	tbl.rows(tbl.rows.length-1).cells[0].innerHTML = sKey
	tbl.rows(tbl.rows.length-1).cells[1].innerHTML = sID
	tbl.rows(tbl.rows.length-1).cells[2].innerHTML = sText
	tbl.rows(tbl.rows.length-1).scrollIntoView()
	GetElement("sel" + sCode, "SELECT").style.display = "none";
	GetElement("div" + sCode, "DIV").style.borderColor = "red"
	FieldChange(GetElement("div" + sCode, "DIV"))
}
function SimpleListDel(sCode, oLastRow) {
	if (oLastRow == "") {
		window.alert("Please select an Item to Delete");
		return;
	}
	if (window.confirm("Delete " + oLastRow.cells[1].innerHTML + "?")) {
		oLastRow.removeNode(true);
		oLastRow = "";
		GetElement("div" + sCode, "DIV").style.borderColor = "red"
		FieldChange(GetElement("div" + sCode, "DIV"))
	}
}
function SimpleListDel2Key(sCode, oLastRow) {
	if (oLastRow == "") {
		window.alert("Please select an Item to Delete");
		return;
	}
	if (window.confirm("Delete " + oLastRow.cells[2].innerHTML + "?")) {
		oLastRow.removeNode(true);
		oLastRow = "";
		GetElement("div" + sCode, "DIV").style.borderColor = "red"
		FieldChange(GetElement("div" + sCode, "DIV"))
	}
}
function SimpleListSave(sTable, sInput) {
	var tbl, inp
	tbl = GetElement(sTable, "TABLE")
	inp = GetElement(sInput, "INPUT")
	inp.value = ""
	for (var i=1; i < tbl.rows.length; i++) {
		inp.value += tbl.rows[i].cells[0].innerHTML + "~"
	}
}
function SimpleListSave2Key(sTable, sInput) {
	var tbl, inp
	tbl = GetElement(sTable, "TABLE")
	inp = GetElement(sInput, "INPUT")
	inp.value = ""
	for (var i=1; i < tbl.rows.length; i++) {
		inp.value += tbl.rows[i].cells[0].innerHTML + "," + tbl.rows[i].cells[1].innerHTML + "~"
	}
}
function ComplexListSave(sTable, sInput, nCol) {
	var tbl, inp
	tbl = GetElement(sTable, "TABLE")
	inp = GetElement(sInput, "INPUT")
	inp.value = ""
	for (var i=1; i < tbl.rows.length; i++) {
		inp.value += tbl.rows[i].cells[nCol].firstChild.value + "~"
	}
}
function FormatInputs(bFormat) {
	var aTB = document.getElementsByTagName("INPUT")
	for (var i = 0; i < aTB.length; i++) {
		if (aTB[i].getAttribute("format") > "") {FormatInput(aTB[i], bFormat, false)}
	}
}
function FormatInput(oTB, bFormat, bSelect) {
	if (bSelect === undefined) {bSelect = true}
	if (bFormat) {
		oTB.value = oTB.value.replace(/,/g, "")
		var v = parseFloat(oTB.value)
		if (isNaN(v)) {v = 0}
		oTB.value = v.format(oTB.getAttribute("format"))
		if(Number(oTB.value) < 0.01) {
			oTB.value = "0.00"
		}

	} else {
		oTB.value = oTB.value.replace(/,/g, "")
		if (bSelect) { oTB.select() }
	}
}
function FireEvent(oEle, sEvent) {
	if (navigator.userAgent.indexOf("MSIE ") > 0) {
		oEle.fireEvent(sEvent)
	} else {
		var evt = document.createEvent("HTMLEvents")
		evt.initEvent(sEvent.substr(2), true, true)
		oEle.dispatchEvent(evt)
	}
}
function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}
function AjaxTabResizer() {
    this.tabHeight = 0
    this.tabWidth = 0
    this.subTabHeight = 0
    this.subTabWidth = 0
    this.ResizeTabs()
}
AjaxTabResizer.prototype = {
    _TabSize: function(div) {
        var regex = /tp\d*$/
        var overflowRegex = /^divMap/
        var bOverflow = true
        if (regex.test(div.id)) {
            if(div.parentNode.parentNode.parentNode.id == "divMain") {
                try {
                    this.tabHeight = div.parentNode.parentNode.parentNode.style.pixelHeight - 80
                    this.tabWidth = div.parentNode.parentNode.parentNode.style.pixelWidth - 20
                    div.style.width = (div.parentNode.parentNode.parentNode.style.pixelWidth - 20) + "px"
                    div.style.height = (div.parentNode.parentNode.parentNode.style.pixelHeight - 80) + "px"
                } catch (e) {
                    div.style.width = "0px"
                    div.style.height = "0px"
                    this.tabHeight = 0
                    this.tabWidth = 0
                }
            } else {
//                this.subTabWidth = div.parentNode.parentNode.parentNode.style.pixelWidth - 15
//                this.subTabHeight = div.parentNode.parentNode.parentNode.style.pixelHeight - 40
                this.subTabWidth = this.tabWidth - 20
                this.subTabHeight = this.tabHeight - 40
                try {
                    //div.parentNode.style.width = this.subTabWidth + "px"
                    div.parentNode.parentNode.style.width = (this.subTabWidth + 10) + "px"
                    div.parentNode.parentNode.parentNode.style.width = (this.subTabWidth + 20) + "px"
                    div.parentNode.previousSibling.style.width = (this.subTabWidth + 10) + "px"
                    div.style.height = this.subTabHeight + "px"
                } catch (e) {
                    div.parentNode.style.width = "0px"
                    div.parentNode.parentNode.parentNode.style.width = "0px"
                    div.parentNode.previousSibling.style.width = "0px"
                    div.style.height = "0px"
                    this.subTabHeight = 0
                    this.subTabWidth = 0
                }
            }
            for (var i = 0 ; i < div.childNodes.length ; i++) {
                if (overflowRegex.test(div.childNodes[i].id)) {
                    try {
                        div.childNodes[i].style.height = this.tabHeight + "px"
                        div.childNodes[i].style.width = this.tabWidth + "px"
                    } catch (e) {
                        div.childNodes[i].style.height = "0px"
                        div.childNodes[i].style.width = "0px"                      
                    }
                    bOverflow = false
                    break
                }
            }
            if(bOverflow) {
                div.style.overflow = "auto"
            }
        }
    },
    ResizeTabs: function() {
        var aDivs = document.getElementsByTagName("DIV")
        if (aDivs == null) {
            var err = Error.nullObject("Unable to find any DIVs", "DIV")
            throw err
        }
        var body = document.getElementsByTagName("body")
        if (body == null) {
            var err = Error.nullObject("Unable to find a body tag.", "BODY")
            throw err
        }
        body.scroll = "no"
        var divMain = GetElement("divMain", "DIV")
        if(divMain == null) {
            var err = Error.nullObject("Unable to set the size of divMain.  This is needed to determine the size of the outer-most Tab Container.", "divMain")
            throw err
        }
        try {
            divMain.style.height = (document.getElementsByTagName("html")[0].clientHeight - 12) + "px"
            divMain.style.width = (document.getElementsByTagName("html")[0].clientWidth - 12) + "px"
        } catch (e) {
            divMain.style.height = "0px"
            divMain.style.width = "0px"
        }
        for (var i = 0 ; i < aDivs.length ; i++) {
            this._TabSize(aDivs[i])
        }
    }
}
Error.nullObject = function(sInfo, sObject) {
    var sMessage = "NullObjectException: Unable to find " + (sObject ? sObject : "Unknown Item")
    var eErr = Error.create(sMessage, {name: "NullObjectException", information: (sInfo ? sInfo : "")})
    eErr.popStackFrame()
    return eErr
   }
   
   function trim(str, chars) {
   	return ltrim(rtrim(str, chars), chars);
   }

   function ltrim(str, chars) {
   	chars = chars || "\\s";
   	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
   }

   function rtrim(str, chars) {
   	chars = chars || "\\s";
   	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
   }
   function IsNumeric(input) {
   	return (input - 0) == input && input.length > 0;
   }
   function OpenWindow(sURL) {
   	window.open(sURL);
   }
   function NORMSINV(p) {
   	// Coefficients in rational approximations
   	var a = new Array(-3.969683028665376e+01, 2.209460984245205e+02,
                      -2.759285104469687e+02, 1.383577518672690e+02,
                      -3.066479806614716e+01, 2.506628277459239e+00);

   	var b = new Array(-5.447609879822406e+01, 1.615858368580409e+02,
                      -1.556989798598866e+02, 6.680131188771972e+01,
                      -1.328068155288572e+01);

   	var c = new Array(-7.784894002430293e-03, -3.223964580411365e-01,
                      -2.400758277161838e+00, -2.549732539343734e+00,
                      4.374664141464968e+00, 2.938163982698783e+00);

   	var d = new Array(7.784695709041462e-03, 3.224671290700398e-01,
                       2.445134137142996e+00, 3.754408661907416e+00);

   	// Define break-points.
   	var plow = 0.02425;
   	var phigh = 1 - plow;

   	// Rational approximation for lower region:
   	if (p < plow) {
   		var q = Math.sqrt(-2 * Math.log(p));
   		return (((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) /
                                             ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
   	}

   	// Rational approximation for upper region:
   	if (phigh < p) {
   		var q = Math.sqrt(-2 * Math.log(1 - p));
   		return -(((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) /
                                                    ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
   	}

   	// Rational approximation for central region:
   	var q = p - 0.5;
   	var r = q * q;
   	return (((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r + a[5]) * q /
                             (((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r + 1);
   }

   function InfoContentClick(sInfoContent) {
   	window.top.frames[4].ClickAnchor(sInfoContent)
   }
   function GotoMenuItem(sMenuItem, sViewItem, sSystemItem, sURL) {
   	//    window.top.frames["menubar"].RedirectPage(sMenuItem, sViewItem, sSystemItem, sURL)+
   	window.top.frames[2].RedirectPage(sMenuItem, sViewItem, sSystemItem, sURL)
   }



if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 
