
function SpacerGif(height,width)
{return"<img src=\""+path+"img/budgetcalculatorspacer.gif\" width=\""+width+"\" height=\""+height+"\" border=\"0\"/>";}
function GraphGenerator()
{this.ScaleXMin=0;this.ScaleXMax=0;this.ScaleYMin=0;this.ScaleYMax=0;this.ScaleXAuto=true;this.ScaleYAuto=true;this.ScaleYFormat="";this.ScaleXFormat="";this.ScaleX=1;this.ScaleY=1;this.aBar=new Array();this.nBars=0;this.drawXAxis=true;this.drawYAxis=true;this.drawXScale=true;this.drawYScale=true;this.drawLegend=true;this.Height=200;this.ScaleHeight=20;this.ScaleWidth=36;this.barWidth=10;this.BarSpacing=2;this.AxisColor="#CCCCCC";this.ScaleColor="#000000";this.ScaleXSeparator="1px dotted #CCCCCC";this.NegativeYAxis=false;}
function SetScaleX(Max,Auto,Format)
{this.ScaleXMin=0;this.ScaleXMax=parseFloat(Max);this.ScaleXAuto=Auto;this.ScaleXFormat=Format;}
function SetScaleY(Max,Auto,Format)
{this.ScaleYMin=parseFloat(Max)-(parseFloat(Max)*2);this.ScaleYMax=parseFloat(Max);this.ScaleYAuto=Auto;this.ScaleYFormat=Format;}
function AddBar(objBar)
{this.nBars=this.nBars+1;this.aBar[this.nBars]=objBar;}
function AutoScaleY()
{currentMax=this.ScaleYMax;for(X2=1;X2<=this.nBars;X2++)
{thisBar=this.aBar[X2];for(DataItem=0;DataItem<=thisBar.DataItems;DataItem++)
{thisValue=Math.abs(thisBar.Data[DataItem]);if(thisValue>currentMax)
currentMax=thisValue;}}
this.ScaleYMax=currentMax;if(this.NegativeYAxis)
{this.ScaleYMin=this.ScaleYMax-(this.ScaleYMax*2)}
else
{this.ScaleYMin=0;}}
function AutoScaleX()
{currentMax=-1;for(X2=1;X2<=this.nBars;X2++)
{thisBar=this.aBar[X2];if((thisBar.DataItems<currentMax)||(currentMax==-1))
currentMax=thisBar.DataItems;}
if(currentMax==-1)
currentMax=0;this.ScaleXMax=currentMax;this.ScaleXMin=0;}
function Draw()
{if(this.nBars==0)
{Output("No bars have been setup for the Graph");return;}
if(this.ScaleYAuto)
this.AutoScaleY();if(this.ScaleXAuto)
this.AutoScaleX();if(this.ScaleXMax==0)
{Output("No Data is available to draw the Graph");return;}
if(this.NegativeYAxis)
{this.AxisHeight=this.Height/2;}
else
{this.AxisHeight=this.Height-(this.ScaleHeight/2);}
strGraph="";strGraph=strGraph+"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" Height=\""+(parseInt(this.Height)+1)+"\"  Width=\""+(parseInt(this.ScaleWidth)*parseInt(this.ScaleXMax)+20)+"\">";strGraph=strGraph+"<tr>";if(this.drawYScale)
{strGraph=strGraph+"<td rowspan=\"3\" ";if(!this.NegativeYAxis)
strGraph=strGraph+"valign=\"bottom\" ";strGraph=strGraph+">";strGraph=strGraph+"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";Steps=parseInt(((this.Height-this.ScaleHeight)/2)/this.ScaleHeight);if(!this.NegativeYAxis)
Steps=Steps*2;this.ScaleY=(this.ScaleYMax/Steps)/this.ScaleHeight;for(iScale=Steps;iScale>=1;iScale--)
{strGraph=strGraph+"<tr>";ScaleNumber=parseInt(((this.ScaleYMax/Steps)*iScale)*10)/10;if(this.ScaleYFormat!="")
{ScaleNumber=eval(this.ScaleYFormat+"(\""+ScaleNumber+"\")");}
strGraph=strGraph+"<td height=\""+this.ScaleHeight+"\" class=\"graphYScale\" nowrap>"+ScaleNumber+"&nbsp;</td><td class=\"graphYScale\" align=\"right\"><font color=\""+this.AxisColor+"\">-</font></td>";strGraph=strGraph+"</tr>";}
strGraph=strGraph+"<tr>";strGraph=strGraph+"<td class=\"graphYScale\" nowrap>0&nbsp;</td><td class=\"graphYScale\" align=\"right\"><font color=\""+this.AxisColor+"\">-</font></td>";strGraph=strGraph+"</tr>";if(this.NegativeYAxis)
{for(iScale=1;iScale<=Steps;iScale++)
{strGraph=strGraph+"<tr>";ScaleNumber=parseInt(((this.ScaleYMin/Steps)*iScale)*10)/10;if(this.ScaleYFormat!="")
ScaleNumber=eval(this.ScaleYFormat+"(\""+ScaleNumber+"\")");strGraph=strGraph+"<td height=\""+this.ScaleHeight+"\" class=\"graphYScale\" nowrap>"+ScaleNumber+"&nbsp;</td><td class=\"graphYScale\" align=\"right\"><font color=\""+this.AxisColor+"\">-</font></td>";strGraph=strGraph+"</tr>";}}
strGraph=strGraph+"</table>";strGraph=strGraph+"</td>";}
if(this.drawYAxis)
{strGraph=strGraph+"<td rowspan=\"3\" class=\"graphAxis\">"+SpacerGif(1,1)+"</td>";}
for(X=this.ScaleXMin;X<=(this.ScaleXMax-1);X++)
{for(X2=1;X2<=this.nBars;X2++)
{thisBar=this.aBar[X2];strGraph=strGraph+"<td width=\""+(this.ScaleWidth/this.nBars)+"\" height=\""+this.AxisHeight+"\" valign=\"bottom\" class=\"graphBar\" style=\"";if((X2==this.nBars)&&(this.ScaleXSeparator!=""))
{strGraph=strGraph+"padding-right: 1px; border-right: "+this.ScaleXSeparator+";"}
strGraph=strGraph+"background-image: url("+thisBar.strAltImage+");\">";if(thisBar.Data[X]>0)
{strGraph=strGraph+"<img src=\""+thisBar.strImage+"\" width=\""+this.barWidth+"\" height=\""+Math.abs(thisBar.Data[X]/this.ScaleY)+"\" title=\""+eval(this.ScaleYFormat+"("+thisBar.Data[X]+")")+"\" border=\"0\">";}
else
{strGraph=strGraph+SpacerGif(1,this.barWidth);}
strGraph=strGraph+"</td>";}}
strGraph=strGraph+"</tr>";if(this.drawXAxis)
{strGraph=strGraph+"<tr>";strGraph=strGraph+"<td colspan=\""+(X*(X2-1))+"\" class=\"graphAxis\">"+SpacerGif(1,1)+"</td>";strGraph=strGraph+"</tr>";}
strGraph=strGraph+"<tr>";if(this.NegativeYAxis)
{for(X=this.ScaleXMin;X<=(this.ScaleXMax-1);X++)
{for(X2=1;X2<=this.nBars;X2++)
{thisBar=this.aBar[X2];strGraph=strGraph+"<td width=\""+(this.ScaleWidth/this.nBars)+"\" height=\""+(this.AxisHeight-1)+"\" valign=\"top\" class=\"graphBar\" style=\"";if((X2==this.nBars)&&(this.ScaleXSeparator!=""))
{strGraph=strGraph+"padding-right: 1px; border-right: "+this.ScaleXSeparator+";";}
strGraph=strGraph+"background-image: url("+thisBar.strAltImage+";\">";if(thisBar.Data[X]<0)
{strGraph=strGraph+"<img src=\""+thisBar.strImage+"\" width=\""+this.barWidth+"\" height=\""+Math.abs(thisBar.Data[X]/this.ScaleY)+"\" title=\""+eval(this.ScaleYFormat+" ("+thisBar.Data[X]+")")+"\" border=\"0\">";}
else
{strGraph=strGraph+SpacerGif(1,this.barWidth);}
strGraph=strGraph+"</td>";}}}
else
{strGraph=strGraph+"<td height=\""+((this.ScaleHeight/2)-1)+"\" class=\"graphBar\">"+SpacerGif(1,1)+"</td>";}
strGraph=strGraph+"</tr>";if(this.drawXScale)
{strGraph=strGraph+"<tr>";if(this.drawYScale)
{strGraph=strGraph+"<td>"+SpacerGif(1,1)+"</td>";}
if(this.drawYAxis)
{strGraph=strGraph+"<td style=\"width: 1px;\">"+SpacerGif(1,1)+"</td>";}
for(iXScale=1;iXScale<=this.ScaleXMax;iXScale++)
{strGraph=strGraph+"<td width=\""+this.ScaleWidth+"\" colspan=\""+this.nBars+"\" class=\"graphXScale\">"+iXScale+"</td>";}
strGraph=strGraph+"</tr>";}
if(this.drawLegend)
{LegendSpan=this.ScaleXMax*this.nBars;if(this.drawYScale)
LegendSpan=LegendSpan+1;if(this.drawYAxis)
LegendSpan=LegendSpan+1;strGraph=strGraph+"<tr>";strGraph=strGraph+"<td colspan=\""+LegendSpan+"\" class=\"graphXScale\">";for(iLegend=1;iLegend<=this.nBars;iLegend++)
{thisBar=this.aBar[iLegend];strGraph=strGraph+"<img src=\""+thisBar.strImage+"\" width=\"10\" height=\"10\" border=\"0\">&nbsp;"+thisBar.Name+"&nbsp;&nbsp;";}
strGraph=strGraph+"</td>";strGraph=strGraph+"</tr>";}
strGraph=strGraph+"</table>";document.getElementById("divResults").innerHTML=strGraph;}
function Output(strOutput)
{document.getElementById("divResults").innerHTML="<span style=\"font-family: Tahoma; font-size: 11px; font-weight: bold; color: #CC3333;\">["+strOutput+"]</span>";}
function updateBalanceValues(strMaximumBalance,strMinimumBalance)
{CurrencyDecimal=",";CurrencyPosition="Suffix";CurrencySymbol=" \u20AC";CurrencyGroup=" ";var balanceField=document.getElementById("MaximumBalance");if(balanceField)
{balanceField.value=FormatCurrency(strMaximumBalance);}
balanceField=document.getElementById("MinimumBalance");if(balanceField)
{balanceField.value=FormatCurrency(strMinimumBalance);}}
GraphGenerator.prototype.SetScaleX=SetScaleX;GraphGenerator.prototype.SetScaleY=SetScaleY;GraphGenerator.prototype.AddBar=AddBar;GraphGenerator.prototype.AutoScaleY=AutoScaleY;GraphGenerator.prototype.AutoScaleX=AutoScaleX;GraphGenerator.prototype.Draw=Draw;GraphGenerator.prototype.Output=Output;