/*
This script creates a date to which to count down to and then counts down to it. It is supposed to display
the decrimenting clock in the place which it is called. This must be called as an onload from the boday tag.
This script is based on a few examples I can't be bothered to cite but the combination of the scripts is
entirely my own...so there :p
*/
function countdown(y, m, d, hr, min, sec)
{
	/*The above invocation collects 6 variables from the calling of the script. They are (in order) a four
	digit year, the month (0-11), the date (1-31), the hour (0-23), the minute (0-59), the second (0-59). This
	is used for displaying the clock.*/
	year=y;
	month=m;
	day=d;
	hour=hr;
	minute=min;
	second=sec;
	var today=new Date();
	var future=new Date();
	future.setFullYear(year); //four digit year
	future.setMonth(month); //0-11
	future.setDate(day); //1-31
	future.setHours(hour); //0-23
	future.setMinutes(minute); //0-59
	future.setSeconds(second); //0-59
	dd=future-today; //The remaining time is calculated
	dday=Math.floor(dd/(60*60*1000*24)*1);
	dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
	dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
	dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);
	//Here the time is corrected to be double digit. The function to do this is below.
	dday=checkTime(dday);
	dhour=checkTime(dhour);
	dmin=checkTime(dmin);
	dsec=checkTime(dsec);
	/*This is where the script writes the time into the HTML. Because of the nature of the code, it is impossible to
	simply call a document.writeln(). The dynamic nature of the clock means that it has to be done by the innerHTML()
	method. I tried many different things but none of them worked.*/
	document.getElementById("txt").innerHTML = "ETA "+dday+ ":"+dhour+":"+dmin+":"+dsec;
	//This causes the clock to count.
	t=setTimeout('countdown(year, month, day, hour, minute, second)',1000);
	//This tests to see if the timer is up; if it is, it shows a different message..
	if (dd<=0) document.getElementById("txt").innerHTML= "Game over, man.";
}
//The above function is an infinite loop.
//The below function corrects the time to have two digits
function checkTime(i)
{
if (i<10)
  {
  i="0" + i;
  }
return i;
}

