// detueb1neu.js
// erstellt am 11. Dezember 2004
// geändert am 25. Mai 2006
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor

var high = 0;
var score =0;
var geloest =0;
var hilfe = 0;

function reset()
{
document.Para.ax.value ="";
document.Para.ay.value ="";
document.Para.bx.value ="";
document.Para.by.value="";
document.Para.cx.value ="";
document.Para.cy.value="";

document.Para.abx.value ="";
document.Para.aby.value ="";
document.Para.acx.value ="";
document.Para.acy.value="";

document.Para.faktor.value ="";

document.Para.detx1.value ="";
document.Para.detx2.value ="";
document.Para.dety1.value ="";
document.Para.dety2.value ="";

document.Para.faktor2.value ="";

document.Para.erg1.value ="";
document.Para.erg2.value ="";
document.Para.ergebnis.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 Hilf2() {
   mapwin=open("determinatehilf.html","DisplayWindow","toolbar=no,directories=no,scrollbars=yes,menubar=no,height=425,width=450,resize=no");
}

function WinOpen(){Hilf2();}

function schreibe()
     {
reset();
high = 100;
hilfe =0;
geloest =0;
applet = document.applets[0];
applet.setVisible("T4", false);
applet.setVisible("T5", false);
applet.setVisible("T6", false);
applet.setVisible("T7", false);
applet.setVisible("T8", false);

ax = zufall(-6,1);
ay = zufall(-6,4);
bx = zufall(3,10);
by = zufall(-2,5);

cx =Math.round((ax+bx)/2)+zufall(-2,2);

if (ay > by) cy = ay+zufall(1,4);
else cy = by +zufall(1,4);

applet.evalCommand("A = ("+String(ax)+","+String(ay)+")");
applet.evalCommand("B = ("+String(bx)+","+String(by)+")");
applet.evalCommand("C = ("+String(cx)+","+String(cy)+")");


document.Para.ax.value =ax;
document.Para.ay.value =ay;
document.Para.bx.value =bx;
document.Para.by.value =by;
document.Para.cx.value =cx;
document.Para.cy.value =cy;

}


function vektorenein(){
applet = document.applets[0];
applet.setVisible("T6", true);
applet.setVisible("T5", true);
high = high -50; if (high <0) high =0;
hilfe = 1;}


function loesungein(){
applet = document.applets[0];
applet.setVisible("T4", true);
applet.setVisible("T7", true);
applet.setVisible("T8", true);
high = high -50; if (high <0) high =0;
hilfe = 2;}

function pruefe()
{
a =0;a2 =0;b1 =0;b2 =0;c1 =0;c2 =0;v1 =0;v2 =0;v3 =0;v4 =0;

fakt1 = 0;fakt2 = 0;det1x =0;det1y =0;det2x =0;det2y =0;minuend=0;subtrahend = 0;ende = 0;

text1="";text2="";text3="";text4="";text5="";text6="";
text7="";text8="";text ="";
document.Para.wertung.value =  text;

// Auslesen der Punktkoordinaten - falls Eingabe per Hand!
if (document.Para.ax.value !="")
{
var a1 = eval(document.Para.ax.value.replace(",","."));

}
else a1 =0;

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

}
else a2 =0;

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

}
else b1 =0;

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

}
else b2 =0;

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

}
else c1 =0;

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

}
else c2 =0;

// Ergebnisse ermitteln


var vabx = b1-a1;
var vaby = b2-a2;
var vacx = c1-a1;
var vacy = c2-a2;
var vfakt1 = 0.5;
var vfakt2 = 0.5;
var verg1 = vabx * vacy;
var verg2= vaby * vacx;
var verg= 0.5*(verg1-verg2);
// Ergebnisse ermitteln Ende


// Auslesen der Vektorkoordinaten von AB und AC!
if (document.Para.abx.value !="")
{
var v1 = eval(document.Para.abx.value.replace(",","."));

}
else v1 =0;

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

}
else v2 =0;


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

}
else v3 =0;

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

}
else v4 =0;


// Auslesen des Faktors und der Determinante!

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

}
else fakt1 =0;

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

}
else det1x =0;

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

}
else det2x =0;


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

}
else det1y =0;

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

}
else det2y =0;


// Ende Auslesen des Faktors und der Determinante!

// Auslesen des 2. Faktors und der Differenz und des Ergebnisses!

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

}
else fakt2 =0;

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

}
else minuend =0;

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

}
else subtrahend =0;

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

}
else ende =0;

// Ende Auslesen des 2. Faktors und der Differenz und des Ergebnisses!

// Auswerung der Eingaben

if (v1 == vabx & v2 == vaby)
{
text1 = "AB (ok)!";
ab = 1;
}
else
{
text1 = "AB (f)!"; high = high -15; if (high <0) high =0;
ab = 0;
}
if (v3 == vacx & v4 == vacy)
{
text2 = "AC (ok)!";
ac =1;
}
else
{
text2 = "AC (f)!";high = high -15; if (high <0) high =0;
ac=0;
}

if (fakt1 != vfakt1 || fakt2 != vfakt2 ) {
text3 = "Faktor 0,5 fehlt !";high = high -15; if (high <0) high =0;
}
else text3 = "";

if (ac ==0 || ab ==0)
{
text4 ="Keine Berechnung, da die Vektoren falsch sind!";
text5 ="";
text6 ="";
text7 ="";
text8 ="";
}

else
{
if (det1x != vabx || det2x != vacx || det1y != vaby || det2y != vacy)
{
text4 ="Vektoren in Determinante (falsch)!";high = high -15; if (high <0) high =0;
detfalsch = 1;
}

else
{
text4 = "Determinate (ok)!";
detfalsch = 0;
}
if (detfalsch ==0)
{
if (verg1 != minuend) {
text5 =" Minuend (falsch)!";high = high -15; if (high <0) high =0;}
else text5="";
if (verg2 != subtrahend) {
text6 =" Subtrahend (falsch)!";high = high -15; if (high <0) high =0;}
else text6="";

if (ende != verg) {
text7 ="Endergebnis falsch!";high = high -15; if (high <0) high =0;}

else {text7 ="Endergebnis richtig!";
if (hilfe ==0){
if (geloest == 0) {
score =score +high;
geloest = 1;
}
else {score = score -35;if (score <0) score =0;}
}else text7 = "Mit schummeln kann's jeder!";
}


}
}
text = text1+" "+text2+" "+text3+"\n"+"  "+text4 +" "+text5+"\n"+text6 +"  "+text7;

if (v1 == vabx & v2 == vaby & v3 == vacx & v4 == vacy & fakt1 == vfakt1 & fakt2 == vfakt2 & det1x == vabx & det2x == vacx & det1y == vaby & det2y == vacy & verg1 == minuend & verg2 == subtrahend & ende == verg) {
if (hilfe == 0) text = "Ausgezeichnet! Alles richtig!\nPerfekt gelöst!";
else text = "Ausgezeichnet! Alles richtig!\nDu hast aber die Hilfe verwendet!\n Daher keine Punkte.";
}
if (a1 == b1 & a2 == b1 & a1 == 0 & c1 == a1 & c1 == 0 & c2 == 0 & b2 == 0 )text = "Keine Punktkoordinaten vorhanden!";
if ((ende == verg & det1x == 0 & det2x == 0 & det1y == 0 & det2y == 0)|| (ende == verg & minuend == 0 & subtrahend == 0))
if (hilfe ==0) text = "Ausgezeichnet! Das Ergebnis ist richtig. \nDoch solltest du zur Übung alle Zahlenwerte eintragen!";
else text = "Schummeln ist deine Stärke! \nDoch solltest du immer mit mir rechnen!\n Natürlich keine Punkte.";
if (det1x == 0 & det2x == 0 & det1y == 0 & det2y == 0 & ende == 0 & a1 != 0 &  b1 != 0 & a2 != 0 & b2 != 0 & v1 == 0 & v2 == 0 & v3 == 0 & v4 == 0 ) text = "Berechnung fehlt, du Witzbold!";

document.Para.wertung.value =  text;
document.Para.punktewertung.value =  String(score)+" Punkte";


}


function auswerten() {

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


score =0;
geloest =1;


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

