var sPage = location.href;

if ( sPage.indexOf(".kppinc.com") != -1 ) {
	var sGameRoot = "http://xgame.kppinc.com";
	var sAvaImg = "http://item.avatar.empas.com/";
} else if ( sPage.indexOf("xtest1.game.empas.com") != -1 || sPage.indexOf("xgame.game.empas.com") != -1  || sPage.indexOf("xevent.game.empas.com") != -1 || sPage.indexOf("xcard.game.empas.com") != -1 || sPage.indexOf("xflash.game.empas.com") != -1 || sPage.indexOf("xcasual.game.empas.com") != -1 ) {
	var sGameRoot = "http://xtest1.game.empas.com";
	var sAvaImg = "http://item.avatar.empas.com/";
} else if ( sPage.indexOf("xgame.nate.com") != -1 ) {
	var sGameRoot = "http://xgame.nate.com";
	var sAvaImg = "http://item.avatar.game.nate.com/";
} else if ( sPage.indexOf("xtest1.game.nate.com") != -1 || sPage.indexOf("xgame.game.nate.com") != -1  || sPage.indexOf("xevent.game.nate.com") != -1 || sPage.indexOf("xcard.game.nate.com") != -1 || sPage.indexOf("xflash.game.nate.com") != -1 || sPage.indexOf("xcasual.game.nate.com") != -1 ) {
	var sGameRoot = "http://xtest1.game.nate.com/";
	var sAvaImg = "http://item.avatar.game.nate.com/";
} else if ( sPage.indexOf(".nate.com") != -1 ) {
	var sGameRoot = "http://game.nate.com";
	var sAvaImg = "http://item.avatar.game.nate.com/";
} else if ( sPage.indexOf("xnategame.okcashbag.com") != -1 ) {
	var sGameRoot = "http://xnategame.okcashbag.com";
	var sAvaImg = "http://item.avatar.game.nate.com/";
} else if ( sPage.indexOf("xtest1.nategame.okcashbag.com") != -1 || sPage.indexOf("xcard.nategame.okcashbag.com") != -1 || sPage.indexOf("xflash.nategame.okcashbag.com") != -1 || sPage.indexOf("xcasual.nategame.okcashbag.com") != -1 ) {
	var sGameRoot = "http://xtest1.nategame.okcashbag.com";
	var sAvaImg = "http://item.avatar.game.nate.com/";
} else if ( sPage.indexOf(".okcashbag.com") != -1 ) {
	var sGameRoot = "http://nategame.okcashbag.com";
	var sAvaImg = "http://item.avatar.game.nate.com/";
} else {
	var sGameRoot = "http://game.empas.com";
	var sAvaImg = "http://item.avatar.empas.com/";
}

// ¼¼ºÎ °ÔÀÓ Á¤º¸
var gmCode = "wgostop";
if (sPage.indexOf("/wgostop/") != -1) {
	var gmCode = "wgostop";
} else if (sPage.indexOf("/vsgostop/") != -1) {
	var gmCode = "vsgostop";
} else if (sPage.indexOf("/gostop/") != -1) {
	var gmCode = "gostop";
} else if (sPage.indexOf("/sutda/") != -1) {
	var gmCode = "sutda";
} else if (sPage.indexOf("/bluepoker/") != -1) {
	var gmCode = "bluepk";
} else if (sPage.indexOf("/highlow/") != -1) {
	var gmCode = "highlow";
} else if (sPage.indexOf("/baduki/") != -1) {
	var gmCode = "baduki";
} else if (sPage.indexOf("/poker/") != -1) {
	var gmCode = "poker";
} else if (sPage.indexOf("/hoola/") != -1) {
	var gmCode = "hoola";
}

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;
}

String.prototype.bytes = function() {
		var str = this;
		var l = 0;
		for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
		return l;
}

// ¾Æ¹ÙÅ¸ ±¸¸Å
function avatar_item_buy (no) {
	//window.open(sLinkURL + "avatar.empas.com/newtrans/transaction.cgi?command=buy&item=" + no, "", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
	window.open(sGameRoot+"/r/ava/u=avatar.empas.com/newtrans/transaction.cgi?command=buy&item=" + no + "&buy_div=WEB&gmcode=" + gmCode, "", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
}

//°¢ °ÔÀÓ¸ÞÀÎ¿¡¼­ ¾Æ¹ÙÅ¸ ±¸¸Å(Å¬¸¯À² ÄÚµå ¶§¹®¿¡ ÇÔ¼ö »õ·Î »ý¼º)
function main_item_buy(click_code,buy_items){
  window.open(click_code+"avatar.empas.com/transaction/transaction.cgi?command=buy&item=" + buy_items + "&buy_div=WEB&gmcode=" + gmCode, "BUY", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
}

//°¢ °ÔÀÓ¸ÞÀÎ¿¡¼­ ¾Æ¹ÙÅ¸ ¼±¹°(Å¬¸¯À² ÄÚµå ¶§¹®¿¡ ÇÔ¼ö »õ·Î »ý¼º)
function main_item_present(click_code,buy_items){
  window.open(click_code+"avatar.empas.com/transaction/transaction.cgi?command=present&item=" + buy_items + "&buy_div=WEB&gmcode=" + gmCode, "PRESENT", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
}

//°¢ °ÔÀÓ¸ÞÀÎ¿¡¼­ ¾Æ¹ÙÅ¸ »ó¼¼º¸±â(Å¬¸¯À² ÄÚµå ¶§¹®¿¡ ÇÔ¼ö »õ·Î »ý¼º)
function main_item_info(click_code,item){
  window.open(click_code+"avatar.empas.com/avatar/view_item_info.cgi?item=" + item + "&buy_div=WEB&gmcode=" + gmCode,'INFO','width=359,height=307,top=10,left=300');
}

// ¾Æ¹ÙÅ¸ ¼±¹°
function avatar_item_present (no) {
	//window.open(sLinkURL + "avatar.empas.com/newtrans/transaction.cgi?command=present&item=" + no, "", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
	window.open(sGameRoot+"/r/ava/u=avatar.empas.com/newtrans/transaction.cgi?command=present&item=" + no + "&buy_div=WEB&gmcode=" + gmCode, "", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
}
// ¾Æ¹ÙÅ¸ Á¤º¸
function avatar_item_info (no) {
	//window.open(sLinkURL + "avatar.empas.com/newtrans/view_item_info.cgi?number=" + no,'','width=359,height=307,top=10,left=300');
	window.open(sGameRoot+"/r/ava/u=avatar.empas.com/newtrans/view_item_info.cgi?number=" + no + "&buy_div=WEB&gmcode=" + gmCode,'','width=359,height=307,top=10,left=300');
}

// ¾Æ¹ÙÅ¸ ÀÌ¹ÌÁö
function view_image (code) {
	var op = new Array (2);
	op = code.split('-');
	var path = sAvaImg+hex(op[0]%256)+"/view";
	return "<img src='"+path+code+".gif' width=81 height=81 border=0>";
}

function view_image_main (code) {
	var op = new Array (2);
	op = code.split('-');
	var path = sAvaImg+hex(op[0]%256)+"/view";
	return "<img src='"+path+code+".gif' width=81 height=81 border=0 style=\"z-index:0\">";
}
function view_big_image (code) {
	var op = new Array (2);
	op = code.split('-');
	var path = sAvaImg+hex(op[0]%256)+"/item";
	return "<img src='"+path+code+"-0.gif' border=0>";
}

function view_big_image_main (code) {
	var op = new Array (2);
	op = code.split('-');
	var path = sAvaImg+hex(op[0]%256)+"/item";
	return "<img src='"+path+code+"-0.gif' border=0 style='border:1px solid #FCD000'>";
}

function item_buy_game (buy_items) {
	if(location.href.indexOf(".nate.com") != -1) {
		window.open("http://avatar.game.nate.com/newtrans/transaction.cgi?g=1&command=buy&item=" + buy_items + "&buy_div=WEB&gmcode=" + gmCode, "BUY", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
	} else {
		window.open("http://avatar.empas.com/transaction/transaction.cgi?g=1&command=buy&item=" + buy_items + "&buy_div=WEB&gamecode=" + gmCode, "BUY", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
	}
}

// ÀÏ¹Ý ÇÔ¼ö
function hex(int) {
	var h = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');

	var lo=int%16;
	//alert(lo);
	var hi=(int-lo)/16;
	//alert(hi);

	return h[hi]+h[lo];
}

// ¾ÆÀÌÅÛÀÌ¸§¿¡¼­ ÇÊ¿ä¾ø´Â ÀÌ¸§Á¦°Å
function stripGameStr(s) {
	var rs = '';
	rs = s.replace('[´ë¹Ú ¸Â°í]','');
	rs = s.replace('[´ë¹Ú Æ÷Ä¿]','');
	rs = s.replace('[´ë¹Ú ÈÇ¶ó]','');
	rs = s.replace('[¿Õ´ë¹Ú ¸Â°í]','');
	return rs;
}

// ±âÈ¹Àü,»õ¾Æ¹ÙÅ¸ ³»¿¡¼­ ¾Æ¹ÙÅ¸ ±¸¸Å
function itemBuyCody (item,game_code) {
	if (game_code==null) game_code = '';
	//window.open("http://avatar.empas.com/game/transaction.cgi?command=buy&item=" + item + "&game_code=" + game_code, "BUY", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
	window.open(sGameRoot+"/r/ava/u=avatar.empas.com/game/transaction.cgi?command=buy&item=" + item + "&game_code=" + game_code + "&buy_div=WEB&gmcode=" + gmCode, "BUY", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
}

// ±âÈ¹Àü,»õ¾Æ¹ÙÅ¸ ³»¿¡¼­ ¾Æ¹ÙÅ¸ ¼±¹°
function itemPresentCody (item,game_code) {
	if (game_code==null) game_code = '';
	//window.open("http://avatar.empas.com/game/transaction.cgi?command=present&item=" + item + "&game_code=" + game_code, "PRESENT", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
	window.open(sGameRoot+"/r/ava/u=avatar.empas.com/game/transaction.cgi?command=present&item=" + item + "&game_code=" + game_code + "&buy_div=WEB&gmcode=" + gmCode, "PRESENT", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width=435,height=493');
}

// ±âÈ¹Àü,»õ¾Æ¹ÙÅ¸ ³»¿¡¼­ ¾Æ¹ÙÅ¸ »ó¼¼º¸±â
function itemInfoCody ( item,game_code) {
	//window.open("http://avatar.empas.com/game/view_item_info.cgi?number="+item+"&game_code=" + game_code,'INFO','width=359,height=307,top=10,left=300');
	window.open(sGameRoot+"/r/ava/u=avatar.empas.com/game/view_item_info.cgi?number="+item+"&game_code=" + game_code + "&buy_div=WEB&gmcode=" + gmCode,'INFO','width=359,height=307,top=10,left=300');
}


function _point2han(point) {
	var uk,cho,man,won,ret="";

	point=Number(point);
	man=Math.floor(point/10000);
	uk=Math.floor(man/10000);
	cho=Math.floor(uk/10000);

	man=man%10000;
	uk=uk%10000;
	won=point%10000;

	if (cho) ret+=String(cho).replace("000","Ãµ")+"Á¶";
	if (uk) ret+=String(uk).replace("000","Ãµ")+"¾ï";
	if (man) ret+=String(man).replace("000","Ãµ")+"¸¸";
	if (won) ret+=String(won).replace("000","Ãµ");
	if (ret =='') ret=0;

	return ret;
}

function gameMoneyChange(money,gamemoney,stats) {
	var m = money.replace(",","");
	var p = 2;
	var g = 0;
	if(m < 5000) {
		if(stats == "tc") {
			p = 3;
		}
	} else if (m < 15000) {
		if(stats == "tc") {
			p = 3;
		}
	} else if (m < 50000) {
		if(stats == "tc") {
			p = 5;
		}
	} else {
		if(stats == "tc") {
			p = 5;
		}
	}
	g = parseInt(gamemoney) + ((gamemoney)*1/10)*p;

	return Math.round(g);
}
