var url_tabsearch = ROOT_URL+"map/images/tab_search.gif";
var url_tabsearch_active = ROOT_URL+"map/images/tab_search_active.gif";
function initializeMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			var bounds = map.getBounds();
			cur_x = center.x;
			cur_y = center.y;
			cur_width = bounds.getNorthEast().x - bounds.getSouthWest().x;
			updatePosition();
		});
		
		setTimeout("zoomInitial();", 1000);
		setTimeout("plotResultSymbol();", 1000);
	} else {
		alert("ご使用のブラウザが動作環境を満たしていない可能性があります。\nヘルプを参照してください。");
	}
}

function updatePosition() {
	var positionString = '経度 : ' + (cur_x-0.0000005).toFixed(6) + '　経度 : ' + (cur_y-0.0000005).toFixed(6) + '　マップ幅 : ' + (cur_width-0.0000005).toFixed(6);
	var target = document.getElementById('cur_position');
	target.innerHTML = positionString;
}

function plotResultSymbol() {
	var plotsymboldataElement = document.getElementById('plotsymboldata');
	var plottextstring = plotsymboldataElement.innerHTML;
	var plotstrings = plottextstring.split(";");
	icons = new Array(plotstrings.length);
	for (var i = 0; i < plotstrings.length; i++) {
		var plotparameters = plotstrings[i].split(",");
		plotSymbol(parseFloat(plotparameters[0]), parseFloat(plotparameters[1]), parseInt(plotparameters[2]), plotparameters[3]);
	}
}

function gotoItemBlock(id) {
	var targetBlock = document.getElementById(id.toString(10));
	var scrollY = 0;
	if (getBrowserType() == "IE") {
		scrollY = targetBlock.parentNode.offsetTop + targetBlock.offsetTop;
	} else {
		scrollY = targetBlock.offsetTop;
	}
	window.scrollTo(0,scrollY);
}

function gotoCommentPage() {
	document.location.href = ROOT_URL + "map/comments/addcomment_form.php?x=" + (cur_x-0.0000005).toFixed(6) + "&y=" + (cur_y-0.0000005).toFixed(6) + "&width=" + (cur_width-0.0000005).toFixed(6);
}

function showCommentsComments(id) {
	readContents(ROOT_URL + "map/commentscomments/getcomments.php?id=" + id, "commentscomments" + id);
}

function showCommentsTrackbacks(id) {
	readContents(ROOT_URL + "map/commentscomments/gettrackbacks.php?id=" + id, "commentscomments" + id);
}

function switch_CommentsComments(id){
	target = document.getElementById("commentscomments" + id);
	if (document["treebutton_comments" + id].src == ROOT_URL+"images/tree_minus.gif") {
		document["treebutton_comments" + id].src = ROOT_URL+"images/tree_plus.gif";
		document["treebutton_trackbacks" + id].src = ROOT_URL+"images/tree_plus.gif";
		target.innerHTML = "";
		target.style.height = "5px";
	} else {
		document["treebutton_comments" + id].src = ROOT_URL+"images/tree_minus.gif";
		document["treebutton_trackbacks" + id].src = ROOT_URL+"images/tree_plus.gif";
		target.style.height = "100%";
		target.innerHTML = "コメントデータロード中...";
		showCommentsComments(id);
	}
}

function switch_CommentsTrackbacks(id){
	target = document.getElementById("commentscomments" + id);
	if (document["treebutton_trackbacks" + id].src == ROOT_URL+"images/tree_minus.gif") {
		document["treebutton_trackbacks" + id].src = ROOT_URL+"images/tree_plus.gif";
		document["treebutton_comments" + id].src = ROOT_URL+"images/tree_plus.gif";
		target.innerHTML = "";
		target.style.height = "5px";
	} else {
		document["treebutton_trackbacks" + id].src = ROOT_URL+"images/tree_minus.gif";
		document["treebutton_comments" + id].src = ROOT_URL+"images/tree_plus.gif";
		target.style.height = "100%";
		target.innerHTML = "トラクバックデータロード中...";
		showCommentsTrackbacks(id);
	}
}

function addCommentsComment(id) {
	var formName = "formAddComment" + id;
	var title = document[formName].title.value;
	var excerpt = document[formName].excerpt.value;
	var url = document[formName].url.value;
	var name = document[formName].name.value;
	if (title == "" || excerpt == "") {
		alert("タイトルと本文を入力してください。");
		return;
	}
	
	var xmlhttp = new XMLHttpRequest();
	if (!xmlhttp) return;
	
	var elementCommentsComments = document.getElementById("commentscomments" + id);
	elementCommentsComments.innerHTML = "コメント書き込み中...";
	
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			elementCommentsComments.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.open('POST', ROOT_URL+'map/commentscomments/addcomment.php', true);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send("parentid=" + id + "&title=" + encodeURIComponent(title) + "&excerpt=" + encodeURIComponent(excerpt) + "&url=" + encodeURIComponent(url) + "&name=" + encodeURIComponent(name));
}

function deleteConfirmCommentsComment(id, parentid) {
	readContents(ROOT_URL+"map/commentscomments/deleteconfirmcomment.php?id=" + id + "&parentid=" + parentid, "commentscomments" + parentid);
}
function deleteCommentsComment(id, parentid) {
	readContents(ROOT_URL+"map/commentscomments/deletecomment.php?id=" + id + "&parentid=" + parentid, "commentscomments" + parentid);
}

function deleteConfirmCommentsTrackback(id, parentid) {
	readContents(ROOT_URL+"map/commentscomments/deleteconfirmtrackback.php?id=" + id + "&parentid=" + parentid, "commentscomments" + parentid);
}
function deleteCommentsTrackback(id, parentid) {
	readContents(ROOT_URL+"map/commentscomments/deletetrackback.php?id=" + id + "&parentid=" + parentid, "commentscomments" + parentid);
}
