//¼­¹öÈ£½ºÆ®¸í¿¡ µû¶ó URLÀ» ´Þ¸®ÇÔ
var sCurrenUrl = location.href;

var ENV_isDev = location.href.indexOf("http://dev-") > -1 || location.href.indexOf("https://dev-") > -1;
var ENV_isAlpha = location.href.indexOf("http://alpha-") > -1 || location.href.indexOf("https://alpha-") > -1;
var ENV_isBeta = location.href.indexOf("http://beta-") > -1 || location.href.indexOf("https://beta-") > -1;
var ENV_isReal = !ENV_isDev && !ENV_isAlpha && !ENV_isBeta;

if( ENV_isDev || ENV_isAlpha ) {
	sAvatarShopURL = "http://alpha-avatar.hangame.com";
	sItemShopURL = "http://alpha-item.hangame.com";
	sLoginURL = "http://alpha-www.hangame.com";
	sJspLoginURL = "http://alpha-id.hangame.com";
	sBBSURL = "http://fkiller1www.hangame.com";
	sStaticURL = "http://fkiller1www.hangame.com";
	sGameURL = "http://alpha-game.hangame.com";
	sQuaURL = "http://fkiller7.hangame.com";
	sMyinfoURL = "http://fkiller1www.hangame.com";
	sPlusURL = "http://alpha-member.hangame.com";
	sMileageURL = "http://alpha-mileage.hangame.com";
	sBbsURL = "http://fkiller1www.hangame.com";
	sHompyURL = "http://alpha-hompy.hangame.com";
	sHbbsURL = "http://alpha-hbbs.hangame.com";
	sEventURL = "http://alpha-event.hangame.com";
	sWwwURL = "http://dev-www.hangame.com";	
	CONTEXTMENU = true;
} else if( ENV_isBeta ) {
	sAvatarShopURL = "http://beta-avatar.hangame.com";
	sItemShopURL = "http://beta-item.hangame.com";
	sLoginURL = "http://beta-www.hangame.com";
	sJspLoginURL = "http://beta-id.hangame.com";
	sBBSURL = "http://bbs.hangame.com";
	sStaticURL = "http://static.hangame.com";
	sGameURL = "http://beta-game1.hangame.com";
	sQuaURL = "http://hanqua.hangame.com";
	sMyinfoURL = "http://myinfo.hangame.com";
	sPlusURL = "http://beta-member.hangame.com";
	sMileageURL = "http://beta-mileage.hangame.com";
	sBbsURL = "http://prewww.hangame.com";
	sHompyURL = "http://beta-hompy.hangame.com";
	sHbbsURL = "http://beta-hbbs.hangame.com";
	sEventURL = "http://beta-event.hangame.com";
	sWwwURL = "http://beta--www.hangame.com";	
	CONTEXTMENU = true;
} else {
	sAvatarShopURL = "http://avatar.hangame.com";
	sItemShopURL = "http://item.hangame.com";
	sLoginURL = "http://www.hangame.com";
	sJspLoginURL = "http://id.hangame.com";
	sBBSURL = "http://bbs.hangame.com";
	sStaticURL = "http://static.hangame.com";
	sGameURL = "http://game1.hangame.com";
	sQuaURL = "http://hanqua.hangame.com";
	sMyinfoURL = "http://myinfo.hangame.com";
	sPlusURL = "http://member.hangame.com";
	sMileageURL = "http://mileage.hangame.com";
	sBbsURL = "http://bbs.hangame.com";
	sHompyURL = "http://hompy.hangame.com";
	sHbbsURL = "http://hbbs.hangame.com";
	sEventURL = "http://event.hangame.com";
	sWwwURL = "http://www.hangame.com";		
	CONTEXTMENU = false;
}

/**
 * °³¹ß È¯°æ¿¡ µû¶ó µµ¸ÞÀÎÀ» ¾ò´Â´Ù.
 *
 * ex) getEnvDomain( "event.hangame.com" ) -> °³¹ß: dev-event.hangame.com
 *                                         -> ¾ËÆÄ: alpha-event.hangame.com
 *                                         -> º£Å¸: beta-event.hangame.com
 *                                         -> ¸®¾ó: event.hangame.com
 *
 * devPrefix ÀÎÀÚ
 * - ÇöÀç ½ÇÇà È¯°æÀÌ °³¹ß È¯°æÀÏ °æ¿ì, 'dev-'´ë½Å devPrefix¿¡ ÁÖ¾îÁø °ªÀ¸·Î ´ëÃ¼ÇÑ´Ù.
 *
 * ex) getEnvDomain( "event.hangame.com", "alpha-" ) -> °³¹ß: alpha-event.hangame.com
 */ 
function getEnvDomain( domain, devPrefix ) {
	var add = "";
	var typeDevPrefix = typeof(devPrefix);
	
	if( ENV_isDev ) {
		if( typeDevPrefix != "undefined" && devPrefix != null ) {
			add = devPrefix;
		} else {
			add = "dev-";
		}
	}
	if( ENV_isAlpha ) {
		add = "alpha-";
	}
	if( ENV_isBeta ) {
		add = "beta-";
	}
	
	var envDomain = add + domain;

	return envDomain;
}


/**
 * °ÔÀÓ¹æ¹ý ÆË¾÷Ã¢À» ¿ÀÇÂ
 *
 * gameid: °ÔÀÓ¾ÆÀÌµð (string type) (¼±ÅÃ°¡´É)
 * group: °ÔÀÓ group (css·Î ³ª´©¾îÁ®ÀÖ´Â ±âÁØÀ¸·Î)
 */
function goGuide(gameid, group, topindex, subindex)
{
	var vTopIndex = "01";
	var vSubIndex = "01";
	if( typeof(topindex) != "undefined" ) {
		vTopIndex = topindex;
	}
	if( typeof(subindex) != "undefined" ) {
		vSubIndex = subindex;
	}

	var url = "http://images.hangame.co.kr/hangame/renewal_2006/gameguide/"+group+"/guide_"+gameid+ vTopIndex +"_" + vSubIndex + ".html";
	openWin(url,"guide",800,650,"no");
}

/**
 * ¹ö±×½Å°í ÆË¾÷Ã¢À» ¿ÀÇÂ
 *
 * gameid: °ÔÀÓ¾ÆÀÌµð (string type) (¼±ÅÃ°¡´É)
 */
function goCS(gameid)
{
	if(!LoginError()) return;
	var bugReport = url_cs_main + "/bugsingo/exMailQuestion_popit.asp?game_id=" + gameid;
	openWin(bugReport,"cs",400,550,"no");
}

/**
 * ³» ¾ÆÀÌÅÛ °¡¹æÀ¸·Î ÀÌµ¿
 *
 */
function goMyItem( chkLogin ) {
	var toUrl = "http://" + getEnvDomain("member.hangame.com", "alpha-") + "/myinfo/mygameitem.nhn";
	top.location.href = toUrl;
}

/**
 * °ÔÀÓº° ¾ÆÀÌÅÛ ¼¥ °¡±â
 *
 * gameid: °ÔÀÓ¾ÆÀÌµð (string type)
 * chkLogin: ·Î±×ÀÎ Ã¼Å© ¿©ºÎ (boolean type) (¼±ÅÃ°¡´É)
 *
 */
function goItemShop( gameid, chkLogin ) {
	if( chkLogin == true && !isLogin() ) {
		return false;
	}
	top.location.href = sItemShopURL + "/gameshop.nhn?m=goItem&gameid="+gameid;
}

/*
 * ÆË¾÷Ã¢ Å©±â
 */
var BUY_POPUP_WIDTH = 540;
var BUY_POPUP_HEIGHT = 540;
var PRESENT_POPUP_HEIGHT_FOR_WEB = 606;

/**
 * ¾ÆÀÌÅÛ »ç¿ë ÆË¾÷Ã¢À» ¿ÀÇÂ.
 *
 * itemCode: ¾ÆÀÌÅÛÄÚµå (string type)
 * gameid: °ÔÀÓ¾ÆÀÌµð (string type) (¼±ÅÃ°¡´É)
 * chkLogin: ·Î±×ÀÎ Ã¼Å© ¿©ºÎ (boolean type) (¼±ÅÃ°¡´É)
 *
 */
function goItemUse( itemCode, gameid, chkLogin ) {
	if( chkLogin == true && !isLogin() ) {
		return false;
	}
	openWin( sItemShopURL + "/itemUse.nhn?m=itemUseGate&status=W&itemcode=" + itemCode, "itemuse", BUY_POPUP_WIDTH, BUY_POPUP_HEIGHT);
}


/**
 * ¾ÆÀÌÅÛ ±¸¸Å ÆË¾÷Ã¢À» ¿ÀÇÂ
 *
 * itemCode: ¾ÆÀÌÅÛÄÚµå (string type)
 * gameid: °ÔÀÓ¾ÆÀÌµð (string type) (¼±ÅÃ°¡´É)
 * chkLogin: ·Î±×ÀÎ Ã¼Å© ¿©ºÎ (boolean type) (¼±ÅÃ°¡´É)
 * toPopup: ÆË¾÷ ¿©ºÎ(boolean type. default = true)
 */
function goItemBuy( itemCode, gameid, chkLogin, toPopup ) {
	if( chkLogin == true && !isLogin() ) {
		return false;
	}

	//2005.02.17 ¾ÆÀÌÅÛ ±¸¸Å °æ·Î ÃßÀû
	if (typeof(sGAMEID)=='string') {
		traceid = "ITEM_GP_" + sGAMEID.toUpperCase() + "_1";
	} else if (typeof(traceid)=='string') {
		// nothing
	} else {
		traceid = "";	
	}
	docref = escape(top.location.href);
	var url = sItemShopURL+'/itemBuy.nhn?m=itemBuyi&status=W&itemcode='+itemCode+'&traceid='+traceid+'&docref='+docref;
	
	if( arguments.length > 3 && typeof(toPopup) != "undefined") {
		if( toPopup == false ) {
			location.href = url;
		}			
	} else {		
		openWin( url, 'itemnotice', BUY_POPUP_WIDTH, BUY_POPUP_HEIGHT);
	}
		
	if (typeof(sGAMEID)=='string' && sGAMEID=="msduelgo" && typeof(game_clicknds) == "function" ) {
		game_clicknds("buyitem",'',sItemShopURL+'/itemBuy.nhn?m=itemBuyi&status=W&itemcode=T20&traceid=ITEM_GP_MSDUELGO_1');
	}
}


/**
 * ¾ÆÀÌÅÛ ¼±¹° ÆË¾÷Ã¢À» ¿ÀÇÂ
 *
 * itemCode: ¾ÆÀÌÅÛÄÚµå (string type)
 * gameid: °ÔÀÓ¾ÆÀÌµð (string type) (¼±ÅÃ°¡´É)
 * chkLogin: ·Î±×ÀÎ Ã¼Å© ¿©ºÎ (boolean type) (¼±ÅÃ°¡´É)
 */

function goItemGift( itemCode, gameid, chkLogin ){
	if( chkLogin == true && !isLogin() ) {
		return false;
	}

	//2005.02.17 ¾ÆÀÌÅÛ ±¸¸Å °æ·Î ÃßÀû
	if (typeof(sGAMEID)=='string') {
		traceid = "ITEM_GP_" + sGAMEID.toUpperCase() + "_1";
	} else if (typeof(traceid)=='string') {
		// nothing
	} else {
		traceid = "";	
	}
	
	openWin(sItemShopURL+'/itemPreShop.nhn?m=itemPreShopi&status=W&itemcode=' + itemCode + '&traceid='+traceid,'itemnotice', BUY_POPUP_WIDTH, PRESENT_POPUP_HEIGHT_FOR_WEB);		
	
	if (typeof(sGAMEID)=='string' && sGAMEID=="msduelgo" && typeof(game_clicknds) == "function" ) {
		game_clicknds("giftitem",'',sItemShopURL+'/itemPreShop.nhn?m=itemPreShopi&status=W&itemcode=T20&traceid=ITEM_GP_MSDUELGO_1');
	}
}

/**
 * ¼ÂÆ® ¾ÆÀÌÅÛ ±¸¸Å ÆË¾÷Ã¢À» ¿ÀÇÂ
 *
 * setCode: ¾ÆÀÌÅÛÄÚµå (string type)
 * chkLogin: ·Î±×ÀÎ Ã¼Å© ¿©ºÎ (boolean type) (¼±ÅÃ°¡´É)
 */
function goSetItemBuy( setCode, chkLogin ) {
	if( chkLogin == true && !isLogin() ) {
		return false;
	}
	// docref = escape(top.location.href);
	var docref = sItemShopURL + "/hanGameShop.nhn";	// ¾ÆÀÌÅÛÃøÀ¸·ÎºÎÅÍ Àü´Þ¹ÞÀº ³»¿ë¿¡ µû¸§. ÃßÈÄ º¯°æ

	var traceid = getTraceID(sGAMEID);
	var url = sItemShopURL + "/itemSet.nhn?m=popUpSetItemBuy&setCode=" + setCode + "&status=W";
	url = url + "&docref=" + docref + "&traceid=" + traceid;

	openWin(url,'itemnotice', BUY_POPUP_WIDTH, BUY_POPUP_HEIGHT);
}


/**
 * Plus ¾ÆÀÌÅÛ »ç¿ë
 *
 * membership 			È¸¿øÁ¦ÀÇ ÇÃ·¯½ºÄÚµå
 * status				È£Ãâ °æ·Î(C:Å¬¶ó, W:À¥)
 * cubaMode 			Äí¹Ù ·Î±×¸¦ À§ÇÑ ÆÄ¶ó¹ÌÅÍ
 * isBettingChanceYn 	¹ÙµÏ º£ÆÃÂù½º ¾ÆÀÌÅÛ ¿©ºÎ
 * useOnWebYn			À¥¿¡¼­»ç¿ë °¡´É ¿©ºÎ 
 * isTop				location.top »ç¿ë ¿©ºÎ
 * gameId				ÇÃ·¯½º ¾ÆÀÌÅÛÀ» »ç¿ëÇÑ °ÔÀÓ¾ÆÀÌµð(optional)
 */
function goUsePlus(itemcode, membership, status, cubaMode, isBettingChanceYn, useOnWebYn, isTop, gameId){
	var retval;
	
	if ( isBettingChanceYn == 'Y' ) {
		alert("´ë±¹½Ç Á¢¼Ó ÈÄ º£ÆÃÇÏ±â ÆË¾÷Ã¢¿¡¼­ ¾ÆÀÌÅÛÀ» »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.");
		return;
	} 
	
	if ( useOnWebYn == 'N' ) {
		goUsePlusNotice();
		return;
	} 
	
	retval = confirm("¾ÆÀÌÅÛÀ» »ç¿ëÇÏ½Ã°Ú½À´Ï±î?");
	
	if(retval){
		url = sItemShopURL + "/itemUse.nhn?status=" + status + "&m=";
		url += "usePlusMainItem_p&itemcode=" + itemcode + "&pluscode=" + membership;
		
		//alert(typeof(gameId));
		if (typeof(gameId)=='string') {
			url += "&gameid=" + gameId; // speciallogt.gameid ³²±â±â À§ÇÔ
		}
		
		url += "&docref=" + escape("http://"+location.host+location.pathname  + "&mode=" + cubaMode); // cuba
		
		if (isTop == 'TOP'){
			top.location.href = url;
		} else if (status != 'C') {
			window.open(url,"itempop","width=390 height=600");
		} else {
			location.href = url;
		}
	}
	
	return;
}

/**
 * Plus ¾ÆÀÌÅÛ »ç¿ë(°ÔÀÓ¿¡¼­ ÀÚµ¿ Àû¿ëµÇ´Â ¾ÆÀÌÅÛ)
 */
function goUsePlusNotice(){
	alert("°ÔÀÓ¿¡ Âü¿©ÇÏ½Ã¸é ÀÚµ¿À¸·Î »ç¿ë/Àû¿ë µË´Ï´Ù.");
}

function isLogin() {
	if ( getCookie(CK_MEMBERID) == "" ) {
		return false;
	} else { return true; }
}

function getTraceID(gameid) {
	var traceid = "";
	
	//2005.02.17 ¾ÆÀÌÅÛ ±¸¸Å °æ·Î ÃßÀû
	if (typeof(gameid)=='string') {
		traceid = "ITEM_GP_" + gameid.toUpperCase() + "_1";
	} else if (typeof(traceid)=='string') {
		// nothing
	}
	
	return traceid;
}

/*
 *  ÇÃ·¡½¬ ¼³Ä¡ ÆË¾÷À» ¿ÀÇÂ
 */
function goFlashHelp() {
	var url = sWwwURL + "/popup/flashHelp.jsp";
	openWin(url,"flashguide",512,440,"yes");
}
