function TZGetCookie(name) 
{
    var index = document.cookie.indexOf(name + "=");
    if (index == -1) return null;
    index = document.cookie.indexOf("=", index) + 1;
    var endstr = document.cookie.indexOf(";", index);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(index, endstr));
}
function TZSetCookie(name,value,expir)
{  
	if (expir == null) { document.cookie = name + "=" + escape (value) + "; path=/"; }
	else { document.cookie = name + "=" + escape (value) + "; expires=" + expir.toUTCString() + "; path=/"; }
}
function SetTimezoneCookie()
{
	if (TZGetCookie("TZ") == null)
	{
		expiry = new Date();
		// move forward 24 hours
		expiry.setTime (expiry.getTime() + 1000 * 60 * 60 * 24);
		// truncate to 3AM
		expiry.setHours (3);
		expiry.setMinutes (0);
		expiry.setSeconds (0);
		expiry.setMilliseconds (0);
		// the cookie contains the minute offset from UTC and should expire at 3AM tomorrow (this ensures that we get it reset each day and should get the cookie set properly when we need it)
		TZSetCookie ("TZ", expiry.getTimezoneOffset(), expiry);
	}
}
SetTimezoneCookie();

