function DataPoint(x, y)
{
	this.x = x;
	this.y = y;
}  

function Chart(topicid, topicname, duration, containerId, charttitleId, mainchartareaId, data, range)
{
	this.topicid = topicid;
	this.topicname = topicname;
	//Duration can be 1d, 1w, 1m, 3m, 6m, 1y
	this.duration = duration;
	this.container = document.getElementById(containerId);
	this.charttitle = document.getElementById(charttitleId);
	this.mainchartarea = document.getElementById(mainchartareaId);
	this.draw = drawChart;
	//data will be an array of datapoints
	this.range = range;
	this.data = data;
	this.hide = hideChart;
	this.show = showChart;
	this.reset = resetChart;
}

function drawChart()
{
	var width = 260;
	var height = 100;

	if (this.range==null || this.range=='' || this.range<0)
		this.range = 10;

	var graph = new JSGraph(this.mainchartarea);
	graph.graphLeftPaddingOverride = 15;
	graph.yAxis(4, height);
	graph.xAxis(4, width);
	graph.addBackground('#FFF8DC');

	graph.addTrellis(height*1/5, 1, '#FF0000', this.range/5,'tahoma,sans-serif',8);
	graph.addTrellis(height*2/5, 1, '#FF0000', this.range*2/5,'tahoma,sans-serif',8);
	graph.addTrellis(height*3/5, 1, '#FF0000', this.range*3/5,'tahoma,sans-serif',8);
	graph.addTrellis(height*4/5, 1, '#FF0000', this.range*4/5,'tahoma,sans-serif',8);
	graph.addTrellis(height, 1, '#FF0000', this.range,'tahoma,sans-serif',8);

	var scale = height/10;


	for (i=0; i<this.data.length; i++)
	{
		graph.addLinePlot(this.data[i].y*scale,1,'maroon',1,this.data[i].x,'Verdana,Arial,Helvetica,sans-serif','maroon',8);
	}
	graph.makeGraph();
}

function hideChart()
{
	this.container.style.display = "none";
	this.mainchartarea.style.display = "none";	
}

function showChart()
{
	this.charttitle.innerHTML = this.topicname + ' : ' + this.duration;
	this.container.style.display = "";
	this.mainchartarea.style.display = "";	
}

function resetChart()
{
	this.topicid = '';
	this.topicname = '';
	this.duration = '';
	this.data.splice(0, this.data.length);
	this.charttitle.innerHTML = "";
	this.mainchartarea.innerHTML = "";
}

