var cid;
cid = "SimpleModeAlertCookie";

function saveScrollLocation()
{
	if (document.all['divPageContents'] != null)
	{
		document.forms[0].__SCROLLLOC.value = document.all['divPageContents'].scrollTop;     
	}
}

function setScrollLocation(position)
{
	if (document.all['divPageContents'] != null)
	{
		document.all['divPageContents'].scrollTop = position;
	}
}

function SimpleModeAlert()
{
	if (!HasClr())
	{
		if (GetCookie(cid) == "")
		{
			alert("EMS is running in Simple Mode because you do not have the Microsoft .Net Framework installed.\nIt is highly recommended that you activate the Advanced Mode by following the instructions under the Getting Started section on the homepage.");
			document.cookie = cid + "=yes";
		}
	}
}

function GetCookie(Name) 
{
	var search = Name + "="
	var returnvalue = ""
	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search)
		if (offset != -1) 
		{
			offset += search.length
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
				end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function HasClr()
{
	if (navigator.userAgent.indexOf(".NET CLR") > -1)
	{
		return true;
	}
	return false;
}

function PreloadImages()
{
	var d = document;
	if (d.images)
	{
		if (!d.MM_p)
			d.MM_p = new Array();

		var i, j = d.MM_p.length, a = PreloadImages.arguments;

		for (i = 0; i < a.length; i++)
			if (a[i].indexOf("#") != 0)
			{
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
	}
}

function GetDropDownListSelectedItemValue(objName)
{
	if (document.all[objName] != null)
	{
		return document.all[objName].options[document.all[objName].selectedIndex].value;
	}
	return null;
}

function GetDropDownListSelectedItemText(objName)
{
	if (document.all[objName] != null)
	{
		return document.all[objName].options[document.all[objName].selectedIndex].text;
	}
	return null;
}

function SwapImage(objName, oldImage, newImage)
{
	if (document.all[objName] != null)
	{
		if (document.all[objName].src.indexOf(oldImage) > -1)
		{
			document.all[objName].src = newImage;
		}
		else
		{
			document.all[objName].src = oldImage;
		}
	}
}


function ShowHideItem(objName, image, expandedImagePath, collapsedImagePath, initialState)
{
	if (document.all[objName].style.display == "none")
	{
		document.all[objName].style.display = "";
		image.src = expandedImagePath;
	}
	else
	{
		document.all[objName].style.display = "none";
		image.src = collapsedImagePath;
	}
}

function ShowHideLeftMenuPane()
{
	if (document.all["divLeftMenuExpanded"].style.display != "none")
	{
		document.all["divLeftMenuExpanded"].style.display = "none";
		document.all["divReportingMenuTitleExpanded"].style.display = "none";
		document.all["divLeftMenuMinimized"].style.display = "";
		document.all["divReportingMenuTitleMinimized"].style.display = "";
		document.all["cellLeftMenuPane"].style.width = "20px";
	}
	else
	{
		document.all["divLeftMenuMinimized"].style.display = "none";
		document.all["divReportingMenuTitleMinimized"].style.display = "none";
		document.all["divLeftMenuExpanded"].style.display = "";
		document.all["divReportingMenuTitleExpanded"].style.display = "";
		document.all["cellLeftMenuPane"].style.width = "230px";
	}
}

function NavigateTo(url)
{
	window.location.href = url;
}

function PopUpWindow(url, width, height, scroll, mode) 
{
	// Close the window to vary the window size
	if (typeof(win) == "object" && !win.closed)
	{
		//win.close();
	}

	if (mode.toLowerCase() == "fullscreen")
	{
		params = "fullscreen";
	}
	else 
	{
		// Default parameters for regular popup window
		params  = "";
		params += "toolbar=0,";
		params += "location=0,";
		params += "directories=0,";
		params += "status=0,";
		params += "menubar=0,";
		params += "resizable=1,";
		params += "top=" + ((screen.height - height) / 2) + ",";
		params += "left=" + ((screen.width - width) / 2) + ",";

		// Default parameters for dialog window
		paramsDialog  = "";
		paramsDialog += "dialogLeft:px;";
		paramsDialog += "dialogTop:px;";
		paramsDialog += "center:yes;";
		paramsDialog += "dialogHide:no;";
		paramsDialog += "edge:raised;";
		paramsDialog += "help:no;";
		paramsDialog += "resizable:yes;";
		paramsDialog += "status:no;";
		paramsDialog += "unadorned:yes;";
		
		// Scrolling
		if (scroll == "" || scroll == "null" || scroll == null || scroll == "no")
		{
			params += "scrollbars=0,";
			paramsDialog += "scroll:0;";
		}
		else
		{
			params += "scrollbars=1,";
			paramsDialog += "scroll:1;";
		}

		// Width
		if (width == "" || width == "null" || width == null) 
		{
			params += "width=500,";
			paramsDialog += "dialogWidth:500px;";
		}
		else 
		{
			params += "width=" + width + ",";
			paramsDialog += "dialogWidth:" + width + "px;";
		}

		// Height
		if (height == "" || height == "null" || height == null) 
		{
			params += "height=600,";
			paramsDialog += "dialogHeight:600px;";
		}
		else 
		{
			params += "height=" + height;
			paramsDialog += "dialogHeight:" + height + "px;";
		}
	}

	// If IE5 or above
	if (document.all && window.print)
	{
		if (mode.toLowerCase() == "modal")
		{
			win = window.showModalDialog(url, '', paramsDialog);
		}
		else if (mode.toLowerCase() == "modeless")
		{
			win = window.showModelessDialog(url, '', paramsDialog);
		}
		else
		{
			win = window.open(url, '', params);
		}
	}
	else
	{
			win = window.open(url, '', params);
	}

	//win.focus();	
}