/* this code copyright 2007 Tom Churm, all rights reserved, no copying without permission */
//if (top.location != document.location) top.location = document.location;

c1 = new Image(); c1.src = "countdown/c1.gif";
c2 = new Image(); c2.src = "countdown/c2.gif";
c3 = new Image(); c3.src = "countdown/c3.gif";
c4 = new Image(); c4.src = "countdown/c4.gif";
c5 = new Image(); c5.src = "countdown/c5.gif";
c6 = new Image(); c6.src = "countdown/c6.gif";
c7 = new Image(); c7.src = "countdown/c7.gif";
c8 = new Image(); c8.src = "countdown/c8.gif";
c9 = new Image(); c9.src = "countdown/c9.gif";
c0 = new Image(); c0.src = "countdown/c0.gif";
cb = new Image(); cb.src = "countdown/cb.gif";
onePix = new Image(); onePix.src = "countdown/clear.gif";

function extract(d,h,m,s,type) {
if (!document.images) return;
if (d < 1) 
{
	document.images.a.src = onePix.src;
	document.images.a.width = 1;
	document.images.b.src = onePix.src;
	document.images.b.width = 1;
	document.images.c.src = onePix.src;
	document.images.c.width = 1;
	document.images.d.src = onePix.src;
	document.images.d.width = 1;
}
else
{
	if (d <= 9) {
	document.images.a.src = onePix.src;
	document.images.a.width = 1;
	//document.images.b.src = onePix.src;
	document.images.b.src = "countdown/c0.gif";
	document.images.c.src = eval("c"+d+".src");
	}
	else 
	{
		if (d < 100) 
		{
			document.images.a.src = onePix.src;
			document.images.a.width = 1;
			document.images.b.src = eval("c"+Math.floor(d/10)+".src");
			document.images.c.src = eval("c"+(d%10)+".src");
		}
		else
		{
			var numHundreds = Math.floor(d/100);
			document.images.a.src = eval("c"+numHundreds+".src");
			var numTens = d - (numHundreds*100);
			document.images.b.src = eval("c"+Math.floor(numTens/10)+".src");
			document.images.c.src = eval("c"+(d%10)+".src");
		}

	}
}
if (h <= 9) {
document.images.e.src = c0.src;
document.images.f.src = eval("c"+h+".src");
}
else {
document.images.e.src = eval("c"+Math.floor(h/10)+".src");
document.images.f.src = eval("c"+(h%10)+".src");
}
if (m <= 9) {
document.images.h.src = c0.src;
document.images.i.src = eval("c"+m+".src");
}
else {
document.images.h.src = eval("c"+Math.floor(m/10)+".src");
document.images.i.src = eval("c"+(m%10)+".src");
}
if (s <= 9) {
document.k.src = c0.src;
document.images.l.src = eval("c"+s+".src");
}
else {
document.images.k.src = eval("c"+Math.floor(s/10)+".src");
document.images.l.src = eval("c"+(s%10)+".src");
}
}
function showCountdown() 
{
if (!document.images){
return;
}
var today = new Date();
var target = new Date(theTargetDate);
var timediff = (  target.getTime()-today.getTime()  );
var oneMinute=1000*60 //minute unit in seconds
var oneHour=1000*60*60 //hour unit in seconds
var oneDay=1000*60*60*24 //day unit in seconds
var dayfield=Math.floor(timediff/oneDay);
var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour);
var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute);
var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute)/1000);

	if(timediff <0)
	{
	}
	else
	{
		extract(dayfield,hourfield, minutefield, secondfield);
		setTimeout("showCountdown()", 1000);
	}

}

function changeImageSize(widthA,heightA,widthB,heightB)
{
	//image array 0-8
	for (i = 1; i <= 12; i++)
	{	
		//if we're showing clear.gif, make sure it's 1x1 pixel
		if(document.images[i].src==onePix.src)
		{
			document.images[i].width = 1;
			document.images[i].height = 1;
		}
		//small colon images
		else if( (i==4)||(i==5)||(i==10) )
		{
			document.images[i].width = widthB;
			document.images[i].height = heightB;
		}
		//normal numbers
		else
		{
			document.images[i].width = widthA;
			document.images[i].height = heightA;
		}
	}
}
function changeBackground(color)
{
	document.bgColor=color;
	document.getElementById('countdownDisp').style.backgroundColor=color;
}
function removeUnderline(linknumber)
{
	for (i = 0; i <4; i++)
	{
		if(i==linknumber)
		{
			document.links[i].style.textDecoration = "none";
			document.links[i].style.fontWeight = "normal";
		}
		else
		{
			document.links[i].style.textDecoration = "underline";
			document.links[i].style.fontWeight = "bold";
		}
	}
}
function removeUnderline2(linknumber)
{
	for (i = 4; i <9; i++)
	{
		if(i==linknumber)
		{
			document.links[i].style.textDecoration = "none";
			document.links[i].style.fontWeight = "normal";
		}
		else
		{
			document.links[i].style.textDecoration = "underline";
			document.links[i].style.fontWeight = "bold";
		}
	}
}

function addLeadingZero(x) {
      return ((x<0 || x>9) ?"":"0") + x;
}


function checkDate(string)
{
    if(!string) return null;
    string += '';

    string = string.replace(/[^0-9^-]/g, '');

    var split = string.split("-");
    var day = parseInt(split[2], 10);
    var month = parseInt(split[1] || 0, 10);
    var year = parseInt(split[0] || 0, 10);

    if(isNaN(year)) year = check.getFullYear();;

    var check = new Date(year, month - 1, day);
    var day2 = check.getDate();
    var year2 = check.getFullYear();
    var month2 = check.getMonth() + 1;

    if ( year2 == year && month == month2 && day == day2 ) return check;
    return null;
}  


