/* The BarChart can be reused as long as the
   copyright notice is not removed:

   BarChart Object - Copyright 1999 InsideDHTML.com, LLC
   For more information, see www.insideDHTML.com
*/

function BarChart_AddValue(label, value,color ) {
  var newItem = this.valueList[this.valueList.length] = new Object
  newItem.label = label
  newItem.value = value
  newItem.color = color ? color : "black"
  return newItem
}

function BarChart_HTMLLabel(barItem,label,format) {
  str=  "<TD wrap valign=center WIDTH=200>"
  str+= "<FONT FACE='" + format.fontFace + "' SIZE='" + format.fontSize + "'>"
  str+= barItem.label + "&nbsp;&nbsp;</FONT></TD>"
  str+= "<TD nowrap valign=center align=center WIDTH=100>"
  str+= "<FONT FACE='" + format.fontFace + "' SIZE='" + format.fontSize + "'>"
  str+= "&nbsp;&nbsp;" + barItem.value + " " + label + "&nbsp;&nbsp;</FONT></TD>"
  return str
}

function BarChart_Draw() {
  var str = "<BR/><TABLE CELLSPACING=1 BORDER=1 CELLPADDING=1 WIDTH=500 BACKGROUND='../images/RinkBackground.gif'"
  if (this.bgColor!="")
    str+=" BGCOLOR='" + this.bgColor + "'"
  str+=">"
  if (this.caption.value!="") {
    str+="<CAPTION valign=left ALIGN='" + this.caption.alignment + "'>"
    str+="<FONT FACE='" + this.caption.fontFace + "'>" 
    str+=this.caption.value + "</FONT><BR/></CAPTION>"
  }
  var totalValue = 0
  for (var i=0;i < this.valueList.length;i++) 
    totalValue+=this.valueList[i].value
  str+="<TD ROWSPAN=" + this.valueList.length+1 + "></TD>"
  var iPercent
  for (var i=0;i < this.valueList.length;i++) {
    str+="<TR>"
    if (this.label.orientation!="right")
      str+=BarChart_HTMLLabel(this.valueList[i],this.unitLabel,this.label)
    str+="<TD ALIGN='" + this.barHOrientation + "' valign=center>"
    iPercent = this.valueList[i].value/totalValue
    str+="<TABLE BGCOLOR='" + this.valueList[i].color + "' CELLSPACING=0 "
    str+="CELLPADDING=0 HEIGHT=" + this.barHeight 
    str+=" WIDTH=" + Math.round(iPercent*this.barWidth) + ">"
    str+="<TR><TD><FONT SIZE=1> </FONT></TD>"
    if (this.valueList[i].value!=0)
    str+="<TD><FONT COLOR=white>&nbsp;&nbsp;" + Math.round(this.valueList[i].value/totalValue*100) + "&nbsp;%&nbsp;&nbsp;</FONT></TD>"
    str+="</TR></TABLE></TD>"
  }
  str +="</TABLE>"
  return str
}

function BarChart_SetCaption(caption, alignment, fontFace) {
  this.caption.value = caption
  this.caption.alignment = alignment ? alignment : "left"
  if (fontFace)
    this.caption.fontFace = fontFace
  return this.caption
}

function BarChart_FormatLabel(orientation, fontSize, fontFace) {
  this.label.orientation = orientation
  if (fontSize!=null)
    this.label.fontSize = fontSize
  if (fontFace)
    this.label.fontFace = fontFace
  return this.label
}

function BarChart() {
  this.label = this.caption = new Object
  this.valueList = new Array()
  this.addValue = BarChart_AddValue
  this.barWidth = 200
  this.barHeight= 20
  this.bgColor = "white"
  this.barHOrientation = "right"
  this.formatLabel = BarChart_FormatLabel 
  this.formatLabel("left","-1","Verdana")
  this.setCaption = BarChart_SetCaption
  this.setCaption("","top","Verdana")
  this.draw = BarChart_Draw
}