// eHelp® Corporation
// Copyright© 1998-2001 eHelp® Corporation.All rights reserved.
// RoboHelp_CSH.js 
// This is a Helper js file for RoboInfo and WebHelp Content Sensitive Help (CSH). 
// Contents used as the options for widnow.open.
// It only supports IE4+ and NS4+.
//

/* Example function calls
// First, create RH_WindowOption object
var MyWin = new RH_WindowOption();
// Set window style and position in object
MyWin.m_nStyle = RHWO_LOCATION | RHWO_MENUBAR | RHWO_RESIZABLE;
MyWin.m_nTop = 50;
MyWin.m_nLeft=50;
MyWin.m_nHeight=300;
MyWin.m_nWidth=400;

// Show Help for topic with HTML Help Map number 11:
RH_ShowHelpById("c:\\myapp\\help\\start_rhc.htm", "11", "myHelpWindow", MyWin)

// Show Help for topic with Context String ID "My_Topic"
RH_ShowHelpByString("c:\\myapp\\help\\start_rhc.htm", "My_Topic", "myHelpWindow", MyWin)
*/


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";


/* 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 by topic number generated for HtmlHelp.
 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] nTopicNumber:     topic number generated for the HTMLHelp context sensitive help.
  [in] strTargetId:      browser's target name, such as "mynewtopic"
  [in] cWindowOption:   browser options. can be 0.
 Result:
   none.
**********************************************/

function RH_ShowHelpById(strUrlToHelpSet, nTopicNumber, strTargetId, cWindowOption)
{
	strContextID = AUTOCONTEXTID_PREFIX + "_" + nTopicNumber;
	RH_ShowHelpByString(strUrlToHelpSet, strContextID, strTargetId, cWindowOption);
}

/**********************************************
 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, "HelpStub", strHelpOptions);  
		}
		else
		{
			strUrl = strUrl+","+ strHelpOptions;
			strHelpOptions = "left=2000,top=2000,height=1,width=1";
			window.open(strUrl, "HelpSecondary", strHelpOptions);
		}
	}
	else {
		window.open(strUrl, "HelpStub", strHelpOptions);
	}
}
