window.onload = function() {
	countdown(19, 2, 3, 0, 0);
}

function countdown(dateTargetYear, dateTargetMonth, dateTargetDay, dateTargetHour, dateTargetMinute) {
	dateToday = new Date();
	dateTodayYear = dateToday.getFullYear() - 2000;
	dateTodayMonth = dateToday.getMonth();
	intToday = (new Date(dateTodayYear, dateTodayMonth, dateToday.getDate(), dateToday.getHours(), dateToday.getMinutes(), dateToday.getSeconds())).getTime(); //dates to miliseconds
	intTarget = (new Date(dateTargetYear, dateTargetMonth - 1, dateTargetDay, dateTargetHour, dateTargetMinute, 0)).getTime(); //dates to miliseconds
	intTimeLeft = Math.round((intTarget - intToday) / 1000); //calc difference 
	if (intTimeLeft < 0) intTimeLeft = 0;
	
	intDays = Math.floor(intTimeLeft / (60 * 60 * 24));
	intTimeLeft %= (60 * 60 * 24);
	intHours = Math.floor(intTimeLeft / (60 * 60));
	intTimeLeft %= (60 * 60);
	intMinutes = Math.floor(intTimeLeft / 60);
	intTimeLeft %= 60;
	intSeconds = intTimeLeft;

	var strDayS = '';
	var strHourS = '';
	var strMinuteS = '';
	var strSecondsS = "";
	if (intDays != 1) strDayS ='s';
	if (intHours != 1) strHourS ='s';
	if (intMinutes != 1) strMinuteS ='s';
	if (intSeconds != 1) strSecondsS ='s';
	strOutput = intDays + ' day' + strDayS + ' ' + intHours + ' hour' + strHourS + ' ' + intMinutes + ' minute' + strMinuteS + ' and ' + intSeconds + ' second' + strSecondsS;
	strOutput += ' until the robot uprising of ' + (dateTargetYear + 2000) + '.';
	document.getElementById('countdown').innerHTML = strOutput;
	
	//recursive call to this function:
	setTimeout('countdown(' + dateTargetYear + ',' + dateTargetMonth + ',' + dateTargetDay + ',' + dateTargetHour + ',' + dateTargetMinute + ');', 1000);
}
