// arrangedecimals.js
// created 10/05/07
// changed 10/05/07
// author: Andreas Meier, Weiden i.d.OPf.
// all rights reserved

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.xt1.value ="";
document.Para.wertung.value ="";
applet = document.applets[0];
applet.evalCommand("A = (-2,10)");
applet.evalCommand("L = (-2,9)");
applet.evalCommand("M = (-2,8)");
applet.evalCommand("N = (-2,7)");
applet.evalCommand("O = (-2,6)");
applet.evalCommand("W = (-2,5)");
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 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;

startzahl = Math.pow(10,zufall(4,6))+zufall(1,11)*Math.pow(10,zufall(2,3))+zufall(0,9);
divisor = Math.pow(10,zufall(1,2));

for (i = 1; i<7 ; i++) {
        vorzeichen = zufall(1,2);
        zahl[i] = zufall(2,20);
        if (vorzeichen == 1) zahl[i] = (startzahl - zahl[i])/divisor;
        else zahl[i] = (startzahl + zahl[i])/divisor;
}
for (i = 1; i<7; i++){
for (j =i+1; j<7;j++){
if (zahl[i] == zahl[j]) zahl [j] = zahl[j]+(zufall(1,3)*zufall(1,25))/10;
}
}

// Sortieren

        for (i = 1; i<=6; i++) {
                for (j = 6; j>=i; j--) {
                        if (zahl[j-1]>zahl[j]) {
                                x = zahl[j-1];
                                zahl[j-1] = zahl[j];
                                zahl[j] = x;
                        }
                }
        }

// ende Sortieren

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

applet.evalCommand("n = "+String(zahl[1]));
applet.evalCommand("i_1 = "+String(zahl[3]));
applet.evalCommand("l_1 = "+String(zahl[4]));
applet.evalCommand("m_1 = "+String(zahl[6]));
applet.evalCommand("n_1 = "+String(zahl[5]));
applet.evalCommand("o_1 = "+String(zahl[2]));
ax = 4; ay = 5;
lx = 4; ly = 7;
mx = 4; my = 8;
nx = 4; ny = 10;
ox = 4; oy = 9;
wx = 4; wy = 6;

}


if (einlegen == 2) {

applet.evalCommand("n = "+String(zahl[5]));
applet.evalCommand("i_1 = "+String(zahl[3]));
applet.evalCommand("l_1 = "+String(zahl[1]));
applet.evalCommand("m_1 = "+String(zahl[6]));
applet.evalCommand("n_1 = "+String(zahl[2]));
applet.evalCommand("o_1 = "+String(zahl[4]));
ax = 4; ay = 9;
lx = 4; ly = 7;
mx = 4; my = 5;
nx = 4; ny = 10;
ox = 4; oy = 6;
wx = 4; wy = 8;}


if (einlegen == 3) {

applet.evalCommand("n = "+String(zahl[3]));
applet.evalCommand("i_1 = "+String(zahl[2]));
applet.evalCommand("l_1 = "+String(zahl[4]));
applet.evalCommand("m_1 = "+String(zahl[1]));
applet.evalCommand("n_1 = "+String(zahl[6]));
applet.evalCommand("o_1 = "+String(zahl[5]));
ax = 4; ay = 7;
lx = 4; ly = 6;
mx = 4; my = 8;
nx = 4; ny = 5;
ox = 4; oy = 10;
wx = 4; wy = 9;}

if (einlegen == 4) {

applet.evalCommand("n = "+String(zahl[5]));
applet.evalCommand("i_1 = "+String(zahl[6]));
applet.evalCommand("l_1 = "+String(zahl[2]));
applet.evalCommand("m_1 = "+String(zahl[1]));
applet.evalCommand("n_1 = "+String(zahl[3]));
applet.evalCommand("o_1 = "+String(zahl[4]));
ax = 4; ay = 9;
lx = 4; ly = 10;
mx = 4; my = 6;
nx = 4; ny = 5;
ox = 4; oy = 7;
wx = 4; wy = 8;}


}


function schreibe()
     {

geloest = 0;
reset();
neueAufgabe();
document.Para.vx.value = "Pull the left arrow into the right position!";
document.Para.xt1.value ="I'm sure, you will do it right.";
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");




if (geloest ==0) {

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

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

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

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

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

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


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

{geloest =1;
loestext1 = "Congratulations! \nEverything's right!";
}
else loestext1 = "Almost correct! \nProove your arrangement once more!";
}
else
{
loestext1 = "You've solved it before! \n Don't cheat!";
score = score - 15; if (score <0) score = 0;
}



ausgabe = loestext1;
ausgabe = ausgabe+"\n Current score: "+String(score)+" points.";
document.Para.wertung.value = ausgabe;
}


/*     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=620,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="arrange decimals";
var punkte = score;
if (punkte < 1) punkte = 1;
// Zurücksetzen der Punkte auf Ausgangswert


score =0;
geloest =1;
document.Para.vx.value ="";
document.Para.xt1.value ="";

text1 ="";
text2 ="Your score is now being submitted. \n";
text3 ="That's why your score has to be deleted here. \n";
text4="So you start at 0 points again.";
text5="";
text = text1+text2+text3+text4+text5;
document.Para.wertung.value = text;

/* 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/ehighsqlpost67w.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><P><H3><font color=#0000EC>Enter your score</font></H3> <P>"

ergebnisse += "Lesson:";
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>You have scored <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 += " points.<br><br>";


   ergebnisse += "It's up to you to write a nickname.<br>";
   ergebnisse += "Then you can send your highscore.<br>";
   ergebnisse += "<br>";
   ergebnisse += "<font color= #0000cc>Example: &nbsp;&nbsp;&nbsp;<b>Sandra from Florida</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>country</b></font></td>";
   ergebnisse += "<td align = center><font color= #0000cc><b>school</b></font></td>";
   ergebnisse += "<td align = center><font color= #0000cc><b>grade</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 > select ...";
ergebnisse += "<option value =1> Africa";
ergebnisse += "<option value =2> Argentina";
ergebnisse += "<option value =3> Australia";
ergebnisse += "<option value =4> Austria";
ergebnisse += "<option value =5> Belgium";
ergebnisse += "<option value =6> Bolivia";
ergebnisse += "<option value =7> Brazil";
ergebnisse += "<option value =8> Bulgaria";
ergebnisse += "<option value =9> Canada";
ergebnisse += "<option value =10> Central America";

ergebnisse += "<option value =11> Chile";
ergebnisse += "<option value =12> China";
ergebnisse += "<option value =13> Colombia";
ergebnisse += "<option value =14> Croatia";
ergebnisse += "<option value =15> Czech Republic";
ergebnisse += "<option value =16> Denmark";
ergebnisse += "<option value =17> Ecuador";
ergebnisse += "<option value =18> Estonia";
ergebnisse += "<option value =19> Finland";
ergebnisse += "<option value =20> France";

ergebnisse += "<option value =21> Germany";
ergebnisse += "<option value =22> Greece";
ergebnisse += "<option value =23> Hungary";
ergebnisse += "<option value =24> India";
ergebnisse += "<option value =25> Indonesia";
ergebnisse += "<option value =26> Ireland";
ergebnisse += "<option value =27> Israel";
ergebnisse += "<option value =28> Italy";
ergebnisse += "<option value =29> Finland";
ergebnisse += "<option value =30> Japan";

ergebnisse += "<option value =31> Korea";
ergebnisse += "<option value =32> Luxembourg";
ergebnisse += "<option value =33> Malaysia";
ergebnisse += "<option value =34> Mexico";
ergebnisse += "<option value =35> Middle East";
ergebnisse += "<option value =36> Netherlands";
ergebnisse += "<option value =37> New Zealand";
ergebnisse += "<option value =38> Norway";
ergebnisse += "<option value =39> Paraguay";
ergebnisse += "<option value =40> Peru";

ergebnisse += "<option value =41> Philippines";
ergebnisse += "<option value =42> Poland";
ergebnisse += "<option value =43> Portugal";
ergebnisse += "<option value =44> Puerto Rico";
ergebnisse += "<option value =45> Romania";
ergebnisse += "<option value =46> Russia";
ergebnisse += "<option value =47> Singapore";
ergebnisse += "<option value =48> Slovak Republic";
ergebnisse += "<option value =49> Spain";
ergebnisse += "<option value =50> Sweden";

ergebnisse += "<option value =51> Taiwan";
ergebnisse += "<option value =52> Thailand";
ergebnisse += "<option value =53> Turkey";
ergebnisse += "<option value =54> Ukraine";
ergebnisse += "<option value =55> United Kingdom";
ergebnisse += "<option value =56> United States";
ergebnisse += "<option value =57> Uruguay";
ergebnisse += "<option value =58> Venezuela";
ergebnisse += "<option value =59> Other Country";
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 > select ...";
   ergebnisse += "<option value =1> Middle School";
   ergebnisse += "<option value =2> Junior High";
   ergebnisse += "<option value =3> Senior High";
   ergebnisse += "<option value =4> Comprehensive";
   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 > select ...";
   ergebnisse += "<option value =1>5th";
   ergebnisse += "<option value =2>6th";
   ergebnisse += "<option value =3>7th";
   ergebnisse += "<option value =4>8th";
   ergebnisse += "<option value =5>9th";
   ergebnisse += "<option value =6>10th";
   ergebnisse += "<option value =7> --";
   ergebnisse += "</select></td></tr></table><br>";


   ergebnisse += "<br> <input type =submit value ='send your highscore'></form>";

   ergebnisse += werbestring1+werbestring2;

   messagewindow(ergebnisse,"Send to database"); /* überträgt den formatierten String */
                                           /*  in ein seperates Fenster        */

}
