p;
    stringTable = window.external.AppletList.WBApplet("DSApplet").StringTable;
    scriptEngine = wb.ScriptEngine.Engine;

    if(ds.GUIState && ds.GUIState.GUIDriver)
        ds.GUIState.GUIDriver.MenuListener.AddListener(3, this);

    processStateFinishedCB = ds.OnProcessingStateFinished;
	processStateFinishedCB.AddCOM(this, "Processing_State_FinishedDelegate");
    processStateStartedCB = ds.OnProcessingStateStarted;
    processStateStartedCB.AddCOM(this, "Processing_State_StartedDelegate");
	lvChangeCB = ds.Script.lv.OnChange;
	lvChangeCB.AddCOM(this, "lv_ChangeDelegate");
    
    SetVars();
    SetPageTitle();
    SetGraphProps();
    SetGraphData(true);
    SizeGraph();		//size the graph by the window size
}

function SetPageTitle()
{
    pageName.innerText = resultObj.Name;
}

function SetGraphProps()
{
    Graph1.BackColor = wb.GetWindowColor();
    Graph1.TitleClear();
    Graph1.Axes(0).LabelBold = true;		//make the x-axis title bold
    Graph1.Axes(1).LabelBold = true;		//make the y-axis title bold
    Graph1.AxesLabelPointSize = 16;			//set font size for the axis labels
    Graph1.Axes(0).LabelPointSize = 14;		//set font size for the axis labels
    Graph1.Axes(1).LabelPointSize = 14;		//set font size for the axis labels
    Graph1.Axes(0).AutomaticLimits = true;
    Graph1.Axes(1).AutomaticLimits = true;
    Graph1.Axes(0).Logarithmic = false;
    Graph1.Axes(1).Logarithmic = false;
    Graph1.PickLines = true;
    Graph1.Type = 4;		//2d line graph
    Graph1.Line2DType = 2;	//line with points
    Graph1.Axes(1).Divisions = 10;
    Graph1.Axes(0).Divisions = 5;
    Graph1.ZoomPanCtrlEnable = false;
    Graph1.style.display = "inline";
	Graph1.Sort2DData = false;
    Graph1.Axes(1).LabelFieldSignificantDigits = ds.Script.DSSigDigitsForGraph;
    Graph1.Axes(0).LabelFieldSignificantDigits = ds.Script.DSSigDigitsForGraph;
}

function SetVars()
{
    resultObj = ds.Tree.FirstActiveObject;
    solInfoObj = resultObj.Parent;

    var bAsyncSolving = ds.GUIState.AnswerSetLayer.IsAsyncJobSolving();
    if( !bAsyncSolving )
	    solInfoObj.Refresh();
	answerSetObj = solInfoObj.Parent;
	refreshTime = solInfoObj.UpdateInterval*1000;
	xAxisType = resultObj.ResultTrackerXAxisDisplay;
	isValidMultiSelect = CanShowMultipleCharts();
	allSelectedSameType = AllSelectedSameType();
	
	numLineColors    = 13;
	arrLineColor     = new Array(numLineColors);
	arrLineColor[0]  =  color(255,   0,   0);      // red
	arrLineColor[1]  =  color(0,   0,   255);      // blue
	arrLineColor[2]  =  color(255, 0,   255);    // magenta
	arrLineColor[3]  =  color(0,   255, 0);      // green
	arrLineColor[4]  =  color(0,   255, 255);    // cyan
	arrLineColor[5]  =  color(255, 255, 0);    // yellow
	arrLineColor[6]  =  color(0,   0,   0);
	arrLineColor[7]  =  color(172, 172, 172);
	arrLineColor[8]  =  color(255, 128, 64);
	arrLineColor[9]  =  color(0,   128, 0);
	arrLineColor[10] =  color(128, 0,   64);
	arrLineColor[11] = color(128, 0,   128);
	arrLineColor[12] = color(0,   128, 128);
}

function AllSelectedSameType()
{
    var activeObjs = ds.Tree.ActiveObjects;
    var activeCount = activeObjs.Count;
    if( activeCount <= 1 )
        return true;
        
    var resultType = resultObj.ResultChartType;
    for(var i=2; i<=activeCount; i++)
    {
        var curObj = activeObjs(i);
        if( curObj.ResultChartType != resultType ) 
            return false;
    }

    return true;
}

function CanShowMultipleCharts()
{
    var activeObjs = ds.Tree.ActiveObjects;
    var activeCount = activeObjs.Count;
    if( activeCount <= 1 )
        return false;
    
    var xAxisType, yAxisType, parentId;
    parentId = resultObj.Parent.ID;
    xAxisType = resultObj.ResultTrackerXAxisDisplay;
    yAxisType = resultObj.UnitString;
    
    for( var i=2; i<=activeCount; i++ )
    {
        var curObj = activeObjs(i);
        if(curObj.Class != ds.Script.id_ResultChart || curObj.Parent.Class != ds.Script.id_SolutionInfoTool)
            return false;
            
        if( parentId != curObj.Parent.ID )
            return false;
        
        if( xAxisType != curObj.ResultTrackerXAxisDisplay )
            return false;
        
        if( yAxisType != curObj.UnitString )
            return false;
    }

    return true;
}

function SetGraphLabels()
{
	if( xAxisType == 0 )  //show time
		Graph1.Axes(0).Label = stringTable.String("ID_Time") + " (" + ds.UnitSystem.UnitString(ds.Script.id_utTIME) + ")";
	else //show cumulative iteration
		Graph1.Axes(0).Label = stringTable.String("ID_CumulativeIteration");
    
    var typeStr = "";
    if (true == allSelectedSameType || false == isValidMultiSelect)
    {
        typeStr = stringForType( resultObj.ResultChartType );
	    var unitStr = resultObj.UnitString;
	    if( unitStr != "" && unitStr != " " )
	    	typeStr += " (" + resultObj.UnitString + ")";
	}
    else
    {
        var unitStr = resultObj.UnitString;
	    if( unitStr != "" && unitStr != " " )
	    	typeStr += " (" + resultObj.UnitString + ")";
    }
	Graph1.Axes(1).Label = typeStr;
}

function stringForType(resType)
{
    if( resType == ds.Script.id_Temperature )
        return stringTable.String( "ID_ResultTemperature" );
	if( resType == ds.Script.id_EquivalentStress )		
		return stringTable.String( "ID_ResultEquivalentStress" );
	if( resType == ds.Script.id_MaximumPrincipalStress )	
		return stringTable.String( "ID_ResultMaximumPrincipalStress" );
	if( resType == ds.Script.id_IntermediatePrincipalStress )	
		return stringTable.String( "ID_ResultIntermediatePrincipalStress" );
	if( resType == ds.Script.id_MinimumPrincipalStress )	
		return stringTable.String( "ID_ResultMinimumPrincipalStress" );
	if( resType == ds.Script.id_MaximumShearStress )	
		return stringTable.String( "ID_ResultMaximumShearStress" );
	if( resType == ds.Script.id_StressIntensity )	
		return stringTable.String( "ID_ResultStressIntensity" );
	if( resType == ds.Script.id_XComponentStress )	
		return stringTable.String( "ID_ResultNormalStress" );
	if( resType == ds.Script.id_YComponentStress )	
		return stringTable.String( "ID_ResultNormalStress" );
	if( resType == ds.Script.id_ZComponentStress )	
		return stringTable.String( "ID_ResultNormalStress" );
	if( resType == ds.Script.id_XYShearStress )	
		return stringTable.String( "ID_ResultShearStress" );
	if( resType == ds.Script.id_YZShearStress )	
		return stringTable.String( "ID_ResultShearStress" );
	if( resType == ds.Script.id_XZShearStress )	
		return stringTable.String( "ID_ResultShearStress" );
	if( resType == ds.Script.id_EquivalentStrain )	
		return stringTable.String( "ID_ResultEquivalentStrain" );
	if( resType == ds.Script.id_MaximumPrincipalStrain )	
		return stringTable.String( "ID_ResultMaximumPrincipalStrain" );
	if( resType == ds.Script.id_IntermediatePrincipalStrain )	
		return stringTable.String( "ID_ResultIntermediatePrincipalStrain" );
	if( resType == ds.Script.id_MinimumPrincipalStrain )	
		return stringTable.String( "ID_ResultMinimumPrincipalStrain" );
	if( resType == ds.Script.id_MaximumShearStrain )	
		return stringTable.String( "ID_ResultMaximumShearStrain" );
	if( resType == ds.Script.id_StrainIntensity )	
		return stringTable.String( "ID_ResultStrainIntensity" );
	if( resType == ds.Script.id_XComponentStrain )	
		return stringTable.String( "ID_ResultNormalStrain" );
	if( resType == ds.Script.id_YComponentStrain )	
		return stringTable.String( "ID_ResultNormalStrain" );
	if( resType == ds.Script.id_ZComponentStrain )	
		return stringTable.String( "ID_ResultNormalStrain" );
	if( resType == ds.Script.id_XYShearStrain )	
		return stringTable.String( "ID_ResultShearStrain" );
	if( resType == ds.Script.id_YZShearStrain )	
		return stringTable.String( "ID_ResultShearStrain" );
    if( resType == ds.Script.id_XZShearStrain )	
		return stringTable.String( "ID_ResultShearStrain" );
	if( resType == ds.Script.id_TotalDisplacement )	
		return stringTable.String( "ID_ResultTotalDeformation" );
	if( resType == ds.Script.id_XComponentDisplacement || resType == ds.Script.id_YComponentDisplacement ||
        resType == ds.Script.id_ZComponentDisplacement )
	    return stringTable.String( "ID_ResultDirectionalDeformation" );
	if( resType == ds.Script.id_TotalVelocity )	
		return stringTable.String( "ID_ResultTotalVelocity" );
	if( resType == ds.Script.id_XComponentVelocity || resType == ds.Script.id_YComponentVelocity ||
        resType == ds.Script.id_ZComponentVelocity || resType == ds.Script.id_XComponentVelocityRS ||
        resType == ds.Script.id_YComponentVelocityRS || resType == ds.Script.id_ZComponentVelocityRS ||
        resType == ds.Script.id_XComponentVelocityPSD || resType == ds.Script.id_YComponentVelocityPSD ||
        resType == ds.Script.id_ZComponentVelocityPSD)
	    return stringTable.String( "ID_ResultDirectionalVelocity" );
	if( resType == ds.Script.id_TotalAcceleration )	
		return stringTable.String( "ID_ResultTotalAcceleration" );
	if( resType == ds.Script.id_XComponentAcceleration || resType == ds.Script.id_YComponentAcceleration ||
        resType == ds.Script.id_ZComponentAcceleration || resType == ds.Script.id_XComponentAccelerationRS ||
        resType == ds.Script.id_YComponentAccelerationRS || resType == ds.Script.id_ZComponentAccelerationRS ||
        resType == ds.Script.id_XComponentAccelerationPSD || resType == ds.Script.id_YComponentAccelerationPSD ||
        resType == ds.Script.id_ZComponentAccelerationPSD)
	    return stringTable.String( "ID_ResultDirectionalAcceleration" );
	if( resType == ds.Script.id_ContactNumElementsInContact )
		return stringTable.String( "ID_ContactNumElementInContact" );
	if( resType == ds.Script.id_ContactCNOS )
		return stringTable.String( "ID_ContactCNOS" );
	if( resType == ds.Script.id_ContactElasticSlip )
		return stringTable.String( "ID_ContactElasticSlip" );
	if( resType == ds.Script.id_ContactMaxNormalStiffness )
		return stringTable.String( "ID_ContactMaxNormalStiffness" );
	if( resType == ds.Script.id_ContactMinNormalStiffness )
		return stringTable.String( "ID_ContactMinNormalStiffness" );
	if( resType == ds.Script.id_ContactMaxTangentialStiffness )
		return stringTable.String( "ID_ContactMaxTangentialStiffness" );
	if( resType == ds.Script.id_ContactMinTangentialStiffness )
		return stringTable.String( "ID_ContactMinTangentialStiffness" );
	if( resType == ds.Script.id_ContactResultingPinball )
		return stringTable.String( "ID_ContactResultingPinball" );
	if( resType == ds.Script.id_ContactPressure )
		return stringTable.String( "ID_ContactResultPressure" );
	if( resType == ds.Script.id_ContactPenetration )
		return stringTable.String( "ID_ContactResultPenetration" );
	if( resType == ds.Script.id_ContactGap )
		return stringTable.String( "ID_ContactResultGap" );
	if( resType == ds.Script.id_ContactFrictionalStress )
		return stringTable.String( "ID_ContactResultFrictionalStress" );
	if( resType == ds.Script.id_ContactSlidingDistance )
		return stringTable.String( "ID_ContactResultSlidingDistance" );
	if( resType == ds.Script.id_ContactNumElementsInSticking )
		return stringTable.String( "ID_ContactNumElementInStickingDefaultName" );
	if( resType == ds.Script.id_ContactContactingArea )
		return stringTable.String( "ID_ContactResultContactingArea" );
	if( resType == ds.Script.id_ContactMaxDampingPressure )
		return stringTable.String( "ID_ContactMaxDampingPressure" );
	if( resType == ds.Script.id_ContactFluidPressure )
		return stringTable.String( "ID_ContactResultFluidPressure" );
	if( resType == ds.Script.id_KineticEnergy )
		return stringTable.String( "ID_KineticEnergy" );
	if( resType == ds.Script.id_StiffnessEnergy )
		return stringTable.String( "ID_StiffnessEnergy" );
	if( resType == ds.Script.id_TOTAL_ENERGY )
		return stringTable.String( "ID_TotalEnergy" );
	if( resType == ds.Script.id_INTERNAL_ENERGY )
		return stringTable.String( "ID_InternalEnergy" );
	if( resType == ds.Script.id_PLASTIC_WORK )
		return stringTable.String( "ID_PlasticWork" );
	if( resType == ds.Script.id_X_MOMENTUM )
		return stringTable.String( "ID_XMomentum" );
	if( resType == ds.Script.id_Y_MOMENTUM )
		return stringTable.String( "ID_YMomentum" );
	if( resType == ds.Script.id_Z_MOMENTUM  )
		return stringTable.String( "ID_ZMomentum" );
	if( resType == ds.Script.id_X_TOTAL_MASS_AVE_VELOCITY )
		return stringTable.String( "ID_XTotalMassAveVelocity" );
	if( resType == ds.Script.id_Y_TOTAL_MASS_AVE_VELOCITY )
		return stringTable.String( "ID_YTotalMassAveVelocity" );
	if( resType == ds.Script.id_Z_TOTAL_MASS_AVE_VELOCITY )
		return stringTable.String( "ID_ZTotalMassAveVelocity" );
	if( resType == ds.Script.id_X_CONTACT_FORCE )
		return stringTable.String( "ID_XContactForce" );
	if( resType == ds.Script.id_Y_CONTACT_FORCE )
		return stringTable.String( "ID_YContactForce" );
	if( resType == ds.Script.id_Z_CONTACT_FORCE )
		return stringTable.String( "ID_ZContactForce" );
	if( resType == ds.Script.id_X_EXTERNAL_FORCE )
		return stringTable.String( "ID_XExternalForce" );
	if( resType == ds.Script.id_Y_EXTERNAL_FORCE )
		return stringTable.String( "ID_YExternalForce" );
	if( resType == ds.Script.id_Z_EXTERNAL_FORCE )
		return stringTable.String( "ID_ZExternalForce" );
	if( resType == ds.Script.id_VOLUME_REDUCTION_ELEMENTAL )
		return stringTable.String( "ID_StiffnessEnergy" );
	if( resType == ds.Script.id_Pressure )
		return stringTable.String( "ID_Pressure" );
	if( resType == ds.Script.id_Density )
		return stringTable.String( "ID_Density" );
	if( resType == ds.Script.id_Position )
		return stringTable.String( "ID_Positional" );		
	if (resType == ds.Script.id_ForceReactionTracker)
		return stringTable.String("ID_ForceReaction");
	if (resType == ds.Script.id_MomentReactionTracker)
	    return stringTable.String("ID_MomentReaction");
	if (resType == ds.Script.id_CONTACT_MIN_GEOMETRIC_SLIDING_DISTANCE)
        return stringTable.String("ID_MinGeometricSlidingDistance");
	if (resType == ds.Script.id_CONTACT_MAX_GEOMETRIC_SLIDING_DISTANCE)
        return stringTable.String("ID_MaxGeometricSlidingDistance");
	if (resType == ds.Script.id_DamageVariable)
	    return stringTable.String("ID_mullinsDamageVariable");
	if (resType == ds.Script.id_MaximumPreviousStrainEnergy)
	    return stringTable.String("ID_mullinsMaximumPreviousStrainEnergy");
	if (resType == ds.Script.id_MaxFailureCriteria)
	    return stringTable.String("ID_PFCMaxFailureCriteria");
	if (resType == ds.Script.id_FiberTensileFailure)
	    return stringTable.String("ID_PFCFiberTensileFailureCriterion");
	if (resType == ds.Script.id_FiberCompressiveFailure)
	    return stringTable.String("ID_PFCFiberCompressiveFailureCriterion");
	if (resType == ds.Script.id_MatrixTensileFailure)
	    return stringTable.String("ID_PFCMatrixTensileFailureCriterion");
	if (resType == ds.Script.id_MatrixCompressiveFailure)
	    return stringTable.String("ID_PFCMatrixCompressiveFailureCriterion");
	if (resType == ds.Script.id_DamageStatus)
	    return stringTable.String("ID_PDMGDamageStatus");
	if (resType == ds.Script.id_FiberTensileDamageVariable)
	    return stringTable.String("ID_PDMGFiberTensileDamageVariable");
	if (resType == ds.Script.id_FiberCompressiveDamageVariable)
	    return stringTable.String("ID_PDMGFiberCompressiveDamageVariable");
	if (resType == ds.Script.id_MatrixTensileDamageVariable)
	    return stringTable.String("ID_PDMGMatrixTensileDamageVariable");
	if (resType == ds.Script.id_MatrixCompressiveDamageVariable)
	    return stringTable.String("ID_PDMGMatrixCompressiveDamageVariable");
	if (resType == ds.Script.id_ShearDamageVariable)
	    return stringTable.String("ID_PDMGShearDamageVariable");
	if (resType == ds.Script.id_EnergyDissipatedPerUnitVolume)
	    return stringTable.String("ID_PDMGEnergyDissipatedPerUnitVolume");
	if (resType == ds.Script.id_SpringElongationTracker)
		return stringTable.String("ID_SpringElongation");
	if (resType == ds.Script.id_SpringVelocityTracker)
		return stringTable.String("ID_SpringVelocity");
	if (resType == ds.Script.id_SpringElasticForceTracker)
		return stringTable.String("ID_SpringElasticForce");
	if (resType == ds.Script.id_SpringDampingForceTracker)
		return stringTable.String("ID_SpringDampingForce");
}

function SetGraphAxisScale()
{
    //find the min/max x and y values in the graph
    var count = Graph1.Datasets.Count;
    if( 0 == count ) return;
	
    if(Graph1.Datasets(0).Count > 0)
    {
        var ymax = Graph1.Datasets(0).Max(1);
        var ymin = Graph1.Datasets(0).Min(1);
        var xmax = Graph1.Datasets(0).Max(0);
        var xmin = Graph1.Datasets(0).Min(0);
    }
	
    if(count > 1)
    {
        for(var i=1; i<count; i++)
        {
            if(Graph1.Datasets(i).Count > 0)
            {
                ymax = Math.max(ymax, Graph1.Datasets(i).Max(1));
                ymin = Math.min(ymin, Graph1.Datasets(i).Min(1));
                xmax = Math.max(xmax, Graph1.Datasets(i).Max(0));
                xmin = Math.min(xmin, Graph1.Datasets(i).Min(0));
            }
        }
    }
	
    var diff = ymax - ymin;
    Graph1.Axes(1).LabelFieldPrecision = 3;
    Graph1.Axes(0).LabelFieldPrecision = 3;
	
    if(Math.abs(ymax) >= 1000 || Math.abs(ymin) >= 1000 || 
       Math.abs(ymax) <= 1e-3 || Math.abs(ymin) <= 1e-3 || (diff < .01 && diff != 0))
    {
        Graph1.Axes(1).LabelUseExponential = true;
    }
		
    if(Graph1.Axes(0).Logarithmic == true)
    {
        Graph1.Axes(0).LabelUseExponential = true;
        Graph1.Axes(0).LabelFieldPrecision = 1;
    }
    if(Graph1.Axes(1).Logarithmic == true)
    {
        Graph1.Axes(1).LabelUseExponential = true;
        Graph1.Axes(1).LabelFieldPrecision = 2;
    }
	
    if(xmin == xmax)
    {
        Graph1.Axes(0).AutomaticLimits = false;
        Graph1.Axes(0).ImposedLimitsMin = xmin-1;
        Graph1.Axes(0).ImposedLimitsMax = xmin+1;
    }
    else
        Graph1.Axes(0).AutomaticLimits = true;
        
    if(ymin == ymax)
    {
        Graph1.Axes(1).AutomaticLimits = false;
        if(ymax == 0)
        {
            Graph1.Axes(1).ImposedLimitsMin = ymax-1;
            Graph1.Axes(1).ImposedLimitsMax = ymax+1;
        }
        else
        {
            Graph1.Axes(1).ImposedLimitsMin = ymax-Math.abs(ymax)/2;
            Graph1.Axes(1).ImposedLimitsMax = ymax+Math.abs(ymax)/2;
        }
    }
    else
        Graph1.Axes(1).AutomaticLimits = true;
    //if there is only one point, or if all points have the same value,
    //don't allow the user to click on the line to get a value
    if((xmin == xmax) && (ymin == ymax))
        Graph1.PickLines = false;
}

function SetGraphData(bAutoUpdate)
{
    var bAsyncSolving = ds.GUIState.AnswerSetLayer.IsAsyncJobSolving();
    if (!bAsyncSolving)
	    solInfoObj.Refresh();  //set the data on the object from the .nlh file
	Graph1.Datasets.Clear();  //clear any data

	var colorIndex = 0;
	var activeObjs = ds.Tree.ActiveObjects;
	var activeCount = activeObjs.Count;
	if (activeCount > 1 && false == isValidMultiSelect)
	    activeCount = 1;

	datasetIndex = 0;
	for (objIndex = 1; objIndex <= activeCount; objIndex++) {
		var currentResult = activeObjs(objIndex);
		var numVals = currentResult.NumX;
		if (numVals == 0) continue;

		Graph1.Datasets.Add();
		Graph1.Datasets(datasetIndex).PointColor = arrLineColor[colorIndex];
		Graph1.Datasets(datasetIndex).LineColor = arrLineColor[colorIndex];
		Graph1.Datasets(datasetIndex).Label = currentResult.Name;
		for (i = 0; i < numVals; i++) {
			var xVal = currentResult.XVal(i);
			var yVal = currentResult.YVal(i);
			Graph1.Datasets(datasetIndex).Add(xVal, yVal, 0);
		}

		if (currentResult.FilterType == 1 && currentResult.FilterValid) {
			var numValsFiltered = currentResult.FilterNumX;
			Graph1.Datasets.Add();
			datasetIndex++;
			colorIndex++;
			Graph1.Datasets(datasetIndex).PointColor = arrLineColor[colorIndex];
			Graph1.Datasets(datasetIndex).LineColor = arrLineColor[colorIndex];
			Graph1.Datasets(datasetIndex).Label = currentResult.Name + " [" + stringTable.String("ID_Filtered") + "]";
			for (var i = 0; i < numValsFiltered; i++) {
				var xVal = currentResult.XVal(i);
				var yVal = currentResult.FilterYVal(i);
				Graph1.Datasets(datasetIndex).Add(xVal, yVal, 0);  //since it's a 2d graph, z val is always zero
			}
		}

		datasetIndex++;
		colorIndex++;
		if (colorIndex >= numLineColors)
			colorIndex = 0;
	}

	if (activeCount > 1 || (activeCount == 1 && currentResult.FilterType == 1))
		Graph1.Legend.Visible = true;
	else
		Graph1.Legend.Visible = false;

	Graph1.Legend.Alignment = 1;
	Graph1.Legend.FrameColor = wb.GetWindowColor();

	SetGraphLabels();
	SetGraphAxisScale();
	Graph1.Draw();

	if (ds.Script.id_Solving == answerSetObj.State)
	    bShouldUpdate = true;

	bAsyncSolving = ds.GUIState.AnswerSetLayer.IsAsyncJobSolving();

	if (true == bShouldUpdate && refreshTime > 0 && true == bAutoUpdate && false == bAsyncSolving)
		setTimeout("refreshPage()", refreshTime);
}

function color(red, green, blue)
{
	return red + (256*green) + (65536*blue);
}

function window_onunload()
{
    if(ds && ds.GUIState && ds.GUIState.GUIDriver)
        ds.GUIState.GUIDriver.MenuListener.RemoveListener(3);
        
    if (processStateStartedCB)
    {
	    processStateStartedCB.RemoveCOM(this, "Processing_State_StartedDelegate");
        processStateStartedCB = null; 
    }

	if(processStateFinishedCB)
	{
	    processStateFinishedCB.RemoveCOM(this, "Processing_State_FinishedDelegate");
		processStateFinishedCB = null;
	}
	
	if (lvChangeCB)
	{
	    lvChangeCB.RemoveCOM(this, "lv_ChangeDelegate");
	    lvChangeCB = null;
	}
}

function refreshPage()
{
    SetGraphData(true);
}

function Processing_State_FinishedDelegate(sender, args)
{
	Processing_State_Finished(args.Type);
}

function Processing_State_Finished(processCode)
{
	if(processCode == 2)
	{
	    bShouldUpdate = false;
        SetGraphData(false);
	}
}

function Processing_State_StartedDelegate(sender, args)
{
	Processing_State_Started(args.Type);
}

function Processing_State_Started(processCode)
{
    if(processCode == 2)
	{
	    bShouldUpdate = true;
        SetGraphData(true);
	}
}

function window_onresize() 
{
    SizeGraph();
}

function SizeGraph()
{
    var pageWidth = document.body.offsetWidth;
    var pageHeight = document.body.offsetHeight;
    var graphWidth = parseInt(pageWidth*.9);
    var graphHeight = parseInt(pageHeight*.9);
    Graph1.style.height = graphHeight;
    Graph1.style.width = graphWidth;
}

function WriteGraphToFile(imageMode, fileName)
{
    var height = parseInt(Graph1.style.height);
    var width = parseInt(Graph1.style.width);
	
    switch( imageMode )
    {
        case 0:  //png
            Graph1.WritePngFile( fileName, width, height, true );
            break;
			
        case 1:  //jpg
            Graph1.WriteJpgFile( fileName, width, height, true );
            break;
			
        case 3:  //bmp
            Graph1.WriteBmpFile( fileName, width, height, true );
            break;
			
        default :
            break;
    }
}

function lv_ChangeDelegate(sender, args)
{
    lv_Change();
}

function lv_Change()
{
	if( xAxisType != resultObj.ResultTrackerXAxisDisplay )
	{
		xAxisType = resultObj.ResultTrackerXAxisDisplay;
		refreshPage();
	}
}

function exportDataToFile( fileName )
{
	var fileText = createTextForFile();
	ds.Script.WriteTextInFile(fileName, fileText);
}

function createTextForFile()
{
	var fileText = "";
	var count = Graph1.Datasets.Count;
	
	//write the column titles to the file
	fileText += Graph1.Axes(0).Label + "\t";
	fileText += Graph1.Axes(1).Label + "\n";
	
	//we can always use the first dataset, because for now, there should only be one
	var itemCount = Graph1.Datasets(0).Count;
	for(i=0; i<itemCount; i++)
	{
		for(var j=0; j<count; j++)
		{
			if(j == 0)
				fileText += Graph1.Datasets(j).ItemAt(i, 0) + "\t";
			fileText += Graph1.Datasets(j).ItemAt(i, 1) + "\t";
		}
		fileText += "\n";
	}

	return fileText;
}

//-->
        </SCRIPT>
    </head>
    <body LANGUAGE="javascript" onload="return window_onload()" onunload="return window_onunload()"
        onresize="return window_onresize()">
        <DIV class="gradient">
            <H1 id="pageName" LANGUAGE="javascript">&nbsp;</H1>
        </DIV>
        <center>
            <OBJECT id="Graph1" style="DISPLAY: none; LEFT: 0px; WIDTH: 806px; TOP: 0px; HEIGHT: 617px"
                height="617" 
                classid="clsid:F113A120-C83C-47B5-847C-179B339C42B7" VIEWASTEXT>
            </OBJECT>
        </center>
        <center>
        </center>
    </body>
</html>
