var BadChars="`~!@^*()_={[}]|:;\"',<.>/?";var CrosswordWidth,CrosswordHeight;var TableAcrossWord,TableDownWord;var Words,Word,Clue,AnswerHash,WordX,WordY,LastHorizontalWord;var OnlyCheckOnce;var timerID,tStart,tFinal,didCheat;var CurrentWord,PrevWordHorizontal,x,y,i,j;var CrosswordFinished,Initialized;if(document.getElementById("waitmessage")!=null){document.getElementById("waitmessage").innerHTML="Please wait while the crossword is loaded...";CurrentWord=-1;PrevWordHorizontal=false;timerID=0;tStart=null;didCheat=false;OnlyCheckOnce=false;TableAcrossWord=new Array(CrosswordWidth);for(var x=0;x<CrosswordWidth;x++){TableAcrossWord[x]=new Array(CrosswordHeight)}TableDownWord=new Array(CrosswordWidth);for(var x=0;x<CrosswordWidth;x++){TableDownWord[x]=new Array(CrosswordHeight)}for(var y=0;y<CrosswordHeight;y++){for(var x=0;x<CrosswordWidth;x++){TableAcrossWord[x][y]=-1;TableDownWord[x][y]=-1}}for(var i=0;i<=LastHorizontalWord;i++){x=WordX[i];y=WordY[i];for(var j=0;j<WordLength[i];j++){TableAcrossWord[x+j][y]=i}}for(var i=LastHorizontalWord+1;i<Words;i++){x=WordX[i];y=WordY[i];for(var j=0;j<WordLength[i];j++){TableDownWord[x][y+j]=i}}for(var y=0;y<CrosswordHeight;y++){document.writeln("<tr>");for(var x=0;x<CrosswordWidth;x++){if(TableAcrossWord[x][y]>=0||TableDownWord[x][y]>=0){document.write('<td id="c'+PadNumber(x)+PadNumber(y)+'" class="box boxnormal_unsel" onclick="SelectThisWord(event);">&nbsp;</td>')}else{document.write("<td></td>")}}document.writeln("</tr>")}Initialized=true;document.getElementById("waitmessage").style.display="none";document.getElementById("crossword").style.display="block"}function WordEntryKeyPress(a){if(CrosswordFinished){return}if(CurrentWord>=0&&a.keyCode==13){OKClick()}}function ContainsBadChars(b){for(var a=0;a<b.length;a++){if(BadChars.indexOf(b.charAt(a))>=0){return true}}return false}function PadNumber(a){if(a<10){return"00"+a}else{if(a<100){return"0"+a}else{return""+a}}}function CellAt(a,b){return document.getElementById("c"+PadNumber(a)+PadNumber(b))}function DeselectCurrentWord(){if(CurrentWord<0){return}document.getElementById("answerbox").style.display="none";ChangeCurrentWordSelectedStyle(false);CurrentWord=-1}function ChangeWordStyle(d,c){if(d<0){return}var a=WordX[d];var e=WordY[d];if(d<=LastHorizontalWord){for(var b=0;b<WordLength[d];b++){CellAt(a+b,e).className=c}}else{for(var b=0;b<WordLength[d];b++){CellAt(a,e+b).className=c}}}function ChangeCurrentWordSelectedStyle(d){if(CurrentWord<0){return}var a=WordX[CurrentWord];var c=WordY[CurrentWord];if(CurrentWord<=LastHorizontalWord){for(var b=0;b<WordLength[CurrentWord];b++){CellAt(a+b,c).className=CellAt(a+b,c).className.replace(d?"_unsel":"_sel",d?"_sel":"_unsel")}}else{for(var b=0;b<WordLength[CurrentWord];b++){CellAt(a,c+b).className=CellAt(a,c+b).className.replace(d?"_unsel":"_sel",d?"_sel":"_unsel")}}}function SelectThisWord(a){if(CrosswordFinished){return}var l,g,c,b,h;document.getElementById("welcomemessage").style.display="none";if(CurrentWord>=0){OKClick()}DeselectCurrentWord();var f=(a.srcElement?a.srcElement:a.target);l=parseInt(f.id.substring(1,4),10);g=parseInt(f.id.substring(4,7),10);if(TableAcrossWord[l][g]>=0&&TableDownWord[l][g]>=0){CurrentWord=PrevWordHorizontal?TableDownWord[l][g]:TableAcrossWord[l][g]}else{if(TableAcrossWord[l][g]>=0){CurrentWord=TableAcrossWord[l][g]}else{if(TableDownWord[l][g]>=0){CurrentWord=TableDownWord[l][g]}}}PrevWordHorizontal=(CurrentWord<=LastHorizontalWord);ChangeCurrentWordSelectedStyle(true);l=WordX[CurrentWord];g=WordY[CurrentWord];b="";var k=0;for(c=0;c<WordLength[CurrentWord];c++){if(CurrentWord<=LastHorizontalWord){h=CellAt(l+c,g)}else{h=CellAt(l,g+c)}if(h.innerHTML!=null&&h.innerHTML.length>0&&h.innerHTML!=" "&&h.innerHTML.toLowerCase()!="&nbsp;"){b+=h.innerHTML.toUpperCase();k++}else{b+="&bull;"}}document.getElementById("wordlabel").innerHTML=b;document.getElementById("wordinfo").innerHTML=((CurrentWord<=LastHorizontalWord)?"Across, ":"Down, ")+WordLength[CurrentWord]+" letters.";document.getElementById("wordclue").innerHTML=Clue[CurrentWord];document.getElementById("worderror").style.display="none";document.getElementById("cheatbutton").style.display=(Word.length==0)?"none":"";if(k==WordLength[CurrentWord]){document.getElementById("wordentry").value=b}else{document.getElementById("wordentry").value=""}document.getElementById("answerbox").style.display="block";try{document.getElementById("wordentry").focus();document.getElementById("wordentry").select()}catch(d){}}function OKClick(){var c,a,e,b,d;if(CrosswordFinished){return}if(document.getElementById("okbutton").disabled){return}c=document.getElementById("wordentry").value.toUpperCase();if(c.length==0){DeselectCurrentWord();return}if(ContainsBadChars(c)){document.getElementById("worderror").innerHTML="The word that you typed contains invalid characters.  Please type only letters in the box above.";document.getElementById("worderror").style.display="block";return}if(c.length<WordLength[CurrentWord]){document.getElementById("worderror").innerHTML="You did not type enough letters.  This word has "+WordLength[CurrentWord]+" letters.";document.getElementById("worderror").style.display="block";return}if(c.length>WordLength[CurrentWord]){document.getElementById("worderror").innerHTML="You typed too many letters.  This word has "+WordLength[CurrentWord]+" letters.";document.getElementById("worderror").style.display="block";return}a=WordX[CurrentWord];e=WordY[CurrentWord];for(b=0;b<c.length;b++){d=CellAt(a+(CurrentWord<=LastHorizontalWord?b:0),e+(CurrentWord>LastHorizontalWord?b:0));d.innerHTML=c.substring(b,b+1)}DeselectCurrentWord()}function CheckClick(){var d,c,l,h,f,a=0,b=0,k;if(CrosswordFinished){return}DeselectCurrentWord();for(h=0;h<CrosswordHeight;h++){for(l=0;l<CrosswordWidth;l++){if(TableAcrossWord[l][h]>=0||TableDownWord[l][h]>=0){k=CellAt(l,h);if(k.className=="box boxerror_unsel"){k.className="box boxnormal_unsel"}}}}for(d=0;d<Words;d++){f="";for(c=0;c<WordLength[d];c++){if(d<=LastHorizontalWord){k=CellAt(WordX[d]+c,WordY[d])}else{k=CellAt(WordX[d],WordY[d]+c)}if(k.innerHTML.length>0&&k.innerHTML.toLowerCase()!="&nbsp;"){f+=k.innerHTML.toUpperCase()}else{f="";b++;break}}if(f!=Word[d]&&f.length>0){a++;ChangeWordStyle(d,"box boxerror_unsel")}}if(OnlyCheckOnce){CrosswordFinished=true;document.getElementById("checkbutton").style.display="none"}if(a>0&&b>0){document.getElementById("welcomemessage").innerHTML=a+(a>1?" errors":" error")+" and "+b+(b>1?" incomplete words were":" incomplete word was")+" found."}else{if(a>0){document.getElementById("welcomemessage").innerHTML=a+(a>1?" errors were":" error was")+" found."}else{if(b>0){document.getElementById("welcomemessage").innerHTML="No errors were found, but "+b+(b>1?" incomplete words were":" incomplete word was")+" found."}}}if(a+b>0){document.getElementById("welcomemessage").style.display="";return}StopTimer();var e=new Date();e.setTime(tFinal);var g=new String();if(e.getMinutes()<10){g+="0"}g+=e.getMinutes();g+=":";if(e.getSeconds()<10){g+="0"}g+=e.getSeconds();document.getElementById("timerdisplay").value=g;CrosswordFinished=true;document.getElementById("checkbutton").style.display="none";document.getElementById("congratulations").style.display="block";document.getElementById("welcomemessage").style.display="none";if(didCheat){document.getElementById("submittable").innerHTML="<blockquote>Try another puzzle without using the Cheat button and you will be able to submit a high score!</blockquote>"}else{document.getElementById("timerval").innerHTML=g;document.getElementById("f_timer").value=tFinal}}function CheatClick(){if(CrosswordFinished){return}var a=CurrentWord;document.getElementById("wordentry").value=Word[CurrentWord];OKClick();ChangeWordStyle(a,"box boxcheated_unsel");didCheat=true}function HashWord(d){var a=(d.charCodeAt(0)*719)%1138;var c=837;var b;for(b=1;b<=d.length;b++){c=(c*b+5+(d.charCodeAt(b-1)-64)*a)%98503}return c}function UpdateTimer(){if(timerID){clearTimeout(timerID);timerID=0}if(!tStart){tStart=new Date()}var b=new Date();var c=b.getTime()-tStart.getTime();b.setTime(c);var a=new String();if(b.getMinutes()<10){a+="0"}a+=b.getMinutes();a+=":";if(b.getSeconds()<10){a+="0"}a+=b.getSeconds();document.getElementById("timerdisplay").value=a;timerID=setTimeout("UpdateTimer()",1000)}function StartTimer(){tStart=new Date();document.getElementById("timerdisplay").value="00:00";timerID=setTimeout("UpdateTimer()",1000)}function StopTimer(){var a=new Date();if(!tStart){tStart=new Date()}tFinal=a.getTime()-tStart.getTime();if(timerID){clearTimeout(timerID);timerID=0}tStart=null}function ResetTimer(){tStart=null;document.getElementById("timerdisplay").value="00:00"};
