// Define global variables and arrays
var qI	= 0;
var checker1 = true;
var choice1	= new Array();
var correctans1 	= 0;
var nextq 	= 1;
var quiz1;

function itemReset() {	//resets everything
	qI 	= 0;
	choice1 = new Array();
	correctans1 	= 0;
	nextq	= 1;
	}
	
function busted() {
	alert('Sorry, you only get one shot at each question.');
	quiz1.history.forward(); 
	quiz1.focus();
	}
	
function book()	{
	parent.location.href='/licensing/learnerdrivers/1646.asp';
	quiz1.document.close();
	}
	
function restart(){
	parent.location.href="/licensing/learnerdrivers/1465.asp;"
	quiz1.document.close();
	}

function startquiz1(openStatus, whetherOrNot) {		// Administer the test and record the ans
		
	checker1 = openStatus;
		
	if (whetherOrNot < qI) { 
		busted(); 
		return; 
		}
		
	if (checker1) { 
		quiz1 = open('','QuizOne','width=640,height=480,scrollbars=yes');
		//quiz1.moveTo(150,150);
		quiz1.focus();
		!checker1;
		}
	
	if (qI == qus1.length) { 
		gradeTest1(); 
		return; 
		}
	displayone();
	}

function quizone(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 displayone()	{	// display questions
	
	// Write the qusestons and answrs options to the new window
	quiz1.document.clear();
	quiz1.document.open();
	quiz1.document.writeln('<html><head><title>Learners Practice Quiz 1</title>');
	quiz1.document.writeln('<link href="/css/purple.css" rel="stylesheet" type="text/css">');
	quiz1.document.writeln('</head><body bgcolor="\#ffffff\">');
	quiz1.document.writeln('<h3>Question '+ qus1[qI].number +'</h3>');
	quiz1.document.writeln('<table width=\'600\' cellspacing=\'5\'>');
	quiz1.document.writeln('<tr class=\'bg3\'><td align=\'left\' valign=\'top\' colspan=\'3\' height=\"40\">');
	quiz1.document.writeln('<p><b class=\'bodyhdr\'>' +qus1[qI].question+ '</b>');
	quiz1.document.writeln('</td></tr><td width=\'2\'>&nbsp;</td></tr>');
	quiz1.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz1.document.writeln('A&nbsp;<input type=\'radio\' name=\"answer\" value=\"a\" onClick="opener.choice1[opener.qI - 1] = this.value;\"></p>');
	quiz1.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');	
	quiz1.document.writeln('<p>'+qus1[qI].optionA+'</p>');
	quiz1.document.writeln('</td><td valign=\'top\' width=\'200\'rowspan=\'4\' height=\"200\">');
	quiz1.document.writeln('<img border=\"0\" width=\"200\" height=\"200\" align=\"right\" src=\"'+qus1[qI].img+'\">');
	quiz1.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz1.document.writeln('B&nbsp;<input type=\'radio\' name=\"answer\" value=\"b\" onClick="opener.choice1[opener.qI - 1] = this.value;\"></p>');
	quiz1.document.writeln('</td><td align=\'left\'valign=\'top\' width=\'340\' height=\'35\'>');
	quiz1.document.writeln('<p>'+qus1[qI].optionB+'</p>');
	quiz1.document.writeln('</td></tr><tr><td align=\'left\' valign=\'top\' width=\'35\' height=\'35\'><p>');
	quiz1.document.writeln('C&nbsp;<input type=\'radio\' name=\"answer\" value=\"c\" onClick="opener.choice1[opener.qI - 1] = this.value;\"></p>');
	quiz1.document.writeln('</td><td align=\'left\' valign=\'top\' width=\'340\' height=\'35\'>');
	quiz1.document.writeln('<p>'+qus1[qI].optionC+'</p>');
	quiz1.document.writeln('</td></tr><tr align=\'left\' valign=\"top\" align=\'left\'><td width=\'30\'height=\'95\'>&nbsp;</td></tr>');
	quiz1.document.writeln('<tr align=\'right\'><td colspan=\'3\'>');
	quiz1.document.writeln('<input type=\'button\' value=\"NEXT QUESTION\" onClick="opener.startquiz1(false,' +nextq+ ')\;">');  
	quiz1.document.writeln('</td></tr></table></body></html>');
	quiz1.document.close();
	// Increment variables for the next question
	qI++;
	nextq++;
	}

function gradeTest1() {		// Increment the variables for the last time	
	qI++;
	nextq++;	
	
	for (var i = 0; i < qus1.length; i++) {		// Compare student ans with correct ans
		if (choice1[i] == qus1[i].ans) {
			correctans1++;
			}
		}	
	printResults1();	// Print the test results
	}
	
function printResults1() {		// Print the questions, answer options, and other info
	quiz1.document.clear();
	quiz1.document.open();
	quiz1.document.writeln('<html><head>');
	quiz1.document.writeln('<title>Quiz One Results</title>');
	quiz1.document.writeln('<link href="css/purplelocal.css" rel="stylesheet" type="text/css">');
	quiz1.document.writeln('</head><body BGCOLOR=\"WHITE\">');						
	quiz1.document.writeln('<h3>Quiz Results</h3>');						
	quiz1.document.writeln('<p class=\'bodyhdr\'>Your score out of 30 is &nbsp;'+correctans1+'</p>');
	quiz1.document.writeln('<p>Here is how you scored individually for each question:</p><hr>');
	quiz1.document.writeln('<table width=\'600\' cellpadding=\'0\'>');
	
	for (var i = 0; i < qus1.length; i++) {
	
	quiz1.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'30\' width=\'20\'>');
	quiz1.document.writeln('<p><b>'+qus1[i].number+ '</b></td><td colspan=\'2\'><p>' +qus1[i].question+'</p>');
	quiz1.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz1.document.writeln('<p>a.</td><td width=\'450\'><p>' +qus1[i].optionA+ '</td>');
	quiz1.document.writeln('<td width=\'100\' rowspan=\'3\'><img border=\"0\" width=\"100\" height=\"100\" src=\"'+qus1[i].img+'\">');
	quiz1.document.writeln('</td></tr><tr valign=\"top\" align=\'left\'><td height=\'20\'>');	
	quiz1.document.writeln('<p>b.</td><td><p>' +qus1[i].optionB+ '</td></tr>');
	quiz1.document.writeln('<tr valign=\"top\" align=\'left\'><td height=\'20\'>');
	quiz1.document.writeln('<p>c.</td><td><p>' +qus1[i].optionC+ '<p>');
	
	// Determine if the student answered each question appropriately, and display accordingly
	if (choice1[i] == qus1[i].ans) {
		quiz1.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"GREEN\">You answered this correctly.  Your answer was:\n' +qus1[i].ans+ '.</font></b>\n</td>');
				}		
		else { 
		quiz1.document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=\"RED\">The correct answer is:\n' +qus1[i].ans+ '\n</font></b>'); 
		}

	quiz1.document.writeln('</td></tr><tr><td colspan=\'3\'><hr></td></tr>');
	}
	i++;	
	quiz1.document.writeln('</table>');
	// Add extra info about the ranking, questions, and application
	quiz1.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.');
	quiz1.document.writeln('</body></html>');
	quiz1.document.close();	
	}

var qus1 = new Array();
qus1[0] =new quizone("1","What does a broken white line down the centre of a road mean?","You must not cross the broken white line.","You may only cross the broken white line to turn right.","You may cross the broken white line when overtaking or turning right, if it is safe to do so.","c","img/trans.gif","Q34 Position")

qus1[1] =new quizone("2","Are people over 65 years of age required to wear a seat belt?","No, if they are passengers.","Yes.","No, if they are driving.","b","img/trans.gif","Q55 Restraints ")

qus1[2] =new quizone("3","Which vehicle must give way?","Vehicle Y.","Vehicle X.","Neither vehicle has to give way.","a","img/Q61.gif","Q61 ROW(1)")

qus1[3] =new quizone("4","Who must give way?","Neither has to give way.","Vehicle X.","The cyclist Y.","b","img/Q136.gif","Q136	Vulnerable Road Users")

qus1[4] =new quizone("5","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)")

qus1[5] = new quizone("6","Which of the following statements is correct?","Sudden braking can cause your vehicle to skid.","Braking severely will always stop your vehicle the fastest.","If you have good tyres your vehicle will not skid.","a","img/trans.gif","Q10 Emergency")

qus1[6] =new quizone("7","Which motorcycle is in the car driver's blind spot? ","Motorcycle Z.","Motorcycle Y.","Motorcycle X.","b","img/Q135.gif","Q135 Vulnerable Road Users"	)

qus1[7] = new quizone("8","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")

qus1[8] = new quizone("9","At a railway crossing, are you allowed to cross if the train has passed, but the lights are still flashing?","Yes.","No.","Yes, unless the crossing has boom gates.","b","img/trans.gif","Q23 Intersections")

qus1[9] =new quizone("10","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")

qus1[10] =new quizone("11","What does the continuous white line dividing the lanes mean?","You are allowed to change lanes if you are turning right.","You are not allowed to change lanes.","You are allowed to change lanes if you are turning left.","b","img/Q33.gif","Q33 Position")

qus1[11] = new quizone("12","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")

qus1[12] = new quizone("13","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")

qus1[13] =new quizone("14","Is vehicle X allowed to overtake vehicle Y?	","Yes, if it is safe to do so.","No.","It depends on the time of day.","b","img/Q35.gif","Q35 Position")

qus1[14] =new quizone("15","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 ")

qus1[15] = new quizone("16","Which of the following statements is correct?","Alcohol has no effect on your driving ability.","Alcohol makes you react faster to hazards.","Alcohol makes you react more slowly to hazards.","c","img/trans.gif","Q3 Alcohol")

qus1[16] =new quizone("17","Are you allowed to park a vehicle on a footpath?","No.","Yes, if it is a passenger vehicle.","Yes.","a","img/trans.gif","img/Q83 Signs & Parking")

qus1[17] =new quizone("18","Which vehicle must give way?","Vehicle X.","Vehicle Y.","Neither vehicle has to give way.","a","img/Q62.gif","Q62 ROW(1)")

qus1[18] =new quizone("19","Which vehicle must give way?","Neither vehicle has to give way.","Vehicle X.","Vehicle Y.","b","img/Q63.gif","	Q63 ROW(1)")

qus1[19] =new quizone("20","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","Q106 Speed")

qus1[20] =new quizone("21","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)")

qus1[21] =new quizone("22","Which vehicle must give way?","Vehicle X.","Neither vehicle has to give way.","Vehicle Y.","c","img/Q73.gif","Q73 ROW(2)")

qus1[22] =new quizone("23","What is the meaning of this sign on the back of a bus?","You must give way to the bus if there is no other traffic on the road at the time.","You must give way to the bus if your speed is less than 70km/h.","You must give way to the bus if it is preparing to move out from a bus stop.","c","img/Q82.gif","Q82 Signs & Parking")

qus1[23] =new quizone("24","What is the meaning of this sign?","Parking is reserved for a person in a wheelchair.","Parking is reserved for emergency vehicles.","Parking is reserved for holders of a current ACROD parking permit.","c","img/Q84.gif","q84 Signs & Parking")

qus1[24] =new quizone("25","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")

qus1[25] =new quizone("26","What area is known as a vehicle driver's blind spot?","The area beside the vehicle that the driver is not looking at.","An area behind or to the side of the vehicle that cannot be seen in the side or rear-view mirrors.","An area which can only be seen in the side or rear-view mirrors.","b","img/trans.gif","Q112 Stop & Indicate")

qus1[26] =new quizone("27","Which motorcycle is in the car driver's blind spot?","Motorcycle X.","Motorcycle Y.","Motorcycle Z.","b","img/Q113.gif","Q113 Stop & Indicate")

qus1[27] = new quizone("28","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")

qus1[28] =new quizone("29","If you are dazzled by another vehicle's headlights, what should you do?","Put your lights on highbeam.","Keep left and look over the top of the approaching vehicle.","Slow down, look left and if you cannot see, pull over and stop.","c","img/trans.gif","Q124 Vehicle")

qus1[29] =new quizone("30","When should you dip your headlights?","When you are within 50 metres of a  vehicle.","When you are within 200 metres of a vehicle.","When you are dazzled by the lights of an on-coming vehicle.","b","img/trans.gif","Q125Vehicle")

