
// ·¹ÀÌ¾î ÆË¾÷
document.write('<script type="text/javascript" src="http://static.mgame.com/common_js/mhtml.js"></script>');
// ºÒ·® ´Ü¾î
document.write('<script type="text/javascript" src="http://static.mgame.com/common_js/bad_word.js"></script>');
// getCookie ÇÔ¼ö
document.write('<script type="text/javascript" src="http://static.mgame.com/common_js/cookie_hash.js"></script>');
// ¸®»çÀÌÁî ÇÔ¼ö
document.write('<script type="text/javascript" src="http://static.mgame.com/common_js/func_library.js"></script>');

var mgamePopupObject;	// ÆË¾÷ ¿ÀºêÁ§Æ®¸í
var thisUri				=	location.href.replace("http://"+ location.host,"").split("/");
var thisHost			=	location.host.split(".");
var thisDomain			=	thisHost[1];

// mgame.comÀº www.mgame.comÀ¸·Î ÀÌµ¿
if(location.host == "mgame.com") location.href	=	"http://www.mgame.com/";

// µµ¸ÞÀÎ ¼ÂÆÃ

if(location.host.indexOf("daum.net") > 0){
	document.domain		=	"daum.net";
} else if(location.host.indexOf("hangame.com") > 0){
	document.domain		=	"hangame.com";
}else{
	document.domain		=	location.host.substr(location.host.indexOf(".")+1);
}


// RPGÄÁÅÙÃ÷´Â iframe¸¸ Çã¿ë
/*
if(thisHost[0].substr(0,2) != "mg" && thisUri[1] == "common_rpgcontents" && window == top) {
	location.href		=	"http://"+ location.host;
}
*/

//###################################################################
// ·Î±×ÀÎ Æû Ã¼Å© - Ã¤³Î¸µ Áö¿ø
// ¿¹) <form method="post" onsubmit="return mgameLoginCheck(this)">
//###################################################################
function mgameLoginCheck(f) {
	if(mgameUserCheck(true)) return;

	f.target	=	"_top";

	if(thisDomain == "buddybuddy") {

		if (!f.ID.value.trim()) {
			error("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			return false;
		}

		if (!f.PWD.value.trim()) {
			error("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			return false;
		}
		
		f.action		=	"https://user.buddybuddy.co.kr/Login/Login.asp";
	} else if(thisDomain == "sbs") {
		if (!f.id.value.trim()) {
			error("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			return false;
		}

		if (!f.passwd.value.trim()) {
			error("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			return false;
		}
		
		f.action		=	"https://sbscert.sbs.co.kr/login/Login/verifyed_login.jsp?loginType=1&national_nm=sbntOd0xfFCzQ&Login_ReturnURL="+ top.location.href;		
	} else {
		if("YES" == getCookie_key("MGAME_KEY_DEFENDER")) {
			mkdplus_copy_to_form(document.f);
		}
	
		if(!f.mgid_enc.value.trim()) {
			error("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			return false;
		}
	
		if(!f.mgpwd_enc.value.trim()) {
			error("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
			return false;
		}
		
		f.action		=	"https://sign.mgame.com/login/login_action_pub_type_b.mgx?tu="+ top.location.href +"&ru="+ top.location.href;
	}
	
	return true;
}


//###################################################################
// ·Î±×ÀÎ ¿©ºÎ Ã¼Å© - Ã¼Çè¾ÆÀÌµð ÆË¾÷ Áö¿ø/ Ã¤³Î¸µ Áö¿ø
// optionÀÌ trueÀÏ °æ¿ì ¸Þ½ÃÁö ¶ç¿ìÁö ¾ÊÀ½
// ¿¹) if(!mgameUserCheck()) return;
// +++++++++++++++++++++++++++
// returnURL ÆÄ¶ó¹ÌÅÍ Ãß°¡ 2009-09-10 daffodil
// ¿¥°ÔÀÓÀº ·Î±×ÀÎ Layer¸¦ ¶ç¿öÁÖ°í, Ã¤³Î¸µÀº ·Î±×ÀÎÆäÀÌÁö·Î ÀüÈ¯ ÇÏ°í ½ÍÀ¸¸é
// ¾Æ·¡¿¹½Ã·Î ÆÄ¶ó¹ÌÅÍ¸¦ ³Ñ°ÜÁØ´Ù
// ¿¹) if(!mgameUserCheck('loginpage','¸®ÅÏ¹Þ°í½ÍÀºURL')) return;
// ++++++++++++++++++++++++++++
//###################################################################

function simpleUserCheck(){
	//¿¥°ÔÀÓ Ã¤³Î¸µ µ¿½Ã Ã¼Å©
	if(getCookie("MGAME") || getCookie("mgx")){
		return true;
	}
}

function mgameUserCheck(opt,returnURL) {	
	
	var currentDomain = top.location.host.substr(top.location.host.indexOf(".")+1);
	var	rurl = "http://"+top.location.host;
	if(!returnURL){
		returnURL = rurl;
	}

	//¿¥°ÔÀÓ
	if(currentDomain == "mgame.com") {
		// ·Î±×ÀÎ ¿©ºÎ
		if(!getCookie("MGAME")) {
			if(opt =="loginpage"){

				Mgame_CommonLayerOpen_trans('http://www.mgame.com/member/login_form_pop.mgame?tu='+returnURL+'&ru='+returnURL, 500, 420, true);
			}else if(!opt){
				error();
			}
			return false;
		}
		
		// È¸¿øÅ¸ÀÔ ¿©ºÎ
		//if(getCookie_2DIM("MGAME","TYPE") != 1000 && getCookie_2DIM("MGAME","TYPE") != 9999 && getCookie_2DIM("MGAME","TYPE") != 7777) {
		if(getCookie_2DIM("MGAME","TYPE") != 1000 && getCookie_2DIM("MGAME","TYPE") != 9999) {
			if(top.location.host == "aw.mgame.com"){
				return true;
			}

			if(!opt) GUEST_POPUP();
			return false;
		}

	//³×ÀÌÆ® (gameon.nate.com)
	}else if(currentDomain == "gameon.nate.com"){	
		if(getCookie("CFN")){	
			if(!getCookie("mgx")){
				gameName = top.location.host.substr(0,top.location.host.indexOf("."));

				switch(gameName){
					case "baduk":		sid = "52";		break;
					case "janggi":		sid = "53";		break;
					case "omok":		sid = "54";		break;
					case "wffm":		sid = "55";		break;
					case "operation7":	sid = "56";		break;
					case "holic2":		sid = "57";		break;
					case "yulgang":		sid = "58";		break;
					case "hon":			sid = "59";		break;
				}
				//error("ÀÌ¿ëµ¿ÀÇ¸¦ ÇØÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
				window.open('http://gameon.nate.com/user_agree_check.jsp?company_id=7&sid='+sid+'&action_type=3&rurl='+rurl,'user_agree','width=604, height=425');
				return false;
			}

		}else{	//·Î±×ÀÎ
			if(opt == "loginpage"){
				top.location.href = 'http://nateonweb.nate.com/login/loginfull.php?rurl='+returnURL
			}else if(!opt){
				error();
			}
			return false;
		}

	//´ÙÀ½ (game.daum.net)
	}else if(currentDomain == "game.daum.net" || currentDomain == "mgame.game.daum.net"){	

		if(getCookie("PROF")){
			if(!getCookie("mgx")){
				gameName = top.location.host.substr(0,top.location.host.indexOf("."));

				switch(gameName){
					case "wffm":		svcId = "339";		break;
					case "yulgang":		svcId = "330";		break;
					case "js":			svcId = "402";		break;
					case "hero":			svcId = "2343";		break;
				}

				error("¿¥°ÔÀÓ ÀÌ¿ë¾à°ü¿¡ µ¿ÀÇ ÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
				if(gameName == "js"){
					top.location.href="https://user.daum.net/privagree/privinfoagree.daum?svcId="+svcId+"&yyyymmdd=20090728&codeName="+gameName+"&&returnUrl=http://sign.mgame.game.daum.net/mgame_agree.mgame?codeName="+gameName;
				} else if(gameName == "hero"){
					top.location.href="https://user.daum.net/privagree/privinfoagree.daum?svcId="+svcId+"&yyyymmdd=20100530&codeName="+gameName+"&&returnUrl=http://sign.mgame.game.daum.net/mgame_agree.mgame?codeName="+gameName;
				}else{
					top.location.href="https://user.daum.net/privagree/privinfoagree.daum?svcId="+svcId+"&codeName="+gameName+"&&returnUrl=http://sign.mgame.game.daum.net/mgame_agree.mgame?codeName="+gameName;
				}
				return false;
			}
		}else{	//·Î±×ÀÎ
			if(opt == "loginpage"){
				top.location.href = 'http://www.daum.net/Mail-bin/login.html?url='+returnURL
			}else if(!opt){
				error();
			}
			return false;
		}

	//ÇÑ°ÔÀÓ (hangame.com)
	}else if(currentDomain == "hangame.com" || currentDomain == "mgame.hangame.com"){
		if(getCookie_nhn("HG_CP_LOGIN")){
			if(!getCookie_nhn("mgx")){

				gameName = top.location.host.substr(0,top.location.host.indexOf("."));

				error("ÀÌ¿ë¾à°ü¿¡ µ¿ÀÇ ÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
				
				top.location.href="https://members.hangame.com/myinfo/thirdparty.nhn?gameid=K_HON&period=30&next=http://sign.mgame.hangame.com/agreement_nhn.mgame?codeName=hon&homeurl=http://www.hangame.com";
				return false;
			}
		}else{

			// ÇÑ°ÔÀÓ alpha- Å×¼·À¸·Î Á¢±Ù½Ã ·Î±×ÀÎ Ã³¸® ( 100513 È²Àç¿ë Ãß°¡)
			var alphaval = "";
			if(top.location.host.substr(0,top.location.host.indexOf("-"))=="alpha") {
				alphaval = "alpha-";
			}

			if(opt == "loginpage"){
				top.location.href = 'http://'+alphaval+'id.hangame.com/wlogin.nhn?popup=false&adult=false&nxtURL='+returnURL
			}else if(!opt){
				error();
			}
			return false;
		}
	
	//Åõ´Ï·£µå (tooniland.com)
	} else if(currentDomain == "tooniland.com"){
		if(getCookie('xUserId')){
			if(!getCookie('mgx')){
				error("ÀÌ¿ë¾à°ü¿¡ µ¿ÀÇ ÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
				top.location.href='http://mgsign.tooniland.com/agreement_tooniland.mgame';
				return false;
			}			
		} else {
			/*
			if(opt == "loginpage" && returnURL != null){
				top.location.href = ''+returnURL
			}else if(!opt){
				error();
			}
			*/
			return false;
		}

	//¹öµð ¹öµð	(buddybuddy.co.kr)
	}else{		

		if(getCookie("UINFO")){		
			if(!getCookie("mgx")){
				if(top.location.host == "js.buddybuddy.co.kr"){
					top.location.href = "http://"+ top.location.host +"/common_lib/channel/buddybuddy/login_process.mgame?codeName=js&returnURL=http://"+ top.location.host;
				}else if(top.location.host == "aw.buddybuddy.co.kr"){
					top.location.href = "http://"+ top.location.host +"/common_lib/channel/buddybuddy/login_process.mgame?codeName=aw&returnURL=http://"+ top.location.host;
				}else if(top.location.host == "holic2.buddybuddy.co.kr"){
					top.location.href = "http://"+ top.location.host +"/common_lib/channel/buddybuddy/login_process.mgame?codeName=holic2&returnURL=http://"+ top.location.host;
				}else if(top.location.host == "sachun.buddybuddy.co.kr"){
					top.location.href = "http://"+ top.location.host +"/common_lib/channel/buddybuddy/login_process.mgame?codeName=sachun&returnURL=http://"+ top.location.host;
				}else{
					top.location.href =	"http://"+ top.location.host +"/member/login_process.mgame?returnURL=http://"+ top.location.host;
				}
				return false;
			}
		}else{ //·Î±×ÀÎ
			if(opt == "loginpage"){
				top.location.href = 'http://game.buddybuddy.co.kr/Member/Login.aspx?URL='+returnURL
			}else if(!opt){
				error();
			}
			return false;
		}
	}
	return true;
}


//###################################################################
// ·Î±×¾Æ¿ô - Ã¤³Î¸µ Áö¿ø
// ¿¹) <a href="javascript:mgameLogout()">·Î±×¾Æ¿ô</a>
//###################################################################
function mgameLogout() {
	if(thisDomain == "buddybuddy") {
		setCookie("MGCPAGREE",null,-1);
		top.location.href	=	"http://user.buddybuddy.co.kr/Login/LogOut.asp?URL=http://"+ top.location.host;
	}
	else if(thisDomain == "game.daum") {
		setCookie("MGCPAGREE",null,-1);
		top.location.href	=	"http://go.daum.net/bin/minidaum.cgi?category=game&logout_url=http://"+ top.location.host;
	}
	else if(thisDomain == "sbs") {
		top.go_logout();
	} else {
		top.logoutforirc();
	}
}


//###################################################################
// ¾ÆÀÌµð/ÆÐ½º¿öµå Ã£±â - Ã¤³Î¸µ Áö¿ø
// ¿¹) <a href="javascript:mgameFindAccount()">¾ÆÀÌµð/ÆÐ½º¿öµå Ã£±â</a>
//###################################################################
function mgameFindAccount() {
	if(thisDomain == "buddybuddy") {
		mgamePopup("http://user.buddybuddy.co.kr/idsearch/IdPwSearchGameForm.asp?from=game&CSSURL=http://game.buddybuddy.co.kr/Common/Css/game_member.css",500,500);
	} else if(thisDomain == "sbs") {
		top.location.href	=	"https://sbscert.sbs.co.kr/login/passwd/findpwd_form.jsp";
	} else {
		mgameLayerPopup("http://sign.mgame.com/t_user_search/",(isIE() ? 400 : 500),350);
	}
}


//###################################################################
// È¸¿ø°¡ÀÔ - Ã¤³Î¸µ Áö¿ø
// ¿¹) <a href="javascript:mgameNewAccount()">È¸¿ø°¡ÀÔ</a>
//###################################################################
function mgameNewAccount() {
	var hostname ="";
	if(thisDomain == "buddybuddy") {
		if(thisHost[0]=="js"){
			hostname = "justishow";
		}else{
			hostname = thisHost[0];
		}
		pageUrl		=	"http://game.buddybuddy.co.kr/Member/Join.aspx?GAMEPATH="+hostname;
	} else if(thisDomain == "sbs") {
		pageUrl		=	"https://sbscert.sbs.co.kr/login/member/join/agree.jsp";
	} else {
		pageUrl		=	"http://sign.mgame.com/_t_regist/regist_F_0000_PRE.mgx?toGOgame=http://"+ location.host;
	}
	
	window.open(pageUrl);
}


//###################################################################
// ÃæÀü 
// ¿¹) <a href="javascript:mgameCashCharge()">ÃæÀü</a>
//###################################################################
function mgameCashCharge() {
	pageUrl		=	"https://bill.mgame.com/mbank/default.asp";
	window.open(pageUrl, 'winMCashCharge', 'width=600,height=560,left=10,top=10');
}


//###################################################################
// °ÔÀÓ ½ÃÀÛ
// ·Î±×ÀÎ ¿©ºÎ Ã¼Å© ÈÄ ·±ÃÄ ½ÇÇà
// ¿¹) <a href="javascript:mgameStart('popstage')">°ÔÀÓ½ÇÇà</a>
//###################################################################
function mgameStart(game) {
	if(!mgameUserCheck()) return;

	try {
		launch_game(game);
	} catch(e) {
		error("°ÔÀÓ ½ÇÇà¿¡ ÇÊ¿äÇÑ ÇÔ¼ö°¡ ¾ø½À´Ï´Ù.");
	}
}


//###################################################################
//ÀÌ¹ÌÁö ¸®»çÀÌÁî
//size°ª º¸´Ù width°ªÀÌ Å¬ °æ¿ì size°ªÀ¸·Î ¸®»çÀÌÂ¡
//¿¹) <img src="a.jpg" alt="a" onload="imageResize(this,500)" />
//###################################################################
function imageResize(obj,size) {
	if(!size) {
		obj.width		=	"100%";
	} else {
		if(w=eval(obj.width) > size) obj.width = size;
	}
}


//###################################################################
// ¹ÙÀÌÆ® ¼ö Á¦ÇÑ
// input, textarea¿¡ limit°ª ¸¸Å­¸¸ ÀÔ·Â°¡´É
// div°ªÀÌ ÀÖÀ» °æ¿ì ÇØ´ç id°ª¿¡ ÇöÀç ¹ÙÀÌÆ® Ãâ·Â
// ¿¹) <textarea onkeyup="messageLimit(this,100)"></textarea>
// ¿¹)<input type="text" onkeyup="messageLimit(this,50,'byte2')">(<span id="byte2">0/50byte</span>)
//###################################################################
function messageLimit(obj,limit,div) {
	var nByte			=	0;

	for(var i=0;i<obj.value.length;i++) { 
		nByte			+=	(obj.value.charCodeAt(i)>128) ? 2 : 1;
		
		if(nByte >= limit) break;			
	}

	if(nByte >= limit) { 
		error(limit +" Bytes ±îÁö¸¸ ÀÔ·ÂÀÌ °¡´ÉÇÕ´Ï´Ù.");
		obj.value			=	obj.value.substr(0,i);
	}
	
	if(document.getElementById("divMessageLimit")) {
		document.getElementById("divMessageLimit").innerText	=	nByte +"/"+ limit +" Bytes";
	} else if(div) {
		document.getElementById(div).innerText	=	nByte +"/"+ limit +" Bytes";
	}
}


//###################################################################
// ¸®»çÀÌÁî
// À¥2.0¿¡ µû¸¥ if_Resize2() ¾÷±×·¹ÀÌµå ¹öÁ¯
// iframe »çÀÌÁî¸¦ º¯°æÇÏ´Â ¹æ½ÄÀÌ¶û ¿ÜºÎÀÇ marginÀÌ³ª padding°ª¿¡µµ Á¤È®ÇÑ ¸®»çÀÌÂ¡~
// ¿¹) <iframe name="content" width="100%" onload="iframeResize(this)"></iframe>
//###################################################################

function iframeResize(ifrm) {

	//alert("common_func.jsÀÇ resize function");
	//alert("³×ÀÌÆ®¿Â ¸®»çÀÌÁî Å×½ºÆ® ³×ÀÌÆ® ¿Â¿¡¼­ ¸®»çÀÌÁî°¡ µÇ½Ã´Â ºÐÀº °øÀ¯ÇØ ÁÖ¼¼¿ä~");
	if(ifrm) {
		try {
			//ifrm.style.height	=	eval(ifrm.name).document.body.scrollHeight;
			ifrm.setAttribute("height", eval(ifrm.name).document.body.scrollHeight);
		} catch(ex) {
		}
		document.body.scrollTop	=	0;

	} else {
		var obj		=	parent.document.getElementsByTagName("iframe");

		for(var i=0;i<obj.length;i++) {
			if(obj[i].name == window.name) {
				try {
					//obj[i].style.height	=	document.body.scrollHeight;
					obj[i].setAttribute("height", document.body.scrollHeight);
				} catch(ex) {
				}
			}
		}
	}
}



/*
function iframeResize(ifrm) {
	if(ifrm) {
		var obj		=	ifrm.contentWindow;

		ifrm.height	=	isXHTML(obj) ? obj.document.documentElement.scrollHeight : obj.document.body.scrollHeight;

		if(isXHTML()) {
			document.documentElement.scrollTop	=	0;
		} else {
			document.body.scrollTop	=	0;
		}
	} else {
		var obj	=	parent.document.getElementsByTagName('iframe')[window.name];

		obj.style.height	=	isXHTML() ? document.documentElement.scrollHeight +'px' : document.body.scrollHeight;
	}
}

function isXHTML(obj) { 
	var xhtml; 
 
	if(navigator.appName == 'Microsoft Internet Explorer') { 
		xhtml		=	(obj ? obj.document.documentElement.clientHeight : document.documentElement.clientHeight) ? 1 : 0; 
	} else { 
		try { 
			xhtml	=	((obj ? obj.document.doctype.publicId.indexOf('XHTML') : document.doctype.publicId.indexOf('XHTML')) == -1) ? 0 : 1; 
		} catch(ex) { 
			xhtml	=	0; 
		} 
	} 
 
	return xhtml; 
} 
*/
function iframeResize2(ifrm) {
	if(ifrm) {
		try {
			ifrm.style.height	=	ifrm.contentWindow.document.documentElement.scrollHeight +'px';  
		} catch(ex) {
		}
			document.documentElement.scrollTop	=	0;  
	} else {
		var obj		=	document.getElementsByTagName("iframe");
		for(var i=0;i<obj.length;i++) {
			if(obj[i].name == window.name) {
				try {
					obj[i].style.height	=	document.documentElement.scrollHeight +'px';
				} catch(ex) {  
				}
			}
		}
	}
}




//###################################################################
// ¸®»çÀÌÁî
// Å×ÀÌºí ÄÚµùÀÏ °æ¿ì iframe resize ÇÏ´Âµ¥, iframeÀÇ height¿¡ parameter ·Î ¹ÞÀº addÇÒ °ªÀ» ´õÇÑ´Ù
/* 
//sample
<table width="610" border="0" cellspacing="0" cellpadding="0" style="text-align:left; ">
	<tr>
		<td id="resize_td">
			<iframe scrolling="no" name="Content" id="Content" width="100%" height="100%" src="" marginheight="0" marginwidth="0" frameborder="0" align="center" onload="iframe_resize_table_add50()" allowTransparency="true"></iframe> 
		</td>
	</tr>
</table>
*/
// ¿¹) <iframe name="content" width="100%" onload="iframeResize(this)"></iframe>
//###################################################################

function iframe_resize_table_add(add_val) {
	alert(Content.document.body.scrollHeight);
	if(!add_val) add_val= 50;	

	//resize_td.height = Content.document.body.scrollHeight + add_val; 
	resize_td.height = Content.document.body.scrollHeight ;
	resize_td.width = Content.document.body.scrollWidth; 
	//alert(resize_td.height);

}


//###################################################################
// ¼ýÀÚ¸¸ ¹Þ±â - input, textarea¿¡ ¼ýÀÚ¸¸ ¹ÞÀ½
// ¿¹) <input type="text" onkeyup="numberCheck(this)" />
//###################################################################
function numberCheck(obj) {
	obj.value			=	obj.value.replace(/[^0-9]/gi,"");	
}


//###################################################################
// ÀÍ½ºÇÃ·Î·¯ 7 °Ë»ç - ÀÍ½ºÇÃ·Î·¯ 7ÀÌ¸é true¹ÝÈ¯
// ¿¹) if(!isIE7()) return;
//###################################################################
function isIE7() {
	var flag				=	false;
	var arrVerStr		=	window.navigator.appVersion.split("; ");

	if(arrVerStr.length >= 4) {
		var arrIEVer	=	arrVerStr[1].split(" ");
		
		if(arrIEVer[1] >= 7.0) {
			flag			=	true;
		}
	}

	return flag;
}


//###################################################################
// °ø¹é Á¦°Å
// ¿¹) if(!document.form1.subject.value.trim()) return;
//###################################################################
String.prototype.trim = function() {
    return this.replace(/(^[ \f\n\r\t]*)|([ \f\n\r\t]*$)/g, "");
}


//###################################################################
// Ãµ´ÜÀ§ ÄÄ¸¶±¸ºÐ
// ¿¹) document.form1.no.value = document.form1.no.value.numberFormat();
//###################################################################
// 1000´ÜÀ§ ±¸ºÐ
String.prototype.numberFormat	=	function() {
    return this.replace(/(\d)(?=(?:\d{3})+(?!\d))/g,'$1,');
}


//###################################################################
// ±ÛÀÚ¼ö Á¦ÇÑ
// ¿¹) document.write(document.form1.subject.cut(15));
//###################################################################
String.prototype.cut = function(len) {
	var str	=	this;
	var l	=	0;

	for(var i=0;i<str.length;i++) {
		l += (str.charCodeAt(i) > 128) ? 2 : 1;
		
		if(l > len) return str.substring(0,i) + "..";
	}

	return str;
}


//###################################################################
// ÆÄÀÏ ÀÎÅ¬·çµå - ½ºÅ©¸³Æ® ÆÄÀÏ ÀÎÅ¬·çµå
// PHP include ÇÔ¼ö¿Í µ¿ÀÏ
// ¿¹) include("http://www.mgame.com/common_js/mhtml.js");
//###################################################################
function include( filename ) {
	var js	=	document.createElement('script');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', filename);
	js.setAttribute('defer', 'defer');
	document.getElementsByTagName('head')[0].appendChild(js);
}


//###################################################################
// ¿¡·¯Ã³¸® - ·¹ÀÌ¾î ÆË¾÷ ¶ç¿ò /  Ã¤³Î¸µ Áö¿ø
// object, iframeÃ¼Å© ÈÄ ÀÚµ¿À¸·Î ·¹ÀÌ¾î ¶Ç´Â ¸ð´ÞÃ¢À¸·Î ¶ç¿ò
// confirmÀÌ trueÀÏ °æ¿ì confirm¿ë ¸ð´ÞÃ¢ ¶ç¿ò
// modalÀÌ trueÀÏ °æ¿ì ¹«Á¶°Ç ¸ð´ÞÃ¢ ¶ç¿ò
//¿¹) error("À¥¼­ºñ½º°³¹ßÆÀ");
//###################################################################
function error(msg,opt,modal) {
	if(!msg) {
		msg	=	"·Î±×ÀÎ ÈÄ ÀÌ¿ëÇÏ¿© ÁÖ¼¼¿ä.";
	}

	if(thisDomain == "mgame") {	
		if(opt) {
			return Mgame_ConfirmPopupOpen(msg);
		} else {
			var obj		=	document.getElementsByTagName("iframe");
			var flag		=	modal ? 1 : 0;
			for(var i=0;i<obj.length;i++) {
				// ·±ÃÄ¸¦ Á¦¿ÜÇÑ ³ª¸ÓÁö
				if(obj[i].name != "launch") {
					try {
						// object Æ÷ÇÔ
						if(eval(obj[i].name).document.getElementsByTagName("object").length) flag++;
					} catch(ex) {
						flag++;
					}
					// ÀÍ½ºÇÃ·Î·¯ 6Àº select ÅÂ±× Æ÷ÇÔ
					if(isIE() && !isIE7()) {
						try {
							if(eval(obj[i].name).document.getElementsByTagName("select").length) flag++;
						} catch(ex) {
							flag++;
						}
					}
				}
			}

						
			if(document.getElementById("mgamePlayer")) flag++;	//	³»°¡ ¸¸µç ÇÃ·¹ÀÌ¾î ¾ÆÀÌµð
			if(document.getElementById("flvplayer")) flag++;			//	UCC ÇÃ·¹ÀÌ¾î ¾ÆÀÌµð
			

			// ¿¹¿ÜÃ³¸®
			if(top.location.href.indexOf("guild.mgame.com/guild/game/wffm") != -1) flag = null;
			if(top.location.href.indexOf("flash.mgame.com") != -1) flag++;
			if(location.href.indexOf("wffm.mgame.com") != -1) flag++;
			

			if(modal) flag++;
			
			// flag °ªÀÌ ÀÖÀ¸¸é ¸ð´Þ ÆË¾÷
			if(flag) {
				try {
					top.Mgame_ErrorPopupOpen("free",msg);
				} catch(e) {
					Mgame_ErrorPopupOpen("free",msg);
				}
			// flag °ªÀÌ ¾øÀ¸¸é ·¹ÀÌ¾î ÆË¾÷
			} else {
				try {
					top.Mgame_ErrorLayerOpen("free",msg);
				} catch(e) {
					Mgame_ErrorLayerOpen("free",msg);
				}
			}
		}
	// ³ª¸ÓÁö µµ¸ÞÀÎÀº ¸ðµÎ ±âº»°ª
	} else {
		if(opt) {
			return confirm(msg);
		} else {
			//alert(msg);
			Mgame_ErrorPopupOpen('free', msg);
		}
	}
}


// ÆÄÀÏ¸íÀ» º¯°æ
function thisFile(a) {
	var thisHref		=	location.href.split("/");
	var thisReFile		=	thisHref[thisHref.length-1].replace(/(\?(.)*)/gi,"");
	var thisLocate		=	thisReFile.split(".");
	var thisName		=	thisLocate[0].replace(/(_(.)*)/gi,"");

	return a ? thisName + "_" + a +"."+thisLocate[1] : thisName + "."+thisLocate[1];
}


// Å¬¸³º¸µå ÀúÀå
function copyLink(v) {
	try {
		var copyPath	=	copyUrl;
	} catch(e) {
		var copyPath	=	location.href +"?idx="+ v;
	}
	
	clipboardData.setData("Text",copyPath);
	error("Å¬¸³º¸µå¿¡ ÀúÀåÇÏ¿´½À´Ï´Ù.");
}


// ÆË¾÷ ¶ç¿ò
function mgamePopup(param,w,h) {
	var popupWidth	=	w ? w : 50;
	var popupHeight	=	h ? h : 50;
	
	mgamePopupObject	=	window.open(param,"mgamePopup","width="+ popupWidth +",height="+ popupHeight +",top=0,left=0");
}

// ÆË¾÷ ¶ç¿ò(½ºÅ©·Ñ ÀÖ°Ô)
function mgamePopup_scroll(param,w,h) {
	var popupWidth	=	w ? w : 50;
	var popupHeight	=	h ? h : 50;
	
	mgamePopupObject	=	window.open(param,"mgamePopup","width="+ popupWidth +",height="+ popupHeight +",top=0,left=0,scrollbars=1,resizable=yes");
}


// ·¹ÀÌ¾î ÆË¾÷ ¶ç¿ò
function mgameLayerPopup(param,w,h) {
	var popupWidth	=	w ? w : 50;
	var popupHeight	=	h ? h : 50;
	
	Mgame_CommonLayerOpen(param,popupWidth,popupHeight);
}

//###################################################################
// °Ô½ÃÆÇ °ü·Ã 
//###################################################################
// µî·ÏÇÏ±â
function writeLink() {
	if(!mgameUserCheck()) return;
	
	var p	=	document.procForm;
	
	p.action			=	thisFile("write");
	p.submit();
}

// ´äº¯ÇÏ±â
function replyLink() {
	if(!mgameUserCheck()) return;
	
	var p	=	document.procForm;
	
	p.action			=	thisFile("write");
	p.mode.value		=	"reply";
	p.submit();
}

// ÀÐ±â
function viewLink(idx,a) {
	var p	=	document.procForm;
	p.idx.value			=	idx;

	if(a) {
		p.action		=	a;
	} else {
		try {
			p.action	=	procAction;
		} catch(e) {
			p.action	=	thisFile("view");
		}
	}
	
	p.submit();
}
// ÀÐ±â_target=_top
function viewLink_top(idx,a) {
	var p	=	document.procForm;
	p.idx.value			=	idx;

	if(a) {
		p.action		=	a;
	} else {
		try {
			p.action	=	procAction;
		} catch(e) {
			p.action	=	thisFile("view");
		}
	}
	p.target="_top";
	p.submit();
}

// ÆäÀÌÁö º¯°æÇÏ±â
function pageLink(page) {
	var p	=	document.procForm;
	
	p.page.value		=	page;
	p.submit();
}

// ¸®½ºÆ®·Î µ¹¾Æ°¡±â
function listLink() {
	var p	=	document.procForm;
	
	p.action			=	thisFile();
	p.submit();
}

// ¸ðµå°ª Ã³¸®
function modeLink(m) {
	if(!mgameUserCheck()) return;
	
	var p	=	document.procForm;

	p.mode.value		=	m;
	p.action			=	thisFile("proc");
	p.submit();
}

// »èÁ¦ÇÏ±â
function deleteLink() {
	if(!mgameUserCheck()) return;
	
	if(!error("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?",true)) {
		return;
	}
	
	var p	=	document.procForm;
		
	p.mode.value		=	"delete";
	p.action			=	thisFile("proc");
	p.submit();
}

// ¼öÁ¤ÇÏ±â
function editLink() {
	if(!mgameUserCheck()) return;
	
	var p	=	document.procForm;
		
	p.mode.value		=	"edit";
	p.action			=	thisFile("write");
	p.submit();
}

// ´ñ±Û Ã³¸®ÆÄÀÏ
function ajaxProc() {
	try {
		var cAction		=	ajaxAction;
	} catch(e) {
		var cAction		=	thisFile("comment");
	}
	
	return cAction;
}

// ´ñ±Û ÀÛ¼º ÈÄ ¸®»çÀÌÁî
function ajaxResize() {
	if(parent.document.getElementById("resize_td")) {
		if(parent.window.if_Resize2) parent.if_Resize2();
	}else {
		try
		{
			iframeResize();
		}
		catch (e)
		{
		}
	}

}

// ´ñ±Û Ãâ·Â div¸í
function ajaxId() {
	try {
		var div			=	ajaxDiv;
	} catch(e) {
		var div			=	"divAjax";
	}
	
	return div;
}

// ´ñ±Û °øÅë Äõ¸®
function ajaxVariable() {
	try { 
		var query		=	ajaxQuery;
	} catch(e) {
		var query		=	"";
	}
	
	return query;
}

// ´ñ±Û ÆäÀÌÂ¡
function ajaxPage(page) {
	ajaxRequest(ajaxId(),ajaxProc(),ajaxVariable() +"&page="+ (page ? page : 1));
	ajaxResize();
}

// ´ñ±Û ÀÔ·Â
function commentWrite() {

	if(!mgameUserCheck()) return;

	// Á¦ÇÑÀû º»ÀÎÀÎÁõÀº commentAuth¿¡.. ½ºÅ©¸³Æ®·Î ºÒ°¡´É.
	try {
		commentAuth();
	} catch(e) {
	}

	
	var f	=	document.commentForm;
	
	if(!f.comment.value.trim()) {
		error("´ñ±ÛÀ» ÀÔ·ÂÇÏ¿© ÁÖ¼¼¿ä.");
		return;
	}

	if(f.comment.value.substring(0,4) == "  * "){	
		error("´ñ±ÛÀ» ÀÔ·ÂÇÏ¿© ÁÖ¼¼¿ä.");
		f.comment.value = "";
		return;
	}
	
	// ºÒ·®´Ü¾î Á¦°Å
	f.comment.value	=	ch_BadWord(f.comment.value);
	f.comment.value = f.comment.value.replace(/"/ig, "&quot;");			//    "  °ª  º¯°æ
	f.comment.value = f.comment.value.replace(/'/ig, "&#39;");				//    '  °ª  º¯°æ
	f.comment.value = f.comment.value.replace(/ /ig, "&nbsp;");			//½ºÆäÀÌ½º °ª º¯°æ
	f.comment.value = f.comment.value.replace(/\r\n/ig, "<br>");			//¿£ÅÍ°ªº¯°æ

	var chr = encodeURIComponent(f.comment.value);							//ÀÎÄÚµùÀ¸·Î Æ¯¼ö¹®ÀÚ µé¾î°¡°Ô º¯°æ (ÇÑ±Û ±úÁü) (ÁÖÀÇ : UTF-8 ·Î ¹Þ¾Æ¾ßÇÑ´Ù)

	ajaxRequest(ajaxId(),ajaxProc(),ajaxVariable() +"&mode=write&comment="+ encodeURIComponent(chr));
	f.reset();
	ajaxResize();
}

// ´ñ±Û »èÁ¦
function commentDelete(idx) {
	if(!mgameUserCheck()) return;
	if(!error("»èÁ¦ÇÏ½Ã°Ú½À´Ï±î?",1)) return;
		
	ajaxRequest(ajaxId(),ajaxProc(),ajaxVariable() +"&mode=delete&idx="+ idx);
	ajaxResize();
}

// ´ñ±Û ´ä±Û
function commentReply(idx) {
	if(!mgameUserCheck()) return;
	
	var obj;
	
	obj		=	document.getElementById("divAjax").getElementsByTagName("div");

	for(var i=0;i<obj.length;i++) {
		if(obj[i].id.substr(0,7) == "divAjax") {
			obj[i].style.display	=	"none";
		}
	}

	obj		=	document.getElementById("divAjax_"+ idx);

	if(obj.style.display == "block") {
		obj.style.display	=	"none";
	} else {
		obj.style.display	=	"block";
		document.commentForm("comment_"+ idx).focus();
	}
	
	ajaxResize();
}

// ´ñ±Û ´ä±Û µî·Ï
function commentReplyWrite(idx,reIdx,reLevel,reStep) {
	if(!mgameUserCheck()) return;
	
	// Á¦ÇÑÀû º»ÀÎÀÎÁõÀº commentAuth¿¡.. ½ºÅ©¸³Æ®·Î ºÒ°¡´É.
	try {
		commentAuth();
	} catch(e) {
	}
	
	var f	=	eval("document.commentForm.comment_"+ idx);
	
	if(!f.value.trim()) {
		error("´ñ±ÛÀ» ÀÔ·ÂÇÏ¿© ÁÖ¼¼¿ä.");
		return;
	}
	
	// ºÒ·®´Ü¾î Á¦°Å
	f.value	=	ch_BadWord(f.value);
	f.value = f.value.replace(/"/ig, "&quot;");			//    "  °ª  º¯°æ
	f.value = f.value.replace(/'/ig, "&#39;");				//    '  °ª  º¯°æ
	f.value = f.value.replace(/ /ig, "&nbsp;");			//½ºÆäÀÌ½º °ª º¯°æ
	f.value = f.value.replace(/\r\n/ig, "<br>");			//¿£ÅÍ°ªº¯°æ

	var chr = encodeURIComponent(f.value);							//ÀÎÄÚµùÀ¸·Î Æ¯¼ö¹®ÀÚ µé¾î°¡°Ô º¯°æ (ÇÑ±Û ±úÁü) (ÁÖÀÇ : UTF-8 ·Î ¹Þ¾Æ¾ßÇÑ´Ù)
	ajaxRequest(ajaxId(),ajaxProc(),ajaxVariable() +"&mode=reply&idx="+ reIdx +"&reLevel="+ reLevel +"&reStep="+ reStep +"&comment="+ encodeURIComponent(chr));
	document.commentForm.reset();
	ajaxResize();
}

// ´ñ±Û °Ë»ö
function commentSearch() {
	if(!document.searchForm) return;
	
	var f	=	document.searchForm;
	
	ajaxRequest(ajaxId(),ajaxProc(),ajaxVariable() +"&searchName="+ f.searchName.value +"&searchWord="+ f.searchWord.value);
	ajaxResize();
}

//###################################################################
//  °øÁö , ÀÌº¥Æ® µî ÄÜÅÙÃ÷ ³» URL º¯°æ
//###################################################################
function notice_commonLink(strUrl,linkType){
	//linkType : 1 (popup)
	//linkType : 0 (link)
	strUrl = "http://"+location.host+strUrl;

	if(linkType == "1")
		window.open(strUrl,"newcontents","width=800, height=600, location=yes, directories=yes, menubar=yes,scrollbars=yes,resizable=yes,status=yes,toolbar=yes");
	else
		location.href = strUrl;
}


//###################################################################
//  ³¯Â¥ Â÷ÀÌ °¡Á®¿È
//###################################################################

function getDateDiff(date, diffType){
	//date = '2009-10-29 12:30:35';

	var gapTime;
	var writeDate = new Date(date.substr(0,4),date.substr(5,2),date.substr(8,2),date.substr(11,2),date.substr(14,2));

	var nowDate = new(Date);
	var nowYear = nowDate.getYear();
	var nowMonth = nowDate.getMonth()+1;
	var nowDay = nowDate.getDate();
	var nowHours = nowDate.getHours();
	var nowMinutes = nowDate.getMinutes();
	
	var currentDate = new Date(nowYear,nowMonth,nowDay,nowHours,nowMinutes);
	
	var gapTimeStamp = currentDate.getTime()-writeDate.getTime();

	if(diffType == "D")
		gapTime = Math.abs(Math.floor(gapTimeStamp/(60*60*24*1000)));
	else if(diffType == "H")
		gapTime = Math.abs(Math.floor(gapTimeStamp/(60*60*1000)));
	else if(diffType == "M")
		gapTime = Math.abs(Math.floor(gapTimeStamp/(60*1000)));

	return gapTime;
}