﻿// Morten's JavaScript Tree Menu Tracking Script
// version 2.3.2-macfriendly, dated 2002-06-10
// http://www.treemenu.com/
// Copyright (c) 2001-2002, Morten Wang & contributors
// All rights reserved.

// This software is released under the BSD License which should accompany
// it in the file "COPYING".  If you do not have this file you can access
// the license through the WWW at http://www.treemenu.com/license.txt

//sm- mtmtrack() is called at least twice during page loading
// 1st at the end of the html page (page loaded, but not images, css etc)
// and again in the window onload() (after all images etc also loaded).
// If it runs successfully the first time the second time the call is ignored.
//var mtmtrack_done = false;
var mtmtrack_codeWindow = false;

function mtmtrack() {
  //if (mtmtrack_done) return; //already done
 if (mtmtrack_codeWindow) return; //already done
 if ((navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3 && navigator.userAgent.indexOf("Opera") == -1) || (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4) || (navigator.appName == "Opera" && parseInt(navigator.appVersion) >= 5)) {
    if (parent) {
      if (parent.isMainPage === true){
        mtmtrack_codeWindow = parent
      } else {
        var MTMCodeFrame = "trvHeader";
        for (var i = 0; i < parent.frames.length; i++) {
          if (parent.frames[i].name == MTMCodeFrame && parent.frames[i].MTMLoaded) {
            mtmtrack_codeWindow = parent.frames[i]
          }
        }
      }  
      setTimeout("mtmtrack_delayed()", 100);
      //mtmtrack_done = true;

    }
  }
}

function mtmtrack_delayed() {
  mtmtrack_codeWindow.MTMTrack = true;
  var menuitemId = mtmtrack_codeWindow.MTMDisplayMenu()
  setTimeout("mtmtrack_onclick('sub" + menuitemId + "')", 200)
  //mtmtrack_onclick("sub" + menuitemId, frameRef)
}

function mtmtrack_onclick(itemId) {
  //sm 2010 - run menuitem onclick function to open sub menus
  var menuitem = parent.trvMenu.document.getElementById(itemId)
  if (menuitem && menuitem.onclick) {
    var func = menuitem.onclick
    func(null)
    //redraw menu
    mtmtrack_codeWindow.MTMTrack = true;
    mtmtrack_codeWindow.MTMDisplayMenu() 
  }
}
