/*------------------------------------------------------------------------
 * about(text)
 * 
 * Set the HTML content of the 'hint' element
 *------------------------------------------------------------------------*/

function about(text) {
  document.getElementById("hint").innerHTML = text;
}


/*------------------------------------------------------------------------
 * unabout()
 * 
 * Reset the HTML content of the 'hint' element to the default message
 *------------------------------------------------------------------------*/

function unabout() {
  about("<b>Hint:<\/b> rollover a menu link for further information");
}


/*------------------------------------------------------------------------
 * index_redirect()
 * 
 * Perform a redirect when an option is selected in the alphabetical index
 * pulldown.
 *------------------------------------------------------------------------*/

function index_redirect(select) {
  var linkurl = select.options[select.selectedIndex].value;
  if (linkurl)
    document.location.href = linkurl;
  return false;
}


/*------------------------------------------------------------------------
 * get_style()
 * 
 * Returns the title of the current active stylesheet.
 *------------------------------------------------------------------------*/

function get_style() {
  var elems = document.getElementsByTagName("link");
  var n, elem, title;

  for (n = 0; (elem = elems[n]); n++) {
     if (elem.getAttribute("rel").indexOf("style") != -1 
     && (title = elem.getAttribute("title"))
     && !elem.disabled)
       return title;
  }
  return null;
}


/*------------------------------------------------------------------------
 * set_style(title)
 * 
 * Set the active stylesheet by enabling the <link rel="style" ...> 
 * element that has a title attribute matching the title argument,
 * and disabling all others.
 *------------------------------------------------------------------------*/

function set_style(title) {
  var elems = document.getElementsByTagName("link");
  var n, elem, tattr;

  for (n = 0; n < elems.length; n++) {
    elem = elems[n];

    if (elem.getAttribute("rel").indexOf("style") != -1 
    && (tattr = elem.getAttribute("title"))) {
      elem.disabled = true;
      if (tattr == title) 
        elem.disabled = false;
    }
  }
}


/*------------------------------------------------------------------------
 * set_cookie(name, value, days)
 * 
 * Set a cookie with the name and value passed as the first two arguments, 
 * set to expire in the number of days specified in the third argument.
 *------------------------------------------------------------------------*/

function set_cookie(name, value, days) {
  var expires;

  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + (days*24*60*60*1000));
    expires = "; expires=" + date.toGMTString();
  }
  else 
    expires = "";

  document.cookie = name + "=" + value + expires + "; path=/";
}


/*------------------------------------------------------------------------
 * get_cookie(name)
 * 
 * Returns the value of the cookie identified by the name argument.
 *------------------------------------------------------------------------*/

function get_cookie(name) {
  var namestr  = name + "=";
  var cookbits = document.cookie.split(';');
  var n;

  for(n = 0; n < cookbits.length; n++) {
    var c = cookbits[n];

    /* remove leading whitespace */
    while (c.charAt(0) == ' ') 
      c = c.substring(1, c.length);

    /* if the name start this cookie fragment, return the value */
    if (c.indexOf(namestr) == 0) 
      return c.substring(namestr.length, c.length);
  }
  return null;
}


/*------------------------------------------------------------------------
 * hide_menu()
 * 
 * Set the stylesheet to 'Hide Menu'
 *------------------------------------------------------------------------*/

function hide_menu() {
  unabout();
  set_style('Hide Menu');
  return false;
}


/*------------------------------------------------------------------------
 * show_menu()
 * 
 * Set the stylesheet to 'Show Menu'
 *------------------------------------------------------------------------*/

function show_menu() {
  unabout();
  set_style('Show Menu');
  return false;
}


function clear_link(name) {
  document.getElementById(name).href = '#';
}
