﻿/* Invoked when checkbox for an option is clicked */
function UpdateAllBox(wrapperId, allBoxId)
  { var all, none;

    /* Find all the checkboxes within the wrapper div */
    var wrapper = document.getElementById(wrapperId);
    if (wrapper == null) return;
    var boxes = wrapper.getElementsByTagName('input');
    if (boxes == null  ||  boxes.length == null) return;
    
    /* Find the all selections checkbox */
    var allBox = document.getElementById(allBoxId);
    if (allBox == null) return;
        
    /* Determine if all options or no options are selected */
    all = true;
    none = true;
    for (var j=0;  j<boxes.length;  j++)
      { all &= boxes[j].checked;
        none &= !boxes[j].checked;
      }

    /* If all options are checked, uncheck all grades */
    if (all)
      for (j=0;  j<boxes.length;  j++)
        boxes[j].checked = false;

    /* If all or none of the options are checked, set the all options box. */
    allBox.checked = (all || none)
  }

/* Invoked when the checkbox for "all options" is clicked. */
function AllBoxClick(wrapperId, allBoxId)
  {
    /* Find all the checkboxes within the wrapper div */
    var wrapper = document.getElementById(wrapperId);
    if (wrapper == null) return;
    var boxes = wrapper.getElementsByTagName('input');
    if (boxes == null  ||  boxes.length == null) return;
    
    /* Find the all selections checkbox */
    var allBox = document.getElementById(allBoxId);
    if (allBox == null) return;

    /* If the all box is now checked, un-check all the option boxes. */
    if (allBox.checked)
      { for (var j=0;  j<boxes.length;  j++)
          { boxes[j].checked = false;
          }
      }
    else
      { allBox.checked = true;
      }
  }