//Copyright 2001,2002,2003 Dennis J. Toms
//Create an alphabetized list
   var alpha = new Array(n);
   for (i=0; i<n; i++) {
      alpha[i] = h[i];
   }
   alpha.sort();
   //Create a scrambled index
   var indx = new Array(n);
   for (i=0; i<n; i++) {
      indx[i] = i;
   }
   var temp; var i; var j;
   for (k=0; k<20; k++) {
      i = Math.round(Math.random()*(n-1));
      j = Math.round(Math.random()*(n-1));
      temp = indx[i];
      indx[i] = indx[j];
      indx[j] = temp;
   }
   var hasFocus = null;
   var spaces = "                        ";
   var date = new Date();
   var tstart = date.getTime();
   var tstop;
   var page = "Page";

   function setButtonFocus(b) {
      hasFocus = b;
      hasFocus.value = spaces;
   }

   function setButtonLabel(t) {
      if (hasFocus != null) {
         hasFocus.value = t;
         hasFocus.blur();
         hasFocus = null;  
      }
   }

   function checkAnswers() {
      var errCount = 0;
      for (i=0; i<n; i++) {
         var txt = document.wForm.elements[i];
         <!--if (txt.value != txt.name) {-->
         if (txt.value != h[indx[i]]) {
            errCount++;
            txt.value = spaces;
         }
  
      }
      if (errCount == 0) {   
        alert(praise);
        self.location=next;
      } 
      else {
         alert("Correct: " +(n-errCount)+ " out of " +n+ "...please continue.");
      }
      
   }
     
   function clearButtons() {
      for (i=0; i<n; i++) {
         var txt = document.wForm.elements[i];
         txt.value = spaces;
      }
   }

   function initLookup() {
     if (document.tForm.lookup.checked) {
       alert("Click on a button to see the ISOM 2000 definition(s).");
     }
   }

   function lookup(b) {
     if (document.tForm.lookup.checked) {
       hasFocus = b;
       for (i=0; i<n; i++) {
         if (hasFocus.name == g[i]) {
           alert("" + d[i]);
           return;
         }
       }
     }
     else {
       setButtonFocus(b);
     }
   }

   function writePage() {
      var w = "";
      <!--w += '<H2>' +page+ " " +heading+ '</H2>';-->
      w += '  Click on a button next to a symbol; then click on a selection at the right.';
      w += '<TABLE COLS=2><TR><TD>';
      w += '<FORM NAME="wForm">';
      <!--w += '<TABLE COLS=4 WIDTH=80%>';-->
      w += '<TABLE COLS=4 WIDTH=400>';
      var j=-1;
      while (j<n-1) {
         j++;
         w += '<TR>';
         w += '<TD WIDTH=50 ALIGN=RIGHT><IMG SRC="' +g[indx[j]]+ '.gif" HEIGHT=31 WIDTH=50 ALT="Symbol"></TD>';
         w += '<TD><INPUT TYPE=BUTTON NAME="' +g[indx[j]]+ '" SIZE=20 VALUE="' +spaces+ '"';
         w += '   onClick="lookup(this)"></TD>';
         j++;
         if (j<=n-1) {
            w += '<TD ALIGN=RIGHT><IMG SRC="' +g[indx[j]]+ '.gif" HEIGHT=31 WIDTH=50 ALT="Symbol"></TD>';
            w += '<TD><INPUT TYPE=BUTTON NAME="' +g[indx[j]]+ '" SIZE=20 VALUE="' +spaces+' "';
            w += '   onClick="lookup(this)"></TD></TR>';
         }
      }
      w += '</TABLE>';
      w += '</FORM>';
      w += '<FORM NAME="sForm">';
      w += '<TD WIDTH=50> </TD>';
      w += '<TD><B>' + criterion + '</B><P>';
      for (i=0; i<m; i++) {
         var txt = b[i];
         w += '<INPUT TYPE=BUTTON VALUE=\"' +txt+ '\" onClick="setButtonLabel(\'' +txt+ '\')"><BR>';
      }
      w += '</FORM>';
      w += '</TD></TR></TABLE>';

      w += '<FORM NAME="tForm">';
      w += '<TABLE CELLPADDING=5>';
      w += ' <TR><TD><BIG>' +page+ " " +heading+ '</BIG>';
      w += '     &nbsp&nbsp&nbsp<INPUT TYPE=BUTTON VALUE="Check Answers" onClick="checkAnswers()">';
      w += '     <INPUT TYPE=BUTTON VALUE="Start Over" onClick="document.location.reload(true)">';
      w += '     &nbsp&nbsp&nbsp&nbsp<INPUT TYPE=CHECKBOX NAME="lookup" onClick="initLookup()"> Lookup&nbsp&nbsp&nbsp</TD>';
      w += '     <TD>Use Lookup to view the ISOM definitions.</TD>';
      w += ' </TR>';
      w += '</TABLE>';
      w += '</FORM>';

      w += '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=5>';
      w += '  <TR BGCOLOR=#E0E0E0>';
      w += '    <TD COLSPAN=4 ALIGN="center"><SMALL>Map Skills Test</SMALL></TD>'; 
      w += '  </TR>';
      w += '  <TR BGCOLOR=#E0E0E0>';       
      w += '      <TD><A HREF=\"' +page+ '_A.html\"><SMALL>' +page+ ' A</SMALL></A></TD>';
      w += '      <TD><A HREF=\"' +page+ '_B.html\"><SMALL>' +page+ ' B</SMALL></A></TD>'; 
      w += '      <TD><A HREF=\"' +page+ '_C.html\"><SMALL>' +page+ ' C</SMALL></A></TD>';  
      w += '      <TD><A HREF=\"' +page+ '_D.html\"><SMALL>' +page+ ' D</SMALL></A></TD></TR>';  
      w += '</TABLE>';

      document.write(w);
      document.close;
   }
