///////////////////////////////////////
// Created By:  Tim Mann             //
// Email:       tim_mann@hotmail.com //
///////////////////////////////////////

	function scaleIt(score, optCounter, optColor, optBGColor, optHeight, optNumBoxes)
	{
		if(score == 0) return false;
		if(score === 'undefined') return false;

		//default values for the optional parameters
		if (optNumBoxes == undefined || optNumBoxes == '') optNumBoxes = 4;
		if (optNumBoxes > 100) optNumBoxes = 100;
		if (optNumBoxes < 1) optNumBoxes = 1;
		
		if (optHeight == undefined || optHeight == '') optHeight = 7;
		if (optColor == undefined || optColor == '') optColor = 'red';					
		if (optBGColor == undefined || optBGColor == '') optBGColor = 'white';	
			
		//outside table for holding the counter
		if (optCounter)document.write('<TABLE border=0 cellpadding=0 cellspacing=0><TR><TD>')
		
			//table holding the scale
			document.write('<TABLE border=1 cellpadding=0 cellspacing=0><TR>')			
				
				//Array holding number of boxes in the scale
				var cellsArray = new Array(optNumBoxes);
				
				//size of each box
				var dividedbyonehundred = eval(100/optNumBoxes)
				
				//loop through all boxes
				for (iCounter=0;iCounter<optNumBoxes;iCounter++)
				{
					//assign each box in the array a value to use in the rendering of the table
					if ((score*10) >= eval(dividedbyonehundred*eval(iCounter+1)))
					{
						cellsArray[iCounter] = eval(dividedbyonehundred*eval(iCounter+1))
					}
					else
					{
						cellsArray[iCounter] = eval((score*10)-eval(dividedbyonehundred*iCounter))
					}
				}
				
				//fill boxes with value
				for (iCounter=0;iCounter<optNumBoxes;iCounter++)
				{
					document.write('<TD><TABLE width=' + dividedbyonehundred + ' height=' + optHeight + ' cellpadding=0 cellspacing=0 border=0><TR>')
					document.write('<TD width=' + cellsArray[iCounter] + ' bgcolor=' + optColor + '></TD><TD width=' + eval(dividedbyonehundred-cellsArray[iCounter]) + ' bgcolor=' + optBGColor + '></TD>')
					document.write('</TR></TABLE></TD>')
				}
		
			//end the table
			document.write('</TR></TABLE>')
		
		//add the counter
		if (optCounter)document.write('</TD><TD class=scaleFont>&nbsp;' + score + '</TD></TR></TABLE>')
	}