// JavaScript Document

var topFrames = top.document.getElementsByTagName("frame");
var calledByFrame = ( top.location.href != window.location.href );

function f_element( p_index, p_deliminator, p_string ) {
  /* 
   * JavaScript version of OpenVMS DCL F$ELEMENT lexical
   */
  var currIndex = p_string.indexOf(p_deliminator);
  var i = 0;
  var outChar = '';
  var outPoint = 0;
  var outString = p_string;
  var trackIndex = 0;

  if ( currIndex >= 0 ) {
      while ( ( trackIndex != p_index ) && ( currIndex != -1 ) ) {
        outPoint = ++currIndex;
        currIndex = p_string.indexOf(p_deliminator,outPoint);
        trackIndex++;
      } // end while ( ( trackIndex != p_index ) && ( currIndex != -1 ) )
      if ( trackIndex != p_index ) {
        outString = p_deliminator;
      } else {
        outString = '';
        for ( i=outPoint; i<p_string.length; i++ ) { 
          outChar = p_string.charAt(i);
          if ( outChar == p_deliminator ) {
            break;
          } else {
            outString = ( outString + outChar );
          } // end if ( outChar == p_deliminator )
        } // for ( i=outPoint; i<p_string.length; i++ )
      } // end if ( trackIndex != p_index )
    } else if ( p_index >= 1 )
      outString = p_deliminator;
    // end if ( currIndex >= 0 )
  
  return outString;
  } // end f_element function

/*
 * -----------------------------------------------------------------------------
 */

function spaces(pLength) {
  /* 
   * ++
   * Name: spaces
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 1-Nov-2008
   * Abstract: To return the specified number of spaces
   * Description: 
   * Parameters: pLength - the number of spaces wanted
   * History:
   *           - Created
   * --
   */
  // [ spaces Constants ]
  var lengthOfString = ( pLength == 'undefined' )
        ? 0
        : parseInt( pLength );

  // [ spaces Variables ]
  var spacesString = "";

  // [ spaces Main Line ]
  while ( spacesString.length < lengthOfString )
    spacesString += " ";

  return spacesString;
  } // end spaces function

/*
 * --------------------------------------------------------------------------------
 * addLoadEvent will execute a JavaScript command/function when a page is
 * brought up in a browser.  Ordinarily only one such command/function can be
 * performed at that time, but addLoadEvent overrides that limitation.
 * --------------------------------------------------------------------------------
 */

function addLoadEvent(func) {
// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

/*
 * --------------------------------------------------------------------------------
 */
 
function getCodeType(p_code) {
  /* 
   * ++
   * Name: getCodeType
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 23-Oct-2008
   * Abstract: To return the specified menu code as either parent, child, or 
   *           grandchild menu option type. A menu code is in either
   *           parent, parent.child, or parent.child.grandchild format.  If this
   *           value 
   *           means it is not that type
   * Requirements: JavaScript f_element function
   * Description: 
   * Parameters: p_code - a three part menu code.
   * History:
   *           - Created
   * --
   */
  // [ getCodeType Constants ]
  var child = 1;
  var dot = ".";
  var grandchild = 2;
  var parent = 0;

  // [ getCodeType Variables ]
  var childCode = f_element(1, dot, p_code);
  var codeType = -1;
  var grandchildCode = f_element(2, dot, p_code);
  var parentCode = f_element(0, dot, p_code);

  // [ getCodeType Main Line ]
  if ( grandchildCode != dot ) {
    codeType = grandchild;
    } else if ( childCode != dot ) {
      codeType = child;
      } else if ( parentCode != "" ) 
        codeType = parent;

  return codeType;
  } // end getCodeType function

/*
 * -----------------------------------------------------------------------------
 */

function navDisplayTest(p_currentPage, p_menuItem) {
  /* 
   * ++
   * Name: navDisplayTest
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 23-Oct-2008
   * Abstract: To test if option should be displayed.
   * Requirements: JavaScript f_element function
   * Description: 
   * Parameters: p_currentPage - the three part menu code of the current page.
   *             p_menuItem - the three part menu code of the option being 
                              considered.
   * History:
   *           - Created
   * --
   */
  // [ navDisplayTest Constants ]
  var dot = ".";
  var isTrue = ( 1 == 1 );

  // [ navDisplayTest Variables ]
  var child = f_element(1, dot, p_currentPage );
  var displayItem = ( p_currentPage == p_menuItem );
  var grandchild = f_element(2, dot, p_currentPage );
  var itemChild = f_element(1, dot, p_menuItem );
  var itemGrandchild = f_element(2, dot, p_menuItem );
  var itemParent = f_element(0, dot, p_menuItem );
  var parent = f_element(0, dot, p_currentPage );

  // [ navDisplayTest Main Line ]
  
  // alert("Current page: "+p_currentPage+"\nMenu item: "+p_menuItem);
  if ( !displayItem ) {
    if ( ( itemChild == dot ) && ( itemGrandchild == dot ) ) {
      // alert("Menu item: "+p_menuItem+" is parent");
      displayItem = isTrue;
      } else if ( itemGrandchild == dot ) {
        // alert("Menu item: "+p_menuItem+" is a child");
        displayItem = ( itemParent == parent );
        } else {
          // alert("Menu item: "+p_menuItem+" is a grandchild");
          displayItem = ( ( itemParent == parent ) && ( itemChild == child ) );
          }
  } else {
    // alert("Menu item: "+p_menuItem+" equals current page");
  }

  return displayItem;
  } // end navDisplayTest function
  
/*
 * -----------------------------------------------------------------------------
 */

function menuIni( ) {
  /* 
   * ++
   * Name: menuIni
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 18-Nov-2008
   * Abstract: To call the displayMenu function using values specific to the
   *           site and page.
   * Description: This function is expecting two pre-existing variables:
   *                  menuOptionArray - The array containing all the possible 
   *                                    options in a hierarchical structure.  
   *                                    See p_menuArray parameter description 
   *                                    in the displayMenu function. This was
   *                                    created in the menuIni.js file.
   *                  menuPageId - The page calling the function.  This was 
   *                               created in the page itself.
   * Parameters: 
   * History:
   *           - Created
   * --
   */  // alert('Invoking meniIni');
  displayMenu( menuOptionsArray, 'menuArea', menuPageId );
  return;
  }

/*
 * -----------------------------------------------------------------------------
 */

function displayMenu(p_menuArray, p_menuAreaId, p_currentPageId) {
  /* 
   * ++
   * Name: displayMenu
   * Author: Alvin Orzechowski, MyFirstWebPage.net
   * Creation Date: 
   * Abstract: 
   * Description: 
   * Parameters: p_menuArray - three dimensional array where each row has these
   *                           values:
   *                             menu order - a three part value that represents
   *                                          how this menu item relates to the 
   *                                          other items: 
   *                                            parent.child.grandchild
   *                                          This is the order the array should
   *                                          be in.
   *                             option - the option that will be displayed in 
   *                                      the menu.
   *                             page id - the file name to be called linked to 
   *                                       for of this option assuming that 
   *                                       ".html" is the default type.  If this 
   *                                       value matches the pageId value on the 
   *                                       current page, the link is turned off.
   *             p_menuArea - the id of the section where the menu will be
   *                          displayed
   * History:
   *           - Created
   * --
   */
  // [ displayMenu Arrays ]
  allTypes = new Array( 'Parent', 'Child', 'Grandchild' );
  allListIds = new Array();
  
  // [ displayMenu Constants ]
  var menuArea = document.getElementById(p_menuAreaId);
  var option = 1;
  var optionCode = 0;
  var optionId = 2;
  // var defaultSubmenuArrow = ' <b style="font-size: 0.75em; color: gray;">&rArr;</b>';
  var defaultSubmenuArrow = ""

  // [ displayMenu Variables ]
  var currentPageCode = "";
  var currentPageId = ( p_currentPageId != "undefined" )
        ? p_currentPageId
        : "";
  var fileName = "";
  var HTMLcode = "";
  var liTag = "";
  var nextOption = "";
  var nextOptionCode = "";
  var nextOptionId = "";
  var nextOptionLink = "";
  var optionSelectedType = -1;
  var parentMarker = "";
  var parentOfNext = false;
  var previousCode = "";
  var previousType = -1;
  var SubmenuArrow = ( typeof( window[ ' menuSubmenuArrow' ] ) != "undefined" )
        ? ( " " + window[ ' menuSubmenuArrow' ] )
        : defaultSubmenuArrow ;
  var targetWindow = ( calledByFrame )
        ? '  target="_parent"'
        : "";
  var ulId = -1;
  var ulType = -1;
  var youAreHere = false;

  // [ displayMenu Main Line ]
  // alert('Begin displayMenu: '+p_menuArray+' '+p_menuAreaId+' '+p_currentPageId);
  if ( p_currentPageId != "" ) 
    for ( j=0; j<p_menuArray.length; j++ ) {
      if ( p_currentPageId == f_element(0, ".", p_menuArray[j][optionId]) ) {
        currentPageCode = p_menuArray[j][optionCode];
        j = p_menuArray.length;
        }
    }

  for ( j=0; j<p_menuArray.length; j++ ) {
    nextOption = p_menuArray[j][option];
    nextOptionCode = p_menuArray[j][optionCode];
    nextOptionId = p_menuArray[j][optionId];
    nextOptionType = getCodeType(nextOptionCode);
    YouAreHere = ( p_currentPageId == f_element(0, ".", nextOptionId ) );
    if ( ( j + 1 ) == p_menuArray.length )
      parentOfNext = false;
      else 
	    parentOfNext = ( nextOptionType < getCodeType(p_menuArray[j+1][optionCode]) );
	parentMarker = ( parentOfNext ) ? ( SubmenuArrow ) : "";

    
    if ( YouAreHere ) {
      nextOptionLink = ( '<a href="#" class="uAreHere" title="You are here">' + nextOption + parentMarker + '</a>' );
      
      } else {
        fileName = ( f_element(1, ".", nextOptionId ) == "." ) 
          ? ( nextOptionId + '.html' )
          : nextOptionId;
        if ( nextOption == 'Home' )
          fileName = homePage
        nextOptionLink = ( '<a href="' + fileName + '"' + targetWindow + '>' + nextOption + parentMarker + '</a>' );
        }
      
    if ( navDisplayTest(currentPageCode, nextOptionCode) ) {
      // alert("Good option: "+nextOption+" ("+nextOptionCode+")");
      previousType = getCodeType(previousCode);
          
      if ( nextOptionType > previousType ) {
        // alert("New unordered list");
        ulType++;
        ulId++
        allListIds[ulId] = String( ulId + 1 );
        while ( allListIds[ulId].length <= 1 )
          allListIds[ulId] = ( '0' + allListIds[ulId] );
        allListIds[ulId] = ( "menuList" + allListIds[ulId] );
        if ( ulType >= 1 )
          HTMLcode += "\n";
        
        HTMLcode += ( '<ul id="' + allListIds[ulId] + '" class="nav' + allTypes[ulType] + '">' + "\n" );
            
        } else if ( nextOptionType < previousType ) {
          while ( ulType > nextOptionType ) {
            // alert("Close unordered list");
            HTMLcode += "</li>\n</ul>\n</li>\n";
            ulType--;
        }
                
          } else
            HTMLcode += "</li>\n";
            
      liTag = ('<li class="nav' + allTypes[nextOptionType] + '">' )
      HTMLcode += ( liTag + spaces(ulType*2) + nextOptionLink );
      previousCode = nextOptionCode;
      }
    }
  while ( ulType >= 1 ) {
    HTMLcode += "</li>\n</ul>\n</li>\n";
    ulType--;
    }
  HTMLcode += "</li>\n</ul>";
  menuArea.innerHTML=HTMLcode;
  /*
  for ( j=0; j<allListIds.length; j++ )
	document.getElementById(allListIds[j]).style.display = 'inline';
	*/
  return;
  } // end displayMenu function

/*
 * -----------------------------------------------------------------------------
 */