//********************************************************
// NavFunctionsV2.js
// Version 2 9/29/01
// 3 levels of navigation working
// redid the debug print 
// Version 1.2
// updated 4/29/01
// updated to work with 4 levels of organization: Chapters:Sections:Subsections:Pages
// updated didn't work
// Version 1.1
// updated 4/25/01
// updated to use relative nav instead of site relative nav
//********************************************************

// This file contains

// function DrawTitle() - Creates the Page's title based on Chapter and Section name
// function DrawPrevButton(imgName) - Draws the previous button on the page
// function DrawPrevLink() - Draws the prev link
// function DrawNextButton(imgName) - Draws the next button on the page
// function DrawNextLink() - Draws the next link
// function DrawPageNavigation() - Draws the page to page navigation 

// function ShowHide() - expands and contracts the sections in the course level nav
// function DrawCourseSubSection(index) - Draws the SubSection part of DrawCourseNavigation
// function DrawCourseSection(index) - Draws the Section part of DrawCourseNavigation
// function DrawCourseChapter(index) - Draws the Chapter part of DrawCourseNavigation
// function DrawCourseNavigation() - Draws the course level navigation

// variable and function naming standard
  // global variable  - gClassnamePropertyName
  // local variable   - lowerCase
  // function         - StartsWithUpperCase

//********************************************************
// Global Variable
//********************************************************

  var gDebug = 0  // used to turn on/off debugging print out 
                  // 0 - draw HTML
				  // 1 - draw HTML + print out HTML in field called debug
				  // the field has to be right under the body tag, 
				  // and the form that it is in must be called test
				  // 2 - print out HTML in field called debug
  var gDebugText = "" // contains HTML to be printed 

  var gNavSpanCounter = 0

//********************************************************
// function DrawTitle
//********************************************************

function DrawTitle()
{
  // variable definitions
	 var outputHTML  = ""
	 
  // display title in one of the three appropriate formats
     // Chapter  
	 // or
	 // Chapter : Section 
	 // or
	 // Chapter : Section : SubSection

        outputHTML += gChapterName[gChapterCurrentIndex]
     
	 // If there is more than one section in the chapter

        if(gChapterNoSections[gChapterCurrentIndex] > 1) 
        {
		  // list the section
	      outputHTML += " > "
          outputHTML += gSectionName[gSectionCurrentIndex]
		  
		  // draw the subsection if there is more than 1 subsection in this section
		  if(gSectionNoSubSections[gSectionCurrentIndex] > 1)
		  {
		    outputHTML += " > "
            outputHTML += gSubSectionName[gSubSectionCurrentIndex]
		  }
        }
     
	 outputHTML += '\r\n'
	 
	 if(gDebug > 0)document.test.debug.value += outputHTML
     if(gDebug < 2)document.writeln(outputHTML)
}

//********************************************************
// function DrawPrevButton
//********************************************************

function DrawPrevButton(imgName)
{
  // variable definitions

     var className = "on"
	 var outputHTML  = ""

  // Hide the button if this is the first page of the course

     if (gPageCurrentIndex == 1)
     {
       // Hide the button by setting the span className = navoff
	   className = "off" 
     }

  // write the following code to the document
     //<span class=on>
     //<a target="_top" href="basic.htm" 
	 // onMouseOut="MM_swapImgRestore()" 
	 // onMouseOver="MM_swapImage('Image2','','../../images/prev_highlite.gif',1)" border="0">
     //<img src="/sitename/images/prev.gif" width="14" height="17" name="Image2"> 
     //</a></span>

     outputHTML += '<span class=' + className + '>\r\n'
     outputHTML += '<a target="_top" href="' + gRelativePath + gPageURL[gPageCurrentIndex - 1] + '"' 
     outputHTML += '\r\n onMouseOut="MM_swapImgRestore()" '
     outputHTML += '\r\n onMouseOver="MM_swapImage('
     outputHTML += "'" + imgName + "','','" + gRelativePath + "images/prev_highlite.gif',1)" + '">\r\n'
	 outputHTML += '<img src="' + gRelativePath + 'images/prev.gif" width="7" height="7" name="' + imgName + '" '
     outputHTML += '" border="0" alt="previous topic">'
	 outputHTML += '</a>\r\n</span>\r\n'

	 if(gDebug > 0)document.test.debug.value += outputHTML
     if(gDebug < 2)document.writeln(outputHTML)
}
  
//********************************************************
// function DrawPrevLink
//********************************************************

function DrawPrevLink()
{
  // variable definitions

     var className = "on"
	 var outputHTML  = ""

  // Hide the link if this is the first page of the course

     if (gPageCurrentIndex == 1)
     {
       // Hide the button by setting the span className = off
	   className = "off" 
     }

  // write the following code to the document
     //<span class=on>
     //<a  target="_top" class=pagelink href="basic.htm" >Prev
     //</a></span>

     outputHTML += '<span class=' + className + '>\r\n'
     outputHTML += '<a target="_top" class=pagenav href="' + gRelativePath + gPageURL[gPageCurrentIndex - 1] + '">'
     outputHTML += 'previous topic'
	 outputHTML += '</a>\r\n</span>\r\n'

	 if(gDebug > 0)document.test.debug.value += outputHTML
     if(gDebug < 2)document.writeln(outputHTML) 
}

//********************************************************
// function DrawNextButton
//********************************************************

function DrawNextButton(imgName)
{
  // variable definitions

     var className = "on"
	 var outputHTML  = ""


  // Hide the button if this is the last page of the course

     if(gPageCurrentIndex == (gPageName.length - 1))
     {
       //Hide the button by setting the span className = off
	   className = "off" 
     }

  // write the following code to the document
     //<span class=on>
     //<a  target="_top" href="basic.htm" onMouseOut="MM_swapImgRestore()"  
	 // onMouseOver="MM_swapImage('Image1','','/sitename/images/next_highlite.gif',1)" border="0">
     //<img src="/sitename/images/next.gif" width="14" height="17" name="Image1"> 
     //</a></span>

     outputHTML += '<span class=' + className + '>\r\n'
     outputHTML += '<a target="_top" href="' + gRelativePath + gPageURL[gPageCurrentIndex + 1] +'"'
     outputHTML += '\r\n onMouseOut="MM_swapImgRestore()"'
     outputHTML += '\r\n onMouseOver="MM_swapImage('
     outputHTML += "'" + imgName + "','','" + gRelativePath + "images/next_highlite.gif',1)" + '">\r\n'
	 outputHTML += '<img src="' + gRelativePath + 'images/next.gif" width="7" height="7" name="' + imgName + '" '
	 outputHTML += 'border="0" alt="next topic">'
     outputHTML += '</a>\r\n</span>\r\n'

	 if(gDebug > 0)document.test.debug.value += outputHTML
     if(gDebug < 2)document.writeln(outputHTML) 
}
  
//********************************************************
// function DrawNextLink
//********************************************************

function DrawNextLink()
{
  // variable definitions
     var className = "on"
	 var outputHTML  = ""

  // Hide the link if this is the last page of the course
     if (gPageCurrentIndex == (gPageName.length - 1))
     {
       // Hide the button by setting the span className = off
	   className = "off" 
     }

  // write the following code to the document
     //<span class=on>
     //<a target="_top" class=pagelink href="basic.htm" >Next
     //</a></span>
     outputHTML += '<span class=' + className + '>\r\n'
     outputHTML += '<a target="_top" class=pagenav href="' +  gRelativePath + gPageURL[gPageCurrentIndex + 1] + '">'
     outputHTML += 'next topic'
	 outputHTML += '</a>\r\n</span>\r\n'

	 if(gDebug > 0)document.test.debug.value += outputHTML
     if(gDebug < 2)document.writeln(outputHTML) 
}

//********************************************************
// function DrawPageNavigation
//********************************************************

function DrawPageNavigation()
{

  // variable definitions
	 var endIndex      = 0
	 var i             = 0
     var outputHTML      = ""

   // Determine the ending index for this subsection 
	  endIndex = gSubSectionStartAtPage[gSubSectionCurrentIndex] + gSubSectionNoPages[gSubSectionCurrentIndex]

  // Write the list of all pages in the section
     //<a target="_top" href="this.htm" class=pagelink>
     //Page 1
     //</a> 
     //<span class=selected>
     //Page 2
     //</span>
     // 
  
     for(i = gSubSectionStartAtPage[gSubSectionCurrentIndex]; i < endIndex; i++)
     {
	   // if this is not the current page
	   if(i != gPageCurrentIndex)
	   {
	     //write the hyperlink and the page name
	     outputHTML += '<a target="_top" href="' +  gRelativePath + gPageURL[i] +  '" class=pagelink>' 
	     outputHTML += gPageName[i]
		 outputHTML += '</a>\r\n'
	   }
	   else
	   {
         //write the page name only
	     outputHTML += '<span class=selected>' 
	     outputHTML += gPageName[i]
		 outputHTML += '</span>\r\n'
	   }
	   
	   // write the seperator unless this is the last page in the section
	   if(i != endIndex -1) 
	   {
		 outputHTML += ' | '
	   }

     } 
	 if(gDebug > 0)document.test.debug.value += outputHTML
     if(gDebug < 2)document.writeln(outputHTML)   	   
}
  
//********************************************************
// function ShowHide
//********************************************************

function ShowHide(iconNameID, navSpanID)
{

  if(navSpanID.className=="on")
  {
    navSpanID.className="off"
	document.images[iconNameID].src =  gRelativePath + "images/arrow_rt.gif"
  }
  else
  {
    navSpanID.className="on"
	document.images[iconNameID].src =  gRelativePath + "images/arrow_dn.gif"
  }

}
  
//********************************************************
// function DrawCourseSubSection
//********************************************************

function DrawCourseSubSection(index)
{

  // variable definitions
	 var expands = 0
	 var current = 0 
	 var subSectionImage
	 var subSectionClass
	 var outputHTML = ""
	 
	 //Is this subsection the current subsection

	 if(gSubSectionCurrentIndex == index) current = 1

	 outputHTML += '    <img src="' + gRelativePath + 'images/nav_blank.gif" >\r\n'
	 outputHTML += '    <img src="' + gRelativePath + 'images/nav_blank.gif" >\r\n'
	 outputHTML += '    <img src="' + gRelativePath + 'images/nav_blank.gif" >\r\n'
	 if(!current) outputHTML += '    <a target="_top" class=nav href="' + gRelativePath + gSubSectionURL[index] + '">'
	 outputHTML += gSubSectionName[index]
	 if(!current) outputHTML += '</a>'
	 outputHTML += '<br>\r\n'

	 return outputHTML

}

  
//********************************************************
// function DrawCourseSection
//********************************************************

function DrawCourseSection(index)
{

  // variable definitions
	 var expands = 0
	 var current = 0 
	 var sectionImage
	 var sectionClass
	 var endsAtSection
	 var k
	 var outputHTML = ""
	 
	 //Is this section the current section
	 if(gSectionCurrentIndex == index) current = 1

	 //Does this section expand (more than 1 subsection)
	 if(gSectionNoSubSections[index] > 1) expands = 1
     
	 //Calculate the number of sections for this chapter
	 endsAtSection = gSectionFirstSubSectionIndex[index] + gSectionNoSubSections[index]
	 
	 if(expands)
	 {
	   gNavSpanCounter ++
	   if(current)
	   {
		   sectionImage = "images/arrow_dn.gif"
		   sectionClass = "on"
	   }
	   else
	   {
		   sectionImage = "images/arrow_rt.gif"
		   sectionClass = "off"
	   }
	   outputHTML += '  <img src="' + gRelativePath + 'images/nav_blank.gif" >\r\n'
	   outputHTML += '  <img name="image' + gNavSpanCounter + '" src="' + gRelativePath + sectionImage 
	   outputHTML += '" onclick="ShowHide'
	   outputHTML += "('image" + gNavSpanCounter + "', navSpan" + gNavSpanCounter + ')" >\r\n'
       outputHTML += '  <a target="_top" class=nav href="' + gRelativePath + gSectionURL[index] + '">' + gSectionName[index] + '</a><br>\r\n'
	   outputHTML += '  <span id=navSpan' + gNavSpanCounter + ' class=' + sectionClass + '>\r\n'
	   
	   // call DrawCourseSubSections
	   for(k=gSectionFirstSubSectionIndex[index]; k < endsAtSection; k++)
	   {
	      outputHTML += DrawCourseSubSection(k)
	   }
	   outputHTML += '  </span>\r\n'

	 }
	 else
	 {
	   outputHTML += '  <img src="' + gRelativePath + 'images/nav_blank.gif" >\r\n'
	   outputHTML += '  <img src="' + gRelativePath + 'images/nav_blank.gif" >\r\n'
	   if(!current) outputHTML += '  <a target="_top" class=nav href="' + gRelativePath + gSectionURL[index] + '">'
	   outputHTML += gSectionName[index]
	   if(!current) outputHTML += '</a>'
	   outputHTML += '<br>\r\n'
	 }

	 return outputHTML
	 //return "Section Index = " + index + " current = " + current + " expands = " + expands + "\r\n"

}
//********************************************************
// function DrawCourseChapter
//********************************************************

function DrawCourseChapter(index)
{

  // variable definitions
	 var expands = 0
	 var current = 0 
	 var chapterImage 
	 var chapterClass	 
	 var j = 0
	 var endsAtSection
	 var outputHTML = ""

  //Is this chapter the current chapter
	 if(gChapterCurrentIndex == index) current = 1

  //Does this chapter expand (more than 1 section)
	 if(gChapterNoSections[index] > 1) expands = 1
     
  //Calculate the number of sections for this chapter
	 endsAtSection = gChapterFirstSectionIndex[index] + gChapterNoSections[index]

  //
	 if(expands)
	 {
	   gNavSpanCounter ++
	   if(current)
	   {
		   chapterImage = "images/arrow_dn.gif"
		   chapterClass = "on"
	   }
	   else
	   {
		   chapterImage = "images/arrow_rt.gif"
		   chapterClass = "off"
	   }
	   outputHTML += '<img name="image' + gNavSpanCounter + '" src="' + gRelativePath + chapterImage 
	   outputHTML += '" onclick="ShowHide'
	   outputHTML += "('image" + gNavSpanCounter + "', navSpan" + gNavSpanCounter + ')" >\r\n'
       outputHTML += '<a target="_top" class=nav href="' + gRelativePath + gChapterURL[index] + '">' + gChapterName[index] + '</a><br>\r\n'
	   outputHTML += '<span id=navSpan' + gNavSpanCounter + ' class=' + chapterClass + '>\r\n'
	   
	   // call DrawCourseSections
	   for(j=gChapterFirstSectionIndex[index]; j < endsAtSection; j++)
	   {
	      outputHTML += DrawCourseSection(j)
	   }
	   outputHTML += '</span>\r\n'

	 }
	 else
	 {
	   outputHTML += '<img src="' + gRelativePath + 'images/nav_blank.gif" >\r\n'
	   if(!current) outputHTML += '<a target="_top" class=nav href="' + gRelativePath + gChapterURL[index] + '">'
	   outputHTML += gChapterName[index]
	   if(!current) outputHTML += '</a>'
	   outputHTML += '<br>\r\n'
	 }

	 return outputHTML
}


//********************************************************
// function DrawCourseNavigation
//********************************************************

function DrawCourseNavigation()
{
  // variable definitions

     var i = 0  //chapter counter
	 var outputHTML = ""

     for(i=1;i<gChapterName.length; i++)
	 {
        outputHTML += DrawCourseChapter(i)
	 }
	 
	 if(gDebug > 0)document.test.debug.value += outputHTML
     if(gDebug < 2)document.writeln(outputHTML)
	 
}
