// addisubibaum2.js
// (c) Andreas Meier
// Sophie-Scholl-Realschule Weiden
// erstellt am 03.02. 2008
// geändert am 03.02. 2008
// alle Rechte liegen beim Autor


var geloest= 0;
var versuch= 0;
var score =0;
var item = 0;


function zufall(min, max, ohne) {
  var zufallszahl;
  do {
  zufallszahl = Math.round(min + Math.random() * (max - min));
  } while (zufallszahl == ohne);
  return zufallszahl;
}

function reset() {
applet = document.applets[0];
applet.setVisible("text1", false);
applet.setVisible("text2", false);
applet.setVisible("text3", false);
applet.setVisible("text4", false);
applet.setVisible("text9", false);
applet.setVisible("text10", false);
applet.setVisible("text11", false);
applet.setVisible("text12", false);
applet.setVisible("text13", false);
applet.setVisible("text14", false);
applet.setVisible("text15", false);
applet.setVisible("text16", false);
applet.setVisible("text17", false);
applet.setVisible("text80", false);
applet.setVisible("text81", false);
applet.setVisible("text82", false);
}



function neueAufgabe() {
reset();
item++;
geloest = 0;
document.Para.loesung1.value ="";
document.Para.loesung2.value ="";
document.Para.loesung3.value ="";
document.Para.wertung.value ="";

zufallsteiler = zufall(1,2);

bzahl1 = zufall(30,850);
bzahl2 = zufall(20,500,bzahl1)
bzahl3 = zufall(10,780);
bzahl4 = zufall(20,550,bzahl3);
if (bzahl1<bzahl2) {dummy = bzahl1; bzahl1 = bzahl2; bzahl2 = dummy;}
if (bzahl3<bzahl4) {dummy = bzahl3; bzahl3 = bzahl4; bzahl4 = dummy;}

if (zufallsteiler ==1) {
bzahl1 = Math.round(bzahl1/10*10)/10;
bzahl2 = Math.round(bzahl2/10*10)/10;
bzahl3 = Math.round(bzahl3/100*100)/100;
bzahl4 = Math.round(bzahl4/100*100)/100;
}

else {
bzahl1 = Math.round(bzahl1/100*100)/100;
bzahl2 = Math.round(bzahl2/100*100)/100;
bzahl3 = Math.round(bzahl3/10*10)/10;
bzahl4 = Math.round(bzahl4/10*10)/10;
}


rech1 = zufall(1,2);
rech2 = zufall(1,2,rech1);
rech3 = 1;

applet = document.applets[0];
applet.evalCommand("basiszahl1 = "+String(bzahl1));
applet.evalCommand("basiszahl2 = "+String(bzahl2));
applet.evalCommand("basiszahl3 = "+String(bzahl3));
applet.evalCommand("basiszahl4 = "+String(bzahl4));
applet.evalCommand("rechenart1 = "+String(rech1));
applet.evalCommand("rechenart2 = "+String(rech2));
applet.evalCommand("rechenart3 = "+String(rech3));

art = zufall(1,5);
if (art == 1) {
applet = document.applets[0];
applet.setVisible("text2", true);
applet.setVisible("text3", true);
applet.setVisible("text9", true);
applet.setVisible("text12", true);
applet.setVisible("text15", true);
applet.setVisible("text80", true);
applet.setVisible("text81", true);

loes3 = applet.getValue("zahl82");
loes1 = bzahl1;
loes2 = bzahl4;
}


if (art == 2) {

applet = document.applets[0];
applet.setVisible("text1", true);
applet.setVisible("text10", true);
applet.setVisible("text13", true);
applet.setVisible("text4", true);
applet.setVisible("text3", true);
applet.setVisible("text15", true);
applet.setVisible("text80", true);
loes3 = applet.getValue("zahl82");
loes2 = applet.getValue("zahl81");
loes1 = bzahl2;
}

if (art == 3) {

applet = document.applets[0];
applet.setVisible("text1", true);
applet.setVisible("text10", true);
applet.setVisible("text11", true);
applet.setVisible("text4", true);
applet.setVisible("text81", true);
applet.setVisible("text82", true);
applet.setVisible("text17", true);
loes3 = applet.getValue("zahl80");
loes2 = bzahl3;
loes1 = bzahl2;
}

if (art == 4) {
applet = document.applets[0];
applet.setVisible("text10", true);
applet.setVisible("text1", true);
applet.setVisible("text4", true);
applet.setVisible("text11", true);
applet.setVisible("text15", true);
applet.setVisible("text80", true);
applet.setVisible("text81", true);

loes3 = applet.getValue("zahl82");
loes1 = bzahl2;
loes2 = bzahl3;

}

if (art == 5) {

applet = document.applets[0];
applet.setVisible("text9", true);
applet.setVisible("text2", true);
applet.setVisible("text3", true);
applet.setVisible("text12", true);
applet.setVisible("text80", true);
applet.setVisible("text82", true);
applet.setVisible("text16", true);
loes3 = applet.getValue("zahl81");
loes2 = bzahl4;
loes1 = bzahl1;
}

loes1 = Math.round(loes1*1000)/1000;
loes2 = Math.round(loes2*1000)/1000;
loes3 = Math.round(loes3*1000)/1000;
document.Para.loesung1.focus();
}

function pruefe()
{
wert1 = 0;wert2 = 0;wert3 = 0;
 if (geloest == 0){

if (document.Para.loesung1.value != ""){
eloes = document.Para.loesung1.value.replace(",",".");
eloes1 =eval(eloes);
}
else eloes1=1000;

if (document.Para.loesung2.value != ""){
eloes = document.Para.loesung2.value.replace(",",".");
eloes2 =eval(eloes);
}
else eloes2=1000;

if (document.Para.loesung3.value != ""){
eloes = document.Para.loesung3.value.replace(",",".");
eloes3 =eval(eloes);
}
else eloes3=1000;

if (eloes1 == loes1){wert1 = 1;score = score +10;}
else {wert1 =0;score = score-10;if (score <0) score =0;}

if (eloes2 == loes2){wert2 = 1;score = score +10;}
else {wert2 =0;score = score-10;if (score <0) score =0;}

if (eloes3 == loes3){wert3 = 1;score = score +10;}
else {wert3 =0;score = score-10;if (score <0) score =0;}



if (wert1 == 1 && wert2 == 1 && wert3 ==1) {
document.Para.wertung.value = "Ausgezeichnet!\n"+
"Du hast alle Werte richtig bestimmt. ";
geloest =1;
}
else {
document.Para.wertung.value = "Leider ist nicht alles richtig!\n"+
"Richtig ist x = "+String(loes1).replace(".",",")+";  y = "+String(loes2).replace(".",",")+";  z = "+String(loes3).replace(".",",");
geloest =1;
}
  }
  else {
document.Para.wertung.value = "Die Aufgabe war schon gelöst!\n"+
"Die Zahlen waren: x = "+String(loes1).replace(".",",")+";  y = "+String(loes2).replace(".",",")+";  z = "+String(loes3).replace(".",",");
score = score -10; if (score <0) score =0;
 }

  document.Para.Punktestand.value = "Punktestand: "+String(score)+ " Punkte bei "+String(item)+" Aufgaben.";
}



/*     Highscore Eintrag vornehmen                                           */
/*                                                                           */
/*     Ausgabe-Fenster definieren und ausgeben                               */
/*                                                                           */
function messagewindow(message, title){
        msgWindow= open("rangliste.htm","msgwin","scrollbars=yes,toolbar=no,directories=no,menubar=no,width=800,height=530,location=no,status=no,resizable=yes");
     msgWindow.document.clear();
     msgWindow.document.open();

     msgWindow.document.writeln('<HTML><HEAD><TITLE>'+title+'</TITLE></HEAD><BODY TEXT="#000000" LINK="#0000FF" VLINK="#FF0000" ALINK="#0080FF" BGCOLOR="EFECA5">');
     msgWindow.document.writeln(message);
     msgWindow.document.writeln('</BODY></HTML>');

}

function auswerten() {

/* Achtung muss für jede Datei manuell angepasst werden */
/*                     Anfang                           */
var aufgabenart="Dezimalzahlen im Rechenbaum 2";
var punkte = score;
if (punkte < 1) punkte = 1;
// Zurücksetzen der Punkte auf Ausgangswert


geloest= 0;
vesuch= 0;
score = 0;
item = 0;
document.Para.wertung.value = "Deine Punkte werden übertragen.\n Du beginnst wieder bei 0 Punkten.";
document.Para.Punktestand.value = "Punktestand: "+String(score)+ " Punkte bei "+String(item)+" Aufgaben.";

/* Achtung muss für jede Datei manuell angepasst werden */
/*                        Ende                          */

   /* Hier wird das Ausgabe-fenster gefüllt und der HTML-Code geschrieben */
   /*                                                                    */
ergebnisse = "<form name = 'eingabe' action ='../../../Mathematik/highsqlpost617w.php' method ='post'>";

werbestring1="&nbsp;<img src='../../../bilder/anzeige1.gif' width='15' height='60' border='0' alt=''>";
werbestring2 = "<!-- ValueClick Media 468x60 and 728x90 Banner CODE for realmath.de -->"+
"<script language='javascript' src='http://media.fastclick.net/w/get.media?sid=41862&m=1&tp=5&d=j&t=s'></script>"+
"<noscript><a href='http://media.fastclick.net/w/click.here?sid=41862&m=1&c=1' target='_top'>"+
"<img src='http://media.fastclick.net/w/get.media?sid=41862&m=1&tp=5&d=s&c=1'"+
"width=728 height=90 border=1></a></noscript><!-- ValueClick Media 468x60 and 728x90 Banner CODE for realmath.de -->";

   ergebnisse += "<font face = 'arial, helvetica' size = 2>";
   ergebnisse += "<CENTER><H2><font color=#FF0000>Highscore</font></H2><H3><font color=#0000EC>Erreichte Punkte eintragen</font></H3>";

ergebnisse += "Du hast bei der Aufgabe<br>";
ergebnisse += "<input type= text size=35 maxlength=35 name='xx_aufgabenart' value ='"+ aufgabenart+"' style=' border: none; color: #dd0000; text-align: center; font-weight: bold; font-family: arial, helvetica; font-size: 15pt; background: #EFECA5' readonly> ";
ergebnisse += "<br>insgesamt <input type='text' size=6 maxlength=6 name=xx_punkte value = "+punkte+" style=' border: none; color: #dd0000; text-align: center; font-weight: bold; font-family: arial, helvetica; font-size: 15pt; background: #EFECA5' readonly> ";
ergebnisse += " Punkte erreicht.<br>";


   ergebnisse += "Die Eingabe der nachfolgenden Daten ist freiwillig.<br>";
   ergebnisse += "Anschließend kannst du deinen Highscore abschicken.<br>";
   ergebnisse += "Bitte keine Umlaute wie ü, ö oder ä verwenden.<br><br>";
   ergebnisse += "<font color= #0000cc>Beispiel: &nbsp;&nbsp;&nbsp;<b>Martina aus Koeln</b>&nbsp;<br></font>";
   ergebnisse += "<font color= #0000cc>Name:&nbsp;</font>";
   ergebnisse += "<input type= text  size= 35  maxlength= 38  name=xx_spieler style='border: 1px solid; border-color: #0000cc; color: #000095; text-align: left; font-weight: bold; font-family: arial, helvetica; font-size: 11pt; background: #ffffff'><br>";
   ergebnisse += "<br><table width = 60%><tr>";
   ergebnisse += "<td align = center><font color= #0000cc><b>Land</b></font></td>";
   ergebnisse += "<td align = center><font color= #0000cc><b>Schulart</b></font></td>";
   ergebnisse += "<td align = center><font color= #0000cc><b>Klasse</b></font></td>";
   ergebnisse += "</tr><tr>";

ergebnisse += "<td><select name= xx_land size=1 style='color: #000095; text-align: center; font-weight: bold; font-size: 10pt'>";
   ergebnisse += "<option value =0 > Bitte wählen ...";
   ergebnisse += "<option value =1> Deutschland";
   ergebnisse += "<option value =2> Österreich";
   ergebnisse += "<option value =3> Schweiz";
   ergebnisse += "<option value =4> anderes Land";
   ergebnisse += "</select></td>";

   ergebnisse += "<td><select name= xx_schulart size=1 style='color: #000095; text-align: center; font-weight: bold; font-size: 10pt'>";
ergebnisse += "<option value =0 > Bitte wählen ...";
   ergebnisse += "<option value =1> Realschule";
   ergebnisse += "<option value =2> Hauptschule";
   ergebnisse += "<option value =3> Gymnasium";
   ergebnisse += "<option value =4> Gesamtschule";
   ergebnisse += "<option value =5> -----";
   ergebnisse += "</select></td>";

   ergebnisse += "<td><select name= xx_klasse size= 1 style= 'color: #000095; text-align: center; font-weight: bold; font-size: 10pt'>";
   ergebnisse += "<option value =0 > Bitte wählen ...";
   ergebnisse += "<option value =1> 5";
   ergebnisse += "<option value =2> 6";
   ergebnisse += "<option value =3> 7";
   ergebnisse += "<option value =4> 8";
   ergebnisse += "<option value =5> 9";
   ergebnisse += "<option value =6> 10";
   ergebnisse += "<option value =7> --";
   ergebnisse += "</select></td></tr></table><br>";


   ergebnisse += "<input type =submit value ='Highscore abschicken'></form><br>";

ergebnisse += werbestring1+werbestring2;



   messagewindow(ergebnisse,"Highscore in Datenbank eintragen"); /* überträgt den formatierten String */
                                           /*  in ein seperates Fenster        */

}