// File: helpSystem.js
// Purpose: Used by applications to display online help

/**
* <p>
* Displays default or contextual online help.
* To use, call showHelp on an instantiated HelpSystem object, eg:
*     var helpSystem = new  HelpSystem (see ctr params);
*     helpSystem.showHelp (actionFrame);
*
* Notes:
* - The default or contextual (helpURL) URL is either absolute (starts with http: or https:),
* or relative (eg /InfoViewApp/help/...), ie within a sibiling app context, in which case the required relative path
* (eg ../..) is prepended.
* - If 1 or more occurences of %LOC% are found in the help URL, they will be substitute for the current
* (installed) locale.
* </p>
* @param (String) actionFrame the frame of the currently displayed action.  If the frame is not null and contains a helpURL,
* its contextual help will be used instead ofthe app's default.
*/
function HelpSystem_ShowHelp (actionFrame) {	
	var urlToShow = this.defaultUrl;
	
    //if the actionFrame is pointing to iStore, we can't access properties.
    try	{
    if (actionFrame && actionFrame.helpURL)	
        urlToShow = actionFrame.helpURL;
    }
    catch(Exception){
        // ignore any caught exceptions and continue
    }
	
	if (urlToShow.substring(0,5).toLowerCase() != 'http:' &&
			urlToShow.substring(0,6).toLowerCase() != 'https:')
		urlToShow = this.rpContext + urlToShow;
	urlToShow = urlToShow.replace (/%LOC%/g, this.loc);	
	
	self.open (urlToShow, this.windowName, this.windowFeatures);	
}

/**
* <p>
* HelpSystem constructor
* Usage example: *     var helpSystem = new  HelpSystem (params);
* </p>
* @param (String) windowName the name of the window in which to display the application's online help.
* An empty string causes a new Window to open each time help is invoked.
* @param (String) windowFeatures features for the help window.
* The (uppercase) string 'DEFAULT' will use defaults HelpSystem's defaults.
* Note that an empty string causes help to display in a new tab in Firefox, depending on your browser settings.
* @param (String) defaultUrl the default help url for the application (non-localized)
* @param (String) rpContext the relative path to get out out of the current web app
* @param (String) loc the effective installed locale
*/
function HelpSystem (windowName, windowFeatures, defaultUrl, rpContext, loc) {
	this.showHelp = HelpSystem_ShowHelp;	// function
	
	this.windowName = windowName;
	if (windowFeatures == 'DEFAULT')
		this.windowFeatures = 'location=no,menubar=no,status=no,scrollbars=yes,resizable=yes';
	else
		this.windowFeatures = windowFeatures;
	this.defaultUrl = defaultUrl;
	this.rpContext = rpContext;
	this.loc = loc;
}

