/*
  ######################################################################################################################
  ###
  ###   ABN AMRO UID DYNAMIC MENU
  ###   abnuidmenu.js, v4.0, 30 oktober 2001
  ###
  ###   Pecoma Collage
  ###   http://www.collage.nl
  ###
  ######################################################################################################################
*/

GenMenu();
/*
  ######################################################################################################################
  ###
  ### CORE
  ###
  ######################################################################################################################
*/

if(document.getElementById)
{
  var doc = document;

  doc.write('<link rel="stylesheet" href="../style/menuGui.css" type="text/css">');

  // *** Preload images
  var fn = new Array('folder_closed.gif', 'folder_open.gif');
  var im = new Array();

  for(i=0; i<fn.length; i++)
  {
    im[i] = new Image();
    im[i].src = '../images/menuGui/' + fn[i];
  }
  
  doc.write('<FONT SIZE=1>&nbsp;<BR></FONT>');
  
  for(i=0; i<item.length; i++)
  {
    if(item[i].parent == -1)
    {
      itemPlot(i, 0);
      for(j=0; j<item.length; j++)
        if(item[j].parent == i)
        {
          itemPlot(j, 1);
          for(k=0; k<item.length; k++)
            if(item[k].parent == j)
              itemPlot(k, 2);
        }
    }
  }
}

/*
  ######################################################################################################################
  ###
  ### FUNCTIONS
  ###
  ######################################################################################################################
*/

function itemConstructor(parent, title, href, altclass)
{
  this.parent   = parent;
  this.title    = title;
  this.href     = href;
  this.altclass   = altclass;
  this.state    = 0;
}

function itemAdd(parent, title, href, altclass)
{
  last_item = item.length;
  item[last_item] = new itemConstructor(parent, title, href, altclass);
  return(last_item);
}

function itemPlot(id, level)
{
  // *** Find out if the current item has child(s)
  item[id].hasChild = itemHasChild(id);
  
  if(item[id].title == '')
    doc.write('<BR>');
  else
  {
    // *** Call appropriate itemPlot function
    var style_class = item[id].altclass ? item[id].altclass : 'level' + level;
    var display = (level == 0 || item[item[id].parent].state) ? 'block' : 'none';
  
    // *** Correct items on the third level when they are expanded, but their parent is not
    if(display == 'block' && level > 0 && item[item[item[id].parent].parent] && !item[item[item[id].parent].parent].state)
      display = 'none';
  
    // *** Plot the table
    doc.write("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 ID='item_" + id + "' STYLE='position:block; display:" + display + "'>");
    doc.write("<TR>");
      doc.write('<TD><DIV CLASS="' + style_class + '">');
        var ahref = '<A HREF="javascript:clickItem(' + id + ')" ONFOCUS="blur()">';
        doc.write(ahref + '<IMG SRC="../images/menuGui/folder_' + (!item[id].hasChild ? 'blank' : (item[id].state ? 'open' : 'closed')) + '.gif" CLASS="overrule" BORDER=0 WIDTH=10 HEIGHT=14 ALT="Item" NAME="img_' + id + '"></A>&nbsp;');
        doc.write(ahref + '&nbsp;' + item[id].title + '&nbsp;</A>');
    doc.write("</DIV></TD>");
    doc.write("</TR>");
    doc.write("</TABLE>");
  }
}

function itemHasChild(id)
{
  for(var j=1; j<item.length; j++)
    if(item[j].parent == id)
      return true;
  return false;
}

function clickItem(id)
{
  if(item[id].hasChild)
  {
    var state = item[id].state == 1 ? 'none' : 'block';
    for(var j=1; j<item.length; j++)
      if(item[j].parent == id)
        document.getElementById('item_' + j).style.display = state;
    item[id].state = 1 - item[id].state;
    if(doc.images['img_' + id])
      doc.images['img_' + id].src = im[item[id].state].src;

    // *** Collapse child items (just root items)
    if(item[id].parent <= 0)
      for(var j=1; j<item.length; j++)
        if(item[j].parent == id && (item[id].state == 0 || item[id].state == item[j].state))
          for(var i=1; i<item.length; i++)
            if(item[i].parent == j)
              document.getElementById('item_' + i).style.display = state;
  }
  if(item[id].href)
  {
    if(default_target.length > 0)
      eval(default_target + '.location.href = item[id].href');
    else
      location.href = item[id].href;
  }
}