// Copyright 2003-2004 © by David D Sadler. All Rights Reserved.

var browserVersion = parseInt(navigator.appVersion);
var isNetscape     = navigator.appName.indexOf("Netscape") != -1;
var isIE           = navigator.appName.indexOf("Microsoft") != -1;
var isOpera        = navigator.userAgent.indexOf("Opera") != -1;
    if (isOpera) {isIE = false; isNetscape = false;}
var agent          = navigator.userAgent.toLowerCase();
var isWindows      = agent.indexOf("win") != -1;
var isMac          = agent.indexOf("mac") != -1;
var isUnix         = agent.indexOf("X11") != -1;
//alert("Agent = " + navigator.userAgent + "\nApp = " + navigator.appName + "\nagent = " + agent + "\nversion = " + browserVersion + "\nisIE = " + isIE + " isNetscape = " + isNetscape + " isOpera = " + isOpera + "\n\n");

// Ad Sense parameters
var google_ad_client = "pub-5476539624993958";
//var google_alternate_ad_url = '<a href="http://www.gardencards.biz/index.htm"><img src="http://www.gardencards.biz/images/Misc/gardencardslogo.jpg" alt="Botanical%20Cards%20for%20Gardeners" border="0"></a>';
var google_ad_width = 468;
var google_ad_height = 60;
var google_ad_format = "468x60_as";
var google_color_border = "B0E0E6";
var google_color_bg = "FFFFFF";
var google_color_link = "000000";
var google_color_url = "336699";
var google_color_text = "333333";
// End Ad Sense parameters

var cpl       = new Array();
    cpl[0]    = ["",      "Half-", "Half-"]; 
    cpl[1]    = ["Half-", "",      "Step-"]; 
    cpl[2]    = ["Half-", "Step-",  ""]; 
var sps       = new Array();
    sps[0]    = ["",                "0"];  //text to use, code for adding text (0=nothing;1=replace all; 2=appendsamesex; 3=appendoppositesex; prepend
    sps[1]    = ["(not applicable)","5"];  
    sps[2]    = ["",                "3"];
    sps[3]    = ["-in-law",         "3"];
    sps[4]    = ["",                "6"];
    sps[5]    = [" (by marriage)",  "2"];
    sps[6]    = [" (by marriage)",  "3"];
    sps[7]    = ["Wife of ",        "4"];
    sps[8]    = ["Husband of ",     "4"];
    sps[9]    = ["Spouse of ",      "4"];
var spstype   = new Array();
    spstype[1] = ["replace"];
    spstype[2] = ["append same gender"];
    spstype[3] = ["append opposite gender"];
    spstype[4] = ["prepend"];
var rels     = new Array();
    rels[0]  = [["Myself", "Male", "Female"],                                     ["Child", "Son", "Daughter"],                      ["Grandchild", "Grandson", "Granddaughter"], ["Great-Grandchild", "Great-Grandson", "Great-Granddaughter"], ["2G-Grandchild", "2G-Grandson", "2G-Granddaughter"], ["3G-Grandchild", "3G-Grandson", "3G-Granddaughter"], ["4G-Grandchild", "4G-Grandson", "4G-Granddaughter"], ["5G-Grandchild", "5G-Grandson", "5G-Granddaughter"], ["6G-Grandchild", "6G-Grandson", "6G-Granddaughter"], ["7G-Grandchild", "7G-Grandson", "7G-Granddaughter"]];
    rels[1]  = [["Parents", "Father", "Mother"],                                  ["Sibling", "Brother", "Sister"],                  ["Nephew/Niece", "Nephew", "Niece"],         ["Grandnephew/niece", "Grandnephew", "Grandniece"], ["Great Grandnephew/niece", "Great Grandnephew", "Great Grandniece"], ["2G-Grandnephew/niece", "2G-Grandnephew", "2G-Grandniece"], ["3G-Grandnephew/niece", "3G-Grandnephew", "3G-Grandniece"], ["4G-Grandnephew/niece", "4G-Grandnephew", "4G-Grandniece"], ["5G-Grandnephew/niece", "5G-Grandnephew", "5G-Grandniece"], ["6G-Grandnephew/niece", "6G-Grandnephew", "6G-Grandniece"]];
    rels[2]  = [["Grandparents", "Grandfather", "Grandmother"],                   ["Uncle/Aunt", "Uncle", "Aunt"],                   ["First Cousin", "", ""],           ["1C1R", "", ""], ["1C2R", "", ""], ["1C3R", "", ""], ["1C4R", "", ""], ["1C5R", "", ""], ["1C6R", "", ""], ["1C7R", "", ""]];
    rels[3]  = [["Great-Grandparents", "Great-Grandfather", "Great-Grandmother"], ["Great Uncle/Aunt", "Great Uncle", "Great Aunt"], ["1C1R", "", ""], ["Second Cousin", "", ""],          ["2C1R", "", ""], ["2C2R", "", ""], ["2C3R", "", ""], ["2C4R", "", ""], ["2C5R", "", ""], ["2C6R", "", ""]];
    rels[4]  = [["2G-Grandparents", "2G-Grandfather", "2G-Grandmother"],          ["2G Uncle/Aunt", "2G Uncle", "2G Aunt"],          ["1C2R", "", ""], ["2C1R", "", ""], ["Thrid Cousin", "", ""],           ["3C1R", "", ""], ["3C2R", "", ""], ["3C3R", "", ""], ["3C4R", "", ""], ["3C5R", "", ""]];
    rels[5]  = [["3G-Grandparents", "3G-Grandfather", "3G-Grandmother"],          ["3G Uncle/Aunt", "3G Uncle", "3G Aunt"],          ["1C3R", "", ""], ["2C2R", "", ""], ["3C1R", "", ""], ["Fourth Cousin", "", ""],          ["4C1R", "", ""], ["4C2R", "", ""], ["4C3R", "", ""], ["4C4R", "", ""]];
    rels[6]  = [["4G-Grandparents", "4G-Grandfather", "4G-Grandmother"],          ["4G Uncle/Aunt", "4G Uncle", "4G Aunt"],          ["1C4R", "", ""], ["2C3R", "", ""], ["3C2R", "", ""], ["4C1R", "", ""], ["Fifth Cousin", "", ""],           ["5C1R", "", ""], ["5C2R", "", ""], ["5C3R", "", ""]];
    rels[7]  = [["5G-Grandparents", "5G-Grandfather", "5G-Grandmother"],          ["5G Uncle/Aunt", "5G Uncle", "5G Aunt"],          ["1C5R", "", ""], ["2C4R", "", ""], ["3C3R", "", ""], ["4C2R", "", ""], ["5C1R", "", ""], ["Sixth Cousin", "", ""],           ["6C1R", "", ""], ["6C2R", "", ""]];
    rels[8]  = [["6G-Grandparents", "6G-Grandfather", "6G-Grandmother"],          ["6G Uncle/Aunt", "6G Uncle", "6G Aunt"],          ["1C6R", "", ""], ["2C5R", "", ""], ["3C4R", "", ""], ["4C3R", "", ""], ["5C2R", "", ""], ["6C1R", "", ""], ["Seventh Cousin", "", ""],         ["7C1R", "", ""]];
    rels[9]  = [["7G-Grandparents", "7G-Grandfather", "7G-Grandmother"],          ["7G Uncle/Aunt", "7G Uncle", "7G Aunt"],          ["1C7R", "", ""], ["2C6R", "", ""], ["3C5R", "", ""], ["4C4R", "", ""], ["5C3R", "", ""], ["6C2R", "", ""], ["7C1R", "", ""], ["Eigth Cousin", "", ""]];
var rrels     = new Array();    
    rrels[0]  = ["Self", "Son", "Daughter", "Brother ", "Sister", "Nephew", "Niece", "Cousin", "Grandson", "Granddaughter",                                        "Father",       "Mother",       "Grandfather",       "Grandmother",       "Husband",       "Wife"];
    rrels[1]  = ["Parents", "Brother", "Sister", "Uncle", "Aunt", "First Cousin", "First Cousin", "1C1R", "Nephew", "Niece",                                       "Grandfather",  "Grandmother",  "Great-Grandfather", "Great-Grandmother", "Father",        "Mother"];
    rrels[2]  = ["Uncle/Aunt", "First Cousin", "First Cousin", "Uncle", "Aunt", "First Cousin", "First Cousin", "1C1R", "Uncle", "Aunt",                           "Grandfather",  "Grandmother",  "Great-Grandfather", "Great-Grandmother", "N/A Aunt",    "N/A Uncle"];
    rrels[3]  = ["Nephew/Niece", "Grandnephew", "Grandniece", "Nephew", "Niece", "G Grandnephew", "G Grandniece", "Nephew/Niece", "G Grandnephew", "G Grandniece", "Brother",      "Sister",       "Father",            "Mother",            "N/A Nephew",  "N/A Niece"];
    rrels[4]  = ["First Cousin", "1C1R", "1C1R", "First Cousin", "First Cousin", "1C1R", "1C1R", "First Cousin", "1C2R", "1C2R",                                   "1C1R",         "1C1R",         "1C2R",              "1C2R",              "First Cousin",  "First Cousin"];
    rrels[5]  = ["Second Cousin", "2C1R", "2C1R", "Second Cousin", "Second Cousin", "2C1R", "2C1R", "Second Cousin", "2C2R", "2C2R",                               "2C1R",         "2C1R",         "2C2R",              "2C2R",              "Second Cousin", "Second Cousin"];
    rrels[6]  = ["Third Cousin", "3C1R", "3C1R", "Third Cousin", "Third Cousin", "3C1R", "3C1R", "Third Cousin", "3C2R", "3C2R",                                   "3C1R",         "3C1R",         "3C2R",              "3C2R",              "Third Cousin",  "Third Cousin"];
    rrels[7]  = ["Fourth Cousin", "4C1R", "4C1R", "Fourth Cousin", "Fourth Cousin", "4C1R", "4C1R", "Fourth Cousin", "4C2R", "4C2R",                               "4C1R",         "4C1R",         "4C2R",              "4C2R",              "Fourth Cousin", "Fourth Cousin"];
    rrels[8]  = ["Grandparents", "Uncle", "Aunt", "G Uncle", "G Aunt", "1C1R", "1C1R", "1C2R", "2C2R", "2C2R",                                             "Great-Grandfather","Great-Grandmother","2G-Grandfather",    "2G-Grandmother",  "N/A Grandfather", "N/A Grandmother"];
    rrels[9]  = ["G Grandparents", "G Uncle", "G Aunt", "2G Uncle", "2G Aunt", "1C2R", "1C2R", "1C3R", "1C3R", "1C3R",                                      "2G-Grandfather",   "2G-Grandmother",  "3G-Grandfather",    "3G-Grandmother", "N/A Great-Grandfather", "N/A Great-Grandmother"];
    rrels[10] = ["2G Grandparents", "2G Uncle", "2G Aunt", "3G Uncle", "3G Aunt", "1C3R", "1C3R", "1C4R", "1C4R", "1C4R",                                   "3G-Grandfather",   "3G-Grandmother",  "4G-Grandfather",    "4G-Grandmother", "N/A 2G-Grandfather", "N/A 2G-Grandmother"];
    rrels[11] = ["3G Grandparents", "3G Uncle", "3G Aunt", "4G Uncle", "4G Aunt", "1C4R", "1C4R", "1C5R", "1C5R", "1C5R",                                   "4G-Grandfather",   "4G-Grandmother",  "5G-Grandfather",    "5G-Grandmother", "N/A 3G-Grandfather", "N/A 3G-Grandmother"];
    rrels[12] = ["4G Grandparents", "4G Uncle", "4G Aunt", "5G Uncle", "5G Aunt", "1C5R", "1C5R", "1C6R", "1C6R", "1C6R",                                   "5G-Grandfather",   "5G-Grandmother",  "6G-Grandfather",    "6G-Grandmother", "N/A 4G-Grandfather", "N/A 4G-Grandmother"];
var irels     = new Array();
    irels[0]  = [   0   ,      1     ,    2     ,    3     ,    4     ,    5     ,    6     ,    7     ,    8     ,    9     ,     10   ,     11   ,     12   ,     13   ,     14   ,     15   , 0 ];   //   Alignment
    irels[0]  = [[0,0,0,0], [0,0,1,3], [1,0,1,3], [0,1,1,3], [1,1,1,3], [0,1,2,6], [1,1,2,6], [0,2,2,5], [0,0,2,7], [1,0,2,8], [0,1,0,2], [1,1,0,2], [0,2,0,2], [1,2,0,2], [0,0,0,0], [0,0,0,0], 0 ];   //  0=male/female; 1&2=pointer pair to rels; 3=modifier
    irels[1]  = [[0,0,1,0], [0,1,1,3], [1,1,1,3], [0,2,1,6], [1,2,1,6], [0,2,2,4], [0,2,2,4], [0,3,2,9], [0,1,2,6], [1,1,2,6], [0,2,0,2], [1,2,0,2], [0,3,0,2], [1,3,0,2], [0,1,0,2], [1,1,0,2], 1 ];
    irels[2]  = [[0,1,2,0], [0,2,2,5], [0,2,2,5], [0,2,1,6], [1,2,1,6], [0,2,2,4], [0,2,2,4], [0,3,2,9], [0,2,3,6], [1,2,3,6], [0,2,0,2], [1,2,0,2], [0,3,0,2], [1,3,0,2], [0,2,1,2], [1,2,1,2], 2 ];
    irels[3]  = [[0,2,1,0], [0,1,3,6], [1,1,3,6], [0,1,2,6], [1,1,2,6], [0,1,4,6], [1,1,4,6], [0,1,2,6], [0,1,4,6], [1,1,4,6], [0,1,1,3], [1,1,1,3], [0,1,0,2], [1,1,0,2], [0,1,2,2], [1,1,2,2], 3 ];
    irels[4]  = [[0,2,2,0], [0,3,2,4], [0,3,2,4], [0,2,2,4], [0,2,2,6], [0,3,2,4], [0,3,2,4], [0,2,2,9], [0,2,4,4], [0,2,4,4], [0,2,1,2], [1,2,1,2], [0,2,4,4], [1,2,4,4], [0,2,2,6], [1,2,2,6], 4 ];
    irels[5]  = [[0,3,3,0], [0,3,4,4], [0,3,4,4], [0,3,3,4], [0,3,3,4], [0,3,4,4], [0,3,4,4], [0,3,3,9], [0,3,5,4], [0,3,5,4], [0,3,4,4], [1,3,4,4], [0,3,5,4], [1,3,5,4], [0,3,3,6], [1,3,3,6], 5 ];
    irels[6]  = [[0,4,4,0], [0,4,5,4], [0,4,5,4], [0,4,4,4], [0,4,4,4], [0,4,5,4], [0,4,5,4], [0,4,4,9], [0,4,6,4], [0,4,6,4], [0,4,5,4], [1,4,5,4], [0,4,6,4], [1,4,6,4], [0,4,4,6], [1,4,4,6], 6 ];
    irels[7]  = [[0,5,5,0], [0,5,6,4], [0,5,6,4], [0,5,5,4], [0,5,5,4], [0,5,6,4], [0,5,6,4], [0,5,5,9], [0,5,7,4], [0,5,7,4], [0,5,6,4], [1,5,6,4], [0,5,7,4], [1,5,7,4], [0,5,5,6], [1,5,5,6], 7 ];
    irels[8]  = [[0,2,0,0], [0,2,1,6], [1,2,1,6], [0,3,1,6], [1,3,1,6], [0,2,3,7], [0,2,3,8], [0,2,4,9], [0,2,2,7], [0,2,2,8], [0,3,0,2], [1,3,0,2], [0,4,0,2], [1,4,0,2], [0,2,0,2], [1,2,0,2], 8 ];
    irels[9]  = [[0,3,0,0], [0,3,1,6], [1,3,1,6], [0,4,1,6], [1,4,1,6], [0,2,4,7], [0,2,4,8], [0,2,5,9], [0,3,2,7], [0,3,2,8], [0,4,0,2], [1,4,0,2], [0,5,0,2], [1,5,0,2], [0,3,0,2], [1,3,0,2], 9 ];
    irels[10] = [[0,4,0,0], [0,4,1,6], [1,4,1,6], [0,5,1,6], [1,5,1,6], [0,2,5,7], [0,2,5,8], [0,2,6,9], [0,2,4,7], [0,2,4,8], [0,5,0,2], [1,5,0,2], [0,6,0,2], [1,6,0,2], [0,4,0,2], [1,4,0,2], 10];
    irels[11] = [[0,5,0,0], [0,5,1,6], [1,5,1,6], [0,6,1,6], [1,6,1,6], [0,2,6,7], [0,2,6,8], [0,2,7,9], [0,2,5,7], [0,2,5,8], [0,6,0,2], [1,6,0,2], [0,7,0,2], [1,7,0,2], [0,5,0,2], [1,5,0,2], 11];
    irels[12] = [[0,6,0,0], [0,6,1,6], [1,6,1,6], [0,7,1,6], [1,7,1,6], [0,2,7,7], [0,2,7,8], [0,2,8,9], [0,2,6,7], [0,2,6,8], [0,7,0,2], [1,7,0,2], [0,8,0,2], [1,8,0,2], [0,6,0,2], [1,6,0,2], 12];

function pickrel (xr,xc,xm) {
  var x = rels[xr][xc][xm];
  if (x == "") {x = rels[xr][xc][0]}
  return(x);
}

function tellmet (fname) {
  if (fname.sond.value == "" || fname.rel.value == "") {return(false)};
  var c = fname.sond.value;
  var r = fname.rel.value;
  var rr  = irels[r][c][1];
  var cc  = irels[r][c][2];
  var  p  = irels[r][c][3];
  var pp  = sps[p][1];
  var rel = "";
  var db  = "off";

  if (irels[r][c][0] == 0) {fname.yrellyr.value = rel = pickrel(rr,cc,1); fname.rrellyr.value = pickrel(cc,rr,1);}  //male
    else {fname.yrellyr.value = rel = pickrel(rr,cc,2); fname.rrellyr.value = pickrel(cc,rr,2);}                    //female
  if (fname.gender.value == 0) {fname.rrellyr.value = pickrel(cc,rr,1);}  //male
    else {fname.rrellyr.value = pickrel(cc,rr,2);}                        //female

  switch(pp) {
    case "0":
      break;
    case "1":
      if (irels[r][c][0] != 0) {rel = pickrel(rr,cc,2)} else {rel = pickrel(rr,cc,1)}
      rel = rel + sps[p][0];
      break;
    case "2":
      rel = rel + sps[p][0];
      break;
    case "3":
      if (irels[r][c][0] != 0) {rel = pickrel(rr,cc,1)} else {rel = pickrel(rr,cc,2)}
      rel = rel + sps[p][0];
      break;
    case "4":
      rel = sps[p][0] + rel;
      break;
    case "5":
      rel = sps[p][0];
      break;
    default:
      break;
    case "6":
      if (irels[0][c][0] == 0) {rel = "Wife of " + rel} else {rel = "Husband of " + rel}
      break;
  }  
  fname.spouse.value = rel;

  //  fname.yrellyr.focus(); fname.rrellyr.focus();
  if (db == "on") {
    var g1, g2, r1, r2 = "";
   
    var l = "Looking at irels[" + r + "][" + c + "] = [" + irels[r][c][0] + "," + irels[r][c][1] + "," + irels[r][c][2] + "," + irels[r][c][3] + "]\n"; 
    var t = "Modify type = " + pp + " (" + spstype[pp] + ") with " + sps[p][0] + "\n"; 
    if (irels[r][c][0] == 0) {g1 = "Male"} else {g1 = "Female"}
    if (irels[0][c][0] == 0) {g2 = "Male"} else {g2 = "Female"}
    g1 = "Gender is " + g1 + "\n";
    g2 = "Gender of first " + g2 + "\n";
    r1 = "Which means " + rels[rr][cc][0] + " (rels[" + rr + "][" + cc + "][0])\n";
    if (irels[r][c][0] == 0) {r2 = pickrel(cc,rr,1) + " rels"} else {r2 = pickrel(cc,rr,2) + " rels"}
    r2 = "And relative is " + r2 + "[" + cc + "][" + rr + "]\n";
	fname.rrellyr.focus();
    alert(l + r1 + r2 + g1 + g2 + t + "\n\n");
  }
  return;
}

function tellme (fname) {
// if (document.getElementById(fname) != "") {
  var r = 0;
  var c = 0;
  var g = 0;
  var yr = 0;
  var rr = 0;
  var cp = "";
  c = fname.yancestor.value;
  r = fname.rancestor.value;
  yg = fname.ygender.value;
  rg = fname.rgender.value;
  cp = cpl[fname.tcouple.value][fname.ycouple.value];

//alert("c = " + c + " and r = " + r);
  
  if (yg == 0) {yr = pickrel(r,c,1)} else {yr = pickrel(r,c,2)};
  if (rg == 0) {rr = pickrel(c,r,1)} else {rr = pickrel(c,r,2)};
  if (cp != "") {yr = cp + yr; rr = cp + rr;};
  fname.yrelly.value = yr;
  fname.rrelly.value = rr;
// }
  return;
}

function startrellys () {
  if (document.prams)    {tellme (document.prams)};
//alert("prams = " + prams  + "  cexample" + cexample + "  pramsr" + pramsr);
  if (document.cexample) {tellme (document.cexample)};
  if (document.pramsr)   {tellmet (document.pramsr)};
  return;
}

var bcolors = ["#CCFFFF", "#87CEFA"];  //87CEFA = LightSkyBlue  CCFFFF = cyan
var mcolor = "yellow"
var kcolor = "LightSteelBlue"              //CCFFFF
var ocolor = "white"
var rcolor = "PaleGreen"
var ar, ac, ai, aa, current; 
var lock = false;

function highlight(which){
  //var tds = document.body.getElementsByTagName("td");
  if (lock == true) {return};
  if (document.all)
//alert("isNetscape = " + isNetscape + "  which = " + which + "  which.getAttribute(ID) = " + which.getAttribute("ID"));
    if (isNetscape) {var which = document.which};
    which.style.backgroundColor=mcolor;
    which.style.cursor="pointer";
//    which.style.color="blue";
    current = which;
    var r = which.getAttribute("ID").charAt(1);
    var c = which.getAttribute("ID").charAt(4);
    var y = "R" + which.getAttribute("ID").charAt(1) + "_C0";
    ar = document.getElementById(y);
    if(ar) {ar.style.backgroundColor=rcolor}
//    ar.style.color="DarkGoldenrod";
    y = "R0_C" + which.getAttribute("ID").charAt(4);
    ac = document.getElementById(y);
    if(ac) {ac.style.backgroundColor=mcolor}
//    ac.style.color="DarkGoldenrod";

  return;
}

function nolight(which){
  if (lock == true) {return};
    var y = current.getAttribute("ID");
    var x = document.getElementById(y);
    x.style.backgroundColor=ocolor;
//    current.style.cursor="default";
//    current.style.color="black";
    if(ar) {ar.style.backgroundColor=ocolor}
//    ar.style.color="black";
    if(ac) {ac.style.backgroundColor=ocolor}
//    ac.style.color="black";
//    ai.style.backgroundColor=ocolor;
//    ai.style.color="black";
//    aa.style.backgroundColor=ocolor;
//    aa.style.color="black";

  return;
}

function chck(element){
//alert("here - 235");
  var v = -1;
  for(var i = 0;i< element.length; ++i) {
    if (element[i].checked) {v = element[i].value; break;}
  } 
  if(v == -1) {return(v)}
  var v = v*1 + 1;
  return(v);
}

function fix(which){
  if (lock == true) { 
    lock = false; 
    if (which != current) {nolight(which); highlight(which);}
	document.getElementById("rellys").style.visibility = "hidden"
    ai.style.backgroundColor=ocolor;
    aa.style.backgroundColor=ocolor;
  }
  else {
    ai = which;
    r = which.getAttribute("ID").charAt(1);
    c = which.getAttribute("ID").charAt(4);
    if (r != c) {
      var y = "R" + which.getAttribute("ID").charAt(4) + "_C" + which.getAttribute("ID").charAt(1);
      ai = document.getElementById(y);
      ai.style.backgroundColor=rcolor;
//      ai.style.color="green";
      y = "R0_C" + which.getAttribute("ID").charAt(1);
      aa = document.getElementById(y);
      aa.style.backgroundColor=rcolor;
//      aa.style.color="green";
    }
    lock = true; 
    highlight(which); 
    genclick(which);
  }
  return;
}

var r, c;

function genclick(which) {
  if (lock == true) { 
  var gena = (isNetscape) ? document.gender : gender;
  var yg = chck(gena.ygen);
  var rg = chck(gena.rgen);
//alert("rels[c][0][0]) = " + rels[c][0][0]); 
  var ma = rels[c][0][0]; if (ma == "Myself") {ma = "self"};
  var mb = rels[r][0][0]; if (mb == "Myself") {mb = "self"};
  var mt = ""; var rt = "";
  var at = "an <u>ascendant</u>"; var dt = "a <u>descendant</u>";
  var hm = "<span style='background-color:" + mcolor + "'>You</span>";
  var hr = "<span style='background-color:" + rcolor + "'>your relative</span>";
  var mt, rt, rc, genm;
  if (r < c ) {mt = dt; rt = at};
  if (c < r ) {mt = at;  rt = dt};
  if (r != c) {
    genm = hm + " are in " + mt + " generation while " + hr + " is in " + rt + " generation.";
  } else {
    genm = hm + " and " + hr + " are of the same generation.";
  }
  }
    rc = r*1 + c*1;
    var db = document.getElementById("rellys").innerHTML = '<tr valign="top"><td align="left"><p style="font-size:small">'
      + 'Your common ancestor is your&nbsp;<span style="text-decoration:underline; background-color:yellow">' + ma + '.</span>'
      + ' And you are the <span style="text-decoration:underline; background-color:yellow">' + pickrel(0,c,yg) + '.</span>'
      + ' to that ancestor. The common ancestor of your relative is their <span style="text-decoration:underline; background-color:PaleGreen">' + mb + '.</span>'
      + ' And they are the <span style="text-decoration:underline; background-color:PaleGreen">' + rels[0][r][rg] + '</span>'
      + ' to that ancestor. You are a </span><span style="text-decoration:underline; background-color:yellow">' + pickrel(r,c,yg) + '</span>'
      + ' to your relative. Your relative is an <span style="text-decoration:underline; background-color:PaleGreen">' + pickrel(c,r,rg) + '</span>'
      + ' to you. ' + genm + '<br>Your Degree of Kinship is ' + rc + '.</p></td></tr>';
	document.getElementById("rellys").style.visibility = "visible";

//alert("html = \n" + db);

  return;
}

function litdiag(which) {
  if (lock == true) {return};
//alert("which = " + which.getAttribute("ID"));
  if (current && which != current) {dim(which)};
  var r, c, y;
  if (document.all)
    which.style.backgroundColor=mcolor;
    which.style.cursor="pointer";
    current = which;
    r = which.getAttribute("ID").charAt(1);
    c = which.getAttribute("ID").charAt(4);
    y = 6 - r;
	document.getElementById("rellys3").innerHTML = '<p style="text-align: left; font-size:x-small">'
		+ 'The ancestor is your: <u>' + rels[y][0][0] + '</u><br>'
		+ 'You are their: <u>' + pickrel(0,y,0) + '</u><br>'
		+ '<br>The ancestor is their: <u>' + rels[c][0][0] + '</u><br>'
		+ 'They are a: <u>' + pickrel(0,c,0)
		+ '</u></p>';
//	document.getElementById("rellys3").style.visibility = "visible";

//alert("r = " + r + " c = " + c);

    for (i=1;i<=c;i++) {
      y = "R" + r + "_C" + i;
      if (document.getElementById(y));
        y = document.getElementById(y);
        y.style.backgroundColor=mcolor;
//        y.style.color="DarkGoldenrod";
    }
    for (i=r;i<7;i++) {
      y = "R" + i + "_C0";
      if (document.getElementById(y));
        y = document.getElementById(y);
        y.style.backgroundColor=mcolor;
//        y.style.color="DarkGoldenrod";
    }
  return;
}

function litany(which) {
  litdiag(which);
  return;
}

function dimdiag(which) {
  if (lock == true) {return};
  dim(which);
  return;
}

function dim(which) {
  var r = current.getAttribute("ID").charAt(1);
  var j = r % 2;
  for (i=0;i<7;i++) {
    var y = "R" + r + "_C" + i;
    if (document.getElementById(y));
      y = document.getElementById(y);
      y.style.backgroundColor=bcolors[j % 2];
      y.style.color=bcolors[j % 2];
      j++; 
  }
    j = r % 2;
    for (i=r;i<7;i++) {
      y = "R" + i + "_C0";
    if (document.getElementById(y));
      y = document.getElementById(y);
      y.style.backgroundColor=bcolors[j % 2];
      y.style.color=bcolors[j % 2];
      j++; 
    }
  return;
}

function fixdiag(which){
  if (lock == false) {
    var r, c, x, y, j;
    r = which.getAttribute("ID").charAt(1);
    c = which.getAttribute("ID").charAt(4);
    x = c*1 + 1;
    if (r%2 == c%2) {j = 1} else {j = 0};
    for (i=x;i<7;i++) {
      y = "R" + r + "_C" + i;
      if (document.getElementById(y));
      y = document.getElementById(y);
      y.style.backgroundColor=bcolors[j % 2];
      j++; 
    }
    lock = true;
    y = 6 - r;
    var at = "Ascendant"; var dt = "Descendant";
    document.getElementById("myancestor").innerHTML = rels[y][0][0];
    document.getElementById("rancestor").innerHTML  = rels[c][0][0];
    document.getElementById("myare").innerHTML      = pickrel(0,y,0);
    document.getElementById("tare").innerHTML       = pickrel(0,c,0);
    document.getElementById("myrel").innerHTML      = pickrel(c,y,0);
    document.getElementById("trel").innerHTML       = pickrel(y,c,0);
    var z = y*1 + c*1;
    x = "(" + y + "+" + c + ")  " + z; j = z + "  (" + c + "+" + y + ")"; 
    document.getElementById("mydgr").innerHTML = x;
 	document.getElementById("tdgr").innerHTML  = j;
    if ( y == c ) {
      document.getElementById("myasc").innerHTML = document.getElementById("tasc").innerHTML = "Same";
    } else {
      x = Math.abs(y-c);
      if (y > c) {at += " (" + x + "R)"} else {dt += " (" + x + "R)"}
      document.getElementById("myasc").innerHTML = (y > c) ? dt : at;
      document.getElementById("tasc").innerHTML  = (c > y) ? dt : at;;
    }
    document.getElementById("rellys").style.visibility = "visible";

//alert("rels[" + c + "][0][0] = " + rels[c][0][0] + " rels[" + y + "][0][0] = " + rels[y][0][0]);
//alert("pickrel(" + y + "," + c + ",0) = " + pickrel(y,c,0) + " pickrel(" + c + "," + y + ",0) = " + pickrel(c,y,0));

  }  else {
    lock = false;
    document.getElementById("rellys").style.visibility = "hidden";
    litany(which);
  }
   
  return;
}

var popuparamslittle = "width=520,height=450";                      // popup window parameters
var popuparams       = "width=520,height=600,scrollbars,resizable";
var popuparamsdefs   = "width=650,height=600,scrollbars,resizable";
var popupchartparams = "width=670,height=600,scrollbars,resizable";
var popupallparams   = "width=620,height=600,scrollbars,resizable,status,toolbar,location";

function openWin(ThisFile,ThisName,TheseProps){
//alert("TheseProps = " + TheseProps);
 var ThisWin=window.open(ThisFile,ThisName,TheseProps);
ThisWin.focus();
}

function setupPos() {
//alert("Navigator = " + navigator.appName);
//alert("isNetscape = " + isNetscape);
  if (document.getElementById('menue'))
  var p = document.getElementById('menue');
  if (isIE) {
    p.style.left = "10px";
    p.style.top  = "10px";
  }
  if (isNetscape) {
    p.style.left = "10px";
    p.style.top  = "100px";
  }
  return;
}

function checkinner() {
  if (document.getElementById('rellys'))  
  var p = document.getElementById('rellys')
  if (isNetscape) {
    p.style.visibility = "hidden";
    p.style.position   = "absolute";
    };
  if (document.getElementById('rellys0'))  
  p = document.getElementById('rellys0')
  if (isNetscape) {
    p.style.visibility = "hidden";
    p.style.position   = "absolute";
    };
//alert("here - 413");
}

function takeYear(theDate)  {
  x = theDate.getYear();
  var y = x % 100;
  y += (y < 38) ? 2000 : 1900;
  return y;
}

//-----------------------------------------------------------------------------
// convert calendar to Julian date
// (Julian day number algorithm adopted from Press et al.)
//-----------------------------------------------------------------------------
function cal_to_jd( y, m, d, h, mn, s )
{
	var jy, ja, jm;			//scratch

	if( y == 0 ) {
		alert("There is no year 0 in the Julian system!");
        return "invalid";
    }
    if( y == 1582 && m == 10 && d > 4 && d < 15 ) {
		alert("The dates 5 through 14 October, 1582, do not exist in the Gregorian system!");
        return "invalid";
    }

//	if( y < 0 )  ++y;
//  if( era == "BCE" ) y = -y + 1;
	if( m > 2 ) {
		jy = y;
		jm = m + 1;
	} else {
		jy = y - 1;
		jm = m + 13;
	}

	var intgr = Math.floor( Math.floor(365.25*jy) + Math.floor(30.6001*jm) + d + 1720995 );

	//check for switch to Gregorian calendar
    var gregcal = 15 + 31*( 10 + 12*1582 );
	if( d + 31*(m + 12*y) >= gregcal ) {
		ja = Math.floor(0.01*jy);
		intgr += 2 - ja + Math.floor(0.25*ja);
	}

	//correct for half-day offset
	var dayfrac = h/24.0 - 0.5;
	if( dayfrac < 0.0 ) {
		dayfrac += 1.0;
		--intgr;
	}

	//now set the fraction of a day
	var frac = dayfrac + (mn + s/60.0)/60.0/24.0;

    //round to nearest second
    var jd0 = (intgr + frac)*100000;
    var jd  = Math.floor(jd0);
    if( jd0 - jd > 0.5 ) ++jd;
    return jd/100000;
}

function dodcalc() {
  mnth = document.dodform.month.selectedIndex;
  month = document.dodform.month.options[mnth].value;
  dy  = document.dodform.day.selectedIndex;
  day = document.dodform.day.options[dy].value;
  year = document.dodform.year.value;
  var monthLength = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
  var weekday = new Array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
  var err = "";
  if (month == "") {err = "Please select a month.\n"}
  if (day == "")   {err = err + "Please select a day.\n"}
  if (year == 19)  {err = err + "Please enter a year.\n"}
  if (year <= 14) {year = 2000 + year*1}
  if (year <= 99) {year = 1900 + year*1}
  if (year/4 == parseInt(year/4)) {monthLength[2] = 29}
  if (day > monthLength[mnth]) {err = err + "Please enter correct day of month.\n"}
  if (err != "") {document.dodform.dayofweek.value = ""; err += "\n"; alert(err); return;}
  var jd = cal_to_jd( year, mnth, dy, 12, 0, 0 );
  //weekday
  var t  = parseFloat(jd) + 0.5;
  var wd = Math.floor( (t/7 - Math.floor(t/7))*7 + 0.000000000317 );   //add 0.01 sec for truncation error correction
  var dob = weekday[wd] + ", " + month + " " + day + ", " + year + ".";
  document.dodform.dayofweek.value = dob;

  return;
}

function today() {
	var months=new Array(13);
	months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="December";
	var time   = new Date();
	var lmonth = months[time.getMonth() + 1];
	var date   = time.getDate();
    var year   = time.getYear();  if (year < 1900) {year = year*1 + 1900};
	document.write(lmonth + " " + date + ", " + year);
	}

var pleft = 10; var ptop = 180;             // Position for IE MAC
//  pleft = 10; var ptop = 125;             // Position for NETSCAPE MAC

function testpos() {
//alert(document.getElementById("testmsg"));
  var msg = "<p style='font-size:x-small'>App = " + navigator.appName + "<br>Version = " + navigator.appVersion + "<br>Agent = " + navigator.userAgent;
  msg += "<br>Position left = " + pleft + "  Position top = " + ptop;
  msg += "<br>browserVersion = " + browserVersion;
  msg += "<br>isNetscape = " + isNetscape + "  isIE = " + isIE + "<br>isWindows = " + isWindows + "  isMac = " + isMac + "  isUnix = " + isUnix + "</p>";
  document.getElementById("testmsg").innerHTML = msg;
  document.getElementById("bpos").style.left = pleft + "px";
  document.getElementById("bpos").style.top  = ptop  + "px";
  document.getElementById("tpos").style.visibility = "visible";
  document.getElementById("bpos").style.visibility = "visible";

//alert("Browser = " + navigator.appName + "  Agent = " + navigator.userAgent + "\n" + "  isIE = " + isIE  + "  isOpera = " + isOpera);
//alert("Browser = " + navigator.appName + "  Agent = " + navigator.userAgent + "\n" + "  isIE = " + isIE  + "  isOpera = " + isOpera + "\n" + "Position left = " + pleft + "  Position top = " + ptop);
  return;
}

function clearpos() {
  document.getElementById("tpos").style.visibility = "hidden";
  document.getElementById("bpos").style.visibility = "hidden";
  return;
}

function enterpos() {
  ptop = window.prompt("Enter Top position:", "0");
  if (ptop == null) {ptop = 0; return;}
  pleft = window.prompt("Enter Left position:", "0");
  if (pleft == null) {pleft = 0; return;}
  testpos();
  return;
}

function setpos() {
  if (isOpera)    {pleft = 25;  ptop = 125}           //Opera
  if (isNetscape) {pleft = 25;  ptop = 115}           //Netscape
  if (isIE)       {pleft = 25;  ptop = 125}           //IE
//testpos();
  document.getElementById("menue").style.left = pleft + "px";
  document.getElementById("menue").style.top  = ptop  + "px";
//alert("Browser = " + navigator.appName + "  Agent = " + navigator.userAgent + "\n" + "  isIE = " + isIE  + "  isOpera = " + isOpera + "\n" + "Position left = " + pleft + "  Position top = " + ptop);
  return;
}
// Copyright 2003-2004 © by David D Sadler. All Rights Reserved.