
var currentQuestion = 0;
var correctAnswers = 0;
var questions = new Array();
var quizElement;
var questionElement;
var optionsElement;


function displayQuestion() {
	questionElement.innerHTML = questions[currentQuestion][0] + " ___________ " + questions[currentQuestion][1];
	var optionsHtml = "";
	for (var n = 2; n <= 5; n++) {
		optionsHtml += "<input id=\"option\" name=\"option\" class=\"radio\" type=\"radio\" /> " + questions[currentQuestion][n] + "<br />";
	}
	optionsElement.innerHTML = optionsHtml;
}


function checkAnswer() {
	var radioOptions = document.forms["quiz"].elements["option"];
	currentQuestion++;
	for (var opt = 0; opt < 4; opt++) {
		if (radioOptions[opt].checked == true && questions[currentQuestion - 1][6] == opt + 2) {
			correctAnswers++;
		}
	}
	if (currentQuestion < questions.length) {
		displayQuestion();
	} else if (currentQuestion == questions.length) {
		var level = "";
		var endOfTestHtml = "";
		if (correctAnswers <= 4) {
			level = "Beginner";
		} else if (correctAnswers >= 5 && correctAnswers <= 8) {
			level = "Elementary";
		} else if (correctAnswers >= 9 && correctAnswers <= 18) {
			level = "Pre-Intermediate";
		} else if (correctAnswers >= 19 && correctAnswers <= 28) {
			level = "Intermediate";
		} else if (correctAnswers >= 29 && correctAnswers <= 34) {
			level = "Upper-Intermediate";
		} else if (correctAnswers >= 35) {
			level = "Advanced";
		}
		endOfTestHtml = "<h2>Grammar Test Results</h2><p>You correctly answered " + correctAnswers + " of " + questions.length + " questions. Your level is approximately " + level + ".</p><h2>Correct Answers</h2><p>";
		for (var i = 0; i < questions.length; i++) {
			endOfTestHtml += (i + 1) + ". " + questions[i][0] + " <span class=\"orange\">" + questions[i][questions[i][6]] + "</span> " + questions[i][1] + "<br />";
		}
		quizElement.innerHTML = endOfTestHtml + "</p>";
	}
}


function initialise() {
	quizElement = document.getElementById("quiz");
	questionElement = document.getElementById("question");
	optionsElement = document.getElementById("options");
	
	var i = 0;
	questions[i] = new Array();
	questions[i][0] = "I come";
	questions[i][1] = "England.";
	questions[i][2] = "to";
	questions[i][3] = "from";
	questions[i][4] = "at";
	questions[i][5] = "in";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "There aren\'t";
	questions[i][1] = "people here.";
	questions[i][2] = "much";
	questions[i][3] = "many";
	questions[i][4] = "a lot";
	questions[i][5] = "some";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "Tim";
	questions[i][1] = "work tomorrow.";
	questions[i][2] = "isn\'t going";
	questions[i][3] = "isn\'t";
	questions[i][4] = "isn\'t going to";
	questions[i][5] = "isn\'t to";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "I\'d like";
	questions[i][1] = "information, please.";
	questions[i][2] = "an";
	questions[i][3] = "some";
	questions[i][4] = "piece";
	questions[i][5] = "a piece";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "";
	questions[i][1] = "to school yesterday?";
	questions[i][2] = "Do you walk";
	questions[i][3] = "Did you walked";
	questions[i][4] = "Did you walk";
	questions[i][5] = "Have you walked";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "I went to the shop";
	questions[i][1] = "some chocolate.";
	questions[i][2] = "for buying";
	questions[i][3] = "for buy";
	questions[i][4] = "to buy";
	questions[i][5] = "buy";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "\'I don\'t like coffee.\' \'";
	questions[i][1] = "do I.\'";
	questions[i][2] = "So";
	questions[i][3] = "Neither";
	questions[i][4] = "Either";
	questions[i][5] = "No";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "\'Have you visited London?\' \'";
	questions[i][1] = ".\'";
	questions[i][2] = "Not yet";
	questions[i][3] = "Ever";
	questions[i][4] = "Already";
	questions[i][5] = "Not";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "Is Jo";
	questions[i][1] = "Chris?";
	questions[i][2] = "taller that";
	questions[i][3] = "taller";
	questions[i][4] = "as tall as";
	questions[i][5] = "more tall";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "You should";
	questions[i][1] = "your homework.";
	questions[i][2] = "make";
	questions[i][3] = "do";
	questions[i][4] = "work";
	questions[i][5] = "give";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "\'Where\'s the";
	questions[i][1] = "post office, please?\'";
	questions[i][2] = "most near";
	questions[i][3] = "near";
	questions[i][4] = "more near";
	questions[i][5] = "nearest";
	questions[i][6] = 5;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "Would you mind";
	questions[i][1] = "the window?";
	questions[i][2] = "closing";
	questions[i][3] = "close";
	questions[i][4] = "to close";
	questions[i][5] = "closed";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "He\'s interested";
	questions[i][1] = "learning Spanish.";
	questions[i][2] = "on";
	questions[i][3] = "to";
	questions[i][4] = "in";
	questions[i][5] = "for";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "How long";
	questions[i][1] = "English?";
	questions[i][2] = "do you learn";
	questions[i][3] = "are you learning";
	questions[i][4] = "have you been learning";
	questions[i][5] = "you learn";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "His office is on the second";
	questions[i][1] = "of the building.";
	questions[i][2] = "floor";
	questions[i][3] = "level";
	questions[i][4] = "ground";
	questions[i][5] = "stage";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "The doctor gave me a";
	questions[i][1] = "for some medicine yesterday.";
	questions[i][2] = "note";
	questions[i][3] = "receipt";
	questions[i][4] = "prescription";
	questions[i][5] = "recipe";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "Can you tell me when";
	questions[i][1] = "?";
	questions[i][2] = "the train leaves";
	questions[i][3] = "does the train leave";
	questions[i][4] = "leaves the train";
	questions[i][5] = "does leave the train";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "I";
	questions[i][1] = "a reply to my letter in the next few days.";
	questions[i][2] = "hope";
	questions[i][3] = "expect";
	questions[i][4] = "wait for";
	questions[i][5] = "get";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "When Simon";
	questions[i][1] = "back tonight, he\'ll cook dinner.";
	questions[i][2] = "comes";
	questions[i][3] = "will come";
	questions[i][4] = "come";
	questions[i][5] = "shall come";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "We arrived ";
	questions[i][1] = "England two days ago.";
	questions[i][2] = "to";
	questions[i][3] = "in";
	questions[i][4] = "on";
	questions[i][5] = "at";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "\'Why are you so hungry?\' \'Oh, I";
	questions[i][1] = "breakfast this morning.\'";
	questions[i][2] = "hadn\'t";
	questions[i][3] = "didn\'t";
	questions[i][4] = "didn\'t have";
	questions[i][5] = "haven\'t";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "You";
	questions[i][1] = "better see a doctor.";
	questions[i][2] = "did";
	questions[i][3] = "would";
	questions[i][4] = "should";
	questions[i][5] = "had";
	questions[i][6] = 5;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "You should";
	questions[i][1] = "swimming.";
	questions[i][2] = "start up";
	questions[i][3] = "get off";
	questions[i][4] = "take up";
	questions[i][5] = "take off";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "\'Did you speak to Juliet?\' \'No, I\'ve";
	questions[i][1] = "seen her.";
	questions[i][2] = "nearly";
	questions[i][3] = "hardly";
	questions[i][4] = "often";
	questions[i][5] = "always";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "He told me that he";
	questions[i][1] = "in Spain the previous year.";
	questions[i][2] = "has been working";
	questions[i][3] = "had been working";
	questions[i][4] = "has worked";
	questions[i][5] = "had been worked";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "She looks";
	questions[i][1] = "she\'s going to be sick.";
	questions[i][2] = "as if";
	questions[i][3] = "as";
	questions[i][4] = "likes";
	questions[i][5] = "if";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "The best way to learn a language is";
	questions[i][1] = "a little every day.";
	questions[i][2] = "speak";
	questions[i][3] = "in speaking";
	questions[i][4] = "to speaking";
	questions[i][5] = "by speaking";
	questions[i][6] = 5;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "She";
	questions[i][1] = "me to go to school.";
	questions[i][2] = "said";
	questions[i][3] = "told";
	questions[i][4] = "suggested";
	questions[i][5] = "made";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "I want to be a teacher when I";
	questions[i][1] = ".";
	questions[i][2] = "grow";
	questions[i][3] = "age";
	questions[i][4] = "grow up";
	questions[i][5] = "am more years";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "I\'m fed up";
	questions[i][1] = "this exercise.";
	questions[i][2] = "with doing";
	questions[i][3] = "to do";
	questions[i][4] = "to doing";
	questions[i][5] = "for doing";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "It";
	questions[i][1] = "my brother.";
	questions[i][2] = "is ages that I didn\'t see";
	questions[i][3] = "is ages since I saw";
	questions[i][4] = "was ages that I haven\'t seen";
	questions[i][5] = "was ages since I saw";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "She has been";
	questions[i][1] = "of murdering her husband.";
	questions[i][2] = "charged";
	questions[i][3] = "accused";
	questions[i][4] = "arrested";
	questions[i][5] = "blamed";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "You aren\'t allowed to use your mobile so";
	questions[i][1] = ".";
	questions[i][2] = "it\'s no point to leave it on";
	questions[i][3] = "it\'s no point in leaving it on";
	questions[i][4] = "there\'s no point in leaving it on";
	questions[i][5] = "there\'s no point to leave it on";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "You";
	questions[i][1] = "the cleaning. I would have done it tonight.";
	questions[i][2] = "needn\'t have done";
	questions[i][3] = "couldn\'t have done";
	questions[i][4] = "can\'t have done";
	questions[i][5] = "wouldn\'t have done";
	questions[i][6] = 2;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "They have put speed bumps on the road to ";
	questions[i][1] = "accidents.";
	questions[i][2] = "avoid";
	questions[i][3] = "prohibit";
	questions[i][4] = "prevent";
	questions[i][5] = "forbid";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "We would never have had the accident if you";
	questions[i][1] = "so fast.";
	questions[i][2] = "wouldn\'t been driving";
	questions[i][3] = "hadn\'t been driving";
	questions[i][4] = "had driven";
	questions[i][5] = "wouldn\'t drive";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "The tree";
	questions[i][1] = "by lightning.";
	questions[i][2] = "was flashed";
	questions[i][3] = "struck";
	questions[i][4] = "was struck";
	questions[i][5] = "flashed";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "If only I";
	questions[i][1] = "richer.";
	questions[i][2] = "am";
	questions[i][3] = "were";
	questions[i][4] = "would be";
	questions[i][5] = "will be";
	questions[i][6] = 3;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "";
	questions[i][1] = "the better team, we lost the match.";
	questions[i][2] = "Despite of being";
	questions[i][3] = "Despite";
	questions[i][4] = "Despite being";
	questions[i][5] = "Although";
	questions[i][6] = 4;
	
	i++;
	questions[i] = new Array();
	questions[i][0] = "By this time next year, I";
	questions[i][1] = "all my exams.";
	questions[i][2] = "will have taken";
	questions[i][3] = "will take";
	questions[i][4] = "take";
	questions[i][5] = "have taken";
	questions[i][6] = 2;
}

