<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_EDITOR_LIB);
include_once($board_skin_path.'/view_comment.php'); //코멘트 파일을 재정의
?>

<script>
// 글자수 제한
var char_min = parseInt(<?php echo $comment_min ?>); // 최소
var char_max = parseInt(<?php echo $comment_max ?>); // 최대
</script>

<!--댓글 쓰기-->
<?php if($is_comment_write) { ?>
<div id="comment-write">
    <button type="button" id="comment-write-button" style="display:none;">댓글 쓰기</button>
    <form id="fcommentform" enctype="multipart/form-data">
    <input type="hidden" name="w" value="c" id="w">
    <input type="hidden" name="bo_table" value="<?php echo $bo_table ?>" id="bo_table">
    <input type="hidden" name="wr_id" value="<?php echo $wr_id ?>">
    <input type="hidden" name="comment_id" value="" id="comment_id">
    <input type="hidden" name="sca" value="<?php echo $sca ?>">
    <input type="hidden" name="sfl" value="<?php echo $sfl ?>">
    <input type="hidden" name="stx" value="<?php echo $stx ?>">
    <input type="hidden" name="spt" value="<?php echo $spt ?>">
    <input type="hidden" name="page" value="<?php echo $page ?>">
    <input type="hidden" name="is_good" value="">
    <div class="fcommentw">
        <?php if($is_member) { ?>
        <div class="cw_info"><?php echo $member['mb_name'];// ?></div>
        <?php } else { ?>
        <div class="cw_guest">
            <div class="cw_guest_info">
                <div class="cw_name">
                    <label for="wr_name" class="sound_only">이름<strong> 필수</strong></label>
                    <input type="text" name="wr_name" value="<?php echo get_cookie("ck_sns_name"); ?>" id="wr_name" class="write_input" placeholder="이름">
                </div>
                <div class="cw_pass">
                    <label for="wr_password" class="sound_only">비밀번호<strong> 필수</strong></label>
                    <input type="password" name="wr_password" id="wr_password" class="write_input cw_pass" placeholder="비밀번호">
                </div>
            </div>
            <div class="cw_captcha"><?php echo $captcha_html;?></div>
        </div>
        <?php } ?>
        <div class="cw_option">
            <div class="cw_option_header">
                <div class="opt_btn btn_movie" data-option="movie"><i class="fa fa-youtube"></i>동영상</div>
                <?php if($board['bo_upload_count'] > 0) { ?><div class="opt_btn btn_file"  data-option="file"><i class="fa fa-file-o"></i>첨부파일</div><?php } ?>
                <div class="opt_btn btn_empticon" data-option="emoticon"><i class="fa fa-meh-o"></i>이모티콘</div>
            </div>
            <div class="cw_option_movie">
                <label for="wr_movie_url" class="sound_only">동영상 경로</label>
                <input type="text" name="wr_movie_url" value="" id="wr_movie_url" class="write_input" placeholder="동영상 주소를 입력하세요. 현재 유튜브만 지원합니다.">
            </div>
            <?php if($board['bo_upload_count'] > 0) { ?>
            <div class="cw_option_file">
                <label for="bf_file_0" class="sound_only">첨부파일</label>
                <input type="file" name="bf_file[]" value="" id="bf_file_0" class="write_input write_file">
                <div id="co_file_del_0" class="file_del"></div>
                <div class="file_btn">
                    <button type="button" class="btn_add_file" data-fileno="0">+</button>
                    <!--<button type="button" class="btn_del_file" data-fileno="0">-</button>-->
                </div>
            </div>
            <?php } ?>
        </div>
        <div class="cw_form">
            <script src="<?php echo G5_PLUGIN_URL; ?>/editor/smarteditor2/js/service/HuskyEZCreator.js"></script>
            <script> var g5_editor_url = "<?php echo G5_PLUGIN_URL;?>/editor/smarteditor2", oEditors = [], ed_nonce = "<?php echo ft_nonce_create('smarteditor');?>";</script>
            <script src="<?php echo G5_PLUGIN_URL?>/editor/smarteditor2/config.js"></script>
            <textarea id="wr_content" name="wr_content" style="width:100%; height: 120px;" class="smarteditor2"></textarea>
        </div>
        <div class="cw_form_tail">
            <div class="cw_secret">
                <input type="checkbox" name="wr_secret" id="wr_secret" value="secret">
                <label for="wr_secret">비밀글</label>
            </div>
            <div class="cw_btn">
                <button type="button" id="co_cancel" class="btn_board btn_board_cancel">취소</button>
                <button type="button" id="co_submit" class="btn_board btn_board_submit">댓글등록</button>
            </div>
        </div>
        <div id="comment-loader"><div class="loader-image"><img src="<?php echo $board_skin_url;?>/img/ajax-loader.gif"></div></div>
    </div>
    </form>
</div>
<!-- 댓글 쓰기 -->
<?php } ?>

<div id="comment-list-wrap">
    <div class="comment-bar">
        <b><i class="fa fa-commenting"></i> 댓글<span class="cmt_total"><?php echo $view['wr_cmt_num']; ?></span></b>
        <button type="button" class="btn_board comment-btn"></button>
    </div>
    <div id="comment-list">
    <?php
    $cmt_amt = count($list);
    for ($i=0; $i<$cmt_amt; $i++) {
        $comment_id = $list[$i]['wr_id'];
        $comment = $list[$i]['content'];
        $comment = preg_replace("/\[\<a\s.*href\=\"(http|https|ftp|mms)\:\/\/([^[:space:]]+)\.(mp3|wma|wmv|asf|asx|mpg|mpeg)\".*\<\/a\>\]/i", "<script>doc_write(obj_movie('$1://$2.$3'));</script>", $comment);
        $pa_name = '';
        if($list[$i]['wr_cmt_depth'] > 1) {
            $pa  = sql_fetch("select * from {$write_table} where wr_id = '{$list[$i]['wr_cmt_parent']}'");
            $pa_name = $pa['wr_name'];
        }

        echo '<div id="comment_'.$comment_id.'" class="co_list" data-id="'.$comment_id.'" data-depth="'.$list[$i]['wr_cmt_depth'].'">';
        echo '<input type="hidden" name="opt_movie['.$comment_id.']" value="'.$list[$i]['wr_1'].'" class="opt_movie">';
            echo '<div class="co_wrap">';
                echo '<div class="co_header">';
                    echo '<div class="co_photo">'.get_member_profile_img($list[$i]['mb_id']).'</div>';
                    echo '<span class="co_name">'.$list[$i]['name'].'</span>';
                    echo '<span class="co_date">'.$list[$i]['datetime'].'</span>';
                echo '</div>';
                //첨부파일
                if($list[$i]['file']['count'] > 0) {
                    echo '<ul class="co_file">';
                    for($f=0;$f<$list[$i]['file']['count'];$f++) {
                        if (isset($list[$i]['file'][$f]['source']) && $list[$i]['file'][$f]['source']) { //이미지도 별도 출력하지 않고 다운로드 처리
                            echo '<li class="file_list">';
                            echo '<i class="fa fa-folder-open" aria-hidden="true"></i>';
                            echo '<a href="'.$list[$i]['file'][$f]['href'].'" class="view_file_download">'.$list[$i]['file'][$f]['source'].$list[$i]['file'][$f]['content'].'('.$list[$i]['file'][$f]['size'].')</a>';
                            echo '<span class="co_file_cnt">'.$list[$i]['file'][$f]['download'].'회 다운로드 <span class="mobile-none">| DATE : '.$list[$i]['file'][$f]['datetime'].'</span></span>';
                            echo '<input type="hidden" name="co_file_name[]" value="'.$list[$i]['file'][$f]['source'].'" class="co_file_name">';
                            echo '<input type="hidden" name="co_file_no[]" value="'.$f.'" class="co_file_no">';
                            echo '</li>';
                        }
                    }
                    echo '</ul>';
                }
                echo '<div class="co_content">';
                    if($pa_name) {
                        echo '<span class="m">@'.$pa_name.'</span>';
                    }
                    if($list[$i]['movie']) {
                        echo '<lite-youtube videoid="'.$list[$i]['movie'].'" playlabel=""></lite-youtube>';
                    }
                    echo $comment;
                echo '</div>';
                echo '<div class="co_ico_wrap">';
                    if($board['bo_use_good']) { echo '<span class="co_ico co_good" data-mode="good"><i class="fa fa-thumbs-o-up"></i><span class="good_cnt">'.$list[$i]['wr_good'].'</span></span>'; }
                    if($board['bo_use_nogood']) { echo '<span class="co_ico co_nogood" data-mode="nogood"><i class="fa fa-thumbs-o-down"></i><span class="nogood_cnt">'.$list[$i]['wr_nogood'].'</span></span>'; }
                    if($list[$i]['is_edit']) { echo '<span class="co_ico co_mod" data-mode="modify">수정</span>'; }
                    if($list[$i]['is_del']) { echo '<span class="co_ico co_del" data-mode="delete">삭제</span>'; }
                    echo '<span class="co_ico co_rep" data-mode="reply">답글'.$list[$i]['wr_cmt_num'].'</span>';
                    echo '<span id="ico_msg_'.$list[$i]['wr_id'].'" class="ico_msg"></span>';
                echo '</div>';
            echo '</div>';
            echo '<div class="co_write_form"></div>';
        echo '</div>';
    }
    ?>
    </div>
</div>

<script>
var board_good   = '<?php echo $board['bo_use_good'];?>';
var board_nogood = '<?php echo $board['bo_use_nogood'];?>';
var file_count   = parseInt(<?php echo (int)$board['bo_upload_count']; ?>);
$(function() {
    //댓글열기
    $('.comment-btn').click(function(){
        if( $(this).hasClass('comment-btn-open')) {
            $(this).removeClass('comment-btn-open');
            $('#comment-list').removeClass('close');
        } else {
            $(this).addClass('comment-btn-open');
            $('#comment-list').addClass('close');
        }
    });

    $(document).on("chagnge", ".emoti_cate", function() {
        var $this = $(this),
            value = $this.val();
        $('.emoti_box').hide();
        $('#emoticon_'+value).show();
    });

    $(document).on("click",".btn_add_file", function() {
        var $this  = $(this),
            $wrap  = $this.closest('.cw_option_file'),
            fileno = parseInt($this.data('fileno')),
            cnt    = $('.cw_option_file').length;
        if(cnt >= file_count) {
            alert('첨부파일은 최대 '+file_count+'개 까지 등록하실 수 있습니다.');
            return false;
        }
        fileno = fileno + 1;
        var html = '';
        html += '<div class="cw_option_file on">';
            html += '<label for="bf_file_'+fileno+'" class="sound_only">첨부파일</label>';
            html += '<input type="file" name="bf_file[]" value="" id="bf_file_'+fileno+'" class="write_input write_file">';
            html += '<div id="co_file_del_'+fileno+'" class="file_del"></div>';
            html += '<div class="file_btn">';
                html += '<button type="button" class="btn_add_file" data-fileno="'+fileno+'">+</button>';
                html += '<button type="button" class="btn_del_file" data-fileno="'+fileno+'">-</button>';
            html += '</div>';
        html += '</div>';
        $wrap.after(html);
    });

    $(document).on("click",".btn_del_file", function() {
        var $this  = $(this),
            $wrap  = $this.closest('.cw_option_file'),
            fileno = parseInt($this.data('fileno'));
        $wrap.remove();
    });

    $(document).on("click", ".opt_btn", function() {
        var $this = $(this),
            opt   = $this.data('option');
        if(opt == 'movie' || opt == 'file') {
            if( $('.cw_option_'+opt).hasClass('on')) {
                $('.cw_option_'+opt).removeClass('on');
            } else {
                $('.cw_option_'+opt).addClass('on');
            }
        }
        
        if(opt == 'emoticon') {
            $.ajax({
            type: "POST",
            data: { act:'emoticon', bo_table:'<?php echo $bo_table ?>' },
                url: '<?php echo $board_skin_url;?>/ajax.board.php',
                success: function(data) {
                    if(data.result == 'failer') {
                        alert(data.message);
                        return false;
                    }
                    var tle  = '';
                    var html = '';
                    $('#myModal').addClass('fadedown emoticon');
                    html += '<div class="emoti_wrapper">';
                        html += '<div class="emoti_cate">';
                            html += '<select name="emoti_cate" id="emoti_cate">';
                            $.each(data.emoti_dir, function(i,$i) {
                                html += '<option value="'+$i+'">'+$i+'</option>';
                            });
                            html += '</select>';
                        html += '</div>';
                        html += '<div class="emoti_list">';
                            $.each(data.emoticon, function(i,$i) {
                                var emoticon = $i;
                                html += '<div id="emoticon_'+i+'" class="emoti_box">';
                                    $.each(emoticon, function(i,$i) {
                                        html += '<div class="emoti_data" data-url="'+$i+'">';
                                            html += '<img src="'+$i+'">';
                                        html += '</div>';
                                    });
                                html += '</div>';
                            });
                        html += '</div>';
                    html += '</div>';
                    $('.header-title').empty().append(tle);
                    $('.myModal-body').empty().append(html);
                    $('#myModal').show(0,'swing', function() {
                        $('html').addClass('noscroll');
                        $('#myModal .myModal-content').addClass('open');
                    });
                    $("#emoti_cate option:eq(0)").prop("selected",true);
                }
            });
            return false;
        }
    });

    $(document).on("click", ".emoti_data", function() {
        var $this = $(this),
            image = $this.data('url');
        if(image) {
            var html = '<img src="'+image+'">';
            oEditors.getById["wr_content"].exec("PASTE_HTML", [html]);
        }
        $('.closex').trigger('click');
    });

    $(document).on("click", "#co_submit", function() {
        var $this = $(this),
            $wrap = $this.closest('form'),
            act   = $('#w').val();
        <?php if($is_guest) { ?>
        var wr_name = $('#wr_name').val();
        var wr_pass = $('#wr_password').val();
        if( !wr_name || !wr_pass ) {
            alert('이름과 비밀번호를 입력해 주세요');
            return false;
        }
        <?php } ?>
        <?php if($is_guest) { echo chk_captcha_js(); } ?>
        if(act != 'cd') {
            var wr_content_editor_data = oEditors.getById['wr_content'].getIR();
                oEditors.getById['wr_content'].exec('UPDATE_CONTENTS_FIELD', []);
                if(jQuery.inArray(document.getElementById('wr_content').value.toLowerCase().replace(/^\s*|\s*$/g, ''), ['&nbsp;','<p>&nbsp;</p>','<p><br></p>','<div><br></div>','<p></p>','<br>','']) != -1){document.getElementById('wr_content').value='';}
                if (!wr_content_editor_data || jQuery.inArray(wr_content_editor_data.toLowerCase(), ['&nbsp;','<p>&nbsp;</p>','<p><br></p>','<p></p>','<br>']) != -1) { alert("내용을 입력해 주십시오."); oEditors.getById['wr_content'].exec('FOCUS'); return false; }
        }
        var f = document.getElementById("fcommentform");
        set_comment_token(f);
        var formData = new FormData($wrap[0]);
        $('#comment-loader').addClass('on');
        $.ajax({
            processData: false,
            contentType: false,
            type: "POST",
            data: formData,
            async: false,
            url: '<?php echo $board_skin_url;?>/ajax.board.php',
            success: function(data) {
                //console.log(data);
                if(data.result == 'failer') {
                    alert(data.message);
                    return false;
                }
                setTimeout(function() {
                    if(data.w == 'c' || data.w == 'cr') { //등록, 댓글답변
                        var html = '';
                        html += '<div id="comment_'+data.comment.wr_id+'" class="co_list co_depth_'+data.comment.wr_cmt_depth+'" data-id="'+data.comment.wr_id+'" data-depth="'+data.comment.wr_cmt_depth+'">';
                        html += '<input type="hidden" name="opt_movie['+data.comment.wr_id+']" value="'+data.comment.wr_1+'" class="opt_movie">';
                            html += '<div class="co_wrap co_new">';
                                html += '<div class="co_header">';
                                    html += '<div class="co_photo">'+data.comment.photo+'</div>';
                                    html += '<span class="co_name">'+data.comment.wr_name+'</span>';
                                    html += '<span class="co_date">'+data.comment.wr_datetime+'</span>';
                                html += '</div>';
                                if(data.comment.file.count > 0) {
                                    html += '<ul class="co_file">';
                                    for(var i=0; i < data.comment.file.count; i++) {
                                        var co_file = data.comment.file[i];
                                        html += '<li class="file_list">';
                                        html += '<i class="fa fa-folder-open" aria-hidden="true"></i>';
                                        html += '<a href="'+co_file['href']+'" class="view_file_download">'+co_file['source']+co_file['content']+'('+co_file['size']+')</a>';
                                        html += '<span class="co_file_cnt">'+co_file['download']+'회 다운로드 <span class="mobile-none">| DATE : '+co_file['datetime']+'</span></span>';
                                        html += '<input type="hidden" name="co_file_name[]" value="'+co_file['source']+'" class="co_file_name">';
                                        html += '<input type="hidden" name="co_file_no[]" value="'+i+'" class="co_file_no">';
                                        html += '</li>';
                                    }
                                    html += '</ul>';
                                }
                                html += '<div class="co_content">';
                                if(data.comment.wr_cmt_depth > 1) {
                                    html += '<span class="m">@'+data.comment.pa_name+'</span>';
                                }
                                if(data.comment.movie) {
                                    html += '<lite-youtube videoid="'+data.comment.movie+'" playlabel=""></lite-youtube>';
                                }
                                html += data.comment.wr_content;
                                html += '</div>';
                                html += '<div class="co_ico_wrap">';
                                    if(board_good) { html += '<span class="co_ico co_good" data-mode="good"><i class="fa fa-thumbs-o-up"></i><span class="good_cnt">0</span></span>'; }
                                    if(board_nogood) { html += '<span class="co_ico co_nogood" data-mode="nogood"><i class="fa fa-thumbs-o-up"></i><span class="nogood_cnt">0</span></span></span>'; }
                                    html += '<span class="co_ico co_mod" data-mode="modify">수정</span>';
                                    html += '<span class="co_ico co_del" data-mode="delete">삭제</span>';
                                    html += '<span class="co_ico co_rep" data-mode="reply">답글'+data.comment.wr_cmt_num+'</span>';
                                    html += '<span id="ico_msg_'+data.comment.wr_id+'" class="ico_msg"></span>';
                                html += '</div>';
                            html += '</div>';
                            html += '<div class="co_write_form"></div>';
                        html += '</div>';
                    }
                    if(data.w == 'c') {
                        //oEditors.getById["wr_content"].exec("SET_IR", [""]);
                        $('#comment-list').prepend(html);
                        $('#comment-write-button').trigger('click');
                    }
                    if(data.w == 'cu') { //수정
                        if(data.comment.file.count == 0) {
                            $('#comment_'+data.comment.wr_id).find('.co_file').remove();
                        } else {
                            html = '';
                            for(var i=0; i < data.comment.file.count; i++) {
                                var co_file = data.comment.file[i];
                                html += '<li class="file_list">';
                                html += '<i class="fa fa-folder-open" aria-hidden="true"></i>';
                                html += '<a href="'+co_file['href']+'" class="view_file_download">'+co_file['source']+co_file['content']+'('+co_file['size']+')</a>';
                                html += '<span class="co_file_cnt">'+co_file['download']+'회 다운로드 <span class="mobile-none">| DATE : '+co_file['datetime']+'</span></span>';
                                html += '<input type="hidden" name="co_file_name[]" value="'+co_file['source']+'" class="co_file_name">';
                                html += '<input type="hidden" name="co_file_no[]" value="'+i+'" class="co_file_no">';
                                html += '</li>';
                            }
                            $('#comment_'+data.comment.wr_id).find('.co_file').empty().html(html);
                        }

                        var ohtml = $('#comment_'+data.comment.wr_id).find('.co_content').html();
                        var pa_name = /<span class="m">(.*)<\/span>/.exec(ohtml);
                        var html = '';
                        if(pa_name) {
                            html += pa_name[0];
                        }
                        if(data.comment.movie) {
                            html += '<lite-youtube videoid="'+data.comment.movie+'" playlabel=""></lite-youtube>';
                        }
                        html += data.comment.wr_content;
                        $('#comment_'+data.comment.wr_id).find('.co_content').empty().html(html);
                        $('#comment-write-button').trigger('click');
                    }
                    if(data.w == 'cr') {
                        $('#comment-write-button').hide();
                        $('#comment_'+data.comment.pa_id).after(html);
                        $('#comment-write-button').trigger('click');
                    }
                    if(data.w == 'cd') {
                        $('#comment_'+data.comment.wr_id).find('.co_content').empty().html(data.comment.wr_content);
                    }
                    
                    $('#comment-loader').removeClass('on');
                }, 1000);
            }
        });
    });

    $(document).on("click", ".co_ico", function() {
        var $this = $(this),
            $wrap = $this.closest('.co_list'),
            wr_id = $wrap.data('id'),
            mode  = $this.data('mode'),
            $form = $('#fcommentform');
        if(mode == 'modify' || mode == 'reply') {
            $wrap.find('.co_wrap').addClass('co_new');
        }
        if(mode == 'modify') {
            var movie      = $wrap.find('.opt_movie').val() ? $wrap.find('.opt_movie').val() : '';
            var co_file    = $wrap.find('.file_list').length;
            var content = $wrap.find('.co_content').html(),
                content = content.replace(/<span class="m">(.*)<\/span>/g,'');
                content = content.replace(/<lite-youtube(.*)<\/lite-youtube>/g,'');

            $('#w').val('cu');
            $('#comment_id').val(wr_id);
            $('#co_submit').empty().text('댓글수정');
            $wrap.find('.co_write_form').append($form);
            document.getElementById('wr_content').value = content;
            //$('#comment-write-button').show();
            $('#wr_movie_url').val('');
            if(movie) {
                $('#wr_movie_url').val(movie);
                $('.btn_movie').trigger('click');
            }

            if(co_file > 0) {
                $('.cw_option_file').remove();
                html = '';
                $.each($wrap.find('.file_list'), function() {
                    var file_name = $(this).find('.co_file_name').val() ? $(this).find('.co_file_name').val() : '';
                    var file_no   = $(this).find('.co_file_no').val();
                    html += '<div class="cw_option_file on">';
                        html += '<label for="bf_file_0" class="sound_only">첨부파일</label>';
                        html += '<input type="file" name="bf_file['+file_no+']" value="" id="bf_file_'+file_no+'" class="write_input write_file">';
                        html += '<div id="co_file_del_'+file_no+'" class="file_del"><input type="checkbox" id="bf_file_del'+file_no+'" name="bf_file_del['+file_no+']" value="1"><label for="bf_file_del'+file_no+'">'+file_name+' 파일 삭제</label></div>';
                        html += '<div class="file_btn">';
                            html += '<button type="button" class="btn_add_file" data-fileno="'+file_no+'">+</button>';
                            if(file_no > 0 && !file_name) { //등록된 파일이 있을 경우 폼 삭제 불가
                                html += '<button type="button" class="btn_del_file" data-fileno="'+file_no+'">-</button>';
                            }
                        html += '</div>';
                    html += '</div>';
                });
                $('.cw_option_movie').after(html);
            }
            document.getElementById('comment_'+wr_id).scrollIntoView(true);
        }
        if(mode == 'reply') {
            $('#w').val('cr');
            $('#comment_id').val(wr_id);
            $('#co_submit').empty().text('댓글답변');
            $wrap.find('.co_write_form').append($form);
            document.getElementById('wr_content').value = '';
            //$('#comment-write-button').show();
            document.getElementById('comment_'+wr_id).scrollIntoView(true);
        }
        if(mode == 'delete') {
            $('#w').val('cd');
            $('#comment_id').val(wr_id);
            var cf = confirm('삭제한 댓글은 다시 복구할 수 없습니다. 삭제하시겠습니까?');
                if (cf === true) {
                    $('#co_submit').trigger('click');
                }
        }
        if(mode == 'good' || mode == 'nogood') {
            var table = $('#bo_table').val();
            if(!table) {
                return false;
            }
            $.ajax({
                type: "POST",
                data: { act:mode,bo_table:table,wr_id:wr_id },
                url: '<?php echo $board_skin_url;?>/ajax.board.php',
                success: function(data) {
                    $wrap.find('.ico_msg').text(data.message);
                    $wrap.find('.ico_msg').fadeIn(200).delay(2500).fadeOut(200);
                    if(data.result == 'success') {
                        $wrap.find('.'+mode+'_cnt').text(data.count);
                    }
                }
            });
        }
    });

    $(document).on("click", "#co_cancel", function() {
        $('#comment-write-button').trigger('click');
    });

    $(document).on("click", "#comment-write-button", function() {
        $(this).hide();
        $('#comment-write').append($('#fcommentform'));
        document.getElementById('wr_content').value = '';
        $('#co_submit').empty().text('댓글등록');
        $('#wr_movie_url').val('');
        $('#co_file_del').empty();
        $('.co_wrap').removeClass('co_new');
        $('.cw_option_movie').removeClass('on');
        $('.cw_option_file').removeClass('on');
    });
});
</script>

<!--modal-->
<div id="myModal" class="myModal">
    <div class="myModal-dialog">
        <div class="myModal-content">
            <div class="myModal-header">
                <h5 class="header-title"></h5>
                <button type="button" class="closex"></button>
            </div>
            <div class="myModal-body"></div>
            <div class="myModal-footer">
                <h5 class="footer-title"></h5>
                <button type="button" class="closex"></button>
            </div>
        </div>
    </div>
</div>
<!--modal-->
<script>
$(function() {
	$(document).on('click', '.closex', function() { //modal close
		$('#myModal .myModal-content').removeClass('open');
		setTimeout( function() {
			$('#myModal').hide();
			$('#myModal').removeClass().addClass('myModal');
			$('html').removeClass('noscroll');
		}, 300);
	});
	$(document).on('click', '#myModal', function(e) {
		if (e.target !== this) return;
		$('.closex').trigger('click');
	});
});

function showModal() {
	$('#myModal').show(0,'swing', function() {
		$('#myModal .myModal-content').addClass('open');
	});
}

function alertModal(message,time=1500) {
	$('#myModal').addClass('smcenter smalert');
	$('.myModal-body').empty().append(message);
	$('#myModal').show(0,'swing', function() {
		$('#myModal .myModal-content').addClass('open');
	}),setTimeout(function() { 
		$('.closex').trigger('click');
	}, time);
}
</script>
