function BarChart(base,step,title)
{
this.arScores = new Array();
this.arStudents = new Array();
this.baseVal=base;
this.step=step;
this.title=title;

this.add = function(xaxis,yaxis){
		this.arScores.push(yaxis);
		this.arStudents.push(xaxis);
}


this.draw=function(){
imRed = new Image();
imYellow = new Image();
imRed.src = "http://www.case.org.sg/images/red.jpg";
imYellow.src = "http://www.case.org.sg/images/yellow.jpg";
strImage = "";
strToWrite = "";

chartHeight = 200;
maxHeight = 0;
datawidth=50;

for(i = 0; i < this.arScores.length; i++) {
 if((this.arScores[i]-this.baseVal) > maxHeight)
    maxHeight = (this.arScores[i]-this.baseVal);
}

counter=0;
mark=this.baseVal;
steps=new Array();
while(mark<(maxHeight+this.baseVal))
{
	mark=this.baseVal+(step*counter);
	steps.push(mark);
	counter++;
}


strToWrite = "<p align='center'><table bgcolor='#ffffff' cellpadding='0' cellspacing='0'><tr align='center'><th style='font-size=18;' colspan=" + (this.arStudents.length+2) + ">" + this.title + "</th></tr><tr><tr align='center'><td style='font-size=18;' colspan=" + (this.arStudents.length+2) + ">&nbsp;</th></tr><tr>";

//markings

strToWrite+="<td valign='top' align='right'>" + steps[counter-1] + "-</td>";
strToWrite+="<td rowspan="+(counter+2)+"><table border='1' bgcolor='black' cellpadding='0' cellspacing='0' width='1px' height=" + (chartHeight+40)+"><tr><td></td></tr></table></td>";

for(i = 0; i < this.arScores.length; i++) {
  strImage = "red.jpg";
  strToWrite += "<td valign=bottom align='center' rowspan=" + (counter) +"><b>"  + this.arScores[i] + "</b><br>";
  strToWrite += "<img src='" + strImage + "' height=" + parseInt(((this.arScores[i]-this.baseVal) / maxHeight) * chartHeight) + " width=" + datawidth + "  hspace=20></td>";
}

strToWrite += "</tr>"
for(i=counter-2;i>-1;i--)
{
	strToWrite+="<tr><td align='right' valign='center'>" + steps[i] + "-</td></tr>"
}
strToWrite+="<tr><td colspan="+(this.arStudents.length+2)+"><table border='1' bgcolor='black' cellpadding='0' cellspacing='0' height='1px' width=" + ((this.arStudents.length+1)*datawidth+100)+"><tr><td></td></tr></table></td></tr>";
strToWrite+="<tr><td>&nbsp;</td>";

for(i = 0; i<this.arStudents.length; i++) {
 if(i % 2 == 0)
    strToWrite += "<td width=datawidth align=center>" + this.arStudents[i] + "</td>";
 else
    strToWrite += "<td width=datawidth align=center>" + this.arStudents[i] + "</td>";
}
strToWrite += "</tr></table></p>";
document.write(strToWrite);
}
}
// -->
