﻿cummunity = function(){};

cummunity.prototype = {
    main: function () {
        $('.preview').click(function () {
            $("#preview").remove();
            $('.imageview').remove();
            var src = $(this).attr('src');
            var image = new Image();
            image.src = src;
            var width = image.width;
            var height = image.height;
            var top = $('html').attr('scrollTop') + 100;
            var left = (parseInt($('body').css('width')) - height) / 2;
            $('body').append('<div class="imageview"><div class="imageview_top"><img src="/images/photo_top.gif" alt="" /></div></div>');
            $('.imageview').css('left', left).css('top', top);
            $('.imageview').animate({ width: width + 2, height: height + 31, 'min-width': 300, 'min-height': 300 }, 'show');
            setTimeout(function () {
                $('.imageview').append('<img src="' + src + '" alt="" style="width:' + width + 'px; height:' + height + 'px;">');
            }, '500');
            $('.imageview').click(function () { $(this).remove(); });
        });
    },
    main_write: function () {
        $('#write').click(function () {
            if ($('#subject').val() == '') { alert('제목을 입력해주세요.'); $('#subject').focus(); return false; }
            if ($('#contents').val() == '') { alert('내용을 입력해주세요.'); $('#contents').focus(); return false; }
            if ($('#imgName').val().length > 0) {
                var file_type = $('#imgName').val().split('.')[$('#imgName').val().split('.').length - 1];
                if (file_type == 'bmp' || file_type == 'jpg' || file_type == 'gif' || file_type == 'zip') { }
                else {
                    alert('파일 확장자는 bmp, jpg, gif, zip만 가능합니다.');
                    return false;
                }
            }
        });
    },
    main_sub: function () {
        $('.preview').click(function () {
            $("#preview").remove();
            $('.imageview').remove();
            var src = $(this).attr('src');
            var image = new Image();
            image.src = src;
            var width = image.width;
            var height = image.height;
            var top = $('html').attr('scrollTop') + 100;
            var left = (parseInt($('body').css('width')) - height) / 2;
            $('body').append('<div class="imageview"><div class="imageview_top"><img src="/images/photo_top.gif" alt="" /></div></div>');
            $('.imageview').css('left', left).css('top', top);
            $('.imageview').animate({ width: width + 2, height: height + 31, 'min-width': 300, 'min-height': 300 }, 'show');
            setTimeout(function () {
                $('.imageview').append('<img src="' + src + '" alt="" style="width:' + width + 'px; height:' + height + 'px;">');
            }, '500');
            $('.imageview').click(function () { $(this).remove(); });
        });
        $('.point').click(function () {
            var point;
            $('input[name="point"]').each(function () { if ($(this).attr('checked')) point = $(this).val(); });
            $.post('/inc/xml/community.aspx', { 'type': 'main_point', 'o': $('#ussIdx').val(), 'p': point }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1') alert('처리중 문제가 생겼습니다.');
                    if ($(this).attr('value') == '0') alert('이미 점수를 주셨습니다.');
                    else {
                        alert(point + '포인트 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
        $('.comment').click(function () {
            var comment_img;
            if ($('#comment_text').val() < 2) {
                alert('내용을 입력해주세요');
                $('#comment_text').focus();
                return;
            }
            $('input[name="comment"]').each(function () { if ($(this).attr('checked')) comment_img = $(this).val(); });
            $.post('/inc/xml/community.aspx', { 'type': 'main_comment', 'o': $('#ussIdx').val(), 'comment': $('#comment_text').val(), 'imgNum': comment_img }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1') alert('처리중 문제가 생겼습니다.');
                    else {
                        alert('댓글이 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
    },
    knowhow: function () {

    },
    knowhow_sub: function () {
        $('.point').click(function () {
            var point;
            $('input[name="point"]').each(function () { if ($(this).attr('checked')) point = $(this).val(); });
            $.post('/inc/xml/community.aspx', { 'type': 'knowhow_point', 'o': $('#ussIdx').val(), 'p': point }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1') alert('처리중 문제가 생겼습니다.');
                    if ($(this).attr('value') == '0') alert('이미 점수를 주셨습니다.');
                    else {
                        alert(point + '포인트 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
        $('.comment').click(function () {
            if ($('#comment_text').val() < 2) {
                alert('내용을 입력해주세요');
                $('#comment_text').focus();
                return;
            }
            var comment_img;
            $('input[name="comment"]').each(function () { if ($(this).attr('checked')) comment_img = $(this).val(); });
            $.post('/inc/xml/community.aspx', { 'type': 'knowhow_comment', 'o': $('#ussIdx').val(), 'comment': $('#comment_text').val(), 'imgNum': comment_img }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1') alert('처리중 문제가 생겼습니다.');
                    else {
                        alert('댓글이 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
    },
    knowhow_write: function () {
        $('#write').click(function () {
            if ($('#subject').val() == '') { alert('제목을 입력해주세요.'); $('#subject').focus(); return false; }
            if ($('#contents').val() == '') { alert('내용을 입력해주세요.'); $('#contents').focus(); return false; }
        });
    },
    story: function () {

    },
    story_write: function () {
        $('#write').click(function () {
            if ($('#subject').val() == '') { alert('제목을 입력해주세요.'); $('#subject').focus(); return false; }
            if ($('#contents').val() == '') { alert('내용을 입력해주세요.'); $('#contents').focus(); return false; }
        });
    },
    story_sub: function () {
        $('.point').click(function () {
            var point;
            $('input[name="point"]').each(function () { if ($(this).attr('checked')) point = $(this).val(); });
            $.post('/inc/xml/community.aspx', { 'type': 'story_point', 'o': $('#ussIdx').val(), 'p': point }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1') alert('처리중 문제가 생겼습니다.');
                    if ($(this).attr('value') == '0') alert('이미 점수를 주셨습니다.');
                    else {
                        alert(point + '포인트 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
        $('.comment').click(function () {
            if ($('#comment_text').val() < 2) {
                alert('내용을 입력해주세요');
                $('#comment_text').focus();
                return;
            }
            var comment_img;
            $('input[name="comment"]').each(function () { if ($(this).attr('checked')) comment_img = $(this).val(); });
            $.post('/inc/xml/community.aspx', { 'type': 'story_comment', 'o': $('#ussIdx').val(), 'comment': $('#comment_text').val(), 'imgNum': comment_img }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1') alert('처리중 문제가 생겼습니다.');
                    else {
                        alert('댓글이 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
    },
    devnote: function () {
    },
    devnote_sub: function () {
        $('.comment').click(function () {
            if ($('#comment_text').val() < 2) {
                alert('내용을 입력해주세요');
                $('#comment_text').focus();
                return;
            }
            $.post('/inc/xml/community.aspx', { 'type': 'devnote_comment', 'o': $('#HiddenNewsIDX').val(), 'comment': $('#comment_text').val() }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1')
                        alert('처리중 문제가 생겼습니다.');
                    else {
                        alert('댓글이 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
        $('#comment_text').keydown(function (e) {
            if (e.which == 13) {
                $('.comment').click();
                return false;
            }
        });
    },

    free_write: function () {
        $('#write').click(function () {
            if ($('#subject').val() == '') { alert('제목을 입력해주세요.'); $('#subject').focus(); return false; }
        });
    },
    free_sub: function () {
        $('.comment').click(function () {
            if ($('#comment_text').val() < 2) {
                alert('내용을 입력해주세요');
                $('#comment_text').focus();
                return;
            }
            $.post('/inc/xml/community.aspx', { 'type': 'free_comment', 'o': $('#HiddenFreeIDX').val(), 'comment': $('#comment_text').val() }, function (data) {
                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1')
                        alert('처리중 문제가 생겼습니다.');
                    else {
                        alert('댓글이 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
        $('#del').click(function () {
            if (!confirm('게시물을 삭제하겠습니까?'))
                return false;
        });
        $('#comment_text').keydown(function (e) {
            if (e.which == 13) {
                $('.comment').click();
                return false;
            }
        });
    },


    eventscreen_write: function () {
        $('#write').click(function () {
            if ($('#subject').val() == '') { alert('제목을 입력해주세요.'); $('#subject').focus(); return false; }
        });
    },
    eventscreen_sub: function () {

        $('.comment').click(function () {
            if ($('#comment_text').val() < 2) {
                alert('내용을 입력해주세요');
                $('#comment_text').focus();
                return;
            }


            $.post('/inc/xml/community.aspx', { 'type': 'eventscreen_comment', 'o': $('#HiddenBoardIdx').val(), 'comment': $('#comment_text').val() }, function (data) {

                $(data).find("result").each(function (i) {
                    if ($(this).attr('value') == '-1') {
                        alert($(this).attr('value'));
                        alert('처리중 문제가 생겼습니다.');
                    } else {
                        alert('댓글이 추가되었습니다.');
                        location.href = location.href;
                    }
                });
            });
        });
        $('#del').click(function () {
            if (!confirm('게시물을 삭제하겠습니까?'))
                return false;
        });
        $('#comment_text').keydown(function (e) {
            if (e.which == 13) {
                $('.comment').click();
                return false;
            }
        });
    }
}
