
// These are the parameters to define the appearance of the menu.

var JAVAMENU_ROOT   = "/wwwSASMT_Courses/Courses/";


var MODE_DEBUG      = false;            // setting this to 'true' will turn on debug messaging when menu is reloaded
var version         = "1.1.7";          // current version
var lastActualHref  = "";               // keeps track of which link the user last klicked on
var showNumbers     = false;            // display the ordering strings: yes=true | no=false
var tocBehaviour    = new Array(1,0);   // Indicates how the menu shall change when clicking in the heading symbol (1st arg.) resp. in the heading text (2nd arg). Arg's meaning: 0 = No change, 1 = menu changes with automatic collapsing, 2 = menu changes with no automatic collapsing.
var tocLinks        = new Array(1,0);   // Indicates wether the content's location shall be changed when clicking in the heading symbol (1st arg.) resp. in the heading text (2nd arg). Arg's meaning: 1 = No, 0 = Yes. 
var nCols           = 8;                // nCols/2 indicates the maximum number of levels in the menu

// Checking the client's browser
var isIE = navigator.appName.toLowerCase().indexOf("explorer") > -1;

// Other global variables:

// oldCurrentNumber is required to keep a headings ordering string (or number) in case the menu should change (tocChange > 0) 
// but the content's location should remain unchanged (i.e. noLink == 1). In those cases the heading preceeded by oldCurrentNumber 
// has to remain hilited (otherwise the heading preceeded by currentNumber has to be hilited).
var oldCurrentNumber = "";
var oldLastVisitNumber = "";

// toDisplay: Array to keep the display status for each heading. It is initialised so only the top level headings are displayed 
// (headings preceeded by a single string without a dot):  
var toDisplay = new Array();
for (ir=0; ir<tocTab.length; ir++) {
  toDisplay[ir] = tocTab[ir][0].split(".").length==1;
}


// In accordance with the SAS Design Guidelines it is not allowed to have linked menuitems that have children.
// It is also not allowed to have menuitems open in a new window if the item is a root-item.
// If the use has disregarded/overseen this we let the him/her know about this. =P
for (ir=0; ir<tocTab.length-1; ir++)
{
  if (tocTab[ir][0].split('.').length < tocTab[ir+1][0].split('.').length && tocTab[ir][2])
    alert("Menuitem "+ tocTab[ir][0] +" (\""+ tocTab[ir][1] +"\") is a linked expanding/collapsing menuitem.\nThis is not allowed in accordance with the SAS Design Guidelines.\nPlease remove the link from your menuData.js file.");
}
for (ir=0; ir<tocTab.length-1; ir++)
{
  if (tocTab[ir][0].split('.').length <= 1 && tocTab[ir][3] == "blank")
    alert("Links that open in a new window may not be present on\nthe first level in the menu. Please remove the \"blank\" property\nfrom Menuitem "+ tocTab[ir][0] +" (\""+ tocTab[ir][1] +"\") in your menuData.js file.");
}

// ************************************************
// The function redisplays the menu and the content 
// ************************************************

function reDisplay(currentNumber, tocChange, noLink, e) {

  // Input parameters:
  // currentNumber: Hierarchical ordering string (or number) of the heading the user wants to display (we call this heading the "current"). This controls the change of both, the menu depending on the second parameter tocChange and the content's URL depending on the third parameter noLink. 
  // tocChange:     Controls how to change the menu. 0 = No change, 1 = Change with automatic collapsing of expanded headings that are not on the path to the current heading, 2 = Change wthout automatic colapsing (as use for example by Windows Explorer or Mac OS).
  // noLink:        Controls wether the content's URL shall be changed to the value given by the 3rd element of an tocTab's entry (= 0) or not (= 1).
  // e:             The event that triggered the function call. If it is set it must be the event object.

  // If there is an event that triggered the function call: Checking the control key depending on the browser used. If it is pressed and tocChange is greater than 0 tocChange is set to 2 so the menu changes without automatic collapsing: 
  if (e) {
    ctrlKeyDown = (isIE) ? e.ctrlKey : (e.modifiers==2);
    if (tocChange && ctrlKeyDown) tocChange = 2;
  }
  
    // Check if the SITE_ROOT (as defined in menuData.js) is correctly formatted (i.e. a heading but no trailing slash)
    if (SITE_ROOT.substr(0,1) != "/")
      SITE_ROOT = "/"+ SITE_ROOT;
    if (SITE_ROOT.substr(SITE_ROOT.length-1,1) == "/")
      SITE_ROOT = SITE_ROOT.slice(0,SITE_ROOT.length-1);

  // Initializing the menu window's document and displaying the title on it's top. The menu is performed by a HTML table:
  toc.document.clear();
  toc.document.write("<html>\n<head>\n\n");
  toc.document.write("<!-- JavaMenu version "+ version +" -->\n\n");
  toc.document.write("<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n");
  toc.document.write("<SCRIPT LANGUAGE=\"JavaScript\">\n");
  toc.document.write("  function makeRedText(heading) {\n");
  toc.document.write("    document.all.item(heading).style.color='#ff3300';\n");
  toc.document.write("  }\n");
  toc.document.write("  function unMakeRedText(heading) {\n");
  toc.document.write("    document.all.item(heading).style.color='#3c3c30';\n");
  toc.document.write("  }\n");
  toc.document.write("  function swapImg(oldImg, newImg) {\n");
  toc.document.write("    var tmp = document[oldImg].src;\n");
  toc.document.write("    if (tmp.search(/\_off/) != -1)\n");
  toc.document.write("      var tmp2 = tmp.replace(\/\_off\/, \"_on\");\n");
  toc.document.write("    else\n");
  toc.document.write("      var tmp2 = tmp.replace(\/\_on\/, \"_off\");\n");
  toc.document.write("    document[oldImg].src=tmp2;\n");
  toc.document.write("  }\n");
  toc.document.write("</SCRIPT>\n");
  toc.document.write("<title>menu</title>\n<link type=\"text/css\" rel=\"stylesheet\" href=\""+ JAVAMENU_ROOT +"\\style.css\">\n");
  toc.document.write("</HEAD>\n");
  toc.document.write("<body>\n");
  toc.document.write("<table style=\"position:absolute; left:15px; top:15px;\" width=202 border=0 cellspacing=0 cellpadding=0>\n");

  toc.document.writeln("<tr>");
  toc.document.writeln(" <td width=202 colspan=\"16\" background=\"images/CoursesHeader.gif\" height=\"29\"></td>");
  toc.document.writeln("</tr>");	
  	

  //currentLevel = the level of the current heading:
  var currentNumArray = currentNumber.split(".");
  var currentLevel = currentNumArray.length-1;

  // currentIndex = Current heading's index in the tocTab array:
  var currentIndex = null;
  for (i=0; i<tocTab.length; i++) {
    if (tocTab[i][0] == currentNumber) {
      currentIndex = i;
      break;
    }
  }

  // If currentNumber was not found in tocTab: No action.
  if (currentIndex == null) return false;

  // currentIsExpanded = Expand/Collaps-state of the current heading:
  if (currentIndex < tocTab.length-1) {
    nextLevel = tocTab[currentIndex+1][0].split(".").length-1;
    currentIsExpanded = nextLevel > currentLevel && toDisplay[currentIndex+1];
  } 
  else
    currentIsExpanded = false;

  // Determining the new URL and target (if given) of the current heading
  theHref = (noLink) ? "" : tocTab[currentIndex][2];
  
  // Determining the name of the item clicked
  var theLink = tocTab[currentIndex][1];
  

  // This is just to make sure se don't add the SITE_ROOT string (as defined in menuData.js)
  // to an item which isn't a link, i.e. just a collapsing/expanding menuitem, or to an external
  // link.

  if (theHref && theHref.substring(0,4) != "http")
    theHref = SITE_ROOT +"/"+ theHref;
 
  theTarget = tocTab[currentIndex][3];


  // ***********************************************************************
  // 1st loop over the tocTab entries: Determining which heading to display:
  // ***********************************************************************
  for (i=1; i<tocTab.length; i++) {
    // Nothing to do if the tocChange parameter is set to 0. If it is set to 1 or 2...
    if (tocChange) {
      thisNumber = tocTab[i][0];
      thisNumArray = thisNumber.split(".");
      thisLevel = thisNumArray.length-1;

    // This will auto-expand the menu to the last actual href the user viewed if he/she collapses the menu and expands it again
    
    if (!theHref && !currentIsExpanded)                                         // clicked item is not a link and is not expanded
      if (currentNumber != lastActualHref)                                      // clicked item is not the same as the last actual href
        if (lastActualHref.substring(0,currentNumber.length) == currentNumber)  // clicked item is a parent to the last actual href
          return reDisplay(lastActualHref.toString(),1,1,0);
          //                                           ^
          //                we just wanna redisplay the menu, not reload the page


      // isOnPath = this heading is on the path to the current heading in the menu hierarchy or a sibling of such a heading:
      isOnPath = true;

      if (thisLevel > 0) {
        for (j=0; j<thisLevel; j++) {
          isOnPath = (j>currentLevel) ? false : isOnPath && (thisNumArray[j] == currentNumArray[j]);
        }
      }

      // By the following, the headings on the path to the current heading and the siblings of such  headings (isOnPath==true, see above) will be displayed anyway. If the tocChange parameter is set to 1 no other heading will be displayed. If it is set to a number greater than 1 the headings that have been displayed before will additionally be displayed again.  
      toDisplay[i] = (tocChange == 1) ? isOnPath : (isOnPath || toDisplay[i]);

      // Now let's perform the expand/collaps mechanism: If the heading is a descendant of the current heading it's next display depends on wether the current heading was expanded or collapsed. If it was expanded the descendants have not to be displayed this time, otherwise only the childs has to be displayed but not the grandchildren, great-grandchildren etc.. Remember that currentIsExpanded says wether the current heading was expanded or not. The if-clause is a criteria for being a descendant of the current heading. If it's a descendant and thisLevel == currentLevel+1 it's a child.
      if (thisNumber.indexOf(currentNumber+".") == 0 && thisLevel > currentLevel) { 		
        if (currentIsExpanded)
          toDisplay[i] = false;
        else 
          toDisplay[i] = (thisLevel == currentLevel+1); 
      }
    } 
  } // End of loop over the tocTab

  // **********************************************************
  // 2nd loop over the tocTab entries: Displaying the headings:
  // **********************************************************
  
  for (i=0; i<tocTab.length; i++) {
    if (toDisplay[i]) {
      thisNumber = tocTab[i][0];
      thisNumArray = thisNumber.split(".");
      thisLevel = thisNumArray.length-1;
      isCurrent = (i == currentIndex);

      nextLevel = 0;
      if (i < tocTab.length-1)
      {
        nextLevel = tocTab[i+1][0].split(".").length-1;
        if (i>0)
          var previousLevel = tocTab[i-1][0].split(".").length-1;
      }
      
      var dontSwapImages = false; // swap or no-swap images on mouseover events (an active link should not swap pics...)
      var dontSwapText = false;   // swap or no-swap text-color on mouseover events (an active link should not swap text-color...)
      var thisClass = "";         // what class from the stylesheet to use for the current object
      var objectType;             // what type is the current object being processed (root/parent/child)


      // Determine what type of object the current object is
      if (thisLevel == 0)
        objectType = "root"
      else
        if (thisLevel >= nextLevel)
          objectType = "child"
        else
          objectType = "parent"
        
      
      /* Image definitions */
      
      var IMG_ROOT_NOCHILDREN_ACTIVE                = JAVAMENU_ROOT +"\\images\\icon_square_on.gif";
      var IMG_ROOT_NOCHILDREN_INACTIVE              = JAVAMENU_ROOT +"\\images\\icon_square_off.gif";

      var IMG_ROOT_NOCHILDREN_NEWWIN_ACTIVE         = JAVAMENU_ROOT +"\\images\\icon_square_on.gif";
      var IMG_ROOT_NOCHILDREN_NEWWIN_INACTIVE       = JAVAMENU_ROOT +"\\images\\icon_square_off.gif";

      var IMG_ROOT_HASCHILDREN_ACTIVE_COLLAPSED     = JAVAMENU_ROOT +"\\images\\icon_arrowright_on.gif";
      var IMG_ROOT_HASCHILDREN_INACTIVE_COLLAPSED   = JAVAMENU_ROOT +"\\images\\icon_arrowright_off.gif";

      var IMG_ROOT_HASCHILDREN_ACTIVE_EXPANDED      = JAVAMENU_ROOT +"\\images\\icon_arrowdown_on.gif";
      var IMG_ROOT_HASCHILDREN_INACTIVE_EXPANDED    = JAVAMENU_ROOT +"\\images\\icon_arrowdown_off.gif";

      var IMG_PARENT_ACTIVE_COLLAPSED               = JAVAMENU_ROOT +"\\images\\icon_arrowright_on.gif";
      var IMG_PARENT_INACTIVE_COLLAPSED             = JAVAMENU_ROOT +"\\images\\icon_arrowright_off.gif";

      var IMG_PARENT_ACTIVE_EXPANDED                = JAVAMENU_ROOT +"\\images\\icon_arrowdown_on.gif";
      var IMG_PARENT_INACTIVE_EXPANDED              = JAVAMENU_ROOT +"\\images\\icon_arrowdown_off.gif";
      
      var IMG_CHILD_ACTIVE                          = JAVAMENU_ROOT +"\\images\\icon_dot_on.gif";
      var IMG_CHILD_INACTIVE                        = JAVAMENU_ROOT +"\\images\\icon_dot_off.gif";
      
      var IMG_CHILD_NEWWIN_ACTIVE                   = JAVAMENU_ROOT +"\\images\\icon_dot_newwin_on.gif";
      var IMG_CHILD_NEWWIN_INACTIVE                 = JAVAMENU_ROOT +"\\images\\icon_dot_newwin_off.gif";
      
      
      var isHidingLastActiveLink    // is the current object collapsed around the last clicked link?
      var isLastActiveLink          // is the current object the last clicked link?
      var hasChildren               // has the current object any children?
      var isExpanded                // is the current object expanded?
      var openLinkInNewWindow       // if the current item is linked, should the link be opened in a new window?
      
      isHidingLastActiveLink = lastActualHref.substring(0,thisNumber.length) == thisNumber && !theHref;
      isLastActiveLink = lastActualHref == thisNumber && !theHref;
      hasChildren = nextLevel > thisLevel;
      isExpanded = nextLevel > thisLevel && toDisplay[i+1];
      openLinkInNewWindow = tocTab[i][2] && tocTab[i][3] == "blank";
      

      /*** ROOT OBJECTS ***/
      if (objectType == "root")
        if (hasChildren) // root has children
        {
          if (isExpanded) // root is expanded
            if (isCurrent && theHref) // root is the currently active link
            {
              imgType = IMG_ROOT_HASCHILDREN_ACTIVE_EXPANDED;
              thisClass = "ActiveMenuRoot";
            }
            else
            {
              imgType = IMG_ROOT_HASCHILDREN_INACTIVE_EXPANDED;
              thisClass = "InactiveMenuRoot";
            }
          else // root has children but is collapsed
          {
            if ((isCurrent && theHref) || isLastActiveLink)  // root is the currently active link
            {
              imgType = IMG_ROOT_HASCHILDREN_ACTIVE_COLLAPSED;
              thisClass = "ActiveMenuRoot";
            }
            else if (isHidingLastActiveLink)  // root has collapsed around the lastest active link
            {
              imgType = IMG_ROOT_HASCHILDREN_ACTIVE_COLLAPSED;
              thisClass = "InactiveMenuRoot";
            }
            else
            {
              imgType = IMG_ROOT_HASCHILDREN_INACTIVE_COLLAPSED;
              thisClass = "InactiveMenuRoot";
            }
          }
        }
        else // root without children
          if ((isCurrent && theHref) || isLastActiveLink)  //root is either the currently active link or the last active link
          {
            if (openLinkInNewWindow)  // open link in new window...
            {
              imgType = IMG_ROOT_NOCHILDREN_NEWWIN_ACTIVE;
              thisClass = "ActiveMenuRoot";
            }
            else
            {
              imgType = IMG_ROOT_NOCHILDREN_ACTIVE;
              thisClass = "ActiveMenuRoot";
            }
          }
          else  // root has no children and is not active
          {
            if (openLinkInNewWindow)  // the root's link should open in a new window...
            {
              imgType = IMG_ROOT_NOCHILDREN_NEWWIN_INACTIVE;
              thisClass = "InactiveMenuRoot";
            }
            else
            {
              imgType = IMG_ROOT_NOCHILDREN_INACTIVE;
              thisClass = "InactiveMenuRoot";
            }
          }
        
      /*** PARENT OBJECTS ***/
      /* Note that a root object with children is NOT the same as a parent object! */
      else if (objectType == "parent")
      {
        if (hasChildren)
        {
          if (isExpanded)  // parent is expanded
            if (isCurrent && theHref)  // parent is the currently active link
            {
              imgType = IMG_PARENT_ACTIVE_EXPANDED;
              thisClass = "ActiveMenuParent";
            }
            else
            {
              imgType = IMG_PARENT_INACTIVE_EXPANDED;
              thisClass = "InactiveMenuParent";            
            }
          else  // parent has children but is collapsed
            if ((isCurrent && theHref) || isLastActiveLink)  // parent is either the currently active link or the last active link
            {
              imgType = IMG_PARENT_ACTIVE_COLLAPSED;
              thisClass = "ActiveMenuParent";
            }
            else if (isHidingLastActiveLink)  // parent has collapsed around the lastest active link
            {
              imgType = IMG_PARENT_ACTIVE_COLLAPSED;
              thisClass = "InactiveMenuParent";
            }
            else
            {
              imgType = IMG_PARENT_INACTIVE_COLLAPSED;
              thisClass = "InactiveMenuParent";
            }
        }
        else  // parent without children, i.e. a child
          if (isCurrent && theHref)  // child is the currently active link
          {
            imgType = IMG_CHILD_ACTIVE;
            thisClass = "ActiveMenuChild";
          }
          else
          {
            imgType = IMG_CHILD_INACTIVE;
            thisClass = "InactiveMenuChild";
          }
      }
      /*** CHILD OBJECTS ***/
      else if (objectType == "child")
      {
        if (isCurrent || isLastActiveLink)  // child is either the currently active link or the last active link
        {
          if (openLinkInNewWindow)  // the child's link should open in a new window
          {
            imgType = IMG_CHILD_NEWWIN_ACTIVE;
            thisClass = "ActiveMenuChild"          
          }
          else
          {
            imgType = IMG_CHILD_ACTIVE;
            thisClass = "ActiveMenuChild"
          }
        }
        else  // child is not the active link
        {
          if (openLinkInNewWindow)  // the child's link should open in a new window
          {
            imgType = IMG_CHILD_NEWWIN_INACTIVE;
            thisClass = "InactiveMenuChild"
          }
          else
          {
            imgType = IMG_CHILD_INACTIVE;
            thisClass = "InactiveMenuChild"
          }
        }
      }


      // If the variable MODE_DEBUG is set to 'true' - display debug messages.
      if (MODE_DEBUG)
        alert("Properties for menuitem " + thisNumber +"\n====================" +"\nobjectType = "+ objectType +"\nthisClass = "+ thisClass +"\nhasChildren = "+ hasChildren +"\nnextLevel = "+ nextLevel +"\nthisLevel = "+ thisLevel +"\nisHidingLastActiveLink = "+ isHidingLastActiveLink +"\nisLastActiveLink = "+ isLastActiveLink +"\nisExpanded = "+ isExpanded);

      // Swap image or not? (The currently active link (or a collapsed parent/root 
      // hiding the last active link) should not swap images on mouseOver events)
      if ((isCurrent && theHref) || isHidingLastActiveLink && !isExpanded)
        dontSwapImages = true;

      // Swap text-color or not? (The currently active link should not swap text-color on mouseOver events)
      if (isLastActiveLink || isCurrent && theHref)
        dontSwapText = true;


      // Create a unique id for each image
      // Note: Internet Explorer does not like it when an image name has dots in it. 
      // So therefore we gotta replace all dots in the name with a string value (in this
      // case, the word "dot". Also note that if you leave out the "a" (can be anything really)
      // at the end it doesn't work properly. Don't ask me why, it's just one of those wierd things...
      var imgName = thisNumber.replace(/\./g, "dot") +"a";


      // Create a mouseOver/mouseOut javascript string for swapping the current image
      // as well as the message to be displayed in the statusfield of the browser...
      var winStatus = (tocTab[i][2] == null) ? winStatus = '' : winStatus = tocTab[i][2];
      
      if (dontSwapImages)
        if (dontSwapText)
          var querySwap = "onMouseOver=\"window.status='"+ winStatus +"'; return true;\" onMouseOut=\"window.status=''; return true;\"";
        else
          var querySwap = "onMouseOver=\"window.status='"+ winStatus +"'; makeRedText('link_"+ imgName +"'); return true;\" onMouseOut=\"window.status=''; unMakeRedText('link_"+ imgName +"'); return true;\"";
      else
        var querySwap = "onMouseOver=\"window.status='"+ winStatus +"'; makeRedText('link_"+ imgName +"'); swapImg('" +imgName+ "', '" +imgType+ "'); return true;\" onMouseOut=\"window.status=''; unMakeRedText('link_"+ imgName +"'); swapImg('" +imgName+ "', '" +imgType+ "'); return true;\"";


      thisLevel = thisLevel*2;
      var colspan = (nCols-thisLevel);
        
      // If the current object is a root or the last child in an expanded menu
      // where the next item is a root, we want to place a horizontal line after it
      if (i>0 && objectType == "root")
      {
        //toc.document.writeln("<tr>");
        //toc.document.writeln("  <td width=210 colspan=\""+ (nCols*2) +"\" bgcolor=\"#cccccc\" height=\"1\"></td>");
        //toc.document.writeln("</tr>");
      }


      // Now writing this menu line, i.e. a table row...:
      toc.document.writeln("<tr>");

      // ...first some empty cells for the line indent depending on the level of this heading...:
      for (k=1; k<=thisLevel; k++) {
        //if (thisLevel > 0)
          toc.document.writeln("  <td width=\"6\" background=\"images/BlankBG.gif\"><img src=\""+ JAVAMENU_ROOT +"\\images\\transparent.gif\" width=\"6\"></td>");
      }

      // ...then the heading symbol and the heading text each with a javaScript link caling just this function reDisplay again: 
       
       // Change tocBehaviour[0] to [1] if you want it to be a link instead of expanding/collapsing the menu item...
      toc.document.writeln("  <td width=\"6\" background=\"images/BlankBG.gif\"><img src=\""+ JAVAMENU_ROOT +"\\images\\transparent.gif\" width=\""+ ((thisLevel % 2 == 0 && thisLevel>0) ? 6 : 10) +"\"></td>");
      toc.document.writeln("  <td width=\"10\" background=\"images/BlankBG.gif\" align=\"right\" valign=\"baseline\"><a href=\"javaScript:history.go(0)\" "+ querySwap +" onMouseDown=\"parent.reDisplay('" + thisNumber + "'," + tocBehaviour[0] + "," + tocLinks[1] + ",event)\"><img src=\"" + imgType + "\" border=0 name=\"" +imgName+ "\"></a></td>");
      toc.document.writeln("  <td width=\"10\" background=\"images/BlankBG.gif\"><a href=\"javaScript:history.go(0)\" "+ querySwap +" onMouseDown=\"parent.reDisplay('" + thisNumber + "'," + tocBehaviour[0] + "," + tocLinks[1] + ",event)\"><img src=\""+ JAVAMENU_ROOT +"\\images\\transparent.gif\" width=\"6\" border=0></A></td>");
      toc.document.writeln("  <td width=\"100%\" class=\"clsGreyBorder\" background=\"images/BlankBG.gif\" colspan=\"" + colspan + "\"><A NAME=\"link_"+ imgName +"\" CLASS=\"" +thisClass+ "\" HREF=\"javaScript:history.go(0)\" "+ querySwap +" onMouseDown=\"parent.reDisplay('" + thisNumber + "'," + tocBehaviour[0] + "," + tocLinks[1] + ",event)\">" + ((showNumbers)?(thisNumber+" "):"&nbsp;") + tocTab[i][1] + "</A></td>");
      toc.document.writeln("</tr>");
    }

    // Place one last horizontal line after the last object
    if (i == tocTab.length-1)
    {
      toc.document.writeln("<tr>");
      toc.document.writeln("  <td width=210 colspan=\""+ (nCols*2) +"\" bgcolor=\"#cccccc\" height=\"1\"></td>");
      toc.document.writeln("</tr>");
    }

  } // End of loop over the tocTab

  // *********************************************************************************************************
  // Closing the menu document and displaying new content in the content frame or in the top window if required 
  // *********************************************************************************************************

  // Updating the global variables oldCurrentNumber and oldLastVisitNumber. See above for its definition
  if (!noLink) { 
    oldLastVisitNumber = oldCurrentNumber;
    oldCurrentNumber = currentNumber;
  }

  // Closing the menu table and the document
  toc.document.writeln("</table>\n</body></html>");
  toc.document.close();

  // Setting the top or content window's location if required
  if (theHref) 
    if (theTarget=="top") top.location.href = theHref;
    else if (theTarget=="parent") parent.location.href = theHref;
    else if (theTarget=="blank")
    {
      open(theHref,"");
      
      main.document.open();
      main.document.clear();
      main.document.write("<html>\n");
      main.document.write("<head>\n");
      main.document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\""+ JAVAMENU_ROOT +"\\style.css\">\n");
      main.document.write("</head>\n");
      main.document.write("<body>\n");
      main.document.write("<br><p class=\"H1\">"+ theLink +"</p>\n");
      main.document.write("<p>The information has been opened in a new window.</p>\n");
      main.document.write("</body>\n");
      main.document.write("</html>\n");
      main.document.close();
    }
    else if (theTarget=="_parent") location.href = theHref;
    /* So we can use mailto:'s in the menu itself... */
    else if (theHref.substr(SITE_ROOT.length+1,7) == "mailto:") open(theHref.substr(SITE_ROOT.length+1));
    else 
		{
		main.location.href = theHref;
		}
  if (theHref)
    lastActualHref = currentNumber;
}

