﻿var i,j,k, sepcount, stemp, lastmarkerused, markwin, newperson = -2;
var transmitdata = new Object();
transmitdata.type = 0;
transmitdata.result = 0;
transmitdata.tmrca = 50;
//transmitdata.type == 0 is not search 
//   ==1 is number
//   ==2 is array
//transmitdata.result == 0 is all
// == 1 is close only 
// == 2 is E,I,J
// == 3 is R1a
// == 4 is all R1b
// == 5 is R1b classified
// == 6 is R1b unclassified
var myopener = window.opener;
var mrkl = markerheadings.length;

var labelstring;
var labelstring2;
var modalslen = 0;
var colspannum;
var modals = new Array(mrkl);
var modalflag = new Array(mrkl);
var globalsortarray;
var dontusemodalflags;
var ttype = 0;
var tresult = 0;
var groupmintmrca;
var searchfail = "<div class='bdy1'><p>There appear to be no results matching your search criteria and within the maximum TMRCA (";
var searchfail2 = ") you specified. Try a longer TMRCA or check your numbers. </p></div>";
var flist = new Array();
var flist = [
[0,"yel",                               "Yellow (Unclassified)",           "",   ""],
[1,"red",                               "Red",                             "",   ""],
[2,"ltblu_black" ,                       "Blue Green-Black",                "",   ":L21"],
[3,"lime",                              "Green",                           "",   ""],
[4,"blu" ,                       "Dark Blue",                       "",   ""],
[5,"ltblu",                             "Blue green",                      "",   ""],
[6,"tan",                               "Olive",                             "The signature of this group is also found among the Lindsays of Jura and the MacNeills of Barra; both lands within the Lordship. It currently appears to be delineated by the marker L165.",   ":L165"],
/*["viol",                              "Violet",                          "",   ""],*/
[7,"yelgr_black",                       "Yellow Green-Black",              "", ":L21"],
[8,"orn",                               "Orange",                          "",   ""],
[9,"mag",                               "Magenta",                         "",   ""],
[10,"gray",                              "Gray",                            "",   ""],
[11,"white",                             "White",                           "",   ""],
[12,"brightredorn",                      "Red Orange",                      "",   ""],
[13,"dkmag",                             "Maroon",                          "",   ""],
[14,"plviol",                            "Pale violet",                     "",   ""],
[15,"rbrn",                              "Brown",                           "",   ""],
[16,"plblue",                            "Pale blue",                       "This group contains several persons known to descend from the line of the Glencoe chiefs. This line traditionally descends from Somerled. It originated Iain Og; son of Angus Og and brother of John first Lord of the Isles. We do not know when the R1a line was broken.",   ""],
[17,"red_black",                         "Red-Black",                       "This is a very common L21+ group in Scotland.",   ":L21"],
[18,"pink_black",                        "Pink-Black",                      "",   ":L21"],
[19,"lime_black",                        "Green-Black",                     "",   ":L21"],
[20,"blu_black",                         "Blue-Black",                      "The McKeans in this group are historically known to have emigrated from the Route in Antrim. They have a family tradition of earlier emigration from Argyle.",   ":L21"],  
[21,"ltblu_black",                       "Blue-Green-Black",                "",   ":L21"],
[22,"tan_black",                         "Olive-Black",                       "",   ":L21"],
[23,"viol_black",                        "Violet-Black",                    "",   ":L21"],
[24,"orn_black",                         "Orange-Black",                    "",   ":L21"],
[25,"mag_black",                         "Magenta-Black",                             "Signatures parallel to this group can be found  among the McMahons of Fermanagh ( one of the territories of ancient Oriel founded by the Collas who allegedly conquered Ulster around 330 AD).  This group was one of the tribes from which Gillebride; Somerled's father; sought assistance against the norse. It is distinguished by a null value for marker DYS425 (which is the same as DYF371t).",   ":L21"],
[26,"gray_black",                        "Gray-Black",                      "",   ":L21"],
[27,"white_black",                       "White-Black",                     "The group below is thought to be from Leinster. It is easily distinguished by the 464X test; whose results turn out 15c-15c-17g-17g.  ",   ":L21"],
[28,"brightredorn_black",                "Red Orange-Black",                "",   ":L21"],
[29,"dkmag_black",                       "Maroon-Black",                    "",   ":L21"],
[30,"plviol_black",                      "Pale Violet-Black",               "",   ":L21"],
[31,"rbrn_black",                        "Brown-Black",                     "This group has been SNP tested and found L21+. Otherwise they are not closely related.",   ":L21"],
[32,"red_blue",                       "Red-Blue",                 "The group below is centered geographically in northwestern Ireland. It is always referred to as the 'Irish' or 'Niall' group. Clan Donalds with this genetic signature may be descendants of Colla Uais; descendants of the O'Neill; or O'Donnell kindreds with whom we regularly served in Irish military operations; the O'Cahans from the Dowry of fighting men provided to Angus Og upon his marriage to the O'Cahan's daughter or descendants of Colla Menn from whom Gillebride sought assistants to recover his lands from the Norse. <br/><br/>This group is positive for both the markers L21 and M222 and thus is distantly related to the L21 groups.", ":M222"],
[33,"pink_blue",                       "Pink-Blue",              "This group is positive for both the markers L21 and L193 and thus is distantly related to the L21 groups above.",   ":L193"],
[34,"dkgreen_black",                     "Dark Green-Black",                 "The group below is called Irish Type III and is only distantly related to the M222+ clusters below. It is positive for marker L21.",   ":L21"],
[35,"mag_blue" ,                       "Magenta-Blue",                "This group is positive for the marker U106.",   ":U106"],
[36,"tan_blue" ,                       "Olive-Blue",                "This group is positive for the marker U152.",   ":U152"],
[37,"viol_blue" ,                       "Violet-Blue",                "This group is positive for both the markers L21 and L159.2 and thus is distantly related to the L21 groups above.",   ":L159.2"],
[38,"pgre_black" ,                       "Pale Green-Black",                "",   ":L21"],
[39,"ltblu_blue" ,                       "Blue Green-Blue",                "This is a family group that is a subset of the M222 (Irish) group above",   ":M222"],
[40,"yelgr_black",                       "Yellow Green-Black",              "", ":L21"],
[41,"dkgreen_black",                     "Dark Green-Black",                "",   ""],
[42,"pgre_black" ,                       "Pale Green-Black",                       "",   ":L21"],
[43,"blu",                               "Dark blue",                "",   ""]
//["pgre_black" ,                       "Pale Green-Black",                       "",   ":L21"],
//["flpink",                            "Pink",                            "",   ""],

];


var fluxus = new Array();
var fluxusdescr = new Array();
var signatures = new Array();
var R1bxtrahaplo = new Array();
for (i = 0; i < 50; i++){
 if (flist[i] != undefined){
   fluxus[i] = flist[i][1];
   fluxusdescr[i] = flist[i][2];
   signatures[i] = flist[i][3];
   R1bxtrahaplo[i] = flist[i][4];
 }
}


var dtmp = new Object();
var myopenwindowname;
var globalmaxtmrca = 100;
var globaltruncate = 0;
var idseq = 0;
var isthereanymatch = 0;
var imr;
for(imr = 0; imr < markerrates.length; imr++)markerrates[imr] = Number(markerrates[imr]); 


function doa(str){
  

 if(str.charAt(0) != ' ')
   window.open("http://www.ysearch.org/search_view.asp?uid="+str+"&viewuid="+str+"&p=0");
   return void 0;
}

function dob(z){

     transmitdata.number = Number(z);
     transmitdata.type = 1;
     transmitdata.result = 1;
     transmitdata.tmrca = globalmaxtmrca;
     transmitdata.truncate = globaltruncate;
     window.open("tables.htm");

  return void 0;
}

function doc(){
var i,j,k, zstring, xnum = -1;

     zstring =  document.myform0.myform0input.value;
     if(! (zstring.length == 6 && zstring.charAt(0) == "&") && !(zstring.length == 5 && zstring.charAt(0) != "&" )){
           alert("Codes must be 5 alphameric characters with an & if Cland Donald code");
           return; 
     } 

     if(zstring.length == 6 && zstring.charAt(0) == "&"){
        zstring = zstring.substr(1);
        zstring = zstring.toUpperCase();
        for(i = 0; i < numberofpeople; i++){
          if(zstring == donald[i][1]){
             xnum = i;
             break;
          }
        }
        if(xnum < 0 || xnum >= numberofpeople){
           alert("This code was not found. Be sure you had or did not have the & depending on whether it was a Clan Donald code or a Ysearch one.");
           return;
        }
     } else {
        zstring = zstring.toUpperCase();
        for(i = 0; i < numberofpeople; i++){
           if(zstring == donald[i][2]){
               xnum = i;
               break;
           }
        }
        if(xnum < 0 || xnum >= numberofpeople){
           alert("This code was not found. Be sure you had or did not have the & depending on whether it was a Clan Donald code or a Ysearch one.");
           return;
        }
     }

     transmitdata.number = xnum;
     transmitdata.type = 1;
     transmitdata.result = 1;
     transmitdata.tmrca = globalmaxtmrca;
     transmitdata.truncate = globaltruncate;
     window.open("tables.htm");

}

function dod(){
var i,j,k, xnum, numused = 0, qqq, numnum, numother;
transmitdata.array = new Array();

    for(i = 0; i < mrkl; i++){

        qqq = document.myform1.elements[i].value;

        for(j = numnum = numother  = 0; j < qqq.length; j++){
            k = qqq.charAt(j);
            if(k.search(/\d/) != -1)numnum++;
            if(k.search(/\D/) != -1 && k != " ")numother++;
        }

        if(numnum < 1 || numnum > 2 || numother > 0){
            xnum = -1;
        } else {
          xnum = Number(qqq);

          if(xnum > 69)xnum = 69;

          if(i == 11 && xnum > 8){
              if(transmitdata.array[9] < 4){
                alert("If DYS385-2 is used you must also include DYS385-1");
                xnum = -1;
              } else {
                xnum -= transmitdata.array[9];
              }
          }
          if(xnum < 0) xnum = -1;
        }      

        if(xnum >= 0)numused++;
        transmitdata.array[i] = xnum; 
    }
        if(numused < 2){
           alert("You must use at least two markers.");
           return ;
        }
        transmitdata.type = 2;
        transmitdata.result = 1;
        transmitdata.tmrca = globalmaxtmrca;
        transmitdata.truncate = globaltruncate;
        window.open("tables.htm");
}



function doq(){
globalmaxtmrca = document.myform2.myform2input.value;
// note that this is a string 
if(globalmaxtmrca < 1)globalmaxtmrca = "1";
if(globalmaxtmrca > 10000)globalmaxtmrca = "10000";

if(document.myform2.myform2check.checked){
   globaltruncate = 1;
} else globaltruncate = 0;



var nextyear = new Date();


nextyear.setFullYear(nextyear.getFullYear() + 1);

document.cookie = "truncate=" + globaltruncate +";";
document.cookie = "tmrca=" + globalmaxtmrca + "; expires=" + nextyear.toGMTString();

}

var nbefore = 6; /* addmajor  ... was 5 */

function getmaxindex(start, stop){
var i,j, maxindex;
var qq = -1;
  for(j =  start; j <= stop; j++){
     if(donald[j].length > qq)qq = donald[j].length;
  }
  return qq - nbefore - 1;  
}

var h = new Array();

function fillmodalsarray(start, stop){
var i,j, max, imax, t, ave , num, xtmp, y; 
  dontusemodalflags = false;
  for(i = 0; i <= lastmarkerused; i++){

     h = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
     for((j = start), (imax = undefined), max = num = ave = 0; j <= stop; j++){

        if(( xtmp = donald[j][i+nbefore]) !== undefined && xtmp !== 0) {

             if( ((ave += (y = Math.round(xtmp))), num++ , (++h[y]) > max)) (max = h[y],imax = y);
        }
     }
     modals[i] = imax;
/*
     if(num)ave /= num;
     for(j = -4; j < 5; j++)h[imax - j] -= (Math.abs(imax - j - ave)) / 100.;

     for(j = 1; j < 5; j++){
         if(h[imax - j] > h[imax])modals[i] = imax - j, h[imax] = h[imax - j];
         if(h[imax + j] > h[imax])modals[i] = imax + j, h[imax] = h[imax + j];
     }  
*/  if(num > 1) { ave /= num; 
      modalflag[i] = true;
       for(j = -4; j < 5; j++)h[imax - j] -= (Math.abs(imax - j - ave)) / 100.; 
      for(j = 1; j < 5; j++){
          if(h[imax - j] > h[imax])modals[i] = imax - j, h[imax] = h[imax - j];
          if(h[imax + j] > h[imax])modals[i] = imax + j, h[imax] = h[imax + j];
      }  
   } else if(num == 1){modalflag[i] = false;} 
     else { modals[i] = undefined;} 
   }
   modalslen = lastmarkerused + 1;
}

function insertmodals(start, stop, type, index){
var i,j,t;

/* line below is the color code indicator bar */

var zz = "  <tr class='sep'> <td class='"+fluxus[donald[start][5]]+"' colspan='"+colspannum+"' style='height: .6em; text-align:left;'> </td> </tr>";

if(type == 1){
  
      zz += "<tr> <td class='txtmodals'>" + 
                 "</td><td class='txtmodals'> Group </td><td class='txtmodals'> Modals </td><td /><td >" + avetmrca + "</td>";


} else {
   if(index != -1){
     zz +=  "<tr><td class='txtmodals'> &amp;" + donald[index][1] + 
       "</td><td class='txtmodals'> <a href='javascript:doa(\"" + donald[index][2] + "\"); '>" + donald[index][2] +
       "</a></td><td class='txtmodals' >"+donald[index][3] + "</td><td /><td />";
   } else {     
     zz += "<tr><td class='txtmodals'> </td><td class='txtmodals'> User </td><td class='txtmodals' />Modals<td /><td />";
   }  

}

       for(j = 0; j <= lastmarkerused; j++){
         zz +=  (modals[j] !== undefined) ?
               "<td>" + (j != 11 ? modals[j] : modals[j] + modals[j-2])  + "</td>" :
               "<td />";
         }
 zz += "<td class='txtmodals'>" + ( ( type != 1 && index != -1 ) ? donald[index][3] : "&nbsp;" ) +"</td>" + 
       ("</tr><tr class='sep'> <td class='sep' colspan='"+colspannum+"'> </td> </tr>");


 document.write(zz);

}


var avetmrca;

function dodistancearray(start, stop){
var j, i2 = -1, alpha, distance , tmrca, i, nmark, nlen2, rsum, k; 
     
var sortarray = new Array();
var j, alpha, distance = 0, tmrca, nmark = 0;
avetmrca = 0;
groupmintmrca = 10000;
var qtmp = new Object();


for(i = start; i <= stop; i++){
 i2++;    
 nmark = distance = 0;
 sortarray[i2] = new Object();
 qtmp = donald[i];
 nlen2 = Math.min(modalslen, qtmp.length - nbefore);

    for(j = 0, rsum = 0, k = nbefore; j < nlen2; j++, k++){
          if(qtmp[k] !== undefined && modals[j] !== undefined && ( dontusemodalflags || modalflag[j] == true  )){
//               (nmark++), (distance += Math.abs(Math.round(qtmp[k]) - Math.round(modals[j]))), (rsum += markerrates[j]);
             (nmark++), (distance += (Math.round(qtmp[k]) !== Math.round(modals[j]))  ), (rsum += markerrates[j]);   
            }
     }

    
    tmrca = (nmark > 1 && distance < nmark) ? (.5 * nmark / rsum) * Math.log((distance + 0.7) / nmark  + 1.) : 10000.;
    if(newperson == i)tmrca = 0;
    if(tmrca > 999)tmrca = 999;
    sortarray[i2].index = i , sortarray[i2].count = i2, sortarray[i2].tmrca = tmrca;


    if(groupmintmrca > tmrca)groupmintmrca = tmrca;
    avetmrca += tmrca;
    if(tmrca < 9.500001)sortarray[i2].str =                     "<td>"+distance+"/"+nmark+"</td><td>"+Math.round(tmrca)+"</td>";
    else if(tmrca < 19.50001)sortarray[i2].str =   "<td>"+distance+"/"+nmark+"</td><td class='lime'>"+Math.round(tmrca)+"</td>";
    else if(tmrca < 29.50001)sortarray[i2].str =  "<td>"+distance+"/"+nmark+"</td><td class='brightyelgr'>"+Math.round(tmrca)+"</td>";
    else if(tmrca < 39.50001)sortarray[i2].str =    "<td>"+distance+"/"+nmark+"</td><td class='yel'>"+Math.round(tmrca)+"</td>";
    else if(tmrca < 49.50001)sortarray[i2].str = "<td>"+distance+"/"+nmark+"</td><td class='brightyelorn'>"+Math.round(tmrca)+"</td>";
    else if(tmrca < 59.50001)sortarray[i2].str = "<td>"+distance+"/"+nmark+"</td><td class='brightredorn'>"+Math.round(tmrca)+"</td>";
    else sortarray[i2].str =                        "<td>"+distance+"/"+nmark+"</td><td class='red'>"+Math.round(tmrca)+"</td>"; 


}
    avetmrca = Math.round(avetmrca*2./(stop-start+1));
    return sortarray;

}

function quicksort( v, left, right){
var t, i, last, ttt;
// from Kernighan and Ritchie
if(left >= right)return;

t = v[left];
v[left] = v[Math.floor((left + right)/2)];
v[Math.floor((left + right)/2)] = t;

last = left;
ttt = globalsortarray[v[left]].tmrca;
for(i = left+1; i <= right; i++){
   if(globalsortarray[v[i]].tmrca - ttt < 0){
       t = v[++last];
       v[last] = v[i];
       v[i] = t;
   }
}
t = v[left];
v[left] = v[last];
v[last] = t;
quicksort(v,left,last-1);
quicksort(v,last+1,right);
}

function dnatablesection(start, stop, hasmodal, index){
var i,j, nument, lastent, t, i2, k;
var zz = "";
var auxarray = new Array();
var sortarray = globalsortarray;

if (hasmodal){
  insertmodals(start, stop, hasmodal, index);
   for(j = 0; j <= stop-start; j++)auxarray[j] = j;
   if(stop > start){
     quicksort(auxarray,0,stop-start); 
   }

} else  document.write("<tr class='sep'> <td class='" + fluxus[donald[start][5]] + "' colspan='"+colspannum+"' style='height: .6em; text-align: left;'> </td> </tr>"); 

  for(i2 = 0; i2 <= stop - start; i2++){
          
    i =   !hasmodal ? i2 + start : sortarray[auxarray[i2]].index; 
    dtmp = donald[i];

if(globaltruncate == 1 && ttype && sortarray[auxarray[i2]].tmrca > globalmaxtmrca) break;
// the above statement is the one that truncates the individual tables by max TMRCA

    zz = "<tr><td class='txt'> <a href='javascript:dob(" + i + "); '>  &amp;" +dtmp[1] + "</a>" +
     "</td><td class='txt'> <a href='javascript:doa(\"" + dtmp[2] + "\"); '>" + dtmp[2] +
       "</a></td><td class='txt' id='q" + i + "' >"+dtmp[3] + "</td>" ; //  fluxus[dtmp[5]];  the fluxus[dtmp[5]] was 4 before addmajor
     
    if(hasmodal){
       zz += sortarray[auxarray[i2]].str;

       for(j = 0, k = nbefore; j < (dtmp.length - nbefore); j++, k++){
        zz += (dtmp[k] !== undefined ) ? 
           ((modals[j] === undefined || Math.round(dtmp[k]) == modals[j]) ? "<td title='"+ markerheadings[j] +"'>" : "<td title='"+ markerheadings[j] +"' class='pink'>") + 
//           ((modals[j] === undefined || Math.round(dtmp[k]) == modals[j]) ? "<td>" : "<td class='pink'>") +
               (dtmp[k] +  (j == 11 ? dtmp[k-2] : 0 ) ) + "</td>" : "<td />";
      }
     
    } else {
      zz += "<td /><td />";
      for(j = 0, k = nbefore; j < (dtmp.length - nbefore); j++, k++){
           zz += (dtmp[k] !== undefined) ?
                "<td>"  +  (dtmp[k] +  (j == 11 ? dtmp[k-2] : 0 ) ) + "</td>" : "<td />";
      }
    }

    zz += tds[lastmarkerused - dtmp.length + nbefore + 1] + "<td class='txt'>"+ dtmp[3] + "</td></tr>";
    sepcount++;
    if(sepcount == 5){
        sepcount = 0;
        zz += "<tr class='sep'> <td class='sep' colspan='"+colspannum+"'> </td> </tr>";
    }
    document.write(zz);
     
  }   
}

function generatetableheadings () {
var i,j, stemp, k= -1;
var xhstyle = " style='background-color: rgb(217,222,255)'";


for(i = 0; i <= lastmarkerused; i++){
 stemp = markerheadings[i].charAt(0);
 for(j = 1; j < markerheadings[i].length; j++){
  if(markerheadings[i].charAt(j) == '=')break;
  stemp = stemp+"<br />"+markerheadings[i].charAt(j);
 }

 k++;
 if(k == 12)k = 0;

 if(markerheadings[i].length <= 6) {
     if(markerheadings[i].indexOf("710") == -1){
          document.write("<th" + (k > 5 ? xhstyle : "") + ">"+stemp+"</th>");
     } else {
         document.write("<th class='sq5'" +  (k > 5 ? xhstyle : "") + ">"+stemp+"</th>");     
     }

  } else if(markerheadings[i].length == 7){
     if(markerheadings[i].indexOf("F399") == -1){
         document.write("<th class='sq2'" +  (k > 5 ? xhstyle : "") + ">"+stemp+"</th>");
     } else {
         document.write("<th class='sq5'" +  (k > 5 ? xhstyle : "") + ">"+stemp+"</th>");
     }
  }  else if(markerheadings[i].length == 8){
     document.write("<th class='sq3'" +  (k > 5 ? xhstyle : "") + ">"+stemp+"</th>");

  }  else {

     document.write("<th class='sq4'" +  (k > 5 ? xhstyle : "") + ">"+stemp+"</th>");
  }
 }
 document.write("<th class='txtname'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>");
}

function allhead(start, stop, modal){
var i, k, l;


document.write("<colgroup span='5' />");

 for(i = k = 0; i < Math.floor((lastmarkerused+1)/12); i++){
   document.write("<colgroup span='6' /><colgroup span='6' class ='sh'/>");
 } 
 k = lastmarkerused + 1 - 12 * (Math.floor((lastmarkerused+1)/12));

 if(k > 0){
     document.write("<colgroup span='"+k+"'/>");
 }
 k -= 6;
 if(k > 0){
     document.write("<colgroup span='"+k+"' class ='sh' />");

 }

 document.write(
  "<thead>" + 
  "<tr><th class='txt'> Clan<br />&nbsp;&nbsp;Donald&nbsp;&nbsp;<br />Code</th>" + 
  "<th class='txtys'>Ysearch<br />Code</th>" + 
  "<th class='txtname'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </th>")

colspannum = 7+lastmarkerused;
   if(modal){
      document.write("<th class='txtdist'> D<br />i<br />s<br />t</th><th class='w1'> T<br />M<br />R<br />C<br />A</th>"); 
   } else {
      document.write("<th class='txtdist' /><th class='w1' />");
   }  
   generatetableheadings();

   document.write("</tr></thead>");
}


function doawholetable(group,mingroup, modal, index){
   var i,j, k;



 lastmarkerused = getmaxindex(groups[group][mingroup][0], groups[group][mingroup][1]);
 if(modal){
     if(!ttype)fillmodalsarray(groups[group][mingroup][0], groups[group][mingroup][1]);
     globalsortarray = dodistancearray(groups[group][mingroup][0], groups[group][mingroup][1]);

 }
 if(!ttype ||  groupmintmrca <= globalmaxtmrca){ 
   isthereanymatch = 1;
   document.write("<div><span style='font-weight: bold;'>"+labelstring+"&nbsp;···&nbsp;"+fluxusdescr[donald[groups[group][mingroup][0]][5]]+" subgroup</span>");
   if(labelstring2 != "")document.write("<br /><br />" + labelstring2);
   document.write("<br /><br /></div><table style='margin-right: 8px'>");

   allhead(groups[group][mingroup][0], groups[group][mingroup][1], modal);
   sepcount = 0;

   document.write("<tbody>");
  dnatablesection(groups[group][mingroup][0],groups[group][mingroup][1],modal, index);

   if(sepcount) document.write( "<tr class='sep'> <td class='sep' colspan='"+colspannum+"'> </td> </tr>");

   document.write("</tbody> </table><p> </p>");
 }
}

function insertmodalsfromperson(index){
var i;
  modalslen = 0;
  for(i = 0; i < mrkl; i++) {
    if(donald[index][i+nbefore] !== undefined) {
       modals[i] = Math.round(donald[index][i+nbefore]);
       modalslen = i;
    } else modals[i] = undefined;
   }
   modalslen++; 
}

function inserthtmlforms(){
var i,j,k,m;
var stemp;
var qstring;
var numcols = 15;
var zz = "<br /><br /><table class='myform1'><tbody> <tr><td class='forms0'>Enter a desired maximum TMRCA in this box, set the desired value setting for table truncation, and click Set<br />&nbsp;</td></tr>" +
"<tr><td><form name='myform2' action='' onsubmit='return false;' ><br /><input type = 'text' name='myform2input' size='6' />"+
"&nbsp;&nbsp;&nbsp;<input type='button' value='Set' onclick='doq();' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' value='Yes' name='myform2check' />&nbsp;Truncate Tables?</form><br /></td></tr> </tbody></table><br /><br />";

zz += "<table class='myform2'><tbody> <tr><td class='forms0'>Enter a Clan Donald code (with an &amp; sign) or Ysearch code (without the &amp; sign) <br /> and click Submit to see a table of distances. <br />&nbsp;</td></tr>" +
"<tr><td><form name='myform0' action='' onsubmit='return false;'><br /><input type = 'text' name='myform0input' size='11' />"+
"&nbsp;&nbsp;&nbsp;<input type='button' value='Submit' onclick='doc();' /></form><br /></td></tr> </tbody></table><br /><br />" + 
"<table class='myform'><tbody><tr><td class = 'forms0'>"+
"Enter any combination of two or more markers and click Submit<br /> to see a table of distances. <br /> &nbsp;"+
"</td></tr>"+
"<tr><td><form name='myform1' action='' onsubmit='return false;'><table class='myform'><tbody>";

zz += "  <tr class='sep'> <td class='sep3' colspan='"+(numcols)+"'> </td> </tr>";
 m = Math.ceil(mrkl/numcols);
 for(i = 0; i < m; i++) {

    for(j = 0; (j < numcols) && ((i*numcols+j) < mrkl); j++){
      stemp = markerheadings[j+i*numcols].substring(0,3);
      if((markerheadings[j+i*numcols].substring(3,6)).length > 0){
        stemp = stemp + "<br />" + (markerheadings[j+i*numcols].substring(3,6));
      }
      if((markerheadings[j+i*numcols].substring(6,9)).length > 0){
        stemp = stemp + "<br />" + (markerheadings[j+i*numcols].substring(6,9));
      }
      zz += "<td class='formhead'>"+stemp+"</td>";

    }
    zz += "</tr><tr>";

    for(j = 0; (j < numcols) && ((i*numcols+j) < mrkl); j++){

       zz += "<td><input type = 'text' size='2' /></td>";
    }
    zz += "</tr><tr class='sep'> <td class='sep3' colspan='"+(numcols)+"'> </td> </tr>";
}

zz += "</td></tr></tbody></table><br />"+
"<input type='button' value='Submit' onclick='dod();' /></form>"+
"<br /></td></tr></tbody></table>";   


document.write(zz);

//var zz2;

//zz2 = zz.replace(new RegExp("<","g"),"qqbbww");
//document.write(zz2);


for(i = 0; i < mrkl; i++)
  document.myform1.elements[i].value = " ";


if(globaltruncate == 1){ 
   document.myform2.myform2check.checked = true;
} else {
   document.myform2.myform2check.checked = false;
}

document.myform2.myform2input.value = globalmaxtmrca;


}

function dowholemajorgroup( i ) {
var j;


   for(j = 0; j <= groups[i].maxminor; j++){

         if(groups[i][j][0] <= groups[i][j][1]){

           if(ttype == 0){ 

               if(groups[i][j][0] < groups[i][j][1])  doawholetable(i,j,1,0);
               else   doawholetable(i,j,0,0);
           } else {
               doawholetable(i,j,2,newperson);
           } 
          
         }
   }
}

var tds = new Array();

// end of functions, MAIN PROGRAM begins here

tds[0] = "";
for(i = 1; i < mrkl; i++)tds[i] = tds[i-1] +"<td />";

allcookies = document.cookie;

var posz = allcookies.indexOf("tmrca=");
if(posz != -1){
   var strtz = posz + 6;
   var endz = allcookies.indexOf(";",strtz);
   if(endz == -1)endz = allcookies.length;
   globalmaxtmrca = allcookies.substring(strtz,endz);
}  
var posz = allcookies.indexOf("truncate=");
if(posz != -1){
   var strtz = posz + 9;
   var endz = allcookies.indexOf(";",strtz);
   if(endz == -1)endz = allcookies.length;
   globaltruncate = allcookies.substring(strtz,endz);
  
}

