// Define global variables and arrays
var qI	= 0;
var checker3 = true;
var choice3	= new Array();
var correctans3 	= 0;
var nextq 	= 1;
var quiz3;

function itemReset() {	//resets everything
	qI 	= 0;
	choice3 = new Array();
	correctans3 	= 0;
	nextq	= 1;
	}
	
function book()	{
	parent.location.href='/licensing/learnerdrivers/1464.asp';
	quiz3.document.close();
	}
	
function busted3() {
	alert('Sorry, you only get one shot at each question.');
	quiz3.history.forward(); 
	quiz3.focus();
	}
	
function restart(){
	parent.location.href="/licensing/learnerdrivers/1465.asp"
	quiz3.document.close();
	}

function startquiz3(openStatus, whetherOrNot) {		// Administer the test and record the ans
		
	checker3 = openStatus;
		
	if (whetherOrNot < qI) { 
		busted3(); 
		return; 
		}
	
	if (checker3) { 
		quiz3 = window.open('','QuizOne','width=640,height=480,scrollbars=yes');
		//quiz3.moveTo(150,150);		
		quiz3.focus(); 
		!checker3;
		}
	
	if (qI == qus3.length) { 
		gradeTest3(); 
		return; 
		}
	displaythree();
	}

function quizthree(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 displaythree()	{	// display questions
			
	// Write the qus3estons and answrs options to the new window
	quiz3.document.clear();
	quiz3.document.open();
	quiz3.document.writeln('<html><head><title>Learners Practice Quiz 3</title>');
	quiz3.document.writeln('<link href="/css/purple.css" rel="stylesheet" type="text/css">');
	quiz3.document.writeln('</head><body bgcolor="\#ffffff\">');
	quiz3.document.writeln('<h3>Question '+ qus3[qI].number +'</h3>');
	quiz3.document.writeln('<table width=\'600\' cellspacing=\'5\'>');
	quiz3.document.writeln('<tr class=\'bg3\'><td align=\'left\' valign=\'top\' colspan=\'3\' height=\"40\">');
	quiz3.document.writeln('<p><b class=\'bodyhdr\'>' +qus3[qI].question+ '</b>');
	quiz3.document.writeln('</td></tr><td width=\'2\'>&nbsp;</td></tr>');
	quiz3.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz3.document.writeln('A&nbsp;<input type=\'radio\' name=\"answer\" value=\"a\" onClick="opener.choice3[opener.qI - 1] = this.value;\"></p>');
	quiz3.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');	
	quiz3.document.writeln('<p>'+qus3[qI].optionA+'</p>');
	quiz3.document.writeln('</td><td valign=\'top\' width=\'200\'rowspan=\'4\' height=\"200\">');
	quiz3.document.writeln('<img border=\"0\" width=\"200\" height=\"200\" align=\"right\" src=\"'+qus3[qI].img+'\">');
	quiz3.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz3.document.writeln('B&nbsp;<input type=\'radio\' name=\"answer\" value=\"b\" onClick="opener.choice3[opener.qI - 1] = this.value;\"></p>');
	quiz3.document.writeln('</td><td align=\'left\'valign=\'top\' width=\'340\' height=\'35\'>');
	quiz3.document.writeln('<p>'+qus3[qI].optionB+'</p>');
	quiz3.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz3.document.writeln('C&nbsp;<input type=\'radio\' name=\"answer\" value=\"c\" onClick="opener.choice3[opener.qI - 1] = this.value;\"></p>');
	quiz3.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');
	quiz3.document.writeln('<p>'+qus3[qI].optionC+'</p>');
	quiz3.document.writeln('</td></tr><tr align=\'left\' valign=\"top\" align=\'left\'><td width=\'30\'height=\'95\'>&nbsp;</td></tr>');
	quiz3.document.writeln('<tr align=\'right\'><td colspan=\'3\'>');
	quiz3.document.writeln('<input type=\'button\' value=\"NEXT QUESTION\" onClick="opener.startquiz3(false,' +nextq+ ')\;">');  
	quiz3.document.writeln('</td></tr></table></body></html>');
	quiz3.document.close();
	// Increment variables for the next question
	qI++;
	nextq++;
	}

function gradeTest3() {		// Increment the variables for the last time	
	qI++;
	nextq++;	
	
	for (var i = 0; i < qus3.length; i++) {		// Compare student ans with correct ans
		if (choice3[i] == qus3[i].ans) {
			correctans3++;
			}
		}	
	printResults3();	// Print the test results
	}
	
function printResults3() {		// Print the questions, answer options, and other info
	quiz3.document.clear();
	quiz3.document.open();
	quiz3.document.writeln('<html><head>');
	quiz3.document.writeln('<title>Quiz Three Results</title>');
	quiz3.document.writeln('<link href="css/purplelocal.css" rel="stylesheet" type="text/css">');
	quiz3.document.writeln('</head><body BGCOLOR=\"WHITE\">');						
	quiz3.document.writeln('<h3>Quiz Results</h3>');						
	quiz3.document.writeln('<p class=\'bodyhdr\'>Your score out of 30 is &nbsp;'+correctans3+'</p>');
	quiz3.document.writeln('<p>Here is how you scored individually for each question:</p><hr>');
	quiz3.document.writeln('<table width=\'600\' cellpadding=\'0\'>');
	
	for (var i = 0; i < qus3.length; i++) {
	
	quiz3.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'30\' width=\'20\'>');
	quiz3.document.writeln('<p><b>'+qus3[i].number+ '</b></td><td colspan=\'2\'><p>' +qus3[i].question+'</p>');
	quiz3.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz3.document.writeln('<p>a.</td><td width=\'450\'><p>' +qus3[i].optionA+ '</td>');
	quiz3.document.writeln('<td width=\'100\' rowspan=\'3\'><img border=\"0\" width=\"100\" height=\"100\" src=\"'+qus3[i].img+'\">');
	quiz3.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');	
	quiz3.document.writeln('<p>b.</td><td><p>' +qus3[i].optionB+ '</td></tr>');
	quiz3.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz3.document.writeln('<p>c.</td><td><p>' +qus3[i].optionC+ '<p>');
	
	// Determine if the student answered each question appropriately, and display accordingly
	if (choice3[i] == qus3[i].ans) {
		quiz3.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"GREEN\">You answered this correctly.  Your answer was:\n' +qus3[i].ans+ '.</font></b>\n</td>');
				}		
		else { 
		quiz3.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"RED\">The correct answer is:\n' +qus3[i].ans+ '\n</font></b>'); 
		}

	quiz3.document.writeln('</td></tr><tr><td colspan=\'3\'><hr></td></tr>');
	}
	i++;	
	quiz3.document.writeln('</table>');
	// Add extra info about the ranking, questions, and application
	quiz3.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.');
	quiz3.document.writeln('</body></html>');
	quiz3.document.close();
	}
	
	
var qus3 = new Array();
qus3[0] =new quizthree("1","What must you do at a children's crossing when a crossing attendant extends this flag?","Stop and do not proceed until the attendant withdraws the sign.","Slow down.","Drive on carefully if no children are on your side of the crossing.","a","img/Q140.gif","Q140 Vulnerable Road Users"	)

qus3[1] = new quizthree("2","Can medication used for colds or travel sickness affect your driving?","No.","Yes.","No, unless it has been prescribed by a doctor.","b","img/trans.gif","Q8 Alcohol")

qus3[2] =new quizthree("3","When are you allowed to sound your vehicle's horn? ","Only when you are travelling outside built-up areas.","Only when it is used as a warning device.","At any time.","b","img/trans.gif","Q129 Vehicle")

qus3[3] =new quizthree("4","Which vehicle must give way?","Vehicle Y.","Neither vehicle has to give way.","Vehicle X.","a","img/Q79.gif","Q79 ROW(2)")

qus3[4] = new quizthree("5","What should you do if your vehicle catches fire?","Accelerate to blow out the flames.","Sound your horn to warn other drivers.","Stop and turn off the ignition.","c","img/trans.gif","Q12Emergency")

qus3[5] = new quizthree("6","Does a police officer directing traffic over-rule traffic signs and traffic lights?","No.","Yes, if it is daylight.","Yes.","c","img/trans.gif","Q27 Intersections")

qus3[6] = new quizthree("7","When approaching traffic lights, what does a green light with a red arrow mean?","You may go in any direction other than that indicated by the arrow.","You may turn in the direction of the arrow, if it is safe to do so.","Stop, the lights are not working properly.","a","img/trans.gif","Q28 Intersections")

qus3[7] =new quizthree("8","What is the maximum speed vehicles towing a caravan or trailer are allowed to travel?","110km/h.","90km/h.","100km/h.","c","img/trans.gif","Q111Speed")

qus3[8] =new quizthree("9","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")

qus3[9] =new quizthree("10","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","b","img/Q78.gif","Q78 ROW(2)")

qus3[10] =new quizthree("11","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/Q41.gif","Q41 Position")

qus3[11] =new quizthree("12","What is the minimum distance a vehicle is allowed to park from an intersection controlled by traffic lights?","3 metres.","6 metres.","20 metres.","c","img/trans.gif","Q89 Signs & Parking")

qus3[12] =new quizthree("13","What must you do before pulling out from a parked position at a kerb?","Sound your horn.","Check your mirror, blind spot and indicate for at least 5 seconds prior to pulling out.","Adjust your passenger-side external mirror.","b","img/trans.gif","Q117 Stop & Indicate")

qus3[13] =new quizthree("14","When is a driver allowed to drive without a seat belt?","When reversing a vehicle.","When aged 65 years and over.","When the driver is pregnant.","a","img/trans.gif","Q58 Restraints ")

qus3[14] =new quizthree("15","Which of the following statements is correct?","All passengers must wear available seat belts or suitable child restraints.","Only passengers over the age of 8 years must wear a seat belt.","Passengers over the age of 65 do not have to wear seat belts.","a","img/trans.gif","Q59 Restraints")

qus3[15] =new quizthree("16","Which vehicle must give way?","Vehicle X.","Vehicle Y.","Neither vehicle has to give way.","b","img/Q68.gif","Q68ROW(1)")

qus3[16] =new quizthree("17","In which order should the vehicles proceed?","Vehicle X, then Y, then Z.","Vehicle Z, then Y, then X.","Vehicle X, then Z, then Y.","b","img/Q69.gif","Q69 ROW(1)")

qus3[17] = new quizthree("18","Which of the following statements is correct?","You should not drive if you are tired.","Your level of fatigue will be increased if you make stops on long trips.","You are more likely to become fatigued on short curving roads.","a","img/trans.gif","Q9 Alcohol")

qus3[18] =new quizthree("19","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 60km/h area.","a","img/Q42.gif","Q42 Position")

qus3[19] =new quizthree("20","What is the minimum distance a vehicle is allowed to park from a railway crossing?","6 metres.","20 metres.","3 metres.","b","img/trans.gif","Q88 Signs & Parking")

qus3[20] =new quizthree("21","What is the minimum distance a vehicle is allowed to park after a bus stop or pedestrian crossing?","3 metres.","6 metres.","10 metres.","c","img/trans.gif","Q90 Signs & Parking")

qus3[21] =new quizthree("22","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","SQ110peed")

qus3[22] =new quizthree("23","Which of the following statements is correct?","Vehicle X gives way to both Y and Z.","Vehicle Z gives way to both X and Y.","Vehicle Y gives way to both X and Z.","c","img/Q67.gif","Q6	ROW(1)")

qus3[23] =new quizthree("24","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")

qus3[24] = new quizthree("25","When approaching traffic lights, what does a green light with a green arrow (as shown in the diagram) mean?","You may turn right only.","You may turn right or drive straight ahead.","You may drive straight ahead only.","b","img/Q29.gif","Q29 Intersections")

qus3[25] =new quizthree("26","Is it legal for you to drive a motor vehicle at night with only one headlight working?","No.","Yes, if the right-hand headlight is visible.","Yes.","a","img/trans.gif","Q128 Vehicle")

qus3[26] = new quizthree("27","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")

qus3[27] =new quizthree("28","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 60km/h area.","b","img/Q43.gif","Q43 Position")

qus3[28] =new quizthree("29","What is the rule regarding overtaking at a pedestrian crossing?","You must not overtake a vehicle that has stopped at a pedestrian crossing.","Give way to pedestrians on your right.","Give way to pedestrians on your left.","a","img/trans.gif","Q139 Vulnerable Road Users"	)

qus3[29] =new quizthree("30","Which vehicle must give way?","Vehicle Y.","Neither vehicle has to give way.","Vehicle X.","a","img/Q77.gif","Q77 ROW(2)")
