var NO_IMAGE = "images/common/no_image.jpg";

var WINDOW = 0;
var POPUP = 1;
var PRINT = 2;

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload)
				oldonload();

			func();
		}
	}
}

function addClickEvent(func) {
	var oldonclick = document.body.onclick;
	if (typeof document.body.onclick != 'function') {
 		document.body.onclick = func;
	} else {
 		document.body.onclick = function() {
  			if (oldonclick)
     			oldonclick();

			func();
 		}
	}
}

function addLoginEvent(func) {
	return WitEvent.addListener(document.body, "login", func);
}

function addLogoutEvent(func) {
	return WitEvent.addListener(document.body, "logout", func);
}

function addMyPointEvent(func) {
	return WitEvent.addListener(document.body, "mypoint", func);
}

function addListStartEvent(func) {
	return WitEvent.addListener(document.body, "liststart", func);
}

function addListEndEvent(func) {
	return WitEvent.addListener(document.body, "listend", func);
}

function removeEvent(listener) {
	WitEvent.removeListener(listener);
}

function triggerLogin() {
	WitEvent.trigger(document.body, "login");
}

function triggerLogout() {
	WitEvent.trigger(document.body, "logout");
	savedFunc = null;
	savedArgs = null;
}

function triggerMyPoint() {
	WitEvent.trigger(document.body, "mypoint");
}

function triggerListStart() {
	WitEvent.trigger(document.body, "liststart");
}

function triggerListEnd() {
	WitEvent.trigger(document.body, "listend");
}

function setUserID(id) {
	userID = id;
}

var savedFunc = null;
var savedArgs = null;

function checkLogin(func, args) {
	if (userID != "") {
		if (func)
			func(args);
	} else {
		if (func) {
			savedFunc = func;	//showMyBase()
			savedArgs = args;	//START
			var listener = addLoginEvent(runSavedFunc);
			openLoginWindow();
		}
	}
}

function runSavedFunc() {
	if (savedFunc)
		savedFunc(savedArgs);
}

function openLoginWindow() {
	openWindow("/jsp/shared/LoginWindow.jsp", "로그인", 420, 370, POPUP);
}

function openMyPOIRegister(pid) {
	openWindow("/jsp/user/MyPOIRegister.jsp?PID=" + pid, "지점담기", 400, 320, POPUP);
}

function openScrapWindow(cid) {
	openWindow("/jsp/travel/Scrap.jsp?CID=" + cid, "스크랩하기", 380, 230, POPUP);
}

function openPrintWindow(type, pid, cid, radius, category) {
	var args = "TYPE=" + type + "&PID=" + pid;

	if (cid)
		args += "&CID=" + cid;

	if (radius)
		args += "&RADIUS=" + radius;

	if (category)
		args += "&CATEGORY=" + escape(category);

	openWindow("/jsp/travel/Print.jsp?" + args, "인쇄하기", 780, 700, PRINT);
}

function getMyBase() {
	new Ajax.Request("/jsp/lib/UserManager.jsp", {
		method: "post",
		asynchronous: false,
		parameters: { TASK: "GET_BASE", USERID: userID },
		onSuccess: function(transport) {
			var data = eval("(" + transport.responseText + ")");
			baseAddress = data.ADDRESS;
			baseTitle = data.TITLE;
			baseX = data.X_POS;
			baseY = data.Y_POS;
			basePOI = data.POI;
		},
		onFailure: function() {
			alert("기본 지점을 가져오지 못했습니다.");
		}
	});
}

function showPOIRoadSearch(title, x, y, cid) {
	$("poi_road_dest").innerHTML = title;
	$("poi_road_dest_x").innerHTML = x;
	$("poi_road_dest_y").innerHTML = y;
	if(cid) $("cid_for_booknavi").innerHTML = cid;

	$("poi_road_dest_mypoint").innerHTML = title;
	$("poi_road_dest_search").innerHTML = title;

	$("DIV_poi_road").style.left = (cursorX - 380) + "px";
	$("DIV_poi_road").style.top = (cursorY + 10)  + "px";
	$("DIV_poi_road_end").style.display = "none";
	$("DIV_poi_road").style.display = "block";

	selectPOIRoadSearchTab("search");

	if (userID != "") {
		getMyBase();

		if (baseTitle && baseTitle != "") {
			$("poi_road_start_mypoint").innerHTML = baseTitle;
			$("poi_road_start").innerHTML = baseTitle;
			$("poi_road_start_x").innerHTML = baseX;
			$("poi_road_start_y").innerHTML = baseY;

		} else {
			$("poi_road_start_mypoint").innerHTML = "설정된 내 기본 지점이 없습니다. <a href='javascript:hidePOIRoadSearch();showMyPoint();'><설정하기></a> ";
		}
	} else {
		$("poi_road_start_mypoint").innerHTML = "로그인 후 이용해 주십시오. <a href='javascript:hidePOIRoadSearch();openLoginWindow();'><로그인하기></a>";
	}

}

function showPOIRoadSearchEnd(title, x, y, cid) {
	$("Spoi_road_start").innerHTML = title;
	$("Spoi_road_start_x").innerHTML = x;
	$("Spoi_road_start_y").innerHTML = y;
	if(cid) $("Scid_for_booknavi").innerHTML = cid;

	$("Spoi_road_start_mypoint").innerHTML = title;
	$("Spoi_road_start_search").innerHTML = title;

	$("DIV_poi_road_end").style.left = (cursorX - 380) + "px";
	$("DIV_poi_road_end").style.top = (cursorY + 10)  + "px";
	$("DIV_poi_road").style.display = "none";
	$("DIV_poi_road_end").style.display = "block";

	$("SDIV_poi_road_mypoint").style.display = "none";
	$("SDIV_poi_road_search").style.display = "block";

	if (userID != "") {
		getMyBase();

		if (baseTitle && baseTitle != "") {
			$("Spoi_road_dest_mypoint").innerHTML = baseTitle;
			$("Spoi_road_dest").innerHTML = baseTitle;
			$("Spoi_road_dest_x").innerHTML = baseX;
			$("Spoi_road_dest_y").innerHTML = baseY;

		} else {
			$("Spoi_road_dest_mypoint").innerHTML = "설정된 내 기본 지점이 없습니다. <a href='javascript:hidePOIRoadSearch();showMyPoint();'><설정하기></a> ";
		}
	} else {
		$("Spoi_road_dest_mypoint").innerHTML = "로그인 후 이용해 주십시오. <a href='javascript:hidePOIRoadSearch();openLoginWindow();'><로그인하기></a>";
	}
}

function hidePOIRoadSearch() {
	$("DIV_poi_road").style.display = "none";
	$("DIV_poi_road_end").style.display = "none";
}

function selectPOIRoadSearchTab(type) {
	$("DIV_poi_road_mypoint").style.display = "none";
	$("DIV_poi_road_search").style.display = "none";
	$("DIV_poi_road_" + type).style.display = "block";
}

function doPOIRoadSearch() {
	var sn = $("poi_road_start").innerHTML;
	var en = $("poi_road_dest").innerHTML;
	var vn = "|";
	var cid = $("cid_for_booknavi").innerHTML;

	var sp = Math.round($("poi_road_start_x").innerHTML) + "," + Math.round($("poi_road_start_y").innerHTML);
	var ep = Math.round($("poi_road_dest_x").innerHTML) + "," + Math.round($("poi_road_dest_y").innerHTML);
	var vp = "|";

	var ro = "R";
	var rt = 1;
	var ho = "";

	openWindow("/jsp/road/road_detail.jsp?SN=" + encodeURIComponent(sn) + "&EN=" + encodeURIComponent(en) + "&VN=" + encodeURIComponent(vn) + "&S_POS=" + encodeURIComponent(sp) + "&E_POS=" + encodeURIComponent(ep) + "&V_POS=" + encodeURIComponent(vp) + "&RO=" + encodeURIComponent(ro) + "&RT=" + encodeURIComponent(rt) + "&HO=" + encodeURIComponent(ho)+ "&CID=" + cid, "booknavi", 800, 700, PRINT);
	hidePOIRoadSearch();
}

function doPOIRoadSearch2() {
	var sn = $("Spoi_road_start").innerHTML;
	var en = $("Spoi_road_dest").innerHTML;
	var vn = "|";
	var cid = $("Scid_for_booknavi").innerHTML;

	var sp = Math.round($("Spoi_road_start_x").innerHTML) + "," + Math.round($("Spoi_road_start_y").innerHTML);
	var ep = Math.round($("Spoi_road_dest_x").innerHTML) + "," + Math.round($("Spoi_road_dest_y").innerHTML);
	var vp = "|";

	var ro = "R";
	var rt = 1;
	var ho = "";

	openWindow("/jsp/road/road_detail.jsp?SN=" + encodeURIComponent(sn) + "&EN=" + encodeURIComponent(en) + "&VN=" + encodeURIComponent(vn) + "&S_POS=" + encodeURIComponent(sp) + "&E_POS=" + encodeURIComponent(ep) + "&V_POS=" + encodeURIComponent(vp) + "&RO=" + encodeURIComponent(ro) + "&RT=" + encodeURIComponent(rt) + "&HO=" + encodeURIComponent(ho)+ "&CID=" + cid, "booknavi", 800, 700, PRINT);
	hidePOIRoadSearch();
}

function changeSearchTab(tabName) {
	if (tabName == 'myInfo') {
		$("search_tab_on_myInfo").style.display = "";
		$("search_tab_on_search").style.display = "none";

		$("search_tab_off_myInfo").style.display = "none";
		$("search_tab_off_search").style.display = "";

		$("DIV_poi_road_mypoint").style.display = "";
		$("DIV_poi_road_search").style.display = "none";
	} else {
		$("search_tab_on_myInfo").style.display = "none";
		$("search_tab_on_search").style.display = "";

		$("search_tab_off_myInfo").style.display = "";
		$("search_tab_off_search").style.display = "none";

		$("DIV_poi_road_mypoint").style.display = "none";
		$("DIV_poi_road_search").style.display = "";
	}
}

function changeSearchTab2(tabName) {
	if (tabName == 'myInfo') {
		$("Ssearch_tab_on_myInfo").style.display = "";
		$("Ssearch_tab_on_search").style.display = "none";

		$("Ssearch_tab_off_myInfo").style.display = "none";
		$("Ssearch_tab_off_search").style.display = "";

		$("SDIV_poi_road_mypoint").style.display = "";
		$("SDIV_poi_road_search").style.display = "none";
	} else {
		$("Ssearch_tab_on_myInfo").style.display = "none";
		$("Ssearch_tab_on_search").style.display = "";

		$("Ssearch_tab_off_myInfo").style.display = "";
		$("Ssearch_tab_off_search").style.display = "none";

		$("SDIV_poi_road_mypoint").style.display = "none";
		$("SDIV_poi_road_search").style.display = "";
	}
}

function changeMyPointTab(type) {
	if (type == 'mypoint') {
		$("mypoint_by_addr_on").style.display = '';
		$("mypoint_by_name_on").style.display = 'none';

		$("mypoint_by_addr_off").style.display = 'none';
		$("mypoint_by_name_off").style.display = '';

		$("mypoint_by_addr").style.display = '';
		$("mypoint_my_name").style.display = 'none';
	} else {
		$("mypoint_by_addr_on").style.display = 'none';
		$("mypoint_by_name_on").style.display = '';

		$("mypoint_by_addr_off").style.display = '';
		$("mypoint_by_name_off").style.display = 'none';

		$("mypoint_by_addr").style.display = 'none';
		$("mypoint_my_name").style.display = '';
	}
}

function closeWindows() {
 	hideMyPoint();

 	if ($("DIV_recommend"))
 		hidePopup();
}

function showMyPoint() {
	closeWindows();
	$("DIV_mypoint").style.display = "block";
}

function hideMyPoint() {
	$("DIV_mypoint").style.display = "none";
}

function setMyPointAddress() {
	$("mypointAddress").style.backgroundImage = "url(none)";

	new Ajax.Request("jsp/lib/UserManager.jsp", {
		method: "post",
		parameters: { TASK: "GET_ADDRESS", ID: userID },
		onSuccess: function(transport) {
			var data = eval("(" + transport.responseText + ")");
			if (data.DONG_ADDR) {
				$("mypointAddress").value = data.DONG_ADDR + " " + data.DETAIL_ADDR;
				baseAddress = data.DONG_ADDR + " " + data.DETAIL_ADDR;
				baseTitle = baseAddress;
				baseX = data.XPOS;
				baseY = data.YPOS;
			} else {
				alert("가져올 수 없는 주소입니다.");
			}
		},
		onFailure: function() {
			alert("주소를 가져오지 못했습니다.");
		}
	});
}

function setMyPoint() {
	basePOI = $("mypointPID").value;
	if (basePOI != "")
		baseTitle = $("mypointPOI").value;

	new Ajax.Request("jsp/lib/UserManager.jsp", {
		method: "post",
		parameters: { TASK: "SET_BASE", ID: userID, TITLE: baseTitle, X: baseX, Y: baseY, POI: basePOI, ADDRESS: baseAddress },
		onSuccess: function(transport) {
		alert("설정되었습니다.");
		triggerMyPoint();
		hideMyPoint();
		},
		onFailure: function() {
			alert("오류가 발생했습니다.");
		}
	});
}

function searchMyPoint() {
	openWindow("jsp/shared/MyPointSearch.jsp?KW=" + $("mypointPOI").value, "기본 지점 검색", 380, 450, POPUP);
}

function openPOISearchWindow() {
	openWindow("/jsp/shared/POISearch.jsp", "지점 검색", 400, 500, POPUP);
}

function openPOISearchWindow2() {
	openWindow("/jsp/shared/POISearch.jsp?type=end", "지점 검색", 400, 500, POPUP);
}

function openWindow(url, title, width, height, type) {
	var args = "";
	args += "width=" + width + ",";
	args += "height=" + height + ",";

	if (!type)
		type = WINDOW;

	if (type == POPUP)
		args += "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
	else if (type == PRINT)
		args += "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0";
	else
		args += "toolbar=1,location=1,status=1,menubar=1,scrollbars=1,resizable=1";

	window.open(url, "_blank", args);
}

function openEditorWindow() {
	window.open("Editor1.jsp", "editor", "width=717,height=700,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0");
}

function markerOn(i) {
	var marker = markerList[i];
	if (marker)
		marker.onMouseOver();
}

function markerOff(i) {
	var marker = markerList[i];
	if (marker)
		marker.onMouseOut();
}

function openBalloon(i) {
	var marker = markerList[i];
	if (marker)
		marker.openWindow();
}

function closeBalloon() {
	map.closeInfoWindow();
}

function openImage(image) {
	if (image.indexOf("http://") == -1) {
		if (image.charAt(0) != '/')
			image = "/" + image;

		image = "http://www.livemap.co.kr" + image;
	}

	window.open("/jsp/shared/ImageView.jsp?IMAGE=" + image, "image", "width=818,height=604,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0");
}

function checkEnter(e) {
	var characterCode;

	if (e && e.which) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}

	if (characterCode == 13)
		return true;
	else
		return false;
}

function hideSelectBoxes() {
	var boxes = document.getElementsByTagName("select");
	if (boxes.length) {
		for (var i = 0; i < boxes.length; i++){
			boxes[i].style.visibility = "hidden";
		}
	} else if (boxes.style) {
		boxes.style.visibility = "hidden";
	}

}

function showSelectBoxes() {
	var boxes = document.getElementsByTagName("select");
	if (boxes.length) {
		for (var i = 0; i < boxes.length; i++)
			boxes[i].style.visibility = "visible";
	} else if (boxes.style) {
		boxes.style.visibility = "visible";
	}
}

function removeChildren(id) {
	var obj = $(id);
	var children = obj.childElements();

	for (var i = 0; i < children.length; i++)
		children[i].remove();
}

function addOption(id, name, value) {
	var opt = document.createElement("option");
	opt.innerText = name;
	opt.value = value;
	$(id).appendChild(opt);
}

function showIntersectionImage(title, url, desc) {
	var icon = '<img src="images/map/icon_mosic1.gif" width="17" height="16">';
	if (title == "")
		icon = "";

	$("DIV_intersection_title").innerHTML = title;
	$("DIV_intersection_icon").innerHTML = icon;
	$("DIV_intersection_image").innerHTML = '<a href="javascript:hideIntersectionImage()"><img src="' + url + '" width="800" height="480" style="border:1px solid #a4a4a4; "></a>';
//	$("DIV_intersection_desc").innerHTML = desc;

	$("DIV_intersection_layer").style.display = "";
	$("DIV_intersection_shadow").style.display = "";
}

function hideIntersectionImage() {
	$("DIV_intersection_layer").style.display = "none";
	$("DIV_intersection_shadow").style.display = "none";
}

function shapeText(text, provider) {
	if (!text)
		return "";

	if (text.indexOf("<P>") != -1 || text.indexOf("<p>") != -1)
		text = text.replace(/<P>&nbsp;<\/P>/g, "");

	if (!provider || provider != 2)
		text = text.replace(/(<br>\r)+/ig, "");
	//	text = text.replace(/\n/g, "<br>");

	return text;
}

function stripImg(text) {
	if (!text)
		return "";

	text = text.replace(/<P align=center><IMG(.*)>/g, "");
	text = text.replace(/\[(.*)\]/g, "");
	text = text.replace(/<P align=center>&lt;(.*)&gt;<\/P>/g, "");
	text = text.replace(/&lt;(.*)&gt;&nbsp;/g, "");
	text = text.replace(/<P style=.LINE-HEIGHT: 100%.><\/P><BR>/g, "");
	text = text.replace(/<P align=center><\/P><BR>/g, "");
	text = text.replace(/&nbsp;/g, "");
	text = text.replace(/<br><P align=left><\/P>/ig, "");

	return text;
}

function showLoading() {
	hidePOIRoadSearch();
	showShadow();
	$("DIV_loading").style.height = getHeight() + "px";
	$("DIV_loading").style.display = "";
}

function hideLoading() {
	hideShadow();
	$("DIV_loading").style.display = "none";
}

function showShadow() {
	$("DIV_shadow").style.display = "";
	$("DIV_shadow").style.left = "0px";
	$("DIV_shadow").style.top = "0px";
	$("DIV_shadow").style.width = (document.body.offsetWidth + 20) + "px";
	$("DIV_shadow").style.height = (document.body.offsetHeight) + "px";
	$("DIV_shadow").style.zIndex = "110";
}

function hideShadow() {
	$("DIV_shadow").style.display = "none";
}

function formatDate(date) {
	return date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8);
}

function formatDateTime(datetime) {
	var date = formatDate(datetime);
	return date + " " + datetime.substring(8, 10) + ":" + datetime.substring(10, 12);
}

function calcDistance(p1, p2) {
	var distance = p1.distanceFrom(p2);
	var num = new Number(distance / 1000);

	return num.toFixed(1);
}

function getPOI(pid, noPopup) {
	if (!noPopup)
		$("formDetail").target = "_blank";

	$("PID").value = pid;
	$("CID").value = "";
	$("formDetail").submit();
}

function getDetail(cid, noPopup) {
	if (!noPopup)
		$("formDetail").target = "_blank";

	$("PID").value = "";
	$("CID").value = cid;
	$("formDetail").submit();
}

function katechToLCode(point) {
	var n0, phi1, BN, nm, error, origin_lat, nn, M, N, t;
	var lon, lat;

	lon = point.x - 400000.0;
	lat = point.y - 600000.0;

	origin_lat = rad(38.0);
	n0 = fnxco(origin_lat);
	phi1 = origin_lat;

	var a = 6377397.155;
	var ee = 0.006674372231315;
	var en_m0 = 0.9999;
	var pi = 3.14159265358979323846;

	do {
		BN = fnxco(phi1);
		nm = n0 + lat / en_m0;
		error = (BN - nm) * Math.pow((1 - ee * Math.sin(phi1) * Math.sin(phi1)), 1.5) / (a * (1 - ee));
		phi1 -= error;
	} while (Math.abs(error) > 10e-10);

	nn = ee / (1 - ee) * Math.pow(Math.cos(phi1), 2.0);
	M = a * (1 - ee) / Math.pow((1 - ee * Math.pow(Math.sin(phi1), 2.0)), 1.5);
	N = a / Math.sqrt(1 - ee * Math.pow(Math.sin(phi1), 2.0));
	t = Math.tan(phi1);

	lat = phi1 - lon * lon * t / (2 * M * N * en_m0 * en_m0) + Math.pow(lon, 4.0) * t / (24 * M * Math.pow(N, 3.0) + Math.pow(en_m0, 4.0)) * (5 + 3 * t * t + nn - 9 * t * t * nn);
	lon = lon / (N * en_m0 * Math.cos(phi1)) - Math.pow(lon, 3.0) / (6 * Math.pow(N, 3.0) * Math.pow(en_m0, 3.0) * Math.cos(phi1)) * (1 + 2 * t * t + nn) + Math.pow(lon, 5) / (120 * Math.pow(N, 5.0) * Math.pow(en_m0, 5.0) * Math.cos(phi1)) * (5 + 28 * t * t + 24 * Math.pow(t, 4.0));

	var regY = lat * 180.0 / pi;
	var regX = lon * 180.0 / pi + 128.0;

	var x1 = Math.floor(regX);
	var x2 = Math.floor((regX - x1) * 60);
	var x3 = Math.floor((((regX - x1) * 60) - x2) * 60);

	var y1 = Math.floor(regY);
	var y2 = Math.floor((regY - y1) * 60);
	var y3 = Math.floor((((regY - y1) * 60) - y2) * 60);

	var iLon = parseInt((parseInt(x1) - 125) * 3600 * 3 + parseInt(x2) * 60 * 3 + parseInt(x3) * 3.0 + 0.5 + 10000);
	var iLat = parseInt((parseInt(y1) - 33) * 3600 * 3 + parseInt(y2) * 60 * 3 + parseInt(y3) * 3.0 + 0.5 + 10000);

	var lcode = iLat + "" + iLon;

	return lcode.substring(0, 3) + "-" + lcode.substring(3, 6) + "-" + lcode.substring(6, 10);
}

function lcodeToKatech(lcode) {
	if (lcode == null)
		return null;

	lcode = lcode.replace(/-/g, "");
	
	if (lcode.length != 10)
		return null;
		
	var tLat = lcode.substring(0, 5);
	var tLon = lcode.substring(5, 10);
	
	var iLat = new Number(tLat);
	var iLon = new Number(tLon);
	
	if (iLon > 85600 || iLon < 10000)
		return null;
	if (iLat > 74800 || iLat < 10000)
		return null;
		
	var lonDeg = (iLon - 10000) / (3600 * 3) + 125;
	var lonMin = (iLon - ((lonDeg - 125) * 3600 * 3) - 10000) / (60 * 3);
	var lonSec = (iLon - ((lonDeg - 125) * 3600 * 3) - (lonMin * 60 * 3) - 10000) / 3.0;

	var latDeg = (iLat - 10000) / (3600 * 3) + 33;
	var latMin = (iLat - ((latDeg - 33) * 3600 * 3) - 10000) / (60 * 3);
	var latSec = (iLat - ((latDeg - 33) * 3600 * 3) - (latMin * 60 * 3) - 10000) / 3.0;

	var lon = lonDeg + ((lonMin * 60) + lonSec) / 3600;
	var lat = latDeg + ((latMin * 60) + latSec) / 3600;

	var b, e_prime, N, origin_lat, nn, t;
	var e, n;
	
	origin_lat = rad(38.0);
	
	var origin_lon = 128.0;
	var a = 6377397.155;
	var ee = 0.006674372231315;
	var en_m0 = 0.9999;
	
	lon -= origin_lon;
	lon = rad(lon);
	lat = rad(lat);
	
	b = fnxco(lat) - fnxco(origin_lat);
	N = a / Math.sqrt(1 - ee * Math.pow(Math.sin(lat), 2.0));
	e_prime = ee / (1 - ee);
	nn = e_prime * Math.pow(Math.cos(lat), 2.0);
	t = Math.tan(lat);
	
	e = en_m0 * (lon * N * Math.cos(lat) + Math.pow(lon, 3.0) / 6.0 * N * Math.pow(Math.cos(lat), 3.0) * (1 - t * t + nn) + Math.pow(lon, 5.0) / 120.0 * N * Math.pow(Math.cos(lat), 5.0) * (5 - 18 * t * t + Math.pow(t, 4.0)));
	n = en_m0 * (b + Math.pow(lon, 2.0) / 2.0 * N * Math.sin(lat) * Math.cos(lat) + Math.pow(lon, 4.0) / 24.0 * N * Math.sin(lat) * Math.pow(Math.cos(lat), 3.0) * (5 - t * t + 9 * nn));

	return new WitPoint(Math.round(e + 400000), Math.round(n + 600000));
}

function katechToWGS84(point) {
	var n0, phi1, BN, nm, error, origin_lat, nn, M, N, t;
	var lon, lat;

	lon = point.x - 400000.0;
	lat = point.y - 600000.0;

	origin_lat = rad(38.0);
	n0 = fnxco(origin_lat);
	phi1 = origin_lat;

	var a = 6377397.155;
	var ee = 0.006674372231315;
	var en_m0 = 0.9999;
	var pi = 3.14159265358979323846;

	do {
		BN = fnxco(phi1);
		nm = n0 + lat / en_m0;
		error = (BN - nm) * Math.pow((1 - ee * Math.sin(phi1) * Math.sin(phi1)), 1.5) / (a * (1 - ee));
		phi1 -= error;
	} while (Math.abs(error) > 10e-10);

	nn = ee / (1 - ee) * Math.pow(Math.cos(phi1), 2.0);
	M = a * (1 - ee) / Math.pow((1 - ee * Math.pow(Math.sin(phi1), 2.0)), 1.5);
	N = a / Math.sqrt(1 - ee * Math.pow(Math.sin(phi1), 2.0));
	t = Math.tan(phi1);

	lat = phi1 - lon * lon * t / (2 * M * N * en_m0 * en_m0) + Math.pow(lon, 4.0) * t / (24 * M * Math.pow(N, 3.0) + Math.pow(en_m0, 4.0)) * (5 + 3 * t * t + nn - 9 * t * t * nn);
	lon = lon / (N * en_m0 * Math.cos(phi1)) - Math.pow(lon, 3.0) / (6 * Math.pow(N, 3.0) * Math.pow(en_m0, 3.0) * Math.cos(phi1)) * (1 + 2 * t * t + nn) + Math.pow(lon, 5) / (120 * Math.pow(N, 5.0) * Math.pow(en_m0, 5.0) * Math.cos(phi1)) * (5 + 28 * t * t + 24 * Math.pow(t, 4.0));

	var regY = lat * 180.0 / pi;
	var regX = lon * 180.0 / pi + 128.0;

	var x1 = Math.floor(regX);
	var x2 = Math.floor((regX - x1) * 60);
	var x3 = Math.floor((((regX - x1) * 60) - x2) * 60);

	var y1 = Math.floor(regY);
	var y2 = Math.floor((regY - y1) * 60);
	var y3 = Math.floor((((regY - y1) * 60) - y2) * 60);

	var x = x1 + "˚ " + x2 + "' " + x3 + '"';
	var y = y1 + "˚ " + y2 + "' " + y3 + '"';

	return new WitPoint(x, y);
}

function rad(x) {
	var pi = 3.14159265358979323846;
	return x * pi / 180;
}

function fnxco(olat) {
	return 6377397.155 * (1 - 0.006674372231315) * ((1.005037306048555 * olat) - 0.5 * 0.005047849240300 * Math.sin(2 * olat) + 0.25 * 0.000010563786831 * Math.sin(4 * olat) - (1.0 / 6.0) * 0.000000020633322 * Math.sin(6 * olat));
}

function debug(s) {
	WitLog.write(s);
}

function MM_swapImgRestore() { //v3.0
 		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

	function toCommaFormat(number) {
	number = '' + number;
	if (number.length > 3) {
		var mod = number.length % 3;
		var output = (mod > 0 ? (number.substring(0,mod)) : '');
		for (i=0 ; i < Math.floor(number.length / 3); i++) {
			if ((mod == 0) && (i == 0))
			output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
			else
			output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
		}
		return (output);
	}
	else return number;
	}

var imageList_common;


////////// 08.3.13 김윤식 작성 및 수정 (슬라이드 쇼)///////////////////////

//var tempPath = "http://www.livemap.co.kr";	//로컬에서 이미지 경로를 인식하기 위한 스트링,,

function slideShowViewing(cid, nm){		//nm : title을 15자로 자른 매개변수
	var imageList_commo;
	new Ajax.Request("jsp/lib/TravelInfoManager.jsp", {
		method: "post",
		parameters: { TASK: "GET_RELATED_IMAGE_LIST", CID: cid },
		onSuccess: function(transport) {
			var data = eval(transport.responseText);
			imageList_common = data;

			var imgPath = imageList_common[0].THUMB_IMG7;
			var imgPath9 = imageList_common[0].THUMB_IMG9;

			//var webImgPath = tempPath + imgPath;
			//var webImgPath9 = tempPath + imgPath9;

			$("ydiv_Slider_images").show();
			$("ysliderImg").innerHTML = ' <a href="javascript:openImage(\'' + imgPath9 + '\')"><img src="' + imgPath + '" width="400" height="300" style="border: 2px solid #ffffff"></a> ';
			$("ydiv_Slider_images_poi_nm").innerText = nm;
		},
		onFailure: function() {
			alert("이미지를 가져오지 못했습니다.");
		}
	});
}

var slideShowInterval_common  = 2000;
var slideShowTimer_common ;
var slideShowImage_common  = 0;

/* play버튼을 중복해서 클릭하거나 setSlideShowInterval_common함수 내부에서
   startSlideShow_common함수가 중복 호출되면 setTimeout함수가 중복 되어버리는
      문제가 발생하기 때문에 startCount변수를 만들어 문제 해결  */
var startCount = 0;

function startSlideShow_common () {

	if(slideShowImage_common >= imageList_common.length)
	{
		slideShowImage_common = 0;
		startCount = 0;		//모든 이미지를 보여준 뒤 slideShowImage_common과 startCount를 0으로 초기화
		return;
	}

	var imgPath_common  = imageList_common[slideShowImage_common].THUMB_IMG7;

	//var webImgPath_common = tempPath + imgPath_common;
	//var webImageList_common = tempPath + imageList_common[slideShowImage_common].THUMB_IMG9;

	$("ysliderImg").innerHTML = ' <a href="javascript:openImage(\'' + imageList_common[slideShowImage_common].THUMB_IMG9 + '\')"><img src="' + imgPath_common  + '" width="400" height="300" style="border:2px solid #ffffff; "></a>';

	if (imageList_common[slideShowImage_common])
	{
		slideShowTimer_common = setTimeout("startSlideShow_common()", slideShowInterval_common);
	}
	slideShowImage_common++;
}

function upStartCount()
{
	startCount++;
}

function initStartCount()
{
	startCount = 0;
}

function playCheck()
{
	startCount>1 ? _nullFunction() : startSlideShow_common();
}

function stopSlideShow_common() {
	if (slideShowTimer_common)
		clearTimeout(slideShowTimer_common);
}

function setSlideShowInterval_common(t) {
	stopSlideShow_common();
	slideShowInterval_common = t;
	startSlideShow_common();
}

function isNull(text) {
	if (text == null) 
		return true;  

	var result = text.replace(/(^\s*)|(\s*$)/g, "");  

 	if (result)  
  		return false;  
 	else  
  		return true;  
}

function closeMakeBalloon(){
	$("makeBalloon").style.display='none';
}

///////////////////////////////////////////////////////////////////////////////////////