
// ****  Time Zone Count Down Javascript  **** //
/*
Visit http://rainbow.arch.scriptmania.com/scripts/
 for this script and many more
 
 This is a countdown timer with a difference. It doesn't just display the time remaining until the clock on your visitor's computer reaches a specified date and time. It counts down until a specific date and time is reached at the page location. So I am in New York, USA (timezone -5) so if you are located in London, UK (timezone +0) then the countdown timer will show 5 hours more than you would expect there to be until the specified time because the timezone countdown timer is counting down to that time in New York, not London.

The script able do this because it both takes into account the timezone offset of your visitor's computer and also allows you to specify the timezone offset that you want it to apply to, so as to save you the effort of adjusting the time that you enter to UTC.   International Time Zones can be found here.
The month can be specified as a number between 1 and 12 to indicate which month of the year that you are counting down to (it will assume next year if the month has already past for this year) or you can specify '*' to have the counter select the appropriate date within the next month. If you do specify a numeric month then the countdown will stop once it reaches zero with a "Sorry Too Late" message but if it is set to monthly then it will automatically restart the countdown for the next month (but only if the page is reloaded). You can also set the month to '0' which will always be matched to the current month.
The day can be specified as a given day of the month (1 through 31) or you can put a + in front of a number to indicate so many days in the future (useful for "limited time offers" that never expire). You can even specify '+0' to countdown to a specific time each day.
The hour should be specified in 'military time' (ie. between 0 and 23, 0 = midnight, 23 = 11 p.m.) to indicate the time of day that the offer expires.

The timezone offset is also specified in hours and should be the number of hours that your local time is ahead (positive number) or behind (negative number) Universal Coordinated Time (UTC also known as GMT or Zulu Time).
You would only need to adjust the timezone if you want the daylight saving at your location taken into account.

The following are some combination examples that you may find useful.

    * To countdown to the end of each month - month = '*', day = '1', hour = 0
    * To countdown to the 21st of each month - month = '0', day = '21', hour = 0
    * To countdown to the end of each day - month = '0', day = '+1', hour = 0
    * To countdown to Noon tomorrow - month = '0', day = '+1', hour = 12
    * To countdown to 4 p.m. today - month = '0', day = '+0', hour = 16
    * To countdown to Christmas - month = '12', day = '25', hour = 0
*/

////////// CONFIGURE THE COUNTDOWN SCRIPT HERE //////////////////
var year = '2009'
var month = '3';     //  '*' for next month, '0' for this month or 1 through 12 for the month 
var day = '29';        //  Offset for day of month day or + day  
var hour = 18;        //  0 through 23 for the hours of the day
var tz = -7;          //  Offset for your timezone in hours from UTC
var lab = 'tzcd';      //  The id of the page entry where the timezone countdown is to show

function start() {displayTZCountDown(setTZCountDown(year,month,day,hour,tz),lab);}

    // **    The start function can be changed if required   **
window.onload = start;

////////// DO NOT EDIT PAST THIS LINE //////////////////

function setTZCountDown(year,month,day,hour,tz) 
{
	var toDate = new Date();
	//debugger;
	if(year)
	{
		toDate.setYear(year);
	}
	
	
	if (month == '*')
	{
		toDate.setMonth(toDate.getMonth() + 1);
	}
	else if (month >= 0) 
	{ 
		//if (month <= toDate.getMonth()) 
		//{
		//		toDate.setYear(toDate.getYear() + 1);
		//}
		toDate.setMonth(month-1);
	}
	
	if (day.substr(0,1) == '+') 
	{
		var day1 = parseInt(day.substr(1));
		toDate.setDate(toDate.getDate()+day1);
	} 
	else
	{
		toDate.setDate(day);
	}
	
	toDate.setHours(hour);
	toDate.setMinutes(0-(tz*60));
	toDate.setSeconds(0);
	
	var fromDate = new Date();
	fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
	
	var diffDate = new Date(0);
	diffDate.setMilliseconds(toDate - fromDate);
	return Math.floor(diffDate.valueOf()/1000);
}

function displayTZCountDown(countdown,tzcd) 
{
	if(document.getElementById(tzcd) != null)
	{
		if (countdown < 0) 
		{
			//document.getElementById(tzcd).innerHTML = "Sorry, you are too late."; 
			document.getElementById(tzcd).innerHTML = "Kickoff!"; 
		}
		else 
		{
			var secs = countdown % 60; 
			if (secs < 10) secs = '0'+secs;
			var countdown1 = (countdown - secs) / 60;
			
			var mins = countdown1 % 60; 
			if (mins < 10) mins = '0'+mins;
			countdown1 = (countdown1 - mins) / 60;
			
			var hours = countdown1 % 24;
			if (hours < 10) hours = '0'+hours;
			var days = (countdown1 - hours) / 24;
			
			//document.getElementById(tzcd).innerHTML = days + " day" + (days == 1 ? '' : 's') + ' + ' +hours+ 'h : ' +mins+ 'm : '+secs+'s';
			document.getElementById(tzcd).innerHTML = 'Countdown to Kickoff: ' + days + ':' +hours+ ':' +mins+ ':'+secs+'';
			
			setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
		}
	}
}
