// Clever. Ok well here you go- won't really help you much though.


var x=0;


var consolePrompt='<div id="consoleContainer"><label for="console">&#62;:</label><input id="console" autocomplete="off" onKeyDown="return checkExecute(event)" onChange="checkster(this.value)" maxlength="50"/></div><div id="newDiv"></div>';


var clockDiv='<div id="clock" style="position:absolute; top:0px; right:0px;"><div id="minutes" style="text-align:right;"></div><div id="seconds" style="text-align:right;"></div></div>';


var message='';


var lastInput='4 8 15 16 23 42';


var repeat=0;


var soundManager = null;





document.write('<head><style>body{background:rgb(0,0,0); color:rgb(0,255,10); font-family:"OCR A EXTENDED"; font-size:1.2em;} input{padding:0px; margin:0px; background:rgb(0,0,0); color:rgb(0,255,10); border:0px; width:80%; font-size:1em;font-family:"OCR A EXTENDED";} a{color:rgb(0,255,10);}</style>');


document.write('</head><body id="bigBody" onMousedown="refocus();" onLoad="refocus();" style="cursor:auto;" scroll="auto"><div></div>'+clockDiv+consolePrompt+'</body>');


setClock();


soundManager = new SoundManager();





function refocus(){


  if(document.getElementById("console")){ //only if valid id


    setTimeout('document.getElementById("console").focus()',10); //timeout so explorer works


  }


}


function checkExecute(e){


  var keynum


  var keychar


  if(window.event){ //IE


    keynum = e.keyCode


  }else if(e.which){ // Netscape/Firefox/Opera


    keynum = e.which


  }


  if(keynum==13){//enter


    checkster(document.getElementById("console").value);


  }


  if(keynum==38){//up arrow


    document.getElementById("console").value=lastInput;


    refocus();


    return false;


  }


}





function standby(){


  document.getElementById("newDiv").innerHTML='[processing]';


}








function sendInput(consoleInput){ //Ajax interface


          try {// XMLHttpRequest tester


          xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 


          } 


          catch (e) {


            document.getElementById("bigBody").innerHTML="This console is non-funcitonal, please upgrade or repair it. (xmlHTTPrequest required)";


          }


          standby();


          sReplace=consoleInput.replace(/(<([^>]+)>)/ig,"");


          sReplace=consoleInput.replace(/(<([^>]+)>)/ig,"");


          document.getElementById("consoleContainer").innerHTML="&#62;:"+sReplace; //break input


          xmlhttp.onreadystatechange = triggered;


          xmlhttp.open("POST","MrMustard.php",true); // query Mr Mustard


          xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');


          xmlhttp.send('i='+consoleInput+'&r='+repeat); //Send post variables


          function triggered() { //state change


            if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { //Done loading and it's all good


              document.getElementById("consoleContainer").innerHTML+="<br/>"+xmlhttp.responseText; // attach a result from php


              document.getElementById("newDiv").id="oldDiv"+x; //change ID to avoid conflict


              document.getElementById("consoleContainer").id="oldCont"+x; //ditto


              document.getElementById("oldDiv"+x).innerHTML=consolePrompt; //get a new prompt


              refocus();


              if(xmlhttp.responseText=="3 mins"){


              minutes=3;


              seconds=1;


              }


              if(xmlhttp.responseText=="1 mins"){


              minutes=1;


              seconds=1;


              


              }


              if(xmlhttp.responseText=="0 mins"){


              minutes=0;


              seconds=5;


              }             


              if(xmlhttp.responseText=="exit"){


              document.getElementById("bigBody").innerHTML='';


              window.open('','_parent','');


              window.close();}


              if(xmlhttp.responseText=="Sequence Accepted"){


              soundManager.play('clicks');


              document.getElementById("seconds").innerHTML='';


              minutes=109;


              seconds=60;


              }


            } 


          }


}





function checkster(consoleInput){


  if(consoleInput!=''){


    x=x+1; //cycle input count


    if(consoleInput=="cls"){


    document.getElementById("bigBody").innerHTML=clockDiv+consolePrompt;


    lastInput="cls";


    refocus();


    }else if(consoleInput=="reboot"){


    document.getElementById("bigBody").innerHTML='rebooting mainframe';


    setTimeout('window.location.replace(unescape(window.location.pathname));',4000);


    }else if(consoleInput=="exit"){


    document.getElementById("bigBody").innerHTML='';


    window.open('','_parent','');


    window.close();


    }else{


    if(lastInput==consoleInput){repeat=1;}else{repeat=0;}


    lastInput=consoleInput;


    sendInput(consoleInput);


    refocus();


    }


    


  }


}





var timerEnd;


var seconds;


var minutes;


function setClock()


{


try {// XMLHttpRequest tester


  xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 


  }


  catch (e) {


  document.getElementById("bigBody").innerHTML="This console is non-funcitonal, please upgrade or repair it. (xmlHTTPrequest required)";


  }


  document.getElementById("minutes").innerHTML="---m";

  document.getElementById("seconds").innerHTML="--s";

  xmlhttp.onreadystatechange = triggerClock;

  xmlhttp.open("GET","MrMustard.php?t=1",true);

  xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

  xmlhttp.send('NULL'); //Send null post variables to server


  function triggerClock() {


  if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { //Done loading and it's all good


    timerEnd=(xmlhttp.responseText);


    minutes=timerEnd.substr(0,3);


    seconds=timerEnd.substr(4,2);


    document.getElementById("minutes").innerHTML=minutes+"m";


    if(minutes>=4){document.getElementById("seconds").innerHTML="";}


  }


}


}








var lastBeep=0;


var resetCheck=0;


ID=window.setTimeout("updateClock();", 1000);


function updateClock() {


  if(document.getElementById("minutes") && document.getElementById("seconds")){ //clock is up


    seconds=seconds-1; //decrement secs


    


    if(seconds==-1){seconds=59;} //dont go negative


    


    if(seconds==59){ 


      minutes=minutes-1; //decrement mins


      soundManager.play('tick');


      


      resetCheck++; //recalibrate increment


    }


    document.getElementById("minutes").innerHTML=minutes+"m"; //show minutes


    if(minutes<4){ //countdown alert and show seconds


      document.getElementById("seconds").innerHTML=seconds+"s"; //display secs


      soundManager.play('tick');


      if(lastBeep==0){//alternate second beeps


        lastBeep=1;


        


        if(minutes==0){soundManager.play('alarm');}else{soundManager.play('beep');}


      } else if(lastBeep==1){


        lastBeep=0;


      }


    


    }


    


    if(seconds<1 && minutes==0){ //time's up


      soundManager.setVolume('whir',200);


      soundManager.play('whir');


      document.getElementById("consoleContainer").innerHTML="&#62;:";


      failure();


      


      //setTimeout('document.getElementById("bigBody").innerHTML=""', 4000); //empty window in 4 secs


      window.open('','_parent',''); 


      setTimeout('window.close()', 42000) //close window in 8 secs


      return;


    }


    


    if(resetCheck==3){resetCheck=0; setClock();} //reclibrate every 3 mins





    


    


ID=window.setTimeout("updateClock();",1000);} //do it again in 1 sec


}


var volcheck=100;


var bgFade=0;


var failcount=0;


function failure(){





        


        if(bgFade<=252){bgFade=bgFade+1;}


        


        if(failcount==2){}


        if(failcount==0){


          soundManager.play('failure'); 


          failcount=12;


          volcheck=volcheck-4;


          soundManager.setVolume('failure',volcheck);


        }


        }
