// zahlenaddieren.js
// erstellt 21. Dezember 2007
// geändert 21. Dezember 2007
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor

var Score = 10; // Startkapital
var Item = 1;
var geloest = 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.kommentar.value = "";
document.Parameter.z4w.value =  "";
document.Parameter.z3w.value =  "";
document.Parameter.z2w.value =  "";
document.Parameter.z1w.value =  "";
}

function aufgabe(){
reset();
geloest =0;

wert = new Array();
for (i = 1; i<4 ; i++) wert[i] = 0;
einer = new Array();
for (i = 1; i<4 ; i++) einer[i] = 0;
zehntel = new Array();
for (i = 1; i<4 ; i++) zehntel[i] = 0;
huntel = new Array();
for (i = 1; i<4 ; i++) huntel[i] = 0;
tautel = new Array();
for (i = 1; i<4 ; i++) tautel[i] = 0;

for (i = 1; i<4 ;i ++) {

einer[i] = zufall(1,10); if (einer[i]>9) einer[i] = 1;
zehntel[i] = zufall(0,9);
huntel[i] = zufall(0,9);
tautel[i] = zufall(0,12); if (tautel[i]>9) tautel[i] = zufall(6,9);
if (zehntel[i] ==0 && huntel[i] == 0 && tautel[i] == 0 ) tautel[i] = zufall(5,9);
}

loeseiner =0;
loeszehntel =0;
loeshuntel =0;
loestautel =0;
loeszehntautel =0;

for (i = 1; i<4 ;i ++) {
loeseiner =loeseiner+einer[i];
loeszehntel =loeszehntel+zehntel[i];
loeshuntel =loeshuntel+huntel[i];
loestautel =loestautel+tautel[i];
} // end i

if(loeseiner >29){ loeseiner = loeseiner-30; loeszehntel = loeszehntel+3;}
if(loeseiner >19){ loeseiner = loeseiner-20; loeszehntel = loeszehntel+2;}
if(loeseiner >9){ loeseiner = loeseiner-10; loeszehntel = loeszehntel+1;}

if(loeszehntel >29){ loeszehntel = loeszehntel-30; loeshuntel = loeshuntel+3;}
if(loeszehntel >19){ loeszehntel = loeszehntel-20; loeshuntel = loeshuntel+2;}
if(loeszehntel >9){ loeszehntel = loeszehntel-10; loeshuntel = loeshuntel+1;}

if(loeshuntel >29){ loeshuntel = loeshuntel-30; loestautel = loestautel+3;}
if(loeshuntel >19){ loeshuntel = loeshuntel-20; loestautel = loestautel+2;}
if(loeshuntel >9){ loeshuntel = loeshuntel-10; loestautel = loestautel+1;}

if(loestautel >29){ loestautel = loestautel-30; loeszehntautel = 3;}
if(loestautel >19){ loestautel = loestautel-20; loeszehntautel = 2;}
if(loestautel >9){ loestautel = loestautel-10; loeszehntautel = 1;}
loes1 = huntel[1];
loes2 = zehntel[2];
loes3 = einer[3];
loes4 = loestautel;
loes5 = loeszehntautel;

document.Parameter.z0a.value =  "+";
if (tautel[1] !=0) document.Parameter.z1a.value =  tautel[1];
else document.Parameter.z1a.value =  "";
document.Parameter.z1b.value =  "";
document.Parameter.z1c.value =  zehntel[1];
document.Parameter.z1d.value =  einer[1];
if (tautel[2] !=0) document.Parameter.z2a.value =  tautel[2];
else document.Parameter.z2a.value =  "";
document.Parameter.z2b.value =  huntel[2];
document.Parameter.z2c.value =  "";
document.Parameter.z2d.value =  einer[2];
if (tautel[3] !=0) document.Parameter.z3a.value =  tautel[3];
else document.Parameter.z3a.value =  "";
document.Parameter.z3b.value =  huntel[3];
document.Parameter.z3c.value =  zehntel[3];
document.Parameter.z3d.value =  "";
document.Parameter.z4a.value =  "";
document.Parameter.z4b.value =  loeshuntel;
document.Parameter.z4c.value =  loeszehntel;
document.Parameter.z4d.value =  loeseiner;
document.Parameter.z4e.value =  "";


document.Parameter.kommentar.value = "";
document.Parameter.Punkte.value=Score;
document.Parameter.Aufgaben.value=Item;

Item++;
document.Parameter.z3d.focus();
}

function ergproof()
{

if (geloest == 0) {

// Tabelle einlesen

if (document.Parameter.z1b.value != ""){
var ze22 = document.Parameter.z1b.value.replace(",",".");
eloes1 =eval(ze22);
}
else eloes1=0;

if (document.Parameter.z2c.value != ""){
var ze23 = document.Parameter.z2c.value.replace(",",".");
eloes2 =eval(ze23);
}
else eloes2=0;


if (document.Parameter.z3d.value != ""){
var ze24 = document.Parameter.z3d.value.replace(",",".");
eloes3 =eval(ze24);
}
else eloes3=0;


if (document.Parameter.z4a.value != ""){
var ze32 = document.Parameter.z4a.value.replace(",",".");
eloes4 =eval(ze32);
}
else eloes4=0;

if (document.Parameter.z4e.value != ""){
var ze33 = document.Parameter.z4e.value.replace(",",".");
eloes5 =eval(ze33);
}
else eloes5=0;


// tabelle einlesen Ende
// auswertung

if (loes1 == eloes1){
document.Parameter.z1w.value= ""; Score = Score + 10;}
else {
document.Parameter.z1w.value=loes1;Score = Score -10;if (Score<0) Score =0;}

if (loes2 == eloes2){
document.Parameter.z1w.value= ""; Score = Score + 10;}
else {
document.Parameter.z2w.value=loes2; Score = Score -10;if (Score<0) Score =0;}

if (loes3 == eloes3){
document.Parameter.z3w.value= ""; Score = Score + 10;}
else {
document.Parameter.z3w.value=loes3; Score = Score -10;if (Score<0) Score =0;}

if (loes4 == eloes4 && loes5 == eloes5){
document.Parameter.z4w.value= ""; Score = Score + 10;}
else {
document.Parameter.z4w.value=String(loes5)+""+String(loes4);
Score = Score -10;if (Score<0) Score =0;}


if (loes1 == eloes1 && loes2 == eloes2 && loes3 == eloes3 && loes4 == eloes4 && loes5 == eloes5){
text = "Ausgezeichnet!\nDie Aufgabe ist komplett gelöst!";
document.Parameter.kommentar.value = text;
document.Parameter.Punkte.value=Score;
geloest = 1;

}
else {
text = "Leider falsch!\nDa sind dir wohl Fehler unterlaufen.\n Richtige Ziffern sind eingeblendet!";
document.Parameter.kommentar.value = text;
document.Parameter.Punkte.value=Score;
geloest = 1;

}
}

else {
text = "Willst du schummeln?\nDafür ziehe ich dir 20 Punkte ab!";
document.Parameter.kommentar.value = text;
Score = Score -20;if (Score<0) Score =0;
document.Parameter.Punkte.value=Score;
geloest = 1;
}
}

function auswerten() {


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

Score = 10; // Startkapital
Item = 1;
start=0;
text ="";
text1 ="";
text2 ="Deine Punkte werden nun übertragen. \n";
text3 ="Damit werden sie hier gelöscht. \n";
text4="Du beginnst also wieder bei 10 Punkten.";
text5="";
text = text1+text2+text3+text4+text5;
document.Parameter.kommentar.value = text;
document.Parameter.Punkte.value=Score;

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


