switch.htm

<html>
<head>
    <title>The Switch</title>
<link rel="stylesheet" type="text/css" href="breaking.css" />
<script src="include.js" type="text/javascript"></script>
<script type="text/javascript">

      //These variables store a status value which indicates
      //which of the two users have agreed the switch.
       var strMyStatus = "";
       var strTheirStatus = "";

       function handleXMLTimerResponse() 
       {   
           parseXML(httpXMLTimer.responseXML);

       setTimeout("getSuggestions()",3000);
        }

   //This function goes through the XML and displays it
   function parseXML(xmlSwitch) 
   {
            //Get the root node (skipping past whitespace until we get to it, if necessary)
            var nodeRoot = xmlSwitch.firstChild;

            nodeRoot = getNextElementNode(nodeRoot);

            if (nodeRoot)
            {
                  var nodeCurrent = nodeRoot.firstChild;
                  
                  while (nodeCurrent)
                  {
                      switch (nodeCurrent.nodeName)
                      {
                      case "switch":
                          setSwitchFromXML(nodeCurrent);
                          break;
 
                      case "mystatus":
                          setMyStatusFromXML(nodeCurrent);
                          break;

                      case "theirstatus":
                          setTheirStatusFromXML(nodeCurrent);
                          break;

                      }
                      nodeCurrent = nodeCurrent.nextSibling;
                  }

                  setDisplayFromStatus();
             }
   }
 
   //Sets the suggestion for the switch itself
   function setSwitchFromXML(node)
   {
       var contents = getTextFromNode(node);

       document.getElementById('idSwitch').innerHTML = contents;
   }

   //Given the status of the two users, this
   //function updates the display (for example,
   //if the other user has agreed to the switch
   //but we haven't, it shows an "Agree" button to let us agree).
   function setDisplayFromStatus()
   {

       if (strMyStatus == "willing")
       {
           if (strTheirStatus == "willing")
           {
                top.location="colour.htm";
           }
           else
           {
                document.getElementById("idYouSuggested").style.display = "block";
                document.getElementById("idTheySuggested").style.display = "none";
                document.getElementById("buttonAgree").style.display = "none";
                document.getElementById("idWaiting").style.display = "block";
           }
       }
       else
       {
           if (strTheirStatus == "willing")
           {
                document.getElementById("idYouSuggested").style.display = "none";
                document.getElementById("idTheySuggested").style.display = "block";
                document.getElementById("buttonAgree").style.display = "block";
                document.getElementById("idWaiting").style.display = "none";
           }
           else
           {
                document.getElementById("idYouSuggested").style.display = "none";
                document.getElementById("idTheySuggested").style.display = "none";
                document.getElementById("buttonAgree").style.display = "none";
                document.getElementById("idWaiting").style.display = "none";
           }
       }

   }

   function setMyStatusFromXML(node)
   {
       strMyStatus = getTextFromNode(node);
   }

   function setTheirStatusFromXML(node)
   {
       strTheirStatus = getTextFromNode(node);
   }
       
        
        function getSuggestions() 
        {    
            doHttpRequest(httpXMLTimer, handleXMLTimerResponse, "getswitch.php", "POST");
        }
       
        function suggest() 
    {    
        var sSuggestion = document.getElementById("txtSuggestion").value;
        var urlPostWithParameters = "putswitch.php?suggestion=" + sSuggestion; 
            doHttpRequest(httpXMLUser, emptyFunction, urlPostWithParameters, "POST");
        }

        function agree() 
        {   
        var urlPostWithParameters = "agreeswitch.php"; 

            doHttpRequest(httpXMLUser, emptyFunction, urlPostWithParameters, "POST");
        }

        function handleReturn()
        {
            suggest();
        }

        setTimeout("getSuggestions()",3000);

</script>
</head>
<body>
        <h1>The Switch</h1>
    <p class="intro">Talk to your partner and decide one way in which you are different.</p>
    <p>Your characters will be different in the same way, but the other way round: your character will be like your partner and your partner's character will be like you.</p>
    <p>How are the two of you different?</p>
 <input type="text" id="txtSuggestion" onKeyPress="handleKeyPress(event, handleReturn)"/></p>
    <p><input type="button" value="Suggest" onclick="suggest()" /></p>
    <p><i><span id="idYouSuggested" style="display:none">You suggested: </span><span id="idTheySuggested" style="display:none">Your partner suggested: </span><span id="idSwitch"></span></i></p>
    <p><i><span id="idWaiting" style="display:none">Waiting for your partner to respond...</span></i></p>
    <p><INPUT ID="buttonAgree" TYPE="button" VALUE="Agree" onclick="agree()" style="display: none" /></p>
</body>
</html>