var t;
var len;
var len2;
var wildcard;
var lenSrch;
var lenSrch2;
var strSrch;
var strSrch2;
var strSearch;
var strSearch2;
var strSndSurname;
var lenCont0;
var lenCont1;
var strSearchCont0;
var strSearchCont1;
var xmlhttp=null;
var results=false;
var w=window;
var h=history;
var d=document;
var strErrMsg='Your internet browser is unable to search this database. Suitable browsers include recent versions of Internet Explorer, Firefox and Safari.';
function dtaLoad(){
  if(w.ActiveXObject){
    try{
      xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch(e){
      try{
        xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
      }
      catch(e){
        xmlhttp=false;
        alert(strErrMsg);
        if(w.h.length)w.h.back();
        return;
      }
    }
  }
  else if(w.XMLHttpRequest){
    try{
      xmlhttp=new XMLHttpRequest();
      xmlhttp.overrideMimeType('text/xml');
    }
    catch(e){
      xmlhttp=false;
      alert(strErrMsg);
      if(w.h.length)w.h.back();
      return;
    }
  }
  else{
    alert(strErrMsg);
    if(w.h.length)w.h.back();
    return;
  }
  if(xmlhttp){
    xmlhttp.open('GET','tblm.xml',true);
    xmlhttp.send(null);
    d.getElementById('strQuery').value="";
    d.getElementById('strQuery2').value="";
    d.getElementById('btnGo').disabled=false;
    d.getElementById('strQuery').focus();
  }
  else{
    alert(strErrMsg);
    if(w.h.length)w.h.back();
    return;
  }
}
function findQuery(){
  d.getElementById('btnGo').disabled='disabled';
  lenSrch=d.getElementById('strQuery').value.length;
  if(lenSrch>28)lenSrch=28;
  lenSrch2=d.getElementById('strQuery2').value.length;
  if(lenSrch2>24)lenSrch2=24;
  strSrch=d.getElementById('strQuery').value.toUpperCase();
  strSrch2=d.getElementById('strQuery2').value.toLowerCase();
  len=0;
  lenCont0=0;
  lenCont1=0;
  len2=0;
  strSearch="";
  strSearchCont0="";
  strSearchCont1="";
  strSearch2="";
  wildcard=0;
  for(var i=0;i<lenSrch;i++){
    if((strSrch.charAt(i)>='A' && strSrch.charAt(i)<='Z') || strSrch.charAt(i)=="'" || strSrch.charAt(i)=="-" || strSrch.charAt(i)==" " || strSrch.charAt(i)=="*"){
      strSearch+=strSrch.charAt(i);
      len++;
    }
  }
  for(var i=0;i<len;i++){
    switch (wildcard){
      case 0:
        if(strSearch.charAt(i)=="*")break;
        strSearchCont0+=strSearch.charAt(i);
        lenCont0++;
        break;
      case 1:
        if(strSearch.charAt(i)=="*")break;
        strSearchCont1+=strSearch.charAt(i);
        lenCont1++;
        break;
      default:
        if(strSearch.charAt(i)=="*")break;
        strSearchCont1+=strSearch.charAt(i);
        lenCont1++;
        break;
    }
    if(strSearch.charAt(i)=="*")wildcard++;
  }
  len=lenCont0+lenCont1;
  for(var i=0; i<lenSrch2; i++){
    if((strSrch2.charAt(i)>='a' && strSrch2.charAt(i)<='z') || strSrch2.charAt(i)==" " || strSrch2.charAt(i)=="-" || strSrch2.charAt(i)=="'"){
      strSearch2+=strSrch2.charAt(i);
      len2++;
    }
  }
  if(len<2){
    d.getElementById('strResult').innerHTML="<table border='0' cellspacing='0'><tr><th class='error'>Data Entry Error</th></tr><tr><td class='error'>Fill in the <b>surname</b> box with at least 2 characters of the name to be found. A given name is optional. If only initials are known, enter the 1st initial only.<br />";
    d.getElementById('btnGo').disabled=false;
    d.getElementById('strQuery').focus();
    return;
  }
  else{
    d.getElementById('htmlProgress').innerHTML='Downloading the index ...';
    if(d.getElementById('blnSound').checked) strSearch=calculateSound(strSearch);
    xmlhttp.onreadystatechange=checkReadyState;
    if(xmlhttp.readyState==4 && xmlhttp.status=='200'){
      d.getElementById('htmlProgress').innerHTML='Searching ...';
      if(t)w.clearTimeout(t);
      t=w.setTimeout('runSearch()',200);
    }
  }
}
function checkReadyState(){
  if(xmlhttp.readyState==4 && xmlhttp.status=='200'){
    d.getElementById('htmlProgress').innerHTML='Searching ...';
    if(t)w.clearTimeout(t);
    t=w.setTimeout('runSearch()',200);
  }
  else if(xmlhttp.readyState==4 && xmlhttp.status !='200'){
    alert('An error occurred while loading the index');
    if(w.h.length)w.h.back();
    return;
  }
}
function runSearch(){
  var count=0;
  var strName="";
  var strName2="";
  var strNameW="";
  var strNameW2="";
  var strArray=new Array();
  var strPrint="";
  var marDoc=xmlhttp.responseXML;
  var sList=marDoc.getElementsByTagName('s');
  var gList=marDoc.getElementsByTagName('g');
  var wsList=marDoc.getElementsByTagName('w');
  var wgList=marDoc.getElementsByTagName('c');
  var dList=marDoc.getElementsByTagName('d');
  var aList=marDoc.getElementsByTagName('a');
  var waList=marDoc.getElementsByTagName('b');
  var pList=marDoc.getElementsByTagName('p');
  var listLen=sList.length;
  var s=d.getElementById('blnSortAlpha').checked;
  var intSrchType;
  if(d.getElementById('blnWildcards').checked)intSrchType=0;
  else if(d.getElementById('blnExact').checked)intSrchType=1;
  else if(d.getElementById('blnSound').checked)intSrchType=2;
  var i=0;
  while(i<listLen){
    strName=sList[i].firstChild.nodeValue;
    strName2=gList[i].firstChild.nodeValue.toLowerCase();
    strNameW=wsList[i].firstChild.nodeValue;
    strNameW2=wgList[i].firstChild.nodeValue.toLowerCase();
    var j=0;
    while(strName.charAt(j) !=' ' && strName.charAt(j) != '/' && strName.charAt(j))j++;
    var k=0;
    while(strNameW.charAt(k) !=' ' && strNameW.charAt(k) !='/' && strNameW.charAt(k))k++;
    if(intSrchType==2){
      strName=calculateSound(strName.substr(0,j));
      strNameW=calculateSound(strNameW.substr(0,k));
    }
    else if(intSrchType==1){
      strName=strName.substr(0,j);
      strNameW=strNameW.substr(0,k);
    }
    if(!wildcard){
      if(j>k)lenCont0=j;
      else lenCont0=k;
    }
    var m=strName.indexOf(strSearchCont0);
    var mW=strNameW.indexOf(strSearchCont0);
    if((((!intSrchType && m>=0 && strName.indexOf(strSearchCont1,m+lenCont0-1)>=0) || (intSrchType==1 && strName.substr(0,lenCont0)==strSearchCont0 && strName.substr(j-lenCont1,lenCont1)==strSearchCont1) || (intSrchType==2 && strName==strSearch)) && (len2==0 || (len2>1 && strName2.indexOf(strSearch2)>=0) || (len2==1 && strName2.charAt(0)==strSearch2.charAt(0)))) || (((!intSrchType && mW>=0 && strNameW.indexOf(strSearchCont1,mW+lenCont0-1)>=0) || (intSrchType==1 && strNameW.substr(0,lenCont0)==strSearchCont0 && strNameW.substr(k-lenCont1,lenCont1)==strSearchCont1) || (intSrchType==2 && strNameW==strSearch)) && (len2==0 || (len2>1 && strNameW2.indexOf(strSearch2)>=0) || (len2==1 && strNameW2.charAt(0)==strSearch2.charAt(0))))){
      if(s){
        strArray[count]=sList[i].firstChild.nodeValue+" "+gList[i].firstChild.nodeValue;
        if(aList[i].firstChild.nodeValue!='-'){
          if(aList[i].firstChild.nodeValue!='a')strArray[count]+=", "+aList[i].firstChild.nodeValue+",";
          else strArray[count]+=", adult,";}
        strArray[count]+=" married "+wsList[i].firstChild.nodeValue+" "+ wgList[i].firstChild.nodeValue;
        if(waList[i].firstChild.nodeValue!='-'){
          if(waList[i].firstChild.nodeValue!='a')strArray[count]+=", "+waList[i].firstChild.nodeValue+",";
          else strArray[count]+=", adult,";}
        strArray[count]+=" on "+dList[i].firstChild.nodeValue;
        if(pList[i].firstChild.nodeValue!='-')strArray[count]+=" at "+pList[i].firstChild.nodeValue;
        strArray[count]+="<br />";
      }
      else{
        strArray[count]=dList[i].firstChild.nodeValue+" marriage of "+sList[i].firstChild.nodeValue+" "+gList[i].firstChild.nodeValue+" and "+wsList[i].firstChild.nodeValue+" "+ wgList[i].firstChild.nodeValue;
        if(pList[i].firstChild.nodeValue!='-')strArray[count]+=" at "+pList[i].firstChild.nodeValue;
        strArray[count]+="<br />";
      }
      count++;
    }
    i++;
  }
  if(count){
    strArray.sort();
    strPrint='<h3 class="results">Search results <span style="font-size:13px; font-weight:normal;">(total of '+count+')</span></h3>';
    for(var i=0;i<count;i++)strPrint+=strArray[i];
    strPrint+="<br />";
    d.getElementById('strResult').innerHTML=strPrint;
    d.getElementById('htmlProgress').innerHTML='View the results below...';
    results=true;
  }
  else{
    d.getElementById('strResult').innerHTML="<h3 class='results'>Search results <span style='font-size:13px; font-weight:normal;'>(total of 0)</span></h3><p>The data you entered, <b><i>"+d.getElementById('strQuery').value+" "+d.getElementById('strQuery2').value+"</i></b>, is not in this database.</p>";
    d.getElementById('htmlProgress').innerHTML='There are no results to view.';
    results=false;
  }
  if(!d.getElementById('strQuery').disabled)d.getElementById('strQuery').focus();
  d.getElementById('btnGo').disabled=false;
}
function calculateSound(strString){
  var strModSound="";
  var strSound="";
  var intStrLen=strString.length;
  for(var i=0;i<intStrLen;i++){
    var strChar=strString.charAt(i);
    if(strChar=='P' || strChar=='F' || strChar=='V')strSound +='1';
    else if(strChar=='B'){
      if(strString.substr(intStrLen-2,2)!='MB' && strString.substr(intStrLen-3,3)!='MBE' && strString.substr(intStrLen-4,4)!='MBES' && strString.substr(intStrLen-3,3)!='MBS')strSound +='1';
    }
    else if(strChar=='C' || strChar=='S' || strChar=='K' || (strChar=='G' && i != intStrLen-1 && (!(i==intStrLen-2 && strString.charAt(intStrLen-1)=='N'))) || strChar=='J' || strChar=='Q' || strChar=='X' || strChar=='Z') strSound +='2';
    else if(strChar=='D' || strChar=='T')strSound +='3';
    else if(strChar=='L') strSound +='4';
    else if(strChar=='M' || strChar=='N'){
      if(i==1 && strChar=='N' && (strString.charAt(0)=='G' || strString.charAt(0)=='K' || strString.charAt(0)=='P'))strSound='5';
      else strSound +='5';
      if(i==0 && strString.charAt(1)=='C' && strChar=='M')strSound+='0';
    }
    else if(strChar=='R')strSound +='6';
    else if(strChar=='H'){
      if(i>1 && strString.charAt(i-1)=='G' && (strString.charAt(i-2)=='A' || strString.charAt(i-2)=='I' || strString.charAt(i-2)=='O' || strString.charAt(i-2)=='U')){
        strSound=strSound.substring(0,strSound.length-1);
      }
    }
    else if(strChar=='W' || strChar=='Y'){
      if(i==0 && ((strChar=='W' && strString.charAt(1)!='R') || strChar=='Y')) strSound +='9';
      else if(strChar=='Y')strSound +='0';
    }
    else if(((strChar=='A' || strChar=='I' || strChar=='O') && (i>0 || (i==0 && strString.charAt(1)!="'"))) || (i != intStrLen-1 && strChar=='E') || strChar=='I' || strChar=='U')strSound +='0';
  }
  strModSound=strSound.charAt(0);
  strSoundLen=strSound.length;
  for(i=1;i<strSoundLen;i++){
    if(strSound.charAt(i)!=strSound.charAt(i-1))strModSound+=strSound.charAt(i);
  }
  return strModSound;
}
function clearForm(){
  d.getElementById('htmlProgress').innerHTML="";
  d.getElementById('strResult').innerHTML="";
}
function displayHelp(){
  var htmlResults="";
  if(results) htmlResults=d.getElementById('strResult').innerHTML;
  else htmlResults="";
  d.getElementById('strResult').innerHTML="<h3 class='results'><p>Using the marriage database</h3>Enter either the husband's name or the wife's maiden name or former married name into the boxes.<br />A given name is optional. If only given name initials are known, enter the first initial only or leave the given name box blank.<br />Click the [ <b>Go</b> ] button to begin the search.</p><h4>Text entry</h4><p>At least 2 allowed characters must be entered into the surname box before a search can proceed.<br />A given name is optional. If only given name initials are known, enter the first initial only or leave the given name box blank.<br />The search is not case sensitive.<br />The only characters allowed are letters of the alphabet, hyphens, spaces, apostrophes and no more than one <b>*</b> wildcard. Any other entered characters are ignored. In particular, the ? wildcard and the logical operators (and, or, not, &, |, &lt;, >, +, -) cannot be used.</p><h4>Searching for a name</h4><p>The default (and generally most satisfactory) method of searching for a name is the <b>containing</b> method. Select [containing] by clicking it, if necessary. Then enter into the surname box, sufficient letters to define the name to be found. Optionally, enter a given name or the first initial. Click the [ <b>Go</b> ] button or press the [Enter] key to begin the search. If the name you wish to find is not in the database, take into account possible spelling variations, as the people and the officials recording their information were often illiterate or semiliterate.<br />It is advisable to omit surname prefixes such as O' and Mac so that the usual variations of spelling these names are all found. <br />The search behaves as though you have entered a * wildcard at each end of your search text. That is, the search engine looks for the exact text you have entered anywhere within the name. For example, if you search for <b>hill</b>, several different names will be found, including <b>hill</b>, <b>hill</b>man, up<b>hill</b> and p<b>hill</b>ips, amongst others. This feature has the annoyance of giving some unwanted names but can be very useful. For example, searching for <b>phil</b> will give philp, philip and phillips, amongst others. This allows you to take into account some likely mis-spellings or variations of the name of interest. If required, one <b>*</b> wildcard can be added within the text to replace zero or more unknown or doubtful characters. For example, searching for r<b>e*</b>d will give r<b>ea</b>d, r<b>ee</b>d and r<b>ei</b>d. Searching for sm<b>*</b>th will give sm<b>i</b>th, sm<b>y</b>th and sm<b>y</b>the, amongst others.<br />The [Clear] button clears both boxes and places the cursor in the left hand box, ready for your next search. It also clears any displayed results.</p><h4>Searching for names using exact matching</h4><p>If you only wish to find surnames with exactly the same spelling as you have entered, select [Exact] by clicking it, if necessary. Note, however, that the database contains spelling variants separated by slashes for some names. With exact matching, only the first variant is compared with your entered text. Also, in the case of formerly married women, no comparison is made with their maiden name. In these cases, the method may not be satisfactory. If required, one * wildcard can be added in any position to replace zero or more unknown or doubtful characters. Exact matching of given names is not available. Any entered given name will be matched by the containing method.</p><h4>Searching for names using sound matching</h4><p>If the above techniques fail, as a last resort you may wish to try the sound method of matching. This will allow you to find more variations of spelling and also take into account the pronunciation of the surname. For example, searching on the name <b>smith</b> will find the names smith, smyth, smythe and schmidt. The method used here is a heavily modified version of Soundex code matching which doesn't require the 1st letter of the name to be known and takes into account such pronunciation variations as dropped h's and g's. You must be prepared to scan the results and reject those which are poor matches. For some shorter names, ones with mainly vowels, and names containing spaces, all the results may be unsatisfactory.<br />To use sound matching, select [Sound] before clicking [ <b>Go</b> ] or pressing [Enter]. You <b>must enter the full surname</b> required. <b>Wildcards are not permitted</b>. Sound matching of given names is not available. Any entered given name will be matched by the containing method.</p>"+htmlResults;
  if(!d.getElementById('strQuery').disabled)d.getElementById('strQuery').focus();
}// Copyright(c)2003-2010 B Leadbeater, Australia