
// OpenWin('page-edit-library.html','w2', 380, Math.ceil(screen.height - 76), 1, 1, parseInt(screen.width - (380 + 12)), 0);
function OpenWin(theURL, winName, wWidth, wHeight, withScrollbars, withResizeable, horzPos, vertPos, boolSetCookie)
{
	winHandle = '';
	vAdjustment = -50;
	if (horzPos == "" && vertPos == "")
	{
		if (screen)
		{
			horzPos = Math.ceil((screen.width - wWidth)/2);
			vertPos = Math.ceil((screen.height - wHeight)/2) + vAdjustment;
		}
		else
		{
			horzPos = 0;
			vertPos = 0;
		}
	}
	winChild = window.open(theURL, winName,'toolbar=no,location=no,scrollbars='+withScrollbars+',resizable='+withResizeable+',width='+wWidth+',height='+wHeight+', left='+horzPos+', top='+vertPos+'');
	setTimeout("winChild.focus()", 500);
	if (boolSetCookie) SetCookie("childWinUrl", theURL, 24);
}

//
// 1, Used for manage the "on" state on menus
// 2. You can set the variable "strOverrideUrl" in the master_template.html through PHP
// ...or allow it to locate the url itself
// 3. Remember to set class="" on the anchor tags so that it's available to be reset
//
function ManageCss(strObName, strNewClassName, strOverrideUrl)
{
	var blnParseEntireStyle = (navigator.userAgent.indexOf("Firefox") != -1)?false:true;
	var objMenu = document.getElementById(strObName);
	if(objMenu != null)
	{
		var strCurrUri = window.location.pathname.toLowerCase().replace("/", "");

		// Add the search string for this project
		strCurrUri += location.search

		// Check for parent menu to override
		// ...set in head of master_template.html
		if (strOverrideUrl != "")
		{
			if (strOverrideUrl != strCurrUri) strCurrUri = strOverrideUrl;
		}

		// Special case for index page
		if (strCurrUri == "") strCurrUri = "index.html";

		var arrA = objMenu.getElementsByTagName("a");
		var strAnchorHref = null;
		for(var i=0; i< arrA.length;i++)
		{
			strAnchorHref = arrA[i]["href"].toLowerCase().replace("//", "").replace("/", "").replace(location.hostname, "").replace(location.protocol, "");
			strAnchorHref = strAnchorHref.replace(":10080", "").replace(location.hash, ""); // .replace(location.search, "");
			strAnchorHref = strAnchorHref.replace("#", "");

			if (strCurrUri.indexOf(strAnchorHref) != -1)
			{
				arrA[i]["class"] = strNewClassName; // For non-IE
				arrA[i]["className"] = strNewClassName; // For IE
				// arrA[i].setAttribute("class", strNewClassName);
				// alert(document.styleSheets[2].rules.item(3).style.getAttribute('color'));
				// alert(arrA[i]["class"]["border"]);
				// arrA[i].href = "javascript:void(0);";
				objStyle = GetCssObjectByRuleName(strNewClassName);
				arrA[i]["style"]["color"] = objStyle["color"];
				arrA[i]["style"]["fontWeight"] = objStyle["fontWeight"];
				arrA[i]["style"]["background"] = objStyle["background"];
				arrA[i]["style"]["border"] = objStyle["border"];
				arrA[i]["style"]["borderTop"] = objStyle["borderTop"];
				arrA[i]["style"]["borderBottom"] = objStyle["borderBottom"];
				arrA[i]["style"]["borderLeft"] = objStyle["borderLeft"];
				arrA[i]["style"]["borderRight"] = objStyle["borderRight"];
				arrA[i]["style"]["margin"] = objStyle["margin"];
				arrA[i]["style"]["padding"] = objStyle["padding"];

				// alert(objStyle.getAttribute('color'));

				// This works fine in IE and Safari but not FireFox
				if (blnParseEntireStyle)
				{
					if (objStyle)
					{
						var str = "";
						for (key in objStyle)
						{
							// str +=key+":"+objStyle[key]+";"; // For testing
							if (objStyle[key])
								arrA[i]["style"][key] = objStyle[key];
						}
						// alert(str); // For testing
					}
				}
			}
		}
	}
}

//
// Looks through all style sheet for a particular rule name
//
function GetCssObjectByRuleName(strCssRuleName)
{
	var cssRules;
	var objStyle;
	var blnTestMode = false;

	if (document.all)
	{
		cssRules = "rules";
	}
	else if (document.getElementById)
	{
		cssRules = "cssRules";
	}

	for (var i = 0; i < document.styleSheets.length; i++)
	{
		for (var j = 0; j < document.styleSheets[i][cssRules].length; j++)
		{
			if (document.styleSheets[i][cssRules][j].selectorText.replace(".", "") == strCssRuleName)
			{
				var objStyle = document.styleSheets[i][cssRules][j].style;
			}
		}
	}

	if (blnTestMode) // For testing
	{
		var str = "";
		for (key in objStyle)
		{
			str +=key+":"+objStyle[key]+";";
		}
		alert(str);
	}


	return objStyle;
}

function GoTo(strLocation)
{
	location.href = strLocation;
	return false;
}

function IsNumeric(strString)
//  check for valid numeric strings
{
	var strValidChars = "0123456789 ";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function HighlightField(objField)
{
	objField.style.border = "1px solid #ff0000";
	objField.style.padding = "1px";
	objField.style.margin = "1px 0 1px 0";
	objField.select();
	objField.focus();
}

function IsUsernameType(arg1)
{
	var re = /^[a-z0-9_]{6,12}$/;
	if (re.test(arg1)) return true;
	return false;
}

