<br class="space5" />
<table class="pivotTablesLayout">
	<tr>

		{* PIVOT TABLES LIST ******************************************************************* *}
		<td>
			<div class="titles left">{$_LANG.reportsManagement.admin.pivots.pivotTableDetails}</div>

			<div id="pivotsListDiv"></div>

		</td>


		{* COLUMNS LIST ************************************************************************ *}
		<td class="pivotTablesOptions">

			<div class="titles right">{$_LANG.reportsManagement.admin.pivots.reportFieldsTitle}</div>

			<div id="columnsListDiv">

				{* --- add normal columns --- *}
				{assign var=lastColCat value=''}{assign var=hasCats value=0}
				{assign var=colCatIdx value=0}
				{foreach from=$columnsList name="colsLoop" item=colName key=colKey}
					{assign var=thisColCat value=$columnsCfg[$colKey].cat}

					{if $thisColCat!=$lastColCat}
						{assign var=colCatIdx value=$colCatIdx+1}
						{if !$smarty.foreach.colsLoop.first}</div>{/if}
						<div {if $smarty.foreach.colsLoop.first}class="colCategoryFirst"{else}class="colCategory"{/if}>
							<a href="#;" class="link toggleCategory" onclick="$('colCategoryBox_{$colCatIdx}').toggle();">[+/-]</a>
							{$_LANG.reports.columnCategories[$reportSource][$thisColCat]}
						</div>
						<div id="colCategoryBox_{$colCatIdx}">
						{assign var=hasCats value=1}
					{/if}

					<div class="eachColumn">
						{counter name=fieldsList}.
						<a href="#;" class="useColumn"
							{if $_LANG.reports.columnDescriptions[$reportSource][$colKey]}tooltip="{$_LANG.reports.columnDescriptions[$reportSource][$colKey]}"{/if}
							onclick="
								if ($F('selectedPivot') && $F('selectedPivot')!='0') {ldelim}
									$('columnNameTitle').innerHTML='{$colName}';
									$('selectedColumn').value='{$colKey}';
									$('columnOperation').value='{$columnsOperation[$colKey]}';
									overlib($('columnOptions').innerHTML, LEFT, BELOW, OFFSETY, -10, WIDTH, 230, STICKY, MOUSEOFF, 600)
								{rdelim} else {ldelim}
									alert('{$_LANG.reportsManagement.admin.pivots.chooseCurrentPivot}');
								{rdelim}
							"
						>{$colName}</a>
					</div>

					{assign var=lastColCat value=$thisColCat}
				{/foreach}

				{* close the last option group - if opened *}
				{if $thisColCat or $hasCats}</div>{/if}

				{* --- add custom columns --- *}
				{if $customColumnsList}
					<div class="colCategory">
						<a href="#;" class="link toggleCategory" onclick="$('colCategoryBox_cust').toggle();">[+/-]</a>
						{$_LANG.reportsManagement.admin.pivots.customColumnsSubtitle}
					</div>
					<div id="colCategoryBox_cust">
						{foreach from=$customColumnsList item=colDet key=colKey}
							<div class="eachColumn">
								{counter name=fieldsList}.
								<a href="#;" class="useColumn"
									onclick="
										if ($F('selectedPivot') && $F('selectedPivot')!='0') {ldelim}
											$('columnNameTitle').innerHTML='{$colDet.n}';
											$('selectedColumn').value='CUSTOM_COLUMN_{$colKey}';
											$('columnOperation').value='sum';
											overlib($('columnOptions').innerHTML, LEFT, BELOW, OFFSETY, -10, WIDTH, 230, STICKY, MOUSEOFF, 600)
										{rdelim} else {ldelim}
											alert('{$_LANG.reportsManagement.admin.pivots.chooseCurrentPivot}');
										{rdelim}
									"
								>{$colDet.n}</a>
							</div>
						{/foreach}
					</div>
				{/if}

			</div>

		</td>
	</tr>
</table>

<div id="columnOptions" style="display:none">
	<div id="columnNameTitle"></div>
	<a class="menuOption" href="#;" onclick="addColumnToPivot('rows');">
		<img src="{$smarty.const.SMARTY_BLANKGIF}" alt="" class="imgIcon icon-reportRows" style="float:right !important;" />
		{$_LANG.reportsManagement.admin.pivots.type_rows}
	</a>
	<a class="menuOption" href="#;" onclick="addColumnToPivot('cols');">
		<img src="{$smarty.const.SMARTY_BLANKGIF}" alt="" class="imgIcon icon-reportColumns" style="float:right !important;" />
		{$_LANG.reportsManagement.admin.pivots.type_cols}
	</a>
	<a class="menuOption" href="#;" onclick="addColumnToPivot('data');">
		<img src="{$smarty.const.SMARTY_BLANKGIF}" alt="" class="imgIcon icon-reportData" style="float:right !important;" />
		{$_LANG.reportsManagement.admin.pivots.type_data}
	</a>
</div>

<input id="selectedColumn" type="hidden" value="" />
<input id="columnOperation" type="hidden" value="" />


{* ========== RUN SOME SCRIPTS ON THE CURRENT PAGE ============================================= *}
<script language="javascript">

	{* resize the height of the columns *}
	Event.observe(window, 'resize', resizePivotTableHeight, false);
	resizePivotTableHeight();
	setInterval(resizePivotTableHeight, 4000);

	{* -- refresh the pivots list page -- *}
	ajaxIframeReload('pivotsListDiv', 'index_load_pivotTables_pivotsList.php');

</script>