<?php
  $score = "0";
  $outof = "0";
  $theword = "";
  $theunderline = "";
  $wordlist = "";
  
  
  function expanded($inwl) {
     $wl = explode(" ", rtrim(ltrim($inwl)));
     if (sizeof($wl) >= 1 && rtrim(ltrim($inwl)) != "") {
       $outw = " ";
       for ($i=0; $i<sizeof($wl); $i++) {
         $outw .= "<a target=_blank title='" . $wl[$i] . "' href='http://www.thefreedictionary.com/" . $wl[$i] . "'>" . $wl[$i] . "</a> ";
       }
       return $outw;
     } else {
       return $inwl;
     }
  }
  
  if (isset($_GET['wordlist'])) {
    $wordlist = $_GET['wordlist'];
  }
  if (isset($_POST['word'])) {
    $theword = $_POST['word'];
  } else if (isset($_GET['huhbig'])) {
    if (strpos($_GET['huhbig'], "~") !== false) {
    $thewords = explode("~", $_GET['huhbig']);
    $theword = $thewords[0];
    $wordlist = str_replace("!", " ", str_replace("wordlist=", "", $thewords[1]));
    $score = str_replace("score=", "", $thewords[2]);
    } else {
    $theword = $_GET['huhbig'];
    }
  } else {
    $theword = substr(md5(microtime()),rand(0,26),81); 
    $seed = str_split('abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'); 
	shuffle($seed); 
	$theword = '';
    foreach (array_rand($seed, 81) as $k) $theword .= $seed[$k];
  } 
  for ($i=0; $i<strlen($theword); $i++) {
    $theunderline .= "-";
  }
  if (isset($_GET['score'])) {
    $score=$_GET['score'];
  }
  if (isset($_GET['outof'])) {
    $outof=$_GET['outof'];
  }
  if (isset($_POST['score'])) {
    $score=$_POST['score'];
  }
  if (isset($_POST['outof'])) {
    $outof=$_POST['outof'];
  }
?>
<html>
<head>
<title>Can You See Any Words - RJM Programming - 2014</title>
<script type="text/javascript">
var overgoes=0;
var score=0;
var outof=0;
var goes=0;
var guess="";
var lettersdone="";
var ci=null;

<?php
  echo "\n var bword='" . $theword . "'; \n";
  echo "\n var versus='" . $theunderline . "'; \n";
  if (isset($_GET['score'])) {
    echo "\n score=" . $_GET['score'] . "; \n";
  }
  if (isset($_GET['outof'])) {
    echo "\n outof=" . $_GET['outof'] . "; \n";
  }
?>

function addtoword(intd) {
  document.getElementById("huhtiny").value = document.getElementById("huhtiny").value + intd.innerHTML;
  intd.style.backgroundColor = 'yellow';
}

function place() { 
   //alert(bword);
   var i = bword.length;
   var j,k,m,kcr,kk=0;
   var col, row;
   var sofar = "";
   for (j=1; j<=9; j++) {
    for (k=1; k<=9; k++) {
       m = j*10 + k;
       document.getElementById(m).innerHTML = bword.substring(kk, (kk+1));
       kk = kk+1;
    }
   }
}
</script>
</head>
<?php
 if (isset($_GET['badluck'])) {
  echo "\n <body style=\"background-color: yellow;\" onload=\" place(); document.getElementById('huhtiny').focus(); \"> \n";
 } else {
  echo "\n <body style=\"background-color: yellow;\" onload=\" place(); document.getElementById('huhtiny').focus(); \"> \n";
 }
?>
<div align="center">
<?php
  global $score, $outof, $wordlist;
  if ($wordlist == "") {
  echo "\n" . '<h1 id="gamename">Can You See Any Words?</h1>' . "\n";
  } else {
  echo "\n" . '<h1 id="gamename">Can You See Any Words? ... Words so far: ' . expanded($wordlist) . '</h1>' . "\n";
  }
  if ($outof < $score) {
    $outof = $score;
  }
  echo "\n <h2 id='scoreis'>Score: " . $score . "</h2> \n";
  echo "\n" . '<form id="gform" method="POST" action="http://' . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . '/PHP/surprise.php">' . "\n";
  echo "\n" . '<input type="hidden" id="returnto" name="returnto" value="' . $_SERVER['PHP_SELF'] . '" />' . "\n";
?>
<input type="hidden" id="wordlist" name="wordlist" value="<?php echo $wordlist; ?>" />
<input type="hidden" id="sword" name="sword" value="<?php echo $theword; ?>" />
<input type="hidden" id="huhbig" name="huhbig" value="<?php echo $theword; ?>" />
<input type="hidden" id="word" name="word" value="<?php echo $theword; ?>" />
<input type="hidden" id="score" name="score" value="<?php echo $score; ?>" />
<table id="guess" name="guess" cellpadding=8 border=5 style=" font-size:18px; text-align:center; background-color: pink; ">
<tr>
<td onclick=" addtoword(this); " id="11">&nbsp;</td>
<td onclick=" addtoword(this); " id="12">&nbsp;</td>
<td onclick=" addtoword(this); " id="13">&nbsp;</td>
<td onclick=" addtoword(this); " id="14">&nbsp;</td>
<td onclick=" addtoword(this); " id="15">&nbsp;</td>
<td onclick=" addtoword(this); " id="16">&nbsp;</td>
<td onclick=" addtoword(this); " id="17">&nbsp;</td>
<td onclick=" addtoword(this); " id="18">&nbsp;</td>
<td onclick=" addtoword(this); " id="19">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="21">&nbsp;</td>
<td onclick=" addtoword(this); " id="22">&nbsp;</td>
<td onclick=" addtoword(this); " id="23">&nbsp;</td>
<td onclick=" addtoword(this); " id="24">&nbsp;</td>
<td onclick=" addtoword(this); " id="25">&nbsp;</td>
<td onclick=" addtoword(this); " id="26">&nbsp;</td>
<td onclick=" addtoword(this); " id="27">&nbsp;</td>
<td onclick=" addtoword(this); " id="28">&nbsp;</td>
<td onclick=" addtoword(this); " id="29">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="31">&nbsp;</td>
<td onclick=" addtoword(this); " id="32">&nbsp;</td>
<td onclick=" addtoword(this); " id="33">&nbsp;</td>
<td onclick=" addtoword(this); " id="34">&nbsp;</td>
<td onclick=" addtoword(this); " id="35">&nbsp;</td>
<td onclick=" addtoword(this); " id="36">&nbsp;</td>
<td onclick=" addtoword(this); " id="37">&nbsp;</td>
<td onclick=" addtoword(this); " id="38">&nbsp;</td>
<td onclick=" addtoword(this); " id="39">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="41">&nbsp;</td>
<td onclick=" addtoword(this); " id="42">&nbsp;</td>
<td onclick=" addtoword(this); " id="43">&nbsp;</td>
<td onclick=" addtoword(this); " id="44">&nbsp;</td>
<td onclick=" addtoword(this); " id="45">&nbsp;</td>
<td onclick=" addtoword(this); " id="46">&nbsp;</td>
<td onclick=" addtoword(this); " id="47">&nbsp;</td>
<td onclick=" addtoword(this); " id="48">&nbsp;</td>
<td onclick=" addtoword(this); " id="49">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="51">&nbsp;</td>
<td onclick=" addtoword(this); " id="52">&nbsp;</td>
<td onclick=" addtoword(this); " id="53">&nbsp;</td>
<td onclick=" addtoword(this); " id="54">&nbsp;</td>
<td onclick=" addtoword(this); " id="55">&nbsp;</td>
<td onclick=" addtoword(this); " id="56">&nbsp;</td>
<td onclick=" addtoword(this); " id="57">&nbsp;</td>
<td onclick=" addtoword(this); " id="58">&nbsp;</td>
<td onclick=" addtoword(this); " id="59">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="61">&nbsp;</td>
<td onclick=" addtoword(this); " id="62">&nbsp;</td>
<td onclick=" addtoword(this); " id="63">&nbsp;</td>
<td onclick=" addtoword(this); " id="64">&nbsp;</td>
<td onclick=" addtoword(this); " id="65">&nbsp;</td>
<td onclick=" addtoword(this); " id="66">&nbsp;</td>
<td onclick=" addtoword(this); " id="67">&nbsp;</td>
<td onclick=" addtoword(this); " id="68">&nbsp;</td>
<td onclick=" addtoword(this); " id="69">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="71">&nbsp;</td>
<td onclick=" addtoword(this); " id="72">&nbsp;</td>
<td onclick=" addtoword(this); " id="73">&nbsp;</td>
<td onclick=" addtoword(this); " id="74">&nbsp;</td>
<td onclick=" addtoword(this); " id="75">&nbsp;</td>
<td onclick=" addtoword(this); " id="76">&nbsp;</td>
<td onclick=" addtoword(this); " id="77">&nbsp;</td>
<td onclick=" addtoword(this); " id="78">&nbsp;</td>
<td onclick=" addtoword(this); " id="79">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="81">&nbsp;</td>
<td onclick=" addtoword(this); " id="82">&nbsp;</td>
<td onclick=" addtoword(this); " id="83">&nbsp;</td>
<td onclick=" addtoword(this); " id="84">&nbsp;</td>
<td onclick=" addtoword(this); " id="85">&nbsp;</td>
<td onclick=" addtoword(this); " id="86">&nbsp;</td>
<td onclick=" addtoword(this); " id="87">&nbsp;</td>
<td onclick=" addtoword(this); " id="88">&nbsp;</td>
<td onclick=" addtoword(this); " id="89">&nbsp;</td>
</tr>&nbsp;<tr>
<td onclick=" addtoword(this); " id="91">&nbsp;</td>
<td onclick=" addtoword(this); " id="92">&nbsp;</td>
<td onclick=" addtoword(this); " id="93">&nbsp;</td>
<td onclick=" addtoword(this); " id="94">&nbsp;</td>
<td onclick=" addtoword(this); " id="95">&nbsp;</td>
<td onclick=" addtoword(this); " id="96">&nbsp;</td>
<td onclick=" addtoword(this); " id="97">&nbsp;</td>
<td onclick=" addtoword(this); " id="98">&nbsp;</td>
<td onclick=" addtoword(this); " id="99">&nbsp;</td>
</tr>
<?php
//echo "\n" . '<tr><td colspan=5><a href="mailto:?subject=Please help me with my Words Within Words Game with the Link at http://' . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] .  $_SERVER['PHP_SELF'] . '?huhbig=' . $theword . '&body=http://' . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] .  $_SERVER['PHP_SELF'] . '?huhbig=' . $theword . '" title="Email Game Link to Friend">Email Game Link to Friend</a></td></tr>' . "\n";
echo "\n" . '<tr><td colspan=9><a href="mailto:?subject=Please help me with my Can You See Any Words Game with the Link at http://' . str_replace(":80/", "/", $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] .  $_SERVER['PHP_SELF']) . '?huhbig=' . $theword . '&body=http://' . str_replace(":80/", "/", $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] .  $_SERVER['PHP_SELF']) . '?huhbig=' . $theword . '~wordlist=' . str_replace(" ", "!", $wordlist) . '~score=' . $score . '" title="Email Game Link to Friend">Email Game Link to Friend</a></td></tr>' . "\n";
?>
<tr><td colspan=9><input type="button" onclick=" document.getElementById('myj').style.display='block'; document.getElementById('myj').src= 'http://www.rjmprogramming.com.au/plus'; " value="Chat Room"></input><iframe src="javascript:false;" id="myj" style="display:none;width:650px;height:800px;"></iframe></td></tr>
</table><br>
<h2 id="leng" name="leng" style=" display:none; ">Big word below has <?php echo strlen($theword); ?> letters for you to work with</h2>
<h1 id='myh1' name='myh1' style=" display:none; color: red;"><?php echo $theword; ?></h1>
<p id='lsofar' name='lsofar'></p>
Your word (if blank, starts new game): <input type="text" id="huhtiny" name="huhtiny" value=""></input>
<input type="submit" id="submit" name="submit" value="Check Your Word" title="Words should be unique to each other and at least 3 characters long. Some plurals will not count.  Diagonals are okay.   Reversed words are okay."></input>
</form>
<p id="information"></p>
</div>
</body>
</html>

