function StopWatch(showTime)
{
  this.id = StopWatch.watches.length;
  StopWatch.watches[this.id] = this;
  this.showTime = typeof showTime == 'function' ? showTime : function() {};
  this.reset();
}

StopWatch.prototype.reset = function()
{
  this.time = 1800; /* ENTER TIME HERE 30min*60sec = 1800 */ 
  this.components = {};
  this.computeComponents();
  this.showTime(this.components);
}

StopWatch.prototype.start = function ()
{
  this.tid = setTimeout('StopWatch.watches[' + this.id + '].run()',1000);
}

/*
StopWatch.prototype.stop = function ()
{
  clearTimeout(this.tid);
}
*/

StopWatch.prototype.run = function ()
{
  this.tid = setTimeout('StopWatch.watches[' + this.id + '].run()',1000);
  /* this.time++; */
  if(this.time > 0) { this.time--; }
  else { this.time = 1800;location.href="index.aspx"; }  /* ENTER TIME HERE */ 
  this.computeComponents();
  this.showTime(this.components);
}

StopWatch.prototype.computeComponents = function()
{
  var hours = Math.floor(this.time / StopWatch.secondsPerHour);
  var remainingTime = this.time - hours * StopWatch.secondsPerHour;
  var minutes = Math.floor(remainingTime / StopWatch.secondsPerMinute);

  var seconds = remainingTime - minutes * StopWatch.secondsPerMinute;

  var formattedTime = '';
  /*formattedTime += hours + ':';*/
  formattedTime += minutes < 10 ? '0' + minutes + ':' : minutes + ':';
  formattedTime += seconds < 10 ? '0' + seconds : seconds;
  this.components.time = this.time;
  this.components.hours = hours;
  this.components.minutes = minutes;
  this.components.seconds = seconds;
  this.components.formattedTime = formattedTime;
}

StopWatch.secondsPerMinute = 60;
StopWatch.secondsPerHour = StopWatch.secondsPerMinute * 60;
StopWatch.watches = new Array();

/*
function showTimeFormWatch (components)
{
 document.watch0.time.value = components.formattedTime;
}
*/

/*
if(!document.layers)
document.write('<style type="text/css">input.time { text-align: right; }<\/style>');
*/

var stopWatch;
function showTimeTableWatch(components)
{
 if(document.all) document.all.timeCell.innerText = components.formattedTime;
 else if(document.getElementById) document.getElementById('timeCell').firstChild.nodeValue = components.formattedTime;
}
