//------------------------------------------------------------
//
// Living Internet Source Code, Version 2006-01-01
// Copyright (c) 1999-2006 William Stewart
//
// The Living Internet source code is free software; you can redistribute
// it and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA
//
// Documentation, a copy of the GNU GPL license, and additional information
// about this software can be obtained at LivingInternet.com/tsourcecode.htm
//
//------------------------------------------------------------
//
// Global variables:
//
//   chapters_index:  String of single letter designators for chapters
//   current_page:  The index of the current page in "page_list"
//   page_list:  List of pages of the site
//   page_list_length:  Number of entries in "page_list"

// Misc storage variables

var s1, s2 ;
var i, j, k, m ;

// page_list is the list of pages used by the Previous and Next
// functions to determine the next and previous page.
// This is the only code update needed to add or delete a page from
// the site: add it to the proper spot in the list, or delete it.
// Note that if you don't add a page to this list, it can still be visited
// from a link, and the ^Up and Contents functions still work as normal.

var page_list = new Array(
"/","i","ii","ii_summary","ii_bush","ii_wiener","ii_sage","ii_ai","ii_darpa","ii_licklider","ii_mcluhan","ii_rand","ii_npl","ii_ipto","ii_kleinrock","ii_roberts","ii_imp","ii_arpanet","ii_ncp","ii_kahn","ii_cerf","ii_tcpip","ii_csnet","ii_nsfnet","ii_eunet","iw","iw_mgmt","iw_mgmt_isoc","iw_mgmt_iab","iw_mgmt_ietf","iw_mgmt_irtf","iw_mgmt_icann","iw_mgmt_iana","iw_mgmt_netsol","iw_mgmt_reg","iw_mgmt_nsf","iw_arch","iw_ip","iw_dns","iw_dns_history","iw_dns_name","iw_dns_dns","iw_dns_alias","iw_dns_info","iw_packet","iw_packet_inv","iw_packet_packet","iw_packet_switch","iw_route","iw_route_arch","iw_route_igp","iw_route_igp_rip","iw_route_igp_ospf","iw_route_igp_igrp","iw_route_egp","iw_route_egp_bgp","iw_route_egp_egp","iw_unix","iw_unix_dev","iw_unix_c","iw_unix_war","iw_unix_gnulinux","iw_unix_more","iw_ethernet","iu","ia","ia_nq","ia_nq_basics","ia_nq_send","ia_nq_reply","ia_nq_conf","ia_nq_info","ia_rfc","ia_rfc_invent","ia_rfc_use","ia_rfc_net","ia_rfc_iops","ia_rfc_fun","ia_rfc_interesting","ia_rfc_email","ia_rfc_ref","ia_tools","ia_tools_top","ia_tools_whois","ia_tools_ping","ia_tools_tracroute","ia_tools_nslookup","ia_tools_stats","ia_text","ia_text_emph","ia_text_emot","ia_text_abbr","ia_text_act","ia_text_desc","ia_myths","ia_myths_coke","ia_myths_tax","ia_myths_toast","ia_myths_cookie","ia_myths_craig","ia_myths_jessica","ia_myths_cruise","ia_hackers","ia_hackers_stallman","ia_hackers_draper","ia_hackers_abene","ia_hackers_mitnick","ia_hackers_poulsen","ia_hackers_levin","ia_hackers_sites","ia_domain","ia_future","ip","ip_geo","ip_arch","ip_speed","ip_access","ip_growth","ip_digital","ip_speech","is","is_conf","is_anon","is_anon_work","is_anon_use","is_anon_limits","is_anon_sites","is_remailers","is_crypt","is_crypt_pkc","is_crypt_pkc_inv","is_crypt_pkc_work","is_crypt_pkc_info","is_crypt_pgp","is_crypt_sig","is_crypt_kra","is_vir","is_vir_prog","is_vir_mac","is_vir_first","is_vir_prot","is_vir_hoax","is_vir_info","is_pass","is_res","it","it_faq","it_faq_history","it_faq_arch","it_faq_create","it_term","it_restart","it_disconnect","it_cancel","im","im_org","im_web","im_hist","im_usenet","im_ml","im_jargon","im_stats","im_notation",
"w","wi","wi_nelson","wi_engelbart","wi_lee","wi_slac","wi_mosaic","wi_netscape","wi_online","wi_w3c","wi_browse","wi_hyper","ww","ww_pages","ww_links","ww_addr","ww_servers","ww_http","ww_html","ww_applets","wu","wu_browsers","wu_browsers_types","wu_browsers_config","wu_browsers_optional","wu_surf","wu_surf_surf","wu_surf_bkmk","wu_surf_frames","wu_surf_keys","wu_search","wu_search_db","wu_search_search","wu_search_special","wu_expert","wu_expert_bool","wu_expert_unique","wu_expert_and","wu_expert_add","wu_expert_words","wu_expert_quest","wu_expert_filter","wu_expert_restrict","wu_expert_wild","wu_expert_test","wu_expert_more","wu_sites","wu_sites_alta","wu_sites_excite","wu_sites_google","wu_sites_info","wu_sites_hot","wu_sites_lycos","wu_sites_yahoo","wa","wa_browser","wa_browser_mult","wa_browser_hist","wa_browser_clone","wa_browser_bkmk","wa_browser_plug","wa_browser_save","wa_browser_about","wa_trick","wa_trick_city","wa_trick_other","wa_trick_search","wa_trick_change","wa_trick_trans","wa_trick_tv","wa_trick_guess","wa_trick_expl","wa_trick_drop","wa_trick_paths","wa_trick_sites","wa_trick_robots","wa_cookie","wa_cookie_what","wa_cookie_cap","wa_cookie_avoid","wa_down","wa_buy","wa_build","wa_misc","wa_arch","wp","ws","wt","wt_find","wt_connect","wt_slow","wt_error","wm","wm_faq","wm_news","wm_rfc","wm_stats",
"e","ei","ew","ew_addr","ew_smtp","ew_pop","ew_pop_pop3","ew_pop_imap","ew_pop_mapi","eu","eu_app","eu_config","eu_addr","eu_subj","eu_comp","eu_send","eu_read","eu_reply","eu_forward","eu_save","eu_delete","ea","ea_dates","ea_att","ea_att_encode","ea_att_send","ea_att_receive","ea_att_mime","ea_atsf","ea_bcc","ea_sig","ea_addrbk","ea_addrgrp","ea_redirect","ea_filter","ea_receipt","ea_findaddr","ea_findpal","ea_free","ea_rem","ea_addrchange","ea_remote","ea_backup","ea_games","ea_net","ea_compact","ep","ep_push","ep_wait","ep_many","ep_free","es","et","et_connect","et_addr","et_format","et_format_why","et_format_fix","et_format_fix_macro","et_spam","et_virus","et_delay","et_rescue","em","em_faq","em_rfc","em_usenet",
"u","ui","ui_netnews","ui_early","ui_nntp","ui_modern","ui_alt","ui_bitnet","ui_fidonet","ui_inn","ui_comm","ui_old","uw","uw_apps","uw_read","uw_hier","uw_list","uu","uu_app","uu_find","uu_desc","uu_read","uu_thread","uu_post","uu_reply","uu_test","uu_answer","uu_arch","ua","ua_disg","ua_cross","ua_cancel","ua_prev","ua_remove","ua_pub","ua_bin","ua_filter","ua_find","ua_create","ua_alt","ua_list","ua_new","ua_old","up","us","ut","um","um_faq","um_web","um_news","um_int","um_rfc","um_note",
"r","ri","ri_early","ri_emisari","ri_planet","ri_talk","ri_eies","ri_compuserve","ri_talkers","ri_irc","ri_net","rw","rw_apps","rw_net","rw_chan","ru","ru_client","ru_server","ru_config","ru_chan","ru_nick","ru_list","ru_join","ru_talk","ru_who","ru_chatq","ra","ra_motd","ra_create","ra_action","ra_priv","ra_notify","ra_ignore","ra_away","ra_part","ra_dcc","ra_ping","ra_mult","ra_cross","ra_script","ra_own","ra_misc","rp","rs","rt","rt_help","rt_irc","rt_lag","rt_split","rm","rm_rfc","rm_faq","rm_chat",
"d","di","di_major","di_client","di_server","dw","dw_client","dw_server","dw_type","dw_extend","du","du_client","du_client_win","du_client_mac","du_client_unix","du_client_other","du_find","du_sign","du_cmd","du_etiq","da","da_log","da_own","da_bots","da_cyborg","da_kill","da_term","dp","ds","dt","dm","dm_news","dm_faq","dm_web","dm_usenet","dm_ask",
"l","li","lw","lw_server","lw_type","lu","lu_find","lu_sub","lu_unsub","lu_send","lu_reply","lu_dig","lu_web","lu_etiq","ll","lli","llw","llu","llu_find","llu_sub","llu_unsub","llu_send","llu_digest","llu_suspend","lla","lla_index","lla_get","lla_give","lla_set","lla_lists","lla_query","lla_reg","lla_rev","lla_scan","lla_search","lla_getpost","lla_stats","lla_show","lla_central","llt","llm","llm_doc","llm_lite","lj","lji","ljw","lju","lju_find","lju_sub","lju_dig","lju_unsub","lja","lja_index","lja_get","lja_which","lja_who","lja_end","ljt","ljt_help","ljt_person","ljt_lists","ljm","lc","lci","lcw","lcu","lcu_find","lcu_sub","lcu_unsub","lcu_set","lcu_info","lca","lca_index","lca_get","lca_view","lca_suspend","lca_digest","lca_recip","lca_stat","lca_run","lca_which","lca_rev","lca_search","lca_fax","lca_release","lca_live","lca_owner","lct","lcm","la","la_mgmt","la_filter","la_config","la_search","la_own","la_known","la_known_oracle","la_known_newsscan","la_known_cnet","la_arch","lp","ls","lt","lt_unsub","lt_noemail","lt_toomuch","lm"
);

var page_list_length = page_list.length ;

// chapters_index is a string of the letters used to correspond to chapters, 
// used for the folder name for each chapter, and used as the first letter
// of every page name in that chapter.  The chapters_index string is used
// by the functions to recognize these letters in the names of pages, and
// to assemble the appropriate contents page on selection of the Contents
// function. If you add a new chapter, you need to add its corresponding
// letter to this string.

var chapters_index ;
chapters_index = "iewurdl" ;

//------------------------------------------------------------
//
// Code initialization:
//
// Reset current_page, then get the page name and set the correct page 

var current_page = 0 ;
s1 = location + "misc" ;
s2 = Get_page_name(s1) ;
Set_current_page(s2) ;

//------------------------------------------------------------
//
// Functions:
//
//   Get_page_name:  Extract the page name from the URL of the
//      current page. 
//   Page_next:  Go to the next page of the site.   
//   Page_previous:  Go to the previous page of the site.
//   Page_up:  Go to the index page one level up from the current page.
//   Set_current_page:  Cycle through page_list to find a
//      match with the current page name.
//   Set_page_name:  Format the page name, add the chapter folders and htm.
//   Site_contents:  Based on the first letter of the page name, load
//      the chapter table of contents.
//   Site_home:  Reset to the site home page.
//   
//------------------------------------------------------------

function Get_page_name(s) {

// Extract the page name from the current URL

 var i, j, k, s1, s2 ;
 
 s1 = s + "misc" ;
 i = s1.indexOf(".htm") ;
 j = i - 2 ;
 k = -1 ;

 // Run backwards from the .htm until you find a slash, or hit the
 // beginning (supposedly impossible, but the guard makes fail-safe)

 while ( (j >=0) && (k == -1)) {

  if (s1.substring(j,j+1) == "/") { k = j; } ;
  j = j - 1 ;

 }

 // Extract the page name, from after the slash to before the .htm

 var s2 = s1.substring(k+1, i) ;

 return s2 ;

}

//------------------------------------------------------------

function Page_next() {

// Load the next page of the site.
// If current_page is not at the end of page_list, add 1, otherwise
// set to the first page.  
// Ask Set_page_name to format the name of the page, then load.

 var s1 ;

 (current_page < page_list_length - 1 ) ? 
   current_page = current_page + 1 : current_page = 0 ;

 s1 = Set_page_name () ;
 location = s1 ;
 
}

//------------------------------------------------------------

function Page_previous() {

// Load the previous page of the site.
// If the current_page is not at the beginning of page_list, subtract 1, 
// otherwise set to the last page.  
// Ask Set_page_name to format the name of the page, then load.

 var s1 ;
 
 (current_page > 0) ? 
   current_page = current_page - 1 : current_page = page_list_length - 1 ;
 
 s1 = Set_page_name () ;
 location = s1 ; 

}

//------------------------------------------------------------

function Page_up() {

// Load the index page one level up from the current page:
//    ft_simple_dry.htm  -->  ft_simple.htm
//    ft                 -->  f
//    f                  -->  /
//    thelp              -->  /

 var char1, j, k, x, s1, s2, s3, s4 ;

// Get the current page, and check its first character

 s1 = page_list[current_page] ;
 char1 = s1.substring(0,1) ;

 // If a top-level page, return the home page

 if (char1 == "t") {
  current_page = 0 ;
 } else {

  // Starting from the end of the page name, search for the previous "_"

  s2 = s1 + "///" ;
  j = -1 ;
  k = 0 ;
  x = -1 ;
  while ( (j == -1) ) {
    s3 = s2.substring(k,k+1) ;
    if (s3 == "_") {
     x = k ;
    }
    if (s3 == "/") {
     j = 0 ;
    }
    k = k + 1 ;
  }

  // If found a "_", then select from the start to one char before

  if ( x != -1 ) {
   s5 = s2.substring(0,x) ;
  } else {

   // If second char of name is folder separator, then the page is a
   // one letter chapter name, so return the home page as the Up page

   s4 = s2.substring(1,2) ;
   if ( s4 == "/" ) {
    s5 = "/" ;
   } else {

    // Page must be a two letter section home page, so select the
    // first character to get the chapter home page

    s5 = s2.substring(0,1) ;
   }
  }

  // Run the page name through page_list to set current_page

  Set_current_page(s5) ;
  
 }

 // Format the page name for loading, then display

 s1 = Set_page_name () ;
 location = s1 ;
 
}

//------------------------------------------------------------

function Set_current_page(s) {

// Run through page_list to find the specified page name,
// and set current_page as an index used by other functions

 var index = 0 ;
 var i = 0 ;
 var found_page = -1 ;

 // Run to end of page_list unless page match found

 while ( (i<=page_list_length) && (found_page == -1) ) {
  if (s == page_list[i]) { found_page = i } ;
  i++ ;
 }

 // Set current_page if match found

 if (found_page != -1) { current_page = found_page; }
 
}

//------------------------------------------------------------

function Set_page_name () {

// Format the page name indicated by current_page for loading

 var s1, s2 ;
 
 s1 = page_list[current_page] ;
 s2 = s1.substring(0,1) ;

 // If the home page, then return just the home page
 
 if (s1 == "/") {
   s1 = "/" ;
 } else {

  // If not top-level page, then add chapter folder name

  if (s2 != "t") {
   s1 = s2 + "/" + s1 ;
  }

  // Add the home designator, and the htm page suffix

  s1 = "/" + s1 + ".htm" ;

 }
 
 return s1 ;
 
}

//------------------------------------------------------------

function Site_contents() {

// When on a top level page, display the main site contents page.
// When on a chapter page, display that chapter's contents page.

 var char1, i, s1, s2, s3 ;
 var on_chapter = -1 ;
 var chapter_toc = "/ttoc_" ;

 // Add the top level help page to the end of the URL, so the home
 // page will be interpreted as a top level page, as in:
 //    livinginternet.com/  -->  livinginternet.com/thelp.htm

 s1 = location + "thelp.htm" ;
 
 // Get page name and check if chapter page
 
 s2 = Get_page_name(s1) ;
 char1 = s2.substring(0,1) ;
 i = chapters_index.indexOf(char1) ;

 // If not a top-level page and confirmed as a valid chapter page, 
 // then assemble the appropriate contents page name and load

 if ((char1 != 't') & (i != -1)) {
  on_chapter = 0 ;
  chapter_toc = chapter_toc + char1 + ".htm" ;
  location = chapter_toc ;
 }

 // If not found to be a chapter page, then display site contents

 if (on_chapter == -1) { location = "/ttoc_site.htm" ; }

}

//------------------------------------------------------------

function Site_home () {

// Load the home page

 location = "/" ;

}

//
// End Living Internet source
//
//------------------------------------------------------------

