// rechteck.js
// erstellt am 23. Mai 2005
// geaendert am 04. Juni 2005
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor

var anzahl =0;
var punkte =0;
var nummer =0;
var geloest =0;
var bonus = 0;

function reset()
{
document.Para.Auswahl.checked == false;
document.Para.Auswahl2.checked == false ;
document.Para.mvx.value ="";
document.Para.mvy.value ="";
document.Para.vx.value ="";
document.Para.vy.value ="";
document.Para.wertung.value="";

}

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 zufallszahl2 = 0;
 zufallszahl2=Math.floor(4*Math.random()+1);  // zwischen 1 und 4
 return zufallszahl2;
}
function zufall3()
{
// Ermittelt eine Zufallszahl
   var zufallszahl3 = 0;
 zufallszahl3=Math.floor(2*Math.random()+1);  // zwischen 1 und 2
 return zufallszahl3;
}

function schreibe()
     {
document.Para.mvx.value ="";
document.Para.mvy.value ="";
document.Para.vx.value ="";
document.Para.vy.value ="";
document.Para.wertung.value="";

vx =0;
vy =0;
mvx =0;
mvy =0;
geloest =0;
anzahl++;
if (anzahl ==5) anzahl = 1;
nummer++
score =20;
vx = zufall();
vy = zufall();
vorzeivy = zufall3();
vorzeivx = zufall3();
if (document.Para.Auswahl2.checked == false)
{
vorzeivx = 2;
vorzeivy = 2;
}

if (vorzeivx ==1) vx =vx/2;
if (vorzeivy ==1 & vorzeivx !=1) vy =vy/2;
mvx = vx*vy;
mvy = 2*(vy+vx);

vxstr = String(vx).replace(".",",");
vystr = String(vy).replace(".",",");
mvxstr = String(mvx).replace(".",",");
mvystr = String(mvy).replace(".",",");

if (document.Para.Auswahl.checked == false & anzahl == 4) anzahl = 1;

if (anzahl ==1)
{
document.Para.mvx.value ="";
document.Para.mvy.value ="";
document.Para.vx.value =vxstr;
document.Para.vy.value =vystr;
}

if (anzahl ==4)
{
document.Para.mvx.value =mvxstr;
document.Para.mvy.value =mvystr;
document.Para.vx.value ="";
document.Para.vy.value ="";
}

if (anzahl ==2)
{
document.Para.mvx.value =mvxstr;
document.Para.mvy.value ="";
document.Para.vx.value =vxstr;
document.Para.vy.value ="";
}

if (anzahl ==3)
{
document.Para.mvx.value ="";
document.Para.mvy.value =mvystr;
document.Para.vx.value =""
document.Para.vy.value =vystr;
}

document.Para.wertung.value="";
}

function pruefe()
{

mv1 =0;
mv2 =0;
v1 =0;
v2=0;

text ="";
document.Para.wertung.value =  text;


// Auslesen der Vektorkoordinaten als Ergebnis!
if (document.Para.vx.value !="")
{
var v1 = eval(document.Para.vx.value.replace(",","."));

}
else v1 =0;

if (document.Para.vy.value !="")
{
var v2 = eval(document.Para.vy.value.replace(",","."));

}
else v2 =0;


// Auslesen der Gegenvektorkoordinaten
if (document.Para.mvx.value !="")
{
var mv1 = eval(document.Para.mvx.value.replace(",","."));

}
else mv1 =0;

if (document.Para.mvy.value !="")
{
var mv2 = eval(document.Para.mvy.value.replace(",","."));

}
else mv2 =0;

// Ende Auslesen der Vektorkoordinaten - Differenz!

// Auswertung der Eingaben

if (geloest !=1)
{


if ((2*(v1+v2) == mv2) & (v1*v2 == mv1))
{
if (document.Para.Auswahl2.checked == true & (vorzeivx ==1 || vorzeivy ==1)) bonus=bonus+5;
if (document.Para.Auswahl.checked == true & anzahl ==4) bonus=bonus+10;

punkte = punkte + score;
text = "Ausgezeichnet! Alles richtig!\nStand: "+String(punkte)+" von "+
String(nummer*20)+ " möglichen Punkten.\nBonuspunkte: "+String(bonus)+ "; Gesamtpunktzahl: "+String(bonus+punkte);
geloest = 1;
}
else
{
text="Alle Lösungen sind leider falsch!";

if (v1*v2 == mv1) text ="Seiten und Flächeninhalt korrekt,\naber Seiten und Umfang falsch.";
if (2*(v1+v2) == mv2) text ="Seiten und Umfang korrekt,\naber Seiten und Flächeninhalt falsch.";
score=score-5;
if (score<=0) score =0;
}

if (mv2 == 0 & v2 == 0 & v1 == 0 & mv1 == 0)
{
text = "Keine Aufgabe erstellt!";
}
}
else
{
text = "Die Aufgabe ist bereits gelöst.\nDu wolltest schummeln!\n Deshalb 5 Punkte Abzug.";
score=score-5;
if (score<=0) score =0;
}

document.Para.wertung.value =  text;

}


function auswerten() {

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

anzahl =0;
punkte =0;
nummer =0;
geloest =0;
bonus = 0;
document.Para.Auswahl.checked == false;
document.Para.Auswahl2.checked == false ;
document.Para.mvx.value ="";
document.Para.mvy.value ="";
document.Para.vx.value ="";
document.Para.vy.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="Grundwissen Rechteck";
var datnam= "highsqlpostww.php";
uebertrag = "<form name = 'eingabe' action ='../../../Mathematik/"+datnam+"' method ='post'>";
auswertung(aufgabenart,points,uebertrag);
/*                     Ende                           */
}


