<!--

// ----------------------------------------------------------------------------
//
// Copyright (C) 2000-2002 Spanner Sofware Ltd
//
// This code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2.0 as published by the Free Software Foundation. See
// http://www.gnu.org/copyleft/gpl.html for full details.
// 
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// Please notify us of any improvements by sending them to
// support@spannersoftware.com
// 
// Dropdown menu functions
// menu.js
// 
// Ref  Date        Author  Action
// 000  06-03-2002  VJS     Created
// 
// ----------------------------------------------------------------------------

opera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
num_menu_layers = 0;
Menu = new Array();

function MenuItem(type, url, itemtext, width, height) {
  this.type = type;
  this.url = url;
  this.itemtext = itemtext;
  this.width = width;
  this.height = height;
}

function GetMaxHeight() {
  max_height = 0;

  for (i = 0; i < Menu.length; i++) {
    if (Menu[i].height > max_height) {
      max_height = Menu[i].height;
    }
  }
  
  return max_height;
}

function GetNoMenus() {
  num_menus = 0;

  for (i = 0; i < Menu.length; i++) {
    if (Menu[i].type == "main") {
      num_menus++;
    }
  }
  
  return num_menus;
}

function add_menu(x, y, hspace, current_url, bg_color, menu_height, item_height) {
  var layer_vis = "visible";
  var curr_item = 0;
  var in_layer = false;
  var menu_layer_no = 0;

  // do mask layer to hide menu layers when not required
  document.writeln('<div id="mask" style="position:absolute; left:8px; top:' + y + 'px; width:748px; height:' + GetMaxHeight() + 'px; z-index:1; visibility: hidden">');
  document.writeln('<a href="javascript:;" onMouseOver="HideAll()"><img src="images/t.gif" width="100%" height="100%" border="0"></a>');
  document.writeln('</div>');
  
  // do main menu buttons first
  curr_item = 0;
  menu_layer_no = 0;
  num_menus = GetNoMenus();
  total_width = (num_menus * (hspace - 4)) + (num_menus * 2) + 100;

  document.writeln('<table bgcolor="' + bg_color + '" width="' + total_width + '" cellspacing="0" cellpadding="2"><tr><td width="10">&nbsp;</td>');
  
  while (curr_item < Menu.length) {
    if (Menu[curr_item].type == "main") {
      if (Menu[curr_item].height > 0) {
        menu_layer_no++;
      }
      
      add_main(hspace, Menu[curr_item].height, Menu[curr_item].url, Menu[curr_item].itemtext, menu_layer_no, menu_height);
    }
      
    curr_item++;
  }

  document.writeln('<td width="*">&nbsp;</td>');
  document.writeln('</tr></table>');

  // now create submenus as layers
  curr_item = 0;
  menu_layer_no = 0;
  curr_x = x;
  in_layer = false;
  
  while (curr_item < Menu.length) {
    if (Menu[curr_item].type == "main") {
      if (in_layer) {
        close_menu_layer();
        in_layer = false;
      }

      if (Menu[curr_item].height > 0) {
        menu_layer_no++;
        open_menu_layer("menu" + menu_layer_no, "hidden", bg_color, curr_x + 1, y - 3, Menu[curr_item].width,
          Menu[curr_item].height);
        in_layer = true;
      }

      curr_x += hspace;
    } else if (Menu[curr_item].type == "item") {
      add_item_button(Menu[curr_item].url, Menu[curr_item].itemtext, item_height, bg_color);
    }
      
    curr_item++;
  }
    
  if (in_layer) {
    close_menu_layer();
  }

  num_menu_layers = menu_layer_no;
}

function ShowMenu(menu_layer_no) {
  if (document.layers) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.layers['menu' + i].visibility = 'hidden';
    }

    document.layers['mask'].visibility = 'visible';
    document.layers['menu' + menu_layer_no].visibility = 'visible';
  } else if (document.all) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.all('menu' + i).style.visibility = 'hidden';
    }

    document.all('mask').style.visibility = 'visible';
    document.all('menu' + menu_layer_no).style.visibility = 'visible';
  } else {
    for (i = 1; i <= num_menu_layers; i++) {
      document.getElementById('menu' + i).style.visibility = 'hidden';
    }

    document.getElementById('mask').style.visibility = 'visible';
    document.getElementById('menu' + menu_layer_no).style.visibility = 'visible';
  }
}

function HideAll() {
  if (document.layers) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.layers['menu' + i].visibility = 'hidden';
    }

    document.layers['mask'].visibility = 'hidden';
  } else if (document.all) {
    for (i = 1; i <= num_menu_layers; i++) {
      document.all('menu' + i).style.visibility = 'hidden';
    }

    document.all('mask').style.visibility = 'hidden';
  } else {
    for (i = 1; i <= num_menu_layers; i++) {
      document.getElementById('menu' + i).style.visibility = 'hidden';
    }

    document.getElementById('mask').style.visibility = 'hidden';
  }
}

function open_menu_layer(menuname, vis, bg_color, nleft, ntop, nwidth, nheight) {
  if (opera) { ntop += 8; }
  document.writeln('<div id="' + menuname + '" style="position:absolute; left:' + nleft + 'px; top:' + ntop + 'px; width:' + nwidth + 'px; height:' + nheight + 'px; z-index:2; visibility:' + vis + '">');
  document.writeln('<table bgcolor="' + bg_color + '" class="menutable" border="0" cellpadding="0" cellspacing="0" width="' + nwidth + '">');
}

function close_menu_layer() {
  document.writeln('</table>');
  document.writeln('</div>');
}

function add_main(nwidth, nheight, url, itemtext, menu_layer_no, menu_height) {
  document.write('<td width="' + (nwidth - 4) + '" class="menucell" onClick="parent.location=\'' + url + '\'"');

  if (nheight == 0) {
    document.writeln('><a class="menutitle" href="' + url + '">' + itemtext + '</a></td>');
  } else {
    document.writeln(' onMouseOver="ShowMenu(' + menu_layer_no + ')"><a class="menutitle" href="' + url + '">' + itemtext + '</a></td>');
  }
}

function add_item_button(url, itemtext, item_height, bg_color) {
  document.write('<tr><td class="menucell" valign="top" onMouseOver="this.style.backgroundColor=\'#999999\'" onMouseOut="this.style.backgroundColor=\'' + bg_color + '\'" onClick="parent.location=\'' + url + '\'">');
  document.writeln('<img src="images/t.gif" width="12" height="' + item_height + '" align="absmiddle"><a class="menuitem" href="' + url + '">' + itemtext + '</a></td></tr>');
}
//-->