/* 
Purpose: Pass bookmark data on to forwarded to library book pages
Created: 3/10/2007
Author: John Robert Shea
*/

// Get Boookmark if one exists
address = window.location;
text = address.toString();
q = text.indexOf('?'); // Questionmark marker for bookmark
len = text.length;

// Initialize variables
Bookmark = '';
Book = '';
Chapter = '';
Page = '';
Pg = '';
Ch = '';

// Check for presence of ? character for bookmark code
if (q > 0) {
  Bookmark = text.substring(q + 1, len);
}

// extract book, chapter and page request
len = Bookmark.length;
if (len >= 3) {
  Book = Bookmark.substring(0,3);
  Ch = 'contents';
  Chapter = '';
  Pg = '';
  Page = '';
}
if (len >= 5) {
  Chapter = Bookmark.substring(3,5);
  Ch = 'chapter' + Chapter;
  Pg = '';
  Page = '';
}

if (len >= 6) {
  Pg = '#page';
  Page = Bookmark.substring(5,len);
  if (Book == 'trw') Pg = '#';
}

if (Chapter == 'cx') { Ch = 'contents'; }
if (Chapter == 'fx') { Ch = 'foreword' }
if (Chapter == 'ix') { Ch = 'indexwords'; }
if (Chapter == 'qx') { Ch = 'questions'; }
if (Chapter == 'ax') { Ch = 'author'; }
if (Chapter == 'lx') { Ch = 'lentlessons'; }
if (Chapter == 'ux') { Ch = 'lentunity'; }
if (Chapter == 'px') { Ch = 'copyright'; }

// Check for The Revealing Word
// Allow entry of Book trw with search word attached (?trwWord)
if (Book == 'trw') {
  L1 = Chapter.substring(0,1);
  L2 = Chapter.substring(1,2);
  if (L2 != 'x' && L1 != L2) {
    Chapter = L1.toLowerCase();
    Chapter = Chapter + Chapter;
    Temp = L1 + L2 + Page;
    Page = Temp;
  }
}

URL = 'http://www.tsmj.org/library/?' + Book + Chapter + Page;
