var sectionImgs;
var itembank;
var response1;
var response2;
var response3;
var response4;
var response5;
var response6;
var Info;
var Infotext;

var questionno 				= 0;
var sectionno 				= 999; 
var instructpage 			= 0;
var incorrectcount 			= 0;
var testnav 				= false;
var gtryagain 				= false;
var gfinish 				= false;
var objclearbutton			= null;
var objbackbutton			= null;
var objCorrect				= null;
var objIncorrect2			= null;
var objIncorrect			= null;
var objforwardbutton		= null;
var objfinishbutton			= null;	
var objinstructbutton		= null;
var objinstructbackbutton	= null;

function SetObjects()
{
	objclearbutton 		  = GetLayer('clearbutton');
	objbackbutton  		  = GetLayer('backbutton');
	objCorrect     		  = GetLayer('Correct');
	objIncorrect2  		  = GetLayer('Incorrect2');
	objIncorrect   		  = GetLayer('Incorrect');
	objforwardbutton 	  = GetLayer('forwardbutton');
	objfinishbutton 	  = GetLayer('finishbutton');
	objinstructbutton 	  = GetLayer('instructbutton');
	objinstructbackbutton = GetLayer('instructbackbutton');
}

function SetFirst(val){firsttime = val;}

function labeltextbits()
{
	Labeltext 	 = new Array;
	Labeltext[0] = "Cubiks online assessment: instructions and practice";
	Labeltext[1] = "Information about the assessment process";
	Labeltext[2] = "Practice online assessment";
	Labeltext[3] = "Practice numerical reasoning test";
	Labeltext[4] = "Further information";		
}

function labelSetUp(nPage)
{	
	if( nPage == 1 ){
		var labelcontent = '<table class="label" cellspacing="0" cellpadding="0" width="480" height="35">';			 
			labelcontent += '<tr height="35"><td width="15">&nbsp;</td>';
   			labelcontent += '<td width="465" class="label">';
			labelcontent += 'Cubiks online assessment: instructions and practice';
			labelcontent += '</td>';
			labelcontent += '</tr>';					
			labelcontent += '</table>';			
	
		SetLayerHtml('labellayer',labelcontent);
		ShowLayer	('labellayer');
	}	
	if( nPage >= 2 && nPage <= 6 ){

		var labelcontent = '<table class="label" cellspacing="0" cellpadding="0" width="480" height="35">';			 
			labelcontent += '<tr height="35"><td width="15">&nbsp;</td>';
   			labelcontent += '<td width="465" class="label">';
			labelcontent += 'Information about the assessment process';
			labelcontent += '</td>';
			labelcontent += '</tr>';					
			labelcontent += '</table>';			
	
			SetLayerHtml('labellayer',labelcontent);
			ShowLayer('labellayer');
	}
	if( nPage == 7 ){

		var labelcontent = '<table class="label" cellspacing="0" cellpadding="0" width="480" height="35">';			 
			labelcontent += '<tr height="35"><td width="15">&nbsp;</td>';
   			labelcontent += '<td width="465" class="label">';
			labelcontent += 'Practice online assessment';
			labelcontent += '</td>';
			labelcontent += '</tr>';					
			labelcontent += '</table>';			
	
			SetLayerHtml('labellayer',labelcontent);
			ShowLayer('labellayer');
	}
	if( nPage == 8 ){

		var labelcontent = '<table class="label" cellspacing="0" cellpadding="0" width="480" height="35">';			 
			labelcontent += '<tr height="35"><td width="15">&nbsp;</td>';
   			labelcontent += '<td width="465" class="label">';
			labelcontent += 'Practice numerical reasoning test';
			labelcontent += '</td>';
			labelcontent += '</tr>';					
			labelcontent += '</table>';			
	
			SetLayerHtml('labellayer',labelcontent);
			ShowLayer('labellayer');
	}
	if( nPage == 9 ){

		var labelcontent = '<table class="label" cellspacing="0" cellpadding="0" width="480" height="35">';			 
			labelcontent += '<tr height="35"><td width="15">&nbsp;</td>';
   			labelcontent += '<td width="465" class="label">';
			labelcontent += 'Further information';
			labelcontent += '</td>';
			labelcontent += '</tr>';					
			labelcontent += '</table>';			
	
			SetLayerHtml('labellayer',labelcontent);
			ShowLayer('labellayer');
	}
}

function OnInstructionPage( nPage )
{
   	var instructs;

	if( nPage == 1 ){
		instructs = '<table width="570"><tr><td>';
		instructs += '<p class="quot2"><b>Some numerical test practice</b></p>'
		instructs += '<p class="quotx">In the following pages you will be presented with 6 practice numerical test questions similar to the ones used in the test that you will be completing online.</p>';
		instructs += '<p class="quotx">While taking this practice test:</p>';
		instructs += '<ul><li><span class="quotx">You will need to work both quickly and accurately, so do not ponder on one question for too long.</span></li>'  
		instructs += '<li><span class="quotx">You will be given 2 chances to get the answer correct.  If you get it wrong twice, the correct answer and a ‘tip’ are given to help you assess your understanding of the type of questions asked.</span></li>'	
		instructs += '<li><span class="quotx">You may use a calculator and rough paper and pencil to do working out if you wish.</span></li></ul>';
		
instructs += '<p class="quotx"><b>We suggest that you time yourself and try to complete the practice questions within 5 minutes.</b>  Timing yourself on the practice test replicates the real testing environment, however these questions do not necessarily reflect the difficulty of the real test.  The actual test has a time limit which is controlled by the computer.  Full instructions will be given to you before you take the actual test under timed conditions.</p>';	
		instructs += '<p class="quotx">Click on "Next" to see more instructions about the practice test.</p>';
		instructs += '</td></tr></table>';	
		questionno = 0;	
	}
	if( nPage == 2 ){
		instructs = '<table width="570"><tr><td>';			
		instructs += '<p class="quot2"><b>Numerical reasoning practice test:</b></p>';
		instructs += '<p class="quotx">For each question, you will be given a number of options from which you should choose <b>one</b> correct answer.</p>';
		instructs += '<p class="quotx">Once you have selected what you believe to be the correct answer, indicate this by either:</p>';
		instructs += '<ul><li><span class="quotx">clicking the left-hand mouse button when the pointer is over your selected answer; or</span></li>';
	  	instructs += '<li><span class="quotx">selecting your answer letter (A, B, C, . . . ) on the keyboard.</span></li></ul>';
		instructs += '<p class="quotx">Your answer will be highlighted in red and a message box will be displayed indicating whether or not you have selected the correct response.</p>';
		instructs += '<p class="quotx">When choosing a response, base your decision only on the information provided. Do not rely on any previous knowledge or experience you may have, as this may lead you to a wrong conclusion.  </p>';
	 	instructs += '<p class="quotx">Click on ‘Next’ to see the first of the 6 example practice questions.</p>';
		instructs += '</td></tr></table>';	
	}
	if( nPage == 3){
		instructs = ' ';
		SetVisibility( true );
		StartItemPages();
	}else {
		SetLayerHtml('InstructionPage',instructs);
		ShowLayer('InstructionPage');
  		instructpage = nPage;
		SetVisibility( false );   
	}	
	instructpage = nPage;
	labelSetUp(nPage);
}

function InstructNext(direction)
{
	OnInstructionPage( instructpage + direction );
}

function keyDown(e)
{  	     
    var key_press = GetKeypressed(e)
	
    if( instructpage < 3 ){
	    if( key_press == 13 || key_press == 34 || key_press == 39 ){
			if(IsLayerVisible('instructbutton')){
				InstructNext(1);	
				return;
			}	
		}
		
	    if( key_press == 33 || key_press == 37){
			if(IsLayerVisible('instructbackbutton')){			
				InstructNext(-1);
				return;
			}
		}
	}				

    if( instructpage >= 3 ){  
	   if( key_press == 13 || key_press == 34 || key_press == 39){ //enter, pagedn or right arrow
			if(IsLayerVisible('forwardbutton')){
				MoveQuestion(1);
				return;
			}			
	   }
	   if( key_press >= 65 && key_press <= 69 ){ //A to E
				SetAnswer(itemBank[questionno].itemindex, parseInt(key_press)-64)
				return;
	   }
	   if( key_press >= 97 && key_press <= 101 ){ //a to e
				SetAnswer(itemBank[questionno].itemindex, parseInt(key_press)-96)
				return;
	   }
	}
	
    if( instructpage >= 3 && questionno == 5 ){  
	   if( key_press == 13 || key_press == 34 || key_press == 39){ //enter, pagedn or right arrow
			if(IsLayerVisible('finishbutton')){
				FinishQuestion();
				return;
			}			
	   }
	}  								
}

function StartQuestionnaire()
{   
 	onfocus="instructbutton.focus()"

	SetKeypressedFunc(keyDown);
	SetObjects();						
	questionSetup();
	InstructNext(1);
}

function DoResize()
{
	if( instructpage < 10 ){
		SetVisibility( false );
		OnInstructionPage(instructpage);
	}
	else {
		SetVisibility( true );
		MoveQuestion(0);
	}
}


function SetVisibility( state )
{
	if( state == true ){
		HideLayer('InstructionPage');
		HideLayer('instructbutton');
		HideLayer('instructbackbutton');					
		HideLayer('CubiksCurvelayer');
		HideLayer('labellayer');
		HideLayer('Correct');
		HideLayer('Incorrect');				
		ShowLayer('qlayer');
		ShowLayer('sectdisp');
		ShowLayer('numberon');
		ShowLayer('backbutton');
		HideLayer('clearbutton');
		HideLayer('forwardbutton');
		HideLayer('finishbutton');
		HideLayer('Finishpanel');				
	}else {
		ShowLayer('InstructionPage');     			
	
		if(instructpage!=9)
			ShowLayer('instructbutton');
	
		if(instructpage==9)
			HideLayer('instructbutton');
	
		if(instructpage!=1)
			ShowLayer('instructbackbutton');
	
		if(instructpage==1)
			HideLayer('instructbackbutton');												
	
		ShowLayer('labellayer');
		HideLayer('qlayer');
		HideLayer('sectdisp');
		HideLayer('numberon');
		HideLayer('backbutton');
		HideLayer('forwardbutton');
		HideLayer('Finishpanel');
		HideLayer('Correct');
		HideLayer('Incorrect');
		HideLayer('clearbutton');		
	}
}

function navigationSetUp()
{
	nextNormal 		= "nimages/bnext.gif";
	nextOver 		= "nimages/rnext.gif";
	prevNormal 		= "nimages/bprev.gif";
	prevOver 		= "nimages/rprev.gif";
	finishNormal 	= "nimages/bfinish.gif";
	finishOver 		= "nimages/rfinish.gif";
	tryagainNormal 	= "nimages/btryagain.gif";
	tryagainOver 	= "nimages/rtryagain.gif";
	previousNormal 	= "nimages/bprev.gif";
	previousOver 	= "nimages/rprev.gif";
	clearNormal 	= "nimages/bclear.gif";
	clearOver 		= "nimages/rclear.gif";	
}

function sectionSetUp()
{
	sectionImgs = new Array(2);

	for( var i =0 ; i < 2; i++ )
		sectionImgs[i] = new Image;

	sectionImgs[0].src = "nimages/Practice1.gif";
	sectionImgs[1].src = "nimages/Practice2.gif";
}

function popupInfo( correctletter, poptiptext )
{
	this.correctletter = correctletter;
	this.poptiptext	   = poptiptext;
}

function popupInfoSetUp()
{
	Info 	= new Array;	
	Info[0] = new popupInfo( "C","Tip: to obtain the population density (ie number of people per square kilometre) you need to divide the total population by the total area.");
	Info[1] = new popupInfo( "E","Tip: as you do not have the figures for the ’total population available to work’ for each country for 1996 you do not have sufficient information to determine which country had the highest rate of unemployment.");
	Info[2] = new popupInfo( "A","Tip: for each country subtract the 1996 ‘population in employment’ figures from the 2001 ‘population in employment’ figures.");
	Info[3] = new popupInfo( "B","Tip: Sum the exports for countries A, B, C, & D and divide the exports for country B by this total and then multiply by 100 to get a %.");	
	Info[4] = new popupInfo( "A","Tip: be aware  that you are looking for a proportional (%) increase so although 2000-2001 may appear a large increase it is not necessarily the largest %  increase.  You need to subtract the first year figure in each pair from the second year figure and then divide this by the first years figure and multiply by 100 to get a percentage.");	
	Info[5] = new popupInfo( "C","Tip: this is a compound interest calculation therefore you need to work out 20% increase year on year from 1996 to 1999 taking into account the 20% increase each year.  Then subtract 80 million from this figure to give you how much more country C's exports would have been worth in 1999 if this had been the case.");
}

function textbits()
{
	Infotext 	= new Array;
	Infotext[0] = " is the correct response. Well done!"
	Infotext[1] = " is the correct response."
	Infotext[2] = "Please spend some time working through why answer "
	Infotext[3] = " is the correct one. Click 'Clear' to remove this message and when you fully understand why " 
	Infotext[4] = " is correct, click 'Next' to continue."
	Infotext[5] = "Please click on ‘Next’ to proceed to the next question."
	Infotext[6] = " is correct, click 'Finish' to continue."
	Infotext[7] = "Please click on ‘Finish’ to proceed to the final page."			
}

function responseItem( tdwidth, tagid, response, answered, correct )
{
	this.tdwidth 	  = tdwidth;
	this.tagid 		  = tagid;
	this.response	  = response;
	this.answered	  = answered;
	this.correct	  = correct;
}

function responseSetUp()
{
	response1 	 = new Array;
	response1[0] = new responseItem( 90,1,"<b>A&nbsp;</b> Country A",false,false);
	response1[1] = new responseItem(90,2,"<b>B&nbsp;</b> Country B",false,false);
	response1[2] = new responseItem(90, 3,"<b>C&nbsp;</b> Country C",false,true);
	response1[3] = new responseItem(90, 4,"<b>D&nbsp;</b> Country D",false,false);
	response1[4] = new responseItem(90,5,"<b>E&nbsp;</b> Cannot Say",false,false);
	
	response2 	 = new Array;
	response2[0] = new responseItem( 90,1,"<b>A&nbsp;</b> Country A",false,false);
	response2[1] = new responseItem(90,2,"<b>B&nbsp;</b> Country B",false,false);
	response2[2] = new responseItem(90, 3,"<b>C&nbsp;</b> Country C",false,false);
	response2[3] = new responseItem(90, 4,"<b>D&nbsp;</b> Country D",false,false);
	response2[4] = new responseItem(90,5,"<b>E&nbsp;</b> Cannot Say",false,true);

	response3 	 = new Array;
	response3[0] = new responseItem( 90,1,"<b>A&nbsp;</b> Country A",false,true);
	response3[1] = new responseItem(90,2,"<b>B&nbsp;</b> Country B",false,false);
	response3[2] = new responseItem(90, 3,"<b>C&nbsp;</b> Country C",false,false);
	response3[3] = new responseItem(90, 4,"<b>D&nbsp;</b> Country D",false,false);
	response3[4] = new responseItem(90,5,"<b>E&nbsp;</b> Cannot Say",false,false);

	response4 	 = new Array;
	response4[0] = new responseItem( 90,1,"<b>A&nbsp;</b> 15%",false,false);
	response4[1] = new responseItem(90,2,"<b>B&nbsp;</b> 20%",false,true);
	response4[2] = new responseItem(90, 3,"<b>C&nbsp;</b> 25%",false,false);
	response4[3] = new responseItem(90, 4,"<b>D&nbsp;</b> 30%",false,false);
	response4[4] = new responseItem(90,5,"<b>E&nbsp;</b> 35%",false,false);

	response5 	 = new Array;
	response5[0] = new responseItem( 90,1,"<b>A&nbsp;</b> 1996-1997",false,true);
	response5[1] = new responseItem(90,2,"<b>B&nbsp;</b> 1997-1998",false,false);
	response5[2] = new responseItem(90, 3,"<b>C&nbsp;</b> 1998-1999",false,false);
	response5[3] = new responseItem(90, 4,"<b>D&nbsp;</b> 1999-2000",false,false);
	response5[4] = new responseItem(90,5,"<b>E&nbsp;</b> 2000-2001",false,false);

	response6 	 = new Array;
	response6[0] = new responseItem( 90,1,"<b>A&nbsp;</b> 20 million",false,false);
	response6[1] = new responseItem(90,2,"<b>B&nbsp;</b> 35 million",false,false);
	response6[2] = new responseItem(90, 3,"<b>C&nbsp;</b> 75 million",false,true);
	response6[3] = new responseItem(90, 4,"<b>D&nbsp;</b> 80 million",false,false);
	response6[4] = new responseItem(90,5,"<b>E&nbsp;</b> 155 million",false,false);
}

function questionItem( itemindex, section, questiontxt, responsechoices, answer, flags )
{
	this.itemindex 		 = itemindex;
    this.section 		 = section;
	this.questiontxt 	 = questiontxt;
	this.responsechoices = responsechoices;
	this.answer 		 = answer;
    this.flags 		     = flags;
}
var itemBank = new Array;

function questionSetup()
{
	navigationSetUp();
    sectionSetUp();
	responseSetUp();
	popupInfoSetUp();
	textbits();
	labeltextbits();
 
	itemBank[0] = new questionItem( 1,1,"Which country was the most densely populated in 2001?",response1,0,0);
	itemBank[1] = new questionItem( 2,1,"Proportionally, which country had the highest rate of unemployment in 1996?",response2,0,0);
	itemBank[2] = new questionItem( 3,1,"Which country had the largest increase in people in employment from 1996 to 2001",response3,0,0);
	itemBank[3] = new questionItem( 4,2,"What percentage of the combined exports for countries A to D in 2001 was attributable to country B?",response4,0,0);
	itemBank[4] = new questionItem( 5,2,"Across which two years did country B’s exports demonstrate the greatest  percentage increase?",response5,0,0);
	itemBank[5] = new questionItem( 6,2,"Country C’s consumer goods exports were projected to rise at 20% per year from 1996 onwards.  Approximately how much more would Country C’s exports have been worth in 1999, compared to the actual 1999 figure, if this had been correct?",response6,0,0);
}

function Popup()
{	
	var quest = questionno;
	
	var Popupcontent = '<table class="quot2" cellspacing="0" cellpadding="0" width="470" height="60" bgcolor="#FDDBD9">';
		Popupcontent += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			 
		Popupcontent += '<tr height="20"><td width="15">&nbsp;</td>';
   		Popupcontent += '<td width="450" class="quot2">';
		Popupcontent += Info[quest].correctletter + Infotext[0];
		Popupcontent += '</td>';
		Popupcontent += '<td width="15">&nbsp;</td></tr>';
		Popupcontent += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			
		Popupcontent += '<tr height="20"><td width="15">&nbsp;</td>';
   		Popupcontent += '<td width="450" class="quot2">';
		Popupcontent += Infotext[5];
		Popupcontent += '</td>';
		Popupcontent += '<td width="15">&nbsp;</td></tr>';			
		Popupcontent += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';					
		Popupcontent += '</table>';			
	
		SetLayerHtml('Correct',Popupcontent);
		ShowLayer('Correct');
}

function PopupQuest5()
{	
	var quest = questionno;
	
	var Popupcontent = '<table class="quot2" cellspacing="0" cellpadding="0" width="470" height="60" bgcolor="#FDDBD9">';
		Popupcontent += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			 
		Popupcontent += '<tr height="20"><td width="15">&nbsp;</td>';
   		Popupcontent += '<td width="450" class="quot2">';
		Popupcontent += Info[quest].correctletter + Infotext[0];
		Popupcontent += '</td>';
		Popupcontent += '<td width="15">&nbsp;</td></tr>';
		Popupcontent += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			
		Popupcontent += '<tr height="20"><td width="15">&nbsp;</td>';
   		Popupcontent += '<td width="450" class="quot2">';
		Popupcontent += Infotext[6];
		Popupcontent += '</td>';
		Popupcontent += '<td width="15">&nbsp;</td></tr>';			
		Popupcontent += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';					
		Popupcontent += '</table>';			
	
		SetLayerHtml('Correct',Popupcontent);
		ShowLayer('Correct');
}

function PopupIncorrect()
{	
	var questno = questionno
			
	var Popupincorrect = '<table class="quot2" cellspacing="0" cellpadding="0" width="470" height="30" bgcolor="#FDDBD9">';
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			 
		Popupincorrect += '<tr height="20"><td width="15">&nbsp;</td>';
		Popupincorrect += '<td width="450" class="quot2">';			
		Popupincorrect += Info[questno].correctletter + Infotext[1];			
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			 
		Popupincorrect += '<tr height="20"><td width="15">&nbsp;</td>';
		Popupincorrect += '<td width="450" class="quot2">';			
		Popupincorrect += Infotext[2] + Info[questno].correctletter + Infotext[3] + Info[questno].correctletter + Infotext[4];
		Popupincorrect += '</td>';
		Popupincorrect += '<td width="15">&nbsp;</td></tr>';
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';
		Popupincorrect += '<tr height="20"><td width="15">&nbsp;</td>';
		Popupincorrect += '<td width="450" class="quot2">';			
		Popupincorrect += Info[questno].poptiptext;
		Popupincorrect += '</td>';
 		Popupincorrect += '<td width="15">&nbsp;</td></tr>';
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';						
		Popupincorrect += '</table>';													

		SetLayerHtml('Incorrect2',Popupincorrect);
		ShowLayer('Incorrect2');
}

function PopupIncorrectQuest5()
{	
	var questno = questionno
			
	var Popupincorrect = '<table class="quot2" cellspacing="0" cellpadding="0" width="470" height="30" bgcolor="#FDDBD9">';
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			 
		Popupincorrect += '<tr height="20"><td width="15">&nbsp;</td>';
		Popupincorrect += '<td width="450" class="quot2">';			
		Popupincorrect += Info[questno].correctletter + Infotext[1];			
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';			 
		Popupincorrect += '<tr height="20"><td width="15">&nbsp;</td>';
		Popupincorrect += '<td width="450" class="quot2">';			
		Popupincorrect += Infotext[2] + Info[questno].correctletter + Infotext[3] + Info[questno].correctletter + Infotext[6];
		Popupincorrect += '</td>';
		Popupincorrect += '<td width="15">&nbsp;</td></tr>';
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';
		Popupincorrect += '<tr height="20"><td width="15">&nbsp;</td>';
		Popupincorrect += '<td width="450" class="quot2">';			
		Popupincorrect += Info[questno].poptiptext;
		Popupincorrect += '</td>';
 		Popupincorrect += '<td width="15">&nbsp;</td></tr>';
		Popupincorrect += '<tr height="10"><td colspan="3">&nbsp;</td></tr>';						
		Popupincorrect += '</table>';													

		SetLayerHtml('Incorrect2',Popupincorrect);
		ShowLayer('Incorrect2');
}

function StartItemPages()
{
// 	var d;
//  d = new Date();
  	testnav = true;
	MoveQuestion(0);
}

function PresentQuestion( questionindex )
{	
	var itemcontent = '<div align="center"><center><table border="0" cellspacing="3" cellpadding="5" width="605"><tr align="left" valign="middle">'; 
	   	itemcontent += '<td colspan="5" class="quote">'; 
		itemcontent += itemBank[questionindex].questiontxt;
		itemcontent += '</td></tr><tr align="left" valign="bottom">';

	for( var i = 0; i < 5; i++ ){
	
		var isresponseactive = (itemBank[questionindex].responsechoices[i].tagid > 0 )?true:false;

		itemcontent += '<td width="' + itemBank[questionindex].responsechoices[i].tdwidth + '">';

		var isresponseactive = (itemBank[questionindex].responsechoices[i].tagid > 0 )?true:false;
		if( isresponseactive ){				
			itemcontent += '<a href="javascript:SetAnswer('				
			itemcontent += itemBank[questionindex].itemindex;
			itemcontent += ',';
			itemcontent += itemBank[questionindex].responsechoices[i].tagid;
			itemcontent += ')" ';
			
			if( itemBank[questionindex].responsechoices[i].answered == true ){
				if (!IsNS4())
					itemcontent += '><span class="answerbox"';
				else
					itemcontent += 'class="answerbox"';
				}															
				itemcontent += '>';
			}
			itemcontent += itemBank[questionindex].responsechoices[i].response;
			if( isresponseactive ){
				if (!IsNS4())
				 	itemcontent += '</span>';

				itemcontent += '</a>';
			}
			itemcontent += '</td>';
	}
	itemcontent += '</tr></table></center></div>';
	
	SetSection( itemBank[questionindex].section );
	SetLayerHtml('qlayer',itemcontent);
	ShowLayer('qlayer');
	SetLayerPixLeft('qlayer',122)
	SetLayerPixTop('qlayer',384)  
	
	for(i=0; i<5; i++){
		if(itemBank[5].responsechoices[i].answered == true && itemBank[questionindex].responsechoices[i].correct == false && gtryagain == true){
			HideLayer('finishbutton');
			HideLayer('forwardbutton');
		}	
		if(itemBank[questionno].responsechoices[i].answered == true && itemBank[questionindex].responsechoices[i].correct == false && gtryagain == true){
			HideLayer('Incorrect2');
			if(IsLayerHidden('Incorrect2'))
				ShowLayer('forwardbutton');	
		}	
	}
}

function SetSection( sectionid )
{
	if (IsNS4()){
		if(document.sectdisp.document.images){

	 		if( sectionid != sectionno ){

				sectionno = sectionid;
            	var obj;
					obj = document.sectdisp.document.images["thesect"];
					obj.src = sectionImgs[sectionid-1].src;
			}
		}		

	}else{
		if( document.images ){
	 		if( sectionid != sectionno ){
				sectionno = sectionid;
            	var obj;
					obj = document.images["thesect"];
					obj.src = sectionImgs[sectionid-1].src;
			}
		}
	}		
}

function SwapNext( onover )
{
	if( document.images ){
        var obj;
		if (IsNS4())
			obj = document.forwardbutton.document.images["gnext"];
		else
			obj = document.images["gnext"];
			
		obj.src = (onover == true)?nextOver:nextNormal;		
	}
}

function SwapClear( onover )
{
	if( document.images ){
		var obj;
		if (IsNS4())
			obj = document.backbutton.document.images["gclear"];
		else
			obj = document.images["gclear"];
			
		obj.src = (onover == true)?clearOver:clearNormal;
	}
}

function SwapTryAgain( onover )
{
	if( document.images ){
    	var obj;
		if (IsNS4())
			obj = document.backbutton.document.images["gtryagain"];
		else
			obj = document.images["gtryagain"];
			
		obj.src = (onover == true)?tryagainOver:tryagainNormal;
	}
}

function SwapPrevious( onover )
{
	if( document.images ){
		var obj;
		if (IsNS4())
			obj = document.backbutton.document.images["gprevious"];
		else
			obj = document.images["gprevious"];
			
		obj.src = (onover == true)?previousOver:previousNormal;
	}	
}

function SwapInstructPrev( onover )
{
	if( document.images ){
        var obj;
		if (IsNS4())
			obj = document.instructbackbutton.document.images["ginstback"];
		else
			obj = document.images["ginstback"];
			
		obj.src = (onover == true)?prevOver:prevNormal;
	}
}

function SwapInstructNext( onover )
{
	if( document.images ){
       	var obj;
		if (IsNS4())
			obj = document.instructbutton.document.images["ginst"];
		else
			obj = document.images["ginst"];
			
		obj.src = (onover == true)?"nimages/rnext.gif":"nimages/bnext.gif";		
	}
}

function SwapFinish( onover )
{
	if( document.images ){	
		var obj;
		if (IsNS4())
			obj = document.finishbutton.document.images["gfinish"];
		else				
			obj = document.images["gfinish"];
			
		obj.src = (onover == true)?finishOver:finishNormal;
	}
}	

function MoveQuestion( direction )
{
	HideLayer('objforwardbutton');
	HideLayer('objbackbutton');	
	HideLayer('objCorrect');
	HideLayer('objIncorrect2');

	if( testnav == false )
		return;

	var newquestionno = questionno + direction;
	if( newquestionno > (itemBank.length-1))
		newquestionno = (itemBank.length-1);		
			
   	if( newquestionno < 0 )
		newquestionno = 0;
				
	if( newquestionno > 5 )
		FinishQuestion(); 

	if(IsLayerVisible('objclearbutton')) {
		HideLayer('objbackbutton');
		HideLayer('objclearbutton');
	}
	if(IsLayerVisible('objCorrect')) {
		HideLayer('objIncorrect2');
		HideLayer('objIncorrect');
		HideLayer('objCorrect');
		HideLayer('objbackbutton');			
	}
	if(IsLayerVisible('objIncorrect2')) {
		HideLayer('objIncorrect2');
		HideLayer('objIncorrect');
		HideLayer('objCorrect');
		HideLayer('objbackbutton');			
	}																		
   	questionno = newquestionno;
	incorrectcount = 0;
   	PresentQuestion( questionno );
	SetNumberon( questionno+1 );
	gtryagain = false;		
}

function SetNumberon( number )
{
	var numbercontent = '<table class="label" cellspacing="0" cellpadding="0" width="670" height="35">';			 
		numbercontent += '<tr height="35"><td width="15">&nbsp;</td>';
		numbercontent += '<td width="645" class="label">';
		numbercontent += '<span class="title">Example practice question&nbsp;' + number + '&nbsp;of&nbsp;6</span>';
		numbercontent += '</td>';
		numbercontent += '</tr>';					
		numbercontent += '</table>';
			
	SetLayerHtml('numberon',numbercontent);
	ShowLayer('numberon');
}

function SetAnswer( questionid ,itemid )
{						
	if (incorrectcount >= 2 )
		return;

	if (IsLayerVisible('objbackbutton') || IsLayerVisible('objclearbutton'))
		return;
			
	if (IsLayerVisible('objforwardbutton') || IsLayerVisible('objfinishbutton'))
		return;	
		
	var iscorrect 	  = false;	
	var questionindex = questionid - 1;		
	
	itemBank[0].answered = 0;
		
	if( itemBank[questionindex].answer != itemid ){
		itemBank[questionindex].answer = itemid;
				
		for( var i = 0; i < 5; i++ ){				
			if(itemBank[questionindex].responsechoices[i].tagid == itemid){
			 	itemBank[questionindex].responsechoices[i].answered = true;
				iscorrect = itemBank[questionindex].responsechoices[i].correct;
			}else{
				itemBank[questionindex].responsechoices[i].answered = false;
			}	
		}	
		PresentQuestion(questionindex);
						
		if( iscorrect == true ){					
			ShowLayer('objCorrect');
			HideLayer('objbackbutton');
			HideLayer('objIncorrect');
			HideLayer('objIncorrect2');
								
			ShowLayer('objforwardbutton');
			incorrectcount = 2;							
			Popup();
			
			if (questionno == 5){
				ShowLayer('objfinishbutton');
				PopupQuest5();				
			}	
			else
				HideLayer('objfinishbutton');			
		}
		if( iscorrect == false ){				
			ShowLayer('objIncorrect');
			ShowLayer('objbackbutton');
			HideLayer('objIncorrect2');
			HideLayer('objclearbutton');	
			HideLayer('objforwardbutton');							
			HideLayer('objCorrect');

			if(gtryagain == false)
				incorrectcount = 2;																							
		}
		if( iscorrect == false && gtryagain == true ){							
			ShowLayer('objclearbutton');
			ShowLayer('objIncorrect2');
			HideLayer('objbackbutton');
			HideLayer('objIncorrect');
			HideLayer('objforwardbutton');							
			HideLayer('objCorrect');
							
			if(gtryagain == true)
				incorrectcount = 2;							

			PopupIncorrect();
			
			if (questionno == 5){
				PopupIncorrectQuest5();
			}	
			else
				HideLayer('objfinishbutton');			
		}									
	}
}

function CloseLayer()
{
//	alert("Close");
	incorrectcount = 0;
	if(IsLayerVisible('objIncorrect')) {
		HideLayer('objIncorrect');
		HideLayer('objIncorrect2')
		gtryagain = true;			
	}
	if(IsLayerHidden('objIncorrect')) {
		HideLayer('objbackbutton');
		gtryagain = true;			
	}
	ClearBtns();
}

function CloseClearBtnLayer()
{
	if(IsLayerVisible('objIncorrect2')) {
		HideLayer('objIncorrect2');
		HideLayer('objbackbutton');
		HideLayer('objfinishbutton');
		HideLayer('objforwardbutton');							
		ShowLayer('objclearbutton');						
		gtryagain = true;			
	}
	
	if(IsLayerVisible('objIncorrect2') && questionno == 5) {
		HideLayer('objfinishbutton');
		HideLayer('objIncorrect2');
		HideLayer('objbackbutton');
		HideLayer('objforwardbutton');				
		ShowLayer('objclearbutton');						
		gtryagain = true;
	}
				
	if(IsLayerHidden('objIncorrect2')) {
		HideLayer('objclearbutton');		
		ShowLayer('objforwardbutton');				
		gtryagain = true;			
	}	

	if(IsLayerHidden('objIncorrect2') && questionno == 5) {
		HideLayer('objclearbutton');
		HideLayer('objforwardbutton');
		ShowLayer('objfinishbutton');						
		gtryagain = true;			
	}	
	ClearBtns();
}	

function ClearBtns()
{	
	for(i=0; i<5; i++){
		if(gtryagain == true)
			itemBank[questionno].responsechoices[i].answered = false;
	}
	PresentQuestion( questionno );
}

function ClearCorrect()
{	
	gfinish = true;

	for(i=0; i<6; i++){	
		for(j=0; j<5; j++){
			if(gfinish == true)
				itemBank[i].responsechoices[j].answered = false;
		}
		itemBank[i].answer = 0
	}
	FinishQuestion();								
}
    
function FinishQuestion() 
{
	testnav = false;

	ShowLayer('Finishpanel');
	HideLayer('qlayer');
	HideLayer('sectdisp');
	HideLayer('numberon');
	HideLayer('backbutton');
	HideLayer('finishbutton');
	HideLayer('forwardbutton');
	ShowLayer('CubiksCurvelayer');			
	ShowLayer('labellayer');
	HideLayer('InstructionPage');			
	HideLayer('Incorrect2');
	HideLayer('instructbackbutton');
	HideLayer('instructbutton');
	HideLayer('Correct');						
	HideLayer('Incorrect');
	HideLayer('clearbutton');

	var labelcontent = '<table class="label" cellspacing="0" cellpadding="0" width="480" height="35">';			 
		labelcontent += '<tr height="35"><td width="15">&nbsp;</td>';
		labelcontent += '<td width="465" class="label">';
		labelcontent += Labeltext[4];
		labelcontent += '</td>';
		labelcontent += '</tr>';					
		labelcontent += '</table>';			

	SetLayerHtml('labellayer',labelcontent);	
	MoveQuestion(0);
}

