//alert('ances');

  var aConnected = '&mdash;&mdash;+&mdash;';
  var aUnconnected = '&mdash;&mdash;&ndash;&mdash;';
  var aSpace = '<SPAN class="x">&mdash;|||</SPAN>&emsp;';
  var aLine = '<SPAN class="x">&mdash;&mdash;||</SPAN>|';

  var ancestorNav = new Object();
   ancestorNav.curId = '';
   ancestorNav.curA = null;

  function aToken(ThisIndiv, BaseId)  {
     this.localRoot = ThisIndiv;
     this.baseId = BaseId;
     }

  function iFather(iElem)  {
     var pairRef = iElem.getAttribute('parentPairRef');
     if (pairRef)  {
        var dadRef = pIndex[pairRef].getAttribute('maleRef');
        if (dadRef) {
           return iIndex[dadRef].iElem;
           }
        }
     return null;
     }

  function iMother(iElem)  {
     var pairRef = iElem.getAttribute('parentPairRef');
     if (pairRef)  {
        var momRef = pIndex[pairRef].getAttribute('femaleRef');
        if (momRef) {
           return iIndex[momRef].iElem;
           }
        }
     return null;
     }

  function isMale(iElem)  {
     return iElem.getAttribute('sex') == 'm';
     }

  function iterateA(myToken)  {
     var thisToken = myToken;
     var thisIndiv = thisToken.localRoot;
     var myId = thisToken.baseId;
     var aThisHTML = (myId != 'A')?aSpace:'';

     var oldG = myId.charAt(myId.length - 1);
     for (var i = myId.length - 2; i > 0; i--) {
        var newG = myId.charAt(i);
        if (newG == oldG) {
           aThisHTML = aSpace + aThisHTML;
           }
        else  {
           aThisHTML = aLine + aThisHTML;
           }
        oldG = newG;
        }
     var savedHTML = aThisHTML;
     aThisHTML = '';
     var tweekedLine = (!isMale(thisIndiv) && (myId != 'A'))
                           ?savedHTML.substring(0, savedHTML.length-6) + '&emsp;|'
                           :savedHTML;
     var myFather = iFather(thisIndiv);
     if (myFather)  {
        var fatherToken = new aToken(myFather, myId + 'f');
        aThisHTML = iterateA(fatherToken) + tweekedLine + aLine + '<BR> ';
        }
     else  {
        aThisHTML = tweekedLine + '<BR> ';
        }
     var connector = (myId == 'A')?'&emsp;':(isMale(thisIndiv)?'/':'\\');
     aThisHTML += savedHTML + connector;
     var selfBlock = (thisIndiv.getAttribute('parentPairRef'))?aConnected:aUnconnected;
     if (myId == 'A') {
        selfBlock = selfBlock.substring(7);
        }
     aThisHTML += selfBlock;
     aThisHTML += '<SPAN CLASS = "boxA" id = ' + myId + '>' + linkedName(thisIndiv, false) + '</SPAN> <BR> ';
     var myMother = iMother(thisIndiv);
     if (myMother)  {
        var motherToken = new aToken(myMother, myId + 'm');
        aThisHTML += iterateA(motherToken);  
        }
     return aThisHTML;
     }

/*
 *  ************ aNav support functions ********
 */

     function atRoot()  {
        return (ancestorNav.curId == 'A');
        }

     function aSpouseId() {
        if (atRoot()) { return null; }
        var aId = ancestorNav.curId;
        var male = aId.charAt(aId.length - 1) == 'f';
        var spouseId = aId.substring(0, aId.length - 1) + ((male)?'m':'f');
        return ((document.getElementById(spouseId))?spouseId:null); 
        }

    function aChildId()  {
       if (atRoot()) { return null; }
       return ancestorNav.curId.substring(0, ancestorNav.curId.length - 1);
       }

    function aFatherId()  {
       var fatherId = ancestorNav.curId + 'f';
       return ((document.getElementById(fatherId))?fatherId:null);
       }

    function aMotherId()  {
       var motherId = ancestorNav.curId + 'm';
       return ((document.getElementById(motherId))?motherId:null);
       }

     function resetAnav(aId)
     {
       if (ancestorNav.curA) { ancestorNav.curA.style.backgroundColor = aBackgroundColor; }
       ancestorNav.curId = aId;
       ancestorNav.curA = document.getElementById(aId);
       ancestorNav.curA.style.backgroundColor = aSelectColor;
       var relSpan = document.getElementById('aNavRel');
       if (aId == 'A')
       { 
         document.getElementById('aChildButton').disabled = true;
         document.getElementById('aRefocusButton').disabled = true; 
         document.getElementById('aSpouseButton').disabled = true;
         document.getElementById('aRootButton').disabled = true;
         relSpan.innerHTML = 'self';
       }
       else 
       { 
         document.getElementById('aChildButton').disabled = false;
         document.getElementById('aRefocusButton').disabled = false;
         document.getElementById('aRootButton').disabled = false;
         document.getElementById('aSpouseButton').disabled = !(aSpouseId());
         var relCount = ancestorNav.curId.length - 1;
         switch (relCount)
         {
          case 1:
           relSpan.innerHTML = 'parent';
           break;
          case 2:
           relSpan.innerHTML = 'grandpar.';
           break;
          case 3:
           relSpan.innerHTML = 'Ggrandpar.';
           break;
          default:
           relSpan.innerHTML = '(' + String(relCount-2) + ')Ggrandpar.';
           break;
          }
       }
       document.getElementById('aFatherButton').disabled = !(aFatherId());
       document.getElementById('aMotherButton').disabled = !(aMotherId());
       ancestorNav.curA.scrollIntoView();
     }

     function rootAnav()
     { resetAnav('A'); }

     function fatherAnav()
     { resetAnav(aFatherId()); }

     function motherAnav()
     { resetAnav(aMotherId()); }

     function childAnav() { 
       resetAnav(aChildId()); 
       }

     function spouseAnav()
     { resetAnav(aSpouseId()); }

     function refocusAnav()
     { ancestorNav.curA.firstChild.onclick(); }




   function buildAnces()  {
      var thisV = mySelectG.value;
      var thisRoot = iIndex[thisV].iElem;
      var htmlBlock = '<BR> ';
      var rootToken = new aToken(thisRoot, 'A');
      htmlBlock += iterateA(rootToken) + ' <BR>&nbsp;';
      return htmlBlock;
      }

       

