// display current time at author location
// =======================================
// copyright Stephen Chapman, Felgall Pty Ltd, 11 July 2001, 25th November 2004
// http://www.felgall.com/ and http://javascript.about.com/
// permission is given to use this script
// provided that all comment lines in the script are retained
// Modified by Al Klein - May 7, 2008

function myTime() {
	var loc = 'New York';	// set to your location
	var mtz = -5;			// set to your local timezone (hours ahead of UTC, negative if behind)
	var stdz = 'EST';		// standard time indicator
	var dayz = 'EDST';		// daylight saving time indicator (blank if you dont have daylight saving)

	var dst = 0;			// this will be set to 1 for daylight savings time

	var gmt = new Date;
	var startDate = new Date;
	var endDate = new Date;
	var thisYear = gmt.getYear();
	if (thisYear < 2000)
		thisYear += 1900;
	startDate.setDate(14 - (Math.floor (1 + thisYear * 5 / 4) % 7));
	startDate.setMonth(2); //March
	endDate.setDate(7 - (Math.floor (1 + thisYear * 5 / 4) % 7));
	endDate.setMonth(10); //November

	//for historical purposes, US from 1900-2006
	//startDate.setDate((2+6 * thisYear - Math.floor (thisYear / 4) ) % 7 + 1); //for the old April date
	//startDate.setMonth(3); //April
	//endDate.setDate(31-( Math.floor (thisYear * 5 / 4) + 1) % 7); //for the old October date
	//endDate.setMonth(9); //October
	
	//European dates, 1996-2099
	//startDate.setDate(31-( Math.floor (thisYear * 5 / 4) + 4) % 7);
	//startDate.setMonth(3); //April
	//endDate.setDate(31-( Math.floor (thisYear * 5 / 4) + 1) % 7);
	//endDate.setMonth(9); //October

	//if (gmt < startDate || gmt >= endDate) dst = 1;
	if (gmt.getMonth() > startDate.getMonth() && gmt.getMonth() < endDate.getMonth()) {dst = 1;} //If we're between the dates, it's DST

	//These have to be adjusted to 0100 UTC - not local time - for Europe
	//If it's the March date, and it's before 2AM, it's ST
	if (gmt.getMonth() == startDate.getMonth() && gmt.getDate() == startDate.getDate() && gmt.getHours() < 2) {dst = 0;}
	//If it's the November date, and it's after 1:59 AM, it's ST
	if ((gmt.getMonth() == endDate.getMonth() && gmt.getDate() == endDate.getDate()) && (gmt.getHours() > 1)) {dst = 0;}

	var text = 'The time in ' + loc + ' is <span id="time">' + setDsp(mtz,dst,stdz,dayz)+'<\/span>';
	if (DOMsupported) setTimeout('updDsp('+mtz+',' +dst+',"' +stdz+'","' +dayz+'")', 1000); //update every second
	return text;

}

var DOMsupported = 0;
var standardDOMsupported = 0;
var ieDOMsupported = 0;
if (document.getElementById) { 
	standardDOMsupported = 1; DOMsupported = 1;
} else { if (document.all) {
	ieDOMsupported = 1; DOMsupported = 1;}
}

function findDOM(objectId) {
	if (standardDOMsupported) {
		return (document.getElementById(objectId));
	}
	if (ieDOMsupported) {
		return (document.all[objectId]);
	}
}

function updDsp(mtz,dst,stdz,dayz) {
	var obj = findDOM('time');

	obj.innerHTML = setDsp(mtz,dst,stdz,dayz);
	setTimeout('updDsp('+mtz+ ','+dst+ ',"'+stdz+ '","'+dayz+ '")', 1000);
}

function setDsp(mtz,dst,stdz,dayz) {
	var dayname = new Array ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday','Friday', 'Saturday', 'Sunday');
	var monthname = new Array ('Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'Jun.', 'Jul.', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.');
	var now = new Date;

	now.setUTCMinutes(now.getUTCMinutes() + (mtz + dst)*60);
	var dow = now.getUTCDay();
	var seconds = now.getUTCSeconds();
	var minute = now.getUTCMinutes();
	var hour = now.getUTCHours();
	var month = now.getUTCMonth();
	var dat = now.getUTCDate();

	if (hour > 11) {
		ampm = 'PM'; hour -= 12;
	} else {
		ampm = 'AM';
	}
	if (hour == 0) {
		hour = 12;
	} 
	if (minute < 10) {
		pad = ':0';
	} else {
		pad = ':';
	}
	
	if (seconds < 10)
	{
		spad = ':0';
	} else {
		spad = ':';
	}

	var txt = hour + pad + minute + spad + seconds + ' ' + ampm + ' (';
	if (dst) txt += dayz; else txt += stdz;

	txt += ')<br>on ' + dayname[dow]+', '+monthname[month]+' '+dat + ', '+now.getUTCFullYear();
	return (txt);
}
