var testing = 0; // VALUE IS 1 IF TESTING LOCAL. VALUE IS 0 IF AT HMCO.

var PopUpTextWin = null;
var PopUpLargeTextWin = null;
var PopUpAnswerWin = null;
var PopUpPDFWin = null;
var PopUpSPWin = null;
var PopUpCPWin = null;
var PopUpIntTextWin = null;
var PopUpSimWin = null;
var PopUpAnimWin = null;
var PopUpVideoWin = null;
var PopUpEditWin = null;
var PopUpLabWin = null;
var PopUpCASWin = null;
var PopUpOEWin = null;
var PopUpSolWin = null;

if(testing == 1){var serverRoot = "../../";}
else{var serverRoot = "http://college.hmco.com/mathematics/blackboard/content/larson/etf4e/";}

var hmcoVideoPath = 'http://college.hmco.com/mathematics/blackboard/shared/content/video_explanations/';

var animationFolder = serverRoot + "animations/";
var simulationFolder = serverRoot + "simulations/";
var editableGraphFolder = serverRoot + "eg/";
var mathGraphFolder = serverRoot + "mg/";
var mathBioFolder =  serverRoot + "bio/";
var mathArticleFolder = serverRoot + "ma/";
var rotatableGraphFolder = serverRoot + "rotgraphs/";
var gcpFolder = serverRoot + "gcp/";
var calcLabFolder = serverRoot + "lab/";
var openExploreFolder = serverRoot + "cas/";

var thePlatform = (navigator.platform.substr(0,3)).toLowerCase();

//****************************************************************************/
// CALLED FROM T FUNCTION(T CALLED FROM CONCEPT PAGES) AND 
// EXPLORE IT FIRST(Pickup)
// EXPLORATIONS(Pickup)
// TRY ITS(Pickup)
// CALLED FROM LOADWINDOW FUNCTION(LOADWINDOW CALLED FROM SOLUTIONS AND NEW PROCESSED FILES)
//****************************************************************************/
function LoadPopUpWindow(file){

	var fileProperties = new SetFileProperties(file);
								
	switch(fileProperties.prefix){
		//** TRYITS, EXPLORATIONS, TECHNOLOGYS, HISTORIES, EXPLORE IT FIRST **//
		case 'ti': case 'ep': case 'tn': case 'hi': case 'ef':
			if(fileProperties.prefix == 'ef' && file.length == 10 ){ // EXPLORE IT FIRST ANSWERS
				OpenAnswerWindow(fileProperties.directory + file + ".html");
				break;
			}
			OpenTextWindow(fileProperties.directory + file + ".html");
			break;
		//** CONNECTIONS **//
		case 'ct':
			OpenLargeTextWindow(fileProperties.directory + file + ".html");
			break;	
		//** EXPLORATION ANSWERS **//
		case 'ea':
			OpenAnswerWindow(fileProperties.directory + file + ".html");
			break;	
		//** MATH TREND CODE **//
		case 'mt':
			OpenAnswerWindow(fileProperties.directory + file + ".html");
			break;		
		//** TRYIT SOLUTIONS **//
		case 'ts':
			document.location.href = file + ".html";
			break;	
		///** SIMULATIONS **//	
		case 'si':	
			OpenSimWindow(simulationFolder + file + '.html');
			break;		
		//** VIDEOS **//		
		case 'vi':
			file = file.replace('vi', '');
			file = file.toLowerCase();
			OpenVideoWindow(hmcoVideoPath + file + '.html');
			break;
		//** MATHGRAPHS **//		
		case 'mg':
			OpenPDFWindow(mathGraphFolder + file + '.pdf');
			break;	
		//** ANIMATIONS **//	
		case 'an':
			var fileName = file.substr(2,7);
			OpenAnimWindow(animationFolder + fileName + '.html');
			break;
		//** ROTATABLE GRAPHS **//	
		case 'rt':
			var fileName = file.substr(2,7);
			OpenAnimWindow(rotatableGraphFolder + fileName + '.html');
			break;		
		//** OPEN EXPLORATIONS INTERMEDIATE PAGE **//			
		case 'oe':
			var chapter = fileProperties.stringChapter;
			var section = fileProperties.section;
			var number = file.substring(8,10);
			GetOpenExplorePage(chapter, section, number);			
			break;		
		//** CALCULUS LAB INTERMEDIATE PAGES **//		
		case 'lb':
			OpenLabWindow(fileProperties.directory + file + ".html");
			break;	
		//** CALCULUS LABS **//		
		case 'la':
			DisplayLabs(file);			
			break;		
		//** MATH BIOS **//		
		case 'bi':
			OpenPDFWindow(mathBioFolder + file + '.pdf');
			break;
		//** MATH ARTCILES **//		
		case 'ma':
			OpenPDFWindow(mathArticleFolder + file + '.pdf');			
			break;	
		//** EDITABLE GRAPHS **//	
		case 'eg':
			OpenEditWindow(editableGraphFolder + file + '.html');
			break;	
		//** EXERCISE SOLUTIONS **//	
		case 'se': case 're': case 'ps':
			OpenSolutionWindow(fileProperties.directory + file + ".html");	
			break;
		default:
			//** CAS FILES **//
			if((file.substr(3,3)) == 'cas'){
				// WE BUILD THE CAS FILE FOR FILES RUN THROUGH THE NEW CONVERSION PROCESS
				if((file.substr(6,1)) == '_'){
					file = BuildLookAheadCASFile(file);
				}
				DisplayOE(file);
			}else{
				OpenTextWindow(fileProperties.directory + file + ".html");
			}				
	}
}

//*************************************************************************************************/
// THIS FUNCTION IS USED FOR PDF FILES THAT HAVE EMBEDDED JAVASCRIPT FUNCTION CALLS FROM BUTTONS.
// PAGE IS THE NEW PAGE THAT WILL OPEN FROM THE BUTTON, REFERRER IS THE CALLING PAGE, ANCHOR IS THE
// LOCATION ON THE REFERRER THE JAVASCRIPT CALL WAS MADE FROM.
//*************************************************************************************************/
function T(page,referrer,anchor){
		
	var fileProperties = new SetFileProperties(page);
	var fileNamePath = fileProperties.directory + page + '.html';
						
	LoadPopUpWindow(page);
	
	// IF THE CALL IS MADE FROM A LOCAL MACHINE THE REFERRER PAGE WILL NOT SCROLL BACK TO THE ANCHOR 
	// BUT WILL REMAIN AT THE BEGINNING OF THE PDF FILE	
	if((document.location.href.indexOf("www.")<0)&&(navigator.appName.indexOf("Explorer")>0)&&(document.location.href.indexOf("not.tdlc")<0)){
		document.location.replace(referrer + ".pdf");
	}else{
		document.location.replace(referrer + ".pdf#" + "a" + anchor);
	}
}


//********************************/  
// LOAD WINDOW - SOLUTION 
//********************************/    
function LoadWindow(page){
	LoadPopUpWindow(page);
}

//********************************/  
// LOAD INDEX TERM FROM INDEX FILE
//********************************/    
function LoadIndexTermPage(chapterSection, bookID){
	
	var file;
	var book = (bookID != null ? bookID : "");
		
	// APPENDIX A	
	if(chapterSection.substring(0,1) == "a"){
		file = 'appendices/' + book + chapterSection + ".pdf";
		OpenPDFWindow(file);
	// SECTION EXERCISE	
	}else if(chapterSection.substring(3,4) == "e"){
		file = 'se' + chapterSection.substring(0,3) + '01' + book;
		var fileProperties = new SetFileProperties(file);
		file = fileProperties.stringChapter + '/' + chapterSection.substring(0,3) + '/' +file + '.html';
		OpenIntTextWindow(file);	
	// SECTION PROJECT	
	}else if(chapterSection.substring(3,4) == "s"){
		file = 'sp' + chapterSection.substring(0,3) + '01' + book;
		var fileProperties = new SetFileProperties(file);
		file = fileProperties.stringChapter + '/' + chapterSection.substring(0,3) + '/' +file + '.pdf';
		OpenPDFWindow(file);
	// PROBLEM-SOLVING	
	}else if(chapterSection.substring(2,3) == "z"){
		file = 'ps' + chapterSection + '03' + book;
		var fileProperties = new SetFileProperties(file);
		file = fileProperties.stringChapter + '/' + chapterSection + '/' +file + '.html';
		OpenIntTextWindow(file);	
	// SECTION CONCEPT	
	}else{
		file = 'sc' + chapterSection + '01' + book;
		var fileProperties = new SetFileProperties(file);
		file = fileProperties.stringChapter + '/' + chapterSection + '/' +file + '.pdf';
		OpenPDFWindow(file);
	}
	
}

//************************************************************************************************//
//************************************************************************************************//
//************* SECTION FEATURES INDEX FUNCTIONS *************************************************//
//************************************************************************************************//
//************************************************************************************************//

//**********************************************************************************/
// THIS FUNCTION WILL CONTROL EACH PAGE LOADING FROM THE SECTION FEATURES INDEX
//**********************************************************************************/
function LoadFeature(pageTypeAndNumber){
		
	var thePrefix = GetItem(pageTypeAndNumber, '_', 0);
	var theNumber = GetItem(pageTypeAndNumber, '_', 1);
				
	switch(thePrefix){
		//** TRYITS, EXPLORATIONS, TECHNOLOGYS, HISTORIES **//
		case 'ti': case 'ep': case 'tn': case 'hi':
			var fileName = BuildFileNameWithSuffix(thePrefix, theNumber, '.html');
			OpenTextWindow(fileName);
			break; 
		//** CONNECTIONS, MATH TRENDS, EXPLORE IT FIRSTS, AND LOOK AHEADS **//
		case 'ct': case 'mt': case 'ef': case 'lk':
			var fileName = BuildFileName(thePrefix, theNumber, '.html');
			OpenLargeTextWindow(fileName);
			break; 	
		///** SIMULATIONS **//	
		case 'si':	
			var fileName = thePrefix + theNumber + '.html';
			OpenSimWindow(simulationFolder + fileName);
			break;		
		//** VIDEOS **//		
		case 'vi':
			theNumber = theNumber.replace('vi', '');
			theNumber = theNumber.toLowerCase();
			OpenVideoWindow(hmcoVideoPath + theNumber + '.html');
			break;
		//** ANIMATIONS **//
		case 'an':
			var fileName = animationFolder + theNumber + '.html';
			OpenAnimWindow(fileName);
			break;
		//** ROTATABLE GRAPHS **//	
		case 'rt':
			theNumber = theNumber.substr(0,7);
			var fileName = rotatableGraphFolder + theNumber + '.html';
			OpenAnimWindow(fileName);
			break;		
		//** OPEN EXPLORATIONS INTERMEDIATE PAGE **//			
		case 'oe':
			var fileName = BuildOEFileName(thePrefix, theNumber, '');
			LoadPopUpWindow(fileName);
			break;		
		//** CALCULUS LAB INTERMEDIATE PAGES **//		
		case 'lb':
			var fileName = BuildFileName(thePrefix, theNumber, '.html');
			OpenLabWindow(fileName);
			break;	
		//** MATH BIOS **//		
		case 'bio':
			var fileName = mathBioFolder + thePrefix + theNumber + '.pdf';
			OpenPDFWindow(fileName);
			break;
		//** SECTION PROJECT **//		
		case 'sp':
			var fileName = BuildFileName(thePrefix, theNumber, '.pdf');
			OpenSPWindow(fileName);
			break;	
		//** MATH ARTCILES **//		
		case 'ma':
			var file = thePrefix + theNumber;
			OpenPDFWindow(mathArticleFolder + file + '.pdf');
			break;	
		//** EDITABLE GRAPHS **//	
		case 'eg':
			OpenEditWindow(editableGraphFolder + theNumber + '.html');
			break;
		//** SECTION CONTENTS TEXT **//	
		case 'sc':
			var fileName = BuildFileName(thePrefix, theNumber, '.pdf');
			OpenIntTextWindow(fileName);
			break;		
		//** GRAPHING CALCULATOR PROGRAMS **//	
		case 'gc':
			GetGCP(theNumber);
			break;			
	}
}

//**********************************************************************************/
// THIS FUNCTION WILL CONTROL EACH PAGE LOADING FROM THE EDUSPACE SECTION LIST
//**********************************************************************************/
function LoadListFeature(pageTypeAndNumber, bookID){
		
	var thePrefix = GetItem(pageTypeAndNumber, '_', 0);
	var theNumber = GetItem(pageTypeAndNumber, '_', 1);
				
	switch(thePrefix){
		//** EXPLORE IT FIRST, LOOK AHEAD, CONNECTIONS, MATH TRENDS **//
		case 'ef': case 'lk': case 'ct': case 'mt':
			var fileName = BuildSectionListFileName(thePrefix, theNumber, '.html');
			OpenLargeTextWindow(fileName);
			break;
		//** SECTION INTERACTIVE TEXT **//	
		case 'sc':
		if ((bookID != null) && (checkAltTextContent(null, gChapterSection))) {
			var fileName = BuildSectionListFileName(thePrefix, theNumber, bookID + '.pdf');
		} else {
			var fileName = BuildSectionListFileName(thePrefix, theNumber, '.pdf');
		}
			OpenIntTextWindow(fileName);
			break;	
		//** GRAPHING CALCULATOR PROGRAMS **//	
		case 'gc':
			GetGCP(theNumber);	
	}
}

//****************************************************************************/
// THIS FUNCTION IS CALLED FROM THE SECTION FEATURES INDEX DROP LIST.
// IT IS USED TO NAVIGATE TO THE APPROPRIATE FEATURE IN THE INDEX.
//****************************************************************************/
function ChooseSectionFeature(value){
	
	var page = parent.frames[1].document.location.href;
	
	var splitPage = page.split('#');	
	var pageAndAnchor = splitPage[0] + '#' + value;
			
	parent.frames[1].document.location.replace(pageAndAnchor);
}

//****************************************************************************************/
// THIS FUNCTION WILL BUILD THE FILE NAME GIVEN THE NUMBER, PREFIX, AND EXTENSION
// FOR LINKS ON THE SECTION LIST IN EDUSPACE.
//****************************************************************************************/
function  BuildSectionListFileName(thePrefix, theNumber, extension){

	//*** MAKE IT A 2 DIGIT NUMBER ***//
	if((theNumber + "").length == 1){ theNumber = "0" + theNumber;} 

	var theChapter = gChapterSection.substr(0,2);
	var fileName = serverRoot + theChapter + '/' + gChapterSection + '/' + thePrefix + gChapterSection + theNumber + extension;
		
	return fileName;		
}	

//****************************************************************************************/
// THIS FUNCTION WILL BUILD THE FILE NAME GIVEN THE NUMBER, PREFIX, AND EXTENSION.
//****************************************************************************************/
function  BuildFileNameWithSuffix(thePrefix, theNumber, extension){
	
	//*** MAKE IT A 3 DIGIT NUMBER ***//
	if((theNumber + "").length == 1){ theNumber = "00" + theNumber;} 
	else if ((theNumber + "").length == 2) { theNumber = "0" + theNumber;} 

	var currentFile = document.location.href;	
	currentFile = GetItem((GetFileName(currentFile)), ".", 0);
	var fileProperties = new SetFileProperties(currentFile);
		
	var theChapter = fileProperties.stringChapter;
	var theSection = fileProperties.section;
			
	
	var fileName = fileProperties.directory + thePrefix + theChapter + theSection + "01" + theNumber + extension;
	
	return fileName;		
}	

//****************************************************************************************/
// THIS FUNCTION WILL BUILD THE FILE NAME GIVEN THE NUMBER, PREFIX, AND EXTENSION.
//****************************************************************************************/
function  BuildFileName(thePrefix, theNumber, extension){

	//*** MAKE IT A 2 DIGIT NUMBER ***//
	if((theNumber + "").length == 1){ theNumber = "0" + theNumber;} 
	
	var currentFile = document.location.href;	
	currentFile = GetItem((GetFileName(currentFile)), ".", 0);
	var fileProperties = new SetFileProperties(currentFile);
		
	var theChapter = fileProperties.stringChapter;
	var theSection = fileProperties.section;
			
	var fileName = fileProperties.directory + thePrefix + theChapter + theSection + theNumber + extension;
	
	return fileName;		
}	

//****************************************************************************************/
// THIS FUNCTION WILL BUILD THE FILE NAME GIVEN THE NUMBER, PREFIX, AND EXTENSION.
// THIS FUNCTION DOES NOT BUILD THE FILE NAME WITH THE FULL PATH.
//****************************************************************************************/
function  BuildOEFileName(thePrefix, theNumber, extension){
	
	//*** MAKE IT A 3 DIGIT NUMBER ***//
	if((theNumber + "").length == 1){ theNumber = "00" + theNumber;} 
	else if ((theNumber + "").length == 2) { theNumber = "0" + theNumber;} 

	var currentFile = document.location.href;	
	currentFile = GetItem((GetFileName(currentFile)), ".", 0);
	var fileProperties = new SetFileProperties(currentFile);
		
	var theChapter = fileProperties.stringChapter;
	var theSection = fileProperties.section;
			
	
	var fileName = thePrefix + theChapter + theSection + "01" + theNumber + extension;
	
	return fileName;		
}	


//************************************************************************************************//
//************************************************************************************************//
//************* OPEN WINDOW FUNCTIONS ***********************************************************//
//************************************************************************************************//
//************************************************************************************************//

//****************************************************************************/
// THIS FUNCTION OPEN THE TEXT WINDOW WITH THE CONTENTS OF THE GIVEN FILE
//****************************************************************************/
function OpenTextWindow(windowName){
  	PopUpTextWin = window.open(windowName, "TextWindow", "width=600,height=420,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  	PopUpTextWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE LARGE TEXT WINDOW WITH THE CONTENTS OF THE GIVEN FILE
//****************************************************************************/
function OpenLargeTextWindow(windowName){
  	PopUpLargeTextWin = window.open(windowName, "LTextWindow", "width=750,height=570,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  	PopUpLargeTextWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE ANSWER WINDOW WITH THE CONTENTS OF THE GIVEN FILE
//****************************************************************************/
function OpenAnswerWindow(windowName){
  	PopUpAnswerWin = window.open(windowName, "AnswerWindow", "width=600,height=420,top=100,left=100,menubar=0,toolbar=0,scrollbars,status,resizable");
  	PopUpAnswerWin.focus();
}


//****************************************************************************/
// THIS FUNCTION OPEN THE PDF WINDOW WITH THE CONTENTS OF THE GIVEN FILE
//****************************************************************************/
function OpenPDFWindow(windowName){
  PopUpPDFWin = window.open(windowName, "PDFWindow", "width=750,height=570,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpPDFWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE PDF WINDOW WITH THE CONTENTS OF THE SECTION PROJECT
//****************************************************************************/
function OpenSPWindow(windowName){
  PopUpSPWin = window.open(windowName, "SPWindow", "width=750,height=570,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpSPWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE PDF WINDOW WITH THE CONTENTS OF THE INTERACTIVE TEXTBOOK
//****************************************************************************/
function OpenIntTextWindow(windowName){
  PopUpIntTextWin = window.open(windowName, "InteractiveTextbook", "width=750,height=570,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpIntTextWin.focus();
}

//**************************************************************************************/
// THIS FUNCTION OPEN THE CALCULATOR PROGRAM WINDOW WITH THE CONTENTS OF THE GIVEN FILE
//**************************************************************************************/
function OpenCPWindow(){
  PopUpCPWin = window.open("", "CPWindow", "width=510,height=550,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpCPWin.focus();
}

//********************************************************************************/
// THIS FUNCTION OPEN THE SIMULATION WINDOW WITH THE CONTENTS OF THE GIVEN FILE.
//********************************************************************************/
function OpenSimWindow(windowName){
  PopUpSimWin = window.open(windowName, "SimulationWindow", "width=670,height=420,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpSimWin.focus();
}

//*************************************************************************************/
// THIS FUNCTION OPEN THE EDITABLE GRAPH WINDOW WITH THE CONTENTS OF THE GIVEN FILE.
//*************************************************************************************/
function OpenEditWindow(windowName){
  PopUpEditWin = window.open(windowName, "GraphExploreWindow", "width=400,height=500,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpEditWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE LAB WINDOW WITH THE CONTENTS OF THE GIVEN FILE
// CALC LAB INTERMEDIATE FILE
//****************************************************************************/
function OpenLabWindow(windowName){
  PopUpLabWin = window.open(windowName, "CalcLabWindow", "width=630,height=420,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpLabWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE ANIMATION WINDOW.
//****************************************************************************/
function OpenAnimWindow(windowName){
  PopUpAnimWin = window.open(windowName, "AnimationWindow", "width=350,height=350,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpAnimWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE VIDEO WINDOW.
//****************************************************************************/
function OpenVideoWindow(windowName){
  PopUpVideoWin = window.open(windowName, "VideoWindow", "width=600,height=420,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpVideoWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPEN THE CAS WINDOW.
//****************************************************************************/
function OpenCASWindow(){
  PopUpCASWin = window.open("", "CASWindow", "width=600,height=150,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpCASWin.focus();
}

//****************************************************************************/
// THIS FUNCTION OPENS THE OPEN EXPLORATION INTERMEDIATE WINDOW.
//****************************************************************************/
function OpenExploreWindow(){
  PopUpOEWin = window.open("", "OpenExploreWindow", "width=600,height=420,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpOEWin.focus();
}

//****************************************************************************/
//****************************************************************************/
function OpenSolutionWindow(windowName){
  PopUpSolWin = window.open(windowName, "SolutionWindow", "width=600,height=420,top=50,left=50,menubar=0,toolbar=0,scrollbars,status,resizable");
  PopUpSolWin.focus();
}

//************************************************************************************************//
//************************************************************************************************//
//************* UTILITIES ************************************************************************//
//************************************************************************************************//
//************************************************************************************************//

//****************************************************************************************/
// THIS FUNCTION WILL SET SPECIFIC PROPERTIES OF A FILE, GIVEN THE FILE NAME.
//****************************************************************************************/
function SetFileProperties(nameString){

	this.prefix		    =	nameString.substring(0,2);							// FILE NAME PREFIX	
	this.chapter		=	parseInt(nameString.substring(2,4),10); 			// 1 INTERACTIVE CHAPTER WITHOUT LEADING ZERO
	this.section		=	nameString.substring(4,5); 							// a INTERACTIVE SECTION LETTER 	
	this.sectionNumber	=	this.section=="z"?0:parseInt(this.section,36)-9;	// a = 1 returns 1
	this.stringChapter	=	this.chapter<10?'0'+this.chapter:this.chapter; 		// 01 INTERACTIVE CHAPTER WITH LEADING ZERO
	this.directory		=	SetDirectory(this.stringChapter,this.section); 		// FILE DIRECTORY STRUCTURE
}

//****************************************************************************************/
// THIS FUNCTION SETS THE DIRECTORY FOR THE CHAPTER.
//****************************************************************************************/
function SetDirectory(theStringChapter,theSection){
	var theDirectory
	
	theDirectory = serverRoot + theStringChapter + '/' + theStringChapter + theSection +'/';

	return theDirectory;
}

//****************************************************************************************/
// THIS FUNCTION RETURNS AN ITEM FROM A STRING GIVEN THE STRING, THE DELIMITER, AND 
// WHAT ITEM NUMBER OF THE STRING.  
//****************************************************************************************/
function GetItem(theString, theDelimiter, whichItem){
	var itemArray = theString.split(theDelimiter);
	
	if(whichItem == "last"){
		itemArray.reverse();
		var theItem = itemArray[0];
	} else {
		var theItem = itemArray[whichItem];
	}
  
  	return theItem;

}

//****************************************************************************************/
// THIS FUNCTION RETURNS THE FILE NAME GIVEN THE WHOLE PATH.
//****************************************************************************************/
function GetFileName(fileNamePath){
	var pathArray = fileNamePath.split("/");
	pathArray.reverse();
	var fileName = pathArray[0];

	return fileName;

}

//************************************************************************************************//
//************************************************************************************************//
//************* GRAPHING CALCULATOR PROGRAMS *****************************************************//
//************************************************************************************************//
//************************************************************************************************//
function GetGCP(program){
	
	// 82 PROGRAM NAME NEEDS TO BE UPPERCASE
	//var ucprogram = program.toUpperCase();
	var ucprogram = program;
	
	var data = '<html><head><title>Open Exploration</title><link rel="stylesheet" TYPE="text/css" href="' + serverRoot + 'calc8e_style.css">\n';
		data += '<script language="JavaScript" SRC="' + serverRoot + 'control.js' + '"></script>\n</head>\n<body bgcolor="white" class="centerscreen">';
		data += '<br>';
		data += '<br>';
		data += '<TABLE ALIGN="center">';
		data += '<TR><TD>';
		data +=	'<TABLE WIDTH="490" CELLSPACING="0" CELLPADDING="0" BORDER="0" BGCOLOR="#FFFFFF">';
		data +=	'<TR WIDTH="490"><TD WIDTH="160">&nbsp;</TD><TD WIDTH="10">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD></TR>';
		data +=	'<TR WIDTH="490"><TD WIDTH="10">&nbsp;</TD><TD COLSPAN="3"><IMG SRC="' + serverRoot + 'images/gc/graphprograms_hed.gif"></TD></TR>';
		data +=	'<TR WIDTH="490"><TD WIDTH="160">&nbsp;</TD><TD WIDTH="10">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD></TR>';
		data +=	'<TR WIDTH="490"><TD WIDTH="10">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD></TR>';
		data += '<TR WIDTH="490">';
		data += '<TD WIDTH="10">&nbsp;</TD>';
		data += '<td class="contenttitle" colspan="3">With the appropriate software and hardware, you can <b>download</b> one of the following Graphing Calculator Programs to your computer.';
		data += '<br> ';
		data += '<br> ';
		data += 'For directions on how to download the program, first click on an option listed below based on your Browser Type and Operating System. ';
		data += '<ul> ';
		data += '<li><a href="javascript:OpenTextWindow(' + "'" + serverRoot + "tools.html#IEW'" + ');">Microsoft&reg; Internet Explorer on Microsoft&reg; Windows&reg;</a> ';
		data += '<li><a href="javascript:OpenTextWindow(' + "'" + serverRoot + "tools.html#NW'" + ');">Firefox&reg; on Microsoft&reg; Windows&reg;</a> ';
		data += '<li><a href="javascript:OpenTextWindow(' + "'" + serverRoot + "tools.html#IEM'" + ');">Microsoft&reg; Internet Explorer on Mac&reg;</a> ';
		data += '<li><a href="javascript:OpenTextWindow(' + "'" + serverRoot + "tools.html#SF'" + ');">Safari&reg; on Macintosh&reg;</a> ';
		data += '<li><a href="javascript:OpenTextWindow(' + "'" + serverRoot + "tools.html#NM'" + ');">Firefox&reg; on Macintosh&reg;</a> ';
		data += '</ul> ';
		data += '<td>';	
		data += '</TR>';
		data += '<TR WIDTH="490"><TD WIDTH="160">&nbsp;</TD><TD WIDTH="10">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD></TR>';
		
		data += '<TR WIDTH="490">';
		data += '<TD WIDTH="10">&nbsp;</TD>';
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + '82/'+ ucprogram +'.82p"><IMG SRC="' + serverRoot + 'images/gc/82t_icon.jpg" BORDER="0"></A></TD>';
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + '83/'+ program +'.83p"><IMG SRC="' + serverRoot + 'images/gc/83t_icon.jpg" BORDER="0"></A></TD>';
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + '83_plus/'+ program +'.8xp"><IMG SRC="' + serverRoot + 'images/gc/83x_icon.jpg" BORDER="0"></A></TD>';
		data += '</TR>';
		
		data += '<TR WIDTH="490"><TD WIDTH="10">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD<TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD></TR>';
		
		data += '<TR WIDTH="490"><TD WIDTH="10">&nbsp;</TD>';
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + '86/'+ program +'.86p"><IMG SRC="' + serverRoot + 'images/gc/86t_icon.jpg" BORDER="0"></A></TD>';
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + '89/'+ program +'.89p"><IMG SRC="' + serverRoot + 'images/gc/89t_icon.jpg" BORDER="0"></A></TD>';	
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + '92/'+ program +'.92p"><IMG SRC="' + serverRoot + 'images/gc/92t_icon.jpg" BORDER="0"></A></TD>';
		data += '</TR>';
		
		data += '<TR WIDTH="490"><TD WIDTH="10">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD><TD WIDTH="160">&nbsp;</TD></TR>';
		data += '<TR WIDTH="490"><TD WIDTH="10">&nbsp;</TD>';
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + '92_plus/'+ program +'.9xp"><IMG SRC="' + serverRoot + 'images/gc/92x_icon.jpg" BORDER="0"></A></TD>';
		data += '<TD WIDTH="160" align="middle"><A HREF="' + gcpFolder + 'voyage_200/main.'+ program +'.v2p"><IMG SRC="' + serverRoot + 'images/gc/v_icon.jpg" BORDER="0"></A></TD>';
		data += '<TD WIDTH="160" align="middle">&nbsp;</TD>';
		data += '</TR></TABLE></TD></TR>';
		data += '</TABLE>';
		
	data += '</body></html>';
	
	OpenCPWindow();	
    PopUpCPWin.document.write(data);
	PopUpCPWin.document.close();}

//************************************************************************************************//
//************************************************************************************************//
//************* CALCULUS LABS ********************************************************************//
//************************************************************************************************//
//************************************************************************************************//

//****************************************************************************************/
// THIS FUNCTION CALLS ALL FUNCTIONS TO DISPLAY THE APPROPRIATE CAS FOR THE 
// CALCULUS LAB.
//****************************************************************************************/
function DisplayLabs(file){
	var fileName = GetPDFFileNameForLabCAS(file) // PDF
	var dataFile = GetDataFileNameForLabCAS(file) // DATA FILE
	var labNumber = GetLabNumber(file);
	var artIcon = GetArtIconForCAS(file);
	
	OpenPDFWindow(fileName);
	
  	WriteToCASLabWindow(dataFile, labNumber, artIcon);
	
	//** DERIVE HAS A TEXT FILE THAT NEEDS TO BE OPENED **//
	if((file.substr(5,3)) == 'der'){
		var txtFile = GetTXTFileNameForLabCAS(file); // TEXT FILE
		OpenTextWindow(txtFile);
	}
}

//****************************************************************************************/
// THIS FUNCTION WILL RETURN THE PDF FILE NAME FOR THE APPROPRIATE CAS ON THE 
// CALC LAB PAGE. WE PARSE THE GIVEN FILE NAME TO GET THE PATH AND THE PDF FILE NAME.
//****************************************************************************************/
function GetPDFFileNameForLabCAS(file){
	
	var theFolder = (file.substr(5,3)) + "/pdf/";
	var thePath = calcLabFolder + theFolder;
	var pdfName = thePath + (GetItem(file, ".", 0)) + ".pdf";
	
	return pdfName;
}

//****************************************************************************************/
// THIS FUNCTION WILL RETURN THE TXT FILE NAME FOR THE APPROPRIATE CAS ON THE 
// CALC LAB PAGE. WE PARSE THE GIVEN FILE NAME TO GET THE PATH AND THE TXT FILE NAME.
//****************************************************************************************/
function GetTXTFileNameForLabCAS(file){
		
	var theFolder = (file.substr(5,3)) + "/txt/";
	var thePath = calcLabFolder + theFolder;
	var pdfName = thePath + (GetItem(file, ".", 0)) + ".txt";
	
	return pdfName;
}

//****************************************************************************************/
// THIS FUNCTION WILL RETURN THE DATA FILE NAME FOR THE APPROPRIATE CAS ON THE CALC
// LAB PAGE. WE PARSE THE GIVEN FILE NAME TO GET THE PATH AND THE CAS FILE NAME.
//****************************************************************************************/
function GetDataFileNameForLabCAS(file){
	var dataName;
	
	// IF TRYING TO ACCESS A MATHCAD FILE ACCESS THE PLATFORM SPECIFIC FOLDER
	if(file.substr(5,3) == 'mcd'){
		var thisPlatform = "_" + thePlatform;
	}else{
		var thisPlatform = "";
	}
	
	var theFolder = (file.substr(5,3)) + "/" + (GetItem(file, ".", 1)) + thisPlatform +  "/";
	dataName = calcLabFolder + theFolder + file;

	return dataName;
}

//****************************************************************************************/
// THIS FUNCTION PARSES THE FILE NAME TO GET THE LAB NUMBER.
//****************************************************************************************/
function GetLabNumber(file){

	if(file.substr(3,1) == '0'){
		return (file.substr(4,1));
	}else{
		return (file.substr(3,2));
	}
}

//****************************************************************************************/
// THIS FUNCTION DYNAMICALLY WRITES THE HTML TO THE OPEN WINDOW OBJECT TO LINK TO THE
// CAS LAB FILE.
//****************************************************************************************/
function WriteToCASLabWindow(dataFile, labNumber, artIcon){
    
	var theData = '<html>\n<title> CAS Lab Data </title>\n<head>\n';
  	theData += '</head>\n';
  	theData += '<body bgcolor=#ffffff MARGINWIDTH="0" MARGINHEIGHT="0" bgcolor="#FFFFFF">\n<center>\n<br>\n';
  	theData += '<table><tr><td>\n';
  	theData += '<img src="' + artIcon + '">\n<br>\n';
  	theData += 'Click here to access the&nbsp;<a href="' + dataFile + '">Data File for Lab ' + labNumber +'</a>.';
  	theData += '</td></tr></table>\n';
  	theData += '</body>\n</html>';
  	
  	OpenCASWindow();
    PopUpCASWin.document.write(theData);
	PopUpCASWin.document.close();

}

///*************************///
///*** OPEN EXPLORATIONS ***///
///*************************///

//****************************************************************************************/
// THIS FUNCTION DYNAMICALLY CREATES THE OPEN EXPLORATION INTERMEDIATE PAGE HTML.
//****************************************************************************************/
function GetOpenExplorePage(chapter, section, number){
	
	var data = '<html><head><title>Open Exploration</title><link rel="stylesheet" TYPE="text/css" href="' + serverRoot + 'calc8e_style.css">\n';
	data += '<script language="JavaScript" SRC="' + serverRoot + 'control.js"></script>\n</head>\n<body bgcolor="white" class="centerscreen">';
	data += '<br>';

	data +=	'<table border="0" width="490" cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF">';
	data +=	'<tr width="490"><td width="10">&nbsp;</TD><TD COLSPAN="4"><IMG SRC="' + serverRoot + 'images/oe/openxploration_head.jpg"></td></tr>';
	
	data += '<tr width="490">';
		data += '<td width="10">&nbsp;</TD>';
		data += '<td class="contenttitle" colspan="4">Select one of the computer algebra systems below to further investigate the example.</td>';
	data += '</tr>';
	
	data += '<tr width="490">';
		data += '<td colspan="5">&nbsp;</TD>';
	data += '</tr>';	
		
	data += '<tr width="490">';
		data += '<td width="10">&nbsp;</TD>';
		data += '<td width="120"><A HREF="javascript:LoadPopUpWindow(' + "'" + chapter + section + 'cas' + number + '02.mth' + "'" + ');"><IMG SRC="' + serverRoot + 'images/oe/derive_btn.jpg" BORDER="0"></A></td>';
		data += '<td width="120"><A HREF="javascript:LoadPopUpWindow(' + "'" + chapter + section + 'cas' + number + '01.mws' + "'" + ');"><IMG SRC="' + serverRoot + 'images/oe/maple_btn.jpg" BORDER="0"></A></td>';
		data += '<td width="120"><A HREF="javascript:LoadPopUpWindow(' + "'" + chapter + section + 'cas' + number + '01.mcd' + "'" + ');"><IMG SRC="' + serverRoot + 'images/oe/mathcad_btn.jpg" BORDER="0"></A></td>';
		data += '<td width="120"><A HREF="javascript:LoadPopUpWindow(' + "'" + chapter + section + 'cas' + number + '01.nb' + "'" + ');"><IMG SRC="' + serverRoot + 'images/oe/mathematica_btn.jpg" BORDER="0"></A></td>';
	data += '</tr>';
	
	data += '</TABLE>';
	
	data += '</body></html>';
		
	OpenExploreWindow();	
	PopUpOEWin.document.write(data);
	PopUpOEWin.document.close();

}

//****************************************************************************************/
// THIS FUNCTION CALLS ALL FUNCTIONS TO DISPLAY THE APPROPRIATE CAS FOR THE 
// OPEN EXPLORATIONS.
//****************************************************************************************/
function DisplayOE(file){

	var chapter = file.substr(0,2);
	var section = file.substr(2,1);
	var number = file.substr(6,2);
	var extension = GetItem(file, '.', 'last');
	
	// LAST TWO ITEMS IN THE CASE FILE NAME BEFORE THE EXTENSION.
	// 03 CAS FILES ARE ACCESSED FROM PAGES OTHER THAN CONCEPTS. FOR EXAMPLE LOOK AHEADS.
	// 01 AND 02 CAS FILES ARE ACCESSED FROM THE CONCEPT PAGES. DERIVE FILES HAVE 02 THE
	// REST OF THE CAS FILES HAVE 01.
	if((file.substr(8,2)) == '03' && extension != 'mth'){ // IF CAS ACCESSED FROM A PAGE OTHER THAN A CONCEPT PAGE AND IS NOT DERIVE
		var pdfFileName = ''; // THERE IS NO PDF FILE
	}else{ // ALL OTHER FILES HAVE A PDF
		var pdfFileName = openExploreFolder + chapter + '/' + chapter + 'pdf/' + GetItem(file, '.', 0) + '.pdf';
	  	OpenPDFWindow(pdfFileName);
	}
	
	// IF TRYING TO ACCESS A MATHCAD FILE ACCESS THE PLATFORM SPECIFIC FOLDER
	if(extension == 'mcd'){
		var dataFileName = openExploreFolder + chapter + '/' + chapter + extension + '_' + thePlatform + '/' + chapter + section + 'cas' + number + '.' + extension;
	}else{
		var dataFileName = openExploreFolder + chapter + '/' + chapter + extension + '/' + chapter + section + 'cas' + number + '.' + extension;
	}
		
	var artIcon = GetArtIconForCAS(file);	
	
  	WriteToCASOEWindow(dataFileName, artIcon);
  	
}

//****************************************************************************************/
// THIS FUNCTION DYNAMICALLY WRITES THE HTML TO THE OPEN WINDOW OBJECT TO LINK TO THE
// CAS FILE.
//****************************************************************************************/
function WriteToCASOEWindow(dataFile, artIcon){
    
	var theData = '<html>\n<head>\n<title>CAS Data</title>\n';
  	theData += '<body bgcolor=#ffffff MARGINWIDTH="0" MARGINHEIGHT="0" bgcolor="#FFFFFF">\n<center>\n<br>\n';
  	theData += '<table><tr><td>\n';
  	theData += '<img src="' + artIcon + '">\n<br>\n';
  	theData += 'Click here to access the&nbsp;<a href="' + dataFile + '">Data File' + '</a> for this exploration.';
  	theData += '</td></tr></table>\n';
  	theData += '</body>\n</html>';
  	
  	OpenCASWindow();
    PopUpCASWin.document.write(theData);
	PopUpCASWin.document.close();

}

//****************************************************************************************/
// THIS FUNCTION WILL RETURN THE ART ICON NAME FOR THE APPROPRIATE CAS ON THE OPEN
// EXPLORATION PAGE AND CALCULUS LAB PAGE. 
// WE PARSE THE GIVEN FILE NAME TO GET THE PATH AND THE CAS ART ICON NAME.
//****************************************************************************************/
function GetArtIconForCAS(file){

	var iconName = (GetItem(file, ".", 1));
	
	return serverRoot + 'images/labs/' + iconName + '_icon.gif';
}

//****************************************************************************************/
// THIS FUNCTION BUILDS THE LOOK AHEAD CAS FILE WHEN NEEDED.
// THIS FUNCTION IS USED FOR LOOK AHEADS THAT ARE RUN THROUGH THE NEW CONVERSION
// AND DO NOT HAVE THE EXACT FILE NAME HARDCODED INTO THE DOCUMENT.
//****************************************************************************************/
function BuildLookAheadCASFile(file){

	var chapter = file.substr(0,2);
	var section = file.substr(2,1);
	var number = file.substr(7,1);
	
	switch(number){
		case '1':
			var extension = '.mth';
			break;
		case '2':
			var extension = '.mws';
			break;
		case '3':
			var extension = '.mcd';
			break;
		case '4':
			var extension = '.nb';
			break;
	}
	
	// SECTION 10a IS THE ONLY SECTION THAT THE CAS NUMBER IS 04
	if(chapter == '10' && section == 'a'){
		var theCASNumber = '04';
	}else{
		var theCASNumber = '02';
	}
		
	return chapter + section + 'cas' + theCASNumber + '03' + extension;

}

//****************************************************************************************/
//****************************************************************************************/
//********************************** SOLUTION ********************************************/
//****************************************************************************************/
//****************************************************************************************/


// INTERACTIVE CHAPTER NUMBER IS THE INDEX FOR THE NUMBER OF SECTIONS	
// THE NUMBER OF SECTIONS INCLUDES THE REVIEW EXERCISES AND PROBLEM SOLVING EXERCISES	
// AND STARTS AT 0. 				
var numOfSections = [5,6,7,10,7,9,5,8,9,11,7,8,6,11,9,9,0,0,0,0,0,7,6,9,9,10,7];
                    

/****************************************************************************************************************/
// THIS FUNCTION WILL LOAD THE EXERCISE PAGE BUILT FROM THE GIVEN PARAMETERS IN THE MAIN FILE.
// THIS FUNCTION ALSO CALLS THE setOptionsListOnLoad FUNCTION TO BUILD THE SECTION OPTION LIST.
// THIS FUNCTION IS CALLED ON THE ONLOAD OF THE SOLUTION MAIN FILE. - calc8e_solution_main.html
/****************************************************************************************************************/
function LoadExercise(){

	var theTopicNumber = GetTopicNumber(gTheType);
	
	// BUILD EXERCISE FILE NAME - SECTION, REVIEW, OR PROBLEM SOLVING
	//Check for Alternate content for ETF - BZ 02/13/06
	if ((inETF == 1) && (checkAltContent(gTheChapter, gTheSection))) {
		var filename = gTheChapter + '/' + gTheChapter + gTheSection + '/' + gTheType + gTheChapter + gTheSection + theTopicNumber + 'etf.html';
	} else {
		var filename = gTheChapter + '/' + gTheChapter + gTheSection + '/' + gTheType + gTheChapter + gTheSection + theTopicNumber + '.html';
	}
	
	// FIRST POPULATE THE FRAME WITH THE EXERCISE PAGE BUILT FROM THE GIVEN PARAMETERS IN THE MAIN FILE
	parent.frames[1].location.replace(filename);
	// PASS OPTIONS LIST SO WE CAN BUILD THE SECTION OPTIONS LIST FOR THE CORRESPONDING CHAPTER
	setOptionsListOnLoad(gTheChapter + "", gTheSection, gTheType);
}

/****************************************************************************************************************/
// THIS FUNCTION WILL CHECK FOR ALTERNATE EXERCISE PAGE CONTENT.
// THIS ALLOWS THE DROP DOWN LIST NAVIGATION TO WORK WITH ETF 4E CONTENT THAT IS DIFFERENT FROM CALC 8E
// THE EXERCISE PAGE COULD ALSO BE CALLED FROM A SPECIAL LINK OR FROM THE INDEX
/****************************************************************************************************************/
function checkAltContent(chapter, section) {	
	//LIST OF SECTIONS WITH ALTERNATE CONTENT IN THEIR EXERCISE PAGES.  BZ - 02/20/06
	var altList = new Array("07d", "08g", "09j", "13i");
	
	var chapSect = (chapter != null ? chapter + section : section);
	
	var returnVal = 0;
	for (var i = 0; i < altList.length; i++) {
		if(chapSect == altList[i]) {
			returnVal = 1
			break;
		}
	}
	return returnVal;
}


/****************************************************************************************************************/
// THIS FUNCTION WILL CHECK FOR ALTERNATE EXERCISE PAGE CONTENT.
// THIS ALLOWS THE DROP DOWN LIST NAVIGATION TO WORK WITH ETF 4E CONTENT THAT IS DIFFERENT FROM CALC 8E
// THE EXERCISE PAGE COULD ALSO BE CALLED FROM A SPECIAL LINK OR FROM THE INDEX
/****************************************************************************************************************/
function checkAltTextContent(chapter, section) {	
	//LIST OF SECTIONS WITH ALTERNATE CONTENT IN THEIR EXERCISE PAGES.  BZ - 02/20/06
	var altList = new Array("07b", "07g", "08g", "09a", "12a", "12b", "13b", "13d", "13e", "13f", "13h", "13j");
	
	var chapSect = (chapter != null ? chapter + section : section);
	
	var returnVal = 0;
	for (var i = 0; i < altList.length; i++) {
		if(chapSect == altList[i]) {
			returnVal = 1
			break;
		}
	}
	return returnVal;
}

/*****************************************************************************************/
// THIS FUNCTION WILL SET THE SELECTED OPTION OF THE CHAPTER DROP LIST.
// THIS FUNCTION IS CALLED ON THE ONLOAD OF THE NAVFRAME. - nav_frame.html
/*****************************************************************************************/
function SelectChapter(){
	
	var chapterNum = parseInt(parent.gTheChapter,10);
	
	if(chapterNum > 20) {
		chapterNum = chapterNum - 20;
	}
	
	if (parent.inETF) {
		document.frm1.selA.options[chapterNum - 1].selected = true;
	} else {
		document.frm1.selA.options[chapterNum - 0].selected = true;
	}
}

/*****************************************************************************************/
// THIS FUNCTIO BUILDS THE LABELS AND VALUES FOR THE SECTION OPTIONS LIST
// BASED ON THE CHAPTER NUMBER SENT FROM THE CHAPTER OPTIONS LIST.
// THIS FUNCTION IS CALLED FROM THE CHAPTER OPTIONS LIST/CHAPTER DROPLIST.
/*****************************************************************************************/
function setOptionsListFromDropList(chapterNumber){
	
	// CHANGE STRING INTERACTIVE CHAPTER TO NUMBER TO BE USED WHEN INDEXING
	var integerChapter = parseInt(chapterNumber,10); 
	var numOfSections = SetSectionNumbers(integerChapter);
	
	// BUILD EXERCISE FILE NAME - SECTION, REVIEW, OR PROBLEM SOLVING
	//Check for Alternate content for ETF - BZ 02/13/06
	if ((parent.inETF == 1) && (checkAltContent(chapterNumber, "a"))) {
		chapterNumber + '/' + chapterNumber + 'a/se' + chapterNumber + 'a01etf.html';
	} else {
		var filename = chapterNumber + '/' + chapterNumber + 'a/se' + chapterNumber + 'a01.html';	
	}
	
	// CHAPTER P IS NUMBER IS 0	- WE NEED TO DISPLAY P NOT 0
	if(integerChapter == 0){stringChapter = 'P';}
	else{ stringChapter = integerChapter; }

	// BUILD THE OPTION LIST LABELS AND VALUES
	var strLabels = CreateLabels(stringChapter, numOfSections);
	var strValues = CreateValues(chapterNumber, numOfSections, 'a', 'se');
	
	// CREATE THE HTML
	var data = getSelectData(strLabels, strValues);
	
	// POPULATE THE DIV TAG WITH THE SECTION OPTIONS LIST CONTENT
	var sectionList = parent.frames[0].document.getElementById("sectionlist");
	sectionList.innerHTML = data;
		
	// NOW POPULATE THE FRAME WITH THE EXERCISE PAGE 
	parent.frames[1].location.replace(filename);
	
}

//******************************************************************************************************************//
// THIS FUNCTION BUILDS THE LABELS AND VALUES FOR THE SECTION OPTIONS LIST 
// BASED ON THE CHAPTER NUMBER SENT FROM BLACKBOARD - EDUSPACE.
// THIS FUNCTION IS ONLY USED FROM THE BB INTERFACE
//******************************************************************************************************************//	
function setOptionsListOnLoad(chapterNumber, sectionLetter, theType){
		
	// CHANGE STRING INTERACTIVE CHAPTER TO INTEGER NUMBER TO BE USED WHEN INDEXING
	var integerChapter = parseInt(chapterNumber,10); 
	var numOfSections = SetSectionNumbers(integerChapter);	
		
	// CHAPTER P IS NUMBER IS 0	- WE NEED TO DISPLAY P NOT 0
	if(integerChapter == 0){var integerChapter = 'P';}
	
	// BUILD THE OPTION LIST LABELS AND VALUES
	var strLabels = CreateLabels(integerChapter, numOfSections);
	var strValues = CreateValues(chapterNumber, numOfSections, sectionLetter, theType);
	
	// CREATE THE HTML
	var data = getSelectData(strLabels, strValues);	
	
	// POPULATE THE DIV TAG WITH THE SECTION OPTIONS LIST CONTENT
	var sectionList = parent.frames[0].document.getElementById("sectionlist");
	sectionList.innerHTML = data;
	 
}//end setOptionsList



/****************************************************/
// THIS FUNCTION RETURNS THE VALUE OF THE PARAMETERS
/****************************************************/
function GetValue(paramName, keyValuePairs){
	
	// LOOP THROUGH THE KEY-VALUE PAIRS FOR THE VALUE 
	value = '';
	for ( var i = 0; i < keyValuePairs.length; i++ ) {
		if ( keyValuePairs[i].slice(0, keyValuePairs[i].indexOf('=')) == paramName ) {
		value = keyValuePairs[i].slice(keyValuePairs[i].indexOf('=') + 1);
		break;
		}
	}
	
	// RETURN VALUE FROM KEY-VALUE PAIR 
	return (value.length > 0 ? unescape(value).split(',') : '');		
}

//****************************************************************************************/
// THIS FUNCTION SETS THE NUMBER OF SECTIONS GIVEN THE CHAPTER NUMBER.
// THE CHAPTER NUMBER ACTS AS AN INDEX FOR THE numOfSections ARRAY.
//****************************************************************************************/
function SetSectionNumbers(theChapter){

	return numOfSections[theChapter];
	    
}

//*********************************************************************//
// THIS FUNCTION BUILDS AN ARRAY OF LABELS FOR THE SECTION OPTIONS LIST.
//*********************************************************************//
function CreateLabels(chapter, numOfSections){

	var strLabels = new Array((numOfSections-1))
	// TRANSLATE THE CHAPTER NUMBER TO THE NUMBER THAT IS TO BE DISPLAYED
	
	if(chapter > 20) {
		chapter = chapter - 20;
	}
	
	for(i=0; i<numOfSections-1 ; i++){
		strLabels[i] = "Section " + chapter + "." + (i + 1);
	}
		
	strLabels[numOfSections-1] = 'Chapter Review Exercises';
	strLabels[numOfSections] = 'Chapter Problem Solving Exercises';

	return(strLabels);
	
}
	
//*********************************************************************//
// THIS FUNCTION BUILDS AN ARRAY OF VALUES FOR THE SECTION OPTIONS LIST.
//*********************************************************************//
function CreateValues(chapter, numOfSections, sectionLetter, theType){
	
	// SET UP LIST OF SECTION LETTERS TO BE USED WHEN BUILDING THE FILE NAME
	var sectionValues = new Array('a','b','c','d','e','f','g','h','i','j');
	
	var strValues = new Array((numOfSections-1));
		
	for(i=0; i<numOfSections; i++){
		strValues[i] = '"se_' + chapter + '_' + sectionValues[i] + '"';
	}	
	
	strValues[numOfSections-1] = "re_" + chapter + '_' + 'z';
	strValues[numOfSections] = "ps_" + chapter + '_' + 'z';
		
	// IF WE ARE COMING FROM BLACKBOARD - EDUSPACE WE NEED TO SET THE SELECTED OF THE EXERCISE OPTION LIST
	if(sectionLetter != 'selA'){
		var sectionNumber	=	sectionLetter=="z"?0:parseInt(sectionLetter,36)-9;	// a = 1 returns 1
		
		if((sectionLetter == 'z') && (theType == 're')){ 
			strValues[numOfSections-1] = strValues[numOfSections-1] + ' selected'; // REVIEW EXERCISES SELECTED
		}else if((sectionLetter == 'z') && (theType == 'ps')){
			strValues[numOfSections] = strValues[numOfSections] + ' selected';		// PROBLEM SOLVING EXERCISES SELECTED
		}else{
			strValues[sectionNumber - 1] = strValues[sectionNumber - 1] + ' selected'; // OTHER SECTION SELECTED
		}	
	}
				
	return(strValues);

}

//*******************************************************************************************************************//
// THIS FUNCTION BUILDS THE SECTION OPTIONS LIST BASED ON THE VALUES IN THE LABELS AND VALUES ARRAYS.
//*******************************************************************************************************************//
function getSelectData(strLabels, strValues){
	
	var dataString = '<select name="selB" OnChange="DisplayExercisePage(this.options[this.selectedIndex].value);" width="250" style="width:250">';
	
	for(i=0; i< strLabels.length; i++){	
		dataString += '<option value=' + strValues[i] + '>' + strLabels[i] +'</option>\n';
	}
	
	dataString += '</select>';
	
	return dataString;	
}

//********************************************************************************************//
// THIS FUNCTION IS CALLED BY THE SECTION OPTIONS LIST/SECTION DROPLIST OF THE ESOLUTIONS
// DROPLIST INTERFACE.
//********************************************************************************************//
function DisplayExercisePage(value){
	
	// SPLIT VALUE BASED ON UNDERSCORE
	chapterSection = value.split('_');
	
	theType = chapterSection[0];
	theChapter = chapterSection[1];
	theSection = chapterSection[2];
			
	LoadExercisePage(theType, theChapter,theSection);
}

//********************************************************************************************//
// THIS FUNCTION WILL LOAD THE EXERCISE PAGE FROM THE ESOLUTIONS(DROPLIST) INTERFACE.
//********************************************************************************************//
function LoadExercisePage(theType, theChapter,theSection){

	var theTopicNumber = GetTopicNumber(theType);

	// BUILD EXERCISE FILE NAME - SECTION, REVIEW, OR PROBLEM SOLVING
	if ((parent.inETF == 1) && (checkAltContent(theChapter,theSection))) {
		var filename = theChapter + '/' + theChapter + theSection + '/' +theType + theChapter + theSection + theTopicNumber + 'etf.html';
	} else {
		var filename = theChapter + '/' + theChapter + theSection + '/' +theType + theChapter + theSection + theTopicNumber + '.html';
	}
	parent.frames[1].location.replace(filename);

}

//********************************************************************************************//
// THIS FUNCTION RETURNS THE TOPIC NUMBER GIVEN THE FILETYPE/PREFIX.
//********************************************************************************************//
function GetTopicNumber(theType){

	// GET TOPIC NUMBER FOR THE FILE TYPE
	// SECTION EXERCISES
	if(theType == 'se'){ return theTopicNumber = '01'; }
	// REVIEW EXERCISES
	else if (theType == 're'){ return theTopicNumber = '02'; }
	// PROBLEM SOLVING EXERCISES
	else{ return theTopicNumber = '03'; }

}