function replaceHtml(el, html) {    
	var oldEl = (typeof el === "string" ? document.getElementById(el) : el);     
	/*@cc_on // Pure innerHTML is slightly faster in IE         oldEl.innerHTML = html;         return oldEl;     @*/     
	var newEl = oldEl.cloneNode(false);

	newEl.innerHTML = html;    
	oldEl.parentNode.replaceChild(newEl, oldEl);    
	/* Since we just removed the old element from the DOM, return a reference to the new element, which can be used to restore variable references. */    
	return newEl; 
}


function popResize(){


	var oBody = new Object;
 
	if ( self.innerWidth) // IE ¿Ü ¸ðµç ºê¶ó¿ìÀú
	{
		oBody.width = self.innerWidth;
		oBody.height = self.innerHeight;
	}else if ( document.documentElement && document.documentElement.clientWidth) // Explorer 6 Strict
	{  
		oBody.width = document.documentElement.clientWidth;
		oBody.height = document.documentElement.clientHeight;
	}else if ( document.body )  // IE ºê¶ó¿ìÀú
	{  
		oBody.width = document.body.clientWidth;
		oBody.height = document.body.clientHeight;
	}

	var pageDiv = document.getElementById("top_tit");

	if(typeof(pageDiv)=="object"){
		var divWidth	= top_tit.offsetWidth;
		var divHeight	= top_tit.offsetHeight;

		//if(navigator.appVersion.indexOf("MSIE 7") > -1){
		//	divHeight	= divHeight + 73;
		//}else{
			divHeight	= divHeight + 73;
		//}

		window.resizeTo(divWidth+10, divHeight);
	}else{
		if(navigator.userAgent.indexOf("MSIE") !=-1)
			window.resizeTo(oBody.width+12, oBody.height+20);
		else
			window.resizeTo(oBody.width+12, oBody.height + 20);
	}
}

// rollover
function initRollovers() {

	if (!document.getElementById) return

	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className == 'imgover') {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_on'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_on'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

window.onload = initRollovers;

//ÆË¾÷ ´Ý±â
function winClose()
{
	try{
		parent.popWindow.style.display = 'none';
	}
	catch(e){
		self.close();
	}
}

//¸Ó´Ï ÄÞ¸¶ Âï±â
function ChangeMoney(num)
{
	var str = String(num)
	var re = /(-?[0-9]+)([0-9]{3})/;
	while(re.test(str)){
			str = str.replace(re, "$1,$2");
	}
	return str;
}


//Ä«µå¾Æ¹ÙÅ¸ ±¸¸ÅÇÏ±â
function CardAvatarBuy(avid,avcnt,game,loc,loc2,present)
{
	if(loc==null || loc.length==0)
		loc = "avatar";

	if(loc2==null || loc2.length==0)
		loc2 = loc;

	if(present==null || present.length==0)
		present = 0;

	var pageUrl = "http://avatar.mgame.com/buy/card_avatar_buy.mgame?";
	pageUrl += "avid="+ avid 
			+"&avcnt="+ avcnt 
			+"&game="+ game 
			+"&loc="+ loc 
			+"&loc2="+ loc2

	popupVisiable2(pageUrl)
}

function HostVal(){
	var currDomain	= "";
	currDomain	= location.href;
	currDomain	= currDomain.split("//");
	currDomain	= "http://"+currDomain[1].substr(0,currDomain[1].indexOf("/"));

	return currDomain;
}

//¾Æ¹ÙÅ¸ ±¸¸ÅÇÏ±â
function GmoneyBuy(setno,game,loc,present,loc2) {
	if(loc==null || loc.length==0)
		loc = "avatar";

	if(loc2==null || loc2.length==0)
		loc2 = loc;

	var popupUrl	=	"";  
	var currHost	=	HostVal();
	if(currHost == "http://mgavatar.gameon.nate.com" || currHost == "http://baduk.gameon.nate.com" || currHost == "http://janggi.gameon.nate.com"){
		popupUrl	=	"http://mgavatar.gameon.nate.com";
	}else{
		popupUrl	=	"http://avatar.mgame.com";
	}

	popupUrl		+= "/buy/avatar_gmoney_buy.mgame?";

	if(loc=="freerefill" || loc=="energy" || loc=="worldcup" || loc=="baduklucky" || loc=="sdgo2" || loc=="sdpo5")
		popupUrl += "avid="+setno;
	else
		popupUrl += "setno="+setno;
	
	popupUrl += "&game="+game+"&present="+present+"&loc="+loc+"&loc2="+loc2;

	//sReturn = window.showModalDialog(popupUrl, "avatarbuy", "dialogwidth:550px;dialogheight:520px;center:yes; help:no; status:no; scroll:no; resizable:yes");
	//if (sReturn != null){   //°ªÀ» ¹Þ¾Æ¿È
	//	document.form.firstwon.value=sReturn;  //Æû¿¡ ³Ö¾îÁÜ
	//}
	popupVisiable2(popupUrl)
}


//¾ÆÀÌÅÛ ±¸¸Å
function ItemBuy(num, present,gamename, mall, pagetype){

	if(typeof(gamename)==undefined)		gamename = "";
	if(typeof(mall)==undefined)			mall = "";
	if(typeof(pagetype)==undefined)		pagetype = "";

	var popupUrl	=	"";  
	var currHost	=	HostVal();
	if(currHost == "http://mgavatar.gameon.nate.com" || currHost == "http://baduk.gameon.nate.com" || currHost == "http://janggi.gameon.nate.com"){
		popupUrl	=	"http://mgavatar.gameon.nate.com";
	}else{
		popupUrl	=	"http://avatar.mgame.com";
	}

	if(present==3){
		popupUrl	+=	"/itemshop/item_popup.mgame?itemid="+ num +"&present="+ present+"&game="+gamename+"&place="+mall ;
	}else{
		popupUrl	+=	"/itemshop/buy/item_buy.mgame?itemid="+ num +"&present="+ present+"&game="+gamename+"&place="+mall ;
	}

	if(pagetype=="page"){
		window.location.href = popupUrl;
	}else{
		window.open( popupUrl, "", "width=408, height=460" );
	}
}

//ÇÁ¸®¹Ì¾ö ÆäÀÌÁö °¡±â
function GoPremium(){
	top.location.href = "http://premium.mgame.com/cardpremium2008/";
}

function AvatarBasket(avid, avname, avimg, avprice, game, menutype)
{
	pageurl = "http://www.mgame.com/avatar/popup/card_basket_popup.mgame?"
			  + "avid="+ avid
			  + "&avname="+ avname
			  + "&avimg="+ avimg
			  + "&avprice="+ avprice
			  + "&game="+ game
			  + "&loc="+ menutype

	popupVisiable(pageurl)
}

//ÂÉ¸£±â »ó¼¼º¸±â
function pop_detail(pagename,pagetype,price,UserID,ItemName,RDate,Img,Message,sex) {

	var pageUrl = "http://www.mgame.com/avatar/popup/wish_pop_detail.mgame?";
	pageUrl += "RDate="+RDate;
	pageUrl += "&UserID="+UserID;
	pageUrl += "&ItemName="+ItemName;
	pageUrl += "&price="+price;
	pageUrl += "&Img="+Img;
	pageUrl += "&Message="+Message;
	pageUrl += "&sex="+sex;
	pageUrl += "&wishtype="+pagetype;

	popupVisiable(pageUrl)
}


//·¹ÀÌ¾î ÆË¾÷ ¶ç¿ì±â
function popupVisiable2(url) 
{
	/*
	try{
		this.popWindow.style.top = document.body.scrollTop+90;
		this.popWindow.style.left = document.body.scrollLeft+250;

		popWindow.innerHTML = '<iframe id="avPopup" frameborder="0" src="" width="300" height="300" scroll="no" allowtransparency="true"></iframe>';
		avPopup.location.href = url;
		this.popWindow.style.display = "block";	

	}catch (e){
		*/
		window.open(url,"buy","width=540,height=640");
		/*
	}
	*/
	
}


function sell(slot,itemid,present,menutype)
{
	if(slot == "layer11") { alert("¼ºÇüÀº µÇÆÈ±â¸¦ ÇÏ½Ç ¼ö ¾ø½À´Ï´Ù."); return; }
	if(present == 1) {	alert("¼±¹°/°ÔÀÓ¸Ó´ÏÁö±Þ¾ÆÀÌÅÛÀº \nµÇÆÈ±â¸¦ ÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");	return;	}

	pageurl = "/avatar/popup/avatar_sell.mgame?avid="+itemid;

	popupVisiable(pageurl)
}

function del(itemid,itemname){
	pageurl = "/avatar/popup/avatar_delete.mgame?avid="+itemid;
	popupVisiable(pageurl)
}

function use(itemid,gubun){
	pageurl = "/avatar/popup/avatar_use.mgame?gubun="+gubun+"&avid="+itemid;

	popupVisiable(pageurl)
}

function detail(itemid,gubun,present){
	pageurl = "/avatar/popup/avatar_detail.mgame?gubun="+gubun+"&avid="+itemid+"&present="+present;

	popupVisiable(pageurl)
}

function goPage_etc(pageurl, pagetype){
	arrPara = pageurl.split("?");

	top.location.href = "/avatar/default.mgame?purl="+ arrPara[0] +"&"+ arrPara[1];
}

function GoMenu(pageurl, mtype, asex){
	window.location.href = "/avatar/default.mgame?URL="+ pageurl +"&M_Type="+ mtype +"&AvatarSex="+ asex ;
}

// Tab Content
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("a");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;

		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		thismenu.onclick = function tabMenuClick() {
			currentmenu = this.container.current;
			if (currentmenu == this)
				return false;

			if (currentmenu) {
				currentmenu.targetEl.style.display = "none";
				if (currentmenu.imgEl) {
					currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", ".gif");
				} else {
					currentmenu.className = currentmenu.className.replace(" on", "");
				}
			}
			this.targetEl.style.display = "";
			if (this.imgEl) {
				this.imgEl.src = this.imgEl.src.replace(".gif", "_on.gif");
			} else {
				this.className += " on";
			}
			this.container.current = this;

			return false;
		};

		if (!thismenu.container.first)
			thismenu.container.first = thismenu;
	}
	if (tabContainer.first)
		tabContainer.first.onclick();
}

// png
function setPng24(obj) { 
    obj.width=obj.height=1; 
    obj.className=obj.className.replace(/\bpng24\b/i,''); 
    obj.style.filter = 
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');" 
    obj.src='http://image.mgame.com/icon_bin.gif';  
    return ''; 
} 

// vertical-align middle
function verticalAlign(obj){
    result=(obj.offsetParent.offsetHeight - obj.offsetHeight)/2+"px";
    if(obj.readyState == "complete"){
        obj.style.marginTop="0";
        obj.style.marginTop=result;
    }else{
        return result;
    }
}

//max-width, max-height
function maxSize(obj,w,h){
    if(obj.readyState != "complete") return "auto";
    real_w=obj.offsetWidth;
    real_h=obj.offsetHeight;
    virt_w=obj.offsetWidth;
    virt_h=obj.offsetHeight;
    if(w>0 && virt_w>w){
        virt_w = w;
        virt_h = real_h * (virt_w/real_w);
    }
    if(h>0 && virt_h>h){
        virt_h = h;
        virt_w = real_w * (virt_h/real_h);
    }

    obj.style.width="0";
    obj.style.height="0";
    obj.style.width=virt_w+"px";
    obj.style.height=virt_h+"px";

}

//min-height
function min_height(obj,h){
    if(obj.readyState != "complete") return "auto";
    if(obj.offsetHeight<h){
        obj.style.height="0";
        obj.style.height=h+"px";
    }

}

// Change Over Row Class
function changeOverRowClass(elId, tagName, searchClass) {
	var el = document.getElementById(elId).getElementsByTagName(tagName);

	for (i=0; i<el.length; i++) {
		if (el[i].className == searchClass || el[i].className == searchClass + " on") {
			el[i].onmouseover = changeOverRowClassOver;
			el[i].onmouseout = changeOverRowClassOut;
		}
	}
}
function changeOverRowClassOver() {
	if (this.className == "") {
		this.className = this.className + " on";
	} else {
		this.className = "on";
	}
}
function changeOverRowClassOut() {
	if (this.className == "on") {
		this.className = "";
	} else {
		this.className = this.className.replace(" on", "");
	}
}

// Add Even Row Class
function addEvenRowClass(elId, tagName, searchClass, addClass) {
	var count = 1;
	var el = document.getElementById(elId).getElementsByTagName(tagName);

for (i=0; i<el.length; i++) {
		if (el[i].className == searchClass) {
			if (count%2) {
				el[i].className = el[i].className + " " + addClass;
			}
			count++;
		}
	}
}

// definition list toggle
function initToggle(tabContainer) {
	triggers = tabContainer.getElementsByTagName("a");

	for(i = 0; i < triggers.length; i++) {
		if (triggers.item(i).href.split("#")[1])
			triggers.item(i).targetEl = document.getElementById(triggers.item(i).href.split("#")[1]);

		if (!triggers.item(i).targetEl)
			continue;

		triggers.item(i).targetEl.style.display = "none";
		triggers.item(i).onclick = function () {
			if (tabContainer.current == this) {
				this.targetEl.style.display = "none";
				tabContainer.current = null;
			} else {
				if (tabContainer.current) {
					tabContainer.current.targetEl.style.display = "none";
				}
				this.targetEl.style.display = "block";
				tabContainer.current = this;
			}
			return false;
		}
	}
}

// iframe resize
function resizeFrame(frm) {
	frm.style.height = "auto";
	contentHeight = frm.contentWindow.document.documentElement.scrollHeight;
	frm.style.height = contentHeight + 0 + "px";
}

// scroll layer
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;

	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;

	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;

	if (typeof(window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof(document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}

	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if(document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}

	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}

		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;

		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}

// Top Menu
function initNavigation(seq) {
	nav = document.getElementById("gnb");
	nav.menu = new Array();
	nav.current = null;
	nav.menuseq = 0;
	navLen = nav.childNodes.length;
	
	allA = nav.getElementsByTagName("a")
	for(k = 0; k < allA.length; k++) {
		allA.item(k).onmouseover = allA.item(k).onfocus = function () {
			nav.isOver = true;
		}
		allA.item(k).onmouseout = allA.item(k).onblur = function () {
			nav.isOver = false;
			setTimeout(function () {
				if (nav.isOver == false) {
					if (nav.menu[seq])
						nav.menu[seq].onmouseover();
					else if(nav.current) {
						menuImg = nav.current.childNodes.item(0);
						menuImg.src = menuImg.src.replace("_on.gif", ".gif");
						if (nav.current.submenu)
							nav.current.submenu.style.display = "none";
						nav.current = null;
					}
				}
			}, 500);
		}
	}

	for (i = 0; i < navLen; i++) {
		navItem = nav.childNodes.item(i);
		if (navItem.tagName != "LI")
			continue;

		navAnchor = navItem.getElementsByTagName("a").item(0);
		navAnchor.submenu = navItem.getElementsByTagName("ul").item(0);
		
		navAnchor.onmouseover = navAnchor.onfocus = function () {
			if (nav.current) {
				menuImg = nav.current.childNodes.item(0);
				menuImg.src = menuImg.src.replace("_on.gif", ".gif");
				if (nav.current.submenu)
					nav.current.submenu.style.display = "none";
				nav.current = null;
			}
			if (nav.current != this) {
				menuImg = this.childNodes.item(0);
				menuImg.src = menuImg.src.replace(".gif", "_on.gif");
				if (this.submenu)
					this.submenu.style.display = "block";
				nav.current = this;
			}
			nav.isOver = true;
		}
		nav.menuseq++;
		nav.menu[nav.menuseq] = navAnchor;
	}
	if (nav.menu[seq])
		nav.menu[seq].onmouseover();
}

// showhide layer 
function popupLayer(divName){
	var div_style =document.getElementById(divName).style.display;
	if (div_style == "block"){
		document.getElementById(divName).style.display ="none";
	}else {
		document.getElementById(divName).style.display ="block";
	}
}

function goPcbang(){
	window.open("http://pcbang.mgame.com/pcbang/pcbang_chainpop.php", "pcbangpop", "status=no,toolbar=no,location=no,scrollbars=no"+",left="+((screen.width - 650) / 2)+",top="+((screen.height - 650) / 2)+",width=650,height=650");
}

function flashPopup(gname, fname, price, popflag){

	var gcode = "";

	if(fname=="dartavatar"){
         popupSize = "width=700,height=554";

		 if(gname=="sdgo2"){
			 switch(price){
				 case 2000 : gcode = 11; break;
				 case 5000 : gcode = 12; break;
				 case 10000 : gcode = 13; break;
			 }
		 } else if(gname=="godori3"){
			 switch(price){
				 case 2000 : gcode = 21; break;
				 case 5000 : gcode = 22; break;
				 case 10000 : gcode = 23; break;
			 }
		 }
	}else if(fname=="magicbox"){
         popupSize = "width=555,height=435";

		 if(gname=="sdgo2"){
			 gcode = 31;
		 }else if(gname=="godori3"){
			 gcode = 41;
		 }
	}

    if(gcode == ""){
		alert("Àß¸øÁ¢±ÙÇÏ¼Ì½À´Ï´Ù.");
		return;
	}

    if(popflag=="pop"){
	    window.open('http://avatar.mgame.com/flash/daebak_popup.mgame?game='+ gname +'&fno='+ gcode , 'flashgame', popupSize);
	}else{
		window.location.href = 'http://avatar.mgame.com/flash/daebak_popup.mgame?game='+ gname +'&fno='+ gcode ;
	}
}