  // JavaScript Document

var browser = navigator.userAgent.toLowerCase();
var browserIE = ( browser.indexOf("msie") != -1 );
var browserFirefox = ( browser.indexOf("firefox") != -1 );
if ( browserFirefox )
{
    document.write('<style type="text/css" media="print">'); 
    document.write('div#footer a { margin-left: -0.5em; padding-left: 0; }'); 
    document.write('b { margin-left: -0.5em; padding-left: 0; }</style>'); 
    document.write('</style>'); 
}

var HTMLcode = "";
var homePageTitle = 'WordsThatEndure.com';

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 replace(p_string,p_text,p_by) {
// Replaces p_text with p_by in p_string
// From:  http://tech.irt.org/articles/js037/
    var strLength = p_string.length, txtLength = p_text.length;
    if ((strLength == 0) || (txtLength == 0)) return p_string;

    var i = p_string.indexOf(p_text);
    if ((!i) && (p_text != p_string.substring(0,txtLength))) return p_string;
    if (i == -1) return p_string;

    var newstr = p_string.substring(0,i) + p_by;

    if (i+txtLength < strLength)
        newstr += replace(p_string.substring(i+txtLength,strLength),p_text,p_by);

    return newstr;
}  // end replace 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();
        }
    }
}

/*
 * --------------------------------------------------------------------------------
 * The following function creates the site menu
 * --------------------------------------------------------------------------------
 */

function displayMenu() {
 /* 
 * ++
 * Name: displayMenu
 * Author: Alvin Orzechowski, MyFirstWebPage.net
 * Creation Date: 31-Oct-2010
 * Abstract: To create the ul list from the menuOptions array and insert it in
 *           the menuArea div of the calling page
 * Description: 
 * Parameters: None
 * History:
 * - Created
 * --
 */
 // [ displayMenu Functions ]
  function closeLI( pCurrentMenu, pPreviousMenu ) {
    var closeListItem = ( pCurrentMenu > pPreviousMenu )
                      ? '\n<ul>'
                      : ( pCurrentMenu < pPreviousMenu )
                          ? '</li>\n</ul></li>\n'
                          : '</li>\n';
    return closeListItem;
    } // end function closeLI
    
  function hrefValue( pID ) {
	var hrefString = ( pID == 'index' )
	                   ? homePage
	                   : ( pID + '.html' );
	return hrefString;
    } // end function hrefValue
    
  function displayOption( pFirstOption, pMenuOption, pSubmenuNext ) {
    var aAttributes = ( pMenuOption.ID == PgID )
                        ? 'class="URHere" title="You are here"'
                        : ( 'href="' + hrefValue(pMenuOption.ID) + '"'
                            + browserWindow 
                            + ' title="View the ' + pMenuOption.menuItem + ' page"' );

    var arrow = ( pSubmenuNext )
                  ? ( '<span class="optionArrow">&nbsp;&nbsp;' + arrowChar + '</span>' )
                  : '';

    var endListItem = ( pFirstOption )
                        ? ''
                        : closeLI( pMenuOption.level, previousLevel );
    var aSource = ( pMenuOption.menuItem + arrow );

    HTMLcode += ( endListItem + '<li><a ' +  aAttributes + '>' + aSource + '</a>' );
    return pMenuOption.level;
    } // end function displayOption
    
 // [ displayMenu Constants ]
  var arrowChar = ( browserIE )
                    ? '<img src="images/arrow-right.gif" border="0"/>'
                    : '&#9658;';
  var menuArea = document.getElementById('menuArea');
  var browserWindow = ( calledByFrame )
                        ? ' target="_parent"'
			                  : "";
                        
 // [ displayMenu Variables ]
  var HTMLcode = '\n<ul id="nav">\n';
  var j = 0;
  var previousLevel = 0;
  var submenuNext = ( 1 == 2 );
  
 // [ displayMenu Main Line ]
  for ( var i in menuOptions ) {
    j = ( parseInt(i) + 1 );
    submenuNext = ( j < menuOptions.length )
                    ? ( menuOptions[i].level < menuOptions[j].level )
                    : ( 1 == 2 );
    previousLevel = displayOption( ( i == 0 ), menuOptions[i], submenuNext );
    }
  HTMLcode += closeLI( 0, previousLevel );
  HTMLcode +=  ('</ul>\n');
  menuArea.innerHTML = HTMLcode;
  return;
} // end function displayMenu

/*
 * --------------------------------------------------------------------------------
 */

function homePageLink() {
 /* 
 * ++
 * Name: homePageLink
 * Author: Alvin Orzechowski, MyFirstWebPage.net
 * Creation Date: 20-Jan-2010
 * Abstract: To properly link to the homePage
 * Description: 
 * Parameters: None
 * History:
 * - Created
 * --
 */
 // [ homePageLink Main Line ]
 
 if ( calledByFrame )
   document.write('<a href="'+homePage+'" target="_parent" title="' + homePageTitle + '">') 
   else 
     document.write('<a href="'+homePage+'"  title="' + homePageTitle + '">');
    
 return;
 } // end homePageLink function

/*
 * --------------------------------------------------------------------------------
 */


function getPassedValue(p_id, p_fromParent) {
  /* 
   * +++
   *
   * Function Name: getPassedValue
   *        Author: Alvin Orzechowski MyFirstWebPage.net
   * Creation Date: 15-Aug-2004
   *      Abstract: To return the passed value or the specified portion of it
   *   Description: 
   *    Parameters: p_id - Value found to the left of an equal sign.  If this is
   *                       found, this function will return the value found to 
   *                       the right of the equal sign.  If this parameter is 
   *                       not provided, this function will return the whole 
   *                       value passed.
   *                p_fromParent - Look for passed value in parent window.  
   *                               Only checked when calledByFrame variable is
   *                               true.  One of two values is expected:
   *                                  yes - Look for passed value in parent 
   *                                        window
   *                                  no - Look for passed value in current
   *                                       window (default)
   *                               This is useful for a frame where a parameter 
   *                               might be passed from the parent window.
   *                               
   *
   *       History: 20-Jan-2010 - p_fromParent added
   * 
   * ---
   */

  // [ getPassedValue Constants ]
  var fromParent = ( p_fromParent != null )
                   ? ( calledByFrame )
                     ? p_fromParent
                     : "no"
                   : "no";
  var passedValue = ( fromParent == "yes" )
                    ? unescape(f_element( 1, "?", window.parent.location.href ))
                    : unescape(location.search.substring(1));

  // [ getPassedValue Variables ]
  var allSubValues = ( fromParent == "yes" )
                     ? f_element( 1, "?", window.parent.location.href ).split('&')
                     : location.search.substring(1,location.search.length).split('&');
  var idValue = ( passedValue == '?' )
                ? ""
                : passedValue;
  var subValue = "";

  // [ getPassedValue Main Line ]
  for (var i=0; i<allSubValues.length; i++) {
    subValue = allSubValues[i].split('=');
    if ( subValue[0] == p_id ) {
      idValue = unescape(subValue[1]);
      i = allSubValues.length;
    } // end if ( subValue[0] == p_id )  
  } // end for (i=0; i<allSubValues.length; i++)

  // [ getPassedValue End of Job ]
  return idValue;

} // end getPassedValue function

/*
 * --------------------------------------------------------------------------------
 */

function include_rpc(script_filename, p1) {
  /* 
   * +++
   *
   * Function Name: include_rpc
   *        Author: Stoyan Stefanov, phpied.com (original)
   *                Alvin Orzechowski, MyFirstWebPage.net (modifications)
   * Creation Date: 20-Mar-2007
   *      Abstract: To call and execute a server script
   *   Description: 
   *    Parameters: script_filename - the name of the script to be called 
   *                                  (required)
   *                p1 - value to be passed (optional)
   *       History: 
   * 
   * ---
   */

  // [ include_rpc Constants ]
  var html_doc = document.getElementsByTagName('head').item(0);
  var js = document.createElement('script');
  
  // [ include_rpc Main Line ]
  if ( p1 != null )
      script_filename += ( '?' + p1 );
  js.setAttribute('language', 'javascript');
  js.setAttribute('type', 'text/javascript');
  js.setAttribute('src', script_filename);
  html_doc.appendChild(js);
  return;
} // end include_rpc function

/*
 * --------------------------------------------------------------------------------
 */

function homePageLink() {
 /* 
 * ++
 * Name: homePageLink
 * Author: Alvin Orzechowski, MyFirstWebPage.net
 * Creation Date: 20-Jan-2010
 * Abstract: To properly link to the homePage
 * Description: 
 * Parameters: None
 * History:
 * - Created
 * --
 */
 // [ homePageLink Main Line ]
 
 if ( calledByFrame )
   document.write('<a href="'+homePage+'" target="_parent" title="' + homePageTitle + '">') 
   else 
     document.write('<a href="'+homePage+'"  title="' + homePageTitle + '">');
    
 return;
 } // end homePageLink function

/*
 * --------------------------------------------------------------------------------
 */

function addMenuOption(p_level, p_ID, p_menuItem, p_Mode) {
 /* 
 * ++
 * Name: addMenuOption
 * Author: Alvin Orzechowski, MyFirstWebPage.net
 * Creation Date: 8-Aug-2010
 * Abstract: To insert or append a new option in the menuOptions array.
 * Description: 
 * Parameters: 
 * History:
 * - Created
 * --
 */
 // [ addMenuOption constants ]
 var addMode = ( typeof p_Mode == 'undefined' )
                    ? 'insert'
                    : ( p_Mode != 'append' )
                        ? 'insert'
                        : p_Mode;
 
 // [ addMenuOption Main Line ]
 nextOption = menuOptions.length;
 if ( addMode == 'insert' ) {
   menuOptions[nextOption] = new optionSpecs( menuOptions[nextOption-1].level, menuOptions[nextOption-1].ID, menuOptions[nextOption-1].menuItem );
   menuOptions[nextOption-1] = new optionSpecs( p_level, p_ID, p_menuItem );
   } else
     menuOptions[nextOption] = new optionSpecs( p_level, p_ID, p_menuItem );

 return;
 } // end addMenuOption function
 
/*
 * --------------------------------------------------------------------------------
 * MyFirstWebPage.net specific functions
 * Leave this section at the end
 * --------------------------------------------------------------------------------
 */

function get_mfwpnLogo(pTM) {
  var mfwpnLogo = '<span class="MFWPNlogo">' +
  '<span style="color: #000000;">My</span>' +
  '<span style="color: #ff0000;">First</span>' +
  '<span style="color: #00ff00;">Web</span>' +
  '<span style="color: #0000ff;">Page</span>' +
  '<span style="color: #000000;">.net';

  if ( pTM == 'tm' )
    mfwpnLogo = ( mfwpnLogo + '&#153;' );
  mfwpnLogo = ( mfwpnLogo + '</span></span>' );

return mfwpnLogo;
} // end get_mfwpnLogo function
