// profiparabel.js
// (c) Andreas Meier
// Sophie-Scholl-Realschule Weiden
// erstellt am 20.04. 2006
// geändert am 20.04. 2006
// alle Rechte liegen beim Autor

var m = 0;
var t = 0;
var hilfe = 0;
var fehler = 0;
var gan = 0;
var aufgabe = 0;
var geloest= 0;
var loesung= 0;
var score = 0;
var ungerade = 0;

function zufall()
{
// Ermittelt eine Zufallszahl
   var zufallszahl = 0;
 zufallszahl=Math.floor(8*Math.random()+1);  // zwischen 1 und 8
return zufallszahl;
}
function zufall2()
{
// Ermittelt eine Zufallszahl
   var zufallszahl = 0;
 zufallszahl=Math.floor(5*Math.random()+1);  // zwischen 1 und 5
return zufallszahl;
}

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



function aufgabeneu()
{
if (gan == 1) Geradeloeschen();
hilfe = 0;
geloest = 0;
aufgabe++;
document.Para.gleichung.value = "";
applet = document.applets[0];
applet.evalCommand("S=(2,2)");
applet.evalCommand("P=(1,3)");
applet.setVisible("p", true);

//a aus  y = a*(x-xs)² festlegen.
vers = zufall();
if (vers == 1) ap = 0.25;
if (vers == 2) ap = -0.25;
if (vers == 3) ap = 0.5;
if (vers == 4) ap = -0.5;
if (vers == 5) ap = 1;
if (vers == 6) ap = -1;
if (vers == 7) ap = 2;
if (vers == 8) ap = -2;
if (ap !=1) aptext =String(ap)+"*";
else aptext = ""
if (ap ==-1) aptext ="- ";

aptext = aptext.replace(".",",")
//x-koordinate des Scheitelpunktes mit Vorzeichen festlegen.
sx = zufall2();
sxv = zufall3();
if (sxv < 3)
   {sxvtext = "+ "+String(sx);
    sx =(-1)*sx;
   }
else {
     sxvtext = "- "+String(sx);
     }
sxvtext = sxvtext.replace(".",",")
//y-koordinate des Scheitelpunktes mit Vorzeichen festlegen.
sy = zufall2();
syv = zufall3();
if (syv < 3)
   {
   syvtext = "- "+String(sy);
    sy =(-1)*sy;
   }
else {
     syvtext = "+ "+String(sy);
     }
syvtext = syvtext.replace(".",",")
//
// Aufgabentext ausgeben
document.Para.aufgzeile1.value ="Zeichne die Parabel p mit";
document.Para.aufgzeile2.value ="y = "+
aptext+ "(x "+sxvtext+")\u00b2 "+syvtext+".   G = IRxIR";
}


function getCoords() {
applet = document.applets[0];
var awert = applet.getValue("a");
var xS = applet.getXcoord("S");
var yS = applet.getYcoord("S");
var dloes = applet.getValueString("p");
dloe =String(dloes);
dloe = dloe.replace("p(x)","y").replace(".",",");

if (awert == ap && xS == sx & yS == sy)
{
if (geloest ==0){

text1 = "Ausgezeichnet!\n";
text2 ="Die Parabel ist richtig gezeichnet!";
text3 ="";
geloest = 1;
if (hilfe == 0) score = score + 15;
else text3 ="\n Du hast dir aber p zeichnen lassen.";
}
else
{
text1 = "Willst du mich betrügen?\n";
text2 ="Die Aufgabe wurde bereits gelöst!\n";
text3 = gleichungablesen.replace("²"," \u00b2");
score = score - 5;
}

}

else {

text1 = "Leider falsch!\n";
text2 = "Die Gleichung deiner Parabel lautet:\n";
text3 = dloe;
score = score - 7;
if (score <0) score = 0;
}

text = text1+ text2 + text3;
document.Para.gleichung.value = text;
ausgabe = document.Para.gleichung.value;
ausgabe = ausgabe +"\n Punktestand: "+score+ " bei "+aufgabe+" Aufgaben";
document.Para.gleichung.value = ausgabe;
}


function Geradezeichnen()
{
applet = document.applets[0];

parabel = aptext+ "(x "+sxvtext+")\u00b2 "+syvtext;
parabel = parabel.replace(",",".");
parabel = parabel.replace(",",".");
parabel = parabel.replace(",",".");


applet.evalCommand("h(x) = "+parabel);
applet.setVisible("h", true);
applet.setVisible("A", true);
applet.setVisible("T2", true);
applet.setVisible("T3", true);

hilfe =1;
gan = 1;}

function Geradeloeschen()
{
applet = document.applets[0];
applet.setVisible("h", false);
applet.setVisible("A", false);
applet.setVisible("T2", false);
applet.setVisible("T3", false);

gan = 0
}

function auswerten() {

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

m = 0;
t = 0;
hilfe = 0;
fehler = 0;
aufgabe = 0;
geloest= 0;
loesung= 0;
score = 0;

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


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

