// sets up millisecond variables for use in modifying javascript date objects
var oneMinute = 60 * 1000;
var oneHour = oneMinute * 60;
var oneDay = oneHour * 24;

function chkTimeRange() {

  // checks for valid HR and MIN values for Time Range setting
  
  oDoc = EEM6().Tabsheet.TabDocument(TABPAGE_REPORT_SETTINGS);
  oFrm = oDoc.settingsForm;
  if(oFrm.TdmUserOptions_cdsOptions_TimeFromHR.selectedIndex == 0 && 
     oFrm.TdmUserOptions_cdsOptions_TimeFromMIN.selectedIndex == 0)
       oFrm.TdmUserOptions_cdsOptions_TimeFromMIN.selectedIndex = 1;
  if(oFrm.TdmUserOptions_cdsOptions_TimeToHR.selectedIndex == 24)
    oFrm.TdmUserOptions_cdsOptions_TimeToMIN.selectedIndex = 0;
}

function formatDate(that) {

  // checks the format of the date field passed
  
  txt = '';
  arThat = that.value.split('/');
  if(arThat.length != 3)
    {alert('Invalid date format');
     return;}
  else if(arThat[2].length != 4)
    txt = 'Year must be four digits long';
  else if(arThat[0].length < 1 || arThat[0].length > 2)
    txt = 'Month must be two digits long';
  else if(arThat[1].length < 1 || arThat[1].length > 2)
    txt = 'Day must be two digits long';
    
  if(txt != '')
    {alert(txt);
     that.focus();
     return;}
     
  if(arThat[1].length == 1)
    arThat[1] = '0' + arThat[1];
  if(arThat[0].length == 1)
    arThat[0] = '0' + arThat[0];
  that.value = arThat.join('/');

}

function chkType() {
  if(EEM6().Reports.ReportSelected().ActionCode == MENU_ACTION_RPT_CALENDAR)
    {updateControlDate('S',this.document.settingsForm.TdmUserOptions_cdsOptions_StartDate.value);}
}

function calendarSettings(form) {

  // prevents the Date Range from being changed from 'Start & Duration' and
  //  and removes  options from the 'Start Period' and 'Duration Period' select boxes
  //  that aren't valid for the Monthly Summary
  
  form.TdmUserOptions_cdsOptions_DateRange[0].disabled = true;
  form.TdmUserOptions_cdsOptions_DateRange[2].disabled = true;
  drawDurPeriod(1,form);
  form.TdmUserOptions_cdsOptions_DurationPeriod.options[1] = null;
  form.TdmUserOptions_cdsOptions_StartPeriod.options[2] = null;
  form.TdmUserOptions_cdsOptions_StartPeriod.options[1] = null;
}

function updateControlCbx(boolVal) {
  EEM6().fraReportControls.date_widget.RemoveTicks.checked = boolVal;
}

function updateControlDate(SED, val) {

  // updates the Date fields in the Controls frame as the user types in the same field
  //  in the Report Settings frame

  frm = this.settingsForm;
  if(SED == 'S')
    {if(repName == 'Monthly Summary')
      {arVal = val.split('/');
       if(arVal.length == 3)
         {arVal[1] = '01';
          val = arVal.join('/');
          frm.TdmUserOptions_cdsOptions_StartDate.value = val;}}
     EEM6().fraReportControls.date_widget.start_date.value = val;}
  else if(SED == 'E')
    EEM6().fraReportControls.date_widget.end_date.value = val;
  else if(SED == 'D')
    EEM6().fraReportControls.date_widget.duration.value = frm.TdmUserOptions_cdsOptions_DurationNumber.value + ' ' + frm.TdmUserOptions_cdsOptions_DurationPeriod.value;
}

function turnOnOff(val,OnOff) {
  doc = EEM6().fraReportControls.document;
  result = OnOff ? 'inline' : 'none';
  switch(val) {
    case 'S':
      doc.all['SD1'].style.display = result;
      doc.all['SD2'].style.display = result;
      doc.all['SD3'].style.display = result;      
      break;
    case 'E':
      doc.all['ED1'].style.display = result;
      doc.all['ED2'].style.display = result;
      doc.all['ED3'].style.display = result;
      break;
    case 'D':
      doc.all['D1'].style.display = result;
      doc.all['D2'].style.display = result;
      break;
  }
}

function updateControlFrame() {
  switch(dRange) {
    case 'SE':
      turnOnOff('S',true);
      turnOnOff('E',true);
      turnOnOff('D',false);
      break;
    case 'SD':
      turnOnOff('S',true);
      turnOnOff('E',false);
      turnOnOff('D',true);
      break;
    case 'ED':
      turnOnOff('S',false);
      turnOnOff('E',true);
      turnOnOff('D',true);
      break;
  }
  
  for(var i=0; i < document.settingsForm.TdmUserOptions_cdsOptions_RemoveTicks.length; i++) {
    if(document.settingsForm.TdmUserOptions_cdsOptions_RemoveTicks[i].checked) {
      updateControlCbx(document.settingsForm.TdmUserOptions_cdsOptions_RemoveTicks[i].value.toLowerCase() == 'true');
      break;
    }
  }
}

function syncDates() {

  // syncs the Date fields in the Report Settings and Controls frames

  frm = this.settingsForm;
  if(this.settingsForm.TdmUserOptions_cdsOptions_StartDate)
    EEM6().fraReportControls.date_widget.start_date.value = frm.TdmUserOptions_cdsOptions_StartDate.value;
  if(this.settingsForm.TdmUserOptions_cdsOptions_EndDate)
    EEM6().fraReportControls.date_widget.end_date.value = frm.TdmUserOptions_cdsOptions_EndDate.value;
  if(this.settingsForm.TdmUserOptions_cdsOptions_DurationNumber)
    EEM6().fraReportControls.date_widget.duration.value = frm.TdmUserOptions_cdsOptions_DurationNumber.value + ' ' + frm.TdmUserOptions_cdsOptions_DurationPeriod.value;
}

  function allORnone(boxes,form)  {
    
    // selects/deselects Days of Week and Months of Year check boxes
    
    if (boxes == 'dow')
     {if (form.TdmUserOptions_cdsOptions_Sun.checked && form.TdmUserOptions_cdsOptions_Mon.checked && form.TdmUserOptions_cdsOptions_Tue.checked && form.TdmUserOptions_cdsOptions_Wed.checked && form.TdmUserOptions_cdsOptions_Thu.checked && form.TdmUserOptions_cdsOptions_Fri.checked && form.TdmUserOptions_cdsOptions_Sat.checked)
       {form.TdmUserOptions_cdsOptions_Sun.checked=false; form.TdmUserOptions_cdsOptions_Mon.checked=false; form.TdmUserOptions_cdsOptions_Tue.checked=false; form.TdmUserOptions_cdsOptions_Wed.checked=false; form.TdmUserOptions_cdsOptions_Thu.checked=false; form.TdmUserOptions_cdsOptions_Fri.checked=false; form.TdmUserOptions_cdsOptions_Sat.checked=false;}
      else
        {form.TdmUserOptions_cdsOptions_Sun.checked=true; form.TdmUserOptions_cdsOptions_Mon.checked=true; form.TdmUserOptions_cdsOptions_Tue.checked=true; form.TdmUserOptions_cdsOptions_Wed.checked=true; form.TdmUserOptions_cdsOptions_Thu.checked=true; form.TdmUserOptions_cdsOptions_Fri.checked=true; form.TdmUserOptions_cdsOptions_Sat.checked=true;}}
    if (boxes == 'moy')
     {if (form.TdmUserOptions_cdsOptions_Jan.checked && form.TdmUserOptions_cdsOptions_Feb.checked && form.TdmUserOptions_cdsOptions_Mar.checked && form.TdmUserOptions_cdsOptions_Apr.checked && form.TdmUserOptions_cdsOptions_May.checked && form.TdmUserOptions_cdsOptions_Jun.checked && form.TdmUserOptions_cdsOptions_Jul.checked && form.TdmUserOptions_cdsOptions_Aug.checked && form.TdmUserOptions_cdsOptions_Sep.checked && form.TdmUserOptions_cdsOptions_Oct.checked && form.TdmUserOptions_cdsOptions_Nov.checked && form.TdmUserOptions_cdsOptions_Dec.checked)
       {form.TdmUserOptions_cdsOptions_Jan.checked=false; form.TdmUserOptions_cdsOptions_Feb.checked=false; form.TdmUserOptions_cdsOptions_Mar.checked=false; form.TdmUserOptions_cdsOptions_Apr.checked=false; form.TdmUserOptions_cdsOptions_May.checked=false; form.TdmUserOptions_cdsOptions_Jun.checked=false;
        form.TdmUserOptions_cdsOptions_Jul.checked=false; form.TdmUserOptions_cdsOptions_Aug.checked=false; form.TdmUserOptions_cdsOptions_Sep.checked=false; form.TdmUserOptions_cdsOptions_Oct.checked=false; form.TdmUserOptions_cdsOptions_Nov.checked=false; form.TdmUserOptions_cdsOptions_Dec.checked=false;}
      else
       {form.TdmUserOptions_cdsOptions_Jan.checked=true; form.TdmUserOptions_cdsOptions_Feb.checked=true; form.TdmUserOptions_cdsOptions_Mar.checked=true; form.TdmUserOptions_cdsOptions_Apr.checked=true; form.TdmUserOptions_cdsOptions_May.checked=true; form.TdmUserOptions_cdsOptions_Jun.checked=true;
        form.TdmUserOptions_cdsOptions_Jul.checked=true; form.TdmUserOptions_cdsOptions_Aug.checked=true; form.TdmUserOptions_cdsOptions_Sep.checked=true; form.TdmUserOptions_cdsOptions_Oct.checked=true; form.TdmUserOptions_cdsOptions_Nov.checked=true; form.TdmUserOptions_cdsOptions_Dec.checked=true;}}
  }

  function changeDRange(value) {

    // this function is called when the selected Date Range radio button is changed

    if(dRange == value)
      return;
    dRange = value;
    if(value == 'SE')
      {if(anType == 'TI' && document.settingsForm.TdmUserOptions_cdsOptions_DisplayInterval.selectedIndex == 3)
         document.settingsForm.TdmUserOptions_cdsOptions_DisplayInterval.selectedIndex = 0;
       else if(document.settingsForm.TdmUserOptions_cdsOptions_GroupBy)
         if(document.settingsForm.TdmUserOptions_cdsOptions_GroupBy.selectedIndex == 4)
           document.settingsForm.TdmUserOptions_cdsOptions_GroupBy.selectedIndex = 1;}
     document.settingsForm.submit();
  }
  
  function changeToD(form,value) {
    if(value == 'n')
      {document.settingsForm.TdmUserOptions_cdsOptions_TimeFromHR.selectedIndex = 0;
       form.TdmUserOptions_cdsOptions_TimeFromMIN.selectedIndex = 1;
       form.TdmUserOptions_cdsOptions_TimeToHR.selectedIndex = 24;
       form.TdmUserOptions_cdsOptions_TimeToMIN.selectedIndex = 0;
       form.TdmUserOptions_cdsOptions_TimeFromHR.disabled = true;
       form.TdmUserOptions_cdsOptions_TimeFromMIN.disabled = true;
       form.TdmUserOptions_cdsOptions_TimeToHR.disabled = true;
       form.TdmUserOptions_cdsOptions_TimeToMIN.disabled = true;}
    else
      {form.TdmUserOptions_cdsOptions_TimeFromHR.disabled = false;
       form.TdmUserOptions_cdsOptions_TimeFromMIN.disabled = false;
       form.TdmUserOptions_cdsOptions_TimeToHR.disabled = false;
       form.TdmUserOptions_cdsOptions_TimeToMIN.disabled = false;}
  }

  function changePeriod(SorE,value,frm) {
    
    // changes Start and End dates to appropriate values when the Start and End Period
    //  selection changes
    
    myDate = new Date();
    if(SorE == 'S')
      {if(value == 'Yesterday')
         {myDate.setTime(myDate.getTime() - oneDay);
          frm.TdmUserOptions_cdsOptions_StartDate.value = myDate.getMonth()+1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();}
       else if(value == 'Start of Week')
         {offset = myDate.getDay() * oneDay;
          myDate.setTime(myDate.getTime() - offset);
          frm.TdmUserOptions_cdsOptions_StartDate.value = myDate.getMonth()+1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();}
       else if(value == 'Start of Month')
         {frm.TdmUserOptions_cdsOptions_StartDate.value = myDate.getMonth()+1 + '/1/' + myDate.getFullYear();}
       else if(value == 'Start of Year')
         {frm.TdmUserOptions_cdsOptions_StartDate.value = '1/1/' + myDate.getFullYear();}
       formatDate(frm.TdmUserOptions_cdsOptions_StartDate);
      }
    else if(SorE == 'E')
      {if(value == 'Today')
         {frm.TdmUserOptions_cdsOptions_EndDate.value = myDate.getMonth()+1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();}
       else if(value == 'Tomorrow')
         {myDate.setTime(myDate.getTime() + oneDay);
          frm.TdmUserOptions_cdsOptions_EndDate.value = myDate.getMonth()+1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();}
       else if(value == 'Start of Week')
         {offset = myDate.getDay() * oneDay;
          myDate.setTime(myDate.getTime() - offset);
          frm.TdmUserOptions_cdsOptions_EndDate.value = myDate.getMonth()+1 + '/' + myDate.getDate() + '/' + myDate.getFullYear();}
       else if(value == 'Start of Month')
         {frm.TdmUserOptions_cdsOptions_EndDate.value = myDate.getMonth()+1 + '/1/' + myDate.getFullYear();}
       else if(value == 'Start of Year')
         {frm.TdmUserOptions_cdsOptions_EndDate.value = '1/1/' + myDate.getFullYear();}
       formatDate(frm.TdmUserOptions_cdsOptions_EndDate);
      }
  }

  function fixPeriod(nm) {
    
    // resets the Start and End Period fields to a setting of 'Fixed'
    oDoc = EEM6().Tabsheet.TabDocument(TABPAGE_REPORT_SETTINGS);
    if(nm.indexOf('Start') > -1)
      oDoc.settingsForm.TdmUserOptions_cdsOptions_StartPeriod.value = 'Fixed';
    else if(nm.indexOf('End') > -1)
      oDoc.settingsForm.TdmUserOptions_cdsOptions_EndPeriod.value = 'Fixed';
  }
  
  function isNum(val) {
  
    // verifies that no illegal characters were included in a passed string
    allowedChars = '0123456789';  
    for(i=0;i<val.length;i++)
      {if(allowedChars.indexOf(val.charAt(i)) == -1)
        return false;}
    return true;
  }
  
  function validDate(tDate) {

    // takes a date as a string and tests to make sure it's a valid date
    
    arDaysInMonths = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
    temp = tDate.split('/');
    if(temp.length != 3)
      return 'Invalid format';
    if(temp[0] < 1 || temp[0] > 12 || !isNum(temp[0]))
      return 'Invalid Month';
    if(temp[1] < 1 || temp[1] > 31 || !isNum(temp[1]))
      return 'Invalid Day';
    if(temp[2] < 1995 || !isNum(temp[2]))
      return 'Invalid Year';
    
    if(temp[0] == 2)  // if Feb., check for leap year
      if(((temp[2] % 4 == 0) && (temp[2] % 100 != 0)) || (temp[2] % 400 == 0))
        arDaysInMonths[1] = 29; 

    days = arDaysInMonths[temp[0]-1];
    if(temp[1] > days)
      return 'Invalid Day';
      
    return 'VALID';
  }
  
  function makeDate(val)  {
    
    // takes a text date value and returns a date object
    
    arVal = val.split('/');
    myDate = new Date(arVal[2],arVal[0]-1,arVal[1]);
    return myDate;
  }
  
  function verifyDates(frm) {
     
    // pulls Start and End date values from the form and passes them to another function
    //   for testing for validity; test Start Date to verify it's not greater than 
    //   current day

    if(frm.TdmUserOptions_cdsOptions_StartDate)
      {result = validDate(frm.TdmUserOptions_cdsOptions_StartDate.value);
       if(result != 'VALID')
         {alert(result + ' in Start Date');
          return false;}
       else
         {oSDate = makeDate(frm.TdmUserOptions_cdsOptions_StartDate.value);
          oDate = new Date();
          if(oSDate.getTime() > oDate.getTime())
            {alert('Start Date cannot be in the future');
             frm.TdmUserOptions_cdsOptions_StartDate.focus();
             return false;}}}
    if(frm.TdmUserOptions_cdsOptions_EndDate)
      {result = validDate(frm.TdmUserOptions_cdsOptions_EndDate.value);
       if(result != 'VALID')
         {alert(result + ' in End Date');
          return false;}}
    if(frm.TdmUserOptions_cdsOptions_StartDate && frm.TdmUserOptions_cdsOptions_EndDate)
      {oSDate = makeDate(frm.TdmUserOptions_cdsOptions_StartDate.value);
       oEDate = makeDate(frm.TdmUserOptions_cdsOptions_EndDate.value);
       if(oEDate <= oSDate)
         {alert('The End Date must be later than the Start Date');
          return false;}}
      
    return true;
  }
  
  function setToFirstOfMonth(value) {
  
    // sets a validated date value to the start of a month
    
    arTemp = value.split('/');
    arTemp[1] = '01';
    return arTemp.join('/');
  }

  function setToFirstOfYear(value) {
  
    // sets a validated date value to the start of a year
    
    arTemp = value.split('/');
    arTemp[0] = '01';
    arTemp[1] = '01';
    return arTemp.join('/');
  }
  
  function chkMonths(frm) {
  
    // checks/sets Start and End months to separate months when needed
    
    arSDate = frm.TdmUserOptions_cdsOptions_StartDate.value.split('/');
    arEDate = frm.TdmUserOptions_cdsOptions_EndDate.value.split('/');
    if(arSDate[0] == arEDate[0])  // check to see if month and year are the same and if so...
      {if(arEDate[0] == '12')     // check to see if it's December, if so...
         {arEDate[0] = '01';      // set to January and
          arEDate[2]++;}          // increment year
       else
         {arEDate[0]++;}          // else just increment month
       frm.TdmUserOptions_cdsOptions_EndDate.value = arEDate.join('/');}
  }
  
  function chkYears(frm) {
  
    // checks/sets Start and End years to separate years when needed
  
    arSDate = frm.TdmUserOptions_cdsOptions_StartDate.value.split('/');
    arEDate = frm.TdmUserOptions_cdsOptions_EndDate.value.split('/');
    if(arSDate[2] == arEDate[2])
      {arEDate[2] ++;
       frm.TdmUserOptions_cdsOptions_EndDate.value = arEDate.join('/');}
  }
  
  function changeGrouping(value,frm) {
    
    // changes the Start and End dates to valid options by the current Group By selection

    // for All, the Group Consecutive checkbox can't be checked
    if(value == 'All')
      {frm.TdmUserOptions_cdsOptions_GroupConsecutive.checked = false;}
           
    // verify dates are valid and if not, set Group By back to what it was
    else if(!verifyDates(frm))  
      {frm.TdmUserOptions_cdsOptions_GroupBy.value = groupBy;
       return;}
       
    // for Month, dates should be set to first of month       
    if(value == 'Month')
      {if(frm.TdmUserOptions_cdsOptions_StartDate)  //if start date exists
        {frm.TdmUserOptions_cdsOptions_StartDate.value = setToFirstOfMonth(frm.TdmUserOptions_cdsOptions_StartDate.value);
         frm.TdmUserOptions_cdsOptions_StartPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate)  //if end date exists
        {frm.TdmUserOptions_cdsOptions_EndDate.value = setToFirstOfMonth(frm.TdmUserOptions_cdsOptions_EndDate.value);
         frm.TdmUserOptions_cdsOptions_EndPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate && frm.TdmUserOptions_cdsOptions_StartDate)  //if both dates exist
        {chkMonths(frm);}}  // check to make sure the months are different

    // for Year, dates should be set to first of *different* years
    else if(value == 'Year')
      {if(frm.TdmUserOptions_cdsOptions_StartDate)  //if start date exists
        {frm.TdmUserOptions_cdsOptions_StartDate.value = setToFirstOfYear(frm.TdmUserOptions_cdsOptions_StartDate.value);
         frm.TdmUserOptions_cdsOptions_StartPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate)  //if end date exists
        {frm.TdmUserOptions_cdsOptions_EndDate.value = setToFirstOfYear(frm.TdmUserOptions_cdsOptions_EndDate.value);
         frm.TdmUserOptions_cdsOptions_EndPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate && frm.TdmUserOptions_cdsOptions_StartDate)  //if both dates exist
        {chkYears(frm);}}  // check to make sure the years are different

    // for Custom Month, change Date Range to SD if it's currently SE
    else if(frm.TdmUserOptions_cdsOptions_DateRange[0].checked && value == 'Custom Month')
      {frm.TdmUserOptions_cdsOptions_DateRange[1].checked = true;
       changeDRange('SD');}
       
    // if checking the Group Consecutive box, check to see if Group By is set to All
    // and if so, display an alert box (can't group consecutive if using All)
    else if(value == 'box')
      {if(frm.TdmUserOptions_cdsOptions_GroupConsecutive.checked == true && frm.TdmUserOptions_cdsOptions_GroupBy.value == 'All')
        {alert("Can't group consecutive when Group By is set to 'All'");
         frm.TdmUserOptions_cdsOptions_GroupConsecutive.checked = false;}}
       
    GroupBy = value;       
  }

  function changeDispInt(value,frm) {
    
    // changes the Start and End dates to valid options by the current Display Interval selection
    
    //first verify dates are valid and if not, set Display Interval back to what it was
    if(!verifyDates(frm))  
      {frm.TdmUserOptions_cdsOptions_DisplayInterval.value = dispInt;
       return;}

    // for Calendar Month, dates should be set to first of month       
    if(value == 'Calendar Month')
      {if(frm.TdmUserOptions_cdsOptions_StartDate)  //if start date exists
        {frm.TdmUserOptions_cdsOptions_StartDate.value = setToFirstOfMonth(frm.TdmUserOptions_cdsOptions_StartDate.value);
         frm.TdmUserOptions_cdsOptions_StartPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate)  //if end date exists
        {frm.TdmUserOptions_cdsOptions_EndDate.value = setToFirstOfMonth(frm.TdmUserOptions_cdsOptions_EndDate.value);
         frm.TdmUserOptions_cdsOptions_EndPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate && frm.TdmUserOptions_cdsOptions_StartDate)  //if both dates exist
        {chkMonths(frm);}}  // check to make sure the months are different
         
    // for Calendar Year, dates should be set to first of *different* years
    else if(value == 'Calendar Year')
      {if(frm.TdmUserOptions_cdsOptions_StartDate)  //if start date exists
        {frm.TdmUserOptions_cdsOptions_StartDate.value = setToFirstOfYear(frm.TdmUserOptions_cdsOptions_StartDate.value);
         frm.TdmUserOptions_cdsOptions_StartPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate)  //if end date exists
        {frm.TdmUserOptions_cdsOptions_EndDate.value = setToFirstOfYear(frm.TdmUserOptions_cdsOptions_EndDate.value);
         frm.TdmUserOptions_cdsOptions_EndPeriod.value = 'Fixed';}
       if(frm.TdmUserOptions_cdsOptions_EndDate && frm.TdmUserOptions_cdsOptions_StartDate)  //if both dates exist
        {chkYears(frm);}}  // check to make sure the years are different
    
    // for Custom Month, change Date Range to SD if it's currently SE
    else if(frm.TdmUserOptions_cdsOptions_DateRange[0].checked && value == 'Custom Month')
      {frm.TdmUserOptions_cdsOptions_DateRange[1].checked = true;
       changeDRange('SD');}
       
    dispInt = value;       
  }
  
  function drawDurPeriod(value,frm) {

    // dynamically create the options in the Duration Period select-box based on the selection
    //  in the Display Interval or Group By selection

    curDuration = frm.TdmUserOptions_cdsOptions_DurationPeriod.value;
    durSet = false;
    
//  NOTE:  Below two lines are commented out because the 'All' group by option has
//   been removed.  When it's added back, these two lines should be uncommented.
    if(frm.TdmUserOptions_cdsOptions_GroupBy && value > 0)
      value--;

    frm.TdmUserOptions_cdsOptions_DurationPeriod.options.length=0;
    var x = 0;
    if(value == 0)
     {frm.TdmUserOptions_cdsOptions_DurationPeriod.options.length=4;
      frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].value="Days";
      frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].text="Days";
      if(!durSet && curDuration == 'Days')
        {frm.TdmUserOptions_cdsOptions_DurationPeriod.value = curDuration;
         durSet = true;}
      x++;
      frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].value="Weeks";
      frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].text="Weeks";
      if(!durSet && curDuration == 'Weeks')
        {frm.TdmUserOptions_cdsOptions_DurationPeriod.value = curDuration;
         durSet = true;}
      x++;}
    if(value == 0 || value == 1 || value == 3)
     {if(value == 1 || value == 3)
       {x = 0;
        frm.TdmUserOptions_cdsOptions_DurationPeriod.options.length=2;}
      frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].value="Months";
      frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].text="Months";
      if(!durSet && curDuration == 'Months')
        {frm.TdmUserOptions_cdsOptions_DurationPeriod.value = curDuration;
         durSet = true;}
      x++;}
    if(value == 2)
     {x = 0;
      frm.TdmUserOptions_cdsOptions_DurationPeriod.options.length=1;}
    frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].value="Years";
    frm.TdmUserOptions_cdsOptions_DurationPeriod.options[x].text="Years";
      if(!durSet && curDuration == 'Years')
        {frm.TdmUserOptions_cdsOptions_DurationPeriod.value = curDuration;
         durSet = true;}
    if(!durSet)
      frm.TdmUserOptions_cdsOptions_DurationPeriod.selectedIndex = 0;
  }
  
  function validAccumGrouping(form) {
    
    // verifies user has selected a valid combination of Accumulation Interval
    //  and Group By selections (Accumulation Interval cannot be greater than
    //  the Group By value)
    
    AI = form.TdmUserOptions_cdsOptions_AccumInterval.selectedIndex;
    GB = form.TdmUserOptions_cdsOptions_GroupBy.selectedIndex;
    
//  NOTE:  The below seven lines are commented out because the 'All' group by option
//   has been removed.  When it is put back, these lines should be uncommented.
    if((AI == 0 || GB == 0) || (AI == 3 && GB == 4))
      return true;
    if(GB == 4 && (AI != 0 && AI != 3))
      return false;
    if(AI == 3 && (GB != 0 && GB != 4))
      return false;
    GB -= 1;
    if(AI > GB)
      return false;
    else
      return true;
  }
  
function checkDoW(frm) {

  // checks to see if any of the Days of Week checkboxes are checked

  if(!frm.TdmUserOptions_cdsOptions_Sun.checked && !frm.TdmUserOptions_cdsOptions_Mon.checked &&
     !frm.TdmUserOptions_cdsOptions_Tue.checked && !frm.TdmUserOptions_cdsOptions_Wed.checked &&
     !frm.TdmUserOptions_cdsOptions_Thu.checked && !frm.TdmUserOptions_cdsOptions_Fri.checked &&
     !frm.TdmUserOptions_cdsOptions_Sat.checked)
        return false;
  else
        return true;
}

function checkMoY(frm) {
  
  // checks to see if any of the Months of Year checkboxes are checked
  
  if(!frm.TdmUserOptions_cdsOptions_Jan && !frm.TdmUserOptions_cdsOptions_Feb &&
     !frm.TdmUserOptions_cdsOptions_Mar && !frm.TdmUserOptions_cdsOptions_Apr &&
     !frm.TdmUserOptions_cdsOptions_May && !frm.TdmUserOptions_cdsOptions_Jun &&
     !frm.TdmUserOptions_cdsOptions_Jul && !frm.TdmUserOptions_cdsOptions_Aug &&
     !frm.TdmUserOptions_cdsOptions_Sep && !frm.TdmUserOptions_cdsOptions_Oct &&
     !frm.TdmUserOptions_cdsOptions_Nov && !frm.TdmUserOptions_cdsOptions_Dec)
       return false;
  else
       return true;
}

function validTimeRange(frm) {

  // Verifies the 'From' time range is earlier than the 'To' time range
  
  if(parseInt(frm.TdmUserOptions_cdsOptions_TimeFromHR.value) < parseInt(frm.TdmUserOptions_cdsOptions_TimeToHR.value))
     return true;
  else if(parseInt(frm.TdmUserOptions_cdsOptions_TimeFromHR.value) == parseInt(frm.TdmUserOptions_cdsOptions_TimeToHR.value) &&
          parseInt(frm.TdmUserOptions_cdsOptions_TimeFromMIN.value) < parseInt(frm.TdmUserOptions_cdsOptions_TimeToMIN.value))
     return true;
  else
    return false;
}

function masterValidation(frm) {
    
  // validation to be performed before doing any 'final' requests, as in:  Graph, Table
  //  Save Report, Download
  
  if(anType == 'CT')
    {if(!validAccumGrouping(frm))
      {alert('The Accumulation Interval must less\nthan or equal to the Grouping Interval.');
       return false;}}
       
  if(!verifyDates(frm))
    {return false;}
    
  if(frm.TdmUserOptions_cdsOptions_Sun)
    {if(!checkDoW(frm))
      {alert('You need to select at least one "Days of Week" checkbox.');
       return false;}}
       
  if(frm.TdmUserOptions_cdsOptions_Jan)
    {if(!checkMoY(frm))
      {alert('You need to select at least on "Months of Year" checkbox.');
       return false;}}

  if(frm.TdmUserOptions_cdsOptions_TimeOfDay && !frm.TdmUserOptions_cdsOptions_TimeOfDay[0].checked)
    {if(!validTimeRange(frm))
      {alert('"From" Time Range must be earlier than "To" Time Range');
       return false;}}
       
  return true;
  }