// <script language="javascript">
//   // when I'll turn 100, causing my own y1c problems.
//   Countdown("July 08, 2069 00:00:00");
// </script>
// *****************************************************************
// Or you can go out on a limb with:


//       CountdownLong(date, format, len);

//       date is something like: "July 08, 2069 00:00:00"
//       len is the amount of space to write the text (30 is a good number)
//       format is one of:
//           o format=1: 000000 (just the raw number of seconds)
//           o format=2: 00h 00m 00s
//           o format=3: 000d 00h 00m 00s
//           o format=4: 000day(s) 00hour(s) 00min(s) 00sec(s) 
//       so for example the above example of time till I turn 100 would be written:

//         <SCRIPT>
//         //CountdownLong(dateString,format,length);
//         CountdownLong("July 08, 2069 01:05:00",4,35);
//         </SCRIPT>

// **********************************************************************************



// permission to use and modify as long as you leave these 4 comment
// lines in tact and unmodified.
// http://www.bloke.com/javascript/Countdown/
speed=1000;
len=40;
tid = 0;
num=0;
clockA = new Array();
timeA = new Array();
formatA = new Array();
dd = new Date();
var d,x;

function doDate(x)
{
  for (i=0;i<num;i++) {
    dt = new Date();
  
    if (timeA[i] != 0) {
      v1 = Math.round(( timeA[i] - dt )/1000) ;
      if (v1 < 0)
        clockA[i].date.value = "**BANG!**";
      if (formatA[i] == 1)
        clockA[i].date.value = v1;
      else if (formatA[i] ==2) {
        sec = v1%60;
	v1 = Math.floor( v1/60);
	min = v1 %60 ;
	hour = Math.floor(v1 / 60);
	if (sec < 10 ) sec = "0"+sec;
	if (min < 10 ) min = "0"+min;
        clockA[i].date.value = hour+"h "+min+"m "+sec+"s";
        }
      else if (formatA[i] ==3) {
        sec = v1%60;
	v1 = Math.floor( v1/60);
	min = v1 %60 ;
	v1 = Math.floor(v1 / 60);
	hour = v1 %24 ;
	day = Math.floor(v1 / 24);
	if (sec < 10 ) sec = "0"+sec;
	if (min < 10 ) min = "0"+min;
	if (hour < 10 ) hour = "0"+hour;
        clockA[i].date.value = day+"d "+hour+"h "+min+"m "+sec+"s";
        }
      else if (formatA[i] ==4 ) {
        sec = v1%60;
	v1 = Math.floor( v1/60);
	min = v1 %60 ;
	v1 = Math.floor(v1 / 60);
	hour = v1 %24 ;
	day = Math.floor(v1 / 24);
	    if (day<0) {
		    clockA[i].date.value = ("0d 0h 0m 0s => Event ongoing")
		    }
		    else
          clockA[i].date.value = day+(day==1?"day ":"days ")+hour+(hour==1?"hour ":"hours ")+min+(min==1?"min ":"mins ")+sec+(sec==1?"sec ":"secs ")
        }
      else
        clockA[i].date.value = "Invalid Format spec";
      }
    else
      clockA[i].date.value = "Countdown till when?";
    }

  tid=window.setTimeout("doDate()",speed);
}

function start(d,x,format) {
  clockA[num] = x
  timeA[num] = new Date(d);
  formatA[num] = format;
//window.alert(timeA[num]+":"+d);
  if (num == 0)  
    tid=window.setTimeout("doDate()",speed);
  num++;
}

function CountdownLong(t,format,len)
{
  document.write('<FORM name=form'+num+'><input name=date size=')
  document.write(len)
  document.write(' value="Countdown: Requires Javascript"></FORM>')
  start(t,document.forms["form"+num],format);
}

function Countdown2001seconds()
{
  CountdownLong("January 01, 2001 00:00:00",1,8);
}

function Countdown2001()
{
  //CountdownLong("January 01, 2000 00:00:00",3,20);
  CountdownLong("January 01, 2001 00:00:00",4,30);
}

function Countdown(t)
{
  CountdownLong(t,4,30);
}


