$(function() {
    $('body').attr('oncontextmenu', 'return false;')
    $('.nav-toggle').click(function(e) {
        e.stopPropagation();
        $("#wrapSideMenu").toggleClass('open')
    });
    $('body').click(function(e) {
        if ($('#wrapSideMenu').hasClass('open') && !$('#wrapSideMenu').hasClass('sidemenu-open')) {
            $("#wrapSideMenu").toggleClass('open')
        }
    })

    $("#wrapSideMenu").on('mouseover', function(e) {
        $(this).addClass('sidemenu-open')
    }).on('mouseleave', function(e) {
        $(this).removeClass('sidemenu-open')
    })

    $('.btn-close, .srch_btn').on('click', function(e) {
        $('.search').toggleClass('active')
    })

    $('.comment_policy_btn, #comment_policy .btn-success').on('click', function() {
        $('#comment_policy').toggle()
    })

    $('.cm-share-btn').click(function(e) {
        e.preventDefault();
        $("#share_box").toggle();
        $(this).parent().toggleClass('clicked')
    });

    $("#share_box .s_close").on('click', function() {
        $("#share_box").toggle();
    })

    $('.cm-comment-btn').on('click', function(e) {
        e.preventDefault();
        $(this).parent().toggleClass('clicked')
        $('.comment-box').toggle();
    })

    $('.cm-like-btn').on('click', function(e) {
        e.preventDefault();
        var form_data = {
            "content_idx": $('.article_contents').attr('id'),
            "content_type": "3"
        };
        $.ajax({
            url: '/web/comm/like_proc',
            async: false,
            type: 'POST',
            dataType: 'JSON',
            data: form_data,
            success: function(rtnJson) {
                if (rtnJson.result_code == "0000") {
                    $("#like_count").html(rtnJson.result_data.like_count);
                    $('.cm-like-btn').parent().addClass('clicked')
                } else {
                    alert("로그인하세요.");
                    go_loging();
                    return false;
                }
            },
            error: function(rtnJson) {
                alert("로그인하세요.");
                go_loging();
                return false;
            }
        });

    })

    if ($('.cm-more-enabled').length) {
        syncPostsRequest = true;
        var scrollSync = {
            lastScroll: 0
        };
        $(window).on('scroll', function() {
            var h = window.innerHeight + (window.pageYOffset || document.documentElement.scrollTop);
            var postOnPageCount = $('.cm-more-enabled').data('post-ids').split(',').length;
            if (syncPostsRequest && postOnPageCount > 0 && postOnPageCount < 100 && scrollSync
                .lastScroll < h && ((h >= document.body.offsetHeight - 60 && h < document.body
                    .offsetHeight - 30) || h == document.body.offsetHeight)) {
                var ids = $('.cm-more-enabled').data('post-ids');
                var pageType = $('.cm-more-enabled').data('page-type');
                syncPostsRequest = false
                $.post(location.href.indexOf('grace') > -1 ? '/grace/posts' : '/reference/posts', {
                        excepts: ids,
                        page: pageType,
                        pageId: location.href.indexOf('grace') > -1 ? location.href.split('/')[6] : 46,
                        orderBy: location.href.split('/').length > 7 ? location.href.split('/')[7] : null
                    },
                    function(res) {
                        var c = $('.cm-more-enabled ul li').last().clone();
                        var t = $('.cm-more-enabled ul').last();
                        var a = null;
                        var n = []
                        for (var i in res.data) {
                            a = c.clone()
                            a.find('div.box > a').attr('href', '/grace/' + res.data[i]
                                .titleUrl + '/' + res.data[i].idx).find(
                                'img').attr('src', res.data[i].mainImg)
                            a.find('div.txtbox > dl > dd > a').attr('href', '/grace/editor/' + res
                                .data[i].editorNameUrl + '/' + res.data[i].editorId).text(res
                                .data[i].editorName)
                            a.find('div.txtbox > dl > dt > a').attr('href', '/grace/' + res.data[i]
                                .titleUrl + '/' + res.data[i]
                                .idx).text(res.data[i].title)
                            a.find('div.txtbox > span.info > span.hit').text('조회수 ' + res.data[i]
                                .views + '회')
                            a.find('div.txtbox > span.info > span.reple').text('댓글 ' + res.data[i]
                                .comments + '회')
                            a.appendTo(t)
                            n.push(res.data[i].idx)
                        }
                        $('.cm-more-enabled').data('post-ids', n.length > 0 ? ids + ',' + n.join(
                            ',') : ids)
                        syncPostsRequest = true;
                    }, 'json');
                $('.cm-more-enabled ul li').last().clone()
            }
            scrollSync.lastScroll = h;
        });
    }
    if ($('body').data('graceview-bg')) {
        $('.channel_header2').css('background', 'url(' + $('body').data('graceview-bg') + ') no-repeat center')
    }


    // 레이어 이외의 공간 클릭시 close
    $(document).mouseup(function(e) {
        var container = $("#comment_policy, .cm-login-popup, #social_login");
        if (container.has(e.target).length === 0) container.hide();

    });

    $('.comment_policy_btn').click(function(e) {
        var popH = $(this).offset().top;
        $('.delivery_info3').css('left', '50%');
        $('.delivery_info3').css('top', '70px');
        $('.delivery_info3').css('margin-left', '-265px');
        //$("html, body").scrollTop(0);


        console.log(popH);

    });


    $('.replay_text').click(function(e) {
        var popH = $(this).offset().top;
        $(".popup_wrap").css('left', '50%');
        $(".popup_wrap").css('top', '100px');
        alert("로그인 후에 이용가능합니다.");
        location.href = '/web/user/login';
    });


    $('.comment_text').on('keyup', function(event) {
        var key = $(this).attr('strA');
        var len = $(this).val().length;
        if (len >= 300) {
            $(this).val($(this).val().substring(0, 300));
            len = 300;
        }
        $("#reply_text_count" + key).html(len + '/300');
    });



    $('.cm-morebtn-open').on('click', function(e) {
        e.preventDefault();
        $('.clipInfoArea_channel .clipInfo-content').css({ 'max-height': 'none', 'height': 'auto' });
        $(this).toggle();
        $('.cm-morebtn-close').toggle();
    });

    $('.cm-morebtn-close').on('click', function(e) {
        e.preventDefault();
        $('.clipInfoArea_channel .clipInfo-content').css({ 'max-height': '80px', 'height': 'none' });
        $(this).toggle();
        $('.cm-morebtn-open').toggle()
    })

    $('.cm-tvmore-btn').on('click', function(e) {
        e.preventDefault()
        var ids = $('.cm-tvmore-enabled').data('post-ids');
        var pageType = $('.cm-tvmore-enabled').data('page-type');
        if (ids) {
            $.post('/cmtv/posts', {
                excepts: ids,
                page: pageType,
                pageId: location.href.split('/')[6],
                orderBy: location.href.split('/').length > 7 ? location.href.split('/')[7] : null
            }, function(res) {
                var c = $('.cm-tvmore-enabled ul li').last().clone();
                var t = $('.cm-tvmore-enabled ul').last();
                var a = null;
                var n = []
                for (var i in res.data) {
                    a = c.clone()
                    a.find('div.box > a').attr('href', '/cmtv/' + res.data[i]
                        .titleUrl + '/' + res.data[i].idx).find(
                        'img').attr('src', res.data[i].mainImg)
                    a.find('div.txtbox > dl > dd > a').attr('href', '/cmtv/editor/' + res
                        .data[i].editorNameUrl + '/' + res.data[i].editorId).text(res
                        .data[i].editorName)
                    a.find('div.txtbox > dl > dt > a').attr('href', '/cmtv/' + res.data[i]
                        .titleUrl + '/' + res.data[i]
                        .idx).text(res.data[i].title)
                    a.find('div.txtbox > span.info > span.hit').text('조회수 ' + res.data[i]
                        .views + '회')
                    a.find('div.txtbox > span.info > span.reple').text(res.data[i]
                        .timeAgo)
                    a.appendTo(t)
                    n.push(res.data[i].idx)
                }
                if (n.length < 10) {
                    $('.cm-tvmore-enabled').data('post-ids', '');
                    $('.cm-tvmore-btn').hide();
                } else {
                    $('.cm-tvmore-enabled').data('post-ids', ids + ',' + n.join(','));
                }
                syncPostsRequest = true;
            }, 'json')
        }
    })



    var swiper = new Swiper('.swiper-containermenu2', {
        slidesPerView: 6,
        spaceBetween: 10,

        breakpoints: {
            // when window width is >= 320px
            320: {
                slidesPerView: 3.5,
                spaceBetween: 10
            },
            // when window width is >= 480px
            480: {
                slidesPerView: 4.5,
                spaceBetween: 10
            },
            // when window width is >= 640px
            800: {
                slidesPerView: 5.5,
                spaceBetween: 20
            }
        }
    });

});


// 댓글
// 댓글 sort 변경
function change_comment_sort(type) {
    $("#comment_sort").val(type);
    $("#comment_sort1").removeClass('current');
    $("#comment_sort2").removeClass('current');
    $("#comment_sort3").removeClass('current');
    $("#comment_sort4").removeClass('current');
    $("#comment_sort" + type).addClass('current');
    comment_list(1);
}

// 대댓글 열기
function comment_reply_open(idx) {
    $("#reply_comment" + idx).toggle();
    $("#reply_comment_main" + idx).addClass('reply_comment_open');
    $("#reply_comment_main" + idx).removeClass('reply_comment');

    comment_reply_list(idx, 1);
    $("#comment_reply_page" + idx).val(1);
}

// 대댓글 닫기
function comment_reply_close(idx) {
    $("#reply_comment" + idx).hide();

    $("#reply_comment_main" + idx).removeClass('reply_comment_open');
    $("#reply_comment_main" + idx).addClass('reply_comment');
}

// 대댓글 더보기
function comment_reply_more(idx) {
    var page = $("#comment_reply_page" + idx).val();
    page = parseInt(page) + 1;
    $("#comment_reply_page" + idx).val(page);
    comment_reply_list(idx, page);

}

// 댓글 더보기
var comment_page = 2;

function comment_list_more() {
    comment_list(comment_page);
}

function comment_list(page) {
    var sort = $("#comment_sort").val();
    var form_data = {
        "sort": sort,
        "page": page,
        "content_idx": $('.reply_box').data('postid'),
        "content_type": $('.reply_box').data('postcontenttype'),
        "is_comment_all_list": $('.reply_box').data('iscommentalllist'),
    };
    $.ajax({
        url: '/web/comm/comment_list',
        async: false,
        type: 'POST',
        timeout: 10000,
        dataType: 'HTML',
        data: form_data,
        success: function(rtnHtml) {
            if (rtnHtml == '') return false;
            var arrHtml = rtnHtml.split("|||||");
            if (arrHtml[0].trim() == '0000') {
                if (page == 1) {
                    $("#comment_list").html(arrHtml[1]);
                } else {
                    $("#comment_list").children('.reply_comment').last().removeAttr("style");
                    $("#comment_list").append(arrHtml[1]);
                }
                $("#comment_count").html(setComma(arrHtml[2]));
                if (arrHtml[3] == "N") {
                    $("#comment_more_btn").hide();
                } else {
                    $("#comment_more_btn").show();
                }

                if ($('.reply_box').data('iscommentalllist') == 'N') {
                    if (parseInt(arrHtml[2]) > 0) {
                        console.log("1");
                        $("#comment_all_list").show();
                    }
                }
                comment_page = page + 1;

            } else {
                alert(arrHtml[1]);
                return false;
            }
        },
        error: function(rtnHtml) {
            return false;
        }
    });
}


// comment 댓글 리스트 가져오기
function comment_reply_list(idx, page) {
    var sort = $("#comment_sort").val();
    var form_data = {
        "comment_idx": idx,
        "page": page,
        "sort": sort
    };
    $.ajax({
        url: '/web/comm/comment_reply_list',
        async: false,
        type: 'POST',
        dataType: 'HTML',
        timeout: 10000,
        data: form_data,
        success: function(rtnHtml) {
            var arrHtml = rtnHtml.split("|||||");
            if (arrHtml[0].trim() == '0000') {
                if (arrHtml[1] != "") {
                    if (page == 1) {
                        $("#reply_comment_list" + idx).html(arrHtml[1]);
                    } else {
                        $("#reply_comment_list" + idx).append(arrHtml[1]);
                    }
                }

                $("#comment_reply_count" + idx).html(setComma(arrHtml[2]));
                if (arrHtml[3] == "N") {
                    $("#reply_more" + idx).hide();
                } else {
                    $("#reply_more" + idx).show();
                }
            }
        },
        error: function(rtnHtml) {
            //alert('데이터 로드에 실패했습니다.');
            return false;
        }
    });
}



// 댓글달기
function comment_add_proc() {
    if (!getCookie('crossmap_comment_sns_id')) {
        alert("로그인 후에 이용가능합니다.");
        go_loging()
        return;
    }

    if ($("#comment").val() == "") {
        alert("댓글을 입력해주세요.");
        return;
    }

    var form_data = {
        "content_idx": $('.reply_box').data('postid'),
        "content_type": $('.reply_box').data('postcontenttype'),
        "comment": $("#comment").val()
    };
    $.ajax({
        url: '/web/comm/comment_add_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.code == "0000") {
                $("#comment").val('');
                $("#comment").focus();
                $("#reply_text_count").html('0/300');

                $("#comment_sort").val('2');
                $("#comment_sort1").removeClass('current');
                $("#comment_sort2").removeClass('current');
                $("#comment_sort2").addClass('current');

                comment_list(1);



            } else {
                alert(rtnJson.msg);
                return false;
            }

        },
        error: function(rtnJson) {
            alert('저장에 실패했습니다.');
            return false;
        }
    });
}



// 대대글 달기
function comment_reply_add_proc(p_idx) {
    if (!getCookie('crossmap_comment_sns_id')) {
        alert("로그인 후에 이용가능합니다.");
        go_loging()
        return;
    }

    if ($("#comment" + p_idx).val() == "") {
        alert("댓글을 입력해주세요.");
        return;
    }

    var form_data = {
        "p_idx": p_idx,
        "content_idx": $('.reply_box').data('postid'),
        "content_type": $('.reply_box').data('postcontenttype'),
        "comment": $("#comment" + p_idx).val()
    };
    $.ajax({
        url: '/web/comm/comment_add_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.code == "0000") {
                $("#comment" + p_idx).val('');
                $("#reply_text_count" + p_idx).html('0/300');
                $("#comment_reply_page" + p_idx).val(1);

                $("#comment_sort").val('2');
                $("#comment_sort1").removeClass('current');
                $("#comment_sort2").removeClass('current');
                $("#comment_sort2").addClass('current');

                comment_reply_list(p_idx, 1);

            } else {
                alert(rtnJson.msg);
                return false;
            }

        },
        error: function(rtnJson) {
            //alert('저장에 실패했습니다.');
            return false;
        }


    });

}
// 주소복사
function copy_url() {
    var copyText = document.getElementById("copy_url");
    copyText.select();
    document.execCommand("Copy");
    alert("주소가 복사되었습니다.");
}


// 댓글 좋아요
function comment_like_select(type, idx) {
    if (!getCookie('crossmap_comment_sns_id')) {
        alert("로그인 후에 이용가능합니다.");
        go_loging()
        return;
    }
    var form_data = {
        "comment_idx": idx,
        "type": type
    };
    $.ajax({
        url: '/web/comm/comment_like_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.code == "0000") {
                var like_count = setComma(rtnJson.data.like_count);
                var bad_count = setComma(rtnJson.data.bad_count);
                $("#comment_like1_" + idx).html(like_count);
                $("#comment_like2_" + idx).html(bad_count);

            } else {
                alert("로그인하세요.");
                return false;
            }
        },
        error: function(rtnJson) {
            alert('저장에 실패했습니다.');
            return false;
        }
    });

}


function comment_del(idx) {
    if (confirm("댓글이 삭제됩니다. 삭제하시겠습니까?") == false) {
        return false;
    }

    var form_data = {
        "idx": idx
    };
    $.ajax({
        url: '/web/comm/user_comment_del_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.code == "0000") {
                comment_list(1);

            } else {
                alert(rtnJson.msg);
                return false;
            }
        },
        error: function(rtnJson) {
            alert('삭제에 실패했습니다.');
            return false;
        }
    });

}


function reply_comment_del(idx, p_idx) {
    if (confirm("댓글이 삭제됩니다. 삭제하시겠습니까?") == false) {
        return false;
    }

    var form_data = {
        "idx": idx
    };
    $.ajax({
        url: '/web/comm/user_comment_del_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.code == "0000") {
                comment_reply_list(p_idx, 1);
            } else {
                alert(rtnJson.msg);
                return false;
            }
        },
        error: function(rtnJson) {
            alert('삭제에 실패했습니다.');
            return false;
        }
    });

}

function comment_delete_refresh(idx, write_id, content_type) {
    var form_data = {
        "idx": idx,
        "write_id": write_id,
        "content_type": content_type
    };
    $.ajax({
        url: '/web/life/user_comment_refresh_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.result.code == "0000") {
                $('.delete span').text(rtnJson.delete_cnt);
            } else {
                alert(rtnJson.msg);
                return false;
            }
        },
        error: function(rtnJson) {
            alert('알 수 없는 오류가 발생하였습니다.');
            return false;
        }
    });
}


function logout_advice() {
    alert("로그아웃 후에 이용해주세요.");
    return false;
}

function comment_logout() {
    location.href = "/web/comm/comment_logout";
}


function comment_spam(idx, write_name) {
    if (!$('.reply_box').data('signed')) {
        alert("로그인 후에 이용가능합니다.");
        return;
    }

    //$("html, body").scrollTop(0);

    $("#comment_spam_layer").toggle();
    $("#comment_write_name_txt").html(write_name);
    $("#comment_spam_idx").val(idx);
    $("#spam_reason_content").val('');
    $('input:radio[name="spam_reason_type"][value="1"]').prop('checked', true);

}


function comment_spam_proc() {
    var idx = $("#comment_spam_idx").val();
    if (idx == '') {
        alert("신고하기에 실패되었습니다.");
        $("#comment_spam_layer").toggle();
        return false;
    }

    if ($("#spam_reason_content").val() == '') {
        alert("신고내용을 입력해주세요.");
        return false;
    }

    var form_data = {
        "comment_idx": idx,
        "spam_reason_content": $("#spam_reason_content").val(),
        "spam_reason_type": $(":input:radio[name=spam_reason_type]:checked").val()

    };
    $.ajax({
        url: '/web/comm/comment_spam_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.code == "0000") {
                alert("신고되었습니다.");
                $("#comment_spam_layer").toggle();
                return false;
            } else {
                alert(rtnJson.msg);
                return false;
            }
        },
        error: function(rtnJson) {
            alert('저장에 실패했습니다.');
            return false;
        }
    });
}


$(document).mouseup(function(e) {
    var container = $("#share_box");
    if (container.has(e.target).length === 0) container.hide();

});

typeof Kakao != 'undefined' && Kakao.init('6ff83d5220e4182ba5f996b2cf6dd52c');

function share_kakao() {
    Kakao.Link.sendDefault({
        objectType: 'feed',
        content: {
            title: $("#share_title").val(),
            imageUrl: $("#share_img_url").val(),
            link: {
                mobileWebUrl: $("#share_copy_url").val(),
                webUrl: $("#share_copy_url").val()
            }
        },
        buttons: [{
            title: '웹으로 보기',
            link: {
                mobileWebUrl: $("#share_copy_url").val(),
                webUrl: $("#share_copy_url").val()
            }
        }]
    });
}

function share_facebook() {
    var share_url = $("#share_copy_url").val();
    var url = encodeURI(share_url);
    window.open("http://www.facebook.com/sharer/sharer.php?u=" + url, "",
        "height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes"
    );
}



function share_band() {
    var share_title = $("#share_title").val() + '\n' + $("#share_copy_url").val();
    var url = encodeURIComponent($("#share_copy_url").val());
    var text = encodeURI(share_title);
    window.open("http://band.us/plugin/share?body=" + text + "&route=" + url, "",
        "height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes"
    );

}


// 카카오톡 스토리 공유하기
function share_kakaostory() {
    var share_url = $("#share_copy_url").val();
    var share_title = $("#share_title").val() + '\n' + $("#share_copy_url").val();
    Kakao.Story.share({
        url: share_url,
        text: share_title,
    });
}

// 네이버공유하기
function share_naver() {
    var share_url = $("#share_copy_url").val();
    var share_title = $("#share_title").val();
    var url = encodeURI(encodeURIComponent(share_url));
    var title = encodeURI(share_title);
    var shareURL = "http://share.naver.com/web/shareView.nhn?url=" + url + "&title=" + title;
    window.open(shareURL, "",
        "height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes"
    );
}

// 트위터 공유하기
function share_twitter() {
    var share_url = $("#share_copy_url").val();
    var share_title = $("#share_title").val();

    var url = share_url;
    var text = encodeURI(share_title);
    window.open("https://twitter.com/intent/tweet?text=" + text + "&url=" + url, "",
        "height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes"
    );
}

function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}


//layer popup
function commonLayerOpen(thisId) {
    $('#' + thisId).show();
}

function commonLayerClose(thisId) {
    $('#' + thisId).hide();
}

function change_toggle(id) {
    $("#" + id).toggle();
}

// 메인페이지 이동 20190215
function goMain() {
    location.href = "/";
}

// 로그인 페이지 이동 20190215
function go_loging() {
    //   e.preventDefault();
    location.href = "/web/user/login?url=" + encodeURIComponent(document.URL);
}

// 날짜 포멧
Date.prototype.format = function(f) {
    if (!this.valueOf()) return " ";

    var weekName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"];
    var d = this;

    return f.replace(/(yyyy|yy|MM|dd|E|hh|mm|ss|a\/p)/gi, function($1) {
        switch ($1) {
            case "yyyy":
                return d.getFullYear();
            case "yy":
                return (d.getFullYear() % 1000).zf(2);
            case "MM":
                return (d.getMonth() + 1).zf(2);
            case "dd":
                return d.getDate().zf(2);
            case "E":
                return weekName[d.getDay()];
            case "HH":
                return d.getHours().zf(2);
            case "hh":
                return ((h = d.getHours() % 12) ? h : 12).zf(2);
            case "mm":
                return d.getMinutes().zf(2);
            case "ss":
                return d.getSeconds().zf(2);
            case "a/p":
                return d.getHours() < 12 ? "오전" : "오후";
            default:
                return $1;
        }
    });
};

String.prototype.string = function(len) {
    var s = '',
        i = 0;
    while (i++ < len) {
        s += this;
    }
    return s;
};
String.prototype.zf = function(len) {
    return "0".string(len - this.length) + this;
};
Number.prototype.zf = function(len) {
    return this.toString().zf(len);
};


// 숫자체크
function checkNumber(val) {
    var regexp = /^[0-9]*$/
    if (!regexp.test(val)) {
        return false;
    }
    return true;
}

// 이메일체크
function checkEmail(val) {
    var regexp = /^[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[@]{1}[-A-Za-z0-9_]+[-A-Za-z0-9_.]*[.]{1}[A-Za-z]{1,5}$/;
    if (!regexp.test(val)) {
        return false;
    }
    return true;
}

// 전화번호체크
function checkPhone(val) {
    var regexp = /^\d{2,3}-\d{3,4}-\d{4}$/;
    if (!regexp.test(val)) {
        return false;
    }
    return true;
}


// 전화번호체크
function checkMobile(val) {
    var regexp = /^((01[1|6|7|8|9])[1-9]+[0-9]{6,7})|(010[1-9][0-9]{7})$/;
    if (!regexp.test(val)) {
        return false;
    }
    return true;
}


// 콤마
function setComma(_no) {
    return _no.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

// json sort
function sortJSON(data, key, way) {
    return data.sort(function(a, b) {
        var x = a[key];
        var y = b[key];
        if (way === '123') {
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
        }
        if (way === '321') {
            return ((x > y) ? -1 : ((x < y) ? 1 : 0));
        }
    });
}

// 아이디 유효성 체크
function member_id_valid_check(val) {
    var regexp = /^[a-zA-Z0-9_-]{5,20}$/;
    if (!regexp.test(val)) {
        return false;
    }
    return true;
}

// 비밀번호 유효성 체크
function member_pwd_valid_check(val) {
    var regexp = /[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/;
    if (regexp.test(val)) {
        return false;
    }
    if (val.length < 6) return false;
    if (val.length > 16) return false;

    return true;
}


var scale = 1;

function zoom_in() {
    scale *= 1.25;
    zoom(scale);
}

function zoom_out() {
    scale /= 1.25;
    zoom(scale);
}

function zoom(scale) {
    var body = document.body;
    body.style.zoom = scale; // IE
    body.style.webkitTransform = 'scale(' + scale + ')'; // Webkit(chrome)
    body.style.webkitTransformOrigin = '0 0';
    body.style.mozTransform = 'scale(' + scale + ')'; // Mozilla(firefox)
    body.style.mozTransformOrigin = '0 0';
    body.style.oTransform = 'scale(' + scale + ')'; // Opera
    body.style.oTransformOrigin = '0 0';
}

// 폰트크기 조절
var targets = new Array('div', 'td', 'tr', 'li', 'ul', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'input');
var sizes = new Array('9', '12', '14', '16', '18', '20', '22', '24', '26');
var startSize = 1;

function ts(target, inc) {
    if (!document.getElementById) return;
    var d = document,
        cEl = null,
        size = startSize,
        i, j, cTags;
    size += inc;
    if (size < 0) {
        size = 0;
    }
    if (size > 9) {
        size = 9;
    }
    startSize = size;
    if (!(cEl = d.getElementById(target))) {
        cEl = d.getElementsByTagName(target)[0];
    }
    cEl.style.fontSize = sizes[size];
    for (i = 0; i < targets.length; i++) {
        cTags = cEl.getElementsByTagName(targets[i]);
        for (j = 0; j < cTags.length; j++) {
            cTags[j].style.fontSize = sizes[size] + "pt";
            cTags[j].style.lineHeight = sizes[size] * 1.5 + "pt";
        }
    }
}
// 폰트크기 조절

function search_keyword_reg(keyword) {
    var return_state = true;
    var form_data = {
        "keyword": keyword
    };
    $.ajax({
        url: '/web/search/search_keyword_reg',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function(rtnJson) {
            if (rtnJson.code == '9999') {
                alert(rtnJson.msg);
                return_state = false;
            } else {
                return_state = true;
            }
        },
        error: function(rtnHtml) {
            return_state = false;
        }

    });
    return return_state;
}

// $(function() {
//     $(document).bind("contextmenu", function(e) {
//         return false;
//     });
// })