//Format Portrait Spouses and children table
re= /@/
//Reset child and child event counters
prevchirec=0
prevcherec=0
//Count number of children and set text accordingly
var noChildren = 0
var vChildText=" "
var vSpouseText=" "
for(i=0;i<noSpouses;i++){
	spocell=dSp[i].split(re)
	noChildren=noChildren+spocell[6]
	}
if (noChildren==0){vChildText=" "}
else {if(noChildren==1){vChildText=" & Child"}
	  else{vChildText=" & Children"}}
//Set heading to reflect no of Spouses and children
if(noSpouses>0){spocell=dSp[0].split(re)}
if((noSpouses>1) && (spocell[0]=="Wife")){document.write("<td><p>&nbsp;Wives"+vChildText+"</p></td>")}
if((noSpouses==1) && (spocell[0]=="Wife")){document.write("<td><p>&nbsp;Wife"+vChildText+"</p></td>")}
if((noSpouses>1) && (spocell[0]=="Husband")){document.write("<td><p>&nbsp;Husbands"+vChildText+"</p></td>")}
if((noSpouses==1) && (spocell[0]=="Husband")){document.write("<td><p>&nbsp;Husband"+vChildText+"</p></td>")}
if(noSpouses==0) {document.write("<td><p>&nbsp;Spouse & Children</p></td><tr><td><br>None recorded</td></tr>")}

for(i=0;i<noSpouses;i++){
	spocell=dSp[i].split(re)
	vSpouseText="&nbsp;"
	if (noSpouses>1){vSpouseText=spocell[0]+" "+(i+1)}
	document.writeln ("<tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr class='tableheadings'><td width='30%'>"+vSpouseText+"</td><td width='20%'>Event Date</td><td width='50%'>Place</td></tr>")
	document.writeln("<tr class='tablerow'><td width='30%'><a href=\'p" + spocell[1] + ".html\'>" + spocell[2] + "</a><sub>" + spocell[5] + "</sub></td>")
	if(spocell[3]==" "){document.writeln("<td width='20%'>&nbsp;</td>")}
	else {document.writeln("<td width='20%'>m. " + spocell[3] + "</td>")}
	document.writeln("<td width='50%'>" + spocell[4] + "</td></tr>")
    document.writeln("</table></td></tr>")
	
	if (spocell[6]>0){
		document.writeln("<tr><td><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr class='tablerow'><td width='5%' class='treegraphic'><img src='../../i/vert2.gif'></td><td width='25%'>&nbsp;</td><td width='20%'>&nbsp;</td><td width='50%'>&nbsp;</td></tr></table>") 
		document.writeln("<table width='100%' border='0' cellspacing='0' cellpadding='0'>")
		for(j=0;j<spocell[6];j++){
			chicell=dC[j+prevchirec].split(re)
			if (chicell[2]!=0){
				for(k=0;k<chicell[2];k++){
					checell=dCE[k+prevcherec].split(re)                        
					document.writeln("<tr class='tablerow'><td width='5%' class='treegraphic'>")
					if(k==0){
						if (j==spocell[6]-1){document.writeln("<img src='../../i/fem2.gif'></td>")}
						else {document.writeln("<img src='../../i/tee2.gif'></td>")}
						document.writeln("<td width='25%'><a href=\'p" + chicell[0] + ".html\'>" + chicell[1] + "</a></td><td width='20%'>" + checell[0] + "</td><td width='50%'>" + checell[1] + "</td></tr>")
					}
					else {
						if (j==spocell[6]-1){document.writeln("&nbsp;</td>")}
						else {document.writeln("<img src='../../i/vert2.gif'></td>")}
						document.writeln("<td width='25%'>&nbsp;</td><td width='20%'>" + checell[0] + "</td><td width='50%'>" + checell[1] + "</td></tr>")
					}
				}
			}
			else {
				if (j==spocell[6]-1){document.writeln("<tr class='tablerow'><td width='5%' class='treegraphic'><img src='../../i/fem2.gif'></td>")}
				else {document.writeln("<tr class='tablerow'><td width='5%' class='treegraphic'><img src='../../i/tee2.gif'></td>")}
				document.writeln("<td width='25%'><a href=\'p" + chicell[0] + ".html\'>" + chicell[1] + "</a></td><td width='20%'>&nbsp;</td><td width='50%'>&nbsp;</td></tr>")
			}
			prevcherec=prevcherec+(chicell[2]*1)
    	}
		prevchirec=prevchirec+(spocell[6]*1)
		document.writeln("</table>")
	}
document.writeln("</td></tr><tr><td><hr class='tabledivider' size='1' width='100%' noshade></td></tr>")																							
}