function Timer()
{
  var timerID = null;
  var timerRunning = false;
  var delay = 1000;
  var secs;
  var initsecs;
  var timehandler='';
  var i = this;

  this.InitializeTimer = function(secstime,functionhandler)
  {
      // Set the length of the timer, in seconds
    secs = secstime;
    initsecs=secs;
    timehandler=functionhandler;
    i.StopTheClock()
        if(secs>0)i.StartTheTimer()
  }
  this.ResetTimer =function()
  {
    secs=initsecs;
  }
  this.StopTimer =function()
  {
    i.StopTheClock();
  }

  this.StopTheClock = function()
  {
    if(timerRunning)
    clearTimeout(timerID)
    timerRunning = false
  }


  this.TimeEvent = function()
  {
    if(timehandler!='')timehandler();
  }

  this.StartTheTimer = function()
  {
    if (secs==0)
    {
      i.StopTheClock()
          i.TimeEvent();
    }
    else
    {
      secs = secs - 1
          timerRunning = true
          timerID = self.setTimeout(function(){i.StartTheTimer();}, delay)
    }
  }
}