/********************************************************************************************************************************
* Licensed Materials - Property of IBM                                                                                          *
*                                                                                                                               *
* IBM Cognos Products: AGS                                                                                                      *
*                                                                                                                               *
* (C) Copyright IBM Corp. 2005, 2018                                                                                            *
*                                                                                                                               *
* US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
*********************************************************************************************************************************/

//help and table of contents
var HELP_CONTENTS_DEFAULT="ug_cr_es_a";	
//the help page with no table of contents
var HELP_CONTENTS_WITH_HID="ug_cr_es";	
var QUICK_TOUR = "estour";

var ES_GETTING_STARTED = "wig_cr_a";

var ES_VIEW_CONTENTS = "ug_cr_es_a";

/*
document.onkeydown = test;
function test(event) {
    if (window.event.keyCode==112) {
        alert(window.event.srcElement.outerHTML);
        window.event.cancelBubble=true;
        window.event.returnValue = false;   
    }    
}
*/

document.onhelp = parent.viewCSHelp;
//Help->Help
//fire the context sensitive help from the application menu bar
function viewHelp() {
    //viewCSHelp('');
	// online link only as Help is not packaged
    getOnlineHelp();
}
function getOnlineHelp(topic) {
    //viewCSHelp('');
	var locale = "en";
	if (productLocale) {
		locale = productLocale;
	}
	// online link only as Help is not packaged
	var helpFilePrefix = "http://www.ibm.com/support/knowledgecenter/"; //The ES Help url, now hosted on IBM Knowledge Center.
	var helpFileSuffix = "SSEP7J_11.0.0/com.ibm.swg.ba.cognos.ug_cr_es.doc/";
	var _helpTopic = "c_ug_cr_es_wlcm.html";
	if(topic != null){
		_helpTopic = topic;
	}
	var helpFileFullURL = helpFilePrefix + helpFileSuffix + _helpTopic;
	
    openHelp(helpFileFullURL);
}
//Help->Contents
function viewContents()
{
	var locale = "en";
	if (productLocale) {
		locale = productLocale;
	}
	var helpTopic = '/c_event_studio.html#event_studio';
	getOnlineHelp( helpTopic );
}

//Help->Quick Tour
function viewTour()
{	
    var locale;
    //set the locale
	if (productLocale) {
		locale = productLocale;
	}
    
	gotoTours(locale, QUICK_TOUR);
}

//Help->Contents
function viewGetStarted()
{
	var locale = "en";
	if (productLocale) {
		locale = productLocale;
	}
		
    gotoHelp( locale, ES_GETTING_STARTED, "" );
}

//Help->Cognos on the Web
function onTheWeb()
{
	var sFeatures = "toolbar=yes,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=750";
	sURL = "http://www-01.ibm.com/software/data/cognos";
	windowHelp = window.open(sURL, "Cognos_on_the_Web", sFeatures);
	windowHelp.focus();
}

//Help->About
function showAbout() {
	dlgReset();
	//st in form vars
	initialiseDialog();
	
	dlgSetParm("m", '/ags/about.xts');
	dlgSetParm('popUpWidth',"658"); 
	dlgSetParm('popUpHeight',"511"); 
	dlgSubmit("popUpFrame");	
}

//context sensitive help
function viewCSHelp(hid)
{
    var found = false;
	var locale = "en";
	var helpIndex = '';
    var helpFile=HELP_CONTENTS_WITH_HID;
	
	//assign the help index if one has been passed to this function
	if (hid && hid.length > 0) {
	    helpIndex = hid;   
	    found=true;
	}
    //loop through the forms in the message frame    
    //we are looking for a hidden input called 'hid' which defines
    //the help context
	else {
        helpIndex = getHelpId();    
        if (helpIndex != '') {
            found = true;
        }
    }
    	
    //set the locale
	if (productLocale) {
		locale = productLocale;
	}
	
    //no help id has been found so show the table of contents and introduction
	if (!found) {
	    helpFile = HELP_CONTENTS_DEFAULT;
	}
	
	//alert("locale:"+locale+",file:"+helpFile+",id:"+helpIndex);
	
	//load the help page
	gotoHelp( locale,helpFile,helpIndex);

    //prevent the default windows explorer help file from loading
	if (window.event) {
        window.event.cancelBubble=true;
        window.event.returnValue = false;   
    }
    
    return false;
}

//get the help id from the message frame form with the name 'hid'
//return the help id or an empty string if it does not exist
function getHelpId() {
    var popupFrame;
    var msgFrame = getMessageIFrame();
    var msgDoc = getFrameDocument(msgFrame);
    var forms = msgDoc.forms;
	var helpIndex = '';    
	var found = false;
	
	//firstly check if the modal popup is visible and has an available hid
	if (typeof popUpIsOpen == "function" && popUpIsOpen() == true) {
	    //alert('found open popup');
	    
	    popupFrame = document.frames['popUpFrame'];
	    popupForm = popupFrame.pform;

	    //check if the popup frame has a hid otherwise we will use the message frame hid
	    if (popupForm != undefined && popupForm.hid) {
	        
	        //assign the forms available in the popup
	        forms = popupFrame.document.forms;
	    }
	}
    
    //loop through the forms. We are looking for a hidden input called 'hid' which defines the help context
    for (var i=0;i<forms.length;i++) {
        
        var form = forms[i];
        
        //loop through the controls in the form
        for (var j=0;(j<form.length && !found);j++) {
            
            var control = form.elements[j];
            
            if (control.getAttribute('type')=='hidden' && control.name=='hid') {
                helpIndex = control.value;
                found=true;
            }
        }
    }
    
    return helpIndex;
}