// Define global variables and arrays
var qI	= 0;
var checker4 = true;
var choice4	= new Array();
var correctans4 	= 0;
var nextq 	= 1;
var quiz4;

function itemReset() {	//resets everything
	qI 	= 0;
	choice4 = new Array();
	correctans4 	= 0;
	nextq	= 1;
	}
	
function busted4() {
	alert('Sorry, you only get one shot at each question.');
	quiz4.history.forward(); 
	quiz4.focus();
	}
	
function book()	{
	parent.location.href='/licensing/learnerdrivers/1464.asp';
	quiz4.document.close();
	}
		
function restart(){
	parent.location.href="/licensing/learnerdrivers/1465.asp"
	quiz4.document.close();
	}

function startquiz4(openStatus, whetherOrNot) {		// Administer the test and record the ans
		
	checker4 = openStatus;
		
	if (whetherOrNot < qI) { 
		busted4(); 
		return; 
		}
	
	if (checker4) { 
		quiz4 = window.open('','QuizOne','width=640,height=480,scrollbars=yes');
		//quiz4.moveTo(150,150);
		quiz4.focus(); 
		!checker4;
		}
	
	if (qI == qus4.length) { 
		gradeTest4(); 
		return; 
		}
	displayfour();
	}

function quizfour(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 displayfour()	{	// display questions

			
	// Write the qusestons and answrs options to the new window
	quiz4.document.clear();
	quiz4.document.open();
	quiz4.document.writeln('<html><head><title>Learners Practice Quiz 4</title>');
	quiz4.document.writeln('<link href="/css/purple.css" rel="stylesheet" type="text/css">');
	quiz4.document.writeln('</head><body bgcolor="\#ffffff\">');
	quiz4.document.writeln('<h3>Question '+ qus4[qI].number +'</h3>');
	quiz4.document.writeln('<table width=\'600\' cellspacing=\'5\'>');
	quiz4.document.writeln('<tr class=\'bg3\'><td align=\'left\' valign=\'top\' colspan=\'3\' height=\"40\">');
	quiz4.document.writeln('<p><b class=\'bodyhdr\'>' +qus4[qI].question+ '</b>');
	quiz4.document.writeln('</td></tr><td width=\'2\'>&nbsp;</td></tr>');
	quiz4.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz4.document.writeln('A&nbsp;<input type=\'radio\' name=\"answer\" value=\"a\" onClick="opener.choice4[opener.qI - 1] = this.value;\"></p>');
	quiz4.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');	
	quiz4.document.writeln('<p>'+qus4[qI].optionA+'</p>');
	quiz4.document.writeln('</td><td valign=\'top\' width=\'200\'rowspan=\'4\' height=\"200\">');
	quiz4.document.writeln('<img border=\"0\" width=\"200\" height=\"200\" align=\"right\" src=\"'+qus4[qI].img+'\">');
	quiz4.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz4.document.writeln('B&nbsp;<input type=\'radio\' name=\"answer\" value=\"b\" onClick="opener.choice4[opener.qI - 1] = this.value;\"></p>');
	quiz4.document.writeln('</td><td align=\'left\'valign=\'top\' width=\'340\' height=\'35\'>');
	quiz4.document.writeln('<p>'+qus4[qI].optionB+'</p>');
	quiz4.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz4.document.writeln('C&nbsp;<input type=\'radio\' name=\"answer\" value=\"c\" onClick="opener.choice4[opener.qI - 1] = this.value;\"></p>');
	quiz4.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');
	quiz4.document.writeln('<p>'+qus4[qI].optionC+'</p>');
	quiz4.document.writeln('</td></tr><tr align=\'left\' valign=\"top\" align=\'left\'><td width=\'30\'height=\'95\'>&nbsp;</td></tr>');
	quiz4.document.writeln('<tr align=\'right\'><td colspan=\'3\'>');
	quiz4.document.writeln('<input type=\'button\' value=\"NEXT QUESTION\" onClick="opener.startquiz4(false,' +nextq+ ')\;">');  
	quiz4.document.writeln('</td></tr></table></body></html>');
	quiz4.document.close();
	// Increment variables for the next question
	qI++;
	nextq++;
	}

function gradeTest4() {		// Increment the variables for the last time	
	qI++;
	nextq++;	
	
	for (var i = 0; i < qus4.length; i++) {		// Compare student ans with correct ans
		if (choice4[i] == qus4[i].ans) {
			correctans4++;
			}
		}	
	printResults4();	// Print the test results
	}
	
function printResults4() {		// Print the questions, answer options, and other info
	quiz4.document.clear();
	quiz4.document.open();
	quiz4.document.writeln('<html><head>');
	quiz4.document.writeln('<title>Quiz Four Results</title>');
	quiz4.document.writeln('<link href="css/purplelocal.css" rel="stylesheet" type="text/css">');
	quiz4.document.writeln('</head><body BGCOLOR=\"WHITE\">');						
	quiz4.document.writeln('<h3>Quiz Results</h3>');						
	quiz4.document.writeln('<p class=\'bodyhdr\'>Your score out of 30 is &nbsp;'+correctans4+'</p>');
	quiz4.document.writeln('<p>Here is how you scored individually for each question:</p><hr>');
	quiz4.document.writeln('<table width=\'600\' cellpadding=\'0\'>');
	
	for (var i = 0; i < qus4.length; i++) {
	
	quiz4.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'30\' width=\'20\'>');
	quiz4.document.writeln('<p><b>'+qus4[i].number+ '</b></td><td colspan=\'2\'><p>' +qus4[i].question+'</p>');
	quiz4.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz4.document.writeln('<p>a.</td><td width=\'450\'><p>' +qus4[i].optionA+ '</td>');
	quiz4.document.writeln('<td width=\'100\' rowspan=\'3\'><img border=\"0\" width=\"100\" height=\"100\" src=\"'+qus4[i].img+'\">');
	quiz4.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');	
	quiz4.document.writeln('<p>b.</td><td><p>' +qus4[i].optionB+ '</td></tr>');
	quiz4.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz4.document.writeln('<p>c.</td><td><p>' +qus4[i].optionC+ '<p>');
	
	// Determine if the student answered each question appropriately, and display accordingly
	if (choice4[i] == qus4[i].ans) {
		quiz4.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"GREEN\">You answered this correctly.  Your answer was:\n' +qus4[i].ans+ '.</font></b>\n</td>');
				}		
		else { 
		quiz4.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"RED\">The correct answer is:\n' +qus4[i].ans+ '\n</font></b>'); 
		}

	quiz4.document.writeln('</td></tr><tr><td colspan=\'3\'><hr></td></tr>');
	}
	i++;	
	quiz4.document.writeln('</table>');
	// Add extra info about the ranking, questions, and application
	quiz4.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.');
	quiz4.document.writeln('</body></html>');
	quiz4.document.close();
	}
	
	
var qus4 = new Array();
qus4[0] =new quizfour("1","Which of the following statements is correct?","Vehicle X must not overtake Y.","Vehicle X may overtake Y, only in a 50km/h area.","Vehicle X may overtake Y.","a","img/Q47.gif","Q47 Position")

qus4[1] =new quizfour("2","What is the speed limit in built-up areas where there are no speed limit signs? ","60km/h.","50km/h.","80km/h.","b","img/trans.gif","Q106Speed")

qus4[2] =new quizfour("3","For how long must you indicate before you overtake a vehicle?","Long enough to give other road users sufficient warning of your intention.","At least 10 metres.","At least 100 metres.","a","img/trans.gif","Q119 Stop & Indicate")

qus4[3] =new quizfour("4","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")

qus4[4] =new quizfour("5","Which vehicle must give way?","Vehicle Y.","Vehicle X.","Neither vehicle has to give way.","a","img/Q61.gif","Q61 ROW(1)")

qus4[5] = new quizfour("6","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")

qus4[6] =new quizfour("7","What is the basic rule that applies to uncontrolled four-way intersections?","Give way to vehicles on your right.","Give way to all vehicles.","Give way to vehicles on your left.","a","img/trans.gif","Q71 ROW(2)")

qus4[7] =new quizfour("8","Are you allowed to park a vehicle on a pedestrian crossing?","Yes, if no pedestrains are using it.","Yes, if it is a passenger vehicle.","No.","c","img/Q142.gif","Q142	Vulnerable Road Users")

qus4[8] = new quizfour("9","When approaching traffic lights, what does a red light with a green arrow (as shown in the diagram) mean?","Stop, until all lights show green.","You may proceed in the direction of the arrow.","Proceed in any direction.","b","img/Q30.gif","Q30 Intersections")

qus4[9] =new quizfour("10","Which vehicle must give way?","Vehicle Y.","Neither vehicle has to give way.","Vehicle X.","c","img/Q80.gif","Q80 ROW(2)")

qus4[10] = new quizfour("11","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")

qus4[11] =new quizfour("12","What must you do at a STOP sign?","Stop at least 2 metres before the sign.","Stop and give way to all traffic on the crossroad.","Slow down and be prepared to stop if any traffic is approaching.","b","img/trans.gif","Q93 Signs & Parking")

qus4[12] =new quizfour("13","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")

qus4[13] =new quizfour("14","Which of the following statements is correct?","Passengers in vehicles are less likely to be injured in a crash if they are wearing seat belts.","The nature of injuries in motor vehicle crashes is not related to the wearing of seat belts.","Passengers in rear seats of a vehicle are not required to wear seat belts.","a","img/trans.gif","Q60 Restraints")

qus4[14] =new quizfour("15","What is the minimum distance a vehicle is allowed to park before a bus stop or pedestrian crossing?","20 metres.","3 metres.","6 metres.","a","img/trans.gif","Q92 Signs & Parking")

qus4[15] =new quizfour("16","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 ")

qus4[16] =new quizfour("17","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle Y.","Vehicle X.","c","img/Q70.gif","Q70 ROW(1)")

qus4[17] = new quizfour("18","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")

qus4[18] =new quizfour("19","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle Y.","Vehicle X.","b","img/Q81.gif","Q81 ROW(2)")

qus4[19] =new quizfour("20","What is the minimum distance a vehicle is allowed to park from an intersection without traffic lights?","3 metres.","10 metres.","1 metre.","b","img/trans.gif","Q91 Signs & Parking")

qus4[20] =new quizfour("21","Which of the following statements is correct?","Vehicle X may overtake Y, only in a 60km/h area.","Vehicle X may overtake Y.","Vehicle X must not overtake Y.","b","img/Q46.gif","Q46 Position")

qus4[21] = new quizfour("22","What is the safest way to approach an intersection?","Travelling at the speed limit for the area.","Travelling at a speed that will allow you to stop if required.","Looking steadily to the right.","b","img/trans.gif","Q21 Intersections")

qus4[22] =new quizfour("23","What is the maximum speed learner drivers (L-plates) are allowed to travel?","110km/h.","90km/h.","100km/h.","c","img/trans.gif","Q108Speed")

qus4[23] =new quizfour("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")

qus4[24] = new quizfour("25","What is the minimum penalty for a provisional driver with a BAC over 0.00%?","A fine.","A fine and issue of demerit points.","A fine and loss of licence.","b","img/trans.gif","Q1 Alcohol")

qus4[25] =new quizfour("26","Should you use high beam or low beam when driving in fog or smoke? ","High beam.","It makes no difference.","Low beam.","c","img/trans.gif","Q131 Vehicle")

qus4[26] =new quizfour("27","What should you do when approaching a pedestrian crossing area?","Ease your way through the pedestrians.","	Sound your horn to warn pedestrians of your approach.","Slow down and be prepared to stop.","c","img/trans.gif","Q141	Vulnerable Road Users ")

qus4[27] = new quizfour("28","What should you do if your accelerator is stuck?","Apply the clutch or select neutral and apply the brake to stop.","Switch off the ignition.","Change to a lower gear.","a","img/trans.gif","Q13Emergency")

qus4[28] =new quizfour("29","Which vehicle must give way?","Vehicle Y.","Vehicle X.","Neither vehicle has to give way.","b","img/Q64.gif","Q64 ROW(1)")

qus4[29] =new quizfour("30","Which of the following statements is correct?","Vehicle X may overtake Y.","Vehicle X must not overtake Y.","Vehicle X may overtake Y, only in a 50km/h area.","a","img/Q45.gif","Q45 Position")
