var UsedBags;
if (typeof(UsedBags)=="undefined")
   UsedBags=function(Interval) {
      this.Register();
      if (typeof(Interval)!="undefined")
         this.Interval=Interval;
      else
         this.Interval=UsedBags.DefaultUpdateInterval;
      this.TimerHandle=0;
      var d=new Date();
      d=new Date(d.getFullYear(),0,1);
      this.BaseSeconds=Date.parse(d)/1000;
      this.BaseTicks=null;
   }
UsedBags.NumBagsPerSecond=15855;
UsedBags.DefaultUpdateInterval=100;
UsedBags.Add=function(Interval)
{
   var bc=new UsedBags(Interval);
   document.write(bc.Html());
   bc.Start();
   return bc;
}
UsedBags.prototype.Register=function()
{
   if (typeof(UsedBags.Registry)=="undefined")
      UsedBags.Registry=new Array();
   this.Index=UsedBags.Registry.length;
   UsedBags.Registry[this.Index]=this;
}
UsedBags.prototype.GetSpanId=function()
{
   return "UsedBags_"+this.Index;
}
if (typeof(document.getElementById)=="function")
   UsedBags.prototype.GetSpan=function()
   {
      return document.getElementById(this.GetSpanId());
   }
else
   UsedBags.prototype.GetSpan=function()
   {
      return document.all[this.GetSpanId()];
   }
UsedBags.prototype.Html=function()
{
   return "<span id=\""+this.GetSpanId()+"\">"+this.GetBagCountString()+"</span>";
}
UsedBags.prototype.Start=function(Interval)
{
   this.Stop();
   if (typeof(Interval)!="undefined")
      this.Interval=Interval;
   this.GetBaseTicks();
   this.TimerHandle=window.setInterval("UsedBags.Registry["+this.Index+"].Update()",this.Interval,"javascript");
}
UsedBags.prototype.Stop=function()
{
   if (this.TimerHandle!=0)
   {
      window.clearInterval(this.TimerHandle);
      this.TimerHandle=0;
   }
   this.BaseTicks=null;
}
UsedBags.prototype.GetBaseTicks=function()
{
   if (this.BaseTicks==null)
      return this.SetBaseTicks();
   var t=this.BaseTicks+this.Count*this.Interval;
   if (t<Date.parse(new Date()))
       return this.SetBaseTicks();
   return t;
}
UsedBags.prototype.SetBaseTicks=function()
{
   this.BaseTicks=Date.parse(new Date());
   this.Count=0;
   return this.BaseTicks;
}
UsedBags.prototype.Update=function()
{
   this.Count++;
   this.GetSpan().innerHTML=this.GetBagCountString();
}
UsedBags.prototype.GetBagCountString=function()
{
   var secs=this.GetBaseTicks()/1000-this.BaseSeconds;
   var bags=Math.round(secs*UsedBags.NumBagsPerSecond);
   bags=bags.toString();
   var s="";
   for (var i=0;i<bags.length;i++)
   {
      if (i>0 && i%3==0)
         s=","+s;
      s=bags.charAt(bags.length-i-1)+s;
   }
   return s;
}
