<%@ Page Language="C#" AutoEventWireup="true"  CodeBehind="_p_many.aspx.cs"   Inherits="Web25175_Hotel2.Web._p_many"  %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>动态权限组</title>
    <script language="javascript" src="js/Web25175_Hotel2.v1.1.js" type="text/javascript"></script>
    <script src="js/permissions.js" type="text/javascript"></script>
    <script src="jQuery/Alert/jquery.js" type="text/javascript"></script>
    <script src="jQuery/Alert/jquery.ui.draggable.js" type="text/javascript"></script>
    <script src="jQuery/Alert/jquery.alerts.js" type="text/javascript"></script>
    <link href="jQuery/Alert/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="css/_p.css" rel="stylesheet" type="text/css" />
    <link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="OperateTitle">
        <div>动态权限组</div>
    </div>
    <div id="msg"></div>
    <div style="width:600px; margin-left:10px;">
    <div style="width:220px; float:left;">
        <input id="Button1" type="button" value="编辑用户" class="opbtn" />
        <input id="Checkbox3" type="checkbox" /> 单独
        <div id="userdiv" class="formdiv">
        <div id="userdivtool" class="formdivtool"><input id="Checkbox1" type="checkbox" />全选/取消 <input id="Button3" type="button" value="确定" class="subbtn"/></div>
        <div id="userlist"></div>
        <div id="user_pinyin"></div>
        </div>
        <div id="userblock"></div>
    </div>
     <div style="width:220px; float:left">
        <input id="Button2" type="button" value="编辑用户组" class="opbtn"  />
        <div id="groupdiv" class="formdiv">
        <div id="groupdivtool" class="formdivtool"><input id="Checkbox2" type="checkbox" />全选/取消 <input id="Button4" type="button" value="确定" class="subbtn" /></div>
        <div id="grouplist"></div>
        <div id="group_pinyin"></div>
        </div>
        <div id="groupblock"></div>
    </div>
    <div style="width:100px; float:left; vertical-align:middle;text-align:center">
        <div style="margin-top:30px;">
        <input id="Button7" type="button" class="bigbtn t0"/></div>
        <div style="margin-top:30px;">
        <input id="Button5" type="button" class="bigbtn t1"/></div>
       <div style="margin-top:30px;">
        <input id="Button6" type="button" class="bigbtn t2" /></div>
    </div>
    <div style="clear:both"></div>
    </div>

    <div id="tip">
     <b>动态权限组</b>:一个或多个用户可以附加、更改一个或多个用户权限。
     <br />
     <b>附加权限组</b>:在原来存在的权限组上附加当前操作的权限组。示例：如存在 1->附加 1，结果 1；如存在 1->附加 2，结果 1、2
     <br />
     <b>更改权限组</b>:取消原来存在权限组更改当前操作的权限组。示例：如存在 1->更改 1，结果 1；如存在 1、2->更改 2，结果 2
      <br />
   </div>
<script type="text/javascript">
document.onselectstart = function(){return false;}
var msg_ = ["正在加载数据,请稍等...", "正在保存数据,请稍等..."];
var server = "";
var arrayuser = null;
var arraygroup = null;
var execute = false;
var executeuserid = 0;
var isfun=false;
init();

function rnd() {
    server = "_p_server.aspx?t=" + new Date() + "&";
}
function wait(msg) {
    uiGet("msg").innerHTML = msg;
    uiGet("msg").style.display = "block";
}
function wait_c() {
    uiGet("msg").innerHTML = "";
    uiGet("msg").style.display = "none";
}
function init() {
    usersite("userblock");
    groupsite("groupblock");
    uiGet("Button1").onclick = function() {
        btnStatus(true);
        adduser(function() {
            usersite("userblock");
        });
        initcheckbox_all_cancel("Checkbox1", "userlist");
        initsubmit("Button3", "userlist", "userdivtool",
        function() {
            usersite("userdiv");
            btnStatus_c()
        },
        "user", "user_pinyin");
    }
    uiGet("Button2").onclick = function() {
        btnStatus(true);
        addgroup(function() {
            groupsite("groupblock");
        });
        initcheckbox_all_cancel("Checkbox2", "grouplist");
        initsubmit("Button4", "grouplist", "groupdivtool",
        function() {
            groupsite("groupdiv");
            btnStatus_c()
        },
        "group", "group_pinyin");
    }
    uiGet("Button7").onclick = function() {
        saveusergroup("cancel");
    }
    uiGet("Button5").onclick = function() {
        saveusergroup("append");
    }
    uiGet("Button6").onclick = function() {
        saveusergroup("modify");
    }
    initpingyin("user_pinyin");
    initpingyin("group_pinyin");
    initfun();
}
function initfun() {
    var chk = uiGet("Checkbox3");
    isfun = chk.checked == true ? true: false;
    chk.onclick = function() {
        isfun = this.checked == true ? true: false;
        if (!isfun) {
            menu_c();
            executeuser_c();
        }
    }
}
function fun_c() {
    var chk = uiGet("Checkbox3");
    chk.checked = false;
    isfun = false;

    menu_c();
    executeuser_c();
}
function btnStatus(flag) {
    uiGet("Button1").disabled = flag;
    uiGet("Button2").disabled = flag;
}
function btnStatus_c() {
    uiGet("Button1").disabled = false;
    uiGet("Button2").disabled = false;
}
function usercontains(value) {
    if (arrayuser != null) {
        return arrayuser.contains(value);
    }
    return false;
}
function groupcontains(value) {
    if (arraygroup != null) {
        return arraygroup.contains(value);
    }
    return false;
}
var userdata = null;
function adduser(fun) {
    this.shade();
    this.rnd();
    this.fun_c();
    var url = server + "action=getuserlist";
    this.wait(msg_[0]);
    uiAjaxGet(url,
    function(e) {
        if (typeof(fun) == "function") {
            fun();
        }
        var data = null;
        try {
            data = eval("(" + e + ")");
        } catch(e) {
            jAlert('解析数据失败', "提示");
            btnStatus_c();
        }
        if (data != null) {
            var div = uiGet("userdivtool");
            div.style.display = "block";
            var div_py = uiGet("user_pinyin");
            div_py.style.display = "block";
            var li_contains = "";
            var li_default = "";
            userdata = data;
            for (i = 0; i < data.Rows.length; i++) {
                var item = data.Rows[i].UserName_S;
                var value = data.Rows[i].UserId_S;
                var flag = usercontains(value);
                if (flag) {
                    var style = "style='border:1px #0099CC solid;background:#89BAE7'";
                    li_contains += "<div item=" + item + " value=" + value + " " + style + " onclick='div_sel(this)' name='user'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' checked />&nbsp;" + item + "</div>";
                } else {
                    li_default += "<div item=" + item + " value=" + value + " onclick='div_sel(this)' name='user'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' />&nbsp;" + item + "</div>";
                }
            }

            var div = uiGet("userdiv");
            with(div.style) {
                position = "absolute";
                height = "580px";
                width = "200px";
                top = "50%";
                left = "50%";
                marginLeft = -(200 / 2) + "px";
                marginTop = -(580 / 2) + "px";
                border = "1px #999999 solid";
                padding = "2px";
                zIndex = 101;
                background = "#dddddd";
            }
            var div2 = uiGet("userlist");
            with(div2.style) {
                overflow = "auto";
                height = "470px";
                width = "190px";
                padding = "2px";
            }
            div2.innerHTML = li_contains + li_default;
            div2.setAttribute("ms", "true");
        }
        this.wait_c();
    });
}
var groupdata = null;
function addgroup(fun) {
    shade();
    this.rnd();
    var url = server + "action=getgrouplist";
    this.wait(msg_[0]);
    uiAjaxGet(url,
    function(e) {
        if (typeof(fun) == "function") {
            fun();
        }
        var data = null;
        try {
            data = eval("(" + e + ")");
        } catch(e) {
            jAlert('解析数据失败', "提示");
            btnStatus_c();
        }
        if (data != null) {
            var div = uiGet("groupdivtool");
            div.style.display = "block";
            var div_py = uiGet("group_pinyin");
            div_py.style.display = "block";
            var li_contains = "";
            var li_default = "";
            groupdata = data;
            for (i = 0; i < data.Rows.length; i++) {
                var item = data.Rows[i].GroupName_S;
                var value = data.Rows[i].GroupId_S;
                var flag = groupcontains(value);
                if (flag) {
                    var style = "style='border:1px #0099CC solid;background:#89BAE7'";
                    li_contains += "<div item=" + item + " value=" + value + " " + style + " onclick='div_sel(this)' name='group'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' checked />&nbsp;" + item + "</div>";
                } else {
                    li_default += "<div item=" + item + " value=" + value + " onclick='div_sel(this)' name='group'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' />&nbsp;" + item + "</div>";
                }
            }

            var div = uiGet("groupdiv");
            with(div.style) {
                position = "absolute";
                height = "580px";
                width = "200px";
                top = "50%";
                left = "50%";
                marginLeft = -(200 / 2) + "px";
                marginTop = -(580 / 2) + "px";
                border = "1px #999999 solid";
                padding = "2px";
                zIndex = 100;
                background = "#dddddd";
            }
            var div2 = uiGet("grouplist");
            with(div2.style) {
                overflow = "auto";
                height = "470px";
                width = "190px";
                padding = "2px";
            }
            div2.innerHTML = li_contains + li_default;
            div2.setAttribute("ms", "true");
        }
        this.wait_c();
    });
}
function checkbox_sel(obj) {
    var div = obj.parentElement;
    div.setAttribute("onclick", "");
    var value = div.getAttribute("value");
    var name = div.getAttribute("name");
    if (obj.checked) {
        with (div.style) {
            border = "1px #0099CC solid";
            background = "#89BAE7";
        }
        push(name, value);
    } else {
        with (div.style) {
            border = "1px #999999 solid";
            background = "#F9F9F9";
        }
        remove(name, value);
    }
}
function div_sel(obj) {
    var box = obj.getElementsByTagName("input")[0];
    var value = obj.getAttribute("value");
    var name = obj.getAttribute("name");
    menu(obj);
    if (box == null) return;
    if (box.checked) {
        box.checked = false;
        with(obj.style) {
            border = "1px #999999 solid";
            background = "#F9F9F9";
        }
        remove(name, value);
    } else {
        box.checked = true;
        with(obj.style) {
            border = "1px #0099CC solid";
            background = "#89BAE7";
        }
        push(name, value);
    }
}
function remove(name, value) {
    if (name == "user") {
        if (arrayuser != null) {
            arrayuser.remove(value);
        }
    }
    if (name == "group") {
        if (arraygroup != null) {
            arraygroup.remove(value);
        }
    }
}
function push(name, value) {
    if (name == "user") {
        if (arrayuser == null) arrayuser = new Array();
        if (arrayuser != null) {
            var flag2 = usercontains(value);
            if (!flag2) {
                arrayuser.push(value);
            }
        }
    }
    if (name == "group") {
        if (arraygroup == null) arraygroup = new Array();
        if (arraygroup != null) {
            var flag2 = groupcontains(value);
            if (!flag2) {
                arraygroup.push(value);
            }
        }
    }
}
function initcheckbox_all_cancel(chkbtn, chklist) {
    var obj = uiGet(chkbtn);
    obj.onclick = function() {
        var box = uiGetTag(uiGet(chklist), "input");
        if (box != null) {
            for (i = 0; i < box.length; i++) {
                if (box[i].getAttribute("type") == "checkbox") {
                    box[i].checked = this.checked;
                    checkbox_sel(box[i]);
                }
            }
        }
    }
}
function initsubmit(subbtn, chklist, chktools, fun, arrayname, pinyin) {
    var obj = uiGet(subbtn);
    obj.onclick = function() {
        shade_c();
        var arrayuser_t = null;
        var arraygroup_t = null;
        switch (arrayname) {
        case "user":
            arrayuser_t = new Array();
            pingyin_user(null, ".");
            break;
        case "group":
            arraygroup_t = new Array();
            pingyin_group(null, ".");
            break;
        }
        var box = uiGetTag(uiGet(chklist), "input");
        var movesdiv = new Array();
        var movesbox = new Array();
        if (box != null) {
            for (i = 0; i < box.length; i++) {
                if (box[i].getAttribute("type") == "checkbox" && box[i].checked) {
                    var item = box[i].parentElement.getAttribute("item");
                    var value = box[i].parentElement.getAttribute("value");
                    switch (arrayname) {
                    case "user":
                        arrayuser_t.push(value);
                        break;
                    case "group":
                        arraygroup_t.push(value);
                        break;
                    }
                    movesbox.push(box[i]);
                } else {
                    movesdiv.push(box[i].parentElement);
                }
            }
        }
        switch (arrayname) {
        case "user":
            arrayuser = arrayuser_t;
            break;
        case "group":
            arraygroup = arraygroup_t;
            break;
        }
        var div = uiGet(chklist);
        for (i = 0; i < movesdiv.length; i++) {
            div.removeChild(movesdiv[i]);
        }
        div.setAttribute("ms", "false");
        for (i = 0; i < movesbox.length; i++) {
            var p = movesbox[i].parentElement;
            p.setAttribute("name", "");
            if (arrayname=="user")
                initgtip(p);
            p.removeChild(movesbox[i]);
        }
        div.style.height = "590px";
        if (typeof(fun) == "function") {
            fun();
        }
        cancelsite(arrayname + "block");
        var div3 = uiGet(chktools);
        div3.style.display = "none";

        var div4 = uiGet(pinyin);
        div4.style.display = "none";
    }
}
function usersite(div) {
    var div2 = uiGet(div);
    with(div2.style) {
        position = "";
        height = "600px";
        width = "200px";
        top = "";
        left = "";
        marginLeft = "0px";
        marginTop = "0px";
        border = "1px #CCCCCC solid";
        padding = "2px";
    }
}
function groupsite(div) {
    var div2 = uiGet(div);
    with(div2.style) {
        position = "";
        height = "600px";
        width = "200px";
        top = "";
        left = "";
        marginLeft = "0px";
        marginTop = "0px";
        border = "1px #CCCCCC solid";
        padding = "2px";
    }
}
function cancelsite(div) {
    var div2 = uiGet(div);
    with(div2.style) {
        position = "";
        height = "";
        width = "";
        top = "";
        left = "";
        marginLeft = "0px";
        marginTop = "0px";
        border = "";
        padding = "";
    }
}
var divuser = uiGet("userlist");
var divgroup = uiGet("grouplist");

divuser.onmousedown = function(e1) {
    ms_userdown(e1);
}
divuser.onsrcoll = function() {
     menu_c();
}
divgroup.onmousedown = function(e1) {
    ms_groupdown(e1);
}
function ms_userdown(e1) {
    var ms_ = divuser.getAttribute("ms");
    if (ms_ != "true") return;
    if (divuser.setCapture) {
        divuser.setCapture();
    }
    if (window.captureEvents) {
        window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
    }
    var x0 = uiGetX(e1);
    var y0 = uiGetY(e1);

    var obj = uiGetPosition(divuser);
    var mix = obj.x;
    var max = obj.x + obj.width - 20;
    /* 20 滚动条 */
    if (x0 >= mix && x0 <= max) {} else {
        return;
    }

    var ms = uiGet("ms_panel");
    ms.style.display = "block";
    ms.style.left = x0 + "px";
    ms.style.top = y0 + "px";

    var divs_ms = uiGetTag(uiGet("userlist"), "div");
    var scrollTop = parseInt(divuser.scrollTop, 10);
    divuser.onmousemove = function(e2) {
        try {
            var x1 = uiGetX(e2);
            var y1 = uiGetY(e2);

            /* 当 y0<y1时,正选 */
            /* 当 y0>y1时,反选 */
            if (y0 > y1) {
                ms.style.top = y1 + "px";
                ms.style.left = x1 + "px";
            }
            ms.style.width = Math.abs(x1 - x0) + 'px';
            ms.style.height = Math.abs(y1 - y0) + 'px';
            for (i = 0; i < divs_ms.length; i++) {

                var item = divs_ms[i];
                var item_pos = uiGetPosition(item);
                var dom_y1 = item_pos.y;
                var dom_y2 = item_pos.height + dom_y1;

                var flag = false;

                /* 对元素所在位置的获取控制 */
                if (y0 < y1) {
                    var y_1 = y0 + scrollTop;
                    var y_2 = y1 + scrollTop;
                    if (y_1 >= dom_y1 && y_1 <= dom_y2) {
                        flag = true;
                    }
                    if (y_2 >= dom_y1 && y_1 <= dom_y1) {
                        flag = true;
                    }
                } else {
                    var y_1 = y0 + scrollTop;
                    var y_2 = y1 + scrollTop;
                    if (y_2 >= dom_y1 && y_2 <= dom_y2) {
                        flag = true;
                    }
                    if (y_1 >= dom_y1 && y_2 <= dom_y1) {
                        flag = true;
                    }
                }
                if (flag) {
                    var box = item.getElementsByTagName("input")[0];
                    var value = item.getAttribute("value");
                    if (y0 < y1) {
                        /* 正选 */
                        box.checked = true;
                        with(box.parentElement.style) {
                            border = "1px #0099CC solid";
                            background = "#89BAE7";
                        }
                        if (arrayuser == null) arrayuser = new Array();
                        if (arrayuser != null) {
                            var flag2 = usercontains(value);
                            if (!flag2) {
                                arrayuser.push(value);
                            }
                        }
                    } else {
                        /* 反选 */
                        box.checked = false;
                        with(box.parentElement.style) {
                            border = "1px #999999 solid";
                            background = "#F9F9F9";
                        }
                        if (arrayuser != null) {
                            arrayuser.remove(value);
                        }

                    }
                }
            }
        } catch(e) {
            //window.alert(e);
        }

    }
}
function ms_groupdown(e1) {
    var ms_ = divgroup.getAttribute("ms");
    if (ms_ != "true") return;
    if (divgroup.setCapture) {
        divgroup.setCapture();
    }
    if (window.captureEvents) {
        window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
    }
    var x0 = uiGetX(e1);
    var y0 = uiGetY(e1);

    var obj = uiGetPosition(divgroup);
    var mix = obj.x;
    var max = obj.x + obj.width - 20;
    /* 20 滚动条 */
    if (x0 >= mix && x0 <= max) {} else {
        return;
    }

    var ms = uiGet("ms_panel");
    ms.style.display = "block";
    ms.style.left = x0 + "px";
    ms.style.top = y0 + "px";

    var divs_ms = uiGetTag(uiGet("grouplist"), "div");
    var scrollTop = parseInt(divgroup.scrollTop, 10);
    divgroup.onmousemove = function(e2) {
        try {
            var x1 = uiGetX(e2);
            var y1 = uiGetY(e2);

            /* 当 y0<y1时,正选 */
            /* 当 y0>y1时,反选 */
            if (y0 > y1) {
                ms.style.top = y1 + "px";
                ms.style.left = x1 + "px";
            }
            ms.style.width = Math.abs(x1 - x0) + 'px';
            ms.style.height = Math.abs(y1 - y0) + 'px';
            for (i = 0; i < divs_ms.length; i++) {

                var item = divs_ms[i];
                var item_pos = uiGetPosition(item);
                var dom_y1 = item_pos.y;
                var dom_y2 = item_pos.height + dom_y1;

                var flag = false;

                /* 对元素所在位置的获取控制 */
                if (y0 < y1) {
                    var y_1 = y0 + scrollTop;
                    var y_2 = y1 + scrollTop;
                    if (y_1 >= dom_y1 && y_1 <= dom_y2) {
                        flag = true;
                    }
                    if (y_2 >= dom_y1 && y_1 <= dom_y1) {
                        flag = true;
                    }
                } else {
                    var y_1 = y0 + scrollTop;
                    var y_2 = y1 + scrollTop;
                    if (y_2 >= dom_y1 && y_2 <= dom_y2) {
                        flag = true;
                    }
                    if (y_1 >= dom_y1 && y_2 <= dom_y1) {
                        flag = true;
                    }
                }
                if (flag) {
                    var box = item.getElementsByTagName("input")[0];
                    var value = item.getAttribute("value");
                    if (y0 < y1) {
                        /* 正选 */
                        box.checked = true;
                        with(box.parentElement.style) {
                            border = "1px #0099CC solid";
                            background = "#89BAE7";
                        }
                        if (arraygroup == null) arraygroup = new Array();
                        if (arraygroup != null) {
                            var flag2 = groupcontains(value);
                            if (!flag2) {
                                arraygroup.push(value);
                            }
                        }
                    } else {
                        /* 反选 */
                        box.checked = false;
                        with(box.parentElement.style) {
                            border = "1px #999999 solid";
                            background = "#F9F9F9";
                        }
                        if (arraygroup != null) {
                            arraygroup.remove(value);
                        }

                    }
                }
            }
        } catch(e) {
            //window.alert(e);
        }

    }
}
document.onmouseup = function() {
    if (divuser.releaseCapture) {
        divuser.releaseCapture();
    }
    if (divgroup.releaseCapture) {
        divgroup.releaseCapture();
    }
    if (window.captureEvents) {
        window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
    }
    if (divuser != null) {
        divuser.onmousedown = null;
        divuser.onmousemove = null;
        divuser.onmousedown = function(e1) {
            ms_userdown(e1);
        }
        divuser.onscroll = function() {
            menu_c();
        }
    }
    if (divgroup != null) {
        divgroup.onmousedown = null;
        divgroup.onmousemove = null;
        divgroup.onmousedown = function(e1) {
            ms_groupdown(e1);
        }
    }
    var ms = uiGet("ms_panel");
    ms.style.display = "none";
    ms.style.width = "0px";
    ms.style.height = "0px"
}
function msg_debug(msg) {
    uiGet("btnmsg").innerHTML = msg;
}
function saveusergroup(action) {
    var dialog = "";
    if (action == "append") {
        dialog = "附加权限";
    } else if (action == "modify") {
        dialog = "更改权限";
    } else if (action == "cancel") {
        dialog = "撤消权限";
    }
    if (arrayuser == null) {
        jAlert('请选择用户', dialog);
        return;
    }
    if (arraygroup == null) {
        jAlert('请选择用户组', dialog);
        return;
    }
    this.rnd();
    var url = server + "action=saveusergroup&info=" + action;
    var senddata = "";
    senddata += "userid=" + (execute == true ? executeuserid: getuserarg());
    senddata += "&groupid=" + getgrouparg();
    this.wait(msg_[1]);
    uiAjaxPost(url, senddata,
    function(e) {
        var data = null;
        try {
            data = eval("(" + e + ")");
        } catch(x) {
            jAlert('解析数据失败' + e, "提示");
        }
        if (data != null) {
            if (data == "success") {
                jAlert(dialog + "成功.", dialog);
            } else if (data == "fail") {
                jAlert(dialog + "失败.", dialog);
            } else if (data == "argerror") {
                jAlert("参数错误.", dialog);
            }
        }
        this.wait_c();
    });
}
function getgrouparg() {
    var valstr = "";
    for (i = 0; i < arraygroup.length; i++) {
        valstr += arraygroup[i] + ",";
    }
    return valstr;
}
function getuserarg() {
    var valstr = "";
    for (i = 0; i < arrayuser.length; i++) {
        valstr += arrayuser[i] + ",";
    }
    return valstr;
}
function initpingyin(pydiv) {
    var py = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.";
    var div = uiGet(pydiv);
    var item = "";
    for (var i = 0; i < py.length; i++) {
        var str = py.charAt(i);
        var name = str == "." ? "全": str;
        if (pydiv == "user_pinyin") {
            item += "<div class='div' onclick='pingyin_user(this)' value='" + str + "'>" + name + "</div>";
        } else if (pydiv == "group_pinyin") {
            item += "<div class='div' onclick='pingyin_group(this)'value='" + str + "'>" + name + "</div>";
        }
    }
    item += "<div style='clear:both;height:0px;display:none;'></div>";
    div.innerHTML = item;
}
function pingyin_user(obj, value) {
    var py = null;
    if (obj == null && value != null) {
        py = value;
    } else if (obj != null && value == null) {
        py = obj.getAttribute("value");
    }
    if (userdata != null && py != null) {
        var data = userdata;
        var li_default = "";
        var li_contains = "";

        for (i = 0; i < data.Rows.length; i++) {
            var item = data.Rows[i].UserName_S;
            var value = data.Rows[i].UserId_S;
            var itemshort = data.Rows[i].UserShortName_S;
            var flag2 = usercontains(value);
            var flag = false;
            if (itemshort.substring(0,1).toLowerCase() == py.toLowerCase()) {
                flag = true;
            }
            if (py == ".") {
                flag = true;
            }
            if (flag) {
                if (flag2) {
                    var style = "style='border:1px #0099CC solid;background:#89BAE7'";
                    li_contains += "<div item=" + item + " value=" + value + " " + style + " onclick='div_sel(this)' name='user'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' checked />&nbsp;" + item + "</div>";
                } else {
                    li_default += "<div item=" + item + " value=" + value + " onclick='div_sel(this)' name='user'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' />&nbsp;" + item + "</div>";
                }
            }
        }
        var html = li_contains + li_default;
        if (html == "") {
            html = "<font style='font-size:14px;'>无法获取 <b>" + py + "</b> 字母用户</font>";
        } else {
            if (py != ".") html = "<font style='font-size:14px;'>以下 <b>" + py + "</b> 字母用户</font>" + html;
        }
        uiGet("userlist").innerHTML = html;
    }
}
function pingyin_group(obj, value) {
    var py = null;
    if (obj == null && value != null) {
        py = value;
    } else if (obj != null && value == null) {
        py = obj.getAttribute("value");
    }
    if (groupdata != null && py != null) {
        var data = groupdata;
        var li_default = "";
        var li_contains = "";

        for (i = 0; i < data.Rows.length; i++) {
            var item = data.Rows[i].GroupName_S;
            var value = data.Rows[i].GroupId_S;
            var itemshort = data.Rows[i].GroupShortName_S;
            var flag2 = groupcontains(value);
            var flag = false;
            if (itemshort.substring(0,1).toLowerCase() == py.toLowerCase()) {
                flag = true;
            }
            if (py == ".") {
                flag = true;
            }
            if (flag) {
                if (flag2) {
                    var style = "style='border:1px #0099CC solid;background:#89BAE7'";
                    li_contains += "<div item=" + item + " value=" + value + " " + style + " onclick='div_sel(this)' name='group'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' checked />&nbsp;" + item + "</div>";
                } else {
                    li_default += "<div item=" + item + " value=" + value + " onclick='div_sel(this)' name='group'><input type='checkbox' value=" + item + "  onclick='checkbox_sel(this)' />&nbsp;" + item + "</div>";
                }
            }
        }
        var html = li_contains + li_default;
        if (html == "") {
            html = "<font style='font-size:14px;'>无法获取 <b>" + py + "</b> 字母用户</font>";
        } else {
            if (py != ".") html = "<font style='font-size:14px;'>以下 <b>" + py + "</b> 字母用户</font>" + html;
        }
        uiGet("grouplist").innerHTML = html;
    }
}
function menu(obj) {
    var value = obj.getAttribute("value");
    var name = obj.getAttribute("name");
    if (name == "" && isfun) {
        var scrollTop = parseInt(divuser.scrollTop, 10);

        var obj_pos = uiGetPosition(obj);
        var div = uiGet("menu");
        var left = obj_pos.x + obj_pos.width;
        var top = obj_pos.y;
        div.style.left = left + "px";
        div.style.top = (top - scrollTop) + "px";
        div.style.height = "48px";
        div.style.display = "block";

        var html = "";
        //html += "<div onclick='getuserinfo(" + value + ")'>查看</div>";
        html += "<div onclick='executeuser(" + value + ")'>操作</div>";
        html += "<div onclick='executeuser_c()'>取消</div>";
        div.innerHTML = html;
    }
}
function menu_c() {
    var div = uiGet("menu");
    div.style.display = "none";
}
function getuserinfo(userid) {
    this.rnd();
    var url = server + "action=getuserlist&userid=" + userid;
    this.wait(msg_[0]);
    uiAjaxGet(url,
    function(e) {
        var data = eval("(" + e + ")");
        uiGet("info").innerHTML = data;
        this.wait_c();
    });
}
function executeuser(userid) {
    var div = uiGetTag(uiGet("userlist"), "div");
    for (i = 0; i < div.length; i++) {
        if (div[i].getAttribute("value") == userid) {
            with(div[i].style) {
                border = "1px red solid";
                background = "#FFF0F0";
            }
            execute = true;
            executeuserid = userid;
        } else {
            with(div[i].style) {
                border = "1px #0099CC solid";
                background = "#89BAE7";
            }
        }
    }
}
function executeuser_c() {
    var div = uiGetTag(uiGet("userlist"), "div");
    for (i = 0; i < div.length; i++) {
        with(div[i].style) {
            border = "1px #0099CC solid";
            background = "#89BAE7";
        }
    }
    execute = false;
    executeuserid = 0;
}
function shade() {
    var div = uiGet("shade");
    var Height = parseInt(document.documentElement.scrollHeight, 10);
    var Width = parseInt(document.documentElement.scrollWidth, 10);
    div.style.top = 0 + "px";
    div.style.left = 0 + "px";
    div.style.width = Width + "px";
    div.style.height = Height + "px";
    div.style.display = "block";
}
function shade_c() {
    var div = uiGet("shade");
    div.style.display = "none";
}
function initgtip(obj) {
    var name = obj.getAttribute("name");
    var item = obj.getAttribute("item");
    var value = obj.getAttribute("value");
    if (name == "") {
        obj.onmouseover = function() {
            var pos = uiGetPosition(this);
            rnd();
            var scrollTop = parseInt(divuser.scrollTop, 10);
            var url = server + "action=getusergrouplist&userid=" + value;
            wait(msg_[0]);
            uiAjaxGet(url,
            function(e) {
                var data = eval("(" + e + ")");
                var value = data;
                var div = uiGet("gtip");
                div.style.display = "block";
                div.style.top = (pos.y- scrollTop) + "px";
                div.style.left = pos.x + pos.width + 40 + "px";
                value = value.trim() == "" ? "无法获取“" + item + "”用户组权限": "“" + item + "”：" + value;
                div.innerHTML = value;
                wait_c();
            });
        }
        obj.onmouseout = function() {
            var div = uiGet("gtip");
            div.style.display = "none";
        }
    }
}
initdivpos();
function initdivpos() {
    var divs = ["groupdiv", "userdiv"];
    for (i = 0; i < divs.length; i++) {
        var id = divs[i];
        var div = uiGet(id);
        if (div != null) {
            if (div.style.position == "absolute") {
                var obj_pos = uiGetPosition(div);
                if (obj_pos.y <= 0) {
                    div.style.top = "0px";
                    div.style.marginTop = "0px";
                }
                if (obj_pos.x <= 0) {
                    div.style.left = "0px";
                    div.style.marginLeft = "0px";
                }
            }
        }
    }
    setTimeout("initdivpos()", 1000);
}
</script>

<div id="btnmsg"></div>
<div id="ms_panel"></div>
<div id="menu"></div>
<div id="shade"></div>
<div id="gtip"></div>
</body>
</html>
