// The following code is used for pointing Help links to specific topics
// set global vars
var RHWO_LOCATION	= 0x1;
var RHWO_MENUBAR	= 0x2;
var RHWO_RESIZABLE	= 0x4;
var RHWO_TOOLBAR	= 0x8;
var RHWO_STATUS		= 0x10;
var RHWO_SCROLLBARS	= 0x20;
var swh_strAgent   = navigator.userAgent.toLowerCase();
var swh_IE     = (swh_strAgent.indexOf("msie") != -1);
var AUTOCONTEXTID_PREFIX = "HelpIdFromHTMLHelp";

var strWebHelpPath = "http://www.wam1.landata.com/Help/WAM_Help_rhc.htm";

// WindowOption Object used to pass browser setting to launch the help system
function RH_WindowOption()
{
	this.m_nStyle = 0;
	this.m_nTop = -1;
	this.m_nLeft = -1;
	this.m_nHeight = -1;
	this.m_nWidth  = -1;
}

/**********************************************
 Show Help topic
 Parameters:
  [in] strUrlToHelpSet:  url to helpset. for WebHelp Enterprise it is the url to server name, such as "http://helpserver.com/RoboApi.asp"
                           for webhelp, it is full path name the webhelp start page name, such as "c:/myapp/help/start_rhc.htm" or "/user/myapp/help/start_rhc.htm"
  [in] strContextID:     context id of the topic
  [in] strTargetId:      browser's target name, such as "mynewtopic"
  [in] cWindowOption:   browser options. can be 0.
 Result:
   none.
**********************************************/

function RH_ShowHelpByString(strUrlToHelpSet, strContextID, strTargetId, cWindowOption)
{

	if (strUrlToHelpSet == null || strUrlToHelpSet == "" ) return;
	if (cWindowOption == null)
	{
		cWindowOption = new Object();
		cWindowOption.m_nStyle = 0;
		cWindowOption.m_nTop = 10;
		cWindowOption.m_nLeft = 10;
		cWindowOption.m_nHeight = 300;
		cWindowOption.m_nWidth  = 400;
	}

	var strURL = "";
	if (strContextID == null) 
		strContextID = "";

	var bServerBased=false;
	//let different agent to make url.
	if (IsServerBased(strUrlToHelpSet))
	{
		strURL = MakeUrlForServerBased(strUrlToHelpSet,strContextID);
		bServerBased=true;
	}
	else
	{
		strURL = MakeUrlForWebHelpBased(strUrlToHelpSet,strContextID);
	}
	ShowHelpTopic(strURL, cWindowOption, strTargetId, bServerBased);
}

function IsServerBased(strUrlToHelpSet)
{
	return (strUrlToHelpSet.toLowerCase().lastIndexOf(".asp") == 
		strUrlToHelpSet.length - 4);
}

function MakeUrlForServerBased(strUrlToHelpSet,strContextID)
{
	return strUrlToHelpSet + "?context=" + strContextID;
}

function MakeUrlForWebHelpBased(strUrlToHelpSet,strContextID)
{
	return strUrlToHelpSet + "#context=" + strContextID;
}

function ShowHelpTopic(strUrl, cWindowOption, strTargetId, bServerBased)
{
	var strHelpOptions = "";
	
	if (cWindowOption.m_nStyle & RHWO_LOCATION)			// Show/Hide Address bar {yes | no}
		strHelpOptions += ",location=yes";
	else
		strHelpOptions += ",location=no";

	if (cWindowOption.m_nStyle & RHWO_TOOLBAR)			// Show/Hide Toolbar {yes | no}
		strHelpOptions += ",toolbar=yes";		
	else
		strHelpOptions += ",toolbar=no";		

	if (cWindowOption.m_nStyle & RHWO_MENUBAR)			// Show/Hide Menubar {yes | no}
		strHelpOptions += ",menubar=yes";		
	else
		strHelpOptions += ",menubar=no";

	if (cWindowOption.m_nStyle & RHWO_STATUS)			// Show/Hide Statusbar {yes | no}
		strHelpOptions += ",status=yes";		
	else
		strHelpOptions += ",status=no";		

	if (cWindowOption.m_nStyle & RHWO_SCROLLBARS)			// Show/Hide Scrollbar {yes | no}
		strHelpOptions += ",scrollbars=yes";
	else
		strHelpOptions += ",scrollbars=no";	

	if (cWindowOption.m_nStyle & RHWO_RESIZABLE)			// Allow help window resizing {yes | no}
		strHelpOptions += ",resizable=yes";
	else
		strHelpOptions += ",resizable=no";

	if (cWindowOption.m_nTop >= 0)
	{
		strHelpOptions += ",top=" + cWindowOption.m_nTop;		// Top position for help window (in pixels)
		strHelpOptions += ",screenY=" + cWindowOption.m_nTop;		// Top position for help window (in pixels)(for netscape)
	}

	if (cWindowOption.m_nLeft >= 0)
	{
		strHelpOptions += ",left=" + cWindowOption.m_nLeft;		// Left position for help window (in pixels)
		strHelpOptions += ",screenX=" + cWindowOption.m_nLeft;	// Left position for help window (in pixels)(for netscape)
	}

	if (cWindowOption.m_nWidth > 0)
	{
		strHelpOptions += ",width=" + cWindowOption.m_nWidth;		// Width of help window (in pixels)
		strHelpOptions += ",outerWidth=" + cWindowOption.m_nWidth;	// Width of help window (in pixels) (for netscape)
	}

	if (cWindowOption.m_nHeight > 0)
	{
		strHelpOptions += ",height=" + cWindowOption.m_nHeight;	// Height of help window (in pixels)
		strHelpOptions += ",outerHeight=" + cWindowOption.m_nHeight;	// Height of help window (in pixels) (for netscape)
	}

	if (swh_IE) {
		if (bServerBased)
		{
			window.open(strUrl, strTargetId, strHelpOptions);  
		}
		else
		{
			strUrl = strUrl+","+ strHelpOptions;
			strHelpOptions = "left=2000,top=2000,height=1,width=1";
			window.open(strUrl, strTargetId, strHelpOptions);
		}
	}
	else {
		window.open(strUrl, strTargetId, strHelpOptions);
	}
}

// function to be used in code
function ShowWAMhelp(strContext)
{
	var MyWin = new RH_WindowOption();
	MyWin.m_nStyle = RHWO_TOOLBAR | RHWO_STATUS | RHWO_RESIZABLE | RHWO_SCROLLBARS;
	MyWin.m_nTop = 0;
	MyWin.m_nLeft = 0;
	MyWin.m_nHeight = window.screen.availHeight - 100;
	MyWin.m_nWidth = 750;

	// First parameter should hold the path to the WebHelp_rhc.htm file. 
	// In this example, a global variable is used
	RH_ShowHelpByString(strWebHelpPath, strContext, "Help", MyWin);
}