//----------------------------------------------------------------
//  ACTIVITY FUNCTIONS
//----------------------------------------------------------------

// used by the actmain, when user clicks on a chapter in the activity TOC
function SetChapOpenAndNavBar(whichChap) {
	if(whichChap != 0){
       chosenChapPath = "ch" + whichChap + "/ch" + whichChap
 		top.frames[0].location = chosenChapPath + 'nav.htm'
   		top.frames[1].location = chosenChapPath + 'open.htm'
 	}
}

//--------

// used by the actmain, when user clicks on a activity in the activity TOC
function SetActivityOpenAndNavBar(whichChap, whichActivity) {
   // set the chapter
	if(whichChap != 0){
       chosenChapPath = "ch" + whichChap  // ex. - ch01/ch01

 		top.frames[0].location = chosenChapPath + "/ch" + whichChap + 'nav.htm'
		// ex. - ch01/a01/s01/fr010101.html
    	top.frames[1].location = 
 			chosenChapPath + '/a' + whichActivity + '/s01/' + "fr" + whichChap + whichActivity + '01.htm'
	}
}

//--------

//used by activity pages when loading, to set the activity pull-down (based on doc name)
// if the doc is 120203.htm, this will set the activity pulldown to index 3 (4th element)
function SetActivityPullDown() {
   docName = new String(document.URL)
	activity = docName.substring(docName.length - 8, docName.length - 6)
	
	// check to see if the nav bar form exists yet
 	existsP = String(top.frames[0].document.forms[0].activity)

	if(existsP == "undefined") { // if it doesn't, recurse in 1 second.
		setTimeout("SetActivityPullDown()",1000)
	} else
 		top.frames[0].document.forms[0].activity.selectedIndex = Number(activity)
}
//--------

// used by the "chapter" pull down menu in the activity nav bar
function doActivityChapterChange() {
	chosenChapNdx = document.forms[0].chapter.selectedIndex
	chosenChapNum = document.forms[0].chapter.options[chosenChapNdx].value
   
	// we need to check if the calling nav bar is the activity nav or a chapter nav
	docPath = new String(document.URL)
   actNavPageP = docPath.indexOf("actnav") // will return -1 if chapter nav

	if(chosenChapNdx > 0){
		if(actNavPageP == -1) // if the current path is a chapter nav
      		chosenChapPath = "../ch" + chosenChapNum + "/" + "ch" + chosenChapNum
		else  // activity nav bar
      		chosenChapPath = "ch" + chosenChapNum + "/" + "ch" + chosenChapNum

     	parent.content.location = chosenChapPath + 'open.htm'
     	parent.navbar.location  = chosenChapPath + 'nav.htm'
	} else
  		parent.location = "../activity.htm"
}

//--------

// used by the "activity" pull down menu in the activity nav bar (used in all of the chapters)
function doActivityChange() {
	chosenChapNdx = document.forms[0].chapter.selectedIndex
	chosenChapNum = document.forms[0].chapter.options[chosenChapNdx].value

	chosenActNdx = document.forms[0].activity.selectedIndex
	chosenActNum = document.forms[0].activity.options[chosenActNdx].value

 	// set the content location to "a01/s01/fr010101.htm"
	if(chosenActNum > 0){ // if not the chapter opener chosen
   		chosenActPath = "a" + chosenActNum + "/s01/fr" + chosenChapNum + chosenActNum + "01.htm"
	} else  // user chose chapter opener
  		chosenActPath = "ch" + chosenChapNum + "open.htm"
 
 	// fill the content frame
   parent.content.location = chosenActPath
}

// opens an activity from the chapter overview page
function openActivityFromOverview(whichActivity) {
	docName = new String(document.URL)
 	whichChap = docName.substring(docName.length - 10, docName.length - 8)

	parent.content.location = "a" + whichActivity + "/s01/" + "fr" + whichChap + whichActivity + "01.htm"
}

// used by 140101 and 39..... to open a new window

function Start(page) {
     OpenWin = this.open(page, "NewWindow", "titlebar=no,width=606,height=388,directories=no,location=no,resizable=no,scrollbars=no,status=no,hotkeys=no,toolbar=no,personalbar=no,statusbar=no,locationbar=no,menubar=no,screenX=0,screenY=0");
}
//----------------------------------------------------------------
//   QUIZ FUNCTIONS
//----------------------------------------------------------------

// used by quiznav to choose the selected quiz
function openSelectedQuiz() {
  chosenQuizNdx = document.forms[0].quiz.selectedIndex
  chosenQuizNum = document.forms[0].quiz.options[chosenQuizNdx].value
  
	// if not the TOC chosen in pull down
	if(chosenQuizNdx > 0)
   		parent.content.location='q' + chosenQuizNum + '.htm'
	else // they chose TOC
		parent.location = "quiz.htm"
}

//-------

// used by quizMain to choose the selected quiz, and set navBar
function openQuizFromTOC(which) {
	top.frames[1].location = "q" + which + ".htm"
}

//-------

// Go to selected quiz from "quiz button" in Chapter overview
function openQuizFromChapOverview() {
	docName = new String(document.URL)
	chapNum = docName.substring(docName.length - 10, docName.length - 8)

	parent.navbar.location = "../../quiz/quiznav.htm"
	parent.content.location = "../../quiz/q" + chapNum + ".htm"
}

//used by quiz pages when loading, to set the quiz pull-down (based on doc name)
function setQuizPullDown() {
	docName  = new String(document.URL)
	quizNum  = docName.substring(docName.length - 6, docName.length - 4)
	
 	parent.navbar.document.forms[0].quiz.selectedIndex = Number(quizNum) //-- this had -1 in awbio 1
}

//----------------------------------------------------------------
// GLOSSARY FUNCTIONS
//----------------------------------------------------------------

// used by glonav to choose the selected letter.
function openSelectedLetter() {	
	chosenLetterNdx = document.forms[0].contents.selectedIndex
	chosenLetter    = document.forms[0].contents.options[chosenLetterNdx].value
       
	//load the word list in the proper frame
	parent.content.wordlist.location = "wordlist/" + chosenLetter + 'words.htm'
	// load the first word in the definition frame
	parent.content.definition.location = "words/" + chosenLetter + "words/" + chosenLetter + '1.htm'
}


