function printFooterText() {
	document.write("Tyto stránky byly vygenerovány free programem <a href='http://sirsi.wz.cz/ancestry2html.php' target='_blank'>Ancestry2html 1.4.1</a> dne 25.2.2010 za použití dat zpracovaných free genealogickým programem <a href='http://rodokmen.webzdarma.cz' target='_blank'>Ancestry 1.0.21.45</a>.");	
}

function filterPeople(array,count) {
	text=$("#namesFilter").val().toLowerCase();
	if (text.length==0) {
		showAllPeople();
		return;
	}
	window.document.styleSheets[2].disabled=false;
	j=0;

	for (i=0;i<count;i++) {
		if (array[i*2+1].toLowerCase().indexOf(text)==-1) {
			$("#"+array[i*2]).hide();
		} else {
			j++;
			$("#"+array[i*2]).show();
		}
	}
	$("#resultCount").html("("+j+" záznamů z "+i+" osob)");
	$("h2.firstLetter").each(function() {
		/*var a = $(this).find("a").get(0);
		var aName = $(a).attr("name");*/
		if ($(this).next().find("li").filter(":visible").length==0) {
			$(this).hide();
			/*$("."+aName).hide();
			$(this).prev().hide();*/
		} else {
			$(this).show();
			/*$("."+aName).show();
			$(this).prev().show();*/
		}
	})
}

function showAllPeople(array,count) {
	$("h2.firstLetter").show();
	window.document.styleSheets[2].disabled=true;
	
	for (i=0;i<count;i++) {
		document.getElementById(array[i*2]).style.display="list-item";
	}
}

function Person(id,lastname,maidenname,firstname) {
	this.id = id;
	this.firstname = firstname;
	this.maidenname = maidenname;
	this.lastname = lastname;
}

function checkNames() {
	var otherNamesString = $("#otherNames").val();
	var otherNamesStringArray = otherNamesString.split(";");
	var otherNames = new Array();

  for (i=0;i<otherNamesStringArray.length;i++) {
		var splitted = otherNamesStringArray[i].split(",");

		otherNames[i] = new Person(splitted[0],splitted[1],splitted[2],splitted[3]);
	}

	var myNamesString = $("#namesForCheck").val();
	var myNamesStringArray = myNamesString.split(";");
	var myNames = new Array();

  for (i=0;i<myNamesStringArray.length;i++) {
		var splitted = myNamesStringArray[i].split(",");

		myNames[i] = new Person(splitted[0],splitted[1],splitted[2],splitted[3]);
	}

	//-------------

	for (i=0;i<myNames.length;i++) {
		var family = 0;

		for (j=0;j<otherNames.length;j++) {
			lastNames = myNames[i].lastname == otherNames[j].lastname && myNames[i].lastname!="?";
			maidenNames = myNames[i].maidenname == otherNames[j].maidenname && myNames[i].maidenname!="?";
			if (lastNames || maidenNames || 
				(myNames[i].lastname == otherNames[j].maidenname && myNames[i].lastname!="?") || 
				(myNames[i].maidenname == otherNames[j].lastname && myNames[i].maidenname!="?")) {
				family=Math.max(1,family);
				if (lastNames || maidenNames) {
					family = Math.max(2,family);
					if (lastNames && maidenNames && myNames[i].firstname == otherNames[j].firstname && myNames[i].firstname!="?" ) {
						family = Math.max(3,family);	
					}
				}
			}
		}

		if (family>0) {
			$("#p"+myNames[i].id+" a").show().css("color",'rgb('+(105+family*50)+',0,0)');
		} else {
			$("#p"+myNames[i].id).hide();
		}

		window.document.styleSheets[2].disabled=false;
	}
}
