//document.writeln('<SCRIPT language=JavaScript src=\"../home/cite.js\" type=text/javascript></SCRIPT>');

//----------------------------------------------------
function localInit() {
exmember = document.location.hash;
exmember = exmember.substring(1,exmember.length);
if (exmember != "") delaymark();
try {pageInit()} catch (e) {;}
}

//----------------------------------------------------
function putpic() {
var fname = document.location.href;
var fp1 = fname.lastIndexOf("_")+1;
fname = fname.substring(fp1,fname.length-4);
for (var x=1;x<members_db.length;x++) {
	fieldsFromRecord(x);
	if (fname == filename && qty > 0) {
		var num = qty.rnd();
		document.writeln("<img src=../home/portrait/" + fname + num + ".jpg width=100 height=140 class=alleft>");
		x = members_db.length;
		}
	}
}	


//idonly=document.location.href;
//idonly=idonly.substring(1+idonly.lastIndexOf("_"),idonly.lastIndexOf(".htm"));

//----------------------------------------------------
function contemporaries(idonly) {
countmem = 0;
countcontact = 0;
document.writeln("<h5 class=cl>Contemporaries</h5>");
for (var x=1;x<members_db.length;x++) {
	fieldsFromRecord(x);
	if (filename == idonly) {memstart = 1*start; memend = 1*end; x = members_db.length;}
	}

paragraph = "<p class=small><span>  ";
for (var x=1;x<members_db.length;x++) {
	fieldsFromRecord(x);
	flag = false;
	if (1*end>=memstart && 1*end <= memend) flag = true;
	if (1*start>=memstart && 1*start <= memend) flag = true;
	if (1*start>=memstart && 1*start <= memend) flag = true;
	if (1*start<=memstart && 1*end >= memend) flag = true;
	if (idonly==filename)	flag=false;
	if (firstname == "Oliver") flag = false;
	if (firstname == "Quentin") flag = false;
	if (firstname == "Ulrika") flag = false;
	if (firstname == "Xavier") flag = false;
	if (firstname == "Zebedee") flag = false;
	if (flag) {
		paragraph += firstname + "&nbsp;" + lastname + ", ";
		countmem++;
		if (contact == 1 || contact == 2) countcontact++;
		}
	}
paragraph = paragraph.substring(0,paragraph.length - 2) + ".</span></p>";
document.writeln(paragraph);
document.writeln("There are " + textNum(countmem) + " friends, and " + textNum(countcontact) + " are in contact.");
}

//----------------------------------------------------
function delaymark(){
checkanchors = document.getElementsByTagName("A");
for (var x=1;x<checkanchors.length;x++) {
	if (checkanchors[x].name == exmember) {
		checkanchors[x].style.backgroundColor = "red";
		checkanchors[x].style.color = "white";
		x = checkanchors.length;
		}
	}
}

//----------------------------------------------------
// Call this onLoad for template based profiles after 10/3/2006
function profileInit() {

formswitch = false;

if (idonly == "form") {
	compare = document.location.href;
	p = compare.lastIndexOf(".htm")+5;
	compare = compare.substring(p);
	formswitch = true;	
	} else {
	compare = idonly;
	}
for (var x=1;x<members_db.length;x++) {
	fieldsFromRecord(x);
	if (compare == filename) {

		memname = firstname + " " + lastname;

		if (formswitch) {
			document.title = memname + " - LPMCC.net";
			document.getElementById("IDfullname").innerHTML = memname;
			document.getElementById("gname2").innerHTML = memname;
			document.getElementById("gname3").innerHTML = memname;
			document.getElementById("gname7").innerHTML = "19" + start + " to 19" + end ;
			if (nickname!="") document.getElementById("gname4").innerHTML = memname + " was also know by club friends as " + nickname;

//if (qty>0) document.getElementById("gname5").src = "../home/portrait/" + passname + "0.jpg";
//if (qty==0)  document.getElementById("gname5").style.display = "none";

// set the previous & next in the series
			memprev = members_db[x-1].split("|");
			memnext = members_db[x+1].split("|");

			backp = "members_form.htm?" + memprev[3];
			nextp = "members_form.htm?" + memnext[3];

			document.getElementById("IDprev").href = backp;
			document.getElementById("IDprev").title = memprev[0] + " " + memprev[1];
			document.getElementById("IDnext").href = nextp;
			document.getElementById("IDnext").title = memnext[0] + " " + memnext[1];

			// alter the form redirect to go to appropriate FIRSTNAMES file
			document.form1.redirect.value = "http://www.crossleys.plus.com/phoenix/members/members_first.htm?" + firstname.charAt(0);

			} else {

			document.getElementById("IDfullname").innerHTML = memname;
			if (nickname == "") document.getElementById("IDnickname").style.display = "none";
			}


		if (qty == 1) document.getElementById("IDportrait").innerHTML = "<img src=../home/portrait/" + compare + "0.jpg width=100 height=140 class=alleft>";
		if (qty > 1) {
			pgallery = ",\'" + compare + "0\'";
			for (var y=1;y<qty;y++) {
				pgallery += ",\'" + compare + (y) + "\'";
				}
			document.getElementById("IDportrait").innerHTML = "<img src=../home/portrait/" + compare + "0.jpg width=100 height=140 class=alleft onclick=swap(this" + pgallery + ")>";
			}
		document.title = memname + " - LPMCC.net";
		memmess = "";
		strtms = "Click the icon to send a message to " + firstname + " ";
		if (contact == 1) memmess = strtms + "<img onClick=snd(\'" + escape(memname) + "\') alt=\'Send a message to " + memname + "\' src=../home/graphics/env.gif>";
		if (contact == 2) {
			memmess = strtms + "<img onClick=snd(\'" + escape(memname) + "\') alt=\'Send a message to " + memname + "\' src=../home/graphics/eml.gif>";
/*			for (var s = 1; s < Skype_db.length;s++) {
				Skype_rec = Skype_db[s].split("|");
				if (Skype_rec[4] == filename) memmess = strtms + "<a href=\'skype:" + Skype_rec[1] + "?call\'><img alt=\'Call " + memname + "\ FREE using Skype' src=../home/graphics/skp.gif></a>";
				}
*/			}
		// 31 Jan 2009 - added link to form
		memmess += "<br><br><a href=members_form.htm?" + filename + " title='Add lurid tales to the bubble box'>Send more information about " + firstname + "</a>";

		document.getElementById("IDmessage").innerHTML = memmess;
		x = members_db.length;
		}
	}		
contentList(memname);
appearanceList(memname);
}
//------------------------------------------------
// adds a list of links to contributions by an ex-member. Passed the actual name

function contentList(mname) {
// first create a full bibliography

// "name|sorter|title|file|description"

makeBibliographyData();

// output

mC = "<h5>Content contributed by " + firstname + "</h5>";
mC += "<p>Click on a line to go to the page.</p>";
mC += "<table width=100% border=1 cellspacing=0 cellpadding=4 bordercolor=#B2C1EF rules=rows>";

x = 0;
isContent = false;


while (x < bibliograph_db.length && mname != bibliograph_db[x].split("|")[0]) x++;

if (x < bibliograph_db.length-1) {
	while (mname == bibliograph_db[x].split("|")[0]) {
		sub = bibliograph_db[x].split("|");
		mC += "<tr style=cursor:pointer;cursor:hand; onClick=\'window.location.href=\"../" + sub[3] + "\"\' onMouseover=\'HiOn(this)\' onMouseout=\'HiOff(this)\'>";
		mC += "<td style=width:248px; class=small>" + sub[2] + "</td>";
		mC += "<td style=width:248px; class=small>" + sub[4] + "</td>";
		mC += "</tr>";
		x++;
		isContent = true;
		}
	}

mC += "</table>";

if (isContent) document.getElementById("messages").innerHTML = mC;

//post_db = []; // dump the database array to save memory
}

//------------------------------------------------
// adds a list of links to pages with the ex-member on. Passed the actual name

function appearanceList(mname) {

//populise(); //fill and sort people_db

var fullname = mname.split(" ");
firstname = fullname[0];
lastname = fullname[1];

mC = "<h5>Pages Mentioning " + firstname + "</h5>";
mC += "<p>Click on a line to go to the page.</p>";
mC += "<table width=100% border=1 cellspacing=0 cellpadding=4 bordercolor=#B2C1EF rules=groups>";
mC += "<tbody>";

x = 0;
isContent = false;
var lastsection = "";


while (x < people_db.length && mname != people_db[x].split("|")[0]) x++;

if (x < people_db.length-1) {
	while (mname == people_db[x].split("|")[0]) {
		sub = people_db[x].split("|");
		icon = sub[1].split("/")[0];
		section = icon.toUpperCase();

		var s = parseInt(section,10);
		if (s > 1950 && s < 2000)	{section += "s PHOTO GALLERY";icon = "gallery";}
		if (s > 2000)			{section += " PHOTO GALLERY";icon = "gallery";}
		if (section == "KANDD")		{section = "KETTERING & DIST MCC";icon = "gallery";}
		if (section == "MEGAPHONE")	section += " ARCHIVE";
		if (section == "MOTOR")		{section += "BIKES";icon = "bike";}
		if (section == "RALLIES")	section += " AND BADGES";
		if (section == "RUNS")		section = "CLUB RUNS AND CAMPS";
		if (section == "ACTIVITY")	section = "ACTIVITIES OLD AND NEW";
		if (section == "POST")		section += " AND MESSAGES";
		if (section == "TRAINING")	section += " SCHEME";

		tdsection = "&nbsp;";
		if (lastsection != section) {
			tdsection = "<img src=../home/gifs/" + icon + ".gif align=left>" + section;
			mC += "</tbody><tbody>";
			}
		mC += "<tr style=cursor:pointer;cursor:hand; onClick=\'window.location.href=\"../" + sub[1] + "\"\' onMouseover=\'HiOn(this)\' onMouseout=\'HiOff(this)\'>";
		mC += "<td style=width:248px; class=small>" + tdsection + "</td>";
		mC += "<td style=width:248px; class=small>" + sub[2] + "</td>";
		mC += "</tr>";
		x++;
		lastsection = section;
		isContent = true;
		}
	}

mC += "</tbody></table>";

if (isContent) document.getElementById("messages").innerHTML += mC;

people_db = []; // dump the database array to save memory
}

// -------------------------------------------------------------
function HiOn(obj) {
obj.style.backgroundColor = "#B2C1EF";
}
// -------------------------------------------------------------
function HiOff(obj) {
obj.style.backgroundColor = "white";
}
//==============================================================
function addCiteRecords() {
bibliograph_db = bibliograph_db.concat(cite_db);
cite_db = null;
}
//==============================================================
// Creates a bibliography_db array 
// Needs menu_db
//       badge_db in rallies/badge.js
//       post_db  in post/post.js
//       so include them in the calling page

// data format "0 Full Name|1 Sort number|2 Title|3 Path/File.htm?Query#Hash|4 Type"

// Note: The Sort Number is a contrived string that allows sensible sorting of entries
//	'00001 page  '
//	'00999 quote ' (random calculations)
//	'01000 badge '
//	'10000-yyyy & 100-mm & 100-dd' to put post order latest first
//	''
//-----------------------------------------------

var bibliograph_db = [];

function makeBibliographyData() {

// first read badge_db and create a sub Array of badge owners

var b_db = [];

for (var x = 0; x < badge_db.length;x++) {
	var sub = badge_db[x].split("|");
	b_db.push(sub[6] + "|" + sub[0]);
	}
//sort and recreate the data entries

b_db.sort();

sub = b_db[0].split("|");
var checkname = sub[0];
var rally = sub[1];
var last_rally = rally;
var rallycount = 1;

for (var x = 1; x < b_db.length; x++) {
	var sub = b_db[x].split("|");
	if (sub[1].charAt(0) != rally.charAt(0) || sub[0] != checkname) {
		var letter = rally.charAt(0);
		var rallyList = rally + " to " + last_rally;
		if (last_rally == rally) rallyList = rally;
		var N = textNum(rallycount);
		N = N.charAt(0).toUpperCase() + N.substring(1);
		rallyNum = N + " badges for ";
		if (rallycount == 1) rallyNum = N + " badge for ";
		bibliograph_db.push(checkname + "|01000 badge |" + letter + " rally badges|rallies/rally_badges" + letter.toLowerCase() + ".htm|" + rallyNum + rallyList + " Rally");
		rally = sub[1];
		last_rally = rally;
		checkname = sub[0];
		rallycount=1;
		} else {
		last_rally = sub[1];
		rallycount++;
		}
	}

// Now add pages from the Main Menu files

for (var x = 1; x < menu_db.length-2; x++) {
	sub = menu_db[x].split("|");
	if (sub[0] < 3) pretitle = sub[1] + ": ";
	if (sub[0] > 2) sub[1] = pretitle + sub[1];
	if (sub[4] != "") {
		var co = sub[4].split(",");
		for (var y = 0; y < co.length; y++) bibliograph_db.push(co[y] + "|00001 page  |" + sub[1] + "|" + sub[2] + "|" + sub[3]);
		}
	}

// Now add post messages

for (var x = 1; x < post_db.length; x++) {
	sub = post_db[x].split("|");
	if (sub[1] == tday.getFullYear()) sub[1] = "index";
	if (sub[1] == "2001") sub[1] = "2002";
	sorter = sub[5].split("/");
	sortxt = 10000-sorter[2] + "" + 100-sorter[1] + "" + 100-sorter[0];
	bibliograph_db.push(sub[2] + "|" + sortxt + "|Message on " + sub[5] + "|post/post_" + sub[1] + ".htm?" + sub[0] + "|" + sub[4]);
	}

bibliograph_db.sort();
}



