﻿var bz2script = {};

/***** 로그인 및 로그인 체크 관련 *****/
bz2script.Logon = function () { }
bz2script.Logon.prototype = {
    Login: function (frm) {
        var id = document.getElementById("txtUserID").value;
        var pwd = document.getElementById("txtPasswd").value;
        if (!id) {
            messageBox("아이디를 입력하세요.", jQuery('#txtUserID')[0]);
            return false;
        } else if (!pwd) {
            messageBox("비밀번호를 입력하세요.", jQuery('#txtPasswd')[0]);
            return false;
        } else {
            var sc = document.createElement('script');
            sc.setAttribute('id', 'loginScript');
            sc.setAttribute('type', 'text/javascript');
            sc.setAttribute('charset', 'utf-8');
            sc.setAttribute('src', 'https://www.blitz2.co.kr/loginexec/' + id + '/' + pwd + '/html');

            if (document.getElementsByTagName('head')[0]) document.getElementsByTagName('head')[0].appendChild(sc);
        }
    }
    ,
    OutPut: function (ret) {
        if (!ret) return false;
        var data = eval("(" + ret + ")");

        switch (data.code) {
            case "-1":
                messageBox("필수 값이 없습니다.", null);
                break;
            case "0":
                location.href = location.href;
                break;
            case "2":
                messageBox("해당 계정은 블럭 상태입니다", null);
                location.href = "http://www.blitz2.co.kr/members/?target=blockuser";
                break;
            case "3":
                messageBox("해당 계정은 탈퇴 대기 상태입니다", null);
                location.href = "http://www.blitz2.co.kr/members/?target=leaveuser";
                break;
            case "4":
                messageBox("해당 계정이 존재 하지 않습니다", null);
                break;
            case "5":
                messageBox("비밀번호가 틀렸습니다", jQuery('#txtPasswd')[0]);
                break;
            case "6":
                messageBox("로그인 중 오류가 발생하였습니다", null);
                break;
            case "7":
                messageBox("간편 ID 유효기간이 만료되어 해당 정보가 삭제되었습니다", null);
                break;
            default:
                messageBox("로그인 중 오류가 발생하였습니다", null);
                break;
        }

        $('#loginScript').remove();
    }
}

function OutPut(ret, fn) {
    if (fn === "html") {
        var logon = new bz2script.Logon();
        logon.OutPut(ret);
    }
    else {
        FlashOutPut(ret);
    }
}    

/***** 각종 팝업 관련 *****/

function messageBox(msg, obj) {
    if (obj === null)       
        DF.UI.Tooltip({
        message: msg
        , skin: "white"
        , position: "center"//"confirm"
        , opacity: 45
        , zIndex: 9999
        , isoverlay: true
        , isdrag: true
        //, onload: function () { alert('onload 무조건 실행'); }
        //, onremove: function () { alert('확인 클릭시 실행'); }       
        });
    else
        DF.UI.Tooltip({
            message: msg
        , skin: "white"
        , position: "center"//"confirm"
        , opacity: 45
        , zIndex: 9999
        , isoverlay: true
        , isdrag: true
            //, onload: function () { alert('onload 무조건 실행'); }
            //, onremove: function () { alert('확인 클릭시 실행'); }
        , onloaded: function () { obj.focus(); }
        });        
}

function messageBoxLocation(msg, target) {
    DF.UI.Tooltip({
        message: msg
        , skin: "white"
        , position: "center"//"confirm"
        , opacity: 45
        , zIndex: 9999
        , isoverlay: true
        , isdrag: true
        //, onload: function () { alert('onload 무조건 실행'); }
        //, onremove: function () { alert('확인 클릭시 실행'); }
        , onloaded: function () { location.href = target; }
    });
}

function iframeResize(height) {
    $('#ifrmeList').height(height + 13);
}

String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
}

String.prototype.trim = function (chars) {
    if (chars) {
        var str = "[" + chars + "\\s]+";
        return this.replace(new RegExp(str, "g"), "");
    }
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function (chars) {
    if (chars) {
        var str = "^[" + chars + "\\s]+";
        return this.replace(new RegExp(str, "g"), "");
    }
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function (chars) {
    if (chars) {
        var str = "[" + chars + "\\s]+$";
        return this.replace(new RegExp(str, "g"), "");
    }
    return this.replace(/\s+$/, "");
}

/**** 문자열 공백 제거 ****/
//var xx = "  포인트 : 30,000 결제 성공  ";
//alert(xx);
//alert("<" + xx.trim() + ">");
//alert("<" + xx.trim("포인트:,") + ">");
//alert("<" + xx.trim(" 포인트: ") + ">");
//alert("<" + xx.ltrim(" 포인트: ") + ">");
//alert("<" + xx.trim("결제성공 ") + ">");
//alert("<" + xx.rtrim("결제성공 ") + ">"); 

/**** 한글 바이트 체크 하기 ****/
String.prototype.bytes = function () {
    var str = this; 
    return str.replace(/[^\x00-\x7F]/g, "xx").replace(/([<\x0D])/g, function ($0, $1) { return ($1 == "<") ? "&lt;" : "<br>" + $1; }).length;
}

String.prototype.cut = function (len, tail) {
    var str = this;
    var l = 0;
    for (var i = 0; i < str.length; i++) {
        l += (str.charCodeAt(i) > 128) ? 2 : 1;
        if (l > len) return str.substring(0, i) + tail;
    }
    return str;
}

// 쿠키 설정
function SetCookie(name, value, expiredays) {
    var todayDate = new Date();
    todayDate.setHours(todayDate.getHours() + expiredays);
    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// 쿠키 불러오기
function GetCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else
        begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

/**** 메뉴 링크 ****/
function flash_link(link_value) {
    switch (link_value.toString()) {
        case "0":                     
            location.href = "/";
            break;
        case "1":
            location.href = "/Guide/World";
            break;
        case "2":
            location.href = "/Guide/Newbie";
            break;
        case "3":
            location.href = "/Guide/Newbie/3";
            break;
        case "4":
            location.href = "/Guide/Newbie/4";
            break;
        case "5":
            location.href = "/Guide/Newbie/1";
            break;
        case "6":
            location.href = "/Media/DownLoad";
            break;
        case "7":
            location.href = "/Media/List";
            break;
        case "8":
            location.href = "/FreeBoard/Report";
            break;
        case "9":
            location.href = "/Media/DownLoad";
            break;                     
        case "50":            
            RunGameStart();
            break;
        case "100":
        case "110":
            location.href = "/News/Notice";
            break;
        case "120":
            location.href = "/News/Event";
            break;
        case "200":
        case "210":
            location.href = "/Guide/World";
            break;
        case "220":
            location.href = "/Guide/Newbie";
            break;
        case "230":
            messageBox('준비중 입니다.', null); //location.href = "/Guide/Tank";
            break;
        case "240":
            messageBox('준비중 입니다.', null); //location.href = "/Guide/Item";
            break;
        case "250":
            messageBox('준비중 입니다.', null); //location.href = "/Guide/Skill";
            break;
        case "260":
            messageBox('준비중 입니다.', null); //location.href = "/Guide/Commander";
            break;        
            break;
        case "300":
        case "310":
            location.href = "/TOC/MyNation";
            break;
        case "320":
            location.href = "/TOC/MyBoard";
            break;
        case "330":
            location.href = "/TOC/Stalking";
            break;
        case "340":
            location.href = "/TOC/Supporters";
            break;
        case "400":            
        case "410":
            location.href = "/Media/DownLoad/";
            break;
        case "420":
            location.href = "/Media/List/";
            break;
        case "430":
            messageBox('준비중 입니다.', null); //location.href = "/Media/MultMedia/";
            break;        
        case "500":
        case "510":
            location.href = "/FreeBoard/Nation";
            break;
        case "520":
            location.href = "/FreeBoard/Report";
            break;
        case "530":
            location.href = "/FreeBoard/Guide";
            break;
        case "540":
            location.href = "/FreeBoard/Helper";
            break;
        case "550":
            location.href = "/FreeBoard/FAQ";
            break;       
    }
}

function RunGameStart() {
    var gameObjectId = "Blitz2Starter";

    var Installed = false;

    try {        
        Installed = $("#" + gameObjectId)[0].ErrMsg ? true : false;
    } catch (err) { ; }
    
    if ($("#" + gameObjectId)[0].ErrMsg == 1003) {
        // 설치된경우
        DF.Net.Ajax({
            url: '/Game/Start',
            onsuccess: function (ret, status) {
                if (ret != "") {
                    var pieces = ret.split("◎");
                    switch (pieces[0]) {
                        case "retValue":
                            switch (pieces[1]) {
                                case "0":
                                    messageBox("로그인이 필요합니다.", null);
                                    return false;
                                    break;
                                case "1":
                                    messageBox("게임을 실행할 수 없습니다.", null);
                                    return false;
                                    break;
                                case "2":
                                    messageBox("접속계정이 존재하지 않습니다.", null);
                                    return false;
                                    break;
                                case "3":
                                    messageBox("게임을 실행할 수 없습니다.(응답오류).", null);
                                    return false;
                                    break;
                                case "4":
                                    messageBox("18세이상 사용자만 이용하실수 있습니다.", null);
                                    return false;
                                    break;
                                case "5":
                                    messageBox("14세 미만 부모 미동의자는 게임을 실행 하실 수 없습니다.", null);
                                    return false;
                                    break;
                                default:
                                    messageBox("오류가 발생했습니다[" + pieces[1] + "]", null);
                                    return false;
                                    break;
                            }
                            break;
                        case "block":
                            messageBoxLocation("해당 계정은 블럭 상태입니다", "http://www.blitz2.co.kr/members/?target=blockuser");
                            return false;
                            break;
                        case "leave":
                            messageBoxLocation("해당 계정은 탈퇴 대기 상태입니다", "http://www.blitz2.co.kr/members/?target=leaveuser");
                            return false;
                            break;
                        case "success":
                            GameExecute(pieces[1]);
                            break;
                    }
                }
                else {
                    messageBox("오류가 발생했습니다[0]", null);
                    return false;
                }
            }
        }).request();
    }
    else if ($("#" + gameObjectId)[0].ErrMsg == -1) {
        top.location.href = "/Media/DownLoad/";
    }
    else {
        top.location.href = "/Home/ActiveX";
    }
}

function GameExecute(runParam) {
    var gameObjectId = "Blitz2Starter";
    var iRet;    
    try {
        iRet = $("#" + gameObjectId)[0].Run(runParam);
    } catch (e) {
        messageBox("오류가 발생하였습니다." + e.Message, null);
        return false;
    }

    switch (iRet) {
        case 1:
            messageBoxLocation('게임이 설치되지 않았습니다.', '/Media/Download');
            return false;
            break;
        case 2:
            messageBox('실행할 권한이 없습니다.', null);
            return false;
            break;
        case 3:
            messageBoxLocation('게임이 설치되지 않았습니다.', '/Media/Download');
            return false;
            break;
        case 4:
            messageBox('알수없는 에러입니다.', null);
            return false;
            break;
        case 5:
            messageBoxLocation('게임버젼이 틀립니다. 게임 다운로드 후 다시 설치하여 주세요.', '/Media/Download');
            return false;
            break;
    }

    // 게임 시작 피시정보 로그 기록
    location.href = '/Game/Running';
    return;
}

function logIn(id, pwd) {

    if (!id) {
        messageBox("아이디를 입력하세요.", null);
        return;
    } else if (!pwd) {
        messageBox("비밀번호를 입력하세요.",null);
        return;
    } else {

        var sc = document.createElement('script');
        sc.setAttribute('id', 'loginScript');
        sc.setAttribute('type', 'text/javascript');
        sc.setAttribute('charset', 'utf-8');
        sc.setAttribute('src', 'https://www.blitz2.co.kr/loginexec/' + id + '/' + pwd + '/flash');

        if (document.getElementsByTagName('head')[0]) document.getElementsByTagName('head')[0].appendChild(sc);
    }
}

function FlashOutPut(ret) {
    if (!ret) return false;
    var data = eval("(" + ret + ")");

    switch (data.code) {
        case "-1":
            messageBox("필수 값이 없습니다.", null);
            break;
        case "0":

            flashMethodCall("main_flash", "addLogIn", [data.nick, data.letter, "BLITZ2 에 오신걸 환영합니다."]);
            break;
        case "2":
            messageBox("해당 계정은 블럭 상태입니다", null);
            location.href = "http://www.blitz2.co.kr/members/?target=blockuser";
            break;
        case "3":
            messageBox("해당 계정은 탈퇴 대기 상태입니다", null);
            location.href = "http://www.blitz2.co.kr/members/?target=leaveuser";
            break;
        case "4":
            messageBox("해당 계정이 존재 하지 않습니다", null);
            break;
        case "5":
            messageBox("비밀번호가 틀렸습니다", null);
            break;
        case "6":
            messageBox("로그인 중 오류가 발생하였습니다", null);
            break;
        case "7":
            messageBox("간편 ID 유효기간이 만료되어 해당 정보가 삭제되었습니다", null);
            break;
        default:
            messageBox("로그인 중 오류가 발생하였습니다", null);
            break;
    }

    $('#loginScript').remove();
}

function logOut() {
    location.href = "/Login/LogOut";
}

function go_Join() {
    location.href = "http://www.blitz2.co.kr/members/?target=regist";
}

function go_Find() {
    window.open('http://www.blitz2.co.kr/members/FindMyInfo/', 'popsearch', '100', '100');
    return false;
}

function go_Message() {
    Letter();
    return false;
}

function go_Info() {
    location.href = "http://www.blitz2.co.kr/members/?target=modify";
}

function go_View() {
    location.href = "/TOC/MyBoard";
}

function gameStart() {
    flash_link("50");
}

/**** 비로그인 & 로그인 박스 포커싱 ****/
function IsNotLoginBoard() {
    messageBox("로그인을 하셔야 게시물을 작성할 수 있습니다.", jQuery('#txtUserID')[0]);
    return false;
}

function IsNotLoginComment() {
    messageBox("꼬릿글 작성을 위해 먼저 로그인을 해 주세요.", top.jQuery('#txtUserID')[0]);
    return false;
}

function IsNotLoginStalking() {
    messageBox("스토킹을 하기 위해 먼저 로그인을 해 주세요.", top.jQuery('#txtUserID')[0]);
    return false;
}

function ScreenshotCancel(msg, rtn) {
    DF.UI.Tooltip({
        message: "스크린샷 " + msg + "을 취소하시겠습니까?"
        , skin: "white"
        , position: "confirm"
        , opacity: 45
        , zIndex: 9999
        , isoverlay: true
        , isdrag: true
        , onremove: function () { location.href = rtn; }
    });
}

function NoticeCancel(msg, rtn) {
    DF.UI.Tooltip({
        message: "공지사항" + msg + "을 취소하시겠습니까?"
        , skin: "white"
        , position: "confirm"
        , opacity: 45
        , zIndex: 9999
        , isoverlay: true
        , isdrag: true
        , onremove: function () { location.href = rtn; }
    });
}

window.AttatchFile = function (originurl, fileurl, thumurl) {    
    var contents = boardContents;
    contents.setData(contents.getData() + "<a href='" + originurl + "' lang='imageviewer' onclick='return false;'><img src='" + fileurl + "' style='border:none' /></a><br />");
    document.getElementById("hidThumbnail").value = thumurl;
}

window.NoticeAttatchFile = function (fileUrl) {
    var contents = boardContents;
    contents.setData(contents.getData() + "<a href='" + originurl + "' lang='imageviewer' onclick='return false;'><img src='" + fileurl + "' style='border:none' /></a><br />");
}

window.EventAttatchFile = function (fileUrl) {
    var contents = boardContents;
    contents.setData(contents.getData() + "<img src='" + fileurl + "' style='border:none' />");
}

window.AdmAttatchFile = function (fileUrl) {
    if ($('#bannerimg')) $('#bannerimg').val(fileUrl);
    if ($('#imgUrl')) $('#imgUrl').val(fileUrl);
}

var returnUrl = "";
//(function(window,jq){
window.contentsSubmit = function (form, callUrl, idx, retUrl, board, isLogin, boardType) {

    if (isLogin != "True") {
        messageBox("로그인을 하셔야 게시물을 작성할 수 있습니다.", jQuery('#txtUserID')[0]);
        return false;
    }

    if (!form || !callUrl || !retUrl)
        return false;
    returnUrl = retUrl;

    var contents = boardContents;

    if (!document.all && jQuery.trim(contents.getData()) === "<br />")
        contents.setData("");

    var title = jQuery.trim(jQuery("#title").val());

    if (title === "") {
        messageBox("제목을 넣어주세요.", jQuery('#title')[0]);
        return false;
    }
    
    if (title.length > 30) {
        messageBox("제목은 30바이트까지 입력이 가능합니다.", jQuery('#title')[0]);
        return false;
    }

    if (jQuery.trim(contents.getData()) === "") {
        messageBox("본문내용을 넣어주세요.", null);
        return false;
    }

    if (board && board === "image") {
        if (!(/&lt;img/i.test(jQuery.trim(contents.getData())) || /&lt;embed/i.test(jQuery.trim(contents.getData())) || /&lt;object/i.test(jQuery.trim(contents.getData())) || /http:/i.test(jQuery.trim(contents.getData()))) || /https:/i.test(jQuery.trim(contents.getData()))) {
            messageBox("이미지/동영상을 넣어주세요.", jQuery('#boardContents')[0]);
            return false;
        }
    }

    var dataParameters = {
        idx: idx,
        contents: jQuery.trim(contents.getData()),
        openType: $('input:radio[name="openType"]:checked').val(),
        boardType: boardType
    };

    DF.Net.Ajax({
        url: callUrl,
        data: dataParameters,
        onsuccess: contentsSubmitResponse
    }).request(form);
}
var contentsSubmitResponse = function (ret, status) {    
    if (!ret) return false;
    var data = eval("(" + ret + ")");
    if (data.error) {
        messageBox(data.error, null);
        return false;
    }
    top.location.href = returnUrl;
}

window.evetSubmit = function (form, callUrl, idx, retUrl, board, isLogin, boardType) {

    if (isLogin != "True") {
        messageBox("로그인을 하셔야 게시물을 작성할 수 있습니다.", jQuery('#txtUserID')[0]);
        return false;
    }
    returnUrl = retUrl;

    DF.Net.Ajax({
        url: callUrl,        
        onsuccess: contentsSubmitResponse
    }).request(form);
}


window.contentsModify = function (form, callUrl, idx,  boardType, isLogin) {
    if (isLogin == "False") {
        messageBox("로그인을 하셔야 게시물을 작성할 수 있습니다.", jQuery('#txtUserID')[0]);
        return false;
    }

    if (!form || !callUrl)
        return false;    

    var contents = boardContents;

    if (!document.all && jQuery.trim(contents.getData()) === "<br />")
        contents.setData("");

    var title = jQuery.trim(jQuery("#title").val());

    if (title === "") {
        messageBox("제목을 넣어주세요.", jQuery('#title')[0]);
        return false;
    }

    if (title.length > 30) {
        messageBox("제목은 30바이트까지 입력이 가능합니다.", jQuery('#title')[0]);
        return false;
    }

    if (jQuery.trim(contents.getData()) === "") {
        messageBox("본문내용을 넣어주세요.", null);
        return false;
    }

    if (boardType == 1) {
        if (!(/&lt;img/i.test(jQuery.trim(contents.getData())) || /&lt;embed/i.test(jQuery.trim(contents.getData())) || /&lt;object/i.test(jQuery.trim(contents.getData())) || /http:/i.test(jQuery.trim(contents.getData()))) || /https:/i.test(jQuery.trim(contents.getData()))) {
            messageBox("이미지/동영상을 넣어주세요.", jQuery('#boardContents')[0]);
            return false;
        }
    }

    var dataParameters = {        
        contents: jQuery.trim(contents.getData()),
        openType: $('input:radio[name="openType"]:checked').val()
    };

    DF.Net.Ajax({
        url: callUrl,
        data: dataParameters,
        onsuccess: contentsModifyResponse
    }).request(form);
}
var contentsModifyResponse = function (ret, status) {
    if (!ret) return false;    
    var data = eval("(" + ret + ")");
    if (data.error) {
        messageBox(data.error, null);
        return false;
    }
    opener.location.href = opener.location.href;
    self.close();
}

window.popupWindow = function(url,id,parameters){
    var pop=window.open(url,id,parameters);
    if(!pop){
        messageBox("사이트 팝업이 차단되었습니다.<br />해당 브라우저 팝업설정을 변경해주시기 바랍니다.", null);
        return false;
    }
    pop.focus();
}

window.popImageUpload = function (bType, fType) {
    var url = "/Upload/" + fType + "/" + bType;
    var popWidth = 420;
    var popHeight = 220;
    var top = (screen.availHeight / 2) - (popHeight / 2);
    var left = (screen.availWidth / 2) - (popWidth / 2);
    var vals = "toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
    var parameters = "left=" + left + ",top=" + top + ",width=" + popWidth + ",height=" + popHeight + "," + vals;

    popupWindow(url, "imgpop", parameters);

    return false;
}

window.popImageUploadAdm = function (e) {
    var url = "/Upload/" + e;
    var popWidth = 420;
    var popHeight = 220;
    var top = (screen.availHeight / 2) - (popHeight / 2);
    var left = (screen.availWidth / 2) - (popWidth / 2);
    var vals = "toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
    var parameters = "left=" + left + ",top=" + top + ",width=" + popWidth + ",height=" + popHeight + "," + vals;

    popupWindow(url, "imgpop", parameters);

    return false;
}

window.popMovieUpload = function () {
    var url = "/Upload/Multimedia";
    var popWidth = 430;
    var popHeight = 280;
    var top = (screen.availHeight / 2) - (popHeight / 2);
    var left = (screen.availWidth / 2) - (popWidth / 2);
    var vals = "toolbar=no,menubar=no,location=no,scrollbars=no,status=no";
    var parameters = "left=" + left + ",top=" + top + ",width=" + popWidth + ",height=" + popHeight + "," + vals;

    popupWindow(url, "mediapop", parameters);

    return false;
}

window.RegistStalking = function (data, nick) {    

    DF.UI.Tooltip({
        message: nick + "님을 스토킹 하시겠습니까?",
        position: "confirm",
        isoverlay: true,
        onremove: function () {
            DF.Net.Ajax({
                url: "/Common/RegistStalking/",
                isoverlay: false,
                data: { data: data, nick: nick },
                onsuccess: function (ret, status) {
                    if (ret != "0") {
                        messageBox("스토킹 추가중 오류가 발생했습니다.", null);
                        return false;
                    }
                    var stalkingCount = $("em:[name='" + nick + "']");
                    var count = parseInt(stalkingCount.html()) + 1;

                    stalkingCount.each(function () {
                        $(this).html(count);
                    });

                    var stalkingImg = $("span:[name='stalking_" + nick + "']");
                    var txt = "<a href='#' onclick=\"javascript:DeleteStalking('" + data + "','" + nick + "'); return false;\"><img src='/img/img_common/btn_unfollow.gif' alt='스토킹 삭제' /></a>";
                    stalkingImg.each(function () {
                        $(this).html(txt).find('a').click(function (event) { event.stopImmediatePropagation(); });
                    });

                    return false;

                }
            }).request();            
        }
    });
}

window.DeleteStalking = function (data, nick) {

    DF.UI.Tooltip({
        message: nick + "님에대한 스토킹을 취소합니다.",
        position: "confirm",
        isoverlay: true,
        onremove: function () {
            DF.Net.Ajax({
                url: "/Common/DeleteStalking/",
                isoverlay: false,
                data: { data: data, nick: nick },
                onsuccess: function (ret, status) {
                    if (ret != "0") {
                        messageBox("스토킹 취소중 오류가 발생했습니다.", null);
                        return false;
                    }
                    var stalkingCount = $("em:[name='" + nick + "']");
                    var count = parseInt(stalkingCount.html()) - 1;
                    stalkingCount.each(function () {
                        $(this).html(count);
                    });

                    var stalkingImg = $("span:[name='stalking_" + nick + "']");
                    var txt = "<a href='#' onclick=\"javascript:RegistStalking('" + data + "','" + nick + "'); return false;\"><img src='/img/img_common/btn_follow.gif' alt='스토킹 추가' /></a>";
                    stalkingImg.each(function () {
                        $(this).html(txt).find('a').click(function (event) { event.stopImmediatePropagation(); });
                    });

                    return false;
                }
            }).request();
        }
    });
}

window.Modify = function (data) {
    var url = "/Common/Modify/" + data;
    var popWidth = 708;
    var popHeight = 600;
    var top = (screen.availHeight / 2) - (popHeight / 2);
    var left = (screen.availWidth / 2) - (popWidth / 2);
    var vals = "toolbar=no,menubar=no,location=no,scrollbars=no,status=no,resizable=yes";
    var parameters = "left=" + left + ",top=" + top + ",width=" + popWidth + ",height=" + popHeight + "," + vals;

    popupWindow(url, "modifypop", parameters);

    return false;
}

window.Delete = function (data) {
    DF.UI.Tooltip({
        message: "해당 글을 삭제 하시겠습니까?",
        position: "confirm",
        isoverlay: true,
        onremove: function () {
            DF.Net.Ajax({
                url: "/Common/Delete/" + data,
                method: "get",
                onsuccess: DeleteResponse
            }).request();
            return false;
        }
    });
}
var DeleteResponse = function (ret, status) {
    if (!ret) return false;
    var data = eval("(" + ret + ")");
    if (data.error) {
        messageBox(data.error, null);
        return false;
    }

    location.href = location.href; 
}

window.DeleteScreenshot = function (data) {
    DF.UI.Tooltip({
        message: "해당 글을 삭제 하시겠습니까?",
        position: "confirm",
        isoverlay: true,
        onremove: function () {
            DF.Net.Ajax({
                url: "/Media/Delete/" + data,
                method: "get",
                onsuccess: DeleteScreenshotResponse
            }).request();
            return false;
        }
    });
}
var DeleteScreenshotResponse = function (ret, status) {
    if (!ret) return false;
    var data = eval("(" + ret + ")");
    if (data.error) {
        messageBox(data.error, null);
        return false;
    }
    location.href = "/Media/List";
}

window.DeleteNotice = function (data) {
    DF.UI.Tooltip({
        message: "해당 글을 삭제 하시겠습니까?",
        position: "confirm",
        isoverlay: true,
        onremove: function () {
            DF.Net.Ajax({
                url: "/News/Delete/" + data,
                method: "get",
                onsuccess: DeleteNoticeResponse
            }).request();
            return false;
        }
    });
}
var DeleteNoticeResponse = function (ret, status) {
    if (!ret) return false;
    var data = eval("(" + ret + ")");
    if (data.error) {
        messageBox(data.error, null);
        return false;
    }
    location.href = "/News/Notice";
}

window.DeleteEvent = function (data) {
    DF.UI.Tooltip({
        message: "해당 글을 삭제 하시겠습니까?",
        position: "confirm",
        isoverlay: true,
        onremove: function () {
            DF.Net.Ajax({
                url: "/News/EventDelete/" + data,
                method: "get",
                onsuccess: DeleteEventResponse
            }).request();
            return false;
        }
    });
}
var DeleteEventResponse = function (ret, status) {
    if (!ret) return false;
    var data = eval("(" + ret + ")");
    if (data.error) {
        messageBox(data.error, null);
        return false;
    }
    location.href = "/News/Event";
}

//contentsIdx, data control

var CmtId = 0;
var commentTxt;
window.RegistCmt = function (id, data) {

    commentTxt = $('#commentTxt_' + id);

    if (jQuery.trim(commentTxt.val()) === "") {
        messageBox("내용을 입력해 주세요", commentTxt[0]);
        return false;
    }

    CmtId = id;    

    DF.Net.Ajax({
        url: "/Common/RegistCmt/",
        type: "html",
        isoverlay: false,
        data: { data: data, idx: id, comment: commentTxt.val() },
        onsuccess: registCmtResponse,
        onload: function () {
            commentTxt.val("");
            parent.iframeResize($(document).find('body').height()); 
        }
    }).request();

    return false;
}

var registCmtResponse = function (ret, status) {

    if (!ret) {
        messageBox("댓글 등록중 오류가 발생했습니다.", null);
        return false;
    }

    var replayCount = $('#replayCount_' + CmtId);
    replayCount.html(parseInt(replayCount.html()) + 1);

    var cmtList = $('#commentList_' + CmtId);
    var cmtWrap = $('#commentWrap_' + CmtId);

    new setGradeIcon().hide();
    cmtList.html(ret);

    /* each comment item background style */
    $('#commentList_' + CmtId + ' > li:odd').addClass('odd');

    commentTxt.focus();

    return false;
}

window.DeleteCmt = function (id, data) {

    CmtId = id.split('_')[0];

    DF.UI.Tooltip({
        message: "댓글을 삭제 하시겠습니까?",
        position: "confirm",
        isoverlay: true,
        onremove: function () {
            DF.Net.Ajax({
                url: "/Common/DeleteCmt/",
                isoverlay: false,
                data: { data: data},
                onsuccess: function (ret, status) {         
                    if (ret != "0") {
                        messageBox("댓글 삭제중 오류가 발생했습니다.", null);
                        return false;
                    }
                    var replayCount = $('#replayCount_' + CmtId);
                    replayCount.html(parseInt(replayCount.html()) - 1);

                    $('#commentList_' + CmtId + ' > li').removeClass('odd');
                    $('#cmt_' + id).remove();
                    $('#commentList_' + CmtId + ' > li:odd').addClass('odd');
                    parent.iframeResize($(document).find('body').height());
                }
            }).request();
            return false;
        }
    });
}

window.searchText = function (url, st) {   

    if ($.trim(st.val()) === "" || $.trim(st.val()).length < 2) {
        messageBox("검색어를 2자 이상 입력해 주세요.", st);
        return false;
    }
        
    location.href = url + st.val();
}

var choiceStalking = 'ALL';
window.ChoiceStalking = function (idx, box) {

    if (choiceStalking == 'NO')
        choiceStalking = 'ALL';

    if (box.checked == true) {

        if (idx == 'ALL') {
            choiceStalking = 'ALL';
            $('#stalkingP_ALL').addClass('selected');
            $("li:[name='stalkingli']").each(function (idx) {
                $(this).removeClass('selected').find("input").removeAttr('checked');
            });
        }
        else {
            $('#stalkingli_' + idx).addClass('selected');

            if (choiceStalking == 'ALL') {
                choiceStalking = "|" + idx + "|";
                $('#stalkingP_ALL').removeClass('selected').find('input').removeAttr('checked');
            }
            else {
                choiceStalking = choiceStalking + "|" + idx + "|";
            }
        }
    }
    else {
        if (idx == 'ALL') {
            choiceStalking = 'NO';
            $('#stalkingP_ALL').removeClass('selected');
        }
        else {
            choiceStalking = choiceStalking.replace("|" + idx + "|", "");
            $('#stalkingli_' + idx).removeClass('selected');
        }
    }
    
    document.getElementById("ifrmeList").src = "/TOC/StalkingList/1/0/" + escape(choiceStalking);
}

var choiceNation = 'ALL';
window.ChoiceNation = function (idx, nc, span) {    

    if (idx == 'ALL') {
        if (choiceNation == "ALL") {
            choiceNation = 'NO';
            $('#nationP_ALL').removeClass('selected');
            $("li:[name='nationli']").each(function (idx) {
                $(this).removeClass('selected');
            });
        }
        else {
            choiceNation = 'ALL';
            $('#nationP_ALL').addClass('selected');
            $("li:[name='nationli']").each(function (idx) {
                $(this).addClass('selected');
            });
        }
    }
    else {
        $("li:[name='nationli']").each(function (idx) {
            $(this).removeClass('selected');
        });

        if (choiceNation == 'ALL') {
            $('#nationP_ALL').removeClass('selected').find('input').removeAttr('checked');
        }

        choiceNation = nc;
        $('#nationli_' + idx).addClass('selected');
    }

    document.getElementById("ifrmeList").src = "/FreeBoard/NationList/1/0/" + escape(choiceNation);
}

window.ChangByte = function (i, span, byte, name) {

    var title = $(i);
    var strlength = title.val().bytes();

    if (strlength > byte) {
        DF.UI.Tooltip({
            message: name + "은 " + byte + "바이트까지 입력이 가능합니다."
        , skin: "white"
        , position: "center"//"confirm"
        , opacity: 45
        , zIndex: 9999
        , isoverlay: true
        , isdrag: true
         , onremove: function () {
             title.val(title.val().cut(byte - 2, ""));
             $(span).html(byte);
             return false;
            }        
        });   
    }
    else {
        $(span).html(strlength);
    }
}

window.Letter = function () {
    window.open("/WebLetterBox/List", "letter", "width=520, height=604");
}

//})(window, jQuery)

