// vorwurzel.js
// erstellt am 28. Dezember 2006
// geändert am 01. Januar 2007
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor


var score =0;
var geloest =0;

function reset(){
document.Para.vx2.value ="";
document.Para.vx3.value ="";
document.Para.vx4.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 hilfe() {
score = score - 15; if (score <0) score =0;
document.Para.points.value = "Aktueller Punktestand: "+String(score)+" Punkte";
document.Para.wertung.value = String(Math.pow(1,2))+" , "+
String(Math.pow(2,2))+" , "+
String(Math.pow(3,2))+" , "+
String(Math.pow(4,2))+" , "+
String(Math.pow(5,2))+" , \n"+
String(Math.pow(6,2))+" , "+
String(Math.pow(7,2))+" , "+
String(Math.pow(8,2))+" , "+
String(Math.pow(9,2))+" , \n"+
String(Math.pow(10,2))+" , "+
String(Math.pow(11,2))+" , "+
String(Math.pow(12,2))+" , "+
String(Math.pow(13,2))+"\n"+
"Diese Hilfe kostet 15 Punkte. Danke!";
}

function schreibe(){
reset();
geloest =0;
zahl1 = zufall(2,13);
if (zahl1<7) zahl2 = zufall(2,6,zahl1);
if (zahl1>6  && zahl1<10) zahl2 = zufall(2,3);
if (zahl1>9) zahl2 = 2;
if (zahl2==4) zahl2 = 3;
quadratzahl= Math.pow(zahl1,2);
erstezahl = quadratzahl*zahl2;

document.Para.vx2.value = String(erstezahl);
document.Para.vx3.value = "";
document.Para.vx4.value = String(zahl2);
document.Para.vx3.focus();

}

function pruefe()
{

if (document.Para.vx3.value !=""){
eingabe = document.Para.vx3.value.replace(",",".");
rat = eval(eingabe);
}
else rat =0;

if (document.Para.vx4.value !=""){
eingabe = document.Para.vx4.value.replace(",",".");
irat = eval(eingabe);
}
else irat =0;

if (geloest ==0) {

if (rat == zahl1 && irat == zahl2) {
document.Para.wertung.value = "Ausgezeichnet, die Aufgabe ist gelöst! \n"+
    "Mit >>Neue Aufgabe erstellen<< \nkannst du weitermachen.";
    score=score+25;
    geloest = 1;
    }

   else   {

    if (Math.round(irat*Math.pow(rat,2)) == erstezahl){
    document.Para.wertung.value = "Du hast richtig radiziert, aber nicht vollständig.\n"+
    String(irat)+" kann weiter radiziert werden.\n"+
    "Dann gibt's auch Punkte.";
    }
    else {
   document.Para.wertung.value = "Leider falsch !\n Es ist: "
   +String(erstezahl) + " = "+String(Math.pow(zahl1,2))+" · "+String(zahl2)+
   " = "+String(zahl1)+"² · "+String(zahl2)+"\n"+
   "Somit lautet die Lösung: "+ String(zahl1)+ " · wurzel("+zahl2+")";
   score = score - 15; if (score <0) score =0;
   geloest = 1;
   }
   }
   }
   else {
   document.Para.wertung.value = "Schwindeln unmöglich !\n Die Aufgabe war schon gelöst.\nDie Lösung war: "
   + String(zahl1)+ " · wurzel("+zahl2+")";
   score = score - 5; if (score <0) score =0;
}



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


function auswerten() {

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


score =0;
geloest =1;

document.Para.vx2.value ="";
document.Para.vx3.value ="";
document.Para.vx4.value ="";

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="Teilweise Radizieren (Hilfe)";
var datnam= "highsqlpost94ww.php";
uebertrag = "<form name = 'eingabe' action ='../../../Mathematik/"+datnam+"' method ='post'>";
auswertung(aufgabenart,punkte,uebertrag);
/*                     Ende                           */
}

