<?php
    if (!empty ($_GET))
    {
/*        if (isset $_GET["this"])
        {
            echo $_GET["this"];
        }
        else
        {
*/            echo "<PRE>";
            var_dump ($_GET);
            echo "</PRE>";
/*        }
*/        
        exit;
    }
?>

<HTML>
<HEAD>
<TITLE>Harry's Maths 2</TITLE>

<SCRIPT LANGUAGE="JavaScript">

var DigitImage = new Array ();

DigitImage[0] = "zero";
DigitImage[1] = "one";
DigitImage[2] = "two";
DigitImage[3] = "three";
DigitImage[4] = "four";
DigitImage[5] = "five";
DigitImage[6] = "six";
DigitImage[7] = "seven";
DigitImage[8] = "eight";
DigitImage[9] = "nine";
DigitImage[10] = "empty";

function GetNewSum()
{
    var FirstDigitImageLeft  = document.getElementById ("FirstDigitLeft");
    var FirstDigitImageRight  = document.getElementById ("FirstDigitRight");
    var SecondDigitImageLeft = document.getElementById ("SecondDigitLeft");
    var SecondDigitImageRight = document.getElementById ("SecondDigitRight");
    var OperatorPlace = document.getElementById ("Operator");
    var AnswerPlaceLeft = document.getElementById ("AnswerLeft");
    var AnswerPlaceRight = document.getElementById ("AnswerRight");
    var CheckAnswer = document.getElementById ("CheckAnswer");
    
    var FirstDigitLeft;
    var FirstDigitRight;
    
    var SecondDigitLeft;
    var SecondDigitRight;

    do
    {
        var FirstDigit  = Math.floor (Math.random()*100);
        var SecondDigit = Math.floor (Math.random()*100);
        var OperatorIndex = Math.floor (Math.random()*4);
        var Result = 0;
    
        switch (OperatorIndex)
        {
            case 0: /* '+' */
                Result = parseInt (FirstDigit) + parseInt (SecondDigit);
            break;

            case 1: /* '-' */
                Result = parseInt (FirstDigit) - parseInt (SecondDigit);
            break;

            case 2: /* '*' */
                Result = parseInt (FirstDigit) * parseInt (SecondDigit);
            break;

            case 3: /* '/' */
                Result = parseInt (FirstDigit) / parseInt (SecondDigit);
            break;

            default:
        }
    }
    while (Result <= 0 || Result >= 100 || Result != parseInt (Result)) 
    
    FirstDigitLeft  = parseInt (FirstDigit)/10;
    FirstDigitRight  = parseInt (FirstDigit) - (10 * parseInt (FirstDigitLeft));
    
    SecondDigitLeft  = parseInt (SecondDigit)/10;
    SecondDigitRight  = parseInt (SecondDigit) - (10 * parseInt (SecondDigitLeft));
  
    if (parseInt (FirstDigitLeft) == 0)
    {
        FirstDigitImageLeft.src = 'empty.png';
    }
    else
    {
        FirstDigitImageLeft.src = DigitImage[parseInt (FirstDigitLeft)] + '.png';
    }

    FirstDigitImageLeft.alt = FirstDigitLeft;
    
    FirstDigitImageRight.src = DigitImage[parseInt (FirstDigitRight)] + '.png';    
    FirstDigitImageRight.alt = FirstDigitRight;
    
    switch (OperatorIndex)
    {
        case 0:
            OperatorPlace.src = 'plus.png';
            OperatorPlace.alt = '+';
        break;

        case 1:
            OperatorPlace.src = 'minus.png';
            OperatorPlace.alt = '-';
        break;

        case 2:
            OperatorPlace.src = 'times.png';
            OperatorPlace.alt = '*';
        break;

        case 3:
            OperatorPlace.src = 'divide.png';
            OperatorPlace.alt = '/';
        break;
        
        default:
    }

    if (parseInt (SecondDigitLeft) == 0)
    {
        SecondDigitImageLeft.src = 'empty.png';
    }
    else
    {
        SecondDigitImageLeft.src = DigitImage[parseInt (SecondDigitLeft)] + '.png';
    }

    SecondDigitImageRight.src = DigitImage[parseInt (SecondDigitRight)] + '.png';
    SecondDigitImageLeft.alt = SecondDigitLeft;
    SecondDigitImageRight.alt = SecondDigitRight;
    
    AnswerPlaceLeft.src      = "question.png";
    AnswerPlaceLeft.alt      = "?";
    AnswerPlaceRight.src     = "empty.png";
    AnswerPlaceRight.alt      = "";
    
    CheckAnswer.src = "CheckAnswer.png";
}

function SetAnswer (digit)
{
    var AnswerPlaceLeft = document.getElementById ("AnswerLeft");
    var AnswerPlaceRight = document.getElementById ("AnswerRight");
    var CheckAnswer = document.getElementById ("CheckAnswer");
    
//    alert ("AnswerPlaceLeft.alt=" + AnswerPlaceLeft.alt + ", AnswerPlaceRight.alt=" + AnswerPlaceRight.alt);
    
    if (AnswerPlaceRight.alt == "?")
    {
        AnswerPlaceRight.src = DigitImage[digit] + '.png';
        AnswerPlaceRight.alt = digit;
    }
    else
    {
        AnswerPlaceLeft.src = DigitImage[digit] + '.png';
        AnswerPlaceLeft.alt = digit;
        AnswerPlaceRight.src = "empty.png";
        AnswerPlaceRight.alt = "?";
    }
    
    CheckAnswer.src = "CheckAnswer.png";
    
}

function CheckTheAnswer ()
{
    var FirstDigitLeft   = document.getElementById ("FirstDigitLeft").alt;
    var FirstDigitRight  = document.getElementById ("FirstDigitRight").alt;
    var Operator         = document.getElementById ("Operator").alt;
    var SecondDigitLeft  = document.getElementById ("SecondDigitLeft").alt;
    var SecondDigitRight = document.getElementById ("SecondDigitRight").alt;
    var Equals           = document.getElementById ("Equals").alt;
    var AnswerLeft       = document.getElementById ("AnswerLeft").alt;
    var AnswerRight      = document.getElementById ("AnswerRight").alt;
    var TotalRight       = document.getElementById ("TotalRight");
    var TotalLeft        = document.getElementById ("TotalLeft");
    var TotalTries       = document.getElementById ("TotalTries");
    
    var CheckAnswerID    = document.getElementById ("CheckAnswer");
    
    var FirstNumber      = (parseInt (FirstDigitLeft)*10) + parseInt (FirstDigitRight);
    var SecondNumber     = (parseInt (SecondDigitLeft)*10) + parseInt (SecondDigitRight);
    var Answer;
    
    if (AnswerRight == "?")
    {
        Answer = parseInt (AnswerLeft);
    }
    else
    {
        Answer = (parseInt (AnswerLeft)*10) + parseInt (AnswerRight);
    }
    
    switch (Operator)
    {
        case '+':
            Result = parseInt (FirstNumber) + parseInt (SecondNumber);
        break;

        case '-':
            Result = parseInt (FirstNumber) - parseInt (SecondNumber);
        break;

        case '*':
            Result = parseInt (FirstNumber) * parseInt (SecondNumber);
        break;

        case '/':
            Result = parseInt (FirstNumber) / parseInt (SecondNumber);
        break;
    }
    
//    alert ("FirstNumber=" + parseInt(FirstNumber) + ", SecondNumber=" + parseInt(SecondNumber) + ", Result=" + parseInt(Result) + ", Answer=" + parseInt(Answer));
    
    if (parseInt (Result) == parseInt (Answer))
    {
        CheckAnswerID.src = "Correct.png";
        
        TotalRight.innerHTML = parseInt (TotalRight.innerHTML) + 1;
        
        setTimeout ("GetNewSum()", 1500);
    }
    else
    {
        CheckAnswerID.src = "Incorrect.png";
    }
    
    TotalTries.innerHTML = parseInt (TotalTries.innerHTML) + 1;
    
    TotalLeft.innerHTML = (((parseInt (TotalTries.innerHTML) - parseInt (TotalRight.innerHTML)) * 10) + 20) - parseInt (TotalTries.innerHTML);
    
    if (parseInt (TotalLeft.innerHTML) == 0)
    {
        document.location = "success2.html";
    }
}

function ajaxRequest (Request)
{
	var ajaxRequester;
    var VariableString = document.getElementById (Request).value;
	
	try
    {
		// Opera 8.0+, Firefox, Safari
		ajaxRequester = new XMLHttpRequest();
	}
    catch (e)
    {
		// Internet Explorer Browsers
		try
        {
			ajaxRequester = new ActiveXObject("Msxml2.XMLHTTP");
		}
        catch (e)
        {
			try
            {
				ajaxRequester = new ActiveXObject("Microsoft.XMLHTTP");
			}
            catch (e)
            {
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}

	// Create a function that will receive data sent from the server
	ajaxRequester.onreadystatechange = function()
    {
		if(ajaxRequester.readyState == 4)
        {
			alert (ajaxRequester.responseText);
		}
	}
    
	ajaxRequester.open ("GET", "harrymaths.php?" + VariableString, true);
	ajaxRequester.send (null); 
}
//-->

</SCRIPT>

</HEAD>

<BODY BGCOLOR="#FFF700" ONLOAD="GetNewSum()">

<CENTER>
<IMG STYLE="border:0" SRC="HarrysMaths2.png"><BR>
<SMALL>
You need to get 20 right out of 20.<BR>
If you get one wrong you need to do another 10 right to make up.<BR>
</SMALL>

<FONT SIZE="+2">So far you have got <SPAN ID="TotalRight">0</SPAN> right out of <SPAN ID="TotalTries">0</SPAN> tries, <SPAN ID="TotalLeft">20</SPAN> left.</FONT><BR>
<BR>
<TABLE CELLSPACING=0 CELLPADDING=20 BGCOLOR="black">
<TR VALIGN="middle">
<TD ALIGN="center"><IMG ID="FirstDigitLeft"   SRC="empty.png"             ALT=""><IMG ID="FirstDigitRight"  SRC="empty.png"             ALT=""></TD>
<TD ALIGN="center"><IMG ID="Operator"         SRC="empty.png"             ALT=""></TD>
<TD ALIGN="center"><IMG ID="SecondDigitLeft"  SRC="empty.png"             ALT=""><IMG ID="SecondDigitRight" SRC="empty.png"             ALT=""></TD>
<TD ALIGN="center"><IMG ID="Equals"           SRC="equals.png"            ALT="="></TD>
<TD ALIGN="center"><IMG ID="AnswerLeft"       SRC="question.png"          ALT="?"><IMG ID="AnswerRight"     SRC="empty.png"             ALT=""></TD>
</TR>
</TABLE>

<BR>
<FONT SIZE="+2">Click on the number you think is the answer.</FONT><BR>
<SMALL>If you put in the first number wrong you need to put in a second number then try again.</SMALL><BR><BR>

<TABLE CELLSPACING=0 CELLPADDING=10 BGCOLOR="black">

<TR VALIGN="middle">
<TD ALIGN="center"><IMG SRC="one.png"   ONCLICK='SetAnswer("1")'></TD>
<TD ALIGN="center"><IMG SRC="two.png"   ONCLICK='SetAnswer("2")'></TD>
<TD ALIGN="center"><IMG SRC="three.png" ONCLICK='SetAnswer("3")'></TD>
<TD ALIGN="center"><IMG SRC="four.png"  ONCLICK='SetAnswer("4")'></TD>
<TD ALIGN="center"><IMG SRC="five.png"  ONCLICK='SetAnswer("5")'></TD>
</TR>

<TR VALIGN="middle">
<TD ALIGN="center"><IMG SRC="six.png"   ONCLICK='SetAnswer("6")'></TD>
<TD ALIGN="center"><IMG SRC="seven.png" ONCLICK='SetAnswer("7")'></TD>
<TD ALIGN="center"><IMG SRC="eight.png" ONCLICK='SetAnswer("8")'></TD>
<TD ALIGN="center"><IMG SRC="nine.png"  ONCLICK='SetAnswer("9")'></TD>
<TD ALIGN="center"><IMG SRC="zero.png"  ONCLICK='SetAnswer("0")'></TD>
</TR>

</TABLE>

<BR>

<IMG ID="CheckAnswer" SRC="CheckAnswer.png" ONCLICK='CheckTheAnswer()'>

<!--
<BR>
Name: <INPUT TYPE="text"   ID="VariableString" />
Time: <INPUT TYPE="button" NAME="Send" VALUE="Send Request" ONCLICK="ajaxRequest('VariableString')" />
-->


<DIV STYLE="border: 0pt none; text-align: right; position: fixed; bottom: 0pt; right: 0pt;">
 <A TITLE="Edit this page (requires logon)" HREF=# ONCLICK="window.open(&quot;/editor/texteditor.php?Filename=//learning/harrymaths2.php&quot;); return false;">
  <IMG STYLE="border: 0pt none ;" SRC="/ultimatewiki/editicon2.png">
 </A>
</DIV>

</BODY>
</HTML>
