//Set veriables, interigate URL

htm = document.URL.indexOf(".htm")//Find the substring ".htm" in the URL
pageNo = document.URL.substring(htm-4,htm-6)//Uses ".htm" as a start point to set variables
pageNoUnits = pageNo.charAt(1)// Split pageNo in to units and tens
pageNoTens = pageNo.charAt(0)
sectionNo = document.URL.substring(htm-6,htm-8)// Section number
sectionNoUnits = sectionNo.charAt(1)
sectionNoTens = sectionNo.charAt(0)
outcomeNo = document.URL.substring(htm-8,htm-9)// Outcome number
QorA = document.URL.substring(htm-3,htm-4)// SAQ "q" = question "a" = answer, also other page type 

// Display blank gif in location bar counters

if(pageNoTens == 0){ 
	pageNoTens = "blank";
}

if(sectionNoTens == 0){
				sectionNoTens = "blank";
		}

outcomeParts = section[outcomeNo -1].length + "a"
var totalParts1 = outcomeParts.charAt(0);
var totalParts2 = outcomeParts.charAt(1);
if (totalParts2 == "a"){
	totalParts2 = "blank"//show blank in units pos if lees than 9
	}
	
sectionPages = section[outcomeNo -1][sectionNo -1];//gets the nuber of pages in current section
sectionNoChar1 = sectionPages.charAt(0);//show the correct number gif in total pages counter
sectionNoChar2 = sectionPages.charAt(1);//show the correct number gif in total pages counter

if(sectionNoChar1 == 0){
  sectionNoChar1 = sectionNoChar2;
  sectionNoChar2 = "blank";
}

if(outcomeNo == 1){
  outcomeLable = 'outcme_1_2.gif';
  outcomeNoGraphic = 2;
}else{
  outcomeLable = 'numh_13.gif';
  outcomeNoGraphic = 3;
}

			
//prepends with 0 if necessary. (Required for URL)

function prependZero(page) { 
  if (page <= 9) {page = "0" + page}	
  pageNo=page;										    
  return;
}

function prependZero2(section) { 
  if (section <= 9) {section = "0" + section}	
  sectionNo=section;										    
  return;
}

// next page

function nextPage(){
if(pageNo < sectionPages){// Goto next page
		pageNo++;
		prependZero(pageNo);	
		location.href=""+outcomeNo+""+sectionNo+""+pageNo+"high.htm";
		return;
	}
else {
		if(sectionNo == section[outcomeNo -1].length){// Check if at end of outcome
				location.href="../menu.htm";
				return;
				}
		sectionNo++
		prependZero2(sectionNo);
		location.href=""+outcomeNo+""+sectionNo+"01high.htm";// Goto first page of next section
	}
}

// previous page

function previousPage(){
	if(pageNo == 01){ 						//  If the pageNo is the first page in the section
		if(sectionNo == 01){ 			  //  If in the last page of first section
		location.href="../menu.htm" //  load the menu page
		return
		}
		sectionNo --; 						  //  If not in the first section minus 1 from sectionNo
		prependZero2(sectionNo);
		pageNo = section[outcomeNo -1][sectionNo -1] //  Make pageNo the value of the number of pages in previous section
		location.href=""+outcomeNo+""+sectionNo+""+pageNo+"high.htm"	//  Location is back the last page of the previous section 
	}
else{
		pageNo-- 										//  If not on first page of a section, minus 1 from pageNo
		prependZero(pageNo);				//  Prepend a zero if necessary so pageNo is usable in the URL
		location.href=""+outcomeNo+""+sectionNo+""+pageNo+"high.htm"	//Go back 1 page
	}
}

// next section

function nextSection(){
	if(sectionNo == section[outcomeNo -1].length){
		location.href="../menu.htm"
		}
	else{
			sectionNo++
			prependZero2(sectionNo);
			location.href=""+outcomeNo+""+sectionNo+"01high.htm"
			}
	}
	
// previous section	
	
function previousSection(){
	if(sectionNo == 01){
		location.href="../menu.htm"
		}
	else{
			sectionNo--
			prependZero2(sectionNo);
			location.href=""+outcomeNo+""+sectionNo+"01high.htm"
			}
	}
	
// show and hide help layer
	
function showHideHelpLayer(){		//  Show and hide help layers
if (browser == "MSIE") {				//	Internet Explorer
		if(helpLayer.style.visibility == "hidden"){
    		helpLayer.style.visibility = "visible"
			}
		else{
			helpLayer.style.visibility = "hidden"
			}			
		}
else if ((browser == "NS")&&(verNo == 4)) {	// Netscape Navigator 4
    	  launchCourseWareGuide()
				}
else if ((browser == "NS")&&(verNo >= 5)) {	// Netscape Navigator 6 and above
    	if(document.getElementById(helpLayer).style.visibility == "hidden"){
    		document.getElementById(helpLayer).style.visibility = "visible"
			}
		else{
			document.getElementById(helpLayer).style.visibility = "hidden"
			}
		}
}

//Pass on the url of page just left
function jumpPage(jumpTo){
	i = document.URL.length
	x = document.URL.substring(i,i-13)
	location=""+jumpTo+"?"+x+""
	}	

var iw, ih, ow, iw, x, y;						//  Get width height and position of window
var marginheight;
if (document.all) {
   iw = document.body.clientWidth;	//  the following is only available after onLoad
   ih = document.body.clientHeight;
   ow = document.body.offsetWidth;
   oh = document.body.offsetHeight;
   x = window.screenLeft;
   y = window.screenTop;
   marginheight = 15;
}
else {
   iw = window.innerWidth;
   ih = window.innerHeight;
   ow = window.outerWidth;
   oh = window.outerHeight;
   x = window.screenX;
   y = window.screenY;
   marginheight = 40;
}

																		
function launchCourseWareGuide() { 	//  Open courseware guide window and center it on the main window
	
var popW = 742, popH = 540;
var topPos = y + oh - ih - marginheight + (ih-popH)/2-60;
var leftPos = x + (ow-iw)/2 + (iw-popW)/2;
var atr = 'width='+popW+',height='+popH+',top='+topPos+',left='+leftPos;

popUp1 = window.open('../cwguide/cw01.htm','commint2',atr);//,toolbar=0,location=0,status=0,menubar=0,resizable=0)
if (popUp1.open){
popUp1.focus()
}
}
		
//Called by btmovie.swf to link to correct movie page
function goToMovie(){
	location.href=""+outcomeNo+""+sectionNo+""+pageNo+"move.htm"
	}

//Navigation bar

navTable = '<a href="#top">'
navTable = '<table width="744" border="0" cellspacing="0" cellpadding="0" height="67">'
navTable += '  <tr>' 
navTable += '   <td>' 
navTable += '      <table width="85" border="0" cellspacing="0" cellpadding="0">'
navTable += '       <tr>' 
navTable += '          <td><a href="../menu.htm" target="_self" onMouseOver=\'document.menu.src="../ifimages/numh_01V.gif";\' onMouseOut=\'document.menu.src="../ifimages/numh_01.gif"\' ><img src="../ifimages/numh_01.gif" width="85" height="67" alt="Menu button" name="menu" border="0"></a></td>'
navTable += '       </tr>'
navTable += '      </table>'
navTable += '    </td>'
navTable += '    <td>' 
navTable += '      <table width="27" border="0" cellspacing="0" cellpadding="0">'
navTable += '        <tr>' 
navTable += '          <td><a href="javascript:previousSection()" onMouseOver=\'document.presec.src="../ifimages/numh_02V.gif";\' onMouseOut=\'document.presec.src="../ifimages/numh_02.gif";\' ><img src="../ifimages/numh_02.gif" width="27" height="67" alt="Back sub section button" name="presec" border="0"></a></td>'
navTable += '        </tr>'
navTable += '      </table>'
navTable += '    </td>'
navTable += '    <td>' 
navTable += '      <table width="27" border="0" cellspacing="0" cellpadding="0" height="67">'
navTable += '       <tr>' 
navTable += '          <td colspan="7"><IMG SRC="../ifimages/numh_03.gif" WIDTH=38 HEIGHT=33 ALT="part label"></td>'
navTable += '        </tr>'
navTable += '        <tr>' 
navTable += '         <td><img src="../ifimages/numh_18.gif" width="3" height="12" ALT="blank"></td>'
navTable += '         <td><img src="../ifimages/'+sectionNoTens+'.gif" width="6" height="12" alt="Blank" name="blankno3"></td>'
navTable += '          <td><img src="../ifimages/'+sectionNoUnits+'.gif" width="6" height="12" name="subsectionno" alt="Current sub section number"></td>'
navTable += '          <td><IMG SRC="../ifimages/numh_21.gif" WIDTH=8 HEIGHT=12 ALT="slash"></td>'
navTable += '          <td><img src="../ifimages/'+totalParts1+'.gif" width="6" height="12" alt="Total number of sub sections" name="totalsubsections"></td>'
navTable += '          <td><img src="../ifimages/'+totalParts2+'.gif" width="6" height="12" alt="Blank" name="blankno4"></td>'
navTable += '         <td><IMG SRC="../ifimages/numh_24.gif" WIDTH=3 HEIGHT=12 ALT="blank"></td>'
navTable += '        </tr>'
navTable += '        <tr>' 
navTable += '          <td colspan="7"><IMG SRC="../ifimages/numh_33.gif" WIDTH=38 HEIGHT=22 ALT="part of nav bar"></td>'
navTable += '        </tr>'
navTable += '     </table>'
navTable += '    </td>'
navTable += '    <td>' 
navTable += '      <table width="24" border="0" cellspacing="0" cellpadding="0">'
navTable += '        <tr>' 
navTable += '          <td><a href="javascript:nextSection()" onMouseOver=\'document.nextsec.src="../ifimages/numh_04V.gif";\' onMouseOut=\'document.nextsec.src="../ifimages/numh_04.gif";\' ><img src="../ifimages/numh_04.gif" width="24" height="67" alt="Forward sub section button" name="nextsec" border="0"></a></td>'
navTable += '        </tr>'
navTable += '      </table>'
navTable += '    </td>'
navTable += '    <td>'
navTable += '      <table width="73" border="0" cellspacing="0" cellpadding="0">'
navTable += '        <tr>' 
navTable += '          <td><IMG SRC="../ifimages/numh_05.gif" WIDTH=73 HEIGHT=67 ALT="part of nav bar"></td>'
navTable += '        </tr>'
navTable += '      </table>'
navTable += '    </td>'
navTable += '    <td> '
navTable += '      <table width="255" border="0" cellspacing="0" cellpadding="0" height="67">'
navTable += '        <tr> '
navTable += '          <td colspan="5"><IMG SRC="../ifimages/numh_06.gif" WIDTH=255 HEIGHT=29 ALT="Communication Higher heading"></td>'
navTable += '        </tr>'
navTable += '        <tr> '
navTable += '          <td><IMG SRC="../ifimages/'+outcomeLable+'" WIDTH=139 HEIGHT=13 ALT="Outcome label"></td>'
navTable += '          <td><img src="../ifimages/'+outcomeNoGraphic+'out.gif" width="10" height="13" name="sectionno" alt="Current section number"></td>'
navTable += '          <td><IMG SRC="../ifimages/numh_15.gif" WIDTH=11 HEIGHT=13 ALT="slash"></td>'
navTable += '          <td><img src="../ifimages/3out.gif" width="10" height="13" name="totalsections" alt="Total number of sections"></td>'
navTable += '          <td><IMG SRC="../ifimages/numh_17.gif" WIDTH=85 HEIGHT=13 ALT="blank"></td>'
navTable += '        </tr>'
navTable += '        <tr> '
navTable += '          <td colspan="5"><IMG SRC="../ifimages/outcomelabel'+outcomeNo+'.gif" WIDTH=255 HEIGHT=25 ALT="reading label"></td>'
navTable += '        </tr>'
navTable += '      </table>'
navTable += '    </td>'
navTable += '    <td>'
navTable += '      <table width="71" border="0" cellspacing="0" cellpadding="0">'
navTable += '       <tr> '
navTable += '          <td><IMG SRC="../ifimages/numh_07.gif" WIDTH=71 HEIGHT=67 ALT="part of nav bar"></td>'
navTable += '        </tr>'
navTable += '      </table>'
navTable += '    </td>'
navTable += '    <td>'
navTable += '      <table width="24" border="0" cellspacing="0" cellpadding="0">'
navTable += '        <tr> '
navTable += '          <td><a href="javascript:previousPage()" onMouseOver=\'document.pre.src="../ifimages/numh_08V.gif";\' onMouseOut=\'document.pre.src="../ifimages/numh_08.gif";\' ><img src="../ifimages/numh_08.gif" width="24" height="67" name="pre" alt="Back page button" border="0"></a></td>'
navTable += '        </tr>'
navTable += '      </table>'
navTable += '    </td>'
navTable += '    <td>'
navTable += '      <table width="41" border="0" cellspacing="0" cellpadding="0" height="67">'
navTable += '        <tr> '
navTable += '          <td colspan="7"><IMG SRC="../ifimages/numh_09.gif" WIDTH=41 HEIGHT=33 ALT="page label"></td>'
navTable += '        </tr>'
navTable += '        <tr> '
navTable += '         <td><IMG SRC="../ifimages/numh_25.gif" WIDTH=5 HEIGHT=12 ALT="blank"></td>'
navTable += '          <td><img src="../ifimages/'+pageNoTens+'.gif" width="6" height="12" name="pagenotens" alt="First digit of current page number"></td>'
navTable += '         <td><img src="../ifimages/'+pageNoUnits+'.gif" width="6" height="12" alt="Second digit of current page number" name="pagenodigits"></td>'
navTable += '         <td><IMG SRC="../ifimages/numh_28.gif" WIDTH=8 HEIGHT=12 ALT="slash"></td>'
navTable += '         <td><img src="../ifimages/'+sectionNoChar1+'.gif" width="6" height="12" name="totalpagestens" alt="First digit of total page numbers"></td>'
navTable += '         <td><img src="../ifimages/'+sectionNoChar2+'.gif" width="6" height="12" alt="Second digit of total page numbers" name="totalpagesdigits"></td>'
navTable += '         <td><img src="../ifimages/numh_24.gif" alt="blank"></td>'
navTable += '       </tr>'
navTable += '       <tr> '
navTable += '         <td colspan="7"><IMG SRC="../ifimages/numh_34.gif" WIDTH=41 HEIGHT=22 ALT="part of nav bar"></td>'
navTable += '       </tr>'
navTable += '     </table>'
navTable +='   </td>'
navTable += '   <td>'
navTable += '     <table width="29" border="0" cellspacing="0" cellpadding="0">'
navTable += '       <tr>' 
navTable += '         <td><TD ROWSPAN=5><a href="javascript:nextPage()" onMouseOver=\'document.next.src="../ifimages/numh_10V.gif";\' onMouseOut=\'document.next.src="../ifimages/numh_10.gif";\' ><img src="../ifimages/numh_10.gif" width="29" height="67" alt="Forward page button" name="next" border="0"></td>'
navTable += '       </tr>'
navTable += '     </table>'
navTable += '   </td>'
navTable += '   <td>'
navTable += '     <table width="20" border="0" cellspacing="0" cellpadding="0">'
navTable += '       <tr> '
navTable += '         <td><IMG SRC="../ifimages/numh_11.gif" WIDTH=20 HEIGHT=67 ALT="part of nav bar"></td>'
navTable += '       </tr>'
navTable += '     </table>'
navTable += '   </td>'
navTable += '   <td>'
navTable += '     <table width="57" border="0" cellspacing="0" cellpadding="0">'
navTable += '      <tr> '
navTable += '        <td><a href="../help.htm" target="_blank" onMouseOver=\'document.help.src="../ifimages/numh_12V.gif";\' onMouseOut=\'document.help.src="../ifimages/numh_12.gif";\'><img src="../ifimages/numh_12.gif" width="57" height="67" alt="Help button" border="0" name="help"></a></td>'
navTable += '      </tr>'
navTable += '     </table>'
navTable += '   </td>'
navTable += '   <td><table width="1" border="0" cellspacing="0" cellpadding="0">'
navTable += '  <tr>'
navTable += '   <td><img src="../ifimages/spacer.gif"></td>'
navTable += ' </tr>'
navTable += ' <tr>'
navTable += '   <td><img src="../ifimages/spacer.gif"></td>'
navTable += ' </tr>'
navTable += '  <tr>'
navTable += '   <td><img src="../ifimages/spacer.gif"></td>'
navTable += ' </tr>'
navTable += '</table>'
navTable += '</td>'
navTable += '  </tr>'
navTable += '</table>'
document.write(navTable)


//Help layers

layerPosLeft = (iw/2) - 325;
layerPosTop = (ih/2) - 130;

var helpLayer
if(verNo >= 5){
		if(QorA == "i"){
helpLayer1 = '<div id="defaultHelp" style="position:absolute; left:'+layerPosLeft+'px; top:'+layerPosTop+'px; width:650px; height:300px; z-index:100; visibility:hidden"> '
helpLayer1 += '<table width="650" height="300" bgcolor="#ffffff" border="1" cellspacing="0" cellpadding="0">'
helpLayer1 += '          <tr> '
helpLayer1 += '            <td height="268"> '
helpLayer1 += '              <div align="center">Default help. Help information with a close window and mor information button.</div>'
helpLayer1 += '            </td>'
helpLayer1 += '          </tr>'
helpLayer1 += '          <tr>'
helpLayer1 += '            <td height="30"> '
helpLayer1 += '              <div align="center"><a href="javascript:showHideHelpLayer()">Click here to close</a></div>'
helpLayer1 += '           </td>'
helpLayer1 += '          </tr>'
helpLayer1 += '        </table>'
helpLayer1 += '</div>'
document.write(helpLayer1)
	if(browser == "NS"){
		helpLayer = "defaultHelp"
		}
	else{helpLayer = defaultHelp}
		}

else if(QorA == "q"){
helpLayer2 = '<div id="saqHelp" style="position:absolute; left:'+layerPosLeft+'px; top:'+layerPosTop+'px; width:650px; height:300px; z-index:100; visibility:hidden"> '
helpLayer2 += '<table width="650" height="300" bgcolor="#ffffff" border="1" cellspacing="0" cellpadding="0">'
helpLayer2 += '          <tr> '
helpLayer2 += '            <td height="268"> '
helpLayer2 += '              <div align="center"><b>SAQ help</b>. Help information with a close window and mor information button.</div>'
helpLayer2 += '            </td>'
helpLayer2 += '          </tr>'
helpLayer2 += '          <tr>'
helpLayer2 += '            <td height="30"> '
helpLayer2 += '              <div align="center"><a href="javascript:showHideHelpLayer()">Click here to close</a></div>'
helpLayer2 += '           </td>'
helpLayer2 += '          </tr>'
helpLayer2 += '        </table>'
helpLayer2 += '</div>'
document.write(helpLayer2)
	if(browser == "NS"){
		helpLayer = "saqHelp"
		}

	else{helpLayer = saqHelp}
	}
}
