﻿// AnalyticChart.js
//





// -----------------------------------

Type.registerNamespace('PPSMA');
// OlapChart.js

// class def for PPSMA.OlapChart.Context object.  PPSMA.OlapChart.Context object
// is responsible for storing state information related to the chart image
// as well as handling user interaction events. There is one instance of
// the PPSMA.OlapChart.Context object per chart.
PPSMA.OlapChart = function PPSMA_OlapChart(){}
PPSMA.OlapChart.ItemType={Series:0, Points:1, Background:2, ViewInfoBar:3, LegendLocation:4};
PPSMA.OlapChart.SubMenuType={DrillDownTo:0, AddActions:1};
PPSMA.OlapChart.LegendLocation={Hide:0, Right:1, Top:2};
PPSMA.OlapChart.PtActiveTypes;
PPSMA.OlapChart.Context = function PPSMA_OlapChart_Context(chartCtxName, olapViewContext, properties)
{
    this._chartCtxName = chartCtxName;
    this._olapViewContext = olapViewContext;
    this._propertiesArray = properties;     //[chartType, legendLocation]
	this._subMenus = PPSMA.ContextMenu.CreateSubMenuCollection();
	this._currentMenu;
	this._seriesIndex;
	this._arrSeries;
	this._activeSeriesLevel = 0;
	this._pointsIndex;
	this._arrPoints;
	this._activePointsLevel = 0;
	this._actionType;
	this._switchEvent;
	this._ptActiveType = PPSMA.OlapChart.ItemType.Series;
	this._focusedArea;
	this._focusedArray;
	this._currentElement;
	this._tempValue;
}
PPSMA.OlapChart.Context.prototype =
{
    //length of method names reduced to minimize html for area map
    //handle OnFocus event of the area tag
    OnF: function PPSMA_OlapChart_Context$OnF(o,a)
    {
        this._focusedArea = o;
        this._focusedArray = a;
    },
    //handle OnKeyDown event of the map
    OnKD: function PPSMA_OlapChart_Context$OnKD(e)
    {
        if (!this._focusedArray) return;
        var bSeries = (this._focusedArray[1] < 0); //point index is -1 on series
        switch (e.keyCode)
        {
            case 13: //ENTER
                if (bSeries)
                    this.SOnC(null,this._focusedArray);
                else
                    this.POnC(null,this._focusedArray);
                break;
            case 93: //MENU KEY
                var elem = this._focusedArea;
                var insetBuffer=2;
                var x = elem.offsetLeft + this.getAbsoluteLeft(e.srcElement) - document.body.scrollLeft + insetBuffer;
                var y = elem.offsetTop + this.getAbsoluteTop(e.srcElement) - document.body.scrollTop + insetBuffer;
                e = new PPSMA.Event(2,x,y,elem);
                if (bSeries)
                    this.SOnC(e,this._focusedArray);
                else
                    this.POnC(e,this._focusedArray);
                break;
            default:
                break;
        }
    },
    //handle OnClick for chart Series
    SOnC: function PPSMA_OlapChart_Context$SOnC(e,a)
    {
		this.SetIndices(a);
		if (this._actionType == PPSMA.OlapChart.ItemType.Points) this._activeSeriesLevel = 0;
		this._actionType = PPSMA.OlapChart.ItemType.Series;
		if (this.CanDrillDownOnClick(e))
		    this.DrillDown();
        else if (this.isRightClick(e))
			this.BuildCtxMenu(e);
    },
    //handle OnClick for chart Points
    POnC: function PPSMA_OlapChart_Context$POnC(e,a)
    {
		this.SetIndices(a);
		this.GetColumnMembersArray();
		this.CheckPtActiveTypeState();
		if (this._actionType == PPSMA.OlapChart.ItemType.Series) this._activeSeriesLevel = 0;
		this._actionType = PPSMA.OlapChart.ItemType.Points;
		if (this.CanDrillDownOnClick(e))
		    this.DrillDown();
        else if (this.isRightClick(e))
			this.BuildCtxMenu(e);
	},
	BGOnC: function PPSMA_OlapChart_Context$BackOnC(e)
	{
	    if (this.isRightClick(e))
	    {
	        this._actionType = PPSMA.OlapChart.ItemType.Background;
	        this._currentElement = e.srcElement;
	        this._subMenus.Clear();
	        this._focusedArray = null;
	        PPSMA.ContextMenu.Create(e, this, e.clientX, e.clientY);
        }
	},
	CheckPtActiveTypeState: function PPSMA_OlapChart_Context$CheckPtActiveTypeState()
	{
	    if (PPSMA.OlapChart.PtActiveTypes && PPSMA.OlapChart.PtActiveTypes.get(this._chartCtxName))
		{
		    this._ptActiveType = PPSMA.OlapChart.PtActiveTypes.get(this._chartCtxName);
		}
	},
	HideViewInfoBarCtxMenu: function PPSMA_OlapChart_Context$HideViewInfoBarCtxMenu(e)
	{
	    if (this.isRightClick(e))
	    {
	        this._actionType = PPSMA.OlapChart.ItemType.ViewInfoBar;
	        this._currentElement = this.getViewInfoDiv(e.srcElement);
	        this._subMenus.Clear();
	        this._focusedArray = null;
	        var xOffset = e.clientX - this.getAbsoluteLeft(e.srcElement);
	        var yOffset = e.clientY - this.getAbsoluteTop(e.srcElement);
	        PPSMA.ContextMenu.Create(e, this, xOffset, yOffset);
        }
	},
	getViewInfoDiv: function PPSMA_OlapGrid_Context$getViewInfoDiv(elem)
    {
        while (elem)
        {
            if (elem.tagName == 'DIV' && elem.id == "_viewInfoId") return elem; 
            elem = elem.parentElement;
        }
    },
	BuildCtxMenu: function PPSMA_OlapChart_Context$BuildCtxMenu(e)
	{
	    this._currentElement = e.srcElement;
	    this._subMenus.Clear();
	    this._focusedArray = null;
	    var currEvent = this.getEvent(e);
	    this._switchEvent = this.GetEventPlaceholder(currEvent);
	    this.GetRowMembersArray();
	    var xOffset = e.clientX - this.getAbsoluteLeft(e.srcElement);
	    var yOffset = e.clientY - this.getAbsoluteTop(e.srcElement);
	    PPSMA.ContextMenu.Create(currEvent, this, xOffset, yOffset);
	},
	getAbsoluteTop: function PPSMA_OlapChart_Context$getAbsoluteTop(o)
    {	
	    oTop = o.offsetTop;
	    while (o.offsetParent != null)
	    {
		    oParent = o.offsetParent;
		    oTop += oParent.offsetTop;
		    o = oParent;
	    }
	    return oTop;
    },
    getAbsoluteLeft: function PPSMA_OlapChart_Context$getAbsoluteLeft(o)
    {
	    oLeft = o.offsetLeft;
	    while (o.offsetParent != null)
	    {
		    oParent = o.offsetParent;
		    oLeft += oParent.offsetLeft;
		    o = oParent;
	    }
	    return oLeft;
    },
    SetIndices: function PPSMA_OlapChart_Context$SetIndices(a)
    {
        if (a && a.length == 2)
        {
            this._seriesIndex=a[0];
            this._pointsIndex=a[1];
        }
    },
    GetRowMembersArray: function PPSMA_OlapChart_Context$GetRowMembersArray()
    {
		this._arrSeries = new Array();
		var members = this._olapViewContext.get_results().get_rowMembers()[this._seriesIndex];
		for (var ndx=0; ndx<members.length; ndx++)
		{
			this._arrSeries.push(members[ndx].get_caption());
		}
    },
    GetColumnMembersArray: function PPSMA_OlapChart_Context$GetColumnMembersArray()
    {
		this._arrPoints = new Array();
		var members = this._olapViewContext.get_results().get_columnMembers()[this._pointsIndex];
		for (var ndx=0; ndx<members.length; ndx++)
		{
			this._arrPoints.push(members[ndx].get_caption());
		}
    },
	GetEventPlaceholder: function PPSMA_OlapChart_Context$GetEventPlaceholder(e)
	{
	    return new PPSMA.Event(e.button,e.clientX,e.clientY,e.srcElement);
	},
	GetSelectedMember: function PPSMA_OlapChart_Context$GetSelectedMember()
	{
	    if (this._actionType == PPSMA.OlapChart.ItemType.Series || this._ptActiveType == PPSMA.OlapChart.ItemType.Series)
	    {
	        var rowMembers = this._olapViewContext.get_results().get_rowMembers();
	        return rowMembers[this._seriesIndex][this._activeSeriesLevel];
	    }
	    else if (this._actionType == PPSMA.OlapChart.ItemType.Points)
	    {
            var colMembers = this._olapViewContext.get_results().get_columnMembers();
            return colMembers[this._pointsIndex][this._activePointsLevel];
        }
        return null;
	},
	GetSelectedMemberHierarchy: function PPSMA_OlapChart_Context$GetSelectedMemberHierarchy()
	{
	    if (this._actionType == PPSMA.OlapChart.ItemType.Series || this._ptActiveType == PPSMA.OlapChart.ItemType.Series)
	    {
	        var rowHiers = this._olapViewContext.get_results().get_rowHierarchies();
	        return rowHiers[this._activeSeriesLevel];
	    }
	    else if (this._actionType == PPSMA.OlapChart.ItemType.Points)
	    {
            var colHiers = this._olapViewContext.get_results().get_columnHierarchies();
            return colHiers[this._activePointsLevel];
        }
        return null;
	},
	AddPrimaryMenuItems: function PPSMA_OlapChart_Context$AddPrimaryMenuItems(m)
    {
        this._currentMenu = m;
        switch(this._actionType)
        {
            case PPSMA.OlapChart.ItemType.Series:
                return this.AddSeriesPrimaryMenuItems();
            case PPSMA.OlapChart.ItemType.Points:
                return this.AddPointsPrimaryMenuItems();
            case PPSMA.OlapChart.ItemType.Background:
                return this.AddBackgroundMenuItems();
            case PPSMA.OlapChart.ItemType.ViewInfoBar:
                return this.AddHideViewInfoBarItems();
            case PPSMA.OlapChart.ItemType.LegendLocation:
                return this.AddLegendLocationMenuItems(this._currentMenu);
            default:
                break;
        }
        return false;
    },
	AddSeriesPrimaryMenuItems: function PPSMA_OlapChart_Context$AddSeriesPrimaryMenuItems()
	{
	    var canNavigate = this.get_canNavigate();
	    var member = this.GetSelectedMember();
	    var hierarchy = this.GetSelectedMemberHierarchy();
		var helper = new PPSMA.ContextMenu.OptionHelper(member, hierarchy, canNavigate, this._olapViewContext);
		if (canNavigate)
		    helper.AddDisabledOption(this._currentMenu, this._arrSeries[this._activeSeriesLevel]);
		helper.DrillDown(this._currentMenu, this._chartCtxName+".DrillDown()",true);
		
        var drillDownTo = helper.DrillDownTo(this._currentMenu,
            this._chartCtxName+".fetchCallback("+this._subMenus.length+")", 
            this._chartCtxName+".populateCallback("+this._subMenus.length+")", 
            this._chartCtxName+".hoverOffCallback("+this._subMenus.length+")",true);
		if (drillDownTo)
		{
		    var ddtSubMenu = new PPSMA.SubMenu(drillDownTo,PPSMA.OlapChart.SubMenuType.DrillDownTo);
		    this._subMenus.Add(ddtSubMenu);
		}
        
        helper.DrillUp(this._currentMenu, this._chartCtxName+".DrillUp()", true);
        helper.ShowOnly(this._currentMenu, this._chartCtxName+".ShowOnly()", true);
        helper.Remove(this._currentMenu, this._chartCtxName+".Remove()", true);

        for (var ndx=0; ndx<this._arrSeries.length; ndx++)
        {
            if (ndx != this._activeSeriesLevel)
            {
                helper.SwitchToOption(this._currentMenu, 
                    this._arrSeries[ndx], 
                    this._chartCtxName+".SwitchTo("+ndx+")");
            }
        }
        PPSMA.ContextMenu.AddMenuSeparator(this._currentMenu);
        this.AddFilterEmptySubMenu(canNavigate);
        helper.Pivot(this._currentMenu, this._chartCtxName+".Pivot()");
        PPSMA.ContextMenu.AddMenuSeparator(this._currentMenu);
        
        if (canNavigate)
        {
			helper.ReportTypeSubMenu(this._currentMenu, this._chartCtxName, this._propertiesArray[0]);
			var formatReportSubMenu = helper.FormatReportSubMenu(this._currentMenu);
			this.AddLegendLocationMenuItems(formatReportSubMenu);
			PPSMA.ContextMenu.AddMenuSeparator(this._currentMenu);
		}
        
        helper.ShowHideInfo(this._currentMenu, this._chartCtxName +".ShowHideInfo()");        
        return (helper.get_optionsAdded() > 0);
	},
	AddPointsPrimaryMenuItems: function PPSMA_OlapChart_Context$AddPointsPrimaryMenuItems()
	{
	    var canNavigate = this.get_canNavigate();
	    var member = this.GetSelectedMember();
	    var hierarchy = this.GetSelectedMemberHierarchy();
		var helper = new PPSMA.ContextMenu.OptionHelper(member, hierarchy, canNavigate, this._olapViewContext);
		if (canNavigate)
	    {
	        if (this._ptActiveType == PPSMA.OlapChart.ItemType.Series)
	            helper.AddDisabledOption(this._currentMenu, this._arrSeries[this._activeSeriesLevel]);
	        else
	            helper.AddDisabledOption(this._currentMenu, this._arrPoints[this._activePointsLevel]);
	    }
		helper.DrillDown(this._currentMenu, this._chartCtxName+".DrillDown()",true);
		
		var drillDownTo = helper.DrillDownTo(this._currentMenu,
            this._chartCtxName+".fetchCallback("+this._subMenus.length+")", 
            this._chartCtxName+".populateCallback("+this._subMenus.length+")", 
            this._chartCtxName+".hoverOffCallback("+this._subMenus.length+")",true);
		if (drillDownTo)
		{
		    var ddtSubMenu = new PPSMA.SubMenu(drillDownTo,PPSMA.OlapChart.SubMenuType.DrillDownTo);
		    this._subMenus.Add(ddtSubMenu);
		}
        
        helper.DrillUp(this._currentMenu, this._chartCtxName+".DrillUp()", true);
        helper.ShowOnly(this._currentMenu, this._chartCtxName+".ShowOnly()", true);
        helper.Remove(this._currentMenu, this._chartCtxName+".Remove()", true);
        
        for (var ndx=0; ndx<this._arrSeries.length; ndx++)
        {
            if (ndx != this._activeSeriesLevel || this._ptActiveType == PPSMA.OlapChart.ItemType.Points)
            {
                helper.SwitchToOption(this._currentMenu, 
                    this._arrSeries[ndx], 
                    this._chartCtxName+".SwitchTo("+ndx+")");
            }
        }
        for (var ndx=0; ndx<this._arrPoints.length; ndx++)
        {
            if (ndx != this._activePointsLevel || this._ptActiveType == PPSMA.OlapChart.ItemType.Series)
            {
                helper.SwitchToOption(this._currentMenu, 
                    this._arrPoints[ndx], 
                    this._chartCtxName+".SwitchTo("+ndx+",true)");
            }
        }
        
        this._olapViewContext.set_menuMetaData(null);
        PPSMA.ContextMenu.AddMenuSeparator(this._currentMenu);
        
        var showDetailsEnabled = true;
        var hasAggregatedBGHiers = helper.HasAggregatedBackGroundHierarchies();
        if (hasAggregatedBGHiers == true)
            showDetailsEnabled = false;
        
        helper.ShowDetails(this._currentMenu, this._chartCtxName+".ShowDetails('')", false, showDetailsEnabled);
        
        var addActionsEnabled = true;
        if (hasAggregatedBGHiers == true) addActionsEnabled = false;
        
        var addActions = helper.AdditionalActions(this._currentMenu,
            this._chartCtxName+".fetchCallback("+this._subMenus.length+")", 
            this._chartCtxName+".populateCallback("+this._subMenus.length+")", 
            this._chartCtxName+".hoverOffCallback("+this._subMenus.length+")",
            false,
            addActionsEnabled);
        if (addActions)
        {
            var aaSubMenu = new PPSMA.SubMenu(addActions,PPSMA.OlapChart.SubMenuType.AddActions);
            this._subMenus.Add(aaSubMenu);
        }
        
        PPSMA.ContextMenu.AddMenuSeparator(this._currentMenu);
        this.AddSortSubMenu(canNavigate);
        this.AddFilterEmptySubMenu(canNavigate);
        helper.Pivot(this._currentMenu, this._chartCtxName+".Pivot()");
        helper.ShowHideInfo(this._currentMenu, this._chartCtxName +".ShowHideInfo();");        
        return (helper.get_optionsAdded() > 0);
	},
	AddFilterEmptySubMenu: function PPSMA_OlapChart_Context$AddFilterEmptySubMenu(canNavigate)
	{
	    if (canNavigate)
	    {
	        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_EmptySeries,
	            this._chartCtxName+".FilterEmpty('2')",g_resFolder + "FilterEmpRowChart.gif","",emptyRow);
	        PPSMA.ContextMenu.AddToggleMenuOption(filterEmptyBy,PPSMA.SR.OlapContextMenu_EmptyPoints,
	            this._chartCtxName+".FilterEmpty('1')",g_resFolder + "FilterEmpColChart.gif","",emptyCol);
        }
	},
	AddSortSubMenu: function PPSMA_OlapChart_Context$AddSortSubMenu(canNavigate)
	{
	    if (canNavigate)
	    {
	        var enableSeriesSort = (this._pointsIndex == this._olapViewContext.get_results().get_sortColIndex());
	        var enableBottomAxisSort = (this._seriesIndex == this._olapViewContext.get_results().get_sortRowIndex());
    	    var sortBy = PPSMA.ContextMenu.CreateSubMenu(this._currentMenu,
    	        PPSMA.SR.OlapContextMenu_Sort,g_resFolder + "Sort.gif");	    
	        PPSMA.ContextMenu.AddDisabledMenuOption(sortBy,
	            PPSMA.SR.OlapContextMenu_SortSeries,"",g_resFolder + "ChartSeriesD.gif");
	        var tab = "   ";
	        PPSMA.ContextMenu.AddMenuOption(sortBy, tab+PPSMA.SR.OlapContextMenu_LargeToSmall,
	            this._chartCtxName+".Sort('2','desc')",g_resFolder + "SortAscNum.gif","",
	            enableSeriesSort && (this._olapViewContext.get_results().get_sortTypeRow() == 'desc'));
	        PPSMA.ContextMenu.AddMenuOption(sortBy,tab+PPSMA.SR.OlapContextMenu_SmallToLarge,
	            this._chartCtxName+".Sort('2','asc');",g_resFolder + "SortDescNum.gif","",
	            enableSeriesSort && (this._olapViewContext.get_results().get_sortTypeRow() == 'asc'));
	        PPSMA.ContextMenu.AddMenuOption(sortBy,tab+PPSMA.SR.OlapContextMenu_NoSort,
	            this._chartCtxName+".Sort('2','nosort');");
            PPSMA.ContextMenu.AddMenuSeparator(sortBy);
	        PPSMA.ContextMenu.AddDisabledMenuOption(sortBy,PPSMA.SR.OlapContextMenu_SortPoints,
	            "",g_resFolder + "ChartBottomAxisD.gif");
	        PPSMA.ContextMenu.AddMenuOption(sortBy,tab+PPSMA.SR.OlapContextMenu_LargeToSmall,
	            this._chartCtxName+".Sort('1','desc');",g_resFolder + "SortAscNum.gif","",
	            enableBottomAxisSort && (this._olapViewContext.get_results().get_sortTypeCol() == 'desc'));
	        PPSMA.ContextMenu.AddMenuOption(sortBy,tab+PPSMA.SR.OlapContextMenu_SmallToLarge,
	            this._chartCtxName+".Sort('1','asc');",g_resFolder + "SortDescNum.gif","",
	            enableBottomAxisSort && (this._olapViewContext.get_results().get_sortTypeCol() == 'asc'));
	        PPSMA.ContextMenu.AddMenuOption(sortBy,tab+PPSMA.SR.OlapContextMenu_NoSort,
	            this._chartCtxName+".Sort('1','nosort');");
        }
	},
	AddBackgroundMenuItems: function PPSMA_OlapChart_Context$AddBackgroundMenuItems()
	{
	    var canNavigate = this.get_canNavigate();
	    var helper = new PPSMA.ContextMenu.OptionHelper(null, null, canNavigate, this._olapViewContext);
        this.AddFilterEmptySubMenu(canNavigate);
	    helper.Pivot(this._currentMenu, this._chartCtxName+".Pivot()");
	    PPSMA.ContextMenu.AddMenuSeparator(this._currentMenu);
	    
	    helper.ReportTypeSubMenu(this._currentMenu, this._chartCtxName, this._propertiesArray[0]);
	    if (canNavigate)
	    {
	    	var formatReportSubMenu = helper.FormatReportSubMenu(this._currentMenu);
	    	this.AddLegendLocationMenuItems(formatReportSubMenu);
	    	PPSMA.ContextMenu.AddMenuSeparator(this._currentMenu);
	    }
	    
	    helper.ShowHideInfo(this._currentMenu, this._chartCtxName +".ShowHideInfo();");        
	    return (helper.get_optionsAdded() > 0);
	},
	AddHideViewInfoBarItems: function PPSMA_OlapChart_Context$AddHideViewInfoBarItems()
	{
	    var canNavigate = this.get_canNavigate();
	    var helper = new PPSMA.ContextMenu.OptionHelper(null, null, canNavigate, this._olapViewContext);
	    helper.ShowHideInfo(this._currentMenu, this._chartCtxName +".ShowHideInfoByDiv();");        
	    return (helper.get_optionsAdded() > 0);
	},
	AddLegendLocationMenuItems: function PPSMA_OlapChart_Context$AddLegendLocationMenuItems(m)
	{
	    PPSMA.ContextMenu.AddMenuOption(m, 
            PPSMA.SR.OlapContextMenu_ChartLegendRight, 
            this._chartCtxName +".showLegendAtRight()", 
            g_resFolder + "LegendRight.gif", null,
            (this._propertiesArray[1] == PPSMA.OlapChart.LegendLocation.Right));
        PPSMA.ContextMenu.AddMenuOption(m, 
	        PPSMA.SR.OlapContextMenu_ChartLegendTop, 
	        this._chartCtxName +".showLegendAtTop()", 
	        g_resFolder + "LegendTop.gif", null,
	        (this._propertiesArray[1] == PPSMA.OlapChart.LegendLocation.Top));
	    var hideFn = this._chartCtxName +".hideLegend()";
	    if (this._propertiesArray[1] == PPSMA.OlapChart.LegendLocation.Hide) hideFn = "";
        PPSMA.ContextMenu.AddMenuOption(m, PPSMA.SR.OlapContextMenu_ChartLegendHide, hideFn);
	    return true;
	},
	set_cubeMetadata: function PPSMA_OlapChart_Context$set_cubeMetadata(dims)
	{	    
	    // this method is called back by the olapviewcontext
	    // to indicate that metadata has been returned.
	    // do nothing - context menu will poll to determine if metadata has been returned
	},
	CanDrillDownOnClick: function PPSMA_OlapChart_Context$CanDrillDownOnClick(e)
	{
	    var member = this.GetSelectedMember();
	    return ((e == null || this.isLeftClick(e)) && 
	        this.get_canNavigate() &&
	        member.get_hasChildren());
	},
    DrillDownTo: function PPSMA_OlapChart_Context$DrillDownTo(drillToHierarchyName, drillToMemberName, drillToLevelName)
    {
	    var drillFromMember = this.GetSelectedMember();
	    var drillFromHierarchy = this.GetSelectedMemberHierarchy();
        this._olapViewContext.crossDrill(drillFromHierarchy.get_name(), drillFromMember.get_name(), unescape(drillToHierarchyName), unescape(drillToMemberName), unescape(drillToLevelName));
    },	
	DrillDown: function PPSMA_OlapChart_Context$DrillDown()
	{
	    var member = this.GetSelectedMember();
	    var hierarchy = this.GetSelectedMemberHierarchy();
		this._olapViewContext.drillDown(hierarchy.get_name(),member.get_name());
	},
	DrillUp: function PPSMA_OlapChart_Context$DrillUp()
	{
	    var member = this.GetSelectedMember();
	    var hierarchy = this.GetSelectedMemberHierarchy();
	    this._olapViewContext.drillUp(hierarchy.get_name(), member.get_name());
	},
	ShowOnly: function PPSMA_OlapChart_Context$ShowOnly()
	{
	    var member = this.GetSelectedMember();
	    var hierarchy = this.GetSelectedMemberHierarchy();
	    this._olapViewContext.showOnly(hierarchy.get_name(), member.get_name());
	},
	Remove: function PPSMA_OlapChart_Context$Remove()
	{
	    var member = this.GetSelectedMember();
	    var hierarchy = this.GetSelectedMemberHierarchy();
	    this._olapViewContext.hide(hierarchy.get_name(), member.get_name());
	},
	FilterEmpty: function PPSMA_OlapChart_Context$FilterEmpty(axis)
	{
	    var iAxis = parseInt(axis);
        var empty = (this._olapViewContext.get_results().get_filterEmptyAxis()==iAxis) || (this._olapViewContext.get_results().get_filterEmptyAxis()==3);
        var sEmpty = "true";
        if (empty) sEmpty = "false";
	    this._olapViewContext.filterEmpty(axis, sEmpty);
	},

	Sort: function PPSMA_OlapChart_Context$Sort(axis,sortType)
	{
		var detailsHelper = new PPSMA.ContextMenu.DetailsHelper(this._olapViewContext,
                                this._gridCtxName,this._seriesIndex,this._pointsIndex);
        var tupleXml = detailsHelper.getCellTupleXml();	    
        if (tupleXml != null)
        {
            this._olapViewContext.sort(axis, tupleXml, sortType, "false",this._pointsIndex, this._seriesIndex);
        }
	},
	Pivot: function PPSMA_OlapChart_Context$Pivot()
	{
	    this._olapViewContext.pivot();
	},
	ShowHideInfoByDiv: function PPSMA_OlapChart_Context$ShowHideInfoByDiv()
	{
	    this._olapViewContext.toggleViewInfoBar(this._currentElement.firstChild);
	},
    ShowHideInfo: function PPSMA_OlapChart_Context$ShowHideInfo()
    {
        var img = null;
        var p = this._currentElement;
        
        while (p != null)
        {
            if (p.tagName == "MAP")
            {   
                img = p;
                break;
            }
            p = p.parentElement;
        }
        
        var viewinfodiv = null;
        if (img != null)
        {
            var pardiv = img.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_OlapChart_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();
    },
	ShowDetails: function PPSMA_OlapChart_Context$ShowDetails(resultTableIndex)
	{
	    var detailsHelper = new PPSMA.ContextMenu.DetailsHelper(this._olapViewContext,
	        this._chartCtxName,this._seriesIndex,this._pointsIndex,resultTableIndex);
	    detailsHelper.showDetails();
	},
	SwitchSeriesEvnt: function PPSMA_OlapChart_Context$SwitchSeriesEvnt()
	{
	    this.SOnC(this._switchEvent,null);
	},
	SwitchPointsEvnt: function PPSMA_OlapChart_Context$SwitchPointsEvnt()
	{
	    this.POnC(this._switchEvent,null);
	},
	SwitchTo: function PPSMA_OlapChart_Context$SwitchTo(ndx,isAxisX)
	{
	    if (!PPSMA.OlapChart.PtActiveTypes) PPSMA.OlapChart.PtActiveTypes = new PPSMA.Hashtable();
	    switch(this._actionType)
        {
            case PPSMA.OlapChart.ItemType.Series:
                this._activeSeriesLevel = ndx;
                window.setTimeout(this._chartCtxName+".SwitchSeriesEvnt()",100);
                break;
            case PPSMA.OlapChart.ItemType.Points:
                if (isAxisX)
                {
                    this._activePointsLevel = ndx;
                    this._ptActiveType = PPSMA.OlapChart.ItemType.Points;
                }
                else
                {
                    this._activeSeriesLevel = ndx;
                    this._ptActiveType = PPSMA.OlapChart.ItemType.Series;
                }
                PPSMA.OlapChart.PtActiveTypes.put(this._chartCtxName, this._ptActiveType);
                window.setTimeout(this._chartCtxName+".SwitchPointsEvnt()",100);
                break;
            default:
                break;
        }
	},
	fetchCallback: function PPSMA_OlapChart_Context$fetchCallback(smIndex)
	{
        var smProps = this._subMenus[smIndex];
		if (smProps)
	    {
		    smProps.HoverOn = true;
		    switch (smProps.Type)
		    {
		        case PPSMA.OlapChart.SubMenuType.AddActions:
		            if (!this._olapViewContext.get_menuMetaData())
		            {
		                var detailsHelper = new PPSMA.ContextMenu.DetailsHelper(this._olapViewContext,
                            this._gridCtxName,this._seriesIndex,this._pointsIndex);
                        var tupleXml = detailsHelper.getCellTupleXml();
		                this._olapViewContext.getCellLevelActions(tupleXml);
                    }
                    break;
                case PPSMA.OlapChart.SubMenuType.DrillDownTo:
		            if (!this._olapViewContext.get_cubeMetadata())
                    {
                        this._olapViewContext.loadCubeMetadata(this._chartCtxName);
                    }
                    break;
                default:
                    smProps.HoverOn = false;
                    break;
		    }
		}
	},
	populateCallback: function PPSMA_OlapChart_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.OlapChart.SubMenuType.AddActions:
		                if (this._olapViewContext.get_menuMetaData())
		                {
		                    this.populateAdditionActionsSubMenuItems(sm);
		                    smProps.IsPopulated = true;
		                }
		                break;
		            case PPSMA.OlapChart.SubMenuType.DrillDownTo:
                        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_OlapChart_Context$hoverOffCallback(smIndex)
	{
	    var sm = this._subMenus[smIndex];
	    if (sm) sm.HoverOn = false;
	},
	showLegendLocMenu: function PPSMA_OlapChart_Context$showLegendLocMenu(e)
	{
	    var currEvent = this.getEvent(e);
	    this._actionType = PPSMA.OlapChart.ItemType.LegendLocation;
	    var elem = currEvent.srcElement;
	    this._currentElement = elem.parentElement.parentElement;
	    var evt = new PPSMA.Event(e.button, e.clientX, e.clientY, this._currentElement);
	    var x = 0;
	    var y = this._currentElement.offsetHeight;
	    PPSMA.ContextMenu.Create(evt, this, x, y);
	},
	showLegendAtRight: function PPSMA_OlapChart_Context$showLegendAtRight()
	{
	    this._tempValue = PPSMA.OlapChart.LegendLocation.Right;
	    this._olapViewContext.setOlapChartLegendLocation(this._tempValue+'',
	        Function.createDelegate(this, this.legendCompleted));
	},
	showLegendAtTop: function PPSMA_OlapChart_Context$showLegendAtTop()
	{
	    this._tempValue = PPSMA.OlapChart.LegendLocation.Top;
	    this._olapViewContext.setOlapChartLegendLocation(this._tempValue+'',
	        Function.createDelegate(this, this.legendCompleted));
	},
	hideLegend: function PPSMA_OlapChart_Context$hideLegend()
	{
	    this._tempValue = PPSMA.OlapChart.LegendLocation.Hide;
	    this._olapViewContext.setOlapChartLegendLocation(this._tempValue+'',
	        Function.createDelegate(this, this.legendCompleted));
	},
	legendCompleted: function PPSMA_OlapChart_Context$legendCompleted(success)
	{
	    if (success) this._propertiesArray[1] = this._tempValue;
	},
	switchToGrid: function PPSMA_OlapChart_Context$switchToGrid()
	{
	    this._tempValue = PPSMA.ContextMenu.OlapReportType.Grid;
	    this._olapViewContext.switchOlapReportType(this._tempValue+'',
	        Function.createDelegate(this, this.switchReportTypeCompleted));
	},
	switchToBarChart: function PPSMA_OlapChart_Context$switchToBarChart()
	{
	    this._tempValue = PPSMA.ContextMenu.OlapReportType.BarChart;
	    this._olapViewContext.switchOlapReportType(this._tempValue+'',
	        Function.createDelegate(this, this.switchReportTypeCompleted));
	},
	switchToStackedBarChart: function PPSMA_OlapChart_Context$switchToStackedBarChart()
	{
	    this._tempValue = PPSMA.ContextMenu.OlapReportType.StackedBarChart;
	    this._olapViewContext.switchOlapReportType(this._tempValue+'',
	        Function.createDelegate(this, this.switchReportTypeCompleted));
	},
	switchTo100StackedBarChart: function PPSMA_OlapChart_Context$switchTo100StackedBarChart()
	{
	    this._tempValue = PPSMA.ContextMenu.OlapReportType.Stacked100BarChart;
	    this._olapViewContext.switchOlapReportType(this._tempValue+'',
	        Function.createDelegate(this, this.switchReportTypeCompleted));
	},
	switchToLineChart: function PPSMA_OlapChart_Context$switchToLineChart()
	{
	    this._tempValue = PPSMA.ContextMenu.OlapReportType.LineChart;
	    this._olapViewContext.switchOlapReportType(this._tempValue+'',
	        Function.createDelegate(this, this.switchReportTypeCompleted));
	},
	switchToLineChartWithMarkers: function PPSMA_OlapChart_Context$switchToLineChartWithMarkers()
	{
	    this._tempValue = PPSMA.ContextMenu.OlapReportType.LineChartWithMarkers;
	    this._olapViewContext.switchOlapReportType(this._tempValue+'',
	        Function.createDelegate(this, this.switchReportTypeCompleted));
	},
	switchReportTypeCompleted: function PPSMA_OlapChart_Context$switchReportTypeCompleted(success)
	{
	    if (success) this._propertiesArray[0] = this._tempValue;
	},
	populateAdditionActionsSubMenuItems: function PPSMA_OlapChart_Context$populateAdditionActionsSubMenuItems(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._chartCtxName +".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._chartCtxName +".ShowDetails('" + ddActions[i].getAttribute("resulttableindex") + "');");    
            } 
        }
        else
        {
            var elem = xdoc.getElementsByTagName("AdditionalActions");
            if (elem != null) PPSMA.ContextMenu.AddDisabledMenuOption(sm, elem[0].getAttribute("message"), "", "");    
        }
	},
    populateDrillDownToSubMenuItems: function PPSMA_OlapChart_Context$populateDrillDownToSubMenuItems(sm)
	{
	    var drillFromMember = this.GetSelectedMember();
	    var drillFromHierarchy = this.GetSelectedMemberHierarchy();
        if ((drillFromMember != null) && (drillFromHierarchy != null))
        {
            var drillFromAxisId = 'R';
            if (this._actionType == PPSMA.OlapChart.ItemType.Points && 
                this._ptActiveType == PPSMA.OlapChart.ItemType.Points)
            {
                drillFromAxisId = 'C';
            }
	        var helper = new PPSMA.ContextMenu.DrillDownToHelper(drillFromMember, drillFromHierarchy, drillFromAxisId, this._olapViewContext);
	        helper.populateSubMenuItems(sm, drillFromMember, drillFromHierarchy, this._chartCtxName + ".DrillDownTo");
	    }
	},	
	getEvent: function PPSMA_OlapChart_Context$getEvent(e)
	{
	    if (e) return e;
        if (window.event) return event;
        return null;
	},
	isLeftClick: function PPSMA_OlapChart_Context$isLeftClick(e)
	{
	    return (e.button == 1);
	},
	isRightClick: function PPSMA_OlapChart_Context$isRightClick(e)
    {
        return (e.button == 2);
    },
    get_canNavigate: function PPSMA_OlapChart_Context$get_canNavigate()
    {
        var results = this._olapViewContext.get_results();
        return results.get_canNavigate();
    } 
}
//chart resizing event handlers
PPSMA.OlapChart.ResizeTimeout=750;// milliseconds
PPSMA.OlapChart.ResizeEvnt = function PPSMA_OlapChart$ResizeEvnt(olapCtxId)
{
    var width, height;
    var server = null, catalog = null, mdx = null;
    var fcoID = null;
    var ctrlDiv = null;
    var controlId;
    
    var olapContext = PPSMA.OlapViewContext.globalIds[olapCtxId];
    if (olapContext != null)
    {
        controlId = olapContext._targetId; 
        ctrlDiv = document.getElementById(controlId);
    }
    if (ctrlDiv == null) return;

    var resizeDiv = document.getElementById(olapContext.innerTargetId);
    if (resizeDiv == null) return;
    if (!resizeDiv.isResizing) return;

    // Get Client height and width
    var hwObject = new Object();
    getHeightAndWidth(hwObject);
    if (ctrlDiv.lastHeight == hwObject.height && ctrlDiv.lastWidth == hwObject.width) return;

    height = hwObject.height;
    width = hwObject.width;
    
    // This stuff is temporary ... am not sure how this is going to get implemented
    // at this point in time. Waiting for Ramey to work out the architecture.
    if (document.getElementById("_dataSourceTextBox"))
        server = document.getElementById("_dataSourceTextBox").value;
    if (document.getElementById("_catalogTextBox"))
        catalog = document.getElementById("_catalogTextBox").value;
    if (document.getElementById("_mdxTextBox"))  
        mdx = document.getElementById("_mdxTextBox").value;
       
    if (PPSMA.OlapChart.IsValid(server) &&
        PPSMA.OlapChart.IsValid(catalog) &&
        PPSMA.OlapChart.IsValid(mdx))
    {
        width = width - 20;
        height = Math.floor(height / 3);
        resizeDiv.isReloading = true;
        olapContext.executeMDX(server, catalog, mdx, height, width);
    }
    else if (document.getElementById("FCOID"))
    {
        fcoID = document.getElementById("FCOID").value;
        
        if ((fcoID != null) && (fcoID != ""))
        {    
            width = width - 20;
            height = Math.floor(height / 3);
            resizeDiv.isReloading = true;
            olapContext.execute(height, width);
        }
    }
    resizeDiv.isResizing = false;
}
PPSMA.OlapChart.Resize = function PPSMA_OlapChart$Resize(olapContext)
{
    if (olapContext != null)
    {
        var ctrlDiv = document.getElementById(olapContext._targetId);
        var resizeDiv = null;
        if (ctrlDiv != null) resizeDiv = document.getElementById(olapContext.innerTargetId);
        if (resizeDiv == null) return;
        if (resizeDiv.isReloading) return;

        if (!resizeDiv.isResizing)
        {
            resizeDiv.isResizing = true;
            resizeDiv.timerId = setTimeout("PPSMA.OlapChart.ResizeEvnt(\"" + olapContext._ctrlProxyId + "\")", PPSMA.OlapChart.ResizeTimeout);
        }
        else
        {
            clearTimeout(resizeDiv.timerId);
            resizeDiv.timerId = setTimeout("PPSMA.OlapChart.ResizeEvnt(\"" + olapContext._ctrlProxyId + "\")", PPSMA.OlapChart.ResizeTimeout);     
        }
    }
    return false;
}
PPSMA.OlapChart.IsValid = function PPSMA_OlapChart$IsValid(s)
{
    return (s && s != "");
}

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();