function SetupSecurity()
{
	// Set protocol to https only if we are in a reports application
	var secureTestRegExp = /\/reports\w*/;
	var bShouldBeSecure = secureTestRegExp.test(window.location.pathname);
	var bAlreadySecure = window.location.protocol == "https:";
	var sHrefAfterProtocol = "//" + window.location.hostname + window.location.pathname + window.location.search
		+ window.location.hash; // Remove the port from the url
	if (bShouldBeSecure && !bAlreadySecure)
		window.location.replace("https:" + sHrefAfterProtocol);
	else if (!bShouldBeSecure && bAlreadySecure)
		window.location.replace("http:" + sHrefAfterProtocol);
}


function SetupImgRollovers()
{
	if (!document.getElementById)
		return;
	var imgPreload = new Array();
	var imgArr = document.getElementsByTagName("img");
	for (var i = 0; i < imgArr.length; i++) {
		if (imgArr[i].getAttribute("rollsrc")) {
			imgPreload[i] = new Image();
			imgPreload[i].src = imgArr[i].getAttribute("rollsrc");
			imgArr[i].state = false; // Keep track of on/off state of rollover image
			imgArr[i].SwapSources = function() {
				var imgTemp = this.getAttribute("src");
				this.setAttribute("src", this.getAttribute("rollsrc"));
				this.setAttribute("rollsrc", imgTemp);
				this.state = !this.state;
			}
			imgArr[i].onmouseover = function() {
				if (this.state) // Make sure rollover image is not already on
					return;
				this.SwapSources();
				return false;
			}
			imgArr[i].onmouseout = function() {
				if (!this.state)
					return;
				this.SwapSources();
				return false;
			}
		}
	}
}


function SetupSubmenus()
{
	if (!document.getElementById)
		return;
	var trArr = document.getElementsByTagName("tr");
	for (var i = 0; i < trArr.length; i++) {
		if (trArr[i].getAttribute("submenu_img")) {
			var sSubmenuImgId = trArr[i].getAttribute("submenu_img");
			var submenuImg = document.getElementById(sSubmenuImgId);
			if (submenuImg) {
				trArr[i].submenuImg = submenuImg;
				trArr[i].onmouseover = function()
					{ return this.submenuImg.onmouseover(); }
				trArr[i].onmouseout = function()
					{ return this.submenuImg.onmouseout(); }
			}
		}
		if (trArr[i].getAttribute("href"))
			trArr[i].onclick = function() { document.location.href = this.getAttribute("href"); }
	}
}


function OnLoad()
{
	//SetupSecurity();	
	SetupImgRollovers();
	SetupSubmenus();
}


function PopupImgDetail(sName, sPicUrl, iWidth, iHeight)
{
	iHeight += 50;
	var sFeatures = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="
		+ iWidth +",height="+ iHeight
		+ ",left=60,top=60";
	var sNewPageHtml = "<html><head><title>" + sName + "</title></head><body topmargin=0 leftmargin=0><IMG src='" + sPicUrl + "'><p align=center><a href='javascript:window.close();'><span style='font-family: Arial;'>Close Window</span></a></p></body></html>";
	var sUrl="javascript:document.write(\"" + sNewPageHtml + "\");";
	window.open(sUrl, "WexImageDetail", sFeatures);
}

