function MapObject(map_width, map_height, control_pad)
{	
	var map;
	var geocoder;
	if(map_width && map_width!=0 && map_height && map_height!=0) {
		//map = new GMap2(document.getElementById("map"), {size:new GSize(map_width, map_height)});
		map = new google.maps.Map(document.getElementById("map"), {size:new GSize(map_width, map_height)});
	} else {
		//map = new GMap2(document.getElementById("map"));
		map = new google.maps.Map(document.getElementById("map"));
	}

	if(control_pad=="undefined" || control_pad != 0){
		map.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT));
	}
	map.disableScrollWheelZoom();
	
	var current_marker;
	var store_list = new Array();
	var store_info;
	var marker_name = "new marker";
	this.center_position_lat;
	this.center_position_lon;
	this.zoom_level;
	this.GetTargetList = function() { return store_list; };
	this.PlaceMarker = PlaceMarker;
	this.InitPositionAndZoom = InitPositionAndZoom;
	this.StartMap = StartMap;
	this.StartMapStatic = StartMapStatic;
	this.ShowMarkers = ShowMarkers;
	this.RemoveMarkers = RemoveMarkers;
	this.RegisterEvents = RegisterEvents;
	this.RegisterLocationEvents = RegisterLocationEvents;

	/* 새로운 장소등록_장소프로필_09-03-31 */
	this.clearOverlays = function() {
		map.clearOverlays();
	}
	this.RemoveMarkers_store_reg = RemoveMarkers_store_reg;
	this.RegisterEvents_store_reg = RegisterEvents_store_reg;

	this.GetClickLat = function() {
		return this.click_position_lat;
	}
	this.GetClickLon = function() {
		return this.click_position_lon;
	}
	this.PanMap = function(lat, lon, zoomlevel) {
			if(!zoomlevel)
				map.setCenter(new GLatLng(lat, lon), this.zoom_level);
			else {
				map.setCenter(new GLatLng(lat, lon), zoomlevel);
				this.zoom_level = zoomlevel;
			}
	}
	this.SettingCurrentPositionZoomlevel = function() {
					var cen_point = map.getCenter();
					this.center_position_lat = cen_point.lat();
					this.center_position_lon = cen_point.lng();
					this.zoom_level = map.getZoom();
				}
	this.SetTargetList = function(target_list) {
					store_list = target_list;
				}
	this.OpenTargetWindow = function(marker_id) {
					return;
				}
	this.CloseTargetWindow = function(marker_id) {
					return;
				}
	this.GetZoomlevel = function() {
					return map.getZoom();
				}
	this.ZoomIn = function() {
					map.zoomIn();
				}
	this.ZoomOut = function() {
					map.zoomOut();
				}
	
	function InitPositionAndZoom(center_position_lat, center_position_lon, zoom_level, map_type, markername)
	{
		this.center_position_lat = center_position_lat;
		this.center_position_lon = center_position_lon;
		this.zoom_level = zoom_level;
		if(markername != "")
			marker_name = markername;
	}
	
	function StartMap(){
		
		var center_geopoint = new GLatLng(this.center_position_lat, this.center_position_lon);

		map.setCenter(center_geopoint, this.zoom_level);
		ShowMarkers(store_list);
		GEvent.addListener(map, "singlerightclick",  function(point, src, overlay) {
			
				try{
					var latlon = map.fromContainerPixelToLatLng(point);
					click_point_lat = latlon.lat();
					click_point_lon = latlon.lng();
					var div_menu = document.getElementById("div_rightclick_menu");			
					div_menu.style.left = map.getContainer().offsetLeft + point.x;
					div_menu.style.top = map.getContainer().offsetTop + point.y;
					div_menu.style.display = "block";
				} catch(e) {
					//alert(e.message);
				}
			});
		GEvent.addListener(map, "click", function() {
			try{ 
				var div_menu = document.getElementById("div_rightclick_menu");
				div_menu.style.display = "none";
			}catch(e) {
				//alert(e.message);
			}
		});
	}
	
	function StartMapStatic(){
		
		var center_geopoint = new GLatLng(this.center_position_lat, this.center_position_lon);
		map.removeControl(new GMapTypeControl());
		map.disableScrollWheelZoom();
		map.disableDoubleClickZoom();
		map.setCenter(center_geopoint, this.zoom_level);
		ShowMarkers(store_list);
	
		try{
				var latlon = map.fromContainerPixelToLatLng(point);
				click_point_lat = latlon.lat();
				click_point_lon = latlon.lng();
		} catch(e) {
					//alert(e.message);
		}
	}

	function RegisterEvents(){
		GEvent.addListener(map, "click",function(overlay,latlng) {
			
			if(!overlay) {
				RemoveMarkers();
				PlaceMarker(latlng.lat(), latlng.lng(), marker_name, "", "");
				try{
					//geocoder.getLocations(latlng, GetAddress);
					
					ActionAfterGetPosition(latlng.lat(), latlng.lng(), "", "");
					
				} catch(e) {}
			}
		});	
	}

	

   function RegisterLocationEvents(){
		GEvent.addListener(map, "click",function(overlay,latlng) {
			
			if(!overlay) {
				RemoveMarkers();
				PlaceMarker(latlng.lat(), latlng.lng(), marker_name, "", "");
				try{
					//geocoder.getLocations(latlng, GetAddress);
					document.store_input.lat.value = latlng.lat();
					document.store_input.lng.value = latlng.lng();
					//ActionAfterGetPosition(latlng.lat(), latlng.lng(), "", "");
					
				} catch(e) {}
			}
		});	
	}

	/* 새로운 장소등록_장소프로필_09-03-31 */
	function RegisterEvents_store_reg(){	
		marker_name="현재위치";
		GEvent.addListener(map, "click",function(overlay,latlng) {
			if(!overlay) {
				RemoveMarkers_store_reg();
				//PlaceMarker_store_reg(latlng.lat(), latlng.lng(), "장소위치", "", "");
				PlaceMarker(latlng.lat(), latlng.lng(), "장소위치", "", "");
                
				try{
					//geocoder.getLocations(latlng, GetAddress);
					ActionAfterGetPosition(latlng.lat(), latlng.lng(), "", "");
				} catch(e) {}
			}
		});
	}
	function RemoveMarkers_store_reg()
	{
		store_list = new Array();

		if(current_marker)
		{	
			map.removeOverlay(current_marker);
		}
	}

	/* 새로운 장소등록_장소프로필 끝 */
	
	function PlaceMarker(lat, lon, name, etc, cat)
	{ 
		var geo_point = new GLatLng(lat, lon)
		var custumIcon = CreateCustomMarkerImage(cat, name);
		if(!name || name=="")    name=marker_name;
		else marker_name = name;
		//markerOptions = { icon:custumIcon, title:marker_name, zIndexProcess:function() {} };
		markerOptions = { icon:custumIcon, title:marker_name};
		var new_marker= new GMarker(geo_point, markerOptions);
		
		map.addOverlay(new_marker); 
		current_marker = new_marker;
		
		if(etc) {
			GEvent.addListener(new_marker, "click", function() {
				new_marker.openInfoWindowHtml(etc, {pixelOffset:new GSize(0,0), maxWidth:300});
			});
			GEvent.addListener(new_marker, "mouseover", function() {
				new_marker.openInfoWindowHtml(etc, {pixelOffset:new GSize(0,0), maxWidth:300});
			});
		}
	}

	function GetAddress(response)
	{
		try{
			var street = "";
			if (!response || response.Status.code != 200) {    
				return;
			} else {    
				place = response.Placemark[0];       
				nara = place.AddressDetails.Country.CountryName;
				if(place.AddressDetails.Country.Locality) {
					si = place.AddressDetails.Country.Locality.LocalityName; 
					gu = place.AddressDetails.Country.Locality.DependentLocality.DependentLocalityName;
					arr_addr = place.AddressDetails.Country.Locality.DependentLocality.Thoroughfare.ThoroughfareName.split(" ");
					if(arr_addr.length > 1) {
						dong = arr_addr[1]; 
						street = arr_addr[0]; 
					} else {
						dong = arr_addr[0]; 
					}
				}
				ActionAfterGetPosition(place.Point.coordinates[1], place.Point.coordinates[0], si+" "+gu+" "+dong, place.address);
			}
		}catch(e){alert(e.message);}
	}
	
	function ShowMarkers(stores)
	{
		store_list = stores;
		for(i=0; i<store_list.length; i++) 
		{
			
			if (store_list[i].position_x != 0 && store_list[i].position_y != 0)
				PlaceMarker(store_list[i].position_x, store_list[i].position_y, store_list[i].marker_name, store_list[i].etc, store_list[i].category_id);
		}
	}


	var baseIcon = new GIcon(G_DEFAULT_ICON);
    //baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(15, 15);
    baseIcon.shadowSize = new GSize(0, 0);
    baseIcon.iconAnchor = new GPoint(7, 7);
    baseIcon.infoWindowAnchor = new GPoint(7, 7);

	function CreateCustomMarkerImage(category_id, marker_name){
	 	var my_image = new GIcon(baseIcon);

		if(!category_id) {
				if(marker_name == "here"){
					my_image.iconSize = new GSize(12, 20);
					my_image.iconAnchor = new GPoint(1, 20);
					my_image.image = 'http://img.runpipe.com/v1/icon/ico_map.gif';
				}else{
					my_image.iconSize = new GSize(20, 34);
					my_image.iconAnchor = new GPoint(1, 20);
					my_image.image = 'http://www.google.com/mapfiles/marker.png';
				}
	 	}else    my_image.image = 'http://img.runpipe.com/v1/icon/ico_cat_'+category_id+'.gif';

		return my_image;
	}

	function RemoveMarkers()
	{
		store_list = new Array();
		map.clearOverlays();
	}
	
}

function getLocation() {  
	// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
	navigator.geolocation.getCurrentPosition(showLocation, showError, {enableHighAccuracy:true,maximumAge:60000});
}

function showError(error) {
	setGPSLocation();
	//alert(error.code + ' ' + error.message);
}

function showLocation(position) {

	var div_map = document.getElementById("map");
	var store_info;
	var dbl_lat = position.coords.latitude;
	var dbl_lon = position.coords.longitude;

	div_map.style.width = "95%";
	div_map.style.height = "100";

	store_info = new Object();
	store_info.town_id = "";
	store_info.town_name = "";
	store_info.marker_id = "1";
	store_info.marker_name = "here";
	store_info.position_x = dbl_lat;
	store_info.position_y = dbl_lon;
	store_info.category_id = "";
	store_info.etc = '';
	store_list.push(store_info);

	if(!obj_map) {
		obj_map = new MapObject();
	}
	obj_map.InitPositionAndZoom(dbl_lat, dbl_lon, 17, "show", "");
	obj_map.SetTargetList(store_list);
	obj_map.StartMap();

	GetAddressInfo(dbl_lat, dbl_lon);
}

function setLocation() {

	var div_map = document.getElementById("map");
	var store_info;
	var dbl_lat = 37.504378949616;
	var dbl_lon = 127.04869657861;
	var addr = "서울시 강남구 삼성동 143 선릉역";
	div_map.style.width = "95%";
	div_map.style.height = "100";

	store_info = new Object();
	store_info.town_id = "";
	store_info.town_name = "";
	store_info.marker_id = "1";
	store_info.marker_name = "here";
	store_info.position_x = dbl_lat;
	store_info.position_y = dbl_lon;
	store_info.category_id = "";
	store_info.etc = '';
	store_list.push(store_info);

	if(!obj_map) {
		obj_map = new MapObject();
	}
	obj_map.InitPositionAndZoom(dbl_lat, dbl_lon, 17, "show", "");
	obj_map.SetTargetList(store_list);
	obj_map.StartMap();

	town_addr.innerHTML = addr;
	PutAddressInfo(addr,0, 0);
}

function getDefaultTown(dbl_lat, dbl_lon) {

	var div_map = document.getElementById("map");
	var store_info;

	if(Math.abs(dbl_lat)){
		div_map.style.width = "95%";
		div_map.style.height = "100";

		store_info = new Object();
		store_info.town_id = "";
		store_info.town_name = "";
		store_info.marker_id = "1";
		store_info.marker_name = "here";
		store_info.position_x = dbl_lat;
		store_info.position_y = dbl_lon;
		store_info.category_id = "";
		store_info.etc = '';
		store_list.push(store_info);

		if(!obj_map) {
			obj_map = new MapObject();
		}
		obj_map.InitPositionAndZoom(dbl_lat, dbl_lon, 17, "show", "");
		obj_map.SetTargetList(store_list);
		obj_map.StartMap();
	}
	GetAddressInfo(dbl_lat, dbl_lon);
}

function ShowMap(div_id)
{	
	town_marker = GetTownPosition(document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value);
	
	var div_map = document.getElementById(div_id);
	div_map.style.width = "598";
	div_map.style.height = "408";
	div_map.style.display = "block";

	if(!obj_map)
	{
		obj_map = new MapObject();
		obj_map.RegisterEvents_store_reg();
	}
	obj_map.RemoveMarkers_store_reg();
	obj_map.InitPositionAndZoom(town_marker.position_x.text, town_marker.position_y.text, 16, "reg", document.store_input.store_name.value);
	obj_map.SetTargetList(store_list);

	if(dbl_x && dbl_y){
		obj_map.InitPositionAndZoom(dbl_x,dbl_y,16);
		dbl_x = null;
		dbl_y = null;
	}
	obj_map.StartMap();
}


function ShowMap_Ajax(div_id)
{   
	CallAjax('/store/add.get.towninfo.ajax.php?town_id=' + document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value, "Display_ShowMap_Ajax(responseText)");
}

function Display_ShowMap_Ajax(responseText)
{
	
	if(obj_map == "[object Object]")
	{
		obj_map.clearOverlays();
	}
	var store_info;
	store_list = null;
	store_list = new Array();

	var ret = eval("(" + responseText + ")");
	
	for(i=0; i<ret.length; i++)
	{
		store_info = new Object();
		store_info.town_id = ret[i].town_id;
		store_info.town_name =ret[i].town_name;
		store_info.marker_id = ret[i].marker_id;
		store_info.marker_name = ret[i].marker_name;
		store_info.position_x = ret[i].position_x;
		store_info.position_y = ret[i].position_y;
		store_info.image_url = ret[i].image_url;
		store_info.category_id = ret[i].category_id;
		store_info.etc = ret[i].etc;
		store_list.push(store_info);
	}
	ShowMap('map');

	// 최근등록한장소
	CallAjax('/store/add.get.town.store.list.ajax.php?town_id=' + document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value, "Display_NewStore_Ajax(responseText)");
}

function Display_NewStore_Ajax(responseText)
{
	var reg_store_new_list = document.getElementById("reg_store_new_list");
	if(responseText){
		var store_HTML = '';
		var ret = eval("(" + responseText + ")");

		for(i=0; i<ret.length; i++)
		{
			store_HTML = store_HTML + '<div class="content_reg_store_new_list"><p class="now1"><img src="http://img.runpipe.com/v1/icon/ico_cat_' + ret[i].category_id + '.gif" border="0" align="absmiddle">&nbsp;<a href="/store/index.php?store_id=' + ret[i].store_id + '" class="a_style2_3">' + ret[i].store_name + '</a></div>';
		}
		reg_store_new_list.innerHTML = store_HTML;
	}else
	{
		reg_store_new_list.innerHTML = '<p class="now7" align="center"><span class="style3_2">발굴된 장소가 없습니다 </span></p>';
	}
}

function ActionAfterGetPosition(lat, lon, main_addr, sub_addr)
{
	CallAjax("/map/address.google.ajax.php?lat="+lat+"&lon="+lon, "PutAddressInfo(responseText)");
	
	document.store_input.store_position_x.value = lat;
	document.store_input.store_position_y.value = lon;
	if(main_addr && main_addr!="undefined" && sub_addr && sub_addr!="undefined"){
	   document.store_input.store_address_main.value = main_addr;
	   document.store_input.store_address_sub.value = sub_addr;
	}
}

function GetAddressInfo(lat, lon)
{  
	CallAjax("/map/address.google.ajax.php?lat="+lat+"&lon="+lon, "PutAddressInfo(responseText)");
}

function PutAddressInfo(resonseText)
{   
	document.store_input.store_address_main.value = responseText;
	document.store_input.store_address_main.readOnly = false;
}

function GetCoordinateInfo(addr)
{ 
	CallAjax("/map/coordinate.google.ajax.php?address="+encodeURIComponent(addr), "PutCoordinateInfo(responseText)");
}

function PutCoordinateInfo(resonseText)
{	
	var text = resonseText.split(',');
	document.store_input.store_position_x.value = text[0];
	document.store_input.store_position_y.value = text[1];
	document.store_input.store_address_main.value = text[2];
}

function GetCoordinateInfo_Edit(addr)
{ 
	CallAjax("/map/coordinate.google.ajax.php?address="+encodeURIComponent(addr), "PutCoordinateInfo_Edit(responseText)");
}

function PutCoordinateInfo_Edit(resonseText)
{	
	var text = resonseText.split(',');
	document.store_input.store_position_x.value = text[0];
	document.store_input.store_position_y.value = text[1];
	//document.store_input.store_address_main.value = text[2];

	ShowCoordinateInfo_Edit(text[1],text[0]);
}

function ShowCoordinateInfo_Edit(dbl_lat, dbl_lon)
{
		var div_map = document.getElementById("map");
		div_map.style.height = "320";
		div_map.style.display = "block";
		
		if(!obj_map) {
			obj_map = new MapObject();
			obj_map.RegisterEvents();
		}

	//	obj_map.RemoveMarkers();
	//	obj_map.InitPositionAndZoom(town_marker.position_x.text, town_marker.position_y.text, parseInt(town_marker.zoomlevel.text), "reg", store_name);

		obj_map.InitPositionAndZoom(dbl_lat, dbl_lon, 16, "reg", store_name);
		obj_map.PlaceMarker(dbl_lat, dbl_lon, "", "", "");
		//obj_map.SetTargetList(arr_theme_item);
		obj_map.StartMap();
}

function ShowMapEdit(div_id, arr_theme_item)
{	
	//var town_marker = GetTownPosition(document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value);
	var div_map = document.getElementById(div_id);
	var address = document.getElementById("store_address_main").value;
   // var address = document.store_input.store_address_main.value;
	var dbl_lat;
	var dbl_lon;

	if(address==" " ){
		ShowMapTown(div_id);
	}else{
		GetCoordinateInfo_Edit(address);
	}
}

function ShowMapTown(div_id)
{	
	var town_marker = GetTownPosition(document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value);
    
	var div_map = document.getElementById(div_id);

	div_map.style.height = "320";
	div_map.style.display = "block";
	
	if(!obj_map) {
		obj_map = new MapObject();
		obj_map.RegisterEvents();
	}
	
	obj_map.RemoveMarkers();
	obj_map.InitPositionAndZoom(town_marker.position_x.text, town_marker.position_y.text, parseInt(town_marker.zoomlevel.text), "reg", store_name);
//	obj_map.SetTargetList(arr_theme_item);
	obj_map.StartMap();
}

function getGPSLocation() {
	// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
	navigator.geolocation.getCurrentPosition(showGPSLocation, showError, {enableHighAccuracy:true,maximumAge:60000});
}

function getGPSLocation_List() {
	// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
	navigator.geolocation.getCurrentPosition(showGPSLocation_List, showError, {enableHighAccuracy:true,maximumAge:60000});
}

function showGPSLocation(position) {  
	var dbl_lat = position.coords.latitude;
	var dbl_lon = position.coords.longitude;

	var latitude = document.getElementById("latitude");
	var longitude = document.getElementById("longitude");
	
	if(latitude) latitude.value = dbl_lat;
	if(longitude) longitude.value = dbl_lon;

    if(!latitude && !longitude) resetGPSAddressInfo(dbl_lat, dbl_lon);	
}

function showGPSLocation_List(position) {
	var dbl_lat = position.coords.latitude;
	var dbl_lon = position.coords.longitude;

    saveGPSAddressInfo(dbl_lat, dbl_lon);	
}

function refreshGPSLocation() {
	// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
	navigator.geolocation.getCurrentPosition(reshowGPSLocation, showError, {enableHighAccuracy:true,maximumAge:60000});
}

function refreshGPSLocation_List() {
	// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
	navigator.geolocation.getCurrentPosition(reshowGPSLocation_List, showError, {enableHighAccuracy:true,maximumAge:60000});
}

function reshowGPSLocation(position) {	

	var dbl_lat = position.coords.latitude;
	var dbl_lon = position.coords.longitude;

	resetGPSAddressInfo(dbl_lat, dbl_lon);	
}

function reshowGPSLocation_List(position) {	

	var dbl_lat = position.coords.latitude;
	var dbl_lon = position.coords.longitude;

	saveGPSAddressInfo(dbl_lat, dbl_lon);	
}

function saveGPSAddressInfo(lat, lon)
{  	
	CallAjax("/map/gps.save.ajax.php?lat="+lat+"&lon="+lon, "reloadNearStore_List(responseText, "+lat+","+lon+")");	 //sess: 세션 GPS값 업데이트 여부
}

function resetGPSAddressInfo(lat, lon)
{  
	CallAjax("/map/gps.refresh.ajax.php?lat="+lat+"&lon="+lon, "reloadNearStores(responseText)");	 //sess: 세션 GPS값 업데이트 여부
}

function reloadNearStores(resonseText){	
	var gps_stores = document.getElementById("gps_stores");
	//var gps_addr = document.getElementById("gps_addr");
	var gps_msg = document.getElementById("gps_msg");
	var text = resonseText.split('|');

	//gps_addr.innerHTML = text[0];
	gps_msg.innerHTML = '&nbsp;&nbsp;<img src="http://img.runpipe.com/v1/btn/btn_reload_wg.gif" border="0" align="absmiddle" valign="absmiddle" style="cursor:pointer" title="위치정보 새로고침" onClick="javascript:refreshGPSLocation();">&nbsp;<span class="style7_1" id="gps_addr">'+text[0]+'</span>'; 
	gps_stores.innerHTML = text[1];
}

function reloadNearStore_List(resonseText, dbl_lat, dbl_lon){	
	var gps_msg = document.getElementById("gps_msg");

	gps_msg.innerHTML = '&nbsp;&nbsp;<img src="http://img.runpipe.com/v1/btn/btn_reload_wg.gif" border="0" align="absmiddle" valign="absmiddle" style="cursor:pointer" title="위치정보 새로고침" onClick="javascript:refreshGPSLocation_List();">&nbsp;<span class="style7_1" id="gps_addr">'+ resonseText+'</span>'; 
	showSearchStoreNear(1, dbl_lat, dbl_lon, 0);
}

function GetGPSAddressInfo(lat, lon)
{  
	CallAjax("/map/address.google.ajax.php?lat="+lat+"&lon="+lon, "PutGPSAddressInfo(responseText, "+lat+", "+lon+")");
}

function PutGPSAddressInfo(resonseText, lat, lon)
{   
	var gps_bar = document.getElementById("gps_bar");
	var gps_stores = document.getElementById("gps_stores");

	var gps_addr = document.getElementById("gps_addr");
	var town_name = document.getElementById("town_name");
	var town_name_b = document.getElementById("town_name_b");
	var town_id = document.getElementById("town_id");
	var text = resonseText.split('|');

	if(Math.abs(lat)){
		gps_addr.innerHTML = text[0];
		if(town_name)	town_name.innerHTML = "<a href='/town/index.php?town_id="+text[1]+"' class='a_font1'>"+text[2]+" 촌</a>";
		if(town_name_b)	town_name_b.innerHTML = "<a href='/town/index.php?town_id="+text[1]+"' class='a_font7_b'>"+text[2]+" 촌</a>";
		if(town_id)		town_id.innerHTML = text[1];
	}else{
		//town_addr.innerHTML = "수도권 2호선 선릉역";
		//town_name.innerHTML = "<a href='/town/index.php?town_id=110'>선릉 촌</a>";
		getGPSDefault(110);
	}

	gps_bar.style.display  = "block";
	gps_stores.style.display  = "block";
}

function getGPSMsg(type) {
	var gps_msg = document.getElementById("gps_msg");
	var link_msg = document.getElementById("link_msg");

	if(type==1){
		gps_msg.innerHTML = '<p class="now7">&nbsp;&nbsp;<img src="http://img.runpipe.com/v1/icon/Firefox.png" border=0 align="absmiddle">&nbsp;<span class="style7_1" id="gps_msg">브라우져 메뉴바 하단에 위치정보 제공을 클릭해 주세요.</span></p>';
		link_msg.innerHTML="";
	}else if(type==2){
		gps_msg.innerHTML = '<p class="now7">&nbsp;&nbsp;<span class="style7_1" >위치정보를 이용할수 있는 브라우져를 추천드립니다. </span></p>';
		link_msg.innerHTML= '<p class="now7"><a href="http://www.google.com/intl/en/landing/chrome/beta/" target="_new" class="style4_3"><img src="http://img.runpipe.com/v1/favicon/favicon_30.gif" border=0 align="absmiddle">&nbsp;구글크롬</a>&nbsp;<a href="http://www.mozilla.or.kr/ko/" target="_new" class="style4_3"><img src="http://img.runpipe.com/v1/icon/Firefox.png" border=0 align="absmiddle">&nbsp;파이어폭스</a></p>';
	}else{
		gps_msg.innerHTML = '<p class="now7">&nbsp;&nbsp;<img src="http://img.runpipe.com/v1/icon/Firefox.png" border=0 align="absmiddle">&nbsp;<span class="style7_1" >주활동지역이 설정되어 있지않습니다.</span></p>';
		link_msg.innerHTML= '<p class="now7"><a href="/user/edit.php" class="style4_3">주활동지역 설정</a></p>';
	}
}

//////////////////////////////////////////search.spot.php

function showCurrentLocation(){
	if (navigator.geolocation)  
		watchLocation();  //지역좌표가 있을 때
	else  
		getDefaultTown();
}

function watchLocation() {  
	// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
	navigator.geolocation.watchPosition(showmainLocation, showError, {enableHighAccuracy:true,maximumAge:60000});
}

function showmainLocation(position) {

	var dbl_lat = position.coords.latitude;
	var dbl_lon = position.coords.longitude;

	GetMainAddressInfo(dbl_lat, dbl_lon);
}

function GetMainAddressInfo(lat, lon)
{  
	CallAjax("/map/address.google.ajax.php?lat="+lat+"&lon="+lon, "PutMainAddressInfo(responseText, "+lat+", "+lon+")");
}

function PutMainAddressInfo(resonseText, lat, lon)
{   
	var town_addr = document.getElementById("town_addr");
	var town_name = document.getElementById("town_name");
	var town_name_b = document.getElementById("town_name_b");
	var town_id = document.getElementById("town_id");
	var text = resonseText.split('|');

	if(Math.abs(lat)){
		town_addr.innerHTML = text[0];
		if(town_name)	town_name.innerHTML = "<a href='/town/index.php?town_id="+text[1]+"' class='a_font1'>"+text[2]+" 촌</a>";
		if(town_name_b)	town_name_b.innerHTML = "<a href='/town/index.php?town_id="+text[1]+"' class='a_font7_b'>"+text[2]+" 촌</a>";
		if(town_id)		town_id.innerHTML = text[1];
	}else{
		//town_addr.innerHTML = "수도권 2호선 선릉역";
		//town_name.innerHTML = "<a href='/town/index.php?town_id=110'>선릉 촌</a>";
		getmainDefaultTown();
	}
}

function getmainDefaultTown() {
	var town_addr = document.getElementById("town_addr");
	var town_name = document.getElementById("town_name");
	var town_name_b = document.getElementById("town_name_b");
	var town_id = document.getElementById("town_id");
	var addr, name, id;

	if(default_town_id){
		addr = default_town_addr;
		if(town_name)	name = "<a href='/town/index.php?town_id="+default_town_id+"' class='a_font1'>"+default_town_name+" 촌</a> ";
		if(town_name_b)	name = "<a href='/town/index.php?town_id="+default_town_id+"' class='a_font7_b'>"+default_town_name+" 촌</a> ";
		if(town_id)		id =default_town_id;
	}else{
		 addr = "수도권 2호선 선릉역";
		if(town_name)	name = "<a href='/town/index.php?town_id=110' class='a_font1'>선릉 촌</a>";
		if(town_name_b)	name = "<a href='/town/index.php?town_id=110' 'a_font7_b'>선릉 촌</a>";
		if(town_id)		id =110;
	}

	town_addr.innerHTML = addr;
	if(town_name)	town_name.innerHTML = name;
	if(town_name_b) town_name_b.innerHTML = name;
	if(town_id)		town_id.innerHTML = id;
}

function SearchStoreNear()
{ 
	if (navigator.geolocation)  
		getSearchLocation();  //지역좌표가 있을 때
	else  
		getDefaultLocation();			 
}

function getSearchLocation() { 
	// Get location no more than 10 minutes old. 600000 ms = 10 minutes.
	navigator.geolocation.getCurrentPosition(setSearchLocation, showError, {enableHighAccuracy:true,maximumAge:60000});
}

function showError(error) {
//	alert(error.code + ' ' + error.message);
}

function setSearchLocation(position) {
	var dbl_lat = position.coords.latitude;
	var dbl_lon = position.coords.longitude;

   showSearchLocationNear(1, dbl_lat,dbl_lon);
}

function getDefaultLocation() {
	var town_id = document.getElementById("town_id").value;
	var town_x = document.getElementById("town_x").value;
	var town_y = document.getElementById("town_y").value;

	if(town_id<1){
		town_id= 110;  /*디폴트촌=선릉*/
		town_x=	37.504378949616;
		town_y=	127.04869657861;
	}  
	showSearchLocationNear(1, town_x, town_y);
}

//////////////////////////////20110817 web display 
function showSearchLocationNear(page, dbl_lat, dbl_lon) {

   CallAjax("../location.search.php?dbl_lat="+dbl_lat+"&dbl_lon="+dbl_lon+"&page="+ page,"DisplayStoreLocationNear(responseText)");
}
function DisplayStoreLocationNear(responseText)
{  
	  var list_store = document.getElementById("list_store_location");
	  list_store.innerHTML = responseText;
	  list_store.style.display = "block";
}



//////////////////////////////20110815 mobile display
function showSearchStoreNear(page, dbl_lat, dbl_lon) {
	   
   CallAjax("/inc/m.search.store.near.php?dbl_lat="+dbl_lat+"&dbl_lon="+dbl_lon+"&page="+ page,"DisplayStoreNear(responseText)");
}

function DisplayStoreNear(text)
{
	  var target = document.getElementById("list_store");
	  target.innerHTML = text;
}



function ShowMapSearchSpot(div_id,lat,lon,town_id)
{	
	
    var list_store = document.getElementById("list_store_location");
    list_store.style.display = "none";
	var div_map = document.getElementById(div_id);
    var dbl_lat;
	var dbl_lon;
	div_map.style.height = "320";
	div_map.style.width = "600";
	div_map.style.display = "block";
	
	
	obj_map = new MapObject();
	obj_map.RegisterEvents();
	obj_map.RegisterLocationEvents();

    

	/*if(town_id==777 || town_id==0){
	if(document.store_input.lat.value){
		dbl_lat = document.store_input.lat.value;
		dbl_lon = document.store_input.lng.value;

	}else{
	
        dbl_lat = 37.504378949616;
	    dbl_lon = 127.04869657861;
	}
	}else{*/
	if(document.store_input.lat.value){
		dbl_lat = document.store_input.lat.value;
		dbl_lon = document.store_input.lng.value;

	}else{
        dbl_lat = lat;
	    dbl_lon = lon;
	}
	//}
	
	obj_map.InitPositionAndZoom(dbl_lat, dbl_lon, 16, "show", "");
    obj_map.StartMap();
	obj_map.PlaceMarker(dbl_lat,dbl_lon, "장소위치", "", "");
}

