//window.onerror = ErrorSetting;
var map, georssLayer, geocoder, NElat, NElon, SWlat, SWlon;
var nowZoom=10, pray=false, timer1=null, pclk=false, nowlat, nowlon, addpmarker, nowaddr;

function membersch(){
	var mname = document.getElementById("schmember").value;
	if(mname != ""){
		unamelist(mname);
		location.href="#map";
	} else {
		alert("유저이름을 적으세요");
		document.getElementById("schmember").focus();
	}
}

function rt_login(){
	if(document.getElementById("r_id").value == ""){
		alert("아이디를 입력해 주세요.");
		document.getElementById("r_id").focus();
		return;
	}
	if(document.getElementById("r_pwd").value == ""){
		alert("비밀번호를 입력해 주세요.");
		document.getElementById("r_pwd").focus();
		return;
	}
	var loginrslt = readpage("rtmemberlogin.asp?r_id="+ encodeURI(document.getElementById("r_id").value) +"&r_pwd="+ encodeURI(document.getElementById("r_pwd").value));
	if (loginrslt == "ok"){
		var indoc = "<a href='javascript:void(0)' onClick='memberpic(); return false;'>";
		indoc = indoc + "<font color='#000000'>";
		indoc = indoc + document.getElementById("r_id").value +" 님 로그인중.";
		indoc = indoc + "</font></a>";
		indoc = indoc + "<input type='button' value='로그아웃' onClick='rt_logout()' />";
		document.getElementById("rtmemberinfo").innerHTML = indoc;
		document.getElementById("areaslt").innerHTML = readpage("areasltins_z.asp");
	} else {
		alert(loginrslt);
	}
}

function rt_logout(){
	var logrslt = readpage("rtmemberlogout.asp");
	var indoc = "아이디<input name='r_id' type='text' id='r_id' size='10' maxlength='20' />";
	indoc = indoc + "비밀번호<input name='r_pwd' type='password' id='r_pwd' size='10' maxlength='20' />";
	indoc = indoc + "<input type='button' value='로그인' onClick='rt_login()' />";
	indoc = indoc + "<input type='button' value='회원가입' onClick='rt_join()' />";
	document.getElementById("rtmemberinfo").innerHTML = indoc;
	document.getElementById("areaslt").innerHTML = "&nbsp;"
}

function rt_join(){
	document.getElementById("workdiv1").style.top = "150px";
	document.getElementById("workdiv1").style.left = (document.body.clientWidth / 2) - 150 + "px";
	document.getElementById("workdiv1").innerHTML = "<table border='0' width='300' cellpadding='0' cellspacing='0' id='adptb' radius='5' rborder='#EE7103' rbgcolor='#FFFFFF'>"+
		"<tr><td height='280' align='left' valign='top'>"+
		"<iframe src='rtjoin.asp' frameborder='0' width='300' height='280'></iframe>"+
		"</td></tr>"+
		"<tr><td height='20' align='right' bgcolor='#AAAAAA'>"+
		"<a href='javascript:void(0)' onClick='adpwinclose()'>닫기</a>"+
		"</td></tr></table>";
	roundTable("adptb");
	document.getElementById("workdiv1").style.visibility = "";
}

function addrcol(add){
	if (add.indexOf("서울") != -1){ return "sk"; }
	if (add.indexOf("경기도") != -1){ return "sk"; }
	if (add.indexOf("인천광역시") != -1){ return "sk"; }
	if (add.indexOf("강원도") != -1){ return "kw"; }
	if (add.indexOf("충청북도") != -1){ return "cb"; }
	if (add.indexOf("충청남도") != -1){ return "cn"; }
	if (add.indexOf("대전") != -1){ return "cn"; }
	if (add.indexOf("경상북도") != -1){ return "kb"; }
	if (add.indexOf("대구") != -1){ return "kb"; }
	if (add.indexOf("부산") != -1){ return "kn"; }
	if (add.indexOf("경상남도") != -1){ return "kn"; }
	if (add.indexOf("전라북도") != -1){ return "jb"; }
	if (add.indexOf("광주광역시") != -1){ return "jn"; }
	if (add.indexOf("전라남도") != -1){ return "jn"; }
	if (add.indexOf("제주") != -1){ return "jj"; }
	
	return "kt";
}

function enterchk(e, wform){
    if (getKeyCode(e) == 13){
      switch(wform){
      	case "schpoint": codeAddress(); break;
      	case "rtid": document.getElementById("r_pwd").focus(); break;
      	case "rtpwd": rt_login(); break;
      }
    }
    return;
}

function adpwinopen(lat, lon, col){
	document.getElementById("workdiv1").style.top = (screen.availHeight / 2) - 200 + "px";
	document.getElementById("workdiv1").style.left = (document.body.clientWidth / 2) - 300 + "px";
	document.getElementById("workdiv1").innerHTML = "<table border='0' width='590' cellpadding='0' cellspacing='0' id='adptb' radius='5' rborder='#EE7103' rbgcolor='#FFFFFF'>"+
		"<tr><td height='380' align='left' valign='top'>"+
		"<iframe src='board/userpointadd.asp?lat="+lat+"&lon="+lon+"&area="+col+"' frameborder='0' width='590' height='380' scrolling='auto'></iframe>"+
		"</td></tr>"+
		"<tr><td height='20' align='right' bgcolor='#AAAAAA'>"+
		"<a href='javascript:void(0)' onClick='adpwinclose()'>닫기</a>"+
		"</td></tr></table>";
	roundTable("adptb");
	document.getElementById("workdiv1").style.visibility = "";
}

function adpwinclose(){
	document.getElementById("workdiv1").innerHTML = "";
	document.getElementById("workdiv1").style.visibility = "hidden";
}

function pointsearch(){
  var q = document.getElementById("schpoint").value;
  if( q == "" ){ return false; }
  document.getElementById("sitelist_div").innerHTML = readpage("pointlist_z.asp?cate=s&q="+encodeURI(q));
  document.getElementById("feslist_div").innerHTML = readpage("pointlist_z.asp?cate=f&q="+encodeURI(q));
  document.getElementById("updiv").innerHTML = readpage("uplist_z.asp?upwidth=365&q="+encodeURI(q));
}

function unamelist(uname){
	document.getElementById("updiv").innerHTML = readpage("uplist_z.asp?upwidth=365&uname="+encodeURI(uname)+"&mlat="+nowlat+"&mlon="+nowlon);
}

function loadtime(u, t){
	document.getElementById("loadingdiv").style.visibility = "";
	setTimeout(u, parseInt(t));
	setTimeout("loadend()", parseInt(t+1000));
}

function loadend(){
	document.getElementById("loadingdiv").style.visibility = "hidden";
}

function totalsearch(){
	var q = document.getElementById("schpoint").value;
	if (q != ""){
		location.href="totalsearch.asp?q="+ encodeURI(q);
	} else {
		alert("검색어를 적어 넣으세요.");
		document.getElementById("schpoint").focus();
	}
}

function plisttoggle(plstyle){
  var ps;
  switch (plstyle){
    case 1:
      ps = "m";
      break;
    case 2:
      ps = "n";
      break;
  }
  document.getElementById("sitelist_div").innerHTML = readpage("pointlist_z.asp?cate=s&ps="+ps+"&mlat="+nowlat+"&mlon="+nowlon);
  document.getElementById("feslist_div").innerHTML = readpage("pointlist_z.asp?cate=f&ps="+ps+"&mlat="+nowlat+"&mlon="+nowlon);
  document.getElementById("updiv").innerHTML = readpage("uplist_z.asp?upwidth=365&ps="+ps+"&mlat="+nowlat+"&mlon="+nowlon);
}

function seeyou(){
	setCookie('NH_LastArea_N', nowlat, 365);
	setCookie('NH_LastArea_E', nowlon, 365);
	//setCookie('NH_LastZoom', nowZoom, 365);
}

function ErrorSetting(msg, file_loc, line_no){
     areatoggle();
     return true; 
}

function mapchng(mc){
	seeyou();
	self.location.href="/?mcorp="+ mc +"&c_gpse="+ nowlat +"&c_gpsn="+ nowlon;
}

function areachng(){
	var sltval = document.getElementById("myarea").value;
	if (sltval == ""){ return false; }
	if (sltval == "add_area"){
		addUserArea();
		return;
	}
	var sltlat = Left(sltval, sltval.indexOf(","));
	var sltlng = Right(sltval, sltval.length - sltval.indexOf(",") - 1);
	gotopoint(sltlat, sltlng);
	plisttoggle(1);
}

function addUserArea(){
	document.getElementById("workdiv1").style.top = (screen.availHeight / 2) - 50 + "px";
	document.getElementById("workdiv1").style.left = (document.body.clientWidth / 2) - 100 + "px";
	document.getElementById("workdiv1").innerHTML = "<table border='0' width='200' cellpadding='0' cellspacing='0' id='addareatb' radius='5' rborder='#EE7103' rbgcolor='#FFFFFF'>"+
		"<tr><td height='80' align='center'>"+
		"이름<input type='text' id='mareaname' name='mareaname' size='20' maxlength='20' /><br>"+
		"<input type='button' value='위 이름으로 관심지역을 등록합니다' onClick='addareago()' />"+
		"</td></tr>"+
		"<tr><td height='20' align='right' bgcolor='#AAAAAA'>"+
		"<a href='javascript:void(0)' onClick='adpwinclose()'>닫기</a>"+
		"</td></tr></table>";
	roundTable("addareatb");
	document.getElementById("workdiv1").style.visibility = "";
}

function addareago(){
	if(document.getElementById("mareaname").value == ""){
		alert("지역이름을 적으세요");
		document.getElementById("mareaname").focus();
		return;
	}
	var addarea = readpage("addmyarea.asp?a_lat="+ nowlat +"&a_lng="+ nowlon +"&a_name="+ encodeURI(document.getElementById("mareaname").value));
	alert(addarea);
	document.getElementById("areaslt").innerHTML = readpage("areasltins_z.asp");
	adpwinclose();
}

function Left(str, n){
if (n <= 0)
  return "";
else if (n > String(str).length)
  return str;
else
  return String(str).substring(0,n);
}

function Right(str, n){
  if (n <= 0)
     return "";
  else if (n > String(str).length)
     return str;
  else {
     var iLen = String(str).length;
     return String(str).substring(iLen, iLen - n);
  }
}

function memberpic(){
	document.getElementById("workdiv1").style.top = "150px";
	document.getElementById("workdiv1").style.left = (document.body.clientWidth / 2) - 150 + "px";
	document.getElementById("workdiv1").innerHTML = "<table border='0' width='300' cellpadding='0' cellspacing='0' id='mempictb' radius='5' rborder='#EE7103' rbgcolor='#FFFFFF'>"+
	 "<tr><td height='250'>"+
	 "<iframe src='memberpic.asp' frameborder='0' width='300' height='250'></iframe>"+
	 "</td></tr>"+
	 "<tr><td height='20' align='right' bgcolor='#AAAAAA'>"+
	 "<a href='javascript:void(0)' onClick='adpwinclose()'>닫기</a>"+
	 "</td></tr></table>";
	roundTable("mempictb");
	document.getElementById("workdiv1").style.visibility = "";
}
