// bruchord.js
// erstellt am 17. Juli 2006
// zuletzt geändert am 18. Juli 2006
// Autor: Andreas Meier, Weiden i.d.OPf.
// alle Rechte liegen beim Autor

var anzahl =0;
var score =0;
var geloest =0;
var gesucht =0;
var pfeila =0;var pfeill =0;var pfeilm =0;var pfeiln =0;var pfeilo =0;var pfeilw =0;


function reset()
{

document.Para.vx.value ="";
document.Para.wertung.value ="";
applet = document.applets[0];
applet.evalCommand("A = (-3,10)");
applet.evalCommand("L = (-3,8)");
applet.evalCommand("M = (-3,6)");
applet.evalCommand("N = (-3,4)");
applet.evalCommand("O = (-3,2)");
applet.evalCommand("W = (-3,0)");
applet.setVisible("A", true);
applet.setVisible("L", true);
applet.setVisible("M", true);
applet.setVisible("N", true);
applet.setVisible("O", true);
applet.setVisible("W", true);

}

function zufall(min, max, ohne) {
  var zufallszahl;
  do {
  zufallszahl = Math.round(min + Math.random() * (max - min));
  } while (zufallszahl == ohne);
  return zufallszahl;
}


function ggt(m,n)
{if (n==0) return m; else return ggt(n, m%n);}

function neueAufgabe() {
zahl = new Array();
for (i = 1; i<7 ; i++)  zahl[i] = 0;
wert = new Array();
for (i = 1; i<7 ; i++)  wert[i] = 0;
zaehler = new Array();
for (i = 1; i<7 ; i++)  zaehler[i] = 0;
nenner = new Array();
for (i = 1; i<7 ; i++)  nenner[i] = 0;


for (i = 1; i<7 ; i++) {
zaehler[i] = zufall(1,10);
nenner [i] = zufall(1,12,zaehler[i]);
if (zaehler[i] > nenner[i]){dummy = zaehler[i]; zaehler[i] = nenner[i]; nenner[i] = dummy;}

divisor = ggt(zaehler[i],nenner[i]);
zaehler[i] = zaehler[i]/divisor;
nenner[i] = nenner[i]/divisor;
zahl[i] = zaehler[i]/nenner[i];
}
for (i = 1; i<7; i++){
for (j =i+1; j<7;j++){
if (zahl[i] == zahl[j]) {nenner [j] = 13+zufall(4,6,5); zahl[j] = zaehler[j]/nenner[j];}
}
}

// Sortieren

        for (i = 1; i<=6; i++) {
                for (j = 6; j>=i; j--) {
                        if (zahl[j-1]>zahl[j]) {
                                x = zahl[j-1];
                                x2 = zaehler[j-1];
                                x3 = nenner[j-1];
                                zahl[j-1] = zahl[j];
                                zaehler[j-1] = zaehler[j];
                                nenner[j-1] = nenner[j];
                                zahl[j] = x;
                                zaehler[j] = x2;
                                nenner[j] = x3;

                        }
                }
        }

// ende Sortieren


einlegen = zufall (1,4)
if (einlegen == 1) {

applet.evalCommand("n = "+String(zaehler[1]));
applet.evalCommand("i_1 = "+String(nenner[1]));

applet.evalCommand("l_1 = "+String(zaehler[3]));
applet.evalCommand("m_1 = "+String(nenner[3]));

applet.evalCommand("n_1 = "+String(zaehler[4]));
applet.evalCommand("o_1 = "+String(nenner[4]));

applet.evalCommand("s_1 = "+String(zaehler[6]));
applet.evalCommand("t_1 = "+String(nenner[6]));

applet.evalCommand("a_2 = "+String(zaehler[5]));
applet.evalCommand("b_2 = "+String(nenner[5]));

applet.evalCommand("c_2 = "+String(zaehler[2]));
applet.evalCommand("d_2 = "+String(nenner[2]));

ax = 1; ay = 0;
lx = 1; ly = 4;
mx = 1; my = 6;
nx = 1; ny = 10;
ox = 1; oy = 8;
wx = 1; wy = 2;

}


if (einlegen == 2) {

applet.evalCommand("n = "+String(zaehler[5]));
applet.evalCommand("i_1 = "+String(nenner[5]));

applet.evalCommand("l_1 = "+String(zaehler[3]));
applet.evalCommand("m_1 = "+String(nenner[3]));

applet.evalCommand("n_1 = "+String(zaehler[1]));
applet.evalCommand("o_1 = "+String(nenner[1]));

applet.evalCommand("s_1 = "+String(zaehler[6]));
applet.evalCommand("t_1 = "+String(nenner[6]));

applet.evalCommand("a_2 = "+String(zaehler[2]));
applet.evalCommand("b_2 = "+String(nenner[2]));

applet.evalCommand("c_2 = "+String(zaehler[4]));
applet.evalCommand("d_2 = "+String(nenner[4]));




ax = 1; ay = 8;
lx = 1; ly = 4;
mx = 1; my = 0;
nx = 1; ny = 10;
ox = 1; oy = 2;
wx = 1; wy = 6;}


if (einlegen == 3) {


applet.evalCommand("n = "+String(zaehler[3]));
applet.evalCommand("i_1 = "+String(nenner[3]));

applet.evalCommand("l_1 = "+String(zaehler[2]));
applet.evalCommand("m_1 = "+String(nenner[2]));

applet.evalCommand("n_1 = "+String(zaehler[4]));
applet.evalCommand("o_1 = "+String(nenner[4]));

applet.evalCommand("s_1 = "+String(zaehler[1]));
applet.evalCommand("t_1 = "+String(nenner[1]));

applet.evalCommand("a_2 = "+String(zaehler[6]));
applet.evalCommand("b_2 = "+String(nenner[6]));

applet.evalCommand("c_2 = "+String(zaehler[5]));
applet.evalCommand("d_2 = "+String(nenner[5]));

ax = 1; ay = 4;
lx = 1; ly = 2;
mx = 1; my = 6;
nx = 1; ny = 0;
ox = 1; oy = 10;
wx = 1; wy = 8;}

if (einlegen == 4) {


applet.evalCommand("n = "+String(zaehler[5]));
applet.evalCommand("i_1 = "+String(nenner[5]));

applet.evalCommand("l_1 = "+String(zaehler[6]));
applet.evalCommand("m_1 = "+String(nenner[6]));

applet.evalCommand("n_1 = "+String(zaehler[2]));
applet.evalCommand("o_1 = "+String(nenner[2]));

applet.evalCommand("s_1 = "+String(zaehler[1]));
applet.evalCommand("t_1 = "+String(nenner[1]));

applet.evalCommand("a_2 = "+String(zaehler[3]));
applet.evalCommand("b_2 = "+String(nenner[3]));

applet.evalCommand("c_2 = "+String(zaehler[4]));
applet.evalCommand("d_2 = "+String(nenner[4]));


ax = 1; ay = 8;
lx = 1; ly = 10;
mx = 1; my = 2;
nx = 1; ny = 0;
ox = 1; oy = 4;
wx = 1; wy = 6;}


}


function schreibe()
     {

geloest = 0;
reset();
neueAufgabe();
document.Para.vx.value = "Ziehe den linken Pfeil an die richtige Stelle!";
pfeila =0;pfeill =0; pfeilm =0; pfeiln =0; pfeilo =0; pfeilw =0;
}

function pruefe()
{

applet = document.applets[0];

var yA = applet.getYcoord("A");
var yL = applet.getYcoord("L");
var yM= applet.getYcoord("M");
var yN = applet.getYcoord("N");
var yO = applet.getYcoord("O");
var yW = applet.getYcoord("W");
var xA = applet.getXcoord("A");
var xL = applet.getXcoord("L");
var xM= applet.getXcoord("M");
var xN = applet.getXcoord("N");
var xO = applet.getXcoord("O");
var xW = applet.getXcoord("W");
// alert(" A: "+ay+"|"+yA+" L: "+ly+"|"+yL+" M: "+my+"|"+yM+" N: "+ny+"|"+yN+" O: "+oy+"|"+yO+" W: "+wy+"|"+yW+"\n"+
// "Zahl1: "+zahl[1]+" zaehler1: "+zaehler[1]+" nenner1: "+nenner[1]+"\n"+
// "Zahl2: "+zahl[2]+" zaehler2: "+zaehler[2]+" nenner2: "+nenner[2]+"\n"+
// "Zahl3: "+zahl[3]+" zaehler3: "+zaehler[3]+" nenner3: "+nenner[3]+"\n"+
//"Zahl4: "+zahl[4]+" zaehler4: "+zaehler[4]+" nenner4: "+nenner[4]+"\n"+
// "Zahl5: "+zahl[5]+" zaehler5: "+zaehler[5]+" nenner5: "+nenner[5]+"\n"+
// "Zahl6: "+zahl[6]+" zaehler6: "+zaehler[6]+" nenner6: "+nenner[6]+"\n");


if (geloest ==0) {

if (ay == yA && xA == 1) {
    if (pfeila == 0) score = score + 15;
    pfeila = 1;
    applet.setVisible("A", false);}
else {
pfeila = 0; score = score - 10; if (score <0) score = 0;
applet.evalCommand("A = (-3,10)");
}

if (ly == yL && xL == 1) {
    if (pfeill == 0) score = score + 15;
    pfeill = 1;
    applet.setVisible("L", false);}
else {
pfeill = 0; score = score - 10; if (score <0) score = 0;
applet.evalCommand("L = (-3,8)");
}

if (my == yM && xM == 1) {
    if (pfeilm == 0) score = score + 15;
    pfeilm = 1;
    applet.setVisible("M", false);}
else {
pfeilm = 0; score = score - 10; if (score <0) score = 0;
applet.evalCommand("M = (-3,6)");
}

if (ny == yN && xN == 1) {
    if (pfeiln == 0) score = score + 15;
    pfeiln = 1;
    applet.setVisible("N", false);}
else {
pfeiln = 0; score = score - 10; if (score <0) score = 0;
applet.evalCommand("N = (-3,4)");
}

if (oy == yO && xO == 1) {
    if (pfeilo == 0) score = score + 15;
    pfeilo = 1;
    applet.setVisible("O", false);}
else {
pfeilo = 0; score = score - 10; if (score <0) score = 0;
applet.evalCommand("O = (-3,2)");
}

if (wy == yW && xW == 1) {
    if (pfeilw == 0) score = score + 15;
    pfeilw = 1; applet.setVisible("W", false);}
else {
pfeilw = 0; score = score - 10; if (score <0) score = 0;
applet.evalCommand("W = (-3,0)");
}


if (pfeila == 1 && pfeill == 1 && pfeilm == 1 &&
    pfeiln == 1 && pfeilo == 1 && pfeilw == 1)

{geloest =1;
loestext1 = "Ausgezeichnet! \nAlle Zahlen richtig geordnet!";
score = score + 20;
}
else loestext1 = "Nicht alle Zahlen sind richtig! \nVerbessere deine Anordnung!";
}
else
{
loestext1 = "Die Aufgabe war schon gelöst! \nSchwindeln geht nicht!";
score = score - 15; if (score <0) score = 0;
}



ausgabe = loestext1;
ausgabe = ausgabe+"\n Aktueller Stand: "+String(score)+" Punkte.";
document.Para.wertung.value = ausgabe;
}

function auswerten() {

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


score =0;
geloest =1;
document.Para.vx.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="Bruchzahlen ordnen (Profi)";
var datnam= "highsqlpost67ww.php";
uebertrag = "<form name = 'eingabe' action ='../../../Mathematik/"+datnam+"' method ='post'>";
auswertung(aufgabenart,punkte,uebertrag);
/*                     Ende                           */
}


