// Function to create arrays.
function makeArray(len) {
 for (var i = 0; i < len; i++) this[i] = null;
this.length = len;
}

// The question object constructor function.

function makeQuestion(questionA, trou, questionB, correctAnswer) {
var args = makeQuestion.arguments;
this.question = questionA + trou + questionB;
this.questionA = questionA;
this.questionB = questionB;
this.correctAnswer = correctAnswer;
this.userAnswer = null;
this.isCorrect = isCorrect;
this.showForm = showForm;
this.userChoices = new makeArray(args.length - 4);
 for (var i = 0; i < args.length - 4; i++) { 
 this.userChoices[i] = args[i + 4];
 }
}

// Method to determine if question is answered correctly.
function isCorrect() {
if (this.correctAnswer == this.userAnswer) return true;
else return false;
}

// Method to display contents of question object.
var letext = "";
function showForm(n) {
letext += '<br />' + (n + 1) + '. ' + this.question + '<blockquote><form>';
 for (var i = 0; i < this.userChoices.length; i++) {
 letext += '<input type = "radio" name = "q' + n + '" onClick = "quiz[' + n + '].userAnswer = ' + i + '">';
 letext += this.userChoices[i] + '<br />';
 }
letext += '<\/form><\/blockquote>';
document.getElementById("ici").innerHTML = letext;
}

// Function to correct the quiz and display score, correct answers.
function correctQuiz() {
var correct = 0;
correctPage = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>correction<\/title><meta http-equiv="content-type" content="text/html;charset=iso-8859-1"><\/head><body>';
 for (var i = 0; i < quiz.length; i++) {
 if (quiz[i].isCorrect()) correct++;
 }
var score = Math.round((correct / quiz.length) * 100);
correctPage += "<br /><font size=\"5\">votre score: " + score + ' %<\/font><p>';
 if (correct < quiz.length) { 
 correctPage += ifWrong;
 for (i = 0; i < quiz.length; i++) {
 if (!quiz[i].isCorrect()) {
reponse = new String (quiz[i].userChoices[quiz[i].userAnswer]);
strikeOuverture = new String ("<strike>");
strikeFermeture = new String ("<\/strike>");
if (reponse == "undefined")
{reponse = "?";strikeOuverture = "";strikeFermeture = "";}

correctPage += (i + 1) + '. ';
correctPage += strikeOuverture;
correctPage += '<font color=\"#ff0000\">' + reponse + '<\/font>';
correctPage += strikeFermeture;
correctPage += ' - ' + quiz[i].questionA + '<font color="#0000ff"><b>' +
 quiz[i].userChoices[quiz[i].correctAnswer] + '<\/b><\/font>' + quiz[i].questionB  +'<br>';
 }
 }
 }
 else correctPage += ifAced;
correctPage += '<br /><center><form action="" method="post" enctype="application/x-www-form-urlencoded"><input type="button" value=\"Au revoir\" onclick=\"javascript:window.close()\";><\/form><\/center><\/body><\/html>';
correctwin = window.open ('', '', 'height=450,width=600,scrollbars=yes');
 if (correctwin.opener == null) correctwin.opener = window;
correctwin.location = 'javascript:opener.correctPage';
}

// Message to display if quiz is aced.
var ifAced = "<P>Bravo, vous &ecirc;tes fran&ccedil;ais(e)?<P>"; 
// Message to display if any are wrong.
var ifWrong = "<P><B>Correction<\/B><P>";

// Create four question objects...

var quiz = new makeArray(20);


quiz[0] = new makeQuestion('Nous habitons maintenant ', '___', ' Strasbourg.', 1, 
 "en", // choice 0
 "&agrave;", // choice 1
 "chez", // choice 2 
 "dans"); // choice 3

quiz[1] = new makeQuestion('Je travaille tous les jours ', '___', ' biblioth&egrave;que.', // 2nd question 
 3, // correct answer
 "de la", // choice 0
 "dans", // choice 1
 "&agrave; le", //choice 2
 "&agrave; la");

quiz[2] = new makeQuestion("Nathalie et ", "___", ", nous allons au cin&eacute;ma dimanche.", 
 0, 
 "moi", 
 "vous",
 "toi",
 "lui");


quiz[3] = new makeQuestion("Je vous pr&eacute;sente Akira ", "___", " mari.",
 2, 
 "ses",
 "ma",
 "mon", 
 "sa");

quiz[4] = new makeQuestion("Noriko habite &agrave; Yokohama ", "___", " les logements sont trop chers &agrave; Tokyo.",
 2, 
 "donc",
 "pourquoi", 
 "parce que",
 "mais");

quiz[5] = new makeQuestion("Je voudrais prendre des vacances ", "___", " me reposer.",
 3, 
 "pourquoi",
 "mais", 
 "parce que",
 "pour");

quiz[6] = new makeQuestion("Il n'a que treize ans, mais il est d&eacute;j&agrave; ", "___", " grand que son p&egrave;re.",
 3, 
 "autant",
 "si", 
 "&eacute;galement",
 "aussi");

quiz[7] = new makeQuestion("Nara se trouve ", "___", " Japon.",
 0, 
 "au",
 "dans", 
 "en",
 "&agrave;");

quiz[8] = new makeQuestion("L'an dernier, l'entreprise a ", "___", " des b&eacute;n&eacute;fices exceptionnels.",
 2, 
 "accompli",
 "achev&eacute;", 
 "r&eacute;alis&eacute;",
 "fabriqu&eacute;");

quiz[9] = new makeQuestion("Le directeur vous a appel&eacute; plusieurs ", "___", ".",
 0, 
 "fois",
 "reprises", 
 "circonstances",
 "cas");

quiz[10] = new makeQuestion("Je vous parle de sc&egrave;nes ", "___", " j'ai vues &agrave; la t&eacute;l&eacute;vision.",
1,
 "qui",
 "que",
 "lesquelles",
 "o&ugrave;");

quiz[11] = new makeQuestion("Je te promets de venir ", "___", " Jean-Luc Nataf aura suffisamment de jours de vacances.",
 0,
 "d&egrave;s que",
 "bien que",
 "&agrave; condition que",
 "&agrave; tel point que");

quiz[12] = new makeQuestion("J'ai oubli&eacute; les documents, mais je ", "___", " montrerai demain.", 
 1, 
 "lui le", 
 "vous les",
 "te la",
 "me les");

quiz[13] = new makeQuestion("Sachiko, Haruhito et moi ", "___", " ensemble hier soir.",
 1, 
 "ont d&icirc;n&eacute;",
 "avons d&icirc;n&eacute;", 
 "dinaient",
 "dinerons");

quiz[14] = new makeQuestion("Nos amis ", "___", " chez nous l'ann&eacute;e prochaine.",
 0, 
 "viendront",
 "viendrez", 
 "viendrons",
 "viendrions");

quiz[15] = new makeQuestion("Il faudrait que les parents ", "___", " moins autoritaires avec leurs enfants.",
 3, 
 "sont",
 "seront", 
 "soit",
 "soient");

quiz[16] = new makeQuestion("Pouvez vous r&eacute;p&eacute;ter plus ", "___", ", je n'ai pas bien compris.",
 1, 
 "rapidement",
 "lentement", 
 "progressivement",
 "brusquement");

quiz[17] = new makeQuestion("Il fume ", "___", " ce soit interdit.",
 1, 
 "m&ecirc;me si",
 "bien que", 
 "parce que",
 "en d&eacute;pit de");

quiz[18] = new makeQuestion("Trop de gens meurent &agrave; ", "___", " d'accidents de la route.",
 3, 
 "suite",
 "fin", 
 "raison",
 "cause");

quiz[19] = new makeQuestion("Les parents n'aiment pas que leurs enfants ", "___", " en discoth&egrave;que.",
 3, 
 "aille",
 "allaient", 
 "vont",
 "aillent");

