// //Copyright (c) 2005 Gammakurve Corporation. All Rights Reserved. // var GK_ns = false; var GK_ns2 = false; var GK_ns3 = false; var GK_ns4 = false; var GK_ns4up = false; var GK_nav = false; var GK_ns6 = false; var GK_ns6up = false; var GK_firefox = false; var GK_firefox0_x = false; var GK_firefox1_x = false; var GK_gecko = false; var GK_ie = false; var GK_ie3 = false; var GK_ie4 = false; var GK_ie4up = false; var GK_ie5 = false; var GK_ie5_5 = false; var GK_ie5up = false; var GK_ie6 = false; var GK_ie6up = false; var GK_opera = false; var GK_opera2 = false; var GK_opera3 = false; var GK_opera4 = false; var GK_opera5 = false; var GK_opera6 = false; var GK_opera7 = false; var GK_opera5up = false; var GK_opera6up = false; var GK_opera7up = false; var GK_aol = false; var GK_aol3 = false; var GK_aol4 = false; var GK_aol5 = false; var GK_aol6 = false; var GK_aol7 = false; var GK_aol8 = false; var GK_webtv = false; var GK_aoltv = false; var GK_tvnavigator = false; var GK_hotjava = false; var GK_hotjava3 = false; var GK_hotjava3up = false; var GK_konq = false; var GK_safari = false; var GK_netgem = false; var GK_webdav = false; var GK_text = false; var GK_ie5_5up = false; var across = null; var down = null; var needsRefresh = false; var needsDrawing = true; var needsResume = false; var crossword = null; var tilesFilled = 0; function initcw(height, width, encoding, acrossSize, downSize, refresh, clientDraws, resumeGame) { needsRefresh = refresh; needsDrawing = clientDraws; needsResume = resumeGame; _10(height, width, encoding); _1(); Behaviour.addLoadEvent(function() { _100(); }); } function _10(height, width, encoding) { crossword = new CWGrid(height, width, 'letter', encoding); return false; } function _1() { var rules = { '#reset' : function(element) { element.onclick = _11011; }, '#refresh' : function(element) { element.onclick = _11010; }, '#verifyAll' : function(element) { element.onclick = _1111; }, '#verifyLetter' : function(element) { element.onclick = _1011; }, '#verifyWord' : function(element) { element.onclick = _1110; }, '#revealAll' : function(element) { element.onclick= function(e) { _11000(); }; }, '#revealLetter' : function(element) { element.onclick = _10100; }, '#revealWord' : function(element) { element.onclick = _10111; }, '#cluePanel' : function(element) { element.onclick = function(e) {return false;}; element.onkeypress = function(e) {return false;}; element.onkeydown = function(e) {return false;}; element.onkeyup = function(e) {return false;} }, '#grid' : function(element) { element.onclick = function (e) { return _1001(e, 'onclick'); }; element.ondblclick = function (e) { return false; }; element.onkeydown = function (e) { return _1001(e, 'onkeydown'); }; element.onfocus = function (e) { return _1001(e, 'onfocus'); }; element.onkeypress = function (e) { return false; }; element.onkeyup = function (e) { return false; }; element.oncontextmenu = function (e) { return false; }; }, '#cluesAcross' : function(element) { element.onclick = function (e) { return _1010(e, 'onclick'); }; element.ondblclick = function (e) { return false; }; element.onkeydown = function (e) { return false; }; element.onfocus = function (e) { return false; }; element.onkeyup = function (e) { return false; }; element.onmouseover = function (e) { return _1010(e, 'onmouseover'); }; element.onmouseout = function (e) { return _1010(e, 'onmouseout'); }; }, '#cluesDown' : function(element) { element.onclick = function (e) { return _1010(e, 'onclick'); }; element.ondblclick = function (e) { return false; }; element.onkeydown = function (e) { return false; }; element.onfocus = function (e) { return false; }; element.onkeyup = function (e) { return false; }; element.onmouseover = function (e) { return _1010(e, 'onmouseover'); }; element.onmouseout = function (e) { return _1010(e, 'onmouseout'); }; }, '#clueLine' : function(element) { element.onmouseover = function (e) { return false; }; element.onmousedown = function (e) { return false; }; element.onfocus = function (e) { return false; }; element.onkeypress = function (e) { return false; }; element.onkeydown = function (e) { return false; }; element.onkeyup = function (e) { return false; }; } }; Behaviour.register(rules); } function _100() { setCursor('wait', 'puzzle'); if (needsResume) { _101011(); } if (needsRefresh) { if (needsDrawing) { _101(false, false); Behaviour.apply(); } setHeightToParent('gridPanel'); setClueLineWidth(); } if (splashScreen) { displayUserMessage('splashScreen', false); splashScreen = false; } if (needsResume) { _101010(); } setCursor('auto', 'puzzle'); } function _101(forPrint, solve) { var startTime=new Date().getTime(); var pelt = document.getElementById('crossword'); var celt = document.getElementById('grid'); if (celt != null) { pelt.removeChild(celt); } var rows = ''; for (var i = 0; i < crossword.height; i++) { rows += '' + _110(i, forPrint, solve) + ''; } var table = '' + rows + '
'; pelt.innerHTML = table; var endTime=new Date().getTime(); var diff = endTime - startTime; showMessage('_10 ' + diff, true); return false; } function _110(i, forPrint, solve) { var aRow = ''; for (var j = 0; j < crossword.width; j++) { if (forPrint) { aRow += _111(i, j, solve); } else { aRow += _1000(i, j); } } return aRow; } function _1000(i, j) { var cell = crossword.grid[i][j]; if (cell.getType() == 'block') { var type = 'block'; var className = ''; var tile = ' '; } else { var type = 'letter'; if (needsResume) { var errorCode = crossword.grid[i][j].getState(); var value = crossword.grid[i][j].value; if (value == '_') { value = ' '; } } else { var errorCode = 0; var value = ' '; } var className = "class='tileCode letterCode-" + errorCode + "'"; var tile = ""; tile = tile.replace(/%i%/g, i); tile = tile.replace(/%j%/g, j); } var index = crossword.grid[i][j].index['start-across']; if (typeof(index) == 'undefined') { var index = crossword.grid[i][j].index['start-down']; if (typeof(index) == 'undefined') { var index = ' '; } } var str = "
%index%
%tile%
"; str = str.replace(/%i%/g, i); str = str.replace(/%j%/g, j); str = str.replace(/%type%/g, type); str = str.replace(/%class%/g, className); str = str.replace(/%tile%/g, tile); str = str.replace(/%index%/g, index); return str; } function _111(i, j, solve) { var cell = crossword.grid[i][j]; if (cell.getType() == 'block') { var str = ''; } else { var cluesObj = across; var index = crossword.grid[i][j].index['start-across']; if (typeof(index) == 'undefined') { var cluesObj = down; var index = crossword.grid[i][j].index['start-down']; if (typeof(index) == 'undefined') { var index = ' '; } } if (solve) { var letter = crossword.grid[i][j].value; } else { var letter = ''; } var str = '
%index%
%letter%
'; str = str.replace(/%index%/g, index); str = str.replace(/%letter%/g, letter); } str = str.replace(/%i%/g, i); str = str.replace(/%j%/g, j); return str; } function _1001(e, action) { if (!e) var e = window.event; if (e.srcElement) { var target = e.srcElement; } else if (e.target) { var target = e.target; } if (target.id == '') { var target = target.firstChild; } var id = target.id; if (id == '') { return; } var comps = id.split('-'); var i = parseInt(comps[1]); var j = parseInt(comps[2]); var cell = 'cell-' + i + '-' + j; switch (action) { case 'onclick': return _100001(i, j); case 'onkeydown': return _10000(cell, e); case 'onfocus': return _100001(i, j); default: break; } } function _1010(e, action) { if (!e) var e = window.event; if (e.srcElement) { var target = e.srcElement; } else if (e.target) { var target = e.target; } switch (target.className) { case 'clueTag': var target = target.parentNode; break; case 'clue': break; default: case 'clues': return; } var id = target.id; if (id == '') { return; } switch (action) { case 'onclick': return _10010(id); case 'onmouseover': var elt = document.getElementById(id); elt.style.textDecoration = 'underline'; break; case 'onmouseout': var elt = document.getElementById(id); elt.style.textDecoration = 'none'; break; default: break; } } function _1011() { var i = curI; var j = curJ; var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; var id = 'gridElement-' + i + '-' + j; var elt = document.getElementById(id); var elt2 = elt.firstChild.childNodes[2].firstChild; if (elt2.value.charAt(0) == answer.charAt(j-col)) { crossword.grid[i][j].setConfirmed(); var errors = 0; } else if (elt2.value.charAt(0) != ' ') { crossword.grid[i][j].setErroneous(); var errors = 1; } var errorCode = crossword.grid[i][j].getState(); elt.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; return false; } function _1110() { if (curDir == 'across') { return _1100(); } else { return _1101(); } } function _1100() { var i = curI; var j = curJ; var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; for (var p = 0; p < answer.length; p++) { var newCol = col + p; var id = 'gridElement-' + row + '-' + newCol; var elt = document.getElementById(id); var elt2 = elt.firstChild.childNodes[2].firstChild; if (elt2.value.charAt(0) == answer.charAt(p)) { crossword.grid[row][newCol].setConfirmed(); var errors = 0; } else if (elt2.value.charAt(0) != ' ') { crossword.grid[row][newCol].setErroneous(); var errors = 1; } var errorCode = crossword.grid[row][newCol].getState(); elt.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; } return false; } function _1101() { var i = curI; var j = curJ; var index = crossword.grid[i][j].index['down']; var answer = down.clues[index].answer; var col = down.clues[index].col - 1; var row = down.clues[index].row - 1; for (var p = 0; p < answer.length; p++) { var newRow = row + p; var id = 'gridElement-' + newRow + '-' + col; var elt = document.getElementById(id); var elt2 = elt.firstChild.childNodes[2].firstChild; if (elt2.value.charAt(0) == answer.charAt(p)) { crossword.grid[newRow][col].setConfirmed(); var errors = 0; } else if (elt2.value.charAt(0) != ' ') { crossword.grid[newRow][col].setErroneous(); var errors = 1; } var errorCode = crossword.grid[newRow][col].getState(); elt.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; } return false; } function _1111() { setCursor('wait', 'puzzle'); var errors = 0; var incomplete = false; var domway = GK_opera?false:true; if (domway) { var pelt = document.getElementById('crossword'); var celt = document.getElementById('grid'); pelt.removeChild(celt); var nrows = crossword.grid.length; var ncols = crossword.grid[0].length; var p = null; for (var k = 0; (p = celt.getElementsByTagName("TD")[k]); k++) { var id = p.id; var comps = id.split('-'); var i = parseInt(comps[1]); var j = parseInt(comps[2]); if (crossword.grid[i][j].type == 'block') { continue; } var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; var elt2 = p.firstChild.childNodes[2].firstChild; if (elt2.value.charAt(0) == answer.charAt(j-col)) { crossword.grid[i][j].setConfirmed(); } else if (elt2.value.charAt(0) != ' ') { crossword.grid[i][j].setErroneous(); errors++; } else { incomplete = true; } var errorCode = crossword.grid[i][j].getState(); p.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; } pelt.appendChild(celt); } else { for (var i = 0; i < crossword.grid.length; i++) { for (var j = 0; j < crossword.grid[i].length; j++) { if (crossword.grid[i][j].type == 'block') { continue; } var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; var id = 'gridElement-' + i + '-' + j; var elt = document.getElementById(id); var elt2 = elt.firstChild.childNodes[2].firstChild; if (elt2.value.charAt(0) == answer.charAt(j-col)) { crossword.grid[i][j].setConfirmed(); } else if (elt2.value.charAt(0) != ' ') { crossword.grid[i][j].setErroneous(); errors++; } else { incomplete = true; } var errorCode = crossword.grid[i][j].getState(); elt.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; } } } if (errors == 0 && !incomplete) { showUserMessage('userMessage', 'dismissUserMessageOk'); setCursor('auto', 'puzzle'); return true; } setCursor('auto', 'puzzle'); return false; } function _10000(cell, e) { _10001(cell); if (!e) var e = window.event; if (e.keyCode) code = e.keyCode; else if (e.which) code = e.which; var character = String.fromCharCode(code); var shifted = false; if (e['shiftKey']) { shifted = true; } return _11100(cell, code, shifted); } function _10001(id) { _100111(curI, curJ, curDir, 'white'); _101000(curI, curJ, 'across', ''); _101000(curI, curJ, 'down', ''); prevI = curI; prevJ = curJ; var comps = id.split('-'); curI = parseInt(comps[1]); curJ = parseInt(comps[2]); _100111(curI, curJ, curDir, '#ccccff'); _101000(curI, curJ, 'across', 'white'); _101000(curI, curJ, 'down', 'white'); if (curDir == 'across') { var index = crossword.grid[curI][curJ].index['across']; var clue = across.clues[index]; _10011(index, curDir, clue); } else { var index = crossword.grid[curI][curJ].index['down']; var clue = down.clues[index]; _10011(index, curDir, clue); } if (splashScreen) { displayUserMessage('splashScreen', false); splashScreen = false; } return false; } function _10010(id) { var comps = id.split('-'); var dir = comps[0]; var index = parseInt(comps[1]); if (dir == 'across') { var clue = across.clues[index]; } else { var clue = down.clues[index]; } var i = clue.row - 1; var j = clue.col - 1; var cell = 'cell-' + i + '-' + j; var elt = document.getElementById(cell); elt.focus(); if (dir != curDir) { _100111(curI, curJ, curDir, 'white'); curDir = dir; } return _10001(cell); } function _10011(index, dir, clue) { var elt = document.getElementById('clueLine'); if (elt != null) { elt.value = index + ' ' + dir + ', ' + clue.clue; } } function _10100(e) { var i = curI; var j = curJ; if (crossword.grid[i][j].isConfirmed()) { return _100100(); } if (curDir == 'across') { var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; var id = 'gridElement-' + i + '-' + j; var elt = document.getElementById(id); var elt2 = elt.firstChild.childNodes[2].firstChild; if (elt2.value == ' ') { tilesFilled ++; } elt2.value = answer.substr(j-col, 1); } else { var index = crossword.grid[i][j].index['down']; var answer = down.clues[index].answer; var col = down.clues[index].col - 1; var row = down.clues[index].row - 1; var id = 'gridElement-' + i + '-' + j; var elt = document.getElementById(id); var elt2 = elt.firstChild.childNodes[2].firstChild; if (elt2.value == ' ') { tilesFilled ++; } elt2.value = answer.substr(i-row, 1); } crossword.grid[i][j].setRevealed(); var errorCode = crossword.grid[i][j].getState(); elt.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; return _100100(); } function _10111(e) { if (curDir == 'across') { return _10101(); } else { return _10110(); } } function _10101() { var i = curI; var j = curJ; var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; for (var p = 0; p < answer.length; p++) { var newCol = col + p; if (crossword.grid[row][newCol].isConfirmed()) { continue; } var cell = 'cell-' + row + '-' + newCol; var elt = document.getElementById(cell); if (elt.value == ' ') { tilesFilled ++; } elt.value = answer.substr(p, 1); crossword.grid[i][newCol].setRevealed(); var errorCode = crossword.grid[i][newCol].getState(); var img = 'img-' + i + '-' + newCol; var elt = document.getElementById(img); elt.className = 'tileCode letterCode-'+errorCode; } return _100010(); } function _10110() { var i = curI; var j = curJ; var index = crossword.grid[i][j].index['down']; var answer = down.clues[index].answer; var col = down.clues[index].col - 1; var row = down.clues[index].row - 1; for (var p = 0; p < answer.length; p++) { var newRow = row + p; if (crossword.grid[newRow][col].isConfirmed()) { continue; } var cell = 'cell-' + newRow + '-' + col; var elt = document.getElementById(cell); if (elt.value == ' ') { tilesFilled ++; } elt.value = answer.substr(p, 1); crossword.grid[newRow][j].setRevealed(); var errorCode = crossword.grid[newRow][j].getState(); var img = 'img-' + newRow + '-' + j; var elt = document.getElementById(img); elt.className = 'tileCode letterCode-'+errorCode; } return _100010(); } function _11000() { setCursor('wait', 'puzzle'); tilesFilled = 0; var domway = GK_opera?false:true; if (domway) { var pelt = document.getElementById('crossword'); var celt = document.getElementById('grid'); pelt.removeChild(celt); var nrows = crossword.grid.length; var ncols = crossword.grid[0].length; var p = null; for (var k = 0; (p = celt.getElementsByTagName("TD")[k]); k++) { var id = p.id; var comps = id.split('-'); var i = parseInt(comps[1]); var j = parseInt(comps[2]); if (crossword.grid[i][j].type == 'block') { continue; } if (crossword.grid[i][j].isConfirmed()) { continue; } var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; crossword.grid[i][j].setRevealed(); var errorCode = crossword.grid[i][j].getState(); p.firstChild.childNodes[2].firstChild.value = answer.substr(j-col, 1); p.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; tilesFilled++; } pelt.appendChild(celt); } else { for (var i = 0; i < crossword.grid.length; i++) { for (var j = 0; j < crossword.grid[i].length; j++) { if (crossword.grid[i][j].type == 'block') { continue; } if (crossword.grid[i][j].isConfirmed()) { continue; } var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; crossword.grid[i][j].setRevealed(); var errorCode = crossword.grid[i][j].getState(); var id = 'gridElement-' + i + '-' + j; elt = document.getElementById(id); elt.firstChild.childNodes[2].firstChild.value = answer.substr(j-col, 1); elt.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; tilesFilled++; } } } showUserMessage('userMessage', 'dismissUserMessageOk'); setCursor('auto', 'puzzle'); return false; } function _11001(e, doReset) { setCursor('wait', 'puzzle'); var domway = GK_opera?false:true; if (domway) { var pelt = document.getElementById('crossword'); var celt = document.getElementById('grid'); pelt.removeChild(celt); var nrows = crossword.grid.length; var ncols = crossword.grid[0].length; var p = null; for (var k = 0; (p = celt.getElementsByTagName("TD")[k]); k++) { var id = p.id; var comps = id.split('-'); var i = parseInt(comps[1]); var j = parseInt(comps[2]); if (crossword.grid[i][j].type == 'block') { continue; } if (doReset) { crossword.grid[i][j].resetState(); } var errorCode = crossword.grid[i][j].getState(); p.style.backgroundColor = 'white'; if (doReset) { p.firstChild.childNodes[2].firstChild.value = ' '; } p.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; } pelt.appendChild(celt); } else { for (var i = 0; i < crossword.grid.length; i++) { for (var j = 0; j < crossword.grid[i].length; j++) { if (crossword.grid[i][j].type == 'block') { continue; } if (doReset) { crossword.grid[i][j].resetState(); } var errorCode = crossword.grid[i][j].getState(); var id = 'gridElement-' + i + '-' + j; var elt = document.getElementById(id); elt.style.backgroundColor = 'white'; if (doReset) { elt.firstChild.childNodes[2].firstChild.value = ' '; } elt.firstChild.childNodes[1].className = 'tileCode letterCode-'+errorCode; } } } var cell = 'cell-' + curI + '-' + curJ; var elt = document.getElementById(cell); if (elt != null) { elt.focus(); } tilesFilled = 0; setCursor('auto', 'puzzle'); return false; } function _11010(e) { return _11001(e, false); } function _11011(e) { var flag = confirm("This action will reset the game. Are your sure?"); if (flag) { return _11001(e, true); } else { return false; } } function _11100(id, key, shifted) { var comps = id.split('-'); var i = parseInt(comps[1]); var j = parseInt(comps[2]); var cell = 'cell-' + i + '-' + j; var elt = document.getElementById(cell); var value = elt.value; var character = String.fromCharCode(code); character = character.toUpperCase(); var nCode = character.charCodeAt(0); showMessage(character+' '+nCode+' '+code); if (nCode == ascii_left) { return _11101(); } else if (nCode == ascii_right) { return _11110(); } else if (nCode == ascii_up) { return _11111(); } else if (nCode == ascii_down) { return _100000(); } else if (nCode == ascii_tab) { if (shifted) { return _100011(); } else { return _100010(); } } else if (nCode == ascii_space ) { return _100110(); } else if (nCode >= ascii_a && nCode <= ascii_z) { if (!(crossword.grid[i][j].getState() & 0x03)) { if (elt.value == ' ') { tilesFilled++; } elt.value = character; } if (tilesFilled == crossword.letterCount) { _1111(); } return _100100(); } else if (nCode == ascii_backspace) { if (!(crossword.grid[i][j].getState() & 0x03)) { if (elt.value != ' ') { tilesFilled--; } elt.value = ' '; } return _100101(); } return false; } function _100001(ti, tj) { if (crossword.grid[ti][tj] != null && crossword.grid[ti][tj].type != 'block' ) { var cell = 'cell-' + ti + '-' + tj; var elt = document.getElementById(cell); elt.focus(); return _10001(cell); } return false; } function _11101() { var ti = curI; var tj = curJ; tj--; while (tj >= 0) { if (crossword.grid[ti][tj].type != 'block' ) { break; } tj--; } if (tj < 0) { return false; } return _100001(ti, tj); } function _11110() { var ti = curI; var tj = curJ; tj++; while (tj < crossword.width) { if (crossword.grid[ti][tj].type != 'block' ) { break; } tj++; } if (tj >= crossword.width) { return false; } return _100001(ti, tj); } function _11111() { var ti = curI; var tj = curJ; ti--; while (ti >= 0) { if (crossword.grid[ti][tj].type != 'block' ) { break; } ti--; } if (ti < 0) { return false; } return _100001(ti, tj); } function _100000() { var ti = curI; var tj = curJ; ti++; while (ti < crossword.height) { if (crossword.grid[ti][tj].type != 'block' ) { break; } ti++; } if (ti >= crossword.height) { return false; } return _100001(ti, tj); } function _100010() { var i = curI; var j = curJ; if (curDir == 'across') { var index = crossword.grid[i][j].index['across']; var nextSeq = across.key2seq[index] + 1; if (nextSeq >= across.seq2key.length) { nextSeq = 0; } var nextIndex = across.seq2key[nextSeq]; var clue = across.clues[nextIndex]; var col = clue.col - 1; var row = clue.row - 1; } else { var index = crossword.grid[i][j].index['down']; var nextSeq = down.key2seq[index] + 1; if (nextSeq >= down.seq2key.length) { nextSeq = 0; } var nextIndex = down.seq2key[nextSeq]; var clue = down.clues[nextIndex]; var col = clue.col - 1; var row = clue.row - 1; } var cell = 'cell-' + row + '-' + col; var elt = document.getElementById(cell); elt.focus(); return _10001(cell); } function _100011() { var i = curI; var j = curJ; if (curDir == 'across') { var index = crossword.grid[i][j].index['across']; var nextSeq = across.key2seq[index] - 1; if (nextSeq < 0) { nextSeq = across.seq2key.length -1; } var nextIndex = across.seq2key[nextSeq]; var clue = across.clues[nextIndex]; var col = clue.col - 1; var row = clue.row - 1; } else { var index = crossword.grid[i][j].index['down']; var nextSeq = down.key2seq[index] - 1; if (nextSeq < 0 ) { nextSeq = down.seq2key.length - 1; } var nextIndex = down.seq2key[nextSeq]; var clue = down.clues[nextIndex]; var col = clue.col - 1; var row = clue.row - 1; } var cell = 'cell-' + row + '-' + col; var elt = document.getElementById(cell); elt.focus(); return _10001(cell); } function _100100() { var ti = curI; var tj = curJ; if (curDir == 'across') { if ( (curJ+1) < crossword.width) { var tj = curJ + 1; } } else { if ( (curI+1) < crossword.height) { var ti = curI + 1; } } if (crossword.grid[ti][tj] != null && crossword.grid[ti][tj].type != 'block' ) { var cell = 'cell-' + ti + '-' + tj; var elt = document.getElementById(cell); elt.focus(); return _10001(cell); } return false; } function _100101() { var ti = curI; var tj = curJ; if (curDir == 'across') { if ( (curJ-1) >= 0) { var tj = curJ - 1; } } else { if ( (curI-1) >= 0) { var ti = curI - 1; } } if (crossword.grid[ti][tj] != null && crossword.grid[ti][tj].type != 'block' ) { var cell = 'cell-' + ti + '-' + tj; var elt = document.getElementById(cell); elt.focus(); return _10001(cell); } return false; } function _100110() { if (curDir == 'across') { prevDir = 'across'; curDir = 'down'; _100111(prevI, prevJ, prevDir, 'white'); _100111(prevI, prevJ, curDir, '#ccccff'); var index = crossword.grid[curI][curJ].index['down']; var clue = down.clues[index]; _10011(index, curDir, clue); } else { prevDir = 'down'; curDir = 'across'; _100111(prevI, prevJ, prevDir, 'white'); _100111(prevI, prevJ, curDir, '#ccccff'); var index = crossword.grid[curI][curJ].index['across']; var clue = across.clues[index]; _10011(index, curDir, clue); } return false; } function _100111(i, j, dir, color) { if (crossword.grid[i][j].type == 'block') { return; } switch (dir) { case 'across': var index = crossword.grid[i][j].index['across']; var answer = across.clues[index].answer; var col = across.clues[index].col - 1; var row = across.clues[index].row - 1; for (var p = 0; p < answer.length; p++) { var newCol = col + p; var cell = 'cell-' + row + '-' + newCol; var elt = document.getElementById(cell); elt.parentNode.parentNode.parentNode.style.backgroundColor = color; } break; case 'down': var index = crossword.grid[i][j].index['down']; var answer = down.clues[index].answer; var col = down.clues[index].col - 1; var row = down.clues[index].row - 1; for (var p = 0; p < answer.length; p++) { var newRow = row + p; var cell = 'cell-' + newRow + '-' + col; var elt = document.getElementById(cell); elt.parentNode.parentNode.parentNode.style.backgroundColor = color; } break; default: break; } } function _101000(i, j, dir, color) { if (dir != 'across' && dir != 'down') { return false; } if (crossword.grid[i][j].type == 'block') { return; } var index = crossword.grid[i][j].index[dir]; var clue = dir+'-'+index; var elt = document.getElementById(clue); elt.style.backgroundColor = color; var offset = 0; for (var x = 1; x < index; x++) { var clue = dir+'-'+x; var elt2 = document.getElementById(clue); if (elt2 == null) { continue; } offset += elt2.offsetHeight; } elt.parentNode.scrollTop = offset; return true; } function _101001() { var startTime=new Date().getTime(); setCursor('wait', 'puzzle'); var encoding = ''; var stateEncoding = ''; var domway = GK_opera?false:true; if (domway) { var pelt = document.getElementById('crossword'); var celt = document.getElementById('grid'); pelt.removeChild(celt); var nrows = crossword.grid.length; var ncols = crossword.grid[0].length; var p = null; for (var k = 0; (p = celt.getElementsByTagName("TD")[k]); k++) { var id = p.id; var comps = id.split('-'); var i = parseInt(comps[1]); var j = parseInt(comps[2]); var elt = p.firstChild.childNodes[2].firstChild; if (elt.tagName == 'INPUT') { var state = crossword.grid[i][j].getState(); stateEncoding += state; if (elt.value == ' ') { encoding += '_'; } else { encoding += elt.value; } } else { stateEncoding += '@'; encoding += '@'; } if (j == (ncols - 1)) { stateEncoding += ','; encoding += ','; } } pelt.appendChild(celt); } else { for (var i = 0; i < crossword.grid.length; i++) { for (var j = 0; j < crossword.grid[i].length; j++) { var id = 'cell-' + i + '-' + j; var elt = document.getElementById(id); if (elt != null) { var state = crossword.grid[i][j].getState(); stateEncoding += state; if (elt.value == ' ') { encoding += '_'; } else { encoding += elt.value; } } else { stateEncoding += '@'; encoding += '@'; } } stateEncoding += ','; encoding += ','; } } var coded = ':grid='+encoding+':state='+stateEncoding; setCursor('auto', 'puzzle'); var endTime=new Date().getTime(); var diff = endTime - startTime; showMessage('_101001 ' + diff, true); return coded; } function SaveGame(game_id, msg, href) { var coded = _101001(); var data = 'game_id='+game_id+coded; var OneWeek = 7 * 24 * 3600 * 1000; var expiryDate = new Date( new Date().getTime() + OneWeek); var path = SGL_JS_CURRURL.split('action'); document.cookie = 'crossword='+ data + '; expires=' + expiryDate.toGMTString() + '; path='+path[0]; return CancelGame(msg, href); } function _101010() { needsResume = false; var expiryDate = new Date(0); var path = SGL_JS_CURRURL.split('action'); document.cookie = 'crossword=; expires=' + expiryDate.toGMTString() + '; path='+path[0]; return false; } function _101011() { var cookie = document.cookie.split(';'); var data = ''; for (var i = 0 ; cookie.length; i++) { if (cookie[i].substr(0, 10) == 'crossword=') { var data = cookie[i]; break; } } if (data == '') { return false; } var data = data.split(':'); var encoding = data[1].split('='); var encoding = encoding[1].split(','); var state = data[2].split('='); var state = state[1].split(','); if (encoding.length != (crossword.grid.length+1) || state.length != (crossword.grid.length+1)) { return false; } for (var i = 0; i < crossword.grid.length; i++) { if (encoding[i].length != crossword.grid[i].length) { return; } for (var j = 0; j < crossword.grid[i].length; j++) { if (crossword.grid[i][j].type == 'block') { if (encoding[i].charAt(j) != '@') { return false; } } else { crossword.grid[i][j].value = encoding[i].charAt(j); crossword.grid[i][j].state = parseInt(state[i].charAt(j)); } } } return false; } function initcwPrint(height, width, encoding, acrossSize, downSize, refresh, clientDraws, solve) { needsRefresh = refresh; needsDrawing = clientDraws; _10(height, width, encoding); Behaviour.addLoadEvent(function() { _11(solve); }); } function _11(solve) { if (needsRefresh) { if (needsDrawing) { _101(true, solve); } } }