// Reconnaissance du navigateur et initialisation
// des variables qui serviront à personnaliser
// certaines instructions.

var isNav, isIE
if (parseInt(navigator.appVersion) >= 4)
{ if (navigator.appName == "Netscape")
  { isNav = true
    layerRef = "document.layers"
	styleRef = ""
  }
  else
  { isIE = true
    layerRef = "document.all"
    styleRef = ".style"
  }
}

var nombreDeQuestions = 10

questionCourante = 1

score = 0

reponseCorrecte = new Array(1, 0, 3, 2, 1, 0, 1, 1, 2, 3)

secondEssai = new Array(-1, 2, 0, 1, -1, 3, 0, 2, 3, 1)

questionsRepondues = new Array(nombreDeQuestions+1) 

nombreDeQuestionsRepondues = 0

var secondeChance

function questionSuivante()
{ // Cache
  questionCouranteLayer = eval ("'question' + questionCourante")
  eval (layerRef + "['" + questionCouranteLayer + "']" + styleRef + ".visibility = 'hidden'")

  if (nombreDeQuestionsRepondues == nombreDeQuestions) 
  { afficherTotal()
    return
  }

  for (i=1; i<=nombreDeQuestions; i++) 
   if (questionsRepondues[i] != "oui") 
	 eval (layerRef + "['progression'].document.progression" + i + ".src = 'images/before_" + i + ".gif'")

  questionCourante++
  if (questionCourante > nombreDeQuestions) 
    questionCourante = 1
  
  for (i=questionCourante; i<=nombreDeQuestions; i++)
  { if (questionsRepondues[i] != "oui")
    { questionCourante = i
	  break
	}
    if (i == nombreDeQuestions) i=0
  }

  questionSuivanteLayer = eval ("'question' + questionCourante")
  eval (layerRef + "['" + questionSuivanteLayer + "']" + styleRef + ".visibility = 'visible'")

  eval (layerRef + "['progression'].document.progression" + questionCourante + ".src = 'images/current_" + questionCourante + ".gif'")
  
  secondeChance = false
}

function verifierReponse()
{ currentobj = eval(layerRef + "['question" +
               questionCourante + "'].document.question" +
			   questionCourante + "Form")

  bonneReponse = false

  if (currentobj.elements[reponseCorrecte[questionCourante-1]].checked)
  { bonneReponse = true // oui
  }
  else if ((secondEssai[questionCourante-1] >= 0) && // il y a une seconde chance 
		   (! secondeChance) && // premier essai 
		   currentobj.elements[secondEssai[questionCourante-1]].checked)
							     // question donnant une seconde chance 
	   { eval (layerRef + "['essayerEncore']" +
			   styleRef + ".visibility = 'visible'") 
	     secondeChance = true // une
	     return
 	   }

  if (bonneReponse) // la
  { // Inf
	eval (layerRef + "['score']." + layerRef + 
	      "['exact']" + styleRef + ".visibility = 'visible'")
	eval (layerRef + "['score']." + layerRef + 
	      "['faux']" + styleRef + ".visibility = 'hidden'") 
	if (!secondeChance) 
	 score +=10 // si
	else 
	 score +=5 // si
	displayscore() // affic
  }

  else // Mau
  {	// Info
	eval (layerRef + "['score']." + layerRef + 
	      "['exact']" + styleRef + ".visibility = 'hidden'") 
	eval (layerRef + "['score']." + layerRef + 
	      "['faux']" + styleRef + ".visibility = 'visible'")
	if (!secondeChance) 
	 score +=0 // si
	else 
	 score +=-5 // si 
	displayscore() // afficher le résultat
  }
 
  eval (layerRef + "['progression'].document.progression" 
       + questionCourante + ".src = 'images/after_"
	   + questionCourante + ".gif'")

  questionsRepondues[questionCourante] = "oui" 
  nombreDeQuestionsRepondues++ 
  questionSuivante()
}

function displayscore ()
{ if (isNav)
   document.layers['score'].document.scoreform.scoreBox.value = score 
  else
   document.all['score'].document.all.scoreform.scoreBox.value = score 
  return 
}

function retourAlaQuestion (direction) 
{ // No
  eval (layerRef + "['essayerEncore']" + styleRef + ".visibility = 'hidden'")

  if (direction == "continuer") 
  { secondeChance = false
	questionSuivante()
  }
}

function afficherTotal() 
{ if (score < 40) // nov
  { eval (layerRef + "['finQuestionnaireNovice']" + styleRef + ".visibility = 'visible'")
    { eval (layerRef + "['pubfin']" + styleRef + ".visibility = 'visible'")
	}
  } 
  else if (score <= 70) // util M
  { eval (layerRef + "['finQuestionnaireIntermediaire']" + styleRef + ".visibility = 'visible'")
    { eval (layerRef + "['pubfin']" + styleRef + ".visibility = 'visible'")
	}
  } 
  else // pro 
  { eval (layerRef + "['finQuestionnaireSavant']" + styleRef + ".visibility = 'visible'")
    { eval (layerRef + "['pubfin']" + styleRef + ".visibility = 'visible'")
	}
  }
}

function sautQuestion(numeroQuestion)
{ // Il fa
  
  if (questionsRepondues[numeroQuestion] != "oui")
  {	// cac
    eval(layerRef + "['question" + questionCourante + "']" + styleRef + ".visibility = 'hidden'")
	
	eval(layerRef + "['question" + numeroQuestion + "']" + styleRef + ".visibility = 'visible'")
	
	eval (layerRef + "['progression'].document.progression" + questionCourante+ ".src = 'images/before_" + questionCourante+ ".gif'")
	
	eval (layerRef + "['progression'].document.progression" + numeroQuestion + ".src = 'images/current_" + numeroQuestion + ".gif'")
	
	questionCourante = numeroQuestion
  }
}
