var srvID = "";
var userID = "";
var mPage = 1;
var firstLoad = 0;
var aryau = "";
var ifrm;
var selectFirst = 0;
var fileOStr = '';
var fileNStr = '';
var fsave = false;
var upYes = false;
var originalFile = '';
var addum = null;
var AnnexType = "";
var eaddum = null;
var _frmData = { id: '', srvid: '' };
var _efrmData = { id: '', srvid: '' };
function resize_r() {
    var s = 0;
    var ss = $(window.parent.document).find('iframe[id=' + ifrm + ']');
    var l = $(window.parent.document).height() - ss.offset().top;
    var t = $(document).height();
    if (l > t) {
        s = l;
    }
    else {
        s = $(document).height();
    }
    $($(window.parent.document).find('iframe[id=' + ifrm + ']')).height(s);
    window.parent.sidebar_r();
}
$(function () {
    $("#PSize").change(function () {
        firstLoad = 0;
        mPage = 1;
        loadP($("#PSize").val(), 1);
    });
    $("#ggtitle").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1
    });
    var coks = document.cookie.substring(document.cookie.indexOf('userinf_tcwl'));
    var coksau = document.cookie.substring(document.cookie.indexOf('TCWL_All'));
    var ary = coks.split(';')[0].split('=');
    aryau = coksau.split(';')[0].split('=')[2];
    if (!ary[2]) {
        $('html').empty();
        return;
    }
    userID = ary[2].split('&')[0];
    srvID = ary[3];
    $('#Huserid').val(userID);
    $('#Hsrvid').val(srvID);
});

$('#AddDialog').on('shown.bs.modal', function () {
    if (addum == null) {
        addum = UM.getEditor('txtAddContent');
    }
    addum.setContent('');
});

$('#EditDialog').on('shown.bs.modal', function () {
        if (eaddum == null) {
            eaddum = UM.getEditor('txtAddContent');
        }
    
});

function existRole(s, p) {
    var e = p.indexOf(s);
    if (e == -1) {
        return false;
    }
    else {
        return true;
    }
}
function SelRole() {
    $('[tag]').each(function (i, e) {
        var tag = $(e).attr('tag');
        if (existRole(tag, aryau)) {
            $(e).show();
        }
        else {
            $(e).hide();
        }
    });
}
jQuery(function ($) {
    $('[data-rel=tooltip]').tooltip();
    $('[data-rel=popover]').popover({ html: true });
});
function ClickEvent() {
    $('[data-rel=tooltip]').tooltip();
    $('[data-rel=popover]').popover({ html: true });
}
function createPage(pageSize, buttons, total) {
    $(".pagination").jBootstrapPage({
        pageSize: pageSize,
        total: total,
        maxPageButton: buttons,
        onPageClicked: function (obj, pageIndex) {
            mPage = pageIndex + 1;
            loadP($("#PSize").val(), mPage);
        }
    });
}
$(function () {
    $(document).on('click', 'th input:checkbox', function () {
        var that = this;
        $(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function () {
			    this.checked = that.checked;
			    $(this).closest('tr').toggleClass('selected');
			});
    });
    $("[tag]").hide();
});
function LoadData() {
    var s = window.location.href.split('=');
    if (s.length == 4) {
        ifrm = s[3];
    }
    resize_r();
    var myDate = new Date();
    var m = myDate.getMonth() + 1;
    if (m < 10) {
        m = "0" + m;
    }
    var d = myDate.getDate();
    if (d < 10) {
        d = "0" + d;
    }
    var strattime = myDate.getFullYear() + "-" + m + "-01";
    var stime = myDate.getFullYear() + "-" + m + "-" + d;
    $("#TStart").val(strattime);
    $("#TEnd").val(stime);
    SelRole();

    $('#AddDialog').on('hide.bs.modal', function () {
        if (fsave == true) {
            delFile(fileOStr);

        }
        else {
            fileOStr += $('#hidfile').val();
            delFile(fileOStr);
        }
        $('#delfile').val('');
        $('#fList').empty();
        fileOStr = '';
        fileNStr = '';
        selectFirst = 0;
         fsave = false;
    });

    $('#EditDialog').on('hide.bs.modal', function () {
        if (fsave == true) {
            delFile(fileOStr);

        }
        else {
            if (upYes == true) {
                fileOStr += $('#uhidfile').val();
              fileOStr=  fileOStr.replace('' + originalFile + '', '');
            }
            delFile(fileOStr);
        }
        $('#delfile').val('');
        $('#fList1').empty();
        fileOStr = '';
        fileNStr = '';
        selectFirst = 0;
        fsave = false;
        upYes = false;
        originalFile = '';
        eaddum.setContent('');
    });

    function delFile(fname) {
        fsave = false;
        if (fname.length < 1) {
            return;
        }

        $('#delfile').val(fname);
        $.ajax({ url: '../../Handlers/common/common.aspx?Method=DelFile&user=' + userID + '&srvid=' + srvID, type: "post", cache: false, data: $('#frmDelFile').serialize(), success: function (d) {

        }, error: function () {

            //$('#LJFalse').modal('show');
        }
        });
}

    $('#uploadify').uploadify({
        'auto': true,
        'buttonCursor': 'hand',
        'buttonText': '选择文件',
        'height': 30,
        'width': 100,
        'debug': false,
        'multi': false,
        'fileTypeDesc': '描述文件类型',
        'fileTypeExts': '*.doc; *.jpg; *.xls',
        'preventCaching': true,
        'queueID': 'fileQueue',
        'removeTimeout': 1,
        'swf': '../Scripts/Uploadify/uploadify.swf',
        'uploader': '../Handlers/system/Daily.aspx?Method=upload',
        'fileSizeLimit': '5120KB',
        'formData': _frmData,
        'folder': 'UploadFile',
        'cancelImage': '../Scripts/Uploadify/uploadify-cancel.png',
        'onUploadSuccess': function (file, data, response) {
            if (selectFirst > 0) {
                $("#hidfile").val('');
            }
            selectFirst = 0;
            fileNStr = fileNStr + data + '╯';
            var mc = data.substring(data.lastIndexOf('/') + 1);
            mc = mc.substring(0, mc.lastIndexOf('.'));
            $("#hidfile").val($("#hidfile").val() + data + '╯');
            $('#uploadlist').show();
            var eachItem = $('<li style="float:left;"><img ></img><a style="float:left;"></a></li>');
            eachItem.find('a').attr('href', "../" + data);
            eachItem.find('a').attr('target', "_blank");
            eachItem.find('a').css({ 'display': 'block' });
            eachItem.find('img').attr('src', "../../Scripts/BootStrap/img/fj.png");
            eachItem.find('img').css({ 'width': '15px', 'height': '15px', 'float': 'left', 'margin-left': '5px' });
            eachItem.find('a').text(mc);
            $('#fList').append(eachItem);
//            $("#filedownload").text(data.split("/")[6]);
//            $("#filedownload").show();
//            $("#hidfile").val(data);
        },
        'onUploadComplete': function (file) {
        },
        'onQueueComplete': function (stats) {
            $('#animate').hide();
            $('#fList').show();
        },
        'onSelect': function (file) {
            if (selectFirst == 0) {
                selectFirst++;
                fileOStr += $("#hidfile").val();
            }
            $('#fList').empty();
            $('#animate').show();
            $('#fList').hide();
            _frmData.id = "khid";
            _frmData.srvid = srvID;
            $("#uploadify").uploadify("settings", "formData", { "srv": srvID, "user": userID });
        }
    });
    $('#uuploadify').uploadify({
        'auto': true,
        'buttonCursor': 'hand',
        'buttonText': '选择文件',
        'height': 30,
        'width': 100,
        'debug': false,
        'multi': false,
        'fileTypeDesc': '描述文件类型',
        'fileTypeExts': '*.doc; *.jpg; *.xls',
        'preventCaching': true,
        'queueID': 'fileQueue',
        'removeTimeout': 1,
        'swf': '../Scripts/Uploadify/uploadify.swf',
        'uploader': '../Handlers/system/Daily.aspx?Method=upload',
        'fileSizeLimit': '5120KB',
        'formData': _frmData,
        'folder': 'UploadFile',
        'cancelImage': '../Scripts/Uploadify/uploadify-cancel.png',
        'onUploadSuccess': function (file, data, response) {
            if (selectFirst > 0) {
                $("#uhidfile").val('');
            }
            selectFirst = 0;
            fileNStr = fileNStr + data + '╯';
            var mc = data.substring(data.lastIndexOf('/') + 1);
            mc = mc.substring(0, mc.lastIndexOf('.'));
            $("#uhidfile").val($("#uhidfile").val() + data + '╯');
            $('#uploadlist1').show();
            var eachItem = $('<li style="float:left;"><img ></img><a style="float:left;"></a></li>');
            eachItem.find('a').attr('href', "../" + data);
            eachItem.find('a').attr('target', "_blank");
            eachItem.find('a').css({ 'display': 'block' });
            eachItem.find('img').attr('src', "../../Scripts/BootStrap/img/fj.png");
            eachItem.find('img').css({ 'width': '15px', 'height': '15px', 'float': 'left', 'margin-left': '5px' });
            eachItem.find('a').text(mc);
            $('#fList1').append(eachItem);
            //            $("#ufiledownload").text(data.split("/")[6]);
            //            $("#ufiledownload").removeAttr("href");
            //            $("#ufiledownload").attr("href", data);
            //            $("#uhidfile").val(data);
        },
        'onUploadComplete': function (file) {
        },
        'onQueueComplete': function (stats) {
            $('#animate1').hide();
            $('#fList1').show();
        },
        'onSelect': function (file) {
            if (upYes == false) {
                if (selectFirst == 0) {
                    selectFirst++;
                    fileOStr += $("#uhidfile").val();
                    originalFile = $("#uhidfile").val();
                }
            }
            else {
                if (selectFirst == 0) {
                    selectFirst++;
                    fileOStr += $("#uhidfile").val(); 
                }
            }
            upYes = true;

            $('#fList1').empty();
            $('#animate1').show();
            $('#fList1').hide();
            _efrmData.id = "khid";
            _efrmData.srvid = srvID;
            $("#uuploadify").uploadify("settings", "formData", { "srv": srvID, "user": userID });
        }
    });
    loadP($("#PSize").val(), 1);
}
function loadP(pagesize, page) {
    var l = layer.load('正在加载数据......');
    var href = window.location.href.split("=");
    var mid = href[3];
    var url = "../Handlers/system/Daily.aspx?Method=Load&srvid=" + srvID + "&userid=" + userID + "&page=" + page + "&rows=" + pagesize + "";
    if (window.location.href.indexOf("check") != -1) {
        url += "&check=" + mid + "";
    }
    $.ajax({
        url: url,
        type: "get",
        cache: false,
        dataType: "json",
        success: function (data) {
            CreateTable(data);
            if (firstLoad == 0) {
                createPage(pagesize, 5, data.total);
                firstLoad = 1;
            }
            if (pagesize < data.total) {
                if (mPage * pagesize >= data.total) {
                    $("#pFooter").html("当前显示：" + ((mPage - 1) * pagesize + 1).toString() + "---" + data.total + "条记录；&nbsp;&nbsp;共：" + data.total + "条记录");
                }
                else {
                    $("#pFooter").html("当前显示：" + ((mPage - 1) * pagesize + 1).toString() + "---" + mPage * pagesize + "条记录；&nbsp;&nbsp;共：" + data.total + "条记录");
                }
            }
            else {
                $("#pFooter").html("当前显示：" + ((mPage - 1) * pagesize + 1).toString() + "---" + data.total + "条记录；&nbsp;&nbsp;共：" + data.total + "条记录");
            }
            layer.close(l);
            resize_r();
        },
        error: function () {
            layer.msg('网络请求错误!', 2, 5);
        }
    });
}
function CreateTable(data) {
    $('th input:checkbox').removeAttr("checked");
    var tb = document.getElementById("Management");
    for (var i = tb.rows.length - 1; i > 0; i--) {
        tb.deleteRow(i);
    }
    for (var i = 0; i < data.rows.length; i++) {
        var _tr1 = $('<tr></tr>');
        var _td0 = $('<td></td>');
        if (data.rows[i].Responder == "") {
            _td0.html("<input type='checkbox'  class='ace'><label class='lbl'></label>");
        }
        var _td1 = $('<td></td>');
        _td1.text(data.rows[i].TimeStr);
        var _td2 = $('<td class="center"></td>');
        _td2.append("<a rel='" + data.rows[i].ID + "' onclick='DailyCheck(this)' style='cursor: pointer;' >查看</a>");
        var _td3 = $('<td class="center"></td>');
        if (data.rows[i].Type == "0") {
            _td3.append("日报");
        }
        else if (data.rows[i].Type == "1") {
            _td3.append("周报");
        }
        else if (data.rows[i].Type == "2") {
            _td3.append("月报");
        }
        else if (data.rows[i].Type == "3") {
            _td3.append("例会");
        } 
        if (data.rows[i].Annex != "") {
            _td3.append('<i class="ace-icon fa fa-paperclip bigger-110"></i>');
        }
        var _td4 = $('<td></td>');
        _td4.append('<span style="cursor:pointer;" class="tooltip-info" data-placement="right" data-rel="tooltip" data-original-title="' + data.rows[i].Respond + '">' + data.rows[i].Respond.substring(0, 15) + '</span>');
        var _td5 = $('<td></td>');
        _td5.append('<span style="cursor:pointer;" class="tooltip-info" data-placement="right" data-rel="tooltip" data-original-title="' + data.rows[i].WhoRead + '">' + data.rows[i].WhoRead.substring(0, 15) + '</span>');
        var _td6 = $('<td class="center"></td>');
        if (data.rows[i].Responder == "") {
            _td6.append('<div class="wjsygn"><a  href="javascript:void(0);" onclick="Edit_Gg(this)" title="修改" tag="M_122_E" ><span class="tbqbgw">修改</span></i></a><a title="删除" tag="M_122_D" href="javascript:Del(\'' + data.rows[i].ID + '\');"><span class="tbqbgw">删除</span></a></div>');
        } else {
            _td6.append('<div class="wjsygn"><a  href="javascript:void(0);" title="修改" tag="M_122_E" ><span style="color:#808A87;" class="tbqbgw">修改</span></i></a><a title="删除" tag="M_122_D" href="javascript:void(0);"><span style="color:#808A87;" class="tbqbgw">删除</span></a></div>');
        }
        var _td7 = $('<td style="display: none;"></td>');
        _td7.text(data.rows[i].ID);
        var _td8 = $('<td style="display: none;"></td>');
        _td8.text(data.rows[i].Type);
        var _td9 = $('<td style="display: none;"></td>');
        _td9.text(data.rows[i].Annex);
        var _td10 = $('<td style="display: none;"></td>');
        _td10.text(data.rows[i].Attach);
        var _td11 = $('<td style="display: none;"></td>');
        _td11.text(data.rows[i].AttachID);
        var _td12 = $('<td style="display: none;"></td>');
        _td12.text(data.rows[i].Respond);
        var _td13 = $('<td style="display: none;"></td>');
        _td13.text(data.rows[i].WhoRead);
        var _td14 = $('<td style="display: none;"></td>');
        _td14.text(data.rows[i].AnnexType);
        _tr1.append(_td0);
        _tr1.append(_td1);
        _tr1.append(_td2);
        _tr1.append(_td3);
        _tr1.append(_td4);
        _tr1.append(_td5);
        _tr1.append(_td6);
        _tr1.append(_td7);
        _tr1.append(_td8);
        _tr1.append(_td9);
        _tr1.append(_td10);
        _tr1.append(_td11);
        _tr1.append(_td12);
        _tr1.append(_td13);
        _tr1.append(_td14);
        $('#Management tbody').append(_tr1);
    }
    ClickEvent();
    SelRole();
}

function Del(obj) {
    layer.confirm("确定删除吗？", function () {
        $.ajax({
            type: "post",
            url: "../Handlers/system/Daily.aspx?Method=del&ID=" + obj,
            cache: false,
            success: function (msg) {
                if (msg == "success") {
                    layer.msg("删除成功！", 1, 1);
                    loadP($("#PSize").val(), 1);
                }
                else {
                    layer.msg("删除失败！", 2, 3);
                }
            },
            error: function () {
                layer.msg("网络错误！", 2, 3);
            }
        });
    });
}
function Edit_Gg(obj) {
    var tds = $(obj).parent().parent().parent().find("td");
    var id = tds.eq(7).text();
    var type = tds.eq(8).text();
    var fj = tds.eq(9).text();
    var csrname = tds.eq(10).text();
    var csrid = tds.eq(11).text();
    AnnexType = tds.eq(14).text();
    $('#fList1').empty();
    var l = layer.load("正在加载...");
    $.ajax({
        type: "get",
        url: "../Handlers/system/Daily.aspx?Method=getCon&update=no&ID=" + id + "&user=" + userID,
        cache: false,
        dataType: "text",
        success: function (data) {
            layer.close(l);
            if (data != null) {
                //$("#efmGonggao .ke-edit-iframe").eq(0).contents().find("body").html(data);
                eaddum.setContent(data);
                $("#eggType option[value=" + type + "]").attr("selected", true);
                $("#EditHid").val(id);
                $('#uploadlist1').show();
                $('#fList1').show();
                if (fj != "") {
                    var fjList = fj.split('╯');
                    for (var i = 0; i < fjList.length; i++) {
                        if (fjList[i].length > 0) {
                            var mc = fjList[i].substring(fjList[i].lastIndexOf('/') + 1);
                            mc = mc.substring(0, mc.lastIndexOf('.'));
                            var eachItem = $('<li style="float:left;"><img ></img><a style="float:left;"></a></li>');
                            if (fjList[i].indexOf('http://') >= 0 || fjList[i].indexOf('www.') >= 0) {
                                eachItem.find('a').attr('href', fjList[i]);
                            }
                            else {
                                eachItem.find('a').attr('href', "../" + fjList[i]);
                            }
                            //eachItem.find('a').attr('href', "../" + fjList[i]);
                            eachItem.find('a').attr('target', "_blank");
                            eachItem.find('a').css({ 'display': 'block' });
                            eachItem.find('img').attr('src', "../../Scripts/BootStrap/img/fj.png");
                            eachItem.find('img').css({ 'width': '15px', 'height': '15px', 'float': 'left', 'margin-left': '5px' });
                            eachItem.find('a').text(mc);
                            $('#fList1').append(eachItem);
                        }
                    }

                    //                    $("#ufiledownload").text(fj.split("/")[6]);
                    //                    $("#ufiledownload").removeAttr("href");
                    //                    $("#ufiledownload").attr("href", fj);
                } else {
                    var eachItem = $('<li style="float:left;">暂无附件！</li>');
                    $('#fList1').append(eachItem);
                    //$("#ufiledownload").removeAttr("href");
                    //$("#ufiledownload").text("暂无附件！");
                }
                $("#uhidfile").val(fj);
                $("#eusernames").val(csrname);
                $("#euserids").val(csrid);
                $("#ePattach").val(csrname);
                $("#EditDialog").modal("show");
            }
        },
        error: function () {
            layer.close(l);
            layer.msg("网络错误！", 2, 3);
        }
    });
}
function Update() {
    $('#efmGonggao').validation();
    var alm = $(".popover");
    if (alm.length > 0) {
        return;
    }
    $(".popover ").remove();
    $("#umeditor_textarea_etxtAddContent").val(escape($("#umeditor_textarea_etxtAddContent").val()));
    fsave = true;
    var fileNew = "false";
    if (fileOStr.length>0) {
        fileNew = "true";
    }
    //alert(fileOStr);
    var obj = $("#EditHid").val();
    $.post("../Handlers/system/Daily.aspx?Method=edit&srvid=" + srvID + "&userid=" + userID + "&fileNew=" + fileNew + "&AnnexType=" + AnnexType, $('#efmGonggao').serialize(), function (data, status) {
        if (status == "success") {
            layer.msg("修改成功！", 2, 1);
            $('#EditDialog').modal('hide');
            loadP($("#PSize").val(), 1);
        }
        else {
            layer.msg("网络错误！请稍后重试！");
        }
    }, "text");
}
function ADD_Gg() {
    $("fmGonggao textarea").val("");
    $(".popover ").remove();
    $("#filedownload").text("");
    $("#hidfile").val("");
    $("#Pattach").val("");
    $("#userids").val("");
    $("#usernames").val("");
    //$("#fmGonggao .ke-edit-iframe").eq(0).contents().find("body").html("")
    $("#AddDialog").modal("show");
}
function Add() {
    $('#fmGonggao').validation();
    var alm = $(".popover");
    if (alm.length > 0) {
        return;
    }
    $(".popover ").remove();
    fsave = true;
    //$("#txtAddContent").val(escape($("#fmGonggao .ke-edit-iframe").eq(0).contents().find("body").html()));
//    $("#txtAddContent").val(escape($("#fmGonggao .ke-edit-iframe").eq(0).contents().find("body").html()));
//    if ($("#fmGonggao .ke-edit-iframe").eq(0).contents().find("body").html() == "<br>" || $("#fmGonggao .ke-edit-iframe").eq(0).contents().find("body").html() == "") {
//        layer.msg("请填写日志信息！", 1, 5);
//        return false;
//    }
//    if ($("#txtAddContent").val() == "%3Cbr%3E" || $("#txtAddContent").val() == "") {
//        layer.msg("请填写日志信息！", 1, 5);
//        return false;
//    }
    if (addum) {
        if (addum.getContentTxt().trim().length<1) {
        layer.msg("日志内容不能为空！", 1, 5);
        return false;
        }
    }
    else {
        alert('编辑器错误！');
        return;
    }

    $("#umeditor_textarea_txtAddContent").val(escape($("#umeditor_textarea_txtAddContent").val()));
    var l = layer.load("正在提交...");
    $.post("../Handlers/system/Daily.aspx?Method=Add&srvid=" + srvID + "&userid=" + userID + "", $('#fmGonggao').serialize(), function (data, status) {
        layer.close(l);
        if (status == "success") {
            layer.msg("添加成功！", 1, 1);
            $('#AddDialog').modal('hide');
            loadP($("#PSize").val(), 1);
        }
        else {
            layer.msg("网络错误！请稍后重试！");
        }
    }, "text");
}
function deleteList() {
    var cbs = $('#Management tbody').find('tr > td:first-child :checkbox:checked');
    var cbslt = cbs.length;
    if (cbslt <= 0) {
        layer.msg('选择不可为空!', 1, 8);
    }
    else {
        layer.confirm("确定删除吗？", function () {
            var ids = "'"
            for (var i = 0; i < cbslt; i++) {
                ids += $(cbs[i]).parent().parent().find("td").eq(7).text() + "','";
            }
            if (ids != null) {
                ids = ids.substring(0, ids.length - 2);
                $.ajax({
                    type: "post",
                    url: "../Handlers/system/Daily.aspx?Method=Deletelist&IDS=" + ids,
                    cache: false,
                    success: function (msg) {
                        if (msg == "success") {
                            layer.msg("删除成功！", 1, 1);
                            loadP($("#PSize").val(), 1);
                        } else {
                            layer.msg("删除失败！请再次操作！", 2, 3);
                        }
                    },
                    error: function () {
                        layer.msg("网络错误！", 2, 3);
                    }
                });
            }
        })
    }
}
function CheckAll() {
    mPage = 1;
    firstLoad = 0;
    Btn_check(15, 1);
}
function Btn_check(pagesize, page) {
    var l = layer.load('正在加载数据......');
    $.ajax({
        url: "../Handlers/system/Daily.aspx?Method=Load&srvid=" + srvID + "&userid=" + userID + "&page=" + page + "&rows=" + pagesize + "&where=where",
        type: "post",
        cache: false,
        data: $('#checkform').serialize(),
        dataType: "json",
        success: function (data) {
            CreateTable(data);
            if (firstLoad == 0) {
                $(".pagination").jBootstrapPage({
                    pageSize: pagesize,
                    total: data.total,
                    maxPageButton: 5,
                    onPageClicked: function (obj, pageIndex) {
                        mPage = pageIndex + 1;
                        Btn_check(15, mPage);
                    }
                });
                firstLoad = 1;
            }
            if (pagesize < data.total) {
                if (mPage * pagesize >= data.total) {
                    $("#pFooter").html("当前显示：" + ((mPage - 1) * pagesize + 1).toString() + "---" + data.total + "条记录；&nbsp;&nbsp;共：" + data.total + "条记录");
                }
                else {
                    $("#pFooter").html("当前显示：" + ((mPage - 1) * pagesize + 1).toString() + "---" + mPage * pagesize + "条记录；&nbsp;&nbsp;共：" + data.total + "条记录");
                }
            }
            else {
                $("#pFooter").html("当前显示：" + ((mPage - 1) * pagesize + 1).toString() + "---" + data.total + "条记录；&nbsp;&nbsp;共：" + data.total + "条记录");
            }
            layer.close(l);
            resize_r();
        },
        error: function () {
            layer.msg('网络请求错误!', 2, 5);
        }
    });
}
function ShuaXin() {
    mPage = 1;
    firstLoad = 0;
    loadP($("#PSize").val(), 1);
}
var isopen = false;
function DailyCheck(obj) {
    var tds = $(obj).parent().parent().find("td");
    var fj = tds.eq(9).text();
    var csrname = tds.eq(10).text();
    var pz = tds.eq(12).text();
    var yd = tds.eq(13).text();
    $("#csr_s").text("");
    $("#contentstr").html("");
    $('#fList2').empty();
    var txt = $(obj).attr("rel");
    var l = layer.load("正在加载...");
    $.ajax({
        type: "get",
        url: "../Handlers/system/Daily.aspx?Method=getCon&update=no&ID=" + txt + "&user=" + userID,
        cache: false,
        dataType: "text",
        success: function (data) {
            layer.close(l);
            if (data != null) {
                $("#contentstr").append(data);
                if (fj != "") {
                    var fjList = fj.split('╯');
                    for (var i = 0; i < fjList.length; i++) {
                        if (fjList[i].length>0) {
                            var mc = fjList[i].substring(fjList[i].lastIndexOf('/') + 1);
                            mc = mc.substring(0, mc.lastIndexOf('.'));
                            var eachItem = $('<li style="float:left;"><img ></img><a style="float:left;"></a></li>');
                            if (fjList[i].indexOf('http://') >= 0 || fjList[i].indexOf('www.') >= 0) {
                                eachItem.find('a').attr('href',  fjList[i]);
                            }
                            else {
                                eachItem.find('a').attr('href', "../" + fjList[i]);
                            }
                            
                            eachItem.find('a').attr('target', "_blank");
                            eachItem.find('a').css({ 'display': 'block' });
                            eachItem.find('img').attr('src', "../../Scripts/BootStrap/img/fj.png");
                            eachItem.find('img').css({ 'width': '15px', 'height': '15px', 'float': 'left', 'margin-left': '5px' });
                            eachItem.find('a').text(mc);
                            $('#fList2').append(eachItem);
                        }
                    }
                    
//                    $("#fj_s").text(fj.split("/")[6]);
//                    $("#fj_s").removeAttr("href");
//                    $("#fj_s").attr("href", fj);
                } else {
                    var eachItem = $('<li style="float:left;">暂无附件！</li>');
                    $('#fList2').append(eachItem);
//                    $("#fj_s").removeAttr("href");
//                    $("#fj_s").text("暂无附件！");
                }
                $("#csr_s").text(csrname);
                var pz_s = pz.split(";");
                var tb = document.getElementById("pz");
                for (var i = tb.rows.length - 1; i >= 0; i--) {
                    tb.deleteRow(i);
                }
                for (var i = 0; i < pz_s.length; i++) {
                    var _tr1 = $('<tr></tr>');
                    var _td0 = $('<td></td>');
                    _td0.text(pz_s[i]);
                    _tr1.append(_td0);
                    $('#pz').append(_tr1);
                }
                var yd_s = yd.split(";");
                var tb_y = document.getElementById("yd");
                for (var i = tb_y.rows.length - 1; i >= 0; i--) {
                    tb_y.deleteRow(i);
                }
                for (var i = 0; i < yd_s.length; i++) {
                    var _tr = $('<tr></tr>');
                    var _td1 = $('<td></td>');
                    _td1.text(yd_s[i]);
                    _tr.append(_td1);
                    $('#yd').append(_tr);
                }
                $("#CheckModal").modal("show");
//                $("img").bind("click", function () {
//                    $.ajax({
//                        url: "../Handlers/system/Daily.aspx?Method=Encryp&img=" + $(this).attr("src"),
//                        type: "post",
//                        cache: false,
//                        success: function (msg) {
//                            layer.close(l);
//                            if (data != "error") {
//                                window.open("ReadImg.htm?img=" + msg);
//                            }
//                            else {
//                                layer.msg("读取失败！", 2, 3);
//                            }
//                        },
//                        error: function () {
//                            layer.close(l);
//                            layer.msg('网络请求错误!', 2, 5);
//                        }
//                    });
//                });
            }
        },
        error: function () {
            layer.close(l);
            layer.msg("网络错误！", 2, 3);
        }
    });
}
//KindEditor.ready(function (K) {
//    editor1 = K.create('#txtAddContent', {
//        cssPath: '"../Scripts/Hntcwleditor/plugins/code/prettify.css',
//        uploadJson: '../Scripts/Hntcwleditor/asp.net/upload_json.ashx?srv=' + srvID + '&path=/Daily/' + userID + '/',
//        fileManagerJson: '../Scripts/Hntcwleditor/asp.net/file_manager_json.ashx',
//        allowFileManager: true,
//        resizeType: 0,
//        items: ['source', '|', 'preview', 'print', '|', 'template', 'image', 'anchor', 'unlink', 'fullscreen', '|',
//                'selectall', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', '|', 'formatblock', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', '|', 'table', 'hr', 'emoticons', 'quickformat'
//            ],
//        imageSizeLimit: '2MB',
//        afterCreate: function () {
//        }
//    });
//    editor2 = K.create('#etxtAddContent', {
//        cssPath: '"../Scripts/Hntcwleditor/plugins/code/prettify.css',
//        uploadJson: '../Scripts/Hntcwleditor/asp.net/upload_json.ashx?srv=' + srvID + '&path=/Daily/' + userID + '/',
//        fileManagerJson: '../Scripts/Hntcwleditor/asp.net/file_manager_json.ashx',
//        allowFileManager: true,
//        resizeType: 0,
//        items: ['source', '|', 'preview', 'print', '|', 'template', 'image', 'anchor', 'unlink', 'fullscreen', '|',
//                'selectall', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', '|', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', '|', 'formatblock', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', '|', 'table', 'hr', 'emoticons', 'quickformat'
//            ],
//        imageSizeLimit: '2MB',
//        afterCreate: function () {
//        }
//    });
//});
$(function () {
    $(".datepicker").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1
    });
    $("#treediv").hide();
    $("#Pattach").on("click", function () {
        $("#treediv").toggle();
        $.ajax({
            dataType: 'json',
            type: "get",
            url: "../Handlers/Process/Process.aspx?Method=LoadAllusers",
            data: { srvid: srvID },
            success: function (jsons) {
                $('#jstree').jstree({
                    "checkbox": {
                        "keep_selected_style": false
                    },
                    "plugins": ['checkbox'],
                    'core': {
                        'data': jsons
                    }
                });
            },
            error: function () {
                layer.msg("网络错误！", 1, 8);
            }
        });
    });
    $("#treediv").on("mouseleave", function () {
        $("#treediv").hide();
    });
    $('#jstree').on("changed.jstree", function (e, data) {
        var s = $('#jstree').jstree('get_checked', 'full');
        var result = '';
        var sid = '';
        for (var i = 0; i < s.length; i++) {
            if ($('#jstree').jstree('is_leaf', s[i])) {
                sid += s[i].id + ',';
                result += s[i].text + ',';
            }
        }
        result = result.substring(0, result.length - 1);
        $("#Pattach").val(result);
        $("#usernames").val(result);
        sid = sid.substring(0, sid.length - 1);
        $("#userids").val(sid);
    });
    $("#etreediv").hide();
    $("#ePattach").on("click", function () {
        $("#etreediv").toggle();
        $.ajax({
            dataType: 'json',
            type: "get",
            url: "../Handlers/Process/Process.aspx?Method=LoadAllusers",
            data: { srvid: srvID },
            success: function (jsons) {
                $('#ejstree').jstree({
                    "checkbox": {
                        "keep_selected_style": false
                    },
                    "plugins": ['checkbox'],
                    'core': {
                        'data': jsons
                    }
                });
            },
            error: function () {
                layer.msg("网络错误！", 1, 8);
            }
        });
    });
    $("#etreediv").on("mouseleave", function () {
        $("#etreediv").hide();
    });
    $('#ejstree').on("changed.jstree", function (e, data) {
        var s = $('#ejstree').jstree('get_checked', 'full');
        var result = '';
        var sid = '';
        for (var i = 0; i < s.length; i++) {
            if ($('#ejstree').jstree('is_leaf', s[i])) {
                sid += s[i].id + ',';
                result += s[i].text + ',';
            }
        }
        result = result.substring(0, result.length - 1);
        $("#ePattach").val(result);
        $("#eusernames").val(result);
        sid = sid.substring(0, sid.length - 1);
        $("#euserids").val(sid);
    });
});