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

var numberOfTabs = 0;
var dimCache;

function syncToolbar()
{
	topparent.getToolbarFrame().sync();
}

function reloadToolbar() {
	topparent.getToolbarFrame().ButtonEnable();
}

function isSplitDisplay()
{
	var fh = document.fhidden;
	if (!fh.YS)
		return false;
	return true;
}

function initxtabcache() {
    xtabCache.initialize(document.getElementById("innerNice1-tab0"));
}

function init(num, tabs) {
	initDebug();

	dimCache = topparent.getGlobal("dimCache");
	if (hasDimensionBar)
	{
		init_dimbar();
	}	

	ContextMenu.initialize(true,false);

	topparent.getConfigFrame().selectedRows.length = 0;
	topparent.getConfigFrame().selectedColumns.length = 0;

	var el = document.getElementById("hideShowTree");
	if (el != null)
	{
		if ( !topparent.getGlobal("treeVisible") )
			el.src = topparent.getGlobal("imgPath") + "open_tab.gif";
		else
			el.src = topparent.getGlobal("imgPath") + "close_tab.gif";

		el.style.visibility = "visible";
	}

	numberOfTabs = tabs;
	var zIndexMax = 1;

	var tabIdx = 0;
	if (hasDimensionBar)
	{
		testDivBar = document.getElementById("testDivBar-tab0");
		if (testDivBar) {
			dimBarData = getDimBarData()[tabIdx]["testDivBar"];
			testDivBar.style.top = dimBarData.top;
			testDivBar.style.left = dimBarData.left;
			testDivBar.style.zIndex = dimBarData.zIndex;
		}
	}

	if ( isSplitDisplay() )
		topparent.openChartPane();

	syncToolbar();
	doResize();
	populateHiddenFormObject();
	if (topparent.initializedFrames["DimTree"])
		updateTree();

	xtabCache = new xtabCache();
	initxtabcache();
	InitDragCursor();

	initialize_ppwbInfo();

	if (!topparent.getGlobal('is_dashboard')) {
		var dimTreeVisible = getCookie("DimTreeVisible");
		if (dimTreeVisible && dimTreeVisible == "False") {
			if (topparent.getGlobal("treeVisible") && document.getElementById("hideShowTree"))
					toggleTree(null,document.getElementById("hideShowTree"));
		} else {
			if (!topparent.getGlobal("treeVisible") && document.getElementById("hideShowTree"))
					toggleTree(null,document.getElementById("hideShowTree"));
		}
	}	
	
	var dimTreeToolbarVisible = getCookie("DimTreeToolbarVisible");
	if (dimTreeToolbarVisible == "False")
		topparent.closeTreeToolbarFrame();
	else
		topparent.openTreeToolbarFrame();	
}

function reloadActionPane() {
	if(fh.ACTPANE.value != 0 && fh.ACTPANE.value != 10) {
		var bSelections = getSelected("r").length || getSelected("c").length;

		if(topparent.wasRedirected()) {
			topparent.setWasRedirected("0");
			if (topparent.getActionFrame().ppesRedirectPage)
				topparent.closeActionPane();
			return;
		}

		switch (fh.ACTPANE.value) {	
			case "1":	//reload find pane only if find in report on
				var findPane = topparent.getActionFrame();
				if(findPane.searchForm && findPane.searchForm.searchTarget && findPane.searchForm.searchTarget.value == 'C')
					return;
				break;	
			case "4":	//reload explain pane if there are selections and set it to cube explain
				if(fh.EXPL.value != '1')
					fh.EXPL.value = 1;
				break;
			case "8":	//never reload custom exception pane
				return; 
			default:
				break;
		}

		fh.CNCT.value = 19;
		fh.target = "ActionPane";
		parseAndSubmit(fh);
	}
}

function getDimBarData() {
	var dbData = topparent.getConfigFrame().dimBarData;
	if (dbData)
		return dbData;
	else
		return dimBarData;
}

//stubs all calls because the debugger is not present...
function NoDebugger() {
	this.debugWindowString = "";
	this.debugWin = "";
	this.maxDebugLength = "";
	this.startTime = "";
	this.stack = "";
	this.execprofile = "";
	this.action = "";
	this.lastCaller = "";
	this.dumpObjects = "";
	this.appendOutput = "";
	this.fontSize = "";
}

NoDebugger.prototype.out = function () { return false; }
NoDebugger.prototype.dumpArgs = function () { return false; }
NoDebugger.prototype.dumpArguments = function () { return false; }
NoDebugger.prototype.dumpObj = function () { return false; }
NoDebugger.prototype.dumpObject = function () { return false; }
NoDebugger.prototype.getObjectName = function () { return false; }
NoDebugger.prototype.getFunctionName = function () { return false; }
NoDebugger.prototype.createFunctionWrapper = function () { return false; }
NoDebugger.prototype.createMethodWrapper = function () { return false; }
NoDebugger.prototype.traceBefore = function () { return false; }
NoDebugger.prototype.traceAfter  = function () { return false; }
NoDebugger.prototype.traceFunction = function () { return false; }
NoDebugger.prototype.traceObject = function () { return false; }
NoDebugger.prototype.dumpProfile = function () { return false; }
NoDebugger.prototype.storeAsString = function () { return false; }

function initDebug() {
	if (typeof pdb == "undefined" && typeof Debugger != "undefined")
	{
		pdb = new Debugger();
		pdb.out("Debugger succesfully initialized!");
	}
	else
		pdb = new NoDebugger();
}

function legendItemRec(name,id,suppressed) {
	this.name = name;
	this.id = id;
	this.suppressed = suppressed;
}