// inline test of browser capabilities
var canRun = false;

if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3))
{
   canRun = true;
}

if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ))
{
   canRun = true;
}

if (!canRun)
{
   alert('Your web browser might not display following page correctly.  These page requires Microsoft Internet Explorer 4.0+ or Netscape Navigator 3.0+.  Additionally you must enable JavaScript in the browser ("Options" menu item).');
   window.history.go(-1);
}

// color schemes, variables, object, and function definitions

// book styles
var cBookBorderColor = '#000000';         // color of book border
var cBookPageColor = '#FFFFFF';           // background for book page
var cPageHeaderColor = '#FFFFFF';        // background for book page header
var cSectionBackColor = '#D9E7C5';       // background for section description and title on the book.html page

// font styles
var cChapterFontColor = cBookBorderColor;      // font color for chapter text
var cHeaderFontColor = cBookBorderColor;       // font color for header text
var cNormalFontColor = '#000000';                  // font color for normal text
var cFooterFontColor = cBookBorderColor;        // font color for footer text

// tab styles
var cSelTabColor = cBookPageColor;               // background for selected tab
var cNonSelTabColor = '#E8E7DB';                  // background for non selected tab
var cLibraryTabColor = cNonSelTabColor;         // background for non library tab
var cTabLinkColor = '#000000';                      // color of tab link

// misc settings
var cChapterFontSize = 2;                            // font Size for chapter title
var cGeneralFont = "Verdana";                            // font name

// verifies that object has been created
function HasInstance(obj)
{
   return (obj != null) && (obj != 'undefined');
}

// standard chapter style
function toChapter(text)
{
   return '<center><strong><font face="' + cGeneralFont + '" size="' + cChapterFontSize + '" color="' + cChapterFontColor + '">' + text + '</font></strong></center>';
}

// standard header style
function toHeader(text)
{
   return '<font face="' + cGeneralFont + '" size="2" color="' + cHeaderFontColor + '"><strong>' + text + '</strong></font>';

}

// replace function
function pbwSearchAndReplace(text, SearchFor, ReplaceWith) {
  var tmpContent = text;
  var tmpBefore = '';
  var tmpAfter = '';
  var tmpOutput = '';
  var intBefore = 0;
  var intAfter = 0;

  if (SearchFor.length > 0) {
    while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {

      // Get all content before the match
      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
      tmpBefore = tmpContent.substring(0, intBefore);
      tmpOutput = tmpOutput + tmpBefore;

      // Get the string to replace
      tmpOutput = tmpOutput + ReplaceWith;

      // Get the rest of the content after the match until the next match or the end of the content
      intAfter = tmpContent.length - SearchFor.length + 1;
      tmpContent = tmpContent.substring(intBefore + SearchFor.length);

    }
  }
  return tmpOutput + tmpContent;
}

// normal text style
function toNormal(text)
{
   if (cNormalFontColor != '#000000')
   {
      return '<font face="' + cGeneralFont + '" size="1" color="'+ cNormalFontColor +'">' + text + '</font>';
   }
   else
   {
      return '<font face="' + cGeneralFont + '" size="1">' + pbwSearchAndReplace(text, "&#13;","<BR>") + '</font>';
   }
}


// footer style
function toFooter(text)
{
   return '<font face="' + cGeneralFont + '" size="1" color="' + cFooterFontColor + '"><em>' + text + '</em></font>';
}

// tab link text
function toTabLink(text)
{
   if (text != 'Library')
   {
      return '<font face="' + cGeneralFont +'" size="1" color="' + cTabLinkColor + '">' + text + '</font>';
   }
   else
   {
      return '<strong><font face="' + cGeneralFont +'" size="3" color="' + cTabLinkColor + '">' + text + '</font></strong>';
   }
}

// insert animated url image
var aniCounter = 0;
function insertAnimatedUrl(url, img1, img2, alt)
{
   aniCounter += 1;
   var aniName = 'aniUrl' + aniCounter;
   document.write('<a href="' + url+ '" onmouseout="' + aniName +'.src=\'' + img1 + '\';" onmouseover="' + aniName +'.src=\'' + img2 + '\';">');
   if (alt != '')
   {
      document.write('<img name="' + aniName + '" src="' + img1 + '" border="0" alt="' + alt + '"></a>');
   }
   else
   {
      document.write('<img name="' + aniName + '" src="' + img1 + '" border="0"></a>');
   }
}

// vertical tabs generator
function addVTab(text, url, root, color)
{
   if (url == '')
   {
      document.write('<tr><td bgcolor="' + color + '" align="left">');
      document.write('<table bgcolor="' + color + '" cellpadding="2"><tr><td align="left" width="50">');
      document.write(toNormal(text));
   }
   else
   {
      document.write('<tr><td style="border-right: 1px solid black;" bgcolor="' + color + '" align="left">');
      document.write('<table bgcolor="' + color + '" cellpadding="2"><tr><td align="left" width="50">');
      document.write('<a href="' + url + '">' + toTabLink(text) + '</a>');
   }
   document.write('</td></tr></table></td></tr>');
   document.write('<tr><td bgcolor="' + cBookBorderColor + '" height = "1"><img src="' + root + 'images/1_1.gif" width="1" height="1"></td></tr>');
   document.write('<tr><td bgcolor="' + cBookBorderColor + '" height = "1"><img src="' + root + 'images/1_1.gif" width="1" height="1"></td></tr>');
}