
        var userID = "";
        var srvID = "";
        var mPage = 1;
        var firstLoad = 0;
        var selectRoleID = "";

        var ifrm;
        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;
                loadRole($("#PSize").val(), 1);
            });
        });
        function createPage(pageSize, buttons, total) {
            $("#z_p").jBootstrapPage({
                pageSize: pageSize,
                total: total,
                maxPageButton: buttons,
                onPageClicked: function (obj, pageIndex) {
                    mPage = pageIndex + 1;
                    loadRole($("#PSize").val(), mPage);
                }
            });
        }
        function loadRole(pagesize, page) {
            var l = layer.load('正在加载数据......');
            $.ajax({
                url: '../Handlers/system/control.aspx?Method=loadRole&srvid=' + srvID + "&page=" + page + "&rows=" + pagesize,
                cache: false,
                dataType: 'json',
                success: function (data) {
                    createRole(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);
                }, error: function () {
                    layer.msg('加载角色信息错误！', 1, 3);
                }
            });
        }
        function createRole(data) {
            var tb = document.getElementById("tdata");
            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 _td1 = $('<td></td>');
                _td1.text(data.rows[i].roleName);
                var _td2 = $('<td></td>');
                if (data.rows[i].deleteYes != "0") {
                    _td2.append('<div class="wjsygn"><a title="修改角色信息" style="cursor:pointer;" onclick="Update(\'' + data.rows[i].ID + '\',\'' + data.rows[i].roleName + '\')"><span class="tbqbgw">修改角色信息</span></a><a title="删除角色信息" style="cursor:pointer;" onclick="delRow(\'' + data.rows[i].ID + '\');"><span class="tbqbgw">删除角色信息</span></a></div>');
                } else {
                    _td2.append('<div class="wjsygn"><a title="修改角色信息" style="cursor:pointer;"><span class="tbqbgw" style="color:#808A87;">修改角色信息</span></a><a title="删除角色信息" style="cursor:pointer;"><span class="tbqbgw" style="color:#808A87;">删除角色信息</span></a></div>');
                }
                var _td3 = $('<td style="display: none;"></td>');
                _td3.text(data.rows[i].ID);
                _tr1.append(_td1);
                _tr1.append(_td2);
                _tr1.append(_td3);
                $('#tdata tbody').append(_tr1);
            
            }
        }
        function delRow(id) {
            layer.confirm("确定删除吗？", function () {
                $.ajax({
                    url: '../Handlers/system/control.aspx?Method=delRole&ID=' + id,
                    cache: false,
                    type: 'post',
                    success: function (data) {
                        if (data == "success") {
                            loadRole($("#PSize").val(), 1);
                            layer.msg('删除成功！', 1, 1);
                        }
                        else {
                            layer.msg('删除角色信息失败！', 1, 3);
                        }
                    }, error: function () {
                        layer.msg('删除角色信息错误！', 1, 3);
                    }
                });
            });
        }
        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; }
                }
            }
        };
        function existRole(s, p) {
            var e = p.indexOf(s);
            if (e == -1) {
                return false;
            }
            else {
                return true;
            }
        }
        function iniParms() {
            var coks = document.cookie.substring(document.cookie.indexOf('userinf_tcwl'));
            var ary = coks.split(';');
            var ary1 = ary[0].split('=');
            if (!ary1[2]) {
                $('html').empty();
                return;
            }
            userID = ary1[2].split('&')[0];
            srvID = ary1[3];
            var s = window.location.href.split('=');
            if (s.length == 4) {
                ifrm = s[3];
            }
            resize_r();
            loadRole($("#PSize").val(), 1);
        }
        function ADD_JueSe() {
            $('#Modal_Add').modal('show');
        }
        function saveADDrow() {
            var name = $("#Add_name").val();
            if (name==""||name==null) {
                layer.msg('角色名称不可为空！！！', 1, 3);
                $("#Add_name").focus();
                return;
            }
            $.ajax({
                url: '../Handlers/system/control.aspx?Method=addRole&name=' + encodeJson_News(name) + "&srvid=" + srvID,
                cache: false,
                type: 'post',
                success: function (data) {
                    var result = data.split('|');
                    if (result.length > 1) {
                        $("#Modal_Add").modal('hide');
                        layer.msg('添加成功！', 1, 1);
                        Update(result[1], name);
                    }
                    else {
                        if (result[0] == "del") {
                            layer.msg('添加角色信息已被其他用户删除,请重新添加！', 1, 3);
                        }
                        else {
                            if (result[0] == "exist") {
                                layer.msg('已经存在此角色名称！', 1, 3);
                            }
                            else {
                                layer.msg('添加角色信息失败！', 1, 3);
                            }
                        }
                    }
                }, error: function () {
                    layer.msg('添加角色信息错误！', 1, 3);
                }
            });
        }
        function ShuaXin() {
            window.location.reload();
        }
        function Update(ID, Name) {
            window.location.href = 'SetControl.htm?id=' + ID + "&title=" + encodeURI(Name) + "&srvid=" + escape(srvID) +"&user="+userID+ "&name=" + ifrm;
        }