﻿g_SITELOCAL = "local.";
g_SITEMEMBER = "gametree.co.kr";
g_SITESSLPORT = "";

getServiceDomain();

// url 정보를 담은 JSON 객체
urls = {
    //홈
    m000 : '/',
	// 뉴스
	m100 : '/Notice/List.aspx',
	m101 : '/Notice/List.aspx',	// 공지사항
	m102 : '/Notice/EventList.aspx?flag=1',	// 이벤트
	m103 : '/Update/List.aspx',		// 업데이트
	// 커뮤니티
	m200 : '/Community/List.aspx?BoardType=1',
	//m201 : '/Community/List.aspx',	// 전체 -> 삭제
	m201 : '/Community/List.aspx?BoardType=1',	// 일상이야기 -> 자유게시판
	m202 : '/Community/List.aspx?BoardType=2',	// 묻고 답하기 -> 고수에게 물어봐
	m203 : '/Community/List.aspx?BoardType=3',	// 스크린 샷
	m204 : '/Community/List.aspx?BoardType=4',	// UCC팡야 -> 유저동영상
	//m206 : '/Community/List.aspx?BoardType=5',	// 나의 노하우 -> 지난 게시물(메뉴에서 빠짐)
	m205 : '/Community/List.aspx?BoardType=6',	// GM홀릭
	// 게임정보
	m300 : '/GameGuide/GameMode.aspx',
	m301 : 'window.open("/Events/OpenTournament/info1.html", "_blank")', //'/GameGuide/Season4Info.aspx',	// 시즌4안내(팝업창)
	m302 : '/GameGuide/GameMode.aspx',	// 게임모드
	m303 : '/GameGuide/Character.aspx',	// 캐릭터&캐디
	m304 : '/GameGuide/ItemList.aspx',	// 아이템
	m305 : '/GameGuide/Course.aspx',	// 코스
	m306 : '/GameGuide/Level.aspx',	// 레벨
	m307 : '/GameGuide/System.aspx',	// 시스템
	// 길드
	m400 : '/Guild/Default.aspx',
	m401 : '/Guild/Default.aspx',	// 길드종합
	m402 : '/Guild/GuildList.aspx',	// 길드목록
	m403 : '/Guild/AD/List.aspx?BoardType=7',	// 길드알리기
	//m404 : '/Guild/Ranking.aspx',	// 길드랭킹
	m404 : '/Guild/MatchList.aspx',	// 길드대전
	// 랭킹
	m500 : 'alert("서비스 준비중입니다.");', //'/Ranking/Season.aspx',
	m501 : 'alert("서비스 준비중입니다.");', //'/Ranking/Season.aspx?Season=4',	// 시즌4랭킹
	m502 : 'alert("서비스 준비중입니다.");', //'/Ranking/Season.aspx?Season=3',	// 시즌3랭킹
	m503 : 'alert("서비스 준비중입니다.");', //'/Ranking/Season.aspx?Season=2',	// 시즌2랭킹
	m504 : 'alert("서비스 준비중입니다.");', // 개인랭킹 (시즌5)
	m505 : 'alert("서비스 준비중입니다.");', // 길드랭킹 (시즌5)
	m506 : 'alert("서비스 준비중입니다.");', // 랭킹의 전당 (시즌5)
	// 대회
	//m600 : 'alert("서비스 준비중입니다.");',  // 준비중
//	m600 : '/Tournament/Apply.aspx',
//	m601 : '/Tournament/Apply.aspx',
//	m602 : '/Tournament/MatchList.aspx',
//	m603 : '/Tournament/MatchSchedule.aspx',
//	m604 : '/Tournament/HonorList.aspx?BoardType=8',
    m600 : '/Tournament/Masters/Apply.aspx',
	m601 : '/Tournament/Masters/Apply.aspx',
    m602 : '/Tournament/ChampionShip/Apply.aspx',
	// 자료실
	m700 : '/Download/Download.aspx',
	m701 : '/Download/Download.aspx',		// 다운로드
	m702 : '/Download/Movie.aspx',	// 동영상
	m703 : '/Download/Fansitekit.aspx',	// 팬사이트킷
	m704 : '/Download/WallPaper.aspx',	// 월페이퍼
	// 고객센터
	m800 : '/Customer/Faq.aspx',
	m802 : '/Customer/Faq.aspx',	 // FAQ
	m801 : '/Customer/AskWrite.aspx',	 // 1:1 문의
	//m803 : 'MyInfo()',	 // 내정보
	m803 : '/Customer/Operation.aspx',	 // 운영정보
	// 초보자가이드
	m900 : '/Beginner/World.aspx',  // 초보자 가이드
	m901 : '/Beginner/World.aspx',  // 팡야속으로
	m902 : '/Beginner/Practice.aspx',  // 기본 익히기
	m903 : '/Beginner/Upgrade.aspx',  // 실력 키우기 -> 능력업그레이드
	m904 : '/Beginner/Rounding.aspx',  // 라운딩 노하우
	m905 : '/Beginner/Scoreinfo.aspx'  // 팡/스코어 안내

}

// 메뉴이동 실행
function m(c, swc) {

    if (swc) Cookie.set('autoOpen','1'); else Cookie.remove('autoOpen');

	var go_url = c ? 'urls["m'+c+'"]' : 'urls["m000"]';
	var _url = eval(go_url) || '/';
	if (/[\(\)]/.test(_url)) {
		eval(_url); // url 정보가 함수명이면 함수를 실행
	} else if (_url) {
        var linkElem = document.createElement ("a");
        if (linkElem.click != undefined) {
            document.body.appendChild(linkElem);
            linkElem.href = _url;
            linkElem.click();
        } else {
            location.href = _url;
        }
	}
}

// 초보자가이드 팝업
function beginnerGuide() {
	var top = (screen.height-700)/2 || 100;
	var left = (screen.width-900)/2 || 100;
	var Pop = window.open("/Img/flash/guide/GameGuide.aspx","_blank","width=900,height=650,top="+top+",left="+left)
	if(!Pop) alert('초보자가이드는 팝업차단이 되어있으면 보실 수 없습니다.\n팝업차단을 해제해 주세요.')
}


/* URL Handle */
function getHTTPS(siteHost)
{
	var ret = "https://";
	if (typeof(g_SITELOCAL)=="string" && g_SITELOCAL != ""){
		var arr = g_SITELOCAL.split('|');
		for(var i=0; i < arr.length; i++){
			if ( siteHost.indexOf( $S(arr[i]) ) > -1 ){
				ret = "http://";
				break;
			}
		}
	}
	return ret;
}

function getSiteHost(url)
{
	var ret = "";
	var idx = url.indexOf("://");
	if (idx > -1){
		var idx2 = url.substring(idx+3, url.length).indexOf("/");
		if (idx2 > -1){
			ret = url.substring(idx+3, idx2 + (idx+3));
		}else{
			ret = url.substring(idx+3, url.length);
		}
		ret = ret.toLowerCase();
	}
	return ret;
}

function getServiceSite()
{
    var url = window.location;
    url = url.toString();
	return ( "http://" + getSiteHost(url) );
}

function getServiceDomain()
{
    var url = document.domain;
    url = url.toLowerCase();

    var arr = url.split('.');

    if (arr.length > 0) {
    g_SITEMEMBER = arr[0] + '.gametree.co.kr';
    }

//    if(arr.length > 0 && (arr[0] == 'my' || arr[0] == 'local'))
//    {
//        g_SITEMEMBER = 'http://member.ntreev.com';
//    }
//    else if(arr.length > 0 && (arr[0] == "dev"))
//    {
//        g_SITELOCAL  = 'dev.';
//        g_SITEMEMBER = 'http://member.ntreev.com';
//    }
//    else if(arr.length > 0 && (arr[0] == "qa"))
//    {
//        g_SITEMEMBER = 'http://member.ntreev.com';
//    }
//    else
//    {
//        g_SITEMEMBER = 'https://member.ntreev.com';
//    }
    // 2008.08.01 by colakongju
	// 현재 도메인 기준으로 글로벌 변수 셋팅
}

function getSecureSite()
{
    var url = window.location;
    url = url.toString();
	return ( getHTTPS(url) + getSiteHost(url) );
}
function getSecureSiteHTTP()
{
    var url = window.location;
    url = url.toString();
	return ( "http://" + getSiteHost(url) );
}
/*-------------------------------------------------------------------*/


/* Member */
function NtreevLogin() {
    Ns.Login.get();
}

function NateLogin() {
    var nate_redirect_url = 'http://ntreev.nate.com/gateway.aspx?sn=2';
    var nate_error_url = 'http://ntreev.nate.com/loginfail.aspx?sn=2';

    var frm = document.forms[0];
	//var login_email = $('login_email');
	var pwd = $('PASSWD');
	var secure = $('nate_secure');
	var redirect = $('redirect');
	var error = $('errorPage');
	var r_url = $('r_url');
	var hiddenID = $('ID');
	var nate_id = $('nate_id');
	var nate_domain = $('nate_domain');
	var nate_saveid = $('nate_saveid');

    if ($T(nate_id.value) == '') {
		alert('아이디를 입력해 주세요.');
		nate_id.focus();
		return;
	}
	if ($T(pwd.value) == '') {
		alert('비밀번호를 입력해 주세요.');
		pwd.focus();
		return;
	}

    /*
    hiddenID.value = login_email.value;
    nate_domain.value = '@' + login_email.value.split('@')[1];
    if (nate_domain.value == '@nate.com') {
        nate_domain.value = '';
        hiddenID.value = login_email.value.split('@')[0];
    }
    */

    hiddenID.value = nate_id.value + nate_domain[nate_domain.selectedIndex].value;
	nate_redirect_url += (nate_saveid.checked) ? '&save=Y' : '&save=N';

	if (secure.checked) {
		frm.action = 'https://xo.nate.com/servlets/LoginServlet';
	}
	else {
		frm.action = 'http://xo.nate.com/servlets/LoginServlet';
	}

	redirect.value = nate_redirect_url +'&r_url=' + encodeURIComponent(r_url.value);
	error.value = nate_error_url;

	frm.__VIEWSTATE.value = '';
	frm.submit();
}

function RechargeTreeCash(method) {
    //var url = g_SITEMEMBER + '/Payment/AgreementState.aspx?Method='+ method;
    //window.open(url, 'Recharge', 'width=510, height=550');
    Ns.TreeCash.recharge(method);
}

function Logout() {
    Ns.Login.out();
}

function FindId() {
    //var url = g_SITEMEMBER + '/Info/FindId.aspx';
    //var name = 'FindIdPopup';
    //var features = 'width=460,height=254,scrollbar=0,status=1,resizable=0';
    //var winFindId = window.open(url, name, features);
    Ns.Content.find();
}

function NateFindId() {
    var url = 'http://helpdesk.nate.com/faq/exMemberInfo.asp?r_url=https://member.nate.com/sccustomer/join/nate/find/find_index.jsp&mode=show';
    window.open(url);
}

function SignUp()
{
    Ns.Content.join();
//    var SignUpURL = g_SITEMEMBER + '/SignUp/Agreement.aspx?rsn=9';
//
//    var target = window.opener;
//    if (target != null && !target.closed){
//
//        var sameDomain = false;
//        var thisDomain = document.domain;
//        var openerDomain = "";
//        try {
//            openerDomain = opener.document.domain;
//            if (thisDomain == openerDomain) sameDomain = true;
//        }
//        catch (e) {
//            // alert(e.message);
//            // opener의 도메인이 다를 경우 e.message는 다음과 같습니다.
//            // IE 6/7 : 액세스가 거부되었습니다.
//            // 크롬 2.0.172.33 : Cannot read property 'domain' of undefined
//            // FireFox 2.0.0.14 : undefined -_-;; 도구의 오류정보를 보면 uncaught exception: HTMLDocument.domain 1 이라고 나옴.
//            // Opera 9.64 : Security error: attempted to read protected variable
//        }
//        //alert("openerDomain : " + openerDomain);
//        //alert("thisDomain : " + thisDomain);
//        //alert("sameDomain : " + sameDomain);
//
//        // 팝업으로 떳을 때
//        if (sameDomain) {
//            if (target.parent != null) {
//                target = target.parent;
//            }
//            target.location = SignUpURL;
//
//            CloseWindow();
//        }
//        // 검색사이트에서 새창으로 떳을 때
//        else
//        {
//            document.location = SignUpURL;
//        }
//    }
//    else {
//        document.location = SignUpURL;
//    }
}

function CloseWindow()
{
    if (/MSIE/.test(navigator.userAgent)) {
        //Explorer 7이상일때
        if(navigator.appVersion.indexOf("MSIE 7.0")>=0) {
            window.open('about:blank','_self').close();
        }
        //Explorer 7이하일때
        else {
            window.opener = self;
            self.close();
        }
    }
    else {
        // IE 이외의 브라우저
        this.close();
    }
}

function MyInfo()
{
    //document.location = g_SITEMEMBER + '/Info/Default.aspx?rsn=9';
    Ns.Content.info();
}

function chkEnterForLogin(e, loginType){
	var key = window.event ? e.keyCode : e.which;
	if (key == 13){
	    if (loginType.toLowerCase() == 'ntreev') {
		    NtreevLogin();
		} else {
		    NateLogin();
		}
	}
}
/*-------------------------------------------------------------------*/


/* Footer */
function ShowNtreevHomepage() {
    window.open('http://www.ntreev.com','ntreevpopup');
}
function ShowPolicy() {
    window.open('http://' + g_SITEMEMBER + '/policy/policy.aspx','ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no');
}
function ShowPrivacy() {
    window.open('http://'  + g_SITEMEMBER + '/policy/privacy.aspx','ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no');
}
function ShowYouthHelp() {
    window.open('http://' + g_SITEMEMBER + '/policy/youthhelp.aspx?mm=N','ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no');
}
function ShowRefusal() {
    window.open('http://' + g_SITEMEMBER + '/policy/refusal.aspx','ntreevpopup','width=459,height=254,statusbar=no,scrollbars=no,toolbar=no,resizable=no');
}
function ShowRefundPolicy() {
    window.open('http://' + g_SITEMEMBER + '/policy/refund.aspx','ntreevpopup','width=589,height=554,statusbar=no,scrollbars=no,toolbar=no,resizable=no');
}
/*-------------------------------------------------------------------*/


/* download */
function NeffyDownload() {
    var url = getServiceSite() + '/Download/Neffy/Neffy.aspx';
	window.open(url,'','width=418,height=789');
}

/* global search box */
function chkGlobalSearchKeyword() {
    if ($T($F('txtGlobalSearchKeyword')) == '') {
        alert ('검색어를 입력해 주세요.');
        return false;
    }

    var keyword = $('txtGlobalSearchKeyword');
    if(keyword.value.size() > 40)
	{
	    alert('검색어는 20자까지만 입력 가능합니다.');
	    return false;
	}

    getGlobalSearchResult();
}

function getGlobalSearchResult() {

    if ($('rdoGlobalSearch1').checked) {
        location.href = '/GameGuide/GameRushList.aspx?SearchArea=All&Keyword=' + encodeURIComponent($F('txtGlobalSearchKeyword'));

    } else {
        location.href = '/Community/Qna.aspx?SearchArea=All&Keyword=' + encodeURIComponent($F('txtGlobalSearchKeyword'));
    }
}

function chkEnterForGlobalSearch(e) {
	var key = window.event ? e.keyCode : e.which;
	if (key == 13) {
	    chkGlobalSearchKeyword();
	}
	else {
	    return false;
	}
}

/* coupon */
function EventTrickzine() {
    var url = '/Events/200808_Coupon/popup_trickzine.aspx';
	var name = 'popup_trickzine';
	var features = 'width=460,height=270,scrollbars=no,status=no,menubar=no,toolbar=no,resizable=no';
	var popup = window.open(url, name, features);
}
/*-------------------------------------------------------------------*/
function OpenGuild(gid)
{
    addprefix = "";
    var url = document.domain;
    url = url.toLowerCase();
    var arr = url.split('.');

    if(arr.length > 0)
    {
        if (arr[0] != "pangya")
            addprefix = arr[0] + ".";
    }
     window.open("http://" + addprefix + "club.pangya.gametree.co.kr/" + gid, "_blank", "");
    return false;
}

function OpenGuildMarkMenu(gidx)
{
    addprefix = "";
    var url = document.domain;
    url = url.toLowerCase();
    var arr = url.split('.');

    if(arr.length > 0)
    {
        if (arr[0] != "pangya")
            addprefix = arr[0] + ".";
    }
    window.open("http://" + addprefix + "club.pangya.gametree.co.kr/GuildManage/GuildInfo.aspx?gidx=" + gidx, "_blank", "");
    return false;
}
/* -- sub main rolling banner action -------------------------------------------------------
	[ _url : 이동할 주소 ] // 미지정시 작동중지
	[ _param : 옵션 ( target|width|height|top|left ) ] // 미지정시 _self 로 작동
------------------------------------------------------------------------------------------ */
function _event(_url,_param) {
	if ( !_url ) return false
	try { var _url = (eval(_url)) ? eval(_url) : _url; } catch (e) {}
	var _type = _param ? _param.split('\|') : '_self';
	var _flag = _type[1] || _type[2] ? "scrollbars=no,toolbar=no,resizable=no" : '';
	var _width  = _type[1] ? ',width='+_type[1] : '';
	var _height = _type[2] ? ',height='+_type[2] : '';
	var _top = _type[3] ? ',top='+_type[3] : '';
	var _left = _type[4] ? ',left='+_type[4] : '';
	if (_type[0] == '_self' || !_type[0]) {
		location.href = _url
	} else if (_type[0] == '_blank') {
		eval('var _popupIf = window.open("'+_url+'","'+_type[0]+'","'+_flag+_width+_height+_top+_left+'")')
		if(!_popupIf) alert("현재 팝업 차단이 설정되어 있습니다.\n정상적인 사용을 위해선 차단을 해제하셔야 합니다.")
	} else if (eval('window.'+_type[0])) {
		alert('a')
		eval('try{'+_type[0]+'.location.href="'+_url+'"; } catch(e) {}')
	} else {
		eval('var '+_type[0]+' = window.open("'+_url+'","'+_type[0]+'","scrollbars=no,toolbar=no,resizable=no'+_width+_height+_top+_left+'")')
		eval('if(!'+_type[0]+') alert("현재 팝업 차단이 설정되어 있습니다.\\n정상적인 사용을 위해선 차단을 해제하셔야 합니다.")')
	}
}
/* -- main rolling banner action ----------------------------------------------------------
	[ _url : 이동할 주소 ] // 미지정시 작동중지
------------------------------------------------------------------------------------------ */
function popOpen(popurl) {
	if (!popurl) return false;
	//alert('요청받은 url\n' + popurl);
	location.href = popurl;
}
