// Scripts copyright 2000 JSL www.jserv.com
// Reuse permitted as long as credit is given to source.

//navigate to two side-by-side windows
function twogo(slidenum) {


   var iColl = document.images;
   var imgsrc;
   
   if (slidenum < 0) {
     for (i = 0; i < iColl.length; i++) {
       imgsrc = iColl[i].src;
       if (imgsrc.indexOf('redtri.gif', 0) != -1) {
          slidenum = i + 3 + slidenum;
          break;
       } else {
       }
     }
   }

   if (slidenum > iColl.length) {slidenum = iColl.length}
   if (slidenum < 1) {slidenum = 1}
   
   var root = 'slide';
   if (slidenum < 10) root = root + '0';
   parent.left.location = root + slidenum + '.htm';
   parent.right.location = 'final/' + root + slidenum + '.htm';
   
   for (i = 0; i < iColl.length; i++) {
      if (i == slidenum - 1) {
         iColl[i].src = '../../../../redtri.gif';
      } else {
         iColl[i].src = '../../../../whitetri.gif';
      }
   }

}

function select_ns(url) {

   var pageType = document.forms[0].pageType.selectedIndex;
   
   if (pageType == 1) {
      re = /slide.*\d+/;
      url = url.replace(re, "sbook");
   }
   if (pageType == 2) {
      re = /slide.*\d+/;
      url = url.replace(re, "sbook2");
   }
   if (pageType == 4) {
      re = /slide.*\d+/;
      url = url.replace(re, "sbookt");
   }

   if (pageType == 3) {
      re = /slide.*\d+/;
      url = url.replace(re, "slidetoc");
   }


   if (window != top) {
      parent.mainFrame.location = url
   } else {
      location = url;
   }  

  var firstpage = url;
  firstpage = firstpage.toLowerCase();
  var title, a, re, tmp, tmp2;
  var aColl = document.anchors;
  var iColl = document.images;
 
  // for web bookshelf version
  re = /s\d+/;
  var i = firstpage.match(re);
  re = /^s/;
  var x = i.toString();
  x = x.replace(re, "");
  re = /^0/;
  x = x.replace(re, "");
   
  for (i = 0; i != iColl.length; i++) {
    iColl[i].src = "wsquare.gif";	
  }
  iColl[x - 1].src = "rsquare.gif";
  
//  for (i = 0; i != aColl.length; i++) {
//     a = aColl[i];
//     title = a.text;  // anchor text
//
//     //kludge fix for ns bug
//     title = title + " ";
//     re = /\s+$/;
//     title = title.replace(re, "");
//     title = title.toLowerCase();
//     title = escape(title);
//     //re = /\s+$/;
//     //title = title.replace(re, "");
//     //alert("title = " + title + " firstpage = " + firstpage);
//     if (firstpage.indexOf(title, 0) == -1) {
//        iColl[i].src = "wsquare.gif";
//        continue;
//     } else {
//     }
//     iColl[i].src = "rsquare.gif";
//     location = "#" + a.name;
//     a.x = 200;
//     break;
//  }



}

function select_ie(url) {

   var pageType = document.forms[0].pageType.selectedIndex;
   var oldUrl = url;
   
   re = /slide.*\d+/;
   if (pageType == 1) {
      url = url.replace(re, "sbook");
   }
   if (pageType == 2) {
      url = url.replace(re, "sbook2");
   }
   if (pageType == 4) {
      url = url.replace(re, "sbookt");
   }
   if (pageType == 3) {
      url = url.replace(re, "slidetoc");
   }

   //navigate
   if (window != top) {
      parent.mainFrame.location = url;
   } else {
      location = url;
      return 0;
   }  
  
   //hilite selected toc item. This
   //method doesn't work with ns
   var aColl = document.all.tags("A");
   oldUrl = oldUrl.toLowerCase();
   oldUrl = escape(oldUrl);
   for (i = 1; i < aColl.length - 1; i++) {
      a = aColl[i];
      url2 = a.href;
      url2 = url2.toLowerCase();
      re = /javascript:select_ie\('/;
      url2 = url2.replace(re, "");
      re = /'\)/;
      url2 = url2.replace(re, "");
 //     alert(oldUrl + "\n" + url2);
      if (oldUrl.indexOf(url2, 0) != -1) {
        a.parentElement.className = 'hilite1';
      } else {
        a.parentElement.className = 'level4';
      }
   }

}

// choose which frame container to go to depending on browser
function go(url) {
  
  //if (parent.frames.length != 0) {
  //  alert('This feature is not available when you are already inside a frame.\nPlease click on the "No Frames" icon (white square) first to escape your current frame.');
  //  return;
  //}
  re = /\.\.\//;
  var s;
  s = url.replace(re, "");
  var ss;
  ss = s.split("?");
  s = ss[0];
  s = s.toLowerCase();
  var app = navigator.appName;
  var version = parseFloat(navigator.appVersion);

  //next clause selects different frame toc per browser
  if (s == 'sbframetoc.htm') {
     if ((app.indexOf('Netscape') != -1) && (version >= 4)) {
        re = /sbframetoc\.htm/;
        url = url.replace(re, "sbframetoc_ns.htm");
        top.location = url;
        return;
     } 
     if ((app.indexOf('Microsoft') != -1) && (version >= 4)) {
        re = /sbframetoc\.htm/;
        url = url.replace(re, "sbframetoc_ie.htm");
        top.location = url;
        return;
     } 
     top.location = url;

     return;
  }

  //select different non-frame toc per browser
  if (s.indexOf('sbooktoc.htm', 0) != -1) {
     if ((app.indexOf('Netscape') != -1) && (version >= 4)) {
        re = /sbooktoc\.htm/;
        url = url.replace(re, "sbooktoc_ns.htm");
        top.location = url;
        return;
     } 
     if ((app.indexOf('Microsoft') != -1) && (version >= 4)) {
         re = /sbooktoc\.htm/;
         url = url.replace(re, "sbooktoc_ie.htm");
         top.location = url;
         return;
     } 
     top.location = url;
     return;
  }   
//alert('x');

  //if (window != top) {
  //   parent.mainFrame.location = url
  //} else {
     top.location = url;
  //}  

}

function relocateNoFrame(URL) {
  //if (self != top) top.location = self.location;
  
}


// choose which frame container to go to depending on browser
function gotoc2(url) {

  re = /\.\.\//;
  var s;
  s = url.replace(re, "");
  var ss;
  ss = s.split("?");
  s = ss[0];
  s = s.toLowerCase();
  var app = navigator.appName;
  var version = parseFloat(navigator.appVersion);
  
  //if (parent.frames.length > 0) {parent.location.href = location.href;}

  //next clause selects different frame toc per browser
  if (s == 'sbframetoc.htm') {
     if ((app.indexOf('Netscape') != -1) && (version >= 4)) {
         re = /sbframetoc\.htm/;
         url = url.replace(re, "sbframetoc_ns.htm");
         parent.location = url;
         return;
     } 
     if ((app.indexOf('Microsoft') != -1) && (version >= 4)) {
         re = /sbframetoc\.htm/;
         url = url.replace(re, "sbframetoc_ie.htm");
         parent.location = url;
         return;
     } 
     location = url;
     return;
  }

  //select different non-frame toc per browser
  if (s.indexOf('sbooktoc.htm', 0) != -1) {
     if ((app.indexOf('Netscape') != -1) && (version >= 4)) {
        re = /sbooktoc\.htm/;
        url = url.replace(re, "sbooktoc_ns.htm");
        parent.location = url;
        return;
     } 
     if ((app.indexOf('Microsoft') != -1) && (version >= 4)) {
        re = /sbooktoc\.htm/;
        url = url.replace(re, "sbooktoc_ie.htm");
        parent.location = url;
        return;
     } 
     location = url;
     return;
  }   

  //if (window != top) {
  //   parent.mainFrame.location = url
  //} else {
  //   location = url;
  //}  

}


// for the frames menu
function sync_ie() {
	
  // go to netscape version if being viewed by netscape	
  var app = navigator.appName;
  if (app.indexOf('Microsoft') == -1) {
    re = /_ie\.htm/;
    myUrl = parent.location.href;
    myUrl = myUrl.replace(re, "_ns.htm");
    parent.location.href = myUrl;
    return;
  }

  //sync toc
  var url, s, ss;
  if (window == top) return 0;
  s = parent.location;
  url = s.toString();
  ss = url.split("?");
  if (ss.length == 1) return 0;
  s = ss[1];
  var path = ss[0];
  var b = path.lastIndexOf("/");
  path = path.substr(0,b);
  path += "/";
  ss = s.split("=");
  s = ss[1];
  var folder;
  if (s[0] == 'f') {
     folder = ss[1];
  }
  folder = path + ss[1];
  var firstpage = path + "slide01.htm";
  parent.mainFrame.location.href = folder;
  firstpage = firstpage.toLowerCase();

  //scroll menu
  var url, a;
  var aColl = document.all.tags("A");
  for (i = 0; i < aColl.length; i++) {
     a = aColl[i];
     url = a.href;
     url = url.toLowerCase();
     re = /javascript:select_ie\('/;
     url = url.replace(re, "");
     re = /'\)/;
     url = url.replace(re, "");
     if (firstpage.indexOf(url, 0) != -1) {
       location.href = a.name;
       a.parentElement.className = 'hilite1';
     } else {
     }
     
  }
//  return 0;
}

function sync_ns() {
  var url, s, ss;
  if (window == top) return 0;
  s = parent.location;
  url = s.toString();
  ss = url.split("?");
  if (ss.length == 1) return 0;
  s = ss[1];
  var path = ss[0];
  var b = path.lastIndexOf("/");
  path = path.substr(0,b);
  path += "/";
  ss = s.split("=");
  s = ss[1];
  var folder;
  if (s[0] == 'f') {
     folder = ss[1];
  }
  folder = path + ss[1];
  var firstpage = path; // + "slide%201.htm";
  parent.mainFrame.location.href = folder;
  firstpage = firstpage.toLowerCase();
  var title, a, re, tmp, tmp2;
  var aColl = document.anchors;
  var iColl = document.images;
  re = "/color/i";
  for (i = 0; i != aColl.length; i++) {
     a = aColl[i];
     title = a.text;
     //kludge fix for ns bug
     title = title + " ";
     re = /\s+$/;
     title = title.replace(re, "");
     title = title.toLowerCase();
     //re = /\s+$/;
     //title = title.replace(re, "");
     title = escape(title);
     if (firstpage.indexOf(title, 0) == -1) {
        iColl[i].src = "wsquare.gif";
        continue;
     } else {
     }
     iColl[i].src = "rsquare.gif";
     location = "sbooktoc_ns.htm#" + a.name;
//     a.x = 200;
//     break;
  }
  return 0;
}


function setFont(font) {

   SetCookie('sbFont', font, expiry);

}

function setFontSize(fontSize) {

  SetCookie('sbFontSize', fontSize, expiry);

}

function init2() {
   var f = GetCookie('sbFont');
   if (f == null) return 0;
   var s = GetCookie('sbFontSize');

//   document.write("<style type='text/css'>.cp {font-family:" + f + "}</style>");
   document.write("<style type='text/css'>p {font-size:" + s + "pt; font-family:" + f + "}</style>");
   document.write("<style type='text/css'>li {font-size:" + s + "pt; font-family:" + f + "}</style>");
}

//ie only, not currently in use
function init() {

   var f = GetCookie('sbFont');
   var s = GetCookie('sbFontSize');

   var obj = document.all.item("pagetext");
   if (obj != null) {
        obj.style.fontFamily = f;
        obj.style.fontSize = s + "pt";
   } else {
   }

}

//following script from Macromedia Dreamweaver, unused, for reference only
function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v3.0
  var newURL='', verStr=navigator.appVersion, app=navigator.appName, version = parseFloat(verStr);
  if (app.indexOf('Netscape') != -1) {
    if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
    else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
  } else if (app.indexOf('Microsoft') != -1) {
    if (version >= IEvers || verStr.indexOf(IEvers) != -1)
     {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
    else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
  } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
  if (newURL) { 
     window.location=unescape(newURL); document.MM_returnValue=false; 
  } else {
     window.location='sbooktoc.htm';
  }
}

// cookies.js
// Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) { endstr = document.cookie.length; }
	return unescape(document.cookie.substring(offset, endstr));
	}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
	}

function DeleteCookie (name,path,domain) {
	if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
	}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
	}


