var listotimes = null; 


var game_id = 1

function 
reset_countdown()
{
   listotimes = Array(); 
   game_id = 1
} 

var on_click_countdown = null; 

function 
set_on_click_countdown(occ)
{
   on_click_countdown = occ;
} 


reset_countdown(); 

function
CDTimer(start,started, countdown,time_button, len,over)
{
   this.start        = new Date(start);
   this.countdown    = countdown;
   this.started      = (started!=null)?started:"Started";
   this.over         = (over!=null)?over:"Over"; 
   this.len          = 3 * 60  * 60 ; 
   time_button.value = this.start.toLocaleString();;
   this.idx          = listotimes.push(this) -1; 
   if(on_click_countdown != null)
   {
       this.countdown.onClick = on_click_countdown; 
   }
}


function
valuize(val, name)
{
   return("" + ((val<10)?" ":"") + val + " " + name + ((val==1)?" ":"s"));
}



function
update_time2( data, now)
{
  <!-- Addaped from :  Alan Palmer -->
  <!-- Web Site:  http://www.jsr.communitech.net -->

  var diff = data.start.getTime() - now.getTime() + 1000;

  if(diff < 0)
  {
     try
    {
	    data.countdown.value =
		   ((data.len > 0) && (diff < ( 0 -data.len)) &&
		   (data.over!=null))?data.over:data.started;
    }
    catch( e)
    {


     }
  }
  else
  {

     var days         =  Math.floor(diff / (1000 * 60 * 60 * 24));
     var hours        =  Math.floor(diff / (1000 * 60 * 60 ));
     var minutes      =  Math.floor(diff / (1000 * 60  ));
     var secs         =  Math.floor(diff / (1000   ));
     var total_hours  =  Math.floor(diff / (  60 * 60 ))/1000;

     minutes %= 60;
     hours   %= 24;
     secs    %= 60;

    data.countdown.value =
     " " +
     valuize(days , "Day")       + " " +
     valuize(hours,"Hour")       + " " +
     valuize(minutes , "Minute") + " " +
     valuize( secs ,"Second"
    );

  }


}

var now_fields =  Array(); 

function
set_now_field(f)
{
   now_fields.push(f) ;
   return(true);
} 

function
update_time( )
{
   var now          = new Date();
   for(i=0;i<listotimes.length;i++)
   {
      //    alert(listotimes[i].start  + "    " + listotimes.length); 
      update_time2(listotimes[i],now);
   }
   for(i=0;i<now_fields.length;i++)
      now_fields[i].value = now.toLocaleString();;
   setTimeout("update_time()", 1000);
   return(false); 
}


