var CK_MEMBERID  =  0;
var CK_PASSWORD  =  1;
var CK_NAME      =  2;
var CK_SEX       =  3;
var CK_AGE       =  4;
var CK_VALID     =  5;
var CK_AVATARID  =  6;
var CK_IDVALID   =  7;
var CK_NICKNAME  =  8;
var CK_SOCIALID  =  9;
var CK_ABSUID    = 10;
var CK_ABSSTATUS = 11;
var CK_PLUSLINK  = 12;
var CK_SERVICE   = 13;
var CK_SUBUPDATE = 14;
var CK_PLUSIP    = 15;
var CK_EMAIL     = 16;
var	CK_LASTDATE  = 17;
var	CK_LOCCODE   = 18;
var	CK_ABSTYPE   = 19;
var	CK_USERGRADE = 20;
var	CK_ADULTADYN = 21;
var	CK_MYGAME    = 22;
var	CK_PLUSITEM  = 23;
var	CK_PU  = 24;
var	CK_HCODE  = 25;
var CK_PLUSCODE = 26;

var MAX_PASSWORD_LEN = 4;

var GMT_KOREA = -540;

var __ndsFrame;
var __ndsChange;

document.title = "ÇÑ°ÔÀÓ - µû¶ó¿Ã ¼ö ¾ø´Â Àç¹Ì, ÇÑ°ÔÀÓ!";

function openWin(sURL, sWindowName, w, h, sScroll, reSize, status)
{
	// È­¸é Áß¾ÓÀ¸·Î Popup ¶ç¿ì±â.. ½ºÅ©·Ñ¹Ù´Â ¿É¼Ç..
	// ex)
	//			openWin("test.asp", "winTest", 400, 300);			¢Ñ ½ºÅ©·Ñ¹Ù ¾øÀ½
	//			openWin("test.asp", "winTest", 400, 300, "yes");	¢Ñ ½ºÅ©·Ñ¹Ù ÀÖÀ½
	//			openWin("test.asp", "winTest", 400, 300, "auto");	¢Ñ ½ºÅ©·Ñ¹Ù ÀÚµ¿

	// windows xp2 °í·Á
	if ( isXPSP2() ) {
		h += 25;
	}

	var x = (screen.width - w) / 2;
	var y = (screen.height - h) / 2;

	if (sScroll==null) sScroll = "no";

	var sOption = "";
	sOption = sOption + "toolbar=no, channelmode=no, location=no, directories=no, menubar=no";
	sOption = sOption + ", scrollbars=" + sScroll + ", resizable=" + reSize + ", status=" + status +", left=" + x + ", top=" + y + ", width=" + w + ", height=" + h;

	var win = controlOpenWindow(sURL, sWindowName, sOption);
	return win;
}

function openWinFreePos(sURL, sWindowName, w, h, x, y, sScroll)
{
	// È­¸é Æ¯Á¤À§Ä¡·Î Popup ¶ç¿ì±â.. ½ºÅ©·Ñ¹Ù´Â ¿É¼Ç..
	// ex)
	//			openWin("test.asp", "winTest", 400, 300, 0, 0);			¢Ñ ½ºÅ©·Ñ¹Ù ¾øÀ½
	//			openWin("test.asp", "winTest", 400, 300, 0, 0 "yes");	¢Ñ ½ºÅ©·Ñ¹Ù ÀÖÀ½
	//			openWin("test.asp", "winTest", 400, 300, 0, 0 "auto");	¢Ñ ½ºÅ©·Ñ¹Ù ÀÚµ¿

	if (sScroll==null) sScroll = "no";

	var sOption = "";
	sOption = sOption + "toolbar=no, channelmode=no, location=no, directories=no, resizable=no, menubar=no";
	sOption = sOption + ", scrollbars=" + sScroll + ", left=" + x + ", top=" + y + ", width=" + w + ", height=" + h;

	var win = controlOpenWindow(sURL, sWindowName, sOption);
	return win;
}

function getCookie(n)
{
	// ÄíÅ° - ·Î±×ÀÎ Á¤º¸ ÀÐ±â..
	// ex)
	//			id = getCookie(CK_MEMBERID);		¢Ñ ¾ÆÀÌµð ÀÐ±â

	var ckLogin = getStrCookie("login");
	if (ckLogin=="" || ckLogin=="undefined" || ckLogin==null) return "";

	var sList = ckLogin.split("%2C");
	if (n < sList.length) return sList[n];

	return "";
}

function isPlusItemCookie(nCookie, plusItemName)
{
	var plusItemCookie = getCookie(nCookie);
	var aPlusItem = "";

	if(plusItemCookie == "" || plusItemCookie.length == 0 )
		return false;
	
	aPlusItem = plusItemCookie.split("%23");

	for(var plusItemIdx = 0; plusItemIdx <= aPlusItem.length; plusItemIdx++)
	{
		if(aPlusItem[plusItemIdx] == plusItemName)
			return true;
	}
	return false;
}

function getStrCookie(sName)
{
	// ÄíÅ°ÀÐ±â..

	var aRec, aCook = document.cookie.split("; ");

	for (var i=0; i<aCook.length; i++) {
		aRec = aCook[i].split("=");
		if (sName.toLowerCase()==unescape(aRec[0].toLowerCase())) return aRec[1];
	}

	return "";
}

function setStrCookie(sName, sValue)
{
	// ÄíÅ°¾²±â..

	//var exDate = new Date;
	//exDate.setMonth(exDate.getMonth() + 6);
	//document.cookie = sName + "=" + sValue + ";expires=" + exDate.toGMTString();
	document.cookie = sName + "=" + sValue + ";domain=" + getFixDomain();
	return "";
}

function setMenuURL(sValue)
{
	setStrCookie("menuurl", sValue);
}

function numberFormat(nVar, nSize)
{
	// 0000000123 Çü½ÄÀ¸·Î ¹ÝÈ¯ÇÏ´Â ÇÔ¼ö, nSize »ý·«½Ã 00 ~ 99
	// ex)
	//			n = 2;
	//			s = numberFormat(n, 5);				¢Ñ s = "00002"
	//			s = numberFormat(n);				¢Ñ s = "02"

	if (nSize==null) nSize = 2;

	var s = "0000000000" + nVar;
	var n = s.length;

	return s.substring(n - nSize, n);
}

function isNum(sVal)
{
	// ¼ýÀÚÇü½ÄÀÎÁö °Ë»ç..
	// ex)
	//			b = isNum("123")					¢Ñ b = true
	//			b = isNum("123°¡³ª´Ù")				¢Ñ b = false

	if (sVal=="") return false;
	for (var i=0; i<sVal.length; i++) {
		if (sVal.charAt(i) < "0") return false;
		if (sVal.charAt(i) > "9") return false;
	}
	return true;
}

function isErrorID_Char(sBuf)
{
	// ¹®ÀÚ¿­¿¡ Æ¯¼ö±âÈ£°¡ ÀÖ´Ù¸é true ¸¦ return...

	var sChk = "!@#$%&*()|'[];:\" ^|><~`=+-\\/{}^_,.?	";
	for ( var i=0; i<sBuf.length; i++ ) {
		if (sChk.indexOf(sBuf.charAt(i)) >= 0) {
			return true;
		}
	}
	return false;
}

function isErrorID_tab(sBuf)
{
	// ¹®ÀÚ¿­¿¡ tab±âÈ£°¡ ÀÖ´Ù¸é true ¸¦ return...

	var sChk = "	";
	for ( var i=0; i<sBuf.length; i++ ) {
		if (sChk.indexOf(sBuf.charAt(i)) >= 0) {
			return true;
		}
	}
	return false;
}


function isErrorAddress(sBuf)
{
	// ¹®ÀÚ¿­¿¡ Æ¯¼ö±âÈ£°¡ ÀÖ´Ù¸é true ¸¦ return...( °ø¹éÇã¿ë )

	var sChk = "!@#$%&*()|'[];:\"^|><~`=+-\\/{}^_,.?";
	for ( var i=0; i<sBuf.length; i++ ) {
		if (sChk.indexOf(sBuf.charAt(i)) >= 0) {
			return true;
		}
	}
	return false;
}

function isErrorID_Word(sBuf)
{
	// ¹®ÀÚ¿­¿¡ Æ¯¼öID°¡ ÀÖ´Ù¸é true ¸¦ return...
	var stopIdList = "";

	stopIdList += "ÇÑ°ÔÀÓ,Å×½ºÆ®,µµ¿ì¹Ì,µµ¿À¹Ì,°ü¸®,¿î¿µ,¸¶½ºÅÍ,¸¶½ºÅ¸,admin,root,doumi,ubnf,qlor,anbf,mouky,";
	stopIdList += "°ü¸®ÀÚ,¿î¿µÀÚ,ÁöÅ´ÀÌ,´ã´ç,Ã¥ÀÓÀÚ,¼¾ÅÍ,¹®ÀÇÃ³¸®,»ó´ã,ÁöÅ°¹Ì,¸Å´ÏÀú,ÇïÆÛ,µ¥½ºÅ©,¾È³»,½Å°í,Á¦¾È,";
	stopIdList += "Ã³¸®,µµ¿òÀÌ,¾Æ¹ÙÅ¸,¾ÆÀÌµð,¾îµå¹Î,¿£ÅäÀÌ,¿£¿¡ÀÌÄ¡¿£,³×ÀÌ¹ö,naver,nhn,hangame,entoi,id,adm,desk,";
	stopIdList += "help,helper,doumi,master,119,gÅë½Å,GÅë½Å";

	var sChk = stopIdList.split(",");
	for ( var i=0; i<sChk.length; i++ ) {
		if (sBuf.indexOf(sChk[i]) >= 0) {
			return true;
		}
	}
	return false;
}

String.prototype.trim = function()
{
	// ¹®ÀÚ¿­¿¡ °ø¹éÁ¦°Å..
	// ex)
	//		s = "       ÃÖº¸À±     ".trim();	¢Ñ s = "ÃÖº¸À±"

    return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.replaceA = function(a, b)
{
	// ¹®ÀÚ¿­ ¹Ù²Ù±â..
	// ex)
	//		s = "abcÃÖº¸À±def".replace("ÃÖº¸À±", "");	¢Ñ s = "abcdef"

	var s = this;
	var n1, n2, s1, s2;

	while (true) {
		if ( s=="" || a=="" ) break;
		n1 = s.indexOf(a);
		if ( n1 < 0 ) break;
		n2 = n1 + a.length;
		if ( n1==0 ) {
			s1 = b;
		}
		else {
			s1 = s.substring(0, n1) + b;
		}
		if ( n2 >= s.length ) {
			s2 = "";
		}
		else {
			s2 = s.substring(n2, s.length);
		}
		s = s1 + s2;
	}
	return s;
}

function checkEmail(EmailForm)
{
	//email Ã¼Å©
	var strEmail = EmailForm.value;
    var i;
    var strCheck1 = false;
    var strCheck2 = false;
	var iEmailLen = strEmail.length
	var emailDomain = "";

	if (iEmailLen > 0) {
		// strEmail ¿¡ '.@', '@.' ÀÌ ÀÖ´Â °æ¿ì ¿¡·¯¸Þ½ÃÁö.
		// strEmailÀÇ ¸Ç¾Õ ¶Ç´Â ¸ÇµÚ¿¡  '@', '.' ÀÌ ÀÖ´Â °æ¿ì ¿¡·¯¸Þ½ÃÁö.
		if ((strEmail.indexOf(".@") != -1) || (strEmail.indexOf("@.") != -1) ||  (strEmail.indexOf(",") != -1) ||
			(strEmail.substring(0,1) == ".") || (strEmail.substring(0,1) == "@") ||
			(strEmail.substring(iEmailLen-1,iEmailLen) == ".") || (strEmail.substring(iEmailLen-1,iEmailLen) == "@"))
		{
	        alert("EmailÀ» Á¤È®ÇÏ°Ô ÀÔ·ÂÇÏ½Ê½Ã¿À.");
	        EmailForm.focus();
			return false;
		}
	    for ( i=0; i<iEmailLen; i++ ) {
	        if ( (strEmail.substring(i,i+1) == ".") || (strEmail.substring(i,i+1) == "-") || (strEmail.substring(i,i+1) == "_") ||
				((strEmail.substring(i,i+1) >= "0") && (strEmail.substring(i,i+1) <= "9")) ||
				((strEmail.substring(i,i+1) >= "@") && (strEmail.substring(i,i+1) <= "Z")) ||
				((strEmail.substring(i,i+1) >= "a") && (strEmail.substring(i,i+1) <= "z")) ) {
	                if (strEmail.substring(i,i+1) == ".")
						strCheck1 = true;
	                if (strEmail.substring(i,i+1) == "@")
						strCheck2 = true;
	        }
	        else {
	            alert("EmailÀ» Á¤È®ÇÏ°Ô ÀÔ·ÂÇÏ½Ê½Ã¿À.");
	            EmailForm.focus();
				return false;
	        }
	    }

	    if ((strCheck1 == false) || (strCheck2 == false)) {
	        alert("\nEmailÀ» Á¤È®ÇÏ°Ô ÀÔ·ÂÇÏ½Ê½Ã¿À.");
	        EmailForm.focus();
			return false;
	    }
		emailDomain = strEmail.substring(strEmail.indexOf("@")+1,strEmail.length);
		
	    if ((emailDomain.indexOf("hanmail") >= 0) || (emailDomain.indexOf("daum") >= 0)) {
		    alert("¢ß´ÙÀ½Ä¿¹Â´ÏÄÉÀÌ¼ÇÀÇ ¸ÞÀÏ°èÁ¤ÀÎ 'hanmail.net'ÀÌ³ª 'daum.net'Àº\n'´ÙÀ½'ÀÇ ¿Â¶óÀÎ ¿ìÇ¥Á¦·Î ÀÎÇÏ¿© »ç¿ëÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.\n ´Ù¸¥ ¸ÞÀÏÀ» µî·ÏÇØ ÁÖ¼¼¿ä.");
	        EmailForm.focus();
	 		return false;
	     }
	}
    return true;
}

function getTimezone()
{
	// Client GMT..

	now = new Date();
	return now.getTimezoneOffset();
}

function getTargetString(sGameid)
{
	var gm = "";
	var ag, sx, mb;

	if ( location.href.indexOf("game1.hangame.com") >= 0 || location.href.indexOf("game3.hangame.com") >= 0) {
		gm = (sGameid==null) ? getStrCookie("gameid") : sGameid;
	}
	if (getCookie(CK_MEMBERID).length > 0 ){
		ag = getCookie(CK_AGE);
	}else{
		ag = "0";
	}
	sx = getCookie(CK_SEX).toLowerCase();
	mb = getStrCookie("HG_AD").toLowerCase(); //2005-01-02(KTF)
	//return "&showme=html&gm=" + gm + "&ag=" + ag + "&sx=" + sx;
	return "&showme=html&gm=" + gm + "&ag=" + ag + "&sx=" + sx + "&mb=" + mb;
}

function getAdvurl(sAdcase, sGameid)
{
	var sTarget = getTargetString(sGameid);
	//alert(sTarget);
	var sKor = "http://hangamead.naver.com/ad?loc=hangame." + sAdcase + sTarget + "&refresh=5";
	
	return sKor;
}

function errPassword(sPassword, sBirth)
{
	// ÆÐ½º¿öµå °Ë»ç..
	// ex)
	//		bErr = errPassword("abcd");		¢Ñ ÆÐ½º¿öµå·Î »ç¿ë ºÒ°¡´ÉÇÑ ¹®ÀÚ¿­ÀÌ¸é bErr ¡ç true

	var ch, i, nLen, sSocialID;

	nLen = sPassword.length;
	if (nLen < MAX_PASSWORD_LEN) return true;

	ch = sPassword.substring(0, 1);
	for ( i=0; i<nLen; i++ ) {
		if (ch != sPassword.substring(i, i + 1)) break;
	}
	if (i >= nLen) return true;
	if (sBirth && sBirth.indexOf(sPassword) >= 0) return true;
	if (sPassword=="1234") return true;

	return false;
}

function chkPwdjohap(sPassword)
{
	// ¿µ¹®, ¼ýÀÚ È¥ÇÕ
	var d1=new Array(10);
	var s1=0;
	var s2=0;
	
	for(i=0;i<sPassword.length;i++) {
		d1[i]=sPassword.substring(i,i+1);
	}
	for(i=0;i<sPassword.length;i++) {
		if('A'<=d1[i] && d1[i]<='Z'||'a'<=d1[i] && d1[i]<='z') s1++;
		if('0'<=d1[i] && d1[i]<='9') s2++;
	}
	
	if(s1 < 1 || s2 < 1) return true;
	
	return false;
}

function errChar(ch)
{
	// ¼ýÀÚ, ¿µ¹®, ÇÑ±Û ÀÌ¿ÜÀÇ ¹®ÀÚÀÌ¸é true ¸®ÅÏÇÔ

	if ( ch >= "0" && ch <= "9" ) return false;
	if ( ch >= "a" && ch <= "z" ) return false;
	if ( ch >= "A" && ch <= "Z" ) return false;

	var sEncode = encodeURI(ch);
	if ( sEncode.length==9 ) {
		var sHex = sEncode.substring(1, 3);
		if ( sHex >= "EA" && sHex <= "ED" ) return false;
	}

	return true;
}

function errStandard(sChk)
{
	// ½ºÆ®¸µ¿¡ ¼ýÀÚ, ¿µ¹®, ÇÑ±Û ÀÌ¿ÜÀÇ ¹®ÀÚ°¡ µé¾îÀÖÀ¸¸é true ¸®ÅÏÇÔ

	var ch;

	for (var i=0; i<sChk.length; i++) {
		ch = sChk.substring(i, i + 1);
		if ( errChar(ch) ) return true;
	}

	return false;
}

function getFixDomain()
{
	var s = document.domain;

	if ( s.indexOf("naver.com") >= 0 ) {
		return "naver.com";
	}
	else if ( s.indexOf("hangame.com") >= 0 ) {
		return "hangame.com";
	}
	else if ( s.indexOf("nhncorp.com") >= 0 ) {
		return "nhncorp.com";
	}
	else {
		var n = s.indexOf(".");
		var test = s.split(".");
		if (test.length > 2)
		{
			return s.substring(n + 1, s.length);
		}else{
			return s;
		}
		
	}
}

function setDomain()
{
	document.domain = getFixDomain();
}

setDomain();


// HTML MUST incluse this code
//<body ONLOAD="page_resize()">    or     window.onload=page_resize
//<div id='page_content'>
// ...
//</div>
//</body>
function page_resize(page_content){
	try{
		if(this.window.name!='') 
		{
			page_content=(page_content==null)?'page_content':page_content;
			var dataobj=document.getElementById(page_content) ;
			dataobj.style.top=0 ;
			dataobj.style.left=0 ;
			var iframe_main;
			if(iframe_main=parent.document.getElementById(this.window.name)) {
				iframe_main.height=dataobj.offsetHeight ;
			}
		}
	}
	catch(e){}
}
// ºü¸£°Ô ¶ç¿ì´Â ÆË¾÷/////////////////////////////////////////
// »ç¿ë¿¹ var win = controlOpenWindow("notice","/notice.jsp","...");

var arrWndOpenWindow = new Array();

function push(array, arg){
	array[array.length] = arg;
}
function pop(array){
	var obj = array[0];
	var temp = new Array();
	for ( i = 1; i < array.length; i++ ){
		temp[i-1] = array[i];
	}
	array = temp;
	return obj;
}
function controlOpenWindow(strURL, strWndName, strOptions) {
	var arrTemp = new Array();
	var wndTemp;
	var wndName;
	
	var arrWndOpenWindow = getArrWndOpenWindow();
	if ( arrWndOpenWindow == null) {
		arrWndOpenWindow = this.arrWndOpenWindow;
	}
	for ( i = 0; i < arrWndOpenWindow.length; i++ ) {
		wndTemp = arrWndOpenWindow[i];
		if ( wndTemp == null) {
			continue;
		}
		if ( !wndTemp['window'] ) {
			continue;
		}
		if ( wndTemp['window'].closed ) {
			arrWndOpenWindow[i] = null;
			continue;
		}
		wndName = wndTemp['name'];
		if ( wndName != "" && strWndName == wndName ) {
			wndTemp['window'].location.replace(strURL);

			push(arrTemp, wndTemp);
			for ( j = 0; j < arrTemp.length; j++ ) {
				push(arrWndOpenWindow, arrTemp[j]);
			}
			return null;
		}
		push(arrTemp, wndTemp);
	}
	for ( i = 0 ; i < arrTemp.length; i++ ) {
		push(arrWndOpenWindow, arrTemp[i]);
	}

	var	wndNewWindow = window.open(strURL, '', strOptions);
	
	var wndSaveWindow = new Array();
	wndSaveWindow['name'] = strWndName;
	wndSaveWindow['window'] = wndNewWindow;

	push(arrWndOpenWindow, wndSaveWindow);
	return wndNewWindow;
}

function getArrWndOpenWindow() {
	return top.arrWndOpenWindow;
}
// ºü¸£°Ô ¶ç¿ì´Â ÆË¾÷°ü·Ã ³¡//////////////////////////////////

//''''''''''''''''''''''''''''''''''''''''''''
// Menu Implement
//
//''''''''''''''''''''''''''''''''''''''''''''

function popsizectl() {
	var appname = navigator.appName;
	var useragent = navigator.userAgent;
	// firefox°¡ ¾Æ´Ò °æ¿ì¿¡¸¸  ¸®»çÀÌÁî¸¦ ÇÏµµ·Ï ÇÔ 
	if(appname.indexOf("Netscape")==-1 && useragent.indexOf("Firefox")==-1) {
		document.getElementById('page_content').style.position="absolute";
		document.getElementById('page_content').style.left="0";
		document.getElementById('page_content').style.top="0";
		document.getElementById('page_content').style.width="0";
		popresize();		
	}
}

function popresize() {
	var objOut,popw,poph;

	objOut=document.all["page_content"];  // ¿Ü°û divÀÇ id·Î objectÃ£±â
	popw=objOut.clientWidth+10;	// 10 px : window border
	poph=objOut.clientHeight+29;	// 29 px : windwo border & title bar
	// windowXP SP2 ÆË¾÷ ¹Ù Å©±â °í·Á
	//if(navigator.appVersion.indexOf("Windows NT 5.1; SV1") != -1){
	//	poph=poph+25;
	//}
	if ( isXPSP2() ) {
		poph += 25;
	}

	if( objOut.style.overflowY == "scroll" ) // ¼¼·Î scrollÇÊ¿äÇÑ °æ¿ì¸¦ À§ÇÑ Á¶°Ç¹®
	{
		popw += 16;  // scroll bar ¸¸Å­ pixel°ª
	}
	this.resizeTo(popw,poph);
	this.focus();
}



function popresize(objId) {
	var objOut,popw,poph;

	if ( typeof(objId)=="undefined" || objId==null )
		objId = "page_content";
		
	objOut=document.all(objId);  // ¿Ü°û divÀÇ id·Î objectÃ£±â
	if ( objOut==null || typeof(objOut)=="undefined" )
		return;
		
	popw=objOut.clientWidth+10;	// 10 px : window border
	poph=objOut.clientHeight+29;	// 29 px : windwo border & title bar
	// windowXP SP2 ÆË¾÷ ¹Ù Å©±â °í·Á
	//if(navigator.appVersion.indexOf("Windows NT 5.1; SV1") != -1){
	//	poph=poph+25;
	//}
	if ( isXPSP2() ) {
		poph += 25;
	}

	if( objOut.style.overflowY == "scroll" ) // ¼¼·Î scrollÇÊ¿äÇÑ °æ¿ì¸¦ À§ÇÑ Á¶°Ç¹®
	{
		popw += 16;  // scroll bar ¸¸Å­ pixel°ª
	}

	if(isXP())	poph += 6; //XP ÀÎ°æ¿ì Ã¢ÀÌ Å­.

	this.resizeTo(popw,poph);
	this.focus();
}

//°ÔÀÓ Å¬¶óÀÌ¾ðÆ® Ã¢¿¡¼­ popup µÇ´Â °æ¿ì
function clientPopResize(objId, addWidth, addHeight) {
	var objOut,popw,poph;

	if (typeof(objId)=="undefined" || objId==null)
		objId = "page_content";
		
	objOut=document.all(objId);  // ¿Ü°û divÀÇ id·Î objectÃ£±â
	if (objOut==null || typeof(objOut)=="undefined")
		return;
		
	popw=objOut.clientWidth+22;		// 10 px : window border
//	poph=objOut.clientHeight+29;	// 29 px : windwo border & title bar
	poph=objOut.clientHeight+10;	// 29 px : windwo border & title bar

	if (objOut.style.overflowY == "scroll") { // ¼¼·Î scrollÇÊ¿äÇÑ °æ¿ì¸¦ À§ÇÑ Á¶°Ç¹®
		popw += 16;  // scroll bar ¸¸Å­ pixel°ª
	}

  	if (addWidth != null && typeof(addWidth)!="undefined" && addWidth > 0)
    	popw += addWidth;
    
  	if (addHeight != null && typeof(addHeight)!="undefined" && addHeight > 0)
    	poph += addHeight;
    
    if (poph >= 600)
    	poph = 599; //600À» ³ÑÀ¸¸é °ÔÀÓ Å¬¶óÀÌ¾ðÆ® ÂÊ¿¡¼­ ¹öÆ°ÀÌ º¸ÀÌÁö ¾Ê´Â ¹®Á¦ ÀÖÀ½.
    
	this.resizeTo(popw,poph);
	this.focus();
}



/**
 * example:
 *  fitPopupSize();                  <- ID°¡ 'page_content'ÀÎ objectÀÇ clientWidth, clientHeight °ª¿¡ µû¶ó »çÀÌÁî Á¶Àý
 *  fitPopupSize( object );          <- ÁÖ¾îÁø objectÀÇ clientWidth, clientHeight°ª¿¡ µû¶ó »çÀÌÁî Á¶Àý
 *  fitPopupSize( "pageOuter" );     <- ID°¡ 'pageOuter'ÀÎ objectÀÇ clientWidth, clientHeight °ª¿¡ µû¶ó »çÀÌÁî Á¶Àý
 *  fitPopupSize( 300, 400 );        <- ÆË¾÷ Å©±â¸¦ 300 x 400À¸·Î Á¶Àý
 */
function fitPopupSize( arg1, arg2 ) {
	var toWidth = null;
	var toHeight = null;
	var objOut = null;

	var typeArg1 = typeof(arg1);
	
	if( typeArg1 == "undefined" ) {
		objOut = document.getElementById("page_content");
	}
	if( typeArg1 == "string" ) {
		objOut = document.getElementById(arg1);
		if( objOut == null ) { return; }
	}
	if( typeArg1 == "object" ) {
		objOut = arg1;
	}
	if( objOut != null ) {
		toWidth = objOut.clientWidth;
		toHeight = objOut.clientHeight;
	}
	if( typeArg1 == "number" && typeof(arg2) == "number" ) {
		toWidth = arg1;
		toHeight = arg2;
	}
	if( toWidth == null && toHeight == null ) { return; }

	fitPopupSize_adjustPosition( toWidth, toHeight );

	fitPopupSize_resize( toWidth, toHeight );
}

function fitPopupSize_adjustPosition( toWidth, toHeight ) {
	var posLeft = (window.screenLeft) ? window.screenLeft : window.screenX;
	var posTop = (window.screenTop) ? window.screenTop : window.screenY;
	var adjustLeft = 0;	var marginWidth = 50;
	var adjustTop = 0;	var marginHeight = 50;
	var movingRequired = false;

	if( posTop + toHeight + marginHeight > screen.availHeight ) {
		adjustTop = -(posTop + toHeight + marginHeight - screen.availHeight);
		movingRequired = true;
	}
	if( posLeft + toWidth + marginWidth > screen.availWidth ) {
		adjustLeft = -(posLeft + toWidth + marginWidth - screen.availWidth);
		movingRequired = true;
	}
	if( movingRequired ) {
		window.moveBy( adjustLeft, adjustTop );
	}
}

function fitPopupSize_resize( toWidth, toHeight ) {
	var oBody = document.body;
	if( oBody == null ) { return; }

	if( typeof(window.innerHeight) != "undefined" && typeof(window.innerWidth) != "undefined" ) {
		window.innerHeight = toHeight;
		window.innerWidth = toWidth;
	} else {
		var diffX = toWidth - oBody.clientWidth;
		var diffY = toHeight - oBody.clientHeight;

		window.resizeBy( diffX, diffY );
	}
	
	var posLeft = (window.screenLeft) ? window.screenLeft : window.screenX;
	var posTop = (window.screenTop) ? window.screenTop : window.screenY;

	if( oBody.clientHeight > screen.availHeight ) {
		var adjustHeight = screen.availHeight - (oBody.clientHeight + 50);
		window.moveTo(posLeft, 0);
		window.resizeBy( 0, adjustHeight );
	}
}

function fitPopupSizeEx() {
	var oBody = document.body;
	if( oBody == null ) { return; }
	
	var idPrefix = "page_content";
	var objId = "";
	var chkResult = false;
	var objChk = null;
	
	for( var i=65; i<=90; i++ ) {
		objId = idPrefix + String.fromCharCode(i);
		objChk = document.getElementById(objId);
		if( objChk == null ) { break; }
	}
	if( objChk != null ) { return; }

	var objOut = window.document.createElement("<div id='" + objId + "' style='position:absolute;left:0;top:0;'>");

	var existNodeList = window.document.body.childNodes;
	while( existNodeList.length > 0 ) {
		objOut.appendChild( existNodeList[0] );
	}
	document.body.appendChild( objOut );

	var toWidth = objOut.clientWidth;
	var toHeight = objOut.clientHeight;
	if( toWidth == null && toHeight == null ) { return; }

	fitPopupSize_adjustPosition( toWidth, toHeight );

	fitPopupSize_resize( toWidth, toHeight );
}



function clickPageCount(section) { 		
    clickframe.location.href='http://click.hangame.com/click/counter.nhn?version=4.0d&section=' + section + '&item=0000';
	var a = 0;
}

function setPageId() {
	if (typeof(__ndsFrame)=="undefined") {
		//var s = "<iframe name='__ndsIframe' onreadystatechange='ndsChange(this);' width=0 height=0 frameborder=0 style='display:none'></iframe>";
		//s += "<script>attachEvent('onload',__ndsLoad2);</script>";
		//var s = "<iframe name='__ndsIframe' src='http://lcs.hangame.com/u{" + document.URL + "}' width=0 height=0 frameborder=0 style='display:none'></iframe>";
		var s = "<iframe name='__ndsIframe' width=0 height=0 frameborder=0 style='display:none'></iframe>";
		__ndsFrame = "set";
		document.write (s);
		setTimeout("__ndsLoadMain()",500);
	//	alert('common sepageid');
	}
	
}

function __ndsLoadMain() {
	if ( document.all.__ndsIframe && typeof(document.all.__ndsIframe)=="object" ) {
		document.all.__ndsIframe.src = "http://lcs.hangame.com/u{" + document.URL + "}";
	} else {
		setTimeout("__ndsLoadMain()",500);	
	}
}

function isXPSP2(){      
    tmp_MSIE = window.navigator.userAgent.indexOf("MSIE");   
    if(tmp_MSIE && window.navigator.userAgent.indexOf("SV1") > tmp_MSIE){     		
        return true;     //SP2   
    }else{    		
        return false;   
    }  
}

/**
 * °°Àº XP SP2 ¹öÀüÀÌ¶óµµ Æ¯Á¤ ¾ð¾î ³»Áö´Â Æ¯Á¤ ÆÐÄ¡°¡ Àû¿ëµÈ XP¿¡¼­ userAgent °ª¿¡¼­ MSIE, SV1 ¹®ÀÚ¿­ÀÇ À§Ä¡°¡ ´Ù¸¥ °æ¿ì°¡ ÀÖ¾î¼­,
 * À§ÀÇ isXPSP2() ÇÔ¼ö¸¦ ±×´ë·Î »ç¿ëÇÒ ¼ö°¡ ¾ø´Â °æ¿ì°¡ ÀÖ´Ù.
 * º¸´Ù ÀÏ¹ÝÀûÀÎ »óÈ²¿¡¼­ ¾µ ¼ö ÀÖµµ·Ï Ãß°¡µÈ ÇÔ¼ö. (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwxp/html/xpsp2web.asp)
 */
function isXPSP2General() {
   var chkIsSP2 = (window.navigator.userAgent.indexOf("SV1") != -1);
   return chkIsSP2;
}

function isXP(){
	var agent = window.navigator.userAgent;
	if(agent.indexOf("MSIE")!= -1 && agent.indexOf("5.1") !=-1)
	    return true;     //SP1   
    else
        return false;   
}

///////////////////
// ·Î±×ÀÎ ¿©ºÎ Á¶»ç (2004.11.25 ½Å±Ô ÄíÅ°)
// 

function isHangameLogined() {
	var hglogin = getStrCookie("HG_LOGIN");
	if ( hglogin.length > 0 )
		return true;
	else
		return false;
}


///////////////////////////////
// ÆË¾÷ ÄíÅ° °ü·Ã (2004.11.24
///////////////////////////////



var common_POPUPCOOKIENAMEGLOBAL = "POPUP";
var common_POPUPCOOKIENAMEEVENT = "EV_POPUP";
var common_POPUPCOOKIEDELIM = "_";
var common_POPUPCOOKIESUBDELIM = "+";

//////////////////////
// escaping, delete delims
//////////////////////
function common_escapePCID(id) {
	return id.replace(/_/g,"").replace(/\+/g,"");
}


//////////////////////
// set popup cookie
// EV_POPUP=name1+expiredate1_name2+expiredate2_name3+expiredate3...;
//////////////////////
function common_setEventPopup(id, expireDays) {
	// only valid in xxx-event.hangame.com or event.hangame.com
	if ( document.location.host.indexOf("event.hangame.com") < 0 ) return;
	
	var popupCookie = unescape(getStrCookie(common_POPUPCOOKIENAMEEVENT));
	var pcaItem = common_parsePopupCookie(popupCookie);
	
	var todayDate = new Date();
	var tempDate = expireDays;
	todayDate.setDate( todayDate.getDate() + Math.floor(tempDate) );
	tempDate = tempDate - Math.floor(tempDate);
	todayDate.setHours(todayDate.getHours() + Math.floor(tempDate*24) );
	tempDate = tempDate*24 - Math.floor(tempDate*24);
	todayDate.setMinutes(todayDate.getMinutes() + Math.round(tempDate*60) );
	var popupDate = common_getYYYYMMDDHHmm(todayDate);

	// add
	pcaItem.add(id,popupDate);
	var finalPCStr = pcaItem.toString();
	document.cookie = common_POPUPCOOKIENAMEEVENT + "=" + finalPCStr + "; path=/; expires=" + pcaItem.maxExpireDate.toGMTString() + ";"
}

//////////////////////
// check popup cookie
// return true if a cookie named "id" exists and is not expired
//////////////////////
function common_existEventPopup(id) {
	// only valid in xxx-event.hangame.com or event.hangame.com
	if ( document.location.host.indexOf("event.hangame.com") < 0 ) return;

	var popupCookie = unescape(getStrCookie(common_POPUPCOOKIENAMEEVENT));
	var pcaItem = common_parsePopupCookie(popupCookie);
	// refresh
	var finalPCStr = pcaItem.toString();
	var maxExpireDate = pcaItem.maxExpireDate;
	if ( maxExpireDate == null )
		maxExpireDate = new Date(1999,11,31,23,59);
	document.cookie = common_POPUPCOOKIENAMEEVENT + "=" + finalPCStr + "; path=/; expires=" + maxExpireDate.toGMTString() + ";"
	
	// get
	var foundItem = pcaItem.search(id);
	if ( foundItem && !foundItem.expired ) {
		return true;
	} else {
		return false;
	}
}

//////////////////////
// set popup cookie
// POPUP=name1+expiredate1_name2+expiredate2_name3+expiredate3...;
//////////////////////

function common_setPopupCookie(id, expireDays) {
	var popupCookie = unescape(getStrCookie(common_POPUPCOOKIENAMEGLOBAL));
	var pcaItem = common_parsePopupCookie(popupCookie);
	
	var todayDate = new Date();
	var tempDate = expireDays;
	todayDate.setDate( todayDate.getDate() + Math.floor(tempDate) );
	tempDate = tempDate - Math.floor(tempDate);
	todayDate.setHours(todayDate.getHours() + Math.floor(tempDate*24) );
	tempDate = tempDate*24 - Math.floor(tempDate*24);
	todayDate.setMinutes(todayDate.getMinutes() + Math.round(tempDate*60) );
	var popupDate = common_getYYYYMMDDHHmm(todayDate);

	// add
	pcaItem.add(id,popupDate);
	var finalPCStr = pcaItem.toString();
	document.cookie = common_POPUPCOOKIENAMEGLOBAL + "=" + finalPCStr + "; domain=hangame.com; path=/; expires=" + pcaItem.maxExpireDate.toGMTString() + ";"
}

//////////////////////
// check popup cookie
// return true if a cookie named "id" exists and is not expired
//////////////////////
function common_existPopupCookie(id) {
	var popupCookie = unescape(getStrCookie(common_POPUPCOOKIENAMEGLOBAL));
	var pcaItem = common_parsePopupCookie(popupCookie);
	// refresh
	var finalPCStr = pcaItem.toString();
	var maxExpireDate = pcaItem.maxExpireDate;
	if ( maxExpireDate == null )
		maxExpireDate = new Date(1999,11,31,23,59);
	document.cookie = common_POPUPCOOKIENAMEGLOBAL + "=" + finalPCStr + "; domain=hangame.com; path=/; expires=" + maxExpireDate.toGMTString() + ";"
	
	// get
	var foundItem = pcaItem.search(id);
	if ( foundItem && !foundItem.expired ) {
		return true;
	} else {
		return false;
	}
}

//////////////////////
// return YYYYMMDDHHmm
//////////////////////
function common_getYYYYMMDDHHmm(d) {
	var year = d.getFullYear();
	var month = common_makeTwoDigits(d.getMonth()+1);
	var date = common_makeTwoDigits(d.getDate());
	var hours = common_makeTwoDigits(d.getHours());
	var mins = common_makeTwoDigits(d.getMinutes());
	return year + month + date + hours + mins;
}

//////////////////////
// "1" -> "01"
//////////////////////
function common_makeTwoDigits(val) {
	if ( eval(val) >= 10 )
		return val.toString();
	else
		return "0"+val.toString();
}

//////////////////////
// YYYYMMDDHHmm -> Date
//////////////////////
function common_makeDateFromString(str) {
	if ( str!=null && str.length==12) {
		var year = eval(str.substring(0,4));
		var month = eval(str.substring(4,6));
		var date = eval(str.substring(6,8));
		var hour = eval(str.substring(8,10));
		var min = eval(str.substring(10,12));
		return new Date(year,month-1,date,hour,min);
	} else
		return null;
}

//////////////////////
// return new common_popupCookieArrayItem from cookie string
//////////////////////
function common_parsePopupCookie(str) {
	var pcaItem = new common_popupCookieArrayItem();
	if ( str ) {
		var arr = str.split(common_POPUPCOOKIEDELIM);
		for ( var i = 0 ; i < arr.length ; i++ ) {
			var temp = arr[i].split(common_POPUPCOOKIESUBDELIM);
			if ( temp!=null ) {
				var pcItem = pcaItem.add(temp[0],temp[1]);
				// maxExpireDate
				if ( pcaItem.maxExpireDate == null )
					pcaItem.maxExpireDate = pcItem.expireDate;
				else if ( pcaItem.maxExpireDate < pcItem.expireDate )
					pcaItem.maxExpireDate = pcItem.expireDate;
			}
		}
	}
	return pcaItem;
}

//////////////////////
// used in common_parsePopupCookie()
//////////////////////
function common_popupCookieArrayItem() {
	this.arrData = new Array();
	this.maxExpireDate = null;
	this.cookieString = "";
	this.toString = common_getPopupCookieString;
	this.add = common_addPopupCookieItem;
	this.search = common_searchPopupCookieItem;
}

//////////////////////
// add item to arrData
//////////////////////
function common_addPopupCookieItem(name,expireDateYYYY) {
	var pcItem = this.search(name);
	if ( pcItem == null ) { // not found
		pcItem = new common_popupCookieItem(common_escapePCID(name),expireDateYYYY);
		this.arrData[this.arrData.length] = pcItem;
	} else { // already exist
		pcItem.expireDateYYYY = expireDateYYYY;
		pcItem.refresh();	
	}
	
	if ( this.maxExpireDate == null )
		this.maxExpireDate = pcItem.expireDate;
	else if ( this.maxExpireDate < pcItem.expireDate )
		this.maxExpireDate = pcItem.expireDate;
	return pcItem;
}

//////////////////////
// return an item named id in arrData
//////////////////////
function common_searchPopupCookieItem(id) {
	var escapedId = common_escapePCID(id);
	for ( var i = 0 ; i < this.arrData.length ; i++ ) {
		if ( this.arrData[i].name == escapedId )
			return this.arrData[i];
	}
	return null;
}

//////////////////////
// return cookie string
//////////////////////
function common_getPopupCookieString() {
	var res = "";
	for ( var i = 0 ; i < this.arrData.length ; i++ ) {
		if ( this.arrData[i] && !this.arrData[i].expired ) {
			if ( res.length > 0 ) res += escape(common_POPUPCOOKIEDELIM);
			res += escape(this.arrData[i].name + common_POPUPCOOKIESUBDELIM + this.arrData[i].expireDateYYYY);
		}
	}
	this.cookieString = res;
	return res;
}

//////////////////////
// pcItem
//////////////////////
function common_popupCookieItem(name,expireDateYYYY) {
	this.name = name;
	this.expireDateYYYY = expireDateYYYY;
	this.expireDate = null;
	this.expired = true;
	this.refresh = common_popupCookieItemRefresh;
	this.refresh();
}

//////////////////////
// refresh date
//////////////////////
function common_popupCookieItemRefresh() {
	this.expireDate = common_makeDateFromString(this.expireDateYYYY);
	var curDate = new Date();
	if ( this.expireDate == null ) {
		this.expired = true;
	} else {
		this.expired = (curDate > this.expireDate) ? true : false;
	}
}

//////////////////////
// delete popup cookie
//////////////////////
function common_delPopupCookie() {
	document.cookie = common_POPUPCOOKIENAMEGLOBAL + "=; domain=hangame.com; path=/; expires=Fri, 31 Dec 1999 23:59:59 ";
}

function common_delEventPopup() {
	document.cookie = common_POPUPCOOKIENAMEEVENT + "=; path=/; expires=Fri, 31 Dec 1999 23:59:59 ";
}


//////////////////////////
// array cookie
//////////////////////////


//////////////////////
// set array cookie
// COOKIENAME=name1+value1+expiredate1_name2+value2+expiredate2_name3+value3+expiredate3...;
//////////////////////
function common_setArrayCookie(cookieName, id, value, expireDays, domain) {
	var acItemList = common_parseArrayCookie(unescape(getStrCookie(cookieName)));
	
	// get expire date
	var endDate = new Date();
	common_addDate(endDate, expireDays);

	// add
	var acItem = acItemList.add(id,value,common_getYYYYMMDDHHmm(endDate));
	common_setArrayCookieReal(cookieName, acItemList.toString(), domain, acItemList.maxExpireDate.toGMTString() );
}

function common_addDate(dateObj, addedDays) {
	var tempDate = addedDays;
	dateObj.setDate( dateObj.getDate() + Math.floor(tempDate) );
	tempDate = tempDate - Math.floor(tempDate);
	dateObj.setHours(dateObj.getHours() + Math.floor(tempDate*24) );
	tempDate = tempDate*24 - Math.floor(tempDate*24);
	dateObj.setMinutes(dateObj.getMinutes() + Math.round(tempDate*60) );
}

//////////////////////
// get array cookie
//////////////////////
function common_getArrayCookie(cookieName, id, domain) {
	var acItemList = common_parseArrayCookie(unescape(getStrCookie(cookieName)));
	
	//refresh
	var maxExpireDate = acItemList.maxExpireDate;
	if ( maxExpireDate == null ) maxExpireDate = new Date(1999,11,31,23,59);
	common_setArrayCookieReal(cookieName, acItemList.toString(), domain, maxExpireDate.toGMTString() );
	
	// get
	var foundItem = acItemList.search(id);
	if ( foundItem && !foundItem.expired )
		return foundItem.value;
	return null;
}

function common_setArrayCookieReal(cookieName, cookieValue, domain, expireDateGMTString) {
	if ( domain != null && domain.length > 0  )
		document.cookie = cookieName + "=" + cookieValue + "; domain=" + domain + "; path=/; expires=" + expireDateGMTString + ";"
	else
		document.cookie = cookieName + "=" + cookieValue + "; path=/; expires=" + expireDateGMTString + ";"
}

//////////////////////
// arrayCookieItem
//////////////////////
function common_arrayCookieItem(name,value,expireDateYYYY) {
	this.name = name;
	this.value = value;
	this.expireDateYYYY = expireDateYYYY;
	this.expireDate = null;
	this.expired = true;
	this.refresh = common_arrayCookieItemRefresh;
	this.refresh();
}

//////////////////////
// refresh date
//////////////////////
function common_arrayCookieItemRefresh() {
	this.expireDate = common_makeDateFromString(this.expireDateYYYY);
	var curDate = new Date();
	if ( this.expireDate == null ) {
		this.expired = true;
	} else {
		this.expired = (curDate > this.expireDate) ? true : false;
	}
}

//////////////////////
// return new common_arrayCookieItemList from cookie string
//////////////////////
function common_parseArrayCookie(str) {
	var acItemList = new common_arrayCookieItemList();
	if ( str ) {
		var arr = str.split(common_POPUPCOOKIEDELIM);
		for ( var i = 0 ; i < arr.length ; i++ ) {
			var temp = arr[i].split(common_POPUPCOOKIESUBDELIM);
			if ( temp!=null ) {
				var acItem = acItemList.add(temp[0],temp[1],temp[2]);
				// maxExpireDate
				if ( acItemList.maxExpireDate == null )
					acItemList.maxExpireDate = acItem.expireDate;
				else if ( acItemList.maxExpireDate < acItem.expireDate )
					acItemList.maxExpireDate = acItem.expireDate;
			}
		}
	}
	return acItemList;
}


//////////////////////
// used in common_parseArrayCookie()
//////////////////////
function common_arrayCookieItemList() {
	this.arrData = new Array();
	this.maxExpireDate = null;
	this.cookieString = "";
	this.toString = common_getArrayCookieString;
	this.add = common_addArrayCookieItem;
	this.search = common_searchArrayCookieItem;
}


//////////////////////
// add item to arrData
//////////////////////
function common_addArrayCookieItem(name,value,expireDateYYYY) {
	var acItem = this.search(name);
	if ( acItem == null ) { // not found
		acItem = new common_arrayCookieItem(common_escapePCID(name),common_escapePCID(value),expireDateYYYY);
		this.arrData[this.arrData.length] = acItem;
	} else { // already exist
		acItem.value = common_escapePCID(value);
		acItem.expireDateYYYY = expireDateYYYY;
		acItem.refresh();	
	}
	
	if ( this.maxExpireDate == null )
		this.maxExpireDate = acItem.expireDate;
	else if ( this.maxExpireDate < acItem.expireDate )
		this.maxExpireDate = acItem.expireDate;
	return acItem;
}

//////////////////////
// return an item named id in arrData
//////////////////////
function common_searchArrayCookieItem(id) {
	var escapedId = common_escapePCID(id);
	for ( var i = 0 ; i < this.arrData.length ; i++ ) {
		if ( this.arrData[i].name == escapedId )
			return this.arrData[i];
	}
	return null;
}

//////////////////////
// return cookie string
//////////////////////
function common_getArrayCookieString() {
	var res = "";
	for ( var i = 0 ; i < this.arrData.length ; i++ ) {
		if ( this.arrData[i] && !this.arrData[i].expired ) {
			if ( res.length > 0 ) res += escape(common_POPUPCOOKIEDELIM);
			res += escape(this.arrData[i].name + common_POPUPCOOKIESUBDELIM + this.arrData[i].value + common_POPUPCOOKIESUBDELIM + this.arrData[i].expireDateYYYY);
		}
	}
	this.cookieString = res;
	return res;
}

function viewActiveObject(html){
	document.write(html);
}
