/********************************************************************
* akfquiz.js 2.0
* Language: JavaScript
* Copyright (C) 2003 Andreas K. Foerster <akfquiz@akfoerster.de>
*
* This file is part of AKFQuiz
*
* AKFQuiz is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* AKFQuiz is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*********************************************************************/

/*
LIMITS:

- Bei checkboxen wird vorerst keine Grafik unterstützt.
*/

  var intmsg = new Array();


  intmsg["DE"] = new Array("Du hast ", " von maximal ", " Punkten.",
    "Das sind ", "Versuch es doch nochmal!",
    "Du hast doch die Lösungen schon gesehen!",
    "Wirklich die Lösungen zeigen?",
    "Auswertung", "Lösungen zeigen", "Nochmal!");

  var msg = new Array();

  var gezeigt = false;  // wurde die Antwort schon gezeigt?

  var leer    = new Image();
  var richtig = new Image();
  var falsch  = new Image();

  function init(lang) {
    if(intmsg[lang])
      msg = intmsg[lang];
    else
      msg = intmsg["EN"];  /* wenn Sprache noch nicht unterstützt wird */

    /* auch schonmal die Bilder laden */
    leer.src    = "leer.png";
    richtig.src = "richtig.gif";
    falsch.src  = "falsch.gif";
    }

  function Auswertung() {

    function bildanzeige(bildname,bild) {
       for(var b=0;b<document.images.length;b++)
         if(document.images[b].name==bildname)
             document.images[b].src=bild.src;
       }

    function auswerten() {
        var Punkte  = 0;
        var Maximum = 0;
        var Wert;

        for(var i=0; i < document.akfquiz.elements.length-1; i++) {
           with(document.akfquiz.elements[i]) {
             if(type=="radio" || type=="checkbox") {
               Wert = eval(value);
               // positive Werte zählen, egal ob angeklickt
               if(Wert>0) Maximum += Wert;
               // Wenn angeklickt, dann prüfen
               if(checked) {
                 Punkte += Wert;
                 // Grafik erstmal nur bei Radio Buttons
                 if(type=="radio") {
                   if(defaultChecked) bildanzeige(name, leer)
                     else { if(Wert>0) { bildanzeige(name, richtig) }
                            else { bildanzeige(name, falsch) }
                      }
                   }
                 }
               }
             }
           }
        var Antwort;
        Antwort = msg[0]+Punkte+msg[1]+Maximum+msg[2];
        if(Punkte>0)
            Antwort += "\n"+msg[3]+parseInt(Punkte*100/Maximum+.5)+"%."
          else
            Antwort += "\n"+msg[4];
        alert(Antwort);
        }


  function schongesehen() {
    alert(msg[5]);
    }

  if(gezeigt) schongesehen(); else auswerten();
  }

  function Aufloesung() {
    if(confirm(msg[6])) {
      BilderLoeschen();
      if(navigator.appName!="Konqueror") location.href = "#fragen";
        for(var i=0; i < document.akfquiz.elements.length; i++) {
           with(document.akfquiz.elements[i]) {
               if(type=="radio" || type=="checkbox")
                 if(eval(value)>0) checked = true; else checked = false;
               }
           }
       gezeigt = true;
       }
     }

  function BilderLoeschen() {
     for(var i=0;i<document.images.length;i++)
        if(document.images[i].src==richtig.src ||
           document.images[i].src==falsch.src)
             document.images[i].src=leer.src;
     }

  function neu() {
     gezeigt = false;
     location.href = "#fragen";
     BilderLoeschen();
     document.akfquiz.reset();
     return true;
     }


  function buttons() {
    document.write('<div align="center">');

 document.write('<input type="button" class="auswertebutton" accesskey="r" value=" ' +
             msg[7] + ' " onClick="Auswertung()" onMouseDown="Bildwechsel(36,Highlight36)"> &nbsp;');
    document.write('<input type="button" class="buttons" accesskey="s" value=" ' +
             msg[8] + ' " onClick="Aufloesung()"> &nbsp;');
    document.write('<input type="reset" class="buttons" accesskey="n" value=" ' +
             msg[9] + ' " onClick="neu()">');
    document.write('<\/div>');
    }