var args = {
	"type": "report",
	"title": "Cross Contract Sample",
	"L1": true,
	"dataset" : "(|ContrName|) (|EndDate|) (|Structure|StruName|) (|Unit|UnitName|)",
	"header": "This report displays unique-key information for elements in the current dataset, and illustrates date and number formatting.<p><ul><li>The 'Ordinal' column is 1 for the most recent period in a contract, 2 for the next most recent, etc.</li><li>If you have contracts having calenders with different date formats, the 'DATE (Formatted)' column will change as the contract of the active element changes.</li><li>Similarly, if your contracts have different DisplayScale and DisplayDecimal settings, 'BAC (Scaled)' will change as the contract of the active element changes.</li><li>However, 'BAC (Millions)' will always display the current unit in millions (try it for Hours.)</li></ul><p>",
	"sql" : [
	{
"query": "select Element.ElemID, ContrName, StruName, WbsNum, EndDate, UnitName, OrdVal, EndDate EndDate2, Bac, Bac Bac2 from EarnedValue inner join Element on Element.ElemID = EarnedValue.ElemID inner join Period on Period.PeriodID = EarnedValue.PeriodID inner join Unit on Unit.UnitID = EarnedValue.UnitID inner join Contract on Contract.ContrID = Period.ContrID inner join Structure on Structure.StruID = Element.StruID where Structure.StruID in (st_id, 3) and Unit.UnitID = un_id and OrdVal = (select OrdVal from Period where PeriodID = cd_id)",
"format": ["", "", "", "", "", "", "", "fmt", "cdd", "d5"],
"scale": ["", "", "", "", "", "", "", "", "ds", "6"],
	},
	{
		"query": "delete from EarnedValue where PeriodID = cd_id"
	},
	],
	"sync": true,
	"cols": ["CONTR", "STRU", "WBS", "DATE", "UNIT", "Ordinal", "DATE (Formatted)", "BAC (Scaled)", "BAC (Millions)"],
	"align": ["l", "l", "l", "r", "l", "r", "c", "r", "r"]
};

(function() {
	"use strict";
	var em = [],
		td_h = "rpt rac rcgr1 rtb",
		td_c = "rpt ra",
		arr = [],
		s, i, ilen, j, jlen, vals, val;
	em.push('<div class="rpt">');
	em.push('<div class="rtitle">');
	s = args.L1 ? args.dataset : extra.title;
	if (args.sync && extra.pf && extra.pf.length) {
		s = s + ' (' + extra.pf + ')';
	}
	em.push(s);
	em.push('<br>');
	s = args.title;
	if (extra.scale.text.length) {
		s = s + ' (' + extra.scale.text + ')';
	}
	em.push(s);
	em.push('</div>');
	if( extra.dataset.ce === 'sum' ) {
		em.push('</div>');
		return em.join('');
	}
	if (args.header) {
		em.push('<br>');
		em.push(args.header);
	}
	em.push('<p>');
	em.push('<table class="rpt">');
	em.push('<tr>');
	for (i = 0, ilen = args.cols ? args.cols.length : 0; i < ilen; i++) {
		s = args.cols[i];
		em.push('<td class="' + td_h + '">' + s + '</td>');
	}
	em.push('</tr>');
	arr = args.sql[0];
	for (i = 0, ilen = arr.length; i < ilen; i++) {
		em.push('<tr>');
		vals = arr[i];
		if (args.sync) {
			vals.shift();
		}
		for (j = 0, jlen = vals.length; j < jlen; j++) {
			val = vals[j];
			s = args.align ? args.align[j] : 'l';
			em.push('<td class="' + td_c + s + '">' + val + '</td>');
		}
		em.push('</tr>');
	}
	em.push('</table>');
	em.push('</div>');
	return em.join('');
})();
