function timezone_offset() {
    var now_client      = new Date();
    var now_gmt_string = now_client.toGMTString();
    var now_gmt        = new Date(now_gmt_string.substring(0, now_gmt_string.lastIndexOf(" ")-1));
	now_client.setSeconds(0,0);
	now_gmt.setSeconds(0,0);
	
    var current_time_offset = (now_client - now_gmt) / (1000 * 60 * 60);
	
	return current_time_offset;
}

function timezone_offset_string(offset) {
	var hours = parseInt(offset);
   	var fractional_hours =  offset - parseInt(offset);
	var mins = Math.abs(parseInt(fractional_hours * 60));
	var display_hours;
	
	if (hours == 0) {
		display_hours = "+00";
	} else if (hours > 0) {
		// add a plus sign and perhaps an extra 0
		display_hours = (hours < 10) ? "+0"+hours : "+"+hours;
	} else {
		// add an extra 0 if needed 
		display_hours = (hours > -10) ? "-0"+Math.abs(hours) : hours;
	}
	
	display_mins = (mins < 10) ? "0"+mins : mins;
	return display_hours+":"+display_mins;
}


$(document).ready(function() {
    var tz_offset = timezone_offset();
	var tz_offset_string = timezone_offset_string(tz_offset);
	$('input#tz_offset').val(tz_offset_string);
});

