// 페이지 이동
function jsSendPage(p) {
	if (p=="r") {
		location.href = "http://www.munjang.or.kr/member/member_join.asp";
	} else if (p=="l") {
		return;
	}
}

// 공백제거 함수
function jsCheckValue(checkStr) 
{
	var FPoint=checkStr.indexOf(" ");	
	while(FPoint != -1) {
		checkStr = checkStr.replace(" ", "");
		FPoint  = checkStr.indexOf(" "); 
	}
	return (checkStr.length);
}


// 숫자 체크 함수 (숫자 외의 값이 있으면 false)
function jsCheckNumeric(x) 
{
	for(i=0;i<x.length;i++) {
		var a=x.charCodeAt(i);
		if(a < 48 || a > 57) {
			return false;
		}
	}
	return true;
}

// 한글 체크 함수 (한글 외의 값이 있으면 false)
function jsCheckHan(x) 
{
	for(i=0;i<x.length;i++) {
		var a=x.charCodeAt(i);
		if (a > 128) {
			return false;
		}
	}
	return true;
}

// 영문 체크 함수 (영문 외의 값이 있으면 false)
function jsCheckAlpha(checkStr) { 
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

	for (i = 0;  i < checkStr.length;  i++) { 
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
			return false;
	}
	return true;
}

// 영문, 숫자 체크 함수 (영문,숫자 외의 값이 있으면 false) 
function jsCheckAlphaNumeric(checkStr)
{ 
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

	for (i = 0;  i < checkStr.length;  i++)
	{ 
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
			return false;
	}
	return true;
}


//로그인 시 허용하지 않는 문자열 체크 
function jsValidate(pInput) {

	var bad_strings = new Array( "'", "select", "union", "insert", "--", "&quot;", "/", "\\", ";", ":", "+", "=", " ", "<", ">", "(", ")", "[", "]" );

	for (i = 0;  i < 19; i++)
	{
		if (pInput.indexOf(bad_strings[i]) >= 0)
		{
			return false;
			break;
		}
	}

	return true;
}

// 전달받은 char(8) 값이 올바른 날짜인지 확인
function jsCheckDate(pCheckDD)
{
	// 1. Length 확인
	if (pCheckDD.length != 8) {
		return false;
	}
	// 2. Number type 인지 확인 
	if (isNaN(pCheckDD)) {
		return false;
	}

	var sYY = pCheckDD.substr(0, 4);
	var sMM = pCheckDD.substr(4, 2);
	var sDD = pCheckDD.substr(6, 2);

	var oCheckDate = new Date(sYY, eval(sMM)-1, eval(sDD)); // Declare Date Obejct Variable 
	var sCheckYY = oCheckDate.getFullYear();
	var sCheckMM = "M0" + (oCheckDate.getMonth() + 1);
	var sCheckDD = "D0" + oCheckDate.getDate();

	sCheckMM = sCheckMM.substr(sCheckMM.length - 2, 2);
	sCheckDD = sCheckDD.substr(sCheckDD.length - 2, 2);

	// 3. 각 단위(YY, MM, DD)의 값 확인
	if (!(sYY > "1800" && sYY < "9999")) {
		return false;
	}
	if (!(sMM > "00" && sMM < "13")) {
		return false;
	}
	if (!(sDD > "00" && sDD < "32")) {
		return false;
	}
	// 4. 정상적인 날짜가 되는지 확인
	if (pCheckDD != sCheckYY + sCheckMM + sCheckDD) {
		return false;
	}
	
	return true;
}


// 문자길이 (한글 2byte 적용)
function jsCalMsgLen(msg) 
{
     len = msg.length;
     for (ii=0; ii<msg.length; ii++)
     {
       xx = msg.substr(ii,1).charCodeAt(0);
       if (xx > 127) { len++; }
     }
     return len;
}


// 주민등록번호 체크
function jsCheckResno(sSsn1, sSsn2)
{
	var sResno, sFmt
	var sBirth, sBirthYear, sBirthMonth, sBirthDate
	
  sResno = sSsn1 + '-' + sSsn2;

  // 주민번호의 형태와 7번째 자리(성별) 유효성 검사
  sFmt = /^\d{6}-[1234]\d{6}$/;
  if (!sFmt.test(sResno)) {
		return false;
  }

  // 날짜 유효성 검사
  sBirthYear = (sResno.charAt(7) <= "2") ? "19" : "20";
  sBirthYear += sResno.substr(0, 2);
  sBirthMonth = sResno.substr(2, 2) - 1;
  sBirthDate = sResno.substr(4, 2);
  sBirth = new Date(sBirthYear, sBirthMonth, sBirthDate);
  if ( sBirth.getYear() % 100 != sResno.substr(0, 2) ||
       sBirth.getMonth() != sBirthMonth ||
       sBirth.getDate() != sBirthDate) {
    return false;
  }

  // Check Sum 코드의 유효성 검사
  buf = new Array(13);
  for (i = 0; i < 6; i++) buf[i] = parseInt(sResno.charAt(i));
  for (i = 6; i < 13; i++) buf[i] = parseInt(sResno.charAt(i + 1));
  multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
  for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);
  if ((11 - (sum % 11)) % 10 != buf[12]) {
    return false;
  }

  return true;
}

// 입력된 주민번호로 생년월일 채우기
function jsBirth()
{
	var sJ1 = document.writeform.pSsn1.value;
	var sJ2 = document.writeform.pSsn2.value;
	var yy=0;
	var mm=0;
	var dd=0;
	
	if (sJ2.length > 1) {
		for(i=0;i<2;i++){
			if(i==0){
				yy = sJ1.charAt(i);
			}else{
				yy = yy + sJ1.charAt(i);
			} 
		}

		for(i=2;i<4;i++){
			if(i==2){
				mm = sJ1.charAt(i);
			}else{
				mm = mm + sJ1.charAt(i);
			} 
		}

		for(i=4;i<6;i++){
			if(i==4){
				dd = sJ1.charAt(i);
			}else{
				dd = dd + sJ1.charAt(i);
			} 
		} 

		var rtn = sJ2.charAt(0);
		if(rtn == "3" || rtn == "4"){
			yy = "20" + yy;
		}else{
			yy = "19" + yy;
		}

		if (rtn == "1" || rtn == "3") {
			document.writeform.pSex[0].checked = true;
		} else {
			document.writeform.pSex[1].checked = true;
		}
		document.writeform.pYear.value = yy;
		document.writeform.pMonth.value = mm;
		document.writeform.pDay.value = dd;
		
		document.writeform.pEmail.focus();
	} else {
		return;
	}
}

// 이메일 체크 함수
function jsIsEmail(s) 
{
	return s.search(/^\s*[\w\~\-\.]+\@[\w\~\-]+(\.[\w\~\-]+)+\s*$/g)>=0;
}


// 검색어 입력여부 체크함수
function jsSearchit()
{
	// 검색어, searchString
	if (jsCheckValue(document.searchform.pSearchStr.value) < 1) {
		alert("검색어를 입력해 주세요.");
		document.searchform.pSearchStr.focus();
		return;
	}

	document.searchform.submit();         
}

// 검색어 InputText에서의 Enter처리
function jsSearchEnter() 
{
	if (window.event.keyCode == 13) {	    // 엔터가 들어오면
		window.event.keyCode = 0;           // 이벤트 무효화
		jsSearchit();
	}  
}


//링크의 포커스를 없앤다
function bluring(){ 
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
//document.onfocusin=bluring;

//테이블 열고 닫기
var old_menu = '';
var old_cell = '';
var old2_menu = '';
var old2_cell = '';

function menuclick(submenu, cellbar) {
	if(old_menu != submenu) {
		if(old_menu != '') {
			old_menu.style.display = 'none';
		}
		submenu.style.display = 'block';
		old_menu = submenu;
		old_cell = cellbar;
	} 
	else {
		submenu.style.display = 'none';
		old_menu = '';
		old_cell = '';
	}
}

function submenuclick(submenu, cellbar){
	if(old2_menu != submenu) {
		if(old2_menu != '') {
			old2_menu.style.display = 'none';
		}
		submenu.style.display = 'block';
		old2_menu = submenu;
		old2_cell = cellbar;
	} 
	else {
		submenu.style.display = 'none';
		old2_menu = '';
		old2_cell = '';
	}
}


// 트리에서 자신이 속한 분류까지 펼치기
function jsMenuFullDisplay(pSEQ) {
	var iTotCnt;
	var iCnt;

	iTotCnt = pSEQ.length / 3

	for (iCnt=2; iCnt<=iTotCnt; iCnt++) {
		jsMenuDisplay(pSEQ.substr(0, iCnt * 3));
	}
}

// 트리에서 하위메뉴 펼치기
function jsMenuDisplay(tmpID) {
	oTargetDiv = document.all(tmpID);
	oSignName = document.all("sign_" + tmpID);

	if(oTargetDiv.style.display != "none") {
		oTargetDiv.style.display="none";
		
		if (oSignName.src.indexOf("/image/tree/tr_lastminus.gif") > 0) {
			oSignName.src = "/image/tree/tr_lastplus.gif";
		} else {
			oSignName.src = "/image/tree/tr_plus.gif"
		}
	} else {
		oTargetDiv.style.display = "";

		if (oSignName.src.indexOf("/image/tree/tr_lastplus.gif") > 0) {
			oSignName.src = "/image/tree/tr_lastminus.gif"
		} else {
			oSignName.src = "/image/tree/tr_minus.gif"
		}
	}
}
//---------------------------------------------------------------------------------------------------
// 회원로그인 팝업창
var LoginOpenwinVal;
var UserBrowserWidth = window.screen.width;
var UserBrowserHeight = window.screen.height;

// 로그인
function jsLogin() {
		//var link = "http://www.munjang.or.kr/member/login/login.asp";
		var link = "http://www.munjang.or.kr/member/login/login_inner.asp?pReturnURL=" + escape(document.location.href);
		document.location.href = link;
		//var width = 550, height = 498;
		//var top = 100, left = (UserBrowserWidth/2) - (width/2);

		//if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		//LoginOpenwinVal.close();
		//LoginOpenwinVal = window.open(link,"jsLogin","resizable=no,status=no,scrollbars=no,width="+width+",height="+height+",top="+top+",left="+left);
}

// 이벤트 페이지 로그인용(전에는 팝업으로 로그인을 했었기 때문에 이게 필요하지 않았다 - 이상호)
function jsEventLogin() {
		//var link = "http://www.munjang.or.kr/member/login/login.asp";
		//alert(parent.window.document.location.href);
		var link = "http://www.munjang.or.kr/member/login/login_inner.asp?pReturnURL=" + escape(parent.window.document.location.href);
		parent.window.document.location.href = link;
		//var width = 550, height = 498;
		//var top = 100, left = (UserBrowserWidth/2) - (width/2);

		//if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		//LoginOpenwinVal.close();
		//LoginOpenwinVal = window.open(link,"jsLogin","resizable=no,status=no,scrollbars=no,width="+width+",height="+height+",top="+top+",left="+left);
}

function jsLogin3() {
		var link = "/member/login/login_inner.asp";
		document.location.href = link;
}


// 로그아웃
function jsLogout() {
	location.href = "http://www.munjang.or.kr/member/login/logout.asp";
}

// 아이디/비번찾기
function jsGoIdPw() {
		//var link = "http://www.munjang.or.kr/member/login/request_id.asp";
		var link = "http://www.munjang.or.kr/member/login/request_id_inner.asp";
		document.location.href = link;
		//var width = 550, height = 498;
		//var top = 100, left = (UserBrowserWidth/2) - (width/2);

		//if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		//LoginOpenwinVal.close();
		//LoginOpenwinVal = window.open(link,"jsGoIdPw","resizable=no,status=no,scrollbars=no,width="+width+",height="+height+",top="+top+",left="+left);
}

// 비번찾기
function jsGotoPws() {
		var link = "http://www.munjang.or.kr/member/login/request_pwd_inner.asp";
		document.location.href = link;
		//var width = 550, height = 498;
		//var top = 100, left = (UserBrowserWidth/2) - (width/2);

		//if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		//LoginOpenwinVal.close();
		//LoginOpenwinVal = window.open(link,"jsGoIdPw","resizable=no,status=no,scrollbars=no,width="+width+",height="+height+",top="+top+",left="+left);
}

// copyright (버그신고)
function jsBug() {
	window.open("/inc/popup_bug.asp", "jsBug", "resizable=no,status=no,scrollbars=no,width=550,height=500,top=100,left=100");
}

// copyright (제휴 및 협력문의)
function jsCop() {
	window.open("/inc/cooperation.asp", "jsCop", "resizable=no,status=no,scrollbars=no,width=620,height=675,top=100,left=100");
}

// copyright (메일발송)
function jsMailTo(mail) {
		var link = "/member/mail_form/mailform.asp?pToMail=" + mail;
		var width = 550, height = 498;
		var top = 100, left = (UserBrowserWidth/2) - (width/2);

		if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		LoginOpenwinVal.close();
		LoginOpenwinVal = window.open(link,"jsMailTo","resizable=no,status=no,scrollbars=no,width="+width+",height="+height+",top="+top+",left="+left);
}

// 팝업 띄우기
function jsPopUp_scrolno(link, W, H) {
		var link = link ;
		var width = W, height = H;
		var top = 100, left = (UserBrowserWidth/2) - (width/2);

		if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		LoginOpenwinVal.close();
		LoginOpenwinVal = window.open(link,"jsPopUp","menubar=no,scrollbars=no,status=no,toolbar=no,resizable=yes,width="+width+",height="+height+",top="+top+",left="+left);
}
function jsPopUp_scrolyes(link, W, H) {
		var link = link ;
		var width = W, height = H;
		var top = 100, left = (UserBrowserWidth/2) - (width/2);

		if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		LoginOpenwinVal.close();
		LoginOpenwinVal = window.open(link,"jsPopUp","menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,width="+width+",height="+height+",top="+top+",left="+left);
}

// 문예지우수작품 안내(06.09.04)
function jsPopGoLiteraryWorks() {
		var link = "/lib_literaryworks/info1.htm";
		var width = 600, height = 209;
		var top = 100, left = (UserBrowserWidth/2) - (width/2);

		if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		LoginOpenwinVal.close();
		LoginOpenwinVal = window.open(link,"LiteraryWorks","resizable=no,status=no,scrollbars=no,width="+width+",height="+height+",top="+top+",left="+left);
}
function jsPopGoLiteraryWorks1() {
		var link = "/lib_literaryworks/info.htm";
		var width = 600, height = 480;
		var top = 100, left = (UserBrowserWidth/2) - (width/2);

		if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		LoginOpenwinVal.close();
		LoginOpenwinVal = window.open(link,"LiteraryWorks","resizable=no,status=no,scrollbars=no,width="+width+",height="+height+",top="+top+",left="+left);
}

// 권한
function jsErrMsg(c) {
	var msg;

	if (c == "m")
	{
		msg = "수정권한이 없습니다.";
	}
	else if (c == "d")
	{
		msg = "삭제권한이 없습니다.";
	}
	else if (c == "e")
	{
		msg = "응모 마감되었습니다.";
	}

	alert(msg);
	return;
}

// 문학사전 링크
function jsGotoDicLink(DicKind, Word)
{
	with (document.LinkForm) {
		pDicKind.value = DicKind;
		if (DicKind == "02")
		{
			action = "view_writer.asp";
		}else{
			action = "view.asp";
		}
		pWord.value = Word;
		submit();
	}
}

function jsGotoDicLink1(Word)		//작가.작품 내용에서 보기
{
	with (document.LinkForm) {
		action = "/dictionary/view_serch.asp";
		//pDicKind.vaule = "02";
		pWord.value = Word;
		submit();
	}
}

//060918
function jsGoMaronie()
{
		var link = "/mai_maronie/";
		var width = 932, height = 800;
		var top = 10, left = 10;

		if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		LoginOpenwinVal.close();
		LoginOpenwinVal = window.open(link,"jsGoMaronie1","resizable=no,status=no,scrollbars=yes,width="+width+",height="+height+",top="+top+",left="+left);
}
function jsGoMaronie1()
{
		var link = "/mai_maronie/event/list.asp";
		var width = 932, height = 800;
		var top = 10, left = 10;

		if (LoginOpenwinVal != null && !LoginOpenwinVal.closed)
		LoginOpenwinVal.close();
		LoginOpenwinVal = window.open(link,"jsGoMaronie1","resizable=no,status=no,scrollbars=yes,width="+width+",height="+height+",top="+top+",left="+left);
}
//---------------------------------------------------------------------------------------------------