function PopupWindow ()
{
	if (window.PopupWindowInstance != null)
		{
		window.alert("You may create only one PopupWindow object on a page.");
		return null;
		}
	window.PopupWindowInstance = this;
	
	this.ShowSideHelp = PopupWindow_ShowSideHelp;
	this.CloseSideHelp = PopupWindow_CloseSideHelp;
	this.ShowWithTimeout = PopupWindow_ShowWithTimeout;
	this.DialogWithTimeout = PopupWindow_DialogWithTimeout;
	
	// internal properties
	this.windowRef = null;
}

function PopupWindow_ShowSideHelp (sHelpURL, cxHelpWidth)
{
	if ((window.SideHelpWindow == null) || (window.SideHelpWindow == false))
		{
		var _tempLeft;
		var _tempTop;
		var _tempWidth;
		var _tempHeight;
		
		_tempLeft = window.screenLeft;
		_tempTop = window.screenTop;
		window.moveTo(_tempLeft, _tempTop);
		this._saveLeft = _tempLeft - (window.screenLeft - _tempLeft);
		this._saveTop = _tempTop - (window.screenTop - _tempTop);
		window.moveTo(this._saveLeft, this._saveTop);
		
		_tempWidth = window.document.body.clientWidth;
		_tempHeight = window.document.body.clientHeight;
		window.resizeTo(_tempWidth, _tempHeight);
		this._saveWidth = _tempWidth + (_tempWidth - window.document.body.clientWidth);
		this._saveHeight = _tempHeight + (_tempHeight - window.document.body.clientHeight);
		window.resizeTo(this._saveWidth, this._saveHeight);
		
		window.moveTo(0,0);
		window.resizeTo(screen.availWidth - cxHelpWidth, screen.availHeight);
		window.SideHelpWindow = window.open(sHelpURL, "PopupWindowHelp", "left=" + (screen.availWidth - cxHelpWidth).toString() + ",top=0,width=" + cxHelpWidth.toString() + ",height=" + screen.availHeight.toString());
		window.SideHelpWindowCloseCheckTimer = window.setInterval(PopupWindow_CheckForClose, 200);
		}
	else
		{
		window.open(sHelpURL, "PopupWindowHelp");
		}
}

function PopupWindow_CheckForClose()
{
	if (window.SideHelpWindow.closed)
	{
		PopupWindow_CloseSideHelp();
		window.clearInterval(SideHelpWindowCloseCheckTimer);
		window.SideHelpWindowCloseCheckTimer = null;
	}
}

function PopupWindow_CloseSideHelp ()
{
	if (window.SideHelpWindow != null)
		{
		window.clearInterval(SideHelpWindowCloseCheckTimer);
		window.SideHelpWindowCloseCheckTimer = null;
		window.SideHelpWindow.close();
		window.SideHelpWindow = null;
		var pw = window.PopupWindowInstance;
		window.moveTo(pw._saveLeft, pw._saveTop);
		window.resizeTo(pw._saveWidth, pw._saveHeight);
		}
}

function PopupWindow_ShowWithTimeout (sHelpURL, nTimeoutSeconds, cxWidth, cyHeight, bAutoCenter, xPosition, yPosition)
{
	if (this.windowRef != null)
		{
		window.alert("You already have a popup window showing. You can show only one timed popup window at a time.");
		return false;
		}
	var sDefaultFeatures = ""; // "directories=no;location=no;menubar=no;scrollbars=no;status=no;toolbar=no;";
	var xWindowPos;
	var yWindowPos;
	var sFeatures;
	if (bAutoCenter)
		{
		var xScreenCenter = Math.floor(screen.availWidth / 2);
		var yScreenCenter = Math.floor(screen.availHeight / 2);
		xWindowPos = xScreenCenter - Math.floor(cxWidth / 2);
		yWindowPos = yScreenCenter - Math.floor(cyHeight / 2);
		sFeatures = sDefaultFeatures + "left=" + xWindowPos.toString() + ",top=" + yWindowPos.toString() + ",width=" + cxWidth.toString() + ",height=" + cyHeight.toString();
		}
	else
		{
		xWindowPos = xPosition;
		yWindowPos = yPosition;
		sFeatures = sDefaultFeatures + "left=" + xWindowPos.toString() + ",top=" + yWindowPos.toString() + ",width=" + cxWidth.toString() + ",height=" + cyHeight.toString();
		}
	this.windowRef = window.open(sHelpURL, "_blank", sFeatures, false);
	window.setTimeout(Popupwindow_ClosePopup, nTimeoutSeconds * 1000);
}

function PopupWindow_DialogWithTimeout (sHelpURL, nTimeoutSeconds, cxWidth, cyHeight, bAutoCenter, xPosition, yPosition)
{
	if (this.windowRef != null)
		{
		window.alert("You already have a popup window showing. You can show only one timed popup window at a time.");
		return false;
		}
	var sFeatures = new String();
	if (bAutoCenter)
		{
		sFeatures = sFeatures.concat("center:yes");
		sFeatures = sFeatures.concat(",dialogWidth:" + cxWidth.toString());
		sFeatures = sFeatures.concat(",dialogHeight:" + cyHeight.toString());
		}
	else
		{
		sFeatures = sFeatures.concat("center:no");
		sFeatures = sFeatures.concat(",dialogWidth:" + cxWidth.toString());
		sFeatures = sFeatures.concat(",dialogHeight:" + cyHeight.toString());
		sFeatures = sFeatures.concat(",dialogLeft:" + xPosition.toString());
		sFeatures = sFeatures.concat(",dialogTop:" + yPosition.toString());
		}
	this.windowRef = window.showModelessDialog(sHelpURL, null, sFeatures);
	window.setTimeout(Popupwindow_ClosePopup, nTimeoutSeconds * 1000);
}

function Popupwindow_ClosePopup ()
{
	var pw = window.PopupWindowInstance;
	if (pw.windowRef != null)
		{
		pw.windowRef.close();
		pw.windowRef = null;
		}
}

