
 // Scramble puzzle differently
 function scramblePuzzle() {
	//return;
	//alert('picked ' + document.numberShuffleForm.pickPuzzle.value);
	var rowxcol = document.gridLightsForm.pickPuzzle.value;
	var cols = parseInt(rowxcol);
	var pos = rowxcol.indexOf('x');
	if (pos > -1) 
		rows = parseInt(rowxcol.substring(pos+1));
	else {
		rows = cols = 3;
	}
	
	saveGridSize(rows, cols);
	
	//alert('pickPuzzle rowxcol = ' + rowxcol + '  rows=' + rows + '  cols=' + cols);
	document.gridLightsForm.action = "gridLights.htm" + "?rows=" +  rows + "&cols=" + cols;
	document.gridLightsForm.submit();
 }

 // Reset to the way the puzzle looked before the user did anything
 function resetPuzzle() {
	initGame();
	return false;
 }

 
 function clickButton(el) {
	incMoves();
	
	toggleMainButton(el);
 }
 
 
// Save the grid size to a cookie 
function saveGridSize(rows, cols) {
	var gridSize = rows + "&" + cols;
	
	// Save the grid size choice to a cookie
	eraseCookie("gridLights");
	createCookie("gridLights", gridSize, 365);  // save cookie for a year

} 
  
function restoreLastGridSize(currRows, currCols) {

	var gridSize = readCookie("gridLights");  // rows&cols
	if (gridSize) {
		// found the cookie
		//alert('found cookie grid size =' + gridSize);
		
		// Make sure the value of the cookie is a valid grid size -- done on page reload
		
		var arrSize = gridSize.split("&");
		if (arrSize.length != 2)
			return;
			
		var rows = parseInt(arrSize[0]);
		var cols = parseInt(arrSize[1]);
		
		if ((rows != currRows) || (cols != currCols)) {
			location.href = "gridLights.htm?rows=" + rows + "&cols=" + cols;
		}
	}

}  // end restoreLastGridSize

 
 