﻿function ShowRequiredFootnotes(i_nShow) {
   document.aspnetForm.ShowRequiredFootnotes.value = i_nShow;
   var clRequiredFootnotesDiv = document.getElementById("RequiredFootnotesDiv");
   var clRequiredFootnotesShown = document.getElementById("RequiredFootnotesShown");
   var clRequiredFootnotesHidden = document.getElementById("RequiredFootnotesHidden");
   
   if (clRequiredFootnotesDiv != null && clRequiredFootnotesShown != null && clRequiredFootnotesHidden != null) {
      if (i_nShow) {
         clRequiredFootnotesDiv.style.display = "block";
         clRequiredFootnotesShown.style.display = "block";
         clRequiredFootnotesHidden.style.display = "none";
      }
      else {
         clRequiredFootnotesDiv.style.display = "none";
         clRequiredFootnotesShown.style.display = "none";
         clRequiredFootnotesHidden.style.display = "block";
      }
   }
   // Resize scroll bars
   onLayoutResize();
}

function AdjustRequiredFootnotes() {
   var clRequiredFootnotesDiv = document.getElementById("RequiredFootnotesDiv");
   var clRequiredFootnotesShown = document.getElementById("RequiredFootnotesShown");
   var clRequiredFootnotesHidden = document.getElementById("RequiredFootnotesHidden");
   
   if (clRequiredFootnotesDiv != null && clRequiredFootnotesShown != null && clRequiredFootnotesHidden != null) {
      if (document.aspnetForm.ShowRequiredFootnotes.value == 'false') {
         clRequiredFootnotesDiv.style.display = "none";
         clRequiredFootnotesShown.style.display = "none";
         clRequiredFootnotesHidden.style.display = "block";
      }
      else {
         clRequiredFootnotesDiv.style.display = "block";
         clRequiredFootnotesShown.style.display = "block";
         clRequiredFootnotesHidden.style.display = "none";
      }
   }
}

//handles the up/down/left/right arrows for paging
function DispPage(i_unFirstRow, i_unFirstCol) {
   document.aspnetForm.FirstRow.value = i_unFirstRow;
   document.aspnetForm.FirstCol.value = i_unFirstCol;
   executeWait(document.aspnetForm);
}

function UpdateIconsState(i_bWrappingIconClicked) {
   var bIsAllOtherDimsDisplayed;
   var bIsLastOtherDimDisplayed = false;
   var bOtherDimWrappingOff;
   var clRow;
   var nOtherDimsCount;
   var nCellIndex;
   var nFirstDispOtherDim;

   var clOtherDimsTable = document.getElementById("OtherDimsTable");
   var clFirstOtherDimDiv = document.getElementById("FirstOtherDimDiv");
   var clFirstOtherDimDisabledDiv = document.getElementById("FirstOtherDimDisabledDiv");
   var clPreviousOtherDimDiv = document.getElementById("PreviousOtherDimDiv");
   var clPreviousOtherDimDisabledDiv = document.getElementById("PreviousOtherDimDisabledDiv");
   var clMainOtherDimsTable = document.getElementById("MainOtherDimsTable0");
   var clNextOtherDimDiv = document.getElementById("NextOtherDimDiv");
   var clNextOtherDimDisabledDiv = document.getElementById("NextOtherDimDisabledDiv");
   var clLastOtherDimDiv = document.getElementById("LastOtherDimDiv");
   var clLastOtherDimDisabledDiv = document.getElementById("LastOtherDimDisabledDiv");
   var clNoWrapOtherDimDiv = document.getElementById("NoWrapOtherDimDiv");
   var clWrapOtherDimDiv = document.getElementById("WrapOtherDimDiv");
   var clDisableWrapOtherDimDiv = document.getElementById("DisableWrapOtherDimDiv");
   var clTopMainOtherDimsTable = document.getElementById("TopMainOtherDimsTable");

   if (clOtherDimsTable == null || clFirstOtherDimDiv == null ||
         clFirstOtherDimDisabledDiv == null || clPreviousOtherDimDiv == null ||
         clPreviousOtherDimDisabledDiv == null || clNextOtherDimDiv == null ||
         clNextOtherDimDisabledDiv == null || clLastOtherDimDiv == null ||
         clLastOtherDimDisabledDiv == null || clWrapOtherDimDiv == null ||
         clDisableWrapOtherDimDiv == null) {
      return;
   }
   else {
      if (typeof (document.aspnetForm.FirstDispOtherDim) != "undefined") {
         nFirstDispOtherDim = parseInt(document.aspnetForm.FirstDispOtherDim.value);
      }
      if (typeof (document.aspnetForm.OtherDimWrappingOff) != "undefined") {
         bOtherDimWrappingOff = document.aspnetForm.OtherDimWrappingOff.value.toLowerCase();
      }

      if (bOtherDimWrappingOff == "true") {
         if (clMainOtherDimsTable != null) {
            clRow = clMainOtherDimsTable.rows[0];
            nOtherDimsCount = clRow.cells.length;
            if (clRow.cells[nOtherDimsCount - 1].style.display != "none") {
               bIsLastOtherDimDisplayed = true;
            }
            // Check if all other dimensions are displayed, wrapping should be disabled.
            bIsAllOtherDimsDisplayed = true;
            for (nCellIndex = 0; nCellIndex <= clRow.cells.length - 1; nCellIndex++) {
               if (clRow.cells[nCellIndex].style.display == "none") {
                  bIsAllOtherDimsDisplayed = false;
               }
            }
         }
         else {
            bIsLastOtherDimDisplayed = true;
            bIsAllOtherDimsDisplayed = true;
         }
         if (nFirstDispOtherDim > 0) {
            // First other dimension
            clFirstOtherDimDiv.style.display = "block";
            clFirstOtherDimDisabledDiv.style.display = "none";
            // Previous other dimension
            clPreviousOtherDimDiv.style.display = "block";
            clPreviousOtherDimDisabledDiv.style.display = "none";
         }
         else {
            // First other dimension
            clFirstOtherDimDiv.style.display = "none";
            clFirstOtherDimDisabledDiv.style.display = "block";
            // Previous other dimension
            clPreviousOtherDimDiv.style.display = "none";
            clPreviousOtherDimDisabledDiv.style.display = "block";
         }
         if (!bIsLastOtherDimDisplayed) {
            // Next other dimension
            clNextOtherDimDiv.style.display = "block";
            clNextOtherDimDisabledDiv.style.display = "none";
            // Last other dimension
            clLastOtherDimDiv.style.display = "block";
            clLastOtherDimDisabledDiv.style.display = "none";
         }
         else {
            // Next other dimension
            clNextOtherDimDiv.style.display = "none";
            clNextOtherDimDisabledDiv.style.display = "block";
            // Last other dimension
            clLastOtherDimDiv.style.display = "none";
            clLastOtherDimDisabledDiv.style.display = "block";
         }
         // Wrapping
         if (!bIsAllOtherDimsDisplayed) {
            clNoWrapOtherDimDiv.style.display = "block";
            clWrapOtherDimDiv.style.display = "none";
            clDisableWrapOtherDimDiv.style.display = "none";
         }
         else {
            if (i_bWrappingIconClicked == true) {
               if (clNoWrapOtherDimDiv.style.display == "none") {
                  clNoWrapOtherDimDiv.style.display = "block";
                  clWrapOtherDimDiv.style.display = "none";
               }
               else {
                  clNoWrapOtherDimDiv.style.display = "none";
                  clWrapOtherDimDiv.style.display = "block";
               }
            }
            else {
               clNoWrapOtherDimDiv.style.display = "none";
               clWrapOtherDimDiv.style.display = "none";
               clDisableWrapOtherDimDiv.style.display = "block";
            }
         }
      }
      else {
         // First other dimension
         clFirstOtherDimDiv.style.display = "none";
         clFirstOtherDimDisabledDiv.style.display = "block";
         // Previous other dimension
         clPreviousOtherDimDiv.style.display = "none";
         clPreviousOtherDimDisabledDiv.style.display = "block";
         // Next other dimension
         clNextOtherDimDiv.style.display = "none";
         clNextOtherDimDisabledDiv.style.display = "block";
         // Last other dimension
         clLastOtherDimDiv.style.display = "none";
         clLastOtherDimDisabledDiv.style.display = "block";
         // Wrapping
         if (clTopMainOtherDimsTable != null && clTopMainOtherDimsTable.rows.length > 1) {
            clNoWrapOtherDimDiv.style.display = "none";
            clWrapOtherDimDiv.style.display = "block";
            clDisableWrapOtherDimDiv.style.display = "none";
         }
         else {
            clDisableWrapOtherDimDiv.style.display = "block";
            clNoWrapOtherDimDiv.style.display = "none";
            clWrapOtherDimDiv.style.display = "none";
         }
      }
   }
}

//-----------------------------------------------------------------------------
function UpdateOtherDimsHTMLTable(i_bWrappingIconClicked) {
   var anCellsWidth = new Array();
   var bOtherDimWrappingOff;
   var clContentSplitter = $find("ctl00_RadContentSplitter");
   var clFirstRow;
   var clRow;
   var clTempTable;
   var clTopTableRow;
   var clTopTableRowCell;
   var clNewMainTable;
   var clNewMainTableRow;
   var nCurrentWidth;
   var nIndex;
   var nOtherDimsCount;
   var nCellIndex;
   var nCellsWidthIndex;
   var nFirstDispOtherDim;
   var nFixedWidth;
   var nOtherDimsTableAvailableWidth;
   var nRowsCount = 0;
   var nRowIndex;
   var nTempCellCount;
   var nTempCellIndex;
   var nTopTableRowsCount;

   var clOtherDimsTable = document.getElementById("OtherDimsTable");
   var clTopMainOtherDimsTable = document.getElementById("TopMainOtherDimsTable");
   var clFirstOtherDim = document.getElementById("FirstOtherDim");
   var clPreviousOtherDim = document.getElementById("PreviousOtherDim");
   var clMainOtherDimsTable = document.getElementById("MainOtherDimsTable0");
   var clNextOtherDim = document.getElementById("NextOtherDim");
   var clLastOtherDim = document.getElementById("LastOtherDim");
   var clWrappingOtherDim = document.getElementById("WrappingOtherDim");
   var clBlankOtherDim = document.getElementById("Oth-3")

   if (clOtherDimsTable == null || clFirstOtherDim == null ||
         clPreviousOtherDim == null || clNextOtherDim == null ||
         clLastOtherDim == null || clWrappingOtherDim == null) {
      return;
   }
   else {
      if (typeof (document.aspnetForm.FirstDispOtherDim) != "undefined") {
         nFirstDispOtherDim = parseInt(document.aspnetForm.FirstDispOtherDim.value);
      }
      if (typeof (document.aspnetForm.OtherDimWrappingOff) != "undefined") {
         bOtherDimWrappingOff = document.aspnetForm.OtherDimWrappingOff.value.toLowerCase();
      }
      nOtherDimsTableAvailableWidth = clContentSplitter.getEndPane().get_width() - 1;

      nFixedWidth = parseInt(clFirstOtherDim.width) + parseInt(clPreviousOtherDim.width) +
	                    parseInt(clNextOtherDim.width) + parseInt(clLastOtherDim.width) +
	                    parseInt(clWrappingOtherDim.width);

      if (clTopMainOtherDimsTable != null) {
         // Put all the other dimensions in the first row
         // and delete all the other rows.
         nRowsCount = clTopMainOtherDimsTable.rows.length;
         if (nRowsCount > 1) {
            clFirstRow = clMainOtherDimsTable.rows[0];
            for (nRowIndex = 1; nRowIndex < nRowsCount; nRowIndex++) {
               var id = "MainOtherDimsTable" + nRowIndex;
               clTempTable = document.getElementById("MainOtherDimsTable" + nRowIndex);
               if (clTempTable != null) {
                  clTempRow = clTempTable.rows[0];
                  nTempCellCount = clTempRow.cells.length - 1;
                  for (nCellIndex = 0; nCellIndex <= nTempCellCount; nCellIndex++) {
                     clFirstRow.appendChild(clTempRow.cells[0]);
                  }
               }
            }
            for (nRowIndex = nRowsCount - 1; nRowIndex >= 1; nRowIndex--) {
               clTopMainOtherDimsTable.deleteRow(nRowIndex);
            }
         }

         clRow = clMainOtherDimsTable.rows[0];
         nOtherDimsCount = clRow.cells.length - 1;
         // Dispaly all the other dimensions and then save the width of each of them.
         for (nCellIndex = 0; nCellIndex <= nOtherDimsCount; nCellIndex++) {
            clRow.cells[nCellIndex].style.display = "";
         }
         for (nCellIndex = 0; nCellIndex <= nOtherDimsCount; nCellIndex++) {
            anCellsWidth[nCellIndex] = clRow.cells[nCellIndex].offsetWidth;
         }
         // First hide all the other dimensions.
         for (nCellIndex = 0; nCellIndex <= nOtherDimsCount; nCellIndex++) {
            clRow.cells[nCellIndex].style.display = "none";
         }

         //force to re-write the top main other dimension table
         var clTopMainOtherDimsTableTD = document.getElementById("Oth-2");
         clTopMainOtherDimsTableTD.style.display = "none";
         clTopMainOtherDimsTableTD.style.display = "";

         // Wrapping Off  
         if (bOtherDimWrappingOff == "true") {
            // Start displaying from the current first other dimension.
            if (nFirstDispOtherDim != -1) {
               nCellIndex = nFirstDispOtherDim;
               while (nCellIndex <= nOtherDimsCount) {
                  if (clRow.cells[nFirstDispOtherDim].style.display == "none") {
                     clRow.cells[nFirstDispOtherDim].style.display = "";
                     nCurrentWidth = nFixedWidth + anCellsWidth[nCellIndex];
                  }
                  else {
                     if (nCurrentWidth + anCellsWidth[nCellIndex] <= nOtherDimsTableAvailableWidth) {
                        clRow.cells[nCellIndex].style.display = "";
                     }
                     nCurrentWidth += anCellsWidth[nCellIndex];
                  }
                  nCellIndex++;
               }
            }
            // The value of the first displayed other dimension is -1.
            // Start displaying from the last one.
            else {
               nCellIndex = nOtherDimsCount;
               while (nCellIndex >= 0) {
                  if (clRow.cells[nOtherDimsCount].style.display == "none") {
                     clRow.cells[nOtherDimsCount].style.display = "";
                     document.aspnetForm.FirstDispOtherDim.value = nCellIndex;
                     nCurrentWidth = nFixedWidth + anCellsWidth[nCellIndex];
                  }
                  else {
                     if (nCurrentWidth + anCellsWidth[nCellIndex] <= nOtherDimsTableAvailableWidth) {
                        clRow.cells[nCellIndex].style.display = "";
                        document.aspnetForm.FirstDispOtherDim.value = nCellIndex;
                     }
                     nCurrentWidth = nCurrentWidth + anCellsWidth[nCellIndex];
                  }
                  nCellIndex--;
               }
            }
         }
         // Wrapping On
         else {
            // Now that all the other dimensions are in the first row of the 
            // HTML table, turn the wrapping on and update the HTML table by
            // adding needed rows.
            clTempRow = clRow;
            nCellIndex = 0;
            nCellsWidthIndex = 0;
            while (nCellIndex <= clTempRow.cells.length - 1) {
               if (clTempRow.cells[0].style.display == "none") {
                  clTempRow.cells[0].style.display = "";
                  nCurrentWidth = nFixedWidth + anCellsWidth[nCellsWidthIndex];
                  nCellIndex++;
                  nCellsWidthIndex++;
               }
               else {
                  if (nCurrentWidth + anCellsWidth[nCellsWidthIndex] <= nOtherDimsTableAvailableWidth) {
                     clTempRow.cells[nCellIndex].style.display = "";
                     nCurrentWidth = nCurrentWidth + anCellsWidth[nCellsWidthIndex];
                     nCellIndex++;
                     nCellsWidthIndex++;
                  }
                  else {
                     nRowsCount = clTopMainOtherDimsTable.rows.length;
                     clTopTableRow = clTopMainOtherDimsTable.insertRow(nRowsCount);
                     clTopTableRowCell = document.createElement("td");
                     clNewMainTable = document.createElement("table");
                     clNewMainTable.id = "MainOtherDimsTable" + nRowsCount;
                     clNewMainTable.border = 0;
                     clNewMainTable.cellPadding = 0;
                     clNewMainTable.cellSpacing = 0;
                     clNewMainTableRow = clNewMainTable.insertRow(0);
                     nTempCellCount = clTempRow.cells.length - 1;
                     nIndex = 0;
                     for (nTempCellIndex = 0; nTempCellIndex <= nTempCellCount; nTempCellIndex++) {
                        if (clTempRow.cells[nIndex].style.display == "none") {
                           clNewMainTableRow.appendChild(clTempRow.cells[nIndex]);
                        }
                        else {
                           nIndex++;
                        }
                     }
                     clTopTableRowCell.appendChild(clNewMainTable);
                     clTopTableRow.appendChild(clTopTableRowCell);
                     clTempRow = clNewMainTableRow;
                     nCellIndex = 0;
                  }
               }
            }
         }
      }
      // Update the icons state
      UpdateIconsState(i_bWrappingIconClicked);
   }
}


//-----------------------------------------------------------------------------
function DispFirstOtherDim() {
   if (typeof (document.aspnetForm.FirstDispOtherDim) != "undefined") {
      if (parseInt(document.aspnetForm.FirstDispOtherDim.value) > 0) {
         document.aspnetForm.FirstDispOtherDim.value = 0;
      }
   }
   UpdateOtherDimsHTMLTable();
}

//-----------------------------------------------------------------------------
function DispPreviousOtherDim() {
   if (typeof (document.aspnetForm.FirstDispOtherDim) != "undefined") {
      if (parseInt(document.aspnetForm.FirstDispOtherDim.value) > 0) {
         document.aspnetForm.FirstDispOtherDim.value = parseInt(document.aspnetForm.FirstDispOtherDim.value) - 1;
      }
   }
   UpdateOtherDimsHTMLTable();
}

//-----------------------------------------------------------------------------
function DispNextOtherDim() {
   var clRow;
   var nOtherDimsCount;

   var clMainOtherDimsTable = document.getElementById("MainOtherDimsTable0");
   clRow = clMainOtherDimsTable.rows[0];
   nOtherDimsCount = clRow.cells.length - 1;
   if (typeof (document.aspnetForm.FirstDispOtherDim) != "undefined") {
      if (parseInt(document.aspnetForm.FirstDispOtherDim.value) < nOtherDimsCount) {
         document.aspnetForm.FirstDispOtherDim.value = parseInt(document.aspnetForm.FirstDispOtherDim.value) + 1;
      }
   }
   UpdateOtherDimsHTMLTable();
}

//-----------------------------------------------------------------------------
function DispLastOtherDim() {
   if (typeof (document.aspnetForm.FirstDispOtherDim) != "undefined") {
      // -1 is assigned to the first displayed other dimension that means
      // the display will start from the last one.
      document.aspnetForm.FirstDispOtherDim.value = -1;
   }
   UpdateOtherDimsHTMLTable();
}

//-----------------------------------------------------------------------------
function WrappingOtherDims(i_bWrap) {
   if (typeof (document.aspnetForm.OtherDimWrappingOff) != "undefined") {
      document.aspnetForm.OtherDimWrappingOff.value = i_bWrap;
   }
   UpdateOtherDimsHTMLTable(true);
   onLayoutResize();
}

function InitializeOtherDims() //called from onPageLoad; this code is not in onPageLoad because this way it gets cached by browsers
{
   UpdateOtherDimsHTMLTable();
}

function ChangeMember(i_nHierarchy, i_bUp) {
   if (i_bUp) {
      document.aspnetForm.PreviousMemberForHierarchy.value = i_nHierarchy;
   }
   else {
      document.aspnetForm.NextMemberForHierarchy.value = i_nHierarchy;
   }
   executeWait(document.aspnetForm);
}



function OnActiveMemberChange(i_nHierarchy, i_strMember) {
   var strActiveMamber = eval("document.aspnetForm.ActiveMember" + i_nHierarchy.toString() + ".value;");

   if (i_strMember != strActiveMamber) {
      eval("document.aspnetForm.ActiveMember" + i_nHierarchy.toString() + ".value = i_strMember;");
      document.aspnetForm.SpecificActiveMemberName.value = i_strMember;
      executeWait(document.aspnetForm);
	}
}

function RefreshActiveMembers() {
   var strMemberName;
   var strFieldName;

   document.aspnetForm.SpecificActiveMemberName.value = "";
   document.aspnetForm.PreviousMemberForHierarchy.value = "";
   document.aspnetForm.NextMemberForHierarchy.value = "";
   for (var i = 0; i < M_astrActiveMembers.length; i++) {

      strMemberName = M_astrActiveMembers[i];
      strMemberName = strMemberName.replace(new RegExp("<", "g"), GLtRep);
      strMemberName = strMemberName.replace(new RegExp(">", "g"), GGtRep);
      strFieldName = "ActiveMember" + M_anViewHierarchyIndices[i].toString()
      if (document.getElementsByName(strFieldName).length != 0) {
         eval("document.aspnetForm.ActiveMember" + M_anViewHierarchyIndices[i].toString() + ".value = strMemberName;");
      }
   }
}

function ShowDownloadOptions() {
   DisplayOption(g_strDownloadOptions);
   onLayoutResize();
   document.aspnetForm.DownloadId.focus();
}

var g_strExcelXmlOptions = "<div id='ExcelXmlOptionDiv' style='display:none;'>"
+ "<table border=0 cellPadding='0' cellSpacing='0'>"
+ "<tr>"
+ "<td class=Default nowrap width='1%'>"
+ "<LABEL FOR=DataFormatXml ACCESSKEY='f'>"
+ resDataFormat
+ "</LABEL>&nbsp;</td>"
+ "<td nowrap>"
+ "<select class=Default id='DataFormatXml' "
+ "onkeypress='javascript:SubmitDownload(event);'>"
+ "<option selected value='EXCEL_WPR'>"
+ resOneWorsheetPerReport
+ "</option>"
+ "<option value='EXCEL_WPS'>"
+ resOneWorsheetPer2dSlice
+ "</option>"
+ "<option value='EXCEL_LF'>"
+ resListFormat
+ "</option>"
+ "<option value='EXCEL_LFS'>"
+ resSparseListFormat
+ "</option>"
+ "</select></td></tr>"
+ "</table>"
+ "</div>";

// download options dialog box
var g_strDownloadOptions = "<TABLE class='OptionTable' width='100%' cellPadding='3' cellSpacing='0'>"
+ "<TR height='3'>"
+ "</TR>"
+ "<tr><td class=OptionHeader nowrap colspan=2>"
+ resDownloadReportDataTo
+ "</td></tr>"
+ "<tr>"
+ "<td class=Default nowrap width='1%'>"
+ "<LABEL FOR=DownloadId ACCESSKEY='d'>" + resDownloadFormat + "</LABEL>"
+ "</td>"
+ "<td nowrap>"
+ "<select class=Default name='Download' title = '" + resDownloadFormat + "' id=DownloadId "
+ "onkeypress='javascript:SubmitDownload(event);' onkeyup='javascript:OnDownloadChange();' onchange='javascript:OnDownloadChange();'>"
+ TranslateDownloadOptions()
+ "</select>"
+ "</td>"
+ "</tr>"
+ "<tr>"
+ "<td colspan=2>"
+ g_strExcelXmlOptions
+ "</td></tr>"
+ "<tr height='6'></tr>"
+ "<TR>"
+ "<td colspan=2>"
+ "<input type=button name=DownloadReportGo value=\"" + resOK
+ "\" onclick=\"javascript:OnDownloadReportOptions();\">&nbsp;"
+ "<input type=button name=Cancel value=\"" + resCancel
+ "\" onclick=\"javascript:OnCancelOptions();\">&nbsp;"
+ "<input name=DialogHelpButton type=button value=\"" + resHelp
+ "\" onclick=\"javascript:DisplayDialogHelp('Download.htm', '');\">"
+ "</td>"
+ "</TR>"
+ "</TABLE>";

//gets the list of allowed types in M_strAllowedDownloadTypes, something like "CSV,SSV,XML"
function TranslateDownloadOptions() {
   // TBD this function should be moved to a table page js area.
   var strOptions = "";
   if (typeof (M_strAllowedDownloadTypes) != "undefined") {
      var astrOptions = M_strAllowedDownloadTypes.split(",");

      for (var i = 0; i < astrOptions.length; i++) {
         strOptions += "<option value='" + astrOptions[i] + "'>" + GetDownloadText(astrOptions[i]) + "</option>";
      }
   }
   return strOptions;
}

function GetDownloadText(strVal) {
   switch (strVal) {
      case "CSV": return resCsv;
      case "SSV": return resSsv;
      case "XML": return resExcelXml;
   }
   return "";
}

function SubmitDownload(e) {
   var key = GetKeyCode(e);
   if (key == 13) {
      OnDownloadReportOptions();
      ResetSubmit(e);
   }
}

function OnDownloadReportOptions() {
   var obj = document.aspnetForm.Download;
   var szFormat = obj.options[obj.selectedIndex].value;
   document.aspnetForm.DownloadFormat.value = szFormat;
   var lTotalCellNo = M_unRows * M_unCols;
   var ulCellNoLimit = 0;

   switch (szFormat) {
      case "CSV": ulCellNoLimit = M_nCellDownloadLimitCSV; break;
      case "SSV": ulCellNoLimit = M_nCellDownloadLimitSSV; break;
      case "XML": ulCellNoLimit = M_nCellDownloadLimitXML; break;
   }

   if (lTotalCellNo > ulCellNoLimit) {
      alert(lTotalCellNo.toString() + " " + resCellNoLimitReached + " " +
               ulCellNoLimit.toString() + ".\n" + resCellNoLimitTryAgain);
      return false;
   }

   document.aspnetForm.action = "../View/dispview.aspx?download=yes";

   if (szFormat == "XML") {
      var objDataFormatXml = document.aspnetForm.DataFormatXml;
      document.aspnetForm.action += "&ExcelXmlDataFormat=" + objDataFormatXml.options[objDataFormatXml.selectedIndex].value;
   }

   OnCancelOptions(); //hide options form, restore toolbar buttons
   onLayoutResize();

   //called this way to give time for OnCancelOptions to end before the submit (necessary in IE 6)   
   setTimeout("document.aspnetForm.submit();document.aspnetForm.DownloadFormat.value='';document.aspnetForm.action = document.location.pathname;", 1000);
   return true;
}

function OnDownloadChange(i_nSelectedIndex) {
   var nIndex;
   var szFormat;
   var obj = document.aspnetForm.Download;
   var objExcelXmlDiv = document.getElementById("ExcelXmlOptionDiv");
   var objDownloadDiv = document.getElementById("DownloadReportOptionsDiv");

   if (i_nSelectedIndex == null) {
      nIndex = obj.selectedIndex;
   }
   else {
      nIndex = i_nSelectedIndex;
   }
   szFormat = obj.options[nIndex].value;
   if (objDownloadDiv != null && !G_dIEVersion) {
      objDownloadDiv.style.overflow = 'hidden';
   }
   if (szFormat == "XML") {
      objExcelXmlDiv.style.display = 'block';
   }
   else {
      objExcelXmlDiv.style.display = 'none';
   }
   onLayoutResize();
   if (objDownloadDiv != null && !G_dIEVersion) {
      objDownloadDiv.style.overflow = 'auto';
   }
}

function SaveCurrentReport() {
   pleaseWait();
   setTimeout("SaveReport();", 10);
}

function SaveReport(i_szNewTitle, i_bApplyDefault, i_nNewFolderId) {
   var aszActiveMembers;
   var aszAdHocGroupMembers;
   var aszAdHocGroupNames;
   var aszChecked;
   var aszCustomBandNames;
   var aszCustomBandValues;
   var aszReverseMemberOrder;
   var aszSelectedLevelLabels;
   var aszSelGroups;
   var aszSelLevels;
   var aszSelSearches;
   var aszTimeSetNames;
   var aszTimeSets;
   var aszUnChecked;
   var aszUnSelGroups;
   var bApplyDefault = true;
   var bCommon;
   var bDimensionValuesPercentages;
   var bFixedHeadersOnScrolling;
   var bSlicerSingleLine;
   var bFullChartRequest;
   var bIncludeCurrentDate;
   var bReductionShowTotalOfOthers;
   var bSuppressCols;
   var bSuppressRows;
   var clObj;
   var dReductionValue;
   var nCubeId;
   var nDrillThroughActionIndex = 0;
   var nFolderId;
   var nHierarchyCount;
   var nIndex;
   var nLabelLength;
   var nMasterDrillthroughActionIndex = 0;
   var nPageMaxCols;
   var nPageMaxRows;
   var nReductionColumn;
   var nReductionType;
   var nReductionValueType;
   var nReportId;
   var nReportType;
   var nSortColumn;
   var nSortType;
   var nSuppressionType;
   var nUserId;
   var szChartOptions;
   var szCustomUser;
   var szDrillThrough = "";
   var szDrillThroughItems = "";
   var szEhCellColor;
   var szEhFrom;
   var szEhMeasures;
   var szEhSelect;
   var szEhTextColor;
   var szEhTo;
   var szFieldNames = "";
   var szHierarchyAverages;
   var szHierarchyMaximums;
   var szHierarchyMeasureTotals;
   var szHierarchyMedians;
   var szHierarchyMinimums;
   var szHierarchyPercentages;
   var szHierarchyStdDeviations;
   var szHierarchyTotals;
   var szHierarchyVariances;
   var szLanguage;
   var szMasterDrillthrough = "";
   var szMasterDrillthroughItems = "";
   var szMeasureFactors;
   var szNestedCols;
   var szNestedFillers;
   var szNestedOthers;
   var szNestedRows;
   var szRankedColumns;
   var szSuppressFrom;
   var szSuppressTo;
   var szTitle;

   nReportId = parseInt(document.aspnetForm.ReportId.value);
   nCubeId = parseInt(document.aspnetForm.CubeId.value);
   if (document.aspnetForm.ReportType.value == "chart") {
      nReportType = 2;
   }
   else if (document.aspnetForm.ReportType.value == "drillthrough") {
      nReportType = 4;
      szDrillThroughItems = document.aspnetForm.DrillThroughItems.value;
      nDrillThroughActionIndex = parseInt(document.aspnetForm.DrillthroughActionIndex.value);
   }
   else if (document.aspnetForm.ReportType.value == "masterdrillthrough") {
      nReportType = 5;
      szMasterDrillthroughItems = document.aspnetForm.MasterDrillThroughItems.value;
      nMasterDrillthroughActionIndex = parseInt(document.aspnetForm.MasterDrillthroughActionIndex.value);
   }
   else {
      nReportType = 1;
   }
   if (document.aspnetForm.isAdministrator.value == "True") {
      bCommon = true;
   }
   else {
      bCommon = false;
   }
   nUserId = parseInt(document.aspnetForm.userId.value);
   if (typeof (i_szNewTitle) != "undefined") {
      szTitle = i_szNewTitle
   }
   else {
      szTitle = document.aspnetForm.ViewTitle.value;
   }
   szLanguage = document.aspnetForm.PerspectiveLanguage.value;
   if (typeof (i_bApplyDefault) != "undefined") {
      bApplyDefault = i_bApplyDefault
   }
   if (typeof (i_nNewFolderId) != "undefined") {
      nFolderId = i_nNewFolderId;
   }
   else {
      nFolderId = parseInt(document.aspnetForm.ReportFolderId.value);
   }
   if (document.aspnetForm.FullChartRequest.value == "True") {
      bFullChartRequest = true;
   }
   else {
      bFullChartRequest = false;
   }
   szChartOptions = ";" + document.aspnetForm.ChartType.value + ";;;"
      + document.aspnetForm.ChartDataLabels.value + ";"
      + document.aspnetForm.ChartSize.value;
   if (bFullChartRequest) {
      szChartOptions += ";True;" + document.aspnetForm.ChartStartRow.value + ";"
         + document.aspnetForm.ChartStartCol.value;
   }
   else {
      szChartOptions += ";False;0;0";
   }
   szChartOptions += ";;;"
         + document.aspnetForm.ScaleBreak.value + ";"
         + document.aspnetForm.ScaleBreakThreshold.value;  
   
   szFieldNames = document.aspnetForm.FieldNames.value;
   if (szFieldNames != "") {
      szDrillThrough = szFieldNames + GMajorSegmentDelimiter
         + document.aspnetForm.Flds.value + GMajorSegmentDelimiter
         + document.aspnetForm.FieldsSelected.value + GMajorSegmentDelimiter
         + document.aspnetForm.FieldTypes.value + GMajorSegmentDelimiter
         + document.aspnetForm.DrillthroughTableRowPageSize.value + GMajorSegmentDelimiter
         + document.aspnetForm.DrillthroughTableColPageSize.value + GMajorSegmentDelimiter
         + GMajorSegmentDelimiter
         + document.aspnetForm.FilterField1.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterField2.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterValue1.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterValue2.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterFieldType1.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterFieldType2.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterOperator1.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterOperator2.value + GMajorSegmentDelimiter
         + document.aspnetForm.FilterRelation.value + GMajorSegmentDelimiter
         + GMajorSegmentDelimiter
         + document.aspnetForm.DrillThroughSortField.value + GMajorSegmentDelimiter
         + document.aspnetForm.DrillThroughSortOrder.value;
   }
   szFieldNames = document.aspnetForm.MasterFieldNames.value;
   if (szFieldNames != "") {
      szMasterDrillthrough = szFieldNames + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFieldOrder.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFieldSelected.value + GMajorSegmentDelimiter
         + document.aspnetForm.DrillthroughTableRowPageSize.value + GMajorSegmentDelimiter
         + document.aspnetForm.DrillthroughTableColPageSize.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFilterField1.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFilterField2.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFilterValue1.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFilterValue2.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFilterOperator1.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFilterOperator2.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFilterRelation.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFieldSort.value + GMajorSegmentDelimiter
         + document.aspnetForm.MasterFieldSortOrder.value;
   }
   nHierarchyCount = parseInt(document.aspnetForm.HierarchyCount.value);
   aszChecked = new Array(nHierarchyCount);
   aszUnChecked = new Array(nHierarchyCount);
   aszSelGroups = new Array(nHierarchyCount);
   aszUnSelGroups = new Array(nHierarchyCount);
   aszSelLevels = new Array(nHierarchyCount);
   aszSelSearches = new Array(nHierarchyCount);
   aszReverseMemberOrder = new Array(nHierarchyCount);
   aszTimeSets = new Array(nHierarchyCount);
   aszTimeSetNames = new Array(nHierarchyCount);
   aszActiveMembers = new Array(nHierarchyCount);
   aszSelectedLevelLabels = new Array(nHierarchyCount);
   aszAdHocGroupMembers = new Array(nHierarchyCount);
   aszAdHocGroupNames = new Array(nHierarchyCount);
   aszCustomBandValues = new Array(nHierarchyCount);
   aszCustomBandNames = new Array(nHierarchyCount);
   for (nIndex = 0; nIndex < nHierarchyCount; nIndex++) {
      clObj = eval("document.aspnetForm.Chk" + nIndex);
      if (typeof (clObj) != "undefined") aszChecked[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.UnChk" + nIndex);
      if (typeof (clObj) != "undefined") aszUnChecked[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.SelGroups" + nIndex);
      if (typeof (clObj) != "undefined") aszSelGroups[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.UnSelGroups" + nIndex);
      if (typeof (clObj) != "undefined") aszUnSelGroups[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.SelLevels" + nIndex);
      if (typeof (clObj) != "undefined") aszSelLevels[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.SelSearches" + nIndex);
      if (typeof (clObj) != "undefined") aszSelSearches[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.ReverseMemberOrder" + nIndex);
      if (typeof (clObj) != "undefined") aszReverseMemberOrder[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.TimeSeriesSelections" + nIndex);
      if (typeof (clObj) != "undefined") aszTimeSets[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.TimeSetNames" + nIndex);
      if (typeof (clObj) != "undefined") aszTimeSetNames[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.ActiveMember" + nIndex);
      if (typeof (clObj) != "undefined") aszActiveMembers[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.SelectedLevelLabels" + nIndex);
      if (typeof (clObj) != "undefined") aszSelectedLevelLabels[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.AdHocGroupMembers" + nIndex);
      if (typeof (clObj) != "undefined") aszAdHocGroupMembers[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.AdHocGroupNames" + nIndex);
      if (typeof (clObj) != "undefined") aszAdHocGroupNames[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.CustomBandValues" + nIndex);
      if (typeof (clObj) != "undefined") aszCustomBandValues[nIndex] = clObj.value;
      clObj = eval("document.aspnetForm.CustomBandNames" + nIndex);
      if (typeof (clObj) != "undefined") aszCustomBandNames[nIndex] = clObj.value;
   }
   szHierarchyMeasureTotals = document.aspnetForm.HierarchyMeasureTotals.value;
   szMeasureFactors = document.aspnetForm.scMeasureFactors.value;
   szNestedCols = document.aspnetForm.Cols.value;
   szNestedRows = document.aspnetForm.Rows.value;
   szNestedOthers = document.aspnetForm.Others.value;
   szNestedFillers = document.aspnetForm.Fillers.value;
   szHierarchyTotals = document.aspnetForm.HierarchyTotals.value;
   szHierarchyPercentages = document.aspnetForm.HierarchyPercentages.value;
   szHierarchyAverages = document.aspnetForm.HierarchyAverages.value;
   szHierarchyMedians = document.aspnetForm.HierarchyMedians.value;
   szHierarchyMinimums = document.aspnetForm.HierarchyMinimums.value;
   szHierarchyMaximums = document.aspnetForm.HierarchyMaximums.value;
   szHierarchyVariances = document.aspnetForm.HierarchyVariances.value;
   szHierarchyStdDeviations = document.aspnetForm.HierarchyStdDeviations.value;
   if (document.aspnetForm.DimensionValuesPercentages.value == "True") {
      bDimensionValuesPercentages = true;
   }
   else {
      bDimensionValuesPercentages = false;
   }
   if (document.aspnetForm.SuppressRowsValue.value == "True") {
      bSuppressRows = true;
   }
   else {
      bSuppressRows = false;
   }
   if (document.aspnetForm.SuppressColsValue.value == "True") {
      bSuppressCols = true;
   }
   else {
      bSuppressCols = false;
   }
   szEhSelect = document.aspnetForm.ehSelect.value;
   szEhFrom = document.aspnetForm.ehFrom.value;
   szEhTo = document.aspnetForm.ehTo.value;
   szEhCellColor = document.aspnetForm.ehCellColor.value;
   szEhTextColor = document.aspnetForm.ehTextColor.value;
   szEhMeasures = document.aspnetForm.ehMeasures.value;
   szRankedColumns = document.aspnetForm.RankedColumns.value;
   nReductionColumn = parseInt(document.aspnetForm.ReductionColumn.value);
   nReductionType = parseInt(document.aspnetForm.ReductionType.value);
   nReductionValueType = parseInt(document.aspnetForm.ReductionValueType.value);
   dReductionValue = parseFloat(document.aspnetForm.ReductionValue.value);
   if (document.aspnetForm.ReductionShowTotalOfOthers.value == "True") {
      bReductionShowTotalOfOthers = true;
   }
   else {
      bReductionShowTotalOfOthers = false;
   }
   nPageMaxRows = parseInt(document.aspnetForm.TableRowPageSize.value);
   nPageMaxCols = parseInt(document.aspnetForm.TableColPageSize.value);
   nSuppressionType = parseInt(document.aspnetForm.SuppressionTypeValue.value);
   szSuppressFrom = document.aspnetForm.SuppressFromValue.value;
   szSuppressTo = document.aspnetForm.SuppressToValue.value;
   if (document.aspnetForm.FixedHeadersOnScrolling.value == "true") {
      bFixedHeadersOnScrolling = true;
   }
   else {
      bFixedHeadersOnScrolling = false;
  }
  if (document.aspnetForm.SlicerSingleLine.value == "True") {
      bSlicerSingleLine = true;
  }
  else {
      bSlicerSingleLine = false;
  }
   nLabelLength = parseInt(document.aspnetForm.LabelLength.value);
   if (document.aspnetForm.IncludeCurrentDateInReports.value == "True") {
      bIncludeCurrentDate = true;
   }
   else {
      bIncludeCurrentDate = false;
   }
   nSortType = parseInt(document.aspnetForm.SortType.value);
   nSortColumn = parseInt(document.aspnetForm.SortColumn.value);
   szCustomUser = document.aspnetForm.CustomUser.value;
   showWait();
   PageMethods.SaveReport(nReportId, nCubeId, document.aspnetForm.ApplicationPath.value, nReportType, bCommon, nUserId,
      szTitle, szLanguage, bApplyDefault, nFolderId, szChartOptions, szDrillThrough,
      aszChecked, aszUnChecked, aszSelGroups, aszUnSelGroups, aszSelLevels, aszSelSearches, 
      aszReverseMemberOrder, aszTimeSets, aszTimeSetNames, aszActiveMembers, aszSelectedLevelLabels,
      aszAdHocGroupMembers, aszAdHocGroupNames, aszCustomBandValues, aszCustomBandNames,
      szHierarchyMeasureTotals, szMeasureFactors, 
      szNestedCols, szNestedRows, szNestedOthers, szNestedFillers,
      szHierarchyTotals, szHierarchyPercentages, szHierarchyAverages, szHierarchyMedians,
      szHierarchyMinimums, szHierarchyMaximums, szHierarchyVariances, szHierarchyStdDeviations,
      bDimensionValuesPercentages, bSuppressRows, bSuppressCols, szEhSelect, szEhFrom, szEhTo,
      szEhCellColor, szEhTextColor, szEhMeasures, szRankedColumns, nReductionColumn, nReductionType,
      nReductionValueType, dReductionValue, bReductionShowTotalOfOthers, nPageMaxRows, nPageMaxCols,
      nSuppressionType, szSuppressFrom, szSuppressTo, bFixedHeadersOnScrolling, nLabelLength,
      bIncludeCurrentDate, nSortType, nSortColumn, szCustomUser, szDrillThroughItems, nDrillThroughActionIndex,
      szMasterDrillthrough, szMasterDrillthroughItems, nMasterDrillthroughActionIndex, bSlicerSingleLine, 
      onSaveReportComplete);
}

function onSaveReportComplete(results, context, methodName) {
   var aszResults = results.split(GCommaRep);
   var clMenu = $find("ctl00_RadPageMenu");
   var clReportNotes;
   var clReportTitle;
   var clRadToolbar = $find("ctl00_MainContent_RadContentToolBar");
   var clSaveErrorMsg;
   var nFolderId;
   var nReportId;
   var szErrorMsg;
   var szTitle;

   if (aszResults.length > 3) {
      nReportId = parseInt(aszResults[0]);
      szTitle = aszResults[1];
      nFolderId = parseInt(aszResults[2]);
      szErrorMsg = aszResults[3];
      if (szErrorMsg != "") {
         szErrorMsg = eval("res" + szErrorMsg);
         clSaveErrorMsg = document.getElementById("SaveReportMsg");
         if (clSaveErrorMsg != null) {
            clSaveErrorMsg.innerHTML = szErrorMsg;
            document.aspnetForm.SaveAs.focus();
         }
         else {
            alert(szErrorMsg);
         }
      }
      else {
         if (nReportId > 0) {
            OnCancelOptions();
            if (document.aspnetForm.ReportId.value != nReportId) {
               document.aspnetForm.ReportId.value = nReportId;
               document.aspnetForm.ReportFolderId.value = nFolderId;
               document.aspnetForm.ViewTitle.value = escapeHTML(szTitle);
               szTitle = szTitle.replace(new RegExp(GLtRep, "g"), "<");
               szTitle = szTitle.replace(new RegExp(GGtRep, "g"), ">");
               clReportTitle = document.getElementById("ReportTitleText");
               if (clReportTitle != null) {
                  szTitle = escapeHTML(szTitle);
                  if (document.aspnetForm.ReportType.value == "drillthrough") {
                     szTitle = resDrillthroughDataPrompt + " " + szTitle;
                  }
                  else if (document.aspnetForm.ReportType.value == "masterdrillthrough") {
                     szTitle = resMasterDrillthroughDataPrompt + " " + szTitle;
                  }
                  clReportTitle.innerHTML = szTitle;
               }
               clReportNotes = document.getElementById("ReportTitleNotes");
               if (clReportNotes != null) {
                  clReportNotes.innerHTML = "";
               }
            }
            AdjustMenuItem(clMenu, "MenuSave", true);
            AdjustMenuItem(clMenu, "MenuSaveAs", true);
            AdjustRadToolbarItem(clRadToolbar, "ToolbarMenuSave", true);
            AdjustRadToolbarItem(clRadToolbar, "ToolbarMenuSaveAs", true);
         }
      }
   }
   hideWait();
}

function SaveCurrentRSReport() {
   document.aspnetForm.SaveRSReportId.value = document.aspnetForm.ReportId.value;
   executeWait(document.aspnetForm);
}

function SaveRSReport(i_szNewTitle, i_bApplyDefault, i_nNewFolderId) {
   var bCommon;
   var nReportId;
   var nUserId;

   nReportId = parseInt(document.aspnetForm.ReportId.value);
   if (document.aspnetForm.isAdministrator.value == "True") {
      bCommon = true;
   }
   else {
      bCommon = false;
   }
   nUserId = parseInt(document.aspnetForm.userId.value);
   showWait();
   PageMethods.ValidateRSReport(nReportId, document.aspnetForm.ApplicationPath.value, bCommon, nUserId, i_szNewTitle,
      i_bApplyDefault, i_nNewFolderId, onValidateRSReportComplete);
}

function onValidateRSReportComplete(results, context, methodName) {
   var aszResults = results.split(GCommaRep);
   var clReportTitle;
   var clSaveErrorMsg;
   var szApplyDefault;
   var szErrorMsg;
   var szFolderId;
   var szReportId;
   var szTitle;

   if (aszResults.length > 4) {
      szReportId = aszResults[0];
      szTitle = aszResults[1];
      szApplyDefault = aszResults[2];
      szFolderId = aszResults[3];
      szErrorMsg = aszResults[4];
      if (szErrorMsg != "") {
         szErrorMsg = eval("res" + szErrorMsg);
         clSaveErrorMsg = document.getElementById("SaveReportMsg");
         if (clSaveErrorMsg != null) {
            clSaveErrorMsg.innerHTML = szErrorMsg;
            document.aspnetForm.SaveAs.focus();
         }
         else {
            alert(szErrorMsg);
         }
      }
      else {
         document.aspnetForm.SaveRSReportId.value = szReportId;
         document.aspnetForm.SaveRSReportTitle.value = szTitle;
         document.aspnetForm.SaveRSReportFolderId.value = szFolderId;
         document.aspnetForm.SaveRSReportApplyDefault.value = szApplyDefault;
         executeWait(document.aspnetForm);
      }
   }
   hideWait();
}

function onSortColumn(i_nSortType, i_nColumn) {
   var szCol = i_nColumn.toString();
   var szType = i_nSortType.toString();
   if (document.aspnetForm.SortColumn.value == szCol && document.aspnetForm.SortType.value == szType) {
      document.aspnetForm.SortColumn.value = -1;
      document.aspnetForm.SortType.value = 0;
   }
   else {
      document.aspnetForm.SortColumn.value = i_nColumn;
      document.aspnetForm.SortType.value = i_nSortType;
   }
   executeWait(document.aspnetForm);
}

function OnRankColumn(i_nColumn, i_nSortColumn, i_nRankType) {
   var aszRankedColumns;
   var aszRankingInfo;
   var bFound;
   var bRankTypeChange = false;
   var nColumnIndex;
   var nIndex;
   var szCol;
   var szColumn;
   var szRankedColumns;
   var szType;

   szColumn = i_nColumn.toString();
   szType = i_nRankType.toString();
   szRankedColumns = document.aspnetForm.RankedColumns.value;
   nColumnIndex = i_nColumn + 1;
   if (szRankedColumns == "") {
      szRankedColumns = szColumn;
      szRankedColumns += ";";
      szRankedColumns += szType;
      if (nColumnIndex <= i_nSortColumn) {
         i_nSortColumn = i_nSortColumn + 1;
      }
   }
   else {
      aszRankingInfo = szRankedColumns.split(",");
      for (nIndex = 0; nIndex < aszRankingInfo.length; nIndex++) {
         aszRankedColumns = aszRankingInfo[nIndex].split(";");
         szCol = aszRankedColumns[0];
         if (szCol < i_nColumn) nColumnIndex++;
      }
      szRankedColumns = "";
      bFound = false;
      for (nIndex = 0; nIndex < aszRankingInfo.length; nIndex++) {
         aszRankedColumns = aszRankingInfo[nIndex].split(";");
         if (typeof (aszRankedColumns[1]) == "undefined") {
            aszRankedColumns[1] = "-1"; // Descending rank
         }
         szCol = aszRankedColumns[0];
         if (szCol == szColumn) {
            if (szType == aszRankedColumns[1]) {
               bFound = true;
               if (nColumnIndex < i_nSortColumn) {
                  i_nSortColumn = i_nSortColumn - 1;
               }
               else if (nColumnIndex == i_nSortColumn) {
                  i_nSortColumn = -1;
               }
            }
            else {
               bRankTypeChange = true;
            }
         }
         else {
            if (szRankedColumns != "") {
               szRankedColumns += ",";
            }
            szRankedColumns += szCol;
            szRankedColumns += ";";
            szRankedColumns += aszRankedColumns[1];
         }
      }

      if (!bFound) {
         if (szRankedColumns != "") {
            szRankedColumns += ",";
         }
         szRankedColumns += szColumn;
         szRankedColumns += ";";
         szRankedColumns += szType;
         if (nColumnIndex <= i_nSortColumn && !bRankTypeChange) {
            i_nSortColumn = i_nSortColumn + 1;
         }
      }
   }

   document.aspnetForm.SortColumn.value = i_nSortColumn;
   if (i_nSortColumn < 0) {
      document.aspnetForm.SortType.value = 0;
   }
   document.aspnetForm.RankedColumns.value = szRankedColumns;

   if (szRankedColumns != "" && (document.aspnetForm.SuppressRowsValue.value == "True" || document.aspnetForm.SuppressColsValue.value == "True")) {
      document.aspnetForm.SuppressRowsValue.value = "False";
      document.aspnetForm.SuppressColsValue.value = "False";
      document.aspnetForm.SuppressionTypeValue.value = "1";
      document.aspnetForm.SuppressFromValue.value = "";
      document.aspnetForm.SuppressToValue.value = "";
      alert(resRankingCancelSuppression);
   }
   executeWait(document.aspnetForm);
}

//--------------------- Reduction ------------------------------
var g_strReductionOptions =
      "<input type=hidden name='ChangeReductionColumn' >"
+ "<TABLE class='OptionTable' width='100%' cellPadding='3' cellSpacing='0'>"
+ "<TR><TD>"
+ "<TABLE cellPadding='3' cellSpacing='0'>"
+ "<TR>"
+ "<td class=OptionHeader nowrap align=left>"
+ resTopBottom
+ "</td>"
+ "</TR>"
+ "<TR height='3'>"
+ "</TR>"
+ "</TABLE>"
+ "</TD></TR>"
+ "<TR><TD>"
+ "<TABLE border='0' cellPadding='3' cellSpacing='0'>"
+ "<tr>"
+ "<th width='10'></th>"
+ "<td class=OptionItem nowrap>"
+ "<LABEL FOR=ChangeReductionTypeId ACCESSKEY='s'>"
+ resSelectionType
+ "</LABEL>"
+ "</td><td>"
+ "<Select class=Default title='"
+ resSelectionType
+ "' name='ChangeReductionType' "
+ "id='ChangeReductionTypeId' class=VariableTextInput "
+ "onkeypress='javascript:return SubmitReduction(event);'>"
+ "<option value='Top'>"
+ resTop
+ "</option>"
+ "<option value='Bottom'>"
+ resBottom
+ "</option>"
+ "</Select>"
+ "</td>"
+ "<th width='10'></th></TR>"
+ "<tr>"
+ "<th width='10'></th>"
+ "<td class=OptionItem nowrap>"
+ "<LABEL FOR=ChangeReductionValueTypeId ACCESSKEY='t'>"
+ resValueType
+ "</LABEL>"
+ "</td><td>"
+ "<Select class=Default title='"
+ resValueType
+ "' name='ChangeReductionValueType' "
+ "id='ChangeReductionValueTypeId' class=VariableTextInput "
+ "onkeypress='javascript:return SubmitReduction(event);'>"
+ "<option value='Count'>"
+ resCount
+ "</option>"
+ "<option value='Percent'>"
+ resPercent
+ "</option>"
+ "<option value='Sum'>"
+ resSum
+ "</option>"
+ "</Select>"
+ "</td>"
+ "<th width='10'></th></TR>"
+ "<tr>"
+ "<th width='10'></th>"
+ "<td class=OptionItem nowrap>"
+ "<LABEL FOR=ChangeReductionValueId ACCESSKEY='v'>"
+ resValuePrompt
+ "</LABEL>"
+ "</td><td>"
+ "<input class=VariableTextInput type=TEXT name='ChangeReductionValue' "
+ "id=ChangeReductionValueId size='10' "
+ "onkeypress='javascript:return SubmitReduction(event);'>"
+ "</td>"
+ "<th width='10'></th></TR>"
+ "</TABLE>"
+ "</TD></TR>"
+ "<tr><td><div id='ShowTotalOfOthersDiv' style='display:none'><table>"
+ "<TR>" // Show total of others
+ "<th width='10'></th>"
+ "<td class=Default colspan=2 align=left nowrap>"
+ "<input type=checkbox id='ShowTotalOfOthers' title='' name='ShowTotalOfOthers'"
+ " onkeypress=\"javascript:SubmitReduction(event);\">"
+ "&nbsp;<LABEL FOR=ShowTotalOfOthers ACCESSKEY='f'>"
+ resShowTotalOfOthers
+ "</LABEL>"
+ "</td>"
+ "<th width='10'></th></TR>"
+ "</table></div></td></tr>"
+ "<TR><TD><TABLE><TR>"
+ "<td nowrap>"
+ "<input type=button name=ReductionGo value='"
+ resOK
+ "' onclick='javascript:return OnReductionOptions();' >&nbsp;"
+ "<input type=button name=Cancel value='"
+ resCancel
+ "' onclick='javascript:OnCancelOptions();'>&nbsp;"
+ "<input type=button name=ReductionRemove value='"
+ resRemove
+ "' onclick='javascript:OnReductionRemove();'>"
+ "&nbsp;"
+ "<input name=DialogHelpButton type=button value=\"" + resHelp
+ "\" onclick=\"javascript:DisplayDialogHelp('TopBottomReduction.htm', '');\">"
+ "</td>"
+ "</TR></TABLE></TD></TR>"
+ "</TABLE>";

function onReduction(i_nColumn) {
   ShowReductionOptions(i_nColumn);
}

function ShowReductionOptions(i_nColumn) {
   var nReductionColumn;

   DisplayOption(g_strReductionOptions);
   document.aspnetForm.ChangeReductionColumn.value = i_nColumn;
   if (!M_bMeasureDimensionOnRow && !M_bRowDimensionCalcDisabled) {
      ShowTotalOfOthersDiv.style.display = 'block';
   }
   if (i_nColumn != document.aspnetForm.ReductionColumn.value) {
      document.aspnetForm.ChangeReductionType.selectedIndex = 0;
      document.aspnetForm.ChangeReductionValueType.selectedIndex = 0;
      document.aspnetForm.ChangeReductionValue.value = "";
      document.aspnetForm.ShowTotalOfOthers.checked = false;
   }
   else {
      document.aspnetForm.ChangeReductionType.selectedIndex = document.aspnetForm.ReductionType.value;
      document.aspnetForm.ChangeReductionValueType.selectedIndex =
         document.aspnetForm.ReductionValueType.value;
      document.aspnetForm.ChangeReductionValue.value =
         (document.aspnetForm.ReductionValue.value).toString();
      if (document.aspnetForm.ReductionShowTotalOfOthers.value == "True") {
         document.aspnetForm.ShowTotalOfOthers.checked = true;
      }
      else {
         document.aspnetForm.ShowTotalOfOthers.checked = false;
      }
   }
   document.aspnetForm.ReductionRemove.disabled = (i_nColumn != document.aspnetForm.ReductionColumn.value);
   document.aspnetForm.ChangeReductionType.focus();
   onLayoutResize();
}

function SubmitReduction(e) {
   var valid = true;
   var key = GetKeyCode(e);

   valid = !(key == 13 && document.aspnetForm.ReductionGo.disabled);
   if (valid) {
      if (key == 13 && !document.aspnetForm.ReductionGo.disabled) {
         if (!OnReductionOptions()) valid = false;
      }
   }
   return valid;
}

function OnReductionOptions() {
   var bValid = true;
   var cChar;
   var nReductionType;
   var nReductionValueType;
   var oReductionValue;
   var szValue;

   szValue = document.aspnetForm.ChangeReductionValue.value;
   cChar = szValue.charAt(0);
   if (cChar == '0') {
      if (szValue.length > 0) {
         cChar = szValue.charAt(1);
         if (cChar < '0' || cChar > '9') {
            bValid = GPattern.test(szValue);
         }
         else {
            bValid = false;
         }
      }
      else {
         bValid = false;
      }
   }
   else if (!GPattern.test(szValue)) {
      bValid = false;
   }
   if (bValid) {
      nReductionType = document.aspnetForm.ChangeReductionType.selectedIndex;
      nReductionValueType = document.aspnetForm.ChangeReductionValueType.selectedIndex;
      if (nReductionValueType == 0) {
         //Count - Value must be a positive integer
         oReductionValue = parseInt(szValue);
         if (isNaN(oReductionValue)) {
            bValid = false;
         }
         else if (oReductionValue <= 0) {
            bValid = false;
         }
         else if (oReductionValue != parseFloat(szValue)) {
            bValid = false;
         }
      }
      else {
         //Percent or Sum - value can be any number for Sum; must be in (0,100] range for Percent
         oReductionValue = parseFloat(szValue);
         if (isNaN(oReductionValue)) {
            bValid = false;
         }
         else if (nReductionValueType == 1 && (oReductionValue <= 0 || oReductionValue > 100)) {
            bValid = false;
         }
      }
   }
   if (!bValid) {
      alert(resInvalidValue);
      document.aspnetForm.ChangeReductionValue.focus();
      return false;
   }
   if (document.aspnetForm.SuppressRowsValue.value == "True" || document.aspnetForm.SuppressColsValue.value == "True") {
      document.aspnetForm.SuppressRowsValue.value = "False";
      document.aspnetForm.SuppressColsValue.value = "False";
      document.aspnetForm.SuppressionTypeValue.value = "1";
      document.aspnetForm.SuppressFromValue.value = "";
      document.aspnetForm.SuppressToValue.value = "";
      alert(resReductionCancelSuppression);
   }

   // reset the pagination (rows only)
   document.aspnetForm.FirstRow.value = 0;
   document.aspnetForm.ReductionColumn.value = document.aspnetForm.ChangeReductionColumn.value;
   document.aspnetForm.ReductionType.value = nReductionType;
   document.aspnetForm.ReductionValueType.value = nReductionValueType;
   document.aspnetForm.ReductionValue.value = oReductionValue;
   document.aspnetForm.ReductionShowTotalOfOthers.value = document.aspnetForm.ShowTotalOfOthers.checked;
   executeWait(document.aspnetForm);
}

function OnReductionRemove() {
   document.aspnetForm.ReductionColumn.value = -1;
   document.aspnetForm.ReductionType.value = 0;
   document.aspnetForm.ReductionValueType.value = 0;
   document.aspnetForm.ReductionValue.value = 0;
   document.aspnetForm.ReductionShowTotalOfOthers.value = false;
   executeWait(document.aspnetForm);
}


function RefreshChart() {

    var objContentPane = document.getElementById("DivContentsScroll");
    if (objContentPane != null) {
        if (typeof (document.aspnetForm.ChartWidth) != "undefined") document.aspnetForm.ChartWidth.value = objContentPane.offsetWidth - 5;
        if (typeof (document.aspnetForm.ChartHeight) != "undefined") document.aspnetForm.ChartHeight.value = objContentPane.offsetHeight - 5;
        executeWait(document.aspnetForm);
    }
}
