var serial = "";
var year = "";
var energydata = [];
var energyHist = {};



$(document).ready(function()
{
	serial = document.location.search.substr(8,12);
	year = document.location.search.substr(26,4);
	$.getJSON("all-energy.json?serial="+serial+"&bymonth=1")
    .done (function(result) {
        loadNewData(result);
        addChart();
	hideError();
    })
    .fail (showError);		
	
	setInterval(updateChart(),6000);
}
);
Date.prototype.addDays = function(days) {
  var dat = new Date(this.valueOf());
  dat.setDate(dat.getDate() + days);
  return dat;
}


function addChart()
{
	energyHist = new Highcharts.chart({
										chart: {
										renderTo: 'energybymonth',
                              zoomType: 'x',
                              resetZoomButton: {
							            position: {
							                x: 0,
							                y: -35
							            }
							         },
                              panning: true,
                              panKey:  'shift',
										height:  '65%',
				},
global: {
                              	useUTC: false,
                                 timezoneOffset: 4 * 60,
                              },
series:  [{
                                 type: 'column',
                                 data: energydata,
                                 name: serial,
                                 color: '#AAFF66',                             
                                 
                              }],

										
                                 title:{
                                 			display:true,
                                 			text: 'Energy Captured per Month',
                                 		},

                             tooltip: {
        pointFormat: '{series.name}: <b>{point.y}</b><br/>',
        valueSuffix: ' kwh',
        shared: true
    },
                                xAxis: {
                                		type: 'datetime',
												dateTimeLabelFormats: {
       									       day: '%b-%y'
    									      },
                                		labels: {
	                                    formatter: function () {
	                                    	var self = this;
	                                       var label = this.axis.defaultLabelFormatter.call(self);
													   return label;
												   },
												},
                                		title: {
                                		text: 'date',
                                		
                                	},
                                },
                             
                                yAxis: {
                                    title: {
                                       text: 'Kilowatt-hours'
                                    },                                    
                                },
                                       
									}
										);
								
}

function loadNewData(incoming)
{
	var formatter = new Intl.DateTimeFormat("en", { month: "short", year: "numeric", timeZone: "UTC" });
	$.each(incoming.energy,function()
	{
		var entry = {};
		entry.name = formatter.format(new Date(this[0]));
		entry.x = Date.parse(this[0]);
		entry.y = parseFloat((this[1] / 1000.0).toFixed(1));
		energydata.push(entry);
	});
	
}

function showError()
{
	$("#errormessage").show();
}
function hideError()
{
	$("#errormessage").hide();
}



@@ -386,42 +386,8 @@
 %09%0A%09%0A
-%09setInterval(updateChart(),6000);%0A
 %7D%0A);
@@ -2917,16 +2917,83 @@
 %0A%7B%0A%09var 
+formatter;%0A        if (typeof(Intl) !== %22undefined%22) %7B%0A            
 formatte
@@ -3082,16 +3082,26 @@
 C%22 %7D);%0A%09
+%7D%0A        
 $.each(i
@@ -3147,16 +3147,49 @@
 y = %7B%7D;%0A
+                if (formatter) %7B%0A
 %09%09entry.
@@ -3228,24 +3228,140 @@
 (this%5B0%5D));%0A
+                %7D else %7B%0A                 entry.name = new Date(this%5B0%5D).toLocaleFormat('%25B %25Y');%0A                %7D%0A
 %09%09entry.x = 

add fallback for Icecat-mobile not having Intl support