/*
 * Library to display only one item with a given class on a page.
 *
 * $Id$
 *
 */

// Function getElementsByClass
//
// Get a list of all of the elements within a given node that have
// a given class.
// Can't believe that this isn't already in the DOM!
//
// Parameters:
//   the_node  - name of the node to search
//   the_class - name of the class to search for
//
// Return:
//   List of nodes matching the class name

function getElementsByClass(the_node, the_class) {
  var nodes = new Array;

  function search_children(the_node) {
    if (the_node.className && the_node.className == the_class){
      nodes[nodes.length] = the_node;
    }
    for (var i=0; i<the_node.childNodes.length; i++) {
      search_children(the_node.childNodes[i]);
    }
  }
  search_children(the_node);

  return nodes;
} 

// Function show_one
//
// Function that changes the display style of all elements with a 
// given class to "none". It then changes the display of an single
// item with a given id to a given value (which defaults to "block").
//
// Parameters:
//   class   - the name of the class to not display
//   id      - the item of the single element to display
//   display - the display mode to use (optional, defaults to "block")
//
// Return:
//   none

function show_one (a_class, an_id, a_display) {
  if (a_display == null) {
    a_display = 'block';
  }
  var elements = getElementsByClass(document, a_class);

  for (var i = 0; i < elements.length; i++) {
    elements[i].style.display = "none";
  }

  var show_element = document.getElementById(an_id);

  if (show_element != null) {
    show_element.style.display = a_display;
  }
}

function show_all (a_class, a_display) {
  if (a_display == null) {
    a_display = 'block';
  }
  var elements = getElementsByClass(document, a_class);

  for (var i = 0; i < elements.length; i++) {
    elements[i].style.display = a_display;
  }
}
 

