﻿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', // 새소식
    101:'news/notice.aspx',   //  - 공지사항
    102:'news/update.aspx',   //  - 업데이트 정보
    103:'news/pressrelease.aspx',   //  - 언론보도
    104:'news/devstory.aspx',   //  - 개발자 이야기
    105:'news/event.aspx',   //  - 이벤트
    200:'information/feature.aspx',   // 게임소개
    201:'information/feature.aspx',   //  - 게임특징
    202:'information/information.aspx',   //  - 게임정보
    203:'information/guide.aspx',   //  - 초보자 가이드
    204:'information/manual.aspx',   //  - 조작법
    300:'bbs/userbbs.aspx',   // 게시판
    301:'bbs/userbbs.aspx',   //  - 유저게시판
    302:'bbs/usergallery.aspx',   //  - 유저갤러리
    303:'bbs/photogallery.aspx',   //  - 포토갤러리
    304:'bbs/huskytalk.aspx',   //  - 허스키톡
    400:'community/hint.aspx',   // 커뮤니티
    401:'community/hint.aspx',   //  - 게임공략
    402:'community/knowledgemain.aspx',   //  - 지식거래
    412:'community/knowledge.aspx?list=myqst', // - 내 지식거래
    403:'community/cartoonmain.aspx',   //  - 연재만화
    404:'community/fansite.aspx',   //  - 팬사이트
    500:'pds/download.aspx',   // 자료실
    501:'pds/download.aspx',   //  - 다운로드
    502:'pds/wallpaper.aspx',   //  - 월페이퍼
    503:'pds/movie.aspx',   //  - 동영상
    504:'pds/screenshot.aspx',   //  - 스크린샷
    505:'pds/papercraft.aspx',   //  - 페이퍼 크레프트
    506:'pds/establish.aspx',   //  - 설정자료
    600:'support/faq.aspx',   // 고객지원
    601:'support/faq.aspx',   //  - FAQ
    602:'support/bugreport.aspx',   //  - 버그리포트
    603:'support/proposal.aspx',    // - 건의게시판
    604:'support/policy.aspx',   //  - 운영정책
    800:'diary/attendance.aspx',   // 개인 다이어리
    801:'diary/attendance.aspx',   // 출석
    802:'diary/activity.aspx',   // 내활동
    803:'diary/shortcut.aspx',   // 단축키
    900:'',   // Quick
    901:'http://help.nexon.com/help/page/nx.aspx?url=uotp/info', //U-OTP
    902:'faron' // 파론통신
};

function menu(menuId) {
    switch(menuId) {
        case 4: //  - 게임실행
            if (!IsLoginUser()) {
		        alert('로그인 하신 후 이용해주세요.');
		        return;
		    }
		    LaunchGame();
            break;
        case 203:   // 초보자 가이드
            window.open(rootPath + WebsiteMenu[menuId], 'Guide', 'toolbars=0,menubars=0,status=0,scrollbars=0,width=960,height=600');
            return;
        case 412:   // 내 지식거래
        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{
	            //778 X 878 
	            window.open(rootPath + WebsiteMenu[menuId], 'Diary', 'toolbars=0,menubars=0,status=0,scrollbars=1,width=795,height=878,top=0,left=0');
	            return;
	        }
	    case 901:
//	        alert('U-OTP 서비스는 11일 오픈베타부터 이용하실 수 있습니다.');
	        window.open(WebsiteMenu[menuId]);
	        break;
	    case 902:
	        window.open(rootPath + WebsiteMenu[menuId], 'FaronWin', 'toolbars=0,menubars=0,status=0,scrollbars=0,width=1024,height=768');
	        break;
		default:
		    location.href = rootPath + WebsiteMenu[menuId];
		    break;
    }
}

function ShowMemo() {
    NgbNote.OpenNotebox('', ''); 
}

function SendMemo(game, character) {
    NgbNote.OpenNoteSend(game, escape(character));
}

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(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?cn='+ no +'&rurl='+ escape(url);
    }
    else {
        if (!popup) {
            location.href = location.href;
        }
    }
}

// PcCheck :: PC사양 자가 진단
function PcCheck() {
    window.open(rootPath +'pds/Diagnostics.aspx', 'PcCheck', 'toolbars=0,menubars=0,status=0,scrollbars=0,width=778,height=612,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=540, height=560, 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");
    }
}

// DriverInstall :: 드라이버 설치법
function DriverInstall() {
    
}

// PcBangSearch :: 개인정보취급방침
function privacyPop() {
    window.open('http://www.nexon.com/join/page/nx.aspx?url=info/guideuserinfo','privacy','width=900,height=600,scrollbars=yes');
}

// PcBangSearch :: 청소년보호정책
function privacyPop1() {
    window.open('http://www.nexon.com/join/page/nx.aspx?url=info/guidechildprotect ','privacy','width=900,height=600,scrollbars=yes');
}

// stipulation :: 서비스이용약관
function stipulation() {
    //window.open(rootPath + 'etc/Stipulation.aspx','operationPolicy','width=600,height=540,scrollbars=no');
    window.open('http://www.nexon.com/join/page/nx.aspx?url=info/stipulation','stipulation','width=900,height=600,scrollbars=yes');
}

// 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.com/nexoncom/PCBANG_init.asp','PcRoomSearch','width=497,height=365,scrollbars=no');
}
// 유저갤러리 이용방법
function userGalleryGuide() {
	   window.open('http://husky.nexon.com/bbs/userGalleryGuide.aspx','UserGalleyGuide','width=817,height=900,scrollbars=1');
}
// 포토갤러리 이용방법
function photoGalleryGuide() {
	   window.open('http://husky.nexon.com/bbs/photoGalleryGuide.aspx','photoGalleyGuide','width=817,height=900,scrollbars=1');
}

function Help(id) {
    var popupId = 'Help_'+id;
    switch (id) {
        case "unsoundreport":
            window.open(rootPath + 'Common/BBS/UnsoundReportHelp.aspx', popupId, 'width=538,height=525,scrollbars=no');
            break;
        case "driverinstall":
            window.open(rootPath +'PDS/DriverInstallHelp.aspx', popupId, 'width=538,height=734,scrollbars=0,toolbars=0,menubars=0,status=0,top=0,left=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=506,height=458,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() { }