var dateFromX = [];
var dateArr   = [];

function calcEnd(date)
{
	//dateFromX = (date.replace(/\//g,","));
	dateFromX = date.split('/');
	makeDat();
	
}

function makeDat()
{
	//dateFuture = new Date(2011,0,8);
	dateFuture = new Date(dateFromX[2],dateFromX[0] - 1,dateFromX[1]);
	GetCount();
}



//###################################
//nothing beyond this point
function GetCount()
{

	dateNow = new Date();									//grab current date
	amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
	delete dateNow;

	// time is already past
	if(amount < 0)
	{
		document.getElementById('countbox').innerHTML = "Now!";
	}
	// date is still good
	else
	{
		days=0; hours=0; mins=0; secs=0; out="";

		amount = Math.floor(amount/1000); //kill the "milliseconds" so just secs

		days   =Math.floor(amount/86400); //days
		amount =amount%86400;

		hours  =Math.floor(amount/3600); //hours
		amount =amount%3600;

		mins   =Math.floor(amount/60); //minutes
		amount =amount%60;

		secs=Math.floor(amount); //seconds
		
		
		if(days != 0 || days == 0)
		{
			// this condition if to put a zero, example 08, to not look like this 8.
			if(days.toString().length < 2)
			{
				days = '0' + days;	
			}
			
			out += days +" day"+((days!=1)?"s":"")+", ";
		}
		
		
		if(days != 0 || hours != 0)
		{
			if(hours.toString().length < 2)
			{
				hours = '0'	+ hours;
			}
			
			out += hours +" hour"+((hours!=1)?"s":"")+", ";
		}
		
		if(days != 0 || hours != 0 || mins != 0)
		{
			if(mins.toString().length < 2)
			{
				mins = '0' + mins;	
			}
			
			out += mins +" minute"+((mins!=1)?"s":"")+", ";
		}
		
		if(secs.toString().length < 2)
		{
			secs = '0' + secs;	
		}
		out += secs +" seconds";
		
		
		//document.getElementById('countbox').innerHTML=out;
		
		document.getElementById('box_days').innerHTML  = days;
		document.getElementById('box_hours').innerHTML = hours;
		document.getElementById('box_mins').innerHTML  = mins;
		document.getElementById('box_secs').innerHTML  = secs;
		
		setTimeout("GetCount()", 1000);
	}
}
