// Define global variables and arrays
var qI	= 0;
var checker8 = true;
var choice8	= new Array();
var correctans8 	= 0;
var nextq 	= 1;
var quiz8;

function itemReset() {	//resets everything
	qI 	= 0;
	choice8 = new Array();
	correctans8 	= 0;
	nextq	= 1;
	}
	
function busted8() {
	alert('Sorry, you only get one shot at each question.');
	quiz8.history.forward(); 
	quiz8.focus();
	}
	
function book()	{
	parent.location.href='/licensing/learnerdrivers/1464.asp';
	quiz8.document.close();
	}
	
function restart(){
	parent.location.href="/licensing/learnerdrivers/1465.asp"
	quiz8.document.close();
	}

function startquiz8(openStatus, whetherOrNot) {		// Administer the test and record the ans
		
	checker8 = openStatus;
		
	if (whetherOrNot < qI) { 
		busted8(); 
		return; 
		}
	
	if (checker8) { 
		quiz8 = window.open('','QuizOne','width=640,height=480,scrollbars=yes');
		//quiz8.moveTo(150,150);		
		quiz8.focus(); 
		!checker8;
		}
	
	if (qI == qus8.length) { 
		gradeTest8(); 
		return; 
		}
	displayeight();
	}

function quizeight(number,question,optionA,optionB,optionC,ans,img) {    
	this.number = number;
	this.question=question; 
	this.optionA = optionA;
	this.optionB=optionB;    
	this.optionC=optionC; 
	this.ans = ans; 
	this.img = img;  
	return this;
	}
	
function displayeight()	{	// display questions
	
	// Write the qusestons and answrs options to the new window
	quiz8.document.clear();
	quiz8.document.open();
	quiz8.document.writeln('<html><head><title>Learners Practice Quiz 8</title>');
	quiz8.document.writeln('<link href="/css/purple.css" rel="stylesheet" type="text/css">');
	quiz8.document.writeln('</head><body bgcolor="\#ffffff\">');
	quiz8.document.writeln('<h3>Question '+ qus8[qI].number +'</h3>');
	quiz8.document.writeln('<table width=\'600\' cellspacing=\'5\'>');
	quiz8.document.writeln('<tr class=\'bg3\'><td align=\'left\' valign=\'top\' colspan=\'3\' height=\"40\">');
	quiz8.document.writeln('<p><b class=\'bodyhdr\'>' +qus8[qI].question+ '</b>');
	quiz8.document.writeln('</td></tr><td width=\'2\'>&nbsp;</td></tr>');
	quiz8.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz8.document.writeln('A&nbsp;<input type=\'radio\' name=\"answer\" value=\"a\" onClick="opener.choice8[opener.qI - 1] = this.value;\"></p>');
	quiz8.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');	
	quiz8.document.writeln('<p>'+qus8[qI].optionA+'</p>');
	quiz8.document.writeln('</td><td valign=\'top\' width=\'200\'rowspan=\'4\' height=\"200\">');
	quiz8.document.writeln('<img border=\"0\" width=\"200\" height=\"200\" align=\"right\" src=\"'+qus8[qI].img+'\">');
	quiz8.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz8.document.writeln('B&nbsp;<input type=\'radio\' name=\"answer\" value=\"b\" onClick="opener.choice8[opener.qI - 1] = this.value;\"></p>');
	quiz8.document.writeln('</td><td align=\'left\'valign=\'top\' width=\'340\' height=\'35\'>');
	quiz8.document.writeln('<p>'+qus8[qI].optionB+'</p>');
	quiz8.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz8.document.writeln('C&nbsp;<input type=\'radio\' name=\"answer\" value=\"c\" onClick="opener.choice8[opener.qI - 1] = this.value;\"></p>');
	quiz8.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');
	quiz8.document.writeln('<p>'+qus8[qI].optionC+'</p>');
	quiz8.document.writeln('</td></tr><tr align=\'left\' valign=\"top\" align=\'left\'><td width=\'30\'height=\'95\'>&nbsp;</td></tr>');
	quiz8.document.writeln('<tr align=\'right\'><td colspan=\'3\'>');
	quiz8.document.writeln('<input type=\'button\' value=\"NEXT QUESTION\" onClick="opener.startquiz8(false,' +nextq+ ')\;">');  
	quiz8.document.writeln('</td></tr></table></body></html>');
	quiz8.document.close();
	// Increment variables for the next question
	qI++;
	nextq++;
	}

function gradeTest8() {		// Increment the variables for the last time	
	qI++;
	nextq++;	
	
	for (var i = 0; i < qus8.length; i++) {		// Compare student ans with correct ans
		if (choice8[i] == qus8[i].ans) {
			correctans8++;
			}
		}	
	printResults8();	// Print the test results
	}
	
function printResults8() {		// Print the questions, answer options, and other info
	quiz8.document.clear();
	quiz8.document.open();
	quiz8.document.writeln('<html><head>');
	quiz8.document.writeln('<title>Quiz Eight Results</title>');
	quiz8.document.writeln('<link href="css/purplelocal.css" rel="stylesheet" type="text/css">');
	quiz8.document.writeln('</head><body BGCOLOR=\"WHITE\">');						
	quiz8.document.writeln('<h3>Quiz Results</h3>');						
	quiz8.document.writeln('<p class=\'bodyhdr\'>Your score out of 30 is &nbsp;'+correctans8+'</p>');
	quiz8.document.writeln('<p>Here is how you scored individually for each question:</p><hr>');
	quiz8.document.writeln('<table width=\'600\' cellpadding=\'0\'>');
	
	for (var i = 0; i < qus8.length; i++) {
	
	quiz8.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'30\' width=\'20\'>');
	quiz8.document.writeln('<p><b>'+qus8[i].number+ '</b></td><td colspan=\'2\'><p>' +qus8[i].question+'</p>');
	quiz8.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz8.document.writeln('<p>a.</td><td width=\'450\'><p>' +qus8[i].optionA+ '</td>');
	quiz8.document.writeln('<td width=\'100\' rowspan=\'3\'><img border=\"0\" width=\"100\" height=\"100\" src=\"'+qus8[i].img+'\">');
	quiz8.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');	
	quiz8.document.writeln('<p>b.</td><td><p>' +qus8[i].optionB+ '</td></tr>');
	quiz8.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz8.document.writeln('<p>c.</td><td><p>' +qus8[i].optionC+ '<p>');
	
	// Determine if the student answered each question appropriately, and display accordingly
	if (choice8[i] == qus8[i].ans) {
		quiz8.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"GREEN\">You answered this correctly.  Your answer was:\n' +qus8[i].ans+ '.</font></b>\n</td>');
				}		
		else { 
		quiz8.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"RED\">The correct answer is:\n' +qus8[i].ans+ '\n</font></b>'); 
		}

	quiz8.document.writeln('</td></tr><tr><td colspan=\'3\'><hr></td></tr>');
	}
	i++;	
	quiz8.document.writeln('</table>');
	// Add extra info about the ranking, questions, and application
	quiz8.document.writeln('<p>You can always <a href=# onclick=\'window.close(); opener.restart();\'"><B>retake</B></a> another quiz or go back and read the <a href=# onclick=\'window.close(); opener.book();\'">Drive Safe Book.</a></p><p>Remember to hit refresh or reload to get a new set of questions.');
	quiz8.document.writeln('</body></html>');
	quiz8.document.close();
	}
	
	
var qus8 = new Array();
qus8[0] =new quizeight	("1","Are passengers allowed to travel in the back of a utility or in an open load space?","Yes, if the vehicle does not exceed 60km/h.","Yes, providing they are seated.","No.","c","img/trans.gif","Q54 Restraints ")

qus8[1] =new quizeight	("2","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle Y.","Vehicle X.","b","img/Q81.gif","Q81 ROW(2)")

qus8[2] =new quizeight	("3","If you are travelling in a lane that has a left-turn arrow marked on the road, can you drive straight ahead?","Yes, if no other traffic is approaching.","No.","Yes.","b","img/trans.gif","Q32 Position")

qus8[3] =new quizeight	("4","What is the meaning of this sign?","No entry.","Caution, crossroad ahead.","Caution, ambulance depot.","b","img/Q103.gif","Q103 Signs & Parking")

qus8[4] =new quizeight	("5","Which of the following statements is correct?","Vehicle X gives way to both Y and Z.","Vehicle Y gives way to both X and Z.","Vehicle Z gives way to both X and Y.","a","img/Q72.gif","Q72 ROW(2)")

qus8[5] =new quizeight	("6","What is the speed limit where roads are under construction or repair?","20km/h.","The speed limit shown on the road works sign.","40km/h.","b","img/trans.gif","Q110 Speed")

qus8[6] =new quizeight	("7","Is it an offence to refuse a breath test for alcohol?","No, providing you have a doctor's certificate.","Yes.","No.","b","img/trans.gif","Q5 Alcohol")

qus8[7] =new quizeight	("8","What is the correct procedure when changing lanes?","Check your blind spot using the external mirrors, indicate and give way to traffic in the other lane.","Touch your brake pedal to warn any drivers behind you, indicate and give way to traffic in the other lane.","Check your mirrors, look over your shoulder to check your blind spot, indicate to change lane for a sufficient distance to warn other drivers of your intention, and give way to traffic in the other lane.","c","img/trans.gif","Q116 Stop & Indicate")

qus8[8] =new quizeight	("9","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle Y.","Vehicle X.","c","img/Q70.gif","Q70 ROW(1)")

qus8[9] =new quizeight	("10","If you are turning right at traffic lights and the light is green (as shown in the diagram), what should you do?","Turn only if you can do so without interfering with other traffic.","Wait until the light changes to red and then turn quickly.","Do not move until the light changes to yellow and then turn quickly.","a","img/Q31.gif","Q31 Intersections")

qus8[10] =new quizeight	("11","Are you allowed to use a hand-held mobile phone while driving?","No.","Yes, providing you do not lose concentration.","Yes.","a","img/trans.gif","Q130 Vehicle")

qus8[11] =new quizeight	("12","What should you do if an emergency vehicle is using a siren or flashing lights?","Flash your headlights to warn other drivers.","Accelerate to avoid the emergency vehicle.","Give way by moving to the left or right, if it is safe to do so.","c","img/trans.gif","Q17Emergency")

qus8[12] =new quizeight	("13","What is the meaning of this sign?","Caution, school ahead.","Caution, pedestrian crossing ahead.","Caution, traffic lights ahead.","b","img/Q149.gif","Q149 Vulnerable Road Users")

qus8[13] =new quizeight	("14","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle Y.","Vehicle X.","b","img/Q74.gif","Q74 ROW(2)")

qus8[14] =new quizeight	("15","Is vehicle X allowed to overtake vehicle Y?","No.","Yes, if it is safe to do so.","It depends on the weather conditions.","b","img/Q36.gif","Q36 Position")

qus8[15] =new quizeight	("16","What should you do when travelling behind a vehicle in wet weather?","Drive the same as you would in dry weather conditions.","Keep a greater distance behind the vehicle than normal.","Keep a closer distance behind the vehicle than normal.","b","img/trans.gif","Q132 Vehicle")

qus8[16] =new quizeight	("17","How do even small amounts of alcohol affect your driving?","By making you think you are driving better than you are.","By helping your driving ability.","By helping your judgement of speed.","a","img/trans.gif","Q4 Alcohol")

qus8[17] =new quizeight	("18","What is the meaning of this sign?","Caution, you are approaching a one-way street.","Caution, you are approaching a '\T'\ junction.","Caution, no through road.","b","img/Q104.gif","Q104 Signs & Parking")

qus8[18] =new quizeight	("19","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","b","img/Q63.gif","	RQ63 OW(1)")

qus8[19] =new quizeight	("20","Are you allowed to travel faster than the speed limit when you are overtaking a vehicle?","No.","Yes.","Yes, if the driver of the vehicle in front signals you to overtake.","a","img/trans.gif","Q107 Speed")

qus8[20] =new quizeight	("21","Which of the following statements is correct?","Vehicle X may overtake Y, only in a 60km/h area.","Vehicle X must not overtake Y.","Vehicle X may overtake Y.","c","img/Q44.gif","Q44 Position")

qus8[21] =new quizeight	("22","When you want to cross an intersection, but you can see that the traffic ahead of you is banked up on the other side of the intersection, what must you do?","Sound your horn and move slowly forward.","Stop before entering and make sure that you will not block the intersection if you join the queue.","Join the queue of traffic.","b","img/trans.gif","Q22 Intersections")

qus8[22] =new quizeight	("23","What is the meaning of this sign?","Caution, an attended children's crossing is ahead.","Caution, watch out for children.","Caution, stop immediately if you see children.","b","img/Q150.gif","Q150 Vulnerable Road Users"	)

qus8[23] =new quizeight	("24","How long must you indicate before you turn left or right for?","At least 70 metres before the turn.","Long enough to give sufficient warning to other road users before you turn.","At least 10 metres before the turn.","b","img/trans.gif","Q118 Stop & Indicate")

qus8[24] =new quizeight	("25","What is the legal blood alcohol concentration (BAC) for drivers with a full licence?","Less than 0.02%.","Less than 0.05%.","Less than 0.08%.","b","img/trans.gif","Q7 Alcohol")

qus8[25] =new quizeight	("26","Who will be fined if a passenger under the age of 16 is not wearing a seat belt or suitable child restraint?","The owner of the vehicle.","The passenger.","The driver of the vehicle.","c","img/trans.gif","Q56	Restraints")

qus8[26] =new quizeight	("27","What is the meaning of this sign?","There is a steep hill ahead.","Slow down for a dip in the road.","Caution, the road curves right, then left.","c","img/Q105.gif","Q105 Signs & Parking")

qus8[27] =new quizeight	("28","What should you do when approaching a railway crossing?","Speed up to clear the crossing quickly.","Slow down and be prepared to stop.","Sound your horn.","b","img/trans.gif","Q25 Intersections")

qus8[28] =new quizeight	("29","Which of the following statements is correct?","Vehicle Y gives way to both X and Z.","Vehicle X gives way to both Y and Z.","Vehicle Z gives way to both X and Y.","a","img/Q66.gif","Q66 ROW(1)")

qus8[29] =new quizeight	("30","What should you do if you are travelling slowly on a two-way road and there is a queue of vehicles behind you?","Pull well over to the left and allow the vehicles to overtake you.","Keep to the middle of the road to prevent dangerous overtaking.","Keep well to the right so the queue of vehicles can overtake on the left.","a","img/trans.gif","Q40 Position")
