/*
---------------------------------------------------------------------------------
 File Description
---------------------------------------------------------------------------------
 Copyleft (C) 2004 kodong™ with 아라곤네트웍스(주)
 Homepage	: http://www.kodong.com, http://www.aragon.co.kr
 Email		: kodong@empal.com, kodong@aragon.co.kr

 샤인 온라인 웹사이트에서 사용하는 일반적인 Javascript 함수를 정의.

 ※ 문자열 관련 스크립트
 getStrLen(obj)
   - 입력받은 항목(obj)의 문자열 길이 계산 
 alertLen(obj, nMin, nMax, msg)
   - 입력받은 항목(obj)의 문자열 길이가 범위(nMin < stringLength < nMax)안에
     없을 경우 경고(msg) 출력 
 chkNull(str)
   - 입력받은 문자열(str)이 공백인지 체크
 alertNull(obj, msg)
   - 입력받은 항목(obj)이 NULL 일 경우 경고(msg) 출력
 chkAlphabet(str)
   - 입력받은 문자열(str)이 영문 문자열인지 체크 (RETURN True / False)
 alertAlphabet(obj,msg)
   - 입력받은 항목(obj)이 영문 문자열이 아닐경우 경고(msg) 출력
 chkHangle(str)
   - 입력받은 문자열(str)이 한글 문자열인지 체크 (RETURN True / False)
 alertHangle(obj, msg)
   - 입력받은 항목(obj)이 한글 문자열이 아닐경우 경고(msg) 출력
 chkNumber(str)
   - 입력받은 문자열(str)이 숫자 문자열인지 체크 (RETURN True / False)
 alertNumber(obj, msg)
   - 입력받은 항목(obj)이 숫자 문자열이 아닐경우 경고(msg) 출력
 chkAlphaNum(str)
   - 입력받은 문자열(str)이 영문/숫자 문자열인지 체크 (RETURN True / False)
 alertAlphaNum(obj, msg)
   - 입력받은 항목(obj)이 영문/숫자 문자열이 아닐경우 경고(msg) 출력
 
 ※ E-Mail 관련 스크립트
 chkEmail(objEmail)
   - 입력받은 E-Mail 항목(objEmail)이 유효한지 체크
 alertEmail(objEmail)
   - 입력받은 E-Mail 항목(objEmail)이 유효하지 않을경우 경고 출력

 ※ 주민등록번호 관련 스크립트
 chkJuminNo(str)
   - 입력받은 문자열이 주민등록번호로 유효한지 체크 (RETURN True / False)
 alertJuminNo(obj1, obj2)
   - 입력받은 항목(obj1, obj2)이 유효한 주민등록번호가 아닐경우 경고(msg) 출력
 
 ※ 팝업 관련 스크립트
 openWindow (url, key, w, h)
   - 메뉴, 주소, 스크롤이 없는 팝업창 생성
 openWindowScroll (url, key, w, h)
   - 스크롤만 있는 팝업창 생성
 
 ※ 쿠키 관련 스크립트
 getCookie(name)
   - 쿠키를 가져오는 함수
 setCookie(name, value, expiredays)
   - 쿠키를 생성하는 함수
 clsWindow(name)
   - 창닫는 함수(setCookie()를 호출함)
---------------------------------------------------------------------------------
*/


/* ------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj)의 문자열 길이 계산 
--------------------------------------------------------------------------------- */
function getStrLen(obj) {
	var nCnt = 0;
	var sTemp;

	for (var i = 0; i < obj.value.length; i++) {
		sTemp = escape(obj.value.substring(i, i+1));
	      
		if (sTemp.substring(1, 2) == "u") nCnt += 2;
		else nCnt += 1;
	}

	return nCnt;
}

/* ------------------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj)의 문자열 길이가 범위(nMin < stringLength < nMax)안에
          없을 경우 경고(msg) 출력 
------------------------------------------------------------------------------------------------ */
function alertLen(obj, nMin, nMax, msg) {
	var nLen = getStrLen(obj);

	if(chkNull(obj.value) || (nLen < nMin) || (nLen > nMax)) {
		alert(msg + " " + nMin + "자 이상 " + nMax + "자 이내로 입력하세요.");
		obj.focus();
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 문자열(str)이 공백인지 체크
--------------------------------------------------------------------------------- */
function chkNull(str) {
     var str = str + "";
     var bSpace = true ;

     if ((str == "") || (str == null) || (str == "　")) return bSpace;

     for (var j = 0; bSpace && (j < str.length);j++) {
	     if (str.substr(j, 1) != " ") bSpace = false ;
     }
     return (bSpace);
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj)이 NULL 일 경우 경고(msg) 출력
--------------------------------------------------------------------------------- */
function alertNull(obj, msg) {
	if(chkNull(obj.value)) {
		alert(msg + " 입력하세요.");
		obj.value = "";
		obj.focus();
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 문자열(str)이 영문 문자열인지 체크 (RETURN True / False)
--------------------------------------------------------------------------------- */
function chkAlphabet(str) {
	var str = str.toUpperCase();

	for (var i = 0; i < str.length; i++) {
		var ch = str.charAt(i);
		if ((ch < "A") || (ch > "Z")) return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj)이 영문 문자열이 아닐경우 경고(msg) 출력
--------------------------------------------------------------------------------- */
function alertAlphabet(obj, msg) {
	if(!alertNull(obj, msg)) return false;
	if(!chkAlphabet(obj.value)) {
		alert(msg + " 영문으로 입력하세요");
		obj.focus();
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 문자열(str)이 한글 문자열인지 체크 (RETURN True / False)
--------------------------------------------------------------------------------- */
function chkHangle(str) {
	for (var i = 0; i < str.length; i++) {
		var ch = str.charAt(i);
		if (((ch < "ㅏ") || (ch > "히")) && ((ch < "ㄱ") || (ch > "ㅎ"))) return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj)이 한글 문자열이 아닐경우 경고(msg) 출력
--------------------------------------------------------------------------------- */
function alertHangle(obj, msg) {
	if(!alertNull(obj, msg)) return false;
	if(!chkHangle(obj.value)) {
		alert(msg + " 한글로 입력하세요.");
		obj.focus();
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 문자열(str)이 숫자 문자열인지 체크 (RETURN True / False)
--------------------------------------------------------------------------------- */
function chkNumber(str) {
	for (var i = 0; i < str.length; i++) {
		if ((str.substr(i, 1) < "0") || (str.substr(i, 1) > "9")) return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj)이 숫자 문자열이 아닐경우 경고(msg) 출력
--------------------------------------------------------------------------------- */
function alertNumber(obj, msg) {
	if(!alertNull(obj, msg)) return false;
	if(!chkNumber(obj.value)) {
		alert(msg + " 숫자로 입력하세요");
		obj.focus();
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 문자열(str)이 영문/숫자인지 체크 (RETURN True / False)
--------------------------------------------------------------------------------- */
function chkAlphaNum(str) {
	var str = str.toUpperCase();

	for (var i = 0; i < str.length; i++) {
		var ch = str.charAt(i);
		if (((ch < "A") || (ch > "Z")) && ((ch < "0") || (ch > "9"))) return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj)이 영문/숫자 문자열이 아닐경우 경고(msg) 출력
--------------------------------------------------------------------------------- */
function alertAlphaNum(obj, msg) {
	if(!alertNull(obj, msg)) return false;
	if(!chkAlphaNum(obj.value)) {
		alert(msg + " 영문, 숫자로 입력하세요");
		obj.focus();
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 문자열이 주민등록번호로 유효한지 체크 (RETURN True / False)
--------------------------------------------------------------------------------- */
function chkJuminNo (str) {
	var value_add = "234567892345"; // 가중치
	var sum = 0, check_digit = 0;

	if (str.substr(6, 1) < 1 || str.substr(6, 1) > 4) return false;

	for (var i=0; i<12; i++) 
		sum = sum + str.substr(i, 1) * value_add.substr(i, 1);
	
	check_digit = 11 - (sum % 11);
	if (check_digit >= 10) check_digit -= 10;

	if (check_digit != str.substr(12, 1)) return false;
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 항목(obj1, obj2)이 유효한 주민등록번호가 아닐경우 경고(msg) 출력
--------------------------------------------------------------------------------- */
function alertJuminNo(obj1, obj2) {
	var msg1 = "주민등록번호 앞자리를";
	var msg2 = "주민등록번호 뒷자리를";

	if (!alertNumber(obj1, msg1)) return false;
	if (!alertNumber(obj2, msg2)) return false;

	if (!alertLen(obj1, 6, 6, msg1)) return false;
	if (!alertLen(obj2, 7, 7, msg2)) return false;

	if (!chkJuminNo(obj1.value + obj2.value)) {
		alert("주민등록번호를 정확히 입력하여 주십시오.");
		obj2.focus();
		return false;
	}
	return true
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 E-Mail 항목(objEmail)이 유효한지 체크
--------------------------------------------------------------------------------- */
function chkEmail(str) {
	var strlen = getStrLen(str);

	for(i = 0; i < strlen; i++) {
		str = str.replace(/(\s)+/, '');
		str = str.replace(/[^A-Za-z0-9_\-\@\. ]/, "\.");
	}

	var Email = /^([A-Za-z0-9_\-]{1,15})(@{1})([A-Za-z0-9_\-]{1,15})(\.{1})([A-Za-z0-9_\-]{2,10})(\.{1}[A-Za-z\-]{2,10})?(\.{1}[A-Za-z\-]{2,10})?$/;

	if(Email.test(str)) return true;
	return false;
}

/* ------------------------------------------------------------------------------
   기능 : 입력받은 E-Mail 항목(objEmail)이 유효하지 않을경우 경고 출력
--------------------------------------------------------------------------------- */
function alertEmail(objEmail) {
	if(!alertNull(objEmail, "전자메일(E-mail)을")) return false;
	if(!chkEmail(objEmail.value)) {
		alert("전자메일(E-mail)을 정확히 입력해 주세요.");
		objEmail.focus();
		return false;
	}
	return true;
}

/* ------------------------------------------------------------------------------
   기능 : 메뉴, 주소, 스크롤이 없는 팝업창 생성
--------------------------------------------------------------------------------- */
function openWindow(url, key, w, h) {
	var w_left = (screen.width - 800) / 2;
	var w_top = (screen.height - 600) / 2;

	window.open(url, key, "width=" + w + ", height=" + h + ", status=no, scrollbars=no, left=" + w_left + ", top=" + w_top + "");
}

/* ------------------------------------------------------------------------------
   기능 : 메뉴, 주소, 스크롤이 있는 팝업창 생성
--------------------------------------------------------------------------------- */
function openWindowmenu(url, key, w, h) {

	window.open(url, key, "width=" + w + ", height=" + h + ", channelmode=0, directories=1, location=1, menubar=1, resizable=1, scrollbars=1, status=0, titlebar=0, toolbar=0");
}


/* ------------------------------------------------------------------------------
   기능 : 스크롤만 있는 팝업창 생성
--------------------------------------------------------------------------------- */
function openWindowScroll(url, key, w, h) {
	var w_left = (screen.width - 800) / 2;
	var w_top = (screen.height - 600) / 2;

	window.open(url, key, "width=" + w + ", height=" + h + ", status=no, scrollbars=yes, left=" + w_left + ", top=" + w_top + "");
}

/* ------------------------------------------------------------------------------
   기능 : 팝업창 생성
--------------------------------------------------------------------------------- */
function openWindowCenter(sURL, sWinName, iWidth, iHeight, sScroll) { 
	if (sScroll == null) sScroll = "no";
	var status = "";

	LeftPosition = (screen.width) ? (screen.width - iWidth) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - iHeight) / 2 : 0;

	status = status + "toolbar=no, channelmode=no, location=no, directories=no, resizable=no, menubar=no";
	status = status + ", scrollbars=" + sScroll + ", left=0, top=0, width=" + iWidth + ", height=" + iHeight+ ", top=" + TopPosition + ", left=" + LeftPosition;

	window.open(sURL, sWinName, status);
}

function setCookie(name, value, expiredays) {
	var todayDate = new Date();
	var cookieStr;
	todayDate.setDate(todayDate.getDate() + expiredays);
	cookieStr = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
	document.cookie = cookieStr;
}

function clsWindow(name) {
	if (document.form.check_box.checked) {
		setCookie(name, "done" , 1);
	}
	this.close();
}

function closeWin(name) { 
	if (document.all.CEvent.checked==true) {
		setCookie(name, "no" , 1);
	} 
	window.close();
}

function ParentGoWin(url) 
{
	window.opener.document.location.href =url;
	this.close();
}

this.focus();

function getCookie(name) {
	var nameOfCookie = name + "=";
	var x = 0
	while (x <= document.cookie.length) {
		var y = (x+nameOfCookie.length);
		if (document.cookie.substring(x, y) == nameOfCookie) {
			if ((endOfCookie = document.cookie.indexOf( ";",y )) == -1)
				endOfCookie = document.cookie.length;

			return unescape(document.cookie.substring(y, endOfCookie));
		}
		x = document.cookie.indexOf(" ", x) + 1;
		if (x == 0)
			break;
	}
	return "";
}

function newWin_center(sURL, sWinName, iWidth, iHeight, sScroll) { 
	if (sScroll == null) sScroll = "no";
	var status = "";

	LeftPosition = (screen.width) ? (screen.width - iWidth) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height - iHeight) / 2 : 0;

	status = status + "toolbar=no, channelmode=no, location=no, directories=no, resizable=no, menubar=no";
	status = status + ", scrollbars=" + sScroll + ", left=0, top=0, width=" + iWidth + ", height=" + iHeight+ ", top=" + TopPosition + ", left=" + LeftPosition;

	window.open(sURL, sWinName, status);
}

function openWindowPOP(sURL, sWinName, iWidth, iHeight, sScroll) { 
	if (sScroll==null) sScroll = "no";
	var status = "";
	LeftPosition = 5
	TopPosition = 5
	status = status + "toolbar=no, channelmode=no, location=no, directories=no, resizable=no, menubar=no";
	status = status + ", scrollbars=" + sScroll + ", left=0, top=0, width=" + iWidth + ", height=" + iHeight+ ", top=" + TopPosition + ", left=" + LeftPosition;
	
	if(getCookie(sWinName) != "no") {
		window.open(sURL, sWinName, status);
	}
}


/* ------------------------------------------------------------------------------
   기능 : 플래쉬 로딩
--------------------------------------------------------------------------------- */

function getFlash(url, w, h)
{
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width=" + w + " height=" + h + ">");
	document.write("<param name='movie' value='" + url + "'>");
	document.write("<param name='quality' value='high'>");
	document.write("<param name='wmode' value='transparent'>");
	document.write("<embed src='" + url + "' quality='high' wmode='transparent' type='application/x-shockwave-flash'  pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=" + w + " height=" + h + "'></embed>");
	document.write("</object>");
}

/* ------------------------------------------------------------------------------
    텍스트 이미지 점선테두리 없애기 
--------------------------------------------------------------------------------- */
function bluring(){ 
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=bluring; 

/* ------------------------------------------------------------------------------
   기능 : 스크린샷 이미지 크기 조절
--------------------------------------------------------------------------------- */
function setImageSize() {
	var i,imgCnt;

	try {
		imgCnt = document.all.myImage.length 

		if((typeof imgCnt == "undefined") || (typeof imgCnt == "unknown")) {
			FormatImage(document.myImage,593);
		} else {
			for (i = 1;i<=imgCnt;i++) {
				FormatImage(document.myImage[i-1],593);
			}
		}
	} 

	catch(e){}
}
function FormatImage(obj,argW,argH) {
	var w,h;
	
	if (FormatImage.arguments.length==2) {
		if (obj.width <= argW) return false;	
		w = argW;
		h = obj.height * (w/obj.width);	
		//obj.height = h;
		obj.width = w;
		obj.style.visibility = "visible";
	}
	else if(FormatImage.arguments.length) {
		if (obj.width <= argW && obj.height <= argH ) return false ;
		if (obj.width > argW) {
			w = argW;
			//h = obj.height * (w/obj.width);	
		}
		else {
			w = obj.width;
			//h = obj.height;
		}
		if (h > argH) {
			w = w * (argH/h);
		//	h = argH;	
		}
		//obj.height = h;
		obj.width = w;
		obj.style.visibility = "visible";
	}
}


/* ------------------------------------------------------------------------------
   기능 : 게임포인트 결제 방법 설명
--------------------------------------------------------------------------------- */

var oldN = "paymentId1";
var underbtn= "paymentId_btn";

function paymentType(numN)
{
    var selN = "paymentId" + numN;
    document.getElementById(oldN).style.display = "none";
    document.getElementById(selN).style.display = "block";
    document.getElementById(underbtn).style.display = "block";
    oldN = selN;
}

// 선택항목별 보여주기
function contentDisplay(objID, activeObjNum, objCnt)
{
    for (i=1; i<=objCnt; i++)
    {
        document.getElementById(objID + i).style.display = "none";
    }
    document.getElementById(objID + activeObjNum).style.display = "block";
}

/* ------------------------------------------------------------------------------
   기능 : 게임포인트 결제 -20세 미만
--------------------------------------------------------------------------------- */

function payUnder20()
{
	var url;
	var status;

    document.getElementById(underbtn).style.display = "none";

	url = "agreement.html";
	status = status + "toolbar=no, channelmode=no, location=no, directories=no, resizable=no, menubar=no";
	status = status + ", scrollbars=no, left=0, top=0, width=500, height=400, top=100, left=100";

	window.open(url, "Agreement", status);
}