var grid=1;
var gridPos=1;
var timerPaused = false;
var InValidGrids=0;
var InValidRowsAndCols=0;
var buildStr='';
totalScore= null;

function init(){
clearGrid();
clearGridStates();
readURL();
grid=1;
gridPos=1;
try{
document.getElementById('tf_g'+grid+'f'+gridPos).focus();
document.getElementById('tf_g'+grid+'f'+gridPos).style.backgroundColor="#cecece";
document.getElementById('g'+grid+'f'+gridPos).style.backgroundColor="#cecece";
}catch(errorObject){}
}

function keyListener(e){
	clearGridStates();
	var showStates=true;
   if(!e){
      e = window.event;
   }
   if((e.keyCode > 96 && e.keyCode < 106)||(e.keyCode > 47 && e.keyCode < 60)){
	if(!(document.getElementById('tf_g'+grid+'f'+gridPos).disabled)){
	 	document.getElementById('tf_g'+grid+'f'+gridPos).value='';
	 }else{
	 	document.getElementById('hiddenfield').focus();
		showStates=false;
	 }
	}
 	if(e.keyCode==13 || e.keyCode==37 || e.keyCode==38 || e.keyCode==39 || e.keyCode==40 ){	 
	 if(e.keyCode==13 ){ 
			 if (getGrid() + 1 < 10){setGrid(getGrid()+1);
			 }else{setGrid(1);
			 }
			}
		   if(e.keyCode==37 ){
			 gridPos--;
			 if (gridPos == 6){ gridPos=9; grid--; if (grid < 1){grid=1;gridPos=7;}}
			 if (gridPos == 3){ gridPos=6; grid--; if (grid < 1){grid=1;gridPos=4;}}
			 if (gridPos == 0){ gridPos=3; grid--; if (grid < 1){grid=1;gridPos=1;}}
		   }
		   if(e.keyCode==39 ){
			  gridPos= gridPos + 1;
			   if (gridPos == 4) {gridPos=1; grid++;if (grid > 9){grid=9;gridPos=3;}}
			   if (gridPos == 7) {gridPos=4; grid++;if (grid > 9){grid=9;gridPos=6;}}
			   if (gridPos == 10) {gridPos=7; grid++;if (grid > 9){grid=9;gridPos=9;}}
		   }
		   if(e.keyCode==40 ){
			  if (gridPos + 3 < 10  ){gridPos = gridPos+3;}else{grid=grid+3; gridPos=gridPos-6; if (grid-3 == 7){grid=2;} if (grid-3 == 8){grid=3;} if (grid-3 == 9){grid=9; gridPos=gridPos+6;}}
		   }
		   if(e.keyCode==38 ){
			  if (gridPos-3 > 0) {gridPos = gridPos-3;}else{grid=grid-3; gridPos=gridPos+6; if (grid+3 == 3){grid=9;} if (grid+3 == 2){grid=8;} if (grid+3 == 1){grid=1; gridPos=gridPos-6;} }
		   }
		 try{
		 	document.getElementById('tf_g'+grid+'f'+gridPos).focus();
		
		  }catch(errorObject){
		  	document.getElementById('hiddenfield').focus();
		  	showStates=false;
	  }
	}
	
	if(showStates){
		showState();
		var temptimer=setTimeout("showState()",50);
	}
	return true;
}
	


function showState(){
	document.getElementById('grid'+grid).style.borderColor="#00f";
	checkSelectedRow();
	checkSelectedCol(); 	
	checkAndShow(1,2,3,1,2,3,'#fcc', 'transparent');
	checkAndShow(4,5,6,1,2,3,'#fcc', 'transparent');
	checkAndShow(7,8,9,1,2,3,'#fcc', 'transparent');
	checkAndShow(1,2,3,4,5,6,'#fcc', 'transparent');
	checkAndShow(4,5,6,4,5,6,'#fcc', 'transparent');
	checkAndShow(7,8,9,4,5,6,'#fcc', 'transparent');
	checkAndShow(1,2,3,7,8,9,'#fcc', 'transparent');
	checkAndShow(4,5,6,7,8,9,'#fcc', 'transparent');
	checkAndShow(7,8,9,7,8,9,'#fcc', 'transparent');
	checkAndShow(1,4,7,1,4,7,'#fcc', 'transparent');
	checkAndShow(2,5,8,1,4,7,'#fcc', 'transparent');
	checkAndShow(3,6,9,1,4,7,'#fcc', 'transparent');
	checkAndShow(1,4,7,2,5,8,'#fcc', 'transparent');
	checkAndShow(2,5,8,2,5,8,'#fcc', 'transparent');
	checkAndShow(3,6,9,2,5,8,'#fcc', 'transparent');
	checkAndShow(1,4,7,3,6,9,'#fcc', 'transparent');
	checkAndShow(2,5,8,3,6,9,'#fcc', 'transparent');
	checkAndShow(3,6,9,3,6,9,'#fcc', 'transparent');
	checkAndShowAllGrid(1,'#fcc', 'transparent');
	checkAndShowAllGrid(2,'#fcc', 'transparent');
	checkAndShowAllGrid(3,'#fcc', 'transparent');
	checkAndShowAllGrid(4,'#fcc', 'transparent');
	checkAndShowAllGrid(5,'#fcc', 'transparent');
	checkAndShowAllGrid(6,'#fcc', 'transparent');
	checkAndShowAllGrid(7,'#fcc', 'transparent');
	checkAndShowAllGrid(8,'#fcc', 'transparent');
	checkAndShowAllGrid(9,'#fcc', 'transparent');
	document.getElementById('tf_g'+grid+'f'+gridPos).style.backgroundColor="#aaa";
	document.getElementById('g'+grid+'f'+gridPos).style.backgroundColor="#aaa";
}

function getGridPosition(){
	return gridPos;
}

function resetGridPosition(){
	gridPos = 1;
}

function setGridPosition(pos){
	gridPos = pos;
}

function getGrid(){
	return grid;
}

function resetGrid(){
	grid = 1;
}

function setGrid(pos){
	grid = pos;
}

function clearGridStates(){
	for(x=1; x<10; x++){
	document.getElementById('grid'+x).style.borderColor="#666";
		for(y=1; y<10; y++){									  								     
    		document.getElementById('tf_g'+x+'f'+y).style.backgroundColor='transparent';     
			document.getElementById('g'+x+'f'+y).style.backgroundColor='transparent';
		}
	}
}

function clearGrid(){
	for(x=1; x<10; x++){
		for(y=1; y<10; y++){									  								     
    		document.getElementById('tf_g'+x+'f'+y).value='';     
		}
	}
}

function enableGrid(){
	for(x=1; x<10; x++){
		for(y=1; y<10; y++){									  								     
    		document.getElementById('tf_g'+x+'f'+y).disabled=false;   
			document.getElementById('g'+x+'f'+y).innerHTML = '<input type="text" id="tf_g'+x+'f'+y+'" class="textfield" tabindex="1" onfocus="setGrid('+x+');setGridPosition('+y+')" onclick="clearGridStates();showState();" value=""  /></div>'; 
		}
	}
}

function countEmptyGridFields(){
var emptyFields=0;
	for(x=1; x<10; x++){
		for(y=1; y<10; y++){									  								     
    		if(document.getElementById('tf_g'+x+'f'+y).value=='') emptyFields++;     
		}
	}
return emptyFields;	
}

function checkAndShowAllGrid(gridnum, activecolor, inactivecolor){
	var grd;
	var tempArrayG=new Array;
	for(y=1; y<10; y++){
			if (document.getElementById('tf_g'+gridnum+'f'+y).value != '') tempArrayG.push(document.getElementById('tf_g'+gridnum+'f'+y).value);
		}
			grd = checkDubbles(tempArrayG);
			var color=inactivecolor;
			if(grd){
				color=activecolor;
				InValidGrids++;
			}
			if (color != 'transparent'){
			document.getElementById('tf_g'+gridnum+'f1').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f1').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f2').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f2').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f3').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f3').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f4').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f4').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f5').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f5').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f6').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f6').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f7').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f7').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f8').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f8').style.backgroundColor=color;
			document.getElementById('tf_g'+gridnum+'f9').style.backgroundColor=color;
			document.getElementById('g'+gridnum+'f9').style.backgroundColor=color;
			}
			var clearArrayG = new Array();
			tempArrayG=clearArrayG;	
	
}

function checkAndShow(x,y,z,gx,gy,gz, activecolor, inactivecolor){
 	var row;
	var tempArray=new Array;
	if (document.getElementById('tf_g'+gx+'f'+x).value != '') tempArray.push(document.getElementById('tf_g'+gx+'f'+x).value);
	if (document.getElementById('tf_g'+gx+'f'+y).value != '') tempArray.push(document.getElementById('tf_g'+gx+'f'+y).value);
	if (document.getElementById('tf_g'+gx+'f'+z).value != '') tempArray.push(document.getElementById('tf_g'+gx+'f'+z).value);
	if (document.getElementById('tf_g'+gy+'f'+x).value != '') tempArray.push(document.getElementById('tf_g'+gy+'f'+x).value);
	if (document.getElementById('tf_g'+gy+'f'+y).value != '') tempArray.push(document.getElementById('tf_g'+gy+'f'+y).value);
	if (document.getElementById('tf_g'+gy+'f'+z).value != '') tempArray.push(document.getElementById('tf_g'+gy+'f'+z).value);
	if (document.getElementById('tf_g'+gz+'f'+x).value != '') tempArray.push(document.getElementById('tf_g'+gz+'f'+x).value);
	if (document.getElementById('tf_g'+gz+'f'+y).value != '') tempArray.push(document.getElementById('tf_g'+gz+'f'+y).value);
	if (document.getElementById('tf_g'+gz+'f'+z).value != '') tempArray.push(document.getElementById('tf_g'+gz+'f'+z).value);
	row = checkDubbles(tempArray);
	var color=inactivecolor;
	if(row){
		color=activecolor;
		InValidRowsAndCols++;
	}
	if (color != 'transparent'){
	document.getElementById('tf_g'+gx+'f'+x).style.backgroundColor=color;
	document.getElementById('g'+gx+'f'+x).style.backgroundColor=color;
	document.getElementById('tf_g'+gx+'f'+y).style.backgroundColor=color;
	document.getElementById('g'+gx+'f'+y).style.backgroundColor=color;
	document.getElementById('tf_g'+gx+'f'+z).style.backgroundColor=color;
	document.getElementById('g'+gx+'f'+z).style.backgroundColor=color;
	document.getElementById('tf_g'+gy+'f'+x).style.backgroundColor=color;
	document.getElementById('g'+gy+'f'+x).style.backgroundColor=color;
	document.getElementById('tf_g'+gy+'f'+y).style.backgroundColor=color;
	document.getElementById('g'+gy+'f'+y).style.backgroundColor=color;
	document.getElementById('tf_g'+gy+'f'+z).style.backgroundColor=color;
	document.getElementById('g'+gy+'f'+z).style.backgroundColor=color;
	document.getElementById('tf_g'+gz+'f'+x).style.backgroundColor=color;
	document.getElementById('g'+gz+'f'+x).style.backgroundColor=color;
	document.getElementById('tf_g'+gz+'f'+y).style.backgroundColor=color;
	document.getElementById('g'+gz+'f'+y).style.backgroundColor=color;
	document.getElementById('tf_g'+gz+'f'+z).style.backgroundColor=color;
	document.getElementById('g'+gz+'f'+z).style.backgroundColor=color;
	}
	var clearArray = new Array();
	tempArray=clearArray;
}


function checkDubbles(darray){
var isDubble=false;
var carray  = new Array();
carray  =  darray;
var clearArray = new Array();
	if(darray.length >0){
	for(x=0; x<darray.length; x++){
	var cnt=0;
		for(c=0; c<carray.length; c++){
			if (carray[c]==darray[x]) cnt++;
			if (cnt > 1){ 
				isDubble=true;
				break;
			}	
		}
		
	}
	}
carray = clearArray; 	
return isDubble;	
}

function checkSelectedRow(){
	var x=0; var y=0; var z=0; var gx=0; var gy=0; var gz=0;
	if (grid == 1 || grid == 2 || grid == 3){
		if (gridPos ==1 || gridPos ==2 || gridPos ==3){
			row = 1;
			x=1; y=2; z=3;
			gx=1; gy=2; gz=3;
		}
		if (gridPos ==4 || gridPos ==5 || gridPos ==6){
			row = 2;
			x=4; y=5; z=6;
			gx=1; gy=2; gz=3;
		}
		if (gridPos ==7 || gridPos ==8 || gridPos ==9){
			row = 3;
			x=7; y=8; z=9;
			gx=1; gy=2; gz=3;
		}
		
	}
	if (grid == 4 || grid == 5 || grid == 6){
		if (gridPos ==1 || gridPos ==2 || gridPos ==3){
			row = 4;
			x=1; y=2; z=3;
			gx=4; gy=5; gz=6;
		}
		if (gridPos ==4 || gridPos ==5 || gridPos ==6){
			row = 5;
			x=4; y=5; z=6;
			gx=4; gy=5; gz=6;
		}
		if (gridPos ==7 || gridPos ==8 || gridPos ==9){
			row = 6;
			x=7; y=8; z=9;
			gx=4; gy=5; gz=6;
		}
	}
	if (grid == 7 || grid == 8 || grid == 9){
		if (gridPos ==1 || gridPos ==2 || gridPos ==3){
			row = 7;
			x=1; y=2; z=3;
			gx=7; gy=8; gz=9;
		}
		if (gridPos ==4 || gridPos ==5 || gridPos ==6){
			row = 8;
			x=4; y=5; z=6;
			gx=7; gy=8; gz=9;
		}
		if (gridPos ==7 || gridPos ==8 || gridPos ==9){
			row = 9;
			x=7; y=8; z=9;
			gx=7; gy=8; gz=9;
		}
	}
	checkAndShow(x,y,z,gx,gy,gz, '#fcc', '#ddd');
}


function checkSelectedCol(){
	var col;
	var x=0; var y=0; var z=0; var gx=0; var gy=0; var gz=0;
	if (grid == 1 || grid == 4 || grid == 7){
		if (gridPos ==1 || gridPos ==4 || gridPos ==7){
			col = 1;
			x=1; y=4; z=7;
			gx=1; gy=4; gz=7;
		}
		if (gridPos ==2 || gridPos ==5 || gridPos ==8){
			col = 2;
			x=2; y=5; z=8;
			gx=1; gy=4; gz=7;
		}
		if (gridPos ==3 || gridPos ==6 || gridPos ==9){
			col = 3;
			x=3; y=6; z=9;
			gx=1; gy=4; gz=7;
		}
	}
	if (grid == 2 || grid == 5 || grid == 8){
		if (gridPos ==1 || gridPos ==4 || gridPos ==7){
			col = 4;
			x=1; y=4; z=7;
			gx=2; gy=5; gz=8;
		}
		if (gridPos ==2 || gridPos ==5 || gridPos ==8){
			col = 5;
			x=2; y=5; z=8;
			gx=2; gy=5; gz=8;
		}
		if (gridPos ==3 || gridPos ==6 || gridPos ==9){
			col = 6;
			x=3; y=6; z=9;
			gx=2; gy=5; gz=8;
		}
	}
	if (grid == 3 || grid == 6 || grid == 9){
		if (gridPos ==1 || gridPos ==4 || gridPos ==7){
			col = 7;
			x=1; y=4; z=7;
			gx=3; gy=6; gz=9;
		}
		if (gridPos ==2 || gridPos ==5 || gridPos ==8){
			col = 8;
			x=2; y=5; z=8;
			gx=3; gy=6; gz=9;
		}
		if (gridPos ==3 || gridPos ==6 || gridPos ==9){
			col = 9;
			x=3; y=6; z=9;
			gx=3; gy=6; gz=9;
		}
	}
	checkAndShow(x,y,z,gx,gy,gz,'#fcc', '#ddd');
}

document.onkeydown = keyListener;  
	
function lockPuzl(){
	//scan all fields for a value and disable
	//buildStr='';
	
	for(x=1; x<10; x++){
		for(y=1; y<10; y++){	
			if (document.getElementById('tf_g'+x+'f'+y).value != ''){
				var fieldval = document.getElementById('tf_g'+x+'f'+y).value;
				//alert( fieldval + ' gevonden in grid ' + x + ' veld ' + y );
				//buildStr += ''+x+''+y+''+fieldval+'-';
				
				document.getElementById('tf_g'+x+'f'+y).disabled=true;
				//document.getElementById('tf_g'+x+'f'+y).className = "textfield_disabled";
				
				document.getElementById('g'+x+'f'+y).innerHTML = '<div style="position:absolute; left:0px; top:3px; width:29px; height:24px; color:#000; font-weight:bold;">'+ fieldval +'</div><input type="text" id="tf_g'+x+'f'+y+'" class="textfield" tabindex="1" onfocus="setGrid('+x+');setGridPosition('+y+')" onclick="clearGridStates();showState();" value="'+ fieldval +'" style="display:none;" disabled="true"/></div>';

			}
		}
	}	
}	

function autolockPuzl(){
	lockPuzl();
}	
	
function readURL(){
	var refString = location.href;
	
	
		var puzlnr = Math.round(Math.random()*100);
		//alert(puzlnr);
		if (puzlnr > 80) puzlnr=puzlnr-30;
		
		var refStrings = new Array('164-178-214-267-323-341-362-384-411-429-472-496-518-549-562-591-614-636-689-695-726-744-769-785-841-899-931-943','125-153-169-223-244-299-319-376-384-426-445-491-538-579-614-668-682-728-732-795-816-865-889-947-956-988','147-181-262-293-328-339-343-372-418-479-491-523-536-549-565-572-588-617-632-693-739-765-772-788-813-846-925-964','138-147-153-176-219-227-262-325-377-414-443-478-513-559-595-638-667-691-732-787-842-888-893-935-954-969-971','118-125-139-146-191-211-282-298-332-383-497-514-529-556-588-591-611-723-779-817-821-896-918-966-977-985-994','124-136-247-278-323-331-354-375-397-413-486-491-535-556-574-616-622-693-718-739-751-772-785-833-862-971-987','193-238-244-299-329-342-355-391-412-435-447-489-496-516-551-595-619-624-668-677-692-713-752-769-787-811-863-872-916','116-155-168-234-262-286-315-351-389-398-412-448-475-539-542-554-561-576-634-666-691-717-724-756-795-822-843-874-941-954-992','163-178-225-247-254-276-319-322-331-348-414-423-462-521-545-567-583-644-688-699-768-771-786-795-836-859-865-888-938-942','123-139-151-166-298-354-367-371-415-434-457-482-531-546-562-578-626-659-677-691-735-743-754-811-893-942-951-976-988','126-148-183-191-217-245-272-353-377-416-438-451-467-489-522-581-621-644-659-678-696-734-755-835-862-893-919-926-968-987','157-168-175-189-196-233-249-278-292-328-373-416-439-484-543-554-569-679-693-733-785-811-836-865-872-915-929-932-941-953','143-168-189-233-264-281-316-342-355-416-448-451-484-537-543-569-576-621-656-665-693-756-767-791-827-844-872-929-941-968','124-145-189-238-253-281-294-312-366-388-418-425-457-492-548-562-617-656-689-698-723-746-794-811-828-854-879-922-963-985','128-179-235-259-292-322-343-361-427-443-451-478-482-495-593-615-623-632-657-669-686-745-767-786-817-856-872-938-989','133-148-156-182-221-277-316-335-361-374-383-443-499-529-531-558-574-587-615-669-723-731-749-775-798-838-883-925-951-963-979','119-136-245-259-286-293-318-343-357-391-455-471-516-525-537-572-584-599-633-656-713-759-765-792-817-821-852-864-977-994','114-128-142-175-189-222-245-271-376-392-437-441-454-483-499-619-625-653-666-671-717-734-832-863-889-928-939-965-986-997','173-212-226-255-274-298-313-338-341-369-412-436-448-487-543-562-621-667-672-693-745-767-771-793-815-839-852-888-897-931','124-163-182-218-225-232-259-313-344-386-475-513-535-549-558-566-572-591-636-687-729-765-791-852-875-883-899-928-946-984','112-136-168-224-259-282-291-325-337-342-417-435-446-461-482-623-645-664-677-696-764-778-783-814-828-857-885-941-974-999','123-151-185-216-224-263-291-315-327-364-373-427-498-528-549-565-586-616-685-731-747-789-795-815-844-883-896-926-959-981','168-187-247-275-282-291-319-325-351-376-398-417-446-493-549-567-618-664-696-711-732-755-783-797-814-828-839-863-927-941','129-153-184-197-212-275-296-318-337-365-431-442-464-486-537-559-573-629-643-666-675-744-776-793-816-834-892-911-923-958-985','156-174-185-192-212-257-276-291-336-351-397-449-454-496-519-592-613-655-661-716-759-775-811-835-858-896-917-929-933-952','156-193-226-247-253-289-337-352-388-391-427-462-474-496-525-554-588-618-632-649-683-716-724-758-772-821-852-864-887-912-959','123-146-167-179-194-239-255-277-327-349-396-427-439-484-534-573-623-677-685-712-763-789-837-851-872-914-933-942-965-981','168-187-247-275-282-291-319-325-351-376-398-417-446-493-549-567-618-664-696-711-732-755-783-797-814-828-839-863-927-941','144-152-173-226-231-247-263-274-298-369-423-436-451-465-479-634-646-659-672-685-745-815-839-841-864-876-888-931-953-966','167-172-191-213-224-251-277-296-311-395-418-421-464-479-529-582-636-649-681-697-711-793-812-833-856-885-899-918-939-947','126-155-212-256-261-274-315-324-342-388-427-439-445-461-536-579-648-666-674-685-724-765-783-797-839-846-853-898-951-986','129-153-184-197-212-296-318-337-365-431-442-464-486-537-559-573-629-643-666-675-744-776-793-816-834-892-911-923-958-985','129-184-198-227-249-281-324-331-365-379-423-431-462-477-539-572-637-645-676-681-733-744-778-786-829-868-884-914-925-989','115-121-199-219-265-274-316-412-426-431-447-468-489-546-563-629-642-661-677-688-696-727-793-834-845-899-913-986-994','139-148-214-221-242-256-279-287-341-376-398-428-473-517-522-588-596-631-684-717-735-761-823-834-855-862-889-897-963-975','111-189-233-249-256-328-339-342-373-451-477-495-515-522-543-569-588-591-618-634-656-733-767-779-785-859-865-929-996','115-156-198-212-249-261-283-354-365-387-391-411-453-466-488-628-647-652-718-722-747-754-825-848-866-892-914-955-997','121-167-174-186-199-225-232-241-273-372-391-427-434-475-546-568-638-673-686-711-736-835-864-878-881-914-928-932-946-989','169-171-239-278-282-295-315-338-366-426-451-483-494-511-545-567-592-619-625-653-688-744-776-795-812-824-838-873-935-942','134-197-247-265-284-296-318-356-383-391-416-435-452-499-528-585-612-655-673-696-715-724-753-792-811-829-844-868-917-976','137-146-185-192-244-281-296-313-336-342-357-388-457-468-472-486-511-537-578-595-623-638-645-659-722-753-761-778-796-815-828-869-911-926-967-974','121-143-162-196-224-287-323-341-358-379-392-428-529-535-543-568-574-586-685-717-731-753-765-782-828-883-915-948-966-981','139-143-185-192-269-283-291-323-362-387-434-442-459-512-525-581-593-655-661-672-728-745-781-813-824-841-915-921-966-978','131-154-163-189-196-219-236-242-261-284-333-349-357-418-439-444-457-462-495-545-568-617-646-659-661-672-694-752-764-779-822-846-869-873-894-913-924-948-955-971','116-153-169-171-244-273-287-346-362-398-432-447-468-481-495-526-533-551-577-584-611-625-643-669-672-718-749-761-825-834-868-933-947-956-994','115-122-146-173-187-194-228-264-299-314-331-352-376-429-437-518-521-542-563-589-597-678-681-732-755-777-793-815-849-886-917-926-938-963-989-992','137-141-228-234-262-333-346-388-395-415-424-463-491-536-547-565-579-618-649-682-694-713-721-765-774-848-875-882-966-971','215-223-272-287-299-327-349-355-362-398-453-461-497-522-534-579-581-617-644-658-711-748-755-766-782-813-825-837-888','128-149-165-184-192-212-366-381-399-463-477-499-514-539-546-558-561-573-595-611-635-649-718-729-745-892-915-927-943-968-989','119-121-147-186-233-244-251-269-334-377-381-414-463-529-537-575-582-642-693-728-731-775-841-853-865-876-922-966-989-991','119-137-183-216-243-255-312-333-346-374-477-486-491-512-547-565-598-618-623-637-738-765-774-796-857-861-893-925-971-998','114-136-169-172-187-219-251-274-363-396-426-449-465-482-522-584-629-643-668-681-717-745-831-857-895-928-935-941-977-992','111-157-189-217-249-256-328-361-373-384-416-423-448-477-515-591-634-665-682-693-728-733-742-785-859-865-898-929-953-996','148-191-234-245-259-261-288-364-399-424-451-467-489-493-513-555-597-615-621-644-659-682-713-747-827-841-856-862-879-919-968','154-165-177-237-256-261-272-283-316-324-357-448-476-493-532-555-579-618-637-669-756-789-792-822-833-847-854-936-945-951','123-137-148-194-215-242-273-344-366-377-388-427-443-468-539-578-641-664-687-728-731-747-762-834-865-897-912-961-976-985','122-171-211-223-277-285-317-326-334-355-417-469-476-498-514-595-611-638-645-692-759-775-788-792-826-838-889-891-933-984','122-171-211-223-277-285-317-326-334-355-417-469-476-498-514-595-611-638-645-692-759-775-788-792-826-838-889-891-933-984','197-215-227-246-252-271-318-323-357-386-427-431-469-498-512-594-613-644-672-681-722-754-789-795-836-853-861-888-919','111-122-168-175-189-196-264-278-339-342-373-451-484-495-522-588-618-621-656-733-767-779-836-844-915-929-932-941-987-996','132-168-174-187-244-279-292-315-347-352-363-447-455-483-511-558-596-626-654-669-748-751-763-799-813-831-864-928-935-946-974','117-143-175-229-236-265-281-311-354-362-387-444-472-499-547-561-616-634-668-722-746-757-794-828-849-871-882-937-963-999','116-145-169-187-218-239-241-267-286-314-321-348-447-458-519-553-591-655-662-766-785-797-824-845-868-873-892-929-941-963-998','137-151-169-178-185-236-243-258-328-339-362-411-433-524-548-561-589-678-695-747-776-783-851-862-874-924-937-946-959-972','133-161-179-196-219-242-275-287-322-363-467-476-484-516-548-562-597-627-634-643-745-788-825-839-868-896-917-931-942-974','141-177-182-198-225-232-274-337-344-386-434-467-475-499-549-566-612-636-641-678-729-765-776-834-875-883-915-928-931-969','119-181-195-249-253-328-344-429-433-456-462-487-491-522-537-559-576-588-618-625-641-657-673-682-766-782-851-868-912-921-995','137-146-152-173-185-247-268-279-314-332-377-419-427-468-531-553-574-645-681-693-735-778-796-839-848-864-928-931-955-967','127-183-235-248-274-291-334-386-392-428-439-452-467-474-515-599-636-648-659-672-685-719-726-771-817-833-868-876-921-983','152-198-219-226-261-284-331-353-377-395-414-432-461-517-544-558-565-596-643-674-699-717-736-758-773-821-845-889-892-915-951','117-162-218-226-233-244-277-322-334-355-373-422-471-489-542-564-623-636-687-735-751-776-787-831-866-873-884-898-948-992','145-164-171-197-274-289-327-351-363-413-428-485-492-534-546-567-573-611-629-684-698-744-757-782-827-833-918-934-949-962','114-166-219-253-298-315-327-333-361-384-437-441-483-531-574-625-666-671-725-749-773-781-792-816-854-895-939-942-997','115-124-161-176-187-244-252-283-323-337-428-442-496-534-541-569-573-615-664-687-778-783-829-851-865-924-936-942-985-991','112-159-165-188-227-248-273-285-316-335-415-443-452-484-533-559-575-624-651-668-697-774-797-824-835-862-888-926-947-959-992','141-165-176-212-236-289-325-334-371-414-432-479-481-523-541-554-569-586-627-631-674-695-733-772-785-822-878-891-937-942-966','119-133-164-186-216-232-261-283-331-382-414-432-459-465-496-611-648-654-675-693-725-771-828-842-877-893-929-943-974-995','117-131-149-196-219-234-251-283-332-371-389-437-464-472-546-561-635-647-678-724-733-776-825-856-878-892-919-964-973-997','114-142-185-211-222-244-299-366-371-384-456-467-475-489-515-597-626-631-644-655-723-734-741-817-868-886-894-929-964-995','151-197-238-242-253-294-327-349-373-388-449-463-474-514-526-587-591-632-723-735-769-788-811-854-865-879-914-951');

		refTime = refString.substring(refString.indexOf('ts=') +3 , refString.indexOf('&ps='));
		
		parseAndPopulate(refStrings[puzlnr], refTime);
	return true;
}	
	
function parseAndPopulate(refString, refTime){
	var myTokens = refString.tokenize("-", " ", true);
	for(x=0; x < myTokens.length; x++){
		var grid = myTokens[x].substring(0,1);
		var gridnum = myTokens[x].substring(1,2);
		var gridval = myTokens[x].substring(2,3);
		document.getElementById('tf_g'+grid+'f'+gridnum).value=gridval;
		document.getElementById('tf_g'+grid+'f'+gridnum).disabled=true;
		
	}
	autolockPuzl();
}
	

function validatePuzl(){

	InValidGrids=0;
	InValidRowsAndCols=0;
	showState();
	var emptyFields = countEmptyGridFields();
	if(InValidGrids==0 && InValidRowsAndCols==0 && emptyFields ==0){
	//forwardPuzl();
	}else{
	//showInvalidWarning();
	}
}
	


