// Copyright (C) 2007 Cognos Incorporated. All Rights Reserved.
// Cognos and the Cognos logo are trademarks of Cognos Incorporated.

// These are the languages (English, French, Japanese, Germany, Swedish and Spanish) that are supported by Cognos 8 Bering.
var sSupportedLangs = " en fr ja de sv es ";
var sDefaultLang = "en";

var sDefaultFeaturesHelp = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=680,height=500";

var sDefaultFeaturesQuickTours = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600";

function getSupportedLang(sProductLocale)
{
	// Use the first two letters of the locale string to construct the path to the localized folder.  
	// Make sure they are converted to lowercase.
	var sLang = sProductLocale;
	sLang = sLang.toLowerCase();

	if ( sSupportedLangs.indexOf(" " + sLang + " ") < 0 )
		sLang = sDefaultLang;
	
	return sLang;
}

// A common API to fire up help documentation
// 	@sProductLocale:	the target product locale
// 	@sStartupFile:		the start up file
// 	@sContext:		the web context line
function gotoHelp( sProductLocale, sStartupFile, sContext )
{	
	var sLang = getSupportedLang(sProductLocale);

	var sURL = "../documentation/" + sLang + "/" + sStartupFile;

	sURL += (sContext == "") ? ".html" : ".html?helpid=" + sContext;
	
	helpWindow = window.open(sURL, "helpWindow", sDefaultFeaturesHelp);
	helpWindow.focus();
}

// A common API to fire up tours documentation
// 	@sProductLocale:	the target product locale
// 	@sStartupFile:		the start up file under tours folder
//	@sOptions:		the options
function gotoTours( sProductLocale, sStartupFile, sOptions )
{
	var sLang = getSupportedLang(sProductLocale);
	
	var sURL = "../documentation/" + sLang + "/tours/" + sStartupFile + ".html";

	if ( sOptions != null )
	    sURL += "?" + sOptions;

	var toursWindow = window.open(sURL, "toursWindow", sDefaultFeaturesQuickTours);
	toursWindow.focus();
}


// The following two APIs will help ReportStudio & CMM etc. for redirecting purpose.
function initDocs()
{
	var query = parseHash(window.location.href); // read URL for topic/section info

	var sLang = sDefaultLang;
	var sBook = "wig_cr_a"; // Drfault to "Get Started" documentation
	var sHelpID = "";
	var sCurrentTopic = "";

	if( query['lang'] && (query['lang'] != "") ) {
		sLang = getSupportedLang(query['lang']);
	}

	if( query['book'] && (query['book'] != "") ) {
		sBook = query['book'];
	}

	if( query['helpid'] && (query['helpid'] != "") ) {
		sHelpID = query['helpid'];
	}

	sCurrentTopic = sLang + "/" + sBook + ".html";

	if( sHelpID != "" )
		sCurrentTopic += "?helpid=" + sHelpID;

	// determine full path to html
	var sDirTopics = "";
	var sDirString = window.location.href.substring(0, window.location.href.indexOf('?') );
	var nPos = sDirString.lastIndexOf('/');
	sDirTopics = (nPos != -1) ? window.location.href.substring(0, nPos + 1) : "";

	sCurrentTopic = sDirTopics + sCurrentTopic;

	window.location.href = sCurrentTopic;
}

function parseHash(s)
{
	var query = new Array();
	var nPos = s.indexOf("?");

	if (nPos != -1)
	{
		s = s.substring(nPos + 1, s.length);
		var sPair = "";
		while (s != "")
		{
			nPos = s.indexOf("&");
			if (nPos == -1) { sPair = s; s = ""; }
			else {	sPair = s.substring(0, nPos); s = s.substring(nPos + 1, s.length); }
			nPos = sPair.indexOf("=");
			if (nPos != -1) query[sPair.substring(0, nPos)] = unescape(sPair.substring(nPos + 1, sPair.length));
		}
	}

	return query;
}

