// gleichunglevel.js
// erstellt am 06. August 2007
// geaendert am 09. August 2007
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor

var Score = 0; // Startkapital
var Item = 1;
var Aufggleich = 0;
var ok = 0;
var k=0;
var start=0;
var aufgabenr=0;
var fehler =0;
var point =0;
var xlos =0;
var geloest =0;
var loesung = 0;

function zufall(min, max, ohne) {
  var zufallszahl;
  do {
  zufallszahl = Math.round(min + Math.random() * (max - min));
  } while (zufallszahl == ohne);
  return zufallszahl;
}

function reset()  {
document.Parameter.summe.value =  "";
Schreibez1();
}


function Schreibez1()  {

document.Parameter.z1.value =  "";
document.Parameter.z2.value =  "";
document.Parameter.z1w.value =  "";
document.Parameter.z2w.value =  "";
document.Parameter.Zahl.value = "";
document.Parameter.Pruefergebnis.value = "";
document.Parameter.kommentar.value = "";
document.Parameter.Punkte.value=Score;
document.Parameter.Aufgaben.value=Item;
document.Parameter.Aufgaben2.value=geloest;
geloest =0;
geloest2 =0;
fehler = 0;
points = 20;
var dummy = 0;
var index = 1;
k = 0;
Item++;
aufgabenr++;
artist = zufall(1,2);
 c = -1;
if (artist ==1){

 do {
     loesung = zufall(1,11);
     if (loesung ==11) loesung = 0.5;
     a = zufall(2,12);
     if (a == 11) a = 0.5;
     if (a == 12) a = 0.1;
     b = 0;
     c = a*loesung + b;
     c = Math.round(c*100)/100;
 } while (c <0);

texta = String(a).replace(".",",")+"x";

textc1 = " = ";
textc2 = String(c).replace(".",",");
art = zufall(1,2);

if (art == 1) aufgabentext = texta + textc1 + textc2;
if (art == 2) aufgabentext = textc2 + textc1 + texta;
}


if (artist ==2){

 do {
     loesung = zufall(2,12);
     if (loesung ==12) loesung = 0.5;
     a = 1;
     if (a == 11) a = 0.5;
     if (a == 12) a = 0.1;
     b = zufall(1,20)/2;
     b =Math.round(b*100)/100;
     c = loesung + b;
     c = Math.round(c*100)/100;
 } while (c <0);

texta = "x + "+String(b).replace(".",",");
textc1 = " = ";
textc2 = String(c).replace(".",",");
art = zufall(1,2);
if (art == 1) aufgabentext = texta + textc1 + textc2;
if (art == 2) aufgabentext = textc2 + textc1 + texta;

}


document.Parameter.z1.value = aufgabentext;
document.Parameter.z2.focus();

}



function ergproof()
{
if (geloest ==0) {
  if (document.Parameter.z2.value != ""){
  exs = document.Parameter.z2.value;
  ex = eval(exs.replace(",","."));
  }
  else ex = 1000;

// auswertung

  if (ex == loesung) {
    text1 ="";
    text2 ="Ausgezeichnet!! \n";
    text3 ="";
    text4="Gib noch die Lösungsmenge an,\n";
    text5 ="dann gibt es Punkte.";
    document.Parameter.Punkte.value=Score;
    document.Parameter.Aufgaben2.value=ok;
    document.Parameter.z2w.value="(r)";
    geloest = 1;
   }
   else
   {
    text1 ="";
    text2 ="Leider falsch! \n";
    text3 ="";
    text4="Versuche, deine Eingabe zu verbessern.";
    text5 ="";
    if (artist ==2) document.Parameter.z1w.value =  "|-"+String(b).replace(".",",");
    else document.Parameter.z1w.value =  "|:"+String(a).replace(".",",");
    document.Parameter.z2w.value="(f)";
    point = point -12; if (point <0) point =0;
    Score++;
    }
    }
 else
{

text2 ="\nNicht schummeln!! \n";
text3 ="Du hast doch diese Aufgabe bereits gelöst.\n";
text4="Sonst zähle ich dies als Fehler!";
text5 ="\n";

}
text = text2+text3+text4+text5;
document.Parameter.kommentar.value = text;
document.Parameter.Punkte.value=Score;
}



function kproof() {

xlos = loesung;

if (geloest2 ==0){
if (document.Parameter.Zahl.value != "")
{
var zah = document.Parameter.Zahl.value.replace(",",".");
zah =eval(zah);
}
else zah=10000;

  if (zah == xlos)
  {
   ok++;
   document.Parameter.Pruefergebnis.value = "Ausgezeichnet!";
   document.Parameter.Punkte.value=Score;
   document.Parameter.Aufgaben2.value=ok;
   point = point+ points; if (point <0) point =0;
   document.Parameter.summe.value="Punktestand: "+point+ " Punkte";
   geloest2 = 1;

  }
  else
  {
   Score++;point = point-10; if (point <0) point =0;
   document.Parameter.Pruefergebnis.value = "Leider falsch!";
  }
  }else {
     document.Parameter.Pruefergebnis.value ="Nicht schummeln!";
     point = point-10; if (point <0) point =0;
     document.Parameter.Punkte.value=Score;
     document.Parameter.summe.value="Punktestand: "+point+ " Punkte";
  }

  }

function auswerten() {

var punkte = point;

// Zurücksetzen der Punkte auf Ausgangswert

Score = 10; // Startkapital
Item = 1;
Aufggleich = 0;
point = 0;
document.Parameter.Punkte.value=Score;
document.Parameter.Aufgaben.value=Item;
document.Parameter.summe.value="Die Punkte werden übertragen ...";

/* Achtung muss für jede Datei manuell angepasst werden */
/*                     Anfang                           */
var aufgabenart="Gleichungen loesen -1-";
var datnam= "highsqlpost613ww.php";
uebertrag = "<form name = 'eingabe' action ='../../../Mathematik/"+datnam+"' method ='post'>";
auswertung(aufgabenart,punkte,uebertrag);
/*                     Ende                           */
}


