// toolbars
var __count = 100;
var __aAllMenu = new Array();

//---------------------------------------------------------------------------------------------
// MENU
//---------------------------------------------------------------------------------------------
function Menu(containerid)
{
  this.aMenuItems = new Array();
  if(containerid == null || containerid == "")
    this.container = "";
  else
    this.container = containerid;
  this.action  = "";

  this.add    = __menu_add;
  this.create = __menu_create;
}

function __menu_add(menuitem)
{
  var id = this.aMenuItems.length;
  this.aMenuItems[id] = menuitem;
  menuitem.id = __count;
  menuitem.menu = this;
  __count++;

  // we ned this for access within events
  var id = __aAllMenu.length;
  __aAllMenu[id] = menuitem;
}

function __menu_create()
{
  var temp = "<table width='100%' height='100%' cellspacing='0' cellpadding='1' style='border: 1px outset;font-family: arial;font-size: 11px'>";

  // get code for all toolbars
  for (var i=0;i<this.aMenuItems.length;i++) {
    var menuitem = this.aMenuItems[i];
    temp+= menuitem.create();
  }
  temp+="</table>";
  // write html code
  var objContainer = document.getElementById(this.container);

  if(this.container == "")
    return temp;
  else
    objContainer.innerHTML = temp;
}

//---------------------------------------------------------------------------------------------
// MENUITEM
//---------------------------------------------------------------------------------------------
function MenuItem(text,image,action,design,tag)
{
  this.id      = "";
  this.height  = "20";
  this.toolbar = null;
  this.tag     = tag;
  this.text    = text;
  this.action  = action;
  this.image   = image;
  this.design  = design;
  this.enabled = true;

  this.setEnabled   = __menuitem_enable;

  this.onmouseup    = __menuitem_mouseup;
  this.onmousedown  = __menuitem_mousedown;
  this.onmouseover  = __menuitem_mouseover;
  this.onmouseout   = __menuitem_mouseout;

  this.create       = __menuitem_create;
}

function __menuitem_direct(id,action)
{
  for (var j=0;j<__aAllMenu.length;j++) {
    if(__aAllMenu[j].id == id){
      var component = __aAllMenu[j];
      if(action == "OVER")
        component.onmouseover();
      if(action == "OUT")
        component.onmouseout();
      if(action == "DOWN")
        component.onmousedown();
        __mbutton_clicked = component;
      if(action == "UP") {
        component.onmouseup();
        if(component.menu.action != "") {
          if(component.tag != "" && component.tag != null)
            eval( component.menu.action + "('" + component.tag + "')");
        }
      }
    }
  }
}

function __menuitem_create()
{
  var temp = "<table border=0 cellspacing=0 cellpadding=0 width='100%'";
      temp+= " id='" + this.id + "' ";
      temp+= " class='MenuItemStandard" + this.design + "' ";
      temp+= " onmouseover='__menuitem_direct(" + this.id + ",\"OVER\")'";
      temp+= " onmouseout='__menuitem_direct(" + this.id + ",\"OUT\")'";
//      temp+= " onmousedown='__menuitem_direct(" + this.id + ",\"DOWN\")'";
      temp+= " onmouseup='__menuitem_direct(" + this.id + ",\"UP\")'";
      temp+= ">";
      temp+= "<tr><td height=" + this.height + " width='1%'>";
  if(this.image)
    temp+= "<img align='absmiddle' border='0' src='" +  this.image + "'>";
    temp+= "</td><td nowrap style='width: 100%'>";
  if(this.text)
    temp+= "<p style='margin-left: 5px;'>" + this.text + "</p>";
  temp+= "</td></tr>";
  temp+= "</table>";
  return temp;
}

function __menuitem_enable(value)
{
  this.enabled = value;
  var button = document.getElementById(this.id);
  if(value) {
    button.className = 'ButtonDisabled';
    button.innerHTML = "<span class='ButtonDisabledContainer'><span class='ButtonDisabledContainer'>" + button.innerHTML + "</span></span>";
  } else {
    button.className = 'ButtonStandardOffice';
    button.innerHTML = button.firstChild.firstChild.innerHTML;
  }
}

function __menuitem_mouseup()
{
  if(!this.enabled)
    return;
  //document.getElementById(this.id).className='MenuItemStandard' + this.design;
  if(this.action != "") {
    eval(this.action);
  }
}

function __menuitem_mousedown()
{
  if(!this.enabled)
    return;
  document.getElementById(this.id).className='MenuItemHover' + this.design;
}

function __menuitem_mouseover()
{
  if(!this.enabled)
    return;
  document.getElementById(this.id).className='MenuItemHover' + this.design;
}

function __menuitem_mouseout()
{
  if(!this.enabled)
    return;
  document.getElementById(this.id).className='MenuItemStandard' + this.design;
}

//---------------------------------------------------------------------------------------------
// MENU SEPARATOR
//---------------------------------------------------------------------------------------------
function MenuSeparator()
{
  this.create       = __menusep_create;
}

function __menusep_create()
{
  var temp = "<table cellspacing='0' cellpadding='0' style='border: 1px solid white; border-top-color: buttonface;height:1px;' width='100%'><tr><td></td></tr><table>";
  return temp;
}


