function getCw() { return document.getElementById("crossword"); } function getCwHead() { return getCw().getElementsByTagName("thead")[0]; } function getCwHeadRow() { return getCwHead().getElementsByTagName("tr")[0]; } function getCwBody() { return getCw().getElementsByTagName("tbody")[0]; } function getCwBodyRows() { return getCwBody().getElementsByTagName("tr"); } function getQuestionsOrderedList() { return document.getElementById("questions"); } function getQuestions() { return getQuestionsOrderedList().getElementsByTagName("li"); } function getNextElement(o) { o=o.nextSibling; while (o) { if (o.nodeType==1) { return o; } else { o=o.nextSibling; } } return false; } function getPreviousElement(o) { o=o.previousSibling; while (o) { if (o.nodeType==1) { return o; } else { o=o.previousSibling; } } return false; } function getNextField(o) { if (getNextElement(o.parentNode) && getNextElement(o.parentNode).getElementsByTagName("input")[0]) { // return next input in this row return getNextElement(o.parentNode).getElementsByTagName("input")[0]; } else { if (getNextElement(o.parentNode.parentNode)) { // retur first input in next row return getNextElement(o.parentNode.parentNode).getElementsByTagName("input")[0]; } else { // return first input in first row return getCwBody().getElementsByTagName("input")[0]; } } } function getPreviousField(o) { if (getPreviousElement(getPreviousElement(o.parentNode))) { // return previous input in this row return getPreviousElement(o.parentNode).getElementsByTagName("input")[0]; } else { if (getPreviousElement(o.parentNode.parentNode)) { // return last input in previous row var inputs=getPreviousElement(o.parentNode.parentNode).getElementsByTagName("input"); return inputs[inputs.length-1]; } else { // return last input in last row var inputs=getCwBody().getElementsByTagName("input"); return inputs[inputs.length-1]; } } } function getUpperField(o) { var position=getPositionInList(o, o.parentNode.parentNode.getElementsByTagName("input")); if (getPreviousElement(o.parentNode.parentNode)) { return getPreviousElement(o.parentNode.parentNode).getElementsByTagName("input")[position]; } else { var rows=getCwBodyRows(); return rows[rows.length-1].getElementsByTagName("input")[position]; } } function getLowerField(o) { var position=getPositionInList(o, o.parentNode.parentNode.getElementsByTagName("input")); if (getNextElement(o.parentNode.parentNode)) { return getNextElement(o.parentNode.parentNode).getElementsByTagName("input")[position]; } else { return getCwBodyRows()[0].getElementsByTagName("input")[position]; } } function KeyCheck(e) { var evnt; var elmnt; if (window.event) { evnt = event; elmnt = evnt.srcElement; } else { evnt = e; elmnt = evnt.target; } var keyID = evnt.keyCode; if (elmnt.type && elmnt.name && elmnt.type=="text" && elmnt.name=="t") { if (keyID>=32) { var field; switch (keyID) { case 37: //left field=getPreviousField(elmnt); break; case 38: //up field=getUpperField(elmnt); break; case 40: //down field=getLowerField(elmnt); break; case 39: //right default: field=getNextField(elmnt); } field.focus(); field.select(); } } } function createFieldCell() { var newTd=document.createElement("td"); var newInput=newTd.appendChild(document.createElement("input")); newInput.type="text"; newInput.name="t"; return newTd; } function createQuestion() { var newLi=document.createElement("li"); var newInput=newLi.appendChild(document.createElement("input")); newInput.type="text"; newInput.name="q"; return newLi; } function createRowLike(refRow) { var newRow=document.createElement("tr"); var nextRowNumber=parseInt(refRow.getElementsByTagName("th")[0].firstChild.nodeValue)+1; var newTh=newRow.appendChild(document.createElement("th")); newTh.appendChild(document.createTextNode(nextRowNumber+".")); var refRowTds=refRow.getElementsByTagName("td"); var nrOfFields=refRowTds.length; for (var i=0; i1) { cwBody.removeChild(cwBodyRows[0]); renumberElements(cwBody.getElementsByTagName("th")); getQuestionsOrderedList().removeChild(getQuestions()[0]); } } function removeLastRow() { var cwBody=getCwBody(); var cwBodyRows=cwBody.getElementsByTagName("tr"); var questions=getQuestions() if (cwBodyRows.length>1) { cwBody.removeChild(cwBodyRows[cwBodyRows.length-1]); getQuestionsOrderedList().removeChild(questions[questions.length-1]); } } function insertLastCol() { var cwHeadRow=getCwHeadRow(); var cwHeadAnchors=cwHeadRow.getElementsByTagName("a"); var lastNr=parseInt(cwHeadAnchors[cwHeadAnchors.length-1].firstChild.nodeValue); var newA=cwHeadRow.appendChild(document.createElement("th")).appendChild(document.createElement("a")); newA.href="#"; newA.onclick=function(){setAsSolution(this); return 0;}; newA.appendChild(document.createTextNode( ( lastNr + 1 ) + ".")); var cwBodyRows=getCwBodyRows(); for (var i=0; i1) { if (cwHeadRowHeadings[0].className=="solution") { cwHeadRowHeadings[1].className="solution"; } cwHeadRow.removeChild(cwHeadRowHeadings[0]); var cwBodyRows=getCwBodyRows(); for (var i=0; i1) { if (cwHeadRowHeadings[cwHeadRowHeadings.length-1].className=="solution") { cwHeadRowHeadings[cwHeadRowHeadings.length-2].className="solution"; } cwHeadRow.removeChild(cwHeadRowHeadings[cwHeadRowHeadings.length-1]); var cwBodyRows=getCwBodyRows(); for (var i=0; i