var Debug = "on";
var path = "";
// var path = "/bova-genealogy/";

var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365 * 5 )); // 5 years from now

//var SrcInd = new Array(
//    "id","Surname","given","Birth","Death","Spouse","Father","Mother","DOL","DOS"
//    );
//  var value = SrcInd[0];
//  for (c=1;c<SrcInd.length;c++){
//    value = value + "`";
//    value = value + SrcInd[c];
//   }
//  SetCookie('bwc',value,expdate,path);

//    1,"Bova","Richard","04/02/1924","07/26/1978",2,3,4,"08/01/02",0,
//    2,"O'Keefe","Emily","09/06/1929","05/16/1995",1,0,0,"08/01/02","08/22/02",
//    3,"Bova","Michael","?","?",4,0,0,"08/01/02",0,
//    4,"McNamara","Josephine Brigit","?","?",3,0,0,"08/01/02",0
// SrcIndCols = 10;
//  if (SrcInd.length % SrcIndCols) {
//    document.write(
//      "Error in Source Index Array." +
//      " SrcInd length = " + SrcInd.length +
//      " SrcIndCols = " + SrcIndCols +
//      " remainder = " + (SrcInd.length % SrcIndCols) +
//     "<BR>");
//   }


function BWDelete(s){
//
// Brick Wall Delete
//
  var bwc = GetCookie('bwc');
  bw = bwc.split("`");
  if (Debug == "on") {alert("Doing Brick Wall Delete "+ s +" " + bw[s+1] + ", " + bw[s + 2]);}
  var value = bw[0];
  for (c=1;c<s;c++){
    value = value + "`";
    value = value + bw[c];
    }
  for (c= s+BWCols;c<bw.length;c++){
    value = value + "`";
    value = value + bw[c];
    }
  SetCookie('bwc',value,expdate,path);
  }

function BWMark(s){
//
// Brick Wall Mark
//
  var bwc = GetCookie('bwc');
  bw = bwc.split("`");
  if (Debug == "on") {alert("Doing Brick Wall Mark "+ s +" " + bw[s+1] + ", " + bw[s + 2]);}
  var today = new Date ();
  FixCookieDate (today); // Correct for Mac date bug - call only once for given Date object!
  yearval = today.getYear();
  if (yearval < 1900) { yearval = yearval + 1900;}
  monthval = today.getMonth();
  monthval = monthval + 1;
  today = "" + monthval + "/" + today.getDate() + "/" + yearval;
  bw[s + 9] = today;
  var value = bw[0];
  for (c=1;c<bw.length;c++){
    value = value + "`";
    value = value + bw[c];
    }
  SetCookie('bwc',value,expdate,path);

  }

function BWDelAll(){
//
// Brick Wall Delete All
//
  alert("Are you sure you want to do this? This will delete all entries in the Brick Wall list. It is only to be used if the list is corrupted and you want to start over from scratch as oppose to trying to fix the individual entries. Before doing this function you want to print the Brick Wall list.");
  BWCols = 10;
  var value = "id";
  var bw = new Array(
    "id","Surname","given","Birth","Death","Spouse","Father","Mother","DOL","DOS"
    );
  for (c=1;c<BWCols;c++){
    value = value + "`";
    value = value + bw[c];
    }
  SetCookie('bwc',value,expdate,path);
  }

function BWAdd(){
//
// Brick Wall Add
//
  AddId = bw.length;
  }

function BWUpd(id,surname,given,dob,dobd,spouse,father,mother){
//
// Brick Wall Update
//
  AddId = id;
  document.add.surname.value = surname;
  document.add.given.value = given;
  document.add.dob.value = dob;
  document.add.dod.value = dod;
  document.add.spouse.value = spouse;
  document.add.father.value = father;
  document.add.mother.value = mother;
  }

function BWAU(surname,given,dob,dod,spouse,father,mother){
//
// Brick Wall Add or Update
//
  if (Debug == "on") {alert("Add to " + AddId + ". length= " +
    bw.length + " " +
    surname + " "+
    given + " " +
    dob + " " +
    dod + " " +
    spouse + " " +
    father + " " +
    mother + " "
    );}
  bw[AddId] = (AddId)/BWCols;
  bw[AddId + 1] = surname;
  bw[AddId + 2] = given;
  bw[AddId + 3] = dob;
  bw[AddId + 4] = dod;
  bw[AddId + 5] = spouse;
  bw[AddId + 6] = father;
  bw[AddId + 7] = mother;
  var today = new Date ();
  FixCookieDate (today); // Correct for Mac date bug - call only once for given Date object!
  yearval = today.getYear();
  if (yearval < 1900) { yearval = yearval + 1900;}
  monthval = today.getMonth();
  monthval = monthval + 1;
  today = "" + monthval + "/" + today.getDate() + "/" + yearval;
  bw[AddId + 8] = today;
  bw[AddId + 9] = 0;
  var value = bw[0];
  for (c=1;c<bw.length;c++){
    value = value + "`";
    value = value + bw[c];
    }
  SetCookie('bwc',value,expdate,path);
  }

function BWList(){
//
// Brick Wall List
//
//  document.write("Doing Brick Wall List<BR>");
  var bwc = GetCookie('bwc');
  bw = bwc.split("`");
  BWCols = 10;
  if (Debug == "on") {alert("doing BW List length = " + bw.length + "entries = " + bw.length/BWCols + "bwc = " + bwc);}
  document.write("<CENTER><TABLE BORDER=1 CELLSPACING=1 CELLPADDING=2 width=1200>");
  document.write("<TR>");
  document.write(
    "<TD><b>Surname</B></TD>" +
    "<TD><b>Given</B></TD>" +
    "<TD><b>DOB</B></TD>" +
    "<TD><b>DOD</B></TD>" +
    "<TD><b>Spouse</B></TD>" +
    "<TD><b>Father</B></TD>" +
    "<TD><b>Mother</B></TD>" +
    "<TD><b>Last Upd</B></TD>" +
    "<TD><b>Last Srch</B></TD>" +
    "<TD>&nbsp</td>"
    );
  document.write("</TR>");
  done = 0;
//  while (done = 0) {
  for (s = BWCols; s < bw.length; s++) {
    document.write("<TR>");
    url='genebwu.htm';
    document.write("<TD><A NAME='gs" + bw[s] + "'> </a><a href=javascript:AddId = "+ s + ");window.top=open(url)'>" + bw[(s+1)] + "</A></TD>");
    //    document.write("<TD><A NAME='gs" + bw[s] + "'> </A><a href='javascript:AddId=" + bw[s] + ";window.top=open(url)'>" + bw[(s + 1)] + "</A></TD>");
    document.write("<td>" + bw[(s + 2)] + "</td>");
    document.write("<td>" + bw[(s + 3)] + "</TD>");
    document.write("<td>" + bw[(s + 4)] + "</TD>");
    document.write("<td>" + bw[(s + 5)] + "</TD>");
    document.write("<td>" + bw[(s + 6)] + "</TD>");
    document.write("<td>" + bw[(s + 7)] + "</TD>");
//  document.write("<td>");
//    if (eval(bw[s+5])) {document.write("<a href='#gs" + bw[s+5] + "'>" + bw[bw[s+5] * BWCols + 1] + ",&nbsp;" + bw[bw[s+5] * BWCols + 2] + "</A>");}
//    else {document.write("&nbsp;");}
//    document.write("</td>");
//    document.write("<td>");
//    if (eval(bw[s+6])) {document.write("<a href='#gs" + bw[s+6] + "'>" + bw[bw[s+6] * BWCols + 1] + ",&nbsp;" + bw[bw[s+6] * BWCols + 2]+ "</A>");}
//    else {document.write("&nbsp;");}
//    document.write("</td>");
//    document.write("<td>");
//    if (eval(bw[s+7])) {document.write("<a href='#gs" + bw[s+7] + "'>" + bw[bw[s+7] * BWCols + 1] +  ",&nbsp;" + bw[bw[s+7] * BWCols + 2] + "</A>");}
//    else {document.write("&nbsp;");}
//    document.write("</td>");
    document.write("<td>" + bw[(s + 8)] + "</TD>");
    document.write("<td>" + bw[(s + 9)] + "</TD>");
    document.write("<TD><table>"  +
      "<td><form action='http://resources.rootsweb.com/cgi-bin/metasearch/metasearch' method=post TARGET='bfg_off'>" +
      "<INPUT TYPE=hidden NAME='given' value='" + bw[s+2] + "'> " +
      "<input type=hidden name='surname' value='" + bw[s+1] + "'>" +
      "<input type=hidden name='type' value='surname'>" +
      "<input type=submit name=submit value='Search'>" +
      "</form></td>" +
      "&nbsp;&nbsp;" +
      "<td><form action='javascript:BWDelete(" + s + ")' method=post><input type=submit name=submit value='Delete'></form></td>" +
      "&nbsp;&nbsp;" +
      "<td><form action='javascript:BWMark(" + s + ")' method=post><input type=submit name=submit value='Mark'></form></td></table>" +
      "</td>"
      );
    document.write("</TR>");
    s = s + BWCols -1;
    }
  document.write("</TABLE></CENTER>");
//  document.write("end of Brick Wall List");
  }