//Global variables

var undefined;    //used to check if a value is not initialised or an object does not exist 

//indexes into arrays relating to Pages (i.e. page name and visitor count.)
//(Multi-dimensional array would be nice, but the JS-method is not worth it here)
var idxHome = 0, idxFeedback=1, idxDesigner=2
var idxcodeMain=3, idxGroup1=4, idxGroup2=5
var idxGroup3=6, idxGroup4=7, idxGroup5=8	

//Array of page names
pageArray = new Array ("home.html","feedback.html","designer.html", "codeMain.html","group1.html","group2.html","group3.html","group4.html","group5.html")

//Array of code examples (*** relate in sequence to group1 = group5 above *** )
codePages = new Array ("Opening a New Window", "Select and Go", "Generating Dynamic Web Pages", "Manipulating the DOM", "Folding Tables")

//Array of visitor counts to each page
visitorArray = new Array(pageArray.length)
	

		
//=============================================================		
//Called by navCode ONLY, for the generated navigation links		
//=============================================================		
function setContent(myFrame, idxPage) 
	{
	 parent.content.document.location.href =pageArray[idxPage]
  }		

//=============================================================		
//Called by initRoutines to ensure a page is within the frameset
//=============================================================	
function fullFrame(idxPage)
{		
  if (top.location == self.location) 
	{
		self.location.replace("index.html?" + pageArray[idxPage])
	}	
}	

//=============================================================		
// Called by each htmlPage, to :
//   . ensure the page is within the frameset, then
//   . highlight the link as the current page,
//   . increment the visitor-count for the page 
//   
//=============================================================	
function initRoutines(myFrame, idxPage)
{		
	
	//first ensure that the page is within a frameset so not opened alone
 	fullFrame(idxPage)
	
	//don't do this the first time in, it gets itself confused.
	//This is not in index, so whereever i am it is "parent"
	//and may still be undefined because i haven;t been there FTI 
	if (parent.hidden.FTI == undefined) 
	   {
		 return
		 }
	else
	{
	}
		
  //===================================================
	//  Only do anything if the page has changed
	//  This is one (messy) way to stop clicks on
	//  the current page adding to the visitor-count.)
	//===================================================

		if (idxPage != parent.hidden.currPage)  
	   {
			//check if the navigation has changed
			if (myFrame != parent.hidden.currFrame) 
	    {
	       chgFrame(myFrame, idxPage)
	    }
			
			//Now set the appearance of the current link to say "You are here" 
			setCurrent(myFrame, idxPage)
		
	    //increment the visitor count for this page:
	    parent.hidden.visitorArray[idxPage]++
		 
		  //Save the current index
		  parent.hidden.currPage= idxPage
		} // was new page 
}	

//=============================================================		
// Called by initRoutines if the navigation bar has changed
//=============================================================	
function chgFrame(myFrame, idxPage) 
{
   //Reset the current navigation:
   parent.hidden.currFrame = myFrame
   setContent(myFrame, idxPage) 
}


		
//=============================================================		
// Called by initRoutines to highlight the link as the current page,
//=============================================================	
function setCurrent(myFrame, idxPage) 
	{
	//-----------------------------------------------------------
	// toggle off the current "Current Page" - 
	// do them all for ease of code and performance 
	// (rather than save or search for the only one that is marked).
	//  nb, myFrame is either 'code' or 'main'
	//-----------------------------------------------------------
	
  var i
	var rs
	var currId
	var tempId
	var newId = ""
		
	//Get the new page ID out of the page name, from the Page array:
	//strip off the .html of the page name to give its ID:
	try {
			tempId = pageArray[idxPage].split(".")
			newId = tempId[0]
	    }
	catch(e) {}		
	
  //---------------------------------------------------------------
	//Reset all buttons to standard class:	
	//---------------------------------------------------------------	
	if (document.getElementById)
	{
		for (i=0 ; i<=pageArray.length-1 ; i++)
	     {	
		    //-----------------------------------------------------------
				// strip off the ".html" of the page name to get its id. 
	  		//-----------------------------------------------------------
			  tempId = pageArray[i].split(".")
			  currId = tempId[0]
				
			  //-----------------------------------------------------------
			  // Reset appearance to normal navigation class; 
				// FTI (during initialisiation) this is null or unidentified 
				// so accept the error
				//
				// (Resetting class does not work if the nav frame has changed;
				// it could do, but it is hidden so it doesn't matter. 
				//-----------------------------------------------------------
				try {
            parent.nav.document.getElementById(currId).parentElement.className ="Nav"
  			    }	
				catch(e){}	
	     }//For all links
			 
       //-----------------------------------------------------------
       //Now set the current button to class 'CurrentPage'
	     //FTI (during initialisiation) this is null or unidentified so accept the error
			 //-----------------------------------------------------------
			 try {	
		       parent.nav.document.getElementById(newId).parentElement.className ="CurrentPage" 
	         } 
			 catch(e){}
	} //if browser can hack it
} //function
	
	
//-------------------------------------------------------------------
// toggle visibility
//-------------------------------------------------------------------
var show = 'Show Code'
var hide = 'Hide Code'

//-------------------------------------------------------------------
// Apply the toggle function to all button onclick events.
// This code only applies to a text page whose first form
// contains buttons to toggle visibility
//-------------------------------------------------------------------
function initButtons()
{
	for (var i=0; i<document.forms[0].elements.length; i++)
    {
	   document.forms[0].elements[i].onclick=toggle
		 document.forms[0].elements[i].value=hide
	  }
}

//-------------------------------------------------------------------
// Toggle visibility and change button text
//-------------------------------------------------------------------
function toggle()
  {
//is it show or hide for now?	
	if (this.value==hide)
	   {
	     togHide(this.name)
			 this.value=show
		 }
	else
	   {
	     togShow(this.name)
			 this.value=hide
		 }
	}	
	
//-------------------------------------------------------------------
// Hide it!
//-------------------------------------------------------------------
function togHide(blockID)
{ 
	if (document.getElementById){document.getElementById(blockID).style.display="none";}	
}	
		
//-------------------------------------------------------------------
// Show it!
//-------------------------------------------------------------------
function togShow(blockID)
{ 
	if (document.getElementById){document.getElementById(blockID).style.display="block";}					
}	
	
