var srvID = "";
var userID = "";
var mPage = 1;
var firstLoad = 0;
var selectFirst = 0;
var fileOStr = '';
var fileNStr = '';
var fsave = false;
var upYes = false;
var originalFile = '';
var addum = null;
var eaddum = null;
var _frmData = {
    id: '',
    srvid: ''
};
var _efrmData = {
    id: '',
    srvid: ''
};
var aryau = "";
var ifrm;
$(function() {
    $("#PSize").change(function() {    
        firstLoad = 0;
        mPage = 1;
        loadP($("#PSize").val(), 1);
    });
    
    $("[tag]").hide();
}); 
document.onkeydown = function(event) {
    var target, code, tag;
    if (!event) {
        event = window.event;   
        target = event.srcElement;
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "TEXTAREA") {
                return true;
            } else {
                return false;
            }
        }
    } else {
        target = event.target;  
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "INPUT") {
                return false;
            } else {
                return true;
            }
        }
    }
};
$('#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 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 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();
        }
    });
}
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() {
    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];
    $(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');
        });
    });
});
function DeletePic() {
    $("#filedownload").text("");
    $("#hidfile").val("");
    $("#depic").hide();
}
function EDeletePic() {
    $("#efiledownload").text("");
    $("#ehidfile").val("");
    $("#edepic").hide();
}

function LoadData() {
    var s = window.location.href.split('=');
    if (s.length == 4) {
        ifrm = s[3];
    }
    resize_r();
    SelRole();
    $('#Huserid').val(userID);
    $('#Hsrvid').val(srvID);
    LoadType();
    $('#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 += $('#ehidfile').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/GongGao.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);
//            var mc = data.split('/')[7];
//            $("#filedownload").text(data.split("/")[6]);
//            $("#filedownload").show();
//            $("#hidfile").val(data);
//            $("#depic").show();
        },
        '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
            });
        }
    });
    $('#euploadfy').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/GongGao.aspx?Method=upload',
        'fileSizeLimit': '5120kb',
        'formData': _efrmData,
        'folder': 'UploadFile',
        'cancelImage': '../Scripts/Uploadify/uploadify-cancel.png',
        'onUploadSuccess': function (file, data, response) {
            if (selectFirst > 0) {
                $("#ehidfile").val('');
            }
            selectFirst = 0;
            fileNStr = fileNStr + data + '╯';
            var mc = data.substring(data.lastIndexOf('/') + 1);
            mc = mc.substring(0, mc.lastIndexOf('.'));
            $("#ehidfile").val($("#ehidfile").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);
            var mc = data.split('/')[7];
//            $("#efiledownload").text(data.split("/")[6]);
//            $("#efiledownload").show();
//            $("#ehidfile").val(data);
//            $("#edepic").show();
        },
        'onUploadComplete': function(file) {},
        'onQueueComplete': function (stats) {
            $('#animate1').hide();
            $('#fList1').show();
        },
        'onSelect': function (file) {
            if (upYes == false) {
                if (selectFirst == 0) {
                    selectFirst++;
                    fileOStr += $("#ehidfile").val();
                    originalFile = $("#ehidfile").val();
                }
            }
            else {
                if (selectFirst == 0) {
                    selectFirst++;
                    fileOStr += $("#ehidfile").val();
                }
            }
            upYes = true;

            $('#fList1').empty();
            $('#animate1').show();
            $('#fList1').hide();
            _efrmData.id = "khid";
            _efrmData.srvid = srvID;
            $("#euploadfy").uploadify("settings", "formData", {
                "srv": srvID,
                "user": userID
            });
        }
    });
    loadP($("#PSize").val(), 1);
}
function loadP(pagesize, page) {
    var l = layer.load('正在加载数据......');
    $(".ace:checkbox").attr("checked", false);
    $.ajax({
        url: "../Handlers/system/GongGao.aspx?Method=Load&srvid=" + srvID + "&userid=" + userID + "&page=" + page + "&rows=" + pagesize + "",
        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>');
        _td0.html("<input type='checkbox'  class='ace'><label class='lbl'></label>");
        var _td1 = $('<td></td>');
        _td1.append("<a href='javascript:void(0)' onclick='CheckGg(this)' rel='" + data.rows[i].ID + "'  title=" + data.rows[i].Title + ">" + data.rows[i].Title.toString().substring(0, 30) + "</a>");
        var _td2 = $('<td></td>');
        _td2.text(data.rows[i].Familiar);
        var _td3 = $('<td></td>');
        _td3.text(data.rows[i].userXM);
        var _td4 = $('<td class="center"></td>');
        if (data.rows[i].State == "1") {
            _td4.text("显示");
        } else {
            _td4.append("<label class='label label-danger'>不显示</label");
        }
        var _td5 = $('<td class="center"></td>');
        _td5.text(data.rows[i].TimeStr.split(" ")[0]);
        var _td6 = $('<td class="center"></td>');
        _td6.append('<div class="wjsygn"><a  href="javascript:void(0);" onclick="Edit_Gg(this)" title="修改" tag="M_119_E"><span class="tbqbgw">修改</span></i></a><a title="删除" tag="M_119_D" href="javascript:Del(\'' + data.rows[i].ID + '\');"><span 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].LeiXing);
        var _td9 = $('<td style="display: none;"></td>');
        _td9.text(data.rows[i].State);
        var _td10 = $('<td style="display: none;"></td>');
        _td10.text(data.rows[i].Attachment);
        var _td11 = $('<td style="display: none;"></td>');
        _td11.text(data.rows[i].Title);
        _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);
        $('#Management tbody').append(_tr1);
    }
    SelRole();
}
function CheckGg(_this) {
    var url = "System/News.htm?id=" + $(_this).attr("rel") + "";
    parent.$('#tctabs').append($('<li ><a href="#a_' + $(_this).attr('rel') + '" data-toggle="tab">资讯<span class="fa fa-times" style=" margin-left:8px;width:10px;height:10px;" onclick="tab_close(this);" onmouseover ="close_over(this);" onmouseout ="close_out(this);"></span></a></li>'));
    parent.$('#tctabcontent').append($('<div class="tab-pane" id="a_' + $(_this).attr('rel') + '" scrolling="no" style="height:100%;margin-top:5px;"><iframe id="m' + $(_this).attr('rel') + '" src="' + url + '" style="border:0px;width:100%;height:100%;"></iframe></div>'));
    parent.$('#tctabs a:last').tab('show');
}
function Del(obj) {
    layer.confirm("确定删除吗？",
    function() {
        $.ajax({
            type: "post",
            url: "../Handlers/system/GongGao.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 Title = tds.eq(11).text();
    var ID = tds.eq(7).text();
    var Attachment = tds.eq(10).text();
    var LeiXing = tds.eq(8).text();
    var State = tds.eq(9).text();
    var l = layer.load("正在加载...");
    $.ajax({
        type: "get",
        url: "../Handlers/system/GongGao.aspx?Method=getCon&ID=" + ID,
        cache: false,
        dataType: "text",
        success: function (data) {
            if (data != null) {
                $("#efmGonggao input").removeAttr("checked").removeAttr("selected");
                $("#filedownload").text("");
                $("#eggTitle").val(Title);
                $("#ehidfile").val(Attachment);
                if (Attachment != "") {
                    $('#uploadlist1').show();
                    $('#fList1').show();
                    var fjList = Attachment.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>');
                            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);
                        }
                    }
                    //                    $("#efiledownload").text(Attachment.split("/")[6]);
                    //                    $("#efiledownload").show();
                    //                    $("#edepic").show();
                } else {
                    var eachItem = $('<li style="float:left;">暂无附件！</li>');
                    $('#fList1').append(eachItem);
                    //                    $("#efiledownload").text("");
                    //                    $("#efiledownload").hide();
                    //                    $("#edepic").hide();
                }
                //                $("#efmGonggao .ke-edit-iframe").eq(0).contents().find("body").html(data);
                eaddum.setContent(data);
                $("#eggType option[value=" + LeiXing + "]").attr("selected", true);
                $("#efmGonggao input:radio[value=" + State + "]").attr("checked", "checked");
                $("#EditHid").val(ID);
                layer.close(l);
                $("#EditDialog").modal("show");
            }
        },
        error: function () {
            layer.close(l);
            layer.msg("网络错误！", 2, 3);
        }
    });
}
function Update() {
    if ($('#eggTitle').val().trim().length < 1) {
        $('#eggTitle').focus();
        return;
    }
    if (eaddum) {
        if (eaddum.getContentTxt().trim().length < 1) {
            layer.msg("日志内容不能为空！", 1, 5);
            return false;
        }
    }
    else {
        alert('编辑器错误！');
        return;
    }
    $('#efmGonggao').validation();
    var alm = $(".popover");
    if (alm.length > 0) {
        return;
    }
    fsave = true;
    $(".popover ").remove();
//    $("#etxtAddContent").val(escape($("#efmGonggao .ke-edit-iframe").eq(0).contents().find("body").html()));
 $("#umeditor_textarea_etxtAddContent").val(escape($("#umeditor_textarea_etxtAddContent").val()));
    $("#eggTitle").val(encodeJson_News($("#eggTitle").val()));
    var obj = $("#EditHid").val();
    var l = layer.load("正在提交...");
    $.post("../Handlers/system/GongGao.aspx?Method=edit&srvid=" + srvID + "&userid=" + userID, $('#efmGonggao').serialize(),
    function(data, status) {
        layer.close(l);
        if (status == "success") {
            layer.msg("修改成功！", 2, 1);
            $('#EditDialog').modal('hide');
            loadP($("#PSize").val(), 1);
        } else {
            layer.msg("网络错误！请稍后重试！");
        }
    },
    "text");
}
function ADD_Gg() {
    $(".popover ").remove();
    $("#ggTitle").val("");
    $("#hidfile").val("");
    $("#depic").hide();
    $("#filedownload").text("");
    $("textarea").val("");
    $("#fmGonggao .ke-edit-iframe").eq(0).contents().find("body").html("");
    fsave = false;
    $("#AddDialog").modal("show");
}
function Add() {
    if ($("#ggTitle").val().trim() == "") {
        $("#ggTitle").focus();
        return;
    }
    if (addum) {
        if (addum.getContentTxt().trim().length<1) {
        layer.msg("公告内容不能为空！", 1, 5);
        return false;
        }
    }
    else {
        alert('编辑器错误！');
        return;
    }

    $('#fmGonggao').validation();
    var alm = $(".popover");
    if (alm.length > 0) {
        return;
    }
  
    if ($("#ggType").val() == null) {
        layer.msg("类别不能为空!", 1, 5);
        return;
    }
    fsave = true;
    $(".popover ").remove();
    var dd = $("#ggTitle").val();
    $("#ggTitle").val($("#ggTitle").val());
    var tt = $("#ggTitle").val();
    //$("#txtAddContent").val(escape($("#fmGonggao .ke-edit-iframe").eq(0).contents().find("body").html()));
     $("#umeditor_textarea_txtAddContent").val(escape($("#umeditor_textarea_txtAddContent").val()));
    var l = layer.load("正在添加...");
    $.post("../Handlers/system/GongGao.aspx?Method=Add&srvid=" + srvID + "&userid=" + userID + "", $('#fmGonggao').serialize(),
    function(data, status) {
        if (status == "success") {
            layer.close(l);
            layer.msg("添加成功！", 1, 1);
            $('#AddDialog').modal('hide');
            loadP($("#PSize").val(), 1);
        } else {
            layer.close(l);
            layer.msg("网络错误！请稍后重试！");
        }
    },
    "text");
}
function LoadType() {
    $.ajax({
        dataType: 'json',
        type: "get",
        url: "../Handlers/system/DataDic.aspx?Method=Load&srvid=" + srvID + "&userid=" + userID + "",
        data: {
            tbname: "TCWL_All_Dic_GongGaoType"
        },
        success: function(jsons) {
            $("#ggType").empty();
            $("#eggType").empty();
            $("#stype").empty();
            var type1 = $("#ggType");
            var type2 = $("#eggType");
            var type3 = $("#stype");
            type3.append("<option value=''>全部</option>");
            for (i = 0; i < jsons.rows.length; i++) {
                $option = $("<option></option>");
                $option.attr("value", jsons.rows[i].id);
                $option.text(jsons.rows[i].text);
                type1.append($option);
                $option2 = $("<option></option>");
                $option2.attr("value", jsons.rows[i].id);
                $option2.text(jsons.rows[i].text);
                type2.append($option2);
                $option3 = $("<option></option>");
                $option3.attr("value", jsons.rows[i].id);
                $option3.text(jsons.rows[i].text);
                type3.append($option3);
            }
        },
        error: function() {
            layer.msg('网络请求错误!', 2, 5);
        }
    });
}
function deleteList() {
    var cbs = $('#Management tbody').find('tr > td:first-child :checkbox:checked');
    var cbslt = cbs.length;
    if (cbslt <= 0) {
        layer.msg('选择不可为空!', 1, 5);
    } 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/GongGao.aspx?Method=Deletelist&IDS=" + ids,
                    cache: false,
                    success: function(msg) {
                        if (msg == "success") {
                            layer.msg("删除成功！", 1, 1);
                            firstLoad = 0;
                            loadP($("#PSize").val(), 1);
                        } else {
                            layer.msg("删除失败！请再次操作！", 2, 3);
                        }
                    },
                    error: function() {
                        layer.msg("网络错误！", 2, 3);
                    }
                });
            }
        })
    }
}
function Btn_check(pagesize, page) {
    var l = layer.load('正在加载数据......');
    var pagesize = $("#PSize").val();
    var page = 1;
     $.ajax({
        url: "../Handlers/system/GongGao.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) {
                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 ShuaXin() {
    loadP($("#PSize").val(), 1);
}
function CreateType() {
    $("#frmAddCategory input").val("");
    $("#M_Position").modal("show");
}
function TypeAdd() {
    $('#frmAddCategory').validation();
    var alm = $(".popover");
    if (alm.length > 0) {
        return;
    }
    $(".popover ").remove();
    var name = $("#txtName").val();
    if (name == "") {
        $("#txtName").focus();
        return;
    }
    $.ajax({
        url: "../Handlers/system/DataDic.aspx?Method=add&srvid=" + srvID + "&tbname=TCWL_All_Dic_GongGaoType",
        cache: false,
        type: 'post',
        data: encodeJson_News(decodeURIComponent($('#frmAddCategory').serialize())),
        success: function(data) {
            if (data == "success") {
                $("#M_Position").modal("hide");
                layer.msg('添加成功！', 1, 1);
                $("#ggType").empty();
                $("#eggType").empty();
                firstLoad = 0;
                LoadType();
            } else {
                if (data == "exist") {
                    layer.msg('已经存在此类别！', 1, 3);
                } else {
                    layer.msg('添加失败！', 1, 3);
                }
            }
        },
        error: function() {
            layer.msg('添加资讯类别错误!', 1, 5);
        }
    });
}
//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=/CompanyNews/' + 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=/CompanyNews/' + 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() {}
//    });
//});