/*------------------------------------------------------------------*\
 * Quiz                                                             *
 * This script is based on scripts available free online at         *
 * The JavaScript Source :: http://javascript.internet.com          *
 *                                                                  *
 * Version 1.0         2007 Created by Gert den Drijver             *
\*------------------------------------------------------------------*/ 

var useranswers = new Array();
var answered = 0;

function renderQuiz() {
  for(i=0;i<questions.length;i++) {
    document.writeln('<p class="question">' + questions[i] + ' <span id="result_' + i + '"><img src="../images/qblank.gif" style="border:0" alt="" /></span></p>');
    for(j=0;j<choices[i].length;j++) {
      document.writeln('<input type="radio" name="answer_' + i + '" value="' + choices[i][j] + '" id="answer_' + i + '_' + j + '" class="question_' + i + '" onclick="submitAnswer(' + i + ', this, \'question_' + i + '\', \'label_' + i + '_' + j + '\')" /><label id="label_' + i + '_' + j + '" for="answer_' + i + '_' + j + '"> ' + choices[i][j] + '</label><br />');
    }
  }
  document.writeln('<p><input type="submit" value="Show Score" onclick="showScore()" /> <input type="submit" value="Reset Quiz" onclick="resetQuiz(true)" /></p><p style="display:none"><img src="../images/qcorrect.gif" style="border:0" alt="Correct!" /><img src="../images/qincorrect.gif" style="border:0" alt="Incorrect!" /></p>');

}
function resetQuiz(showConfirm){
  if(showConfirm)
    if(!confirm("Weet je zeker dat je jouw antwoorden wilt wissen en opnieuw wilt beginnen ?"))
      return false;
  document.location = document.location;
}


function submitAnswer(questionId, obj, classId, labelId) {
  useranswers[questionId] = obj.value;
  document.getElementById(labelId).style.fontWeight = "bold";
  disableQuestion(classId);
  showResult(questionId);
  answered++;
}
function showResult(questionId) {
  if(answers[questionId] == useranswers[questionId]) {
    document.getElementById('result_' + questionId).innerHTML = '<img src="../images/qcorrect.gif" style="border:0" alt="Correct!" />';
  } else {
    document.getElementById('result_' + questionId).innerHTML = '<img src="../images/qincorrect.gif" style="border:0" alt="Incorrect!" />';
  }
}
function showScore() {
  if(answered != answers.length) {
    alert("Je hebt nog niet alle vragen beantwoord!");
    return false;
  }
  questionCount = answers.length;
  correct = 0;
  incorrect = 0;
  for(i=0;i<questionCount;i++) {
    if(useranswers[i] == answers[i])
      correct++;
    else
      incorrect++;
  }
  pc = Math.round((correct / questionCount) * 100);
  alertMsg = "Je scoorde " + correct + " van de " + questionCount + "\n\n";
  alertMsg += "Je hebt " + pc + "% van de antwoorden goed! \n\n";
  if(pc == 100)
    alertMsg += response[0];
  else if(pc >= 90)
    alertMsg += response[1];
  else if(pc >= 70)
    alertMsg += response[2];
  else if(pc > 50)
    alertMsg += response[3];
  else if(pc >= 40)
    alertMsg += response[4];
  else if(pc >= 20)
    alertMsg += response[5];
  else if(pc >= 10)
    alertMsg += response[6];
  else
    alertMsg += response[7];
  if(pc < 100) {
    if(confirm(alertMsg))
      resetQuiz(false);
    else
      return false;
  } else {
    alert(alertMsg);
  }
}
function disableQuestion(classId) {
  var alltags=document.all? document.all : document.getElementsByTagName("*")
  for (i=0; i<alltags.length; i++) {
    if (alltags[i].className == classId) {
      alltags[i].disabled = true;
    }
  }
}

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: James Crooke :: http://www.cj-design.com */

var questions = new Array();
var choices = new Array();
var answers = new Array();
var response = new Array();

// To add more questions, just follow the format below.

questions[0] = "1) De vorm van een PAS OP bord is ...";
choices[0] = new Array();
choices[0][0] = "vierkant";
choices[0][1] = "rond";
choices[0][2] = "driehoekig";
choices[0][3] = "zeshoekig";
answers[0] = choices[0][2];

questions[1] = "2) De kleuren van een PAS OP bord zijn ...";
choices[1] = new Array();
choices[1][0] = "blauw wit";
choices[1][1] = "rood zwart";
choices[1][2] = "rood wit blauw";
choices[1][3] = "rood wit zwart";
answers[1] = choices[1][3];

questions[2] = "3) Het doel van een PAS OP bord is ...";
choices[2] = new Array();
choices[2][0] = "jou te waarschuwen";
choices[2][1] = "jou te waarschuwen dat je iets mag";
choices[2][2] = "jou te waarschuwen dat je iets niet mag";
choices[2][3] = "jou te waarschuwen dat je iets moet";
answers[2] = choices[2][0];

questions[3] = "4) De vorm van KIJK HIER borden is ...";
choices[3] = new Array();
choices[3][0] = "rond";
choices[3][1] = "vierkant op z'n punt";
choices[3][2] = "driehoekig punt naar boven";
choices[3][3] = "rechthoekig of vierkant";
answers[3] = choices[3][3];

questions[4] = "5) De vorm van JE MAG HIER NIET borden is ...";
choices[4] = new Array();
choices[4][0] = "driehoekig punt naar boven";
choices[4][1] = "zeshoekig";
choices[4][2] = "rond";
choices[4][3] = "driehoekig punt naar beneden";
answers[4] = choices[4][2];

questions[5] = "6) De vorm en kleuren van JE MOET HIER borden zijn ...";
choices[5] = new Array();
choices[5][0] = "vierkant,rood wit blauw";
choices[5][1] = "rond, blauw en wit";
choices[5][2] = "rond, rood, wit en zwart";
choices[5][3] = "driehoekig, rood wit en zwart";
answers[5] = choices[5][1];

// response for getting 100%
response[0] = "Excellent, klik op het kereltje boven in het scherm !";
// response for getting 90% or more
response[1] = "Excellent, probeer het nog eens om 100%!"
// response for getting 70% or more
response[2] = "Goed gedaan, dit is een goede score, kun je nog beter ?";
// response for getting over 50%
response[3] = "Aardig, je hebt meer dan de helft goed, kun je nog beter?";
// response for getting 40% or more
response[4] = "Je hebt er een paar goed, dat kun je vast beter!";
// response for getting 20% or more
response[5] = "Dat was niet zo goed, waarom probeer je het niet nogeens ?";
// response for getting 10% or more
response[6] = "Dat was behoorlijk slecht!  Probeer het opnieuw om beter te scoren!";
// response for getting 9% or less
response[7] = "Oh jee, ik denk dat nog veel moet leren (of probeer het opnieuw)!";

//dDr End of Quiz
