﻿var rootPath = '/';

// Website 설정 참조 (참조가 안될 경우 직접 처리할 것)
if (Website) {
    if (Website.RootPath) {
        rootPath = Website.RootPath;
    }
}

function IsLoginUser() {
    return (UI_LOGIN && UI_LOGIN == true);
}

var WebsiteMenu = {
    0:'',
    1:'default.aspx',   // 메인페이지
    4:'',   //  - 게임실행

    100:'news/notice.aspx', //NEWS
    101:'news/notice.aspx', //공지사항
    102:'news/update.aspx', //업데이트
    103:'news/event.aspx', //이벤트
    104:'news/pressrelease.aspx', //보도자료
    105:'news/devstory.aspx', //개발자노트

    200:'guide/guide.aspx', //GUIDE
    201:'guide/guide.aspx', //초보자가이드
    202:'guide/feature.aspx', //게임특징
    203: 'guide/pc_intro.aspx', //캐릭터소개
    204: 'guide/story.aspx', //스토리소개

    300:'community/userbbs.aspx', //COMMUNITY
    301:'community/userbbs.aspx', //자유게시판
    302:'trade/web/itemlist.aspx', //물품거래소
    303:'community/knowledgemain.aspx', //지식거래소
    313:'community/knowledge.aspx?list=myqst', //내 지식거래
    304:'community/fansite.aspx', //팬사이트
    305:'community/guild.aspx', //길드
    306:'community/guildsearch.aspx', //길드검색
    307:'community/guildarticle.aspx', //길드홍보

    400: 'ucc/usergallerymain.aspx', //UCC게시판
    401: 'ucc/usergallerymain.aspx?category=1',   //UCC게시판 스크린샷
    402: 'ucc/usergallerymain.aspx?category=2',   //UCC게시판 팬아트
    403: 'ucc/cartoonmain.aspx',   //UCC게시판 연재만화
    404: 'ucc/usermovie.aspx?category=4',   //UCC게시판 동영상

    500:'downloads/download.aspx', //DOWNLOADS
    501:'downloads/download.aspx', //다운로드
    502:'downloads/movie.aspx', //동영상
    503:'downloads/wallpaper.aspx', //월페이퍼
    504:'downloads/screenshot.aspx', //스크린샷
    505:'downloads/artwork.aspx', //아트워크

//    500: 'http://heroes.nexon.com/event/2009package/', //SHOP
//    501:'', //아이템샵
//    502:'', //장바구니
//    503:'', //구매내역

    600:'support/faq.aspx', //SUPPORT
    601:'support/faq.aspx', //자주묻는질문
    602:'support/bugreport.aspx', //버그리포트
    603:'support/proposal.aspx', //건의사항
    604:'support/policy.aspx', //운영정책

    800:'diary/character.aspx', //개인메뉴
    801:'diary/character.aspx', //캐릭터설정
    802:'diary/coupon.aspx', //쿠폰박스
    803:'diary/shortcut.aspx', //단축키설정

    900:'', //Quick
    901: 'http://help.nexon.com/help/page/nx.aspx?url=uotp/info', //U-OTP
    902: '/support/serverreport.aspx' //U-OTP
};

function menu(menuId, category) {
    switch(menuId) {
        case 4: //  - 게임실행
            if (!IsLoginUser()) {
		        alert('로그인 하신 후 이용해주세요.');
		        return;
		    }
		    LaunchGame();
            break;
        case 202:
        case 204:
            var url = rootPath + WebsiteMenu[menuId] + '?guide=' + ((category > 0) ? category : 1);
            location.href = url;
            break;
//        case 302:
//            if (category == 3) {
//                var url = rootPath + 'community/usermovie.aspx?category=' + category;
//                location.href = url;
//                break;
//            }
        case 306:
        case 312:
            var url = rootPath + WebsiteMenu[menuId] + '?category=' + ((category > 0) ? category : 1);
            location.href = url;
            break;
        case 307:
            var url = rootPath + WebsiteMenu[menuId] + '?category=' + category;
            location.href = url;
            break;
        case 314:   // 내 지식거래
//        case 403:
//            alert('준비중 입니다.');
//            return;
//            break;        
        case 602:     // 버그리포트
        case 603:
		    if (!IsLoginUser()) {
		        alert('로그인 하신 후 이용해주세요.');
		        return;
		    }
		    location.href = rootPath + WebsiteMenu[menuId];
		    break;
		case 800:     // 다이어리
		    menuId = 801;
	    case 801:
	    case 802:
	    case 803:
	        if (!IsLoginUser()) {
	            alert('로그인 하신 후 이용해주세요.');
	            return;
	        }
	        else{
	            window.open(rootPath + WebsiteMenu[menuId], 'Diary', 'toolbars=0,menubars=0,status=0,scrollbars=1,width=817,height=600,top=0,left=0');
	            return;
	        }

	    case 901:
	        window.open(WebsiteMenu[menuId]);
	        break;
	    case 902:
	        window.open(WebsiteMenu[menuId], 'servereportWin', 'width=502,height=523,scrollbars=no,resizable=no');	        
	        break;
		default:
		    location.href = rootPath + WebsiteMenu[menuId];
		    break;
    }
}

function ShowMemo() {
    NgbNote.OpenNotebox('', ''); 
}

function SendMemo(game, character, server) {
    var serverName = (server) ? server : '프리미어';
    var fullName = '['+ serverName +']' + character; 
    NgbNote.OpenNoteSend(game, escape(fullName));
}

function IsReservedUser() {
    $.get(rootPath + 'Common/IsReservedUser.aspx', null, function(data, status) {
        if(status == "success") {
            switch(data) {
                case "true":
                    alert('캐릭터명을 선점하실 수 있습니다.\n\n공지를 통해 캐릭터명 선점이 가능한 일정과 방법을 확인하여 주세요.');
                    break;
                case "false":
                    alert('캐릭터명 선점 대상이 아닙니다. ');
                    break;
                case "logout":
                    alert('로그인 하신 후 이용해주세요.');
                    break;
                default:
                    break;
            }
        }
        else {
            alert('일시적인 오류로 캐릭터명 선점 여부를 확인하지 못하였습니다.\n\n잠시 후 다시 이용해주세요.');
        }
    });
}

function ChangeMasterCharacter(gamecode, no, popup, name) {
    if (confirm("'"+ name +"' 캐릭터를 대표캐릭터로 설정하시겠습니까?")) {
        var url = location.href;
        if (popup == true && location.search.indexOf('reload=Y') < 0) {
            url += (location.search == '') ? '?' : '&';
            url += 'reload=Y';
        }
        
        location.href = rootPath +'Common/ChangeMasterCharacter.aspx?gamecode='+gamecode+'&cn='+ no +'&rurl='+ escape(url);
    }
    else {
        if (!popup) {
            location.href = location.href;
        }
    }
}

function ShowPlayerInfo(nxOid, charName) {
    var url = rootPath + 'Common/Achievement/CharacterInfo.aspx?ServerCode=1&nxOid=' + nxOid + '&GameID=' + escape(charName);
    window.open(url, 'characterInfoWin', 'width=800,height=345,scrollbars=no,resizable=no');
}

// 팝업:튜토리얼가이드
function TutorialGuide(index) {
    var url = 'http://tutorial.heroes.nexon.com';
    if (index) {
        url += '?'+ index;
    }
    var feature = (navigator.userAgent.indexOf("MSIE 6") > 0) ? 'width=416,height=458' : 'width=420,height=462';
    feature += ',statusbar=yes,menubar=no,location=no,scrollbars=no,resizable=no';
    window.open(url,'tutorialguide', feature);
}

// 팝업:서바이벌가이드
function SurvivalGuide(index) {
    var url = 'http://guide.heroes.nexon.com';
    if (index) {
        url += '?'+ index;
    }

    var feature = (navigator.userAgent.indexOf("MSIE 6") > 0) ? 'width=416,height=576' : 'width=420,height=580';
    feature += ',statusbar=yes,menubar=no,location=no,scrollbars=no,resizable=no';
    window.open(url, 'survivalguide', feature);
}

// PcCheck :: PC사양 자가 진단
function PcCheck() {
    window.open(rootPath +'downloads/Diagnostics.aspx', 'PcCheck', 'toolbars=0,menubars=0,status=0,scrollbars=0,width=700,height=522,top=0,left=0');
}

function ShowAnswerForm(postNo, answerNo) {
    if (!IsLoginUser()) {
        alert('로그인 하신 후 이용해주세요.');
        return;
    }
    var url = rootPath + 'Community/KnowledgeAnswer.aspx?'+ BbsConstants.KeyName_PostNo +'='+ postNo;
    if (answerNo > 0) {
        url += '&'+ BbsConstants.KeyName_AnswerNo +'='+ answerNo;
    }
    window.open(url, 'knowledgeAnswer', 'width=532, height=523, scrollbars=no, status=no, resizable=no');
}

function DeleteAnswer(bbs, post, answer) {
    if (confirm('답변을 삭제하시겠습니까?')) {
        var url = rootPath + 'Common/BBS/AnswerProcessing.aspx';
        $.get(url, {bn:bbs,no:post,an:answer,mode:'delete'}, function(data, status) {
            if(status == "success") {
                if (data == "ok") {
                    alert('답변을 삭제하였습니다.');
                    location.href = location.href;
                }
                else {
                    switch(data) {
                        case "logout":
                            alert("로그인 하신 후 이용해 주세요.");
                            break;
                        case "not_allowed":
                            alert("작성자만 삭제하실 수 있습니다.");
                            break;
                        case "already_choose":
                            alert("채택된 답변은 삭제할 수 없습니다.");
                            break;
                        case "param_error":
                            alert("필수 정보가 누락되었습니다.");
                            break;
                        default:
                            alert("예외가 발생하여 답변을 삭제하지 못하였습니다.["+ data +"]");
                            break;
                    }
                }
            }
            else {
                alert("일시적인 오류로 인하여 답변을 삭제하지 못하였습니다.");
            }
        }, "text");
    }
}

function ChoiceAnswer(bbs, post, answer) {
    if (confirm('선택한 답변을 채택하시겠습니까?')) {
        var url = rootPath + 'Common/BBS/AnswerProcessing.aspx';
        $.get(url, {bn:bbs,no:post,an:answer,mode:'choice'}, function(data, status) {
            if(status == "success") {
                if (data == "ok") {
                    alert('답변을 채택했습니다.');
                    location.href = location.href;
                }
                else {
                    switch(data) {
                        case "logout":
                            alert("로그인 하신 후 이용해 주세요.");
                            break;
                        case "not_allowed":
                            alert("질문 작성자만 답변 채택을 할 수 있습니다.");
                            break;
                        case "already_choose":
                            alert("이미 채택한 답변이 존재합니다.");
                            location.href = location.href;
                            break;
                        case "param_error":
                            alert("필수 정보가 누락되었습니다.");
                            break;
                        default:
                            alert("예외가 발생하여 답변을 채택하지 못하였습니다.["+ data +"]");
                            break;
                    }
                }
            }
            else {
                alert("일시적인 오류로 인하여 답변을 채택하지 못하였습니다.");
            }
        }, "text");
    }
}

// PlayTip :: 게임 플레이 팁
function PlayTip() {
    window.open(rootPath + 'guide/play_tip/tip_01.aspx','PlayTip','width=640,height=790,scrollbars=no');
}

// ArtworkUseGuide :: 아트워크 이미지 사용 안내
function ArtworkUseGuide() {
    window.open(rootPath + 'downloads/Artwork_img_use_guide.aspx','ArtworkUseGuide','width=482,height=520,scrollbars=no');
}

// PcBangSearch :: 개인정보취급방침
function privacyPop() {
    window.open('http://www.nexon.com/KR/info/privacy_popup.html','privacy','width=600,height=570,scrollbars=no');
}

// stipulation :: 서비스이용약관
function stipulation() {
    window.open('http://www.nexon.com/etc/pop_stipulation.html','stipulation','width=600,height=520,scrollbars=no');
}

// OpenGameUseGuide :: 게임이용등급안내 오픈
function OpenGameUseGuide() {
    window.open(rootPath + 'etc/gameuse.aspx','OpenGameUse','width=500,height=440,scrollbars=no');
}

// PcBangSearch :: PC방 찾기 오픈
function PcRoomSearch() {
    window.open('http://pcbang.nexon.co.kr/nexoncom/PCBANG_init.asp','PcRoomSearch','width=497,height=365,scrollbars=no');
}

function CBTFreeBoard() {
    window.open('/cbt/community/tester_list.asp', 'cbt_freeboard', 'width=637,height=770,scrollbars=yes');
}

function Help(id) {
    var popupId = 'Help_'+id;
    switch (id) {
        case "unsoundreport":
            window.open(rootPath + 'Common/BBS/UnsoundReportHelp.aspx', popupId, 'width=500,height=502,scrollbars=no');
            break;
        case "driverinstall":
            window.open(rootPath +'Downloads/DriverInstallHelp.aspx', popupId, 'width=500,height=667,scrollbars=0,toolbars=0,menubars=0,status=0,top=0,left=0');
            break;
        case "kinpoint":
            window.open(rootPath +'Community/kin_point.aspx', popupId, 'width=482,height=349,scrollbars=0,toolbars=0,menubars=0,status=0');
            break;
        default:
            break;
    }
}

function UnsoundReport(bbs, post, comment, answer) {
    answer = (answer > 0) ? answer : 0;
    var url_reportable = rootPath + 'Common/BBS/UnsoundReportable.aspx';
    var url_report = rootPath + 'Common/BBS/UnsoundReport.aspx?bn='+bbs+'&no='+post+'&cn='+comment+'&an='+answer;
    
    $.get(url_reportable, {bn:bbs,no:post,cn:comment,an:answer}, function(data, status) {
        if(status == "success") {
            if (data == "ok") {
                window.open(url_report, 'Help_UnsoundReport', 'width=500,height=398,scrollbars=no');
            }
            else {
                switch(data) {
                    case "logout":
                        alert("로그인 하신 후 이용해 주세요.");
                        break;
                    case "already_report":
                        alert("이미 신고한 게시물 입니다.");
                        break;
                    case "param_error":
                        alert("신고에 필요한 정보가 누락되었습니다.");
                        break;
                    default:
                        alert("신고 기능을 이용하실 수 없습니다.");
                        break;
                }
            }
        }
        else {
            alert("일시적인 오류로 인하여 신고 기능을 이용하실 수 없습니다.");
        }
    }, "text");
}

function doNothing() { }


function check091216Event(flag) {
    $.get("/event/2009opening/_CheckWinner.aspx?eventflag=" + flag, function(data) {
    switch (Number(data)) {
            case 0: alert("당첨자가 아닙니다."); break;        
            case 1: alert("당첨자입니다."); break;
            case -91: alert("로그인이 필요합니다."); break;
            default:
                alert("오류가 발생하였습니다. 버그리포트에 문의해 주세요.");
                location.reload();
                break;
        }
    });

    return;
}



function checkCommonEvent(event_idx) {
    $.getJSON("/event/_CheckWinner.aspx?event_idx=" + event_idx, function(data) {
        switch (Number(data.flag)) {
            case 0: alert(data.message); break;
            case 1:
                if (data.couponpin === undefined) {
                    alert(data.message);
                } else {
                    if (saveToClipboard(data.couponpin, "")) {
                        alert(data.message + ' [' + data.couponpin + ']\n쿠폰번호가 클립보드에 복사되었습니다.');
                    } else {
                        alert(data.message + ' [' + data.couponpin + ']');
                    }
                    
                }
                break;
            case -91: alert("로그인이 필요합니다."); break;
            case -92: alert("정상적인 계정이 아닙니다."); break;
            case -93: alert("캐릭터 생성 후 확인해 주시기 바랍니다."); break;
            default:
                alert("오류가 발생하였습니다. 버그리포트에 문의해 주세요.");
                location.reload();
                break;
        }
    });

    return;
}