// Server time -> Corrected Local & UTC time script (Version 2.0). Dan Cotruta, 28 July 2004.
// Version 1 - Moving clock, based on client clock.
// Version 1.1 - Moving clock based on client time (using forms), corrected timestamp (based on server - client difference).
// Version 1.5 - Moving clock based on server - client time difference [corrected local time] (using forms).
// Version 1.6 - 2 Moving clocks based on server - client time difference [corrected local & UTC time] (using forms).
// Version 2.0 - 2 Moving clocks based on server - client time difference [corrected local & UTC time] (using layers).
// Version 3.0 - 2 Moving clocks based on server - client time difference [corrected local & UTC time] (using layers).
//		 Added ability to choose timezone. Removed some redundant lines of code.
// Version 3.0 - 20041027 SJB DEBUG 
// 
// This script uses the simpleFindObj function and an implementation of clockWriteToDiv function developed by Andrew Shearer // (see below).
// Andrew Shearer's functions are the only parts of this script that may be used freely (as long as the notices are 
// preserved intact.
// THIS SCRIPT MAT NOT BE USED WITHOUT PRIOR PERMISSION FROM THE AUTHOR!
// If you wish to use this script then send an email to dan.cotruta@gmail.com

// vars-vars-vars-vars-vars-vars-vars-vars-vars-vars-vars-vars-vars-vars
var tzone_ncsoft_pst = -28800000;
var tzone_ncsoft = -18000000;
var tzone_gmt = null;
var tzone_hatsch = 3600000;
var tzone_china = 28800000;
var clockID = null;
var clockRunning = false;
var x = new Date();
var ltime = x.getTime();
var stime = x.getTime();
// var stime = 1.12859079609E+12;
var diff = (ltime - stime);
// endvars-endvars-endvars-endvars-endvars-endvars-endvars-endvars-endvars

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


// func-func-func-func-func-func-func-func-func-func-func-func-func-func
<!--
/*** simpleFindObj, by Andrew Shearer
Efficiently finds an object by name/id, using whichever of the IE,
classic Netscape, or Netscape 6/W3C DOM methods is available.
The optional inLayer argument helps Netscape 4 find objects in
the named layer or floating DIV. */
//-->
function simpleFindObj(name, inLayer) 
{
	return document[name] || (document.all && document.all[name])
	|| (document.getElementById && document.getElementById(name))
	|| (document.layers && inLayer && document.layers[inLayer].document[name]);
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// func-func-func-func-func-func-func-func-func-func-func-func-func-func
<!--
/*** Implementation of clockWriteToDiv function by Andrew Shearer. */
//-->
function divWrite(div, input)
{
	var div_x = simpleFindObj(div);
	input = input;
	if (div_x && div_x.innerHTML) 
	{
		div_x.innerHTML = input;
	}
	else if (div_x && div_x.document) 
	{
		div_x.document.writeln(input);
		div_x.document.close();
	}
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// func-func-func-func-func-func-func-func-func-func-func-func-func-func
function localDisplay(local, layer) 
{
	divWrite(layer, local);
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// func-func-func-func-func-func-func-func-func-func-func-func-func-func
function UTCDisplay(utc) 
{
	divWrite("layer2", utc);
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


// func-func-func-func-func-func-func-func-func-func-func-func-func-func
function stop()
{
	if(clockRunning) clearTimeout(clockID);
	clockRunning = false;
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// func-func-func-func-func-func-func-func-func-func-func-func-func-func
function makeGMT (day, date, month, year, hour, minute, second)
{
	if (day == 0)
	{
		day = "So.";
	}
	else if (day == 1)
	{
		day = "Mo.";
	}
	else if (day == 2)
	{
		day = "Di.";
	}
	else if (day == 3)
	{
		day = "Mi.";
	}
	else if (day == 4)
	{
		day = "Do.";
	}
	else if (day == 5)
	{
		day = "Fr.";
	}
	else if (day == 6)
	{
		day = "Sa.";
	}
	if (month == 0)
	{
		month = "Jan.";
	}
	else if (month == 1)
	{
		month = "Feb.";
	}
	else if (month == 2)
	{
		month = "März";
	}
	else if (month == 3)
	{
		month = "April";
	}
	else if (month == 4)
	{
		month = "Ma1";
	}
	else if (month == 5)
	{
		month = "Juni";
	}
	else if (month == 6)
	{
		month = "Juli";
	}
	else if (month == 7)
	{
		month = "Aug.";
	}
	else if (month == 8)
	{
		month = "Sep.";
	}
	else if (month == 9)
	{
		month = "Okt.";
	}
	else if (month == 10)
	{
		month = "Nov.";
	}
	else if (month == 11)
	{
		month = "Dez.";
	}

	if (hour < 10)
	{
		hour = ("0" + hour);
	}

	if (minute < 10)
	{
		minute = ("0" + minute);
	}

	if (second < 10)
	{
		second = ("0" + second);
	}

	UTCDisplay(day + ", " + date + " " + month + " " + year + "  " + hour + ":" + minute + ":" + second);
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// func-func-func-func-func-func-func-func-func-func-func-func-func-func
function makeLocal(day, date, month, year, hour, minute, second, layer)
{
	if (day == 0)
	{
		day = "So.";
	}
	else if (day == 1)
	{
		day = "Mo.";
	}
	else if (day == 2)
	{
		day = "Di.";
	}
	else if (day == 3)
	{
		day = "Mi.";
	}
	else if (day == 4)
	{
		day = "Do.";
	}
	else if (day == 5)
	{
		day = "Fr.";
	}
	else if (day == 6)
	{
		day = "Sa.";
	}
	if (month == 0)
	{
		month = "Jan.";
	}
	else if (month == 1)
	{
		month = "Feb.";
	}
	else if (month == 2)
	{
		month = "März";
	}
	else if (month == 3)
	{
		month = "April";
	}
	else if (month == 4)
	{
		month = "Ma1";
	}
	else if (month == 5)
	{
		month = "Juni";
	}
	else if (month == 6)
	{
		month = "Juli";
	}
	else if (month == 7)
	{
		month = "Aug.";
	}
	else if (month == 8)
	{
		month = "Sep.";
	}
	else if (month == 9)
	{
		month = "Okt.";
	}
	else if (month == 10)
	{
		month = "Nov.";
	}
	else if (month == 11)
	{
		month = "Dez.";
	}

	if (hour < 10)
	{
		hour = ("0" + hour);
	}

	if (minute < 10)
	{
		minute = ("0" + minute);
	}

	if (second < 10)
	{
		second = ("0" + second);
	}
	
	localDisplay(day + ", " + date + " " + month + " " + year + "  " + hour + ":" + minute + ":" + second, layer);
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// func-func-func-func-func-func-func-func-func-func-func-func-func-func
function display() 
{
	var ltime = new Date(); 
	var ltime_unix = ltime.getTime();
	ltime = new Date(ltime_unix-diff);
	ServerDSTCheck = ltime.getTime();
	
	var UTCDay = ltime.getUTCDay();
	var UTCDate = ltime.getUTCDate();
	var UTCMonth = ltime.getUTCMonth();
	var UTCYear = ltime.getUTCFullYear();
	var UTCHours = ltime.getUTCHours();
	var UTCMinutes = ltime.getUTCMinutes();
	var UTCSeconds = ltime.getUTCSeconds();
	makeGMT (UTCDay, UTCDate, UTCMonth, UTCYear, UTCHours, UTCMinutes, UTCSeconds);

	var Spring2004NewYork = new Date();
	Spring2004NewYork.setTime(Date.UTC(2004, 3, 4, 7, 0, 0));
	GoSpring2004NewYork = Spring2004NewYork.getTime();

	var Fall2004NewYork = new Date();
	Fall2004NewYork.setTime(Date.UTC(2004, 9, 31, 6, 0, 0));
	GoFall2004NewYork = Fall2004NewYork.getTime();

	var Spring2005NewYork = new Date();
	Spring2005NewYork.setTime(Date.UTC(2005, 3, 3, 7, 0, 0));
	GoSpring2005NewYork = Spring2005NewYork.getTime();

	var Fall2005NewYork = new Date();
	Fall2005NewYork.setTime(Date.UTC(2005, 9, 30, 6, 0, 0));
	GoFall2005NewYork = Fall2005NewYork.getTime();

	var Spring2006NewYork = new Date();
	Spring2006NewYork.setTime(Date.UTC(2006, 3, 2, 7, 0, 0));
	GoSpring2006NewYork = Spring2006NewYork.getTime();

	var Fall2006NewYork = new Date();
	Fall2006NewYork.setTime(Date.UTC(2006, 9, 29, 6, 0, 0));
	GoFall2006NewYork = Fall2006NewYork.getTime();

	var Spring2007NewYork = new Date();
	Spring2007NewYork.setTime(Date.UTC(2007, 2, 25, 1, 0, 0));
	GoSpring2007NewYork = Spring2007NewYork.getTime();
	
	var Fall2007NewYork = new Date();
	Fall2007NewYork.setTime(Date.UTC(2007, 9, 28, 1, 0, 0));
	GoFall2007NewYork = Fall2007NewYork.getTime();
	
	if (ServerDSTCheck >= GoSpring2004NewYork && ServerDSTCheck < GoFall2004NewYork)
	{
		tzone_ncsoft = -21600000;
		divWrite("local_ncsoft", "CDT = GMT - 05:00 (Central Daylight / Summer Time)");
	}
	
	else if (ServerDSTCheck >= GoFall2004NewYork && ServerDSTCheck < GoSpring2005NewYork)
	{
		tzone_ncsoft = -18000000;
		divWrite("local_ncsoft", "CST = GMT - 06:00 (Central Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2005NewYork && ServerDSTCheck < GoFall2005NewYork)
	{
		tzone_ncsoft = -21600000;
		divWrite("local_ncsoft", "CDT = GMT - 05:00 (Central Daylight / Summer Time)");
	}

	else if (ServerDSTCheck >= GoFall2005NewYork && ServerDSTCheck < GoSpring2006NewYork)
	{
		tzone_ncsoft = -18000000;
		divWrite("local_ncsoft", "CST = GMT - 06:00 (Central Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2006NewYork && ServerDSTCheck < GoFall2006NewYork)
	{
		tzone_ncsoft = -21600000;
		divWrite("local_ncsoft", "CDT = GMT - 05:00 (Central Daylight / Summer Time)");
	}
	
	else if (ServerDSTCheck >= GoFall2006NewYork && ServerDSTCheck < GoSpring2007NewYork)
	{
		tzone_ncsoft = -18000000;
		divWrite("local_ncsoft", "CST = GMT - 06:00 (Central Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2007NewYork && ServerDSTCheck < GoFall2007NewYork)
	{
		tzone_ncsoft = -21600000;
		divWrite("local_ncsoft", "CDT = GMT - 05:00 (Central Daylight / Summer Time)");
	}

	var Spring2004gmt = new Date();
	Spring2004gmt.setTime(Date.UTC(2004, 2, 28, 1, 0, 0));
	GoSpring2004gmt = Spring2004gmt.getTime();

	var Fall2004gmt = new Date();
	Fall2004gmt.setTime(Date.UTC(2004, 9, 31, 1, 0, 0));
	GoFall2004gmt = Fall2004gmt.getTime();

	var Spring2005gmt = new Date();
	Spring2005gmt.setTime(Date.UTC(2005, 2, 27, 1, 0, 0));
	GoSpring2005gmt = Spring2005gmt.getTime();

	var Fall2005gmt = new Date();
	Fall2005gmt.setTime(Date.UTC(2005, 9, 30, 1, 0, 0));
	GoFall2005gmt = Fall2005gmt.getTime();

	var Spring2006gmt = new Date();
	Spring2006gmt.setTime(Date.UTC(2006, 2, 26, 1, 0, 0));
	GoSpring2006gmt = Spring2006gmt.getTime();

	var Fall2006gmt = new Date();
	Fall2006gmt.setTime(Date.UTC(2006, 9, 29, 1, 0, 0));
	GoFall2006gmt = Fall2006gmt.getTime();

	var Spring2007gmt = new Date();
	Spring2007gmt.setTime(Date.UTC(2007, 2, 25, 1, 0, 0));
	GoSpring2007gmt = Spring2007gmt.getTime();
	
	var Fall2007gmt = new Date();
	Fall2007gmt.setTime(Date.UTC(2007, 9, 28, 1, 0, 0));
	GoFall2007gmt = Fall2007gmt.getTime();
	
	if (ServerDSTCheck >= GoSpring2004gmt && ServerDSTCheck < GoFall2004gmt)
	{
		tzone_gmt = 3600000;
		divWrite("local_gmt", "GMT + 01:00 (British Summer Time)");
	}
	
	else if (ServerDSTCheck >= GoFall2004gmt && ServerDSTCheck < GoSpring2005gmt)
	{
		tzone_gmt = null;
		divWrite("local_gmt", "GMT (Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2005gmt && ServerDSTCheck < GoFall2005gmt)
	{
		tzone_gmt = 3600000;
		divWrite("local_gmt", "GMT + 01:00 (British Summer Time)");
	}

	else if (ServerDSTCheck >= GoFall2005gmt && ServerDSTCheck < GoSpring2006gmt)
	{
		tzone_gmt = null;
		divWrite("local_gmt", "GMT (Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2006gmt && ServerDSTCheck < GoFall2006gmt)
	{
		tzone_gmt = 3600000;
		divWrite("local_gmt", "GMT + 01:00 (British Summer Time)");
	}
	
	else if (ServerDSTCheck >= GoFall2006gmt && ServerDSTCheck < GoSpring2007gmt)
	{
		tzone_gmt = null;
		divWrite("local_gmt", "GMT (Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2007gmt && ServerDSTCheck < GoFall2007gmt)
	{
		tzone_gmt = 3600000;
		divWrite("local_gmt", "GMT + 01:00 (British Summer Time)");
	}

	var Spring2004hatsch = new Date();
	Spring2004hatsch.setTime(Date.UTC(2004, 2, 28, 1, 0, 0));
	GoSpring2004hatsch = Spring2004hatsch.getTime();

	var Fall2004hatsch = new Date();
	Fall2004hatsch.setTime(Date.UTC(2004, 9, 31, 1, 0, 0));
	GoFall2004hatsch = Fall2004hatsch.getTime();

	var Spring2005hatsch = new Date();
	Spring2005hatsch.setTime(Date.UTC(2005, 2, 27, 1, 0, 0));
	GoSpring2005hatsch = Spring2005hatsch.getTime();

	var Fall2005hatsch = new Date();
	Fall2005hatsch.setTime(Date.UTC(2005, 9, 30, 1, 0, 0));
	GoFall2005hatsch = Fall2005hatsch.getTime();

	var Spring2006hatsch = new Date();
	Spring2006hatsch.setTime(Date.UTC(2006, 2, 26, 1, 0, 0));
	GoSpring2006hatsch = Spring2006hatsch.getTime();

	var Fall2006hatsch = new Date();
	Fall2006hatsch.setTime(Date.UTC(2006, 9, 29, 1, 0, 0));
	GoFall2006hatsch = Fall2006hatsch.getTime();
	
	var Spring2007hatsch = new Date();
	Spring2007hatsch.setTime(Date.UTC(2007, 2, 25, 1, 0, 0));
	GoSpring2007hatsch = Spring2007hatsch.getTime();
	
	var Fall2007hatsch = new Date();
	Fall2007hatsch.setTime(Date.UTC(2007, 9, 28, 1, 0, 0));
	GoFall2007hatsch = Fall2007hatsch.getTime();
	
	if (ServerDSTCheck >= GoSpring2004hatsch && ServerDSTCheck < GoFall2004hatsch)
	{
		tzone_hatsch = 7200000;
		divWrite("local_hatsch", "CEST = GMT + 02:00 (Daylight / Summer Time)");
	}
	
	else if (ServerDSTCheck >= GoFall2004hatsch && ServerDSTCheck < GoSpring2005hatsch)
	{
		tzone_hatsch = 3600000;
		divWrite("local_hatsch", "CET = GMT + 01:00 (Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2005hatsch && ServerDSTCheck < GoFall2005hatsch)
	{
		tzone_hatsch = 7200000;
		divWrite("local_hatsch", "CEST = GMT + 02:00 (Daylight / Summer Time)");
	}

	else if (ServerDSTCheck >= GoFall2005hatsch && ServerDSTCheck < GoSpring2006hatsch)
	{
		tzone_hatsch = 3600000;
		divWrite("local_hatsch", "CET = GMT + 01:00 (Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2006hatsch && ServerDSTCheck < GoFall2006hatsch)
	{
		tzone_hatsch = 7200000;
		divWrite("local_hatsch", "CEST = GMT + 02:00 (Daylight / Summer Time)");
	}
	
	else if (ServerDSTCheck >= GoSpring2006hatsch && ServerDSTCheck < GoSpring2007hatsch)
	{
		tzone_hatsch = 3600000;
		divWrite("local_hatsch", "CET = GMT + 01:00 (Standard Time)");
	}

	else if (ServerDSTCheck >= GoSpring2007hatsch && ServerDSTCheck < GoFall2007hatsch)
	{
		tzone_hatsch = 7200000;
		divWrite("local_hatsch", "CEST = GMT + 02:00 (Daylight / Summer Time)");
	}
	
	divWrite("local_china", "Standard Time (GMT+8) all year round");
	
	ncsoft_time = new Date(ltime_unix-diff+tzone_ncsoft);
	var ncsoft_Day = ncsoft_time.getUTCDay();
	var ncsoft_Date = ncsoft_time.getUTCDate();
	var ncsoft_Month = ncsoft_time.getUTCMonth();
	var ncsoft_Year = ncsoft_time.getUTCFullYear();
	var ncsoft_Hours = ncsoft_time.getUTCHours();
	var ncsoft_Minutes = ncsoft_time.getUTCMinutes();
	var ncsoft_Seconds = ncsoft_time.getUTCSeconds();
	makeLocal (ncsoft_Day, ncsoft_Date, ncsoft_Month, ncsoft_Year, ncsoft_Hours, ncsoft_Minutes, ncsoft_Seconds, "ncsoft_layer");

	gmt_time = new Date(ltime_unix-diff+tzone_gmt);
	var gmt_Day = gmt_time.getUTCDay();
	var gmt_Date = gmt_time.getUTCDate();
	var gmt_Month = gmt_time.getUTCMonth();
	var gmt_Year = gmt_time.getUTCFullYear();
	var gmt_Hours = gmt_time.getUTCHours();
	var gmt_Minutes = gmt_time.getUTCMinutes();
	var gmt_Seconds = gmt_time.getUTCSeconds();
	makeLocal (gmt_Day, gmt_Date, gmt_Month, gmt_Year, gmt_Hours, gmt_Minutes, gmt_Seconds, "gmt_layer");

	hatsch_time = new Date(ltime_unix-diff+tzone_hatsch);
	var hatsch_Day = hatsch_time.getUTCDay();
	var hatsch_Date = hatsch_time.getUTCDate();
	var hatsch_Month = hatsch_time.getUTCMonth();
	var hatsch_Year = hatsch_time.getUTCFullYear();
	var hatsch_Hours = hatsch_time.getUTCHours();
	var hatsch_Minutes = hatsch_time.getUTCMinutes();
	var hatsch_Seconds = hatsch_time.getUTCSeconds();
	makeLocal (hatsch_Day, hatsch_Date, hatsch_Month, hatsch_Year, hatsch_Hours, hatsch_Minutes, hatsch_Seconds, "hatsch_layer");

	china_time = new Date(ltime_unix-diff+tzone_china);
	var china_Day = china_time.getUTCDay();
	var china_Date = china_time.getUTCDate();
	var china_Month = china_time.getUTCMonth();
	var china_Year = china_time.getUTCFullYear();
	var china_Hours = china_time.getUTCHours();
	var china_Minutes = china_time.getUTCMinutes();
	var china_Seconds = china_time.getUTCSeconds();
	makeLocal(china_Day, china_Date, china_Month, china_Year, china_Hours, china_Minutes, china_Seconds, "china_layer");

	var wtime = ltime_unix - diff;
	clockID = setTimeout('display()',1000 - (wtime % 1000));
	clockRunning = true;
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// func-func-func-func-func-func-func-func-func-func-func-func-func-func
function tick() 
{
	stop();
	display();
}
// endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc-endfunc

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx