/*

functions for showing and hiding page elements

Define elementIDs as an array of IDs of HTML elements in order to use
showOneElement() and hideElements().

*/

var elementIDs = null;

// showOneElement: show one element among the elementIDs array, and
// hide all the others.
// elementID must be one of the values in the elementIDs array.
function showOneElement(elementID) {
  if (! elementIDs) return;
  for (var i = 0; i < elementIDs.length; i++) {
    var element = document.getElementById(elementIDs[i]);
    if (element == null) continue;
    if (elementID != null && elementID == elementIDs[i]) {
      element.style.display = 'inline';
      element.style.display = 'block';
    }
    else {
      element.style.display = "none";
    }
  }
}

// hideElements: hide all elements in the elementIDs array
function hideElements() { showOneElement(null); }


// setVisibility: show, hide or toggle visibility of an HTML element

// Set show to 1 (or true) to show element, 0 (or false) to hide it,
// -1 to toggle it.  Set setButton to true to look for and adjust a
// plus/minus image associated with the element (the image should have
// the same ID as the associated element, but with "_img" appended).
// Return true if the action taken was to show the element, false
// otherwise.

function setVisibility(elementID, show, setButton) {
  var element = document.getElementById(elementID);
  if (element == null) return false;
  var img = setButton ? document.getElementById(elementID + "_img") : null;
  if (show == -1) show = (element.style.display == 'none');
  if (show) {
    element.style.display = 'inline';
    element.style.display = 'block';
    if (img != null) img.src = "/images/minus.gif";
  }
  else {
    element.style.display = "none";
    if (img != null) img.src = "/images/plus.gif";
  }
  return show ? true : false;
}

// Wrapper around setVisibility() to show an element.
function showElement(elementID) {
  setVisibility(elementID, 1, null);
}

// Wrapper around setVisibility() to hide an element.
function hideElement(elementID) {
  setVisibility(elementID, 0, null);
}
