var centerLatitude=13.713756376124321;var centerLongitude=100.5587249994278;var startZoom=12;var provinceZoomLevel=12;var districtZoonLevel=14;var map;var displayBounds=new GLatLngBounds();var iconPath="index/image/";var currentMarker='property';var markerIcon=[];var resultMarker=[];var resultMarkerType=[];var resultMarkerTooltip=[];var resultMarkerID=[];var resultMarkerNum=0;var resultMarkerInfo=[];var fitZoom=15;var fitCenter=new GLatLng();var blockCount=0;var propertyCount=0;var propertyMarker;var mapClickHandler;var browser=navigator.appName;var version=getInternetExplorerVersion();var showProperty=[];if((browser=='Microsoft Internet Explorer')&&(version<7)){var olderbrowsers="yes";}else{var olderbrowsers="no";}
function addCommas(nStr)
{nStr+='';x=nStr.split('.');x1=x[0];x2=x.length>1?'.'+x[1]:'';var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,'$1'+','+'$2');}
return x1+x2;}
function getInternetExplorerVersion(){var rv=-1;if(navigator.appName=='Microsoft Internet Explorer'){var ua=navigator.userAgent;var re=new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");if(re.exec(ua)!=null)
rv=parseFloat(RegExp.$1);}
return rv;}
function updateMapCenter(lat,lng,level){var center=new GLatLng(lat,lng);map.setCenter(center,level);}
function makeCopyrightSmaller(){if(map.isLoaded())
{for(var i=0;i<map.getContainer().childNodes.length;++i){if(map.getContainer().childNodes[i].innerHTML.indexOf(String.fromCharCode(169))!==-1){map.getContainer().childNodes[i].style.fontSize='8px';window.clearInterval(copyrightTimer);break;}}}}
function makeIcon(){var tempArray1=[];var tempArray2=[];var icon=new GIcon();icon.iconSize=new GSize(25,37);icon.iconAnchor=new GPoint(13,37);icon.infoWindowAnchor=new GPoint(13,3);icon.transparent=iconPath+"pin_trans.png";icon.image=iconPath+"pin_red.png";tempArray1['unselected']=icon;var icon=new GIcon();icon.iconSize=new GSize(25,37);icon.iconAnchor=new GPoint(13,37);icon.infoWindowAnchor=new GPoint(13,3);icon.transparent=iconPath+"pin_trans.png";icon.image=iconPath+"pin_red_selected.png";tempArray1['selected']=icon;markerIcon['sponsor']=tempArray1;var icon=new GIcon();icon.iconSize=new GSize(25,37);icon.iconAnchor=new GPoint(13,37);icon.infoWindowAnchor=new GPoint(13,3);icon.transparent=iconPath+"pin_trans.png";icon.image=iconPath+"pin_blue.png";tempArray2['unselected']=icon;var icon=new GIcon();icon.iconSize=new GSize(25,37);icon.iconAnchor=new GPoint(13,35);icon.infoWindowAnchor=new GPoint(13,3);icon.transparent=iconPath+"pin_trans.png";icon.image=iconPath+"pin_blue_selected.png";tempArray2['selected']=icon;markerIcon['property']=tempArray2;}

// ---------- //
function addBlock(){ // open_block_1
	if(blockCount==0){ // open_block_2
		var newBlock=document.createElement('div');
		var mapContainer=document.getElementById('map_div');
		newBlock.className='drsElement drsMoveHandle';
		newBlock.id='newBlock';
		newBlock.style.left='80px';
		newBlock.style.top='85px';
		newBlock.style.width='140px';
		newBlock.style.height='140px';
		if(olderbrowsers=="yes"){ // open_block_3
			newBlock.style.backgroundImage="url(index/image/fill.gif)";
		} // close_block_3
		else{ // open_block_4
			newBlock.style.backgroundImage="url(index/image/fill.png)";
		} // close_block_4
		mapContainer.appendChild(newBlock);
		var newBlockInfo=document.createElement('div');
		newBlockInfo.id='newBlockInfo';
		newBlockInfo.style.fontFamily='font-family:Verdana ,Trebuchet MS,Helvetica,Sans-Serif';
		newBlockInfo.style.backgroundColor='#ffffff';
		newBlockInfo.style.backgroundRepeat='no-repeat';
		newBlockInfo.style.backgroundPosition='5px 5px';
		newBlockInfo.style.fontSize='11px';
		newBlockInfo.style.lineHeight='15px';
		newBlockInfo.style.position='absolute';
		newBlockInfo.style.width='180px';
		newBlockInfo.style.padding='5px 5px 5px 25px';
		mapContainer.appendChild(newBlockInfo);
		function getLocalAttributes(){ // open_block_5
			var blockLeft=document.getElementById('newBlock').style.left.replace(/px/,"");
			var blockWidth=document.getElementById('newBlock').style.width.replace(/px/,"");
			var blockTop=document.getElementById('newBlock').style.top.replace(/px/,"");
			var blockHeight=document.getElementById('newBlock').style.height.replace(/px/,"");
			var topLeft1=parseFloat(blockLeft)+parseFloat(blockWidth);
			var topLeft2=parseFloat(blockTop)+parseFloat(blockHeight);
			var bottomRight1=parseFloat(blockLeft);var bottomRight2=parseFloat(blockTop);
			var mapCoords=map.fromContainerPixelToLatLng(new GPoint(0,0));
			var blockTopLeft=map.fromContainerPixelToLatLng(new GPoint(topLeft1,topLeft2));
			var blockBottomRight=map.fromContainerPixelToLatLng(new GPoint(bottomRight1,bottomRight2));
			document.getElementById('search_lat1').value=blockTopLeft.y;
			document.getElementById('search_lng1').value=blockTopLeft.x;
			document.getElementById('search_lat2').value=blockBottomRight.y;
			document.getElementById('search_lng2').value=blockBottomRight.x;
		} // close_block_5
		setTimeout(getLocalAttributes,250);blockCount=1;getBlockAttributes();
	} // close_block_2
} // close_block_1

function clearBlock(){if(blockCount>0){var mapBlock=document.getElementById('newBlock');var infoBlock=document.getElementById('newBlockInfo');mapBlock.parentNode.removeChild(mapBlock);infoBlock.parentNode.removeChild(infoBlock);blockCount=0;document.getElementById('search_lat1').value="";document.getElementById('search_lng1').value="";document.getElementById('search_lat2').value="";document.getElementById('search_lng2').value="";}}
function getPropertyLocation(marker){latlng=marker.getLatLng();var lng=latlng.lng();var lat=latlng.lat();$('postlat').value=lat;$('postlng').value=lng;}
function addPropertyMarker(latlng){propertyMarker=new GMarker(latlng,{icon:markerIcon['property']['selected'],draggable:true,bouncy:false});map.addOverlay(propertyMarker);GEvent.addListener(propertyMarker,"dragend",function(){getPropertyLocation(propertyMarker);});map.panTo(latlng);getPropertyLocation(propertyMarker);}
function clearPropertyMarker(){map.removeOverlay(propertyMarker);}
function addProperty(){if(propertyCount==0){addPropertyMarker(map.getCenter());mapClickHandler=GEvent.addListener(map,"click",function(overlay,latlng){if(overlay){}else{clearPropertyMarker();addPropertyMarker(latlng);}});propertyCount=1;}}
function clearProperty(){if(propertyCount>0){clearPropertyMarker();GEvent.removeListener(mapClickHandler);$('postlat').value="";$('postlng').value="";propertyCount=0;}}
function ddMapControl(){}
ddMapControl.prototype=new GControl();ddMapControl.prototype.availableControlType=new Array;var controlPanelWidth;var controlTypePic=["0px 0px","0px -31px","0px -62px","0px -93px","0px -155px","0px -186px","0px -217px"];var controlTypeAltPic=["31px 0px","31px -31px","31px -62px","31px -93px","31px -155px","31px -186px","31px -217px"];var controlTypeName=["handDiv","zoomInDiv","zoomOutDiv","propertyDiv","blockDiv","mapsizeDiv","originDiv"];var controlTypeToolTip=["จับเลื่อนแผนที่","ซูมเข้าเพื่อดูแผนที่ให้ละเอียดขึ้น","ซูมออกเพื่อดูแผนที่ในมุมกว้าง","ระบุตำแหน่งอสังหาฯในแผนที่","ระบุพื้นที่สำหรับค้นหาอสังหาฯ","ขยายแผนที่","กลับไปยังตำแหน่งเริ่มต้น"]
var controlTypeAltToolTip=["จับเลื่อนแผนที่","ซูมเข้าเพื่อดูแผนที่ให้ละเอียดขึ้น","ซูมออกเพื่อดูแผนที่ในมุมกว้าง","ยกเลิกการระบุตำแหน่งอสังหาฯในแผนที่","ยกเลิกการระบุพื้นที่สำหรับค้นหาอสังหาฯ","ย่อแผนที่","กลับไปยังตำแหน่งเริ่มต้น"]
ddMapControl.prototype.initialize=function(map){var backgroundContainer=document.createElement("div");var container=document.createElement("div");backgroundContainer.style.backgroundImage="url(index/image/controlbg.png)";backgroundContainer.id='ddMapControl';backgroundContainer.style.width="37px";container.style.width="37px";container.style.height=controlPanelHeight+'px';backgroundContainer.style.height=controlPanelHeight+'px';container.style.padding="5px";backgroundContainer.style.padding="5px";backgroundContainer.style.position="absolute";if(olderbrowsers=="yes"){backgroundContainer.style.backgroundColor="#dddddd";backgroundContainer.style.opacity=60;backgroundContainer.style.filter='alpha(opacity=60)';}
for(var j=0;j<this.availableControlType.length;j++){if(this.availableControlType[j]==0){var handDiv=document.createElement("div");handDiv.id=controlTypeName[0];this.setButtonStyle_(handDiv,controlTypePic[0],controlTypeToolTip[0],controlTypeName[0]);container.appendChild(handDiv);GEvent.addDomListener(handDiv,"click",function(){changeControlType(0);});}/*else
if(this.availableControlType[j]==1){var zoomInDiv=document.createElement("div");zoomInDiv.id=controlTypeName[1];this.setButtonStyle_(zoomInDiv,controlTypePic[1],controlTypeToolTip[1],controlTypeName[1]);container.appendChild(zoomInDiv);GEvent.addDomListener(zoomInDiv,"click",function(){map.zoomIn();});}else
if(this.availableControlType[j]==2){var zoomOutDiv=document.createElement("div");zoomOutDiv.id=controlTypeName[2];this.setButtonStyle_(zoomOutDiv,controlTypePic[2],controlTypeToolTip[2],controlTypeName[2]);container.appendChild(zoomOutDiv);GEvent.addDomListener(zoomOutDiv,"click",function(){map.zoomOut();});}*/else
if(this.availableControlType[j]==3){var propertyDiv=document.createElement("div");propertyDiv.id=controlTypeName[3];this.setButtonStyle_(propertyDiv,controlTypePic[3],controlTypeToolTip[3],controlTypeName[3]);container.appendChild(propertyDiv);GEvent.addDomListener(propertyDiv,"click",function(){togglePropertyControl();});}

// ---------- //
else if(this.availableControlType[j]==4){ // open_block_1
	var blockDiv=document.createElement("div");
	blockDiv.id=controlTypeName[4];
	this.setButtonStyle_(blockDiv,controlTypePic[4],controlTypeToolTip[4],controlTypeName[4]);
	container.appendChild(blockDiv);
	$('search_lat1').value="";
	$('search_lng1').value="";
	$('search_lat2').value="";
	$('search_lng2').value="";
	GEvent.addDomListener(blockDiv,"click",function(){toggleBlockControl();});
} // close_block_1

/*else
if(this.availableControlType[j]==5){var mapsizeDiv=document.createElement("div");mapsizeDiv.id=controlTypeName[5];mapsize=$('moveable_map').classNames();if(mapsize=='shrunk'){this.setButtonStyle_(mapsizeDiv,controlTypeAltPic[5],controlTypeToolTip[5],controlTypeName[5]);}else
{this.setButtonStyle_(mapsizeDiv,controlTypePic[5],controlTypeAltToolTip[5],controlTypeName[5]);}
container.appendChild(mapsizeDiv);GEvent.addDomListener(mapsizeDiv,"click",function(){toggleMapSize();});}*/else
if(this.availableControlType[j]==6){var originDiv=document.createElement("div");originDiv.id=controlTypeName[6];this.setButtonStyle_(originDiv,controlTypePic[6],controlTypeToolTip[6],controlTypeName[6]);container.appendChild(originDiv);GEvent.addDomListener(originDiv,"click",function(){if($('this_is_showpage')!=null){var center=new GLatLng(showProperty['main']['lat'],showProperty['main']['lng']);map.setCenter(center,map.getZoom());}});};}
map.getContainer().appendChild(backgroundContainer);map.getContainer().appendChild(container);return container;}
ddMapControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(60,15));}
ddMapControl.prototype.setButtonStyle_=function(button,picture,tooltip,bottomname){button.style.backgroundImage="url(index/image/ControlButton.png)";button.style.backgroundPosition=picture;button.style.width="31px";button.style.height="31px";button.style.cursor="pointer";var hidden_link=document.createElement("a");hidden_link.href="#";hidden_link.onclick=function(){return false;};hidden_link.title=tooltip;hidden_link.innerHTML="hidden";hidden_link.style.width="31px";hidden_link.style.height="31px";hidden_link.style.display="block";hidden_link.style.textIndent="-9999px";hidden_link.id="link_"+bottomname;button.appendChild(hidden_link);if(navigator.appName.indexOf("Netscape")!=-1){button.style.cssFloat="left";}
else{button.style.styleFloat="left";}
button.style.margin="0px 0px 3px 3px";}

// ---------- //
function toggleMapSize(){ // open_block_1
	if($("mapsizeDiv").style.backgroundPosition==controlTypeAltPic[5]){ // open_block_2
		$("mapsizeDiv").style.backgroundPosition=controlTypePic[5];
		$("link_mapsizeDiv").title=controlTypeAltToolTip[5];
		expand_map();
	} // close_block_2
	else{ // open_block_3
		$("mapsizeDiv").style.backgroundPosition=controlTypeAltPic[5];
		$("link_mapsizeDiv").title=controlTypeToolTip[5];
		shrink_map();
	} // close_block_3
} // close_block_1

// ---------- //
function toggleBlockControl(){ // open_block_1
	if($("blockDiv").style.backgroundPosition==controlTypePic[4]){ // open_block_2
		addBlock();
		$("blockDiv").style.backgroundPosition=controlTypeAltPic[4];$("link_blockDiv").title=controlTypeAltToolTip[4];
	} // close_block_2
	else{ // open_block_3
		$("blockDiv").style.backgroundPosition=controlTypePic[4];
		$("link_blockDiv").title=controlTypeToolTip[4];
		clearBlock();
	} // close_block_3
} // close_block_1

function togglePropertyControl(){if($("propertyDiv").style.backgroundPosition==controlTypePic[3]){addProperty();$("propertyDiv").style.backgroundPosition=controlTypeAltPic[3];$("link_propertyDiv").title=controlTypeAltToolTip[3];}else{$("propertyDiv").style.backgroundPosition=controlTypePic[3];$("link_propertyDiv").title=controlTypeToolTip[3];clearProperty();}}
function changeControlType(selectedControlType){$("blockDiv").style.backgroundPosition=controlTypePic[4];$("handDiv").style.backgroundPosition=controlTypePic[0];$("propertyDiv").style.backgroundPosition=controlTypePic[3];$(controlTypeName[selectedControlType]).style.backgroundPosition=controlTypeAltPic[selectedControlType];}
var displayingLandmark=[];var displayingLandmarkNum=0;var deletingLandmark=[];var deletingLandmarkNum=0;var landmarkIcon=[];var landmarkIconPath='index/image/landmarks/';function makeLandmarkIcon(icon_id){if(icon_id<8000){var icon=new GIcon();icon.iconSize=new GSize(16,16);icon.iconAnchor=new GPoint(8,8);icon.image=landmarkIconPath+icon_id+'.png';}else{var icon=new GIcon();icon.iconSize=new GSize(161,84);icon.iconAnchor=new GPoint(80,84);icon.image=landmarkIconPath+icon_id+'.png';}
landmarkIcon[icon_id]=icon;}
function initLandmarkVariable(){displayingLandmarkNum=0;displayingLandmark.clear();deletingLandmarkNum=0;deletingLandmark.clear();}
function clearLandmark(){for(var i=0;i<deletingLandmarkNum;i++){map.removeOverlay(deletingLandmark[i]);}}
function addLandmark(id,lat,lng,displayname,icon_id,url){var latlng=new GLatLng(lat,lng);if(landmarkIcon[icon_id]==null){makeLandmarkIcon(icon_id);}
var marker=new GMarker(latlng,{icon:landmarkIcon[icon_id],title:displayname});displayingLandmark[displayingLandmarkNum]=marker;displayingLandmarkNum++;map.addOverlay(marker);if(icon_id>8000){GEvent.addListener(marker,"click",function(){window.open(url);});}}
function updateLandmark(){var bounds=map.getBounds();var southWest=bounds.getSouthWest();var northEast=bounds.getNorthEast();var mapBoundary='ne='+northEast.toUrlValue()+'&sw='+southWest.toUrlValue()+'&zoomlevel='+map.getZoom();var myAjax=new Ajax.Request('/property/getlandmark',{method:'get',parameters:mapBoundary,onComplete:function(request){landmarks=eval("("+request.responseText+")");deletingLandmark=displayingLandmark.clone();deletingLandmarkNum=displayingLandmarkNum;displayingLandmarkNum=0;displayingLandmark.clear();for(var i=0;i<landmarks.length;i++){var landmark=landmarks[i]
var lat=landmark.lat;var lng=landmark.lng;var displayname=landmark.displayname;var id=landmark.id;var icon_id=landmark.icon_id
var url=landmark.url;if(lat&&lng&&lat!=0&&lng!=0){addLandmark(id,lat,lng,displayname,icon_id,url);}}
clearLandmark();}});}
function makePostMap(lat,lng,present){if(GBrowserIsCompatible()){map=new GMap(document.getElementById("post_map_div"));makeIcon();controlPanelHeight=($('post_map_div').getHeight()-10);ddmapcontrol=new ddMapControl();ddmapcontrol.availableControlType=[1,2,3];map.addControl(ddmapcontrol);map.removeMapType(G_SATELLITE_MAP);var mapTypeControl=new GMapTypeControl();map.addControl(mapTypeControl);map.disableDoubleClickZoom();if(present){var center=new GLatLng(lat,lng);map.setCenter(center,startZoom);addPropertyMarker(center);mapClickHandler=GEvent.addListener(map,"click",function(overlay,latlng){if(overlay){}else{clearPropertyMarker();addPropertyMarker(latlng);}});propertyCount=1;$("propertyDiv").style.backgroundPosition=controlTypeAltPic[3];$('postlat').value=lat;$('postlng').value=lng;}else{var center=new GLatLng(centerLatitude,centerLongitude);map.setCenter(center,startZoom);$('postlat').value="";$('postlng').value="";}
copyrightTimer=window.setInterval('makeCopyrightSmaller()',150);initLandmarkVariable();updateLandmark();GEvent.addListener(map,'zoomend',function(){updateLandmark();});GEvent.addListener(map,'moveend',function(){updateLandmark();});}}
function makeEditPostMap(lat,lng,present){if(GBrowserIsCompatible()){map=new GMap(document.getElementById("post_map_div"));controlPanelHeight=($('post_map_div').getHeight()-10);ddmapcontrol=new ddMapControl();ddmapcontrol.availableControlType=[1,2,3];map.addControl(ddmapcontrol);map.removeMapType(G_SATELLITE_MAP);var mapTypeControl=new GMapTypeControl();map.addControl(mapTypeControl);map.disableDoubleClickZoom();makeIcon();if(present){var center=new GLatLng(lat,lng);map.setCenter(center,startZoom);addPropertyMarker(center);mapClickHandler=GEvent.addListener(map,"click",function(overlay,latlng){if(overlay){}else{clearPropertyMarker();addPropertyMarker(latlng);}});propertyCount=1;$("propertyDiv").style.backgroundPosition=controlTypeAltPic[3];$('postlat').value=lat;$('postlng').value=lng;}else{var center=new GLatLng(lat,lng);map.setCenter(center,startZoom);$('postlat').value="";$('postlng').value="";}
copyrightTimer=window.setInterval('makeCopyrightSmaller()',150);initLandmarkVariable();updateLandmark();GEvent.addListener(map,'zoomend',function(){updateLandmark();});GEvent.addListener(map,'moveend',function(){updateLandmark();});}}
function parseMainPropertyinfo(){var tempArray=[];lat=json_property['post']['lat'];lng=json_property['post']['lng'];sponsor=json_property['post']['sponsor'];title=json_property['post']['title'];id=json_property['post']['id'];user_id=json_property['post']['user_id'];province_id=json_property['post']['province_id'];district_id=json_property['post']['district_id'];place_type_id=json_property['post']['place_type_id'];post_type_id=json_property['post']['post_type_id'];tempArray['lat']=lat;tempArray['lng']=lng;tempArray['sponsor']=sponsor;tempArray['title']=title;tempArray['id']=id;tempArray['user_id']=user_id;tempArray['province_id']=province_id;tempArray['district_id']=district_id;tempArray['place_type_id']=place_type_id;tempArray['post_type_id']=post_type_id;showProperty['main']=tempArray;}
function makeShowMap(){if(GBrowserIsCompatible()){showProperty.clear();parseMainPropertyinfo();if(showProperty['main']['lat']&&showProperty['main']['lng']){map=new GMap2(document.getElementById("map_div"));var center=new GLatLng(centerLatitude,centerLongitude);map.setCenter(center,14);controlPanelHeight=($('map_div').getHeight()-10);ddmapcontrol=new ddMapControl();ddmapcontrol.availableControlType=[1,2];map.addControl(ddmapcontrol);map.addControl(new GScaleControl());map.removeMapType(G_SATELLITE_MAP);var mapTypeControl=new GMapTypeControl();map.addControl(mapTypeControl);map.disableDoubleClickZoom();copyrightTimer=window.setInterval('makeCopyrightSmaller()',150);makeIcon();addShowMarker(showProperty['main']['lat'],showProperty['main']['lng'],showProperty['main']['title'],showProperty['main']['sponsor'],showProperty['main']['id']);initLandmarkVariable();updateLandmark();GEvent.addListener(map,'zoomend',function(){updateLandmark();});GEvent.addListener(map,'moveend',function(){updateLandmark();});}}}
function requestNOMAPMessage(user_id,post_id){var myAjax=new Ajax.Request('/property/nomap',{method:'get',parameters:{user_id:user_id,post_id:post_id}});}
function requestNOMAPNearby(id,province_id,district_id,place_type_id,post_type_id){var myAjax=new Ajax.Request('/property/get_nearby_nomap',{method:'get',parameters:{post_id:id,pid:province_id,did:district_id,pt_id:post_type_id,plt_id:place_type_id}});}
function requestNearbySponsor(id,province_id,district_id,place_type_id,post_type_id){var bounds=map.getBounds();var southWest=bounds.getSouthWest();var northEast=bounds.getNorthEast();var mapBoundary='ne='+northEast.toUrlValue()+'&sw='+southWest.toUrlValue();var myAjax=new Ajax.Request('/property/get_nearby_withmap',{method:'get',parameters:{post_id:id,ne:northEast.toUrlValue(),sw:southWest.toUrlValue(),pid:province_id,did:district_id,pt_id:post_type_id,plt_id:place_type_id}});}
function addShowMarker(lat,lng,title,sponsor,id){var latlng=new GLatLng(lat,lng);if(sponsor==0){var marker=new GMarker(latlng,{icon:markerIcon['property']['selected'],title:title});}
else{var marker=new GMarker(latlng,{icon:markerIcon['sponsor']['selected'],title:title});}
map.addOverlay(marker);map.setCenter(latlng,13);}

// ---------- //
function makeSearchMap(){ // open_block_1
	if(GBrowserIsCompatible()){ // open_block_2
		map=new GMap(document.getElementById("map_div"));
		var center=new GLatLng(centerLatitude,centerLongitude);
		map.setCenter(center,startZoom);
		controlPanelHeight=($('map_div').getHeight()-10);
		ddmapcontrol=new ddMapControl();
		ddmapcontrol.availableControlType=[5,1,2,4];
		//makeIcon();
		map.addControl(ddmapcontrol);
		// ---------- //
		var customUI = map.getDefaultUI();
		customUI.maptypes.physical = false;
		map.setUI(customUI);
		//map.addControl(new GScaleControl());
		//map.removeMapType(G_SATELLITE_MAP);
		//var mapTypeControl=new GMapTypeControl();
		//map.addControl(mapTypeControl);
		map.disableDoubleClickZoom();
		//copyrightTimer=window.setInterval('makeCopyrightSmaller()',150);
		GEvent.addListener(map,"zoom",getBlockAttributes);
		//initLandmarkVariable();
		//updateLandmark();
		//GEvent.addListener(map,'zoomend',function(){updateLandmark();});
		//GEvent.addListener(map,'moveend',function(){updateLandmark();});
	} // close_block_2
} // close_block_1

function getSponsorMarker(sponsor_listing,position){var myAjax=new Ajax.Request('/property/listsponsor',{method:'get',parameters:{sid:sponsor_listing},onComplete:function(request){markers=eval("("+request.responseText+")");for(var i=0;i<markers.length;i++){var markerinfo=markers[i].post
var lat=markerinfo.lat;var lng=markerinfo.lng;if(lat&&lng&&lat!=0&&lng!=0){addMarker(markerinfo,'sponsor',position);}}
fitZoom=map.getBoundsZoomLevel(displayBounds);if(fitZoom>15)
fitZoom=15;fitCenter=displayBounds.getCenter();}});}
function getPropertyMarker(property_listing,position){var myAjax=new Ajax.Request('/property/listproperty',{method:'get',parameters:{pid:property_listing},onComplete:function(request){markers=eval("("+request.responseText+")");for(var i=0;i<markers.length;i++){var markerinfo=markers[i].post
var lat=markerinfo.lat;var lng=markerinfo.lng;if(lat&&lng&&lat!=0&&lng!=0){addMarker(markerinfo,'property',position);}}
fitZoom=map.getBoundsZoomLevel(displayBounds);if(fitZoom>15)
fitZoom=15;fitCenter=displayBounds.getCenter();setFitBounds();}});}
function addMarker(markerinfo,icontype,position){var id=markerinfo.id;if(resultMarker[id]==null){var lat=markerinfo.lat;var lng=markerinfo.lng;var title=markerinfo.title;var price=markerinfo.price;var price_unit=markerinfo.price_unit;var default_picture=markerinfo.default_picture;var latlng=new GLatLng(lat,lng);var marker=new GMarker(latlng,{icon:markerIcon[icontype]['unselected'],title:title});resultMarker[id]=marker;resultMarkerType[id]=icontype;resultMarkerID[resultMarkerNum]=id;resultMarkerNum++;var aMarkerInfo=[];aMarkerInfo['title']=title;aMarkerInfo['price']=price;aMarkerInfo['price_unit']=price_unit;aMarkerInfo['default_picture']=default_picture;resultMarkerInfo[id]=aMarkerInfo;if(position==2){GEvent.addListener(marker,"mouseover",function(){highlightMarker(id);highlightListing('nearby',id);});GEvent.addListener(marker,"mouseout",function(){unHighlightMarker(id);unHighlightListing('nearby',id);});}else{GEvent.addListener(marker,"mouseover",function(){highlightMarker(id);highlightListing(icontype,id);});GEvent.addListener(marker,"mouseout",function(){unHighlightMarker(id);unHighlightListing(icontype,id);});}
GEvent.addListener(marker,"click",function(){source_id='1'+(icontype=="sponsor"?'11':'01')+position;new Ajax.Request('/property/stat/'+id+'/'+source_id);window.open('/property/show/'+id);});map.addOverlay(marker);displayBounds.extend(latlng);}}
function removeAllMarker(){markerNum=resultMarkerNum;for(var i=0;i<markerNum;i++){map.removeOverlay(resultMarker[resultMarkerID[i]]);}}
function highlightMarker(id){if(resultMarker[id]!=null){resultMarker[id].setImage(markerIcon[resultMarkerType[id]]['selected'].image);showMouseOver(id,resultMarkerInfo[id]['title'],resultMarkerInfo[id]['price'],resultMarkerInfo[id]['price_unit'],resultMarkerInfo[id]['default_picture']);}}
function highlightListing(listingType,id){$(listingType+'_listing_'+id).addClassName(listingType+'_highlight');}
function unHighlightMarker(id){if(resultMarker[id]!=null){resultMarker[id].setImage(markerIcon[resultMarkerType[id]]['unselected'].image);hideMouseOver(id);}}
function unHighlightListing(listingType,id){$(listingType+'_listing_'+id).removeClassName(listingType+'_highlight');}
function setFitBounds(){map.setZoom(fitZoom-1);map.setCenter(fitCenter);}
function initSearchVariable(){removeAllMarker();resultMarkerID.clear();resultMarker.clear();resultMarkerType.clear();resultMarkerTooltip.clear();resultMarkerNum=0;resultMarkerInfo.clear();displayBounds=new GLatLngBounds();clearBlock();}
function showMouseOver(id,title,price,price_unit,default_picture){var bb=map.getBounds();if(resultMarkerTooltip[id]==null){contents=prepareMarkerTooltop(title,price,price_unit,default_picture);resultMarkerTooltip[id]=document.createElement("div");resultMarkerTooltip[id].style.display="none";resultMarkerTooltip[id].style.position="absolute";resultMarkerTooltip[id].style.padding="0";resultMarkerTooltip[id].style.margin="0";resultMarkerTooltip[id].style.zIndex=50000;resultMarkerTooltip[id].innerHTML="<div class=\"markerTooltip\">"+contents+"</div>";document.body.appendChild(resultMarkerTooltip[id]);}
if(bb.contains(resultMarker[id].getPoint())){var tlcLatLng=map.fromContainerPixelToLatLng(new GPoint(0,0),true);var tlcDivPixel=map.fromLatLngToDivPixel(tlcLatLng);var pointDivPixel=map.fromLatLngToDivPixel(resultMarker[id].getPoint());var c=new GPoint(pointDivPixel.x-tlcDivPixel.x,pointDivPixel.y-tlcDivPixel.y);var mapPos=findPosition(map.getContainer());resultMarkerTooltip[id].style.left="-1000px";resultMarkerTooltip[id].style.top="-1000px";resultMarkerTooltip[id].style.display="block";var tipLeft=c.x-resultMarker[id].getIcon().iconAnchor.x+mapPos[0];if(tipLeft>(document.body.offsetWidth/2)){tipLeft-=resultMarkerTooltip[id].offsetWidth;}else{tipLeft+=resultMarker[id].getIcon().iconSize.width;}
resultMarkerTooltip[id].style.left=tipLeft+"px";var tipTop=c.y-resultMarker[id].getIcon().iconAnchor.y+mapPos[1];if((c.y+map.getContainer().offsetTop)>(map.getContainer().offsetTop+(map.getContainer().offsetHeight/2))){tipTop-=resultMarkerTooltip[id].offsetHeight;}else{tipTop+=resultMarker[id].getIcon().iconSize.height;}
resultMarkerTooltip[id].style.top=tipTop+"px";}}
function hideMouseOver(id){if(resultMarkerTooltip[id]!=null){resultMarkerTooltip[id].style.display="none";}}
function prepareMarkerTooltop(title,price,price_unit,default_picture){var popupHTML='<div class="markerbox">';if(default_picture!=null){popupHTML+='<img class="tooltip_photo" src="'+default_picture+'"/>';}else{popupHTML+='<img class="tooltip_photo" src="index/image/noimage-thumb.jpg"/>';}
if(title.length>40){title=title.substring(0,40);}
popupHTML+='<div class="popup_detail_box"><h3>'+title+'...</h3>';popupHTML+='ราคา '+addCommas(price)+"  "+price_unit;popupHTML+='</div></div>';return popupHTML;}

// ---------- //
function getBlockAttributes(){ // open_block_1
	if(blockCount>0){ // open_block_2
		var blockLeft=document.getElementById('newBlock').style.left.replace(/px/,"");
		var blockWidth=document.getElementById('newBlock').style.width.replace(/px/,"");
		var blockTop=document.getElementById('newBlock').style.top.replace(/px/,"");
		var blockHeight=document.getElementById('newBlock').style.height.replace(/px/,"");
		var topLeft1=parseFloat(blockLeft)+parseFloat(blockWidth);
		var topLeft2=parseFloat(blockTop)+parseFloat(blockHeight);
		var bottomRight1=parseFloat(blockLeft);
		var bottomRight2=parseFloat(blockTop);
		var mapCoords=map.fromContainerPixelToLatLng(new GPoint(0,0));
		var blockTopLeft=map.fromContainerPixelToLatLng(new GPoint(topLeft1,topLeft2));
		var blockBottomRight=map.fromContainerPixelToLatLng(new GPoint(bottomRight1,bottomRight2));
		var rad=180/Math.PI;
		var blockActualWidth=3960*Math.acos(Math.cos((90-blockTopLeft.y)/rad)*Math.cos((90-blockBottomRight.y)/rad)+Math.sin((90-blockTopLeft.y)/rad)*Math.sin((90-blockBottomRight.y)/rad)*Math.cos((blockTopLeft.y-blockBottomRight.y)/rad));
		var blockActualHeight=3960*Math.acos(Math.cos((90-blockTopLeft.x)/rad)*Math.cos((90-blockBottomRight.x)/rad)+Math.sin((90-blockTopLeft.x)/rad)*Math.sin((90-blockBottomRight.x)/rad)*Math.cos((blockTopLeft.x-blockBottomRight.x)/rad));
		var blockActualAreaKM=Math.round(((blockActualWidth*blockActualHeight)*1.609344)*100)/100;
		var string='<strong>ขนาด: </strong>'+(Math.round(blockActualWidth*100)/100)+' กม. x '+(Math.round(blockActualHeight*100)/100)+'กม. <br /><stron>พื้นที่: </strong>';
		if(blockActualAreaKM>301){ // open_block_3
			string+='<font color="red">'+blockActualAreaKM+'กม.&sup2;</font><br /><font color="red">ขนาดใหณ่กว่า 300 กม.&sup2;</font>';
			document.getElementById('newBlockInfo').style.backgroundImage='url(index/image/nope.gif)';
			if(olderbrowsers=="yes"){ // open_block_4
				document.getElementById('newBlock').style.backgroundImage="url(index/image/fill_alert.gif)";
			} // close_block_4
			else{ // open_block_5
				document.getElementById('newBlock').style.backgroundImage="url(index/image/fill_alert.png)";
			} // close_block_5
		} // close_block_3
		else{ // open_block_6
			string+=blockActualAreaKM+'กม.&sup2;';
			document.getElementById('newBlockInfo').style.backgroundImage='url(index/image/yup.gif)';
			if(olderbrowsers=="yes"){ // open_block_7
				document.getElementById('newBlock').style.backgroundImage="url(index/image/fill.gif)";
			} // close_block_7
			else{ // open_block_8
				document.getElementById('newBlock').style.backgroundImage="url(index/image/fill.png)";
			} // close_block_8
		} // close_block_6
		newInfoTop=parseInt(blockHeight)+parseInt(blockTop)+5;
		document.getElementById('newBlockInfo').style.top=newInfoTop+'px';
		document.getElementById('newBlockInfo').style.left=blockLeft+'px';
		document.getElementById('newBlockInfo').innerHTML=string;
		document.getElementById('search_lat1').value=blockTopLeft.y;
		document.getElementById('search_lng1').value=blockTopLeft.x;
		document.getElementById('search_lat2').value=blockBottomRight.y;
		document.getElementById('search_lng2').value=blockBottomRight.x;
		// ทดสอบ
		//document.getElementById('display_block').innerHTML = blockTopLeft.y + ", " + blockTopLeft.x + ", " + blockBottomRight.y + ", " + blockBottomRight.x;
	} // close_block_2
} // close_block_1

var drag_mapsize=0;if(typeof addEvent!='function')
{var addEvent=function(o,t,f,l)
{var d='addEventListener',n='on'+t,rO=o,rT=t,rF=f,rL=l;if(o[d]&&!l)return o[d](t,f,false);if(!o._evts)o._evts={};if(!o._evts[t])
{o._evts[t]=o[n]?{b:o[n]}:{};o[n]=new Function('e','var r = true, o = this, a = o._evts["'+t+'"], i; for (i in a) {'+'o._f = a[i]; r = o._f(e||window.event) != false && r; o._f = null;'+'} return r');if(t!='unload')addEvent(window,'unload',function(){removeEvent(rO,rT,rF,rL);});}
if(!f._i)f._i=addEvent._i++;o._evts[t][f._i]=f;};addEvent._i=1;var removeEvent=function(o,t,f,l)
{var d='removeEventListener';if(o[d]&&!l)return o[d](t,f,false);if(o._evts&&o._evts[t]&&f._i)delete o._evts[t][f._i];};}
function cancelEvent(e,c)
{e.returnValue=false;if(e.preventDefault)e.preventDefault();if(c)
{e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();}};function DragResize(myName,config)
{var props={myName:myName,enabled:true,handles:['tl','tm','tr','ml','mr','bl','bm','br'],isElement:null,isHandle:null,element:null,handle:null,minWidth:10,minHeight:10,minLeft:[0,0],maxLeft:[9999,9999],minTop:[0,0],maxTop:[9999,9999],zIndex:1,mouseX:0,mouseY:0,lastMouseX:0,lastMouseY:0,mOffX:0,mOffY:0,elmX:0,elmY:0,elmW:0,elmH:0,allowBlur:true,ondragfocus:null,ondragstart:null,ondragmove:null,ondragend:null,ondragblur:null};for(var p in props)
this[p]=(typeof config[p]=='undefined')?props[p]:config[p];};DragResize.prototype.apply=function(node)
{var obj=this;addEvent(node,'mousedown',function(e){obj.mouseDown(e);});addEvent(node,'mousemove',function(e){obj.mouseMove(e);});addEvent(node,'mouseup',function(e){obj.mouseUp(e);});};DragResize.prototype.select=function(newElement){with(this)
{if(!document.getElementById||!enabled)return;if(newElement&&(newElement!=element)&&enabled)
{element=newElement;element.style.zIndex=++zIndex;if(this.resizeHandleSet)this.resizeHandleSet(element,true);elmX=parseInt(element.style.left);elmY=parseInt(element.style.top);elmW=element.offsetWidth;elmH=element.offsetHeight;if(ondragfocus)this.ondragfocus();}}};DragResize.prototype.deselect=function(delHandles){with(this)
{if(!document.getElementById||!enabled)return;if(delHandles)
{if(ondragblur)this.ondragblur();if(this.resizeHandleSet)this.resizeHandleSet(element,false);element=null;}
handle=null;mOffX=0;mOffY=0;}};DragResize.prototype.mouseDown=function(e){with(this)
{if(!document.getElementById||!enabled)return true;if(document.getElementById('newBlock')){document.getElementById('newBlockInfo').style.display='none';}
var elm=e.target||e.srcElement,newElement=null,newHandle=null,hRE=new RegExp(myName+'-([trmbl]{2})','');while(elm)
{if(elm.className)
{if(!newHandle&&(hRE.test(elm.className)||isHandle(elm)))newHandle=elm;if(isElement(elm)){newElement=elm;break}}
elm=elm.parentNode;}
if(element&&(element!=newElement)&&allowBlur)deselect(true);if(newElement&&(!element||(newElement==element)))
{if(newHandle)cancelEvent(e);select(newElement,newHandle);handle=newHandle;if(handle&&ondragstart)this.ondragstart(hRE.test(handle.className));}}};DragResize.prototype.mouseMove=function(e){with(this)
{if(!document.getElementById||!enabled)return true;mouseX=e.pageX||e.clientX+document.documentElement.scrollLeft;mouseY=e.pageY||e.clientY+document.documentElement.scrollTop;var diffX=mouseX-lastMouseX+mOffX;var diffY=mouseY-lastMouseY+mOffY;mOffX=mOffY=0;lastMouseX=mouseX;lastMouseY=mouseY;if(!handle)return true;var isResize=false;if(this.resizeHandleDrag&&this.resizeHandleDrag(diffX,diffY))
{isResize=true;}
else
{var dX=diffX,dY=diffY;if(elmX+dX<minLeft[drag_mapsize])mOffX=(dX-(diffX=minLeft[drag_mapsize]-elmX));else if(elmX+elmW+dX>maxLeft[drag_mapsize])mOffX=(dX-(diffX=maxLeft[drag_mapsize]-elmX-elmW));if(elmY+dY<minTop[drag_mapsize])mOffY=(dY-(diffY=minTop[drag_mapsize]-elmY));else if(elmY+elmH+dY>maxTop[drag_mapsize])mOffY=(dY-(diffY=maxTop[drag_mapsize]-elmY-elmH));elmX+=diffX;elmY+=diffY;}
with(element.style)
{left=elmX+'px';width=elmW+'px';top=elmY+'px';height=elmH+'px';}
if(window.opera&&document.documentElement)
{var oDF=document.getElementById('op-drag-fix');if(!oDF)
{var oDF=document.createElement('input');oDF.id='op-drag-fix';oDF.style.display='none';document.body.appendChild(oDF);}
oDF.focus();}
if(ondragmove)this.ondragmove(isResize);cancelEvent(e);}};DragResize.prototype.mouseUp=function(e){with(this)
{if(!document.getElementById||!enabled)return;if(document.getElementById('newBlock')){getBlockAttributes();document.getElementById('newBlockInfo').style.display='block';}
var hRE=new RegExp(myName+'-([trmbl]{2})','');if(handle&&ondragend)this.ondragend(hRE.test(handle.className));deselect(false);}};DragResize.prototype.resizeHandleSet=function(elm,show){with(this)
{if(!elm._handle_tr)
{for(var h=0;h<handles.length;h++)
{var hDiv=document.createElement('div');hDiv.className=myName+' '+myName+'-'+handles[h];elm['_handle_'+handles[h]]=elm.appendChild(hDiv);}}
for(var h=0;h<handles.length;h++)
{elm['_handle_'+handles[h]].style.visibility=show?'inherit':'hidden';}}};DragResize.prototype.resizeHandleDrag=function(diffX,diffY){with(this)
{var hClass=handle&&handle.className&&handle.className.match(new RegExp(myName+'-([tmblr]{2})'))?RegExp.$1:'';var dY=diffY,dX=diffX,processed=false;if(hClass.indexOf('t')>=0)
{rs=1;if(elmH-dY<minHeight)mOffY=(dY-(diffY=elmH-minHeight));else if(elmY+dY<minTop[drag_mapsize])mOffY=(dY-(diffY=minTop[drag_mapsize]-elmY));elmY+=diffY;elmH-=diffY;processed=true;}
if(hClass.indexOf('b')>=0)
{rs=1;if(elmH+dY<minHeight)mOffY=(dY-(diffY=minHeight-elmH));else if(elmY+elmH+dY>maxTop[drag_mapsize])mOffY=(dY-(diffY=maxTop[drag_mapsize]-elmY-elmH));elmH+=diffY;processed=true;}
if(hClass.indexOf('l')>=0)
{rs=1;if(elmW-dX<minWidth)mOffX=(dX-(diffX=elmW-minWidth));else if(elmX+dX<minLeft[drag_mapsize])mOffX=(dX-(diffX=minLeft[drag_mapsize]-elmX));elmX+=diffX;elmW-=diffX;processed=true;}
if(hClass.indexOf('r')>=0)
{rs=1;if(elmW+dX<minWidth)mOffX=(dX-(diffX=minWidth-elmW));else if(elmX+elmW+dX>maxLeft[drag_mapsize])mOffX=(dX-(diffX=maxLeft[drag_mapsize]-elmX-elmW));elmW+=diffX;processed=true;}
return processed;}};var dragresize=new DragResize('dragresize',{minWidth:10,minHeight:10,minLeft:[45,45],minTop:[5,5],maxLeft:[475,610],maxTop:[310,310]});dragresize.isElement=function(elm)
{if(elm.className&&elm.className.indexOf('drsElement')>-1)return true;};dragresize.isHandle=function(elm)
{if(elm.className&&elm.className.indexOf('drsMoveHandle')>-1)return true;};dragresize.ondragfocus=function(){};dragresize.ondragstart=function(isResize){};dragresize.ondragmove=function(isResize){};dragresize.ondragend=function(isResize){};dragresize.ondragblur=function(){};dragresize.apply(document.getElementById('map_div'));

// คืนค่าเริ่มต้น
function default_select_bounds() { // open_block_1
	if($("blockDiv").style.backgroundPosition != controlTypePic[4]) { // open_block_2
		$("blockDiv").style.backgroundPosition=controlTypePic[4];
		$("link_blockDiv").title=controlTypeToolTip[4];
		clearBlock();
	} // close_block_2
} // close_block_1