/* (c) Sam Gratrix */


// The Birth, Baptism, Marriage and Death classes have similar code, so often Cert will be uses as a generic
// reference to these four classes, mainly to aid diffing. Yes, I could be more clever about code reuse, but
// I think given the suble differences that crop up, diffing will do for now.


// ===========================================================================================================
// CertEntry and CertLook used to map a persons id to an entry in the CertSet and CertGroup. This is so that
// we can look up other people mentioned in the certificate.

function MarriageEntry(id, group, type)
{
	this.id    = id;
	this.group = group;
	this.type  = type;
}


// -----------------------------------------------------------------------------------------------------------

MarriageEntry.prototype.debug = function()
{
	return 'MarriageEntry: id = ' + this.id + ', group = ' + this.group + ', type = ' + this.type + '. ';
}


// ===========================================================================================================
// CertSet - Collection of Certs objects. Access functions take a person id and automatically do a lookup for
// the actual cert. Assumes that each person can only exist in the cert set once. Each entry in the group
// is an array so that mutiple Certs can be attributed to a persons id.

function MarriageSet()
{
	this.group_length = 0;
	this.group        = new Array();

	this.look_length  = 0;
	this.look         = new Array();

	for(var i=0; i<arguments.length; i++)
	{
		if(typeof(arguments[i]) != 'undefined')
		{
			this.add(arguments[i]);
		}
	}
}


// -----------------------------------------------------------------------------------------------------------

MarriageSet.prototype.add = function(cert)
{
	// If a new id is enountered, then make a new group.

	if(typeof(this.group[cert.id]) == 'undefined')
	{
		this.group[cert.id] = new Array();

		this.group_length++;
	}

	// Add the object to the appropiate group.

	var g = this.group[cert.id].push(cert) - 1;

	// Now create lookup information for fast querying.

	var people = cert.people;
	var solem  = cert.solem;

//	if(people == '') return;

	if(people.row1.myid != '')  // groom
	{
		if(typeof(this.look[people.row1.myid]) == 'undefined')
		{
			this.look[people.row1.myid] = new Array();

			this.look_length++;
		}

		this.look[people.row1.myid].push(new MarriageEntry(cert.id, g, 0));
	}

	if(people.row2.myid != '')  // bride
	{
		if(typeof(this.look[people.row2.myid]) == 'undefined')
		{
			this.look[people.row2.myid] = new Array();

			this.look_length++;
		}

		this.look[people.row2.myid].push(new MarriageEntry(cert.id, g, 2));
	}

	if(!cert.full) return;

	if(people.row1.dadid != '')  // grooms father
	{
		if(typeof(this.look[people.row1.dadid]) == 'undefined')
		{
			this.look[people.row1.dadid] = new Array();

			this.look_length++;
		}

		this.look[people.row1.dadid].push(new MarriageEntry(cert.id, g, 1));
	}

	if(people.row2.dadid != '') // brides father
	{
		if(typeof(this.look[people.row2.dadid]) == 'undefined')
		{
			this.look[people.row2.dadid] = new Array();

			this.look_length++;
		}

		this.look[people.row2.dadid].push(new MarriageEntry(cert.id, g, 3));
	}

	if(solem.p1_id != '') // presence 1
	{
		if(typeof(this.look[solem.p1_id]) == 'undefined')
		{
			this.look[solem.p1_id] = new Array();

			this.look_length++;
		}

		this.look[solem.p1_id].push(new MarriageEntry(cert.id, g, 4));
	}

	if(solem.p2_id != '') // presence 2
	{
		if(typeof(this.look[solem.p2_id]) == 'undefined')
		{
			this.look[solem.p2_id] = new Array();

			this.look_length++;
		}

		this.look[solem.p2_id].push(new MarriageEntry(cert.id, g, 5));
	}

	if(solem.p3_id != '') // presence 3
	{
		if(typeof(this.look[solem.p3_id]) == 'undefined')
		{
			this.look[solem.p3_id] = new Array();

			this.look_length++;
		}

		this.look[solem.p3_id].push(new MarriageEntry(cert.id, g, 6));
	}
}


// -----------------------------------------------------------------------------------------------------------
// For index only inforamtion. This is a shead load of index info, so we construct the Cert here rahter than
// as inline code to save on download. This is a "synthetic certifficate" in that it is automatically
// generated from index information. Conseqently it looks a bit back to front!

MarriageSet.prototype.tack = function(id, references)
{
	// If this person is already in the indexes then generate an alert.

	if(this.get(id, 1).length) alert('Marriage index issue for ' + id);

	var rs = new MarriageReferenceSet(references);

	// Deduce some information from the index

	var d = new TDate(0,0,0);
	var w = '';
	var n = '';
	var s = '';
	var spn = '';
	var sps = '';

	for(var i=0; i<rs.refs.length; i++)
	{
		var ref = rs.refs[i];

		if(d.stamp < ref.date.stamp)
		{
			d = ref.date;

			w = d.nice();
			n = ref.firsts;
			s = ref.surname;
			spn = ref.spfirsts;
			sps = ref.spsurname;
		}
	}

	var cert = new Marriage(
		id,
		rs,
		d,
		0,
		new MarriagePeople(
			new MarriageRow('', w,id,  n+' '+  s,'','','','','','','',new Address('','','','','','')),
			new MarriageRow('','','',spn+' '+sps,'','','','','','','',new Address('','','','','',''))),
			0,0,
		'Generated from ' + (rs.refs.length == 1 ? 'the' : rs.refs.length) + ' index reference' + (rs.refs.length == 1 ? '' : 's') + ' so use only as a guide.'
		);

	cert.full = 0;

	this.add(cert);
}


// -----------------------------------------------------------------------------------------------------------
// Returns a filtered and sorted CertLook object which tells you where the person is in the certificates.
// Use .length to determine if there are any results.
//
// To Do: Ordering.

MarriageSet.prototype.get = function(person_id, simple)
{
	var look = this.look[person_id];

	var filter = new Array();

	if(typeof(look) != 'undefined')
	{
		for(var i=0; i<look.length; i++)
		{
			if(simple && look[i].type != 0 && look[i].type != 2)
			{
				continue;
			}

			var add = 1;

			for(var j=0; j<filter.length; j++)
			{
				if( (filter[j].id != look[i].id) || (filter[j].group != look[i].group) )
				{
					continue;
				}

				add = 0;

				break;
			}

			if(add)
			{
				filter.push(look[i]);
			}
		}
	}

	return filter;
}


// -----------------------------------------------------------------------------------------------------------
// Display all the certificates related to the person.
//
// TO DO: Allow passing of filter control.

MarriageSet.prototype.display = function(person_id, simple)
{
	var filter = this.get(person_id, simple);

	var html = '';

	for(var i=0; i<filter.length; i++)
	{
		var entry = filter[i];

		var group = this.group[entry.id];

		var cert  = group[entry.group];

		html += cert.display(person_id);
	}

	delete filter;

	return html;
}


// -----------------------------------------------------------------------------------------------------------
// Get history data for use in the summary lines of the Person display.
//
// TO DO: Allow passing of filter control.

MarriageSet.prototype.history = function(person_id)
{
	var filter = this.get(person_id);

	var histroy = new Array();

	for(var i=0; i<filter.length; i++)
	{
		var entry  = filter[i];

		var cert   = this.group[entry.id][entry.group];

		histroy.push(cert.history(entry.type));
	}

	delete filter;

	return histroy;
}


// -----------------------------------------------------------------------------------------------------------

MarriageSet.prototype.dump = function()
{
	var html = '';

	for(var id in this.group)
	{
		html += this.group[id].display();
	}

	return html;
}


// -----------------------------------------------------------------------------------------------------------

MarriageSet.prototype.report = function()
{
	return(this.group_length);
}


// ===========================================================================================================
// Cert. A regular cert is full, if however, it have been fudged from an index then it's not full.

function Marriage(id, reference, date, location, people, rites, solem, note)
{
	this.id           = id;

	this.full         = 1;
	this.reference    = reference;
	this.date         = date;
	this.location     = location;
	this.people       = people;
	this.rites        = rites;
	this.solem        = solem;
	this.note         = note;

	// Reverse references

	if(this.reference) this.reference.up = this;
	if(this.location ) this.location.up  = this;
	if(this.people   ) this.people.up    = this;
	if(this.rites    ) this.rites.up     = this;
	if(this.solem    ) this.solem.up     = this;
}


// -----------------------------------------------------------------------------------------------------------
// When a cert is displayed we may wish to alter the view given who we are displaying it for. That is, we can
// display a cert choosing to highlight the 'main' person, or any other people such are relations, etc.

Marriage.prototype.display = function(person_id)
{
	var html = '';

	html += '<table border="0" cellspacing="1" cellpadding="0" width="748" class="bor1"><tr><td>';
	html += '<table border="0" cellspacing="0" cellpadding="0" width="100%">';

	html += '<tr><td>' + this.reference.display() + '</td></tr>';

	if(this.full)
	{
		html += '<tr><td>' + this.location.display() + '</td></tr>';
	}

	html += '<tr><td>' + this.people.display(person_id) + '</td></tr>';

	if(this.full)
	{
		html += '<tr><td>' + this.rites.display(person_id) + '</td></tr>';
		html += '<tr><td>' + this.solem.display(person_id) + '</td></tr>';
	}

	var ref_notes = this.reference.notes();

	if(this.note.length || ref_notes.length)
	{
		html += '<tr><td><table border="0" cellspacing="0" cellpadding="0" width="100%" class="certmarriage">';
		html += '<tr><th class="adr6">My Notes</th><td class="adr6" width="100%">' + this.note;

		if(this.note.length && ref_notes.length) html += '<br/>';

		html += ref_notes + '</td></tr></table></td></tr>';
	}

	html += '</table></td></tr></table>';

	return html;
}


// -----------------------------------------------------------------------------------------------------------

Marriage.prototype.history = function(person_type)
{
    // I could add rel detail to the 'of' string (tricky?), but it will be too wide so I won't bother anyway.

	var of = 'Marriage of ' + this.people.row1.ns.split(' ')[0] + ' &amp; ' + this.people.row2.ns.split(' ')[0];

	switch(person_type)
	{
		case 0 : var histroy = new Array(this.date, 'Married',
									   this.people.row1.address.nice(),
									   this.people.row1.ns,
									   this.people.row1.cond,
									   '',
									   this.people.row1.age,
									   0,
									   of,
									   this.people.row1.rp,
									   '<a>'); break;

		case 1 : var histroy = new Array(this.date, 'Son Marr',
									   ' ',
									   this.people.row1.fns,
									   'Father',
									   '',
									   '',
									   0,
									   of,
									   this.people.row1.rpf,
									   '<a>'); break;

		case 2 : var histroy = new Array(this.date, 'Married',
									   this.people.row2.address.nice(),
									   this.people.row2.ns,
									   this.people.row2.cond,
									   '',
									   this.people.row2.age,
									   0,
									   of,
									   this.people.row2.rp,
									   '<a>'); break;

		case 3 : var histroy = new Array(this.date, 'Dau Marr',
									   ' ',
									   this.people.row2.fns,
									   'Father',
									   '',
									   '',
									   0,
									   of,
									   this.people.row2.rpf,
									   '<a>'); break;

		case 4 : var histroy = new Array(this.date, 'Marr Wit', '', this.solem.p1_name, 'Witness', '', '', 0, of, '', '<a>'); break;
		case 5 : var histroy = new Array(this.date, 'Marr Wit', '', this.solem.p2_name, 'Witness', '', '', 0, of, '', '<a>'); break;
		case 6 : var histroy = new Array(this.date, 'Marr Wit', '', this.solem.p3_name, 'Witness', '', '', 0, of, '', '<a>'); break;
	}

	return histroy;
}


// ===========================================================================================================
// CertReferenceGroup - Typically a person can be found in both the local records and the general records.

function MarriageReferenceSet(array)
{
	this.up  = 0;

	this.refs    = array;
	this.country = '';
	this.year    = 0;

    // To do - sort into lro, then gro order.

	// Grab a country and year

	for(var i=0; i<this.refs.length; i++)
	{
		if(this.refs[i].type == 0) // lro
		{
			this.country = this.refs[i].country;
			this.year    = this.refs[i].year;

			if(this.year > 0) return;
		}
	}

	for(var i=0; i<this.refs.length; i++)
	{
		if(this.refs[i].type == 1) // gro
		{
			this.country = this.refs[i].country;
			this.year    = this.refs[i].year;

			if(this.year > 0) return;
		}
	}
}


// -----------------------------------------------------------------------------------------------------------

MarriageReferenceSet.prototype.display = function()
{
	var html = '';

	html += '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="certmarriage"><tr valign="center">';
	html += '<td valign="center" class="adr3x">';
	html += '<img border=0 width=23 height=15 align="absmiddle" src="../images/' + this.country + '.gif" alt="">';
	html += '<b> ' + (this.year > 0 ? this.year + ' ' : '') + (this.up.full ? 'Entry' : 'Index') + ' of Marriage</b></td>';
	html += '<th class="adr5">Source</th><td class="adr3nr" width="100%">';

	for(var i=0; i<this.refs.length; i++)
	{
		if(i) html += '<br>';

		html += (i+1) + '. ' + this.refs[i].display();
	}

	html += '</td>';

	if(this.up.full)
	{
		if(tree_private == 1)
		{
			html += '<td class="adr3"><img onclick="popcertmarriage(\'' + this.up.id + '\')" border="0" width="20" height="16" src="../images/ff_image.gif" title="Open Image"></td>';
		}

		// html += '<td class="adr3"><img onclick="map_search_mark_center(\'' + 0 + '\')" border="0" width="22" height="12" src="../images/os.gif" title="Add To Map"></td>';
	}

	html += '</tr></table>';

	return html;
}

MarriageReferenceSet.prototype.notes = function()
{
	var html = '';

	for(var i=0; i<this.refs.length; i++)
	{
		if(this.refs[i].note.length)
		{
			if(html.length) html += '<br/>';

			html += 'Source ' + (i+1) + '. ' + 	this.refs[i].note;
		}
	}

	return html;
}


// ===========================================================================================================
// CertReference - Not all entries need to be use, whichever are appropriate to the LRO, GRO, etc.

var MarriageReferenceTypes = new Array('LRO', 'GRO');

function MarriageReference(type, source, year, quater, firsts, surname, spfirsts, spsurname, country, office, subdistrict, register, county, district, vol, page, region, ref, note)
{
	this.year        = year;
	this.quater      = quater;

	var q = quater.toLowerCase();
	    q = (q == 'mar' ? '-1' : (q == 'jun' ? '-2' : (q == 'sep' ? '-3' : (q == 'dec' ? '-4' : 0)))) ;
	this.date        = new TDate(parseInt(year), q, 0);

	this.type        = type;
	this.source      = source;
	this.firsts      = firsts;
	this.surname     = surname;
	this.spfirsts    = spfirsts;
	this.spsurname   = spsurname;
	this.country     = country;
	this.office      = office;
	this.subdistrict = subdistrict;
	this.register    = register;
	this.county      = county;
	this.district    = district;
	this.vol         = vol;
	this.page        = page;
	this.region      = region;
	this.ref         = ref;
	this.note        = note;
}


// -----------------------------------------------------------------------------------------------------------

MarriageReference.prototype.display = function()
{
	var html = '';

	if(this.source      != '') html += this.source      + ': ';

    html += MarriageReferenceTypes[this.type] + ' - ';

	if(this.country     != '') html += this.country     + ' - ';
	if(this.quater      != '') html += this.quater      + ' - ';
	if(this.year        != '') html += this.year        + ' - ';
	if(this.firsts      != '') html += this.firsts      + ' - ';
	if(this.surname     != '') html += this.surname     + ' - ';
	if(this.spfirsts    != '') html += this.spfirsts    + ' - ';
	if(this.spsurname   != '') html += this.spsurname   + ' - ';

	html += '<br/>&nbsp;&nbsp;&nbsp;&nbsp;';

	if(this.office      != '') html += this.office      + ' - ';
	if(this.subdistrict != '') html += this.subdistrict + ' - ';
	if(this.register    != '') html += this.register    + ' - ';
	if(this.county      != '') html += this.county      + ' - ';
	if(this.district    != '') html += this.district    + ' - ';
	if(this.vol         != '') html += this.vol         + ' - ';
	if(this.page        != '') html += this.page        + ' - ';
	if(this.region      != '') html += this.region      + ' - ';
	if(this.ref         != '') html += this.ref         + ' - ';

    var l = html.length - 3; if(l < 0) len = 0;

	return html.substr(0, l);
}


// ===========================================================================================================
// CertLocation - This is just the stuff from the boxes at the top of the cert form. It is not really used for
// anything other than display. For the proper address of the person you should really use the Address class.
// For proper cert location data it should be redervied from CertReference. CertLocation is just as it is
// transcribed.

function MarriageLocation(reg, at, in_data, cty_data)
{
	this.up = 0;

	this.reg      = reg;
	this.at       = at;
	this.in_data  = in_data;
	this.cty_data = cty_data;
}


// -----------------------------------------------------------------------------------------------------------

MarriageLocation.prototype.display = function()
{
	var html  = '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="certmarriage"><tr valign="top">';

	html += '<th class="adr3" width="126">Marriage Solemnized at</th><td class="adr3">'+this.at+'</td>';

	if(this.in_data.length == 4)
	{
		html += '<th class="adr5" width="45">'+this.in_data[0]+'</th><td class="adr3">'+this.in_data[1]+'</td>';
		html += '<th class="adr5" width="45">'+this.in_data[2]+'</th><td class="adr3">'+this.in_data[3]+'</td>';
	}
	else
	{
		html += '<th class="adr5" width="93">'+this.in_data[0]+'</th><td class="adr3">'+this.in_data[1]+'</td>';
	}

	html += '<th class="adr5">'+this.cty_data[0]+'</th><td class="adr3">'+this.cty_data[1]+'</td></tr></table>';

	return html;
}


// ===========================================================================================================
// MarriageCol - As written on the certifficate, use for display and information on cert. Final arg is a
// processed vesion of the address.

function MarriageRow(no, wm, myid, ns, age, cond, rp, res, dadid, fns, rpf, address)
{
	this.no      = no;
	this.wm      = wm;
	this.myid    = myid;
	this.ns      = ns;
	this.age     = age;
	this.cond    = cond;
	this.rp      = rp;
	this.res     = res;
	this.dadid   = dadid;
	this.fns     = fns;
	this.rpf     = rpf;
	this.address = address;
}


// ===========================================================================================================
// MarriagePeople - Collects two of the above.

function MarriagePeople(row1, row2)
{
	this.up = 0;

	this.row1  = row1;
	this.row2  = row2;
}


// -----------------------------------------------------------------------------------------------------------

MarriagePeople.prototype.display = function(person_id)
{
	var html  = '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="certmarriage"><tr valign="top">';

	html += '<th>No.</th><th class="adr4">When<br>Married</th>';
	html += '<th class="adr4">Name and<br>Surname</th><th class="adr4">Age</th>';
	html += '<th class="adr4">Condition</th><th class="adr4">Rank or<br>Profession</th>';
	html += '<th class="adr4">Residence at the<br>time of Marriage</th>';
	html += '<th class="adr4">Father\'s Name<br>and Surname</th>';
	html += '<th class="adr4">Rank or Profession<br>of Father</th></tr><tr>';

	var a0 = ''; var a1 = ''; if(person_id == this.row1.myid ) { a0 = '<span class="certmatch">'; a1 = '</span>'; }
	var b0 = ''; var b1 = ''; if(person_id == this.row1.dadid) { b0 = '<span class="certmatch">'; b1 = '</span>'; }
	var c0 = ''; var c1 = ''; if(person_id == this.row2.myid ) { c0 = '<span class="certmatch">'; c1 = '</span>'; }
	var d0 = ''; var d1 = ''; if(person_id == this.row2.dadid) { d0 = '<span class="certmatch">'; d1 = '</span>'; }

	html += '<td rowspan="2">'+this.row1.no+'</td>';
	html += '<td rowspan="2" class="adr4">'+a0+c0+this.row1.wm+c1+a1+'<br>'+a0+c0+this.row2.wm+c1+a1+'</td>';
	html += '<td class="adr4"><a href="#" onclick=\'paste_update("'+this.row1.myid +'");\' title="'+this.row1.myid +'">'+a0+this.row1.ns +a1+'</a></td>';
	html += '<td class="adr4">'+a0+this.row1.age+a1+'</td>';
	html += '<td class="adr4">'+a0+this.row1.cond+a1+'</td>';
	html += '<td class="adr4">'+a0+this.row1.rp+a1+'</td>';
	html += '<td class="adr4">'+a0+this.row1.res+a1+'</td>';
	html += '<td class="adr4"><a href="#" onclick=\'paste_update("'+this.row1.dadid+'");\' title="'+this.row1.dadid+'">'+b0+this.row1.fns+b1+'</a></td>';
	html += '<td class="adr4">'+b0+this.row1.rpf+b1+'</td>';
	html += '</tr><tr>';
	html += '<td class="adr4"><a href="#" onclick=\'paste_update("'+this.row2.myid +'");\' title="'+this.row2.myid +'">'+c0+this.row2.ns +c1+'</a></td>';
	html += '<td class="adr4">'+c0+this.row2.age+c1+'</td>';
	html += '<td class="adr4">'+c0+this.row2.cond+c1+'</td>';
	html += '<td class="adr4">'+c0+this.row2.rp+c1+'</td>';
	html += '<td class="adr4">'+c0+this.row2.res+c1+'</td>';
	html += '<td class="adr4"><a href="#" onclick=\'paste_update("'+this.row2.dadid+'");\' title="'+this.row2.dadid+'">'+d0+this.row2.fns+d1+'</a></td>';
	html += '<td class="adr4">'+d0+this.row2.rpf+d1+'</td>';

	html += '</tr></table>';

	return html;
}


// ===========================================================================================================
// MarriageRites - As written on the certifficate, use for display on cert.

function MarriageRites(key, married, established, after, me, mex)
{
	this.up = 0;

	this.key         = key;
	this.married     = married;
	this.established = established;
	this.after       = after;
	this.me          = me;
	this.mex         = mex;
}


// -----------------------------------------------------------------------------------------------------------

MarriageRites.prototype.display = function(person_id)
{
	var html  = '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="certmarriage"><tr valign="center">';

	html += '<th class="adr8">Marriage<br>in the</th><td class="adr8">'+this.married+'</td>';

	if(this.key==0)
	{
		html += '<th class="adr7" width="203">According to the Rites and Ceremonies<br>of the Established Church, By</th><td class="adr8">'+this.established+'</td>';
		html += '<th class="adr7">Or After</th><td class="adr8">'+this.after+'</td>';
	}
	else if(this.key==1)
	{
		html += '<th class="adr7" width="130">According to the Rites<br>and Ceremoniesm of the</th><td class="adr8">'+this.established+'</td>';
		html += '<th class="adr7">By</th><td class="adr8">'+this.after+'</td>';
	}

	html += '<th class="adr7">By Me</th><td class="adr8">'+this.me+'<br>'+this.mex+'</td></tr></table>';

	return html;
}


// ===========================================================================================================
// MarriageSolem - As written on the certifficate, use for display on cert. Yes, this is a bit naff really.
// b = between, p = presence.

function MarriageSolem(b1_id, b1_name, b2_id, b2_name, p1_id, p1_name, p2_id, p2_name, p3_id, p3_name)
{
	this.up = 0;

	this.b1_id   = b1_id;
	this.b1_name = b1_name;
	this.b2_id   = b2_id;
	this.b2_name = b2_name;
	this.p1_id   = p1_id;
	this.p1_name = p1_name;
	this.p2_id   = p2_id;
	this.p2_name = p2_name;
	this.p3_id   = p3_id;
	this.p3_name = p3_name;
}


// -----------------------------------------------------------------------------------------------------------

MarriageSolem.prototype.display = function(person_id)
{
	var html  = '<table border="0" cellspacing="0" cellpadding="0" width="100%" class="certmarriage"><tr valign="center">';

	if(this.p3_name.length)
	{
		var b10 = ''; var b11 = ''; if(person_id == this.b1_id) { b10 = '<span class="certmatch">'; b11 = '</span>'; }
		var b20 = ''; var b21 = ''; if(person_id == this.b2_id) { b20 = '<span class="certmatch">'; b21 = '</span>'; }
		var p10 = ''; var p11 = ''; if(person_id == this.p1_id) { p10 = '<span class="certmatch">'; p11 = '</span>'; }
		var p20 = ''; var p21 = ''; if(person_id == this.p2_id) { p20 = '<span class="certmatch">'; p21 = '</span>'; }
		var p30 = ''; var p31 = ''; if(person_id == this.p3_id) { p30 = '<span class="certmatch">'; p31 = '</span>'; }

		html += '<th width="25%" rowspan="2">This Marriage was<br>Solemnized Between us</td>';
		html += '<td width="25%"><a href="#" onclick=\'paste_update("'+this.b1_id+'");\' title="'+this.b1_id+'">'+b10+this.b1_name+b11+'</a></td>';
		html += '<th width="25%" class="adr4" rowspan="2">In the<br>Presence of us</td>';
		html += '<td width="25%" rowspan="2"><a href="#" onclick=\'paste_update("'+this.p1_id+'");\' title="'+this.p1_id+'">'+p10+this.p1_name+p11+'</a>';
		html += '<br><a href="#" onclick=\'paste_update("'+this.p2_id+'");\' title="'+this.p2_id+'">'+p20+this.p2_name+p21+'</a>';
		html += '<br><a href="#" onclick=\'paste_update("'+this.p3_id+'");\' title="'+this.p3_id+'">'+p30+this.p3_name+p31+'</a></td></tr><tr>';
		html += '<td><a href="#" onclick=\'paste_update("'+this.b2_id+'");\' title="'+this.b2_id+'">'+b20+this.b2_name+b21+'</a></td>';
	}
	else
	{
		var b10 = ''; var b11 = ''; if(person_id == this.b1_id) { b10 = '<span class="certmatch">'; b11 = '</span>'; }
		var b20 = ''; var b21 = ''; if(person_id == this.b2_id) { b20 = '<span class="certmatch">'; b21 = '</span>'; }
		var p10 = ''; var p11 = ''; if(person_id == this.p1_id) { p10 = '<span class="certmatch">'; p11 = '</span>'; }
		var p20 = ''; var p21 = ''; if(person_id == this.p2_id) { p20 = '<span class="certmatch">'; p21 = '</span>'; }

		html += '<th width="25%" rowspan="2">This Marriage was<br>Solemnized Between us</td>';
		html += '<td width="25%"><a href="#" onclick=\'paste_update("'+this.b1_id+'");\' title="'+this.b1_id+'">'+b10+this.b1_name+b11+'</a></td>';
		html += '<th width="25%" class="adr4" rowspan="2">In the<br>Presence of us</td>';
		html += '<td width="25%"><a href="#" onclick=\'paste_update("'+this.p1_id+'");\' title="'+this.p1_id+'">'+p10+this.p1_name+p11+'</a></td></tr><tr>';
		html += '<td><a href="#" onclick=\'paste_update("'+this.b2_id+'");\' title="'+this.b2_id+'">'+b20+this.b2_name+b21+'</a></td>';
		html += '<td><a href="#" onclick=\'paste_update("'+this.p2_id+'");\' title="'+this.p2_id+'">'+p20+this.p2_name+p21+'</a></td>';
	}

	html += '</tr></table>';

	return html;
}

