//alert('family');

      function noteItem(noteDate, noteElemPtr) {
         this.nDate = noteDate;
         this.nPtr = noteElemPtr;
         }
      noteItem.prototype.dateCompareTo = function(b) {
         var aDate = this.nDate;
         var bDate = b.nDate;
         return (aDate == bDate)?0:((aDate > bDate)?1:-1);
         }
      noteItem.dateCompare = function(a, b) { return a.dateCompareTo(b); }

      function placeNotes(xNotes)  {
         var notes = new Array(xNotes.length);
         var sortBy = new Array(xNotes.length);
         //  ****  assumes year is only four adjacent non-blank digits in field  *********
         for (var i=0; i<xNotes.length; i++) {
            var noteDate = xNotes[i].getAttribute('date');
            var thisDate = '0000';
            if (noteDate)  {
               for (var s=0; s<=noteDate.length-4; s++)  {
                  if (!isNaN(noteDate.substring(s, s + 4)) && (noteDate.charAt(s) != ' '))  {
                     thisDate = noteDate.substring(s, s + 4);
                     break;
                     }
                  }
               }
            sortBy[i] = new noteItem(thisDate, xNotes[i]);
            }
         sortBy.sort(noteItem.dateCompare);
    
         for (var i=0; i<xNotes.length; i++)  {
            notes[i] = sortBy[i].nPtr;
            }

         htmlBlock += ' <BR> <SPAN class="ital">notes -</SPAN>';
         for (var n = 0; n < notes.length; n++)  {
            var type = notes[n].getAttribute('type');
            var date = notes[n].getAttribute('date');
            var place = notes[n].getAttribute('place');
            var textNode = notes[n].firstChild;
            var noteText = (textNode)
                             ?'<SPAN STYLE="font-style: italic;">' + textNode.nodeValue + '</SPAN>'
                             :'';
            htmlBlock += (n == 0)?' <DIV STYLE="margin-left: 1em;">':'<BR> <SPAN>';
            htmlBlock += (type)?'<SPAN STYLE="text-decoration: underline;">' + type.toLowerCase() + '</SPAN>: ': '';
            htmlBlock += (date)?date + '; ':'';
            htmlBlock += (place)?place + '; ':'';
            htmlBlock += (noteText != '')?' - ' + noteText:'';
            }
         htmlBlock += '</DIV>';
         }

     var htmlBlock;


     function buildFamily()  {
       var thisV = mySelectG.value;
       var thisRoot = iIndex[thisV].iElem;
       htmlBlock = '';
       htmlBlock += '<DIV id=' + thisRoot.getAttribute("iID") + 
                      'F STYLE="margin-left: 1em; margin-bottom: 5px;"><SPAN STYLE="font-weight: bold; font-size: 120%;">' +
                       thisRoot.getAttribute("displayName") + '</SPAN>';
       
      var thisBDate = thisRoot.getAttribute("bDate");
      if ((thisBDate) && (thisBDate !='9999-99-99'))  {
         var thisBDateMod = thisRoot.getAttribute("bDateMod");
         htmlBlock += ' <BR> <SPAN>birth: ' + ((thisBDateMod)?thisBDateMod + ' ':'') + thisBDate;
        var thisBPlace = thisRoot.getAttribute("bPlace");
        if ((thisBPlace) && (thisBPlace != ""))  {
          htmlBlock += ' at ' + thisBPlace;
          }
          htmlBlock += '</SPAN>';       
        }
      var thisDDate = thisRoot.getAttribute("dDate");
      if ((thisDDate) && (thisDDate !='9999-99-99'))  {
         var thisDDateMod = thisRoot.getAttribute("DDateMod");
         htmlBlock += ' <BR> <SPAN>death: ' + ((thisDDateMod)?thisDDateMod + ' ':'') + thisDDate;
        var thisDPlace = thisRoot.getAttribute("dPlace");
        if ((thisDPlace) && (thisDPlace != ""))  {
          htmlBlock += ' at ' + thisDPlace;
          }
          htmlBlock += '</SPAN>';       
        }


      htmlBlock += '  <DIV STYLE="margin-left: 2em;">';

       if (thisRoot.getAttribute("parentPairRef"))  {
         var thisPairRef = thisRoot.getAttribute('parentPairRef');
         var thisPair = pIndex[thisPairRef];

         htmlBlock += ' <SPAN class="ital">father: </SPAN>';
         if (thisPair.getAttribute('maleRef'))  {
           var father = iIndex[thisPair.getAttribute('maleRef')].iElem;
           htmlBlock += linkedName(father) + ' <BR>';
           }
         else  {
           htmlBlock += '<SPAN class="ital">[not available]</SPAN><BR>';
           }

         htmlBlock += ' <SPAN class="ital">mother: </SPAN>';
         if (thisPair.getAttribute('femaleRef'))  {
           var mother = iIndex[thisPair.getAttribute('femaleRef')].iElem;
           htmlBlock += linkedName(mother);
           }
         else  {
           htmlBlock += '<SPAN class="ital">[not available]</SPAN>';
           }



         var progeny = thisPair.getElementsByTagName("progeny");
         if (progeny.length > 1)  {
           var children = new Array();
           for (var i=0; i < progeny.length; i++)  {
              children.push(new iChild(iIndex[progeny[i].getAttribute("childRef")].iElem));
              }
           children.sort(iChild.bDateCompare);
           htmlBlock += '<SPAN class="ital">full siblings - </SPAN> <DIV STYLE="margin-left: 1em;">';
           for (var i=0; i < children.length; i++) {
              var thisSib = children[i].iElem;
              if (thisSib != thisRoot)  {
                   htmlBlock += linkedName(thisSib) + ' <BR>';
                   }
              }
           htmlBlock += ' </DIV>';
           }
        }



 //  ************************************



      var iNotes = thisRoot.getElementsByTagName('iNote');
      if (iNotes.length > 0)  {
         placeNotes(iNotes);
         } 
      else {
         htmlBlock += '<BR> ';
         } 

       var partners = thisRoot.getElementsByTagName("partner");
       if (partners.length > 0)  {
         var spouses = new Array();  
         for (var i=0; i < partners.length; i++)  {

         spouses.push(new iSpouse(partners[i]));
         }
      spouses.sort(iSpouse.sortDateCompare);
         for (var isp=0; isp < spouses.length; isp++)  {
           if (spouses[isp].iElem.getAttribute("partnerRef"))  {
              var thisSpouse = iIndex[spouses[isp].iElem.getAttribute("partnerRef")].iElem;
              htmlBlock += '---------- <BR> <SPAN class="ital">spouse: </SPAN>' + linkedName(thisSpouse);
             }
          else  {
              htmlBlock += '---------- <BR> <SPAN class="ital">spouse: [not available]</SPAN>';
             }              


           var myPair = pIndex[spouses[isp].iElem.getAttribute("partnerPairRef")];
           if (myPair.getElementsByTagName("marriage").length > 0)  {
              var thisMarriage = myPair.getElementsByTagName('marriage')[0];
           thisMDate = thisMarriage.getAttribute('mDate');
              thisMDateMod = thisMarriage.getAttribute('mDateMod');
              thisMPlace = thisMarriage.getAttribute('mPlace');
              if ((thisMDate) || (thismPlace)) {
                 htmlBlock += '<BR> &nbsp;&nbsp;&nbsp;&nbsp;married&nbsp;'
                 htmlBlock += (thisMDateMod)?thisMDateMod + '&nbsp;':'';
                 htmlBlock += (thisMDate)?thisMDate:'';
                 htmlBlock += (thisMPlace)?' at ' + thisMPlace:'';
                 }
              }


         var mNotes = myPair.getElementsByTagName('mNote');
         if (mNotes.length > 0)  {
           placeNotes(mNotes);
            } 
         else {
            htmlBlock += '<BR> ';
            } 


// insert family notes here



           var progeny = myPair.getElementsByTagName("progeny");
           if (progeny.length > 0)  {
             var children = new Array();
             for (var j=0; j < progeny.length; j++)  {
                children.push(new iChild(iIndex[progeny[j].getAttribute("childRef")].iElem));
                }
             children.sort(iChild.bDateCompare);
             htmlBlock += '<SPAN class="ital">children - </SPAN><DIV STYLE="margin-left: 1em;"> ';
             for (var j=0; j < children.length; j++) {
                var thisChild = children[j].iElem;
                if (thisChild != thisRoot)  {
                     htmlBlock += linkedName(thisChild) + ' <BR>';
                     }
                }
             htmlBlock += ' </DIV>';
             }         // ********* if (progeny.length > 0)  


           }        // ********* for (var isp=0; isp < spouses.length; isp++)  

         }       //  ********* if (partners.length > 0)  

       htmlBlock += ' </DIV> </DIV>';
       
       return htmlBlock;

       }
