// $Revision: 3870 $

var SpeedObj = new TProgressObject("SpeedObj", 13, 32, "#5FAC20", "#939393");
var ProgressObj = new TProgressObject("ProgressObj", 13, 32, "#5E5E5E", "#939393");
var ProgressObj2 = new TProgressObject2("ProgressObj", 13, 32, "#5E5E5E", "#939393");

function TProgressObject(id, height, numOfCells, activeColor, inactiveColor)
{
  this.NumOfCells = numOfCells;
  this.ActiveColor = activeColor;
  this.InactiveColor = inactiveColor;
  this.ID = id;
  //this.Width = width;
  this.Height = height;
  
  this.Place = Place;
  this.Update = Update;
  this.UpdatePercents = UpdatePercents;

  this.NumOfActiveBars = 0;

}

function Place()
{
  var res = "";
  
  res = "<table border='0' cellspacing='1' cellpadding='0' height='"+this.Height+/*"' width='"+this.Width+*/"'><tr>";
  
  for(var i = 0; i < this.NumOfCells - 1; i++)
  {
    res += "<td id='"+this.ID+String(i)+"' style='background: " + this.InactiveColor + 
          "' width='3px'></td>";
  }
  
  res += "</tr></table>";
  
  return res;
}

function Update(activeCells)
{
  var id;
  for(var i = 0; i < activeCells; i++)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(id).style.backgroundColor = this.ActiveColor;      
  }
  
  for(; i < this.NumOfCells; i++)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(id).style.backgroundColor = this.InactiveColor;
  }
}

function UpdatePercents(activeCellsPercents)
{
  if(activeCellsPercents > 100)  activeCellsPercents = 100; // auto correction

  var prevNumOfActiveBars = this.NumOfActiveBars;
  this.NumOfActiveBars = Math.floor((activeCellsPercents / 100.0) * this.NumOfCells);

  if(prevNumOfActiveBars == this.NumOfActiveBars)  return; // nothing changed

  var id;
  for(var i = prevNumOfActiveBars; i < this.NumOfActiveBars; i++)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(this.ID + String(i)).style.backgroundColor = this.ActiveColor;      
  }
  
  for(i = prevNumOfActiveBars - 1; i >= this.NumOfActiveBars; i--)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(this.ID + String(i)).style.backgroundColor = this.InactiveColor;
  }
}


function TProgressObject2(id, height, numOfCells, activeColor, inactiveColor)
{
  this.NumOfCells = numOfCells;
  this.ActiveColor = activeColor;
  this.InactiveColor = inactiveColor;
  this.ID = id;
  //this.Width = width;
  this.Height = height;

  this.NumOfActiveBars = 0;


this.GetDigitalViewID = function()
{
  return this.ID + "DigitalValue";
};

this.GetDigitalView = function()
{
  return document.getElementById(this.GetDigitalViewID());
};

this.Place = function()
{
  var res = "";
  
  res = "<table border='0' cellspacing='1' cellpadding='0' height='"+this.Height+/*"' width='"+this.Width+*/"'><tr>";
  
  for(var i = 0; i < this.NumOfCells - 1; i++)
  {
    res += "<td id='"+this.ID+String(i)+"' style='background: " + this.InactiveColor + 
          "' width='3px'></td>";
  }
  
  res += "</tr></table>";
  
  return res;
};

this.Update = function(activeCells)
{
  var id;
  for(var i = 0; i < activeCells; i++)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(id).style.backgroundColor = this.ActiveColor;      
  }
  
  for(; i < this.NumOfCells; i++)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(id).style.backgroundColor = this.InactiveColor;
  }
};

this.UpdatePercents = function(activeCellsPercents)
{
  if(activeCellsPercents > 100)  activeCellsPercents = 100; // auto correction

  var prevNumOfActiveBars = this.NumOfActiveBars;
  this.NumOfActiveBars = Math.floor((activeCellsPercents / 100.0) * this.NumOfCells);

  if(prevNumOfActiveBars == this.NumOfActiveBars)  return; // nothing changed

  var id;
  for(var i = prevNumOfActiveBars; i < this.NumOfActiveBars; i++)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(this.ID + String(i)).style.backgroundColor = this.ActiveColor;      
  }
  
  for(i = prevNumOfActiveBars - 1; i >= this.NumOfActiveBars; i--)
  {
    id = this.ID + String(i);
    if(document.getElementById(id) != undefined)
      document.getElementById(this.ID + String(i)).style.backgroundColor = this.InactiveColor;
  }
};

}

