/*/////////////////////////////////////////////////////////////////////////////

Component:    Javascript Show/Hide Function

Description:  My javascript show/hide function governs display toggling for
              elements that can optionally be hidden or shown in my user
              interface template, and in the individual pages that import it.
              It is used most prominently in the authentication form common to
              every public page of my site, but it governs other elements as
              well, such as the various peripheral information sections on my
              Journal page.

Project:      My Website
                User Interface

Path:         [...]/httpdocs/resources/showhide.js

Author:       The Confessor <http://confessor.org/contact.php>

Copyright:    (C) 2007-2010 The Confessor

License:      Use of all or portions of my website source code in your own
              projects is subject to the terms and conditions listed here:
              <http://confessor.org/termsofuse.php>

/////////////////////////////////////////////////////////////////////////////*/

var prevtarget = null;

function toggle(target,action,prevtarget_action) {

  element = document.getElementById(target+'element');
  img = document.getElementById(target+'img');

  if (prevtarget) {
    prevelement = document.getElementById(prevtarget+'element');
    previmg = document.getElementById(prevtarget+'img');
  }

  if (element.style.display != "" && (action == 'hide' || action == 'both')) {
    element.style.display = '';
    img.src = '/resources/toggle_closed.gif';
    if (prevtarget == target) {
      prevtarget = null;
    }
    try {eval(target+'_onhide();');}
    catch(err) {}
  }

  else if (element.style.display == "" && (action == 'show' || action == 'both')) {
    if (!prevtarget || prevtarget_action != 'interrupt') {
      if (prevtarget && prevtarget_action == 'hide') {
        prevelement.style.display = '';
        previmg.src = '/resources/toggle_closed.gif';
      }
      element.style.display = 'block';
      img.src = '/resources/toggle_open.gif';
      if (prevtarget_action != 'ignore') {
        prevtarget = target;
      }
      try {eval(target+'_onshow();');}
      catch(err) {}
    }
  }
}