//==============================================================================
// JAVASCRIPT COMMON FUNCTIONS ARE DIVIDED INTO THREE MAIN SECTIONS:
// 1. COMMON FUNCTIONS FOR ALL OUR PAGES
// 2. COMMON FUNCTIONS THAT ARE USED FOR THE LAYOUT OF THE PAGE
// 3. COMMON EVENT HANDLER FUNCTIONS
//------------------------------------------------------------------------------

var GJSSYS_BROWSER_UNKNOWN = 0;
var GJSSYS_BROWSER_N451    = 1;
var GJSSYS_BROWSER_MS55    = 2;
var GJSSYS_BROWSER_MS50    = 3;
var GJSSYS_BROWSER_MS401   = 4;
var GJSSYS_BROWSER_N6      = 5;
var GJSSYS_BROWSER_MS6     = 6;
var GJSSYS_BROWSER_N70     = 7;
var GJSSYS_BROWSER_N71     = 8;

var PWdsapp_eBrowser;
var PWdsapp_bIsIE;
var PWdsapp_bActiveXEnabled;

var REPORT_TYPE_FOLDER = 0;
var REPORT_TYPE_TABLE = 1;
var REPORT_TYPE_QT = 2;
var REPORT_TYPE_CHART = 3;
var REPORT_TYPE_EXCEL = 4;
var REPORT_TYPE_PDF = 5;
var REPORT_TYPE_ITEMSEL = 6;
var REPORT_TYPE_DOC = 7;
var REPORT_TYPE_HTM = 8;
var REPORT_TYPE_HTML = 9;
var REPORT_TYPE_PPT = 10;
var REPORT_TYPE_TXT = 11;
var REPORT_TYPE_MAP = 13;

var bFullScreen;
var G_strRootPath = "";

// Ensure 'undefined' is defined.
var undefined;

//Wds Form
var ObjWdsForm;

// used for encoding in older browsers.
var G_bURIEncode = typeof encodeURIComponent == "function";
var hexchars = "0123456789ABCDEF";
var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

//==============================================================================
// COMMON FUNCTIONS THAT CAN BE CALLED FROM ALL OF OUR PAGES
//------------------------------------------------------------------------------
//==============================================================================
// Functions that are called once, during initialization.
//------------------------------------------------------------------------------
// Get the Browser type and version
function GetBrowser()
{
	var dAppVersion;
	var szAppName;

	PWdsapp_bIsIE = false;
	szAppName = navigator.appName;
	if (szAppName == "Netscape") {
		dAppVersion = parseFloat(navigator.appVersion);
		if (dAppVersion >= 5.0) {
			PWdsapp_eBrowser  = GJSSYS_BROWSER_N6;
			dAppVersion = parseFloat(navigator.userAgent.split("Netscape/")[1]);
			if( dAppVersion == 7.0 )
				PWdsapp_eBrowser = GJSSYS_BROWSER_N70;
			else if( dAppVersion >= 7.1 )
				PWdsapp_eBrowser = GJSSYS_BROWSER_N71;
		}
		else if (dAppVersion >= 4.51) {
			PWdsapp_eBrowser  = GJSSYS_BROWSER_N451;
		}
	}
	else if (szAppName == "Microsoft Internet Explorer") {
		PWdsapp_bIsIE = true;
		dAppVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);

		if (dAppVersion >= 6.0) {
			PWdsapp_eBrowser = GJSSYS_BROWSER_MS6;
		}
		else if (dAppVersion >= 5.5) {
				PWdsapp_eBrowser = GJSSYS_BROWSER_MS55;
		}
		else if (dAppVersion >= 5.0) {
			PWdsapp_eBrowser = GJSSYS_BROWSER_MS50;
		}
		else if (dAppVersion >= 4.01) {
			PWdsapp_eBrowser = GJSSYS_BROWSER_MS401;
		}
	}
	else {
		PWdsapp_eBrowser = GJSSYS_BROWSER_UNKNOWN;
	}
}

GetBrowser();

// ----------------------------------------------------------------------------
// Check if ActiveX support is enabled.
function CheckActiveX()
{
   PWdsapp_bActiveXEnabled = false;
   // If IE, test if ActiveX support is enabled.
   if(PWdsapp_bIsIE) {
      try {
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
         PWdsapp_bActiveXEnabled = true;
	   }
	   catch(ex) {
		}
   }
}

CheckActiveX();

/*------------------------------------------------------------------------------
** Most of this code was kindly 
** provided to me by
** Andrew Clover (and at doxdesk dot com)
** http://and.doxdesk.com/ 
** in response to my plea in my blog at 
** http://worldtimzone.com/blog/date/2002/09/24
** It was unclear whether he created it.
** This replaces encodeURIComponent which is not available in earlier browsers (IE 5.0)
*/
function utf8(wide) {
	var c, s;
	var enc = "";
	var i = 0;
	while(i<wide.length) {
		c= wide.charCodeAt(i++);
		// handle UTF-16 surrogates
		if (c>=0xDC00 && c<0xE000) continue;
		if (c>=0xD800 && c<0xDC00) {
			if (i>=wide.length) continue;
			s= wide.charCodeAt(i++);
			if (s<0xDC00 || c>=0xDE00) continue;
			c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
		}
		// output value
		if (c<0x80) enc += String.fromCharCode(c);
		else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
		else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
		else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
	}
	return enc;
}

// ----------------------------------------------------------------------------
function toHex(n) {
	return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

// ----------------------------------------------------------------------------
function encodeURIComponentOld(s) {
	var s = utf8(s);
	var c;
	var enc = "";
	for (var i= 0; i<s.length; i++) {
		if (okURIchars.indexOf(s.charAt(i))==-1)
			enc += "%"+toHex(s.charCodeAt(i));
		else
			enc += s.charAt(i);
	}
	return enc;
}

// ----------------------------------------------------------------------------
function URIencode(i_strString) {
	
	if (G_bURIEncode) {
        return encodeURIComponent(i_strString);
    }
    else {
        return encodeURIComponentOld(i_strString);
    }
}

//------------------------------------------------------------------------------
function HTMLencode(
   i_strString
   )
{
   var encodedResult;
   
   encodedResult = i_strString;
   if (i_strString.indexOf("&") > -1 || i_strString.indexOf("<") > -1 
         || i_strString.indexOf(">") > -1 || i_strString.indexOf("'") > -1 
         || i_strString.indexOf('"') > -1 || i_strString.indexOf("·") > -1)
   {
      // the & must be done first.
      encodedResult = encodedResult.replace("&","&amp;");
      encodedResult = encodedResult.replace("<","&lt;");
      encodedResult = encodedResult.replace(">","&gt;");
      encodedResult = encodedResult.replace("'","&apos;");
      encodedResult = encodedResult.replace("\"","&quot;");
      encodedResult = encodedResult.replace("·","&#183;");  
   }

   return encodedResult;
}

// ----------------------------------------------------------------------------
function TrimWhiteSpace(i_strName)
{
	var strName = i_strName;
	while (strName.charAt(0) == ' ')
		strName = strName.substr(1);
	while (strName.charAt(strName.length-1) == ' ')
		strName = strName.substr(0, strName.length - 1);
	return strName;
}

//Get the back ground color for this perticular style.
// ----------------------------------------------------------------------------    
function getBackGroundColor(strBackGroundStyle)
{
	var bkgColor;
	var bkgColorIndex = getStyleSheetRuleIndex(strBackGroundStyle);

	// If the browser supports the W3C DOM way, use cssRules.
	if (document.styleSheets[0].cssRules) {
		bkgColor = document.styleSheets[0].cssRules[bkgColorIndex].style.backgroundColor;
	}
	// If it supports the Microsoft way, use rules.
	else if (document.styleSheets[0].rules) {
		bkgColor = document.styleSheets[0].rules[bkgColorIndex].style.backgroundColor;
	}

	return bkgColor;
}

//Get the index where this perticular style exists in the style sheet.
// ----------------------------------------------------------------------------
function getStyleSheetRuleIndex(strBackGroundStyle)
{
	var astrRules;

	// If the browser supports the W3C DOM way, use cssRules.
	if (document.styleSheets[0].cssRules) {
		astrRules = document.styleSheets[0].cssRules;
	}
	// If it supports the Microsoft way, use rules.
	else if (document.styleSheets[0].rules) {
		astrRules = document.styleSheets[0].rules
	}
	for (var i = 0; i < astrRules.length; i++) {
		if (astrRules[i].selectorText == strBackGroundStyle) {
			return i;
		}
	}

	return false;
}

//==============================================================================
// COMMON FUNCTIONS THAT ARE USED FOR THE LAYOUT OF THE PAGE
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function myfocus(obj)
{
   var coverTop = document.getElementById("CoverTop");
	if (obj.style.visibility != 'hidden' && coverTop == null) {
		obj.focus();
		if( obj.select != undefined )
			obj.select();
	}
	else {
	   obj.blur();
	}
}

//------------------------------------------------------------------------------
// This function works only for Netscape
function testScroll()
{
	// Initialize scrollbar cache if necessary
	if (window._pageXOffset == null) {
		window._pageXOffset = window.pageXOffset;
		window._pageYOffset = window.pageYOffset;
	}
	// Expose Internet Explorer compatible object model
	document.body.scrollTop = window.pageYOffset;
	document.body.scrollLeft = window.pageXOffset;
	window.document.body.scrollHeight = document.height;
	window.document.body.scrollWidth = document.width;

	// If cache != current values, call the onscroll event
	if (((window.pageXOffset != window._pageXOffset) || 
		(window.pageYOffset != window._pageYOffset)) && (window.onscroll))
		window.onscroll();
	// Cache new values
	window._pageXOffset = window.pageXOffset;
	window._pageYOffset = window.pageYOffset;
}

// ----------------------------------------------------------------------------    
function IsOkSetActive()
{
	if( typeof(document.activeElement.type) == 'undefined') {
		return true;
	}
	return false;
}

// ----------------------------------------------------------------------------    
function onObjectClick()
{
	if (PWdsapp_bIsIE) {
		if (IsOkSetActive()) {
			if (PWdsapp_eBrowser == GJSSYS_BROWSER_MS55) {
				if (typeof(document.all['SpanTable']) != 'undefined') {
					setTimeout("document.all['SpanTable'].setActive();", 1);
				}
			}
		}
	}
}

// -----------------------------------------------------------------------------
function adjustPosition(nPos)
{
	if (typeof(nPos) == "undefined")
		nPos = 0;
	return nPos;
}

// ----------------------------------------------------------------------------    
function scrollToPosition()
{
	if (!PWdsapp_bIsIE) {
		window.scrollTo(getPositionX(), getPositionY());
	}
	else {
		document.all['SpanTable'].scrollTop = getPositionY();
		document.all['SpanTable'].scrollLeft = getPositionX();
	}
}

// ----------------------------------------------------------------------------    
function setWDSScroll()
{
	if (typeof(savePosition) != 'undefined') {

		if (!PWdsapp_bIsIE) {
			window.onscroll = savePosition;
			setTimeout("scrollToPosition();", 1);
		}
		else {
			// the logic should be better here.  There is not always
			// a SpanTable span, and if there is, it needs to be resized
			// and positioned differently depending on if the folder pane is
			// shown or hidden (maybe the search page too)
			if (typeof(document.all['SpanTable']) != 'undefined') {
				document.all['SpanTable'].onscroll = savePosition;

				var nTimeout;
				nTimeout = 100;
				if (typeof(ObjWdsForm.IF_ReportType) != 'undefined')
					{
					if (ObjWdsForm.IF_ReportType.value == REPORT_TYPE_CHART)
						nTimeout = 500;

					setTimeout("scrollToPosition();", nTimeout);
					}
			}
		}
	}
}

//  ----------------------------------------------------------------------------    
//  This function resets the chart pagination.
//  The paging variables for the chart view need to be reset whenever it is
//  possible that the selections can change (SPR 009345).  This code used to be 
//  called on entry into the chart view (ShowView), but was removed to solve a 
//  problem with maintaining the state when moving between tabs (SPR 008754).
//  TBD - A general solution is required for handling variables that need to be
//        maintained during tab and global actions (Help, Reports, Login, etc) 
//   -------------------------------------------------------------------------------------------
function ResetChartPagination()
{
   if (typeof(ObjWdsForm.sWD_ChartRow) != 'undefined'){
        ObjWdsForm.sWD_ChartRow.value = 0;
        ObjWdsForm.sWD_ChartCol.value = 0;
    }
}

//  --------------------------------------------------------------------------------------------    
//  This routine will initialize the form object, if the page has a form then an id
//  for that form will be retirved.   The entire WdsAsp solution will have the same form
//  name (WdsForm).
//   -------------------------------------------------------------------------------------------
function initWdsFormObj()
{    
    if (document.getElementById("WdsForm") != null ) 
    {
		ObjWdsForm = document.getElementById("WdsForm");
    } 
    else {
        ObjWdsForm = document.forms[0];
    }
}
// ----------------------------------------------------------------------------    
function onPageLoadGlobal()
{
	var clForm;

    // Get Wds Form from its Id 
    initWdsFormObj();
	
	// Reset all form variables back to original values (when HTML was loaded).
	clForm = ObjWdsForm;	
	clForm.reset();
	
	// Ensure the <select> fields are OK with the back button.
	// For each of the <select> elements
	var aSelects = document.getElementsByTagName( "select" )
	for( var nSelects = 0; nSelects < aSelects.length; nSelects++ )
	{
		// If that select element exists and has some <option> elements
		var objSelect = aSelects[ nSelects ];
		if (objSelect.selectedIndex >= 0 ) {  // if there is a selection 
		   if( ( objSelect != null ) && ( objSelect.options != null ) )
		   {	
			   // If the selected item is not the default item
			   if( !objSelect.options[ objSelect.selectedIndex ].defaultSelected )
			   {
				   // Search through all the options and select the default item.
				   for( var nIndex = 0; nIndex < objSelect.length; nIndex++ )
				   {
					   if( objSelect.options[nIndex].defaultSelected )
						   objSelect.selectedIndex = nIndex;
				   }
			   }
		   }
		}
	}

	if( clForm.CS_AppPath != undefined )
		G_strRootPath = clForm.CS_AppPath.value;

	// Compatibility layer for Netscape to test scroll position
	if (document.layers) {
		// This works only for Netscape
		document.body = new Object;
		setInterval("testScroll();", 100);
	}
	setWDSScroll();
	
	// Set focus to the Actions menu
	var actBtn = document.getElementById( "ActBtn" );
	if( actBtn != null )
		myfocus( actBtn );
		
	// Set the tableau size (if possible)
	var cell4 = document.getElementById( "cell4" );
	var actDiv = document.getElementById( "ActDiv" );
	if( ( actDiv != null ) &&
		( cell4 != null ) &&
		( clForm.CS_TableauHeight != undefined ) &&
		( clForm.CS_TableauWidth != undefined ) &&
		( clForm.CS_ActiveXEnabled != undefined ) )
	{
		// Determine the size of the client (<body>) area.
		var clientWidth;
		var clientHeight;
		if( window.innerWidth == undefined )
		{
			// IE
			clientWidth = document.body.clientWidth;
			clientHeight = document.body.clientHeight;
		}
		else
		{
			// NN
			clientWidth = window.innerWidth;
			clientHeight = window.innerHeight;
		}

		// Start with the width and height of the body
		var height = clientHeight;
		var width = clientWidth;

		// Remove the height of cell1 (top customization area)
		var cell = document.getElementById( "cell1" );
		if( cell != null )
			height -= cell.offsetHeight;

		// Remove the height of cell5 (bottom customization area)
		cell = document.getElementById( "cell5" );
		if( cell != null )
			height -= cell.offsetHeight;

		// Remove the width of cell2 (left customization area)
		cell = document.getElementById( "cell2" );
		if( cell != null )
			width -= cell.offsetWidth;

		// Remove the width of cell6 (right customization area)
		cell = document.getElementById( "cell6" );
		if( cell != null )
			width -= cell.offsetWidth;

		// Determine the absolute postion of the bottom of the Action button div.
		cell = actDiv;
		var actDivPosY = 0;
		while( cell != null )
		{
			actDivPosY += cell.offsetTop;
			cell = cell.offsetParent;
		}
		actDivPosY += actDiv.offsetHeight;

		// Determine the absolute postion of the top of cell4.
		cell = cell4;
		var cell4PosY = 0;
		while( cell != null )
		{
			cell4PosY += cell.offsetTop;
			cell = cell.offsetParent;
		}

		// Subtract the the Action button div height from the height of cell4.
		height -= ( actDivPosY - cell4PosY );

		// Store the tableau size.
		clForm.CS_TableauHeight.value = height;
		clForm.CS_TableauWidth.value = width;
		clForm.CS_ActiveXEnabled.value = PWdsapp_bActiveXEnabled;
	}
}

// ----------------------------------------------------------------------------
// Launch the ASP page that lists the tables.
function ListTables()
{
	if (typeof(ObjWdsForm) == 'undefined') {
		location = G_strRootPath + "/ReportFolders/reportFolders.aspx";
	}
	else {
		ObjWdsForm.CS_InHelp.value = "False";
		if (typeof(ObjWdsForm.sRF_Task) == 'undefined'
			|| ObjWdsForm.sRF_Task.value != '2')
		{
			ObjWdsForm.action = G_strRootPath + "/ReportFolders/reportFolders.aspx";
		}
		else { // advanced search page
			ObjWdsForm.action = G_strRootPath + "/ReportFolders/AdvancedSearch.aspx";
		}
		executeWait(ObjWdsForm);
	}
}

// ----------------------------------------------------------------------------
// Return the current dimension
function GetCurrentDim()
{
	if (document != null
		&& ObjWdsForm != null
		&& ObjWdsForm.sWD_CurDim != null
		)
	{
		return ObjWdsForm.sWD_CurDim.value;
	}
	else {
		return 0;
	}
}

// ----------------------------------------------------------------------------
// Return the highest dimension
function GetMaxDim()
{
	if (typeof(ObjWdsForm) == "undefined") {
		alert(resTableNoLoaded);
		return -1; // return an error indication
	}
	return ObjWdsForm.sWD_MaxDim.value;
}

// ----------------------------------------------------------------------------
function SpawnWindow()
{
	var strOldTarget;
	var wndSummary;
	var bSpawn = false;
	var szSummaryPage = "_WdsSummary";
	var szSummaryPath = "/TableViewer/summary.aspx";

	if (typeof(ObjWdsForm.CS_spawnwindow) != "undefined") {
		bSpawn = ObjWdsForm.CS_spawnwindow.value == "True" ? true : false;
	}
	if (bSpawn) {
		GenerateNewWindow(szSummaryPage, szSummaryPath);
	}

	return bSpawn;
}

//==============================================================================
// COMMON EVENT HANDLER FUNCTIONS
//-----------------------------------------------------------------------------
function OnRequestedLang(lang)
{
	try {
		if (typeof(SaveSelectionState) != "undefined") {
			SaveSelectionState();
		}
	}
	catch (ex) {
	}

	ObjWdsForm.CS_langSwitch.value = "True";
	
	var currLangObj = document.getElementById( "GL_CurrentLang" );
	if( currLangObj != null )
		ObjWdsForm.CS_ChosenLang.value = currLangObj.value;
	else
		ObjWdsForm.CS_ChosenLang.value = lang;

	if (typeof(ObjWdsForm) == 'undefined') {
		document.location = document.location.pathname;
	}
	else {
		ObjWdsForm.action = document.location.pathname;
		executeWait(ObjWdsForm);
	}
}

// -----------------------------------------------------------------------------
function OnLogin()
{
	var szDocumentPath;
	var szaDocumentPathTemp;
	var nNumberOfFolders = 0;
	var szCurrentPage = ""

	try {
		if (typeof(SaveSelectionState) != "undefined") {
			SaveSelectionState();
		}
	}
	catch (ex) {
	}
	
	szDocumentPath = document.location.pathname;

	szaDocumentPathTemp = szDocumentPath.split("/");
	nNumberOfFolders = szaDocumentPathTemp.length;

	if (typeof(gCurrentPage) != "undefined") {
		szCurrentPage = gCurrentPage;
	}
	if (szaDocumentPathTemp[nNumberOfFolders - 1].toLowerCase() != szCurrentPage.toLowerCase()) { 
		ObjWdsForm.LG_targetpage.value = szDocumentPath;
	}
	else if (ObjWdsForm.CS_TargetPage.value != "undefined" && ObjWdsForm.CS_TargetPage.value != "") {
	    ObjWdsForm.LG_targetpage.value = ObjWdsForm.CS_TargetPage.value;	      
	}	 
		
	ObjWdsForm.LG_reprompt.value = "";
	var szQueryString = document.location.search;
	ObjWdsForm.action = G_strRootPath + "/Common/Login/login.aspx" + szQueryString;
	ObjWdsForm.CS_InHelp.value = "False";
	executeWait(ObjWdsForm);
}

//------------------------------------------------------------------------------
function OnLogout()
{    
	ObjWdsForm.action = G_strRootPath + "/Common/Login/logout.aspx";
	executeWait(ObjWdsForm);
}

//-----------------------------------------------------------------------------
function RegisterUser()
{
	var szQueryString = document.location.search;
	ObjWdsForm.CS_InHelp.value = "False";
	ObjWdsForm.action = G_strRootPath + "/Common/Login/register.aspx" + szQueryString;
	executeWait(ObjWdsForm);
}

//-------------------------------------------------------------------------------
function OnDataBank()
{
	if (typeof(zeroScrollPosition) != "undefined") {
	   zeroScrollPosition();
	}
	
	if (typeof(SaveSelectionState) != "undefined") {
	   SaveSelectionState();
	}
	
	ListTables();
}

// ----------------------------------------------------------------------------
function ShowReport()
{
	var nMaxDim = eval(GetMaxDim());
	if (nMaxDim != eval(GetCurrentDim())) {
	}
	
	// Any changes made to any item should be save to the hidden fields
	if (typeof(SaveSelectionState) != 'undefined') {
      SaveSelectionState();
   }
	if (nMaxDim == -1) // if error
		return;
	if (typeof(ObjWdsForm.sWD_CurDim) != "undefined") {
		if (typeof(zeroScrollPosition) != "undefined") {
			zeroScrollPosition();
		}
		ObjWdsForm.IF_ReportType.value = REPORT_TYPE_TABLE;
		ObjWdsForm.sWD_CurDim.value = nMaxDim;
		ObjWdsForm.CS_InHelp.value = "False";
		ObjWdsForm.action = ObjWdsForm.CS_NextPage.value;
		executeWait(ObjWdsForm);
	}
}

// ----------------------------------------------------------------------------
function ShowNavMap()
{
   ObjWdsForm.CS_InHelp.value = "False";
   ObjWdsForm.action = G_strRootPath + "/NavMaps/navMap.aspx";
   executeWait(ObjWdsForm);
}

// ----------------------------------------------------------------------------
function OnActivateProfile()
{
	var szDocumentPath;
	
	// Any changes made to any item should be save to the hidden fields
	if (typeof(SaveSelectionState) != 'undefined') {
      SaveSelectionState();
   }
	
	szDocumentPath = document.location.pathname;
	ObjWdsForm.PR_NextPage.value = szDocumentPath;
	ObjWdsForm.PR_Mode.value = 1;
	ObjWdsForm.action = G_strRootPath + "/Common/Profiles/UserProfiles.aspx";
	executeWait(ObjWdsForm);
}

// ----------------------------------------------------------------------------
function OnDeleteProfile()
{
	var szDocumentPath;

	szDocumentPath = document.location.pathname;

	//Profile is activated from the view dimension page,therefore, profile has to be activated and applied.
	ObjWdsForm.PR_NextPage.value = szDocumentPath;
	ObjWdsForm.PR_Mode.value = 2;
	ObjWdsForm.action = G_strRootPath + "/Common/Profiles/UserProfiles.aspx";
	executeWait(ObjWdsForm);
}

// ----------------------------------------------------------------------------
function OnActivateProfileTab()
{
	ObjWdsForm.PR_NextPage.value = ObjWdsForm.PR_NextPage.value;
	ObjWdsForm.PR_Mode.value = 1;
	ObjWdsForm.CS_InHelp.value = "False";
	ObjWdsForm.action = G_strRootPath + "/Common/Profiles/UserProfiles.aspx";
	executeWait(ObjWdsForm);
}

// ----------------------------------------------------------------------------
function OnDeleteProfileTab()
{
	//Profile is activated from the view dimension page,therefore, profile has to be activated and applied.
	ObjWdsForm.PR_NextPage.value = ObjWdsForm.PR_NextPage.value;
	ObjWdsForm.PR_Mode.value = 2;
	ObjWdsForm.CS_InHelp.value = "False";
	ObjWdsForm.action = G_strRootPath + "/Common/Profiles/UserProfiles.aspx";
	executeWait(ObjWdsForm);
}

// -----------------------------------------------------------------------------
function OnSaveProfile() {
    ObjWdsForm.CS_InHelp.value = "False";
	ObjWdsForm.CS_SaveMode.value="True"; 
	ObjWdsForm.PR_Mode.value = 3;
	ObjWdsForm.action = G_strRootPath + "/Common/Profiles/UserProfiles.aspx";
	executeWait(ObjWdsForm);
}

// ----------------------------------------------------------------------------
function OnDeactivateProfile()
{
	var szDocumentPath;

	szDocumentPath = document.location.href;
    ResetChartPagination();
	
	ObjWdsForm.PR_DeactivateAllProfiles.value = "True";
	ObjWdsForm.PR_Mode.value = 0;
	ObjWdsForm.action = szDocumentPath;
	executeWait(ObjWdsForm);
}

// ----------------------------------------------------------------------------    
function OnActivateThisProfile(nProfileId)
{
	var szDocumentPath;

	szDocumentPath = document.location.href;

    ResetChartPagination();
    //Dimesion Search should be turned off.
    TrunOffDimSearch();
	ObjWdsForm.PR_ActivateThisProfile.value = nProfileId;
	ObjWdsForm.action = szDocumentPath;
	executeWait(ObjWdsForm);
}

//------------------------------------------------------------------------------
function OnContactUs()
{
	try {
		if (typeof(SaveSelectionState) != "undefined") {
			SaveSelectionState();
		}
	}
	catch (ex) {
	}

	var szDocumentPath;
	var szaDocumentPathTemp;
	var nNumberOfFolders = 0;
	var szCurrentPage = ""

	szDocumentPath = document.location.pathname;

	szaDocumentPathTemp = szDocumentPath.split("/");
	nNumberOfFolders = szaDocumentPathTemp.length;

	if (typeof(gCurrentPage) != "undefined") {
		szCurrentPage = gCurrentPage;
	}
	if (szaDocumentPathTemp[nNumberOfFolders - 1].toLowerCase() != szCurrentPage.toLowerCase()) {
		ObjWdsForm.CS_TargetPage.value = szDocumentPath;
	}
	else if (szCurrentPage.toLowerCase() == "login.aspx" || szCurrentPage.toLowerCase() == "register.aspx") {
	   ObjWdsForm.CS_TargetPage.value = ObjWdsForm.LG_targetpage.value;
	}	         
	ObjWdsForm.action = G_strRootPath + "/Common/ContactUs/ContactUs.aspx";
	ObjWdsForm.CS_InHelp.value = "False";
	executeWait(ObjWdsForm);
}

// ----------------------------------------------------------------------------
function GenerateNewWindow(strPageName, strPagePath)
{
	var strOldTarget;
	var wndNew;

	wndNew = window.open("",
		strPageName, "toolbar=yes, menubar=no,status=no, directories=no,resizable=yes, height=600, width=800, scrollbars=yes, dependant=no");
	strOldTarget = ObjWdsForm.target;
	ObjWdsForm.target = wndNew.name;
	ObjWdsForm.action = G_strRootPath + strPagePath;
	ObjWdsForm.submit();
	ObjWdsForm.target = strOldTarget;
	wndNew.focus();
}

// ----------------------------------------------------------------------------
function IsSpawnWindow()
{
   var bSpawn = false;
	if (typeof(ObjWdsForm.CS_spawnwindow) != "undefined") {
		bSpawn = ObjWdsForm.CS_spawnwindow.value == "True" ? true : false;
	}
	return bSpawn;
}

//------------------------------------------------------------------------------
function DisplayDemoPage(szDistinationPath)
{
	var szDocumentPath;
	var szaDocumentPathTemp;
	var nNumberOfFolders = 0;
	var szCurrentPage = "";

	szDocumentPath = document.location.pathname;

	szaDocumentPathTemp = szDocumentPath.split("/");
	nNumberOfFolders = szaDocumentPathTemp.length;

	if (typeof(gCurrentPage) != "undefined") {
		szCurrentPage = gCurrentPage;
	}
	if (szaDocumentPathTemp[nNumberOfFolders - 1].toLowerCase() != szCurrentPage.toLowerCase()) {
		ObjWdsForm.CS_TargetPage.value = szDocumentPath;
	}
	else if (szCurrentPage.toLowerCase() == "login.aspx" || 
		        szCurrentPage.toLowerCase() == "register.aspx") {
		ObjWdsForm.CS_TargetPage.value = ObjWdsForm.LG_targetpage.value;		
	}			
	ObjWdsForm.action = G_strRootPath + szDistinationPath;
	ObjWdsForm.CS_InHelp.value = "False";
	executeWait(ObjWdsForm);
}
//------------------------------------------------------------------------------
function OnTutorials()
{
	var szTutorialPage = "_WdsTutorials";
	var szTutorialPath = "/Common/Tutorials/Tutorials.aspx";

	try {
		if (typeof(SaveSelectionState) != "undefined") {
		    if (!IsSpawnWindow()) 
			    SaveSelectionState();
		}
	}
	catch (ex) {
	}

	ObjWdsForm.CS_InHelp.value = "False";
	if (IsSpawnWindow()) {
		GenerateNewWindow(szTutorialPage, szTutorialPath);
	} else {
		DisplayDemoPage(szTutorialPath);
	}
}

//------------------------------------------------------------------------------
function OnFlashDemo()
{
	var szDemoPath = "/Common/Tutorials/DemoPage.aspx";

	DisplayDemoPage(szDemoPath);
}
//------------------------------------------------------------------------------
function OnHome()
{
	ObjWdsForm.action = G_strRootPath + "/HomePage.aspx";
	executeWait(ObjWdsForm);
}

//------------------------------------------------------------------------------
function OnNews()
{
	var szDocumentPath;
	var szaDocumentPathTemp;
	var nNumberOfFolders = 0;
	var szCurrentPage = ""

	try {
		if (typeof(SaveSelectionState) != "undefined") {
			SaveSelectionState();
		}
	}
	catch (ex) {
	}

	szDocumentPath = document.location.pathname;

	szaDocumentPathTemp = szDocumentPath.split("/");
	nNumberOfFolders = szaDocumentPathTemp.length;

	if (typeof(gCurrentPage) != "undefined") {
		szCurrentPage = gCurrentPage;
	}
	if (szaDocumentPathTemp[nNumberOfFolders - 1].toLowerCase() != szCurrentPage.toLowerCase()) {
		ObjWdsForm.CS_TargetPage.value = szDocumentPath;
	}
	else if (szCurrentPage.toLowerCase() == "login.aspx" || szCurrentPage.toLowerCase() == "register.aspx") {
	   ObjWdsForm.CS_TargetPage.value = ObjWdsForm.LG_targetpage.value;
	}
	ObjWdsForm.action = G_strRootPath + "/Common/News/News.aspx";
	ObjWdsForm.CS_InHelp.value = "False";
	executeWait(ObjWdsForm);
}

//==============================================================================
// HELP RELATED FUNCTIONS
//------------------------------------------------------------------------------
function OpenHelpWindow(i_szHelpPage, bOnTab, i_szAnchor)
{
	var szLocation = "";
	var szHelpPage = i_szHelpPage;
	var szAnchor = "";
	var wndHelp;
	var bFamesInHelp;
	
    bFramesInHelp = AreFramesInHelp();
	if (typeof(i_szAnchor) != 'undefined') szAnchor = i_szAnchor;
	if (bOnTab) {
    	if (bFramesInHelp) {
		    // Open Help window in-place (as parent window)
		    ObjWdsForm.CS_InHelp.value = "True";
		    if (szAnchor != "") szHelpPage += "#" + i_szAnchor;
		    ObjWdsForm.CS_HelpPage.value = szHelpPage;
		    ObjWdsForm.action = document.location.pathname;
		    executeWait(ObjWdsForm);
		}
		else {
		    // Open Help window in-place (as parent window)
	        location = G_strRootPath + "/Common/HelpNoFrames/" + G_strLanguage + "/WDS.htm#" + szHelpPage.substr(0, szHelpPage.length - 4);
		}
	}
	else {
     	if (bFramesInHelp) {
		    // Open wndHelp window.
		    szLocation = G_strRootPath + "/Common/Help/help.aspx?HelpPage=" + szHelpPage;
		    // the querystring does not like anchors, so use a seperate field.
		    if (szAnchor != "") szLocation += "&HelpAnchor=" + i_szAnchor;
		    szLocation += "&CS_ChosenLang=" + G_strLanguage;
		}
		else {
		    // Open Help window in-place (as parent window)
	        szLocation = G_strRootPath + "/Common/HelpNoFrames/" + G_strLanguage + "/WDS.htm#" + szHelpPage.substr(0, szHelpPage.length - 4);
		}		    
		wndHelp = window.open(szLocation,
			"Help", "width=" + 600 + ",height=" + 400 + " ,toolbar=yes,menubar=yes,status=yes,directories=yes,resizable=yes,scrollbars=yes,dependent=no");			    
	}
}

// ----------------------------------------------------------------------------
function AreFramesInHelp()
{
   var bFramesInHelp = true;
	if (typeof(ObjWdsForm.CS_FramesInHelp) != "undefined") {
		bFramesInHelp = ObjWdsForm.CS_FramesInHelp.value.toLowerCase() == "true" ? true : false;
	}
	return bFramesInHelp;
}

// ----------------------------------------------------------------------------    
function TrunOffDimSearch()
{
   var objForm = ObjWdsForm;

   if (objForm.WD_SearchStringBuffer != null) {
      objForm.WD_SearchStringBuffer.value = "";
   }
   if (objForm.WD_DateLowerBuffer != null) {
      objForm.WD_DateLowerBuffer.value = "";
   }
   if (objForm.WD_DateUpperBuffer != null) {
      objForm.WD_DateUpperBuffer.value = "";
   }
}

//-------------------------------------------------------------------------
// In the case of required login, user will be redirected to the login page.
//-------------------------------------------------------------------------
function ReDirectToLoginPage() {
	var szQueryString = document.location.search;
	
	onPageLoadGlobal();
	
	ObjWdsForm.LG_targetpage.value = document.location.pathname + szQueryString
	ObjWdsForm.action = G_strRootPath + "/Common/Login/login.aspx";
	ObjWdsForm.CS_InHelp.value = "False";
	executeWait(ObjWdsForm);
}

//-------------------------------------------------------------------------
// This function creates the cell footer tables for the Printable Version of the table.
//-------------------------------------------------------------------------
function footerTables(){
	var nRow = 0;
    var footer = document.getElementById("cell5");
    var footerTable = null;
    var linkTag = null;
    
    if ( footer != null ) {
		footerTable = document.body.appendChild(document.createElement("Table"));
	    
		footerTable.setAttribute("id", "FooterTable", 0);  
		footerTable.insertRow(nRow);
	    
		footerTable.rows[nRow].insertCell(0);
		footerTable.rows[nRow].cells[0].appendChild(footer); 
		footerTable.rows[nRow].cells[0].style.visibility = "visible";
	
	    // Remove all the links from the footer
		removeHref(footerTable);
	}
    return footerTable;          
}

//-------------------------------------------------------------------------
// Remove all the href links for a specified element.
//-------------------------------------------------------------------------
function removeHref(objElement){
    var linkTag = null;
    
	// Remove all the links from the footer
	linkTag = objElement.getElementsByTagName("A");
	if (linkTag.length > 0) {
		for (var Index = linkTag.length - 1; Index >= 0; Index--) {
			if (linkTag[Index].removeAttribute("href", 0)) {
				linkTag[Index].style.textDecoration = "underline";
			}
		}
	}    
}

// ----------------------------------------------------------------------------    
//Remove hidden form field
function RemoveFormField(
	i_clForm,
	i_strName
	)
{
	var aclFields;
	var clField;
	var nFieldCount;
	var nIndex;
	
	aclFields = i_clForm[i_strName];
	if (aclFields != undefined) {
		if (aclFields.length == undefined) {
			aclFields.parentNode.removeChild(aclFields);
		}
		else {
			nFieldCount = aclFields.length;
			for (nIndex = nFieldCount - 1; nIndex >= 0; nIndex--) {
				clField = aclFields[nIndex];
				clField.parentNode.removeChild(clField);
			}
		}
	}
}

// This function creates a string from the FORM hidden input field values, so that it can be posted to the server.
function CreateHttpRequest(i_clForm)
{
	var aclFormFields;
	var bAddToRequest;
	var clFormField;
	var strRequest = "";
	var unIndex;
	var unFieldCount = 0;

	// Make sure the form object is defined.
	if (i_clForm != undefined) {
		aclFormFields = i_clForm.getElementsByTagName("INPUT");
		// For each INPUT form field, create a string "name=value".  Join all of
		// these strings with the "&" character.  The result will look something
		// like: "sWD_TableId=1&sWD_ChartType=5&PR_ProfileApplied=False".
		for (unIndex = 0; unIndex < aclFormFields.length; unIndex++) {
			bAddToRequest = false;
			clFormField = aclFormFields[unIndex];
			// Only include the INPUT tags of type hidden.
			if (PWdsapp_bIsIE) {
				// For IE the hidden fields are of type "hidden".
				if (clFormField.type.toLowerCase() == "hidden") {
					bAddToRequest = true;
				}
			}
			else if (clFormField.className.toLowerCase() == "hiddenfield") {
				// In Netscape and others there is a problem with the form.reset() not resetting
				// hidden fields, so we use "text" fields and hide them using the "hiddenfield" rule.
				bAddToRequest = true;
			}
			if (bAddToRequest) {
				// Don't add "&" if it's the first INPUT tag found.
				if (unFieldCount > 0) {
					strRequest += "&";
				}
				strRequest += clFormField.name + "=";
				strRequest += URIencode(clFormField.value);
				unFieldCount++;
			}
		}
	}

	return strRequest;
}
