// (c) 2003 LeProZy
// Take these broken wings.
// JAVA IS FOR PUSSIES.

today		= 0;
the_day		= 0;
the_day_end	= 0;
timeleft	= 0;
flag_stop   = false;
txt_during	= "LANur pågår!";
txt_after	= "LANur er slutt.";

function repeat() 
	{
	down("COUNTDOWN");
	if (!flag_stop) {
		setTimeout("repeat()",1000);
		}
	}

function start() 
	{
	ctstart	= document.forms["COUNTDOWN"].CTSTART.value;
	ctend	= document.forms["COUNTDOWN"].CTEND.value;
	
	today		= (new Date()).getTime();
	the_day		= (new Date(ctstart)).getTime();
	the_day_end = (new Date(ctend)).getTime();
	
	// timeleft is in millisecs
	timeleft = (the_day - today) / 1000;
	
	repeat();
	}

function down(box)
	{
	timeleft = timeleft - 1;
	ctleft = timeleft;

	days	= (ctleft - (ctleft % 86400)) / 86400;
	ctleft	= ctleft - (days * 86400);
	hours	= (ctleft - (ctleft % 3600)) / 3600;
	ctleft	= ctleft - (hours * 3600);
	mins	= (ctleft - (ctleft % 60)) / 60;
	ctleft	= ctleft - (mins * 60);
	secs	= Math.round(ctleft);
	if (secs == 60) secs = 59;
	
	if (timeleft < 1 &&  today < the_day_end) {
		// there she goes
		document.forms[box].time.value = txt_during;
		} else
	if (today > the_day_end) {
		// seems like a bitch to me.
		document.forms[box].time.value = txt_after;
		flag_stop = true;
		} else {
		// oh, look at that ass. (this is actually valid js syntax)
		if (days == 1) out = "1 dag, ";
		else out = days + " dager, ";
		
		if(hours < 10) out = out + "0";
		out = out + hours + ":";
		
		if(mins < 10) out = out + "0";
		out = out + mins + ":";
		
		if(secs < 10) out = out + "0";
		out = out + secs;
		
		document.forms[box].time.value = out;
		}
	}
	
start();


