/*えう*/
/*
map = new GMap2(document.getElementById("gmap"));
iconObj = new GIcon();
iconObj.image = "./ico/hanabi01.gif";
iconObj.iconSize = new GSize(11,11);
iconObj.iconAnchor = new GPoint(0,0);
*/

map = new GMap2(document.getElementById("gmap"));

function disp_gmap() {
	map = new GMap2(document.getElementById("gmap"));
	if (GBrowserIsCompatible()) {
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(36.94989178681327, 138.603515625), 4);
		map.addControl(new GOverviewMapControl(new GSize(100,100)));
		addMarker(map);
	}
	return 1 ;
}

function re_disp_gmap() {
//	map = GMap2(document.getElementById("gmap"));
	if (GBrowserIsCompatible()) {
		map.clearOverlays();
		addMarker(map);
	}
/*
*/
	return 1 ;
}

function addMarker(map) {
//	var xmlData = httpObj.responseXML;
	var pointData = document.getElementsByTagName('form');
	for (var i=1; i<pointData.length; i++) {
//		if(pointData[i].gmapx) alert('i=' + i + ';');
		if(pointData[i].gmapx.value != null){
			var rnd = Math.ceil(Math.random() * 8) ;
			iconObj = new GIcon();
			iconObj.image = "./ico/hanabi0" + rnd + ".gif";
			iconObj.iconSize = new GSize(11,11);
			iconObj.iconAnchor = new GPoint(6,6);
			var mx = pointData[i].gmapx.value;
			var my = pointData[i].gmapy.value;
/*
			var mid = pointData[i].id.value;
			var mz = pointData[i].gmapz.value;
			var mdname = pointData[i].dname.value;
			var mpref = pointData[i].pref.value;
			var madd_l2 = pointData[i].add_l2.value;
			var madd_l3 = pointData[i].add_l3.value;
*/
			var marker = new GMarker(new GLatLng(my, mx),iconObj);
			map.addOverlay(marker);
/*
			GEvent.addListener(marker, 'mouseover', function() {
				marker.openInfoWindow(
					document.createTextNode(mdname + "\n" + mpref + " " + madd_l2 + " " + madd_l3));
				map.setZoom = mz ;
				});
			GEvent.addListener(marker, 'mouseout', function() {
				map.closeInfoWindow();
				map.setZoom = 4 ;
				});
*/
		}
	}
	return 1 ;
}


function serch(q){
	var gGeo = new GClientGeocoder();
	gGeo.getLatLng(q,onGeocoding);
	return 1 ;
}

function on_add_button(){
	q = "" ;
//	q = document.getElementById('add_l1').text + ' ' + document.getElementById('add_l2').value ;
	for(i = 0; i < document.getElementById('add_l1').options.length; i++){
		if(document.getElementById('add_l1').options[i].selected){
			q = document.getElementById('add_l1').options[i].text ;
		}
	}
	q = q + ' ' + document.getElementById('add_l2').value ;
//	q = q + ' ' + document.getElementById('add_l3').value ;
	serch(q);
	return 1;
}

function onGeocoding(ggpoint){
	if(ggpoint){
			if(map.getZoom() <= 10){
				map.setZoom(11) ;
			}
			map.panTo(ggpoint);
			map.clearOverlays();
			iconObj = new GIcon();
			iconObj.image = "./ico/hanabi01.gif";
			iconObj.iconSize = new GSize(11,11);
			iconObj.iconAnchor = new GPoint(6,6);
			marker = new GMarker(ggpoint, iconObj);
			map.addOverlay(marker);
			document.getElementById('gmapx').value = ggpoint.x ;
			document.getElementById('gmapy').value = ggpoint.y ;
			document.getElementById('gmapz').value = 11 ;
	}
	return 1 ;
}
/*
*/


function likes(in_id,out_id) {
	data = document.getElementById(in_id).value ;
	if(data.length <= 0) {
		document.getElementById(out_id).innerHTML = '' ;
		return 0 ;
	}
	url_data = encodeURIComponent(data) ;
	url = './day_search_ajax.php?day=' + url_data ;
	text = requestFile( out_id , 'GET' , url , true ) ;
	return 1 ;
}

function likes_click(like,id) {
	document.getElementById(id).value = like ;
	return 1 ;
}


//XMLHttpRequestオブジェクト生成
function createHttpRequest(){

	//Win ie用
	if(window.ActiveXObject){
			try {
					//MSXML2以降用
					return new ActiveXObject("Msxml2.XMLHTTP") //[1]'
			} catch (e) {
					try {
							//旧MSXML用
							return new ActiveXObject("Microsoft.XMLHTTP") //[1]'
					} catch (e2) {
							return null
					}
			 }
	} else if(window.XMLHttpRequest){
			//Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
			return new XMLHttpRequest() //[1]'
	} else {
			return null
	}
}

//ファイルにアクセスし受信内容を確認します
function requestFile( data , method , fileName , async )
{
	//XMLHttpRequestオブジェクト生成
	var httpoj = createHttpRequest() //[1]
	
	//open メソッド
	httpoj.open( method , fileName , async ) //[2]
	
	//受信時に起動するイベント
	httpoj.onreadystatechange = function()	//[4]
	{ 
		//readyState値は4で受信完了
		if (httpoj.readyState==4)	//[5]
		{ 
			//コールバック
			on_loaded(httpoj, data)
		}
	}
	
	//send メソッド
	httpoj.send( data ) //[3]
		
}

//コールバック関数 ( 受信時に実行されます )
function on_loaded(oj, id)
{
			//レスポンスを取得
		res	= oj.responseText //[6]
			
			//ダイアログで表示
		if(res.length > 0) {
			document.getElementById(id).innerHTML = res ;
		}

}


