/***********************************************
* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

function createTable()
{
  var letters = "GSTHGINKOPELL FABEIBMOZRLIMASONCISHAMANHNDRAZIWECLERICNRVAMPIRED";
  var table = "<TABLE ID='puzzle' STYLE='cursor:hand; color:#aaaaaa;'>";
  for(var j=0;j<8;j++)
  {
    table += "<TR>";
    for(var i=0;i<8;i++)
      table += "<TD id=\'cell" + (j*8+i) +
               "\' onclick=\'mouse(" + (j*8+i) + 
               ")\' align=\'center\' style=\'border:outset medium; width:16px;\'>" +
               letters.charAt(j*8+i) + "</TD>";
    table += "</TR>";
  }
  table += "</TABLE><P ID=\'answer\'>First Unselected: <B>GSTHGINKOP</B></P>";
  return table;
}

function updateAnswer()
{
  var answer = "First Unselected: <B>";
  var length = 0;
  for(var j=0;j<8;j++)
    for(var i=0;i<8;i++)
    {
      var id = "cell"+(j*8+i);
      var td = document.getElementById(id);
      if(td.style.backgroundColor != "#aaaaaa")
      { 
        answer += td.innerHTML;
	if(td.innerHTML.length == 0) answer += "&nbsp;";
        length += 1;
        if(length >= 10) i = j = 1000;
      }
    }
  answer += "</B>";
  document.getElementById("answer").innerHTML = answer;
}

function mouse(cell)
{
  var id = "cell"+cell;
  var td = document.getElementById(id);
  if(td.style.backgroundColor != "#aaaaaa")
    td.style.backgroundColor = "#aaaaaa";
  else
    td.style.backgroundColor = "#000000";    
  updateAnswer();
}

function addPuzzle()
{
  var table = createTable();
  document.write(table);
  disableSelection(document.getElementById("puzzle"));
}
