var tzone = 10800000;
var clockID = null;
var clockRunning = false;
var x = new Date();

function simpleFindObj(name, inLayer)
{
	return document.getElementById(name);
//	return window.document[name] || (document.all && document.all[name]) || (document.getElementById && document.getElementById(name)) || (document.layers && inLayer && document.layers[inLayer].document[name]);
}

function divWrite(div, input)
{
	var div_x = simpleFindObj(div);
//alert (div_x.innerHTML);
	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();
	}
}

function localDisplay(local)
{
	divWrite("layer1", local);
}

function stop()
{
	if(clockRunning) clearTimeout(clockID);
	clockRunning = false;
}

function makeLocal(day, date, month, year, hour, minute, second)
{
	if(summerTime(date,month,year)){hour += 1;}
	if (hour < 10)
	{
		hour = ("0" + hour);
	}

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



	localDisplay( hour + ":" + minute );
}

function summerTime(day,month,year){
	month += 1;
	if(month < 3 || month > 10){return false;}
	if(month > 3 && month < 10){return true;}
	var start_day = getLastSunday(3, year);
	var end_day = getLastSunday(10, year);
	if(month == 3 && day < start_day){return false;}
	else if(month == 10 && day >= end_day){return false;}
	return true;
}

function getLastSunday(month, year){
	var a,y,m,d;
	a = (14 - month) / 12;
	y = year - a;
	m = month - 12*a - 2;
	d = (7000 + (31 + y + y / 4 - y / 100 + y /400 + (31*m)/12))%7;

	return (31-d);
}

function display()
{
	var ltime = new Date();
	var ltime_unix = ltime.getTime();
	ltime = new Date(ltime_unix);
	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();

	var Spring2004 = new Date();
	Spring2004.setTime(Date.UTC(2004, 2, 27, 23, 0, 0));
	GoSpring2004 = Spring2004.getTime();

	var Fall2004 = new Date();
	Fall2004.setTime(Date.UTC(2004, 9, 30, 23, 0, 0));
	GoFall2004 = Fall2004.getTime();

	var Spring2005 = new Date();
	Spring2005.setTime(Date.UTC(2005, 2, 26, 23, 0, 0));
	GoSpring2005 = Spring2005.getTime();

	var Fall2005 = new Date();
	Fall2005.setTime(Date.UTC(2005, 9, 29, 23, 0, 0));
	GoFall2005 = Fall2005.getTime();

	var Spring2006 = new Date();
	Spring2006.setTime(Date.UTC(2006, 2, 25, 23, 0, 0));
	GoSpring2006 = Spring2006.getTime();

	var Fall2006 = new Date();
	Fall2006.setTime(Date.UTC(2006, 9, 28, 23, 0, 0));
	GoFall2006 = Fall2006.getTime();


	qtime = new Date(ltime_unix+tzone);
	var qDay = qtime.getUTCDay();
	var qDate = qtime.getUTCDate();
	var qMonth = qtime.getUTCMonth();
	var qYear = qtime.getUTCFullYear();
	var qHours = qtime.getUTCHours();
	var qMinutes = qtime.getUTCMinutes();
	var qSeconds = qtime.getUTCSeconds();
	makeLocal (qDay, qDate, qMonth, qYear, qHours, qMinutes, qSeconds);
	var wtime = ltime_unix;
	clockID = setTimeout('display()',1000 - (wtime % 1000));
	clockRunning = true;
}

function tick()
{
	stop();
	display();
}
