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

