﻿var M_strReportDefinitionOptions =
   "<table class='OptionTable' width='100%' cellPadding='3' cellSpacing='0'>"
   + "<tr><td><table cellPadding='3' cellSpacing='0'>"
   + "<tr><td>"
   + "<table cellPadding='3' cellSpacing='0'>"
   + "<tr>"
   + "<td class=OptionHeader nowrap align=left>" + resReportDefinition + "</td>"
   + "</tr>"
   + "<tr height='3'></tr>"
   + "</table>"
   + "</td></tr>"
   + "<tr><td>"
   + "<table cellPadding='3' cellSpacing='0'>"
   + "<tr>"
   + "<td nowrap><table>"
   + "<tr>"
   + "<td id='ReportListTD' style='display:none'>"
   + "<table><tr>"
   + "<td class=OptionItem nowrap>"
   + "<LABEL FOR=CubeReportId ACCESSKEY=\"d\">" + resChooseReport + "</LABEL>"
   + "</td>"
   + "<td class=OptionItem nowrap>"
   + "<select name=CubeReport title = '" + resChooseReport
   + "' id=CubeReportId onkeypress=\"javascript:SubmitReportDefinition(event);\" />"
   + "</td>"
   + "</tr></table>"
   + "</td>"
   + "<td id='CurrentReportTD' style='display:none'>"
   + "<table><tr>"
   + "<td class=OptionItem nowrap>"
   + resChooseReport
   + "</td>"
   + "<td class=OptionItem nowrap id=CurrentReportTitleTD>"
   + "</td>"
   + "</tr></table>"
   + "</td>"
   + "</tr>"
   + "<tr><td>"
   + "<table><tr>"
   + "<td><input type=checkbox id='DetailedDefinition' title='' name='DetailedDefinition' "
   + "onkeypress='javascript:SubmitReportDefinition(event);' "
   + "onclick='ChangeDetail();' >"
   + "</td>"
   + "<td class=OptionItem nowrap>"
   + "<label for='DetailedDefinition'>"
   + resDetailedDefinition
   + "</label></td>"
   + "</tr></table>"
   + "</td></tr>"
   + "<tr><td>"
   + "<table><tr>"
   + "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>"
   + "<td class=OptionItem id='RptSelectionLimit' nowrap>"
   + "<LABEL FOR=SelectionLimit ACCESSKEY=\"d\">" + resSelectedMembersDisplayLimit + "</LABEL>"
   + "</td>"
   + "<td class=OptionItem nowrap>"
   + "<select name=SelectionLimit title = '" + resSelectedMembersDisplayLimit
   + "' id=SelectionLimit onkeypress=\"javascript:SubmitReportDefinition(event);\" />"
   + "</td>"
   + "</tr></table>"
   + "</td></tr>"
   + "<tr><td nowrap>"
   + "<input type=button name=ReportDefinitionGo value=\"" + resOK 
   + "\" onclick=\"javascript:OnReportDefinitionOptions();\">&nbsp;"
   + "<input type=button name=Cancel value=\"" + resCancel 
   + "\" onclick=\"javascript:OnCancelOptions();\">"
   + "</td>"
   + "</tr></table></td>"
   + "</tr>"
   + "</table>"
   + "</td></tr>"
   + "<tr height='6'></tr>"
   + "</table>"
   + "</td>"
   + "<td width='100%'></td>"
   + "</tr>"
   + "</table>";
   
function ShowReportDefinitionOptions(i_bCurrentReport)
{
   var clDetailedDefinition;
   var clReport;
   var clReportTD;
   var clSelectionLimit;
   var clSelectionLimitLabel;
   var nIndex;
   var strText;

   DisplayOption(M_strReportDefinitionOptions, "SummaryButton");
   clDetailedDefinition = document.getElementById("DetailedDefinition");
   clSelectionLimit = document.getElementById("SelectionLimit");
   clSelectionLimitLabel = document.getElementById("RptSelectionLimit");
   SelectControlAddOption(clSelectionLimit, 0, "0")
   SelectControlAddOption(clSelectionLimit, 10, "10", true)
   SelectControlAddOption(clSelectionLimit, 20, "20")
   SelectControlAddOption(clSelectionLimit, 30, "30")
   SelectControlAddOption(clSelectionLimit, 40, "40")
   SelectControlAddOption(clSelectionLimit, 50, "50")
   clSelectionLimit.disabled = true;
   clSelectionLimitLabel.className = "DisabledOptionItem";
   if (typeof(i_bCurrentReport) != 'undefined' && i_bCurrentReport) {
      clReportTD = document.getElementById("CurrentReportTD");
      clReportTD.style.display = "block";
      clReport = document.getElementById("CurrentReportTitleTD");
      strText = document.aspnetForm.ViewTitle.value;
      if (strText == "") {
         strText = document.aspnetForm.NewViewTitle.value;
      }
	   strText = strText.replace(new RegExp(GSingleQuoteRep, "g"), "'");
	   strText = strText.replace(new RegExp(GLtRep, "g"), "&lt;");
	   strText = strText.replace(new RegExp(GGtRep, "g"), "&gt;");
      clReport.innerHTML = strText;
      clDetailedDefinition.focus();
   }
   else {
      clReportTD = document.getElementById("ReportListTD");
      clReportTD.style.display = "block";
      clReport = document.getElementById("CubeReportId");
      for (nIndex = 0; nIndex < M_anCubeReportIds.length; nIndex++) {
         strText = M_astrCubeReportTitles[nIndex];
         if (strText.length > G_nMaxDataSourceTitle) {
            strText = strText.substring(0, G_nMaxDataSourceTitle - 1) + G_strThreeDots;
         }
         SelectControlAddOption(clReport, M_anCubeReportIds[nIndex], strText);
      }
      clReport.focus();
   }
   // Resize scroll bars
   onLayoutResize();
}

function ChangeDetail()
{
   var clDetailedDefinition;
   var clSelectionLimit;
   var clSelectionLimitLabel;

   clDetailedDefinition = document.getElementById("DetailedDefinition");
   clSelectionLimit = document.getElementById("SelectionLimit");
   clSelectionLimitLabel = document.getElementById("RptSelectionLimit");
   if (clDetailedDefinition.checked) {
      clSelectionLimit.disabled = false;
      clSelectionLimitLabel.className = "OptionItem";
   }
   else {
      clSelectionLimit.disabled = true;
      clSelectionLimitLabel.className = "DisabledOptionItem";
   }
}

function SubmitReportDefinition(e)
{
   var key = GetKeyCode(e);
   if ( key == 13) {
      OnReportDefinitionOptions();
      ResetSubmit(e);
   }
}

function OnReportDefinitionOptions()
{
   var clDetailedDefinition;
   var clReport;
   var clSelectionLimit;
   var nCubeID = 0;
   var nReportID = 0;
   var szAction = "../View/ReportDefinition.aspx";
   
   if (document.getElementById("ReportListTD").style.display == "block") {
      clReport = document.getElementById("CubeReportId");
      nReportID = clReport.options[clReport.selectedIndex].value;
      szAction = szAction + "?ReportId=" + nReportID + "&DetailedDefinition=";
   }
   else {
      szAction = szAction + "?DetailedDefinition=";
   }
   clDetailedDefinition = document.getElementById("DetailedDefinition");
   if (clDetailedDefinition.checked) {
      szAction = szAction + "1";
   }
   else {
      szAction = szAction + "0";
   }
   clSelectionLimit = document.getElementById("SelectionLimit");
   szAction = szAction + "&SelectedMembersDisplayLimit=" 
      + clSelectionLimit.options[clSelectionLimit.selectedIndex].value;
	document.aspnetForm.action = szAction;
	executeWait(document.aspnetForm);
}