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

var zaehler =0;
var neuerzaehler =0;
var score =0;
var geloest =0;
var schwindel =0;
var auswahl = 0;
function reset()

{
document.Para.w4.value = "";
document.Para.z1.value = "";
document.Para.zhun.value = "";
document.Para.nhun.value = "100";
document.Para.prozent.value = "";
document.Para.wertung.value = "";
}

function zufall3()
{
// Ermittelt eine Zufallszahl
   var zufallszahl3 = 0;
 zufallszahl3=Math.floor(150*Math.random()+1);  // zwischen 1 und 150
 return zufallszahl3;
}

function schreibe()
     {
reset();
schwindel = 0;
geloest =0;
neuerzaehler = zufall3();
versuch = 0;
zaehler = neuerzaehler/100;
zaehler=Math.round(zaehler * 100) / 100;
document.Para.z1.value = String(zaehler).replace(".",",");
document.Para.nhun.value ="100";
document.Para.zhun.focus();

}

function pruefe()
{
text="";
prozentzeichen = 1;
if (geloest == 0){

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

if (document.Para.prozent.value !=""){
eingabe = document.Para.prozent.value.replace(",",".");
eingabe = eingabe.replace(/ /g,"");
if (String(neuerzaehler)+"%" != eingabe) prozentzeichen = 0;
eingabe = eingabe.replace("%","");
i=eingabe.search("/");if(i>-1) schwindel=1;
eprozent = eval(eingabe);
}
else eprozent =0;



if (schwindel ==0)
{

if ((neuerzaehler == ezhun  & neuerzaehler == eprozent & prozentzeichen == 1)|| (0 == ezhun  & neuerzaehler == eprozent & prozentzeichen == 1))
{
text1 = "Ausgezeichnet!\n";
text2 = "20 Punkte gehen auf dein Konto.\n";
score = score + 20;
text3 = "Aktueller Punktestand: "+score+" Punkte.";
geloest =1;
}

else{

text1 = "Leider falsch!\n";
text2 = "Deshalb 20 Punkte Abzug.\n";
score = score - 20;if (score <0) score = 0;
text3 = "Aktueller Punktestand: "+score+" Punkte.";
if (neuerzaehler != ezhun) text1 = "Du hast falsch erweitert!\n";
}

if (neuerzaehler == ezhun  & neuerzaehler == eprozent & prozentzeichen == 0)
{
text1 = "Richtig, aber das \"%\" - Zeichen fehlt! \n";
text2 = "Deshalb 15 Punkte Abzug.\n";
score = score +5; if (score <0) score = 0;
text3 = "Aktueller Punktestand: "+score+" Punkte.";
geloest =1;}

}// schwindel =1
else
{
text1 = "Es fehlt die Prozentangabe!\n";
text2 = "Schwindeln geht nicht!\n";
score = score +10;if (score <0) score = 0;
text3 = "Aktueller Punktestand: "+score+" Punkte.";
}

}

else
{
text1 = "Die Aufgabe ist bereits gelöst!\n";
text2 = "Schwindeln geht nicht!\n";
score = score - 10;if (score <0) score = 0;
text3 = "Aktueller Punktestand: "+score+" Punkte.";
}
text = text1+text2+text3;
document.Para.wertung.value = text;
}

function auswerten() {

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

zaehler =0;
nenner =1;
score =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="Dezimalzahlen und Prozent";
var datnam= "highsqlpost63ww.php";
uebertrag = "<form name = 'eingabe' action ='../../../Mathematik/"+datnam+"' method ='post'>";
auswertung(aufgabenart,punkte,uebertrag);
/*                     Ende                           */
}

