// (C) 2007 by Jean-Christophe Koerber. All rights reserved.

function addMenuItem (menu, className, label, address, key)
{
 menu[menu.length]=new MenuItem(className, label, address, key);
}

function MenuItem (className, label, address, key)
{
 this.className=className;
 this.label=label;
 this.address=address;
 this.key=key;
}

function buildMenu (menu, identity, menuLeftLocation, menuRightLocation, key)
{
 var element;
 var content;
 var index;
 var maxIndex;
 var menuItem;

 if (menu.length>0)
 {
  element=document.getElementById(identity);

  if (element)
  {
   content="";

   for (index=0, maxIndex=menu.length; index<maxIndex; index++)
   {
    menuItem=menu[index];

    content+=(menuItem.key!=key?"":"<b><i>");

    if (menuItem.label!="")
    {
     if (menuItem.address!="")
     {
      content+="<a href=\""+menuItem.address+"\" class=\""+menuItem.className+"\">"+menuItem.label+"</a>";
     }
     else
     {
      content+="<font class=\""+menuItem.className+"\">"+menuItem.label+"</font>";
     }
    }
    else
    {
     content+="<font class=\""+menuItem.className+"\">&nbsp;</font>";
    }

    content+=(menuItem.key!=key?"":"</i></b>");
    content+="<br/>";
   }

   if ((menuLeftLocation)
       &&(menuLeftLocation!="")
       &&(menuRightLocation)
       &&(menuRightLocation!=""))
   {
    content+="<table width=\"100%\" class=\"menu\" cellspacing=\"0\">";
    content+="<tr>";
    content+="<td align=\"left\">";
    content+="<img src=\""+menuLeftLocation+"\"/>";
    content+="</td>";
    content+="<td align=\"right\">";
    content+="<img src=\""+menuRightLocation+"\"/>";
    content+="</td>";
    content+="</tr>";
    content+="</table>";
   }

   element.innerHTML=content;
  }
 }
}