var PieChart = function(chartId, title) {

	$('#' + chartId)
			.highcharts(
					{
						chart : {
							backgroundColor:'#fff',
							plotBackgroundColor : null,
							plotBorderWidth : null,
							plotShadow : false
						},
						title : {
							text : title
						},
						tooltip : {
							pointFormat : '{series.name}: <b>{point.percentage:.1f}</b> %'
						},
						plotOptions : {
							pie : {
								size:250,
								allowPointSelect : true,
								cursor : 'pointer',
								dataLabels : {
									enabled : true,
									color : '#000000',
									connectorColor : '#000000',
									format : '<b>{point.name}</b>:  {point.percentage:.1f} %'
								}
							}
						},
						series : [ {
							type : 'pie',
							name : 'URL content type distribution',
							data : []
						} ]
					});

}

var UrlContentTypeDistribution = function(containerId, testPlanId) {
	var pieChart = new PieChart(containerId, "URL content type distribution");
	var chart = $("#" + containerId).highcharts();
	var urlPath = [ testPlanId, "urlContentTypePercent" ];
	var url = generateUrl(urlPath);
	var i=0;
	var intervalId = setInterval(function() {
	
		$.post(url, "", function(data) {
			var dataArray = new Array();
			if(!data.success){
				information(data.failedMessage);
				return;
			}
				
			else data=data.data;
			
				for(var key in data)
				dataArray.push([key,data[key]]);
				chart.series[0].setData(dataArray);
				
			
			loadItems.urlDistribution=true;
		},"json");
		
		if (testStatus == "Complete"&&i>=1) {
			clearInterval(intervalId);
			return;
		}
		i++;

	}, 1000);
}
