var XLTimer = {};

XLTimer.Functions = new Array();
XLTimer.TimeOut = 100;
XLTimer.Identifier = -1;


XLTimer.Start = function (JSCode)
{
  if(XLTimer.Identifier == -1)
  {
    XLTimer.Functions = new Array();
    XLTimer.Functions[XLTimer.Functions.length] = JSCode;
    XLTimer.Identifier = setTimeout("XLTimer.Execute()", XLTimer.TimeOut);
    return XLTimer.Functions.length - 1;
  }
  else
  {
    XLTimer.Identifier = setTimeout("XLTimer.Execute()", XLTimer.TimeOut);
  }
  return -1;
}


XLTimer.Execute = function ()
{
  
  if(!XLCommon.IsEmpty(XLTimer.Identifier))
  {
    var ex = false;
    for(var i = 0; i < XLTimer.Functions.length; i++)
    {
      if(!XLCommon.IsEmpty(XLTimer.Functions[i]))
      {
        ex = true;
        eval(XLTimer.Functions[i]);
      }
    }
    if(ex)
    {
      XLTimer.Identifier = setTimeout("XLTimer.Execute()", XLTimer.TimeOut);
    }
    else
    {
      XLTimer.Functions = false;
      clearTimeout(XLTimer.Identifier);
      XLTimer.Identifier = -1;
    }
  }
}



XLTimer.AddCode = function (JSCode)
{
  if(XLTimer.Identifier == -1)
  {
    return XLTimer.Start(JSCode);
  }
  else
  {
    XLTimer.Functions[XLTimer.Functions.length] = JSCode;
    return XLTimer.Functions.length - 1;
  }
}


XLTimer.DelCode = function (JSCodeID)
{
  if(XLTimer.Identifier != -1)
  {
    XLTimer.Functions[JSCodeID] = "";
  }
  return true;
}
