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 8 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.  If you will be taking the test online, this has a time limit which is controlled by the computer.  If you will be taking the pencil/paper version of the test, you will be timed by your test administrator and advised when the time limit is reached.  In either testing circumstance, full instructions will be given to you before you take the 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 8 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 == 7 ){  
	   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/Practice3.gif";
	sectionImgs[1].src = "nimages/Practice4.gif";
}

function popupInfo( correctletter, poptiptext )
{
	this.correctletter = correctletter;
	this.poptiptext	   = poptiptext;
}

function popupInfoSetUp()
{
	Info 	= new Array;	
	Info[0] = new popupInfo( "C","Tip: Check the price of a document holder when ten are purchased.");
	Info[1] = new popupInfo( "E","Tip: Calculate the price of 2 keyboards and 10 document holders separately.");
	Info[2] = new popupInfo( "D","Tip: Compare the price of an individual mouse mat and one in the third column.");
	Info[3] = new popupInfo( "C","Tip: Each order of 5 mice is priced at $4 a mouse.");	
	Info[4] = new popupInfo( "D","Tip: Subtract the number of flights booked to Europe from the number of flights booked to USA.");	
	Info[5] = new popupInfo( "B","Tip: There were 50 flights in total.");
	Info[6] = new popupInfo( "C","Tip: Divide the number of European flights by the number of Malaysian flights.");
	Info[7] = new popupInfo( "B","Tip: Divide the overall decrease into the total number of flights taken January to March.");

}

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> $7",false,false);
	response1[1] = new responseItem(90,2,"<b>B&nbsp;</b> $63",false,false);
	response1[2] = new responseItem(90,3,"<b>C&nbsp;</b> $70",false,true);
	response1[3] = new responseItem(90,4,"<b>D&nbsp;</b> $150",false,false);
	response1[4] = new responseItem(90,5,"<b>E&nbsp;</b> $220",false,false);
	
	response2 	 = new Array;
	response2[0] = new responseItem(90,1,"<b>A&nbsp;</b> $98",false,false);
	response2[1] = new responseItem(90,2,"<b>B&nbsp;</b> $199",false,false);
	response2[2] = new responseItem(90,3,"<b>C&nbsp;</b> $248",false,false);
	response2[3] = new responseItem(90,4,"<b>D&nbsp;</b> $350",false,false);
	response2[4] = new responseItem(90,5,"<b>E&nbsp;</b> $418",false,true);

	response3 	 = new Array;
	response3[0] = new responseItem(90,1,"<b>A&nbsp;</b> $0.50",false,false);
	response3[1] = new responseItem(90,2,"<b>B&nbsp;</b> $1.00",false,false);
	response3[2] = new responseItem(90,3,"<b>C&nbsp;</b> $1.50",false,false);
	response3[3] = new responseItem(90,4,"<b>D&nbsp;</b> $2.00",false,true);
	response3[4] = new responseItem(90,5,"<b>E&nbsp;</b> $2.50",false,false);

	response4 	 = new Array;
	response4[0] = new responseItem(90,1,"<b>A&nbsp;</b> $30",false,false);
	response4[1] = new responseItem(90,2,"<b>B&nbsp;</b> $60",false,false);
	response4[2] = new responseItem(90,3,"<b>C&nbsp;</b> $120",false,true);
	response4[3] = new responseItem(90,4,"<b>D&nbsp;</b> $240",false,false);
	response4[4] = new responseItem(90,5,"<b>E&nbsp;</b> $300",false,false);

	response5 	 = new Array;
	response5[0] = new responseItem(90,1,"<b>A&nbsp;</b> 20",false,false);
	response5[1] = new responseItem(90,2,"<b>B&nbsp;</b> 30",false,false);
	response5[2] = new responseItem(90,3,"<b>C&nbsp;</b> 40",false,false);
	response5[3] = new responseItem(90,4,"<b>D&nbsp;</b> 50",false,true);
	response5[4] = new responseItem(90,5,"<b>E&nbsp;</b> 60",false,false);

	response6 	 = new Array;
	response6[0] = new responseItem(90,1,"<b>A&nbsp;</b> $3,500",false,false);
	response6[1] = new responseItem(90,2,"<b>B&nbsp;</b> $17,500",false,true);
	response6[2] = new responseItem(90,3,"<b>C&nbsp;</b> $27,500",false,false);
	response6[3] = new responseItem(90,4,"<b>D&nbsp;</b> $35,000",false,false);
	response6[4] = new responseItem(90,5,"<b>E&nbsp;</b> $70,000",false,false);

	response7 	 = new Array;
	response7[0] = new responseItem(90,1,"<b>A&nbsp;</b> 15%",false,false);
	response7[1] = new responseItem(90,2,"<b>B&nbsp;</b> 20%",false,false);
	response7[2] = new responseItem(90,3,"<b>C&nbsp;</b> 25%",false,true);
	response7[3] = new responseItem(90,4,"<b>D&nbsp;</b> 30%",false,false);
	response7[4] = new responseItem(90,5,"<b>E&nbsp;</b> 35%",false,false);

	response8 	 = new Array;
	response8[0] = new responseItem(90,1,"<b>A&nbsp;</b> 25%",false,false);
	response8[1] = new responseItem(90,2,"<b>B&nbsp;</b> 33%",false,true);
	response8[2] = new responseItem(90,3,"<b>C&nbsp;</b> 45%",false,false);
	response8[3] = new responseItem(90,4,"<b>D&nbsp;</b> 50%",false,false);
	response8[4] = new responseItem(90,5,"<b>E&nbsp;</b> 66%",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,"If document holders cost the retailer $15 how much profit would she make when a customer buys 10 document holders in one order?",response1,0,0);
	itemBank[1] = new questionItem( 2,1,"What is the total cost for an order of 2 ergonomic keyboards and 10 document holders?",response2,0,0);
	itemBank[2] = new questionItem( 3,1,"What is the increase in price per item when mouse mats are bought separately rather than in batches of twenty?",response3,0,0);
	itemBank[3] = new questionItem( 4,1,"How much extra would it cost to order 20 ergonomic mice in 5 orders of 4 each, rather than placing one order for 20?",response4,0,0);
	itemBank[4] = new questionItem( 5,2,"How many more flights were booked to the USA than to Europe?",response5,0,0);
	itemBank[5] = new questionItem( 6,2,"Business flights to Australia cost $350.  What was their total cost in the period January to March?",response6,0,0);
	itemBank[6] = new questionItem( 7,2,"What was the number of European flights booked as a percentage of the Malaysian flights?",response7,0,0);
	itemBank[7] = new questionItem( 8,2,"In April to June the planned number of flights to Hong Kong is 30.  What is this decrease as a percentage of the number of flights booked in January to March?",response8,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[7].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 > 7 )
		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;8</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 == 7){
				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 == 7){
				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 == 7) {
		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 == 7) {
		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<8; 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);
}

