﻿// ----------------------------------------------------------------------------
//
// ACTION constants
var ACTION_NONE = "0";
var ACTION_SAVE_REPORT = "1";
var ACTION_TITLE_NOTES = "2";
var ACTION_CHANGE_FOLDER_NAME = "3";
var ACTION_NEW_FOLDER_NAME = "4";

// Temporary code for scroll bars and tables positions, it needs to be looked at again.

var OFFSET_TOP = 1;
var OFFSET_LEFT = 2;
var BOTTOM_HEIGHT = 3;
var RIGHT_WIDTH = 4;
var WIDTH_USEDUP = 5;
var HEIGHT_USEDUP = 6;

var CAN_MOVE_NO = 0;
var CAN_MOVE_UP = 1;
var CAN_MOVE_DOWN = 2;
var CAN_MOVE_UP_DOWN = 3;

var NODE_FOLDER = 0;
var NODE_REPORT = 1;
var NODE_NO_CONTENTS = 2;

var GPattern = /^[-]\d{1,}$|^[+]\d{1,}$|^[-]{0,1}\d*[.]\d{1,}$|^\d{1,}$|^[+]\d*[.]\d{1,}$|^[+]\d{1,}[.]{0,1}\d*$|^[-]{0,1}\d{1,}[.]{0,1}\d*$|^[-]{0,1}\d{1,}[eE][-]{0,1}\d{1,}$|^[-]{0,1}\d{1,}[eE][+]\d{1,}$|^[-]{0,1}\d*[.]\d{1,}[eE][-]{0,1}\d{1,}$|^[-]{0,1}\d*[.]\d{1,}[eE][+]\d{1,}$|^[+]\d{1,}[eE][-]{0,1}\d{1,}$|^[+]\d{1,}[eE][+]{0,1}\d{1,}$|^[+]\d*[.]\d{1,}[eE][-]{0,1}\d{1,}$|^[+]\d*[.]\d{1,}[eE][+]{0,1}\d{1,}$|^[-]{0,1}\d{1,}[.]\d*[eE][-]{0,1}\d{1,}$|^[-]{0,1}\d{1,}[.]\d*[eE][+]\d{1,}$|^[+]\d{1,}[.]\d*[eE][+]{0,1}\d{1,}$|^[+]\d{1,}[.]\d*[eE][-]\d{1,}$/;

// ----------------------------------------------------------------------------
var G_CloseActionsList = 0;
var G_CloseLanguageList = 0;
var G_CloseTutorialList = 0;
var G_CloseSummaryList = 0;
var G_CloseSearchList = 0;

//Browser detection:-------------------------------------------------
//if something here is modified, similar variables in Globals.vb should be updated
var G_dNetscapeVersion = 0;
var G_dIEVersion = 0;

var IE = 1;
var NETSCAPE = 2;
var FIREFOX = 3;
var SAFARI = 4;

var GCommaRep = String.fromCharCode(29);
var GSpaceRep = String.fromCharCode(28);
var GEmptyRep = String.fromCharCode(160);
var GSingleQuoteRep = String.fromCharCode(27);
var GDoubleQuoteRep = String.fromCharCode(26);
var GMinorSegmentDelimiter = String.fromCharCode(24);
var GLtRep = String.fromCharCode(23);
var GGtRep = String.fromCharCode(22);
var GDelim20 = String.fromCharCode(20);

var G_strThreeDots = "...";

// Navigation Tool
var MenusAndToolbars = 0;
var MenusOnly = 1;
var ToolbarsOnly = 2;

// Max. number of characters to display in "Data Source" drop-down when creating a new report
var G_nMaxDataSourceTitle = 80;

// Max. number of characters to display in "Select" element.
var G_nMaxSelectItems = 40;

var M_astrLanguageCodes = new Array();
var M_astrLanguageNames = new Array();
var M_astrTutorials = new Array();
var M_strTutorialsPage = "../Tutorials/Tutorials.aspx?TutorialIndex=";

var G_nBrowser = DetectBrowser();

function DetectBrowser() {
	var ua = window.navigator.userAgent.toLowerCase();
	switch(true){
		case (ua.indexOf("msie") > 0):			
			//get IE version:
			var index = ua.indexOf ("msie");
			G_dIEVersion = parseFloat(ua.substring(index + 5));
			return IE;
			break;
		case ua.indexOf("netscape") > 0:			
			//get NS version:
			var index = ua.indexOf ("netscape/");
			G_dNetscapeVersion = parseFloat(ua.substring(index + 9));
			return NETSCAPE;
			break;
		case ua.indexOf("firefox") > 0:
			return FIREFOX;
			break;
		case ua.indexOf("safari") > 0:
			return SAFARI;
			break;
		default:
			return 0;	
	}
}

function onLayoutResize()
{
	var clDivContents = document.getElementById("DivContents");
	var szUrl = document.location.pathname;
	
	if (clDivContents != null) {
		if (szUrl.indexOf("Help") >= 0) {
         // Remove scrolling from the parent div for Help pages.
         clDivContents.className = "ContentTableBody";
		}
		// Resize the page
		RepositionContents();
	}
   if (G_CloseLanguageList == 1) {
      CollapseLanguageList();
   }	
}

function ClearCurrentAction()
{
   document.aspnetForm.CurrentAction.value = ACTION_NONE;
   document.aspnetForm.CurrentActionBuffer1.value = "";
   document.aspnetForm.CurrentActionBuffer2.value = "";
}

function RepositionContents()
{
   // Find the size of the dimensions list pane and remember the size.
   ResizeDimensionListPane();
   
  	// Find the height and width of the report content pane.
	RepositionElement(); 
}

function ResizeDimensionListPane()
{
   var clDimListLabel = document.getElementById("ctl00_lblDimsTitle");
   var clDimListTitle = document.getElementById("DimsTitle");
   var clDimListToolbar = document.getElementById("DimListToolbar");
	var clDivDimsList = document.getElementById("ctl00_DivDimList");
	var clDivDimsListContents = document.getElementById("DivDimListContents");
	var clLeftArea = document.getElementById("LeftArea");
	var nDimsTitleWidth;
	var nDimsWidthPct;
	var nWidth;
	
	if(clDivDimsList != null) {
	   nDimsTitleWidth = clDimListLabel.offsetWidth;
	   nDimsWidthPct = document.aspnetForm.DimListWidthPct.value;
      switch (G_nBrowser)
      {
         case IE:
      	   nWidth = Math.max((document.body.clientWidth - clLeftArea.offsetWidth) 
      	      * nDimsWidthPct / 100, nDimsTitleWidth);
            clDivDimsList.style.posWidth = nWidth;
            clDivDimsListContents.style.posWidth = nWidth;
            clDimListToolbar.style.posWidth = nWidth;
            clDimListTitle.style.posWidth = nWidth;
            break;
         default:
            nWidth = Math.max((window.innerWidth - clLeftArea.offsetWidth) * nDimsWidthPct / 100, 
               nDimsTitleWidth);
            clDivDimsList.style.width= nWidth; 
            clDivDimsListContents.style.width= nWidth; 
            clDimListToolbar.style.width= nWidth; 
            clDimListTitle.style.width= nWidth;
      }
	}
}

function RepositionElement()
{
   var clDivContents = document.getElementById("DivContentsScroll");
   var clDivDisplay;

   if(clDivContents == null) {
      //help page, or some page that doesn't have a special scroll area
      clDivContents = document.getElementById("DivContents");
   }
   else {
      // Dimension page has different display modes with different scrolling DIVs
      clDivDisplay = document.getElementById("TimeSetsDiv");
      if (clDivDisplay != null) {
         if (clDivDisplay.style.display == "block") {
            clDivContents = document.getElementById("DivContentsScroll2");
         }
      }
      clDivDisplay = document.getElementById("AdHocGroupsDiv");
      if (clDivDisplay != null) {
         if (clDivDisplay.style.display == "block") {
            clDivContents = document.getElementById("DivContentsScroll3");
         }
      }
      clDivDisplay = document.getElementById("CustomBandsDiv");
      if (clDivDisplay != null) {
         if (clDivDisplay.style.display == "block") {
            clDivContents = document.getElementById("DivContentsScroll4");
         }
      }
      if(clDivContents != null) {
         var clDivContentsMain = document.getElementById("DivContents");
         if (clDivContentsMain != null) {
            // Remove scrolling from the parent div, if present.
            clDivContentsMain.className = "ContentTableBody";
         }
      }
   }
      
   if(clDivContents != null) {
      AdjustObjectWidth(clDivContents);
      AdjustObjectHeight(clDivContents);
   }

   var szUrl = document.location.pathname;
   if (szUrl.indexOf("dispview.aspx") >= 0 || 
         szUrl.indexOf("dispchart.aspx") >= 0 ||
         szUrl.indexOf("drillthrough.aspx") >= 0) {
      // Scrolling
      ResizeScrollArea();
      SyncScroll();
   }
}

function GetOffSet(i_clElement, i_nDirection)
{  
    var nOffSet = 0;
    var clElement = i_clElement;
    
    switch (i_nDirection) {
		case OFFSET_TOP:
			while (clElement != null && clElement.tagName.toUpperCase() != "BODY") {
				nOffSet += clElement.offsetTop;
				clElement = clElement.offsetParent;
			}
			break;
		case OFFSET_LEFT:
			while (clElement != null && clElement.tagName.toUpperCase() != "BODY") {
				nOffSet += clElement.offsetLeft;
				clElement = clElement.offsetParent;
			}
			break;
		case BOTTOM_HEIGHT:
			if (clElement != null) {
				nOffSet = clElement.offsetHeight;
			}
			break;	
		case RIGHT_WIDTH:
			if (clElement != null) {
				nOffSet = clElement.offsetWidth;
			}
		break;
	}
    
    // If the nOffSet is equal to 1 then it is just the control placed in it then the size 
    // should be equal to 0.
    if (nOffSet == 1) {
      nOffSet = 0;
    }
    
	return nOffSet;
}

function getSize(i_clElement, i_nDirection)
{
   var nPos = 1;
	var clElement = i_clElement;
		
	if (i_nDirection == HEIGHT_USEDUP) {
		nPos += GetOffSet(clElement, OFFSET_TOP); 
   } 
   else {
      nPos += GetOffSet(clElement, OFFSET_LEFT);
   }
	return 	nPos;					
}

function AdjustObjectWidth(obj)
{
   var clOtherDimsTable = document.getElementById("OtherDimsTable");
   
   var clObj = obj;
   var nObjLeft = 0;
   var nMiddleAreaLeft = 0;
   var nRightWidth=0;
   var nObjWidth = 0;
   
   if (clObj != null) {
      nObjLeft = getSize(clObj, WIDTH_USEDUP);
	}

	switch (G_nBrowser){
	   case IE :
	      nObjWidth = document.body.clientWidth - nObjLeft;
         if (clObj != null) {
            if (Math.abs(clObj.style.posWidth - nObjWidth) > 1) {
               // Don't adjust if the difference is only 1 pixel.
               clObj.style.posWidth = nObjWidth;
            }
         }
	      if (clOtherDimsTable != null) {
	         clOtherDimsTable.style.posWidth = nObjWidth;
	      }
	      break;
	   default :
	      nObjWidth = window.innerWidth - nObjLeft;   
   	   if (clObj != null) {
   	      clObj.style.width = nObjWidth;  
   	   }

         var clLeftArea = document.getElementById("LeftArea");
         var clMiddleArea = document.getElementById("MiddleArea");
         if (clMiddleArea != null && clLeftArea != null) {
            nMiddleAreaLeft = clLeftArea.offsetWidth;
         }

         var clContentTopBar = document.getElementById("ContentTopBar");
         var clToolBarTable = document.getElementById("ToolBarTable");
         var clTopPageTable = document.getElementById("TopPageTable");
	      if (clToolBarTable != null) {
	         clToolBarTable.style.width = window.innerWidth - getSize(clToolBarTable,WIDTH_USEDUP);
	         if (clContentTopBar != null) {
	            clContentTopBar.style.width = clToolBarTable.style.width;
	         }
         }

         var clMenuTD = document.getElementById("MenuTD");
         var clMenuTable = document.getElementById("MenuTable");

         if (clMenuTable != null) {
	         clMenuTable.style.width = window.innerWidth - getSize(clMenuTable,WIDTH_USEDUP);
	      }
	      if (clMenuTD != null) {
	         clMenuTD.style.width = clMenuTable.style.width;
            clLogo = document.getElementById("MenuAppLogo");
            if (clLogo != null && clLogo.style.display == 'block') {
               clMenuTable.style.height = "34";
            }
	      }

	      if (clLeftArea != null) {
	         clTopPageTable.style.width = clToolBarTable.offsetWidth + getSize(clToolBarTable,WIDTH_USEDUP) 
	            - clLeftArea.offsetWidth;
	      }
	      if (clMiddleArea != null) {
	         clMiddleArea.style.width = clTopPageTable.style.width;
	      }
	      if (clOtherDimsTable != null) {
	         clOtherDimsTable.style.width = nObjWidth;
	      }
	      break;
	}
}

function AdjustObjectHeight(obj)
{   
    //dimensions list
   var clDimListTitleTR = document.getElementById("DimListTitleTR");
   var clDimListToolbarSpacerTR = document.getElementById("DimListToolbarSpacerTR");
   var clDimListToolbarTR = document.getElementById("DimListToolbarTR");
   var clDivDimsList = document.getElementById("ctl00_DivDimList");
   var clDivDimsListContents = document.getElementById("DivDimListContents");
   
   // menu
   var clMenuTD = document.getElementById("MenuTD");
   
   // layout
   var clHeaderArea = document.getElementById("HeaderArea");
   var clMiddleArea = document.getElementById("MiddleArea");
   var clFooterArea = document.getElementById("FooterArea");
   
    //vertical divider  
   var clVerticalLineTable = document.getElementById("VerticalLineTable");
      
   //help page
   var clHelpPage = document.getElementById("helpPage");
   var clHelpToc = document.getElementsByName("Help_Toc")[0];
   var clHelpBody = document.getElementById("Help_Body");
   
   var clObj = obj;
   var nHeaderAreaHeight = 0;
   var nFooterAreaTop = 0;
   var nFooterAreaHeight = 0;
   var nMiddleAreaHeight = 0;
   var nObjTop = 0;
   var nAvailableHeight;
   
   if (clObj != null) nObjTop = getSize(clObj, HEIGHT_USEDUP);
   if (clHeaderArea != null) nHeaderAreaHeight = clHeaderArea.offsetHeight;
   if (clMiddleArea != null) nMiddleAreaHeight = clMiddleArea.offsetHeight;
   if (clFooterArea != null) {
      nFooterAreaHeight = clFooterArea.offsetHeight;
      nFooterAreaTop = clFooterArea.offsetTop;
   }
   nAvailableHeight = document.body.clientHeight - nFooterAreaHeight - nHeaderAreaHeight - 1;
   if (clMenuTD != null) {
      nAvailableHeight = nAvailableHeight - clMenuTD.offsetHeight;
   }
                                                                                             
   switch (G_nBrowser){
	   case IE :
         if (document.body.clientHeight - nHeaderAreaHeight > nMiddleAreaHeight){
            if (clObj != null) {
               if (nFooterAreaTop < nObjTop){ 
                  clObj.style.posHeight = 0;
                  if (nFooterAreaTop > document.body.clientHeight){
                     clMiddleArea.style.posHeight = document.body.clientHeight - nHeaderAreaHeight;
                  } else {
                     clMiddleArea.style.posHeight = nMiddleAreaHeight;
                  }
                  nMiddleAreaHeight = clMiddleArea.offsetHeight;                  
               }
               else { 
                  clObj.style.posHeight = nFooterAreaTop - nObjTop;
                  clMiddleArea.style.posHeight = "100%";                  
               }
               
            }
            if (clHelpPage != null) {
               if (clHelpToc != null) {
                  clHelpToc.style.posHeight = nFooterAreaTop - getSize(clHelpToc,HEIGHT_USEDUP);
               }
               if (clHelpBody != null) {
                  clHelpBody.style.posHeight = nFooterAreaTop - getSize(clHelpBody,HEIGHT_USEDUP);
               }
             }
         } 
         else {
            if (clObj != null) {
               clObj.style.posHeight = document.body.clientHeight-nObjTop;
            }
            if (clHelpPage != null) {
               if (clHelpToc != null) {
                  clHelpToc.style.height = document.body.clientHeight - getSize(clHelpToc,HEIGHT_USEDUP);
               }
               if (clHelpBody != null) {
                  clHelpBody.style.height = document.body.clientHeight - getSize(clHelpBody,HEIGHT_USEDUP);
               }
            }
         }
         if (clDivDimsList != null) {
           clDivDimsList.style.posHeight = nAvailableHeight;
           clDivDimsListContents.style.posHeight = nAvailableHeight - 1
              - clDimListToolbarTR.offsetHeight - clDimListToolbarSpacerTR.offsetHeight
              - clDimListTitleTR.offsetHeight;
         }
         if (clVerticalLineTable != null) {
            clVerticalLineTable.style.height = nAvailableHeight ;
         }
          
         break;
      default :         
         if (window.innerHeight - nHeaderAreaHeight > nMiddleAreaHeight){
            
            if (G_dNetscapeVersion == 7.1) {
               if (clFooterArea != null) {
                  if (clObj != null) {
                     if (clMiddleArea != null) {
                        clMiddleArea.style.height= window.innerHeight - nFooterAreaHeight 
                           - nHeaderAreaHeight;
                     }
                     if (clFooterArea != null) {
                        nFooterAreaTop = clFooterArea.offsetTop;
                     }
                     if (nFooterAreaTop < nObjTop){ 
                        clObj.style.height = 0;
                        if (nFooterAreaTop > window.innerHeight){
                           clMiddleArea.style.height = window.innerHeight - nHeaderAreaHeight;
                        } 
                        else {
                           clMiddleArea.style.height = nMiddleAreaHeight;
                        }
                        nMiddleAreaHeight = clMiddleArea.offsetHeight;                        
                     } 
                     else {
                        clObj.style.height = nFooterAreaTop - nObjTop;
                        clMiddleArea.style.height = "100%";                        
                     } 
                  }
               }               
              
            } 
            else {
               if (clFooterArea != null) {
                  nFooterAreaTop = clFooterArea.offsetTop;
               }
               if (clObj != null) {
                  if (nFooterAreaTop < nObjTop){ 
                     clObj.style.height = 0;
                     if (nFooterAreaTop > window.innerHeight){
                        clMiddleArea.style.height = window.innerHeight - nHeaderAreaHeight;
                     } 
                     else {
                        clMiddleArea.style.height = nMiddleAreaHeight;
                     }
                     nMiddleAreaHeight = clMiddleArea.offsetHeight;                     
                  } 
                  else { 
                     clObj.style.height = nFooterAreaTop - nObjTop;
                     clMiddleArea.style.height = "100%";                     
                  }                  
               }               
            }           
                      
            if (clHelpPage != null) {
               if (clHelpToc != null) {
                  clHelpToc.style.height = nFooterAreaTop - getSize(clHelpToc,HEIGHT_USEDUP);
               }
               if (clHelpBody != null) {
                  clHelpBody.style.height = nFooterAreaTop - getSize(clHelpBody,HEIGHT_USEDUP);
               }
             }
         } 
         else {
            if (clObj != null) {
               clObj.style.height = window.innerHeight - nObjTop;
            }
            if (clHelpPage != null) {
               if (clHelpToc != null) {
                  clHelpToc.style.height = window.innerHeight - getSize(clHelpToc,HEIGHT_USEDUP);
               }
               if (clHelpBody != null) {
                  clHelpBody.style.height = window.innerHeight - getSize(clHelpBody,HEIGHT_USEDUP);
               }
             }
         }
          if (clVerticalLineTable != null) {
            clVerticalLineTable.style.height = nAvailableHeight ;
          }
          
         if (clDivDimsList != null){
            clDivDimsList.style.height = nAvailableHeight;
            clDivDimsListContents.style.height = nAvailableHeight - 1
                - clDimListToolbarTR.offsetHeight - clDimListToolbarSpacerTR.offsetHeight
                - clDimListTitleTR.offsetHeight;                
         }
        break;
  }
}

function onBodyLoad()
{
   document.aspnetForm.onsubmit = VerifyFormSubmission;
   document.getElementById("TopPageTable").style.display = 'block';
   if (G_nBrowser == NETSCAPE) {
      if (G_dNetscapeVersion == 7.1) {
         document.getElementById("TopPageTable").style.position='relative';
      }
   }
   onLayoutResize();   
   FixImageTitles();
   
   // Reset appropriate global hidden fields (to handle Back button)
	if (document.aspnetForm.TimerId.value != 0) {
		clearTimeout(document.aspnetForm.TimerId.value);
		document.aspnetForm.TimerId.value = 0;
	}
}

// ----------------------------------------------------------------------------
function ExpandLanguageList(i_clLanguageButton, i_strLangDiv)
{
   var clContentTopBar;
   var clHeaderArea;
   var clLangDiv;
   var clLeftArea;
   var nHeaderAreaHeight = 0;
   var nContentTopBarHeight = 0;
   var nIndex;
   var nLeft;
   var nLeftAreaWidth = 0;
   var nTop;
   var strCurLang;
   var strLang;
   var strLangDivContent = "";
   
   if (i_clLanguageButton != null) {
      clLangDiv = document.getElementById(i_strLangDiv);
      if (clLangDiv != null) {
         if (G_CloseLanguageList == 1) {
            CollapseLanguageList();
         }
         else {
            if (G_CloseTutorialList == 1) {
               CollapseTutorialList();
            }
            if (G_CloseSummaryList == 1) {
               CollapseSummaryList();
            }
            if (G_CloseSearchList == 1) {
               CollapseSearchList();
            }
            hideObjectElements();
            hideSelectionControls();

            if (clLangDiv.innerHTML == null || clLangDiv.innerHTML.indexOf("<p") < 0) {
               strCurLang = document.aspnetForm.PerspectiveLanguage.value;
               for (nIndex = 0; nIndex < M_astrLanguageCodes.length; nIndex++) {
                  strLang = M_astrLanguageCodes[nIndex].toLowerCase();
                  strLangDivContent += "<p class='LangPage'>";
                  strLangDivContent += "<NOBR><a class='MenuItem' href='";
                  strLangDivContent += "javascript:OnRequestedLang(\"" + strLang + "\");'>";
                  strLangDivContent += "<IMG SRC='../Bmp/";
                  if (strLang == strCurLang) {
                     strLangDivContent += "checkmark";
                  }
                  else {
                     strLangDivContent += "transparent";
                  }
                  strLangDivContent += ".gif' alt='' border='0'>&nbsp;";
                  strLangDivContent += M_astrLanguageNames[nIndex] + "</a></NOBR></p>";
               }
               clLangDiv.innerHTML = strLangDivContent;
            }
            clLangDiv.style.position = "absolute";
            clLangDiv.style.zIndex = 99;
            clLangDiv.style.visibility = "visible";
            clLangDiv.style.display = "block";
            clHeaderArea = document.getElementById("HeaderArea");
            clLeftArea = document.getElementById("LeftArea");
            if (clHeaderArea != null) {
               nHeaderAreaHeight = clHeaderArea.offsetHeight;
            }
            if (clLeftArea != null) {
               nLeftAreaWidth = clLeftArea.offsetWidth;
            } 
            clContentTopBar = document.getElementById("ContentTopBar");
            if (clContentTopBar != null) {
               nContentTopBarHeight = clContentTopBar.offsetHeight;
            }
                          
            nLeft = M_pfnCalculateX(i_clLanguageButton) - nLeftAreaWidth - clLangDiv.offsetWidth 
               + i_clLanguageButton.offsetWidth;
            nTop = M_pfnCalculateY(i_clLanguageButton) - nHeaderAreaHeight + nContentTopBarHeight;
            clLangDiv.style.left = nLeft;
            clLangDiv.style.top = nTop;
            G_CloseLanguageList = 1;
         }
      }
   }  
}

// ----------------------------------------------------------------------------
function CollapseLanguageList()
{
   var clLangDiv;
   
   clLangDiv = document.getElementById("GL_CurrentLang");
   if (clLangDiv != null) {
      clLangDiv.style.position = "static";
      clLangDiv.style.visibility = "hidden";
      clLangDiv.style.display = "none";
   }
   G_CloseLanguageList = 0;
   showSelectionControls();
}

// ----------------------------------------------------------------------------
function CollapseDropDownLists(i_Event)
{
   // Determine what was clicked and if it was a drop down list button
	var clickElem = (G_nBrowser == IE) ? window.event.srcElement : i_Event.target;

   if (G_CloseLanguageList == 1 && (clickElem.id != "LanguageButton")) {
      CollapseLanguageList();
   }
   if (G_CloseTutorialList == 1 && (clickElem.id != "TutorialsButton")) {
      CollapseTutorialList();
   }
   if (G_CloseSummaryList == 1 && (clickElem.id	!= "SummaryButton")) {
      CollapseSummaryList();
   }
   if (G_CloseSearchList == 1 && (clickElem.id != "SearchButton")) {
      CollapseSearchList();
   }
}

// ----------------------------------------------------------------------------
function OnRequestedLang(i_szLang) 
{           
   CollapseLanguageList();
   if (document.aspnetForm.PerspectiveLanguage.value != i_szLang) {
      document.aspnetForm.PerspectiveLanguage.value = i_szLang;
      executeWait(document.aspnetForm);
   }
}

// Functions handling displaying of the tutorials
// ----------------------------------------------------------------------------
function DisplayTutorialsButton()
{
   var clTutorialsButton;
   var clTutorialsLbl;
   clTutorialsButton = document.getElementById("TutorialsButton");
   clTutorialsLbl =  document.getElementById("TutorialsLbl");
   if (clTutorialsButton != null) {
      clTutorialsButton.style.display = 'block';
      clTutorialsButton.disabled = false;
      SwitchImage(clTutorialsButton, "active");
   }
   if (clTutorialsLbl != null) {
     clTutorialsLbl.style.display = 'block';
   }
}

//------------------------------------------------------------------------------
function ExpandTutorialList(i_clTutorialButton, i_strTutorialDiv)
{
   var clContentTopBar;
   var clHeaderArea;
   var clTutorialDiv;
   var clLeftArea;
   var nHeaderAreaHeight = 0;
   var nContentTopBarHeight = 0;
   var nIndex;
   var nLeft;
   var nLeftAreaWidth = 0;
   var nTop;
   var strCurTutorial;
   var strTutorial;
   var strTutorialDivContent = "";
   
   if (i_clTutorialButton != null) {
      clTutorialDiv = document.getElementById(i_strTutorialDiv);
      if (clTutorialDiv != null) {
         if (G_CloseTutorialList == 1) {
            CollapseTutorialList();
         }
         else {
            if (G_CloseLanguageList == 1) {
               CollapseLanguageList();
            }
            if (G_CloseSummaryList == 1) {
               CollapseSummaryList();
            }
            if (G_CloseSearchList == 1) {
               CollapseSearchList();
            }
            OnCancelOptions();
            hideObjectElements();
            hideSelectionControls();

            if (clTutorialDiv.innerHTML == null || clTutorialDiv.innerHTML.indexOf("<p") < 0) {
               for (nIndex = 0; nIndex < M_astrTutorials.length; nIndex++) {
                  strTutorial = M_astrTutorials[nIndex];
                  strTutorialDivContent += "<p class='LangPage'>";
                  strTutorialDivContent += "<NOBR><a href='";
                  strTutorialDivContent += "javascript:OnRequestedTutorial(\"" + M_strTutorialsPage + nIndex + "\")'; class='MenuItem'>";
                  strTutorialDivContent += "&nbsp;" + strTutorial + "&nbsp;" + "</a></NOBR></p>";
               }
               clTutorialDiv.innerHTML = strTutorialDivContent;
            }
            clTutorialDiv.style.position = "absolute";
            clTutorialDiv.style.zIndex = 99;
            clTutorialDiv.style.visibility = "visible";
            clTutorialDiv.style.display = "block";
            clHeaderArea = document.getElementById("HeaderArea");
            clLeftArea = document.getElementById("LeftArea");
            if (clHeaderArea != null) {
               nHeaderAreaHeight = clHeaderArea.offsetHeight;
            }
            if (clLeftArea != null) {
               nLeftAreaWidth = clLeftArea.offsetWidth;
            } 
            clContentTopBar = document.getElementById("ContentTopBar");
            if (clContentTopBar != null) {
               nContentTopBarHeight = clContentTopBar.offsetHeight;
            }
                          
            nLeft = M_pfnCalculateX(i_clTutorialButton) - nLeftAreaWidth - clTutorialDiv.offsetWidth 
               + i_clTutorialButton.offsetWidth;
            nTop = M_pfnCalculateY(i_clTutorialButton) - nHeaderAreaHeight + nContentTopBarHeight;
            clTutorialDiv.style.left = nLeft;
            clTutorialDiv.style.top = nTop;
            G_CloseTutorialList = 1;
         }
      }
   }  
}

//------------------------------------------------------------------------------
function CollapseTutorialList()
{
   var clTutorialDiv;
   
   clTutorialDiv = document.getElementById("TutorialsDiv");
   if (clTutorialDiv != null) {
      clTutorialDiv.style.position = "static";
      clTutorialDiv.style.visibility = "hidden";
      clTutorialDiv.style.display = "none";
   }
   G_CloseTutorialList = 0;
   showSelectionControls();
}

//------------------------------------------------------------------------------
function OnRequestedTutorial(i_strTutorialsPage) 
{           
   CollapseTutorialList();
   document.aspnetForm.action = i_strTutorialsPage;   
   executeWait(document.aspnetForm);
}

//------------------------------------------------------------------------------
function hideObjectElements()
{
	var aclObjectElements = document.getElementsByTagName("OBJECT");
	// Hide all OBJECT elements.
	for (i=0; i < aclObjectElements.length; i++) {
		aclObjectElements[i].style.visibility= 'hidden';
	}
}

//------------------------------------------------------------------------------
function hideSelectionControls()
{
	var selectcontrols = document.getElementsByTagName("SELECT");
   // Hide all SELECT elements.
	for (i=0; i < selectcontrols.length; i++) {
		selectcontrols[i].style.visibility = 'hidden';
	}
}

//------------------------------------------------------------------------------
function showObjectElements()
{
	var aclObjectElements = document.getElementsByTagName("OBJECT");
	// Show all OBJECT elements.
	for (i=0; i < aclObjectElements.length; i++) {
		aclObjectElements[i].style.visibility= 'visible';
	}
}

//------------------------------------------------------------------------------
function showSelectionControls()
{
	var selectcontrols = document.getElementsByTagName("SELECT");
   // Show all SELECT elements.
	for (i=0; i < selectcontrols.length; i++) {
		selectcontrols[i].style.visibility = 'visible';
	}
}

//------------------------------------------------------------------------------
// The following two functions deal with IE's bug. When relatively positionned
// Div element is embedded deep in our complicated html table structure, both
// offsetLeft and offsetTop value is wrong.
function M_pfnCalculateX(i_objDiv)
{
	var curleft = 0;
	if (i_objDiv.offsetParent)
	{
		while (i_objDiv.offsetParent)
		{
			curleft += i_objDiv.offsetLeft
			i_objDiv = i_objDiv.offsetParent;
		}
	}
	else if (i_objDiv.x) {
		curleft += i_objDiv.x;
	}

	return curleft;
}

function M_pfnCalculateY(i_objDiv)
{
	var curtop = 0;
	if (i_objDiv.offsetParent)
	{
		while (i_objDiv.offsetParent)
		{
			curtop += i_objDiv.offsetTop
			i_objDiv = i_objDiv.offsetParent;
		}
	}
	else if (i_objDiv.y) {
		curtop += i_objDiv.y;
	}

	return curtop;
}

function OnReportSummary(i_strSummaryPage, i_strSummaryType, i_nReportId, i_nDimList)
{
   document.aspnetForm.action = i_strSummaryPage + "?SummaryType="
      + i_strSummaryType.toString() + "&SummaryReportId=" + i_nReportId.toString() 
      + "&SummaryDimList=" + i_nDimList.toString();
   executeWait(document.aspnetForm);
}

function ShowDim(i_unViewDim, i_unStoredDim, i_unHr)
{
   var aszActiveHierarchies;
   var clDivDimsListContents = document.getElementById("DivDimListContents");
   ClearDrillThroughState();
   if (document.aspnetForm.MembersSearchString != null) {
      document.aspnetForm.MembersSearchString.value = "";
      document.aspnetForm.SelSearchResults.value = 0;
   }
   if (document.aspnetForm.FirstItem != null) {
      document.aspnetForm.FirstItem.value = 0;
   }
   if (document.aspnetForm.ShowSelected != null) {
      document.aspnetForm.ShowSelected.value = "";
   }
   
	if (typeof(document.aspnetForm) != "undefined") {
	    document.aspnetForm.DivDimsListScroll.value = clDivDimsListContents.scrollTop;
		if (typeof(document.aspnetForm.Dim) != "undefined") {
			//zeroScrollPosition();
         if (typeof(document.aspnetForm.FirstItem) != "undefined") {
            document.aspnetForm.FirstItem.value = 0;
         }
			document.aspnetForm.Dim.value = i_unViewDim;
			document.aspnetForm.DimIndex.value = i_unStoredDim;
			if (typeof(document.aspnetForm.ActiveHierarchies) != "undefined") {
			   aszActiveHierarchies = document.aspnetForm.ActiveHierarchies.value.split(",");
			   aszActiveHierarchies[i_unStoredDim] = i_unHr.toString();
			   document.aspnetForm.ActiveHierarchies.value = aszActiveHierarchies.join(",");
			}
			//document.aspnetForm.SelLevelRequest.value = -1;
			document.aspnetForm.action = "../Dim/dimension.aspx";
			executeWait(document.aspnetForm);
      }
   }
}

// Return the highest dimension
function GetMaxDim()
{
   if (typeof(document.aspnetForm) == "undefined") {
      alert(resTableNoLoaded);
		return -1; // return an error indication
   }
   return document.aspnetForm.DimCount.value;
}

function ShowReport()
{
   document.aspnetForm.FirstRow.value = 0; //reinitialization needed especially when returning from drillthrough
   document.aspnetForm.FirstCol.value = 0;
   ClearDrillThroughState();
   document.aspnetForm.action = "../View/dispview.aspx" ;
   executeWait(document.aspnetForm);
}

function OnLoadView(i_nReportId, i_eType, i_bChartEnabled, i_nReportFolderId)
{
	var szActionPage;

	if (i_eType == 2) {
		if (i_bChartEnabled) {
			szActionPage = "dispchart.aspx?ReportId=" + i_nReportId + "&foldId=" + i_nReportFolderId;
			document.aspnetForm.ReportType.value = "chart";
		}
		else {
			alert(resChartsEnabled);
			return;
		}
	}
	else {
		szActionPage = "dispview.aspx?ReportId=" + i_nReportId + "&foldId=" + i_nReportFolderId;
		document.aspnetForm.ReportType.value = "table";
	}
   document.aspnetForm.action = "../View/" + szActionPage;
   if (typeof(GetChartSize) != 'undefined') {
      GetChartSize();
   }
	executeWait(document.aspnetForm);
}

function OnLoadFirstDimension(i_nReportId)
{
   document.aspnetForm.action = "../Dim/dimension.aspx?ReportId=" + i_nReportId;
	executeWait(document.aspnetForm);
}

function OnLoadRSReport(i_szRSServer, i_szRSReportPath, i_nReportId)
{
   document.aspnetForm.action = "../View/RSReport.aspx?RSServer=" + i_szRSServer 
                             + "&RSReportPath=" + i_szRSReportPath + "&ReportId=" + i_nReportId;
   executeWait(document.aspnetForm);
}

function escapeHTML(str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}

function unescapeHTML(str)
{
   var div = document.createElement('div');
   div.innerHTML = str;
   if (G_nBrowser == IE) {
      return div.innerText;
   }
   else {
      return div.textContent;
   }
}

function FixImageTitles()
{
   var aclImages;
   var clImage;
   var nIndex;
   var szTitle;

   if (G_nBrowser != IE) {
	   // Set the image titles where missing (as in some server controls - e.g. tree node images).
	   aclImages = document.getElementsByTagName("IMG");
	   for (nIndex=0; nIndex < aclImages.length; nIndex++) {
		   clImage = aclImages[nIndex];
		   if (clImage.title.length == 0) {
		      clImage.title = clImage.alt;
		   }
	   }
	   // Also check <input type="image">
	   aclImages = document.getElementsByTagName("input");
	   for (nIndex=0; nIndex < aclImages.length; nIndex++) {
		   clImage = aclImages[nIndex];
		   if (clImage.type == "image") {
		      if (clImage.title.length == 0) {
		         clImage.title = clImage.alt;
		      }
		   }
	   }
	}
	// fix checkbox titles for all browsers
   aclImages = document.getElementsByTagName("input");
   for (nIndex=0; nIndex < aclImages.length; nIndex++) {
	   clImage = aclImages[nIndex];
	   if (clImage.type == "checkbox") {
	      szTitle = clImage.title;
	      if (szTitle.length > 0) {
	         szTitle = unescapeHTML(szTitle);
	         clImage.title = szTitle;
	         clImage.alt = szTitle;
	      }
	   }
   }
}

function zeroScrollPosition()
{
   document.aspnetForm.ContentPosX.value = 0;
   document.aspnetForm.ContentPosY.value = 0;
}

// Replace the image on the specified image button by changing the suffix from the current one
// to the supplied one (e.g. 'public_reports_active.gif' -> ''public_reports_over.gif').
function SwitchImage(i_clImageButton, i_strSuffix)
{
   var strSource = i_clImageButton.src.replace(new RegExp("selected_over", "g"),"selectedover");
   var astrValues = strSource.split("_");
   var strLastPart = astrValues[astrValues.length - 1];
   var astrLastPart = strLastPart.split(".");
   if (astrLastPart[0] == "selectedover" && i_strSuffix == "active") {
      astrLastPart[0] = "selected";
   }
   else if ((astrLastPart[0] == "selected" || astrLastPart[0] == "selectedover") 
         && i_strSuffix == "over") {
      astrLastPart[0] = "selectedover";
   }
   else {
      astrLastPart[0] = i_strSuffix;
   }
   strLastPart = astrLastPart.join(".");
   astrValues[astrValues.length - 1] = strLastPart;
   strSource = astrValues.join("_");
   i_clImageButton.src = strSource.replace(new RegExp("selectedover", "g"),"selected_over");
}

function AttachReportFoldersNodeCheckedHandlers()
{
   var aclCheckboxes;
   var clCheckbox;
   var nIndex;
   var nNodeIndex;
   var nPos1;
   var nPos2;
   var strId;
   var strString1 = "ReportsTreen";
   var strString2 = "CheckBox";

	// Attach onClick handler to all tree view nodes checkboxes (the only checkboxes on this page)
	M_nCheckedNodes = 0;
   M_nCheckedReportNodes = 0;
	aclCheckboxes = document.getElementsByTagName("input");
	for (nIndex=0; nIndex < aclCheckboxes.length; nIndex++) {
		clCheckbox = aclCheckboxes[nIndex];
		if (clCheckbox.type == "checkbox") {
         strId = clCheckbox.id;
         nPos1 = strId.lastIndexOf(strString1);
         nPos2 = strId.lastIndexOf(strString2);
		   if (nPos1 >= 0 && nPos2 >= 0) {
            strId = strId.substring(nPos1 + strString1.length, nPos2);
            nNodeIndex = parseInt(strId);
            if (clCheckbox.checked) {
               M_anNodeChecked[nNodeIndex] = 1;
               M_nCheckedNodes += 1;
               if (M_anNodeType[nNodeIndex] == NODE_REPORT) {
                  M_nCheckedReportNodes += 1;
               }
            }
            else {
               M_anNodeChecked[nNodeIndex] = 0;
            }
		      clCheckbox.onclick = ReportFoldersNodeChecked;
		   }
		}
	}
   if (M_clNodesSelected != null) {
      M_clNodesSelected.innerHTML = "(" + M_nCheckedReportNodes.toString() + " " + resSelected + ")"
   }
}

// ----------------------------------------------------------------------------
function ReportFoldersNodeChecked(i_clEvent)
{
   var clEvent;
   var clSource;
   var nNodeIndex;
   var nPos1;
   var nPos2;
   var strId;
   var strString1 = "ReportsTreen";
   var strString2 = "CheckBox";
   
   clEvent = (i_clEvent) ? i_clEvent : event;
   clSource = (clEvent.target) ? clEvent.target : clEvent.srcElement;
   strId = clSource.id;
   nPos1 = strId.lastIndexOf(strString1);
   nPos2 = strId.lastIndexOf(strString2);
   if (nPos1 >= 0 && nPos2 >= 0) {
      strId = strId.substring(nPos1 + strString1.length, nPos2);
      nNodeIndex = parseInt(strId);
      if (clSource.checked) {
         M_anNodeChecked[nNodeIndex] = 1;
         M_nCheckedNodes += 1;
         if (M_anNodeType[nNodeIndex] == NODE_REPORT) {
            M_nCheckedReportNodes += 1;
         }
      }
      else {
         M_anNodeChecked[nNodeIndex] = 0;
         M_nCheckedNodes -= 1;
         if (M_anNodeType[nNodeIndex] == NODE_REPORT) {
            M_nCheckedReportNodes -= 1;
         }
      }
      if (M_clNodesSelected != null) {
         M_clNodesSelected.innerHTML = "(" + M_nCheckedReportNodes.toString() + " " + resSelected + ")"
      }
      AdjustReportFoldersButtons();
   }
}

function ConfirmReportsAndFoldersDeletion()
{
   var nFolders;
   var strPrompt = "";
   
   nFolders = M_nCheckedNodes - M_nCheckedReportNodes;
   if (M_nCheckedReportNodes > 0) {
      strPrompt += M_nCheckedReportNodes.toString() + " ";
      if (M_nCheckedReportNodes == 1) {
         strPrompt += resReportLowercase;
      }
      else {
         strPrompt += resReportsLowercase;
      }
   }
   if (M_nCheckedReportNodes > 0 && nFolders > 0) {
      strPrompt += " " + resAndLowercase + " ";
   }
   if (nFolders > 0) {
      strPrompt += nFolders.toString() + " ";
      if (nFolders == 1) {
         strPrompt += resFolderLowercase;
      }
      else {
         strPrompt += resFoldersLowercase;
      }
   }
   if ((M_nCheckedReportNodes == 1 && nFolders == 0) || (M_nCheckedReportNodes == 0 && nFolders == 1)) {
      strPrompt += " " + resIsSelectedForDeletion + "\n";
   }
   else if (M_nCheckedReportNodes > 0 || nFolders > 0) {
      strPrompt += " " + resAreSelectedForDeletion + "\n";
   }
   if (nFolders > 0) {
      strPrompt += resDeleteFolderContentsWarning + "\n";
   }
   if (strPrompt.length > 0) {
      strPrompt += resDoYouWantToProceed;
      return confirm(strPrompt);
   }
   else {
      return false;
   }
}

var clMoveToTopMenuhref;
var clMoveUpMenuhref;
var clMoveDownMenuhref;
var clMoveToBottomMenuhref;
var clDeleteMenuhref;

function AdjustReportFoldersButtons()
{
   var bSearch = false;
   var nIndex;
   
   if (M_szReportSearchString.length > 0) {
      bSearch = true;
   }
   
   // Get all Sub-Menus of 'Edit' Menu
   if (M_clPageMenuTable != null) {
   
      var M_clDeleteMenu;
      var M_clChangeMenu;
      var M_clMoveToTopMenu;
      var M_clMoveUpMenu;
      var M_clMoveDownMenu;
      var M_clMoveToBottomMenu;
      var M_clMoveToFolderMenu;
   
      var clPageMenuLinks = M_clPageMenuTable.getElementsByTagName("a");
      for(nMenuIndex=0; nMenuIndex < clPageMenuLinks.length; nMenuIndex++)
      {
         if (clPageMenuLinks[nMenuIndex].innerHTML == resEditMenu) {
            var clPageMenuDiv = document.getElementById("ctl00_ContentMenu_PageMenun" + nMenuIndex + "Items");
            var clPageMenuDivLinks = clPageMenuDiv.getElementsByTagName("a");
            for(nMenuDivIndex=0; nMenuDivIndex < clPageMenuDivLinks.length; nMenuDivIndex++)
            {         
               switch (clPageMenuDivLinks[nMenuDivIndex].innerHTML) {
                  case resDelete :
                     M_clDeleteMenu = clPageMenuDivLinks[nMenuDivIndex];
                     break;
                  case (resChange + G_strThreeDots) :
                     M_clChangeMenu = clPageMenuDivLinks[nMenuDivIndex];
                     break;
                  case resMoveToTop :
                     M_clMoveToTopMenu = clPageMenuDivLinks[nMenuDivIndex];
                     break;
                  case resMoveUp :
                     M_clMoveUpMenu = clPageMenuDivLinks[nMenuDivIndex];
                     break;
                  case resMoveDown :
                     M_clMoveDownMenu = clPageMenuDivLinks[nMenuDivIndex];
                     break;
                  case resMoveToBottom :
                     M_clMoveToBottomMenu = clPageMenuDivLinks[nMenuDivIndex];
                     break;
                  case (resMoveToFolder + G_strThreeDots) :
                     M_clMoveToFolderMenu = clPageMenuDivLinks[nMenuDivIndex];
                     break;
               }      
            }
         }
      }
   }
   
   if (M_clMoveTopButton != null && M_clMoveUpButton != null && M_clMoveDownButton != null
         && M_clMoveBottomButton != null) {
      M_clMoveTopButton.disabled = true;
      M_clMoveUpButton.disabled = true;
      M_clMoveDownButton.disabled = true;
      M_clMoveBottomButton.disabled = true;
      if (M_nCheckedNodes == 1) {
         for (nIndex = 0; nIndex < M_anNodeChecked.length; nIndex++) {
            if (M_anNodeChecked[nIndex] == 1) {
               if (M_anNodeCanMove[nIndex] == CAN_MOVE_UP_DOWN) {
                  M_clMoveTopButton.disabled = false;
                  M_clMoveUpButton.disabled = false;
                  M_clMoveDownButton.disabled = false;
                  M_clMoveBottomButton.disabled = false;
               }
               else if (M_anNodeCanMove[nIndex] == CAN_MOVE_UP) {
                  M_clMoveTopButton.disabled = false;
                  M_clMoveUpButton.disabled = false;
               }
               else if (M_anNodeCanMove[nIndex] == CAN_MOVE_DOWN) {
                  M_clMoveDownButton.disabled = false;
                  M_clMoveBottomButton.disabled = false;
               }
               break;
            }
         }
      }
      if (M_clMoveTopButton.disabled) {
         SwitchImage(M_clMoveTopButton, "unavailable");
         M_clMoveTopButton.style.cursor = "default";
         // Adjust MoveToTop Menu
         if (M_clMoveToTopMenu != null) {
            if (M_clMoveToTopMenu.href != "") {
               clMoveToTopMenuhref = M_clMoveToTopMenu.href;
            }
            M_clMoveToTopMenu.disabled = true;
            M_clMoveToTopMenu.className = "DisabledMenu";
            M_clMoveToTopMenu.removeAttribute('href'); 
         }
      }
      else {
         SwitchImage(M_clMoveTopButton, "active");
         M_clMoveTopButton.style.cursor = "auto";
         // Adjust MoveToTop Menu
         if (M_clMoveToTopMenu != null && clMoveToTopMenuhref != null) {
            M_clMoveToTopMenu.href	= clMoveToTopMenuhref;
            M_clMoveToTopMenu.className = ""; 
            M_clMoveToTopMenu.disabled = false;
         }
      }
      if (M_clMoveUpButton.disabled) {
         SwitchImage(M_clMoveUpButton, "unavailable");
         M_clMoveUpButton.style.cursor = "default";
         // Adjust MoveUp Menu
         if (M_clMoveUpMenu != null) {
            if (M_clMoveUpMenu.href != "") {
               clMoveUpMenuhref = M_clMoveUpMenu.href;
            }
            M_clMoveUpMenu.disabled = true;
            M_clMoveUpMenu.className = "DisabledMenu";
            M_clMoveUpMenu.removeAttribute('href'); 
         }
      }
      else {
         SwitchImage(M_clMoveUpButton, "active");
         M_clMoveUpButton.style.cursor = "auto";
         // Adjust MoveUp Menu
         if (M_clMoveUpMenu != null && clMoveUpMenuhref != null) {
            M_clMoveUpMenu.href	= clMoveUpMenuhref;
            M_clMoveUpMenu.className = "";
            M_clMoveUpMenu.disabled = false;
         }
      }
      if (M_clMoveDownButton.disabled) {
         SwitchImage(M_clMoveDownButton, "unavailable");
         M_clMoveDownButton.style.cursor = "default";
         // Adjust MoveDown Menu
         if (M_clMoveDownMenu != null) {
            if (M_clMoveDownMenu.href != "") {
               clMoveDownMenuhref = M_clMoveDownMenu.href;
            }
            M_clMoveDownMenu.disabled = true;
            M_clMoveDownMenu.className = "DisabledMenu";
            M_clMoveDownMenu.removeAttribute('href');
         }
      }
      else {
         SwitchImage(M_clMoveDownButton, "active");
         M_clMoveDownButton.style.cursor = "auto";
         // Adjust MoveDown Menu
         if (M_clMoveDownMenu != null && clMoveDownMenuhref != null) {
            M_clMoveDownMenu.href	= clMoveDownMenuhref;
            M_clMoveDownMenu.className = "";  
            M_clMoveDownMenu.disabled = false;
         }
      }
      if (M_clMoveBottomButton.disabled) {
         SwitchImage(M_clMoveBottomButton, "unavailable");
         M_clMoveBottomButton.style.cursor = "default";
         // Adjust MoveToBottom Menu
         if (M_clMoveToBottomMenu != null) {
            if (M_clMoveToBottomMenu.href != "") {
               clMoveToBottomMenuhref = M_clMoveToBottomMenu.href;
            }
            M_clMoveToBottomMenu.disabled = true;
            M_clMoveToBottomMenu.className = "DisabledMenu";
            M_clMoveToBottomMenu.removeAttribute('href'); 
         }
      }
      else {
         SwitchImage(M_clMoveBottomButton, "active");
         M_clMoveBottomButton.style.cursor = "auto";
         // Adjust MoveToBottom Menu
         if (M_clMoveToBottomMenu != null && clMoveToBottomMenuhref != null) {
            M_clMoveToBottomMenu.href	= clMoveToBottomMenuhref;
            M_clMoveToBottomMenu.className = "";
            M_clMoveToBottomMenu.disabled = false;
         }
      }
   }
   if (M_clDeleteButton != null) {
      M_clDeleteButton.disabled = true;
      if (M_nCheckedNodes > 0) {
         M_clDeleteButton.disabled = false;
      }
      if (M_clDeleteButton.disabled) {
         SwitchImage(M_clDeleteButton, "unavailable");
         M_clDeleteButton.style.cursor = "default";
         // Adjust Delete Menu
         if (M_clDeleteMenu != null) {
            if (M_clDeleteMenu.href != "") {
               clDeleteMenuhref = M_clDeleteMenu.href;
            }
            M_clDeleteMenu.disabled = true;
            M_clDeleteMenu.className = "DisabledMenu";
            M_clDeleteMenu.removeAttribute('href'); 
         }
      }
      else {
         SwitchImage(M_clDeleteButton, "active");
         M_clDeleteButton.style.cursor = "auto";
         // Adjust Delete Menu
         if (M_clDeleteMenu != null && clDeleteMenuhref != null) {
            M_clDeleteMenu.href	= clDeleteMenuhref;
            M_clDeleteMenu.className = ""; 
            M_clDeleteMenu.disabled = false;
         }
      }
   }
   if (M_clMoveDivider != null) {
      if (M_anNodeChecked.length > 0 && !bSearch) {
         M_clMoveDivider.style.display = 'block';
      }
      else {
         M_clMoveDivider.style.display = 'none';
      }
   }
   if (M_clSortButton != null && M_clSortButton.src.indexOf("_clicked") < 0) {
      if (M_anNodeChecked.length > 0 && !bSearch) {
         M_clSortButton.style.display = 'block';
         M_clSortButton.disabled = false;
      }
      else {
         M_clSortButton.style.display = 'none';
      }
   }
   if (M_clCreateNewReportDivider != null) {
      if (M_clReportsChoice != null || M_clExpandReportFolders != null || M_clMoveUpButton != null) {
         M_clCreateNewReportDivider.style.display = 'none';
      }
      else {
         M_clCreateNewReportDivider.style.display = 'none';
      }
   }
   if (M_clCreateNewFolderButton != null && M_clCreateNewFolderButton.src.indexOf("_clicked") < 0) {
      if (M_anNodeChecked.length > 0 && !bSearch) {
         M_clCreateNewFolderButton.style.display = 'block';
         M_clCreateNewFolderButton.disabled = false;
      }
      else {
         M_clCreateNewFolderButton.style.display = 'none';
      }
   }
   if ((M_clMoveToFolderButton != null && M_clMoveToFolderButton.src.indexOf("_clicked") < 0)) {
      if (M_anNodeChecked.length > 0 && !bSearch) {
         M_clMoveToFolderButton.style.display = 'block';
         if (M_nCheckedNodes > 0) {
            M_clMoveToFolderButton.disabled = false;
            SwitchImage(M_clMoveToFolderButton, "active");
            M_clMoveToFolderButton.style.cursor = "auto";
            // Adjust MoveToFolder Menu
            if (M_clMoveToFolderMenu != null) {
               M_clMoveToFolderMenu.href	= "javascript:ShowMoveToFolderOptions();"
               M_clMoveToFolderMenu.className = "";
               M_clMoveToFolderMenu.disabled = false;
            }
         }
         else {
            M_clMoveToFolderButton.disabled = true;
            SwitchImage(M_clMoveToFolderButton, "unavailable");
            M_clMoveToFolderButton.style.cursor = "default";
            // Adjust MoveToFolder Menu
            if (M_clMoveToFolderMenu != null) {
               M_clMoveToFolderMenu.disabled = true;
               M_clMoveToFolderMenu.className = "DisabledMenu";
               M_clMoveToFolderMenu.removeAttribute('href');
            }
         }
      }
      else {
         M_clMoveToFolderButton.style.display = 'none';
      }
   }
   if (M_clChangeButton != null && M_clChangeButton.src.indexOf("_clicked") < 0) {
      if (M_anNodeChecked.length > 0) {
         M_clChangeButton.style.display = 'block';
         if (M_nCheckedNodes == 1) {
            M_clChangeButton.disabled = false;
            SwitchImage(M_clChangeButton, "active");
            M_clChangeButton.style.cursor = "auto";
            // Adjust Change Menu
            if (M_clChangeMenu != null) {
               M_clChangeMenu.href	= "javascript:ShowChangeOptions();"
               M_clChangeMenu.className = "";
               M_clChangeMenu.disabled = false;
            }
         }
         else {
            M_clChangeButton.disabled = true;
            SwitchImage(M_clChangeButton, "unavailable");
            M_clChangeButton.style.cursor = "default";
            // Adjust Change Menu
            if (M_clChangeMenu != null) {
               M_clChangeMenu.disabled = true;
               M_clChangeMenu.className = "DisabledMenu";
               M_clChangeMenu.removeAttribute('href');
            }
            
         }
      }
      else {
         M_clChangeButton.style.display = 'none';
      }
   }
   if (M_clSearchButton != null) {
      if (bSearch) {
         SwitchImage(M_clSearchButton, "selected");
      }
      else {
         SwitchImage(M_clSearchButton, "active");
      }
   }
}

function AdjustCheckedNodeVisibility()
{
   var clContents;
   var clMovedNodeCheckbox;
   
   if (M_strMovedNodeCheckbox.length > 0) {
      clMovedNodeCheckbox = document.getElementById(M_strMovedNodeCheckbox);
      if (clMovedNodeCheckbox != null) {
         // Ensure that the checkbox associated with currently moved node is visible.
         clContents = document.getElementById("DivContents");
         if (clContents != null) {
            if (GetOffSet(clMovedNodeCheckbox, OFFSET_TOP) 
                  + GetOffSet(clMovedNodeCheckbox, BOTTOM_HEIGHT) >= 
                  GetOffSet(clContents, OFFSET_TOP) + GetOffSet(clContents, BOTTOM_HEIGHT))
            {
               clContents.scrollTop = GetOffSet(clMovedNodeCheckbox, OFFSET_TOP) 
                  - GetOffSet(clContents, OFFSET_TOP);
            }
         }
      }
   }
}

function DisplayLogin()
{
  // var clLoginButton;
   
  // clLoginButton = document.getElementById("LoginButton");
   //if (clLoginButton != null) {
     // clLoginButton.style.display = 'block';
      //clLoginButton.disabled = false;
      //SwitchImage(clLoginButton, "active");
      //if (document.aspnetForm.login.value == "") {
        // clLoginButton.alt = resSignOn;
         //clLoginButton.title = resSignOn;          
      //} else {
       //  clLoginButton.alt = resSignOut;
        // clLoginButton.title = resSignOut;  
      //}
   //}
}

function LoginLogout()
{
   if (document.aspnetForm.login.value == "") {
      ShowLoginOptions();
   } else {
		document.aspnetForm.action = "../Browse/LogOut.aspx"
		executeWait(document.aspnetForm);   
   }
}

function AdjustGlobalSettings(i_strLanguage, i_strLanguageCodes, i_strLanguageNames, 
   i_nDisplayLogin, i_strUser, i_strPassword, i_nLoginError, i_nRegistrationError, i_strErrorMessage,
   i_nDisplayLogo, i_strTutorials, i_strTutorialsPage, i_strCurrentAction, i_strCurrentActionBuffer1,
   i_strCurrentActionBuffer2, i_nNavigationTool, i_bValidUser)
{
   var clLanguageButton;
   var clLoginButton;
   var clLogo;
   var clTableViewButton;
   var clTutorialsButton;
   var strCurLang;
   
   // Remove extra fields from the URL, they are saved on the form      
   document.aspnetForm.action = document.location.pathname;
   
   document.aspnetForm.CurrentAction.value = i_strCurrentAction;
   document.aspnetForm.CurrentActionBuffer1.value = i_strCurrentActionBuffer1;
   document.aspnetForm.CurrentActionBuffer2.value = i_strCurrentActionBuffer2;
   
   document.aspnetForm.ReloadForm.value = false;
   document.aspnetForm.PerspectiveLanguage.value = i_strLanguage;
   // btnTableView is language specific, so different .gif needs to be displayed
   // when French has been selected as UI language
   clTableViewButton = document.getElementById("ctl00_ContentToolbar_btnTableView");
   strCurLang = document.aspnetForm.PerspectiveLanguage.value;
   if (clTableViewButton != null && strCurLang.substr(0,2).toLowerCase() == 'fr') {
      clTableViewButton.src = '../Bmp/table_view_fr_active.gif';
   }
   // page with charts has  tableview button as html control that is not run at server
   // so it's id is different:
   clTableViewButton = document.getElementById("btnTableView"); 
   if (clTableViewButton != null && strCurLang.substr(0,2).toLowerCase() == 'fr') {
      clTableViewButton.src = '../Bmp/table_view_fr_active.gif';
   }    
   if (i_strLanguageCodes.length > 0) {
      M_astrLanguageCodes = i_strLanguageCodes.split(GCommaRep);
      M_astrLanguageNames = i_strLanguageNames.split(GCommaRep);
      DisplayLanguageChoice();      
   }
   else {
      clLanguageButton = document.getElementById("LanguageButton");
      clLanguageButton.style.display = 'none';
   }
   //csBeginMod WattersJ 2009-09-30 Display Info Message to screen
   if (i_nLoginError == 0 && i_strErrorMessage.length > 0){
    //display message to user.
           ShowMessageOptions(i_strErrorMessage);        
   }
   //csEndMod WattersJ 2009-09-30 Display Info Message to screen
   if (i_nDisplayLogin == 1) {
      DisplayLogin();
      document.aspnetForm.CheckRegistration.value = "0";
      document.aspnetForm.PerspectiveUserId.value = i_strUser;
      document.aspnetForm.PerspectivePassword.value = i_strPassword;
      if (i_nLoginError == 1) {
         if (i_strErrorMessage.length > 0) {
            //csBeginMod WattersJ 2009-09-30 error message by res string or by normal string         
            if (i_strErrorMessage.split(GEmptyRep).length < 1) {          
                eval("ShowLoginOptions(res" + i_strErrorMessage + ");");
            }else{
                //csEndMod WattersJ 2009-09-30 error message by res string or by normal string         
                eval("ShowLoginOptions('" + i_strErrorMessage + "');");
            }
         }
         else {
            ShowLoginOptions();
         }
      }
      else if (i_nRegistrationError == 1) {
         if (i_strErrorMessage.length > 0) {
            eval("ShowRegisterOptions(res" + i_strErrorMessage + ");");
         }
         else {
            ShowRegisterOptions();
         }
      }
   }
   if (i_strTutorials.length > 0) {
      M_astrTutorials = i_strTutorials.split(GCommaRep);
      M_strTutorialsPage = i_strTutorialsPage;
      DisplayTutorialsButton();
   }
   else {
      clTutorialsButton = document.getElementById("TutorialsButton");
      clTutorialsButton.style.display = 'none';   
   }
   
   // Hide all contents if there is no valid user yet
   if (!i_bValidUser) {
      var clMenuTD = document.getElementById("MenuTD");
      if (clMenuTD != null) {
         clMenuTD.style.height = 0;
      }
	   var clToolBarLine;
      clToolBarLine = document.getElementById("ToolBarLine");
      if (clToolBarLine != null) {
         clToolBarLine.style.display = 'none';
      }
      var clReportHeader;
      clReportHeader = document.getElementById("ReportHeader");
      if (clReportHeader != null) {
         clReportHeader.style.display = 'none';
      }
      var clDivContents;
      clDivContents = document.getElementById("DivContents");
      if (clDivContents != null) {
         clDivContents.style.display = 'none';
      }
      return;
   }
   
   // Navigation tool
   switch (i_nNavigationTool) {
	   case MenusOnly :
		   var clMenuTable;
         clMenuTable = document.getElementById("MenuTable");
         if (clMenuTable != null) {
            clMenuTable.style.display = 'block';
         }
		   break;
		case ToolbarsOnly :
         var clMenuTD = document.getElementById("MenuTD");
	      if (clMenuTD != null) {
	         clMenuTD.style.height = 0;
	      }
    
		   var clDimListToolbarTR;
         clDimListToolbarTR = document.getElementById("DimListToolbarTR");
         if (clDimListToolbarTR != null) {
            clDimListToolbarTR.style.display = 'block';
         }
		   var clToolBarLine;
         clToolBarLine = document.getElementById("ToolBarLine");
         if (clToolBarLine != null) {
            clToolBarLine.style.display = 'block';
         }
		   break;
	   default:
	      var clMenuTable;
         clMenuTable = document.getElementById("MenuTable");
         if (clMenuTable != null) {
            clMenuTable.style.display = 'block';
         }
         var clDimListToolbarTR;
         clDimListToolbarTR = document.getElementById("DimListToolbarTR");
         if (clDimListToolbarTR != null) {
            clDimListToolbarTR.style.display = 'block';
         }
         var clToolBarLine;
         clToolBarLine = document.getElementById("ToolBarLine");
         if (clToolBarLine != null) {
            clToolBarLine.style.display = 'block';
         }
   }
   
   if (i_nDisplayLogo == 1) {
      if (i_nNavigationTool == MenusAndToolbars || i_nNavigationTool == MenusOnly) {
         clLogo = document.getElementById("MenuAppLogo");
         if (clLogo != null) {
            clLogo.style.display = 'block';
         }
      }
      else {
         clLogo = document.getElementById("AppLogo");
         if (clLogo != null) {
            clLogo.style.display = 'block';
         }
      }
   }
   
   if (typeof(document.aspnetForm.PrintableVersion) != "undefined") {
      document.aspnetForm.PrintableVersion.value = "";
   }
}

// ----------------------------------------------------------------------------
function DisplayLanguageChoice()
{
   var clLanguageButton;
   
   clLanguageButton = document.getElementById("LanguageButton");
   if (clLanguageButton != null) {
      clLanguageButton.style.display = 'block';
      clLanguageButton.disabled = false;
      SwitchImage(clLanguageButton, "active");
   }
}

//-----------------------------------------------------------------------------
function OnShowDimsList()
{
   var clDivDimsList = document.getElementById("ctl00_DivDimList");   
      
   if (clDivDimsList.style.display == 'block')
   {        
      clDivDimsList.style.display = 'none';      
       document.getElementById("DivVerticalLineOpenTop").style.display='none';
	   document.getElementById("DivVerticalLineOpen").style.display='none';
	   document.getElementById("DivVerticalLineOpenBottom").style.display='none';
	   document.getElementById("DivVerticalLineCloseTop").style.display='block';
	   document.getElementById("DivVerticalLineClose").style.display='block';
	   document.getElementById("DivVerticalLineCloseBottom").style.display='block';
	   
	  if(G_nBrowser != IE)
	   {	         
	     clDivDimsList.style.width= 0;
	   }	  
	   document.aspnetForm.ShowDimsListPane.value='False';
   }
   else
   {        
       document.getElementById("DivVerticalLineOpenTop").style.display='block';
	   document.getElementById("DivVerticalLineOpen").style.display='block';
	   document.getElementById("DivVerticalLineOpenBottom").style.display='block';
	   document.getElementById("DivVerticalLineCloseTop").style.display='none';
	   document.getElementById("DivVerticalLineClose").style.display='none';
	   document.getElementById("DivVerticalLineCloseBottom").style.display='none';
	   clDivDimsList.style.display='block';	  
	   document.aspnetForm.ShowDimsListPane.value='True';     
   }
   onLayoutResize();
}

function AdjustDividerStatus(i_bValidUser)
{
   if (i_bValidUser) {
      if (document.aspnetForm.ShowDimsListPane.value=='False' ) {
         document.getElementById("ctl00_DivDimList").style.display='none';     
         document.getElementById("DivVerticalLineOpenTop").style.display='none';
         document.getElementById("DivVerticalLineOpen").style.display='none';
         document.getElementById("DivVerticalLineOpenBottom").style.display='none';
         document.getElementById("DivVerticalLineCloseTop").style.display='block';
         document.getElementById("DivVerticalLineClose").style.display='block';
         document.getElementById("DivVerticalLineCloseBottom").style.display='block';
   	   
         if(G_nBrowser != IE)
         {	         
            document.getElementById("ctl00_DivDimList").style.width= 0;
         }	  
      }
      else
      {
         document.getElementById("DivVerticalLineOpenTop").style.display='block';
         document.getElementById("DivVerticalLineOpen").style.display='block';
         document.getElementById("DivVerticalLineOpenBottom").style.display='block';
         document.getElementById("DivVerticalLineCloseTop").style.display='none';
         document.getElementById("DivVerticalLineClose").style.display='none';
         document.getElementById("DivVerticalLineCloseBottom").style.display='none';
         document.getElementById("ctl00_DivDimList").style.display='block'; 	  
      }
   }
}

function AttachCubeLevelNodeCheckedHandlers()
{
   var aclCheckboxes;
   var clCheckbox;
   var nIndex;
   var strString1 = "CubeDimensionsTreen";

	// Attach onClick handler to all tree view nodes checkboxes (the only checkboxes on this page)
	aclCheckboxes = document.getElementsByTagName("input");
	for (nIndex=0; nIndex < aclCheckboxes.length; nIndex++) {
		clCheckbox = aclCheckboxes[nIndex];
		if (clCheckbox.type == "checkbox") {
		   if (clCheckbox.id.indexOf(strString1) > 0) {
		      clCheckbox.checked = false;
		      clCheckbox.onclick = CubeLevelNodeChecked;
		   }
		}
	}
}

function CubeLevelNodeChecked(i_clEvent)
{
   var bAllLevel;
   var clCheckbox;
   var clEvent;
   var clSource;
   var nIndex;
   var nLevelNodeIndex;
   var nLevelsAbove;
   var nLevelsBelow;
   var nNodeIndex;
   var nPos1;
   var nPos2;
   var strId;
   var strIdPrefix;
   var strIdSuffix;
   var strString1 = "CubeDimensionsTreen";
   var strString2 = "CheckBox";
   
   clEvent = (i_clEvent) ? i_clEvent : event;
   clSource = (clEvent.target) ? clEvent.target : clEvent.srcElement;
   strId = clSource.id;
   nPos1 = strId.lastIndexOf(strString1);
   nPos2 = strId.lastIndexOf(strString2);
   if (nPos1 >= 0 && nPos2 >= 0) {
      strIdPrefix = strId.substring(0, nPos1 + strString1.length);
      strIdSuffix = strId.substring(nPos2);
      strId = strId.substring(nPos1 + strString1.length, nPos2);
      nNodeIndex = parseInt(strId);
      nLevelNodeIndex = M_anLevelNodeIndex[nNodeIndex];
      if (nNodeIndex >= 0) {
         nLevelsAbove = M_anLevelsAbove[nLevelNodeIndex];
         nLevelsBelow = M_anLevelsBelow[nLevelNodeIndex];
         bAllLevel = M_abLevelsAll[nLevelNodeIndex];
         if (clSource.checked) {
            M_nLevelsChecked += 1;
            if (nLevelsAbove > 0) {
               // Select all levels above this one, too.
               for (nIndex = 1; nIndex <= nLevelsAbove; nIndex++) {
                  strId = strIdPrefix + (nNodeIndex - nIndex).toString() + strIdSuffix;
                  clCheckbox = document.getElementById(strId);
                  if (clCheckbox != null) {
                     if (!clCheckbox.checked) {
                        clCheckbox.checked = true;
                        M_nLevelsChecked += 1;
                     }
                  }
               }
            }
            else if (bAllLevel) {
               // Select the next level, too, when selecting the "All" level.
               strId = strIdPrefix + (nNodeIndex + 1).toString() + strIdSuffix;
               clCheckbox = document.getElementById(strId);
               if (clCheckbox != null) {
                  if (!clCheckbox.checked) {
                     clCheckbox.checked = true;
                     M_nLevelsChecked += 1;
                  }
               }
            }
         }
         else {
            M_nLevelsChecked -= 1;
            if (nLevelsBelow > 0) {
               // Unselect all levels below this one, too.
               for (nIndex = 1; nIndex <= nLevelsBelow; nIndex++) {
                  strId = strIdPrefix + (nNodeIndex + nIndex).toString() + strIdSuffix;
                  clCheckbox = document.getElementById(strId);
                  if (clCheckbox != null) {
                     if (clCheckbox.checked) {
                        clCheckbox.checked = false;
                        M_nLevelsChecked -= 1;
                     }
                  }
               }
            }
            if (nLevelsAbove == 1) {
               bAllLevel = M_abLevelsAll[nLevelNodeIndex - 1];
               if (bAllLevel) {
                  // Unselect the "All" level when unselecting the one just below it.
                  strId = strIdPrefix + (nNodeIndex - 1).toString() + strIdSuffix;
                  clCheckbox = document.getElementById(strId);
                  if (clCheckbox != null) {
                     if (clCheckbox.checked) {
                        clCheckbox.checked = false;
                        M_nLevelsChecked -= 1;
                     }
                  }
               }
            }
         }
      }
   }
}

function AttachCubeMeasureNodeCheckedHandlers()
{
   var aclCheckboxes;
   var clCheckbox;
   var nIndex;
   var strString1 = "CubeMeasuresTreen";

	// Attach onClick handler to all tree view nodes checkboxes (the only checkboxes on this page)
	aclCheckboxes = document.getElementsByTagName("input");
	for (nIndex=0; nIndex < aclCheckboxes.length; nIndex++) {
		clCheckbox = aclCheckboxes[nIndex];
		if (clCheckbox.type == "checkbox") {
		   if (clCheckbox.id.indexOf(strString1) > 0) {
		      clCheckbox.checked = false;
		      clCheckbox.onclick = CubeMeasureNodeChecked;
		   }
		}
	}
}

function CubeMeasureNodeChecked(i_clEvent)
{
   var clEvent;
   var clSource;
   
   clEvent = (i_clEvent) ? i_clEvent : event;
   clSource = (clEvent.target) ? clEvent.target : clEvent.srcElement;
   if (clSource.checked) {
      M_nMeasuresChecked += 1;
   }
   else {
      M_nMeasuresChecked -= 1;
   }
}

function ValidateSearchString(i_szSearchString)
{
   var szTemp;

   // empty string   
   szTemp = i_szSearchString;
	if ( szTemp == ""){
		alert(resSearchEnterWord);
		return false;
	}

   // spaces
	szTemp = szTemp.replace(new RegExp(" ", "g"),"");
	if ( szTemp == ""){
		alert(resSearchEnterWord);
		return false;
	}
    
   // commas
	szTemp = szTemp.replace(new RegExp("\,", "g"),"");
	if ( szTemp == ""){
		alert(resSearchEnterWord);
		return false;
	}
	
   //back slashes
   //To escape back slash in regular expression we need to put there four of them
   // but it represents just one - RegExp("\\\\", "g").
   szTemp = szTemp.replace(new RegExp("\\\\", "g"),""); 
   if ( szTemp == ""){
      alert(resSearchEnterWord);			
      return false;
   }

   //double quotes  is a special case
	szTemp = i_szSearchString;
	if (szTemp.indexOf("\"") > -1) {
		if (szTemp.indexOf("\"") == 0){
			if (szTemp.length > 1) {
				szTemp = szTemp.substr(1,szTemp.length - 1);
			}
			 else {
				alert(resSearchEnterWord);			
				return false;
			}
		}
		if (szTemp.lastIndexOf("\"") == szTemp.length - 1) {
			if (szTemp.length > 1) {
				szTemp = szTemp.substr(0,szTemp.length - 2);
			}
			else {
				alert(resSearchEnterWord);			
				return false;
			}
		}
		if (szTemp.length < 0) {			
			alert(resSearchEnterWord);			
			return false; 
		}
   } 
   return true;
}

function SubmitSearch(e)
{
   var key = GetKeyCode(e);
   if ( key == 13) {
      if (!ReportSearch()) {
         ResetSubmit(e);
      }
   }
}

function ReportSearch(i_clSearchEntry)
{
   var clSearchEntry;
   
   if (i_clSearchEntry != null) {
      clSearchEntry = i_clSearchEntry;
   }
   else {
      clSearchEntry = document.aspnetForm.SearchString;
   }
   if (clSearchEntry != null) {
      var nLen;
      var szSearchString = clSearchEntry.value;
      
      CollapseSearchList();
      if (!ValidateSearchString(szSearchString)) {
         clSearchEntry.focus();
      }
      else {
		   //replace quotes with a special character
		   szSearchString = szSearchString.replace(new RegExp("\"", "g"), GDoubleQuoteRep);
		   nLen = szSearchString.length;
         if (nLen > 1 && szSearchString.indexOf(GDoubleQuoteRep) == 0 
               && szSearchString.lastIndexOf(GDoubleQuoteRep) == nLen - 1) {
            // Fill "Phrase" segment (unquoted) - second segment
            szSearchString = GDelim20 + szSearchString.substr(1, nLen - 2) + GDelim20 + GDelim20 + GDelim20
         }
         else {
            // Fill "All Words" segment - first segment
            szSearchString = szSearchString + GDelim20 + GDelim20 + GDelim20 + GDelim20
         }
         document.aspnetForm.ReportSearchString.value = escapeHTML(szSearchString);
         document.aspnetForm.ReportSearchFields.value = SF_REPORT_TITLES.toString() + "," + SF_REPORT_NOTES.toString();
         clSearchEntry.value = "";
         executeWait(document.aspnetForm);
      }
   }
}

// ----------------------------------------------------------------------------
function ShowReportsFolder()
{
   zeroScrollPosition();
	document.aspnetForm.action = "../Browse/BrowseTables.aspx";
   executeWait(document.aspnetForm);
}

// ----------------------------------------------------------------------------
function ShowChart()
{
   zeroScrollPosition();
   document.aspnetForm.ReportType.value = "chart";
   ClearDrillThroughState();
   document.aspnetForm.FirstRow.value = 0;
   document.aspnetForm.FirstCol.value = 0;
   document.aspnetForm.ChartStartRow.value = 0;
   document.aspnetForm.ChartStartCol.value = 0;
   document.aspnetForm.FullChartRequest.value = "False";
   GetChartSize();
	document.aspnetForm.action = "../View/dispchart.aspx";
   executeWait(document.aspnetForm);
}

// ----------------------------------------------------------------------------
// ---handles underlined cells in dispview.aspx, as well as the return to drillthrough data button in help
function OnDrillThrough(i_szDrillThroughMembers, i_szMemberFootnoteSymbols, i_szMemberFootnoteText, i_szDrillThroughActionName, i_szDrillthroughActionId)
{
	var szBuffer = i_szDrillThroughMembers;
	szBuffer = szBuffer.replace(new RegExp(GSingleQuoteRep, "g"), "\'");
   szBuffer = szBuffer.replace(new RegExp("<", "g"), GLtRep);
   szBuffer = szBuffer.replace(new RegExp(">", "g"), GGtRep);
	document.aspnetForm.DrillThroughItems.value = szBuffer;
	
	if (typeof(document.aspnetForm.DrillThroughActionName) != "undefined" && i_szDrillThroughActionName != null) {
	   szBuffer = i_szDrillThroughActionName.replace(new RegExp(GSingleQuoteRep, "g"), "\'");
	   document.aspnetForm.DrillThroughActionName.value = szBuffer;
	}
	
	if (typeof(document.aspnetForm.DrillthroughActionIndex) != "undefined" && i_szDrillthroughActionId != null) {
	   document.aspnetForm.DrillthroughActionIndex.value = i_szDrillthroughActionId;
	}
	
	szBuffer = i_szMemberFootnoteSymbols.replace(new RegExp(GSingleQuoteRep, "g"), "\'");
	szBuffer = szBuffer.replace(new RegExp("<", "g"), GLtRep);
	szBuffer = szBuffer.replace(new RegExp(">", "g"), GGtRep);
	document.aspnetForm.DrillThroughMemberFootnoteSymbols.value = szBuffer;
	
	szBuffer = i_szMemberFootnoteText.replace(new RegExp(GSingleQuoteRep, "g"), "\'");
	szBuffer = szBuffer.replace(new RegExp("<", "g"), GLtRep);
	szBuffer = szBuffer.replace(new RegExp(">", "g"), GGtRep);
	document.aspnetForm.DrillThroughMemberFootnoteText.value = szBuffer;
	
	document.aspnetForm.Dim.value = 1 + eval(GetMaxDim());
	document.aspnetForm.FirstRow.value = 0;
	document.aspnetForm.FirstCol.value = 0;
	if (typeof(document.aspnetForm.DrillthroughSet) != "undefined") {
		document.aspnetForm.PrevDrillthroughSet.value = document.aspnetForm.DrillthroughSet.value;
		document.aspnetForm.DrillthroughSet.value = 0;
	}
	
	document.aspnetForm.ReportType.value = "drillthrough";
		
	document.aspnetForm.action = "../View/drillthrough.aspx";
	executeWait(document.aspnetForm);
}

// ----------------------------------------------------------------------------
function ShowDrillThrough()
{
   document.aspnetForm.action = "../View/Drillthrough.aspx" ;
   executeWait(document.aspnetForm);
}

// ----------------------------------------------------------------------------
function ClearDrillThroughState()
{
   document.aspnetForm.DrillThroughItems.value = "";
   document.aspnetForm.DrillThroughActionName.value = "";
   document.aspnetForm.DrillThroughMemberFootnoteSymbols.value = "";
   document.aspnetForm.DrillThroughMemberFootnoteText.value = "";
}

// SYMBOLIC FOOTNOTES
var M_aFootnoteDescriptions;
var M_aFootnoteSymbols;
var M_className = document.all ? "className" : "class";		// IE vs NN
var M_copyFootnotePopupBox;
var M_copyCurrentFootnoteSpanClass;
var M_footnoteSpan;
var M_footnoteTimeoutID = 0;
var M_footnotetimeoutDelay = 500;
var M_footnotePopupOffset = 5;	// Distance from Footnote Symbols to Footnote Popup Box
var M_footnoteBoundary = 5;		// Distance from Footnote Popup Box to screen boundaries

if (G_dIEVersion >= 5.5) {
	var M_oPopup = window.createPopup();
}
else if (G_dIEVersion > 0) {
	var M_aHiddenSelects = new Array();
}

function DisplayFootnotes(i_aFootnoteSymbols, i_aFootnoteDescriptions, i_footnoteSpan) {
    M_aFootnoteSymbols = i_aFootnoteSymbols;
    M_aFootnoteDescriptions = i_aFootnoteDescriptions;
    M_footnoteSpan = i_footnoteSpan;

    if (M_footnoteTimeoutID != 0){
        clearTimeout(M_footnoteTimeoutID);
    }
    M_footnoteSpan.style.cursor='default';
    M_footnoteTimeoutID = setTimeout("ShowFootnotes()", M_footnotetimeoutDelay);
}

//Hides the Popup Window used for Footnotes and Missing Values
function HideFootnotes (i_footnoteSpan) {

    var popupBox = document.getElementById("footnotesBox");
    
    // Clear the timer
    if (M_footnoteTimeoutID != 0){
        clearTimeout(M_footnoteTimeoutID);
        M_footnoteTimeoutID = 0;
    }
    else {
			if (G_dIEVersion >= 5.5) {
				// hide the IE Popup object
				M_oPopup.hide();
			}
			else if (G_dIEVersion > 0) {
				// Show the previously hidden <SELECT> elements (Pre-5.5 IE only)
				var nIndex;
				var nLen = M_aHiddenSelects.length;
				var szName;
			
				for (nIndex = 0; nIndex < nLen; nIndex++) {
				   szName = M_aHiddenSelects[nIndex];
				   if (szName.length > 0) {
					   document.all[szName].style.visibility = "visible";
				   }
				}
				M_aHiddenSelects = new Array();
			}
			
        // Reset the class of the footnote span to its original style
         i_footnoteSpan.setAttribute(M_className, M_copyCurrentFootnoteSpanClass, 0);
        
        if (popupBox != null) { 
            // Reset the Div
            popupBox.parentNode.replaceChild(M_copyFootnotePopupBox,popupBox);
        }      
    }
}

function ShowFootnotes(){
    // Reset the TimeoutID
    M_footnoteTimeoutID = 0;

    var clLeftArea = document.getElementById("LeftArea");
    var clHeaderArea = document.getElementById("HeaderArea");
    
    // Span Size and Positioning Variables
    var spanWidth = M_footnoteSpan.offsetWidth;
    var spanHeight = M_footnoteSpan.offsetHeight;
    var spanPosX = 0;
    var spanPosY = 0;
    var offsetX = 0;
    var offsetY = 0;
    var overflowY = 0;

    // Div variables
    var popupBox = document.getElementById("footnotesBox");
    var divPaddingStyle;
    var divPadding;
    
    // Available screen size (in our document window)
    var docWidth;
    var docHeight;

   if (G_dIEVersion) {
		docWidth = document.body.clientWidth - 4;	// IE 
		docHeight = document.body.clientHeight;
	   divPaddingStyle = popupBox.currentStyle.paddingLeft;
      divPadding = divPaddingStyle.substr(0,divPaddingStyle.length - 2);
   }
	else {
		docWidth = window.innerWidth;	            // NN
		docHeight = window.innerHeight;
	   divPaddingStyle = document.defaultView.getComputedStyle(popupBox,null);
      divPadding = parseInt(divPaddingStyle.getPropertyValue('padding-left'));
   }
    
    // Get the absolute position of the span
    var currentElement = M_footnoteSpan;
	 spanPosX = GetOffSet(currentElement, OFFSET_LEFT); 
    spanPosY = GetOffSet(currentElement, OFFSET_TOP);
    
    // Save the Div Element here so that it can be easily reset
    // in the HideFootnotes function
    M_copyFootnotePopupBox = popupBox.cloneNode(true);

    // We use a different style for the footnote span to highlight it.
    // Save the original class so that it can be reset in the HideFootnotes function
    M_copyCurrentFootnoteSpanClass = M_footnoteSpan.getAttribute(M_className);
    M_footnoteSpan.setAttribute(M_className, "CurrentFootnoteSpanOnPopup", 0);

    // Create the <Table> to contain the Footnotes Data
    var footnotesTable = document.getElementById("footnotesTable");
    var footnoteTR;
    var footnoteSymbol;
    var footnoteDesc;
    
    for (index = 0; index < M_aFootnoteSymbols.length; index++) {
		footnoteSymbol = "(" + M_aFootnoteSymbols[index] + ")";
		footnoteSymbol = footnoteSymbol.replace(new RegExp(GSingleQuoteRep, "g"), "'")
		footnoteDesc = M_aFootnoteDescriptions[index];
		footnoteDesc = footnoteDesc.replace(new RegExp(GSingleQuoteRep, "g"), "'")
      footnotesTable.insertRow(index);                 
      
      footnotesTable.rows[index].insertCell(0);
      footnotesTable.rows[index].cells[0].appendChild(document.createTextNode(
			footnoteSymbol));          
      footnotesTable.rows[index].cells[0].align = "left";
      footnotesTable.rows[index].cells[0].vAlign = "top";

      footnotesTable.rows[index].insertCell(1);
      footnotesTable.rows[index].cells[1].appendChild(document.createTextNode(
			footnoteDesc));  
      footnotesTable.rows[index].cells[1].align = "left";
      footnotesTable.rows[index].cells[1].vAlign = "top";                    
    } 
        
    // Populate, format, and position the Popup box
    // We adjust the width first because any changes in these settings will affect the height.
    // Offsets are measured from the top/left of the current span position
    var boxWidth = footnotesTable.offsetWidth + 2*divPadding;
    var boxLeft;
    var maxBoxWidth;

    // Left side of screen   
    if (spanPosX <= (docWidth/2)) {   
        maxBoxWidth = docWidth - spanWidth - spanPosX - M_footnotePopupOffset
			- M_footnoteBoundary - 2 * divPadding;
        if (boxWidth > maxBoxWidth) {
           boxWidth = maxBoxWidth;
        }
        offsetX = M_footnotePopupOffset + spanWidth;
    }
    // Right side of screen
    else {
        maxBoxWidth = spanPosX - M_footnotePopupOffset - M_footnoteBoundary - 2 * divPadding;
        if (boxWidth > maxBoxWidth) {
           boxWidth = maxBoxWidth;
        }
        offsetX = offsetX - M_footnotePopupOffset - boxWidth - 2*divPadding;
    }
    
    boxLeft = spanPosX + offsetX;
    if (G_nBrowser != IE) boxLeft = boxLeft - clLeftArea.offsetWidth;
    if(docWidth < boxLeft + boxWidth) //truncation
      boxLeft = docWidth - boxWidth - divPadding;
    
    // Set the table width and position
    footnotesTable.width = boxWidth;
    popupBox.style.left = boxLeft;
 
     
    // Allow the box to stretch vertically, if required
    // overflowY tells us how much to shift the box up or down
    // Note: There are different overflow and offset calculations
    // based on current span position
    var boxHeight = footnotesTable.offsetHeight + 2*divPadding;
    var boxTop;
    var noOverflowHeight = 0;

    // Top half of available screen 
    if (spanPosY <= ((docHeight)/2)){
        noOverflowHeight = ((docHeight) - spanPosY - spanHeight - M_footnotePopupOffset 
			- M_footnoteBoundary);
        overflowY = noOverflowHeight - boxHeight; 
        
        // only shift the box when required
        if (overflowY >= 0){
            overflowY = 0;
        }       
        offsetY = spanHeight + M_footnotePopupOffset + overflowY;
    }
    
    // Bottom half of available screen
    else {
        noOverflowHeight = spanPosY - M_footnoteBoundary - M_footnotePopupOffset;
        overflowY = boxHeight - noOverflowHeight;
        
        // only shift the box when required
        if (overflowY <= 0){
            overflowY = 0;
        }
        offsetY = overflowY - M_footnotePopupOffset - boxHeight;
    }
    
	boxTop = spanPosY + offsetY;
	
	if (G_nBrowser != IE) boxTop = boxTop - clHeaderArea.offsetHeight;
	
	// Display the message from top to bottom
  	if (boxTop < 0) {
  	  boxTop = 0;
  	}
   popupBox.style.top = boxTop;
   
	// Display it
	if (G_dIEVersion >= 5.5) {
		// use IE Popup object
		boxLeft -= document.aspnetForm.PosX.value;
		boxTop -= document.aspnetForm.PosY.value;
		var popupBody = M_oPopup.document.body;
		popupBody.innerHTML = popupBox.innerHTML;
		M_oPopup.show(boxLeft, boxTop, 0, 0);
		var realHeight = popupBody.scrollHeight;
		var realWidth = popupBody.scrollWidth;
		M_oPopup.hide();
		M_oPopup.show(boxLeft, boxTop, realWidth, realHeight, document.body);
	}
	else {
		var aSelects;
		var nElement = 0;
		var nIndex;
		
		if (G_dIEVersion > 0) {
			M_aHiddenSelects = new Array();
		}
		aSelects = document.getElementsByTagName('SELECT')
		for (nIndex = 0; nIndex < aSelects.length; nIndex++) {
			if (G_dIEVersion > 0) {
				// Hide all <SELECT> elements (Pre-5.5 IE only)
				// They could be displayed on top of the footnote window
				if (aSelects[nIndex].style.visibility != "hidden") {
					M_aHiddenSelects[nElement++] = aSelects[nIndex].name;
					aSelects[nIndex].style.visibility = "hidden";
				}
			}
			else {
				// Blur all <SELECT> elements in Netscape, their list portion
				// could be displayed on top of the footnote window.
				aSelects[nIndex].blur();
			}
		}
		
		// Show the <div> element in Netscape and pre-5.5 IE
		setTimeout("document.getElementById('footnotesBox').style.visibility = 'visible';", 1);
	}
}

//summary buttons for dispview and drillthrough
function OnCubeSummary(i_strSummaryType, i_nCubeId, i_nDimList)
{
   M_bFormSubmitted = true;
   document.aspnetForm.action = "../Browse/SummaryWithCubeState.aspx?SummaryType=" + i_strSummaryType.toString()
		+ "&SummaryCubeId=" + i_nCubeId.toString() + "&SummaryDimList=" + i_nDimList.toString();
   executeWait(document.aspnetForm);
}

function OnFootnoteSummary(i_strSummaryType)
{
   M_bFormSubmitted = true;
   document.aspnetForm.FirstRow.value = 0;
   document.aspnetForm.FirstCol.value = 0;
   document.aspnetForm.action = "../Browse/SummaryWithCubeState.aspx?SummaryType=" + i_strSummaryType.toString();
   executeWait(document.aspnetForm);
}

function OnMissingValueSummary(i_strSummaryType)
{
   M_bFormSubmitted = true;
   document.aspnetForm.FirstRow.value = 0;
   document.aspnetForm.FirstCol.value = 0;
   document.aspnetForm.action = "../Browse/SummaryWithCubeState.aspx?SummaryType=" + i_strSummaryType.toString();
   executeWait(document.aspnetForm);
}

function OnDimensionSummary(i_strSummaryType, i_nDimIndex)
{
   M_bFormSubmitted = true;
   document.aspnetForm.action = "../Browse/SummaryWithCubeState.aspx?SummaryType=" + i_strSummaryType.toString()
		+ "&DimensionIndex=" + i_nDimIndex.toString();
   executeWait(document.aspnetForm);
}

function OnMemberSummary(i_strSummaryType, i_szDimName, i_szHierarchy, i_szMember)
{
   M_bFormSubmitted = true;
   var szMember = i_szMember.replace(new RegExp(GSingleQuoteRep, "g"), "\'");
   szMember = szMember.replace(new RegExp("<", "g"), GLtRep);
   szMember = szMember.replace(new RegExp(">", "g"), GGtRep);
   document.aspnetForm.action = "../Browse/SummaryWithCubeState.aspx?SummaryType=" + i_strSummaryType.toString()
		+ "&DimensionName="
		+ escape(i_szDimName) + "&HierarchyName=" + escape(i_szHierarchy)
		+ "&MemberName=" + escape(szMember);
   executeWait(document.aspnetForm);
}

function OnHierarchySummary(i_strSummaryType, i_nDimIndex, i_nHierarchyIndex)
{
   M_bFormSubmitted = true;
   document.aspnetForm.action = "../Browse/SummaryWithCubeState.aspx?SummaryType=" + i_strSummaryType.toString()
		+ "&DimensionIndex="	+ i_nDimIndex.toString() + "&HierarchyIndex=" + i_nHierarchyIndex.toString();
   executeWait(document.aspnetForm);
}

function ExpandSummaryList(i_DropDownCell, i_DropDownDiv, i_bAlignRight)
{
   var clSummaryListDiv;
  
   var clDropDownCell = document.getElementById(i_DropDownCell);
   var clSummaryListDiv = document.getElementById(i_DropDownDiv);
   var clHeaderArea = document.getElementById("HeaderArea");
   var clLeftArea = document.getElementById("LeftArea");
   var nHeaderAreaHeight = 0;
   var nLeftAreaWidth = 0;
  
   if (clHeaderArea != null) nHeaderAreaHeight = clHeaderArea.offsetHeight;
   if (clLeftArea != null) nLeftAreaWidth = clLeftArea.offsetWidth;

   var nContentTopBarHeight = 0;
   clContentTopBar = document.getElementById("ContentTopBar");
   if (clContentTopBar != null) {
      nContentTopBarHeight = clContentTopBar.offsetHeight;
   }
    
   if(clDropDownCell != null && clSummaryListDiv != null) {
      if (G_CloseSummaryList == 1) {
         CollapseSummaryList();
      }
      else {
         if (G_CloseLanguageList == 1) {
            CollapseLanguageList();
         }
         if (G_CloseTutorialList == 1) {
            CollapseTutorialList();
         }
         if (G_CloseSearchList == 1) {
            CollapseSearchList();
         }
         OnCancelOptions();
         hideObjectElements();
         hideSelectionControls(); 

         clSummaryListDiv.style.position = "absolute";
         clSummaryListDiv.style.zIndex = 99;
         clSummaryListDiv.style.visibility = "visible";
         clSummaryListDiv.style.display = "block";
         var left = M_pfnCalculateX(clDropDownCell) - nLeftAreaWidth;
         var top = M_pfnCalculateY(clDropDownCell) - nHeaderAreaHeight + nContentTopBarHeight;
         if (i_bAlignRight) {
            left = left - clSummaryListDiv.offsetWidth + clDropDownCell.offsetWidth;
         }
         clSummaryListDiv.style.left = left;
         clSummaryListDiv.style.top = top;
         G_CloseSummaryList = 1;
      }
   }
}

function CollapseSummaryList()
{
   var clSummaryListDiv = document.getElementById("SummaryDiv");
   if(clSummaryListDiv != null) {
      clSummaryListDiv.style.position = "static";
      clSummaryListDiv.style.visibility = "hidden";
      clSummaryListDiv.style.display = "none";
   }
   G_CloseSummaryList = 0;
   showSelectionControls();
}

function FindViewDim(i_nDim)
{
   var nIndex;
   
   for (nIndex = 0; nIndex < M_anViewDimIndices.length; nIndex++) {
      if (M_anViewDimIndices[nIndex] == i_nDim) {
         return nIndex;
      }
   }
   return - 1;
}

//-------------------------------------------------------------------
// Adds options to a select control, accounting for browser differences.
function SelectControlAddOption(i_objSelect, i_szValue, i_szText, i_bSelected) {

   var objNewOption;
   var szText;
   
   if (i_objSelect) {
      objNewOption = document.createElement("option");
      objNewOption.value = i_szValue;
      objNewOption.title = unescapeHTML(i_szText);
      if (i_szText.length > G_nMaxSelectItems) {
         szText = unescapeHTML(i_szText.substring(0, G_nMaxSelectItems - 1) + G_strThreeDots);
      }
      else {
         szText = unescapeHTML(i_szText);  
      }
      switch (G_nBrowser) {
		   case SAFARI :
			   i_objSelect.appendChild(objNewOption);
			   objNewOption.appendChild(document.createTextNode(szText));
			   break;
		   default:
		      objNewOption.text = szText;
		      i_objSelect.options.add(objNewOption);	
      }
      if (i_bSelected) {
         objNewOption.selected = true;
      }
   }
}

// ----------------------------------------------------------------------------
// TBD Chart sizing will be redone soon.  Keep this here for now.
function GetChartSize() {
	var varWidth = 0;
   var varHeight = 0;
   var varOffsetHeight = 0;
   var varOffsetWidth = 0;
   var objContentPane = document.getElementById("DivContents");
   var objFooterArea = document.getElementById("FooterArea");
   var objHeaderArea = document.getElementById("HeaderArea");
   var objTopBarRow = document.getElementById("TopBarRow");
   
   // get the height
   if (objHeaderArea) varOffsetHeight += objHeaderArea.offsetHeight;
   if (objTopBarRow) varOffsetHeight += objTopBarRow.offsetHeight * 2;
   if (objFooterArea) varOffsetHeight += objFooterArea.offsetHeight;
   // get the width
   if (objContentPane) varOffsetWidth = GetOffSet(objContentPane, OFFSET_LEFT);
   
   //ensure some reasonable minimums
   varOffsetHeight = Math.max(varOffsetHeight, 140);
   varOffsetWidth = Math.max(varOffsetWidth, 100);

	if( typeof( window.innerWidth ) == 'number' ) {
      varHeight = window.innerHeight;
      varWidth = window.innerWidth;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
      varWidth = document.documentElement.clientWidth;
      varHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      varHeight = document.body.clientHeight;
      varWidth = document.body.clientWidth;
	}
   varWidth= varWidth - varOffsetWidth - 50;
   varHeight = varHeight - varOffsetHeight - 50;
   if (varWidth*3>= varHeight*4) varWidth = Math.round(varHeight*4/3);
   else varHeight = Math.round(varWidth*3/4);

   if (typeof(document.aspnetForm.ChartWidth) != "undefined") document.aspnetForm.ChartWidth.value=varWidth;
   if (typeof(document.aspnetForm.ChartHeight) != "undefined")document.aspnetForm.ChartHeight.value=varHeight;
}

function ExpandSearchList(i_DropDownCell, i_DropDownDiv, i_bAlignRight)
{
   var clSearchListDiv;
   
   var clDropDownCell = document.getElementById(i_DropDownCell);
   var clSearchListDiv = document.getElementById(i_DropDownDiv);
   var clHeaderArea = document.getElementById("HeaderArea");
   var clLeftArea = document.getElementById("LeftArea");
   var nHeaderAreaHeight = 0;
   var nLeftAreaWidth = 0;
  
   if (clHeaderArea != null) nHeaderAreaHeight = clHeaderArea.offsetHeight;
   if (clLeftArea != null) nLeftAreaWidth = clLeftArea.offsetWidth;

   var nContentTopBarHeight = 0;
   clContentTopBar = document.getElementById("ContentTopBar");
   if (clContentTopBar != null) {
      nContentTopBarHeight = clContentTopBar.offsetHeight;
   }
    
   if(clDropDownCell != null && clSearchListDiv != null) {
      if (G_CloseSearchList == 1) {
         CollapseSearchList();
      }
      else {
         if (G_CloseLanguageList == 1) {
            CollapseLanguageList();
         }
         if (G_CloseTutorialList == 1) {
            CollapseTutorialList();
         }
         if (G_CloseSummaryList == 1) {
            CollapseSummaryList();
         }
         OnCancelOptions();
         hideObjectElements();
         hideSelectionControls(); 

         clSearchListDiv.style.position = "absolute";
         clSearchListDiv.style.zIndex = 99;
         clSearchListDiv.style.visibility = "visible";
         clSearchListDiv.style.display = "block";
         var left = M_pfnCalculateX(clDropDownCell) - nLeftAreaWidth;
         var top = M_pfnCalculateY(clDropDownCell) - nHeaderAreaHeight + nContentTopBarHeight;
         if (i_bAlignRight) {
            left = left - clSearchListDiv.offsetWidth + clDropDownCell.offsetWidth;
         }
         clSearchListDiv.style.left = left;
         clSearchListDiv.style.top = top;
         G_CloseSearchList = 1;
      }
   }
}

//-------------------------------------------------------------------
function CollapseSearchList()
{
   var clSearchListDiv = document.getElementById("SearchDiv");
   if(clSearchListDiv != null) {
      clSearchListDiv.style.position = "static";
      clSearchListDiv.style.visibility = "hidden";
      clSearchListDiv.style.display = "none";
   }
   G_CloseSearchList = 0;
   showSelectionControls();
}

//-------------------------------------------------------------------
function AdjustDimsListScroll()
{
   var clDivDimsListContents = document.getElementById("DivDimListContents");
   var nscrollTop;

   if (clDivDimsListContents != null) {
      nScrollTop = document.aspnetForm.DivDimsListScroll.value;
      clDivDimsListContents.scrollTop = parseInt(nScrollTop);
   }
}

//-------------------------------------------------------------------
function NotImplementedYet()
{
   alert("Not implemented yet");
}

//-------------------------------------------------------------------
// Wrapping and Fixed Headers
var WRAPPING_ON = 1;
var WRAPPING_OFF = 2;

//-------------------------------------------------------------------
function InitializeWrappingandFixedHeadersOptions(i_strLabelforMaximumLength)
{
   // Hidden fields
   var clLabelWrappingOn = document.aspnetForm.LabelWrappingOn;
   var clFixedHeadersOnScrolling = document.aspnetForm.FixedHeadersOnScrolling;
   var clLabelLength = document.aspnetForm.LabelLength;
   if (clLabelWrappingOn != null && clFixedHeadersOnScrolling != null && clLabelLength != null) {
      var clWrappingOn = document.getElementById("WrappingOn");
      var clWrappingOff = document.getElementById("WrappingOff");
      var clFixedHeaders = document.getElementById("FixedHeaders");
      var clLabelForMaximumLength = document.getElementById("LabelForMaximumLength");
      var clMaximumLabelLength = document.getElementById("MaximumLabelLength");
      clLabelForMaximumLength.innerHTML = i_strLabelforMaximumLength;
      TableOptionsPopulateWrappingSelect(clMaximumLabelLength, 10, 5, clLabelLength.value);
      if (clLabelWrappingOn.value == "true") {
         clWrappingOn.checked = true;
         clWrappingOff.checked = false;
         clFixedHeaders.disabled = true;
         clMaximumLabelLength.disabled = true;
      }
      else {
         clWrappingOn.checked = false;
         clWrappingOff.checked = true;
         clFixedHeaders.disabled = false;
         if (clFixedHeadersOnScrolling.value == "true") {
            clFixedHeaders.checked = true;
         }
         else  {
            clFixedHeaders.checked = false;
         }
         clMaximumLabelLength.disabled = false;
      }
   }
}

//-------------------------------------------------------------------
function TableOptionsPopulateWrappingSelect(i_objSelect, i_nOptions, i_nStep, i_nDefaultValue) {
   var nIndex;
   var nValue;
   var nSelectedIndex = 0;

   if (i_objSelect) {
      SelectControlAddOption(i_objSelect, resUnlimited, resUnlimited);
      for (nIndex = 1; nIndex < i_nOptions; nIndex++) {
         nValue = (nIndex + 1) * i_nStep;
         if (nValue == i_nDefaultValue) {
            nSelectedIndex = nIndex;
         }
         SelectControlAddOption(i_objSelect, nValue, nValue.toString());
      }
      i_objSelect.selectedIndex = nSelectedIndex;
   }
}

//---------------------------------------------------------------
function SelectWrappingOption(i_nWrappingOption)
{
   var clFixedHeaders = document.getElementById("FixedHeaders");
   var clLabelForFixedHeaders = document.getElementById("LabelForFixedHeaders");
   var clLabelForMaximumLength = document.getElementById("LabelForMaximumLength");
   var clMaximumLabelLength = document.getElementById("MaximumLabelLength");
   var nSelectedIndex = 0;
   
   if (clFixedHeaders == null || clMaximumLabelLength == null) {
      return;
   }
   
   if (i_nWrappingOption == WRAPPING_ON) {
      clFixedHeaders.disabled = true;
      clFixedHeaders.checked = false;
      clLabelForFixedHeaders.className = "DisabledOptionItem";
      clMaximumLabelLength.disabled = true;
      clLabelForMaximumLength.className = "DisabledOptionItem";
   }
   else {
      var clFixedHeadersOnScrolling = document.aspnetForm.FixedHeadersOnScrolling;
      clFixedHeaders.disabled = false;
      clLabelForFixedHeaders.className = "OptionItem";
      if (clFixedHeadersOnScrolling.value == "true") {
         clFixedHeaders.checked = true;
      }
      else  {
         clFixedHeaders.checked = true;
      }
      clMaximumLabelLength.disabled = false;
      clLabelForMaximumLength.className = "OptionItem";
   }
}

function SubmitWrappingandFixedHeadersOptions()
{
   var clLabelWrappingOn = document.aspnetForm.LabelWrappingOn;
   var clFixedHeadersOnScrolling = document.aspnetForm.FixedHeadersOnScrolling;
   var clLabelLength = document.aspnetForm.LabelLength;
   var nIndex;
   var nMaxLabelLength;
   
   if (clLabelWrappingOn != null && clFixedHeadersOnScrolling != null && clLabelLength != null) {
      var clWrappingOn = document.getElementById("WrappingOn");
      var clFixedHeaders = document.getElementById("FixedHeaders");
      var clMaximumLabelLength = document.getElementById("MaximumLabelLength");
      if (clWrappingOn.checked) {
         clLabelWrappingOn.value = "true";
         clFixedHeadersOnScrolling.value = "false";
      }
      else  {
         clLabelWrappingOn.value = "false";
         if (clFixedHeaders.checked) {
            clFixedHeadersOnScrolling.value = "true";
         }
         else {
            clFixedHeadersOnScrolling.value = "false";
         }
         nIndex = clMaximumLabelLength.selectedIndex;
         if (nIndex > 0) {
            nMaxLabelLength = clMaximumLabelLength.options[nIndex].value;
         }
         else {
            nMaxLabelLength = 0;
         }
         clLabelLength.value = nMaxLabelLength;
      }
   }
}

function SubmitToUrl(i_szUrl)
{
	document.aspnetForm.action = i_szUrl;
	executeWait(document.aspnetForm);
}

/***** Menu Control Customization ****/
var GMenuNode;
var GMenuNodeExpanded = false;
var GMenuData;

function Menu_HoverStatic(item) {
    var node = Menu_HoverRoot(item);
    var data = Menu_GetData(item);
    if (!data) return;
    __disappearAfter = data.disappearAfter;
    
    /* Custom Code: keep track of current static node */
    GMenuNode = node;
    GMenuData = data;
    
    /* Custom Code: Menu expansion is disabled when hovering on static items */
    //Menu_Expand(node, data.horizontalOffset, data.verticalOffset); 
}

function ExpandMenuItem()
{
   if (GMenuNodeExpanded) {
      Menu_Collapse(GMenuNode);
      GMenuNodeExpanded = false;
   }
   else {
      hideObjectElements();
      Menu_Expand(GMenuNode, GMenuData.horizontalOffset, GMenuData.verticalOffset);
      GMenuNodeExpanded = true;
   }
}

function Menu_Unhover(item) {
   var node = (item.tagName.toLowerCase() == "td") ?
     item:
     item.cells[0];
   var nodeTable = getElementByTagName(node, "table");
   if (nodeTable.hoverClass) {
     Menu_RemoveClassName(nodeTable, nodeTable.hoverClass);
   }
   node = nodeTable.rows[0].cells[0].childNodes[0];
   if (node.hoverHyperLinkClass) {
     Menu_RemoveClassName(node, node.hoverHyperLinkClass);
   }
   Menu_Collapse(node);
   
   /* Custom code: keep track of current static item expansion state */
   if (node == GMenuNode) {
      GMenuNodeExpanded = false;
   }
}

function getElementByTagName(element, tagName) {
    var elements = getElementsByTagName(element, tagName);
    if (elements && elements.length > 0) {
        return elements[0];
    }
    else return null;
}

function getElementsByTagName(element, tagName) {
    if (element && tagName) {
        if (element.getElementsByTagName) {
            return element.getElementsByTagName(tagName);
        }
        if (element.all && element.all.tags) {
            return element.all.tags(tagName);
        }
    }
    return null;
}
/***** End of Menu Control Customization ****/