function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function openWin(win_url,win_name,win_features,set_parent) { 
  var new_win 
  new_win=window.open(win_url, win_name, win_features) 
  if (set_parent==1) {
    new_win.par=self 
 } 
} 


var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;


if (document.getElementById) {isID = 1; isDHTML = 1;}
else {
if (document.all) {isAll = 1; isDHTML = 1;}
else {
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {isLayers = 1; isDHTML = 1;}
}}

function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return (document.getElementById(objectID).style) ; }
		else { 
			if (isAll) { return (document.all[objectID].style); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
	else {
		if (isID) { return (document.getElementById(objectID)) ; }
		else { 
			if (isAll) { return (document.all[objectID]); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
}


function nextPage(currPage){
  // takes the current page filename and directs the user to the next numerical page
  var returnstring;
  var nextPageNum;
  var nextPageString;
  var padString = "";
  // retrieve the actual number of the page; cast into integer.
  var currPageNum = parseFloat(getPage(currPage));
  if (currPageNum == totalPages) {
    // this may need to change; I'll handle the module outline to next page scenario here
    returnString = nextFromEndPoints(currPage);
  } else {
    nextPageNum = currPageNum + 1;
    if (nextPageNum < 10) { padString = padString + "0"; }
    nextPageString = new String(nextPageNum);
    returnString = currPage.substring(0,8) + padString + nextPageString + ".html";
    // above line grabs module/section/lesson intact, and adds on the new page string
  }
  document.location = returnString;
}

function prevPage(currPage){
  // takes the current page filename and directs the user to the previous numerical page
  var returnstring;
  var prevPageNum;
  var prevPageString;
  var padString = "";
  // retrieve the actual number of the page; cast into integer.
  var currPageNum = parseFloat(getPage(currPage));
  if (currPageNum <= 1) {
    returnString = prevFromEndPoints(currPage);
  } else {
    prevPageNum = currPageNum - 1;
    if (prevPageNum < 10) { padString = padString + "0"; }
    prevPageString = new String(prevPageNum);
    returnString = currPage.substring(0,8) + padString + prevPageString + ".html";
  }
  document.location = returnString;
}

function getPage(currPage){
  // the page string is mmSssLllpp.html; we need the 9th and 10th character, but JS starts at 0
  return (currPage.substring (8,10));
}

function getLesson(currPage){
  // the page string is mmSssLllpp.html; we need the 7th and 8th character, but JS starts at 0
  return (currPage.substring (6,8));
}

function getSection(currPage){
  // the page string is mmSssLllpp.html; we need the 4th and 5th character, but JS starts at 0
  return (currPage.substring (3,5));
}

function getModule(currPage){
  // the page string is mmSssLllpp.html; we need the 1st and 2nd character, but JS starts at 0
  return (currPage.substring (0,2));
}

function nextFromEndPoints(currPage) {
  var returnString = "";
  var currSection = getSection(currPage);
  var currSectionNum = parseInt(currSection,10);
  var currLesson = getLesson(currPage)
  var currLessonNum = parseInt(currLesson,10);
  var currModule = getModule(currPage);
  if (currSectionNum == 0) {
    // we're at the module header; hence we'll set the returnstring here.
    returnString = currModule + "s01l0101.html";
    // above line grabs module string intact, increments the section and lesson, 
    // then adds on the first page string
    document.location = returnString;
  } else {
    // check to see if we're the last lesson in a section
    if (currLessonNum == totalLessons) {
      //yep, then check to see if we're the last section
      if (currSectionNum == totalSections) {
        //yep, force return to moduleTOC
        returnString = curIndex;
      } else {
        // no, go to the intro for the next section
		
        currSectionNum = currSectionNum + 1;
        if (currSectionNum < 10) currSection = "0" + currSectionNum;
        else currSection = new String(currSectionNum);
        returnString = currModule + "s" + currSection + "l0101.html";
      }
    } else {
      // no, go to the next lesson
      currLessonNum = currLessonNum + 1
      if (currLessonNum < 10) currLesson = "0" + currLessonNum;
      else currLesson = new String(currLessonNum);
      returnString = currModule + "s" + currSection + "l" + currLesson + "01.html";
    }
  }
  return (returnString);
}

function prevFromEndPoints(currPage) {
  var returnString = "";
  var currSection = getSection(currPage);
  var currSectionNum = parseInt(currSection,10);
  var currLesson = getLesson(currPage)
  var currLessonNum = parseInt(currLesson,10);
  var currModule = getModule(currPage);
  var lastPageNum = 0;
  var lastPage = "";
  var padding = "";
  if (currLessonNum == 1) {
    // we're at the section intro; 
    if (currSectionNum == 1) {
    // we're at the first section intro; prev will be the module header
	
      returnString = curIndex;
    } else {
      currSectionNum = currSectionNum - 1;
      currLessonNum = checkSessionArray(currSectionNum-1);
  	  if (currLessonNum < 10) padding = "0";
      if (currSectionNum < 10) currSection = "0" + currSectionNum;
      else currSection = new String(currSectionNum);
      lastPageNum = checkLessonArray(currSectionNum-1, currLessonNum-1);
      if (lastPageNum < 10) lastPage = "0" + lastPageNum;
      else lastPage = new String(lastPageNum);
      returnString = currModule + "s" + currSection + "l" + padding + currLessonNum + lastPage + ".html";
    }
  } else {
    // check to see if we're the first lesson in a section
    currLessonNum = currLessonNum - 1
    if (currLessonNum < 10) currLesson = "0" + currLessonNum;
    else currLesson = new String(currLessonNum);
    lastPageNum = checkLessonArray(currSectionNum-1, currLessonNum-1);
    if (lastPageNum < 10) lastPage = "0" + lastPageNum;
    else lastPage = new String(lastPageNum);
    returnString = currModule + "s" + currSection + "l" + currLesson + lastPage + ".html";
  }
  return (returnString);
}

function toc() {
  document.location = curIndex;
}

function checkSessionArray(arrayIndex) {
  return sectionsArray[arrayIndex];
}

function checkLessonArray(sectionIndex, lessonIndex) {
  return lessonPagesArray[sectionIndex][lessonIndex];
}

function checkCookie()
{
	cookiename = readCookie('Chabner_short5e');
	if (cookiename != null)
	{
	
	}
	else 
	{
		url = location.href;
		createCookie('Chabner_short5e',url,365);
	}
} 
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function assigncookie(cookiename)
{		
	url = location.href;
	createCookie('Chabner_short5e',url,365);
}