
var shopSelectID = "";
var mapCenterPos ="";
var mapCenterAddress = "";
var mapObj;
var gPos;

var isFirstSearch = true;


function sendMob(targetObj, id){
	shopSelectID = id;
	myLightbox.textStart(targetObj, "text_mob");
}

function sendmail(){
	var mail = $('mail').value.split("@");
	new Ajax.Updater(
			"lightFlashOrText",
			"mail.php",
			{
				parameters : "shop_id=" + shopSelectID + "&mail1=" + mail[0] + "&mail2=" + mail[1],
				method : "get",
				onFailure : function() {
					alert("error");
				}
			}
	);
	sendToGoogle("/shop_search/mobile/shop_id=" + shopSelectID);
}

function shopSearch(){
	shopSearch2($('pref').options[$('pref').selectedIndex].value, $('citycode').options[$('citycode').selectedIndex].value, 1);
}

function shopSearch2(pref, citycode, page){
	new Ajax.Updater(
			"resultArea",
			"list.php",
			{
				parameters : "pref=" + pref + "&citycode=" + citycode + "&page=" + page,
				method : "get",
				onComplete : function() {
					$('footer').style.display = "none";
					$('footer').style.display = "block";
				},
				onFailure : function() {
					alert("error");
				}
			}
	);
	sendToGoogle("/shop_search/index/pref=" + pref + "&citycode=" + citycode + "&page=" + page);
	if(isFirstSearch){
		isFirstSearch = false;
		new Ajax.Request("conv.html", {
			method : "get"//,
			//onSuccess: function(r){alert(r.responseText)}
		});
	}
}


function viewDetail(id){
	new Ajax.Updater(
			"detail",
			"detail.php",
			{
				parameters : "shop_id=" + id,
				method : "get",
				onComplete : function() {
					$('list').style.display = "none";
					$('detail').style.display = "block";
					mapCenterPos = $('mapCenterPos').value;
					mapCenterAddress = $('mapCenterAddress').value;
					mapLoad();
				},
				onFailure : function() {
					alert("error");
				}
			}
	);
	sendToGoogle("/shop_search/details/shop_id=" + id);
}


function viewList(){
	$('list').style.display = "block";
	$('detail').style.display = "none";
}


function mapLoad(printable){
	if (GBrowserIsCompatible()) {
		GUnload();
		mapObj = new GMap2($("gmap"));
		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{
		$("gmap").innerHTML = "<p>地図が表示できません</p>";
	}
}

function geoLoad(gPosObj) {
	if (gPosObj) {
		gPos = gPosObj;
		mapObj.setCenter(gPosObj, 15);
		mapObj.addOverlay(new GMarker(gPosObj));
	}else{
		$("gmap").innerHTML = "<p>地図が見つかりませんでした</p>";
	}
}

var printWaitCount = 0;
function printWait(){
	if(mapObj.isLoaded()){
		printWaitCount = 0;
		window.print();
	}else if(printWaitCount < 10){
		printWaitCount++;
		setTimeout(printWait, 1000);
	}
}


function doSearchCheck(){
	if(jQuery("#pref").val() == "" || jQuery("#citycode").val() == ""){
		jQuery("#doSearchOn").css("display", "none");
		jQuery("#doSearchOff").css("display", "inline");
	}else{
		jQuery("#doSearchOn").css("display", "inline");
		jQuery("#doSearchOff").css("display", "none");
	}
}

