/**
 * common.js 호환 레이어 파일
 * 
 */


/**
 * 로그인 쿠키 관련 상수 목록
 * HG.CONSTANT 로 이동
 */
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_VIP       = 22;
var	CK_PLUSITEM  = 23;
var	CK_PU		 = 24;
var	CK_HCODE		 = 25;
var	CK_PLUSCODE		 = 26;


/**
 * JS 쿠키 관련 상수 목록
 * HG.CONSTANT 로 이동
 */
var JS_IDVALID   =  0;
var JS_AGE 		 =  1;
var JS_SEX       =  2;
var JS_ADULTADYN =  3;
var JS_GRC       =  4;
var JS_PBK       =  5;
var JS_PBS       =  6;
var JS_EVENT     =  7;
var JS_6MONTH    =  8;
var JS_PHEJIRES  =  9;
var JS_PROMOTION = 10;
var JS_PUBILL	 = 11;
var JS_IDI_CD	 = 12;

var MAX_PASSWORD_LEN = 4;

var GMT_KOREA = -540;

var __ndsFrame;
var __ndsChange;


/**
 * 한게임 브라우저 지원 정책에 따라(6.0이상만 지원) 
 * encodeURIComponent 함수 정의 하는 부분 제거 함
 */
 
 
/**
 * sWindowName에 한글사용금지/영문사용
 *
 * @example
openWin("test.asp", "winTest", 400, 300);			☞ 스크롤바 없음
openWin("test.asp", "winTest", 400, 300, "yes");	☞ 스크롤바 있음
openWin("test.asp", "winTest", 400, 300, "auto");	☞ 스크롤바 자동
 */
function openWin(sURL, sWindowName, w, h, sScroll, reSize, status) {
	var x = (screen.width - w) / 2;
	var y = (screen.height - h) / 2;
	
	var win = C.openWin(sURL, sWindowName, C.OPTION_NEWWINDOW, {
		left : x,
		top : y,
		width : w,
		height : h,
		scrollbars : screen.width == 800 && screen.height == 600 ? "yes" : (sScroll || "no"),
		resizable : reSize || "auto",
		status : status || "auto"
	});
	
	try {
		win.focus();
	} catch(e) {}
	
	return win;
}

function openWinFreePos(sURL, sWindowName, w, h, x, y, sScroll) {
	C.openWin(sURL, sWindowName, C.OPTION_NEWWINDOW, {
		left : x,
		top : y,
		width : w,
		height : h,
		scrollbars : screen.width == 800 && screen.height == 600 ? "yes" : (sScroll || "no")
	});
}

function openWinNative(sURL, sWindowName, width, height, x, y) {
	var left = (typeof(x) != "undefined") ? x : (screen.availWidth - width) / 2;
	var top = (typeof(y) != "undefined") ? y : (screen.availHeight - height) / 2;
	
	C.openWin(sURL, sWindowName, C.OPTION_NEWWINDOW, {
		left : left,
		top : top,
		width : width,
		height : height
	});
}


/*
 * 이벤트 핸들러 wrapper function
 * addEventHandler("onload", function) or addEventHandler("load", function)
 */
function addEventHandler(eventName, handler) {
	C.addEvent(window, eventName, handler);
}


/**
 * 로그인 쿠키 값 가져옴
 * @deprecated HG 라이브러리로 대체
 */
function getCookie(n) {
	return HG.getLoginCookie(n);
}


/**
 * JS 쿠키 값 가져옴
 * @deprecated HG 라이브러리로 대체
 */
function getJsCookie(n) {
	return HG.getJSCookie(n);
}


/**
 * 회원제 해지예약상태체크 
 * @deprecated HG 라이브러리로 대체
 */
function isPlusHejiResType(plustype) {
	return HG.isPlusHejiResType(plustype);
}


/**
 * @deprecated HG 라이브러리로 대체
 */
function isPlusItemCookie(nCookie, plusItemName) {
	return HG.isPlusItemCookie(nCookie, plusItemName);
}


/**
 * author : monarchi
 * desc : login info for publishing game client (billing module)
 * @deprecated HG 라이브러리로 대체
 */
function getStrCookieForPubGameString() {
	return HG.getStrCookieForPubGameString();
}


/*
 * 쿠키읽기..
 * @deprecated HG 라이브러리로 대체
 */
function getStrCookie(sName) {
	return HG.getCookie(sName);
}


/*
 * 쿠키 파싱 버그 수정 : 쿠키 내용에 = 이 있는 경우 Contents 유실되는 경우를 막음
 * 20080718 이정은
 * @deprecated 진도의 쿠키 모듈 사용으로 용도가 사라짐
 */
function getRealContents(aRec) {
	if (aRec.length > 2) {
		return aRec.slice(1, aRec.length).join('');
	} else {
		return aRec[1];
	} 
}


/*
 * 쿠키쓰기..
 * @deprecated HG 라이브러리로 대체
 */
function setStrCookie(sName, sValue) {
	HG.setCookie(sName, sValue);
	return "";
}

function setMenuURL(sValue) {
	HG.setCookie("menuurl", sValue);
}


/**
 * 0000000123 형식으로 반환하는 함수, nSize 생략시 00 ~ 99
 * ex)
 *			n = 2;
 *			s = numberFormat(n, 5);				☞ s = "00002"
 *			s = numberFormat(n);				☞ s = "02"
 * @deprecated STR의 패딩 함수 사용 권고 
 */
function numberFormat(nVar, nSize) {
	return STR.padLeft(nVar, nSize || 2, '0');
}


/**
 * 숫자형식인지 검사..
 * ex)
 *		b = isNum("123")					☞ b = true
 *		b = isNum("123가나다")				☞ b = false
 * @deprecated STR의 숫자 판별 함수 사용 권고 
 */
function isNum(sVal) {	
	return STR.containsOnlyNumber(sVal);
}


/**
 * 문자열에 특수기호가 있다면 true 를 return...
 * @deprecated HG 라이브러리로 대체, id 검증 메소드 사용 권고
 */
function isErrorID_Char(sBuf) {
	return !HG.verifyId(sBuf);
}


/**
 * 문자열에 tab기호가 있다면 true 를 return...
 * @deprecated STR의 문자 포함 체크 함수 사용 권고 
 */
function isErrorID_tab(sBuf) {
	return STR.contains(sBuf, '\t');
}


/**
 * 문자열에 특수기호가 있다면 true 를 return...( 공백허용 )
 * @deprecated HG 라이브러리로 대체, 특수 문자 포함 체크 메소드 사용 권고
 */
function isErrorAddress(sBuf) {
	return HG.containsSpecialCharacter(sBuf);
}


/**
 * 문자열에 특수ID가 있다면 true 를 return...
 * @deprecated HG 라이브러리로 대체, 아이디로 사용금지된 문자열 판별  메소드 사용 권고
 */
function isErrorID_Word(sBuf) {
	return HG.checkForbiddenId(sBuf);
}


/*
 * 문자열에 공백제거..
 * ex)
 *		s = "       최보윤     ".trim();	☞ s = "최보윤"
 */
String.prototype.trim = function() {
    return STR.trim(this);
}


/*
 * 문자열 바꾸기..
 * ex)
 *		s = "abc최보윤def".replace("최보윤", "");	☞ s = "abcdef"
 */
String.prototype.replaceA = function(a, b) {
	return STR.replace(this, a, b);
}


/*
 * email 체크
 * @deprecate 공통의 email 문자열 검증 함수에서 alert 등의 행위를 지정하는 것은 적절하지 않음
 * STR.isEmailAddress, HG.verfiyMailDomain 메소드를 이용하여 체크한 다음 결과에 따라서 행위를 지정하게 작성하는 것을 권고
 */
function checkEmail(EmailForm) {
	var strEmail = EmailForm.value;
	
	if (STR.isEmailAddress(strEmail) == true) {
		return true;
		
		/*	2009.09.29 일자로 다음/한게임 온라인우표제 관련 체크 삭제되었음
		if (HG.verifyMailDomain(strEmail)) {
			return true;
		} else {
			alert("㈜다음커뮤니케이션의 메일계정인 'hanmail.net'이나 'daum.net'은\n'다음'의 온라인 우표제로 인하여 사용하실 수 없습니다.\n 다른 메일을 등록해 주세요.");
		}
		*/
	} else {
		alert("Email을 정확하게 입력하십시오.");
	}

	EmailForm.focus();
	return false;
}


function getTimezone() {
	// Client GMT..

	var now = new Date();
	return now.getTimezoneOffset();
}


function getTargetString() {
	var ag, sx;
	if (getCookie(CK_MEMBERID).length > 0 ){
		ag = getCookie(CK_AGE);
		sx = getCookie(CK_SEX) == 'M' ? '1' : '2';
	}else{
		ag = "";
		sx = "";
	}
	
	return "&t2=" + sx + ag;
}



var poker = /hoola2|poker7|duelpoker|sudda|highlow|baduki/g;
var gostop = /msduelgo|ssduelgo|duelgo|gostop|dxgostop|whatu|sambong|doublego/g;
var casual = /tetris|diff|cross|solcard|nomo/g;
var puzzle = /mahjong|reverse|solitaire|same|bby|bingo|hexadlx|mine|bbuster|panpan/g;
var board = /janggi|omok|yutnori2|chess|onecard|bridge|sinyutnori/g;
var sports = /billiard4|billiard3|billiardj|pocket8|pocket9|pocketc8|billiards/g;


function getUnitString(sGameid) {
	var unitid = "";
	var gm = "";
	if ( location.href.indexOf("game1.hangame.com") >= 0 || location.href.indexOf("game3.hangame.com") >= 0) {
		gm = (sGameid==null) ? getStrCookie("gameid") : sGameid;
	}	
	if(gm.search(gostop) >= 0) {
		unitid = "338A";
	}else if(gm.search(poker) >= 0) {	
		unitid = "339A";	
	}else if(gm.search(casual) >= 0) {
		unitid = "340A";	
	}else if(gm.search(puzzle) >= 0) {
		unitid = "341A";	
	}else if(gm.search(board) >= 0) {
		unitid = "342A";	
	}else if(gm.search(sports) >= 0) {
		unitid = "343A";	
	}
		
	return unitid ;
}


/* ad 페이지 url 을 리턴 */
function getAdvurl(sAdunit, sGameid, userid)
{
	var sTarget = getTargetString();
	//alert(sTarget);
	//var sKor = "http://hangamead.naver.com/ad?loc=hangame." + sAdcase + sTarget + "&refresh=5";
	//수정 전 예 : http://hangamead.naver.com/ad?loc=hangame.148600ss&showme=html&gm=duelgo&ag=27&sx=m
	//수정 후 예: http://ad.hangame.com/adshow?unit=338A&ag=27&sx=m&hgid=shawm
	
	//?t1=[임의발행된 유저 식별자 optional]&t2=[남자면 1 여자면 2][나이]
	//수정 후 예: http://ad.hangame.com/adshow?unit=338A&t2=130
	
				
	var sKor = "http://ad.hangame.com/adshow?unit=" + sAdunit + sTarget;
 	
	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 s1 = sPassword.search(/[A-Za-z]/);
	var s2 = sPassword.search(/[0-9]/);
	
	if (s1 == -1 || s2 == -1) {
		return true;
	} else {
		return false;
	}
}

/*
 * 숫자, 영문, 한글 이외의 문자이면 true 리턴함
 * @deprecate 문자열의 숫자, 영문, 한글 체크에 패턴 매칭을 이용하게 되면서 사용하지 않음
 */
function errChar(ch) {
	var errPos = ch.search(/^[^0-9a-zA-Z\uAC00-\uD7AF\u1100-\u11FF\u3130-\u318F]$/);
	if ( errPos != -1 ) {
		return true;
	} else {
		return false;
	}
}

/*
 * 스트링에 숫자, 영문, 한글 이외의 문자가 들어있으면 true 리턴함
 * @deprecate HG의 문자열 체크 함수로 대체
 */
function errStandard(sChk) {
	return HG.verifyStandardString(sChk);
}


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("game.daum.net") >= 0 ) {
		return "daum.net";
	} else if ( s.indexOf("hanjamaru.com") >= 0 ) {
		return "hanjamaru.com";
	} else if ( s.indexOf("admin.nhncorp.com") >= 0 ) {
		return "admin.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();

/*
 * @deprecated
 * 
 */
//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();

/**
 * @deprecated
 * array의 기본 push 메소드 이용으로 대체를 권고 
 */
function push(array, arg){
	array.push(arg);
}

/**
 * @deprecated
 * array의 기본 pop 메소드 이용으로 대체를 권고  
 */
function pop(array){
	return array.pop();
}

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
//
//''''''''''''''''''''''''''''''''''''''''''''


/**
 * @deprecated
 * fitpopupsize(objId) 로 대체 가능
 */
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();
}


/**
 * @deprecated
 * fitPopupSize 내부 로직으로 직접 호출하여 사용하지 않을 것을 권고함
 */
function fitPopupSize_calcSize( arg1, arg2, arg3 ) {
	var toWidth = null;
	var toHeight = null;
	var objOut = null;
	var positionRequired = true;

	var typeArg1 = typeof(arg1);
	var typeArg2 = typeof(arg2);
	var typeArg3 = typeof(arg3);
	
	if( typeArg1 == "undefined" || typeArg1 == "boolean" ) {
		objOut = document.getElementById("page_content");
		
		if( typeArg1 == "boolean" ) {
			positionRequired = arg1;
		}
	}
	if( typeArg1 == "string" ) {
		objOut = document.getElementById(arg1);
		if( objOut == null ) { return null; }
				
		if( typeArg2 == "boolean" ) {
			positionRequired = arg2;
		}
	}

	if( typeArg1 == "object" ) {
		objOut = arg1;
				
		if( typeArg2 == "boolean" ) {
			positionRequired = arg2;
		}
	}
	
	if( objOut != null ) {
		var objParent = objOut.parentNode;
		var getStyle = function(obj) {
			if( obj.currentStyle ) {
				return obj.currentStyle;
			} else if( document.defaultView.getComputedStyle ) {
				return document.defaultView.getComputedStyle(obj, null);
			}
		}

		if( objParent != null && objParent.tagName == "BODY" && getStyle(objOut).position == "absolute" ) {
			try {
				var bodyPaddingTop = 0; var outerPaddingTop = 0;
				var bodyPaddingBottom = 0; var outerPaddingBottom = 0;
				var bodyPaddingLeft = 0; var outerPaddingLeft = 0;
				var bodyPaddingRight = 0; var outerPaddingRight = 0;
				
				if( document.body.currentStyle ) {
					var bodyCurrentStyle = document.body.currentStyle;
					bodyPaddingTop = parseInt(bodyCurrentStyle.paddingTop);
					bodyPaddingBottom = parseInt(bodyCurrentStyle.paddingBottom);
					bodyPaddingLeft = parseInt(bodyCurrentStyle.paddingLeft);
					bodyPaddingRight = parseInt(bodyCurrentStyle.paddingRight);
					
					var outerCurrentStyle = objOut.currentStyle;
					outerPaddingTop = parseInt(outerCurrentStyle.paddingTop);
					outerPaddingBottom = parseInt(outerCurrentStyle.paddingBottom);
					outerPaddingLeft = parseInt(outerCurrentStyle.paddingLeft);
					outerPaddingRight = parseInt(outerCurrentStyle.paddingRight);
					
				} else if( document.defaultView.getComputedStyle ) {
					var objBodyStyle = document.defaultView.getComputedStyle(document.body, null);
					bodyPaddingTop = parseInt(objBodyStyle.getPropertyValue("padding-top"));
					bodyPaddingBottom = parseInt(objBodyStyle.getPropertyValue("padding-bottom"));
					bodyPaddingLeft = parseInt(objBodyStyle.getPropertyValue("padding-left"));
					bodyPaddingRight = parseInt(objBodyStyle.getPropertyValue("padding-right"));
					
					var outerCurrentStyle = document.defaultView.getComputedStyle(objOut, null);
					outerPaddingTop = parseInt(outerCurrentStyle.getPropertyValue("padding-top"));
					outerPaddingBottom = parseInt(outerCurrentStyle.getPropertyValue("padding-bottom"));
					outerPaddingLeft = parseInt(outerCurrentStyle.getPropertyValue("padding-left"));
					outerPaddingRight = parseInt(outerCurrentStyle.getPropertyValue("padding-right"));
				}
				
				var adjustHeight = bodyPaddingTop + bodyPaddingBottom;
				var adjustWidth = bodyPaddingLeft + bodyPaddingRight;
				
				var oWidth = objOut.clientWidth;
				var oHeight = objOut.clientHeight;
				
				// objOut.style.height = oHeight + adjustHeight;				
				objOut.style.paddingTop = outerPaddingTop + bodyPaddingTop;
				objOut.style.paddingBottom = outerPaddingBottom + bodyPaddingBottom;

				// objOut.style.width = oWidth + adjustWidth;
				objOut.style.paddingLeft = outerPaddingLeft + bodyPaddingLeft;
				objOut.style.paddingRight = outerPaddingRight + bodyPaddingRight;
			} catch(e) {
				// do nothing
				// alert( e.message );
			}
		}
		toWidth = objOut.clientWidth;
		toHeight = objOut.clientHeight;
	}

	if( typeArg1 == "number" && typeof(arg2) == "number" ) {
		toWidth = arg1;
		toHeight = arg2;
		
		if( typeArg3 == "boolean" ) {
			positionRequired = arg3;
		}
	}

	//	if( toWidth == null && toHeight == null ) { return {}; }
	
	if (toWidth > screen.availWidth) toWidth = screen.availWidth;
	if (toHeight > screen.availHeight) toHeight = screen.availHeight;

	return { "width":toWidth, "height":toHeight, "positionRequired":positionRequired };
}

/**
 * 팝업 사이즈 조절
 * @deprecated HG 네임스페이스에 해당 메소드 구현, 대체함  
 * @example
fitPopupSize( [doMove] );                  // ID가 'page_content'인 object의 clientWidth, clientHeight 값에 따라 사이즈 조절
fitPopupSize( object, [doMove] );          // 주어진 object의 clientWidth, clientHeight값에 따라 사이즈 조절
fitPopupSize( "pageOuter", [doMove] );     // ID가 'pageOuter'인 object의 clientWidth, clientHeight 값에 따라 사이즈 조절
fitPopupSize( 300, 400, [doMove] );        // 팝업 크기를 300 x 400으로 조절
 */
function fitPopupSize( arg1, arg2, arg3 ) {
	HG.fitPopupSize(arg1, arg2, arg3);
}

/**
 * @deprecated
 * HG.fitPopupSize 함수 대체
 */
function fitPopupSize_resize( toWidth, toHeight ) {
	HG.fitPopupSize(toWidth, toHeight, false);
}


/**
 * @deprecated 
 * HG.fitPopupSizeEx 함수 대체
 */
function fitPopupSizeEx() {
	HG.fitPopupSizeEx();
}


/**
 * @deprecated 
 * clickPageCount(section,version,icode,ccode,url) 정의에 의해 실제 사용되지 않음
 */
function clickPageCount(section) {
    //clickframe.location.href='http://click.hangame.com/click/counter.nhn?version=4.0d&section=' + section + '&item=0000';
	var a = 0;
}


/**
 * @deprecated 
 * clickPageCount(section,version,icode,ccode,url) 정의에 의해 실제 사용되지 않음
 */
function clickPageCount(section,version) {
	if(version==null||version=='') version = "4.0d";
    //clickframe.location.href='http://click.hangame.com/click/counter.nhn?version=' + version + '&section=' + section + '&item=0000';
	var a = 0;
}

function clickPageCount(section,version,icode,ccode,url) {
	var ndsURL = "";
	if(version==null||version=='') version = "4.0d";
	if(icode!=null&&icode!='') ndsURL = "/common/ndsCount.nhn?destinationURL=/i:" + icode + "/c:" + ccode + "?";
	if(url==null||url=='') return;//ndsURL += "http://click.hangame.com/click/counter.nhn?version=" + version + "&section=" + section + "&item=0000";
	else ndsURL += url;
	
	//alert(ndsURL);
	clickframe.location.href = ndsURL;
	
	var a = 0;
}
//author : 손정민
//createdt : 20061024
//배너등의 NDS 클릭률을 잡기 위한 함수
//arg : NDS-클릭 집계로 넘겨줄 파라미터값: id 발급후 생성되는 URL값
function setNdsClickTag(arg) {
	// arg에 &값이 들어올수도 있음(URL인코딩처리 필)	
	arg = escape(arg);
	
	if (typeof(__ndsFrame)=="undefined") {
		var s = "<iframe name='__ndsIframe' width=0 height=0 frameborder=0 style='display:none'></iframe>";
		__ndsFrame = "set";
		document.write (s);
	}
	
	__ndsLoadSub(arg);	
}
//author : 손정민
//createdt : 20061024
//setNdsClickTag에서 호출하는 실질적으로 NDS call하는 함수
//arg : NDS 로 넘겨줄 파라미터값, 이 값으로 NDS등록하면 됨
function __ndsLoadSub(arg) {
	if ( document.all.__ndsIframe && typeof(document.all.__ndsIframe)=="object" ) {
		document.all.__ndsIframe.src = "/common/ndsCount.nhn?destinationURL=" + arg ;
	} else {
		setTimeout("__ndsLoadSub('"+ arg + "')",500);	
	}
}
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() {
	var ndsIframe = getNdsIframe();
	if (ndsIframe) {
		ndsIframe.src = "http://lcs.hangame.com/u{" + document.URL + "}";
	} else {
		setTimeout("__ndsLoadMain()",500);	
	}
}

function getNdsIframe() {
	var frames = document.getElementsByName('__ndsIframe');
	if (frames && frames.length > 0 && typeof(frames[0]) == 'object') {
		return frames[0];
	}
	return null;
}


/**
 * window xp sp2 인지 판별
 *
 * @deprecated 
 * HG 네임스페이스에 해당 메소드 구현, 대체함  
 */
function isXPSP2(){
	return HG.isXPSP2();      
}

/**
 * 같은 XP SP2 버전이라도 특정 언어 내지는 특정 패치가 적용된 XP에서 userAgent 값에서 MSIE, SV1 문자열의 위치가 다른 경우가 있어서,
 * 위의 isXPSP2() 함수를 그대로 사용할 수가 없는 경우가 있다.
 * 보다 일반적인 상황에서 쓸 수 있도록 추가된 함수. (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwxp/html/xpsp2web.asp)
 *
 * @deprecated 
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function isXPSP2General() {
	return HG.isXPSP2();      
}


/**
 * window xp 인지 판별
 *
 * @deprecated 
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function isXP(){
	return HG.isXP();
}


/**
 * 로그인 여부 조사 (2004.11.25 신규 쿠키)
 *
 * @deprecated 
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function isHangameLogined() {
	return HG.isLoggedin();
}


///////////////////////////////
// 팝업 쿠키 관련 (2004.11.24
///////////////////////////////

/**
 * 팝업 쿠키 로직 내부적으로 사용되는 상수들
 *
 * @deprecated 
 * 글로벌 스페이스에서 제거되어야 함
 * 외부에서 사용되더라도 연계성은 없음. 그러한 경우에는 따로 상수를 정의하는 것이 맞을 것 같음
 */
var common_POPUPCOOKIENAMEGLOBAL = "POPUP";
var common_POPUPCOOKIENAMEEVENT = "EV_POPUP";
var common_POPUPCOOKIENAMEDOMAIN = "DM_POPUP";
var common_POPUPCOOKIEDELIM = "_";
var common_POPUPCOOKIESUBDELIM = "+";


/**
 * 쿠키 내용의 아이디에서 딜리미터로 사용되는 특수문자를 제거하는 메소드
 *
 * @deprecated
 * 팝업 쿠키 로직 내부적으로 사용되는 메소드로 외부에서 사용되더라도 연계성은 없음. 
 * 그러한 경우에는 따로 해당 로직을 구현하는 것이 맞는 것 같음
 */
function common_escapePCID(id) {
	return id.replace(/_/g,"").replace(/\+/g,"");
}


/**
 * 서비스 도메인별 팝업 설정을 지원하기 위해 만들어진 쿠키 설정 함수
 * 기존 함수들을 참고함.
 * DM_POPUP=name1+expiredate1_name2+expiredate2_name3+expiredate3...;
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_setDomainPopup(id, expireDays) {
	HG.setDomainPopup(id, expireDays);
}


/**
 * 서비스 도메인별 팝업 설정을 지원하기 위해 만들어진 쿠키 확인 함수
 * 기존 함수들을 참고함.
 * return true if a cookie named "id" exists and is not expired
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_existDomainPopup(id) {
	return HG.existDomainPopup(id);
}


/**
 * set popup cookie
 * EV_POPUP=name1+expiredate1_name2+expiredate2_name3+expiredate3...;
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_setEventPopup(id, expireDays) {
	HG.setEventPopup(id, expireDays);
}


/*
 * check popup cookie
 * return true if a cookie named "id" exists and is not expired
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_existEventPopup(id) {
	return HG.existDomainPopup(id);
}


/**
 * set popup cookie
 * POPUP=name1+expiredate1_name2+expiredate2_name3+expiredate3...;
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_setPopupCookie(id, expireDays) {
	HG.setPopupCookie(id, expireDays);
}

/**
 * check popup cookie
 * return true if a cookie named "id" exists and is not expired
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_existPopupCookie(id) {
	return HG.existPopupCookie(id);
}


/**
 * return YYYYMMDDHHmm
 *
 * @deprecated
 * 팝업 쿠키 로직 내부적으로 사용되는 메소드, 쿠키 로직 내부적으로는 DateTime의 포맷팅 기능의 사용으로 대체됨
 * 해당 기능을 사용하는 부분도 DateTime의 포맷팅 기능을 사용하도록 권고
 */
function common_getYYYYMMDDHHmm(d) {
	return C.DateTime.createFromDate(d).toFormattedString('yyyyMMddhhmm');
}


/**
 * "1" -> "01"
 *
 * @deprecated
 * 팝업 쿠키 로직 내부적으로 사용되는 메소드, 쿠키 로직 내부적으로는 STR의 포맷팅 기능의 사용으로 대체됨
 * 해당 기능을 사용하는 부분도 STR의 포맷팅 기능을 사용하도록 권고
 */
function common_makeTwoDigits(val) {
	return STR.format("%02d", value);
}


/**
 * YYYYMMDDHHmm -> Date
 *
 * @deprecated
 * 팝업 쿠키 로직 내부적으로 사용되는 메소드, 쿠키 로직 내부적으로는 DateTime의 포맷팅 기능의 사용으로 대체됨
 * 해당 기능을 사용하는 부분도 DateTime의 포맷팅 기능을 사용하도록 권고
 */
function common_makeDateFromString(str) {
	return C.DateTime.createFromFormattedString('yyyyMMddhhmm', str).getDateObject();
}


/**
 * return new common_popupCookieArrayItem from cookie string
 *
 * @deprecated
 * 팝업 쿠키 로직 내부적으로 사용되는 메소드, 외부에서 사용하지 않을 것을 권고함.
 */
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;
}




//////////////////////
// delete popup cookie
//////////////////////
/*
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_delPopupCookie() {
	HG.resetPopupCookie();
}


/*
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_delEventPopup() {
	HG.resetEventPopup();
}



//////////////////////////
// array cookie
//////////////////////////

/**
 * set array cookie
 * COOKIENAME=name1+value1+expiredate1_name2+value2+expiredate2_name3+value3+expiredate3...;
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_setArrayCookie(cookieName, id, value, expireDays, domain) {
	HG.setArrayCookie(cookieName, id, value, expireDays, domain);
}


/**
 * get array cookie
 *
 * @deprecated
 * HG 네임스페이스에 해당 메소드 구현, 대체함 
 */
function common_getArrayCookie(cookieName, id, domain) {
	return HG.getArrayCookie(id, cookieName, domain);
}




function viewActiveObject(html){
	document.write(html);
}
/* 캐쥬얼 및 고포류 게임페이지 AD*/
function setAdPage(adCode,adGameid,adUserid)	{
  	var adUrl=getAdvurl(adCode,adGameid,adUserid);
  	_writeGameIframeAd(adUrl,250,100);
}
/* 캐쥬얼 및 고포류 게임페이지 광고 iframe Ad 태그 */
function _writeGameIframeAd(adUrl, width, height) {
	var s="<iframe src='" + adUrl + "' width='" + width + "' height='" + height + "' frameborder=0 scrolling=no marginheight=0 marginwidth=0></iframe>";
	document.write(s);
}

/* 내부광고용 Iframe Ad 태그*/
function _writeIframeAd(invenid, width, height) {
	document.write("<iframe src='http://ad.nbms.hangame.com/adshow?unit=" + invenid + "' width='" + width + "' height='" + height + "' frameborder=0 scrolling=no marginheight=0 marginwidth=0></iframe>");
}
/* 내부광고용 Iframe Ad 태그 (2010.01.21 ver. NBMS2)*/
function _writeIframeAd2(invenid, width, height) {
	document.write("<iframe src='http://ad2.nbms.hangame.com/adshow?slot=" + invenid + "' width='" + width + "' height='" + height + "' frameborder=0 scrolling=no marginheight=0 marginwidth=0></iframe>");
}


/**
 * @deprecated 
 * eventpark의 spc방 팝업, 스키드 러시의 런처 페이지에서만 사용.
 * 공통 스크립트로 적합하지는 않은 것 같음. 링크를 사용하거나 직접 윈도우 오픈 스크립트를 이용하는 것이 더 좋을 것 같음.
 * 개발, 알파, 베타, 리얼 등의 분리가 힘들다는 문제 점 또한 가지고 있음. 
 */
function pcbangSearch() {
	window.open('http://pcbang.hangame.com/intro.nhn', '_pcbang_search', '');
}

var __kiwi_uganda_dooli_keroro_title = (typeof(__page_specific_title)=='string'&&__page_specific_title.trim()!='')? __page_specific_title:"한게임 - 즐거운 쉼표, Go 한게임!";
document.title = __kiwi_uganda_dooli_keroro_title;



// 미디어채널링 관련 추가
function isMediaChannel() { 
	var idi_cd = getJsCookie(JS_IDI_CD);
	if (idi_cd != null && idi_cd != "" && idi_cd != "HG") {
		var nexturl = document.URL;
		openWin("/common/channeling/restrict.nhn?m=popup&nexturl="+nexturl, "restrictpopup", 490, 360);
		return true;
	}
	return false;
}


function mediaChannelYN() {
	var idi_cd = getJsCookie(JS_IDI_CD);
	if (idi_cd != null && idi_cd != "" && idi_cd != "HG") {
		return true;
	}
	return false;
}

function goPcCheck(gameid) {
	var expectedWidth = 740;
	var expectedHeight = 400;
	var WindowLeft = (screen.availWidth - expectedWidth)/2;
	var WindowTop = (screen.availHeight - expectedHeight)/2;
	openWin("/common/autospeccheck/check.nhn?gameId="+gameid+"&as_gameId="+gameid+"&action=/common/autospeccheck/check.nhn&nextm=view", "pccheck", expectedWidth, expectedHeight);
}

//안정화지표 표준화	
function callSSIG(gameid, step, memberid) {
	HG.callSSIG(gameid, step, memberid);
}

function callSSIGforGP(gameid, step, memberid) {
	HG.callSSIGforGP(gameid, step, memberid);
}

function callSSIGandPclog(gameid, step, memberid) {
	HG.callSSIGandPclog(gameid, step, memberid);
}
