/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *  Copyright (c) 2002-4  Peter Heinrich
 *  All Rights Reserved
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */



/**
 *  Make sure this page isn't trapped in someone else's frame.
 */
if( top != self )
   top.location.replace( location.href );



/**
 *  Find an object in the DOM tree, regardless of which DOM is supported by the
 *  current browser (with the exception of Netscape 4).
 */
function getObject( id )
{
   var object = null;

   if( document.getElementById )
      object = document.getElementById( id );    
   else if( document.all )
      object = document.all[ id ];
   else if( document.layers )
      object = document.layers[ id ]; 

   return( object );
}



/**
 *  Return the style portion of an object from the DOM tree.
 */
function getStyle( id )
{
   var style = getObject( id );

   if( null != style && null != style.style )
      style = style.style;

   return( style );
}


function initMenus()
{
  var list = document.getElementsByTagName( 'div' );
  var images = document.images ? new Array() : null;

  for( var i = 0; i < list.length; i++ )
  {
    if( list[ i ].className == "submenu" )
    {
      if( list[ i ].captureEvents )
        list[ i ].captureEvents( Event.MOUSEOUT );

      list[ i ].autoHide = true;
      list[ i ].onmouseout = hideMenu;

      if( null != images )
      {
        var base = list[ i ].getAttribute( 'id' );
        var off = new Image();
        var on = new Image();

        off.src = "/images/" + base + ".gif";
        on.src = "/images/" + base + "-on.gif";

        images.push( off, on );
      }
    }
  }
}


function hideMenu( e )
{
  //  Microsoft uses a special property instead of passing the event as an argu-
  //  ment to this function.
  if( !e )
    e = window.event;

  var from;

  if( e.target )
    from = e.target;
  else if( e.srcElement )
    from = e.srcElement;

  //  Defeat Safari bug.
  if( 3 == from.nodeType )
    from = from.parentNode;

  //  Find the containing submenu, or null if none.
  while( from && !from.autoHide )
    from = from.parentNode;

  //  We're leaving a submenu (or a child of a submenu.
  if( from.autoHide )
  {
    var to;

    if( e.relatedTarget )
      to = e.relatedTarget;
    else if( e.toElement )
      to = e.toElement;

    //  Find the containing submenu, or null if none.
    while( to && !to.autoHide )
      to = to.parentNode;

    //  Are we moving someplace not contained by the current submenu?
    if( to != from )
    {
      if( from.visibility )
        from.visibility = "hidden";
      else
        from.style.visibility = "hidden";
    }
  }
}


function showMenu( id )
{
  var list = document.getElementsByTagName('div');

  for( var i = 0; i < list.length; i++ )
  {
    var name = list[ i ].className;

    if( name == "submenu" )
    {
      var other = list[ i ].getAttribute( 'id' );
      var style = getStyle( other );

      if( other != id && null != style )
        style.visibility = "hidden";
    }
    else if( name == "sublight" )
      list[ i ].className = "subitem";
  }

  var style = getStyle( id );
  if( null != style )
    style.visibility = "visible";
}


/**
 *  Change the image associated with an element in the current document.
 */
function swapImage( id, imageURL )
{
   var element = getObject( id );

   if( null != element )
      element.src = imageURL;      
}


/**
 *  Change the display style of an element, usually to toggle between its usual
 *  state ('block' or 'inline') and 'none' (to make it invisible).
 */
function setDisplay( id, value )
{
   var style = getStyle( id );

   if( null != style )
      style.display = value;
}


/**
 *  Sets the class associated with an object.
 */
function setClass( id, value )
{
  var element = getObject( id );

  if( null != element )
    element.className = value;
}


/**
 *  Open a URL in a separate browser window.  Javascript is only required when
 *  using strict HTML, since that variant doesn't employ the 'target' attribute
 *  on elements.
 */
function opennew( url )
{
   newwindow = window.open( url, '_blank', 'location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes' );

   if( window.focus )
     newwindow.focus();
}
