/*



 ******************************************************************



    			CodeCracker 2008 - The-Puzzler.com 



 ******************************************************************



 */







var Initialise = false;

var ScoreAdded = false;
var MakeTheTable = false;

var TableObj = null;

var Error = "Failed to load or execute required JavaScript files.";
var initial_count = new Array();
var rows_limit = 0; // Set to 0 to disable limitation


// holds an instance of XMLHttpRequest
  
var xmlHttp = createXmlHttpRequestObject();

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() 
{
// will store the reference to the XMLHttpRequest object
var xmlHttp;
// this should work for all browsers except IE6 and older
try
{
// try to create XMLHttpRequest object
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
// assume IE6 or older
var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
								"MSXML2.XMLHTTP.5.0",
								"MSXML2.XMLHTTP.4.0",
								"MSXML2.XMLHTTP.3.0",
								"MSXML2.XMLHTTP",
								"Microsoft.XMLHTTP");
// try every prog id until one works

for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
{
  try 
  { 
	// try to create XMLHttpRequest object
	xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
  } 
  catch (e) {}
}
}
// return the created object or display an error message
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else 
return xmlHttp;
}




$(document).ready
	
	
	
	(
	function()
			{
				  // only continue if xmlHttp isn't void
				  if (xmlHttp)
				  {
					// try to connect to the server
					try
					{
					// Call this when the DOM is ready:
							$.getJSON("../app/test.php",
									{ cmd : "init" },
									make_table);
							$(".MenuButtonsDis").click(function()
									{
										 $.getJSON("../app/displayHighScores.php",
												{ cmd : "init" },
												make_table);
									});


					}
					
					// display the error in case of failure
					catch (e)
					{
						alert("Can't connect to server:\n" + e.toString());
					}

				  }else 
				  {
											alert("Damn");  
				  }
			}
 );
 
function make_table(obj)
{
 var str = "";
 TableObj = obj;
}

function addRow(table_id)
{
  var row_no = 1;
  var tbl = document.getElementById(table_id);
  // counting rows in table
  var rows_count = tbl.rows.length;
  if (initial_count[table_id] == undefined)
  {
    // if it is first adding in this table setting initial rows count
    initial_count[table_id] = rows_count;
  }
  // determining real count of added fields
  var tFielsNum =  rows_count - initial_count[table_id];
  if (rows_limit!=0 && tFielsNum >= rows_limit) return false;
  var text = 'Name:';
  var input = '<input type="text" name="'+row_no+'" value="Anonymous" id="'+row_no+'" style="width:100%;"/>';
  var remove= '<input type="button" value="Submit" onclick="submitScore(document.getElementById('+row_no+').value)" style="width:100%;"/>';
  
  try {
    var newRow = tbl.insertRow(rows_count);
    var newCell = newRow.insertCell(0);
    newCell.innerHTML = text;
    var newCell = newRow.insertCell(1);
    newCell.innerHTML = input;
    var newCell = newRow.insertCell(2);
    newCell.innerHTML = remove;
  } catch (ex) {
    //if exception occurs
    alert(ex);
  }
}

function submitScore(input)
{ 
  this.ACrosswordPuzzle.menu.submitScore(input);
}

function JSONscriptRequest(_1)



{



   this.fullUrl = _1;



   this.headLoc = document.getElementsByTagName("head").item(0);



   this.scriptId = "JscriptId" + JSONscriptRequest.scriptCounter ++ ;







}



JSONscriptRequest.scriptCounter = 1;



JSONscriptRequest.prototype.init = function()



{



   this.scriptObj = document.createElement("script");



   this.scriptObj.setAttribute("type", "text/javascript");



   this.scriptObj.setAttribute("charset", "utf-8");



   this.scriptObj.setAttribute("src", this.fullUrl);



   this.scriptObj.setAttribute("id", this.scriptId);







}



;



JSONscriptRequest.prototype.finit = function()



{



   this.headLoc.removeChild(this.scriptObj);







}



;



JSONscriptRequest.prototype.submit = function(_2)



{



   this.headLoc.appendChild(this.scriptObj);







}



;



function CrosswordClue(_1, _3, _4, _5, _6, _7, _8)



{



   this.len = _1;



//   this.clue = _2;



   this.answer = _3;



   this.sign = _4;



   this.dir = _5;



   this.xpos = _6;



   this.ypos = _7;



   this.numberlist = _8;



   this.revealed = false;



   this.matched = false;







}







CrosswordClue.prototype.completed = function()



{



   return this.matched || this.revealed;







}



;







function CodeCrackerGrid(_8)



{



  this.puzz = _8;



}







CodeCrackerGrid.prototype.render = function()



{  



   var buf = "";



   buf += "<table border='0' cellspacing='0' cellpadding='0' style='border-collapse: collapse;'>";



   for(var i = 0; i < 26; i ++ )



   {



      var row = "<tr>";



      for(var j = 0; j < 2; j ++ )



      {



	    row += "<td class='CodeCrackerReadOnlyCell' id='CodeCrackerGrid"+j+"_"+i+"'></td>";



      }



      buf += row + "</tr>";







   }



   buf += "</table>";



   



   



   var _19 = document.getElementById("HorzList");



   _19.style.width = 50;



   _19.innerHTML = buf;



   



   



   



   for(var i = 0; i < 26; i ++ )



   {



      var key = "CodeCrackerGrid" + 1 + "_" + i;



      var _1d = document.getElementById(key);



      _1d.className = "InputWhiteCell";







   }



};







CodeCrackerGrid.prototype.bind = function()



{



  this.inputCacheForCodeCracker = new oyGridElementCache(2, 26, "oyInputForCodeCracker");



  for(var i = 0; i < 26; i ++ )



  {



    for(var j = 0; j < 2; j ++ )



    {



      this.bindItem(j, i);



    }



  }







};







CodeCrackerGrid.prototype.unbind = function()



{



   for(var i = 0; i < this.clues.length; i ++ )



   {



      var _11 = document.getElementById(this.ns + i);



      _11.onclick = null;







   }



};







CodeCrackerGrid.prototype.bindItem = function(x, y)



{



     



   var _3c = this.inputCacheForCodeCracker.getElement(x, y);



   if(_3c != null)



   {



      var _3d = this;



      _3c.onclick = function()



      {



         _3d.unfocusOldCell();



         _3d.focusNewCell(x, y, false);







      }



      ;



      _3c.onkeydown = function(e)



      {



         return _3d.handleKeyDown(x, y, e);







      }



      ;



      _3c.onkeypress = function(e)



      {



         return _3d.handleKeyPress(x, y, e);







      }



      ;







   }







};







CodeCrackerGrid.prototype.fillCodeCracker = function(i, j)



{



  var key = "CodeCrackerGrid" + j + "_" + i;



  var _2b = document.getElementById(key);



  this.fillIn(_2b, j, i);



  this.puzz.menu.setCellState(j, i, 0);







}



;







CodeCrackerGrid.prototype.replaceLetterWithNumber = function(a)



{



	for(var i = 0; i < this.puzz.h; i ++ ) {



	   for(var j = 0; j < this.puzz.w; j ++ ){



		  var _39 = this.puzz.inputCache.getElement(j, i);



			if(_39 != null){



			  if (a == _39.value){



				_39.value = _39.alt;



			  }



	



			}



	   }



	 }



};



CodeCrackerGrid.prototype.fillIn = function(_2c, x, y)



{



  _2c.innerHTML = "<input id='oyInputForCodeCracker"+x+"_"+y+"' class='oyCellInput' autocomplete='off' type='text' size='1' maxlength='2' value=''>";



    



};







CodeCrackerGrid.prototype.focusNewCell = function(x, y, _50, _51)



{



   if(this.focused != null)



   {



      this.dir = this.focused.dir;



      this.focusCellList(this.menu.getCellPosListFor(this.focused), true);







   }



   var _52 = document.getElementById("CodeCrackerGrid" + x + "_" + y);



   if(_52 != null)



   {



      _52.className = "InputWhiteCell";



      if(_50)



      {



         var _52 = this.inputCacheForCodeCracker.getElement(x, y);



         _52.focus();







      }



   }



   this.xpos = x;



   this.ypos = y;



   this.puzz.menu.focusNewCell(x, y);



   this.puzz.menu.invalidateMenu();







}



;











CodeCrackerGrid.prototype.handleKeyDown = function(x, y, e)



{



   if( ! e)



   {



      e = window.event;







   }



   var _6a = (e.which) ? e.which : e.keyCode;



   var dir = (_6a >= 37 && _6a <= 40) || _6a == 8;



   if(dir)



   {



      var _6c = null;



      switch(_6a)



      {



         case 8 : //Backspace



           var _66 = this.inputCacheForCodeCracker.getElement(x, y);



		   if( ! _66.readOnly)



		   {



			 for(var i = 0; i < this.puzz.h; i ++ ) {



			   for(var j = 0; j < this.puzz.w; j ++ ){



				  var _39 = this.puzz.inputCache.getElement(j, i);



					if(_39 != null){



					  var _68 = this.inputCacheForCodeCracker.getElement(0, y);



					  if (_68.value == _39.value){



						_39.value = _66.alt;



					  }



					}



	



				}



			  }



			  



	     	  _66.value = "";



			  _66.alt = "";



			}



		



		// this.moveToPrevCell(x, y);



         break;



         case 38 : //Up Key



         while(true)



         {



            if(y > 0)



            {



               y = y - 1;



               _6c = this.inputCacheForCodeCracker.getElement(x, y);



               if(_6c != null)



               {



                  break;







               }



            }



            else



            {



               break;







            }



         }



         break;



         case 40 : //Down key



         while(true)



         {



            if(y < 25)



            {



               y = y + 1;



               _6c = this.inputCacheForCodeCracker.getElement(x, y);



               if(_6c != null)



               {



                  break;







               }



            }



            else



            {



               break;







            }



         }



         break;







      }



      if(_6c != null)



      {



         this.focusNewCell(x, y, false);



         _6c.focus();



      }



   }



   return true;







}



;











CodeCrackerGrid.prototype.handleKeyPress = function(x, y, e)



{



   if( ! e)



   {



      e = window.event;







   }



   var _64 = (e.which) ? e.which : e.keyCode;



   var c = String.fromCharCode(_64).toUpperCase();



   if(_64 == 32)



   {



      c = " ";







   }



  



   if (this.puzz.isValidNumber(c))



   {



      var _66 = this.inputCacheForCodeCracker.getElement(x, y);



      if( ! _66.readOnly)



      {



         if (this.puzz.isValidNumber(_66.value)) {



			var _70 = this.inputCacheForCodeCracker.getElement(0, y);



			this.replaceLetterWithNumber(_70.value);



			_66.value = _66.value + c;



			_66.alt   = _66.value + c;



		 } else {



		   _66.value = c;	



		   _66.alt   = c;



		 }



		 for(var i = 0; i < this.puzz.h; i ++ ) {



      	   for(var j = 0; j < this.puzz.w; j ++ ){



              var _39 = this.puzz.inputCache.getElement(j, i);



                if(_39 != null){



				  if (_66.value == _39.value){



				   var _67 = this.inputCacheForCodeCracker.getElement(0, y);



				    _39.value = _67.value;



					_39.alt   = c;



				  }







         	    }



      	   }



         }



      }







   }



   return false;







}



;







function ClueList(_8, _9, _a)



{



   this.puzz = _8;



   this.name = _9;



   this.clues = _a;



}















ClueList.prototype.getClueIndexForPoint = function(x, y)



{



  



 return - 1;







}



;



function CrosswordMenu(_1)



{



   this.puzz = _1;



   this.hlist = _1.hlist;



   this.vlist = _1.vlist;



   this.codeCrackergrid = _1.codeCrackerGrid;



   this.footer = _1.footer;



   this.canReveal = _1.canReveal;



   this.canCheck = _1.canCheck;



   this.clues = _1.clues;



   this.currentMenu = null;



   this.over = null;



   this.cache = new Array();



   for(var i = 0; i < this.puzz.h; i ++ )



   {



      for(var j = 0; j < this.puzz.w; j ++ )



      {



         var _4 = j + "_" + i;



         this.cache[_4] = - 1;







      }



   }



   this.checks = 0;



   this.reveals = 0;



   this.deducts = 0;



   this.matches = 0;



   this.score = 0;



   this.rank = - 1;



   this.xpos = _1.xpos;



   this.ypos = _1.ypos;



   this.name = oyGetCookie("OYG_NICK_NAME");



   if(this.name == null || this.name == "")



   {



      this.name = "Anonymous";







   }



   this.server = new Server(this.puzz.appHome, this.puzz.ns);



   this.scoreSubmittedMatches = 0;







}



CrosswordMenu.prototype.setCellState = function(x, y, _7)



{



   this.cache[x + "_" + y] = _7;







}



;



CrosswordMenu.prototype.getCellState = function(x, y)



{



   return this.cache[x + "_" + y];







}



;



CrosswordMenu.prototype.bind = function()



{



   this.inputCache = this.puzz.inputCache;



   this.startOn = new Date();







}



;



CrosswordMenu.prototype.unbind = function()



{



   this.inputCache = null;







}



;



CrosswordMenu.prototype.focusNewCell = function(x, y)



{



   this.xpos = x;



   this.ypos = y;







}



;



CrosswordMenu.prototype.invalidateMenu = function()



{



   if(this.currentMenu != null)



   {



      this.currentMenu();







   }



}



;



CrosswordMenu.prototype.installWelcomeMenu = function()



{



   this.currentMenu = this.installWelcomeMenu;



   var _c = document.getElementById("PuzzleFooter");



   _c.innerHTML = "";



   var _d = this;



   var _e = escape(this.name);



   _e = _e.replace(/%20/g, " ");



   this.addNoneWordAction(_c, "Welcome, <a class='oysTextLink' href='' id='oygWelcomeLink'>" + _e + "</a>! ");



   var _f = document.getElementById("oygWelcomeLink");



   _f.onclick = function()



   {



      _d.askNickName();



      _d.invalidateMenu();



      return false;







   }



   ;



   this.addNewLine(_c);



   this.addAction(_c, "Start Now", "Starting...", "strt", function()



   {



      _d.puzz.bind();



      _d.installContextMenu();



      document.getElementById("Static").innerHTML = "";



      _d.footer.stateOk("Enjoy the game!");







   }



   );



   this.footer.stateOk("Ready to begin!");



 //  this.server.trackAction(this.puzz.uid, "wlm");







}



;



CrosswordMenu.prototype.installContextMenu = function()



{



   this.currentMenu = this.installContextMenu;



   var _10 = document.getElementById("PuzzleFooter");



   _10.innerHTML = "";



   var _11 = this.hlist.getClueIndexForPoint(this.xpos, this.ypos);



   var _12 = this.vlist.getClueIndexForPoint(this.xpos, this.ypos);



   if( ! this.canReveal)



   {



      this.addNoneWordAction(_10, "Reveal Disabled");







   }



   else



   {



      if(_11 != - 1)



      {



         var _13 = "Reveal <b>" + (_11 + 1) + "A</b>";



         if( ! this.hlist.clues[_11].completed())



         {



            this.addRevealWordAction(this.hlist.clues[_11], _10, _13);







         }



         else



         {



            this.addAction(_10, _13, "", null, null);







         }



      }



      if(_12 != - 1)



      {



         var _13 = "Reveal <b>" + (_12 + 1) + "D</b>";



         if( ! this.vlist.clues[_12].completed())



         {



            this.addRevealWordAction(this.vlist.clues[_12], _10, _13);







         }



         else



         {



            this.addAction(_10, _13, "", null, null);







         }



      }



   }



   if( ! this.canCheck)



   {



      this.addNoneWordAction(_10, "Check Disabled");







   }



   else



   {



      var _13 = "Check <b>" + (_11 + 1) + "A</b>";



      if(_11 != - 1)



      {



         if( ! this.hlist.clues[_11].completed())



         {



            this.addCheckWordAction(this.hlist.clues[_11], _10, _13);







         }



         else



         {



            this.addAction(_10, _13, "", null, null);







         }



      }



      var _13 = "Check <b>" + (_12 + 1) + "D</b>";



      if(_12 != - 1)



      {



         if( ! this.vlist.clues[_12].completed())



         {



            this.addCheckWordAction(this.vlist.clues[_12], _10, _13);







         }



         else



         {



            this.addAction(_10, _13, "", null, null);







         }



      }



      var _14 = this;



      this.addAction(_10, "Check <b>All</b>", "Checking All...", "chkll", function()



      {



         _14.checkAll();



         _14.invalidateMenu();



         return false;







      }



      );



      this.addNewLine(_10);



      var _14 = this;



      this.addSubmitLeaveMenuItems(_10);







   }



   this.footer.update();



   var _15 = false;



   for(var i = 0; i < this.clues.length; i ++ )



   {



      if( ! this.clues[i].completed())



      {



         _15 = true;



         break;







      }



   }



   if( ! _15)



   {



      this.over = true;







   }



   if(this.over)



   {



      this.over = true;



      this.puzz.unbind();



      this.installDoneMenu();







   }



}



;



CrosswordMenu.prototype.installDoneMenu = function()



{



   this.currentMenu = this.installDoneMenu;



   var _17 = document.getElementById("PuzzleFooter");



   _17.innerHTML = "";



   this.addNoneWordAction(_17, "Game Over!");



   this.addNewLine(_17);



   var msg = "You have <b>" + this.score + "</b> points";



   if(this.rank != - 1)



   {



      msg += " (rank <b>" + this.rank + "</b>)";







   }



   msg += ".";



   this.addNoneWordAction(_17, msg);



   this.addNewLine(_17);



   var _19 = this;



   this.addSubmitLeaveMenuItems(_17);



   this.footer.stateOk("Game over!");



  // this.server.trackAction(this.puzz.uid, "ovr");



   this.footer.update();







}



;



CrosswordMenu.prototype.addSubmitLeaveMenuItems = function(_1a)



{



   // var _1b = "Submit <b>Score</b>";



   // if(this.matches > 0 && this.scoreSubmittedMatches < this.matches)



   // {



      // var _1c = this;



      // this.addAction(_1a, _1b, "Submitting score...", "sbmt", function()



      // {



         // _1c.submitScore();



         // _1c.invalidateMenu();



         // return false;







      // }



      // );







   // }



   // else



   // {



      // this.addAction(_1a, _1b, "", null, null);







   // }



   var _1c = this;



   this.addAction(_1a, "Leave <b>Game</b>", "Leaving...", "lv", function()



   {



      _1c.leaveGameEarly(_1c.puzz.leaveGameUrl);



      _1c.footer.stateOk("Done");



      return false;







   }



   );







}



;



CrosswordMenu.prototype.leaveGameEarly = function(url)



{



   this.footer.stateBusy("Leaving...");



   var _1e = true;



   if(this.puzz.started && ! this.over)



   {



      _1e = confirm("Game is in progress. Do you want to leave the game?");







   }



   if(_1e)



   {



      var loc = this.puzz.appHome + "/app/leaveGame.php?ns=" + this.puzz.ns;



      if(url != null)



      {



         loc = unescape(url);







      }



      window.location = loc;







   }



   this.footer.stateOk("Done");







}



;



CrosswordMenu.prototype.addAction = function(_20, _21, _22, _23, _24)



{



   _21 = _21.replace(" ", "&nbsp;");



   var _25 = document.createElement("SPAN");



   _25.innerHTML = " &nbsp; ";



   _20.appendChild(_25);



   var _25 = document.createElement("A");



   _25.innerHTML = _21;



   _25.href = "";



   if( ! _24)



   {



      _25.className = "MenuButtonsDis";



      _25.onclick = function()



      {



         return false;







      }



      ;







   }



   else



   {



      _25.className = "MenuButtons";



      var _26 = this;



      _25.onclick = function()



      {



         _26.footer.stateBusy(_22);



         setTimeout(function()



         {



            _24();



      //      _26.server.trackAction(_26.puzz.uid, _23);







         }



         , 100);



         return false;







      }



      ;







   }



   _20.appendChild(_25);







}



;



CrosswordMenu.prototype.addNewLine = function(_27)



{



   var _28 = document.createElement("SPAN");



   _28.innerHTML = "<span style='font-size: 4px;'><br />&nbsp;<br /></span>";



   _27.appendChild(_28);







}



;



CrosswordMenu.prototype.addNoneWordAction = function(_29, _2a)



{



   var _2b = document.createElement("SPAN");



   _2b.className = "MenuButtonsNone";



   _2b.innerHTML = _2a;



   _29.appendChild(_2b);



   var _2b = document.createElement("SPAN");



   _2b.innerHTML = " ";



   _29.appendChild(_2b);







}



;



CrosswordMenu.prototype.addCheckWordAction = function(_2c, _2d, _2e)



{



   var _2f = this;



   this.addAction(_2d, _2e, "Checking...", "chk", function()



   {



      _2f.checkWord(_2c);



      _2f.invalidateMenu();



      return false;







   }



   );







}



;



CrosswordMenu.prototype.addRevealWordAction = function(_30, _31, _32)



{



   var _33 = this;



   this.addAction(_31, _32, "Revealing...", "rvl", function()



   {



      _33.revealWord(_30);



      _33.invalidateMenu();



      return false;







   }



   );







}



;



CrosswordMenu.prototype.getCurrentValueFor = function(x, y)



{



   var _36 = this.inputCache.getElement(x, y).value;



   if(_36 == " " || _36 == "")



   {



      _36 = null;







   }



   return _36;







}



;



CrosswordMenu.prototype.getCellPosListFor = function(_37, _38, top)



{



   var all = new Array();



   for(var i = 0; i < _37.len; i ++ )



   {



      all.push(this.charToPos(_37, i));







   }



   return all;







}



;



CrosswordMenu.prototype.charToPos = function(_3c, _3d)



{



   var pos = new function()



   {



   }



   ;



   if(_3c.dir == 0)



   {



      pos.x = _3c.xpos + _3d;



      pos.y = _3c.ypos;







   }



   else



   {



      pos.x = _3c.xpos;



      pos.y = _3c.ypos + _3d;







   }



   return pos;







}



;



CrosswordMenu.prototype.showAnswer = function(_3f, _40)



{



   for(var i = 0; i < _3f.len; i ++ )



   {



      var pos = this.charToPos(_3f, i);



      var _43 = this.inputCache.getElement(pos.x, pos.y);



      if( ! _43.readOnly)



      {



         _43.readOnly = true;



         _43.value = _3f.answer.charAt(i).toUpperCase();



         this.setCellState(pos.x, pos.y, _40);



         var _44 = document.getElementById("oyCell" + pos.x + "_" + pos.y);



         switch(_40)



         {



            case 1 :



               _44.className = "GuessedCell";



               break;



            case 2 :



               _44.className = "RevealedCell";



               break;



            default :



               alert("Bad state code!");







         }



      }



   }



   this.puzz.invalidate();







}



;



CrosswordMenu.prototype.checkWordStatus = function(_45)



{



   var _46 = new function()



   {



   }



   ;



   _46.wrong = 0;



   _46.isComplete = true;



   _46.buf = "";



   for(var i = 0; i < _45.len; i ++ )



   {



      var _48;



      if(_45.dir == 0)



      {



         _48 = this.getCurrentValueFor(_45.xpos + i, _45.ypos);







      }



      else



      {



         _48 = this.getCurrentValueFor(_45.xpos, _45.ypos + i);







      }



      if(_48 == null)



      {



         _46.isComplete = false;



         _46.buf += ".";







      }



      else



      {



         _46.buf += _48;







      }



      if(_48 != _45.answer.charAt(i).toUpperCase())



      {



         _46.wrong ++ ;







      }



   }



   return _46;







}



;



CrosswordMenu.prototype.askNickName = function(_49)



{



   if(_49)



   {



      _49 = "Score: " + _49 + ". ";







   }



   else



   {



      _49 = "";







   }



   if(this.name == null)



   {



      this.name = "";







   }



   var _4a = this.name;



   this.name = window.prompt(_49 + "Log-on feature is yet to come!\n" + "Scoring feature will be active soon. Enjoy the game!",this.name); var _4b=true;



   if(this.name == null || this.name == "")



   {



      this.name = _4a;



      _4b = false;







   }



   if(this.name != null && this.name != "")



   {



      oySetCookieForPeriod("OYG_NICK_NAME", this.name, 1000 * 60 * 60 * 24 * 360, "/");



      return _4b;







   }



   else



   {



      this.name = "Anonymous";



      return false;







   }



}



;



CrosswordMenu.prototype.getScoreForMatch = function(_4c)



{



   return _4c.len;







}



;



CrosswordMenu.prototype.getDeductsForReveal = function(_4d)



{



   return _4d.len * 2;







}



;



CrosswordMenu.prototype.getDeductionForCheck = function(_4e)



{



   var _4f = 3;



   var _50 = (_4e.len - _4e.len % _4f) / _4f;



   if(_50 < 1)



   {



      _50 = 1;







   }



   return _50;







}



;



CrosswordMenu.prototype.revealWord = function(_51)



{



   this.deducts += this.getDeductsForReveal(_51);



   this.reveals ++ ;



   this.showAnswer(_51, 2);



   _51.revealed = true;



   _51.matched = false;



   var _52 = this.checkWordStatus(_51);



   this.footer.stateOk("Revealed [" + _52.buf + "]!");







}



;



CrosswordMenu.prototype.checkAll = function()



{



   var _53 = 0;



   var _54 = 0;



   for(var i = 0; i < this.clues.length; i ++ )



   {



      if(this.clues[i].completed())



      {



         continue;







      }



      var _56 = this.checkWordStatus(this.clues[i]);



      if(_56.isComplete)



      {



         _53 ++ ;



         this.checks ++ ;



         this.deducts += this.getDeductionForCheck(this.clues[i]);



         if(_56.wrong == 0)



         {



            this.showAnswer(this.clues[i], 1);



            this.score += this.getScoreForMatch(this.clues[i]);



            this.clues[i].matched = true;



            this.clues[i].revealed = false;



            _54 ++ ;



            this.matches ++ ;







         }



      }



   }



   if(_53 == 0)



   {

      var outstr = "No complete words found!";
      this.footer.stateError(outstr);

   }



   else



   {


      var outstr = "Checked " + _53 + ", " + _54 + " matched!";
      this.footer.stateOk(outstr);







   }

   var len = TableObj.length;
   for (var i = 0; i < len; i++)
   {
	 var user = TableObj[i];
	 if (this.score > user["score"]){
	   MakeTheTable = true;
	 }
   }

   if ((MakeTheTable) && !(ScoreAdded)){

 	 ScoreAdded = true;
     addRow('mytable');
     this.footer.stateOk(outstr + "<br>Congratulations, you made a high score!<br>Please enter your name below and hit \"Submit\"");  

   }

	  else{

        this.footer.stateOk(outstr + "<br>Sorry, didn't make the high scores table!");  

	  }


}



;



CrosswordMenu.prototype.checkWord = function(_57)



{



   var _58 = this.checkWordStatus(_57);



   if( ! _58.isComplete)



   {



      this.footer.stateError("The word [" + _58.buf + "] is incomplete!");







   }



   else



   {



      this.checks ++ ;



      this.deducts += this.getDeductionForCheck(_57);



      if(_58.wrong != 0)



      {



         this.footer.stateError("[" + _58.buf + "] didn't match!");







      }



      else



      {



         this.matches ++ ;



         this.showAnswer(_57, 1);



         this.score += this.getScoreForMatch(_57);



         _57.revealed = false;



         _57.matched = true;



         this.footer.stateOk("[" + _58.buf + "] matched!");







      }



   }



}



;



CrosswordMenu.prototype.submitScore = function(nameofUser)



{



   if(this.matches == 0)



   {



      this.footer.stateError("Nothing to submit yet!");



      alert("Nothing to submit yet!\nUncover some words first.");







   }



   else



   {



      var ms = new Date().getTime() - this.puzz.menu.startOn.getTime();

      var state = document.getElementById("State");



      this.server.submitScore(this, this.score, this.matches, nameofUser);

	  

	  if (state.className != "StateOk")

	  {  



        this.footer.stateBusy("Submitting score...");

	  }





   }



}



;



function CrossWordFooter(_1)



{



   this.puzz = _1;







}



CrossWordFooter.prototype.bind = function()



{



   var _2 = this;



   this.clockTime = setInterval(function()



   {



      _2.clockUpdate();







   }



   , 1000);







}



;



CrossWordFooter.prototype.unbind = function()



{



   clearInterval(this.clockTime);



   this.clockTime = null;







}



;



CrossWordFooter.prototype.stateOk = function(_3)



{



   var _4 = document.getElementById("State");



   _4.innerHTML = "<b>&gt;</b> " + _3 + "&nbsp;";



   _4.className = "StateOk";







}



;



CrossWordFooter.prototype.stateBusy = function(_5)



{



   var _6 = document.getElementById("State");



   _6.innerHTML = "<b>&gt;</b> " + _5 + "&nbsp;";



   _6.className = "StateBusy";







}



;



CrossWordFooter.prototype.stateError = function(_7)



{



   var _8 = document.getElementById("State");



   _8.innerHTML = "<b>&gt;</b> " + _7 + "&nbsp;";



   _8.className = "StateError";







}



;



CrossWordFooter.prototype.clockUpdate = function()



{



   var _9 = function(i)



   {



      if(i < 10)



      {



         i = "0" + i;







      }



      return i;







   }



   ;



   if(this.puzz.started)



   {



      var ms = new Date().getTime() - this.puzz.menu.startOn.getTime();



      var _c = Math.round(ms / 1000);



      var _d = 0;



      if(_c >= 60)



      {



         _d = Math.round(_c / 60);



         _c = _c % 60;







      }



      document.getElementById("oygFooterClock").innerHTML = "&nbsp;Time: <b>" + _9(_d) + "</b>:<b>" + _9(_c) + "</b>";







   }



}



;



CrossWordFooter.prototype.update = function()



{



   var _e = "";



   if( ! this.puzz.started)



   {



      _e += "Game has not yet started!";







   }



   else



   {



      _e += "Score: <b>" + this.puzz.menu.score + "</b> points";



      if(this.puzz.menu.rank != - 1)



      {



         _e += " (rank <b>" + this.puzz.menu.rank + "</b>)";







      }



   }



   document.getElementById("oygFooterStatus").innerHTML = _e;







}



;



function oyGridElementCache(w, h, ns)



{



   this.ns = ns;



   this.cache = new Array();



   for(var i = 0; i < h; i ++ )



   {



      for(var j = 0; j < w; j ++ )



      {



         var key;



         key = this.ns + j + "_" + i;



         this.cache[key] = document.getElementById(key);







      }



   }



}



oyGridElementCache.prototype.getElement = function(x, y)



{



   return this.cache[this.ns + x + "_" + y];







}



;



var ie4 = (document.all) ? true : false;



var ns4 = (document.layers) ? true : false;



var ns6 = (document.getElementById && ! document.all) ? true : false;



function oyShowLayer(lay)



{



   if(ie4)



   {



      document.all[lay].style.visibility = "visible";



      document.all[lay].style.display = "block";







   }



   if(ns4)



   {



      document.layers[lay].visibility = "show";







   }



   if(ns6)



   {



      document.getElementById([lay]).style.visibility = "visible";



      document.getElementById([lay]).style.display = "block";







   }



}



function oyHideLayer(lay)



{



   if(ie4)



   {



      document.all[lay].style.visibility = "hidden";



      document.all[lay].style.display = "none";







   }



   if(ns4)



   {



      document.layers[lay].visibility = "hide";







   }



   if(ns6)



   {



      document.getElementById([lay]).style.visibility = "hidden";



      document.getElementById([lay]).style.display = "none";







   }



}



function oySetCookie(_19, _1a, _1b, _1c, _1d, _1e)



{



   document.cookie = _19 + "=" + escape(_1a) + ((_1b) ? "; expires=" + _1b.toGMTString() : "") + ((_1c) ? "; path=" + _1c : "") + ((_1d) ? "; domain=" + _1d : "") + ((_1e) ? "; secure" : "");







}



function oyGetCookie(_1f)



{



   var dc = document.cookie;



   var _21 = _1f + "=";



   var _22 = dc.indexOf("; " + _21);



   if(_22 == - 1)



   {



      _22 = dc.indexOf(_21);



      if(_22 != 0)



      {



         return null;







      }



   }



   else



   {



      _22 += 2;







   }



   var end = document.cookie.indexOf(";", _22);



   if(end == - 1)



   {



      end = dc.length;







   }



   return unescape(dc.substring(_22 + _21.length, end));







}



function oySetCookieForPeriod(_24, _25, _26, _27, _28, _29)



{



   var _2a = new Date();



   _2a.setTime(_2a.getTime() + _26);



   oySetCookie(_24, _25, _2a, _27, _28, _29);







}



function oyBrowserDetection()



{



   this.agt = navigator.userAgent.toLowerCase();



   this.browser = "";



   this.version = 0;



   this.compleVersion = 0;



   this.isIE = false;



   this.isNetscape = false;



   this.isFirefox = false;



   this.isOpera = false;



   this.isGood = false;



   this.sf = false;



   this.isWin = ((this.agt.indexOf("win") != - 1) || (this.agt.indexOf("16bit") != - 1));



   this.isMac = (this.agt.indexOf("mac") != - 1);



   this.isLinux = (this.agt.indexOf("linux") != - 1);



   if(navigator.userAgent.indexOf("MSIE") != - 1 && navigator.userAgent.indexOf("AOL") == - 1)



   {



      this.browser = "IE";



      this.isIE = true;



      reg = /(MSIE)(.)(\d+)(.)(\d+)/i;



      ar = reg.exec(navigator.userAgent);



      this.version = ar[3];



      this.compleVersion = ar[3] + ar[4] + ar[5];







   }



   else



   {



      if(navigator.userAgent.indexOf("Firefox") != - 1)



      {



         this.browser = "Firefox";



         this.isFirefox = true;



         reg = /(Firefox)(.)(\d+)(.)(\d+)/i;



         ar = reg.exec(navigator.userAgent);



         this.version = ar[3];



         this.compleVersion = ar[3] + ar[4] + ar[5];







      }



      else



      {



         if(navigator.userAgent.indexOf("Netscape") != - 1)



         {



            this.browser = "Netscape";



            this.isNetscape = true;



            reg = /(Netscape)(.)(\d+)(.)(\d+)/i;



            ar = reg.exec(navigator.userAgent);



            this.version = ar[3];



            this.compleVersion = ar[3] + ar[4] + ar[5];







         }



         else



         {



            if(navigator.userAgent.indexOf("Safari") != - 1)



            {



               this.sf = true;







            }



			else{



			  if(navigator.userAgent.indexOf("Opera") != - 1)



			  {



				this.browser = "Opera";



				this.isOpera = true;



				reg = /(Opera)(.)(\d+)(.)(\d+)/i;



				ar = reg.exec(navigator.userAgent);



				this.version = ar[3];



				this.compleVersion = ar[3] + ar[4] + ar[5];



			  }



			}



         }



      }



   }



   if((this.isIE && this.version >= 5) || (this.isNetscape && this.version >= 6) || (this.isFirefox && this.version >= 1) || (this.isOpera && this.version >= 9))



   {



      this.isGood = true;







   }



}



function Connect(_2b)



{



   var _2c = new oyBrowserDetection().isGood;



   if( ! _2c)



   {



      var msg = "Your current browser is not ideal for accessing this site.\n" + "We support Microsoft IE 6.0+, Firefox 1.0+, Netscape6.0+ and Opera 9.0+ versions.\n\n" + "It might still work OK, do you want to try?";



      if(confirm(msg))



      {



         _2c = true;







      }



   }



   if( ! _2c)



   {



      Error = "This browser is not supported.";







   }



   else



   {



      var div = document.getElementById("MainContext");



      if(div == null)



      {



         Error = "Bad template file.";







      }



      else



      {



         var _2f = document.getElementById("Puzzle");



         if(_2f == null)



         {



            Error = "Failed to load puzzle file.";







         }



         else



         {



            _2b.init();



            _2b.render();



            _2b.menu.installWelcomeMenu();







         }



      }



   }



}



function oygNextRandomInt()



{



   var rnd = "" + Math.random();



   var idx = rnd.indexOf(".");



   return rnd.substring(idx + 1);







}



Initialise = true;



Error = null;



function CrosswordPuzzle(_1, _2, ns, _4, _5, _6, w, h)



{



   this.guid = _1;



   this.uid = oygNextRandomInt();



   this.appHome = _2;



   this.ns = ns;



   this.title = _4;



   this.desc = _5;



   this.w = w;



   this.h = h;



   this.clues = _6;



   this.xpos = 0;



   this.ypos = 0;



   this.focused = null;



   this.dir = 0;



   this.leaveGameUrl = null;



   this.copyrightGameUrl = null;



   this.publisher = null;



   this.menu = null;



   this.canReveal = true;



   this.canCheck = true;



   this.reorderClues();



   this.started = false;







}



CrosswordPuzzle.prototype.reorderClues = function()



{



   var _9 = [].concat(this.clues);



   var _a = [];



   for(var i = 0; i < this.clues.length; i ++ )



   {



      for(var j = 0; j < this.clues.length; j ++ )



      {



         if(this.clues[i] == null || this.clues[j] == null || i == j)



         {



            continue;







         }



         if(this.clues[i].xpos == this.clues[j].xpos && this.clues[i].ypos == this.clues[j].ypos)



         {



            _a.push(this.clues[i]);



            _a.push(this.clues[j]);



            this.clues[i] = null;



            this.clues[j] = null;







         }



      }



   }



   this.hclues = [];



   this.vclues = [];



   for(var i = 0; i < _a.length; i ++ )



   {



      if(_a[i].dir == 0)



      {



         this.hclues.push(_a[i]);







      }



      else



      {



         this.vclues.push(_a[i]);







      }



   }



   for(var i = 0; i < this.clues.length; i ++ )



   {



      if(this.clues[i] == null)



      {



         continue;







      }



      if(this.clues[i].dir == 0)



      {



         this.hclues.push(this.clues[i]);







      }



      else



      {



         this.vclues.push(this.clues[i]);







      }



   }



   this.clues = _9;







}



;



CrosswordPuzzle.prototype.init = function()



{



   this.hlist = new ClueList(this, "Across", this.hclues);



   this.vlist = new ClueList(this, "Down", this.vclues);



   this.codeCrackerGrid = new CodeCrackerGrid(this);



   



   var _d = this;



   document.getElementById("aHeader").innerHTML = "<span class='HeaderTitle'>" + this.title + "</span><br><span class='oyHeaderDesc'>" + this.desc + "</span>";



   var _e = "<table border='0' cellspacing='0' cellpadding='0' width='100%'><tr>";



   _e += "<td class='oyFooter' id='oygFooterStatus' align='left'></td>";



   _e += "<td class='oyFooter' id='oygFooterClock' align='right'></td>";



   _e += "</tr>";



   var cr = "&nbsp;";



   if(this.publisher != null)



   {



      cr = this.publisher;







   }



   _e += "<tr><td class='oyCopyright' colspan='2' align='center'><a class='oysTextLink' id='oygCopyright' href=''>" + cr + "</a></tr>";



   _e += "</table>";



   document.getElementById("Footer").innerHTML = _e;



   document.getElementById("oygCopyright").onclick = function()



   {



      _d.menu.leaveGameEarly(_d.copyrightGameUrl);



      return false;







   }



   ;



 //  var _10 = "<img id='oygTrackAction' width='1px' height='1px'>";



 //  var _11 = document.getElementById("HeaderMenu");



 //  _11.innerHTML = "<a id=\"oygHeaderMenuBtn\" href=\"\"><img style=\"padding : 4px; \" src=\""+this.appHome+" / images / Codecrackerheader.jpg\" border=\"0\" alt=\"Image for CodeCracker\"></a>";



 //  document.getElementById("oygHeaderMenuBtn").onclick = function()



 //  {



 //     _d.menu.leaveGameEarly(_d.leaveGameUrl);



 //     return false;







  // }



  // ;



   this.footer = new CrossWordFooter(this);



   this.footer.stateBusy("Starting up...");



   this.menu = new CrosswordMenu(this);







}



;



CrosswordPuzzle.prototype.render = function()



{



   var buf = "";



   buf += "<table border='0' cellspacing='0' cellpadding='0' style='border-collapse: collapse;'>";



   for(var i = 0; i < this.h; i ++ )



   {



      var row = "<tr>";



      for(var j = 0; j < this.w; j ++ )



      {



         row += "<td class='ReadOnlyCell' id='oyCell"+j+"_"+i+"'></td>";







      }



      buf += row + "</tr>";







   }



   buf += "</table>";



   var _16 = 25;



   var _17 = 400;



   var _18 = this.w * _16;



   if(_18 < _17)



   {



      _18 = _17;







   }



   _18 += "px";



   var _19 = document.getElementById("PuzzleFooter");



   _19.style.width = _18;



   var _19 = document.getElementById("State");



   _19.style.width = _18;



   var _19 = document.getElementById("Puzzle");



   _19.style.width = _18;



   _19.innerHTML = buf;







   for(var i = 0; i < this.hlist.clues.length; i ++ )



   {



      this.renderHorz(this.hlist.clues[i]);







   }



   for(var i = 0; i < this.vlist.clues.length; i ++ )



   {



      this.renderVert(this.vlist.clues[i]);







   }



   



  



}



;



CrosswordPuzzle.prototype.renderVert = function(_1a)



{



   for(var i = 0; i < _1a.len; i ++ )



   {



      var key = "oyCell" + _1a.xpos + "_" + (_1a.ypos + i);



      var _1d = document.getElementById(key);



      _1d.className = "InputWhiteCell";







   }



}



;



CrosswordPuzzle.prototype.renderHorz = function(_1e)



{



   for(var i = 0; i < _1e.len; i ++ )



   {



      var key = "oyCell" + (_1e.xpos + i) + "_" + _1e.ypos;



      var _21 = document.getElementById(key);



      _21.className = "InputWhiteCell";







   }



}



;



CrosswordPuzzle.prototype.fillVert = function(_22, idx)



{



   for(var i = 0; i < _22.len; i ++ )



   {



      var key = "oyCell" + _22.xpos + "_" + (_22.ypos + i);



      var _26 = document.getElementById(key);



      this.fillIn(_26, _22.xpos, _22.ypos + i, i, idx, 1);



      this.menu.setCellState(_22.xpos, _22.ypos + i, 0);







   }



}



;



CrosswordPuzzle.prototype.fillHorz = function(_27, idx)



{



   for(var i = 0; i < _27.len; i ++ )



   {



      var key = "oyCell" + (_27.xpos + i) + "_" + _27.ypos;



      var _2b = document.getElementById(key);



      this.fillIn(_2b, _27.xpos + i, _27.ypos, i, idx, 0);



      this.menu.setCellState(_27.xpos + i, _27.ypos, 0);







   }



}



;



CrosswordPuzzle.prototype.fillIn = function(_2c, x, y, i, idx, dir)



{



   if(i == 0)



   {



      _2c.style.backgroundImage = "url(\""+this.appHome+" / img / "+(idx+1)+".gif\")";







   }



   _2c.innerHTML = "<input id='oyInput"+x+"_"+y+"' class='oyCellInput' autocomplete='off' type='text' size='1' maxlength='2' value=''>";







}



;



CrosswordPuzzle.prototype.bind = function()



{



   var _33 = 0;



   for(var i = 0; i < this.hlist.clues.length; i ++ )



   {



      this.fillHorz(this.hlist.clues[i], _33);



      _33 ++ ;







   }



   var _35 = 0;



   for(var i = 0; i < this.vlist.clues.length; i ++ )



   {



      this.fillVert(this.vlist.clues[i], _35);



      _35 ++ ;







   }



   



   this.codeCrackerGrid.render();



   



   



   for(var i = 0; i < 26; i ++ ){



     for (var j = 0; j < 2; j ++ ) 



       {



         this.codeCrackerGrid.fillCodeCracker(i, j);



       }



   }











   this.codeCrackerGrid.bind();



   



   for(var i = 0; i < 26; i ++ ){



     var _41 = this.codeCrackerGrid.inputCacheForCodeCracker.getElement(0,i);



     _41.value = String.fromCharCode(65 + i);



	 _41.readOnly = true;



   }







   this.inputCache = new oyGridElementCache(this.w, this.h, "oyInput");



   for(var i = 0; i < this.h; i ++ )



   {



      for(var j = 0; j < this.w; j ++ )



      {



         this.bindItem(j, i);



	       



      }



   }



   



   for(var i = 0; i < this.vlist.clues.length; i ++ )



   {



	 var numberList = this.vlist.clues[i].numberlist.split( "," );



	 for(j = 0; j < numberList.length; j++) {



	   var _42 = this.inputCache.getElement(this.vlist.clues[i].xpos,this.vlist.clues[i].ypos + j);  



	   if (_42 != null) {



	     _42.value = numberList[j];



	   }



     }







   }



   



   for(var i = 0; i < this.hlist.clues.length; i ++ )



   {



	 var numberList = this.hlist.clues[i].numberlist.split( "," );



	 for(j = 0; j < numberList.length; j++) {



	   var _42 = this.inputCache.getElement(this.hlist.clues[i].xpos + j,this.hlist.clues[i].ypos);  



	   if (_42 != null) {



	     _42.value = numberList[j];



	   }



     }







   }







   this.menu.bind();



   this.footer.bind();



   this.footer.update();



   this.started = true;







}



;



CrosswordPuzzle.prototype.unbind = function()



{



   for(var i = 0; i < this.h; i ++ )



   {



      for(var j = 0; j < this.w; j ++ )



      {



         var _39 = this.inputCache.getElement(j, i);



         if(_39 != null)



         {



            _39.onclick = null;



            _39.onkeydown = null;



            _39.onchange = null;







         }



      }



   }



   this.footer.unbind();



   this.menu.unbind();







}



;



CrosswordPuzzle.prototype.bindItem = function(x, y)



{



   var _3c = this.inputCache.getElement(x, y);



   if(_3c != null)



   {



      var _3d = this;



      _3c.onclick = function()



      {



         _3d.unfocusOldCell();



         _3d.focusNewCell(x, y, false);







      }



      ;



      _3c.onkeydown = function(e)



      {



         return _3d.handleKeyDown(x, y, e);







      }



      ;



      _3c.onkeypress = function(e)



      {



         return _3d.handleKeyPress(x, y, e);







      }



      ;







   }



}



;



CrosswordPuzzle.prototype.focusCellList = function(all, _45)



{



   for(var i = 0; i < all.length; i ++ )



   {



      var _47 = document.getElementById("oyCell" + all[i].x + "_" + all[i].y);



      var _48 = this.menu.getCellState(all[i].x, all[i].y);



      if(_47 != null)



      {



         if(_45 && _48 == 0)



         {



            _47.className = "FocusedCell";







         }



         else



         {



            this.restoreCellState(_47, all[i].x, all[i].y);







         }



      }



   }



}



;



CrosswordPuzzle.prototype.unfocusOldWord = function()



{



   if(this.focused != null)



   {



      this.focusCellList(this.menu.getCellPosListFor(this.focused), false);



      this.focused = null;







   }



}



;



CrosswordPuzzle.prototype.focusNewWord = function(x, y)



{



   var _4b = this.hlist.getClueIndexForPoint(x, y);



   var _4c = this.vlist.getClueIndexForPoint(x, y);



   var _4d = null;



   if(_4b != - 1 && _4c != - 1)



   {



      if(this.dir == 0)



      {



         _4d = this.hlist.clues[_4b];







      }



      else



      {



         _4d = this.vlist.clues[_4c];







      }



   }



   else



   {



      if(_4b != - 1)



      {



         _4d = this.hlist.clues[_4b];







      }



      if(_4c != - 1)



      {



         _4d = this.vlist.clues[_4c];







      }



   }



   return _4d;







}



;



CrosswordPuzzle.prototype.focusNewCell = function(x, y, _50, _51)



{



   if(_51 != null)



   {



      this.focused = _51;







   }



   else



   {



      this.focused = this.focusNewWord(x, y);







   }



   if(this.focused != null)



   {



      this.dir = this.focused.dir;



      this.focusCellList(this.menu.getCellPosListFor(this.focused), true);







   }



   var _52 = document.getElementById("oyCell" + x + "_" + y);



   if(_52 != null)



   {



      _52.className = "oyCellActive";



       if(_50)



      {



         var _52 = this.inputCache.getElement(x, y);



		 if (_52 != null) {



           _52.focus();



		 }







      }



   }



   if (_52 != null) {



     this.xpos = x;



     this.ypos = y;



     this.menu.focusNewCell(x, y);



     this.menu.invalidateMenu();



   }







}



;



CrosswordPuzzle.prototype.unfocusOldCell = function()



{



   var _53 = document.getElementById("oyCell" + this.xpos + "_" + this.ypos);



   if(_53 != null)



   {



      this.restoreCellState(_53, this.xpos, this.ypos);







   }



   this.unfocusOldWord();







}



;



CrosswordPuzzle.prototype.invalidate = function()



{



   this.unfocusOldCell();



   this.focusNewCell(this.xpos, this.ypos, true);







}



;



CrosswordPuzzle.prototype.restoreCellState = function(_54, x, y)



{



   var _57 = this.menu.getCellState(x, y);



   switch(_57)



   {



      case - 1 :



      _54.className = "ReadOnlyCell";



      break;



      case 0 :



      _54.className = "InputWhiteCell";



      break;



      case 1 :



      _54.className = "GuessedCell";



      break;



      case 2 :



      _54.className = "RevealedCell";



      break;



      default :



      alert("Bad state code!");







   }



}



;



CrosswordPuzzle.prototype.isValidChar = function(c)



{



   return (c >= "A" && c <= "Z") || c == " ";







}



;







CrosswordPuzzle.prototype.isValidNumber = function(c)



{



   return (c >= "0" && c <= "9");







}



;







CrosswordPuzzle.prototype.moveToPrevCell = function(x, y)



{



   if(this.dir == 0)



   {



      x -- ;







   }



   else



   {



      y -- ;







   }



   var _5b = this.menu.getCellState(x, y);



   if(_5b != - 1)



   {



      var _5c = this.inputCache.getElement(x, y);



      if(_5c != null)



      {



         this.unfocusOldCell();



         this.focusNewCell(x, y, false);



         _5c.focus();







      }



   }



}



;



CrosswordPuzzle.prototype.moveToNextCell = function(x, y)



{



   if(this.dir == 0)



   {



      x ++ ;







   }



   else



   {



      y ++ ;







   }



   var _5f = this.menu.getCellState(x, y);



   if(_5f != - 1)



   {



      var _60 = this.inputCache.getElement(x, y);



      if(_60 != null)



      {



         this.unfocusOldCell();



         this.focusNewCell(x, y, false);



         _60.focus();







      }



   }



}



;



CrosswordPuzzle.prototype.handleKeyPress = function(x, y, e)



{



   if( ! e)



   {



      e = window.event;







   }



   var _64 = (e.which) ? e.which : e.keyCode;



   var c = String.fromCharCode(_64).toUpperCase();



   if(_64 == 32)



   {



      c = " ";







   }



   if(this.isValidChar(c))



   {



      var _66 = this.inputCache.getElement(x, y);



      if( ! _66.readOnly)



      {



         _66.value = c.toUpperCase();







      }



      this.moveToNextCell(x, y);







   }  



   else if (this.isValidNumber(c))



   {



      var _66 = this.inputCache.getElement(x, y);



      if( ! _66.readOnly)



      {



         _66.value = c;



      }







   }



   return false;







}



;



CrosswordPuzzle.prototype.handleKeyDown = function(x, y, e)



{



   if( ! e)



   {



      e = window.event;







   }



   var _6a = (e.which) ? e.which : e.keyCode;



   var dir = (_6a >= 37 && _6a <= 40) || _6a == 8;



   if(dir)



   {



      var _6c = null;



      switch(_6a)



      {



         case 8 :



         this.moveToPrevCell(x, y);



         break;



         case 37 :



         while(true)



         {



            if(x > 0)



            {



               x = x - 1;



               _6c = this.inputCache.getElement(x, y);



               if(_6c != null)



               {



                  break;







               }



            }



            else



            {



               break;







            }



         }



         break;



         case 39 :



         while(true)



         {



            if(x < this.w - 1)



            {



               x = x + 1;



               _6c = this.inputCache.getElement(x, y);



               if(_6c != null)



               {



                  break;







               }



            }



            else



            {



               break;







            }



         }



         break;



         case 38 :



         while(true)



         {



            if(y > 0)



            {



               y = y - 1;



               _6c = this.inputCache.getElement(x, y);



               if(_6c != null)



               {



                  break;







               }



            }



            else



            {



               break;







            }



         }



         break;



         case 40 :



         while(true)



         {



            if(y < this.h - 1)



            {



               y = y + 1;



               _6c = this.inputCache.getElement(x, y);



               if(_6c != null)



               {



                  break;







               }



            }



            else



            {



               break;







            }



         }



         break;







      }



      if(_6c != null)



      {



         this.unfocusOldCell();



         this.focusNewCell(x, y, false);



         _6c.focus();







      }



   }



   return true;







}



;



function oygEndpoint()



{



   this.cookie = oygNextRandomInt();



   this.seq = 0;



   this.oob = 0;



   this.badcookie = 0;







}



oygEndpoint.noendpoint = 0;



function CompletionPort(_1, _2)



{



   this.endpoint = _1;



   _1.seq ++ ;



   this.seq = _1.seq;



   this.onError = null;



   this.onTimeout = null;



   this.onComplete = null;



   this.onDone = null;



   this.timeout = 15 * 1000;



   this.ajax = new JSONscriptRequest(_2);

   

}



CompletionPort.prototype.init = function()



{



   this.ajax.init();



   var _3 = this;



   this.timer = setTimeout(function()



   {



      var _4 = _3.onTimeout;



      _3.finit();



      if(_4 != null)



      {



         _4();







      }



   }



   , this.timeout);



   this.ajax.submit();







}



;



CompletionPort.prototype.finit = function()



{



   this.onError = null;



   this.onTimeout = null;



   this.onComplete = null;



   this.ajax.finit();



   this.ajax = null;



   clearTimeout(this.timer);



   this.timer = null;







}



;



function Server(_5, ns)



{



   this.appHome = _5;



   this.ns = ns;



   this.ep = new oygEndpoint();



   this.md5 = new oySign();



   this.trackSeq = 0;



//   this.trackURL = this.appHome + "/app/trackAction.php";



   this.submitURL = this.appHome + "/app/submitScore2.php";







}



Server.prototype.computeMatrix = function(_7)



{



   var _8 = new function()



   {



   }



   ;



   var _9 = "";



   var _a = "";



   for(var i = 0; i < _7.length; i ++ )



   {



      if(_7[i].matched)



      {



         _a += "1";



         _9 += _7[i].answer;







      }



      else



      {



         _a += "0";







      }



   }



   _8.states = _a;



   _8.concat = _9;



   return _8;







}



;



// Server.prototype.trackAction = function(_c, _d)



// {



   // if(_d != null)



   // {



      // var _e = escape(_c);



      // var _f = "uid=" + _e + "&ns=" + escape(this.ns) + "&verb=" + escape(_d);



      // var _10 = this.md5.hex_hmac_md5(_e, _f);



      // var _11 = "data=" + escape(_f) + "&sign=" + _10 + "&seq=" + this.trackSeq;



      // var url = this.trackURL + "?" + _11;



      // document.getElementById("oygTrackAction").src = url;



      // this.trackSeq ++ ;







   // }



// }



// ;



Server.prototype.submitScore = function(_13, _15, _19, nameOfUser)



{
   var url = this.submitURL + "?" + "name=" + nameOfUser + "&score=" + _15;

   this.submitScoreAjaxAnywhere(this.ep, _13, url, _19, _15);

};



Server.prototype.submitScoreAjaxAnywhere = function(ep, _25, url, _27, score)



{

   var _28 = _25;



   var cp = new CompletionPort(ep, url);



   cp.onComplete = function()



   {



      _28.scoreSubmittedMatches = _27;
	  
      _28.invalidateMenu();
  
   }



   ;



   cp.onTimeout = function()



   {



      _28.footer.stateError("Timeout waiting for server to reply!"); alert("Failed to submit score. Server didn't reply!");







   }



   ;



   cp.onError = function(msg)



   {



      _28.footer.stateError("Failed to submit score!");



      alert("Failed to submit score. Server replied with:\n\n" + msg);







   }



   ;



   oygSubmitScoreCompletionPoint = cp;



   cp.init();

   cp.oygSubmitScoreJSONComplete();







}



;





CompletionPort.prototype.oygSubmitScoreJSONComplete = function()

{

//   var oygSubmitScoreCompletionPoint;



   //var cp = oygSubmitScoreCompletionPoint;



   if(this != null)



   {



		var _2f = this.onComplete;



		var _30 = this.onError;



		this.finit();





		   if(_2f != null)



		   {



			  _2f();







		   }





    }

}



function oySign()



{



   this.hexcase = 0;



   this.b64pad = "";



   this.chrsz = 8;



   this.calculate = function(s)



   {



      return this.hex_md5(s);







   }



   ;



   this.test = function(s)



   {



      return this.md5_vm_test();







   }



   ;







}



oySign.prototype.hex_md5 = function(s)



{



   return this.binl2hex(this.core_md5(this.str2binl(s), s.length * this.chrsz));







}



;



oySign.prototype.b64_md5 = function(s)



{



   return this.binl2b64(this.core_md5(this.str2binl(s), s.length * this.chrsz));







}



;



oySign.prototype.str_md5 = function(s)



{



   return this.binl2str(this.core_md5(this.str2binl(s), s.length * this.chrsz));







}



;



oySign.prototype.hex_hmac_md5 = function(_6, _7)



{



   return this.binl2hex(this.core_hmac_md5(_6, _7));







}



;



oySign.prototype.b64_hmac_md5 = function(_8, _9)



{



   return this.binl2b64(this.core_hmac_md5(_8, _9));







}



;



oySign.prototype.str_hmac_md5 = function(_a, _b)



{



   return this.binl2str(this.core_hmac_md5(_a, _b));







}



;



oySign.prototype.md5_vm_test = function()



{



   return this.hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";







}



;



oySign.prototype.core_md5 = function(x, _d)



{



   x[_d >> 5] |= 128 << ((_d) % 32);



   x[(((_d + 64) >>> 9) << 4) + 14] = _d;



   var a = 1732584193;



   var b = - 271733879;



   var c = - 1732584194;



   var d = 271733878;



   for(var i = 0; i < x.length; i += 16)



   {



      var _13 = a;



      var _14 = b;



      var _15 = c;



      var _16 = d;



      a = this.md5_ff(a, b, c, d, x[i + 0], 7, - 680876936);



      d = this.md5_ff(d, a, b, c, x[i + 1], 12, - 389564586);



      c = this.md5_ff(c, d, a, b, x[i + 2], 17, 606105819);



      b = this.md5_ff(b, c, d, a, x[i + 3], 22, - 1044525330);



      a = this.md5_ff(a, b, c, d, x[i + 4], 7, - 176418897);



      d = this.md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);



      c = this.md5_ff(c, d, a, b, x[i + 6], 17, - 1473231341);



      b = this.md5_ff(b, c, d, a, x[i + 7], 22, - 45705983);



      a = this.md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);



      d = this.md5_ff(d, a, b, c, x[i + 9], 12, - 1958414417);



      c = this.md5_ff(c, d, a, b, x[i + 10], 17, - 42063);



      b = this.md5_ff(b, c, d, a, x[i + 11], 22, - 1990404162);



      a = this.md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);



      d = this.md5_ff(d, a, b, c, x[i + 13], 12, - 40341101);



      c = this.md5_ff(c, d, a, b, x[i + 14], 17, - 1502002290);



      b = this.md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);



      a = this.md5_gg(a, b, c, d, x[i + 1], 5, - 165796510);



      d = this.md5_gg(d, a, b, c, x[i + 6], 9, - 1069501632);



      c = this.md5_gg(c, d, a, b, x[i + 11], 14, 643717713);



      b = this.md5_gg(b, c, d, a, x[i + 0], 20, - 373897302);



      a = this.md5_gg(a, b, c, d, x[i + 5], 5, - 701558691);



      d = this.md5_gg(d, a, b, c, x[i + 10], 9, 38016083);



      c = this.md5_gg(c, d, a, b, x[i + 15], 14, - 660478335);



      b = this.md5_gg(b, c, d, a, x[i + 4], 20, - 405537848);



      a = this.md5_gg(a, b, c, d, x[i + 9], 5, 568446438);



      d = this.md5_gg(d, a, b, c, x[i + 14], 9, - 1019803690);



      c = this.md5_gg(c, d, a, b, x[i + 3], 14, - 187363961);



      b = this.md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);



      a = this.md5_gg(a, b, c, d, x[i + 13], 5, - 1444681467);



      d = this.md5_gg(d, a, b, c, x[i + 2], 9, - 51403784);



      c = this.md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);



      b = this.md5_gg(b, c, d, a, x[i + 12], 20, - 1926607734);



      a = this.md5_hh(a, b, c, d, x[i + 5], 4, - 378558);



      d = this.md5_hh(d, a, b, c, x[i + 8], 11, - 2022574463);



      c = this.md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);



      b = this.md5_hh(b, c, d, a, x[i + 14], 23, - 35309556);



      a = this.md5_hh(a, b, c, d, x[i + 1], 4, - 1530992060);



      d = this.md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);



      c = this.md5_hh(c, d, a, b, x[i + 7], 16, - 155497632);



      b = this.md5_hh(b, c, d, a, x[i + 10], 23, - 1094730640);



      a = this.md5_hh(a, b, c, d, x[i + 13], 4, 681279174);



      d = this.md5_hh(d, a, b, c, x[i + 0], 11, - 358537222);



      c = this.md5_hh(c, d, a, b, x[i + 3], 16, - 722521979);



      b = this.md5_hh(b, c, d, a, x[i + 6], 23, 76029189);



      a = this.md5_hh(a, b, c, d, x[i + 9], 4, - 640364487);



      d = this.md5_hh(d, a, b, c, x[i + 12], 11, - 421815835);



      c = this.md5_hh(c, d, a, b, x[i + 15], 16, 530742520);



      b = this.md5_hh(b, c, d, a, x[i + 2], 23, - 995338651);



      a = this.md5_ii(a, b, c, d, x[i + 0], 6, - 198630844);



      d = this.md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);



      c = this.md5_ii(c, d, a, b, x[i + 14], 15, - 1416354905);



      b = this.md5_ii(b, c, d, a, x[i + 5], 21, - 57434055);



      a = this.md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);



      d = this.md5_ii(d, a, b, c, x[i + 3], 10, - 1894986606);



      c = this.md5_ii(c, d, a, b, x[i + 10], 15, - 1051523);



      b = this.md5_ii(b, c, d, a, x[i + 1], 21, - 2054922799);



      a = this.md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);



      d = this.md5_ii(d, a, b, c, x[i + 15], 10, - 30611744);



      c = this.md5_ii(c, d, a, b, x[i + 6], 15, - 1560198380);



      b = this.md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);



      a = this.md5_ii(a, b, c, d, x[i + 4], 6, - 145523070);



      d = this.md5_ii(d, a, b, c, x[i + 11], 10, - 1120210379);



      c = this.md5_ii(c, d, a, b, x[i + 2], 15, 718787259);



      b = this.md5_ii(b, c, d, a, x[i + 9], 21, - 343485551);



      a = this.safe_add(a, _13);



      b = this.safe_add(b, _14);



      c = this.safe_add(c, _15);



      d = this.safe_add(d, _16);







   }



   return new Array(a, b, c, d);







}



;



oySign.prototype.md5_cmn = function(q, a, b, x, s, t)



{



   return this.safe_add(this.bit_rol(this.safe_add(this.safe_add(a, q), this.safe_add(x, t)), s), b);







}



;



oySign.prototype.md5_ff = function(a, b, c, d, x, s, t)



{



   return this.md5_cmn((b & c) | (( ~ b) & d), a, b, x, s, t);







}



;



oySign.prototype.md5_gg = function(a, b, c, d, x, s, t)



{



   return this.md5_cmn((b & d) | (c & ( ~ d)), a, b, x, s, t);







}



;



oySign.prototype.md5_hh = function(a, b, c, d, x, s, t)



{



   return this.md5_cmn(b ^ c ^ d, a, b, x, s, t);







}



;



oySign.prototype.md5_ii = function(a, b, c, d, x, s, t)



{



   return this.md5_cmn(c ^ (b | ( ~ d)), a, b, x, s, t);







}



;



oySign.prototype.core_hmac_md5 = function(key, _3a)



{



   var _3b = this.str2binl(key);



   if(_3b.length > 16)



   {



      _3b = this.core_md5(_3b, key.length * this.chrsz);







   }



   var _3c = new Array(16), opad = new Array(16);



   for(var i = 0; i < 16; i ++ )



   {



      _3c[i] = _3b[i] ^ 909522486;



      opad[i] = _3b[i] ^ 1549556828;







   }



   var _3e = this.core_md5(_3c.concat(this.str2binl(_3a)), 512 + _3a.length * this.chrsz);



   return this.core_md5(opad.concat(_3e), 512 + 128);







}



;



oySign.prototype.safe_add = function(x, y)



{



   var lsw = (x & 65535) + (y & 65535);



   var msw = (x >> 16) + (y >> 16) + (lsw >> 16);



   return (msw << 16) | (lsw & 65535);







}



;



oySign.prototype.bit_rol = function(num, cnt)



{



   return (num << cnt) | (num >>> (32 - cnt));







}



;



oySign.prototype.str2binl = function(str)



{



   var bin = new Array();



   var _47 = (1 << this.chrsz) - 1;



   for(var i = 0; i < str.length * this.chrsz; i += this.chrsz)



   {



      bin[i >> 5] |= (str.charCodeAt(i / this.chrsz) & _47) << (i % 32);







   }



   return bin;







}



;



oySign.prototype.binl2str = function(bin)



{



   var str = "";



   var _4b = (1 << this.chrsz) - 1;



   for(var i = 0; i < bin.length * 32; i += this.chrsz)



   {



      str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & _4b);







   }



   return str;







}



;



oySign.prototype.binl2hex = function(_4d)



{



   var _4e = this.hexcase ? "0123456789ABCDEF" : "0123456789abcdef";



   var str = "";



   for(var i = 0; i < _4d.length * 4; i ++ )



   {



      str += _4e.charAt((_4d[i >> 2] >> ((i % 4) * 8 + 4)) & 15) + _4e.charAt((_4d[i >> 2] >> ((i % 4) * 8)) & 15);







   }



   return str;







}



;



oySign.prototype.binl2b64 = function(_51)



{



   var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";



   var str = "";



   for(var i = 0; i < _51.length * 4; i += 3)



   {



      var _55 = (((_51[i >> 2] >> 8 * (i % 4)) & 255) << 16) | (((_51[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 255) << 8) | ((_51[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 255);



      for(var j = 0; j < 4; j ++ )



      {



         if(i * 8 + j * 6 > _51.length * 32)



         {



            str += this.b64pad;







         }



         else



         {



            str += tab.charAt((_55 >> 6 * (3 - j)) & 63);







         }



      }



   }



   return str;







}



;




