// Copyright Martin Tester 2002 mailto: webmaster@wssc.org.uk
// Not to be copied or used without permission
// This code was originally written to support the Welsh Springer Spaniel Club's website (www.wssc.org.uk)

///////////////////
var headText = '<HTML><HEAD>';
headText += '<LINK REL=stylesheet TYPE="text/css" HREF="pedstyle.css"></HEAD>' ;
headText += '<BODY TOPMARGIN=5 MARGINHEIGHT=5 BACKGROUND="images/bgivory.gif" BGCOLOR="white" text=#000000>';
//define frequently used onClick text as variable
var ocText = '<A HREF=\"javascript:void(0);\" onClick=\"top.frinput.document.forms[0].elements[0].value=\'';
var ocText2 = '\';top.frinput.document.pedform.index.value=\'';


///////////////////
function getIndex( name )
// name is to be lowercase
{
 if( top.frinput.document.pedform.index.value!='0' )
  { 
    return top.frinput.document.pedform.index.value;
  }
 for ( var i=2; i<=(nA.length - 1); i++ )
  {
    if( nA[i].toLowerCase().indexOf(name) > -1 )
    {
      return i;
    }
  }
  return 0;
}

///////////////////
function calcPedigree( name )
{
  var numgen = top.frinput.document.forms[0].elements[5].options[top.frinput.document.forms[0].elements[5].selectedIndex].value;
  if( name.length == 0 )
  {
    alert('Please enter a name' );
    return;

  }
  var dbnum = getIndex( name.toLowerCase() );
  if( dbnum<2 )
  {
       alert("Sorry - unable to generate the pedigree for \'" + name + "\'. Name not found in the database.");
       return;
    }
  if( sA[dbnum]>=1 || dA[dbnum]>=1 )
  {
    var winwidth=650;
    var winheight=550;
    if( numgen==4)
      { winwidth=500;
        winheight=400;
      }
    var filename = 'pedigree.htm?' + String(dbnum) + String(numgen);
    newWindow( filename,winwidth,winheight);
  }
  else
  {
    alert("Sorry - unable to generate the pedigree for " + nA[dbnum] + ". Parents not recorded in the database.");
    return;
  }
}

///////////////////
function writePedigree( dbnum, numgen )
{
  //pedArray = new Array (63)
  pedArray = new Array (127)
  clText = new Array (3)
  //clArray = new Array (63)
  clArray = new Array (127)
  clText[0]=' CLASS=TI';
  clText[1]=' CLASS=ST';
  clText[2]=' CLASS=CH';
  clArray[0]=clText[0];

  genArray = new Array (6)
  genArray[0]='Parents';
  genArray[1]='G Parents';
  genArray[2]='GG Parents';
  genArray[3]='GGG Parents';
  genArray[4]='GGGG Parents';
  genArray[5]='GGGGG Parents';

  var picReqd = ( ( '' + pA[dbnum] )!='undefined' );
  if( picReqd ){ picReqd= confirm( ' A picture exists for ' + nA[dbnum] + ', do you want it shown?' ) }

  
  rowArray = new Array( 127 )
  rowArray=['0','8','8','4','4','4','4','2','2','2','2','2','2','2','2','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ;
  idxArray = new Array( 127 )
  idxArray=[0,1,3,7,15,16,8,17,18,4,9,19,20,10,21,22,2,5,11,23,24,12,25,26,6,13,27,28,14,29,30];
  tdwArray = new Array( 2 )
  var jmax1=14;
  var jmax2=30;
  var tabledets ='<TABLE WIDTH=100% BORDER=2 CELLSPACING=0 CELLPADDING=5><TR>';
  tdwArray = ['<TD WIDTH=24% ROWSPAN=','<TD WIDTH=28% ROWSPAN=']
  var tdheader= '<TD COLSPAN=4';
  if( numgen==4 )
  { jmax1=6;
    jmax2=14;
    rowArray=['0','4','4','2','2','2','2','1','1','1','1','1','1','1','1'] ;
    idxArray=[0,1,3,7,8,4,9,10,2,5,11,12,6,13,14,];
    tabledets ='<TABLE WIDTH=80% BORDER=2 CELLSPACING=0 CELLPADDING=5><TR>';
    tdwArray = ['<TD WIDTH=32% ROWSPAN=','<TD WIDTH=35% ROWSPAN=']
    tdheader= '<TD COLSPAN=3';
  }
  if( numgen==6 )
  { jmax1=30;
    jmax2=62;
    rowArray=['0','16','16','8','8','8','8','4','4','4','4','4','4','4','4','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ;
    idxArray=[0,1,3,7,15,31,32,16,33,34,8,17,35,36,18,37,38,4,9,19,39,40,20,41,42,10,21,43,44,22,45,46,2,5,11,23,47,48,24,49,50,12,25,51,52,26,53,54,6,13,27,55,56,28,57,58,14,29,59,60,30,61,62];
    tabledets ='<TABLE WIDTH=100% BORDER=2 CELLSPACING=0 CELLPADDING=1><TR>';   // cellpadding was 5
    tdwArray = ['<TD WIDTH=18% ROWSPAN=','<TD WIDTH=28% ROWSPAN=']  // was 19% & 24%
    tdheader= '<TD COLSPAN=5';
  }
  if( numgen==7 )
  { jmax1=62;
    jmax2=126;
    rowArray=['0','32','32','16','16','16','16','8','8','8','8','8','8','8','8','4','4','4','4','4','4','4','4','4','4','4','4','4','4','4','4','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'] ;
    idxArray=[0,1,3,7,15,31,63,64,32,65,66,16,33,67,68,34,69,70,8,17,35,71,72,36,73,74,18,37,75,76,38,77,78,4,9,19,39,79,80,40,81,82,20,41,83,84,42,85,86,10,21,43,87,88,44,89,90,22,45,91,92,46,93,94,2,5,11,23,47,95,96,48,97,98,24,49,99,100,50,101,102,12,25,51,103,104,52,105,106,26,53,107,108,54,109,110,6,13,27,55,111,112,56,113,114,28,57,115,116,58,117,118,14,29,59,119,120,60,121,122,30,61,123,124,62,125,126];
    tabledets ='<TABLE WIDTH=100% BORDER=2 CELLSPACING=0 CELLPADDING=5><TR>';
    tdwArray = ['<TD WIDTH=16% ROWSPAN=','<TD WIDTH=20% ROWSPAN=']
    tdheader= '<TD COLSPAN=6';
  }

  var i =dbnum;
  pedArray[0]=i;
  var n=1;
  for ( var j=0; j<=jmax1; j++ )
  {
    pedArray[ n ] = 0
    if( sA[pedArray[j]] >= 1 )
    { pedArray[ n ] = sA[pedArray[j]]; }
    if ((nA[pedArray[n]].indexOf(' Ch ') > -1 )||(nA[pedArray[n]].indexOf('Ch ') == 0 )||(nA[pedArray[n]].indexOf('Champion') == 0 )||(nA[pedArray[n]].indexOf(' Champion ') > -1 ))
    { clArray[n++]=clText[2] }
    else
    { clArray[n++]=clText[1] }

    pedArray[ n ] = 0
    if( dA[pedArray[j]] >= 1 )
    { pedArray[ n ] = dA[pedArray[j]]; }
    if ((nA[pedArray[n]].indexOf(' Ch ') > -1 )||(nA[pedArray[n]].indexOf('Ch ') == 0 )||(nA[pedArray[n]].indexOf('Champion') == 0 )||(nA[pedArray[n]].indexOf(' Champion ') > -1 ))
    { clArray[n++]=clText[2] }
    else
    { clArray[n++]=clText[1] }
  }

   var stext;
   var birthDate;
   var hips;
   var colour;
  ( xA[i]=='d') ? ( stext='(Dog' ) : ( stext='(Bitch' );
//  ( ( ''+bA[pedArray[0]] )=="undefined" ) ? ( birthDate = ')' ) : ( birthDate = ( ', born ' + bA[pedArray[0]] + ')'  ) );

  ( ( ''+bA[pedArray[0]] )=="undefined" ) ? ( birthDate = '' ) : ( birthDate = ( ', born ' + bA[pedArray[0]]) );
//////////////
  ( ( ''+cA[pedArray[0]] )=="undefined" ) ? ( colour = '' ) : ( colour = ( ', ' + cA[pedArray[0]] ) );
  ( ( ''+hA[pedArray[0]] )=="undefined" ) ? ( hips = ')' ) : ( hips = ( ', Hip Score ' + hA[pedArray[0]] + ')'  ) );
////////////////
    var heading = 'The Pedigree of ' + nA[pedArray[0]] + ' <BR><NOBR>&nbsp;&nbsp;' + stext + colour + birthDate + hips + '</NOBR>';

  document.writeln( '<CENTER>' + tabledets );
  document.writeln( tdheader + clArray[0] + '>' + heading + '</TD></TR><TR>' );
// can we insert a picture?
  if( picReqd )
  { 
    document.writeln( tdheader + ' ALIGN=right VALIGN=top><IMG SRC="images/' + pA[dbnum] + '.jpg" ALT="'+nA[dbnum]+'" VSPACE=10></TD></TR><TR>' );
  }

  for ( var j=0; j<=numgen-2; j++ )
  {
    document.writeln( '<TD CLASS=GENERATION>' + genArray[j] + '</TD>');
  }
  document.writeln( '</TR><TR>');

  var tdwidx = 0;
  var postBreaks = '<BR>';
  var preBreaks = '';
  for ( j=1; j<=jmax2; j++ )
  { var idx=idxArray[j];
//    (( ''+bA[pedArray[idx]] )=="undefined" || pedArray[idx] <= 1 || rowArray[idx]=="1"  ) ? ( birthDate = '' ) : ( birthDate = '<BR><SPAN CLASS=DOB>(born ' + getDate(pedArray[idx],'brief') + ')</SPAN>'  );
    (( cA[pedArray[idx]] )==null || pedArray[idx] <= 1 || rowArray[idx]=="1" || rowArray[idx]=="2" ) ? ( colour = '' ) : ( colour = '<SPAN CLASS=COLOUR>' + cA[pedArray[idx]] + '</SPAN>'  );
    (( hA[pedArray[idx]] )==null || pedArray[idx] <= 1 || rowArray[idx]=="1" || rowArray[idx]=="2" ) ? ( hips = '' ) : ( hips = '<SPAN CLASS=HIPS>Hips ' + hA[pedArray[idx]] + '</SPAN>'  );
    ( rowArray[idx]=="1"  ) ? (  tdwidx = 1 ) : ( tdwidx = 0 );    // was =="1"
    if( rowArray[idx]=="16"  ){ postBreaks = '<BR><BR><BR><BR><BR><BR><BR><BR><BR>'; preBreaks = colour + postBreaks }
    else if( rowArray[idx]=="8"  ){ postBreaks = '<BR><BR><BR><BR>'; preBreaks = colour + postBreaks }
    else if( rowArray[idx]=="4"  ){ postBreaks = '<BR><BR>'; preBreaks = colour + '<BR><BR>' }
    else{ postBreaks = '<BR>';preBreaks ='' }
    if( colour + hips == '' ){ postBreaks = ''; preBreaks = postBreaks; }

    document.writeln( tdwArray[tdwidx] + rowArray[idx] + clArray[idx] + '>' + preBreaks + nA[pedArray[idx]] + postBreaks + hips + '</TD>');

    if( idx==jmax2 )
    { document.writeln( '</TR>'); }
    else
    { if ( idx > jmax1 )
      { document.writeln( '</TR><TR>'); }
    }
  }
  document.writeln( '</TABLE></CENTER>');
}

///////////////////
var wwidth=150;
var wheight=150;
function newWindow(newContent,wwidth,wheight)
{
   PedWinObj=window.open('','pedwin','menubar=yes,scrollbars=yes,resizable=yes,right=20,top=10');
   PedWinObj.resizeTo(wwidth+30,wheight+30);
   PedWinObj.location=newContent
}

///////////////////
ilist = new Array()
function calcMatches( name )
{
  if( name=='ignore' )
    { return; }
  if( name.length == 0 )
  {
    alert('Please enter a name or year' );
    return;
  }
  var yrInt = 0;
  var temp;
  if( name.length == 4 )
  {
    yrInt = parseInt( name );
  }
  if( yrInt >= 1890 )
  {
      var matchnum = getYearList( name );
      var heading = matchnum + " WSS found for " + name;
      var alertText = "Sorry - no WSS found for " + name;
  }
  else
  {
      var matchnum = getIndexList( name.toLowerCase() );
      var heading = matchnum + " matches found for \'" + name + "\'";
      var alertText = "Sorry - no matches found for \'" + name + "\'";
  }
  if( matchnum>=1 )
  {
    top.frmatches.document.writeln( headText );
    top.frmatches.document.writeln( '<DIV CLASS=HDR>' + heading + '</DIV><HR>' );
    for (var i=0;  i<=matchnum-1; i++)
    {
      ( xA[ilist[i]]=='d') ? ( stext=' (d)' ) : ( stext=' (b)' );
      temp = nA[ilist[i]];
      top.frmatches.document.writeln( ocText + temp + ocText2 + ilist[i] + '\'">' + temp + '</A>'+stext+'<BR>' );
    }
    top.frmatches.document.writeln('<HR></BODY></HTML>');
    top.frmatches.document.close();
    top.frmatches.scroll(1,1);
  }
  else
  {
    alert( alertText );
  }
}

///////////////////
function getIndexList( name )
// name is to be lowercase
{
  var j=0;
  for ( var i=2; i<=(nA.length - 1); i++ )
  {
    if( name=='full champions' &&  nA[i].indexOf('Ch ') == 0 )
    {
        ilist[j++] = i;
    }
    else
    {
         if( name=='all champions' && ( nA[i].indexOf('Ch ') == 0 || nA[i].indexOf(' Ch ') > -1 ) )
         {
             ilist[j++] = i;
         }
         else
         {
             if( name=='pictures' && ( '' + pA[i] ) !='undefined' )
             {
                 ilist[j++] = i;
             }
             else
             {
                 if( nA[i].toLowerCase().indexOf(name) > -1 )
                 {
                     ilist[j++] = i;
                 }
             }
         }
    }
  }
  return j;
}

///////////////////
function getYearList( yearStr )
{
  var j=0;
  for ( var i=2; i<=(nA.length - 1); i++ )
  {
    if( (''+bA[i])!='undefined' )
    {
      if( bA[i].indexOf(yearStr) == ( bA[i].length - 4 ) )
      {
        ilist[j++] = i;
      }
    }
  }
  return j;
}

///////////////////
function getOffspringList( dbnum )
{
  var j=0;
  for ( var i=2; i<=(nA.length - 1); i++ )
  {
    if( ( sA[i]==dbnum ) || ( dA[i]==dbnum ) )
    {
      ilist[j++] = i;
    }
  }
  return j;
}
///////////////////
function calcOffspring( name )
{
  if( name.length == 0 )
  {
    alert('Please enter a name' );
    return;
  }
  var dbnum = getIndex( name.toLowerCase() );
  if( dbnum>=2 )
  {
    var matchnum = getOffspringList( dbnum );
    if( matchnum>=1 )
    {
      var heading = matchnum + " offspring found for \'" + nA[dbnum] + "\'";

      top.frlistings.document.writeln( headText );
      top.frlistings.document.writeln( '<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>');
      top.frlistings.document.writeln( '<TR><TD CLASS=HDR COLSPAN="2">' + heading + '</TD></TR>' );
      top.frlistings.document.writeln( '<TR><TD CLASS=PARENTS COLSPAN="2" ALIGN="right">' );

       var temp;
       var temp2;
      ( sA[dbnum]>=1 ) ? ( temp = nA[sA[dbnum]] ) : ( temp = nA[0] );
      ( sA[dbnum]>=1 ) ? ( temp2= sA[dbnum] ) : ( temp2=0 );
      top.frlistings.document.writeln( '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Parents:&nbsp;' + ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>&nbsp;x&nbsp;' );

      ( dA[dbnum]>=1 ) ? ( temp = nA[dA[dbnum]] ) : ( temp = nA[0] );
      ( dA[dbnum]>=1 ) ? ( temp2= dA[dbnum] ) : ( temp2 =0 );
      top.frlistings.document.writeln( ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>&nbsp;)</TD></TR>' );

      var ptext;
      ( xA[dbnum]=='d') ? ( ptext=' (dam ' ) : ( ptext=' (sire ' );

      for (var i=0;  i<=matchnum-1; i++)
      {
        var stext=' (b)';
        if( xA[ilist[i]]=='d')
          { stext=' (d)' }
        var temp2 = ilist[i];
        var temp = nA[temp2];
        top.frlistings.document.writeln( '<TR><TD>' + ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>'+ stext +'</TD>' );
        if( xA[dbnum]=='d' )
        { temp2=dA[ilist[i]]; temp = nA[temp2]; }
        else
        { temp2=sA[ilist[i]]; temp = nA[temp2]; }
        top.frlistings.document.writeln( '<TD>' + ptext + ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>&nbsp;)</TD></TR>' );
      }
      top.frlistings.document.writeln('</TABLE>');
      top.frlistings.document.writeln('<HR></BODY></HTML>');
      top.frlistings.document.close();
      top.frlistings.scroll(1,1);
    }
    else
    {
      alert("Sorry - no offspring found for " + nA[dbnum] );
    }
  }
  else
  {
     alert( "Sorry - name \'" + name + "\' not found" );
  }
}

///////////////////
function getSiblingList( dbnum, fullSibs )
{
  var j=0;
  for ( var i=2; i<=(nA.length - 1); i++ )
  {
    if( i != dbnum )
    {
      if( ( fullSibs=="full" && (( sA[dbnum]>1 && sA[i]==sA[dbnum] ) && ( dA[dbnum]>1 && dA[i]==dA[dbnum] )) ) || ( fullSibs=="all" && (( sA[dbnum]>1 && sA[i]==sA[dbnum] ) || ( dA[dbnum]>1 && dA[i]==dA[dbnum] )) ) )
      {
        ilist[j++] = i;
      }
    }
  }
  return j;
}
///////////////////
function calcSibling( name, fullSibs )
{
  if( name.length == 0 )
  {
    alert('Please enter a name' );
    return;
  }
  var dbnum = getIndex( name.toLowerCase() );
  if( dbnum>=2 )
  {
    var matchnum = getSiblingList( dbnum, fullSibs );
    var sibType="";
    if( fullSibs=="full"){ sibType=" full" };
    if( matchnum>=1 )
    {
      var heading = matchnum + sibType + " siblings found for \'" + nA[dbnum] + "\'";

      top.frlistings.document.writeln( headText );
      top.frlistings.document.writeln( '<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>');
      top.frlistings.document.writeln( '<TR><TD CLASS=HDR COLSPAN="2">' + heading + '</TD></TR>' );
      top.frlistings.document.writeln( '<TR><TD CLASS=PARENTS COLSPAN="2" ALIGN="right">' );
      var temp2 = 0;
      if( sA[dbnum]>=1 )
        { temp2 = sA[dbnum] }
      var temp = nA[temp2];
      top.frlistings.document.writeln( '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Parents:&nbsp;' + ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>&nbsp;x&nbsp;' );
      temp2 = 0;
      if( dA[dbnum]>=1 )
        { temp2 = dA[dbnum] }
      temp = nA[temp2];
      top.frlistings.document.writeln( ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>&nbsp;)</TD></TR>' );

      for (var i=0;  i<=matchnum-1; i++)
      {
        var stext=' (b)';
        if( xA[ilist[i]]=='d')
          { stext=' (d)' }
        
        var temp2 = ilist[i];
        var temp = nA[temp2];
        top.frlistings.document.writeln( '<TR><TD>' + ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>'+ stext +'</TD>' );
        if( fullSibs!="full" )
        {
          temp2 = sA[ilist[i]];
          temp = nA[temp2];
          top.frlistings.document.writeln( '<TD>(&nbsp;' + ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>&nbsp;x&nbsp;' );
          
          temp2 = dA[ilist[i]];
          temp = nA[temp2];
          top.frlistings.document.writeln( ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>&nbsp;)</TD></TR>' );
        }
        else
        {
          top.frlistings.document.writeln( '<TD>&nbsp;</TD></TR>' );
        }
      }
      top.frlistings.document.writeln( '</TABLE>');

      top.frlistings.document.writeln('<HR></BODY></HTML>');
      top.frlistings.document.close();
      top.frlistings.scroll(1,1);
    }
    else
    {
      alert("Sorry - no" + sibType + " siblings found for " + nA[dbnum] );
    }
  }
  else
  {
     alert( "Sorry - name \'" + name + "\' not found" );
  }
}

///////////////////
function calcDetails( name )
{
  if( name.length == 0 )
  {
    alert('Please enter a name' );
    return;
  }
  var dbnum = getIndex( name.toLowerCase() );
  if( dbnum>=2 )
  {
      var heading = "Details for \'" + nA[dbnum] + "\'";

      top.frlistings.document.writeln( headText );
      top.frlistings.document.writeln( '<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=0>');
      top.frlistings.document.writeln( '<TR><TD CLASS=HDR COLSPAN="4" WIDTH="95%">' + heading + '</TD></TR>' );

      ( xA[dbnum]=='d')? ( stext='Dog' ) : ( stext='Bitch' );
      ( ( ''+bA[dbnum] )!="undefined" ) ? ( birthDate = bA[dbnum] ) : ( birthDate = bA[0] );
      top.frlistings.document.writeln( '<TR><TD WIDTH="1%">Sex:&nbsp;&nbsp;</TD>' );
      top.frlistings.document.writeln( '<TD>' + stext + '</TD>' );
      top.frlistings.document.writeln( '<TD WIDTH="1%">Born:&nbsp;&nbsp;</TD>' );
      top.frlistings.document.writeln( '<TD>' + birthDate + '</TD></TR>' );

      top.frlistings.document.writeln( '<TR><TD WIDTH="1%">Sire:</TD>' );
      var parentIndex = 0;
      var parentName = 'Not stored';
      if( sA[dbnum]>=1 )
        { parentIndex = sA[dbnum];
          parentName = nA[parentIndex];
        }
      var tempHREF = ocText + parentName + ocText2 + parentIndex + '\'">';
      var tempS = '<TD COLSPAN="3">';
      var tempF = '</TD></TR>';
      var tempM = '';
      if( parentIndex >=2 )
        {
          tempF = '</A></TD></TR>';
          tempM = tempHREF;
        }
      top.frlistings.document.writeln( tempS + tempM + parentName + tempF );

      top.frlistings.document.writeln( '<TR><TD WIDTH="1%">Dam:</TD>' );
      parentIndex = 0;
      parentName = 'Not stored';
      if( dA[dbnum]>=1 )
        { parentIndex = dA[dbnum];
          parentName = nA[parentIndex];
        }
      var tempHREF = ocText + parentName + ocText2 + parentIndex + '\'">';
      tempF = '</TD></TR>';
      tempM = ''
      if( parentIndex >=2 )
        {
          tempF = '</A></TD></TR>';
          tempM = tempHREF;
        }
      top.frlistings.document.writeln( tempS + tempM + parentName + tempF );
      if( ( '' + pA[dbnum] )!='undefined' )
      { top.frlistings.document.writeln( '<TR><TD COLSPAN="4" ALIGN=left VALIGN=top><IMG SRC="images/shim.gif" ALT="" WIDTH ="10" HEIGHT="10"></TD></TR>' );
        top.frlistings.document.writeln( '<TR><TD COLSPAN="4" ALIGN=left VALIGN=top><IMG SRC="images/' + pA[dbnum] + '.jpg" ALT="'+nA[dbnum]+'"></TD></TR>' );
      }
      top.frlistings.document.writeln( '</TABLE>');

      top.frlistings.document.writeln('<HR></BODY></HTML>');
      top.frlistings.document.close();
      top.frlistings.scroll(1,1);
  }
  else
  {
     alert( "Sorry - name \'" + name + "\' not found" );
  }
}
///////////////////
yearArray = new Array (10)
for( i=0; i<10; i++ )
{ yearArray[i] = new Array () }

function decadeMatches( decade )
{
  if( decade=='ignore' )
    { return; }
  var matchnum = getDecadeList( decade );
  var temp;
  var temp2;
  if( matchnum>=1 )
  {
    var heading = matchnum + " WSS found for the " + decade + "0s";
    top.frmatches.document.writeln( headText );
    top.frmatches.document.writeln( '<DIV CLASS=HDR>' + heading + '</DIV><HR>' );
    for ( yr=0; yr<=9; yr++ )
    {
        for ( i=1;  i<=yearArray[yr][0]; i++)
        {
           if( i==1 )
           {
             top.frmatches.document.writeln( '<DIV CLASS=YEAR>' + decade + yr + '</DIV>' );
           }
           ( xA[yearArray[yr][i]]=='d') ? ( stext=' (d)' ) : ( stext=' (b)' );
           var temp2 = yearArray[yr][i];
        //   temp2 = 888;
           temp = nA[yearArray[yr][i]];
           top.frmatches.document.writeln( ocText + temp + ocText2 + temp2 + '\'">' + temp + '</A>'+stext+'<BR>' );
        }
    }
    top.frmatches.document.writeln('<HR></BODY></HTML>');
    top.frmatches.document.close();
    top.frmatches.scroll(1,1);
  }
  else
  {
    alert('Sorry - no WSS found for the ' + decade + '0s' );
  }
}

///////////////////
function getDecadeList( decade )
{
  var j=0;
  for( i=0; i<10; i++ )
  { yearArray[i][0] = 0 }

  for ( i=2; i<=(nA.length - 1); i++ )
  {
    if( (''+bA[i])!='undefined' )
    {
      if( bA[i].indexOf(decade) == ( bA[i].length - 4 ) )
      {
          yrStr = bA[i].charAt(bA[i].length - 1 );
          if( yrStr>='0' && yrStr<='9' )
          {
            yrInt = parseInt( yrStr );
            yearArray[yrInt][0]++;
            yearArray[yrInt][yearArray[yrInt][0]] = i;
            j++;
          }
      }
    }
  }
  return j;
}
///////////////////
function getDate( index, mode )
{
  if( mode=='brief' )
  {
    chunks = new Array ()
    chunks = bA[index].split(' ');
    bDate = chunks[0] + '-' + chunks[1].substring(0,3) + '-' + chunks[2].substring(2,4);
    return bDate;
  }
  else
  {
    return bA[index];
  }
}
///////////////////
