var carray = ['#ccffcc', '#ffffcc','#ccccff','#00ff00','#eecc44','#ffcccc','#ff9933', '#ff9999', '#ffff33', '#99ffff', '#0099ff', '#99ffcc','#ff99cc','#cccc99','#ccff00','#cccccc','#ff9999','#993399','#999999','#ffffff',];
function placevalues() {

for (var i =0; i < 9; i++) {
	for (var j =0; j < 9; j++) {
if (spos[i][j]) {
var setvalue = document.getElementById("cell"+[i]+[j]);
setvalue.value = spos[i][j];

//setvalue.readOnly = true;
}
if (scol[i][j]) {
var startcol = document.getElementById("cell"+[i]+[j]);
var gc = scol[i][j];
startcol.style.background = carray[gc-1];
document.getElementById("td"+[i]+[j]).style.background = carray[gc-1];
}
//countup = countup + 1;
}
}


} //close function

var countup = 0;
function showsolution() {
var allInputs = document.getElementsByTagName("input");
for (var i =0; i < 9; i++) {
	for (var j =0; j < 9; j++) {
if (allInputs[countup].type=="text") {
//allInputs[countup].style.color = inputlettersol;
allInputs[countup].value = cells[i][j];
allInputs[countup].style.color = '#000000';
//allInputs[countup].style.fontSize = "14pt";
allInputs[countup].style.fontStyle = "normal";
}
countup = countup + 1;
}
}
countup = 0;
}

function showsindiv() {
var thisone = document.getElementById("show00");
var that = thisone.innerHTML;
alert (that);
thisone.style.background = "#ccffcc";

}

function checksolution() {
var allInputs = document.getElementsByTagName("input");
for (var i =0; i < 9; i++) {
	for (var j =0; j < 9; j++) {
if (allInputs[countup].type=="text") {

if (cells[i][j] == allInputs[countup].value) {

}
else {
var mistakes = "1";
}
}
countup = countup + 1;
}
}
countup = 0;
if (!mistakes) {
alert ("Congratulations! You got the answer right!");
}
else {
alert ("Sorry, your answer is not currently correct");
}
mistakes = 0;
}

function resetgrid() {

var allInputs = document.getElementsByTagName("input");
for (var i =0; i < 9; i++) {
	for (var j =0; j < 9; j++) {
if (allInputs[countup].type=="text") {
allInputs[countup].value = '';
}
countup = countup + 1;
}
}
countup = 0;
placevalues();
}

function helpcell() {

}
function savelastmove() {

}

//
var font, fcolor, setcheckval;
function showmistakes(thisrow,thiscol) {
// nb re lower case
if (thisrow == "9") {
}

else {
var thisref = document.getElementById("cell"+thisrow+thiscol);
//alert (thisref.value.length);
if (thisref.value.length > 1)  {
// update font size to smaller
thisref.style.fontSize = "10pt";
} // greater than 1
else {
thisref.style.fontSize = "14pt";
}
}

var allInputs = document.getElementsByTagName("input");
if (document.sudokucheck.iswrong.checked) {
font = 'italic';
setcheckval = 1;

}
else {
font = 'normal';
setcheckval = 0;
}
var usehere = -1;
for (var i =0; i < 9; i++) {
for (var j = 0; j < 9; j++) {
usehere = usehere + 1;
if (allInputs[usehere].type=="text") {
if (allInputs[usehere].value != "") {
if (allInputs[usehere].value == cells[i][j]) {
allInputs[usehere].style.fontStyle = "normal";
allInputs[usehere].style.color = "black";
}
else {
//
if (allInputs[usehere].value.length < 2) {
allInputs[usehere].style.fontStyle = font;
if (setcheckval) {
allInputs[usehere].style.color = "red";
}
//
}
else {
allInputs[usehere].style.fontStyle = "normal";
allInputs[usehere].style.color = "black";
						}
					}
				}

			}

		}
	}
usehere = 0;
}
function colchange(thecol) {
var thepat =[0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0];
var setcount = -1;
if (thecol == "green") { setnew = "#99FF33"; setnewb = "#CCFFCC"; setnewc = "#33FF99";}
if (thecol == "blue") { setnew = "#CCFFFF"; setnewb = "#6699CC"; setnewc = "#99CCFF";}
if (thecol == "yellow") { setnew = "#FFFFCC"; setnewb = "#CCCC66"; setnewc = "#FFFF33";}
if (thecol == "pink") { setnew = "#FFCCCC"; setnewb = "#CC9999"; setnewc = "#FF99CC";}

if(document.getElementsByTagName)//check for obj
   {
   var nodes = document.getElementsByTagName("td")
   var max = nodes.length
   for(var i = 0;i < max;i++)
      {
      var nodeObj = nodes.item(i);
      var attrMax = nodeObj.attributes.length
      for(var j = 0; j < attrMax; j++)
         {
          if(nodeObj.attributes.item(j).nodeName == 'class')
             {

             if(nodeObj.attributes.item(j).nodeValue == "midletter" || nodeObj.attributes.item(j).nodeValue == "midletterx") { setcount++;
            // alert(nodeObj.attributes.item(j).nodeValue);
            if (thepat[setcount] == '1') { nodeObj.style.background = setnew; }
            else if (thepat[setcount] == '2')   { nodeObj.style.background = setnewc;} 
            else {nodeObj.style.background = setnewb; }
            }
             if(nodeObj.attributes.item(j).nodeValue == "topletter" || nodeObj.attributes.item(j).nodeValue == "topletterx") { setcount++;
            // alert(nodeObj.attributes.item(j).nodeValue);
	                  if (thepat[setcount] == '1') { nodeObj.style.background = setnew; }
	                    else if (thepat[setcount] == '2')   { nodeObj.style.background = setnewc;} 
            else {nodeObj.style.background = setnewb; }
			}



             }

         }
      }
   }




var allInputs = document.getElementsByTagName("input");
for (var i =0; i < 81; i++) {

if (allInputs[i].type=="text" && allInputs[i].size=="1") {

 if (thepat[i] == '1') {allInputs[i].style.background = setnew;} 
else if (thepat[i] == '2') {allInputs[i].style.background = setnewc;} else {allInputs[i].style.background = setnewb;}

}
}


}//close fx
