﻿// AnalyticGrid.js
//





// -----------------------------------

Type.registerNamespace('PPSMA');
// OlapGrid.js

// class def for PPSMA.OlapGrid.Context object.  PPSMA.OlapGrid.Context object
// is responsible for storing state information related to an Html OlapGrid
// as well as handling user interaction events. There is one instance of
// the PPSMA.OlapGrid.Context object per html grid.
PPSMA.OlapGrid = function PPSMA_OlapGrid(){}
PPSMA.OlapGrid.SubMenuType={DrillToDetail:0, AddActions:1};
PPSMA.OlapGrid.ReportLayout={TabularForm:0, CompactForm:1};
PPSMA.OlapGrid._CurrProxyId = "";

PPSMA.OlapGrid.Context = function PPSMA_OlapGrid_Context(gridCtxName, olapViewContext)
{
    this._gridCtxName = gridCtxName;
    this._lastCell = null;
    this._lastColor = "";
    this._olapViewContext = olapViewContext;
	this._subMenus = PPSMA.ContextMenu.CreateSubMenuCollection();
	this._anchorException = false;
	this._viewInfoBar = false;
	this._currentElement;
	this._currentMenu;
	this._reportLayout = PPSMA.OlapGrid.ReportLayout.CompactForm;
	this._showPropertiesCell = null;
	this._memberPropertyCount = null;
}
PPSMA.OlapGrid.Context.prototype =
{  
    getCellTypeId: function PPSMA_OlapGrid_Context$getCellTypeId(currCell)
    {
        var cellType = '';
        if (currCell != null)
        {
            var cellId = currCell.getAttribute("id");
            if (cellId != null && cellId.length >= 5)
            {
                // look at the first char to determine if it is row header, column header, or data cell
                var first_char = cellId.charAt(0);
                switch (first_char)
                {
                    case 'R':  // row header
                    case 'C':  // column header
                    case 'D':  // data cell                          
                    case 'P':  // pulpit cell  
                    case 'Z':  // member property column header                        
                    case 'Y':  // member property data value                        
                        cellType = first_char;
                        break;
                }                   
            }
        }
        return cellType;
    },
    getCellRowPosition: function PPSMA_OlapGrid_Context$getCellRowPosition(currCell)
    {
        var rowPos = null;
        if (currCell != null)
        {
            var cellId = currCell.getAttribute("id");
            if (cellId != null && cellId.length >= 5)
            {                
                // parse out the row/col position vals
                var rowMatches = cellId.match("R[0-9]+");
                if (rowMatches.length >= 1)
                {
                    var rowPosStr = rowMatches[0];
                    if (rowPosStr.length >= 1)
                    {
                        rowPos = parseInt(rowPosStr.substring(1, rowPosStr.length));
                    }
                }
            }
         }
         return rowPos;
    },
    getSortedCellColumnPosition: function PPSMA_OlapGrid_Context$getSortedCellColumnPosition(currCell)
    {
        var cellTypeId = this.getCellTypeId(currCell);
        var cIndex = this.getCellColumnPosition(currCell);
        if (cellTypeId == 'C')
        {
            cIndex = cIndex - (currCell.getAttribute('colspan') - 1);
        }
        return cIndex;
    },
    getCellColumnPosition: function PPSMA_OlapGrid_Context$getCellColumnPosition(currCell)
    {
        var colPos = null;
        if (currCell != null)
        {
            var cellId = currCell.getAttribute("id");
            if (cellId != null && cellId.length >= 5)
            {                
                // parse out the row/col position vals
                var colMatches = cellId.match("C[0-9]+");
                if (colMatches.length >= 1)
                {
                    var colPosStr = colMatches[0];
                    if (colPosStr.length >= 1)
                    {
                        colPos = parseInt(colPosStr.substring(1, colPosStr.length));
                    }
                }
            }
         }
         return colPos;
    },
    getTableColumnPosition: function PPSMA_OlapGrid_Context$getTableColumnPosition(currRow, cellIndex)
    {
        var tableIndex = 0;
        var spanCount = 0;
        var currCell = currRow.firstChild;
        while (currCell && spanCount < cellIndex)
        {
            spanCount += currCell.getAttribute('colspan');
            if (spanCount <= cellIndex)
            {
                tableIndex++;
            }
            currCell = currCell.nextSibling;
        }
        
        return tableIndex;        
    },
    getHeaderCellMember: function PPSMA_OlapGrid_Context$getHeaderCellMember(currCell)
    {
        var member = null;
        if (currCell != null)
        {
            var rowPos = this.getCellRowPosition(currCell);
            var colPos = this.getCellColumnPosition(currCell);
                
            if ((rowPos != null) && (colPos != null))
            {
                var cellTypeId = this.getCellTypeId(currCell);
                switch (cellTypeId)
                {
                    case 'R':
                        var rowMembers = this._olapViewContext.get_results().get_rowMembers();
                        member = rowMembers[rowPos][colPos];
                        break;
                    case 'C':
                        var colMembers = this._olapViewContext.get_results().get_columnMembers();
                        member = colMembers[colPos][rowPos];
                        break;
                    case 'D':                            
                    case 'P':                            
                        break;
                }                   
            }
        }
        return member;
    },
    getHeaderCellHierarchy: function PPSMA_OlapGrid_Context$getHeaderCellHierarchy(currCell)
    {
        var hier = null;
        if (currCell != null)
        {
            var rowPos = this.getCellRowPosition(currCell);
            var colPos = this.getCellColumnPosition(currCell);
                
            if ((rowPos != null) && (colPos != null))
            {
                var cellTypeId = this.getCellTypeId(currCell);
                switch (cellTypeId)
                {
                    case 'Z':
                    case 'Y':
                        var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
                        hier = rowHiers[rowPos];
                        break;
                    case 'R':
                        var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
                        hier = rowHiers[colPos];
                        break;
                    case 'C':
                        var colHiers = this._olapViewContext.get_results().get_columnHierarchies();
                        hier = colHiers[rowPos];
                        break;
                    case 'D':                            
                    case 'P':                            
                        break;
                }                   
            }
        }
        return hier;
    },
    
    getTotalMemberPropertyCount: function PPSMA_OlapGrid_Context$getTotalMemberPropertyCount()
    {
        if (this._memberPropertyCount == null)
        {
            var propertyCount = 0;
            var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
                
            if (rowHiers)
            {
				for (var i = 0; i < rowHiers.length; i++)
				{
					var rowHiersName = rowHiers[i].get_name();  
					var memberProperties = this.getQueryMemberProperties(rowHiersName);
					propertyCount += memberProperties.get_count();
				}
            }
        }
         return propertyCount;
    },
    
    get_canNavigate: function PPSMA_OlapGrid_Context$get_canNavigate()
    {
        var results = this._olapViewContext.get_results();
        return results.get_canNavigate();
    },
    handleSingleClick: function PPSMA_OlapGrid_Context$handleSingleClick(e)
    {
        var currCell = this.getCurrentElement(e);
        this.selectCell(currCell);    
    },
    selectLink: function PPSMA_OlapGrid_Context$selectLink(e)
    {
        var currEvent = this.getEvent(e);
        var rightClick = (currEvent.button == 2);
        if (currEvent.button == 1 || rightClick)
        {
            this.selectLinkCell(currEvent);
            var currCell = this.getCurrentElement(currEvent);
            this._anchorException = (currCell.tagName == "A" && rightClick);
        }
    },
    selectLinkCell: function PPSMA_OlapGrid_Context$selectLinkCell(e)
    {
        var currCell = this.getCurrentElement(e);
        if (currCell)
        {
            this.selectCell(currCell.parentNode);
            // check to see if you are entering pulpit cell
            if (currCell.innerHTML != "" && currCell.firstChild.tagName == "A")
            {
                currCell.firstChild.focus();
            }
        }
    },
    handleContextMenu: function PPSMA_OlapGrid_Context$handleContextMenu(e)
    {
        this.propsCancel();
        this._subMenus.Clear();        
        var currEvent = this.getEvent(e);
        var currElem = this.getCurrentElement(e);
        var currCell = this.getCellFromElement(currElem);
        this.selectCell(currCell);
        var parentDiv = document.getElementById(this._olapViewContext.get_innerTargetId());
        var yOffset = e.clientY + document.body.scrollTop - this.getAbsoluteTop(currElem);
        var xOffset = e.clientX + document.body.scrollLeft - this.getAbsoluteLeft(currElem);
        if (parentDiv)
        {
            xOffset += parentDiv.scrollLeft;
            yOffset += parentDiv.scrollTop;
        }
        PPSMA.ContextMenu.Create(currEvent, this, xOffset, yOffset, this._anchorException);
    },
    HideViewInfoBarCtxMenu: function PPSMA_OlapGrid_Context$HideViewInfoBarCtxMenu(e)
    {
        if (e.button == 2)
        {
            this._viewInfoBar = true;
            this._subMenus.Clear();        
            var currEvent = this.getEvent(e);
            this._currentElement = this.getViewInfoDiv(currEvent.srcElement);
            var xOffset = currEvent.clientX - this.getAbsoluteLeft(currEvent.srcElement);
	        var yOffset = currEvent.clientY - this.getAbsoluteTop(currEvent.srcElement);
            PPSMA.ContextMenu.Create(currEvent, this, xOffset, yOffset);
        }
    },
    getViewInfoDiv: function PPSMA_OlapGrid_Context$getViewInfoDiv(elem)
    {
        while (elem)
        {
            if (elem.tagName == 'DIV' && elem.id == "_viewInfoId") return elem; 
            elem = elem.parentElement;
        }
    },
    getAbsoluteTop: function PPSMA_OlapGrid_Context$getAbsoluteTop(o)
    {	
	    oTop = o.offsetTop;
	    while (o.offsetParent != null)
	    {
		    oParent = o.offsetParent;
		    oTop += oParent.offsetTop;
		    o = oParent;
	    }
	    return oTop;
    },
    getAbsoluteLeft: function PPSMA_OlapGrid_Context$getAbsoluteLeft(o)
    {
	    oLeft = o.offsetLeft;
	    while (o.offsetParent != null)
	    {
		    oParent = o.offsetParent;
		    oLeft += oParent.offsetLeft;
		    o = oParent;
	    }
	    return oLeft;
    },
    AddPrimaryMenuItems: function PPSMA_OlapGrid_Context$AddPrimaryMenuItems(m)
    {
        var containsItemsFlag = false;		
        var canNavigate = this.get_canNavigate();
        var member = this.getHeaderCellMember(this._lastCell);
        var hierarchy = this.getHeaderCellHierarchy(this._lastCell);
        var helper = new PPSMA.ContextMenu.OptionHelper(member,hierarchy,canNavigate,this._olapViewContext);
        if (this._viewInfoBar)
        {
            helper.ShowHideInfo(m, this._gridCtxName +".handleShowHideInfoByDiv();");
            this._viewInfoBar = false;
            return (helper.get_optionsAdded() > 0);
        }
        this._currentMenu = m;
        var cellId = this.getCellTypeId(this._lastCell);
        if ((cellId == 'R') || (cellId == 'C') || (cellId == 'P'))
        {
            if ((cellId == 'R') || (cellId == 'C'))
            {        
                if (member != null)
                {
                    helper.DrillDown(m, this._gridCtxName +".handleDrillDownMenuClick();",false);
                    
                    var drillDownTo = helper.DrillDownTo(m,
                        this._gridCtxName+".fetchCallback("+this._subMenus.length+")", 
                        this._gridCtxName+".populateCallback("+this._subMenus.length+")", 
                        this._gridCtxName+".hoverOffCallback("+this._subMenus.length+")",
                        false);
                    if (drillDownTo)
                    {
                        var ddtSubMenu = new PPSMA.SubMenu(drillDownTo,PPSMA.OlapGrid.SubMenuType.DrillToDetail);
                        this._subMenus.Add(ddtSubMenu);
                    }
                    
                    helper.DrillUp(m, this._gridCtxName +".handleDrillUpMenuClick();", false);
                    
                    if ((this._reportLayout == PPSMA.OlapGrid.ReportLayout.CompactForm) || (cellId == 'C'))
                    {
                        helper.ExpandCollapse(m, 
                            this._gridCtxName +".handleExpandMenuClick();",
                            this._gridCtxName +".handleCollapseMenuClick();", 
                            false);
                    }

                    helper.ShowOnly(m, this._gridCtxName +".handleShowOnlyMenuClick();", false);
                              
                    helper.Remove(m, this._gridCtxName +".handleRemoveMenuClick();", false);
                    
                }
            }
            if (canNavigate) 
            {
                if ((cellId == 'R') && (member != null))
                {
                    this._olapViewContext.set_menuMetaData(null);
                    PPSMA.ContextMenu.AddMenuSeparator(m);
                    helper.ShowProperties(m, this._gridCtxName +".handleShowPropertiesMenuClick();", false, true);
                    PPSMA.ContextMenu.AddMenuSeparator(m);
                }
                if (cellId == 'P') 
                {
                    this._olapViewContext.set_menuMetaData(null);
                    helper.ShowProperties(m, this._gridCtxName +".handleShowPropertiesMenuClick();", false, true);
                    PPSMA.ContextMenu.AddMenuSeparator(m);
                }
                
                PPSMA.ContextMenu.AddMenuSeparator(m);
                if (cellId == 'C') 
                {
                    this.AddSortSubMenu();
                }
                this.AddFilterEmptySubMenu();
                helper.Pivot(m, this._gridCtxName +".handlePivotMenuClick();", false);
            }
        }
        else if (cellId == 'D')
        {
            var showDetailsEnabled = true;
            var hasAggregatedBGHiers = helper.HasAggregatedBackGroundHierarchies();
           
            this._olapViewContext.set_menuMetaData(null);
            if ((this._lastCell.innerHTML == "") || (hasAggregatedBGHiers == true))
                showDetailsEnabled = false;
                    
            helper.ShowDetails(m, this._gridCtxName +".handleShowDetailsMenuClick('');", false, showDetailsEnabled);
            
            var addActionsEnabled = true;
            var aggregateValue = this._lastCell.getAttribute("rt");
            if (((aggregateValue != null) && (aggregateValue == "aggr")) || (hasAggregatedBGHiers == true)) addActionsEnabled = false;
            
            var addActions = helper.AdditionalActions(m,
                this._gridCtxName+".fetchCallback("+this._subMenus.length+")", 
                this._gridCtxName+".populateCallback("+this._subMenus.length+")", 
                this._gridCtxName+".hoverOffCallback("+this._subMenus.length+")",
                false,
                addActionsEnabled);
            if (addActions)
            {
                var aaSubMenu = new PPSMA.SubMenu(addActions,PPSMA.OlapGrid.SubMenuType.AddActions);
	            this._subMenus.Add(aaSubMenu);
	        }
            if (canNavigate)
            { 
                PPSMA.ContextMenu.AddMenuSeparator(m);
                this.AddSortSubMenu();
                this.AddFilterEmptySubMenu();
                helper.Pivot(m, this._gridCtxName +".handlePivotMenuClick();", false);
            }
        }
        else if (((cellId == 'Z') || (cellId == 'Y')) && (canNavigate))
        {
            this._olapViewContext.set_menuMetaData(null);
            helper.ShowProperties(m, this._gridCtxName +".handleShowPropertiesMenuClick();", false, true);
            this.AddHidePropertiesSubMenu(m, helper);
            PPSMA.ContextMenu.AddMenuSeparator(m);
            this.AddFilterEmptySubMenu();
            helper.Pivot(m, this._gridCtxName +".handlePivotMenuClick();", false);
        }
        if (canNavigate) 
        {
            this.AddFormattingSubMenus(m,helper);
        }
        helper.ShowHideInfo(m, this._gridCtxName +".handleShowHideInfoMenuClick();");
        
        return (helper.get_optionsAdded() > 0);
    },
	AddFilterEmptySubMenu: function PPSMA_OlapGrid_Context$AddFilterEmptySubMenu()
	{
	    if (this._olapViewContext.get_results().get_filterEmptyAxis()==-1) return;
	    var emptyRow = (this._olapViewContext.get_results().get_filterEmptyAxis()==2) || 
	                    (this._olapViewContext.get_results().get_filterEmptyAxis()==3);
	    var emptyCol = (this._olapViewContext.get_results().get_filterEmptyAxis()==1) || 
	                    (this._olapViewContext.get_results().get_filterEmptyAxis()==3);
	    var filterEmptyBy = PPSMA.ContextMenu.CreateSubMenu(this._currentMenu, 
	        PPSMA.SR.OlapContextMenu_Filter, g_resFolder + "ImageFilter.gif");	    
	    PPSMA.ContextMenu.AddToggleMenuOption(filterEmptyBy, PPSMA.SR.OlapContextMenu_EmptyRows, 
	        this._gridCtxName+".handleFilterEmptyRowMenuClick();", 
	        g_resFolder + "FilterEmpRow.gif","", emptyRow);
	    PPSMA.ContextMenu.AddToggleMenuOption(filterEmptyBy, PPSMA.SR.OlapContextMenu_EmptyCols, 
	        this._gridCtxName+".handleFilterEmptyColMenuClick();", 
	        g_resFolder + "FilterEmpCol.gif","", emptyCol);
	},
	AddHidePropertiesSubMenu: function PPSMA_OlapGrid_Context$AddHidePropertiesSubMenu(m, helper)
	{
        var rIndex = this.getCellRowPosition(this._lastCell);
        var cIndex = this.getCellColumnPosition(this._lastCell);
            
        var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
        var selectedHier = rowHiers[rIndex];
        var memberProperties = selectedHier.get_memberProperties();
        var memberPropertyCaptions = memberProperties.get_captions();
        var memberPropertyNames = memberProperties.get_names();
        var hideProp = PPSMA.SR.OlapContextMenu_HideProperty;
        var propertyCaption = memberPropertyCaptions[cIndex];
        if (propertyCaption.length > 20)
        {
            propertyCaption = propertyCaption.substr(0, 20)+PPSMA.SR.OlapPropertiesDialog_LongStringPadding;
        }
        var menuCaption = hideProp.replace("{caption}", propertyCaption);
        helper.HideProperty(m, menuCaption, 
            this._gridCtxName +".handleHidePropertyMenuClick(\"" + selectedHier.get_name() + "\", \"" + memberPropertyNames[cIndex] + "\");", 
            false, true);
	},
	AddSortSubMenu: function PPSMA_OlapGrid_Context$AddSortSubMenu()
	{
	    var enableRowSort = (this.getSortedCellColumnPosition(this._lastCell) == this._olapViewContext.get_results().get_sortColIndex());
	    var sortBy = PPSMA.ContextMenu.CreateSubMenu(this._currentMenu, PPSMA.SR.OlapContextMenu_Sort,
	        g_resFolder + "Sort.gif");
	    PPSMA.ContextMenu.AddMenuOption(sortBy, PPSMA.SR.OlapContextMenu_LargeToSmall,
	        this._gridCtxName+".handleSortMenuClick('desc');", g_resFolder + "SortAscNum.gif","",
	        enableRowSort && (this._olapViewContext.get_results().get_sortTypeRow() == 'desc'));
	    PPSMA.ContextMenu.AddMenuOption(sortBy, PPSMA.SR.OlapContextMenu_SmallToLarge, 
	        this._gridCtxName+".handleSortMenuClick('asc');",g_resFolder + "SortDescNum.gif","",
	        enableRowSort && (this._olapViewContext.get_results().get_sortTypeRow() == 'asc'));
	    PPSMA.ContextMenu.AddMenuOption(sortBy,PPSMA.SR.OlapContextMenu_NoSort,
	        this._gridCtxName+".handleSortMenuClick('nosort');");
	},
	AddFormattingSubMenus: function PPSMA_OlapGrid_Context$AddFormattingSubMenus(m,helper)
	{
	    PPSMA.ContextMenu.AddMenuSeparator(m);
        helper.ReportTypeSubMenu(m, this._gridCtxName, PPSMA.ContextMenu.OlapReportType.Grid);
        this.AddFormatReportSubMenu(m, helper);
	},
	AddFormatReportSubMenu: function PPSMA_OlapGrid_Context$AddFormatReportSubMenu(m,helper)
	{
	    var formatSubMenu = helper.FormatReportSubMenu(m);
        PPSMA.ContextMenu.AddMenuOption(formatSubMenu, PPSMA.SR.OlapContextMenu_CompactLayout,
            this._gridCtxName+".handleFormatReportMenuClick(1);",
            g_resFolder + "LayoutCompact.gif", null, 
            this._reportLayout == PPSMA.OlapGrid.ReportLayout.CompactForm);
        PPSMA.ContextMenu.AddMenuOption(formatSubMenu, PPSMA.SR.OlapContextMenu_TabularLayout,
            this._gridCtxName+".handleFormatReportMenuClick(0);",
            g_resFolder + "LayoutTabular.gif", null, 
            this._reportLayout == PPSMA.OlapGrid.ReportLayout.TabularForm);
	},
	fetchCallback: function PPSMA_OlapGrid_Context$fetchCallback(smIndex)
	{
        var smProps = this._subMenus[smIndex];
		if (smProps)
	    {
		    smProps.HoverOn = true;
		    switch (smProps.Type)
		    {
		        case PPSMA.OlapGrid.SubMenuType.AddActions:
		            if (!this._olapViewContext.get_menuMetaData())
                    {
                        var rIndex = this.getCellRowPosition(this._lastCell);
                        var cIndex = this.getCellColumnPosition(this._lastCell);
                        var detailsHelper = new PPSMA.ContextMenu.DetailsHelper(this._olapViewContext,
                            this._gridCtxName,rIndex,cIndex);
                        var tupleXml = detailsHelper.getCellTupleXml();
		                this._olapViewContext.getCellLevelActions(tupleXml);
                    }
                    break;
		        case PPSMA.OlapGrid.SubMenuType.DrillToDetail:
		            if (!this._olapViewContext.get_cubeMetadata())
                    {
                        this._olapViewContext.loadCubeMetadata(
                            "PPSMA.OlapViewContext.globalIds['" + 
                            this._olapViewContext.get_ctrlProxyId() + 
                            "'].get_reportContext()");
                    }
                    break;
                default:
                    smProps.HoverOn = false;
                    break;
		    }
		}
	},
	populateCallback: function PPSMA_OlapGrid_Context$populateCallback(smIndex)
	{
        var smProps = this._subMenus[smIndex];
        if (smProps && smProps.HoverOn)
        {
            var bPopulated = smProps.IsPopulated;
            if (!bPopulated)
            {		
                var sm = smProps.Menu;
                PPSMA.ContextMenu.RemoveAllButFirst(sm);
                switch (smProps.Type)
                {
                    case PPSMA.OlapGrid.SubMenuType.AddActions:
                        if (this._olapViewContext.get_menuMetaData())
                        {
                            this.populateAdditionActionsSumMenuItems(sm);
                            smProps.IsPopulated = true;
                        }
                        break;
                    case PPSMA.OlapGrid.SubMenuType.DrillToDetail:
                        if (this._olapViewContext.get_cubeMetadata())
                        {
                            this.populateDrillDownToSubMenuItems(sm);
                            smProps.IsPopulated = true;
                        }
                        break;
                    default:
                        break;
                }
            }
            //if submenu is already populated, call refresh to kill polling interval and pass
            //a false to prevent force refresh...
            //else if just populated, call refresh to kill polling and a true to force refresh
            if (bPopulated)
                PPSMA.ContextMenu.RefreshMenu(sm,false);
            else if (smProps.IsPopulated)//else if submenu has just been populated, 
                PPSMA.ContextMenu.RefreshMenu(sm,true);
		}
	},
	hoverOffCallback: function PPSMA_OlapGrid_Context$hoverOffCallback(smIndex)
	{
	    var smProps = this._subMenus[smIndex];
	    if (smProps) smProps.HoverOn = false;
	},
	set_cubeMetadata: function PPSMA_OlapGrid_Context$set_cubeMetadata(dims)
	{
	    // do nothing - context menu will poll to determine if metadata has been returned
	},	
    handleDrillDownMenuClick: function PPSMA_OlapGrid_Context$handleDrillDownMenuClick()
    {
        this.drillDownCell(this._lastCell);
    },
    handleDrillDownToMenuClick: function PPSMA_OlapGrid_Context$handleDrillDownMenuClick(drillToHierarchyName, drillToMemberName, drillToLevelName)
    {
        this.drillDownToCell(this._lastCell, unescape(drillToHierarchyName), unescape(drillToMemberName), unescape(drillToLevelName));
    },
    handleDrillUpMenuClick: function PPSMA_OlapGrid_Context$handleDrillUpMenuClick()
    {
        this.drillUpCell(this._lastCell);
    },
    handleExpandMenuClick: function PPSMA_OlapGrid_Context$handleExpandMenuClick()
    {
        this.expandCell(this._lastCell);
    },
    handleCollapseMenuClick: function PPSMA_OlapGrid_Context$handleCollapseMenuClick()
    {
        this.collapseCell(this._lastCell);
    },
    handleShowOnlyMenuClick: function PPSMA_OlapGrid_Context$handleShowOnlyMenuClick()
    {
        this.showOnlyCell(this._lastCell);
    },
    handleRemoveMenuClick: function PPSMA_OlapGrid_Context$handleRemoveMenuClick()
    {
        this.removeCell(this._lastCell);
    },
    handleShowPropertiesMenuClick: function PPSMA_OlapGrid_Context$handleShowPropertiesMenuClick()
    {
        this.showProperties(this._lastCell);
    },
    handlePivotMenuClick: function PPSMA_OlapGrid_Context$handlePivotMenuClick()
    {
        this.pivot(this._lastCell);
    },    
    handleFilterEmptyRowMenuClick: function PPSMA_OlapGrid_Context$handleFilterEmptyRowMenuClick()
    {
        this.filterEmptyRow(this._lastCell);
    },    
    handleSortMenuClickAsc: function PPSMA_OlapGrid_Context$handleSortMenuClickAsc(colIndex,rowIndex)
    {
        this.sortByDirectionArrow('asc',colIndex,rowIndex);
    },    
    handleSortMenuClickDesc: function PPSMA_OlapGrid_Context$handleSortMenuClickDesc(colIndex,rowIndex)
    {
        this.sortByDirectionArrow('desc',colIndex,rowIndex);
    },    
    handleSortMenuClick: function PPSMA_OlapGrid_Context$handleSortMenuClick(sortType)
    {
        this.sort(this._lastCell,sortType);
    },    
    handleFilterEmptyColMenuClick: function PPSMA_OlapGrid_Context$handleFilterEmptyColMenuClick()
    {
        this.filterEmptyCol(this._lastCell);
    },    
    handleFormatReportMenuClick: function PPSMA_OlapGrid_Context$handleFormatReportMenuClick(reportLayout)
    {
        this.changeReportLayout(reportLayout);
    },
    handleShowHideInfoByDiv: function PPSMA_OlapGrid_Context$handleShowHideInfoByDiv()
    {
        this._olapViewContext.toggleViewInfoBar(this._currentElement.firstChild);
    },
    handleShowHideInfoMenuClick: function PPSMA_OlapGrid_Context$handleShowHideInfoMenuClick()
    {
        var table = null;
        var p = this._lastCell.parentElement;
        while (p != null)
        {
            if (p.tagName == "TABLE")
            {                
                table = p;
                break;
            }
            p = p.parentElement;
        }
        
        var viewinfodiv = null;
        if (table != null)
        {
            var pardiv = table.parentElement.parentElement;
            p = pardiv.firstChild;
            while (p != null)
            {
                if ((p.tagName == "DIV") && (p.id == "_viewInfoId"))
                {                
                    viewinfodiv = p;
                    break;
                }
                p = p.nextSibling;
            }
        }
        
        if (viewinfodiv != null)
        {
            this._olapViewContext.toggleViewInfoBar(viewinfodiv.firstChild);
        }
    },
    handleShowUrlMenuClick: function PPSMA_OlapGrid_Context$handleShowUrlMenuClick(urlContent)
    {
        var wX = parseInt((screen.availWidth - 800) / 2);
        var wY = parseInt((screen.availHeight - 400) / 2);
        var winRef = window.open(urlContent, "URLWindow", "left="+ wX +",top=" + wY + ",height=400" + ",width=800" + ",menubar,toolbar,titlebar,status,location,resizable,scrollbars");
        if (winRef != null) winRef.focus();
    },
    handleShowDetailsMenuClick: function PPSMA_OlapGrid_Context$handleShowDetailsMenuClick(resultTableIndex)
    {
        this.showDetails(this._lastCell, resultTableIndex);
    },
    handleDoubleClick: function PPSMA_OlapGrid_Context$handleDoubleClick(e)
    {
        // Deselects the selected text ondblclick
        if(document.all) //IE
        {
            document.onselectstart = function() { return false; }; 
	        //Removes the first instance of selected test, because 
	        //the object above works after first double click.
	        document.selection.empty();
        }
        var currCell = this.getCurrentElement(e);
        this.drillDownCell(currCell);
    },
    handleExpandClick: function PPSMA_OlapGrid_Context$handleExpandClick(e)
    {
        var img = this.getCurrentElement(e);
        if (img != null)
        {
            var currCell = img.parentElement;
            this.expandCell(currCell);
        }
    },
    handleCollapseClick: function PPSMA_OlapGrid_Context$handleCollapseClick(e)
    {
        var img = this.getCurrentElement(e);
        if (img != null)
        {
            var currCell = img.parentElement;
            this.collapseCell(currCell);
        }
    },
    handleKeyEvent: function PPSMA_OlapGrid_Context$handleKeyEvent(e)
    {
        var bubbleEvent = true;
        
        var currEvent = this.getEvent(e);
        var currCell = this.getCurrentElement(e);
		
		if (currCell.tagName == "A")
        {
           currCell = currCell.parentNode;
        }
        
        var cIndex = currCell.cellIndex;  //Get cell index (location across columns)
        var rIndex = currCell.parentNode.rowIndex;  //Get row index
        var cId = currCell.id;
        
        var keyPressed = currEvent.keyCode; //Get selected key code
        
        // Noncharacter key codes
        var keyLeft = 37;
        var keyRight = 39;
        var keyUp = 38;
        var keyDown = 40;
        var keySpace = 32;
        
        // count - single hier; add 1 for each additional hierarchy
        // accommodates for cell selection with flatten row headers
        var singleHierCount = 1;
        var rowHierCount = 0;
        var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
        rowHierCount = rowHiers.length;
        
        var pulpitHierCount = null;
        
        //check ReportLayout type
        if (this._reportLayout == PPSMA.OlapGrid.ReportLayout.CompactForm)
        {
            if (rowHierCount == 0)
            {
                pulpitHierCount = 1;
            }
            else
            {
                pulpitHierCount = 2;
            }
        }
        if (this._reportLayout == PPSMA.OlapGrid.ReportLayout.TabularForm)
        {
            pulpitHierCount = singleHierCount + rowHierCount;
        }
        
        // Get properties count
        var memberPropertyCount = this.getTotalMemberPropertyCount();
        var overallCount = pulpitHierCount + memberPropertyCount;
        
        switch (keyPressed)
        {
            case keyLeft:  // 37
            if (currCell.previousSibling != null)
            {
                currCell = currCell.previousSibling;
                currCell.focus();
                this.selectCell(currCell);
				// check to see if you are entering pulpit cell
                if (currCell.innerHTML != "")
				{
					if (currCell.firstChild.tagName == "A")
					{
						currCell = currCell.firstChild;
						currCell.focus();
					}
				}
			}
			bubbleEvent = false;
            break;
            
            case keyUp:  // 38
            if (currCell.parentNode.previousSibling != null)
            {
                // Get the column index from the ID
                var colPosition = this.getCellColumnPosition(currCell);
                var cellId = this.getCellTypeId(this._lastCell);
                                                
                if ((cellId == 'C') || (cellId == 'D'))
                {
                    if (colPosition > 0 && cIndex > 0)
                    {
                        colPosition = colPosition - currCell.getAttribute('colspan') + overallCount;
                        colPosition = this.getTableColumnPosition(currCell.parentNode.previousSibling, colPosition);
                    }
                    else
                    {
                        colPosition = cIndex;
                    }
                }    
                else
                {
                    colPosition = cIndex;
                }
                currCell = currCell.parentNode.previousSibling.childNodes[colPosition];
                currCell.focus();
                this.selectCell(currCell);
				// check to see if you are entering pulpit cell
                if (currCell.innerHTML != "")
				{
					if (currCell.firstChild.tagName == "A")
					{
						currCell = currCell.firstChild;
						currCell.focus();
					}
				}			
            }
            bubbleEvent = false;
            break;
            
            case keyRight:  // 39
            if (currCell.nextSibling != null)
            {
                currCell = currCell.nextSibling;
                currCell.focus();
                this.selectCell(currCell);
            }
            bubbleEvent = false;
            break;
            
            case keyDown:  // 40
            if (currCell.parentNode.nextSibling != null)
            {
                // Get the column index from the ID
                var colPosition = this.getCellColumnPosition(currCell);
                var cellId = this.getCellTypeId(this._lastCell);
                        
                if ((cellId == 'C') || (cellId == 'D'))
                {
                    if (colPosition > 0 && cIndex > 0)
                    {
                        colPosition = colPosition - currCell.getAttribute('colspan') + overallCount;
                        colPosition = this.getTableColumnPosition(currCell.parentNode.nextSibling, colPosition);
                    }
                    else
                    {
                        colPosition = cIndex;
                    }
                }    
                else
                {
                    colPosition = cIndex;
                }    
                currCell = currCell.parentNode.nextSibling.childNodes[colPosition];
                currCell.focus();
                this.selectCell(currCell); 
            }
            bubbleEvent = false;
            break;
            
            case keySpace:  // 32
            var currMbr = this.getHeaderCellMember(this._lastCell);
            if (currMbr)
            {
            	if (currMbr.get_drilledDown())
            	{
            		this.collapseCell(this._lastCell);
            	}
            	else
            	{
            		this.expandCell(this._lastCell);
            	}
            }
           	break;
        }
        return bubbleEvent;
    },
    
    //Uses IE's default tab functionality to move betweet links which
    //are defined in the pulpit cell.
    handleTabEvent: function PPSMA_OlapGrid_Context$handleTabEvent(e)
    {
        var pulpitAnchor = this.getCurrentElement(e);
                    
        currCell = pulpitAnchor.parentNode;
        this.selectCell(currCell);
	},
        
    selectCell: function PPSMA_OlapGrid_Context$selectCell(currCell)
    {
    	// restore previously selected cell
    	if (this._lastCell)
    	{
    	    this._lastCell.style.backgroundColor = this._lastColor;
		}

		// select new cell
        this._lastColor = currCell.style.backgroundColor;
        currCell.style.backgroundColor = "#FEE197";
        this._lastCell = currCell;
    },
    
    handleDeselectCell: function PPSMA_OlapGrid_Context$handleDeselectCell(e)
	{
		var currCell = this.getCurrentElement(e);
		var currEvent = this.getEvent(e);
			
		if (currCell.tagName == "A")
		{
			currCell = currCell.parentNode;
		}
		currCell.style.backgroundColor = this._lastColor;
	},    
    
    showDetails: function(currCell, resultTableIndex)
    {
        var rIndex = this.getCellRowPosition(currCell);
        var cIndex = this.getCellColumnPosition(currCell);
        var detailsHelper = new PPSMA.ContextMenu.DetailsHelper(this._olapViewContext,
            this._gridCtxName,rIndex,cIndex,resultTableIndex);
        detailsHelper.showDetails();
    },    
    populateAdditionActionsSumMenuItems: function PPSMA_OlapGrid_Context$populateAdditionActionsSumMenuItems(sm)
	{
        var xdoc = new ActiveXObject("Microsoft.XMLDOM");
        var xml = "";
        xml = this._olapViewContext.get_menuMetaData();
        xdoc.async = false;
        xdoc.loadXML(xml);

        var urlActions = xdoc.getElementsByTagName("UrlAction");
        if ((urlActions != null) && (urlActions.length > 0))
        {
           for (var i = 0; i < urlActions.length; i++)
            {
                PPSMA.ContextMenu.AddMenuOption(sm, urlActions[i].getAttribute("caption"), this._gridCtxName +".handleShowUrlMenuClick('" + urlActions[i].getAttribute("content") + "');", "");    
            } 
        }
        
        var ddActions = xdoc.getElementsByTagName("DDAction");
        if ((ddActions != null) && (ddActions.length > 0))
        {
           for (var i = 0; i < ddActions.length; i++)
            {
                PPSMA.ContextMenu.AddMenuOption(sm, ddActions[i].getAttribute("caption"), this._gridCtxName +".handleShowDetailsMenuClick('" + ddActions[i].getAttribute("resulttableindex") + "');", "");    
            } 
        }
        else
        {
            var elem = xdoc.getElementsByTagName("AdditionalActions");
            if (elem != null) PPSMA.ContextMenu.AddDisabledMenuOption(sm, elem[0].getAttribute("message"), "", "");    
        }       
	},
    populateDrillDownToSubMenuItems: function PPSMA_OlapGrid_Context$populateDrillDownToSubMenuItems(sm)
	{
		var drillFromAxisId = this.getCellTypeId(this._lastCell);
        var drillFromMember = this.getHeaderCellMember(this._lastCell);
        var drillFromHierarchy = this.getHeaderCellHierarchy(this._lastCell);
        if ((drillFromMember != null) && (drillFromHierarchy != null))
        {
	        var helper = new PPSMA.ContextMenu.DrillDownToHelper(drillFromMember, drillFromHierarchy, drillFromAxisId, this._olapViewContext);
	        helper.populateSubMenuItems(sm, drillFromMember, drillFromHierarchy, this._gridCtxName+".handleDrillDownToMenuClick");
	    }
	},
    drillDownCell: function PPSMA_OlapGrid_Context$drillDownCell(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
            var member = this.getHeaderCellMember(currCell);
            var hierarchy = this.getHeaderCellHierarchy(currCell);
            if ((member != null) && (hierarchy != null))
            {
                if (member.get_hasChildren())
                {
                    this._olapViewContext.drillDown(hierarchy.get_name(), member.get_name());
                }
            }
        }
    },
    drillDownToCell: function PPSMA_OlapGrid_Context$drillDownCell(currCell, drillToHierarchyName, drillToMemberName, drillToLevelName)
    {
 	    if (this.get_canNavigate())
 	    {
            var member = this.getHeaderCellMember(currCell);
            var memberHierarchy = this.getHeaderCellHierarchy(currCell);
            if ((member != null) && (memberHierarchy != null))
            {
                this._olapViewContext.crossDrill(memberHierarchy.get_name(), member.get_name(), drillToHierarchyName, drillToMemberName, drillToLevelName);
            }
        }
    },
    drillUpCell: function PPSMA_OlapGrid_Context$drillUpCell(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
            var member = this.getHeaderCellMember(currCell);
            var hierarchy = this.getHeaderCellHierarchy(currCell);
            if ((member != null) && (hierarchy != null))
            {
                if (member.get_hasParent())
                {
                    this._olapViewContext.drillUp(hierarchy.get_name(), member.get_name());
                }
            }
        }
    },
    expandCell: function PPSMA_OlapGrid_Context$expandCell(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
            var member = this.getHeaderCellMember(currCell);
            var hierarchy = this.getHeaderCellHierarchy(currCell);
            if ((member != null) && (hierarchy != null))
            {
                if (member.get_hasChildren())
                {
                    this._olapViewContext.expand(hierarchy.get_name(), member.get_name());
                }
            }
        }
    },
    collapseCell: function PPSMA_OlapGrid_Context$collapseCell(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
            var member = this.getHeaderCellMember(currCell);
            var hierarchy = this.getHeaderCellHierarchy(currCell);
            if ((member != null) && (hierarchy != null))
            {
                if (member.get_drilledDown())
                {
                    this._olapViewContext.collapse(hierarchy.get_name(), member.get_name());
                }
            }
        }
    },
    showOnlyCell: function PPSMA_OlapGrid_Context$showOnlyCell(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
            var member = this.getHeaderCellMember(currCell);
            var hierarchy = this.getHeaderCellHierarchy(currCell);
            if ((member != null) && (hierarchy != null))
            {
                if (!hierarchy.get_isSingleton())
                {
                    this._olapViewContext.showOnly(hierarchy.get_name(), member.get_name());
                }
            }
        }
    },
    removeCell: function PPSMA_OlapGrid_Context$removeCell(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
            var member = this.getHeaderCellMember(currCell);
            var hierarchy = this.getHeaderCellHierarchy(currCell);
            if ((member != null) && (hierarchy != null))
            {
                if (!hierarchy.get_isSingleton())
                {
                    this._olapViewContext.hide(hierarchy.get_name(), member.get_name());
                }
            }
        }
    },
    showPropertiesGetSelectedHierarchy: function PPSMA_OlapGrid_Context$showPropertiesGetSelectedHierarchy(currCell)
    {
        var cellId = this.getCellTypeId(currCell);
        var selectedHierarchy = null;
        if ((cellId == "R") || (cellId == "Z") || (cellId == "Y"))
        {    
            selectedHierarchy = this.getHeaderCellHierarchy(currCell);
        }
        else if (cellId == "P")
        {
            var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
            var colPos = this.getCellColumnPosition(currCell);
            selectedHierarchy = rowHiers[colPos];
        }
        // else ERROR...
        return selectedHierarchy;
    },
    showProperties: function PPSMA_OlapGrid_Context$showProperties(currCell)
    {
        this._showPropertiesCell = currCell;                     
        var selectedHierarchy = this.showPropertiesGetSelectedHierarchy(this._showPropertiesCell); 
        
        if (selectedHierarchy != null)
        {
            if(!this._olapViewContext.getDimensionPropertiesList(selectedHierarchy.get_name()))
            {
                var selectedMemberXml = this.getSelectedMemberXml();
		        this._olapViewContext.getDimensionProperties(selectedMemberXml);
                window.setTimeout(this._gridCtxName + ".populateDimensionPropertiesList(\"" + selectedHierarchy.get_name() + "\", false)", 200);   
            }
            else
            {
                window.setTimeout(this._gridCtxName + ".populateDimensionPropertiesList(\"" + selectedHierarchy.get_name() + "\", true)", 100);   
            }
        }
    },
    SetShowPropertiesXandY: function PPSMA_OlapGrid_Context$SetShowPropertiesXandY(elem, menuHeight)
    {     
        var parentDiv = document.getElementById(this._olapViewContext.get_innerTargetId());
         
        var yOffset = this.getAbsoluteTop(this._showPropertiesCell);
        var xOffset = this.getAbsoluteLeft(this._showPropertiesCell);
        var width = this._showPropertiesCell.offsetWidth;
        var height = this._showPropertiesCell.offsetHeight;
       
        // Don't want to render the div below the bottom of the document.
        var availHeight = document.documentElement.clientHeight;
        if (availHeight == 0) availHeight = document.body.clientHeight;     
        if ((yOffset + menuHeight) > availHeight)
        {
            yOffset -= menuHeight;
            if (yOffset < 0) yOffset = 0;
        }
        var availWidth = document.documentElement.clientWidth;
        if (availWidth == 0) availWidth = document.body.clientWidth;     
        if ((xOffset + 225) > availWidth)
        {
            xOffset = (availWidth - 225);
            if (xOffset < 0) xOffset = 0;
        }
        var scrollLeft = 0;
        var scrollTop = 0;       
        var parentDiv = document.getElementById(this._olapViewContext.get_innerTargetId());
        if (parentDiv != null)
        {
            scrollLeft = parentDiv.scrollLeft;
            scrollTop = parentDiv.scrollTop;
        }           
        elem.style.left = (xOffset + width - scrollLeft - 10) + "px";
        elem.style.top = (yOffset + height - scrollTop - 10) + "px";
    },      
    populateDimensionPropertiesList: function PPSMA_OlapGrid_Context$populateDimensionPropertiesList(selectedHierarchyName, haveData)
    {      
    	if ((this._olapViewContext.get_menuMetaData()) || (haveData))
        {
            this.addDimensionPropertiesToList(selectedHierarchyName);
        }
        else
        {
            window.setTimeout(this._gridCtxName + ".populateDimensionPropertiesList(\"" + selectedHierarchyName + "\", false)", 100);  
        }
    },
    initializeShowPropertiesBox: function PPSMA_OlapGrid_Context$initializeShowPropertiesBox()
    {
        var showPropertiesDiv = document.getElementById(this._olapViewContext.get_ctrlProxyId() + "_ShowPropertiesDiv");
        if (showPropertiesDiv) return;
        
        var proxyid = this._olapViewContext.get_ctrlProxyId();

        // Main div
        showPropertiesDiv = document.createElement("div"); 
        var id = proxyid + "_ShowPropertiesDiv"; 
        showPropertiesDiv.setAttribute("id", id);  
        showPropertiesDiv.setAttribute("className", "dimPropParentBorder");
        showPropertiesDiv.setAttribute("style", "left:0px; top:0px; display:none; visibility: hidden;");
        
        // Selected dimension information div.
        var selectedDimDiv = document.createElement("div"); 
        id = proxyid + "_SelectedMemberNameTable"; 
        selectedDimDiv.setAttribute("id", id);  
        selectedDimDiv.setAttribute("className", "dimPropSelectedMember");
       
        var selectedDimSpan = document.createElement("span"); 
        id = proxyid + "_gspanSelectedDimension"; 
        selectedDimSpan.setAttribute("id", id); 
        selectedDimSpan.innerHTML = "&nbsp;"; 
      
        selectedDimDiv.appendChild(selectedDimSpan);
        showPropertiesDiv.appendChild(selectedDimDiv);
        
        // Attribute checkboxes parent div.
        var checkboxesDiv = document.createElement("div"); 
        id = proxyid + "_gDimProperties"; 
        checkboxesDiv.setAttribute("id", id);  
        checkboxesDiv.setAttribute("className", "dimPropCheckBoxes");
        checkboxesDiv.onclick = PPSMA.OlapViewContext.globalIds[proxyid].get_reportContext().propInputClick; 
      
        showPropertiesDiv.appendChild(checkboxesDiv);
        
        // Footer div.
        var footerDiv = document.createElement("div"); 
        id = proxyid + "_ShowPropertiesFooter"; 
        footerDiv.setAttribute("id", id);  
        footerDiv.setAttribute("className", "dimPropFooter");
               
        var inputElem = document.createElement("input"); 
        id = proxyid + "_propSelectAll"; 
        inputElem.setAttribute("id", id);  
        inputElem.setAttribute("className", "dimPropSelectAll");
        inputElem.setAttribute("type", "checkbox");
        inputElem.setAttribute("title", PPSMA.SR.OlapPropertiesDialog_SelectAll);
        inputElem.onclick = PPSMA.OlapViewContext.globalIds[proxyid].get_reportContext().propsSelectAll; 
        
        var selectAllTextDiv = document.createElement("div"); 
        selectAllTextDiv.setAttribute("className", "dimPropSelectAllText");
        selectAllTextDiv.innerHTML = PPSMA.SR.OlapPropertiesDialog_SelectAll; 
      
        var apply = document.createElement("A"); 
        apply.setAttribute("className", "dimPropApply");
        apply.innerHTML = PPSMA.SR.OlapPropertiesDialog_Apply; 
        apply.onclick = PPSMA.OlapViewContext.globalIds[proxyid].get_reportContext().propsApply;      
        var cancel = document.createElement("A"); 
        cancel.setAttribute("className", "dimPropCancel");
        cancel.innerHTML = PPSMA.SR.OlapPropertiesDialog_Cancel; 
        cancel.onclick = PPSMA.OlapViewContext.globalIds[proxyid].get_reportContext().propsCancel;      
        
        footerDiv.appendChild(inputElem);
        footerDiv.appendChild(selectAllTextDiv);
        footerDiv.appendChild(apply);
        footerDiv.appendChild(cancel);
        
        showPropertiesDiv.appendChild(footerDiv);

        document.body.appendChild(showPropertiesDiv);
                
    },
    addDimensionPropertiesToList: function PPSMA_OlapGrid_Context$addDimensionPropertiesToList(selectedHierarchyName)
    {
    	this.initializeShowPropertiesBox();

        var divBody = document.getElementById(this._olapViewContext.get_ctrlProxyId() + "_gDimProperties");
       
        var div_Children = divBody.getElementsByTagName("div");
        while(true)
        {
            if (div_Children.length == 0) break;
            divBody.removeChild(div_Children[0]);
        }
         
        var dimProperties;
        var dimPropertiesNames;
        var dimPropertiesCaptions;
        var dimPropertiesChecked;
        var selectedHierarchyCaption = "";
       
        if (this._olapViewContext.get_menuMetaData())
        {
            var xdoc = new ActiveXObject("Microsoft.XMLDOM");
            var xml = "";
            xml = this._olapViewContext.get_menuMetaData();
            xdoc.async = false;
            xdoc.loadXML(xml);

            var xmlDimPropertiesRootNode = xdoc.getElementsByTagName("DimensionProperties");
            var xmlDimProperties = xdoc.getElementsByTagName("DimProperty");
           
            selectedHierarchyCaption = xmlDimPropertiesRootNode[0].getAttribute("caption");
            dimProperties = this._olapViewContext.addDimensionPropertiesList(selectedHierarchyName, selectedHierarchyCaption, xmlDimProperties.length);
            dimProperties.set_noPropertiesMessage(xmlDimPropertiesRootNode[0].getAttribute("NoPropertiesMessage"));
                     
            if ((xmlDimProperties != null) && (xmlDimProperties.length > 0))
            {
                var selectedHier = null;
                var memberProperties = this.getQueryMemberProperties(selectedHierarchyName);
                var memberPropertyNames = null;
                if (memberProperties != null) 
                {
                    memberPropertyNames = memberProperties.get_names();
                }
                                
                dimPropertiesNames = dimProperties.get_names();
                dimPropertiesCaptions = dimProperties.get_captions();
                dimPropertiesChecked = dimProperties.get_checked();
                for (var i = 0; i < xmlDimProperties.length; i++)
                {
                    dimPropertiesNames[i] = xmlDimProperties[i].getAttribute("name");
                    dimPropertiesCaptions[i] = xmlDimProperties[i].getAttribute("caption");
                    if (memberProperties != null)
                    {
                        for (var j = 0; j < memberProperties.get_count(); j++)
                        {
                            if (memberPropertyNames[j] == dimPropertiesNames[i]) dimPropertiesChecked[i] = true;
                        }
                    }
                }                
            }
        }
        else
        {
            dimProperties = this._olapViewContext.getDimensionPropertiesList(selectedHierarchyName);
            selectedHierarchyCaption = dimProperties.get_caption();
            dimPropertiesNames = dimProperties.get_names();
            dimPropertiesCaptions = dimProperties.get_captions()
            dimPropertiesChecked = dimProperties.get_checked();
        }
             
        var height = 0;
        var width = 0;
        if (dimProperties.get_count() > 0)
        {
           if (dimProperties.get_count() < 10) 
           {
                height = (dimProperties.get_count() * 20) + 2;
                divBody.style.height = height + "px"; 
                divBody.style.overflow = "hidden";
           }
           else 
           {
                height = 202;
                divBody.style.height = height + "px";
                divBody.style.overflow = "auto";
           }
                
           var hierElem = document.getElementById(this._olapViewContext.get_ctrlProxyId() + "_gspanSelectedDimension");
           var propStr = PPSMA.SR.OlapPropertiesDialog_PropertiesCaption;
           hierElem.innerHTML = propStr.replace("{caption}", selectedHierarchyCaption);
            
           var mainDivElem = document.getElementById(this._olapViewContext.get_ctrlProxyId() + "_ShowPropertiesDiv");
           mainDivElem.style.width = "200px";
           mainDivElem.style.left = "0px";
           mainDivElem.style.top = "0px";
           mainDivElem.style.visibility = "visible";
           mainDivElem.style.display = "block";
           this.SetShowPropertiesXandY(mainDivElem, (height+40));
           
           var numSelected = 0;
           for (var i = 0; i < dimProperties.get_count(); i++)
           {
                var inputid = this._olapViewContext.get_ctrlProxyId() + "_inputPropCheckBox_" + i;
                var divid = this._olapViewContext.get_ctrlProxyId() + "_divPropCheckBox_" + i;
                var labelid = this._olapViewContext.get_ctrlProxyId() + "_divPropLabel_" + i;
                var cbdiv = document.createElement("div");
                var cbinput = document.createElement("input");
                var cblabel = document.createElement("label");
                
                cbdiv.setAttribute("id", divid);
                cbdiv.setAttribute("className", "dimPropCheckBox");
                
                cbinput.setAttribute("type", "checkbox");
                cbinput.setAttribute("title", dimPropertiesCaptions[i]);
                cbinput.setAttribute("value", dimPropertiesNames[i]);
                cbinput.setAttribute("id", inputid);
                
                cblabel.setAttribute("for", inputid);               
                cblabel.setAttribute("title", dimPropertiesCaptions[i]);                   
                cblabel.setAttribute("className", "dimPropCheckBoxLabel");                 
                cblabel.setAttribute("id", labelid);
               
                var caption = dimPropertiesCaptions[i];
                //if (i == 0) // for testing long captions
                    //caption = "FFFFFFFFFFFFFFFFFFFWWWWWWWWWWMMMTFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
                    //caption = "FFFFFFFFFFFFFFFFFFFWWWWWWWWWWMMMTFFFFFFFFFFFFFFFFFFFFFFFFF";
                                  
                if (caption.length > 100) 
                {
                    caption = caption.substr(0, 100)+PPSMA.SR.OlapPropertiesDialog_LongStringPadding;
                }     
                cblabel.innerHTML = "&nbsp;" + caption;       
                cbdiv.appendChild(cbinput);
                cbdiv.appendChild(cblabel);
                divBody.appendChild(cbdiv);
                
                var labelOffsetWidth = document.getElementById(labelid).offsetWidth;
                if (labelOffsetWidth > width)  width = labelOffsetWidth;
                
                if (dimPropertiesChecked[i] == true) 
                {
                    ++numSelected;
                    document.getElementById(inputid).checked = true;
                    document.getElementById(divid).style.backgroundColor = "#AEC8EA";
                }
            }
            var SelectAllElem = document.getElementById(this._olapViewContext.get_ctrlProxyId() + "_propSelectAll");
            numSelected == dimProperties.get_count() ? SelectAllElem.checked = true : SelectAllElem.checked = false;
           
            var selectedDimDivElem = document.getElementById(this._olapViewContext.get_ctrlProxyId() + "_SelectedMemberNameTable");
            if (selectedDimDivElem.offsetWidth > width) width = selectedDimDivElem.offsetWidth;
            
            if (width > 200) mainDivElem.style.width = (width + 30) + "px";
        }
        else 
        {
            alert(dimProperties.get_noPropertiesMessage());
            return false;
        }

        window.document.body.onclick = "";        

        PPSMA.OlapGrid._CurrProxyId = this._olapViewContext.get_ctrlProxyId();               
        window.document.body.onclick = PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext().propsHide;
        window.document.body.onkeypress = PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext().propsKeyPress;
        return true;
    },
    getSelectedMemberXml: function PPSMA_OlapGrid_Context$getSelectedMemberXml()
    {
        var xdoc = new ActiveXObject("Microsoft.XMLDOM");
        xdoc.async = false;
        xdoc.documentElement = xdoc.createElement("_dimProp");
        var dimensionElem = xdoc.createElement("Dimension");
        xdoc.documentElement.appendChild(dimensionElem);
             
        var selectedHierarchy = this.showPropertiesGetSelectedHierarchy(this._showPropertiesCell); 
        dimensionElem.setAttribute("name", selectedHierarchy.get_name());       
        return xdoc.documentElement.xml;  
    },   
    propInputClick: function PPSMA_OlapGrid_Context$propInputClick()
    {
        var reportContextObj = PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext();
        if (!reportContextObj) return;
        
        var DimPropertiesElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_gDimProperties");
	    var inputCollection = DimPropertiesElem.getElementsByTagName("input");
	    var selectedHierarchyName = reportContextObj.showPropertiesGetSelectedHierarchy(reportContextObj._showPropertiesCell).get_name();
        var dimProperties = reportContextObj._olapViewContext.getDimensionPropertiesList(selectedHierarchyName);
        var dimPropertiesChecked = dimProperties.get_checked();
        
        var srcElem = event.srcElement;  
        if (srcElem.className == "dimPropCheckBox") 
        {
            var id = srcElem.id;
            var sindex = srcElem.id.substr((PPSMA.OlapGrid._CurrProxyId.length + 17), id.length);  // "_divPropCheckBox_"
            var index = parseInt(sindex);
            inputCollection[index].checked == false ? inputCollection[index].checked = true : inputCollection[index].checked = false;
        }
        if (srcElem.className == "dimPropCheckBoxLabel") 
        {
            var id = srcElem.id;
            var sindex = srcElem.id.substr((PPSMA.OlapGrid._CurrProxyId.length + 14), id.length);  // "_divPropLabel_"
            var index = parseInt(sindex);
            inputCollection[index].checked == false ? inputCollection[index].checked = true : inputCollection[index].checked = false;
        }
	    
        for (var i = 0; i < inputCollection.length; ++i)
        {
            var divElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_divPropCheckBox_" + i);
            var inputElem = inputCollection[i];
	    
	        if (inputElem.checked == false)
	        {
	            divElem.style.backgroundColor = "fff";
	            dimPropertiesChecked[i] = false;
	        }
	        else
	        {
	            divElem.style.backgroundColor = "#AEC8EA";
	            dimPropertiesChecked[i] = true;
	        }
	    }
    },
    propsSelectAll: function PPSMA_OlapGrid_Context$propsSelectAll()
    {
        var reportContextObj = PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext();
        if (!reportContextObj) return;
        
        var DimPropertiesElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_gDimProperties");
	    var inputCollection = DimPropertiesElem.getElementsByTagName("input");
	    var SelectAllElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_propSelectAll");
	    var selectedHierarchyName = reportContextObj.showPropertiesGetSelectedHierarchy(reportContextObj._showPropertiesCell).get_name();
        var dimProperties = reportContextObj._olapViewContext.getDimensionPropertiesList(selectedHierarchyName);
        var dimPropertiesChecked = dimProperties.get_checked();
	    
	    if (SelectAllElem.checked == false)
        {
			for (var i = 0; i < inputCollection.length; ++i)
			{
			    var inputElem = inputCollection[i];
			    if (inputElem.checked == true) 
			    {
					inputElem.checked = false;
					var divElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_divPropCheckBox_" + i);
					divElem.style.backgroundColor = "fff";
					dimPropertiesChecked[i] = false;
				}
			}
        }
        else
        {
			for (var i = 0; i < inputCollection.length; ++i)
			{
			    var inputElem = inputCollection[i];
			    if (inputElem.checked == false)
			    {
				    inputElem.checked = true;
					var divElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_divPropCheckBox_" + i);
					divElem.style.backgroundColor = "#AEC8EA";
					dimPropertiesChecked[i] = true;
			    }
			}
		}
    },
    handleHidePropertyMenuClick: function PPSMA_OlapGrid_Context$handleHidePropertyMenuClick(hierName, propertyName)
    {
 	    if (!this.get_canNavigate()) return;
 	    
        // If not null - tells me that the user has retrieved the xml via/ajax call.
        var dimProperties = this._olapViewContext.getDimensionPropertiesList(hierName);
        if (dimProperties != null)
        {
            var dimPropertiesNames = dimProperties.get_names();
            var dimPropertiesChecked = dimProperties.get_checked();        
        
            for (var i = 0; i < dimProperties.get_count(); i++)
            {
                if ((dimPropertiesNames[i] == propertyName) && (dimPropertiesChecked[i] == true))
                {
                    dimPropertiesChecked[i] = false;
                    break;        
                }
            }
        }
        else
        {
            var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
            for (var rowHierIndex in rowHiers)
            {
                if (rowHiers[rowHierIndex].get_name() == hierName)
                {
                    var memberProperties = rowHiers[rowHierIndex].get_memberProperties();
                    if (memberProperties != null) 
                    {
                        memberProperties.hide(propertyName);
                        break;
                    }
                }
            }
        }
        this._olapViewContext.applyDimensionProperties();     
    },
    getQueryMemberProperties: function PPSMA_OlapGrid_Context$getQueryMemberProperties(selectedHierarchyName)
    {
        var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
        for (var rowHierIndex in rowHiers)
        {
            if (rowHiers[rowHierIndex].get_name() == selectedHierarchyName)
            {
                selectedHier = rowHiers[rowHierIndex];
                return(selectedHier.get_memberProperties());
            }
        }
        return null;
    },  
    revertMemberPropertySelections: function PPSMA_OlapGrid_Context$revertMemberPropertySelections(selectedHierarchyName)
    {
        var memberProperties = this.getQueryMemberProperties(selectedHierarchyName);
        var memberPropertyNames;
        if (memberProperties != null) memberPropertyNames = memberProperties.get_names();
              
        var dimProperties = this._olapViewContext.getDimensionPropertiesList(selectedHierarchyName);
        if(dimProperties != null)
        {          
            var dimPropertiesNames = dimProperties.get_names();
            var dimPropertiesChecked = dimProperties.get_checked();
            for (var i = 0; i < dimProperties.get_count(); i++)
            {
                dimPropertiesChecked[i] = false;
                for (var j = 0; j < memberProperties.get_count(); j++)
                {
                    if (memberPropertyNames[j] == dimPropertiesNames[i]) dimPropertiesChecked[i] = true;
                }
            }   
        }
    },
    isDirtyMemberProperties: function PPSMA_OlapGrid_Context$isDirtyMemberProperties(selectedHierarchyName)
    {
        var memberProperties = this.getQueryMemberProperties(selectedHierarchyName);
        var memberPropertyNames;
        if (memberProperties != null) memberPropertyNames = memberProperties.get_names();
              
        var dimProperties = this._olapViewContext.getDimensionPropertiesList(selectedHierarchyName);
        if(dimProperties != null)
        {          
            if (((memberProperties == null)||(memberProperties.get_count() == 0)) && (dimProperties.get_enabledCount() > 0)) return true;
            
            var dimPropertiesNames = dimProperties.get_names();
            var dimPropertiesChecked = dimProperties.get_checked();
            for (var i = 0; i < dimProperties.get_count(); i++)
            {
                var foundMatch = false;
                for (var j = 0; j < memberProperties.get_count(); j++)
                {
                    if (memberPropertyNames[j] == dimPropertiesNames[i]) 
                    {
                        foundMatch = true;
                        if (dimPropertiesChecked[i] == false)
                        {
                            return true;
                        }
                    }
                }
                if(foundMatch == false)
                {
                    if (dimPropertiesChecked[i] == true)
                    {
                        return true;
                    }              
                }
            }   
        }
        return false;  
    },  
    propsApply: function PPSMA_OlapGrid_Context$propsApply()
    {
        var reportContextObj = PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext();
        
        if ((!reportContextObj) || (!reportContextObj.get_canNavigate())) return;
        
	    var selectedHierarchyName = reportContextObj.showPropertiesGetSelectedHierarchy(reportContextObj._showPropertiesCell).get_name();
        if (reportContextObj.isDirtyMemberProperties(selectedHierarchyName) == false)
        {
            reportContextObj.propsCancel();
            return;
        }
        
        var elem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_ShowPropertiesDiv");
        elem.style.visibility = "hidden";
        elem.style.display = "none";
        
        var DimPropertiesElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_gDimProperties");
	    var collection = DimPropertiesElem.getElementsByTagName("input");
	    var dimProperties = reportContextObj._olapViewContext.getDimensionPropertiesList(selectedHierarchyName);
	    if (dimProperties != null)
	    {
	        var dimPropertiesChecked = dimProperties.get_checked();
    	    
		    for (var i = 0; i < collection.length; ++i)
		    {
		        var el = collection[i];
		        el.checked ? dimPropertiesChecked[i] = true : dimPropertiesChecked[i] = false;
		    }
            var SelectAllElem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_propSelectAll");
            SelectAllElem.checked == true ? dimPropertiesChecked[dimProperties.get_count()] = true : dimPropertiesChecked[dimProperties.get_count()] = false;
        }
        reportContextObj._olapViewContext.applyDimensionProperties();
        PPSMA.OlapGrid._CurrProxyId = "";
    },
    propsCancel: function PPSMA_OlapGrid_Context$propsCancel()
    {
        if (PPSMA.OlapGrid._CurrProxyId != "")
        {
            var reportContextObj = PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext();
            if (reportContextObj) 
            {
    	        var selectedHierarchyName = reportContextObj.showPropertiesGetSelectedHierarchy(reportContextObj._showPropertiesCell).get_name();
    	        reportContextObj.revertMemberPropertySelections(selectedHierarchyName)
    	    }
            var elem = document.getElementById(PPSMA.OlapGrid._CurrProxyId + "_ShowPropertiesDiv");
            if (elem != null)
            {
                elem.style.visibility = "hidden";
                elem.style.display = "none";
            }
            PPSMA.OlapGrid._CurrProxyId = "";
    	}
    }, 
    propsKeyPress: function PPSMA_OlapGrid_Context$propsKeyPress()
    {
        if (event.keyCode == 27) // escape key
        {
            if (PPSMA.OlapGrid._CurrProxyId == "") return;
            PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext().propsCancel();
        }
    },
    propsHide: function PPSMA_OlapGrid_Context$propsHide()
    {
        if (PPSMA.OlapGrid._CurrProxyId == "") return;
        
        var srcElem = event.srcElement;      
        while (srcElem)
        {
            if (srcElem.className == "dimPropParentBorder") return;
            srcElem = srcElem.parentElement;
        }
          
        PPSMA.OlapViewContext.globalIds[PPSMA.OlapGrid._CurrProxyId].get_reportContext().propsApply();
    },     
    pivot: function PPSMA_OlapGrid_Context$pivot(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
            this._olapViewContext.pivot();
        }
    },
    filterEmptyRow: function PPSMA_OlapGrid_Context$filterEmptyRow(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
	        var emptyRow = (this._olapViewContext.get_results().get_filterEmptyAxis()==2) || (this._olapViewContext.get_results().get_filterEmptyAxis()==3);
    	    var sEmpty = "true";
    	    if (emptyRow) sEmpty = "false";
            this._olapViewContext.filterEmpty("2", sEmpty);
        }
    },
    filterEmptyCol: function PPSMA_OlapGrid_Context$filterEmptyCol(currCell)
    {
 	    if (this.get_canNavigate())
 	    {
    	    var emptyCol = (this._olapViewContext.get_results().get_filterEmptyAxis()==1) || (this._olapViewContext.get_results().get_filterEmptyAxis()==3);
    	    var sEmpty = "true";
    	    if (emptyCol) sEmpty = "false";
            this._olapViewContext.filterEmpty("1", sEmpty);
        }
    },
    sortByDirectionArrow: function PPSMA_OlapGrid_Context$sortByDirectionArrow(sortType,cIndex,rIndex)
    {
 	    if (this.get_canNavigate())
 	    {
            var detailsHelper = new PPSMA.ContextMenu.DetailsHelper(this._olapViewContext,
                            this._gridCtxName,rIndex,cIndex);
 	        var tupleXml = detailsHelper.getCellTupleXml();
            if (tupleXml != null )
            {
                this.olapContextSort(sortType,tupleXml);
            }
        }
    },
    sort: function PPSMA_OlapGrid_Context$sort(currCell,sortType)
    {
 	    if (this.get_canNavigate())
 	    {
            var cellTypeId = this.getCellTypeId(currCell);
            var rIndex = 0;
            var cIndex = this.getSortedCellColumnPosition(currCell);
            var detailsHelper = new PPSMA.ContextMenu.DetailsHelper(this._olapViewContext,
                            this._gridCtxName,rIndex,cIndex);
 	        var tupleXml = detailsHelper.getCellTupleXml();
 	        if (tupleXml != null )
            {
                this.olapContextSort(sortType,tupleXml);
            }
        }
    },
    olapContextSort: function PPSMA_OlapGrid_Context$olapContextSort(sortType,tupleXml)
    {
 	    if (this.get_canNavigate())
 	    {
 	        var preservePeerGroup = "false";
 	        if (this._reportLayout == PPSMA.OlapGrid.ReportLayout.CompactForm)
 	        {
 	            preservePeerGroup = "true";
 	        }
            this._olapViewContext.sort("2", tupleXml, sortType, preservePeerGroup);
        }
    },
    changeReportLayout: function PPSMA_OlapGrid_Context$changeReportLayout(reportLayout)
    {
        this._olapViewContext.changeViewConfiguration("ReportLayout", reportLayout);
    },
    switchToGrid: function PPSMA_OlapGrid_Context$switchToGrid()
	{
	    //won't be called, already a grid
	},
	switchToBarChart: function PPSMA_OlapGrid_Context$switchToBarChart()
	{
	    this._olapViewContext.switchOlapReportType(PPSMA.ContextMenu.OlapReportType.BarChart);
	},
	switchToStackedBarChart: function PPSMA_OlapGrid_Context$switchToStackedBarChart()
	{
	    this._olapViewContext.switchOlapReportType(PPSMA.ContextMenu.OlapReportType.StackedBarChart);
	},
	switchTo100StackedBarChart: function PPSMA_OlapGrid_Context$switchTo100StackedBarChart()
	{
	    this._olapViewContext.switchOlapReportType(PPSMA.ContextMenu.OlapReportType.Stacked100BarChart);
	},
	switchToLineChart: function PPSMA_OlapGrid_Context$switchToLineChart()
	{
	    this._olapViewContext.switchOlapReportType(PPSMA.ContextMenu.OlapReportType.LineChart);
	},
	switchToLineChartWithMarkers: function PPSMA_OlapGrid_Context$switchToLineChartWithMarkers()
	{
	    this._olapViewContext.switchOlapReportType(PPSMA.ContextMenu.OlapReportType.LineChartWithMarkers);
	},
    getCurrentElement: function PPSMA_OlapGrid_Context$getCurrentElement(e)
    {
        if (window.event) 
            return event.srcElement;
        else 
            return null;
    },
    getCellFromElement: function PPSMA_OlapGrid_Context$getCellFromElement(elem)
    {
        var cell = null;
        if ((elem) && (elem.tagName))
        {
            if (elem.tagName.toLowerCase() == "td")
            {
                cell = elem;
            }
            else if ((elem.tagName.toLowerCase() == "img") || (elem.tagName.toLowerCase() == "a"))
            {
                var p = elem.parentNode;
                if ((p) && (p.tagName))
                {
                    if (p.tagName.toLowerCase() == "td")
                    {
                        cell = p;
                    }
                }
            
            }
        }
        return cell;
    },
    getEvent: function PPSMA_OlapGrid_Context$getEvent(e)
    {
        if (window.event) 
            return event;
        else 
            return null;
    }
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();