﻿/*
 * C9 전역 자바스크립트 함수 선언파일
 * Author : KyungHwan, Park
 
 */

/** 개발 환경에 따른 도메인 얻기 */
var ENV_isLocal = location.href.indexOf("http://local-") > -1 || location.href.indexOf("https://local-") > -1;
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;

function getEnvDomain( domain, devPrefix ) {
	var add = "";
	var typeDevPrefix = typeof(devPrefix);
	
	if( ENV_isLocal ) {
		if( typeDevPrefix != "undefined" && devPrefix != null ) {
			add = devPrefix;
		} else {
			add = "local-";
		}
	}
	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;
}

/** 메뉴 이동 */
function goMenu(name) {
	switch(name) {
		case 'main' : location.href="/index.nhn"; break;
		case 'representCafe' : window.open("http://cafe.naver.com/thec9.cafe", "cate"); break;
		case 'hangame' : location.href="http://www.hangame.com"; break;
		
		// 새소식
		case 'notice' : location.href="/news/noticeBoard.nhn"; break;
		case 'event' : location.href="/news/eventBoard.nhn"; break;
		
		// 가이드
		case 'introduceWorld' : location.href="/guide/introduceWorld.nhn"; break;
		case 'introduceSpeciality' : location.href="/guide/introduceSpeciality.nhn"; break;
		case 'characterInfo' : location.href="/guide/characterInfo.nhn"; break;
		case 'beginnerInfo' : location.href="/guide/beginnerInfo.nhn"; break;
		case 'controlInfo' : location.href="/guide/controlInfo.nhn"; break;
		case 'systemInfo' : location.href="/guide/systemInfo.nhn"; break;
		case 'stageInfo' : location.href="/guide/gameInfo.nhn?m=selectStageInfo"; break;
		case 'itemInfo' : location.href="/guide/gameInfo.nhn?m=selectItemInfo"; break;
		case 'skillInfo' : location.href="/guide/gameInfo.nhn?m=selectSkillInfo"; break;
		case 'questInfo' : location.href="/guide/gameInfo.nhn?m=selectQuestInfo"; break;
		case 'makerInfo' : location.href="/guide/gameInfo.nhn?m=selectMakerInfo"; break;
		case 'legendInfo' : location.href="/guide/gameInfo.nhn?m=selectLegendInfo"; break;
		case 'townInfo' : location.href="/guide/gameInfo.nhn?m=selectTownInfo"; break;
		
		// 웹진
		case 'webzineInfo' : location.href="/guide/webzineInfo.nhn?m=webzineInfo"; break;
		case 'gamemecaInfo' : location.href="/guide/webzineInfo.nhn?m=webzineInfo&webzineid=1"; break;
		case 'gamechosonInfo' : location.href="/guide/webzineInfo.nhn?m=webzineInfo&webzineid=2"; break;
		case 'tigInfo' : location.href="/guide/webzineInfo.nhn?m=webzineInfo&webzineid=3"; break;
		
		// 커뮤니티
		case 'storyBoard' : location.href="/community/storyBoard.nhn"; break;
		case 'eventBoard' : location.href="/community/eventBoard.nhn"; break;
		case 'ourStoryBoard' : location.href="/community/ourStoryBoard.nhn"; break;
		case 'c9ucc' : location.href="/community/uccBoard.nhn"; break;
		case 'pvpRanking' : goRankingMenu("/community/ranking.nhn?m=pvpRankingClassicInfo"); break;
		case 'rankingDestroy' : goRankingMenu("/community/ranking.nhn?m=rankingDestroyInfo"); break;
		//case 'guildRanking' : goRankingMenu("/community/ranking.nhn?m=guildRankingInfo"); break;
		//case 'levelRanking' : goRankingMenu("/community/ranking.nhn?m=levelRankingInfo"); break;
		case 'pvpRankingClassic' : goRankingMenu("/community/ranking.nhn?m=pvpRankingClassicInfo"); break;
		case 'promoter' : location.href="/community/promoter.nhn"; break;
		case 'testServer' : location.href="/community/testServer.nhn"; break;
		case 'championshipRanking' : location.href="/community/ranking.nhn?m=pvpChampionshipRanking"; break;
		
		// 길드
		case 'guildHome' : location.href="/guild/guildHome.nhn"; break;
		case 'guildList' : location.href="/guild/guildList.nhn?m=list"; break;
		case 'guildBoard' : location.href="/guild/guildBoard.nhn"; break;
		
		// 다운로드
		case 'download' : location.href="/pds/download.nhn"; break;
		case 'multimedia' : location.href="/pds/multimedia.nhn"; break;
		
		// 고객센터
		case 'faq' : location.href="/cscenter/faq.nhn"; break;																
		case 'email' : location.href="/cscenter/email.nhn"; break;
		case 'myQuestion' : location.href="/cscenter/myQuestion.nhn"; break;
		case 'idembez' : location.href="/idembez.nhn"; break;
		case 'security' : location.href="/cscenter/security.nhn"; break;
		case 'policy' : location.href="/cscenter/policy.nhn"; break;
		
		// store
		case 'itemShop' : location.href="/shop/purpleshop.nhn"; break;
		case 'itemList' : location.href="/shop/purpleshop.nhn?m=branchlist&branchId=shop01"; break;
		case 'shopGuide' : location.href="/shop/shopGuide.nhn"; break;
	}
	
}

/** 랭킹 메뉴 링크 */
function goRankingMenu(url) {
	if(isHangameLogined()) {
		location.href = url;
	} else {
		openPopupLoginForm(null,null,'B');
	}
}

/** 서브 메뉴 보이기 */
function showSubMenu(menuName) {
	var menu = document.getElementById(menuName);
	if(menu.style.display == "none") {
		menu.style.display = "block";
	}else {
		menu.style.display = "none";
	}
}

/** 자동사양체크 */
function goUserPcCheck() {
	WindowLeft = (screen.width - 593)/2;
	WindowTop = (screen.height - 188)/2;
	window.open("/common/publish/popupSpecAnalyzer.jsp?action=/pds/download.nhn?m=specAnalyze","pccheck","scrollbars=no,width=550, height=400, top="+WindowTop+", left="+WindowLeft);
}

/** 마이페이지 쿠폰 리스트 */
function goCouponList(isusable, couponType) {
	location.href="/mypage.nhn?m=couponList&isusable=" + isusable + "&couponType=" + couponType;
}

/** 쿠폰사용 */
function useCoupon(url, couponCode) {
	openWin(url + "/coupon.nhn?m=use&code=" + couponCode, "couponUse" ,400, 560, "auto");
}

/** 모든 쿠폰 보기 */
function allCoupon(url) {
	window.open(url + "/service/index.nhn", "hangame");
}

/** Family Site */
function goFamilySite(siteNum) {
	if(typeof(siteNum) == "undefined"){
		siteNum = document.getElementById("familySite").value;
	}
	var goUrl;
	if(siteNum == '1') {
		goUrl = "http://cafe.naver.com/thec9.cafe";
	} else if(siteNum == '2') {
		goUrl = "http://www.thisisgame.com/c9/index.php";
	} else if(siteNum == '3') {
		goUrl = "http://c9.gamechosun.co.kr/";
	}
	if(siteNum >= 1 && siteNum <= 3) {
		window.open(goUrl, "familySite");
	}
}

/** 팝업(쿠키체크) */
function popupManager(url, cookie_name, width, height) {
	if (getCookie(cookie_name) != "1") {
		openWin(url, cookie_name, width, height, "auto");
	}
}

/** 랭킹페이지 바로가기 */
function goRankingPage(method) {
	var url = "/community/ranking.nhn?m=" + method;
	window.open(url,"rankingPage","fullscreen, enubar=yes, toolbar=yes, location=yes, status=yes, resizble=yes, scrollbars=yes");
}

/** MyC9 */
function goMyC9(gubun, userId) {
	var url = 'http://' + getEnvDomain('c9.hangame.com') + '/mypage.nhn?m=';
	if(gubun != null) url += gubun;
	else {
		url += 'privateInfo';
	}
	
	if(typeof(userId) != "undefined") {
		url += '&memberid=' + userId;
	}
	
	openWin(url, "MyC9", 700, 500, "auto");
}

/** 길드페이지 바로가기 */
function goGuildPage(guildName, serverId) {
	var url = "/guild/guildList.nhn?m=list&searchWord=" + guildName + "&serverId=0" + serverId;
	window.open(url,"guildPage","fullscreen, enubar=yes, toolbar=yes, location=yes, status=yes, resizble=yes, scrollbars=yes");
}
