// Image-based countdown script  v1.0
// http://www.dithered.com/javascript/countdown/index.html
// code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)

var endDate;
var countdownGraphics;


//// Preload number graphics
//function countdownSetGraphics(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9) {
//	countdownGraphics = new Array(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9);
//	preloadImages(num0, num1, num2, num3, num4, num5, num6, num7, num8, num9);
//}


//// Image preloader
//function preloadImages() {
//	document.preload = new Array();
//	if (document.images) {
//		for (var i = 0; i < preloadImages.arguments.length; i++) {
//			document.preload[i] = new Image();
//			document.preload[i].src = preloadImages.arguments[i];
//		}
//	}
//}

// Initialize and start the countdown
function countdownInit(year, month, day, hour, minute, second) {

	// set date to countdown to
	endDate = new Date(year, month - 1, day, ( (hour) ? hour : 0), ( (minute) ? minute : 0), ( (second) ? second : 0));
	
	// start countdown
	countdownUpdate();
	setInterval('countdownUpdate()', 1000);
}


// Update the countdown display
function countdownUpdate() {	
			var separator = ':';

			// calculate the time until countdown end date
			var now = new Date();
			var difference = endDate - now;

			
				
				// decompose difference into days, hours, minutes and seconds parts
				var days    = parseInt(difference / 86400000) + '';
				var hours   = parseInt((difference % 86400000) / 3600000) + '';
				var minutes = parseInt((difference % 3600000) / 60000) + '';
				var seconds = parseInt((difference % 60000) / 1000) + '';
				
				if (seconds == 0 & minutes == 0)
				{
					// **************** don't forget to change this !!!!!! *****************
					window.location = "../Cart/CartTimeout.aspx";
				}
//				else
//				{
//					// negative values should be set to 0
//					// single digit values should have a '0' prepended to them
//					if (isNaN(days) || days.charAt(0) == '-') days = '0000';
//					else if (days.length == 1) days = '000' + days;
//					else if (days.length == 2) days = '00' + days;
//					else if (days.length == 3) days = '0' + days;
//					if (isNaN(hours) || hours.charAt(0) == '-') hours = '00';
//					else if (hours.length == 1) hours = '0' + hours;
//					if (isNaN(minutes) || minutes.charAt(0) == '-') minutes = '00';
//					else if (minutes.length == 1) minutes = '0' + minutes;
//					if (isNaN(seconds) || seconds.charAt(0) == '-') seconds = '00';
//					else if (seconds.length == 1) seconds = '0' + seconds;

//					// change countdown graphics
//					if (document.images['countdown_d1000']) document.images['countdown_d1000'].src = countdownGraphics[parseInt(days.charAt(0))];
//					if (document.images['countdown_d100']) document.images['countdown_d100'].src = countdownGraphics[parseInt(days.charAt(1))];
//					if (document.images['countdown_d10']) document.images['countdown_d10'].src = countdownGraphics[parseInt(days.charAt(2))];
//					if (document.images['countdown_d1']) document.images['countdown_d1'].src = countdownGraphics[parseInt(days.charAt(3))];
//					if (document.images['countdown_h10']) document.images['countdown_h10'].src = countdownGraphics[parseInt(hours.charAt(0))];
//					if (document.images['countdown_h1']) document.images['countdown_h1'].src = countdownGraphics[parseInt(hours.charAt(1))];
//					if (document.images['countdown_m10']) document.images['countdown_m10'].src = countdownGraphics[parseInt(minutes.charAt(0))];
//					if (document.images['countdown_m1']) document.images['countdown_m1'].src = countdownGraphics[parseInt(minutes.charAt(1))];
//					if (document.images['countdown_s10']) document.images['countdown_s10'].src = countdownGraphics[parseInt(seconds.charAt(0))];
//					if (document.images['countdown_s1']) document.images['countdown_s1'].src = countdownGraphics[parseInt(seconds.charAt(1))];
//				}
}
