// dezimalzahlen.js
// (c) Andreas Meier
// Sophie-Scholl-Realschule Weiden
// erstellt am 25.05. 2007
// geändert am 25.05. 2007
// alle Rechte liegen beim Autor


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

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

function brueche()
{
geloest = 0;
document.Para.wertung.value = "";
document.Para.g10.value = "";

applet = document.applets[0];
applet.evalCommand("R_1 = (0.2,2)");
applet.setVisible("T1", false);
applet.setVisible("T2", false);
applet.setVisible("T3", false);
applet.setVisible("T4", false);
applet.setVisible("T5", false);
applet.setVisible("T6", false);
applet.setVisible("v", false);
applet.setVisible("n", false);
applet.setVisible("M_5", false);

art = zufall (1,3);
if (art ==1 ) {
tausende = zufall(15,50);
hunderte =0;
zehne =0;
schtausende = zufall(2,5);
schhunderte =0;
schzehne =0;
applet = document.applets[0];
applet.evalCommand("tausend = "+String(tausende));
applet.evalCommand("hundert = "+String(hunderte));
applet.evalCommand("zehn = "+String(zehne));
applet.evalCommand("schritttausend = "+String(schtausende));
applet.evalCommand("schritthundert = "+String(schhunderte));
applet.evalCommand("schrittzehn = "+String(schzehne));

textein = zufall(1,2);
if (textein == 2) {
textein = 5;
text2ein = zufall(1,4);
loespunkt = zufall(1,4,text2ein);
loesung = 0.4*10*(loespunkt-1);
}
else {
text2ein = zufall(2,5);
loespunkt = zufall(2,5,text2ein);
loesung = 0.4*10*(loespunkt-1);
}

loespunkt = zufall(2,4,text2ein);
loesung = 0.4*10*(loespunkt-1);
applet = document.applets[0];
applet.setVisible("T"+String(textein), true);
applet.setVisible("T"+String(text2ein), true);

wert = tausende*1000+(loespunkt-1)*schtausende*1000;
document.Para.g10.value = " Wo steht die Zahl "+String(wert/10000).replace(".",",")+"?";
applet.evalCommand("loes = "+String(wert));
applet.evalCommand("M_5 = ("+String(loesung)+",2)");

}


if (art ==2) {
tausende = zufall(1,55);
hunderte =zufall(1,9);
zehne =0;
schtausende = 0;
schhunderte =0;
schzehne =1;
applet = document.applets[0];
applet.evalCommand("tausend = "+String(tausende));
applet.evalCommand("hundert = "+String(hunderte));
applet.evalCommand("zehn = "+String(zehne));
applet.evalCommand("schritttausend = "+String(schtausende));
applet.evalCommand("schritthundert = "+String(schhunderte));
applet.evalCommand("schrittzehn = "+String(schzehne));

textein = zufall(1,2);
if (textein == 2) {
textein = 5;
text2ein = zufall(1,4);
loespunkt = zufall(1,40,text2ein*10);
loesung = 0.4*(loespunkt-1);
}
else {
text2ein = zufall(2,5);
loespunkt = zufall(2,38,text2ein*10);
loesung = 0.4*(loespunkt-1);
}

loespunkt = zufall(2,38,text2ein*10);
loesung = 0.4*(loespunkt-1);
applet = document.applets[0];
applet.setVisible("T"+String(textein), true);
applet.setVisible("T"+String(text2ein), true);

wert = tausende*1000+hunderte*100+(loespunkt-1)*schzehne;
document.Para.g10.value = " Wo steht die Zahl "+String(wert/10000).replace(".",",")+"?";
applet.evalCommand("loes = "+String(wert));
applet.evalCommand("M_5 = ("+String(loesung)+",2)");
}

if (art ==3) {
tausende = zufall(1,55);
hunderte =zufall(1,9);
zehne =0;
schtausende = 0;
schhunderte =zufall(1,2);
schzehne =0;
applet = document.applets[0];
applet.evalCommand("tausend = "+String(tausende));
applet.evalCommand("hundert = "+String(hunderte));
applet.evalCommand("zehn = "+String(zehne));
applet.evalCommand("schritttausend = "+String(schtausende));
applet.evalCommand("schritthundert = "+String(schhunderte));
applet.evalCommand("schrittzehn = "+String(schzehne));

textein = zufall(1,2);
if (textein == 2) {
textein = 5;
text2ein = zufall(1,4);
loespunkt = zufall(1,40,text2ein*10);
loesung = 0.4*(loespunkt-1);
}
else {
text2ein = zufall(2,5);
loespunkt = zufall(2,38,text2ein*10);
loesung = 0.4*(loespunkt-1);
}

loespunkt = zufall(2,38,text2ein*10);
loesung = 0.4*(loespunkt-1);
applet = document.applets[0];
applet.setVisible("T"+String(textein), true);
applet.setVisible("T"+String(text2ein), true);

wert = tausende*1000+hunderte*100+(loespunkt-1)*schhunderte*10;
document.Para.g10.value = " Wo steht die Zahl "+String(wert/10000).replace(".",",")+"?";
applet.evalCommand("loes = "+String(wert));
applet.evalCommand("M_5 = ("+String(loesung)+",2)");
}

}



function pruefe()
{

if (geloest == 0)
{
applet = document.applets[0];
var xr1 = applet.getXcoord("R_1");

if (xr1 < loesung+0.04 && xr1 > loesung - 0.04)
{
geloest = 1;
score = score +20;
document.Para.wertung.value = "Ausgezeichnet! Das hast du richtig gut gemacht.\n"+
"Aktueller Punktestand: "+String(score);
}
else {
score = score - 10; if (score <0) score =0;
document.Para.wertung.value = "Leider falsch! Die richtige Lösung ist eingeblendet.\n"+
"Aktueller Punktestand: "+String(score);
applet = document.applets[0];
applet.setVisible("T1", true);
applet.setVisible("T2", true);
applet.setVisible("T3", true);
applet.setVisible("T4", true);
applet.setVisible("T5", true);
applet.setVisible("T6", true);
applet.setVisible("v", true);
geloest = 1;
}
}
else {
score = score - 10; if (score <0) score =0;
document.Para.wertung.value = "Die Aufgabe war schon geloest!\n"+
"Aktueller Punktestand: "+String(score);
}
}

function auswerten() {

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


geloest= 0;
vesuch= 0;
score = 0;

document.Para.wertung.value = "Deine Punkte werden übertragen.\n Du beginnst wieder bei 0 Punkten.";

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


