// Table.js includes code used on the table page only.

var M_bMeasureDimensionOnRow = false;
var M_bRowDimensionCalcDisabled = false;

//-----------------------------------------------------------------------------
function OnSelectMembers(i_nHierarchy, i_szGroupCode, i_nLevel) {
   var szValue;

   szValue = i_szGroupCode.replace(new RegExp(GSingleQuoteRep, "g"), "\'");
   szValue = szValue.replace(new RegExp("<", "g"), GLtRep);
   szValue = szValue.replace(new RegExp(">", "g"), GGtRep);
   document.aspnetForm.SelectMembers.value = szValue;
   document.aspnetForm.SelectMembersLevel.value = i_nLevel;
   document.aspnetForm.SelectMembersHierarchy.value = i_nHierarchy;
   document.aspnetForm.FirstRow.value = 0;
   document.aspnetForm.FirstCol.value = 0;
   executeWait(document.aspnetForm);
}

//-----------------------------------------------------------------------------
function ShowPrintableVersion() {
   var anColWidths = new Array();
   var anRowHeights = new Array();
   var nCell;
   var nCol;
   var nCols;
   var nHeaderInfoHeight = 0;
   var nInnerColIndex;
   var nInnerRowIndex;
   var nRows;
   var objTemp;
   var OTHER_DIM_HEIGHT = 20;  // an estimate of the height of the other dims.
   var szCols = document.aspnetForm.Cols.value;
   var szRows = document.aspnetForm.Rows.value;

   nInnerColIndex = szRows.split(",").length - 1;
   nInnerRowIndex = szCols.split(",").length;

   var clFixedHeadersOnScrolling = document.aspnetForm.FixedHeadersOnScrolling;
   if (clFixedHeadersOnScrolling != null && clFixedHeadersOnScrolling.value == "true") {
      var objTable = document.getElementById("cornerTable");
      if (objTable != null) {
         var objRow = objTable.rows[nInnerRowIndex];
         var nCornerTableCols = objRow.cells.length;
         if (document.aspnetForm.DisplayChart.value == "True") {
            nCornerTableCols = nCornerTableCols -1
         }          
         for (nCell = 0; nCell < nCornerTableCols; nCell++) {
            anColWidths[nCell] = objRow.cells[nCell].offsetWidth;
         }

         // get the row heights
         var nCornerTableRows = objTable.rows.length;
         for (nCell = 0; nCell < nCornerTableRows; nCell++) {
            nCol = Math.min(nInnerColIndex, objTable.rows[nCell].cells.length - 1);
            anRowHeights[nCell] = objTable.rows[nCell].cells[nCol].offsetHeight;
         }
      }

      var objTable = document.getElementById("headerRowTable");
      if (objTable != null) {
         var objRow = objTable.rows[nInnerRowIndex];
         var nHeaderRowTableCols = objRow.cells.length;
         for (nCell = 0; nCell < nHeaderRowTableCols; nCell++) {
            anColWidths[nCornerTableCols + nCell] = objRow.cells[nCell].offsetWidth;
         }
      }

      // get the row heights
      var objTable = document.getElementById("headerColumnTable");
      if (objTable != null) {
         var nHeaderColumnTableRows = objTable.rows.length;
         for (nCell = 0; nCell < nHeaderColumnTableRows; nCell++) {
            nCol = Math.min(nInnerColIndex, objTable.rows[nCell].cells.length - 1);
            anRowHeights[nCornerTableRows + nCell] = objTable.rows[nCell].cells[nCol].offsetHeight;
         }
      }
   }
   else {
      // because of rowspans in the col headers, use the inner most row dim.
      if (document.aspnetForm.DisplayChart.value == "True") {
         nInnerRowIndex = szCols.split(",").length + 1;

      }
      // Only get the row/col measurements if there are preview charts.	         
      var objTable = document.getElementById("ContentsTable");
      if (objTable != null) {
         var objRow = objTable.rows[nInnerRowIndex];
         // get the column widths
         nCols = objRow.cells.length;
         for (nCell = 0; nCell < nCols; nCell++) {
            anColWidths[nCell] = objRow.cells[nCell].offsetWidth;
         }
         // get the row heights
         nRows = objTable.rows.length;
         for (nCell = 0; nCell < nRows; nCell++) {
            nCol = Math.min(nInnerColIndex, objTable.rows[nCell].cells.length - 1);
            anRowHeights[nCell] = objTable.rows[nCell].cells[nCol].offsetHeight;
         }
      }
   }

   // Get the height of the header info
   objTemp = document.getElementById("ReportTitle");
   if (objTemp != null) {
      nHeaderInfoHeight += objTemp.offsetHeight;
   }
   objTemp = document.getElementById("ReportSubTitles");
   if (objTemp != null) {
      nHeaderInfoHeight += objTemp.offsetHeight;
   }
   // other dims
   // estimate the height of the other dims, as they are written to screen
   // differently than in the table view.
   if (document.aspnetForm.OtherDimCount != null) {
      nHeaderInfoHeight += (OTHER_DIM_HEIGHT * document.aspnetForm.OtherDimCount.value);
   }
   document.aspnetForm.PrintColWidths.value = anColWidths;
   document.aspnetForm.PrintRowHeights.value = anRowHeights;
   document.aspnetForm.PrintHeaderInfoHeight.value = nHeaderInfoHeight;

   document.aspnetForm.PrintableVersion.value = "true";
   document.aspnetForm.ReportType.value = "chart";
   document.aspnetForm.target = "_parent";
   executeWait(document.aspnetForm);
}
// Chart view code
//-----------------------------------------------------------------------------
function OnSelectPreview(i_nStartRow, i_nStartCol) {

   // This function is called when full chart is requested from the preview.
   GetChartSize();
   zeroScrollPosition();

   document.aspnetForm.FullChartRequest.value = "True";
   document.aspnetForm.ChartStartRow.value = i_nStartRow;
   document.aspnetForm.ChartStartCol.value = i_nStartCol;
   document.aspnetForm.action = document.location.pathname;
   executeWait(document.aspnetForm);
}

//-----------------------------------------------------------------------------
function OnSelectPreview2(i_nStartRow, i_nEndRow, i_nStartCol, i_nEndCol) {
   // This function is called when the page right, left, up, down is clicked.
   GetChartSize();
   document.aspnetForm.ChartStartRow.value = i_nStartRow;
   document.aspnetForm.ChartEndRow.value = i_nEndRow;
   document.aspnetForm.ChartStartCol.value = i_nStartCol;
   document.aspnetForm.ChartEndCol.value = i_nEndCol;
   document.aspnetForm.action = document.location.pathname;
   executeWait(document.aspnetForm);
}

//-----------------------------------------------------------------------------
function OnChartSelectMembers(i_nHierarchy, i_szGroupCode, i_nLevel) {
   // This function is called when a member link is clicked.
   GetChartSize();
   document.aspnetForm.SelectMembers.value =
		i_szGroupCode.replace(new RegExp(GSingleQuoteRep, "g"), "\'");
   document.aspnetForm.SelectMembersLevel.value = i_nLevel;
   document.aspnetForm.SelectMembersDim.value = i_nDim;
   document.aspnetForm.ChartStartRow.value = 0;
   document.aspnetForm.ChartStartCol.value = 0;
   document.aspnetForm.FullChartRequest.value = "False";
   document.aspnetForm.action = document.location.pathname;
   executeWait(document.aspnetForm);
}


// Comment for test

