/*
This builds the page header and menus.
*/

function HeaderArray(){

    document.write('<table id="top" border="0" cellpadding="0" cellspacing="0" width="100%"><tbody>');

       document.write('<tr>');
          document.write('<td><table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody>');
             document.write('<tr>');
                document.write('<td width="120"><a href="' + mailto + '?subject=' + recordSet + '"><img alt="' + mailtoName + '" border="0" height="30" src="' + reference_server + root + includes + 'DavidEllis.gif" width="120"></a></td>');
                document.write('<td width="100%"><img alt="" border=0 height=30 src="' + reference_server + root + includes + 'row1filler.gif" width="100%"></td>');
                document.write('<td width=460><img alt="" border=0 height=30 src="' + reference_server + root + includes + 'Title.gif" width="460"></td>');
             document.write('</tr>');
          document.write('</tbody></table></td>');
       document.write('</tr>');

       document.write('<tr>');
          document.write('<td><table border="0" cellPadding="0" cellSpacing="0" width="100%"><tbody>');

             document.write('<tr>');
                document.write('<td width="100%"><img alt="" border="0" height="14" src="' + reference_server + root +includes + 'row2filler.gif" width="100%"></td>');
                document.write('<td width="56"><a href="' + reference_server + root + 'Index.htm"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'home.gif"></a></td>');
                document.write('<td width="3"><img alt="" border="0" width="3" height="14" src="' + reference_server + root + includes + 'row2shadow.gif"></td>');
             document.write('</tr>');

             document.write('<tr>');
                document.write('<td width="100%"><img alt="" border="0" width="100%" height="4" src="' + reference_server + root + includes + 'row3filler.gif" width="100%"></td>');
                document.write('<td width="56"><img alt="" border="0" width="56" height="4" src="' + reference_server + root + includes + 'row3filler.gif"></td>');
                document.write('<td width="3"><img alt="" border="0" width="3" height="4" src="' + reference_server + root + includes + 'row3right.gif"></td>');
             document.write('</tr>');

          document.write('</tbody></table></td>');
       document.write('</tr>');

    document.write('</tr></tbody></table>');

} //HeaderArray

/*
This builds a standard page footer.
*/

function Footer(theDate){

    document.write('<hr>');

    document.write('<table border="0" cellpadding="0" cellspacing="0" width="100%"><tbody>');

        document.write('<tr><td width="325" style="color:#003333">Go to <a href="#top">top of page</a>.</td>');
        document.write('<td style="color:#003333; text-align:right">Contact <a href="' + mailto + '?subject=' + recordSet + '">' + mailtoName + '</a>&nbsp;</td></tr>');
        document.write('<tr><td colspan="2" style="color:#003333; text-align:center">© ' + theDate + ' David J. Ellis</td></tr>');
        document.write('<tr><td height="14" colspan="2"></td></tr>');
        document.write('<tr><td width="100%" colspan="2"><img alt="" border="0" height="19" src="' + reference_server + root + includes + 'footerfiller.gif" width="100%"></td></tr>');

    document.write('</tbody></table>');

} //Footer

/*
This builds the single level image sequencer.
*/

function ImageSequencer(theTitle,theImage,thePrevious,theNext,theWidth){

    document.write('<table bgColor=#fafafa border="0" cellPadding=4 cellSpacing="0" height="1" width="100%"><tbody>');

       document.write('<tr><td align=left bgColor=#fafafa height=40 vAlign=top width="100%">');
          document.write('<font style="color: darkblue; font-family: Arial; font-size: 21px; font-style: italic; font-weight: bold">');
          document.write(theTitle + '</font>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="100%">');
          document.write('<table border="0" cellPadding="0" cellSpacing="0" width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + thePrevious + '"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Previous.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width="64">');
             document.write('<a href="' + reference_server + root + pages + theNext + '"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Next.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="100%">');
           if(typeof theWidth=="undefined" || theWidth==""){
             document.write('<img alt="" border="0" src="' + reference_server + root + images + theImage +'">');
           } else {
             document.write('<img alt="" border="0" src="' + reference_server + root + images + theImage +'" width="' + theWidth + '">');
           }
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="100%">');
          document.write('<table border="0" cellPadding="0" cellSpacing="0" width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + thePrevious + '"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Previous.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + theNext + '"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Next.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
          document.write('</td></tr>');

       document.write('</tbody></table>');

} //ImageSequencer

/*
This builds the second level (left and right) image sequencer.
*/

function ImageSequencer2(theTitle,theImage,thePrevious,theNext,theLeft,theRight,theWidth){
    document.write('<table bgColor=#fafafa border=0 cellPadding=4 cellSpacing=0 height=1 width="100%"><tbody>');

       document.write('<tr><td align=left bgColor=#fafafa height=40 vAlign=top width="100%">');
          document.write('<font style="color: darkblue; font-family: Arial; font-size: 21px; font-style: italic; font-weight: bold">');
          document.write(theTitle + '</font>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width="100%">');
          document.write('<table border=0 cellPadding=0 cellSpacing=0 width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + thePrevious + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Previous.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + theNext + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Next.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width="100%">');
          document.write('<table border=0 cellPadding=0 cellSpacing=0 width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + theLeft + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Left.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + theRight + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Right.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width="100%">');
           if(typeof theWidth=="undefined" || theWidth==""){
             document.write('<img alt="" border=0 src="' + reference_server + root + images + theImage +'">');
           } else {
             document.write('<img alt="" border=0 src="' + reference_server + root + images + theImage +'" width="' + theWidth + '">');
           }
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width="100%">');
          document.write('<table border=0 cellPadding=0 cellSpacing=0 width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + thePrevious + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Previous.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + theNext + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Next.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width="100%">');
          document.write('<table border=0 cellPadding=0 cellSpacing=0 width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + theLeft + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Left.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=64>');
             document.write('<a href="' + reference_server + root + pages + theRight + '"><img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Right.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height=1 vAlign=top width=150>');
             document.write('<img alt="" border=0 height=14 src="' + reference_server + root + includes + 'Row2Filler.gif" width=152></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
       document.write('</td></tr>');

       document.write('</tbody></table>');

} //ImageSequencer2


/*

autoSequencer, which uses routines refreshImage and gotHit, is an
automatic image sequencer for files that share a root filename. It
requires two variables to be externally declared: 

var currImg = new Image(); 

currImg is used to setup and then to store each image as it is
displayed. 

var fileList = new Array(4,true,"rootFileName","fileType",s1,s2,...,sn); 

fileList is an array defining the files and containing the all the
suffixes that are to be appended to the filename root and then displayed
in sequence. The first element of the array is the count that determines
which element is to be displayed next. Normally it is preset to 4 but
may be preset to the element, or sequence, that is to be displayed
first. This is followed by a status flag that indicates if the sequencer
is running or not. This should be set to true, as shown. Next is the
root file name, i.e. that part of the filename that is common to all the
files. Next is the file type, normally ".jpg". The remaining elements
may be a list of numbers or short strings that are to be appended to the
root filename and displayed. If they are numbers they must be values in
the range 0 to 999 and leading zeros will be added by is routine so that
each is three characters long. If they are strings, they must be placed
in quotes. A range of numeric suffixes between 0 and 999 may be included
as ...,"[]",nn,min,max,... where "[]" is a value that indicates the
start of a range of values. Next is the count within the range, normally
set to equal the minimum value in the range; then the minimum value; and
finally then the maximum value. When using repeat statements, only
numeric values are permitted and the "[]" marker is required. 

Calling paramenters are the delay time in milliseconds; the page title;
and optionally, the width of the images.

*/

function autoSequencer(timer,theTitle,theWidth){

    document.write('<table bgColor=#fafafa border="0" cellPadding=4 cellSpacing="0" height="1" width="100%"><tbody>');

       document.write('<tr><td align=left bgColor=#fafafa height=40 vAlign=top width="100%">');
          document.write('<font style="color: darkblue; font-family: Arial; font-size: 21px; font-style: italic; font-weight: bold">');
          document.write(theTitle + '</font>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height=40 vAlign=top width="100%">');
          document.write('<div id="imageTitle"></div>'); // Establish a place for the image name.
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="100%">');
          document.write('<table border="0" cellPadding="0" cellSpacing="0" width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width=64>');
             document.write('<a href="javascript:refreshImage(-1)"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Previous.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width="64">');
             document.write('<a href="javascript:refreshImage(1)"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Next.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="100%">');

          refreshImage(0);
          if(typeof theWidth=="undefined" || theWidth==""){
             document.write('<a href="javascript:gotHit(' + timer + ')">' +
                            '<img alt="" border=0 src="' + currImg.src + '" name="displayImage"></a>');
          } else {
             document.write('<a href="javascript:gotHit(' + timer + ')">' +
                            '<img alt="" border=0 src="' + currImg.src + '" name="displayImage" width="' + theWidth + '">');
          }

       document.write('</td></tr>');

       document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="100%">');
          document.write('<table border="0" cellPadding="0" cellSpacing="0" width="950"><tbody>');
             document.write('<tr><td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width=64>');
             document.write('<a href="javascript:refreshImage(-1)"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Previous.gif" width=64></a></td>');
             document.write('<td width="100%"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'row2filler.gif" width="100%"></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width=64>');
             document.write('<a href="javascript:refreshImage(1)"><img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Next.gif" width=64></a></td>');
             document.write('<td align=left bgColor=#fafafa height="1" vAlign=top width="150">');
             document.write('<img alt="" border="0" height="14" src="' + reference_server + root + includes + 'Row2Filler.gif" width="152"></td>');
             document.write('</tr>');
          document.write('</tbody></table>');
          document.write('</td></tr>');

       document.write('</tbody></table>');

       refreshImage(timer);

} // autoSequencer

/*
This routine refreshes the image.

The paramter "type" is 0 to initialize the routine. When "type" is set to -1 or 1 the images will be
sequenced without a timeout. Otherwise "type" is set to the timer delay in milliseconds and the images
will sequence without user intervention until an image is clicked.
*/

function refreshImage(type){

// First we deal with setup and indexing the count.

   i=fileList[0];
   switch (type) {
      case 0: // This is the setup call. Make sure the initial parameters are correct.
         if (i>fileList.length-1 || i<4) {i=4; fileList[0]=i;}
         if (fileList[i]=="[]") { // Initialize an inner sequence but do not increment.
            fileList[i]="[a]";
            fileList[i+1]=fileList[i+2];
         }
         fileList[1]=true;
         break;

      case 1: // This is a user controlled increment.
         if (fileList[i]!="[]") { // Handle regular incrementing first.
            if (fileList[i]=="[a]") { // Increment an inner sequence count if its active.
               fileList[i+1]++;
               if (fileList[i+1]>fileList[i+3]) { // Close an inner sequence when its done.
                  fileList[i]="[]";
                  i=i+4;
               }
            } else {
               i++;
            }
            if (i>fileList.length-1) i=4; // Wrap around at end of list.
            fileList[0]=i;
         }
         if (fileList[i]=="[]") { // If we reached an inner sequence, initialize it but do not increment.
            fileList[i]="[a]";
            fileList[i+1]=fileList[i+2];
         }
      break;

      case -1: // This is a user controlled decrement.
         if (fileList[i-3]!="[]") { // Handle regular decrementing first.
            if (fileList[i]=="[a]") { // Decrement an inner sequence count if its active.
               fileList[i+1]--;
               if (fileList[i+1]<fileList[i+2]) { // Close an inner sequence when its done.
                  fileList[i]="[]";
                  i--;
               }
            } else {
               i--;
            }
            if (i<4) i=fileList.length-1; // Wrap around at end of list.
            fileList[0]=i;
         }
         if (fileList[i-3]=="[]") { // If we reached an inner sequence, initialize it but do not decrement.
            i=i-3;
            fileList[i]="[a]";
            fileList[i+1]=fileList[i+3];
            fileList[0]=i;
         }
      break;

      default: // The timer controlled increment is presently identical to user controlled.
         if (fileList[i]!="[]") { // Handle regular incrementing first.
            if (fileList[i]=="[a]") { // Increment an inner sequence count if its active.
               fileList[i+1]++;
               if (fileList[i+1]>fileList[i+3]) { // Close an inner sequence when its done.
                  fileList[i]="[]";
                  i=i+4;
               }
            } else {
               i++;
            }
            if (i>fileList.length-1) i=4; // Wrap around at end of list.
            fileList[0]=i;
         }
         if (fileList[i]=="[]") { // If we reached an inner sequence, initialize it but do not increment.
            fileList[i]="[a]";
            fileList[i+1]=fileList[i+2];
         }
      break;

   }

// Now we handle building the filename.
   i = fileList[0];
   if (fileList[i]=="[a]") i++; // Point to the count.

   if (typeof fileList[i]=="number") {
      if (fileList[i] < 10) {
         filename = fileList[2] + '00' + fileList[i] + fileList[3];
      } else if (fileList[i] < 100) {
         filename = fileList[2] + '0' + fileList[i] + fileList[3];
      } else {
         filename = fileList[2] + fileList[i] + fileList[3];
      }
   } else {
      filename = fileList[2] + fileList[i] + fileList[3];
   }
   currImg.src = reference_server + root + images + filename;

// Display the image.
   switch (type) {
        case 0:  fileList[0]--; // Decrement count to compensate for its being pre-incremented by all other cases.
                 break;         // No need to worry about inner sequences as they will be reset.
        case 1:  document.images.displayImage.src=eval('currImg.src');
                 clearTimeout(timerid);
                 fileList[1] = false;
                 break;
        case -1: document.images.displayImage.src=eval('currImg.src');
                 clearTimeout(timerid);
                 fileList[1] = false;
                 break;
        default: document.images.displayImage.src=eval('currImg.src');
                 // This builds the call to refreshImage so that the value of "type" can be passed to setTimeout
                 functionCall = "refreshImage(" + type + ")" ;
                 timerid = setTimeout(functionCall,type);
                 break;
   }

// Finally, update the name of the image for the user
   if (document.all)
      imageTitle.innerHTML="<h5>"+filename+" - click to stop/start sequencing.</h5>";
   else if (document.getElementById){
      rng = document.createRange();
      el = document.getElementById("imageTitle");
      rng.setStartBefore(el);
      htmlFrag = rng.createContextualFragment("<h5>"+filename+" - click to stop/start sequencing.</h5>");
      while (el.hasChildNodes()) el.removeChild(el.lastChild);
      el.appendChild(htmlFrag);
   }

} // refreshImage

/*
This routine stops sequencing or restarts it if the user clicks on the image.
*/

function gotHit(delay){
   if (fileList[1]) {
      fileList[1] = false;
      clearTimeout(timerid);
   } else {
      fileList[1] = true;
      refreshImage(delay);
   }
} // gotHit


/*
Following are several routines that manage lists that are used in
outline descendant tree.
   listElement(listLvl,status,content[,sources]) builds list elements.
   listOpen(listLvl[,startNum]) opens a new list.
   listClose() closes a list.

listElement(listLvl,nameID,status,link,content[,sources]) builds list elements.

"state" is a 10 element array used to store the list state and must be
declared and initialized to zero externally. 

"listLvl" is the element level from 0 to 3 or is "". When not "", it
causes a new list element or marriage to be started. When "", the values
are appended to the currently open list element.

"nameID" adds an ID to the list entry so that it may be linked to. This
parameter is ignored for all cases except when a new list element is
being started. e.g. When set to "rep3" and this is a new list element,
then this list element will be tagged with id="rep3". 

"status" defines the status of the data. It may optionally ne null but
should be included when a new list element or a marriage is being
started. 

"link" allows an individual to be linked to another location and should
only be used when a new individual is named - i.e. as a new list element
or as a marriage. e.g. When set to "Chapter10.htm#rep3" then this
individuals name will be linked to "Chapter10#rep3". 

"content" is the data to be presented in the list element. 

Following the first five parameters are optional parameters in sets of
three that indicate the sources to be used. The first optional parameter
in the set of three is the dataset. The second is the image or link to
be displayed. The third is the link name. If the first two parameters
are a null string, then the source name is stated without any link.
There may be up to three sources per list element. 

*/

function listElement(listLvl,nameID,status,link,content){

    var outText = '';
    var strFact = '';
    var strData = '';

// First split the content to look for key words.
    if(content.indexOf(" ") != -1) {
        strFact = content.slice(0,content.indexOf(" "));
        strData = content.slice(content.indexOf(" "));
    }

// Start building the output string.
// Find those that are marriages.
    var j = listLvl;
    if(strFact == "married" || strFact == "partner") {
        j = j + 10;
    }
// Set up item code and record the data type.
    if(j < 11) {                                        // If we have an individual with an ID set it up.
        if(nameID != "") {
            outText = ' id="' + nameID + '"';           // Heads and list items can have IDs within the tag.
        }
    } else {
        if(nameID != "") {
            outText = '<a name="' + nameID + '"></a>';  // Anything else needs a specific "<a name" tag.
        }
    }
    switch(j) {
        case 0: outText = '<h5' + outText + '>'; state[1] = 0; break;
        case 1: outText = '<li' + outText + '>'; state[1] = 0; break;
        case 2: outText = '<li' + outText + '>'; state[1] = 0; break;
        case 3: outText = '<li' + outText + '>'; state[1] = 0; break;
// If this is a level 10 marriage and we are already at level 0
// or level 10 then close the original </h5> and reopen it to
// throw correct line spacing.
// state[0] is the current state and listLvl is the one we are about to process.
        case 10: outText = '<h5' + outText + '>';
                 if(state[0] == 0 || state[0] == 10) {outText = '</h5>' + outText;}
                 state[1] = 1; break;
// If we just closed a lower level list and have a new marriage then
// we should supress the <br>.
        case 11: if(listLvl==state[0]) {outText = '<br>' + outText;} state[1] = 1; break;
        case 12: if(listLvl==state[0]) {outText = '<br>' + outText;} state[1] = 1; break;
        case 13: if(listLvl==state[0]) {outText = '<br>' + outText;} state[1] = 1; break;
        default: outText = '<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + outText; state[1] = 2; break;
    }

// Check the current state and see if we need to open or close any lists.
    if(state[1] != 2) {                               // Ignore continuation lines.
        var i = (listLvl + 1) * 2;
        if(state[1] == 1) {
            state[i+1]++;                             // Count the marriages.
        } else {
            state[i+1] = 0;                           // Reset marriage count if its a new individual
            state[i]++;                               // and increment the element count.
        }
        if(listLvl > state[0]) {                      // New individual at incr. level (NB: cannot be a marriage,
            state[0] = listLvl;                       // might be child of multiple mariages. Update the current
            listOpen(listLvl,state[i]);               // state and open a new list.
        } else if (listLvl < state[0]) {              // New individual at decr. level may be multiple marriage.
            while(listLvl != state[0]) {              // Iterate up to the new list level (might be more than one level).
                if(state[1] == 0 || state[0] != listLvl+1) {
                    i = (state[0] + 1) * 2;
                    state[i] = 0;                     // New individual or a marriage more than one level away.
                    state[i+1] = 0;                   // Reset the element count and marriage count of current level.
                }
                listClose();                          // Close the existing list.
                state[0]--;                           // Decrement the current state. 
            }
        }
    }

// Highlight any facts that are not well established.
    if(state[1] != 0) {                    // state[1] is non zero when we have a continuation line or marriage.
        document.write(outText);
        if(link != "" && (strFact == "married" || strFact == "partner")) {
            popUpLink("",link,strFact);    // If we have a link on this fact, set it up.
        } else {
            document.write(strFact);       // Else just write the fact.
        }
        switch(status) {                   // Include status and highlight it only if it is uncertain.
            case "": outText = strData; break;
            case "Proven": outText = ' <em class="st">' + status + '</em> ' + strData + ' '; break;
            case "Probable": outText = ' <em class="st">' + status + '</em> ' + strData + ' '; break;
            case "Conjecture": outText = ' <em class="cl">' + status + '</em> ' + strData + ' '; break;
            case "Claimed": outText = ' <em class="cl">' + status +  ' ' + strData + '</em> '; break;
            default:  outText = ' <em class="cl">' + status +  ' ' + strData + '</em> '; break;
        }
        document.write(outText);
    } else {
        switch(status) {                   // Always include the status of an primary individual.
            case "": break;
            case "Proven": outText = outText + '<em class="st">' + status + ':</em> '; break;
            case "Probable": outText = outText + '<em class="st">' + status + ':</em> '; break;
            case "Conjecture": outText = outText + '<em class="cl">' + status + ':</em> '; break;
            case "Claimed": outText = outText + '<em class="cl">' + status + ':</em> '; break;
            default: outText = outText + '<em class="cl">' + status + ':</em> '; break;
        }
        document.write(outText);
        if(link != "") {
            popUpLink("",link,content);    // If we have a link on this person, set it up.
        } else {
            document.write(content);       // Else just write the name.
        }
    }

// Now work on the citations.
    if(arguments.length>5){
        outText = ' <sup>[<cite>';
        for(i=5; i<arguments.length-1; i=i+3) {
            if(arguments[i+1] != "") {
                document.write(outText);
                if((arguments[i+1].indexOf(".htm") != -1) || (arguments[i+1].indexOf("http://") != -1)) {
                    popUpLink(arguments[i],arguments[i+1],arguments[i+2]);
                } else {
                    popUpImage(arguments[i],arguments[i+1],arguments[i+2]);
                }
            } else {
                document.write(outText + arguments[i+2]);
            }
            outText = ', ';
        }
        document.write('</cite>]</sup>');
    }

} //listElement


/*
listOpen(listLvl[,startNum]) opens a new list. If present, startNum
specifies the number of the next element.
*/

function listOpen(listLvl){

    var outText = '';

    if(arguments.length>1) {
        outText = ' start=' + arguments[1];
    }

    switch(listLvl) {
        case 0: outText = ''; break;
        case 1: outText = '</h5><ol' + outText + '>'; break;
        case 2: outText = '<ol' + outText + ' class="withalpha">'; break;
        case 3: outText = '<ol' + outText + ' class="withroman">'; break;
        default: break;
    }

    document.write(outText);

}


/*
listClose() closes a list.
*/

function listClose(){

    if(state[0] > 0) { 
        document.write('</ol>');
    } else {
        document.write('</h5>');
    }
}


/*
This builds the link to a popup window with source information in
an HTML page.
*/

function popUpLink(theDataset,theLink,theName){
    if(theLink.indexOf("http://") != -1) {
        document.write('<a href="' + theLink + '"' +
                       'target="PopUpExtLink"' +
                       'onclick="PopUpExtLink=window.open(this.href,this.target,&#39;toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1024,height=768&#39;);PopUpExtLink.focus();">' +
                       theName + '</a>');
    } else {
        document.write('<a href="' + reference_server + root + theDataset + pages + theLink + '"' +
                       'target="PopUpLink"' +
                       'onclick="PopUpLink=window.open(this.href,this.target,&#39;toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1024,height=768&#39;);PopUpLink.focus();">' +
                       theName + '</a>');
    }

} //popUpLink

/*
This builds the link to a popup window with source information in
a jpg image.
*/

function popUpImage(theDataset,theLink,theName){
    document.write('<a href="' + reference_server + root + theDataset + images + theLink + '"' +
                   'target="PopUpImage"' +
                   'onclick="PopUpImage=window.open(this.href,this.target,&#39;toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1024,height=768&#39;);PopUpImage.focus();">' +
                   theName + '</a>');

} //popUpImage

/*
Many pages use tables of data. In order to reduce the volume of
HTML code in those pages the following scripts were developed. They can
build a table using plain text, a table using quotation style text, and
a table with links to other information.
*/


// *** Table functions.

/*
This builds a table row for the page title in the transcription. 
*/

function tbTitle(theSpan,theTitle){
    document.write('<tr><th colspan="' + theSpan + '">' + theTitle + '</th></tr>');
} //tbTitle

/*
This builds a table row of column headers in the transcription.
Calling parameters are paired: first is the column width, second is the heading.
The column width may optionally be a null string - "" - if the width is to be unspecified.
*/

function tbHead(){
      document.write('<tr>');
      for(i=0; i<arguments.length; i++) {
          var th = '<th>';
          if (arguments[i] != "") {
              th = '<th width="' + arguments[i] + '">';
          }
        document.write(th + arguments[i+1] + '</th>');
        i = i + 1;
      }
      document.write('</tr>');
} //tbHead

/*
This builds a table row in the transcription.
Each calling parameter is one element in the row.

A second function tbRowQ is provided to allow a specific row to be quoted.
*/

function tbRow(){
      document.write('<tr>');
      for(i=0; i<arguments.length; i++)
      {
        document.write('<td>' + arguments[i] + '</td>');
      }
      document.write('</tr>');
} //tbRow

function tbRowQ(){
      document.write('<tr>');
      for(i=0; i<arguments.length; i++)
      {
        document.write('<td class="quote">' + arguments[i] + '</td>');
      }
      document.write('</tr>');
} //tbRowQ

// *** Table functions with links on the parameters.

/*
This builds a table row in the transcription with pop up links.
The first parameter is the data set, which may be null if the calling
location is the same as the pop up target location. After that parameters
are in pairs. The second parameter in the pair is a link associated with
the previous parameter. A null link parameter creats an entry without a link.

A similar function, tbRowPop2L, does the same thing except that all
entries after the first are kept in the same table element so that the
resulting table is a two column one.
*/

function tbRowPopL(){
      document.write('<tr>');
      for(i=1; i<arguments.length; i++){
         if(!arguments[i+1] == ""){
                  arguments[i] = '<a href="' + reference_server + root + arguments[0] + pages + arguments[i+1] + '"' +
                                 'target="PopUpWindow"' +
                                 'onclick="PopUpWindow=window.open(this.href,this.target,&#39;toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1024,height=768&#39;);PopUpWindow.focus();' +
                                 '">' + arguments[i] + '</a>';
         }
         document.write('<td>' + arguments[i] + '</td>');
         i = i + 1;
      }
      document.write('</tr>');
} //tbRowPopL

function tbRowPop2L(){
      document.write('<tr>');
      sep = '<td>';
      for(i=1; i<arguments.length; i++){
         if(!arguments[i+1] == ""){
                  arguments[i] = '<a href="' + reference_server + root + arguments[0] + pages + arguments[i+1] + '"' +
                                 'target="PopUpWindow"' +
                                 'onclick="PopUpWindow=window.open(this.href,this.target,&#39;toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1024,height=768&#39;);PopUpWindow.focus();' +
                                 '">' + arguments[i] + '</a>';
         }
         document.write(sep + arguments[i]);
         if (i==1) {sep = '</td><td>' } else { sep = ', '}
         i = i + 1;
      }
      document.write('</td></tr>');
} //tbRowPop2L


/*
This opens the tables. 

style FN     is a table with framed cells, normal size font.
style FS     is a table with framed cells,  small size font.
style FQ     is a table with framed cells, normal size font, quotation style.
style FSQ    is a table with framed cells,  small size font, quotation style.
style NFQ    is a table with unframed cells, normal size font, quotation style.
style NFSQ   is a table with unframed cells,  small size font, quotation style.
*/

function tbOpen(style){
    switch(style) {
        case "FN":    outText = '<p><table style="BORDER-COLLAPSE: collapse" cellSpacing="3" cellPadding="1" border="3" width="95%"><tbody>'; break;
        case "FS":    outText = '<p><table style="BORDER-COLLAPSE: collapse" cellSpacing="3" cellPadding="1" border="3" width="95%"><tbody class="sm">'; break;
        case "FQ":    outText = '<p><table style="BORDER-COLLAPSE: collapse" cellSpacing="3" cellPadding="1" border="3" width="95%"><tbody class="qu">'; break;
        case "FSQ":   outText = '<p><table style="BORDER-COLLAPSE: collapse" cellSpacing="3" cellPadding="1" border="3" width="95%"><tbody class="smqu">'; break;
        case "NFQ":   outText = '<p><table style="BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" border="0" width="95%"><tbody class="qu">'; break;
        case "NFSQ":  outText = '<p><table style="BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" border="0" width="95%"><tbody class="smqu">'; break;
        default:      outText = '<p><table><tbody>'; break;
    }
      document.write(outText);
} //tbOpen

/*
This builds the last row on each page in the transcription. 
*/

function tbNull(theSpan){
    document.write('<tr><td colspan="' + theSpan + '"></td></tr>');
} //tbNull

/*
This builds the last row on each page in the transcription. 
*/

function tbClose(){
    document.write('</tbody></table></p>');
} //tbClose

// ** DEVELOPMENT UTILITY FUNCTIONS
function listPropertyNames(obj){    //temporary test function

	var names = "";
	var c2 = 0;
	names += "Properties, with values, for Object " + obj.tagName + ":\n";
	for (var i in obj) {
		if (obj[i] != null && obj[i] != "" && i != "innerHTML" && i != "innerText" && i != "outerHTML") {
		    if (i != "outerText") {
			c2 = c2 + 1;
			names += " .." + i + " = " + obj[i] + ",  ";
		    }
		}
		if (c2 > 3) {
			names += "\n";
			c2 = 0;
                }
	}
	alert(names);
}

