var HELP_ROOT_MAIN =			"Main.htm";
var HELP_ROOT_URL =				"/NmConsole/Help/1033/index.htm";
var HELP_DESK_URL =				"/NmConsole/Help/1033/index.htm";
var HELP_GETTINGSTARTED_URL =	"http://www.whatsupgold.com/wug14webhelp";
var HELP_DEMOSERVER_URL =		"/NmConsole/Help/1033/DemoHelp/index.htm";


// a flag for resizing the main window back on help window close
// only set if this window is resized by openening help
var bWindowResizedByHelp = false;

// open a help window
// use oAspForm.OpenHelpTopic(sHelpTopicUrl)
//
CAspForm.prototype.OpenHelpTopic = function(sHelpTopicUrl, bDoNotResize)
{
	// if there is not help set for this window then use the root url
	if(sHelpTopicUrl == null)
	{
		sHelpTopicUrl = HELP_ROOT_URL;
	}
	
	try
	{
		//jch - maybe test for window location and do not re-open the window, just focus?
		bDoNotResize = true;
		
		// help window arguments:
		// allow resizing and show the location bar, but turn off the toolbars
		var sHelpWinOpenArgs = "resizable=1,toolbars=0,location=1,status=1,scrollbars=1";
		
		// calculate the current window and screen dimensions
		var nWindowWidth = window.innerWidth || document.body.clientWidth;
		var nWindowHeight = window.innerHeight || document.body.clientHeight;
		var nScreenWidth = screen.availWidth;
		var nScreenHeight = screen.availHeight;
	
		// calculate the proposed new width dimensions
		var nNewMainWindowWidth = parseInt((nWindowWidth/3)*2);
		var nNewHelpWindowWidth = nWindowWidth - nNewMainWindowWidth;
	
		// determine if the windows are to be sized (if within 100 pixels)
		var bSizeWindows = (nWindowWidth - nScreenWidth > - 100) ? !bDoNotResize : false;
		if(bSizeWindows)
		{
			sHelpWinOpenArgs = sHelpWinOpenArgs + ",height=" + (nScreenHeight-80) + ",width=" + (nNewHelpWindowWidth-10);
		}
		
		var sHelpRoot = HELP_ROOT_URL;
		var sTranslationLanguageID = g_nTranslationLanguageID;
		if(sTranslationLanguageID != "1033")
		{
		    sHelpRoot = sHelpRoot.replace("1033",sTranslationLanguageID);
		}
		
		//-->add querystring arguments for help...
		if(sHelpTopicUrl.indexOf("http://") > -1)
		{
		    sHelpTopicUrl = sHelpRoot + "?" + sHelpTopicUrl.split("/")[6] + "?toc.htm?nFeatureMask=" + g_nEnabledFeatureMask;
		}
		else if(sHelpTopicUrl != "index.htm")
		{
		    sHelpTopicUrl = sHelpRoot + "?" + sHelpTopicUrl + "?toc.htm?nFeatureMask=" + g_nEnabledFeatureMask;
		}
		else
		{
		    sHelpTopicUrl = sHelpRoot + "?nFeatureMask=" + g_nEnabledFeatureMask;
		}
		
		// open the help window and resize windows if needed
		var oHelpWindow = window.open(sHelpTopicUrl, "help", sHelpWinOpenArgs);
		if(oHelpWindow == null)
		{
			alert(MainMenu.t_sPopupFailedMessage);
			return;
		}
		
		if(bSizeWindows)
		{	
			oHelpWindow.moveTo(nNewMainWindowWidth+2 ,0);
			window.resizeTo(nNewMainWindowWidth, nScreenHeight);
			window.moveTo(0,0);
			// flag for resizing back on help window close
			bWindowResizedByHelp = true;
		}
		oHelpWindow.focus();
	}
	catch(e)
	{
		alert(MainMenu.t_sPopupFailedMessage + "\n\nERROR: " + e.message);
	}
}

// 
//help window needs... [I tested at the bottom of /WebHelp/whver.js]
//try { window.onunload = parent.window.opener.OnHelpWindowClose; }
//catch(e) {}
//this will resize the window back after the help window closes
// jch - also - maximizing ie is wierd - investigate
function OnHelpWindowClose()
{
	if(bWindowResizedByHelp)
	{
		bWindowResizedByHelp = false;
		window.resizeTo(screen.availWidth, screen.availHeight);
		window.moveTo(0,0);
	}
}

_GetHttpRequestObject=function()
{
	try {return new XMLHttpRequest();} catch (e) {};
	try {return new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {};
	try {return new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {};
	return null;
}

var NOOP_INTERVAL=60000*5;

//---
// execute a NOOP every 5 minutes to keep the session from timing out
//---
function _DoNoop()
{
	try
	{
		var oHttpRequest = _GetHttpRequestObject();
		
		var oUrl = new CUrl();
		oUrl.Parse(document.location.href);
		oUrl.m_sUrlPath="/NmConsole/CoreNm/Framework/Noop.asp";
		oHttpRequest.open("GET", oUrl.AsString());
		oHttpRequest.onreadystatechange=function() {};
		oHttpRequest.send(null);
		
		setTimeout("_DoNoop();",NOOP_INTERVAL);
	}catch(e){};
}

setTimeout("_DoNoop();",NOOP_INTERVAL);