
var mapCenterPos ="";
var mapCenterAddress = "";
var mapObj;
var gPos;

function mapLoad(){
	if (GBrowserIsCompatible()) {
		mapObj = new GMap2($("shopMap"));
		mapObj.addControl(new GLargeMapControl());
		if(mapCenterPos){
			var pos = mapCenterPos.split(",");
			gPos = new GLatLng(pos[0], pos[1]);
			mapObj.setCenter(gPos, 15);
			mapObj.addOverlay(new GMarker(gPos));
		}else{
			var gGeo = new GClientGeocoder();
			gGeo.getLatLng(mapCenterAddress, geoLoad);
		}
	}else{
		$("shopMap").innerHTML = "地図が表示できません";
	}
}

function geoLoad(gPosObj) {
	if (gPosObj) {
		gPos = gPosObj;
		mapObj.setCenter(gPosObj, 15);
		mapObj.addOverlay(new GMarker(gPosObj));
	}else{
		$("shopMap").innerHTML = "地図が見つかりませんでした";
	}
}


function creatMapTool(address){
	$('gtool').style.display = "block";
	$('shopMap').style.width = "624px";
	$('shopMap').style.height = "500px";
	$('gtoolad').value = address;
	mapCenterPos = "";
	mapCenterAddress = address;
	mapLoad();
	Event.observe(window, 'unload', GUnload, false);
}

function creatMapTool2(pos){
	if(pos){
		$('gtool').style.display = "block";
		$('shopMap').style.width = "624px";
		$('shopMap').style.height = "500px";
		mapCenterPos = pos;
		mapCenterAddress = "";
		mapLoad();
		Event.observe(window, 'unload', GUnload, false);
	}else{
		alert("座標が入力されていません");
	}
}

function getCenterPos(){
	var cObj = mapObj.getCenter();
	if(cObj){
		$('g_map').value = cObj.y+","+cObj.x;
	}
}

