/*
	timezones.js
	for agilitylogistics.com.au
	by David Nash
	June 2007

	Reads cookies and sets timezones, or provides defaults if no cookies set.
*/

var TZMAP;		//timezone for the map
var CITY1;		//timezone for clock 1
var CITY2;		//timezone for clock 2
var CITY3;		//timezone for clock 3

var CITY = new Array();
CITY['Adelaide'] = 'ACST';
CITY['Amsterdam'] = 'CET';
CITY['Atlanta'] = 'EST';
CITY['Auckland'] = 'NZT';
CITY['Brisbane'] = 'GMT1000';
CITY['Chicago'] = 'CST';
CITY['Christchurch'] = 'NZT';
CITY['Darwin'] = 'GMT0930';
CITY['Dunedin'] = 'NZT';
CITY['Frankfurt'] = 'CET';
CITY['Hong Kong'] = 'CCT';
CITY['Istanbul'] = 'EET';
CITY['Jakarta'] = 'JOG';
CITY['Kuwait'] = 'GMT0300';
CITY['Lae'] = 'GMT1000';
CITY['London'] = 'WET';
CITY['Los Angeles'] = 'PST';
CITY['Madang'] = 'GMT1000';
CITY['Milan'] = 'CET';
CITY['Melbourne'] = 'AEST';
CITY['Mumbai'] = 'GMT0530';
CITY['New York'] = 'EST';
CITY['Paris'] = 'CET';
CITY['Perth'] = 'AWST';
CITY['Port Moresby'] = 'GMT1000';
CITY['Shanghai'] = 'CCT';
CITY['Singapore'] = 'GMT0800';
CITY['Sydney'] = 'AEST';
CITY['Tokyo'] = 'JST';
CITY['Toronto'] = 'EST';
CITY['Vancouver'] = 'PST';
CITY['Wellington'] = 'NZT';


//See if a cookie has been set. Use it, otherwise give a default.

//world map
if( readCookie('tzMap') )
	TZMAP = readCookie('tzMap');
else
	TZMAP = 'Sydney';


//line clock 1
if( readCookie('city1') )
	CITY1 = readCookie('city1');
else
	CITY1 = 'London';

//line clock 2
if( readCookie('city2') )
	CITY2 = readCookie('city2');
else
	CITY2 = 'New York';

//line clock 3
if( readCookie('city3') )
	CITY3 = readCookie('city3');
else
	CITY3 = 'Shanghai';


var CONFIG = false;


function tz_init() {
	if( document.getElementById ) {
		//set city names for map
		var text1 = document.createTextNode(TZMAP);
		document.getElementById('tzMapName').appendChild(text1);
		

		//for the config page, set select options
		if( CONFIG ) {
			document.getElementById('optionTZMap').firstChild.nodeValue = TZMAP;
			document.tzform.worldmap.value = document.getElementById('optionTZMap').firstChild.nodeValue; //for ie

			document.getElementById('optionTZ1').firstChild.nodeValue = CITY1;
			document.tzform.clock1.value = document.getElementById('optionTZ1').firstChild.nodeValue; //for ie
			
			document.getElementById('optionTZ2').firstChild.nodeValue = CITY2;
			document.tzform.clock2.value = document.getElementById('optionTZ2').firstChild.nodeValue; //for ie

			document.getElementById('optionTZ3').firstChild.nodeValue = CITY3;
			document.tzform.clock3.value = document.getElementById('optionTZ3').firstChild.nodeValue; //for ie
		} //end if config
	} //end if dom
} //end fn



//cookie functions from quirksmode.org
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/*
City names:
Adelaide
Amsterdam
Atlanta
Auckland
Brisbane
Chicago
 Christchurch
Darwin
 Dunedin
Frankfurt
Hong Kong
Istanbul
Jakarta
Kuwait
 Lae
London
Los Angeles
 Madang
 Melbourne
Milan
Mumbai
New York
Paris
Perth
 Port Moresby
Shanghai
Singapore
Sydney
Tokyo
Toronto
Vancouver
 Wellington
*/
