<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
	
		<title>Los Angeles Stadt der Engel</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel='stylesheet' media='all' type="text/css" href="stylesheet.css" />
		<style type="text/css"></style>
	</head>
    
    <body onload="load()" onunload="GUnload()">
	<script
		src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzosMcEBJXrsEQFGBQAWclRQgU1QyBe_kcGDWdfFXsq08_1MSqxREpHLDVDDm5p9ub3kwCQeYethC1w"
		type="text/javascript">
	</script>

		<?php

		//Connect with database
		require_once("db_connection.php");

		//If value is submitted, show choosen line on map
    	if (array_key_exists('stops',$_GET)) {
    		$stops = $_GET['stops'];
	    	echo "<p>Sie haben <b>$stops</b> ausgewählt.</p>\n";
	   		$sql = "SELECT lat, lon, name FROM stops WHERE name='".$stops."'";
			$result = mysql_query($sql) OR die("Mist! ". mysql_error());
         if (mysql_num_rows($result)<>0) {
			$rows = mysql_num_rows($result);
			$cols = mysql_num_fields($result);
			
			for($r=0; $r< $rows; $r++) {
				$xobj[$r] = mysql_result($result, $r, 0);
				$yobj[$r] = mysql_result($result, $r, 1);
				$nobj[$r] = mysql_result($result, $r, 2);
			}
	 	
		
		//Javascript part to show set attributes in map
		mysql_free_result($result);
		$zoom = "14";
		echo '<script type="text/javascript">';
		echo '//<![CDATA[
		function load() {
			function createListener (marker, text) {
				GEvent.addListener(marker, "click", function() {
					marker.openInfoWindowHtml(text);
				}
				);
			}
			if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById("map"));
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
				map.addControl(new GScaleControl());
				map.addControl(new GOverviewMapControl());
		';
		echo '
			 map.setCenter(new GLatLng('.$xobj[0].', '.$yobj[0].'), '.$zoom.');
			 var point = new Array();
			 var text = new Array();
			 var marker = new Array();
		';
		for ($r=0; $r<$rows; $r++) {
			echo '
			point['.$r.'] = new GLatLng('.$xobj[$r].','.$yobj[$r].');
			text['.$r.'] = "'.$nobj[$r].'";
		  ';
		}
		echo '
			var icon = new GIcon();
			icon.image = "./images/Metrologo.png";
			icon.iconSize = new GSize(25, 25);
			icon.iconAnchor = new GPoint(25, 25);
			icon.infoWindowAnchor = new GPoint(25, 25);
			';
		
		echo '
			var marker = new Array();
			for (i=0; i< point.length; i++) {
				marker[i] = new GMarker(point[i],icon);
				map.addOverlay(marker[i]);
				createListener (marker[i], text[i]);
			 }
		';
		echo '
			}
		}
		  //]]></script>
		';
		}
	 } else { 
	 
	 //if no value is submitted, just show map
		$stops = "";
		echo "<p class='submenue'>Bitte wählen Sie eine Halstestelle!</p>\n";
		echo '<script type="text/javascript">';
		echo '//<![CDATA[
		
		function load() {
			if (GBrowserIsCompatible()) {
				var map = new GMap2(document.getElementById("map"));
				map.setCenter(new GLatLng(34.024908,-118.392846),12);
			 }
		}
		';
		echo '
		  //]]></script>
		';
	 }
	 
		?> 
	

		<?php require_once("map.txt"); ?>
		<div class="data"><p class="menue">Wo befindet sich eine bestimmte Haltestelle?</p>
		<div id="map" style="width: 850px; height: 550px;"></div>
		


		<?php
		//This part creates the drop-down form to ask for a value 
		echo "<form action='' method='get'><p>\n";
		echo "<select name='stops' size='1'>\n";
		echo '<option value="_">Bitte wählen...</option>';
		$sql = "SELECT DISTINCT name FROM stops ORDER BY name ";
		$result1 = mysql_query($sql) OR die("Mist! ". mysql_error());
		
		if ($result1) {
			$rows = mysql_num_rows($result1);
			$cols = mysql_num_fields($result1);
		
			for($r=0; $r< $rows; $r++) {
				for($c=0; $c<$cols; $c++) {
						echo "<option value='".mysql_result($result1, $r, $c)."'>".mysql_result($result1, $r, $c)."</option>\n";
				}
			}
		} else {
			echo "Fehler result1\n";
		  }
				
		echo "</select>\n";
		echo "<input type='submit' value='OK' />\n";
		echo "<input type='hidden' name='page' id='page' value='querys/query18'>";
		echo "<input type='hidden' name='nav' id='nav' value='subpages/Kartenabfragen'>";
		echo "</p></form>\n";
		?>
				
		
	</body>
</html>