<?php
/*=================================================
		Project: phpGedView
		File: functions_blocks.php
		Author:
				John Finlay
				Joe Witthuhn				jaw959@users.sourceforge.net
				Kurt Norgaz 				kurtnorgaz
		Comments:
				Various functions used to create blocks and modules for the
				MyGedView page.  These functions can be used to create custom
				blocks in other applications as well.

		Change Log:
				11/06/03 - File Created from functions.php

		phpGedView: Genealogy Viewer
		Copyright (C) 2002 to 2003		  John Finlay and Others

		This program is free software; you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation; either version 2 of the License, or
		(at your option) any later version.

		This program is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.

		You should have received a copy of the GNU General Public License
		along with this program; if not, write to the Free Software
		Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

===================================================*/
# $Id: functions_blocks.php,v 1.218 2004/12/01 18:06:00 yalnifj Exp $

if (strstr($_SERVER["PHP_SELF"],"functions")) {
		print "Now, why would you want to do that.		  You're not hacking are you?";
		exit;
}

/**
 * Block definition array
 *
 * The following block definition array defines the
 * blocks that can be used to customize the portals
 * their names and the function to call them
 * "name" is the name of the block in the lists
 * "descr" is a textual description of the block
 * "type" the options are "user" or "gedcom" or undefined
 * - The type determines which lists the block is available in.
 * - Leaving the type undefined allows it to be on both the user and gedcom portal
 * @global $PGV_BLOCKS
 */
$PGV_BLOCKS = array();
$PGV_BLOCKS["print_upcoming_events"]["name"]		= $pgv_lang["upcoming_events_block"];
$PGV_BLOCKS["print_upcoming_events"]["descr"]		 = $pgv_lang["upcoming_events_descr"];
$PGV_BLOCKS["print_todays_events"]["name"]		  = $pgv_lang["todays_events_block"];
$PGV_BLOCKS["print_todays_events"]["descr"] 	   = $pgv_lang["todays_events_descr"];
$PGV_BLOCKS["print_logged_in_users"]["name"]		= $pgv_lang["logged_in_users_block"];
$PGV_BLOCKS["print_logged_in_users"]["descr"]		 = $pgv_lang["logged_in_users_descr"];
$PGV_BLOCKS["print_user_messages"]["name"]		  = $pgv_lang["user_messages_block"];
$PGV_BLOCKS["print_user_messages"]["descr"] 	   = $pgv_lang["user_messages_descr"];
$PGV_BLOCKS["print_user_messages"]["type"]		  = "user";
$PGV_BLOCKS["print_user_favorites"]["name"] 	   = $pgv_lang["user_favorites_block"];
$PGV_BLOCKS["print_user_favorites"]["descr"]		= $pgv_lang["user_favorites_descr"];
$PGV_BLOCKS["print_user_favorites"]["type"] 	   = "user";
$PGV_BLOCKS["print_welcome_block"]["name"]		  = $pgv_lang["welcome_block"];
$PGV_BLOCKS["print_welcome_block"]["descr"] 	   = $pgv_lang["welcome_descr"];
$PGV_BLOCKS["print_welcome_block"]["type"]		  = "user";
$PGV_BLOCKS["print_random_media"]["name"]		 = $pgv_lang["random_media_block"];
$PGV_BLOCKS["print_random_media"]["descr"]		  = $pgv_lang["random_media_descr"];
$PGV_BLOCKS["print_gedcom_block"]["name"]		 = $pgv_lang["gedcom_block"];
$PGV_BLOCKS["print_gedcom_block"]["descr"]		  = $pgv_lang["gedcom_descr"];
$PGV_BLOCKS["print_gedcom_block"]["type"]		 = "gedcom";
$PGV_BLOCKS["print_gedcom_favorites"]["name"]		 = $pgv_lang["gedcom_favorites_block"];
$PGV_BLOCKS["print_gedcom_favorites"]["descr"]		  = $pgv_lang["gedcom_favorites_descr"];
$PGV_BLOCKS["print_gedcom_favorites"]["type"]		 = "gedcom";
$PGV_BLOCKS["print_gedcom_stats"]["name"]		 = $pgv_lang["gedcom_stats_block"];
$PGV_BLOCKS["print_gedcom_stats"]["descr"]		  = $pgv_lang["gedcom_stats_descr"];
$PGV_BLOCKS["print_login_block"]["name"]		= $pgv_lang["login_block"];
$PGV_BLOCKS["print_login_block"]["descr"]		 = $pgv_lang["login_descr"];
$PGV_BLOCKS["print_login_block"]["type"]		= "gedcom";
$PGV_BLOCKS["print_user_news"]["name"]		  = $pgv_lang["user_news_block"];
$PGV_BLOCKS["print_user_news"]["descr"] 	   = $pgv_lang["user_news_descr"];
$PGV_BLOCKS["print_user_news"]["type"]		  = "user";
$PGV_BLOCKS["print_gedcom_news"]["name"]		= $pgv_lang["gedcom_news_block"];
$PGV_BLOCKS["print_gedcom_news"]["descr"]		 = $pgv_lang["gedcom_news_descr"];
$PGV_BLOCKS["print_gedcom_news"]["type"]		= "gedcom";
$PGV_BLOCKS["print_recent_changes"]["name"] 	   = $pgv_lang["recent_changes_block"];
$PGV_BLOCKS["print_recent_changes"]["descr"]		= $pgv_lang["recent_changes_descr"];
$PGV_BLOCKS["print_block_theme_select"]["name"] 		= $pgv_lang["theme_select_block"];
$PGV_BLOCKS["print_block_theme_select"]["descr"]		= $pgv_lang["theme_select_descr"];
$PGV_BLOCKS["print_block_theme_select"]["type"] 	   = "gedcom";

$PGV_BLOCKS["print_block_name_top10"]["name"]			= $pgv_lang["block_top10"];
$PGV_BLOCKS["print_block_name_top10"]["descr"]			= $pgv_lang["block_top10_descr"];

//-- upcoming events block
//-- this block prints a list of the upcoming events of living people in your gedcom
function print_upcoming_events($block=true) {
	global $pgv_lang, $month, $year, $day, $monthtonum, $HIDE_LIVE_PEOPLE, $SHOW_ID_NUMBERS, $command, $indilist, $TEXT_DIRECTION;
	global $PGV_IMAGES, $PGV_IMAGE_DIR, $GEDCOM;

	if ($command=="user") $filter = "living";
	else $filter = "all";

	$daytext = "";
	//-- check if the events are already stored in the session before trying to calculate them
	if (isset($_SESSION["upcoming_events"][$command][$GEDCOM])) {
		$daytext = $_SESSION["upcoming_events"][$command][$GEDCOM];
	}
	$myindilist = array();
	$myfamlist = array();
	$oldmonth=$month;
	$oldyear = $year;
	$oldday = $day;

	if (empty($daytext)) {
		$action = "block";
		$monthstart = mktime(1,0,0,$monthtonum[strtolower($month)],$day,$year);
		$mmon = strtolower(date("M", $monthstart));
		$query = "2 DATE[^\n]*$mmon";
		$myindilist = search_indis($query);
		$myfamlist = search_fams($query);
		uasort($myindilist, "itemsort");
		uasort($myfamlist, "itemsort");
	}
	if ((count($myindilist)>0)||(count($myfamlist)>0)) {
		for($k=0; $k<30; $k++) {
			$mday = date("j", $monthstart);
			$mmon = strtolower(date("M", $monthstart));
			$day = $mday;
			$year = (int)date("Y", $monthstart);
			if ($mmon!=strtolower($month)) {
				$query = "2 DATE[^\n]*$mmon";
				$myindilist = search_indis($query);
				$myfamlist = search_fams($query);
				$month=$mmon;
				uasort($myindilist, "itemsort");
				uasort($myfamlist, "itemsort");
			}
			$dayindilist = array();
			$query = "2 DATE[^\n]*[^1-9]$mday $mmon";
			foreach($myindilist as $gid=>$indi) {
				if (preg_match("/$query/i", $indi["gedcom"])>0) {
					if (displayDetailsById($gid)) $dayindilist[$gid]=$indi;
				}
			}
			$dayfamlist = array();
			foreach($myfamlist as $gid=>$fam) {
				if (preg_match("/$query/i", $fam["gedcom"])>0) {
					if (displayDetailsById($gid, "FAM")) $dayfamlist[$gid]=$fam;
				}
			}
			if ((count($dayindilist)>0)||(count($dayfamlist)>0)) {
				foreach($dayindilist as $gid=>$indi) {
					$disp = true;
					if ($disp) {
						$indilines = split("\n", $indi["gedcom"]);
						$factrec = "";
						$lct = count($indilines);
						$text = "";
						for($i=1; $i<=$lct; $i++) {
							if ($i<$lct) $line = $indilines[$i];
							if (empty($line)) $line = " ";
							if ($i==$lct||($line{0}=="1")) {
								if (!empty($factrec)) {
									$ct = preg_match("/$query/i", $factrec, $match);
									if ($ct>0) {
										$text_fact = get_calendar_fact($factrec, $action, $filter, $gid); 
										
										if ($text_fact!="filter") $text.=$text_fact;
									}
								}
								$factrec="";
							}
							$factrec.=$line."\n";
						}
						if (!empty($text)) {
							$daytext .= "<img id=\"box-".$gid."-".$k."-sex\" src=\"$PGV_IMAGE_DIR/";
							if (preg_match("/1 SEX M/", $indi["gedcom"])>0) $daytext .= $PGV_IMAGES["sex"]["small"]."\" title=\"".$pgv_lang["male"]."\" alt=\"".$pgv_lang["male"];
							else  if (preg_match("/1 SEX F/", $indi["gedcom"])>0) $daytext .= $PGV_IMAGES["sexf"]["small"]."\" title=\"".$pgv_lang["female"]."\" alt=\"".$pgv_lang["female"];
							else $daytext .= $PGV_IMAGES["sexn"]["small"]."\" title=\"".$pgv_lang["sex"]." ".$pgv_lang["unknown"]."\" alt=\"".$pgv_lang["sex"]." ".$pgv_lang["unknown"];
							$daytext .= "\" class=\"sex_image\" />";
							$names = preg_split("/,/", $indi["name"]);
							$indi["name"] = check_NN($names);
							$daytext .= "<a href=\"individual.php?pid=$gid&amp;ged=".$indi["file"]."\"><b>".PrintReady($indi["name"])."</b>";
							if ($SHOW_ID_NUMBERS) {
								if ($TEXT_DIRECTION=="ltr") 
									 $daytext .= " &lrm;($gid)&lrm;";
								else $daytext .= " &rlm;($gid)&rlm;";
							}
							$daytext .= "</a><br />\n";
							$daytext .= "<div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
							$daytext .= $text;
							$daytext .= "</div><br />";
						}
					}
				}
				foreach($dayfamlist as $gid=>$fam) {
					$indilines = split("\n", $fam["gedcom"]);
					$factrec = "";
					$lct = count($indilines);
					$text = "";
					for($i=1; $i<=$lct; $i++) {
						if ($i<$lct) $line = $indilines[$i];
						if (empty($line)) $line = " ";
						if ($i==$lct||($line{0}=="1")) {
							if (!empty($factrec)) {
								$ct = preg_match("/$query/i", $factrec, $match);
								if ($ct>0) {
									$text_fact = get_calendar_fact($factrec, $action, $filter, $gid); 
									if ($text_fact!="filter") $text.=$text_fact;
								}
							}
							$factrec="";
						}
						$factrec.=$line."\n";
					}
					if (!empty($text)) {
						$names = preg_split("/[,+]/", $fam["name"]);
						$fam["name"] = check_NN($names);
						$daytext .= "<a href=\"family.php?famid=$gid&amp;ged=".$fam["file"]."\"><b>".PrintReady($fam["name"])."</b>";
						if ($SHOW_ID_NUMBERS) {
								if ($TEXT_DIRECTION=="ltr") 
									 $daytext .= " &lrm;($gid)&lrm;";
								else $daytext .= " &rlm;($gid)&rlm;";
						}
						$daytext .= "</a><br />\n";
						$daytext .= "<div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
						$daytext .= $text;
						$daytext .= "</div><br />";
					}
				}
			}
			$monthstart += (60*60*24);
		}
	}
	if (!empty($daytext)) {
		print "<div id=\"upcoming_events\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["upcoming_events"]."</b>";
		print_help_link("index_events_help", "qm");
		print "</div></td><td class=\"blockh3\" >&nbsp;</td>";
		print "</tr></table>";
		print "<div class=\"blockcontent\" >";
		if ($block) print "<div class=\"small_inner_block\">\n";
		print $daytext;
	}
	//-- store the findings in the session so that the calculation does not happen again
	$_SESSION["upcoming_events"][$command][$GEDCOM] = $daytext;
	if ($block) print "</div>\n";
	$day = $oldday;
	$month = $oldmonth;
	$year = $oldyear;
	print "</div>"; // blockcontent
	print "</div>"; // block
}

//-- today's events block
//-- this block prints a list of today's upcoming events of living people in your gedcom
function print_todays_events($block=true) {
	global $pgv_lang, $month, $year, $day, $monthtonum, $HIDE_LIVE_PEOPLE, $SHOW_ID_NUMBERS, $command, $TEXT_DIRECTION;
	global $PGV_IMAGE_DIR, $PGV_IMAGES, $GEDCOM;

	if ($command=="user") $filter = "living";
	else $filter = "all";

	$daytext = "";
	$action = "today";
	$dayindilist = array();
	$dayfamlist = array();
	if (isset($_SESSION["todays_events"][$command][$GEDCOM])) {
		$daytext = $_SESSION["todays_events"][$command][$GEDCOM];
	}
	else {
		$query = "2 DATE[^\n]*[^1-9]$day $month";
		$dayindilist = search_indis($query);
		$dayfamlist = search_fams($query);
	}
	if ((count($dayindilist)>0)||(count($dayfamlist)>0)) {
		uasort($dayindilist, "itemsort");
		uasort($dayfamlist, "itemsort");
		foreach($dayindilist as $gid=>$indi) {
			$disp = true;
			if (($filter=="living")&&(is_dead_id($gid)==1)) $disp = false;
			else if ($HIDE_LIVE_PEOPLE) $disp = displayDetailsByID($gid);
			if ($disp) {
				$indilines = split("\n", $indi["gedcom"]);
				$factrec = "";
				$lct = count($indilines);
				$text = "";
				for($i=1; $i<=$lct; $i++) {
					if ($i<$lct) $line = $indilines[$i];
					if (empty($line)) $line = " ";
					if ($i==$lct||($line{0}=="1")) {
						if (!empty($factrec)) {
							$ct = preg_match("/$query/i", $factrec, $match);
							if ($ct>0) {
								$text_fact = get_calendar_fact($factrec, $action, $filter, $gid);
								if ($text_fact!="filter") $text.=$text_fact;
							}
						}
						$factrec="";
					}
					$factrec.=$line."\n";
				}
				if (!empty($text)) {
					$daytext .= "<img id=\"box-".$gid."-".$lct."-sex\" src=\"$PGV_IMAGE_DIR/";
					if (preg_match("/1 SEX M/", $indi["gedcom"])>0) $daytext .= $PGV_IMAGES["sex"]["small"]."\" title=\"".$pgv_lang["male"]."\" alt=\"".$pgv_lang["male"];
					else  if (preg_match("/1 SEX F/", $indi["gedcom"])>0) $daytext .= $PGV_IMAGES["sexf"]["small"]."\" title=\"".$pgv_lang["female"]."\" alt=\"".$pgv_lang["female"];
					else $daytext .= $PGV_IMAGES["sexn"]["small"]."\" title=\"".$pgv_lang["sex"]." ".$pgv_lang["unknown"]."\" alt=\"".$pgv_lang["sex"]." ".$pgv_lang["unknown"];
					$daytext .= "\" class=\"sex_image\" />";
					$names = preg_split("/,/", $indi["name"]);
					$indi["name"] = check_NN($names);
					$daytext .= "<a href=\"individual.php?pid=$gid&amp;ged=".$indi["file"]."\"><b>".PrintReady($indi["name"])."</b>";
					if ($SHOW_ID_NUMBERS) {
					   if ($TEXT_DIRECTION=="ltr") 
							$daytext .= " &lrm;($gid)&lrm;";
					   else $daytext .= " &rlm;($gid)&rlm;";
					}
					$daytext .= "</a><br />\n";
					$daytext .= "<div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
					$daytext .= $text;
					$daytext .= "</div><br />";
				}
			}
		}
		foreach($dayfamlist as $gid=>$fam) {
			$indilines = split("\n", $fam["gedcom"]);
			$factrec = "";
			$lct = count($indilines);
			$text = "";
			for($i=1; $i<=$lct; $i++) {
				if ($i<$lct) $line = $indilines[$i];
				if (empty($line)) $line = " ";
				if ($i==$lct||($line{0}=="1")) {
					if (!empty($factrec)) {
						$ct = preg_match("/$query/i", $factrec, $match);
						if ($ct>0) {
							$text_fact = get_calendar_fact($factrec, $action, $filter, $gid); 
							if ($text_fact!="filter") $text.=$text_fact;
						}
					}
					$factrec="";
				}
				$factrec.=$line."\n";
			}
			if (!empty($text)) {
				$display = true;
				if (preg_match("/$query/i", $fam["gedcom"])>0) {
					if (displayDetailsById($gid, "FAM")) $dayfamlist[$gid]=$fam;
				}
				$parents = find_parents($gid);
				if (!empty($parents["HUSB"])) {
					if (($filter=="living")&&(is_dead_id($parents["HUSB"])==1)) $display = false;
					else if ($HIDE_LIVE_PEOPLE) $display = displayDetailsByID($parents["HUSB"]);
				}
				if ($display) {
					if (!empty($parents["WIFE"])) {
						if (($filter=="living")&&(is_dead_id($parents["WIFE"])==1)) $display = false;
						else if ($HIDE_LIVE_PEOPLE) $display = displayDetailsByID($parents["WIFE"]);
					}
				}
				if ($display) {
					$names = preg_split("/[,+]/", $fam["name"]);
					$fam["name"] = check_NN($names);
					
					$daytext .= "<a href=\"family.php?famid=$gid&amp;ged=".$fam["file"]."\"><b>".PrintReady($fam["name"])."</b>";
					if ($SHOW_ID_NUMBERS) {
					   if ($TEXT_DIRECTION=="ltr") 
							$daytext .= " &lrm;($gid)&lrm;";
					   else $daytext .= " &rlm;($gid)&rlm;";
					}
					$daytext .= "</a><br />\n";
					$daytext .= "<div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
					$daytext .= $text;
					$daytext .= "</div><br />";
				}
			}
		}
	}
	if (!empty($daytext)) {
		print "<div id=\"on_this_day_events\" class=\"block\">";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["on_this_day"]."</b>";
		print_help_link("index_onthisday_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<div class=\"blockcontent\" >";
		if ($block) print "<div class=\"small_inner_block\">\n";
		print $daytext;
		if ($block) print "</div>\n";
		print "</div>"; // blockcontent
		print "</div>"; // block
	}
	//-- store the results in the session to improve speed of future page loads
	$_SESSION["todays_events"][$command][$GEDCOM] = $daytext;
}

/**
 * logged in users
 *
 * prints a list of other users who are logged in
 */
function print_logged_in_users($block=true) {
		global $pgv_lang, $PGV_SESSION_TIME, $TEXT_DIRECTION;

		$cusername = getUserName();
		$thisuser = getUser($cusername);
		if (!$thisuser['visibleonline']) return;
		$users = getUsers();
		$loggedusers = array();
		foreach($users as $user) {
			if ($user["loggedin"]=="Y") {
				if (time() - $user["sessiontime"] > $PGV_SESSION_TIME) userLogout($user["username"]);
				else if ((userIsAdmin($cusername))||($user['visibleonline'])) $loggedusers[] = $user;
			}
		}
		if (count($loggedusers)<2) return;

		print "<div id=\"logged_in_users\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["users_logged_in"]." &lrm;(".count($loggedusers).")&lrm;</b>";
		print_help_link("index_loggedin_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<div class=\"blockcontent\">";
		if ($block) print "<div class=\"small_inner_block\">\n";
		uasort($loggedusers, "usersort");
		foreach($loggedusers as $user) {
			print "<br />".PrintReady($user["fullname"]);
			if ($TEXT_DIRECTION=="ltr") print " &lrm; - ".$user["username"]."&lrm;<br />";
			else print " &rlm; - ".$user["username"]."&rlm;<br />";
			if ($cusername!=$user["username"]) {
				if ($user["contactmethod"] != "none") print "<a href=\"#\" onclick=\"return message('".$user["username"]."');\">".$pgv_lang["message"]."</a><br />";
				else print "<br /";
			}
		}
		if ($block) print "</div>\n";
		print "</div>"; // blockcontent
		print "</div>"; // block
}

//-- print user messages
function print_user_messages($block = true) {
		global $pgv_lang, $PGV_IMAGE_DIR, $TEXT_DIRECTION, $TIME_FORMAT, $PGV_STORE_MESSAGES, $PGV_IMAGES;

		$usermessages = getUserMessages(getUserName());

		print "<div id=\"user_messages\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["my_messages"]." &lrm;(".count($usermessages).")&lrm;</b>";
		print_help_link("mygedview_message_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<div class=\"blockcontent\">";
		if ($block) print "<div class=\"small_inner_block\">\n";
		print "<form name=\"messageform\" onsubmit=\"return confirm('".$pgv_lang["confirm_message_delete"]."');\">\n";
		if (count($usermessages)==0) print $pgv_lang["no_messages"]."<br />";
		else {
			print "<input type=\"hidden\" name=\"action\" value=\"deletemessage\" />\n";
			print "<table class=\"list_table\"><tr>\n";
			print "<td class=\"list_label\">".$pgv_lang["delete"]."</td>\n";
			print "<td class=\"list_label\">".$pgv_lang["message_subject"]."</td>\n";
			print "<td class=\"list_label\">".$pgv_lang["date_created"]."</td>\n";
			print "<td class=\"list_label\">".$pgv_lang["message_from"]."</td>\n";
			print "<td class=\"list_label\">".$pgv_lang["message_to"]."</td>\n";
			print "</tr>\n";
			foreach($usermessages as $key=>$message) {
				if (isset($message["id"])) $key = $message["id"];
				print "<tr>";
				print "<td class=\"list_value_wrap\"><input type=\"checkbox\" name=\"message_id[]\" value=\"$key\" /></td>\n";
				$showmsg=preg_replace("/(\w)\/(\w)/","\$1/<span style=\"font-size:1px;\"> </span>\$2",PrintReady($message["subject"]));
				$showmsg=preg_replace("/@/","@<span style=\"font-size:1px;\"> </span>",$showmsg);
				print "<td class=\"list_value_wrap\"><a href=\"#\" onclick=\"expand_layer('message$key'); return false;\"><b>".$showmsg."</b> <img id=\"message${key}_img\" src=\"".$PGV_IMAGE_DIR."/".$PGV_IMAGES["plus"]["other"]."\" border=\"0\" /></a></td>\n";
				if (!empty($message["created"])) $time = strtotime($message["created"]);
				else $time = time();
				$day = date("j", $time);
				$mon = date("M", $time);
				$year = date("Y", $time);
				$tempuser = getUser($message["from"]);
				print "<td class=\"list_value_wrap\">".get_changed_date("$day $mon $year")." - ".date($TIME_FORMAT, $time)."</td>\n";
				print "<td class=\"list_value_wrap\">";
				if ($tempuser) {
					print PrintReady($tempuser["fullname"]);
					if ($TEXT_DIRECTION=="ltr") print " &lrm; - ".htmlspecialchars($message["from"])."&lrm;";
					else print " &rlm; - ".htmlspecialchars($message["from"])."&rlm;";							
				}
				else print "<a href=\"mailto:".$message["from"]."\">".preg_replace("/@/","@<span style=\"font-size:1px;\"> </span>",$message["from"])."</a>";
				print "</td>\n";
				print "<td class=\"list_value_wrap\">".$message["to"]."</td>\n";
				print "</tr>\n";
				print "<tr><td class=\"list_value_wrap\" colspan=\"5\"><div id=\"message$key\" style=\"display: none;\">\n";
				$message["body"] = nl2br(htmlspecialchars($message["body"]));
				$message["body"] = preg_replace("/(http:.*)(<)/", "<a href=\"$1\" dir =\"ltr\">$1</a>$2", $message["body"]);

				print PrintReady($message["body"])."<br /><br />\n";
				if (preg_match("/RE:/", $message["subject"])==0) $message["subject"]="RE:".$message["subject"];
				if ($tempuser) print "<a href=\"#\" onclick=\"reply('".$message["from"]."', '".$message["subject"]."'); return false;\">".$pgv_lang["reply"]."</a> | ";
				print "<a href=\"index.php?action=deletemessage&amp;message_id=$key\" onclick=\"return confirm('".$pgv_lang["confirm_message_delete"]."');\">".$pgv_lang["delete"]."</a></div></td></tr>\n";
			}
			print "</table>\n";
			print "<input type=\"submit\" value=\"".$pgv_lang["delete_selected_messages"]."\" /><br /><br />\n";
		}
		$users = getUsers();
		if (count($users)>1) {
			print $pgv_lang["message"]." <select name=\"touser\">\n";
			$username = getUserName();
			uasort($users, "usersort");
			if (userIsAdmin($username)) print "<option value=\"all\">".$pgv_lang["broadcast_all"]."</option>\n";
			foreach($users as $user) {
				if ($username!=$user["username"] && $user["verified_by_admin"])  {
					print "<option value=\"".$user["username"]."\"";
					print ">".PrintReady($user["fullname"]);
					if ($TEXT_DIRECTION=="ltr") print " &lrm; - ".$user["username"]."&lrm;</option>\n";
					else print " &rlm; - ".$user["username"]."&rlm;</option>\n";								
				}
			}
			print "</select><input type=\"button\" value=\"".$pgv_lang["send"]."\" onclick=\"message(document.messageform.touser.options[document.messageform.touser.selectedIndex].value, 'messaging2', ''); return false;\" />\n";
		}
		print "</form>\n";
		if ($block) print "</div>\n";
		print "</div>"; // blockcontent
		print "</div>"; // block
}

//-- print user favorites
function print_user_favorites($block = true) {
		global $pgv_lang, $PGV_IMAGE_DIR, $PGV_IMAGES, $GEDCOM, $TEXT_DIRECTION, $INDEX_DIRECTORY, $MEDIA_DIRECTORY, $MULTI_MEDIA, $MEDIA_DIRECTORY_LEVELS, $command, $PGV_DATABASE, $indilist;

		$userfavs = getUserFavorites(getUserName());
		if (!is_array($userfavs)) $userfavs = array();
		print "<div id=\"user_favorites\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["my_favorites"]." &lrm;(".count($userfavs).")&lrm;</b>";
		print_help_link("mygedview_favorites_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<div class=\"blockcontent\">";
		if ($block) print "<div class=\"small_inner_block\">\n";
		if (count($userfavs)==0) {
		print $pgv_lang["no_favorites"];
		print "\n";
		} else {
		print "<table width=\"100%\" class=\"$TEXT_DIRECTION\">";
		$mygedcom = $GEDCOM;
		$current_gedcom = $GEDCOM;
		if ($block) $style = 1;
		else $style = 2;
		foreach($userfavs as $key=>$favorite) {
			if ($favorite["type"]=="INDI") {
				$current_gedcom = $GEDCOM;
				$GEDCOM = $favorite["file"];
				require $INDEX_DIRECTORY.$GEDCOM."_conf.php";
				if (($PGV_DATABASE == "index") and ($GEDCOM != $current_gedcom)) {
					$indexfile = $INDEX_DIRECTORY.$GEDCOM."_index.php";
					$fp = fopen($indexfile, "r");
					$fcontents = fread($fp, filesize($indexfile));
					fclose($fp);
					$lists = unserialize($fcontents);
					unset($fcontents);
					$indilist = $lists["indilist"];
					$current_gedcom = $GEDCOM;
				}
				$indirec = find_person_record($favorite["gid"]);
				print "<tr><td>";
				if (isset($favorite["id"])) $key=$favorite["id"];
				print "<div id=\"box".$favorite["gid"].".0\" class=\"person_box";
				if (preg_match("/1 SEX F/", $indirec)>0) print "F";
				else if (preg_match("/1 SEX M/", $indirec)>0) print "";
				else print "NN";
				print "\">\n";
				print_pedigree_person($favorite["gid"], $style, 1, $key);
				print "</div>\n";
				if ($command=="user" || userIsAdmin(getUserName())) print "<font size=\"1\"><a href=\"index.php?command=$command&amp;action=deletefav&amp;fv_id=".$key."\" onclick=\"return confirm('".$pgv_lang["confirm_fav_remove"]."');\">".$pgv_lang["remove"]."</a><br />\n";
				print "</td></tr>\n";
			}
		}
		$GEDCOM = $mygedcom;
		require $INDEX_DIRECTORY.$GEDCOM."_conf.php";
		if (($PGV_DATABASE == "index") and ($GEDCOM != $current_gedcom)) {
			$indexfile = $INDEX_DIRECTORY.$GEDCOM."_index.php";
			$fp = fopen($indexfile, "r");
			$fcontents = fread($fp, filesize($indexfile));
			fclose($fp);
			$lists = unserialize($fcontents);
			unset($fcontents);
			$indilist = $lists["indilist"];
		}
			print "</table>\n";
		}
	?>
<script language="JavaScript" type="text/javascript">
<!--
var pasteto;
function iopenfind(textbox) {
		pasteto = textbox;
		findwin = window.open('findid.php', '', 'left=50,top=50,width=450,height=450,resizable=1,scrollbars=1');
}
function paste_id(value) {
		pasteto.value=value;
		document.addfavform.submit();
}
//-->
</script>
<?php
		print "<form name=\"addfavform\" method=\"get\" action=\"index.php\">\n";
		print "<input type=\"hidden\" name=\"action\" value=\"addfav\" />\n";
		print "<input class=\"pedigree_form\" type=\"text\" name=\"gid\" size=\"3\" value=\"\" /><a href=\"#\" onclick=\"iopenfind(document.addfavform.gid); return false;\"> ".$pgv_lang["find_id"]."</a>";
		print " <input type=\"submit\" value=\"".$pgv_lang["add"]."\" style=\"font-size: 8pt; \" />\n";
		print "\n</form>\n";
		if ($block) print "</div>\n";
		print "</div>\n"; // content
		print "</div>";   // block
}

//-- function to print the welcome block
function print_welcome_block($block = true) {
		global $pgv_lang, $day, $month, $year, $PGV_IMAGE_DIR, $PGV_IMAGES, $user, $GEDCOM, $TIME_FORMAT,$command;

		print "<div id=\"user_welcome\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["welcome"]." ".$user["fullname"]."</b>";
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<table class=\"blockcontent\" cellspacing=\"0\" cellpadding=\"0\" style=\" width: 100%; direction:ltr;\"><tr>";
		print "<td class=\"tab_active_bottom\" colspan=\"3\" ></td></tr><tr>";
		if ($user["editaccount"]) {
			print "<td class=\"center details2\" style=\" width: 33%; clear: none; vertical-align: top; margin-top: 2px;\"><a href=\"edituser.php\"><img src=\"".$PGV_IMAGE_DIR."/".$PGV_IMAGES["indis"]["small"]."\" border=\"0\" alt=\"".$pgv_lang["myuserdata"]."\" /><br />".$pgv_lang["myuserdata"]."</a></td>";
		}
		if (!empty($user["gedcomid"][$GEDCOM])) {
			print "<td class=\"center details2\" style=\" width: 34%; clear: none; vertical-align: top; margin-top: 2px;\"><a href=\"pedigree.php?rootid=".$user["gedcomid"][$GEDCOM]."\"><img src=\"".$PGV_IMAGE_DIR."/".$PGV_IMAGES["pedigree"]["small"]."\" border=\"0\" /><br />".$pgv_lang["my_pedigree"]."</a></td>";
			print "<td class=\"center details2\" style=\" width: 33%; clear: none; vertical-align: top; margin-top: 2px;\"><a href=\"individual.php?pid=".$user["gedcomid"][$GEDCOM]."\"><img src=\"".$PGV_IMAGE_DIR."/".$PGV_IMAGES["indis"]["small"]."\" border=\"0\" /><br />".$pgv_lang["my_indi"]."</a>\n</td>";
		}
		print "</tr><tr><td class=\"center\" colspan=\"3\"><a href=\"#\" onclick=\"window.open('index_edit.php?name=".getUserName()."&amp;command=user', '', 'top=50,left=50,width=600,height=550,scrollbars=1,resizable=1');\">".$pgv_lang["customize_page"]."</a>\n";
		print_help_link("mygedview_customize_help", "qm");
		print "\n<br />".get_changed_date("$day $month $year")." - ".date($TIME_FORMAT, time()-$_SESSION["timediff"])."\n";
		print "</td>\n";
		print "</tr></table>"; // blockcontent
		print "</div>"; // block

}

//-- function to display a random picture from the gedcom
function print_random_media($block = true) {
		global $pgv_lang, $GEDCOM, $medialist, $MULTI_MEDIA, $TEXT_DIRECTION, $PGV_IMAGE_DIR, $PGV_IMAGES, $MEDIA_EXTERNAL, $MEDIA_DIRECTORY;

		if (!$MULTI_MEDIA) return;
		$medialist = array();

		get_media_list();
		$ct = count($medialist);
		if ($ct>0) {
				$disp = false;
				$i=0;
				while(!$disp && $i<10) {
						$index = rand(0,$ct-1);
						$value = $medialist[$index];
						$links = $value["link"];
						$disp = true;
						if (count($links) != 0){
							foreach($links as $id=>$type) {
									if ($type=="INDI") {
											$disp = $disp && displayDetailsByID($id);
									}
									else if ($type=="FAM") {
											$parents = find_parents($id);
											$disp = $disp && displayDetailsByID($parents["HUSB"]);
											$disp = $disp && displayDetailsByID($parents["WIFE"]);
									}
									else if ($type=="SOUR") {
											$disp = $disp && showFact("OBJE", $id);
									}
							}
						}
						$i++;
				}
				if (!$disp) return false;
				print "<div id=\"random_picture\" class=\"block\">";
				print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
				print "<td class=\"blockh1\" >&nbsp;</td>";
				print "<td class=\"blockh2\" ><div class=\"blockhc\">";
				print "<b>".$pgv_lang["random_picture"]."</b>";
				print_help_link("index_media_help", "qm");
				print "</div></td>";
				print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
				print "</table>";
				print "<div class=\"blockcontent\" >";
				if ($block) print "<div class=\"small_inner_block\">\n";
				$imgwidth = 300;
				$imgheight = 300;
				if (preg_match("'://'", $value["file"])) {
					$image_type = array("bmp", "gif", "jpeg", "jpg", "pcx", "png", "tiff");
					$path_end=substr($value["file"], strlen($value["file"])-5);
					$type=strtolower(substr($path_end, strpos($path_end, ".")+1));
					if (in_array($type, $image_type)){
					   $imgwidth = 400;
					   $imgheight = 500;
					} else {
					   $imgwidth = 800;
					   $imgheight = 400;
					}
				}
				else if ((preg_match("'://'", $MEDIA_DIRECTORY)>0)||(file_exists(filename_decode($value["file"])))) {
				   $imgsize = getimagesize(filename_decode($value["file"]));
				   if ($imgsize){
					   $imgwidth = $imgsize[0]+50;
					   $imgheight = $imgsize[1]+50;
				   }
				}
				print "<table id=\"random_picture_box\" width=\"95%\"><tr><td valign=\"top\"";

				if ($block) print " align=\"center\" class=\"details1\"";
				else print " class=\"details2\"";
				print " >";
				if (stristr($value["file"], "mailto:")){
					if ($MEDIA_EXTERNAL) print "<a href=\"".urlencode($value["file"])."\">";
				}
				else print "<a href=\"#\" onclick=\"return openImage('".urlencode($value["file"])."',$imgwidth, $imgheight);\">";
				if ($block) {
					if (file_exists(filename_decode($value["thumb"])) || strstr($value["thumb"], "://")) {
						print "<img src=\"".$value["thumb"]."\" border=\"0\" class=\"thumbnail\" alt=\"\" ";
						$imgsize = getimagesize(filename_decode($value["thumb"]));
						if ($imgsize[0] > 175) print "width=\"175\" ";
						print "/>";
					}
				}
				else {
					if (file_exists(filename_decode($value["file"])) || strstr($value["file"], "://")) {
						print "<img src=\"".$value["file"]."\" border=\"0\" class=\"thumbnail\" alt=\"\" ";
						$imgsize = getimagesize(filename_decode($value["file"]));
						if ($imgsize[0] > 175) print "width=\"175\" ";
						print "/>";
					}
				}
				if (!($MEDIA_EXTERNAL) && stristr($value["file"], "mailto:"));
				else print "</a>\n";
				if ($block) print "<br />";
				else print "</td><td class=\"details2\">";
				if (stristr($value["file"], "mailto:")){
					if ($MEDIA_EXTERNAL) print "<a href=\"".urlencode($value["file"])."\">";
				}
				else print "<a href=\"#\" onclick=\"return openImage('".urlencode($value["file"])."',$imgwidth, $imgheight);\">";
				if ($value["title"]!=$value["file"]) print "<b>".PrintReady($value["title"])."</b><br />";
				if (!($MEDIA_EXTERNAL) && stristr($value["file"], "mailto:"));
				else print "</a>";
				$links = $value["link"];
				if (count($links) != 0){
					foreach($links as $id=>$type) {
						if (($type=="INDI")&&(displayDetailsByID($id))) print " <a href=\"individual.php?pid=".$id."\">".$pgv_lang["view_person"]." -".PrintReady(get_person_name($id))."</a><br />";
						if ($type=="FAM") print " <a href=\"family.php?famid=".$id."\">".$pgv_lang["view_family"]." - ".PrintReady(get_family_descriptor($id))."</a><br />";
						if ($type=="SOUR") print " <a href=\"source.php?sid=".$id."\">".$pgv_lang["view_source"]." - ".PrintReady(get_source_descriptor($id))."</a><br />";
					}
				}
				print "<br /><div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
				print_fact_notes($value["gedcom"], $value["level"]);
				print "</div>";
				print "</td></tr></table>\n";
				if ($block) print "</div>\n";
				print "</div>"; // blockcontent
				print "</div>"; // block
		}
}

//-- function to print the gedcom block
function print_gedcom_block($block = true) {
		global $hits,$pgv_lang, $day, $month, $year, $GEDCOM, $GEDCOMS, $ALLOW_CHANGE_GEDCOM, $TIME_FORMAT,$SHOW_COUNTER, $command,$THEME_DIR,$TEXT_DIRECTION;


		print "<div id=\"gedcom_welcome\" class=\"block\" >\n";
		print "<table class=\"blockheader\" cellpadding=\"0\" cellspacing=\"0\" style=\"direction:ltr;padding:0;margin:0;\"><tr>";
		print "<td class=\"blockh1\" ></td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print PrintReady("<b>".$GEDCOMS[$GEDCOM]["title"]."</b>");	 
		print "</div></td>";
		print "<td class=\"blockh3\"></td></tr></table>\n";
		print "<div class=\"blockcontent\">";
		if (!$block) print "<table><tr><td>";
		print "<div class=\"center\">";
		print "<br />".get_changed_date("$day $month $year")." - ".date($TIME_FORMAT, time()-$_SESSION["timediff"])."<br />\n";
		if($SHOW_COUNTER)
				print "\n<br />".$pgv_lang["hit_count"]."  ".$hits."\n";
		print "\n<br />";
		if (!$block) print "</div></td><td><div class=\"center\">";
		if (userGedcomAdmin(getUserName())) {
				print "<a href=\"#\" onclick=\"window.open('index_edit.php?name=".preg_replace("/'/", "\'", $GEDCOM)."&amp;command=gedcom', '', 'top=50,left=50,width=600,height=550,scrollbars=1,resizable=1');\">".$pgv_lang["customize_gedcom_page"]."</a>\n";
		}
		print "</div>";
		if (!$block) print "</td></tr></table>";
		print "</div>\n";
		print "</div>";

}

//-- print gedcom favorites
function print_gedcom_favorites($block = true) {
		global $pgv_lang, $PGV_IMAGE_DIR, $PGV_IMAGES, $GEDCOM, $command;

		$userfavs = getUserFavorites($GEDCOM);
		if (!is_array($userfavs)) $userfavs = array();
		print "<div id=\"gedcom_favorites\" class=\"block\">\n";

		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["gedcom_favorites"]." &lrm;(".count($userfavs).")&lrm;</b>";
		print_help_link("index_favorites_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<div class=\"blockcontent\">";
		if ($block) print "<div class=\"small_inner_block\">\n";
		if (count($userfavs)==0) {
				if (userGedcomAdmin(getUserName())) print $pgv_lang["no_favorites"];
				else print $pgv_lang["no_gedcom_favorites"];
		}
		if ($block) $style = 1;
		else $style = 2;
		foreach($userfavs as $key=>$favorite) {
			if ($favorite["type"]=="INDI") {
				$indirec = find_person_record($favorite["gid"]);
				if (isset($favorite["id"])) $key=$favorite["id"];
				print "<div id=\"box".$favorite["gid"].".0\" class=\"person_box";
				if (preg_match("/1 SEX F/", $indirec)>0) print "F";
				else if (preg_match("/1 SEX M/", $indirec)>0) print "";
				else print "NN";
				print "\" style=\"position: static; left: 0px; top: auto; width: 99%; z-index: 1;\">\n";
				print_pedigree_person($favorite["gid"], $style, 1);
				if ($command=="user" || userGedcomAdmin(getUserName())) print "<font size=\"1\"><a href=\"index.php?command=$command&amp;action=deletefav&amp;fv_id=".$key."\" onclick=\"return confirm('".$pgv_lang["confirm_fav_remove"]."');\">".$pgv_lang["remove"]."</a><br />\n";
				print "</div>\n";
			}
		}
		if (userGedcomAdmin(getUserName())) { ?>
			<script language="JavaScript" type="text/javascript">
			var pasteto;
			function iopenfind(textbox) {
					pasteto = textbox;
					findwin = window.open('findid.php', '', 'left=50,top=50,width=450,height=450,resizable=1,scrollbars=1');
			}
			function paste_id(value) {
					pasteto.value=value;
					document.addfavform.submit();
			}
			</script>
			<?php
			print "<form name=\"addfavform\" method=\"get\" action=\"index.php\">\n";
			print "<input type=\"hidden\" name=\"action\" value=\"addfav\" />\n";
			print "<input type=\"hidden\" name=\"command\" value=\"$command\" />\n";
			print "<input class=\"pedigree_form\" type=\"text\" name=\"gid\" size=\"3\" value=\"\" /><font size=\"1\"><a href=\"#\" onclick=\"iopenfind(document.addfavform.gid); return false;\"> ".$pgv_lang["find_id"]."</a></font>";
			print " <input type=\"submit\" value=\"".$pgv_lang["add"]."\" style=\"font-size: 8pt; \" />\n";
			print "\n</form>\n";
		}
		if ($block) print "</div>\n";
		print "</div>"; // blockcontent
		print "</div>"; // block
}

//-- function to print the gedcom statistics block

function print_gedcom_stats($block = true) {
		global $pgv_lang, $day, $month, $year, $GEDCOM, $GEDCOMS, $ALLOW_CHANGE_GEDCOM, $command, $COMMON_NAMES_THRESHOLD;

		print "<div id=\"gedcom_stats\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["gedcom_stats"]."</b>";
		print_help_link("index_stats_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<div class=\"blockcontent\">";

		print "<b><a href=\"index.php?command=gedcom\">".PrintReady($GEDCOMS[$GEDCOM]["title"])."</a></b><br />\n";
		$head = find_gedcom_record("HEAD");
		$ct=preg_match("/1 SOUR (.*)/", $head, $match);
		if ($ct>0) {
			$softrec = get_sub_record(1, "1 SOUR", $head);
			$tt= preg_match("/2 NAME (.*)/", $softrec, $tmatch);
			if ($tt>0) $title = trim($tmatch[1]);
			else $title = trim($match[1]);
			if (!empty($title)) {
					$text = str_replace("#SOFTWARE#", $title, $pgv_lang["gedcom_created_using"]);
					$tt = preg_match("/2 VERS (.*)/", $softrec, $tmatch);
					if ($tt>0) $version = trim($tmatch[1]);
					else $version="";
					$text = str_replace("#VERSION#", $version, $text);
					print $text;
			}
		}
		$ct=preg_match("/1 DATE (.*)/", $head, $match);
		if ($ct>0) {
			$date = trim($match[1]);
			if (empty($title)) $text = str_replace("#DATE#", get_changed_date($date), $pgv_lang["gedcom_created_on"]);
			else $text = $text = str_replace("#DATE#", get_changed_date($date), $pgv_lang["gedcom_created_on2"]);
			print $text;
		}
		print "<br />\n";
		print "<b>".get_list_size("indilist")."</b> ".$pgv_lang["stat_individuals"]."\n";
		print "<b>".get_list_size("famlist")."</b> ".$pgv_lang["stat_families"]."\n";
				print "<b>".get_list_size("sourcelist")."</b> ".$pgv_lang["stat_sources"]."\n";
		print "<b>".get_list_size("otherlist")."</b> ".$pgv_lang["stat_other"]."<br />\n";
		$surnames = get_common_surnames_index($GEDCOM);
		if (count($surnames)>0) {
			print "<br /><b>".$pgv_lang["common_surnames"]."</b>";
			print_help_link("index_common_names_help", "qm");
			print "<br />\n";
			$i=0;
			foreach($surnames as $surname) {
				if ($i>0) {
					print ", ";
				}
				print "<a href=\"indilist.php?surname=".urlencode($surname["name"])."\">".PrintReady($surname["name"])."</a>";
				$i++;
			}
		}
		print "</div>\n";
		print "</div>";
}

/**
 * Print Login Block
 *
 * Prints a block allowing the user to login to the site directly from the portal
 */
function print_login_block($block = true) {
		global $pgv_lang, $GEDCOM, $GEDCOMS, $command, $PHP_SELF, $QUERY_STRING, $USE_REGISTRATION_MODULE, $LOGIN_URL;

		$uname = getUserName();
		if (!empty($uname)) return;
		print "<div id=\"login_block\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["login"]."</b>";
		if ($USE_REGISTRATION_MODULE) print_help_link("index_login_register_help", "qm");
		else print_help_link("index_login_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
		print "</table>";
		print "<div class=\"blockcontent\">";
		if (!$block) print "</td><td>";
		print "<div class=\"center\"><form method=\"post\" action=\"$LOGIN_URL\" name=\"loginform\" onsubmit=\"t = new Date(); document.loginform.usertime.value=t.getFullYear()+'-'+(t.getMonth()+1)+'-'+t.getDate()+' '+t.getHours()+':'+t.getMinutes()+':'+t.getSeconds(); return true;\">\n";
		print "<input type=\"hidden\" name=\"url\" value=\"index.php?command=$command&amp;\" />\n";
		print "<input type=\"hidden\" name=\"ged\" value=\"";if (isset($GEDCOM)) print $GEDCOM; print "\" />";
		print "<input type=\"hidden\" name=\"pid\" value=\"";if (isset($pid)) print $pid; print "\" />";
		print "<input type=\"hidden\" name=\"usertime\" value=\"\" />\n";
		print "<input type=\"hidden\" name=\"action\" value=\"login\" />\n";
		print "<table>";
		print "<tr><td>".$pgv_lang["username"]."</td><td><input type=\"text\" name=\"username\" size=\"15\" class=\"formField\" /></td></tr>\n";
		print "<tr><td>".$pgv_lang["password"]."</td><td><input type=\"password\" name=\"password\" size=\"15\" class=\"formField\" /></td></tr>\n";
		print "<tr><td colspan=\"2\" class=\"center\"><input type=\"submit\" value=\"".$pgv_lang["login"]."\" /></td></tr>\n";
		print "</table>\n";
		print "</form></div>\n";
		if (!$block) print "</td></tr></table>";
		print "<div class=\"center\">";
		if ($USE_REGISTRATION_MODULE){
				print $pgv_lang["no_account_yet"]."<br />";
				print "<a href=\"login_register.php?action=register\">".$pgv_lang["requestaccount"]."</a>";
				print_help_link("new_user_help", "qm");
		}

		print "<br /><br />";
		print $pgv_lang["lost_password"]."<br />";
		print "<a href=\"login_register.php?action=pwlost\">".$pgv_lang["requestpassword"]."</a>";
		print_help_link("new_password_help", "qm");
		print "</div>";
		print "</div>";
		print "</div>";
}

/**
 * Prints a user news/journal
 *
 */
function print_user_news($block = true) {
		global $pgv_lang, $PGV_IMAGE_DIR, $PGV_IMAGES, $TEXT_DIRECTION, $command, $TIME_FORMAT;

		$uname = getUserName();
		$usernews = getUserNews($uname);

		print "<div id=\"user_news\" class=\"block\">\n";
		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["my_journal"]."</b>";
		print_help_link("mygedview_myjournal_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>";
		print "</table>";
		print "<div class=\"blockcontent\">";
		if ($block) print "<div class=\"small_inner_block, $TEXT_DIRECTION\">\n";
		if (count($usernews)==0) print $pgv_lang["no_journal"];
		foreach($usernews as $key=>$news) {
				$day = date("j", $news["date"]);
				$mon = date("M", $news["date"]);
				$year = date("Y", $news["date"]);
				print "<div class=\"person_box\">\n";
				$ct = preg_match("/#(.+)#/", $news["title"], $match);
				if ($ct>0) {
						if (isset($pgv_lang[$match[1]])) $news["title"] = preg_replace("/$match[0]/", $pgv_lang[$match[1]], $news["title"]);
				}
				print "<span class=\"news_title\">".PrintReady($news["title"])."</span><br />\n";
				print "<span class=\"news_date\">".get_changed_date("$day $mon $year")." - ".date($TIME_FORMAT, $news["date"])."</span><br /><br />\n";
				$ct = preg_match("/#(.+)#/", $news["text"], $match);
				if ($ct>0) {
						if (isset($pgv_lang[$match[1]])) $news["text"] = preg_replace("/$match[0]/", $pgv_lang[$match[1]], $news["text"]);
				}
				$ct = preg_match("/#(.+)#/", $news["text"], $match);
				if ($ct>0) {
						if (isset($pgv_lang[$match[1]])) $news["text"] = preg_replace("/$match[0]/", $pgv_lang[$match[1]], $news["text"]);
						if (isset($$match[1])) $news["text"] = preg_replace("/$match[0]/", $$match[1], $news["text"]);
				}
				$trans = get_html_translation_table(HTML_SPECIALCHARS);
				$trans = array_flip($trans);
				$news["text"] = strtr($news["text"], $trans);
				$news["text"] = nl2br($news["text"]);
				print PrintReady($news["text"])."<br /><br />\n";
				print "<a href=\"#\" onclick=\"editnews('$key'); return false;\">".$pgv_lang["edit"]."</a> | ";
				print "<a href=\"index.php?action=deletenews&amp;news_id=$key&amp;command=$command\" onclick=\"return confirm('".$pgv_lang["confirm_journal_delete"]."');\">".$pgv_lang["delete"]."</a><br />";
				print "</div><br />\n";
		}
		if ($block) print "</div>\n";
		if (!empty($uname)) print "<br /><a href=\"#\" onclick=\"addnews('$uname'); return false;\">".$pgv_lang["add_journal"]."</a>\n";
		print "</div>\n";
		print "</div>";
}

/**
 * Prints a gedcom news/journal
 *
 * @todo Add an allowed HTML translation
 */
function print_gedcom_news($block = true) {
		global $pgv_lang, $PGV_IMAGE_DIR, $PGV_IMAGES, $TEXT_DIRECTION, $GEDCOM, $command, $TIME_FORMAT, $VERSION;

		$uname = getUserName();
		$usernews = getUserNews($GEDCOM);
		print "<div id=\"gedcom_news\" class=\"block\">\n";

		print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
		print "<td class=\"blockh1\" >&nbsp;</td>";
		print "<td class=\"blockh2\" ><div class=\"blockhc\">";
		print "<b>".$pgv_lang["gedcom_news"]."</b>";
		if (userGedcomAdmin(getUserName())){
				print_help_link("index_gedcom_news_ahelp", "qm_ah");
		}
				else print_help_link("index_gedcom_news_help", "qm");
		print "</div></td>";
		print "<td class=\"blockh3\">&nbsp;</td></tr>";
		print "</table>";
		print "<div class=\"blockcontent\">";

		if ($block) print "<div class=\"small_inner_block, $TEXT_DIRECTION\">\n";
		if (count($usernews)==0) print $pgv_lang["no_news"];
		foreach($usernews as $key=>$news) {
				$day = date("j", $news["date"]);
				$mon = date("M", $news["date"]);
				$year = date("Y", $news["date"]);
				print "<div class=\"person_box\">\n";
				$ct = preg_match("/#(.+)#/", $news["title"], $match);
				if ($ct>0) {
						if (isset($pgv_lang[$match[1]])) $news["title"] = preg_replace("/$match[0]/", $pgv_lang[$match[1]], $news["title"]);
				}
				print "<span class=\"news_title\">".PrintReady($news["title"])."</span><br />\n";
				print "<span class=\"news_date\">".get_changed_date("$day $mon $year")." - ".date($TIME_FORMAT, $news["date"])."</span><br /><br />\n";
				$ct = preg_match("/#(.+)#/", $news["text"], $match);
				if ($ct>0) {
						if (isset($pgv_lang[$match[1]])) $news["text"] = preg_replace("/$match[0]/", $pgv_lang[$match[1]], $news["text"]);
				}
				$ct = preg_match("/#(.+)#/", $news["text"], $match);
				if ($ct>0) {
						if (isset($pgv_lang[$match[1]])) $news["text"] = preg_replace("/$match[0]/", $pgv_lang[$match[1]], $news["text"]);
						$varname = $match[1];
						if (isset($$varname)) $news["text"] = preg_replace("/$match[0]/", $$varname, $news["text"]);
				}
				$trans = get_html_translation_table(HTML_SPECIALCHARS);
				$trans = array_flip($trans);
				$news["text"] = strtr($news["text"], $trans);
				$news["text"] = nl2br($news["text"]);
				print PrintReady($news["text"])."<br /><br />\n";
				if (userGedcomAdmin($uname)) {
						print "<a href=\"#\" onclick=\"editnews('$key'); return false;\">".$pgv_lang["edit"]."</a> | ";
						print "<a href=\"index.php?action=deletenews&amp;news_id=$key&amp;command=$command\" onclick=\"return confirm('".$pgv_lang["confirm_news_delete"]."');\">".$pgv_lang["delete"]."</a><br />";
				}
				print "</div><br />\n";
		}
		if ($block) print "</div>\n";
		if (userGedcomAdmin($uname)) print "<br /><a href=\"#\" onclick=\"addnews('".preg_replace("/'/", "\'", $GEDCOM)."'); return false;\">".$pgv_lang["add_news"]."</a>\n";
		print "</div>\n";
		print "</div>";

}

/**
 * print recent changes
 *
 * searches the gedcom for the most recent changes
 */
function print_recent_changes($block=true) {
		global $pgv_lang, $factarray, $month, $year, $day, $monthtonum, $HIDE_LIVE_PEOPLE, $SHOW_ID_NUMBERS, $command, $indilist, $TEXT_DIRECTION;
		global $PGV_IMAGES, $PGV_IMAGE_DIR;

		$monthstart = mktime(1,0,0,$monthtonum[strtolower($month)],$day,$year);
		$mmon = strtolower(date("M", $monthstart));
		$myindilist = array();
		$myfamlist = array();
		$mysourcelist = array();
		$query = "1 CHAN.*2 DATE[^\n]*[0-9]{1,2} $mmon $year";
		$myindilist = search_indis($query);
		$myfamlist = search_fams($query);
		$mysourcelist = search_sources($query);
		if ((count($myindilist)==0)&&(count($myfamlist)==0)&&(count($mysourcelist)==0)) {
				$mmon2 = $mmon;
				while($mmon2==$mmon) {
						$monthstart = $monthstart - (60*60*24);
						$mmon2 = strtolower(date("M", $monthstart));
				}
				$mmon = $mmon2;
				$year = (int)date("Y", $monthstart);
				$query = "1 CHAN.*2 DATE[^\n]*[0-9]{1,2} $mmon $year";
				$myindilist = search_indis($query);
				$myfamlist = search_fams($query);
				$mysourcelist = search_sources($query);
		}
		if ((count($myindilist)>0)||(count($myfamlist)>0)||(count($mysourcelist)>0)) {
				print "<div id=\"recent_changes\" class=\"block\">\n";
				print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
				print "<td class=\"blockh1\" >&nbsp;</td>";
				print "<td class=\"blockh2\" ><div class=\"blockhc\">";
				print "<b>".$pgv_lang["recent_changes"]."</b>";
				print_help_link("recent_changes_help", "qm");
				print "</div></td>";
				print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
				print "</table>";
				print "<div class=\"blockcontent\">";

				if ($block) print "<div class=\"small_inner_block\">\n";
				$oldmonth=$month;
				$oldyear = $year;
				$oldday = $day;
				for($k=0; $k<30; $k++) {
						$mday = date("j", $monthstart);
						$mmon = strtolower(date("M", $monthstart));
						$day = $mday;
						$year = (int)date("Y", $monthstart);
						if ($mmon!=strtolower($month)) {
								$query = "1 CHAN.*2 DATE[^\n]*[0-9]{1,2} $mmon $year";
								$myindilist = search_indis($query);
								$myfamlist = search_fams($query);
								$mysourcelist = search_sources($query);
								$month=$mmon;
						}
						$query = "2 DATE[^\n]*[^1-9]$mday $mmon $year";
						$dayindilist = array();
						foreach($myindilist as $gid=>$indi) {
								if (preg_match("/$query/i", $indi["gedcom"])>0) {
										if (displayDetailsById($gid)) $dayindilist[$gid]=$indi;
								}
						}
						$dayfamlist = array();
						foreach($myfamlist as $gid=>$fam) {
								if (preg_match("/$query/i", $fam["gedcom"])>0) {
										if (displayDetailsById($gid, "FAM")) $dayfamlist[$gid]=$fam;
								}
						}
						$daysourcelist = array();
						foreach($mysourcelist as $gid=>$source) {
								if (preg_match("/$query/i", $source["gedcom"])>0) {
										if (displayDetailsById($gid, "SOUR")) $daysourcelist[$gid]=$source;
								}
						}
						if ((count($dayindilist)>0)||(count($dayfamlist)>0)||(count($daysourcelist)>0)) {
								foreach($dayindilist as $gid=>$indi) {
										$names = preg_split("/,/", $indi["name"]);
										$indi["name"] = check_NN($names);
										$daytext = "<img src=\"$PGV_IMAGE_DIR/";
										if (preg_match("/1 SEX M/", $indi["gedcom"])>0) $daytext .= $PGV_IMAGES["sex"]["small"]."\" title=\"".$pgv_lang["male"]."\" alt=\"".$pgv_lang["male"];
										else  if (preg_match("/1 SEX F/", $indi["gedcom"])>0) $daytext .= $PGV_IMAGES["sexf"]["small"]."\" title=\"".$pgv_lang["female"]."\" alt=\"".$pgv_lang["female"];
										else $daytext .= $PGV_IMAGES["sexn"]["small"]."\" title=\"".$pgv_lang["sex"]." ".$pgv_lang["unknown"]."\" alt=\"".$pgv_lang["sex"]." ".$pgv_lang["unknown"];
										$daytext .= "\" class=\"sex_image\" />";
										print "<a href=\"individual.php?pid=$gid&amp;ged=".$indi["file"]."\"><b>".$daytext.PrintReady($indi["name"])."</b>";
										if ($SHOW_ID_NUMBERS) {
											if ($TEXT_DIRECTION=="ltr") 
												 print " &lrm;($gid)&lrm;";
											else print " &rlm;($gid)&rlm;";
										}										 
										print "</a><br />\n";
										print "<div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
										$factrec = get_sub_record(1, "1 CHAN", $indi["gedcom"]);
										$fact = "CHAN";
										if ((showFact($fact, $gid))&&(showFactDetails($fact, $gid))) {
												print $factarray[$fact];
												$ct = preg_match("/\d DATE (.*)/", $factrec, $match);
												if ($ct>0) {
														print " - <span class=\"date\">".get_changed_date($match[1]);
														$tt = preg_match("/3 TIME (.*)/", $factrec, $match);
														if ($tt>0) {
																print " - ".$match[1];
														}
														print "</span>\n";
												}
										}
										print "</div><br />";
								}
								foreach($dayfamlist as $gid=>$fam) {
										$names = preg_split("/[,+]/", $fam["name"]);
										$fam["name"] = check_NN($names);
										print "<a href=\"family.php?famid=$gid&amp;ged=".$fam["file"]."\"><b>".PrintReady($fam["name"])."</b>";
										if ($SHOW_ID_NUMBERS) {
											if ($TEXT_DIRECTION=="ltr") 
												 print " &lrm;($gid)&lrm;";
											else print " &rlm;($gid)&rlm;";
										}											  
										print "</a><br />\n";
										print "<div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
										$factrec = get_sub_record(1, "1 CHAN", $fam["gedcom"]);
										$ft = preg_match("/1\sCHAN/", $factrec, $match);
										$fact = "CHAN";
										if ((showFact($fact, $gid))&&(showFactDetails($fact, $gid))) {
												print $factarray[$fact];
												$ct = preg_match("/\d DATE (.*)/", $factrec, $match);
												if ($ct>0) {
														print " - <span class=\"date\">".get_changed_date($match[1]);
														$tt = preg_match("/3 TIME (.*)/", $factrec, $match);
														if ($tt>0) {
																print " - ".$match[1];
														}
														print "</span>\n";
												}
										}
										print "</div><br />";
								}
								foreach($daysourcelist as $gid=>$source) {
										print "<a href=\"source.php?sid=$gid&amp;ged=".$source["file"]."\"><b>".PrintReady($source["name"])."</b>"; 
										if ($SHOW_ID_NUMBERS) {
											if ($TEXT_DIRECTION=="ltr") 
												 print " &lrm;($gid)&lrm;";
											else print " &rlm;($gid)&rlm;";
										}											  
										print "</a><br />\n";
										print "<div class=\"indent" . ($TEXT_DIRECTION=="rtl"?"_rtl":"") . "\">";
										$factrec = get_sub_record(1, "1 CHAN", $source["gedcom"]);
										$fact = "CHAN";
										if ((showFact($fact, $gid))&&(showFactDetails($fact, $gid))) {
												print $factarray[$fact];
												$ct = preg_match("/\d DATE (.*)/", $factrec, $match);
												if ($ct>0) {
														print " - <span class=\"date\">".get_changed_date($match[1]);
														$tt = preg_match("/3 TIME (.*)/", $factrec, $match);
														if ($tt>0) {
																print " - ".$match[1];
														}
														print "</span>\n";
												}
										}
										print "</div><br />";
								}
						}
						$monthstart -= (60*60*24);
				}
				if ($block) print "</div>\n";
				$day = $oldday;
				$month = $oldmonth;
				$year = $oldyear;
				print "</div>\n";
		print "<br />\n";
		print "</div>";
		}
}

function print_block_theme_select($style=0){
		global $pgv_lang;
				print "<div id=\"theme_select\" class=\"block\">\n";
				print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
				print "<td class=\"blockh1\" >&nbsp;</td>";
				print "<td class=\"blockh2\" ><div class=\"blockhc\">";
				print "<b>".$pgv_lang["change_theme"]."</b>";
				print_help_link("change_theme", "qm");
				print "</div></td>";
				print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
				print "</table>";
				print "<div class=\"blockcontent\"><div class=\"center\"><br />";
						global $ALLOW_THEME_DROPDOWN, $ALLOW_USER_THEMES, $THEME_DIR, $pgv_lang, $themeformcount;

				if (!isset($themeformcount)) $themeformcount = 0;
				$themeformcount++;
				$uname = getUserName();
				$user = getUser($uname);
				isset($_SERVER["QUERY_STRING"]) == true?$tqstring = "?".$_SERVER["QUERY_STRING"]:$tqstring = "";
				$frompage = $_SERVER["PHP_SELF"].$tqstring;
				$themes = get_theme_names();
				print "<div class=\"theme_form\">\n";
				switch ($style) {
						case 0:
						print "<form action=\"themechange.php\" name=\"themeform$themeformcount\" method=\"post\">";
						print "<input type=\"hidden\" name=\"frompage\" value=\"".urlencode($frompage)."\" />";
						print "<select name=\"mytheme\" class=\"header_select\" onchange=\"document.themeform$themeformcount.submit();\">";
						print "<option value=\"\">".$pgv_lang["change_theme"]."</option>\n";
						foreach($themes as $themedir) {
								print "<option value=\"".$themedir["dir"]."\"";
								if ($uname) {
										if ($themedir["dir"] == $user["theme"]) print " class=\"selected-option\"";
								}
								else {
										 if ($themedir["dir"] == $THEME_DIR) print " class=\"selected-option\"";
								}
								print ">".$themedir["name"]."</option>\n";
						}
						print "</select></form>";
						break;
						case 1:
								$menu = array();
								$menu["label"] = $pgv_lang["change_theme"];
								$menu["labelpos"] = "left";
								$menu["link"] = "#";
								$menu["class"] = "thememenuitem";
								$menu["hoverclass"] = "thememenuitem_hover";
								$menu["flyout"] = "down";
								$menu["submenuclass"] = "favsubmenu";
								$menu["items"] = array();
								foreach($themes as $themedir) {
										$submenu = array();
										$submenu["label"] = $themedir["name"];
										$submenu["labelpos"] = "right";
										$submenu["link"] = "themechange.php?frompage=".$frompage."&amp;mytheme=".$themedir["dir"];
										$submenu["class"] = "favsubmenuitem";
										$submenu["hoverclass"] = "favsubmenuitem_hover";
										$menu["items"][] = $submenu;
								}
								print_menu($menu);
						break;
				}
				print "</div>\n";

				print "<br /></div></div>";
				print "</div>";
}

function print_block_name_top10 (){
		global $pgv_lang, $GEDCOM, $HNN;

		//-- cache the result in the session so that subsequent calls do not have to
		//-- perform the calculation all over again.
		if (isset($_SESSION["top10"][$GEDCOM])) {
			$surnames = $_SESSION["top10"][$GEDCOM];
		}
		else {
			$tindilist = get_indi_list();
			foreach($tindilist as $gid=>$indi) {
				$name = check_NN(trim($indi["name"]));
				if (stristr($name, $pgv_lang["NN"].",")===false && stristr($name, $HNN.",")===false) {
					$name = preg_replace(array("/ [jJsS][rR]\.?,/", "/ I+,/"), array(",",","), $name);
					$names = preg_split("/,/", $name);
					$surname = trim($names[0]);
					$surname = str2upper($surname);
					if (!isset($surnames[$surname])) {
						 $surnames[$surname] = array();
						 $surnames[$surname]["match"] = 1;
						 $surnames[$surname]["name"] = $names[0];
					}
					else {
						 $surnames[$surname]["match"]++;
					}
				}
			}
			arsort($surnames);
			$_SESSION["top10"][$GEDCOM] = $surnames;
		}
		if (count($surnames)>0) {
				print "<div id=\"top10\" class=\"block\">\n";
				print "<table class=\"blockheader\" cellspacing=\"0\" cellpadding=\"0\" style=\"direction:ltr;\"><tr>";
				print "<td class=\"blockh1\" >&nbsp;</td>";
				print "<td class=\"blockh2\" ><div class=\"blockhc\">";
				print "<b>".$pgv_lang["block_top10_title"]."</b>";
				print_help_link("index_common_names_help", "qm");
				print "</div></td>";
				print "<td class=\"blockh3\">&nbsp;</td></tr>\n";
				print "</table>";
				print "<div class=\"blockcontent\"><table width=\"100%\">";
				$i=0;
				foreach($surnames as $surname) {
						print "<tr><td class=\"name2\">&nbsp;- <a href=\"indilist.php?surname=".urlencode($surname["name"])."\">".PrintReady($surname["name"])."</a></td><td align=\"right\">[".$surname["match"]."]&nbsp;</td></tr>";
					$i++;
					if ($i>9) break;
				}
				print "</table>";
				print "</div>";
				print "</div>";
		}
}


?>
