// addisubibaum2.js
// (c) Andreas Meier
// Sophie-Scholl-Realschule Weiden
// erstellt am 03.02. 2008
// geändert am 03.02. 2008
// alle Rechte liegen beim Autor


var geloest= 0;
var versuch= 0;
var score =0;
var item = 0;


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

function reset() {
applet = document.applets[0];
applet.setVisible("text1", false);
applet.setVisible("text2", false);
applet.setVisible("text3", false);
applet.setVisible("text4", false);
applet.setVisible("text9", false);
applet.setVisible("text10", false);
applet.setVisible("text11", false);
applet.setVisible("text12", false);
applet.setVisible("text13", false);
applet.setVisible("text14", false);
applet.setVisible("text15", false);
applet.setVisible("text16", false);
applet.setVisible("text17", false);
applet.setVisible("text80", false);
applet.setVisible("text81", false);
applet.setVisible("text82", false);
}



function neueAufgabe() {
reset();
item++;
geloest = 0;
document.Para.loesung1.value ="";
document.Para.loesung2.value ="";
document.Para.loesung3.value ="";
document.Para.wertung.value ="";

zufallsteiler = zufall(1,2);

bzahl1 = zufall(30,850);
bzahl2 = zufall(20,500,bzahl1)
bzahl3 = zufall(10,780);
bzahl4 = zufall(20,550,bzahl3);
if (bzahl1<bzahl2) {dummy = bzahl1; bzahl1 = bzahl2; bzahl2 = dummy;}
if (bzahl3<bzahl4) {dummy = bzahl3; bzahl3 = bzahl4; bzahl4 = dummy;}

if (zufallsteiler ==1) {
bzahl1 = Math.round(bzahl1/10*10)/10;
bzahl2 = Math.round(bzahl2/10*10)/10;
bzahl3 = Math.round(bzahl3/100*100)/100;
bzahl4 = Math.round(bzahl4/100*100)/100;
}

else {
bzahl1 = Math.round(bzahl1/100*100)/100;
bzahl2 = Math.round(bzahl2/100*100)/100;
bzahl3 = Math.round(bzahl3/10*10)/10;
bzahl4 = Math.round(bzahl4/10*10)/10;
}


rech1 = zufall(1,2);
rech2 = zufall(1,2,rech1);
rech3 = 1;

applet = document.applets[0];
applet.evalCommand("basiszahl1 = "+String(bzahl1));
applet.evalCommand("basiszahl2 = "+String(bzahl2));
applet.evalCommand("basiszahl3 = "+String(bzahl3));
applet.evalCommand("basiszahl4 = "+String(bzahl4));
applet.evalCommand("rechenart1 = "+String(rech1));
applet.evalCommand("rechenart2 = "+String(rech2));
applet.evalCommand("rechenart3 = "+String(rech3));

art = zufall(1,5);
if (art == 1) {
applet = document.applets[0];
applet.setVisible("text2", true);
applet.setVisible("text3", true);
applet.setVisible("text9", true);
applet.setVisible("text12", true);
applet.setVisible("text15", true);
applet.setVisible("text80", true);
applet.setVisible("text81", true);

loes3 = applet.getValue("zahl82");
loes1 = bzahl1;
loes2 = bzahl4;
}


if (art == 2) {

applet = document.applets[0];
applet.setVisible("text1", true);
applet.setVisible("text10", true);
applet.setVisible("text13", true);
applet.setVisible("text4", true);
applet.setVisible("text3", true);
applet.setVisible("text15", true);
applet.setVisible("text80", true);
loes3 = applet.getValue("zahl82");
loes2 = applet.getValue("zahl81");
loes1 = bzahl2;
}

if (art == 3) {

applet = document.applets[0];
applet.setVisible("text1", true);
applet.setVisible("text10", true);
applet.setVisible("text11", true);
applet.setVisible("text4", true);
applet.setVisible("text81", true);
applet.setVisible("text82", true);
applet.setVisible("text17", true);
loes3 = applet.getValue("zahl80");
loes2 = bzahl3;
loes1 = bzahl2;
}

if (art == 4) {
applet = document.applets[0];
applet.setVisible("text10", true);
applet.setVisible("text1", true);
applet.setVisible("text4", true);
applet.setVisible("text11", true);
applet.setVisible("text15", true);
applet.setVisible("text80", true);
applet.setVisible("text81", true);

loes3 = applet.getValue("zahl82");
loes1 = bzahl2;
loes2 = bzahl3;

}

if (art == 5) {

applet = document.applets[0];
applet.setVisible("text9", true);
applet.setVisible("text2", true);
applet.setVisible("text3", true);
applet.setVisible("text12", true);
applet.setVisible("text80", true);
applet.setVisible("text82", true);
applet.setVisible("text16", true);
loes3 = applet.getValue("zahl81");
loes2 = bzahl4;
loes1 = bzahl1;
}

loes1 = Math.round(loes1*1000)/1000;
loes2 = Math.round(loes2*1000)/1000;
loes3 = Math.round(loes3*1000)/1000;
document.Para.loesung1.focus();
}

function pruefe()
{
wert1 = 0;wert2 = 0;wert3 = 0;
 if (geloest == 0){

if (document.Para.loesung1.value != ""){
eloes = document.Para.loesung1.value.replace(",",".");
eloes1 =eval(eloes);
}
else eloes1=1000;

if (document.Para.loesung2.value != ""){
eloes = document.Para.loesung2.value.replace(",",".");
eloes2 =eval(eloes);
}
else eloes2=1000;

if (document.Para.loesung3.value != ""){
eloes = document.Para.loesung3.value.replace(",",".");
eloes3 =eval(eloes);
}
else eloes3=1000;

if (eloes1 == loes1){wert1 = 1;score = score +10;}
else {wert1 =0;score = score-10;if (score <0) score =0;}

if (eloes2 == loes2){wert2 = 1;score = score +10;}
else {wert2 =0;score = score-10;if (score <0) score =0;}

if (eloes3 == loes3){wert3 = 1;score = score +10;}
else {wert3 =0;score = score-10;if (score <0) score =0;}



if (wert1 == 1 && wert2 == 1 && wert3 ==1) {
document.Para.wertung.value = "Ausgezeichnet!\n"+
"Du hast alle Werte richtig bestimmt. ";
geloest =1;
}
else {
document.Para.wertung.value = "Leider ist nicht alles richtig!\n"+
"Richtig ist x = "+String(loes1).replace(".",",")+";  y = "+String(loes2).replace(".",",")+";  z = "+String(loes3).replace(".",",");
geloest =1;
}
  }
  else {
document.Para.wertung.value = "Die Aufgabe war schon gelöst!\n"+
"Die Zahlen waren: x = "+String(loes1).replace(".",",")+";  y = "+String(loes2).replace(".",",")+";  z = "+String(loes3).replace(".",",");
score = score -10; if (score <0) score =0;
 }

  document.Para.Punktestand.value = "Punktestand: "+String(score)+ " Punkte bei "+String(item)+" Aufgaben.";
}


function auswerten() {

var punkte = score;
if (punkte < 1) punkte = 1;
// Zurücksetzen der Punkte auf Ausgangswert


geloest= 0;
vesuch= 0;
score = 0;
item = 0;
document.Para.wertung.value = "Deine Punkte werden übertragen.\n Du beginnst wieder bei 0 Punkten.";
document.Para.Punktestand.value = "Punktestand: "+String(score)+ " Punkte bei "+String(item)+" Aufgaben.";

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


