// Google Map
function point(lat,lng,amp,des,icon,type,polygonType)
{
	var map = new GMap2(document.getElementById("map"),{ size: new GSize(195,115) } );
	var controller=new GSmallMapControl();
	GEvent.addListener(map, "zoomend", function() 
	{
		if(map.getZoom()>=0 && map.getZoom()<17) {
			document.getElementById("zoom").value=map.getZoom();
			document.getElementById("zoom").selectedIndex=map.getZoom();
		}
	});
	map.addControl(controller);
	map.setCenter(new GLatLng(lat,lng), amp);

	if(type==1)
		map.setMapType(G_HYBRID_MAP);
	else if(type==2)
		map.setMapType(G_SATELLITE_MAP);
	else if(type==3)
		map.setMapType(G_NORMAL_MAP);
	
	//map.addControl(new GMapTypeControl());

	var baseIcon = new GIcon();
	baseIcon.shadow = "";
	baseIcon.iconSize = new GSize(32, 32);
	baseIcon.shadowSize = new GSize(32, 32);
	baseIcon.iconAnchor = new GPoint(8.9, 32);
	baseIcon.shadowAnchor = new GPoint(32, 32);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
	function createMarker(point) 
	{
		var letteredIcon = new GIcon(baseIcon);
		letteredIcon.image = "http://www.travelthailand.com/images/icon_shop.png";

		markerOptions = {draggable: false,icon:letteredIcon};
		var marker = new GMarker(point, markerOptions);
		GEvent.addListener(marker, "click", function() 
		{
			//marker.openInfoWindowHtml(des, {maxWidth:400});
		});
		return marker;
	}
	var point = new GLatLng(lat,lng);
	map.addOverlay(createMarker(point));
	
	if(polygonType==1){
		var polyline = new GPolyline([
			new GLatLng(13.896733,100.544836),
			new GLatLng(13.897732,100.545094),
			new GLatLng(13.897639,100.545780),
			new GLatLng(13.896545,100.545598),
			new GLatLng(13.896733,100.544836)
		], "#66cc00", 8);
		map.addOverlay(polyline);    
	}else if(polygonType==2){
		var polyline = new GPolyline([
			new GLatLng(12.678902, 101.152560),
			new GLatLng(12.682963, 101.152517),
			new GLatLng(12.683026, 101.158869),
			new GLatLng(12.681247, 101.158912),
			new GLatLng(12.681414, 101.157689),
			new GLatLng(12.678818, 101.157624),
			new GLatLng(12.678902, 101.152560)
		], "#66cc00", 8);
		map.addOverlay(polyline)
	}else if(polygonType==5){
		var polyline = new GPolyline([
			new GLatLng(14.733299, 100.190591),
       		new GLatLng(14.733838, 100.194668),
       		new GLatLng(14.736079, 100.195226),
        	new GLatLng(14.736453, 100.192265),
        	new GLatLng(14.735457, 100.190033),
        	new GLatLng(14.733299, 100.190591)
		], "#66cc00", 8);
		map.addOverlay(polyline)
	}

}

function plot()
{
	var lat=document.getElementById("lat").value;
	var lng=document.getElementById("lng").value;
	var zoom=document.getElementById("zoom").value;
	var name=document.getElementById("name").value;
	var desc=document.getElementById("desc").value;
	var url=document.getElementById("url").value;
	var type=document.getElementById("mapType").value;
	var default_lat=document.getElementById("default_lat").value;
	var default_lng=document.getElementById("default_lng").value;
	var default_zoom=document.getElementById("default_zoom").value;
	var polygonType=document.getElementById("polygonType").value;
	var strIMG=document.getElementById("hdIMG").value;
	//var info="<u>"+name+"</u><br>"+desc2;
	var info=name+strIMG+"<br /><br />"+desc;
	if(url!='')
		info += "<br /><br />goto : <a href='"+url+"'>"+url+"</url>";
	if(zoom=="") zoom=default_zoom;
	if( (lat=="") || (lng=="") )
	{
		point(default_lat, default_lng,parseInt(zoom),"","",type,polygonType);
	}
	else
	{
		point(lat,lng,parseInt(zoom),info,"",type,polygonType);
	}
}
//plot();
// End Google Map