//~~~~Button Style Constants~~~~~~~~
var defBorderDark   = "THREEDDARKSHADOW";
var defBorderLight  = "THREEDHIGHLIGHT";
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var rootPath;

function handlePostBack(ctl)
{
	__doPostBack(ctl.id, "");
}
function strictEncode(txtCtl)
{
	var sVal = txtCtl.value;
	sVal = sVal.replace(/</g, "").replace(/>/g, "");
	sVal = sVal.replace("?", "").replace(/>/g, "");
	sVal = sVal.replace("#", "").replace(/>/g, "");
	sVal = sVal.replace("&", "").replace(/>/g, "");
	txtCtl.value = sVal
}
function safeEncode(txtCtl)
{
	var sVal = txtCtl.value;
	txtCtl.value = sVal.replace(/</g, "").replace(/>/g, "");
}
function htmEncode(txtCtl)
{
	var sVal = txtCtl.value;
	txtCtl.value = sVal.replace(/</g, '{').replace(/>/g, '}');
}
function NumsOnly()
{
	// enforces numeric-only input in textboxes.
	var iKeyCode = event.keyCode;
	//alert("keyCode: " + iKeyCode);
	if ((iKeyCode >= 48 && iKeyCode <= 57) || (iKeyCode == 189))
	{
		// Keyboard Number keys allowed, but not if Shift is pressed
		if (window.event.shiftKey)
			window.event.returnValue = false;
		else
			return;
	}
	else if ((iKeyCode >= 96 && iKeyCode <= 105) || (iKeyCode == 109))
	{
		// Numeric keypad keys... allowed
		return;
	}
	else
	{
		// 37, 38, 39, 40
		switch (iKeyCode)
		{
			case 9:
			case 16:
			case 17:
			case 18:
			case 8:
			case 46:
			case 110:
			case 190:
			case 36:
			case 35:
				// tab, shift, ctrl, alt, backspc, del, del (keypad), home, end
				return;
				break;
			case 37:
			case 38:
			case 39:
			case 40:
				// cursor keys: left, up, right, down
				return;
				break;
			default:
				// no others are allowed.
				// Note that we allow the event to bubble
				// up to the document level for additional 
				// keystroke handling.
				window.event.returnValue = false;
				return;
		}
	}
}
function SetButton(obj, bDisabled)
{
	// Enables or Disables a BUTTON element
	// and changes the button's Image as appropriate.
	try {
		if(bDisabled==true) BtnRestore(obj);
		obj.disabled = bDisabled;
		if(obj.children.length > 0)
		{
			var srcStr = obj.firstChild.src;
			if(bDisabled==true)
			{
				// Disable the button
				if(srcStr.indexOf("_disabled.gif") < 0)
				{
					srcStr = srcStr.replace(".gif", "_disabled.gif");
					obj.firstChild.src = srcStr;
				}
			}
			else
			{
				// Activate the button
				if(srcStr.indexOf("_disabled.gif")>0)
				{
					srcStr = srcStr.replace("_disabled.gif", ".gif");
					obj.firstChild.src = srcStr;
				}
			}
		}
	}
	catch(e) {
	}
}
function BtnHilite(oCtl)
{
	if(!oCtl.disabled)
	{
		oCtl.runtimeStyle.borderRightColor  = defBorderDark;
		oCtl.runtimeStyle.borderBottomColor = defBorderDark;
		oCtl.runtimeStyle.borderLeftColor   = defBorderLight;
		oCtl.runtimeStyle.borderTopColor    = defBorderLight;
	}
}
function BtnRestore(oCtl)
{
	oCtl.runtimeStyle.borderColor = "";
	oCtl.runtimeStyle.backgroundColor = "";
}
function MakeLong(iVal)
{
	var iRetVal=0;
	try {
		if (!isNaN(parseInt(iVal)))
		{
			iRetVal = parseInt(iVal);
		}
	}
	catch(e) {
		iRetVal=0;
	}
	return iRetVal;
}
function FormatAsCurrency(iVal)
{
	var sRetVal="0.00";
	try {
		var sValue = "0";
		var sDecimal = "00";
		var ary = MakeString(iVal).split(".")
		if (ary.length > 0)
		{
			if (!isNaN(parseInt(ary[0])))
			{
				sValue = parseInt(ary[0]).toString();
			}
			
			if (ary.length > 1)
			{
				if (!isNaN(parseInt(ary[1])))
				{
					sDecimal = parseInt(ary[1]).toString();
					if (sDecimal.length == 1)
						sDecimal = "0" + sDecimal;
					else if (sDecimal.length > 2)
						sDecimal = sDecimal.substr(0, 2);
				}
			}
		}
		sRetVal = sValue + "." + sDecimal;
	}
	catch(e) {
		sRetVal="0.00";
	}
	return sRetVal;
}
function MakeString(strInput)
{
	var sRetVal="";
	try {
		sRetVal = strInput.toString();
		}
	catch(e) {
		sRetVal="";
	}
	return sRetVal;
}
function MakeBoolean(iVal)
{
	var bRetVal=false;
	try {
		var sTmp = MakeString(iVal).toLowerCase;
		if (sTmp.length > 0)
		{
			if (!isNaN(parseInt(sTmp)))
			{
				if (parseInt(sTmp)!=0)
					bRetVal=true;
			}
			else
			{
				if ((sTmp=="true") || (sTmp=="y") || (sTmp=="yes"))
					bRetVal=true;
			}
		}
	}
	catch(e) {
		bRetVal=false;
	}
	return bRetVal;
}
function ElementExists(elementID)
{
	var bRetVal=false;
	var sTag="";
	try {
		sTag = document.getElementById(elementID).tagName
		if (sTag.length > 0)
			bRetVal=true;
	}
	catch(e) {
		bRetVal=false;
	}
	return bRetVal;
}
function PopupCoords(left, top)
{
	this.left = left;
	this.top = top;
}
function CalcPopupCoords(el, objPopupCoords)
{
	var iDiff=0;
	GetLeftTop(el, objPopupCoords);
	iDiff = (window.event.clientX - objPopupCoords.left);
	objPopupCoords.left = (window.event.screenX - iDiff) - document.body.scrollLeft;
	iDiff = (window.event.clientY - objPopupCoords.top);
	objPopupCoords.top  = ((window.event.screenY - iDiff) + el.offsetHeight) - document.body.scrollTop;
}
function GetLeftTop(AnObject, objPopupCoords)
{
	try {
		var oParent=null;
		objPopupCoords.left = AnObject.offsetLeft;
		objPopupCoords.top = AnObject.offsetTop;
		oParent = AnObject.offsetParent;
		while (oParent!=null)
		{
			objPopupCoords.left += oParent.offsetLeft;
			objPopupCoords.top += oParent.offsetTop;
			oParent = oParent.offsetParent;
		}
	}
	catch(e) {
	}
}
function SetComboIndex(id, cboCtl)
{
	var opt;
	try {
		var val = MakeString(id).toLowerCase();
		for (opt in cboCtl.options)
		{
			if (MakeString(opt.Value).toLowerCase == val)
			{
				opt.Selected = true;
				break;
			}
		}
	}
	catch(e) {
	}
}
function ClearAllOptions(ctl)
{
	var bRetVal=false;
	var el;
	try {
		for (el in ctl.options)
			ctl.Remove(el.Index);
		bRetVal = (ctl.options.length=0) ? true : false;
	}
	catch(e) {
		bRetVal=false;
	}
	return bRetVal;
}
function AddOption(sTxt, sVal, ctl)
{
	try {
		var el = document.createElement("option");
		el.innerText = sTxt;
		el.value = sVal;
		ctl.appendChild(el);
		return el;
	}
	catch(e) {
	}
}
function LoadAsModalDialog(dlgTitle, dlgURL, ht, wd, bResizable)
{
	var sRetVal="";
	var sURL="";
	var sPg = dlgURL.replace(".aspx?", "&");
	sPg = sPg.replace(".aspx", "");
	sPg = sPg.replace("?", "&");
	if(dlgTitle.length > 0)
	{
		sURL = rootPath + "/Admin/rsDialog.aspx?title=" + dlgTitle + "&page=" + sPg;
	}
	else
	{
		sURL = rootPath + "/Admin/rsDialog.aspx?page=" + sPg;
	}
	var sizable = "no";
	if(bResizable)
	{
		sizable = "yes";
	}
	sRetVal = window.showModalDialog(sURL, null, "dialogHeight:" + ht + "px;dialogWidth:" + wd + "px;center:yes;help:no;resizable:" + sizable + ";scroll:yes;status:yes;");
	return sRetVal;
}


