function initMenu() {
  var topMenuBar = document.getElementById('topMenuBarId');
  for (var i = 0 ; i < topMenuBar.childNodes.length ; i ++) {
    if (topMenuBar.childNodes[i].className == "topMenu") {
      addEvent(topMenuBar.childNodes[i], 'mouseover', show);
      addEvent(topMenuBar.childNodes[i], 'mouseout', hide);
    }
  }
}

function addEvent(target, eventName, functionName) {
  // For IE
  eval('target.on'+eventName+'=functionName');
  // For DOM compliant browsers
  try {
    target.addEventListener(eventName, functionName, true); // true important for Opera7
  } catch (e) {
  }
}

function show() {
  for (var i = 0 ; i < this.childNodes.length ; i ++) {
    if (this.childNodes[i].className == "topSubMenu") {
      this.childNodes[i].style.visibility = "visible";
      this.childNodes[i].style.display = "block";
    }
  }
  return true;
}

function hide() {
  for (var i = 0 ; i < this.childNodes.length ; i ++) {
    if (this.childNodes[i].className == "topSubMenu") {
      this.childNodes[i].style.visibility = "hidden";
      this.childNodes[i].style.display = "none";
    }
  }
  return true;
}

function showImage(imageDir, scriptNbr, width, height) {
    var windowWidth = width + 20;
    var windowHeight = height + 100;
    var scX = Math.floor((window.screen.width - windowWidth) / 2);
    var scY = Math.floor((window.screen.height - windowHeight) / 2);
    var myWindow = window.open("", "w" + scriptNbr, "toolbar=no,menubar=no,location=no,status=no,scrollbars=yes,width=" + windowWidth + ",screenX=" + scX + ",screenY=" + scY + ",height=" + windowHeight);
    var request = new XMLHttpRequest();
    var url = "/" + imageDir + "/g" + scriptNbr + ".txt";
    request.open("GET", url, false);
    request.send(null);

    myWindow.document.open();
    myWindow.document.writeln("<html><body bgcolor='white'>");
    myWindow.document.writeln("<p><center><a href='javascript:void(0)' onclick='window.close()'>Close</a></center></p>");
    myWindow.document.writeln("<p><center><img src='/" + imageDir + "/graph" + scriptNbr + ".png'></center></p>");

    myWindow.document.writeln("<pre>");
    myWindow.document.writeln(request.responseText);
    myWindow.document.writeln("</pre>");
    myWindow.document.writeln("</body></html>");
    myWindow.document.close();
}

