$(function (){
$(".report-title").append("<h3>"+report_title+"</h3>");

var layouts = [
	{
		key : 0,
		name : "Layout 0" 
	}
	,{
		key : 1,
		name : "Layout 1"
	}
	,{
		key : 2,
		name : "Layout 2"
	}
	
]; ;


var cosmosPivotPivotGrid = $("#cosmosPivot").dxPivotGrid({
	allowSortingBySummary : true,
	allowSorting : true,
	allowFiltering : true,
	dataSource : {
		fields : fields,
		store : cosmosPivot
	},
	export:{
		enabled: true,
		fileName: "dataPivot",
		proxyUrl: undefined
	},
	fieldChooser : {
		enabled : true,
		height:600,
		layout: 0,
		texts : {
			allFields : "Todos",
			columnFields : "Columnas",
			dataFields : "Datos",
			rowFields : "Filas",
			filterFields : "Filtro"
		},
		title: "Field Chooser",
		width:600
	}

}).dxPivotGrid("instance");

var pivotGridChart = $("#pivotgrid-chart").dxChart({
	commonSeriesSettings: {
		type: "bar"
	},
	
	tooltip: {
		enabled: true /*,
		customizeTooltip: function (args) {
			var valueText = (args.seriesName.indexOf("Total") != -1) ? 
					Globalize.formatCurrency(args.originalValue,
						"USD", { maximumFractionDigits: 0 }) :
					args.originalValue;

			return {
				html: args.seriesName + "<div class='currency'>"
					+ valueText + "</div>"
			};
		}
		*/
	},
	
	size: {
		height: 320
	},
	adaptiveLayout: {
		width: 450
	},
	dataSource : cosmosPivot,
}).dxChart("instance");


var ee =    cosmosPivotPivotGrid.bindChart(pivotGridChart, {
        dataFieldsDisplayMode: "splitPanes",
        alternateDataFields: false
    });
	
var cosmosPivotFieldChooser = $("#cosmosPivot-fieldchooser").dxPivotGridFieldChooser({
	dataSource : cosmosPivotPivotGrid.getDataSource(),
	texts : {
		allFields : "Todos",
		columnFields : "Columnas",
		dataFields : "Datos",
		rowFields : "Filas",
		filterFields : "Filtro"
	},
	width : 400,
	height : 800
	}).dxPivotGridFieldChooser("instance");
	
$("#layouts").dxRadioGroup({
	items : layouts,
	layout : "horizontal",
	valueExpr : "key",
	displayExpr : "name",
	value : 0,
	onValueChanged : function (e) {
		cosmosPivotFieldChooser.option("layout", e.value);
	}
	})
});