<!-- page head start-->
<div class="page-head">
	<h3>
		Edit Data Wisata Bahari
	</h3>
</div>
<!-- page head end-->

<!--body wrapper start-->
<div class="wrapper">
		<?php
		$ket = @$_GET['ket'];
		
		if($ket != "")
		{
			if($ket == "berhasil")
			{
				echo "<div class=\"alert alert-success\">  
					Data <strong>Berhasil</strong> di Simpan!
				</div>" ;	
			}
			else
			{
				if($ket == "ada")	
					$text = "Maaf, NIM yang diinput sudah ada pada database";
				else if($ket == "jumlah")
					$text = "Maaf, jumlah target perbulan tidak sama dengan target setahun.";
				
				echo "<div class=\"alert alert-danger\">  
					$text
				</div>" ;
			}
		}
	?>
	<div class="alert alert-warning fade in">
		<button data-dismiss="alert" class="close close-sm" type="button">
			<i class="fa fa-times"></i>
		</button>
		<strong>Info!</strong> Field dengan tanda (*) harus di isi! 
	</div>
	<?php
		$id = $_GET['id'];
		$cari = mysql_query("SELECT * FROM bahari WHERE id = '$id'");
		$r = mysql_fetch_array($cari);
	?>
	<div class="row">
		<div class="col-lg-12">
			<section class="panel">
				<header class="panel-heading">
					Form Edit Data <?php echo "$r[1]"; ?>
				</header>
				<div class="panel-body">
					<div class=" form">
						<form class="cmxform form-horizontal tasi-form" id="commentForm" method="POST" action="content/bahari_update.php" enctype="multipart/form-data">
							<div class="form-group ">
								<label for="cname" class="control-label col-lg-2">Nama Tempat Wisata *</label>
								<div class="col-lg-10">
									<input name="id" value="<?php echo "$r[0]"; ?>" type="hidden" />
									<input class=" form-control" name="nama" value="<?php echo "$r[1]"; ?>" type="text" required />
								</div>
							</div>
							<div class="form-group ">
								<label for="curl" class="control-label col-lg-2">Fasilitas</label>
								<div class="col-lg-10">
									<textarea class="wysihtml5 form-control" rows="9" name="fas"><?php echo "$r[2]"; ?></textarea>
								</div>
							</div>
							<div class="form-group ">
								<label for="curl" class="control-label col-lg-2">Keterangan</label>
								<div class="col-lg-10">
									<textarea class="wysihtml5 form-control" rows="9" name="ket"><?php echo "$r[3]"; ?></textarea>
								</div>
							</div>
							<div class="form-group ">
								<label for="curl" class="control-label col-lg-2">Map</label>
								<div class="col-lg-10">
									<div id="mapa"></div>
									<div class="eventtext">
									<div>Lattitude: <span id="latspan"></span></div>

									<div>Longitude: <span id="lngspan"></span></div>
									<div>Lat Lng: <span id="latlong"></span></div>
									
									</div>
								</div>
							</div>
							<div class="form-group ">
								<label for="cname" class="control-label col-lg-2">Koordinat Lokasi *</label>
								<div class="col-lg-3">
									<input class=" form-control" id="latclicked" name="lat" value="<?php echo "$r[5]"; ?>" type="text" placeholder="Lattitude" required/>
								</div>
								<div class="col-lg-3">
									<input class=" form-control" id="langclicked" name="lang" value="<?php echo "$r[6]"; ?>" type="text" placeholder="Longitude" required />
								</div>
							</div>
							<div class="form-group">
								<div class="col-lg-offset-2 col-lg-10">
									<button class="btn btn-success" type="submit"><i class="fa fa-floppy-o"></i> Simpan</button>
									<button class="btn btn-warning" type="reset"><i class="fa fa-trash-o"></i> Reset</button>
								</div>
							</div>
						</form>
					</div>

				</div>
			</section>
		</div>
	</div>
</div>
<script type="text/javascript">
	if (GBrowserIsCompatible())
	{
		map = new GMap2(document.getElementById("mapa"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl(3));
		map.setCenter( new GLatLng(-4.5407415, 129.8852402), 12,0);

		GEvent.addListener(map,'mousemove',function(point)
		{
			document.getElementById('latspan').innerHTML = point.lat()
			document.getElementById('lngspan').innerHTML = point.lng()
			document.getElementById('latlong').innerHTML = point.lat() + ', ' + point.lng()
		});

		GEvent.addListener(map,'click',function(overlay,point)
		{
			document.getElementById('latclicked').value = point.lat()
			document.getElementById('langclicked').value = point.lng()
		});
		
		
		// Create a marker
		GDownloadUrl("phpsqlajax_genxml.php", function(data) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
            var nama = markers[i].getAttribute("nama");
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
            var marker = createMarker(point, nama);
            map.addOverlay(marker);
          }
        });

	}
	 function createMarker(point, nama) {
      var marker = new GMarker(point);
      var html = "<b>" + nama + "</b> <br/>";
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
</script>
<!--body wrapper end-->