// grundwert.js
// erstellt am 28. Dezember 2005
// geändert am 28. Dezember 2005
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor

var score =0;
var geloest =0;
var schwindel =0;
var versuch = 0;
var prost =0;

function reset()
{
document.Para.w1.value = "";
document.Para.w2.value = "";
document.Para.s1.value = "";
document.Para.s2.value = "";
document.Para.p1.value = "";
document.Para.p2.value = "";

document.Para.wertung.value = "";

}


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



function schreibe()
     {
reset();
versuch =0;
schwindel = 0;
geloest =0;

art = zufall(1,3);
if (art ==1) {
ausgangszahl = zufall(3,10);
wert1b = ausgangszahl/2;
wert1 = zufall(1,8);
faktor = zufall(2,10)
wert2 =wert1* faktor;
wert2b = wert1b*faktor;
loes = wert2b;
document.Para.p1.value = String(wert1);
document.Para.s1.value = String(wert1b).replace(".",",");
document.Para.p2.value = String(wert2);
document.Para.s2.focus();
}

if (art ==2) {
ausgangszahl = zufall(3,10);
wert1b = ausgangszahl/2;
wert1 = zufall(1,8);
faktor = zufall(2,10)
wert2 =wert1* faktor;
wert2b = wert1b*faktor;
loes = wert1b;
document.Para.p1.value = String(wert2);
document.Para.s1.value = String(wert2b).replace(".",",");
document.Para.p2.value = String(wert1);
document.Para.s2.focus();
}

if (art ==3) {
ausgangszahl = zufall(3,15);
wert1b = ausgangszahl;
wert1 = zufall(1,4);
faktor = zufall(2,5)
wert2 =wert1* faktor;
wert2b = wert1b*faktor;
loes = wert2b;
document.Para.p1.value = String(wert1);
document.Para.s1.value = String(wert1b).replace(".",",");
document.Para.p2.value = String(wert2);
document.Para.s2.focus();
}


geloest = 0;
}

function pruefe()
{
if (geloest ==0){

if (document.Para.s2.value !=""){
eingabe = document.Para.s2.value.replace(",",".");
es2 = eval(eingabe);
}else es2 =1000;


if (loes == es2) {
document.Para.w2.value = "";
score = score+20;
geloest =1;
document.Para.wertung.value = "Ausgezeichnet! \nAlle Werte sind richtig berechnet.";
document.Para.punktewertung.value ="Aktueller Punktestand: "+String(score);
}

else {
document.Para.w2.value = "";
score = score -15;
if (score<0) score =0;
document.Para.wertung.value = " Leider nicht richtig! \n Richtig war der Wert: "+String(loes).replace(".",",");
document.Para.punktewertung.value ="Aktueller Punktestand: "+String(score);
geloest =1;
}
}
else {
document.Para.w2.value = "";
score = score - 25;
if (score<0) score =0;
document.Para.wertung.value = " Willst du betrügen! Die Aufgabe war schon \ngelöst: 25 Punkte Abzug!";

document.Para.punktewertung.value ="Aktueller Punktestand: "+String(score);
}


}

function auswerten() {

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


score =0;
geloest =0;

geloest =0;
text1 ="";
text2 ="Deine Punkte werden nun übertragen. \n";
text3 ="Damit werden sie hier gelöscht. \n";
text4="Du beginnst also wieder bei 0 Punkten.";
text5="";
text = text1+text2+text3+text4+text5;
document.Para.wertung.value = text;

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


