
// Adapted partly from :
// GO1.1 :: Generic onload by brothercake - http://www.brothercake.com/
// and a script by Josh Fraser (http://www.onlineaspect.com)
// and http://www.quirksmode.org/

function calculate_time_zone() {
	var rightNow = new Date();
	var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);  // jan 1st
	var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st
	var temp = jan1.toGMTString();
	var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	temp = june1.toGMTString();
	var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
	var std_time_offset = (jan1 - jan2) / (1000 * 60 * 60);
	var daylight_time_offset = (june1 - june2) / (1000 * 60 * 60);
	var dst;
	if (std_time_offset == daylight_time_offset) {
		dst = "0"; // daylight savings time is NOT observed
	} else {
		// positive is southern, negative is northern hemisphere
		var hemisphere = std_time_offset - daylight_time_offset;
		if (hemisphere >= 0)
			std_time_offset = daylight_time_offset;
		dst = "1"; // daylight savings time is observed
	}
	if (std_time_offset == 0)
	{
		std_time_offset = 'gmt';
	}
	createCookie('tz', std_time_offset, '365');
}



//setup onload function
if(typeof window.addEventListener != 'undefined')
{
    //.. gecko, safari, konqueror and standard
    window.addEventListener('load', calculate_time_zone, false);
}
else if(typeof document.addEventListener != 'undefined')
{
    //.. opera 
    document.addEventListener('load', calculate_time_zone, false);
}
else if(typeof window.attachEvent != 'undefined')
{
    //.. win/ie
    window.attachEvent('onload', calculate_time_zone);
}

//** remove this condition to degrade older browsers
else
{
    //.. mac/ie5 and anything else that gets this far
    
    //if there's an existing onload function
    if(typeof window.onload == 'function')
    {
        //store it
        var existing = onload;
        
        //add new onload handler
        window.onload = function()
        {
            //call existing onload function
            existing();
            
            //call generic onload function
            calculate_time_zone();
        };
    }
    else
    {
        //setup onload function
        window.onload = calculate_time_zone;
    }
}
