var last_menu = null;
var hide_timeout = null;

function display_menu( target )
{
  if( target )
  {
    if( last_menu )
      hide_menu( );

    if( hide_timeout )
      clearTimeout( hide_timeout );

    var obj = document.getElementById( target );
    var parent = document.getElementById( target + "_parent" );

    obj.style.left = (getPageOffsetLeft( parent ) - 1) + "px";
    obj.style.top = (getPageOffsetTop( parent ) + parent.offsetHeight) + "px";
    obj.style.visibility = "visible";

    last_menu = obj;
  }
  else
    hide_timeout = setTimeout( "hide_menu()", 300 );     
}

function hide_menu( )
{
  last_menu.style.visibility = "hidden";
  last_menu = null;
  clearTimeout( hide_timeout );
}

function hover( el, obj )
{
  el.oldColor = el.style.backgroundColor;
  el.style.backgroundColor = '#FFFFFF';

  if( obj )
    show( obj );
}

function unhover( el, obj )
{
  el.style.backgroundColor = el.oldColor;

  if( obj )
    hide( obj );
}

function getPageOffsetLeft( el )
{
  var x;

  x = el.offsetLeft;
  if( el.offsetParent )
    x += getPageOffsetLeft( el.offsetParent );

  return x;
}

function getPageOffsetTop( el )
{
  var y;

  y = el.offsetTop;
  if( el.offsetParent )
    y += getPageOffsetTop( el.offsetParent );

  return y;
}

function define( what, def )
{
  wnd = window.open( "","","width=400,height=338" );
  wnd.document.writeln( "<font size='+1'><b>" + what + ":</b></font><hr /><br />" );
  wnd.document.writeln( def );
}

function change_vis( obj )
{
  if( navigator.userAgent.indexOf( "MSIE" ) == -1 )
  {
    var o = document.getElementById( obj );
    if( o.style.display == "none" )
      o.style.display = "block";
    else
      o.style.display = "none";
  }
  else
  {
    if( document.all[obj].style.display == "none" )
      document.all[obj].style.display = "block";
    else
      document.all[obj].style.display = "none";
  }
}  

function set_vis( obj, vis )
{
  if( navigator.userAgent.indexOf( "MSIE" ) == -1 )
  {
    var o = document.getElementById( obj );
    if( vis )
      o.style.display = "block";
    else
      o.style.display = "none";
  }
  else
  {
    if( vis )
      document.all[obj].style.display = "block";
    else
      document.all[obj].style.display = "none";
  }
}

document.onmousemove = mouseMove;
if( document.layers ) document.captureEvents( Event.MOUSEMOVE );

var cur_obj;
var x_offset = 5, y_offset = 5;
var x, y;

function show( obj )
{
  cur_obj = obj;

  if( document.all[cur_obj] )
  {
    if( ( x + document.all[cur_obj].offsetWidth + x_offset ) > document.body.clientWidth )
      x -= document.all[cur_obj].offsetWidth + 2*x_offset;
    if( ( y + document.all[cur_obj].offsetHeight + y_offset ) > document.body.clientHeight )
      y -= document.all[cur_obj].offsetHeight + 2*y_offset;

    document.all[cur_obj].style.left = document.body.scrollLeft + x + x_offset;
    document.all[cur_obj].style.top = document.body.scrollTop + y + y_offset;

    document.all[cur_obj].style.visibility = "visible";
  }
}

function hide( obj )
{
  cur_obj = null;

  if( document.all[obj] )
    document.all[obj].style.visibility = "hidden";
}

function mouseMove( e )
{
  x = event.clientX;
  y = event.clientY;

  if( document.all[cur_obj] )
  {
    if( ( x + document.all[cur_obj].offsetWidth + x_offset ) > document.body.clientWidth )
      x -= document.all[cur_obj].offsetWidth + 2*x_offset;
    if( ( y + document.all[cur_obj].offsetHeight + y_offset ) > document.body.clientHeight )
      y -= document.all[cur_obj].offsetHeight + 2*y_offset;

    document.all[cur_obj].style.left = document.body.scrollLeft + x + x_offset;
    document.all[cur_obj].style.top = document.body.scrollTop + y + y_offset;
  }
}