
function AddMenuItem( objMenu, id, show, text, href, onClick )
{
 var objAnchor = new ItemAnchor( text );

 objAnchor.addAttribute( "href", href );

 if ( onClick != null )
 {
  objAnchor.addAttribute( "onClick", onClick );
 }

 var objSpan = new ItemSpan( objAnchor );

 objSpan.addAttribute( "id", id );

 var objItem = new ItemMenu( id, objSpan, show );

 objMenu.addItem( objItem );
}

function ItemAttribute( name, value )
{
 this.name = name;
 this.value = value;

 this.getHTML = 
  function getHTML()
  {
   return this.name + '=\"' + this.value + '\"';
  }
}

function ItemTag( name, value )
{
 this.name = name;
 this.value = value;
 this.attributes = new Array();

 this.addAttribute = 
  function addAttribute( name, value )
  {
   this.attributes[ this.attributes.length ] = new ItemAttribute( name, value );
  }

 this.getHTML = 
  function getHTML()
  {
   var str = "";

   str += "<" + this.name;
   var ix = 0;
   for ( ix = 0; ix < this.attributes.length; ++ix )
   {
    var objAttr = this.attributes[ ix ];
    if ( objAttr != null )
    {
     str += " " + objAttr.getHTML();
    }
   }
   str += ">";

   if ( this.value != null )
   {
    if ( typeof this.value == "string" )
    {
     str += this.value;
    }
    else
    {
     str += this.value.getHTML();
    }
   }

   str += "</" + this.name + ">"

   return str;
  }
}

function ItemAnchor( value )
{
 this.tag = new ItemTag( "a", value );

 this.addAttribute = 
  function addAttribute( name, value )
  {
   this.tag.addAttribute( name, value );
  }

 this.getHTML = 
  function getHTML()
  {
   return this.tag.getHTML();
  }
}

function ItemSpan( value )
{
 this.tag = new ItemTag( "span", value );

 this.addAttribute = 
  function addAttribute( name, value )
  {
   this.tag.addAttribute( name, value );
  }

 this.getHTML = 
  function getHTML()
  {
   return this.tag.getHTML();
  }
}

function ItemMenu( id, objItem, show )
{
 this.id = id;
 this.objItem = objItem;
 this.show = show;

 this.getID = 
  function getID()
  {
   return this.id;
  }
 
 this.getHTML = 
  function getHTML()
  {
   return this.objItem.getHTML();
  }
}

function SpecialMenu( id )
{
 this.id = id;
 this.align = 'right';
 this.emptyStr = '&nbsp;';
 this.separator = '&nbsp|&nbsp';
 this.elements = new Array();

 this.display = 
  function display() 
  {
   var obj = GetElementById( this.id );
   if ( obj != null )
   {
    var str = this.getHTML();
    SetElementTextByObj( obj, str );
    onUpdateTextSize();
   }
  }

 this.addItem = 
  function addItem( objItem )
  {
   this.elements[ this.elements.length ] = objItem;
  }

 this.showItem = 
  function showItem( id, show )
  {
   var ix = 0;
   for ( ix = 0; ix < this.elements.length; ++ix )
   {
    objItem = this.elements[ ix ];
    if ( objItem != null && objItem.getID() == id )
    {
     objItem.show = show;
     return true;
    }
   }
   return false;
  }

 this.getHTML = 
  function getHTML()
  {
   var objItem = null;
   var strItem = "";
   var strMenu = "";
   
   var ix = 0;
   for ( ix = 0; ix < this.elements.length; ++ix )
   {
    objItem = this.elements[ ix ];
    if ( objItem != null && objItem.show == true )
    {
     strItem = objItem.getHTML();
     
     if ( strItem != null && strItem.length > 0 )
     {
      if ( strMenu != "" )
      {
       strMenu += this.separator;
      }

      strMenu += strItem;
     }
    }
   }

   if ( strMenu == "" )
   {
    strMenu = this.emptyStr;
   }

   return strMenu;
  }
}
 
