function openImgWindow(siteURL,width,height) {
	var opts = "scrollbars=no,resizeable=yes,width=" + width + ",height=" + height + ",top=10,left=10"
	window.open(siteURL, "imgwindow", opts);
}

var axel	 = Math.random() + "";
var ord		 = axel * 1000000000000000000 + "?";

//This part of script alleviates a Netscape document.write bug
NS4 = document.layers;
if (NS4) {
	origWidth = innerWidth;
        origHeight = innerHeight;
}
function reDo() {
	if (innerWidth != origWidth || innerHeight != origHeight)
	location.reload();
}
if (NS4) onresize = reDo;

n =0;
ie=0;
if (document.all)
{
  n=0;
  ie=1;
  fShow="visible";
  fHide="hidden";
  styleClass="clsMenuItemIE";
  menuSubItemStyleClass="clsSubMenuItemIE";
  menuHeaderStyleClass="clsMenuHeaderStyleIE";
}
else if (document.layers)
{
  n=1;
  ie=0;
  fShow="show";
  fHide="hide";
  styleClass="clsMenuItemNS";
  menuSubItemStyleClass="clsSubMenuItemNS";
  menuHeaderStyleClass="clsMenuHeaderStyleNS";
}

function ttnbRefreshMenuStructure()
{
  if (n) // for Netscape only
  {
    var menubarIndex = 1;
    for (index=0;index < top.document.layers.length;index++) {
      if (top.document.layers[index].id.indexOf("submenu") != -1) {
	  layerHTMLstring = "";
	  layerHTMLstring += "<table border="+menubar.subMenuPaneBorder+" bgcolor="+menubar.bgColor+" cellspacing=0 cellpadding=0>\n";

	  for (itemIndex=0;itemIndex < top.document.layers[index].document.links.length;itemIndex++) {
	      /* Now rewrite the layer using our stored text. */
          layerHTMLstring += "<tr><td><a class="+menuSubItemStyleClass+" title='' href='";
          layerHTMLstring += menubar.subMenuLayerDataArray[menubarIndex][itemIndex].location;
          layerHTMLstring += "'>";
          layerHTMLstring += menubar.subMenuLayerDataArray[menubarIndex][itemIndex].text;
          layerHTMLstring += "&nbsp;</a></td></tr>\n";
		}
        layerHTMLstring += "</table>\n";
        top.document.layers[index].document.open();
        top.document.layers[index].document.write(layerHTMLstring);
        top.document.layers[index].document.close();
        top.document.layers[index].onMouseOver = setCurMenuVisible2;
	top.document.layers[index].onMouseOut = setCurMenuInvisible;
        top.document.layers[index].document.linkColor = "#FFFFFF";
        top.document.layers[index].document.vlinkColor = "#87AFBF";
        top.document.layers[index].document.alinkColor = "#87AFBF";
        top.document.layers[index].document.hlinkColor = "#87AFBF";
		menubarIndex++;
	  }
      if (top.document.layers[index].id.indexOf("menuheader") != -1) {
		top.document.layers[index].visibility = fShow;
	  }
	}
  }
}

function MenuLayerData()
{
  // no code needed
}

function addItem(idItem, text, location, altLocation)
{
  var Lookup = "<!-- ITEM "+idItem+" -->";
  if (HTMLstr.indexOf(Lookup) != -1)
  {
    alert(idItem + " already exist");
    return;
  }

  var MENUitem = "\n<!-- ITEM "+idItem+" -->\n";
  /* New code that calculates the width of each menu heading individually depending on heading text. */
  this.menuHeaderPaneWidth = (text.length + 2) * this.menuHeaderPaneWidthFactor;

  /* This is a more robust way of making sure that menubar headers don't wrap onto a second line. */
  /* But take it out again because it causes other problems. */
  //text = text.replace(" ", "&nbsp;");

  if (n)
  {
    var index = this.subMenuLayerDataArray.length;
    this.subMenuLayerDataArray[index] = new Array();
    this.menuHeaderLayerDataArray[idItem] = new MenuLayerData();
    this.menuHeaderLayerDataArray[idItem].location = location;

//    MENUitem += "<td width="+this.menuHeaderPaneWidth+" height="+this.subMenuPaneHeight+">\n";
//    MENUitem += "<ilayer name="+idItem+"menuheader" + " width="+this.menuHeaderPaneWidth+" visibility=hide>";

    MENUitem += "<td height=22>\n<ilayer height=22 name="+idItem+"menuheader visibility=hide>";
    MENUitem += "<a title='" + text + "' href='"+location+"' class="+menuHeaderStyleClass;
    MENUitem += " onMouseOver='displaySubMenu(";
    MENUitem += '"';
    MENUitem += idItem;
    MENUitem += '"';
    MENUitem += ")' onMouseOut='setCurMenuInvisible2();' onclick='return true;'>";
    MENUitem += text;
    MENUitem += "</a>";
    MENUitem += "</ilayer>";
    MENUitem += "</td>\n";
  }
  else if (ie)
  {
    MENUitem += "<td>\n";
	/* the menuHeaderStyle on the DIV seems to affect vertical positioning of the header menubar text? */
//  MENUitem += "<div width="+this.menuHeaderPaneWidth+" id='"+idItem+"' style='position:relative; "+this.menuHeaderStyle+"' "
    MENUitem += "<div id='"+idItem+"' style='position:relative; "+this.menuHeaderStyle+"' "
    MENUitem += 'onMouseOver="';
    MENUitem += "displaySubMenu('"+idItem+"')";
    MENUitem += '" ';
    MENUitem += "onMouseOut='setCurMenuInvisible();'>\n";
//  MENUitem += "<a class="+menuHeaderStyleClass+" title='"+text+"'";
    MENUitem += "<a class="+menuHeaderStyleClass+" title=''";
    if (location != null)
    {
      MENUitem += "href='"+location+"' onClick='hideCurrentMenu()'";
    }
    else
    {
      if (altLocation != null)
      {
        MENUitem += "href='"+altLocation+"' ";
      }
      else
      {
        MENUitem += "href='.' ";
      }
      MENUitem += "onClick='return false;'"
    }
    MENUitem += ">";
    MENUitem += text;
    MENUitem += "</a>\n";
    MENUitem += "</div>\n";
    MENUitem += "</td>\n";
  }

  MENUitem += "<!-- END OF ITEM "+idItem+" -->\n";
  MENUitem += "<!-- MAIN_MENU -->\n";

  HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);

}

function addSubItem(idParent, text, location)
{
  var MENUitem = "";
  Lookup = "<!-- ITEM "+idParent+" -->";
  if (HTMLstr.indexOf(Lookup) == -1)
  {
    alert(idParent + " not found");
    return;
  }
  Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
  if (HTMLstr.indexOf(Lookup) == -1)
  {
    MENUitem += "\n";
    if (n)
    {
      MENUitem += "<layer id='"+idParent+"submenu' visibility=hide border=1 bgcolor='"+this.bgColor;
      MENUitem += " onMouseOut='setCurMenuInvisible();' onMouseOver='setCurMenuVisible2();'>\n";
      MENUitem += "<table border=0 bgcolor="+this.bgColor+" cellspacing=0 cellpadding=0>\n";
      MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
      MENUitem += "</table>\n";
      MENUitem += "</layer>\n";
    }
    if (ie)
    {
      MENUitem += "<span bgcolor=black id='"+idParent+"submenu' onMouseOut='setCurMenuInvisible();'";
      MENUitem += " onMouseOver='setCurMenuVisible();'";
      MENUitem += " style='background-color:"+this.bgColor+"; position:absolute; border-width: thin; border-style: outset; visibility: hidden '>\n";
      MENUitem += "<table border="+this.subMenuPaneBorder+" bgcolor="+this.bgColor+" cellspacing=0 cellpadding=1>\n";
      MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
      MENUitem += "</table>\n";
      MENUitem += "</span>\n";
    }
    MENUitem += "\n";
    MENUitem += "<!-- SUB_MENU -->\n";
    HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
  }

  if (n)
  {
      var currentMenuIndex = this.subMenuLayerDataArray.length - 1;
      var index = this.subMenuLayerDataArray[currentMenuIndex].length;
      this.subMenuLayerDataArray[currentMenuIndex][index] = new MenuLayerData();
      this.subMenuLayerDataArray[currentMenuIndex][index].text = text;
      this.subMenuLayerDataArray[currentMenuIndex][index].location = location;
  }
  MENUitem = "<tr><td width=5>&nbsp;</td><td><a class="+menuSubItemStyleClass+" title='' href='"+location+"'><font class=menubold>"+text+"&nbsp;</font></a></td><td width=5>&nbsp;</td></tr>\n";
  //MENUitem = "<tr><td><a style="+menuSubItemStyle+" title='' href='"+location+"'><font class=menubold>"+text+"&nbsp;</font></a></td></tr>\n";
  //MENUitem = "<tr><td><a class="+menuSubItemStyleClass+" title='"+text+"' href='"+location+"'><font class=menubold>"+text+"&nbsp;</font></a></td></tr>\n";
  MENUitem += Lookup;
  HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}

function showMenuBar()
{
  document.writeln(HTMLstr);
}

function MenuBar()
{
   this.bgColor = "#990000";
  if (ie)
  {
    /* style (as well as styleClass) needed for IE DIV */
    this.menuHeaderStyle = "font: bold 7pt Verdana, Arial, Helvetica; color: white; text-decoration: none;";
    //this.subMenuPaneWidth = subMenuPaneWidth;
    this.menuHeaderPaneWidthFactor = 0; // 15
    this.subMenuPaneHeight = 22;
    this.menuHeaderIndent = 0;
    this.rightmargin = 0;
  }
  else if (n)
  {
    this.subMenuLayerDataArray = new Array();
    this.menuHeaderLayerDataArray = new Array();

    this.menuHeaderStyle = "font: bold 8pt Verdana, Arial, Helvetica; color: white; text-decoration: none;";
    //this.subMenuPaneWidth = subMenuPaneWidth - 9;
    this.menuHeaderPaneWidthFactor = 0;  // 6
    this.subMenuPaneHeight = 22;
    this.menuHeaderIndent = 0;
    this.rightMargin = 0;
  }
  this.mainPaneBorder = 0;
  this.subMenuPaneBorder = 0;

  this.addItem    = addItem;
  this.addSubItem = addSubItem;
  this.showMenuBar   = showMenuBar;

  lastMenu = null;
  lastMenuHeading = null;

  HTMLstr = "<!-- MENU PANE DECLARATION BEGINS -->\n";
  HTMLstr += "\n";
  HTMLstr += "<table width=760 cellpadding=0 cellspacing=0 border="+this.mainPaneBorder+">\n";
  HTMLstr += "<tr>";
  HTMLstr += "<!-- MAIN MENU STARTS -->\n";
  HTMLstr += "<!-- MAIN_MENU -->\n";
  HTMLstr += "<!-- MAIN MENU ENDS -->\n";
  HTMLstr += "</tr>\n";
  HTMLstr += "</table>\n";
  HTMLstr += "<!-- SUB MENU STARTS -->\n";
  HTMLstr += "<!-- SUB_MENU -->\n";
  HTMLstr += "<!-- SUB MENU ENDS -->\n";
  HTMLstr += "\n";
  HTMLstr += "<!-- MENU PANE DECLARATION ENDS -->\n";
}

function displaySubMenu(idMainMenu)
{
  var menu;
  var submenu;
  //alert(eval("nav" + idMainMenu));

  if (n)
  {
    idMainMenuLayerName = idMainMenu + "menuheader";
    menu = document.layers[idMainMenuLayerName];

     if (document.layers[idMainMenu+"submenu"] != null)
    {
      submenu = document.layers[idMainMenu+"submenu"];
      if (lastMenu != null && lastMenu != submenu) hideCurrentMenu();

      submenu.left = document.layers[idMainMenuLayerName].pageX + 3;
      submenu.top  = document.layers[idMainMenuLayerName].pageY +
      document.layers[idMainMenuLayerName].clip.height;
		if (eval("nav" + idMainMenu)) {
      		submenu.visibility = fShow;
		}

      submenu.onMouseOut=hideCurrentMenu;
    } else
    {
      if (lastMenu != null) hideCurrentMenu();
    }
  }
  else if (ie)
  {
     if (document.all.item(idMainMenu+"submenu") != null)
    {
      menu = eval(idMainMenu);
      submenu = eval(idMainMenu+"submenu.style");

      var totalOffset = 0;
      var item = menu;
      do
      {
        totalOffset += eval('item.offsetLeft');
        item = eval('item.offsetParent');
      } while (item != null);
      submenu.left = totalOffset+3;

      submenu.top  = menu.style.top;
	  if (eval("nav" + idMainMenu)) {
      		submenu.visibility = fShow;
		}

    }

    if (lastMenu != null && lastMenu != submenu)
    {
      hideCurrentMenu();
    }

  }

  setCurMenuVisible();
  lastMenu = submenu;
  lastMenuHeading = menu;

}

function hideCurrentMenu()
{
  if (lastMenu != null)
  {
    lastMenu.visibility = fHide;
    lastMenu = null;
    lastMenuHeading = null;
  }
}

var timeOutID = null;
function setCurMenuVisible()
{
   if (timeOutID)
  {
    clearTimeout(timeOutID);
    timeOutID = null;
  }
}

function setCurMenuVisible2()
{
   if (timeOutID)
  {
    clearTimeout(timeOutID);
    timeOutID = null;
  }

  /* This timeout when executed should clear out any hide timeout set by leaving the menu bar. (?) */
  timeOutID = setTimeout("setCurMenuVisible()", 300)

}

function setCurMenuInvisible()
{
   if (ie ||
         (n && lastMenuHeading && lastMenu &&
          lastMenuHeading.name+"submenu" != lastMenu.name))
  {
    timeOutID = setTimeout("hideCurrentMenu()", 500)  }
}

function setCurMenuInvisible2()
{
   if (n)
  {
    timeOutID = setTimeout("hideCurrentMenu()", 500)
  }
}
