// 57.38.1-64.42.6, JS/GP/CWHead.js for crossword puzzles at TRINP = www.trinp.org/
//-------------------------------------------------------------------------->

finishT=false; showInfoT=false; showCluesT=false; showTrayT=false;
wrong_wrdN=0; right_wrdN=0;   // global variables for score
cellDimensioN=48;  //  global variable used for cell width and height
                     //  48px largest for table with 11x11 or 12x12 cells
leftN=20;  // (620-580)/2
           // horizontal distance of PuzzleBox from left edge window/frame
wrong_letT=false;

//====================

function quickSniffO()
{
 var agtS = navigator.userAgent.toLowerCase();
 var ieT = (agtS.indexOf("msie")!=-1);
// FirefoxT = (((agtS.indexOf("mozilla")!=-1) && (majorI>4))
//           && (agtS.indexOf("firefox")!=-1));
// FirefoxT special case of Nav4UpT

 if (ieT) { IE4UpT=true; Nav4UpT=false }
  else { IE4UpT=false; Nav4UpT=true }

 Nav5UpT=Nav4UpT;  // temporarily
 if (Nav4UpT)
   { topS = ".top="; lftS = ".left="; docS = "document."; stlS = "";
     if (Nav5UpT)  // for Netscape 6 and 7
      { docS = "document.getElementById('"; stlS = "').style" }
      else { docS = "document."; stlS = "" }  // for Netscape 4
   }
  else
   { topS=".pixelTop="; lftS=".pixelLeft="; docS="document.all.";
     stlS=".style";
   }
}

//====================

function getCluesO()
{
 var x=0; var y=0;
 var tempS='<table cellpadding="0" cellspacing="0">';

 CluesA_TableS=tempS; CluesD_TableS=tempS;
 Get_GP_CW();
 for (wordN=1; wordN<AcrA.length; wordN++)
 {
  y=0;
  while (y<NumA.length)
  {
   for (x=0; x<NumA[0].length; x++)
   { 
   if (NumA[y][x]==wordN)
    {
     if (AcrA[wordN-1]>'')
     {
      tempS ='<tr><td valign="top"><small><b>'+wordN+'</b></small>&nbsp;</td><td>';
      tempS+=AClA[wordN-1]+'&nbsp;<small>('
      tempS+=AcrA[wordN-1].length+')</small></td></tr>'
      CluesA_TableS+=tempS            
     }
     if (DwnA[wordN-1]>'')
     {
      tempS ='<tr><td valign="top"><small><b>'+wordN+'</b></small>&nbsp;</td><td>';
      tempS+=DClA[wordN-1]+'&nbsp;<small>('
      tempS+=DwnA[wordN-1].length+')</small></td></tr>'
      CluesD_TableS+=tempS            
     }
     wordN++
    }
   }
   y++
  }
 }
 CluesA_TableS+='</table>'; CluesD_TableS+='</table>'
}

//=====================================================

function Adjust_Cell(C,AnswS,inOutS)
{
 var i=inOutS.indexOf(C);
 var beginS=""; var endS="";

 while (i>-1)
 {
  beginS=inOutS.substring(0, i);
  endS  =inOutS.substring(i+1,inOutS.length);
  inOutS=beginS+AnswS+endS;
  i=inOutS.indexOf(C);
 }

 return inOutS;
}

function makePuzzlO()
{
 var tableWidth=NumA[0].length*cellDimensioN;
 var gridS=
  '<table width="'+tableWidth+'" cellpadding="0" cellspacing="0" bgcolor="#00ffff" '+
  'align="center" border="1">';
 var cell0BgrS="#000020";
 var cell1BgrS="background='../../Graf/Bkgr/HalfTrsp.gif'";
   // cell of type 0: blank; 1: letter/space only; 2: (first) letter/space and number of word
 var chrColS="#000000"; var chrBkgS='style="background:'+cell1BgrS+'"';
 var cell0S ='<td bgcolor="'+cell0BgrS+'" width="'+cellDimensioN+'" '+
  'height="'+cellDimensioN+'" align="center" valign="middle">'+
  '<font color="'+cell0BgrS+'">&#149;</font></td>';
    // with symbol for printing
// var cell1S ='<td bgcolor="'+cell1BgrS+'" width="'+cellDimensioN+'" '+
 var cell1S ='<td '+cell1BgrS+' width="'+cellDimensioN+'" '+
  'height="'+cellDimensioN+'" align="left" valign="top" id="CellXY">&nbsp;</td>';
// var cell2S ='<td bgcolor="'+cell1BgrS+'" width="'+cellDimensioN+'" '+
 var cell2S ='<td '+cell1BgrS+' width="'+cellDimensioN+'" '+
  'height="'+cellDimensioN+'" align="left" valign="top" id="CellXY">'+
  '<font face="Courier"><small><a '+
  'href="javascript:Enter_Words(!)">!</a></small>';
    // symbol '!' indicates place of number
 var buttonS=
  '<table height="'+cellDimensioN+'" align="center" id="InfoNScore"><tr>'+
   '<td><table bgcolor="#808080" border="1"><tr><td><font size="-1" face="Courier">&nbsp;'+
    '<a href="JavaScript:showInfO()" class="Button">&nbsp;INFO&nbsp;</a>&nbsp;</font>'+
    '</td></tr></table></td>'+
   '<td width="16"> </td>'+
   '<td><table bgcolor="#808080" border="1"><tr><td><font size="-1" face="Courier">&nbsp;'+
    '<a href="JavaScript:showCluesO()" class="Button">&nbsp;CLUES&nbsp;</a>&nbsp;</font>'+
    '</td></tr></table></td>'+
   '<td width="16"> </td>'+
   '<td><table bgcolor="#808080" border="1"><tr><td align="center"><font '+
    'size="-1" face="Courier">&nbsp;<a href="JavaScript:switchTrayO()" '+
    'class="Button">&nbsp;SHOW/HIDE TRAY&nbsp;</a>&nbsp;</font>'+
    '</td></tr></table></td>'+
   '<td width="16"> </td>'+
   '<td><table bgcolor="#808080" border="1"><tr><td><font size="-1" face="Courier">&nbsp;'+
    '<a href="JavaScript:showScorO()" class="Button">&nbsp;SCORE&nbsp;</a>&nbsp;</font>'+
    '</td></tr></table></td>'+
  '</tr></table>';
 var tempS='';

 for (var y=0; y<NumA.length; y++)
 {
  gridS+="<tr>";
  for (var x=0; x<NumA[y].length; x++)
  {
   if (NumA[y][x]==99) gridS+=cell0S;
    else
    {
     if (NumA[y][x]>0)
       { var numberS=NumA[y][x];
         if (numberS.charAt(0)=="0") numberS=numberS.substring(1);
         tempS=Adjust_Cell('!',numberS,cell2S) }
      else tempS=cell1S;
     tempS=Adjust_Cell('X',x,tempS);
     tempS=Adjust_Cell('Y',y,tempS);
     if ((AnsA[y][x]=="") || (AnsA[y][x]=="_")) AnsA[y][x]="&nbsp;";
     gridS+=tempS
    } //else
  } //for
  gridS+="</tr>";
 } //for
 gridS+="</table>";
 puzzlS=gridS+buttonS+'</div>'
}

function showPuzzlO()
{  // only used one time, when starting
 var x_inner=0;
 var alphabetS="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 var letterI=0; var I=0; var C=' ';
 var leftI=0; var l_QuoteS='"0px"'; var topI=0; var t_QuoteS='"0px"';
 var chrColS="#000000";
 var trayS=
   '<table width="100%" background="../../Graf/Bkgr/HalfTrsp.gif" '+
   'border="2"><tr height="390"><td valign="bottom" align="right">'+
   '<font color="#000000" id="TrayText"><b>LETTER TRAY &nbsp;<br />'+
   'with tiles (still) available</b> &nbsp;<br />'+
   '<br /><br />'+
   '<small>Interactive crossword puzzles &nbsp;<br />'+
   'on TRINPsite and MVVM &nbsp;<br />'+
   '&copy; M. Vincent van Mechelen, 60-64 aSWW &nbsp;</small></font></td></tr>'+
   '</table>';

 if (BodyObjsT) leftN=Math.round((displayWidN+2-580)/2);
   // (700+2-580)/2=121/2
 makePuzzlO();
 window.document.write('<div id="PuzzleBox" style="left:'+leftN+'px">');
 window.document.write(puzzlS+'</div>');

 topI=223+((NumA[0].length+1)*(cellDimensioN+2));
 window.document.write('<div id="LetterTray" style="top:'+topI+'px">');
 window.document.write(trayS+'</div>');
 eval(docS+"TrayText"+stlS+'.background="#e0e0e0"');

   UseA = new Array();  // 26x14 array with truth values for letter tiles
     // 'true' now means 'no tile in store'; later it also means 'in use'
     // max is 9+5=14 tiles with an A, min is 2 tiles; first based on Scrabble:
     // A9, B2, C2, D4, E12, F2, G3, H2, I9, J1+1, K1+1, L4, M2, N6, O8, P2
     // Q1+1, R6, S4, T6, U4, V2, W2, X1+1, Y2, Z1+1: 98+5=103 letter tiles;
     // then added for min needed: A5, C1, E1, H3, I1, L3, M2, N4, P1, R2,
     // S2, V1: 103+26=129 tiles in total

     // A9, B2+1, C2+1, D4, E12, F2+1, G3, H2+1, I9, J1+2, K1+2, L4, M2+1, N6, O8, P2+1,
     // Q1+2, R6, S4, T6, U4, V2+1, W2+1, X1+2, Y2+1, Z1+2: 98+18=116 letter tiles;
     // then added for min needed: A5, E1, H3, I1, L3, M1, N4, R2, S2:
     // 116+22=138 tiles in total


   UseA[0] =new Array(false,false,false,false,false,false,false,false,false,false,false,false,false,false); // A
   UseA[1] =new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // B
   UseA[2] =new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // C
   UseA[3] =new Array(false,false,false,false,true,true,true,true,true,true,true,true,true,true); // D
   UseA[4] =new Array(false,false,false,false,false,false,false,false,false,false,false,false,false,true); // E
   UseA[5] =new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // F
   UseA[6] =new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // G
   UseA[7] =new Array(false,false,false,false,false,true,true,true,true,true,true,true,true,true); // H
   UseA[8] =new Array(false,false,false,false,false,false,false,false,false,false,true,true,true,true); // I
   UseA[9] =new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // J 
   UseA[10]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // K
   UseA[11]=new Array(false,false,false,false,false,false,false,true,true,true,true,true,true,true); // L
   UseA[12]=new Array(false,false,false,false,true,true,true,true,true,true,true,true,true,true); // M
   UseA[13]=new Array(false,false,false,false,false,false,false,false,false,false,true,true,true,true); // N
   UseA[14]=new Array(false,false,false,false,false,false,false,false,true,true,true,true,true,true); // O
   UseA[15]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // P
   UseA[16]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // Q
   UseA[17]=new Array(false,false,false,false,false,false,false,false,true,true,true,true,true,true); // R
   UseA[18]=new Array(false,false,false,false,false,false,true,true,true,true,true,true,true,true); // S
   UseA[19]=new Array(false,false,false,false,false,false,true,true,true,true,true,true,true,true); // T
   UseA[20]=new Array(false,false,false,false,true,true,true,true,true,true,true,true,true,true); // U
   UseA[21]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // V
   UseA[22]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // W
   UseA[23]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // X
   UseA[24]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // Y
   UseA[25]=new Array(false,false,false,true,true,true,true,true,true,true,true,true,true,true); // Z

   for (letterI=0; letterI<=25; letterI++)
   {
    C=alphabetS.charAt(letterI);
    for (I=1; I<=UseA[0].length; I++)
    {
     if (UseA[letterI][I-1]==false)
      {
       cellS='<div id="PuzzleBox"><div class="GivenLetter" id="'+C+I+'">'+
       '<table width="32" height="32" bgcolor="#ffff00" border="0" class="Tile"><tr>'+
       '<td align="center" valign="middle">';
       if (Nav4UpT) cellS+='<small>';  // because of resizing effects
       cellS+='<b><font face="Courier" color="'+chrColS+'">'+C+'</font></b>';
       if (Nav4UpT) cellS+='</small>'; 
       cellS+='</td></tr></table></div></div>';
  // absolute position in PuzzleBox layer, because relative position on
  // LetterTray does not work in IE (even tho working in Firefox)
       window.document.write(cellS);
       if (I<11)
         {
          leftI=10+(letterI*38); 
          topI=((NumA[0].length+1)*cellDimensioN)+I*38
         }
        else  // if >10 tiles of one letter, then in second column
         {
          leftI=48+(letterI*38);
          topI=((NumA[0].length+1)*cellDimensioN)+798-(I*38)
         }                           // (10+1)*38-(I-10)*38
       moveTileO(C+I,leftI,topI,false)
      } // if
    } // for
   } // for
}

function moveTileO(S,I1,I2,T)
{
 var objS=S; var leftI=I1; var topI=I2; var visibleT=T;

 if (Nav5UpT)
   { l_QuoteS='"'+parseInt(leftI)+'px"';  // value with "px" 
     t_QuoteS='"'+parseInt(topI)+'px"';   // between quotes
     eval(docS + objS + stlS + lftS + l_QuoteS);
     eval(docS + objS + stlS + topS + t_QuoteS) }
  else 
   { eval(docS + objS + stlS + lftS + leftI);
     eval(docS + objS + stlS + topS + topI) }
 if (visibleT==true)
   eval(docS + objS + stlS + '.visibility="visible"');
  else
   eval(docS + objS + stlS + '.visibility="hidden"');
}

function locateInputO(N1,N2,T,S)
{
 var x_wordN=N1; var y_wordN=N2; var acrosT=T; var wordS=S;
 var letterI=26; var placeI=-1; var objS='';
 var objTopS=".pixelTop";  if (Nav4UpT) objTopS=".top";
 var C_N_S="?0";
 var I=0; var J=1;
 var margiN=Math.round((580-NumA[0].length*cellDimensioN)/2);
   // 580 fixed width of PuzzleBox (usually wider than puzzle)
 var leftI=0;
 var l_QuoteS='"0px"'; var topI=0; var t_QuoteS='"0px"'; 
 var cellHeightN=parseInt(cellDimensioN)+2;
   if (Nav4UpT) cellHeightN=cellHeightN-2;
 
 margiN=margiN+parseInt(cellDimensioN)-37;
   // to locate tile (32 wide) to the (bottom) right of cell

 for (I=0; I<wordS.length; I++)
 { leftI=0;
   letterI=wordS.charCodeAt(I)-65;
   objS=wordS.charAt(I);
   if (acrosT)
     { if (AnsA[y_wordN][x_wordN+I].charAt(0)==objS) leftI=-1 }
    else
     { if (AnsA[y_wordN+I][x_wordN].charAt(0)==objS) leftI=-1 }
   if (leftI>-1)
    {
     J=UseA[0].length-1;
     while ((J<UseA[0].length) && (J>-1)) 
      {
       if (UseA[letterI][J]==false) { UseA[letterI][J]=true; placeI=J+1; J=-1 }
       J--  // J=-1 becomes J=-2
      } // end while
     if (J==-1)
       { 
        alert("Alas, there are no "+objS+"'s anymore! (See tiles on tray.)");
        I=wordS.length }
      else
       {
        objS=wordS.charAt(I)+placeI;
        if (acrosT) C_N_S=AnsA[y_wordN][x_wordN+I];
               else C_N_S=AnsA[y_wordN+I][x_wordN]; 
        letterI=C_N_S.charCodeAt(0);
        if ((letterI>64) && (letterI<91))
         {
          letterI=letterI-65;
          J=parseInt(C_N_S.substring(1))-1;  // number may be 2 digits!
          UseA[letterI][J]=false;

       if (J<10)  // (J+1)<11
         {
          leftI=10+(letterI*38); 
          topI=((NumA[0].length+1)*cellDimensioN)+J*38+38
         }
        else
         {
          leftI=48+(letterI*38);
          topI=((NumA[0].length+1)*cellDimensioN)+760-(J*38)
         }                                 // 798-((J+1)*38) 
          moveTileO(C_N_S,leftI,topI,showTrayT)
         }  
        if (acrosT)
          {
           AnsA[y_wordN][x_wordN+I]=objS;
           leftI=(x_wordN+I)*cellDimensioN;
           topI=10+y_wordN*cellHeightN;
          }
         else
          { 
           AnsA[y_wordN+I][x_wordN]=objS;
           leftI=x_wordN*cellDimensioN;
           topI=10+(y_wordN+I)*cellHeightN;
          }
        moveTileO(objS,leftN+margiN+leftI,topI,true);
       }  // end else
    }  // end if 
    wrong_wrdN=-1;  // temporarily, to make sure that a word has been entered
  } // end for
}

function plainTextO(S)
{  // deletes hypertext codes between square brackets
   // char codes between '&' and ';' will be replaced by one character
 var inS=S; var outS="";
 var brackCodeT=false; var ampCodeI=-1;
 var I=0; var C="?";

 for (I=0; I<inS.length; I++)
 {
  C=inS.charAt(I);
  if (C=="<") brackCodeT=true;
  if (C=="&") ampCodeI=I;
  if ((!brackCodeT) && (ampCodeI==-1)) outS=outS+C;
  if (C==">") brackCodeT=false;
  if ((C==";") && (ampCodeI>-1))
   { C=inS.charAt(ampCodeI+1);
     if (C=="n") C=" ";  // for '&nbsp;'
     outS=outS+C;
     ampCodeI=-1 }
 } // for

 return outS
}

function Enter_Words(N)
{
 var wordN=N;
 var acrosC=''; var acrosT=true;
 var x=0; var y=0;
 var x_wordN=-1; var y_wordN=0;
 var msgS="!!"; var inS="??"; var formerS="??";
 var alertS='After having seen the results you cannot continue!'+
   '\nTo start again you will first have to reload this page.'

if (finishT) alert(alertS);
else
{

 while (x_wordN<0)
  {
   for (x=0; x<NumA[0].length; x++)  // no 'while' within 'while'!
   { 
    if (NumA[y][x]==wordN) { x_wordN=x; y_wordN=y }
   }
   y++
  }
 if ((AcrA[wordN-1]>'') && (DwnA[wordN-1]>''))
   {
    if (AnsA[y_wordN][x_wordN+1]!='&nbsp;') 
      { msgS="Do you mean "+wordN+" down?"; acrosT=false }
     else msgS="Do you mean "+wordN+" across?";
    if (IE4UpT)  // use VBScript
      {
       returnI = window.makeMsgBox("Across or down?",msgS,32,4,0,0);
       if (returnI==7) acrosT=!acrosT
      }
     else  // use JavaScript
      {
       if (!window.confirm(msgS)) acrosT=!acrosT
      }
   }
  else
   { if (AcrA[wordN-1]>'') acrosT=true; else acrosT=false }

 msgS='ENTER/CHANGE WORD '+wordN;
 if (acrosT)
   msgS+=' across ('+AcrA[wordN-1].length+' letters)\nCLUE: '+plainTextO(AClA[wordN-1]);
  else
   msgS+=' down ('+DwnA[wordN-1].length+' letters)\nCLUE: '+plainTextO(DClA[wordN-1]);

 formerS="";
 while (inS=="??")
 { inS=prompt(msgS,formerS); formerS=inS;
   if (acrosT) x=AcrA[wordN-1].length; else x=DwnA[wordN-1].length;
   if (inS!=null)
    {
     if (inS.length>x)
       { alert('Your entry is too long!'); inS="??" }
      else
       {
        inS=inS.toUpperCase(); x=0;
        for (x=0; x<inS.length; x++)
        { y=inS.charCodeAt(x);
          if ((y<65) || (y>90))
           { alert('Please, use letters only! (See tiles at bottom.)');
             x=inS.length; inS="??" }
        } // for
       } // else
    } // if
 } // while

 if (inS!=null) locateInputO(x_wordN,y_wordN,acrosT,inS)

}  // else (finishT=false)
}

//===============================

function onClickO(S)
{
 var NewFileS=S; var newFileS=NewFileS.toLowerCase();
 var pathS=PathS.toLowerCase();
 var windoS="width=622,height=330,resizable=yes,scrollbars=yes,toolbar=yes";
// EXTRA AT MVVM
 var alertS="This link does not work in the present inline frame or "+
  "pop-up window. Load the puzzle into the (original) parent window, if you "+
  "would like to make use of this link.";

 if (iFrameT)  // EXTRA AT MVVM
  {
//
 if (pathS.indexOf('///')>-1)
  pathS='file://c:'+pathS.substring(10);  // off-line '///C|'='//C:'
 if (newFileS.indexOf('file:///c')>-1)
  newFileS='file://c:'+newFileS.substring(10);  // off-line '///C|'='//C:'
 if ((newFileS.indexOf(pathS)>-1) || (newFileS.indexOf('../')>-1)
     || (newFileS.indexOf('file://')>-1))
   { window.TRNP_IRight1.location.href=NewFileS
     eval(docS+'CluesBox'+stlS+'.visibility="hidden"');
     eval(docS+'InfoBox'+stlS+'.visibility="hidden"');
     showCluesT=false; showInfoT=false;
// iFrameContenT=true
 } 
  else  // differs from popUpO(), which uses frame content exclusively 
   { NewFileS+='#iFrame';
     if (iFramePopUpT && iFramePopUp.closed) iFramePopUpT=false;
     if (iFramePopUpT)
       { iFramePopUp.location.replace(NewFileS); iFramePopUp.focus() }
      else 
       { createNewVu("iFramePopUp",NewFileS,"TITLE",windoS);
         iFramePopUpT=true }
   }

  }
  else alert(alertS)  // EXTRA AT MVVM

}
/*
function onClickO(S)
{
 var NewFileS=S;
 if ((NewFileS.indexOf(PathS)>-1) || (NewFileS.indexOf('../')>-1))
   { window.TRINP_IRight.location.href=NewFileS;
     eval(docS+'CluesBox'+stlS+'.visibility="hidden"');
     eval(docS+'InfoBox'+stlS+'.visibility="hidden"');
     showCluesT=false; showInfoT=false; iFrameContenT=true }
  else popUpO();
}
*/

function redefinedLinksO(S)  // pages linked to will be shown in iframe
{                   // or pop-up window instead of parent/opener window
 var boxS=S;
 var I=boxS.indexOf(' href="') // only lower case href="..."
 var J=0;
 var fileS="name.html";

 while (I>-1)
 {
  J=boxS.substring(I+7).indexOf('"');
  fileS="'"+boxS.substring(I+7,I+J+7)+"'";
  boxS=boxS.substring(0,I+1)+
   'HREF="JavaScript:onClickO('+fileS+')"'+
   boxS.substring(I+J+8);
  I=boxS.indexOf(' href="')  // now upper case HREF="..." discarded
 }

 return boxS
}

function makeWarningBoxO()  // FROM MVVM-SITE
{
 var warningS=
  '<span class="Info">'+
  '<b>WARNING</b>:<br />'+
  'by following a link on the left of this frame or in one of '+
  'the two top floating menus you will lose the puzzle and everything you '+
  'may already have filled in.<br />'+
  'However, apart from the links in the top right (TRINPsite) menu, you '+
  'can safely click on any link in or over this inline frame without '+
  'abandoning the puzzle.<br />'+
  '(This message will be deleted after clicking INFO or CLUES.)'+
  '</span>';

 document.write('<div align="left" id="WarningBox">');
 document.write(warningS);
 document.write('</div>');
}

function makeInfoBoxO()
{
 var infoS=
  '<table height="100%" cellpadding="0" cellspacing="0">'+
   '<tr><td valign="top" align="left">'+
    '<b class="Theme">'+themeS+'</b>'+
    '<hr />'+
    '<span class="Info">'+
    '<b>G E N E R A L &nbsp; I N F O R M A T I O N<br />for all '+
    '<a href="../Pzzl.htm">TRINPsite crossword puzzles</a></b>'+
    '<br/><br />'+
    'You can enter any number of words in any order. To '+
    '<nobr>(re)enter</nobr> '+
    '(the beginning of) a particular word click its number.<br />'+
    'The letters chosen must still be available from the letter tray, '+
    'which may or may not be made visible at the bottom of this page. '+
    '(If there are spelling variants, there will be a hint in the clue.)<br />'+
    'The INFO, CLUES and TRAY buttons on the left are ON/OFF buttons for '+
    'visible/invisible.<br />'+
    'You can see your final SCORE and find out which <nobr>word(s)</nobr> '+
    'are correct at any moment. Cells with wrong letters are colored red, '+
    'the other cells green.<br />'+
    'To return to the Across and Down clues in this frame press the CLUES '+
    'button on the left.</span></td></tr>'+
   '<tr><td valign="bottom" align="right" class="Info"><br />'+
    '&copy; M. Vincent van Mechelen, 64 aSWW&nbsp;'+
   '</td></tr>'+
  '</table>';

 document.write('<div id="InfoBox">');
 document.write(redefinedLinksO(infoS));
 document.write('</div>');
}

function makeCluesBoxO()
{
 var boxS=
  '<b class="Theme">'+themeS+'</b>'+
  '<hr />'+
  '<span class="Info">'+
  '<b>A C R O S S</b><br />'+
  CluesA_TableS+'<br />'+
  '<b>D O W N</b><br />'+
  CluesD_TableS+
  '</span>';

 document.write('<div id="CluesBox">');
 document.write(redefinedLinksO(boxS));
 document.write('</div>');
}

function showIFramesColBoxesO()
{
 if (iFrameT && PostPageT)
  { makeWarningBoxO(); moveToIFramesColLeftO("WarningBox");
    makeCluesBoxO(); moveToIFramesColLeftO("CluesBox");
    makeInfoBoxO(); moveToIFramesColLeftO("InfoBox"); }
}

//===========================================================

function showInfO()
{
 if (showInfoT)
   { eval(docS+'InfoBox'+stlS+'.visibility="hidden"');
     showInfoT=false }
  else
   { eval(docS+'WarningBox'+stlS+'.visibility="hidden"');
     eval(docS+'CluesBox'+stlS+'.visibility="hidden"');
     eval(docS+'InfoBox'+stlS+'.visibility="visible"');
     showInfoT=true; showCluesT=false }
}

function showCluesO()
{
 if (showCluesT)
   { eval(docS+'CluesBox'+stlS+'.visibility="hidden"');
     showCluesT=false }
  else
   { eval(docS+'WarningBox'+stlS+'.visibility="hidden"');
     eval(docS+'CluesBox'+stlS+'.visibility="visible"');
     eval(docS+'InfoBox'+stlS+'.visibility="hidden"');
     showCluesT=true; showInfoT=false }
}

function switchTrayO()
{
 var tableHeight=(NumA[0].length+1)*cellDimensioN;  // includes buttons
 var alphabetS="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

 showTrayT=!showTrayT
 if (showTrayT)
   eval(docS + "LetterTray" + stlS + '.visibility="visible"');
  else
   {
    eval(docS + "LetterTray" + stlS + '.visibility="hidden"');
    if (Nav4UpT)
     eval(docS+"PuzzleBox"+stlS+'.height="'+tableHeight+'px"');
       // PuzzleBox reduced because otherwise links not accessible
   }

 for (var letterI=0; letterI<=25; letterI++)
 {
  C=alphabetS.charAt(letterI);
  for (var I=1; I<=UseA[0].length; I++)
  {
   if (UseA[letterI][I-1]==false)
    {
     objS=C+I;
     if (showTrayT)
       eval(docS + objS + stlS + '.visibility="visible"');
      else
       eval(docS + objS + stlS + '.visibility="hidden"');
    } // if
  } // for
 } // for
}

function showScorO()
{
 var x=0; var x2=0; var y=0; var y2=0; var z=0;
 var totN=0; var I=0;
 var wrong_letS="x";
 var pluralS="s";

 if (finishT) wrong_wrdN=-1;  // to see score again

 if (wrong_wrdN==-1)
  {
   wrong_wrdN=0;  // initial value given back
   finishT=true;

 for (y=0; y<NumA.length; y++)
 {
  for (x=0; x<NumA[y].length; x++)
  {
   if (NumA[y][x]<99)
    {
      for (var wordN=1; wordN<=AcrA.length; wordN++)
      {
       if (NumA[y][x]==wordN)
       {
        if (AcrA[wordN-1]>'')
        {
         wrong_letT=false;
         for (z=0; z<AcrA[wordN-1].length; z++)
         {
          x2=x+z; 
          objS='Cell'+x2; objS=objS+y;
          if ((AnsA[y][x2]!="_") && (AnsA[y][x2].charAt(0)!=AcrA[wordN-1].charAt(z)))
            {
             if (AnsA[y][x2]!=wrong_letS)
              {
               eval(docS + objS+ stlS + '.background="#e02020"');
               AnsA[y][x2]=wrong_letS
              }
             wrong_letT=true
            }
           else 
            {
             AnsA[y][x2]=AnsA[y][x2].charAt(0);
             eval(docS + objS+ stlS + '.background="#c0e0c0"')
            }
         }
         if (wrong_letT) wrong_wrdN++; else right_wrdN++;
        }
        if (DwnA[wordN-1]>'')  // a number may be BOTH across AND down!
        {
         wrong_letT=false;
         for (var z=0; z<DwnA[wordN-1].length; z++)
         {
          y2=y+z;
          objS='Cell'+x; objS=objS+y2;
          if ((AnsA[y2][x]!="_") && (AnsA[y2][x].charAt(0)!=DwnA[wordN-1].charAt(z)))
            {
             if (AnsA[y2][x]!=wrong_letS)
              {
               eval(docS + objS+ stlS + '.background="#e02020"');
               AnsA[y2][x]=wrong_letS
              }
             wrong_letT=true
            }
           else
            {
             AnsA[y2][x]=AnsA[y2][x].charAt(0);
             eval(docS + objS+ stlS + '.background="#c0e0c0"')
            }
         }
         if (wrong_letT) wrong_wrdN++; else right_wrdN++;
        }
       wordN=AcrA.length+1

      } // for
     } //if
   } //if
  } //for
 } //for

   totN=right_wrdN+wrong_wrdN;  // total no. of words
   I=Math.round((100*right_wrdN)/totN)
    // % of words right

   if (right_wrdN==1) pluralS="";
   alert("Score: "+right_wrdN+" word"+pluralS+" of "+totN+"  ("+I+"% correct)")
   wrong_wrdN=0; right_wrdN=0;  // in case score is revisited
  }
  else alert('You have not entered any word yet')
}

// (C) 57-64 ASWW, M. Vincent van Mechelen