    var RepSelWinHandle;


      function DoAcctSel(APageName){
        //alert(document.CTReportSetAddEdPage.OpenPopUp.value);
        if (APageName == null) {
        	APageName = 'CTSelectGroupAcctsPage';
		}
        var TheURL = APageName + '?RepSetId=' + document.CTReportSetAddEdPage.SchedRepID.value;
        TheURL = TheURL + '&RepRTMFName=' + document.CTReportSetAddEdPage.ReportOrGroupFileName.value;

        if (document.CTReportSetAddEdPage.ReportOrGroupLocation!=null){
          if ((document.CTReportSetAddEdPage.ReportOrGroupLocation.value=="")||(document.CTReportSetAddEdPage.ReportOrGroupLocation.value=="#"))
            TheURL = TheURL + '&CustomRep=false';
          else{
            TheURL = TheURL + '&CustomRep=true';
            TheURL = TheURL + '&UserDirName=' + document.CTReportSetAddEdPage.ReportOrGroupLocation.value;}
        }
        else
          TheURL = TheURL + '&CustomRep=false';

        if (document.CTReportSetAddEdPage.ViewFinalRep!=null){
          if ((document.CTReportSetAddEdPage.ViewFinalRep.value=="true"))
            TheURL = TheURL + '&ViewFinalRep=true';
          else
            TheURL = TheURL + '&ViewFinalRep=false';
        }
        else
          TheURL = TheURL + '&ViewFinalRep=false';

        if (document.CTReportSetAddEdPage.IsReportAGroup!=null){
          //if ((document.CTReportSetAddEdPage.IsReportAGroup.value=="")||(document.CTReportSetAddEdPage.IsReportAGroup.value=="#"))
          if ((document.CTReportSetAddEdPage.IsReportAGroup.value=="true"))
            TheURL = TheURL + '&ReportGroup=true';
          else
            TheURL = TheURL + '&ReportGroup=false';
        }
        else
            TheURL = TheURL + '&ReportGroup=false';

        var FeatureStr = "scrollbars=yes, resizable=yes, toolbar=yes, menubar=yes, statusbar=yes, ";
        if (document.CTReportSetAddEdPage.OpenPopUp!=null){
            var ActualHeight="850";
            var ActualWidth="1050";
         }
        FeatureStr = FeatureStr + "width=" + ActualWidth + ", height=" + ActualHeight + ", top=50, left=50";

        if (document.CTReportSetAddEdPage.ReportDesc!=null)
            TheURL = TheURL + '&RepDesc=' + document.CTReportSetAddEdPage.ReportDesc.value;

        //alert(TheURL);

        if (document.CTReportSetAddEdPage.OpenPopUp!=null)
          document.CTReportSetAddEdPage.OpenPopUp.value="-1";
        RepSelWinHandle = window.open(TheURL, APageName, FeatureStr);
        RepSelWinHandle.focus();
        window.blur();
      }

      function DoRunInTaskerRepNow(APageName, CurrRecIndex){
        //alert(APageName + ' , ' + CurrRecIndex);
        document.CTReportSetAddEdPage.CurrSchedRepNo.value=CurrRecIndex;
        __doPostBack('SaveAndTestRunSchedRep', 'CLICK');
        if (DoSaveAndRunSchedRepNow(APageName) == 0)
          return;
        var UserResult = 1; 
	//confirm('Do you want to view report progress while it is being generated?');
         if(UserResult=="1"){
          if (document.CTReportSetAddEdPage.ViewFinalRep!=null){
            document.CTReportSetAddEdPage.ViewFinalRep.value="true";
            if (document.CTReportSetAddEdPage.OpenPopUp!=null)
              document.CTReportSetAddEdPage.OpenPopUp.value="true";
          }
        }
        else{
        }
        DoAcctSel(APageName);
        window.blur();        
      }

      function InitializeHiddenVars(){
        if (document.CTReportSetAddEdPage.CloseAndExit!=null){
          if (document.CTReportSetAddEdPage.CloseAndExit.value=="true"){
	    window.close();
	    return;
	  }
        }
        if (document.CTReportSetAddEdPage.RSR_StartDateType!=null){
          //document.CTReportSetAddEdPage.StartDateSelect.value=document.CTReportsMainEntryPage.RSR_StartDateType.value;
          //alert(document.CTReportSetAddEdPage.RSR_StartDateType.value + " " + document.CTReportsMainEntryPage.StartDateSelect.value);
          //alert(document.CTReportSetAddEdPage.RSR_StartDateType.value);
          //alert(document.CTReportSetAddEdPage.StartDateSelect);
          SetRadioValue(document.CTReportSetAddEdPage.StartDateSelect, document.CTReportSetAddEdPage.RSR_StartDateType.value);
          //setCheckedValue(document.CTReportSetAddEdPage.StartDateSelect, document.CTReportsMainEntryPage.RSR_StartDateType.value);
        }

        if (document.CTReportSetAddEdPage.RSR_EndDateType!=null){
          //document.CTReportSetAddEdPage.EndDateSelect.value=document.CTReportsMainEntryPage.RSR_EndDateType.value;
          SetRadioValue(document.CTReportSetAddEdPage.EndDateSelect, document.CTReportSetAddEdPage.RSR_EndDateType.value);
          //setCheckedValue(document.CTReportSetAddEdPage.EndDateSelect, document.CTReportsMainEntryPage.RSR_EndDateType.value);
          //alert(document.CTReportSetAddEdPage.RSR_EndDateType.value + " " + document.CTReportsMainEntryPage.EndDateSelect.value);
        }

        SetDateSelOptions();

        if (document.CTReportSetAddEdPage.OpenPopUp!=null){
          if (document.CTReportSetAddEdPage.OpenPopUp.value!="-1"){
            if (document.CTReportSetAddEdPage.OpenPopUp.value=="CTReportSelector") {
              DoReportSel(-1);
              window.blur();
            }
            else{
              DoEditAcctGroupSel(document.CTReportSetAddEdPage.OpenPopUp.value);
              window.blur();
            }
          }
        }  
        //DoSavePDFAfterGenCBoxClick();
        //DoEmailPDFAfterGenCBoxClick();
      }

    function ValidateNewRepDesc(){
      var TempDesc=RemoveBlanks(document.CTReportSetAddEdPage.NewRepDesc.value)
      //alert(TempDesc);
      if (TempDesc==''){
        alert("Please enter a valid Report Group Description.");
        document.CTReportSetAddEdPage.NewRepDesc.focus();
        return(1);
      }
      else
        return(0);
    }

    function RefreshPage(){
//alert("RefreshPagex"+document.CTReportSetAddEdPage.CTReportSetAddEdPage_SchedReportsDataSourceFocusedRow.value);
      //document.location="CTReportSetAddEdPage?CurrSchedRepNo="+document.CTReportSetAddEdPage.CTReportSetAddEdPage_SchedReportsDataSourceFocusedRow.value;
      document.location="CTReportSetAddEdPage?CurrSchedRepNo="+document.CTReportSetAddEdPage.CurrSchedRepNo.value;
      //location.reload();
      //return;
      //alert(AcctGrpId + " x " + AcctGrpCount);
      //document.CTReportSetAddEdPage.AcctSelectionGroup.value=AcctGrpId;
      //document.CTReportSetAddEdPage.AccountsSelectionGroup.value=AcctGrpCount;
      //document.CTReportSetAddEdPage.AccountsSelectionGroup.setFocus();
      //document.CTReportSetAddEdPage.AccountsSelectionMethod.setFocus();
    }

      function DoSetReportSelCallBack(){
        var ARepName="#";
        if (document.CTReportSetAddEdPage.ReportOrGroupFileName!=null)
          ARepName=document.CTReportSetAddEdPage.ReportOrGroupFileName.value;
        var ARepLoc="#";
        if (document.CTReportSetAddEdPage.ReportOrGroupLocation!=null)
          ARepLoc=document.CTReportSetAddEdPage.ReportOrGroupLocation.value;
        var aIsRepGroup="false";
        if (document.CTReportSetAddEdPage.IsReportAGroup!=null)
          aIsRepGroup=document.CTReportSetAddEdPage.IsReportAGroup.value;
        //alert("DoSetReportSelCallBack " + ARepName + " x " + ARepLoc + " x " + aIsRepGroup);
        RepSelWinHandle.SetCurrentParams(ARepName, ARepLoc, aIsRepGroup);
        RepSelWinHandle.focus();
        //alert("done DoSetReportSelCallBack " + RepSelWinHandle);
      }

     function SetSelRepInCaller(aRepName, aRepUserDir, aIsRepGroup){
             //alert("SetSelRepInCaller - " + aRepName + " x " + aRepUserDir + " x " + aIsRepGroup);
        document.CTReportSetAddEdPage.ReportOrGroupFileName.value=aRepName;
        document.CTReportSetAddEdPage.ReportOrGroupLocation.value=aRepUserDir;
        document.CTReportSetAddEdPage.IsReportAGroup.value=aIsRepGroup;
        //document.CTReportSetAddEdPage.SelRepFileNameAndDescURL.href.text=aRepName;
        //alert("SetSelRepInCaller - " + aRepName + " x " + aRepUserDir + " x " + aIsRepGroup);
        __doPostBack('AddScheduledReportBtn', 'CLICK');
     }

      function DoReportSel(CurrRecIndex){
        var TheURL = "CTReportSelector?Dummy=true";
        if (document.CTReportSetAddEdPage.ReportOrGroupLocation!=null){
          if ((document.CTReportSetAddEdPage.ReportOrGroupLocation.value=="")||(document.CTReportSetAddEdPage.ReportOrGroupLocation.value=="#"))
            TheURL = TheURL + "&ShowStdReps=true";
        }
        if (document.CTReportSetAddEdPage.AddedFromSubRep!=null){
          //alert(document.CTReportSetAddEdPage.AddedFromSubRep.value);
          if ((document.CTReportSetAddEdPage.AddedFromSubRep.value=="")||(document.CTReportSetAddEdPage.AddedFromSubRep.value=="true")){
            TheURL = TheURL + "&ShowAllReps=true";}
        }
        //document.CTReportSetAddEdPage.CurrSchedRepNo.value=CurrRecIndex;
        var ActualHeight="750";
        var FeatureStr = "scrollbars=yes, resizable=yes, toolbar=yes, menubar=yes, statusbar=yes, ";
        FeatureStr = FeatureStr + "width=1050, height=" + ActualHeight + ", top=100, left=100";
        //alert(TheURL+FeatureStr);
        RepSelWinHandle = window.open(TheURL, "SelectReport", FeatureStr);
        //alert("EditFontColorBorder - ");
      }

      function DoLaunchRecord(RepSetId, CurrRecIndex){
      //Launches report
        //alert(APageName + ' , ' + CurrRecIndex);
        var TheURL = 'CTReportsMainEntryPage?RepRTMFName=' + document.CTReportSetAddEdPage.ReportOrGroupFileName.value;
        document.CTReportSetAddEdPage.CurrSchedRepNo.value=CurrRecIndex;
        __doPostBack('SaveAndTestRunSchedRep', 'CLICK');
        if (DoSaveAndRunSchedRepNow(TheURL) == 0)
          return;

        if (document.CTReportSetAddEdPage.ReportOrGroupLocation!=null){
          if ((document.CTReportSetAddEdPage.ReportOrGroupLocation.value=="")||(document.CTReportSetAddEdPage.ReportOrGroupLocation.value=="#"))
            TheURL = TheURL + '&CustomRep=false';
          else
            TheURL = TheURL + '&CustomRep=true';
        }
        else{
          TheURL = TheURL + '&CustomRep=false';
          TheURL = TheURL + '&UserDirName=' + document.CTReportSetAddEdPage.ReportOrGroupLocation.value;
        }

        if (document.CTReportSetAddEdPage.IsReportAGroup!=null){
          //if ((document.CTReportSetAddEdPage.IsReportAGroup.value=="")||(document.CTReportSetAddEdPage.IsReportAGroup.value=="#"))
          if ((document.CTReportSetAddEdPage.IsReportAGroup.value=="true"))
            TheURL = TheURL + '&ReportGroup=true';
          else
            TheURL = TheURL + '&ReportGroup=false';
        }
        else
            TheURL = TheURL + '&ReportGroup=false';

        if (document.CTReportSetAddEdPage.ReportDesc!=null)
            TheURL = TheURL + '&RepDesc=' + document.CTReportSetAddEdPage.ReportDesc.value;

        var UserResult = true; 
	//confirm('Do you want to display the report run page before running or directly run the report?'
        //+ '\nPress Ok to display the report run page to modify report options.\nPress Cancel to directly run report using current report set options.');
        //alert(UserResult);
        if(UserResult=="0")
          TheURL = TheURL + '&AutoRunRep=true';          

        TheURL = TheURL + '&RepSetId=' + RepSetId;

        var ActualHeight="850";
        var FeatureStr = "scrollbars=yes, resizable=yes, toolbar=yes, menubar=yes, statusbar=yes, ";
        FeatureStr = FeatureStr + "width=1050, height=" + ActualHeight + ", top=100, left=100";
        //alert(TheURL+FeatureStr);
        RepSelWinHandle = window.open(TheURL, "RunReport", FeatureStr);
        RepSelWinHandle.focus();
        window.blur();
        //alert("EditFontColorBorder - ");

        //alert(RepSetId);
        //document.CTReportSetAddEdPage.CurrSchedRepNo.value=CurrRecIndex;
        //__doPostBack('SaveAndTestRunSchedRep', 'CLICK');
      }

      function DoEditRecord(CurrRecIndex){      //"Configures" RptSet
       //alert(CurrRecIndex);
        document.CTReportSetAddEdPage.CurrSchedRepNo.value=CurrRecIndex;
        __doPostBack('EditRepBtn', 'CLICK');
      }

      function DoDeleteRecord(CurrRecIndex){
        var UserResult = true;
	//confirm('Are you sure you want to remove the scheduled Report # :' + (CurrRecIndex + 1) + '?');
        //	alert(UserResult);
        if(UserResult=="1"){
          document.CTReportSetAddEdPage.CurrSchedRepNo.value=CurrRecIndex;
          __doPostBack('RemoveRepBtn', 'CLICK');
        }
      }

      function DoShowAcctSelPopUp(){
       //alert(CurrRecIndex);
        __doPostBack('EditAcctGroupBtn', 'CLICK');
      }

      //javascript:DoRunInTaskerRepNow('CTTestSchedRepPage');
      function SetAutoTaskState(){
        if (document.CTReportSetAddEdPage.SchedRepSetCBox!=null){
                //if (document.CTReportSetAddEdPage.SchedRepSetCBox.checked==true)
                //  alert("1");
                //if (document.CTReportSetAddEdPage.SchedRepSetCBox.checked==true)
                //  document.CTReportSetAddEdPage.TaskOffset.disabled=false;
                //else
                //  document.CTReportSetAddEdPage.TaskOffset.disabled=true;
                //if (document.CTReportSetAddEdPage.SchedRepSetCBox.checked==true)
                //  document.CTReportSetAddEdPage.TaskOffsetDays.disabled=false;
                //else
                //  document.CTReportSetAddEdPage.TaskOffsetDays.disabled=true;
                if (document.CTReportSetAddEdPage.SchedRepSetCBox.checked==true)
                  document.CTReportSetAddEdPage.AutoRepPeriod.disabled=false;
                else
                  document.CTReportSetAddEdPage.AutoRepPeriod.disabled=true;
        }
      }

      function SetDateSelOptions(){
       var GoBackType = document.CTReportSetAddEdPage.GoBackUnits;
       var GoBackQty = document.CTReportSetAddEdPage.GoBackQuantity;
       var GoBackDays = 0;
       var dateEnd = new Date(theform.EndDateCal.value);
       var dateStart = new Date(dateEnd.value);
       var adays = dateStart.getDate();
       var ayear = dateStart.getFullYear();
       var amonth = dateStart.getMonth();
       document.CTReportSetAddEdPage.GoBackQuantity.disabled = GetRadioValue(document.CTReportSetAddEdPage.StartDateType != "1");
       document.CTReportSetAddEdPage.GoBackUnits.disabled=document.CTReportSetAddEdPage.GoBackQuantity.disabled;
       document.CTReportSetAddEdPage.StartDateCalEditor.disabled = GetRadioValue(document.CTReportSetAddEdPage.StartDateType != "2")
       document.CTReportSetAddEdPage.EndDateCalEditor.disabled = GetRadioValue(document.CTReportSetAddEdPage.EndDateType != "2")
       if (GetRadioValue(document.CTReportSetAddEdPage.EndDateType) == "0")
           dateEnd = dateEnd.getDate - dateEnd.getDay ;
       if (GetRadioValue(document.CTReportSetAddEdPage.EndDateType)=="1")
           dateEnd = dateEnd.getDate;
       if (GetRadioValue(document.CTReportSetAddEdPage.EndDateType) == "2")
           dateEnd = document.CTReportSetAddEdPage.EndDateCal.value;
       theform.EndDateCal.value = dateEnd;
       document.CTReportSetAddEdPage.EndDateCal.value = dateEnd;
       document.CTReportSetAddEdPage.EndDateCal.RefreshPage;
       if (GetRadioValue(document.CTReportSetAddEdPage.StartDateType) == "0") 
           dateStart = dateEnd.getFullYear() - DaysInTheYear(dateEnd);

       if (GetRadioValue(document.CTReportSetAddEdPage.StartDateType)=="1"){
              document.CTReportSetAddEdPage.GoBackQuantity.disabled=false;
              document.CTReportSetAddEdPage.GoBackUnits.disabled=false;
              if (GoBackType=="0") {                  //days
                  aday = daysInMonth(ayear,amonth);
                  dateStart.setFullYear(ayear,amonth,aday);
                  //document.CTReportSetAddEdPage.StartDateCal.value = dateStart;		
              }	    
              if (GoBackType=="1") {            //weeks
                  GoBackDays = GoBackQty * 7;
                  dateStart = dateEnd-GoBackDays;
                  //document.CTReportSetAddEdPage.StartDateCal.value = 		(document.CTReportSetAddEdPage.EndDateCal.value - GoBackDays);
              }
              if (GoBackType == "2") {        // months

                  for (var i = 0; i  < GoBackQty; i++){
                      amonth = amonth - 1;
                      if (amonth < 0) {
                          amonth =  11;
                          ayear = ayear - 1;
                      }  
                  }
                  dateStart.setMonth = amonth;
                  dateStart.setYear = ayear;
                  //dateStart.setDate = adays;
              }
             // if (GoBackType == "3") {        // years
                //  ayear 
           //   document.CTReportSetAddEdPage.StartDateCal.value = (document.CTReportSetAddEdPage.EndDateCal.value - GoBackQty);

          }
       theform.StartDateCal.value = dateStart;
       document.CTReportSetAddEdPage.StartDateCal.value = dateStart;
       document.CTReportSetAddEdPage.StartDateCal.RefreshPage;
      }

    // function CloseWin() {
//		Window.Close();

    function OpenEditRepSetWindow(ARepSetParams){
      var AUrl = 'CTReportSetAddEdPage' + ARepSetParams;
      var FeatureStr = "scrollbars=yes, resizable=yes, toolbar=yes, menubar=yes, statusbar=yes, ";
      FeatureStr = FeatureStr + " width=1050, height=875, top=50, left=60";
      //alert(AUrl);
      window.open(AUrl, "ReportSetWin", FeatureStr);
  }

  //    }