<?
include("../include/connect.inc.php");
include("../include/function.user.inc.php");
$obj_db = new mysql_operator($obj_dbconfig->get_configdb());
$obj_db->opendb();
if($_POST["mapsave"] =="Y")
{
$updatesql = "update sbs_contact set 
cont_lat				= '".$_POST["cont_lat"]."',
cont_lng				= '".$_POST["cont_lng"]."' WHERE cont_id = '".$_POST["cont_id"]."'";
$mapupdate = mysql_query($updatesql) or die ($updatesql);

if($mapupdate){
//echo"$updatesql";
echo"<body onload=\"self.parent.tb_remove()\">";
exit();
}
}

$sersql="select  * from sbs_contact WHERE cont_id ='".$_GET["mapcase"]."".$_POST["cont_id"]."' LIMIT 0,1";
$serquery =mysql_query($sersql) or die ($sersql);
while($serrow = mysql_fetch_array($serquery)) { 
?>
<!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> 
 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    <title>Google Maps</title> 
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?=Getconfig(gm)?>" type="text/javascript"></script> 
 
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js" type="text/javascript"></script> 
<script type="text/javascript"> 
 
    //<![CDATA[
 
var map;
var present = null;
 
function updateHiddenFields(marker) {
	latlng = marker.getLatLng();
 
	var lng = latlng.lng();
	var lat = latlng.lat();
 
	$('marker_lat').value = lat;
	$('marker_lng').value = lng;	
}
 
function addMarker(latlng) {
 
	if (!present) {
	var lat = latlng.lat();
	var lng = latlng.lng();
 
	var newMarker = new GMarker(latlng, {draggable: true, bouncy: false});	
			
	map.addOverlay(newMarker);		
	
	GEvent.addListener(newMarker, "dragend", function() {
		updateHiddenFields(newMarker);	
	});		
	
	updateHiddenFields(newMarker);
	map.panTo(latlng); 
	present = true;
}
 
}
 
function load() {	
	if (GBrowserIsCompatible()) { 
		map = new GMap2(document.getElementById("map")); 
		map.setCenter(new GLatLng(<?if($serrow["cont_lat"]==""){echo"13.7471";}else{echo $serrow["cont_lat"];}?>,<?if($serrow["cont_lng"]==""){echo"100.5448";}else{echo $serrow["cont_lng"];}?>), 13); 
		map.addControl(new GLargeMapControl());
     	map.addControl(new GMapTypeControl());
		GEvent.addListener(map, "click", function(overlay, latlng) {
			if (!overlay) {
				addMarker(latlng);
			}
		});
	} 

} 
 
    //]]>	
    </script> 
<body onload="load()" onunload="GUnload()"> 
<div id="map" style="width:750px;height:550px"></div> 
 
 <center>
<form method="POST" action="">
	<input id="marker_lat" type="hidden" value="" name="cont_lat"/> 
	<input id="marker_lng" type="hidden" value="" name="cont_lng"/> 
	<input type="hidden" value="Y" name="mapsave"/> 
	<input type="hidden" value="<?=$_GET["mapcase"]?>" name="cont_id"/> 
	<input type="submit" value="บันทึก" name="commit"/> &nbsp;&nbsp;&nbsp;&nbsp;
	<input type="button" id="closescript" value="ยกเลิก" onclick="self.parent.tb_remove();" />
</form>
</center>
  </body></html>
 <?$obj_db->closedb();}?>