<!DOCTYPE html>
<html lang="la">
<head>
	<title>Index generalis Vocis Latinae – Epistulas eligere</title>
	<meta name="author" content="Bernd Platzdasch"><!-- 2.3.2015 // 22.6.2015 -->
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<link rel="stylesheet" type="text/css" href="css/sev.css">
	<script type="text/javascript" src="js/jquery-1.11.2.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="js/jquery-ui-1.11.4.custom/jquery-ui.min.js"></script>
	<link rel="stylesheet" type="text/css" href="js/jquery-ui-1.11.4.custom/jquery-ui.css">
	<script src="js/store.js" type="text/javascript"></script>
	<style type="text/css">
		li.ui-menu-item { font-size: small !important; }
		#dig1, #dig2, #annus1, #annus2, #ord { width: 12em; }
	</style>
	<?php
// Debugging:
// error_reporting(E_ALL);
// ini_set('display_errors', true);	

		include("php/sql_select.inc.php");
		include("php/namen.inc.php");
		function ort_ausgeben($ort) {
			$ort = trim($ort);
			if ($ort != "") {
				$x = substr_count($ort, "=");
				if ($x >= 1) {
					$alle_namen_arr = explode(" = ", $ort);
					$erster_name = array_shift($alle_namen_arr);
					sort($alle_namen_arr);
					$alle_namen = implode(" = ", $alle_namen_arr);
					$res = $erster_name . "<span style='color:gray;'> = " . $alle_namen . "</span>";
				} else {$res = $ort;}
			}
			return $res;
		}
		$PHP_SELF = $_SERVER ["PHP_SELF"];
		// "0" = Skript wird erstmals aufgerufen:
		if (!isset($_POST ["sent"])) { $sent = 0; } else { $sent = 1; }
		// Automatische Suche über Klick gestatten:
// 		$sent = 1;
		$auto = 0;
		if (isset($_POST ["mittens"])) { $mittens = $_POST ["mittens"];} else { if (isset($_GET ["mittens"])) { $mittens = $_GET ["mittens"]; $auto = 1; } else { $mittens=""; } }
		$annus1= (isset($_POST ["annus1"])) ? $_POST ["annus1"] : "";
		$annus2= (isset($_POST ["annus2"])) ? $_POST ["annus2"] : "";
		$locus= (isset($_POST ["locus"])) ? $_POST ["locus"] : "";
		if (isset($_POST ["accipiens"])) { $accipiens = $_POST ["accipiens"]; } else { if (isset($_GET ["accipiens"])) { $accipiens = $_GET ["accipiens"]; $auto = 1; } else { $accipiens=""; } }
		$dig1 = (isset($_POST ["dig1"])) ? $_POST ["dig1"] : "";
		$dig2 = (isset($_POST ["dig2"])) ? $_POST ["dig2"] : "";
		$ord = (isset($_POST ["ord"])) ? $_POST ["ord"] : "ASC";
		//
		$sel = (isset($_POST ["sel"])) ? $_POST ["sel"] : 1;
		$bl = (isset($_POST ["bl"])) ? $_POST ["bl"] : "";
		$anf = (isset($_POST ["anf"])) ? $_POST ["anf"] : "";
		$zur = (isset($_POST ["zur"])) ? $_POST ["zur"] : "";
		$vor = (isset($_POST ["vor"])) ? $_POST ["vor"] : "";
		$end = (isset($_POST ["end"])) ? $_POST ["end"] : "";
		//
		if (($bl == "l◄") AND ($anf != "")) { $sel = 1; }
		if (($bl == "►") AND ($vor != "")) { $sel = $vor; }
		if (($bl == "◄") AND ($zur != "")) { $sel = $zur; }
		if (($bl == "►l") AND ($end != "")) { $sel = $end; }
		//
		$mittens = addslashes($mittens);
		$locus = addslashes($locus);
		$accipiens = addslashes($accipiens);
		$anz_angezeigte = 0;
		//
		require_once $_SERVER['DOCUMENT_ROOT'] . '/db_connection.php';
		//
		$sql_select_dis = "SELECT DISTINCT Briefdatum, sorBriefdatum FROM voxlatina WHERE Textgattung='Epistula' ORDER BY sorBriefdatum";
		$sql_result_dis = $db->query($sql_select_dis);
		$arrDatum = array();
            while ($row_dis = $sql_result_dis->fetch_object()) {
                $datum = $row_dis->Briefdatum;
                array_push($arrDatum, $datum);
            }
		 if ($sent == 1) {
			//
			$colBriefempfaenger = "style='background-color: #fff; color: #000;'";
			$colOrt = "style='background-color: #fff; color: #000;'";
			$colAutor = "style='background-color: #fff; color: #000;'";
			$colBriefdatum = "style='background-color: #fff; color: #000;'";
			$colFaszikel = "style='background-color: #fff; color: #000;'";
			$bgcolor = "style='background-color: #f4f4f4; color: green;'";
			switch ($dig1) {
				case "Autor": $colAutor = $bgcolor; break;
				case "sorBriefdatum": $colBriefdatum = $bgcolor; break;
				case "Ort": $colOrt = $bgcolor; break;
				case "Briefempfaenger": $colBriefempfaenger = $bgcolor; break;
				case "Faszikel,Objektzaehler": $colFaszikel = $bgcolor; break;
			}
			//
			if(($annus1 == "") AND ($annus2 == "")) {
				$sql_select_vgl = "";
			} else {
				$vgl_annus1 = implode("", (array_reverse(explode(".", $annus1))));
				$vgl_annus2 = implode("", (array_reverse(explode(".", $annus2))));
				if($vgl_annus1 <= $vgl_annus2) {
					$sql_select_vgl = "AND (sorBriefdatum >= '$vgl_annus1') AND (sorBriefdatum <= '$vgl_annus2') ";
				}
				if ($vgl_annus1 >= $vgl_annus2) {
					$sql_select_vgl = "AND (sorBriefdatum >= '$vgl_annus2') AND (sorBriefdatum <= '$vgl_annus1') ";
				}
				if (($vgl_annus1 != "") AND ($vgl_annus2 == "")) {
					$sql_select_vgl = "AND (sorBriefdatum = '$vgl_annus1')";
				}
				if (($vgl_annus1 == "") AND ($vgl_annus2 != "")) {
					$sql_select_vgl = "AND (sorBriefdatum = '$vgl_annus2')";
				}
			}
			$digest1 = $dig1;
			$digest2 = $dig2;
			if ($digest1 == "Faszikel,Objektzaehler") { $digest1 = "Faszikel " . $ord . ", Objektzaehler"; }
			if ($digest2 == "Faszikel,Objektzaehler") { $digest2 = "Faszikel " . $ord . ", Objektzaehler"; }
			$sql_order_by = "ORDER BY " . $digest1 . " " . $ord;
			 if ($digest2 != "") { $sql_order_by = $sql_order_by . ", " . $digest2 . " " . $ord; }
			 //
			// Vorteil über LEFT JOIN: auch nach den Originalnamen kann gesucht werden.
			$sql_select = "SELECT * FROM voxlatina AS v
			LEFT JOIN voxlatina_namen AS vna ON v.AutorID = vna.NameID
			LEFT JOIN voxlatina_namen AS vnb ON v.BriefempfaengerID = vnb.NameID
			WHERE
			(Textgattung = 'Epistula' OR Textgattung ='Telegraphema') AND (Ort LIKE '%$locus%')";
			$sql_select = sql_select($mittens, "vna", $sql_select, "A");
			$sql_select = sql_select($accipiens, "vnb", $sql_select, "A");
			//
			$sql_select = $sql_select . $sql_select_vgl . $sql_order_by;
			$sql_result = $db->query($sql_select);
			//
			$treffer = "";
			$insgesamt = $sql_result->num_rows;
			switch ($insgesamt) {
				case 0: $treffer = "Ne una quidem epistula!";
				break;
				case 1: $treffer = "1 epistula!";
				break;
				default: $treffer = $insgesamt . " epistulae!";
			}
		 } else {
			$insgesamt = "0";
			$range = "0";
		}
	?>
	<script type="text/javascript">
 		function formularNeu() {
			window.location.href = "epistulae.php";
			sessionStorage.clear();
		}
		function formenInit() {
			store_mnu();
			if((sessionStorage.getItem("ID") == "epistulae") && (sessionStorage.length >= "1")) {
				var mittens = sessionStorage.getItem("mittens");
				var locus = sessionStorage.getItem("locus");
				var accipiens = sessionStorage.getItem("accipiens");
				var annus1 = sessionStorage.getItem("annus1");
				var annus2 = sessionStorage.getItem("annus2");
				var dig1 = sessionStorage.getItem("dig1");
				var dig2 = sessionStorage.getItem("dig2");
				var ord = sessionStorage.getItem("ord");
			} else {
				var mittens =  "<?php echo $mittens ?>";
				var locus =  "<?php echo $locus ?>";
				var accipiens = "<?php echo $accipiens ?>";
				var annus1 = "<?php echo $annus1 ?>";
				var annus2 = "<?php echo $annus2 ?>";
				var dig1 = "<?php echo $dig1 ?>";
				var dig2 =  "<?php echo $dig2 ?>";
				var ord =  "<?php echo $ord ?>";
			}
			sessionStorage.clear();
			document.form1.mittens.value = mittens;
			document.form1.locus.value = locus;
			document.form1.accipiens.value = accipiens;
			temp = annus1;
			for (i = 0; i < document.getElementById("annus1").length; ++i) {
				if (document.getElementById("annus1").options[i].value == temp) {
					document.form1.annus1[i].selected = "true";
				}
			}
			temp = annus2;
			for (i = 0; i < document.getElementById("annus2").length; ++i) {
				if (document.getElementById("annus2").options[i].value == temp) {
					document.form1.annus2[i].selected = "true";
				}
			}
			// Sortierreihenfolge1:
			sor_arr = new Array("Autor", "sorBriefdatum", "Ort", "Briefempfaenger", "Faszikel,Objektzaehler");
			temp = dig1;
			for (i = 0; i < sor_arr.length; i++) {
				if(sor_arr[i] == temp) {
					document.form1.dig1[i].selected = "true";
				}
			}
			// Sortierreihenfolge2:
			sor_arr = new Array("","Autor", "sorBriefdatum", "Ort", "Briefempfaenger", "Faszikel,Objektzaehler");
			temp = dig2;
			for (i = 0; i < sor_arr.length; i++) {
				if(sor_arr[i] == temp) {
					document.form1.dig2[i].selected = "true";
				}
			}
			// Sortierrichtung:
			sor_arr = new Array( "ASC", "DESC");
			temp = ord;
			for (i = 0; i < sor_arr.length; i++) {
				if(sor_arr[i] == temp) {
					document.form1.ord[i].selected = "true";
				}
			}
			document.getElementById("defaultActionButton").focus();
		}
		var optionen = new Array(); // G L O B A L !
		function createDatenseiten() {
			if("<?php echo $sent ?>" == "1") {
				if ( "<?php echo $insgesamt ?>" > 0) {
					var insgesamt = "<?php echo $insgesamt ?>";
					var range=30;
					var rest = insgesamt % range;
					var divi = insgesamt / range;
					if (rest == 0) {
						var ganz = insgesamt / range;
					} else {
						var ganz = vorkomma(divi);
						ganz = ganz - 0; // wieder in Zahl umwandeln
					}
					for (var i=1; i <= ganz; i++) {
						var wert1 = ((i * range) - range) + 1;
						optionen.push(wert1);
						var wert2 = (i * range);
						optionen.push(wert2);
					}
					if (rest != 0) {
						wert1 = (ganz * range) + 1;
						optionen.push(wert1);
						wert2 = (ganz * range) + rest;
						optionen.push(wert2);
					}
					var laenge = optionen.length;
					for (var i=0; i < laenge; i++) {
						var newOpt = document.createElement("option");
						var f1 = optionen[i];
						var f2 = optionen[i+1];
						f1 != f2 ? txt = f1 + "–" + f2 : txt = f1;
						var newTxt = document.createTextNode(txt);
						newOpt.setAttribute("value", optionen[i]);
						document.form2.sel.appendChild(newOpt);
						newOpt.appendChild(newTxt);
						i++;
					}
					for (var i=0; i < laenge; i++) {
						var newOpt = document.createElement("option");
						var f1 = optionen[i];
						var f2 = optionen[i+1];
						f1 != f2 ? txt = f1 + "–" + f2 : txt = f1;
						var newTxt = document.createTextNode(txt);
						newOpt.setAttribute("value", optionen[i]);
						document.form3.sel.appendChild(newOpt);
						newOpt.appendChild(newTxt);
						i++;
					}
					for (i = 0; i < optionen.length; i++) {
						if(optionen[i] == "<?php echo $sel ?>") {
							break;
						}
					}
					if("<?php echo $insgesamt ?>" > 30) {
						document.form2.sel[i/2].selected = "true";
						document.form3.sel[i/2].selected = "true";
					}
					if("<?php echo $insgesamt ?>" >= 5) {
						document.getElementById("sursum").style.display = "block";
					}
				}
			}
		}
		function vorkomma(z) {
			var s = z.toString();
			var p = s.indexOf(".");
			return s.substr(0, p);
		}
		function autosuche() {
			if ("<?php echo $auto ?>" == 1) {
				document.form1.submit();
			}
		}
		function storeSS(id) {
			sessionStorage.clear();
			sessionStorage.setItem("ID", "epistulae");
			var arr_keys = new Array ( "mittens", "locus", "accipiens", "annus1", "annus2", "dig1", "dig2", "ord");
			for(var i=0; i < arr_keys.length; i++) {
				if(arr_keys[i] == id){
					arr_keys.splice(i, 1);
				}
			}
			for (var i=0; i < arr_keys.length; i++) {
				var value = document.getElementById(arr_keys[i]).value;
				var key = arr_keys[i];
				sessionStorage.setItem(key, value);
			}
			if (id == "mittens") {
				document.location.href = "idx_epi_mit.php";
			}
			if (id == "locus") {
				document.location.href = "idx_epi_loc.php";
			}
			if (id == "accipiens") {
				document.location.href = "idx_epi_acc.php";
			}
 		}
	</script>
</head>
<body onLoad="formenInit(); autosuche();">
<?php
	include("header.inc.php");
// 	include("php/erster_name.inc.php");
// 	include("php/vorname_nachname.inc.php");
	include("php/ds_mnu.inc.php");
?>
	<div class="border">
		<div id="main">
			<h1>Epistulas eligere</h1>
			<div class="quaestio">
				<form name="form1" action="<?php echo $PHP_SELF ?>" method="POST">
					<table style="margin-left: 5.7em;">
						<tr>
							<td class="label">
								<span title="Nomen eius, qui epistulam misit.">MITTENS:</span>
							</td>
							<td>
								<input class="strg" type="search" name="mittens" id="mittens">
							</td>
							<td>
								<input class="indexbutton" type="button"  onClick="storeSS('mittens');" value="Index&thinsp;&hellip;">
							</td>
						</tr>
						<tr>
							<td class="label">
								<span title="Dies aut spatium temporis, quo epistula scripta est.">Dies:</span>
							</td>
							<td>
								<select id="annus1" name="annus1">
									<option value="">&nbsp;</option>
									<?php
										for ($x = 1, $c = count($arrDatum); $x < $c; $x++) {
											echo "<option value=\"$arrDatum[$x]\">$arrDatum[$x]</option>";
										}
									?>
								</select> —
								<select id="annus2" name="annus2">
									<option value="">&nbsp;</option>
									<?php
										for ($x = 1, $c = count($arrDatum); $x < $c; $x++) {
											echo "<option value=\"$arrDatum[$x]\">$arrDatum[$x]</option>";
										}
									?>
								</select>
							</td>
							<td>&#160;</td>
						</tr>
						<tr>
							<td class="label">
								<span title="Locus, unde epistula missa est.">Locus:</span>
							</td>
							<td >
								<input class="strg" type="search" name="locus" id="locus">
							</td>
							<td>
								<input class="indexbutton" type="button" onClick="storeSS('locus');" value="Index&thinsp;&hellip;">
							</td>
						</tr>
						<tr>
							<td class="label">
								<span title="Nomen eius, qui epistulam accepit.">ACCIPIENS:</span>
							</td>
							<td style="padding-bottom: 0.5em;">
								<input class="strg" type="search" name="accipiens" id="accipiens">
							</td>
							<td>
								<input class="indexbutton" type="button" onClick="storeSS('accipiens');" value="Index&thinsp;&hellip;">
							</td>
						</tr>
						<tr>
							<td style="padding-top:0.5em;" class="label">
								Ordo:
							</td>
							<td style="padding-top: 0.5em;">
								<select id="dig1" name="dig1">
									<option value="Autor">Mittens</option>
									<option value="sorBriefdatum">Dies</option>
									<option value="Ort">Locus</option>
									<option value="Briefempfaenger">Accipiens</option>
									<option value="Faszikel,Objektzaehler" selected>Fasciculus</option>
								</select> —
								<select id="dig2" name="dig2">
									<option value="">&nbsp;</option>
									<option value="Autor">Mittens</option>
									<option value="sorBriefdatum">Dies</option>
									<option value="Ort">Locus</option>
									<option value="Briefempfaenger">Accipiens</option>
									<option value="Faszikel,Objektzaehler">Fasciculus</option>
								</select>
							</td>
							<td>&#160;</td>
						</tr>
						<tr>
							<td class="label">
								&#160;
							</td>
							<td>
								<select id="ord" name="ord">
									<option value="ASC" selected>A — Z</option>
									<option value="DESC">Z — A</option>
								</select>
							</td>
							<td>&#160;</td>
						</tr>
						<tr>
							<td>&#160;</td>
							<td>
								<input type="hidden" name="bl" value="l◄">
								<input type="hidden" name="bl" value="◄">
								<input type="hidden" name="bl" value="►">
								<input type="hidden" name="bl" value="►l">
								<input type="hidden" name="anf" value="">
								<input type="hidden" name="zur" value="">
								<input type="hidden" name="vor" value="">
								<input type="hidden" name="end" value="">
								<input type="hidden" name="sent" value="<?php echo $sent ?>">
								<input id="denuo" type="button" class="button" value="Delere" onClick="formularNeu();">
								<input id="defaultActionButton" type="submit" class="button" value="Eligere">
							</td>
							<td>&#160;</td>
						</tr>
					</table>
				</form>
				<p id="treffer">&#160;<!-- &#160; wichtig! -->
					<?php if ($sent == 1) {echo $treffer;} ?>
				</p>
		</div>
		<?php
			// Bei Treffer = 0 wenigstens die Einträge von form1 weitergeben:
			if ($insgesamt == 0) {
				echo "<form id='form2' name='form2' action=' $PHP_SELF' method='POST'>
					<input type='hidden' name='mittens' value='$mittens'>
					<input type='hidden' name='annus1' value='$annus1'>
					<input type='hidden' name='annus2' value='$annus2'>
					<input type='hidden' name='locus' value='$locus'>
					<input type='hidden' name='accipiens' value='$accipiens'>
					<input type='hidden' name='dig1' value='$dig1'>
					<input type='hidden' name='dig2' value='$dig2'>
					<input type='hidden' name='ord' value='$ord'>
					<input type='hidden' name='sent' value='$sent'>
				</form>";
			}
			// A U S G A B E :
			if ($insgesamt > 0) {
				// B u t t o n n a v i g a t i o n 1 :
				echo "
					<form id='form2' name='form2' style='visibility: hidden;' action='$PHP_SELF' method='POST'>
						<input class='inp_nav' type='submit' name='bl' value='l◄'>
						<input class='inp_nav' type='submit' name='bl' value='◄'>
						<input class='inp_nav' type='submit' name='bl' value='►'>
						<input class='inp_nav' type='submit' name='bl' value='►l'>
						<input type='hidden' name='anf'>
						<input type='hidden' name='zur'>
						<input type='hidden' name='vor'>
						<input type='hidden' name='end'>
						<input type='hidden' name='mittens' value='$mittens'>
						<input type='hidden' name='annus1' value='$annus1'>
						<input type='hidden' name='annus2' value='$annus2'>
						<input type='hidden' name='locus' value='$locus'>
						<input type='hidden' name='accipiens' value='$accipiens'>
						<input type='hidden' name='dig1' value='$dig1'>
						<input type='hidden' name='dig2' value='$dig2'>
						<input type='hidden' name='ord' value='$ord'>
						 <input type='hidden' name='sent' value='$sent'>
						<select name='sel' style='width:8.8em; margin-left: 1em;' onChange='document.form2.submit();'></select>
					</form>
				";
				// A u s g a b e t a b e l l e :
				echo "<p style='clear:both; height: 6px;'>&#160;</p>";
				echo "<table id='ausgabe'>";
					// sql-limit
					$zaehler = $sel;
					$range=30;
					$firstrun = 1;
					if ($insgesamt < 30) { $range = 0; }
					$sel--;
					if ($insgesamt >= 30) { $sql_limit = "LIMIT $sel, $range"; } else { $sql_limit =""; }
					$sql_select = "$sql_select $sql_limit";
					//
					$sql_result = $db->query($sql_select);
					$anz_angezeigte = $sql_result->num_rows;
					//
					while ($row = $sql_result->fetch_object()) {
						$BN = $BL = "";
						if ($firstrun == 1) { $firstrun = 0; } else { echo "<tr><td colspan='3'><p class='sep'></p> </td></tr>"; }
						$IID = $row->IID;
						$Bid = $row->BriefempfaengerID;
						$bis = $row->Bis;
						$p = $row->Seite != "" ? ", p. " : "";
						if ($bis != "") { $bis = "–" . $bis; $p = ", pp. "; }
						$sql_select_2 = "SELECT * FROM voxlatina_namen WHERE NameID = '$Bid'";
						$sql_result_2 = $db->query($sql_select_2);
						while ($row_2 = $sql_result_2->fetch_object()) {
							$BN = $row_2->Originalname; $BL= htmlspecialchars($row_2->extLink);
						}
						$Aid = $row->AutorID;
						$sql_select_3 = "SELECT * FROM voxlatina_namen WHERE NameID = '$Aid'";
						$sql_result_3 = $db->query($sql_select_3);
						while ($row_3 = $sql_result_3->fetch_object()) {
							$AN = $row_3->Originalname; $AL= htmlspecialchars($row_3->extLink);
						}
						$nil = "<span style='color: gray;'> –&thinsp;·&thinsp;–&thinsp;·&thinsp;– </span>";
						$BE = namen_ausgeben($row->Briefempfaenger, $BN, $BL, $nil);
						$AU = namen_ausgeben($row->Autor, $AN, $AL, $nil);
						if (trim($row->Ort) != "") $OR = ort_ausgeben($row->Ort); else $OR = $nil;
						if (trim($row->Briefdatum) != "") $BD = $row->Briefdatum; else $BD = $nil;
// 						if ($AU != $nil) {
							echo "<tr><td class='zaehler'>$zaehler.</td><td class='labelausg'>Mittens:</td><td $colAutor>$AU</td></tr>";
// 						}
// 						if ($BD != $nil) {
							echo "<tr><td>&#160;</td><td class='labelausg'>Dies:</td><td $colBriefdatum>$BD</td></tr>";
// 						}
// 						if ($OR != $nil) {
							echo "<tr><td>&#160;</td><td class='labelausg'>Locus:</td><td $colOrt>$OR</td></tr>";
// 						}
// 						if ($BE != $nil) {
							echo "<tr><td>&#160;</td><td class='labelausg'>Accipiens:</td><td $colBriefempfaenger>$BE</td></tr>";
// 						}
						echo "<tr><td>&#160;</td><td class='labelausg'>Fasciculus:</td><td $colFaszikel>fasc. $row->Faszikel ";
						echo "(tom. $row->Band, a. $row->Jahr)" . $p . $row->Seite . $bis . "</td></tr>";
						echo "<tr><td >&#160;</td><td class='labelausg'>&#160;</td>";
						ds_mnu($IID, $row->Faszikel, $row->Seite, $navigatrum);
						$zaehler++;
					}
				echo "</table>";
				// B u t t o n n a v i g a t i o n 2 :
				echo "
					<form id='form3' name='form3' style='visibility: hidden;' action='$PHP_SELF' method='POST'>
						<input class='inp_nav' type='submit' name='bl' value='l◄'>
						<input class='inp_nav' type='submit' name='bl' value='◄'>
						<input class='inp_nav' type='submit' name='bl' value='►'>
						<input class='inp_nav' type='submit' name='bl' value='►l'>
						<input type='hidden' name='anf'>
						<input type='hidden' name='zur'>
						<input type='hidden' name='vor'>
						<input type='hidden' name='end'>
						<input type='hidden' name='mittens' value='$mittens'>
						<input type='hidden' name='annus1' value='$annus1'>
						<input type='hidden' name='annus2' value='$annus2'>
						<input type='hidden' name='locus' value='$locus'>
						<input type='hidden' name='accipiens' value='$accipiens'>
						<input type='hidden' name='dig1' value='$dig1'>
						<input type='hidden' name='dig2' value='$dig2'>
						<input type='hidden' name='ord' value='$ord'>
						 <input type='hidden' name='sent' value='$sent'>
						<select name='sel' style='width:8.8em; margin-left: 1em;' onChange='document.form3.submit();'></select>
					</form>";
			}
			$db->close();
		?>
		<p id="sursum"><a href="javascript: window.scrollTo(0, 0);"><b>sursum</b></a></p>
		<p>&#160;</p>
	</div>
</div>
<?php include("footer.inc.php"); ?>
<script>
	// Eingabetaste ruft defaultActionButton auf
	$(document).ready(function() {
		$("#mittens").autocomplete({
			source: 'auto_epi.php?db_feld=Autor',
			minLength: 3,
			delay: 500
		});
		$("#accipiens").autocomplete({
			source: 'auto_epi.php?db_feld=Briefempfaenger',
			minLength: 3,
			delay: 500
		});
		$("#locus").autocomplete({
			source: 'auto_epi.php?db_feld=Ort',
			minLength: 3,
			delay: 500
		});
		$("input").bind("keydown", function(event) {
			var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
			if (keycode == 13) {
				document.getElementById('defaultActionButton').click();
				return false;
			} else {
				return true;
			}
		});

		// Seitenaufbau
		createDatenseiten();
		if(("<?php echo $sent ?>" == 1) && ("<?php echo $insgesamt ?>" > 0)) {
			document.form2.anf.value = 0;
			document.form3.anf.value = 0;
			var end = <?php echo $sel ?> + <?php echo $range ?> + 1;
			if (end > optionen[optionen.length-2]) { end = 1; }
			document.form2.vor.value = end ;
			document.form3.vor.value = end ;
			var zur = <?php echo $sel ?> - <?php echo $range ?> + 1;
			if (zur < 0) { zur = 1; }
			document.form2.zur.value = zur;
			document.form3.zur.value = zur;
			document.form2.end.value = optionen[optionen.length-2];
			document.form3.end.value = optionen[optionen.length-2];
		}
		if("<?php echo $insgesamt ?>" <= 30) {
			$("#ausgabe").css("margin-top", "0");
		}
		if("<?php echo $insgesamt ?>" > 30) {
			$("form[name=form2]").css("visibility", "visible");
		}
		if(("<?php echo $insgesamt ?>" > 30) && ("<?php echo $anz_angezeigte ?>" > 5)) { $("form[name=form3]").css("visibility", "visible"); }
		if("<?php echo $anz_angezeigte ?>" < 5) { $("#sursum").css("display", "none"); }
	});
</script>
</body>
</html>
