//서버호스트명에 따라 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);
}

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");
}
