﻿/// <reference path="~/scripts/jquery-vsdoc.js"/>
var GMT = {};

GMT.days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];

GMT.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

GMT.offsetForDate = function(reference) {
	return parseInt(reference.getTimezoneOffset(), 10) / 60;
}

GMT.offsetForDateString = function(reference) {
	var off = this.offsetForDate(reference);
	if (off < 0)
		return off.toString().replace('-', '+');
	if (off > 0)
		return '-' + off.toString();
	return '';
}

GMT.clockToLocal = function() {
	var localDate = new Date();
	var localOffset = this.offsetForDateString(localDate);

	$('#localdate').replaceWith(
		this.days[localDate.getDay()] + ', ' +
		this.months[localDate.getMonth()] + ' ' +
		localDate.getDate() + ' ' +
		localDate.getFullYear());
		
	$('#localtimezone').replaceWith(localOffset);
}

GMT.matchesToLocal = function() {
	$('cite').each(function() {
		var gmt = $(this).attr('gmt');

		if (gmt && gmt != '' && gmt.indexOf(':') == 2 && gmt.length >= 4) {
			var local = null;// new Date();
			eval('local = ' + $(this).attr('jsdate') + ';');
			local.setHours(local.getHours() - GMT.offsetForDate(local));
			$(this).html('<b>' + AddZero(local.getHours()) + ':' + AddZero(local.getMinutes()) + '</b> GMT' + GMT.offsetForDateString(local)); // + ','
			$(this).attr('gmt', '');
		}
	});
}

