var charts = {
	name: 'charts',
	mandatoryVsGuideComplianceChart: null,
	newChart: true,
	pieChart: null,
	mandatoryVsGuideChart: null,
	getPieSeries : function(series) {
		var retVal = [];
		var percentages = utils.getPercentages(series.values);
		for (i = 0; i < series.keys.length; i++) {
			if (series.keys[i] == common.KEY_POOR) {
				retVal[i] = {y:series.values[i], text:percentages[i]+'%', color:common.COLOUR_POOR};
			} else if (series.keys[i] == common.KEY_SUFFICIENT) {
				retVal[i] = {y:series.values[i], text:percentages[i]+'%', color :common.COLOUR_SUFFICIENT};
			} else if (series.keys[i] == common.KEY_GOOD) {
				retVal[i] = {y:series.values[i], text:percentages[i]+'%', color :common.COLOUR_GOOD};
			} 
		}
		return retVal;
	},
	updatePieChart: function(locationSelection, dateRange) {
		historyController.getPieChartData(locationSelection, dateRange, function(pieSeries){
			var node = dojo.byId('pieChart');
			node.innerHTML = "";
			charts.pieChart = new dojox.charting.Chart2D(node).
				addPlot("default", {type:"Pie", labelOffset:-15, radius:70, htmlLabels:false}).
				addSeries("Series A", charts.getPieSeries(pieSeries)).
				render();
		});
	},
	updateTrendChart: function(locationSelection, dateRange) {
		historyController.getTrendChart(locationSelection, dateRange, function(chart) {
			var dates = common.getDatesFromDateRange();
			var node = dojo.byId("trendChart");
			node.innerHTML = "";
			charts.mandatoryVsGuideChart = new dojox.charting.Chart2D(node).
				addPlot("default", {type: "StackedColumns", gap: 5}).
				addAxis("x", {min:0, max:dates.length+1, minorTicks:false, labels:charts.getLabels(dates), htmlLabels:false}).
				addAxis("y", {vertical: true,min:0, max:100,minorTicks:false, majorTicks:true, labels:[{value:0, text:"0%"},{value:100, text:"100%"}], htmlLabels:false}).
				addSeries("Good", chart.goodSeries.values, {fill: common.COLOUR_GOOD}).
				addSeries("Sufficient", chart.sufficientSeries.values, {fill: common.COLOUR_SUFFICIENT}).
				addSeries("Poor", chart.poorSeries.values, {fill: common.COLOUR_POOR}).
				setTheme(dojox.charting.themes.PlotKit.epacolours).
				render();
		});
	},
	getLabels: function(dates) {
		var labels = new Array();
		labels[0] = {value: 0, text: ""};
		for (var i=0; i<dates.length; i++) {
			labels[i+1] = {value: i+1, text: dates[i].getFullYear().toString().substr(2)};
		}
		labels[i+1] = {value: i+1, text: ""};
		return labels;
	}
};
