<%@ Page Language="c#" AutoEventWireup="true" Inherits="Web.Wpdcc.selectServiceClass" CodeBehind="selectServiceClass.aspx.cs" %>

<html>
<head>
    <title>注册服务管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!--#include file = "../Css/head.htm" -->
    <style>
        form {
    margin-bottom: 0px;
    }
    </style>
    <script language="javascript" type="text/javascript">
        // 加入已选
        function Add() {
            var selectFrom = document.getElementById("d_b1");
            var selectTo = document.getElementById("d_b2");
            if (selectFrom.selectedIndex < 0) {
                alert("请选择待选栏目！");
                return;
            }

            for (var loop = 0; loop < selectFrom.options.length; loop++) {
                if (selectFrom.options[loop].selected == true) {
                    var optionName = selectFrom.options[loop].text;
                    var optionValue = selectFrom.options[loop].value;
                    var flag = false;
                    var ii;
                    for (var i = 0; i < selectTo.options.length; i++) {
                        if (optionValue == selectTo.options[i].value) {
                            flag = true;
                            ii = i;
                            break;
                        }
                    }

                    if (flag == true) {
                        alert("“" + selectFrom.options[loop].text + "”栏目已被选择！\n\r对应已选栏目“" + selectTo.options[ii].text + "”");
                    }
                    else {
                        selectTo.add(new Option(optionName, optionValue));
                    }
                }
            }

        }

        function AddAll() {
            var selectFrom = document.getElementById("d_b1");
            var selectTo = document.getElementById("d_b2");


            for (var loop = 0; loop < selectFrom.options.length; loop++) {

                var optionName = selectFrom.options[loop].text;
                var optionValue = selectFrom.options[loop].value;
                var flag = false;
                for (var i = 0; i < selectTo.options.length; i++) {
                    if (optionValue == selectTo.options[i].value) {
                        flag = true;
                        break;
                    }
                }

                if (flag == false) {

                    selectTo.add(new Option(optionName, optionValue));
                }

            }
        }

        // 从已选中删除
        function Del() {
            var selectTo = document.getElementById("d_b2");
            var nIndex = selectTo.selectedIndex;
            var nLen = selectTo.length;
            if (nLen < 1) return;
            if (nIndex < 0) {
                alert("请选择已选栏目！");
                return;
            }

            for (var loop = 0; loop < selectTo.options.length; loop++) {
                if (selectTo.options[loop].selected) {
                    selectTo.options[loop] = null; loop--;
                }
            }

        }
        function DelAll() {
            var selectTo = document.getElementById("d_b2");
            var nLen = selectTo.length;
            if (nLen < 1) return;
            for (var loop = nLen; loop >= 0; loop--) {
                selectTo.options[loop] = null;
            }

        }

        // 排序：向上移动
        function Up() {
            var sel = document.getElementById("d_b2");
            var nIndex = sel.selectedIndex;
            var nLen = sel.length;
            if ((nLen < 1) || (nIndex == 0)) return;
            if (nIndex < 0) {
                alert("请选择一个要移动的已选栏目！");
                return;
            }
            var sValue = sel.options[nIndex].value;
            var sHTML = sel.options[nIndex].innerHTML;
            sel.options[nIndex].value = sel.options[nIndex - 1].value;
            sel.options[nIndex].innerHTML = sel.options[nIndex - 1].innerHTML;
            sel.options[nIndex - 1].value = sValue;
            sel.options[nIndex - 1].innerHTML = sHTML;
            sel.selectedIndex = nIndex - 1;
        }

        // 排序：向下移动
        function Down() {
            var sel = document.getElementById("d_b2");
            var nIndex = sel.selectedIndex;
            var nLen = sel.length;
            if ((nLen < 1) || (nIndex == nLen - 1)) return;
            if (nIndex < 0) {
                alert("请选择一个要移动的已选栏目！");
                return;
            }
            var sValue = sel.options[nIndex].value;
            var sHTML = sel.options[nIndex].innerHTML;
            sel.options[nIndex].value = sel.options[nIndex + 1].value;
            sel.options[nIndex].innerHTML = sel.options[nIndex + 1].innerHTML;
            sel.options[nIndex + 1].value = sValue;
            sel.options[nIndex + 1].innerHTML = sHTML;
            sel.selectedIndex = nIndex + 1;
        }

        // 提交处理
        function checkform() {
            try {
                var sel = document.getElementById("d_b2");
                var nLen = sel.length;
                var str1 = "";
                var str2 = "";
                for (var i = 0; i < nLen; i++) {
                    if (i > 0) {
                        str2 += ",";
                        str1 += ",";
                    }
                    str2 += sel.options[i].value;
                    str1 += sel.options[i].text;
                }
                document.getElementById("d_name").value = str1;
                document.getElementById("d_value").value = str2;
            } catch (e) {
                return false;
            }
            return true;
        }

    </script>
</head>
<body>
    <form id="myform" method="post" runat="server">
        <div class="edit-func-box func-box">
            <div class="hd b">
                注册服务对应栏目选择
            </div>
            <div class="bd" style="max-height:350px">
                <table class="edit-table">
                    <tr>
                        <th colspan="2">
                            <div align="center">
                                可选栏目
                            </div>
                        </th>
                        <th></th>
                        <th colspan="2">
                            <div align="center">
                                已选栏目
                            </div>
                        </th>
                    </tr>
                    <tr>
                        <th width="15%"></th>
                        <td>
                            <asp:ListBox ID="d_b1" runat="server" SelectionMode="Multiple" Height="288px" Width="168px"></asp:ListBox>
                        </td>
                        <th width="15%" align="center">
                            <p>
                                <input onclick="Add()" type="button" value=" -> " name="b1" class="btn btn-mini btn-primary" />
                                 </p>
                            <br />
                            <p>
                                <input onclick="Del()" type="button" value=" <- " name="b1" class="btn btn-mini btn-primary" />
                            </p>
                            <br />
                            <p>
                                <input  onclick="AddAll()" type="button" value=">>" name="b1"  class="btn btn-mini btn-primary" />
                                 </p>
                            <br />
                            <p>
                                <input  onclick="DelAll()" type="button" value="<<" name="b1"  class="btn btn-mini btn-primary" />
                            </p>

                        </th>
                        <td>
                            <asp:ListBox ID="d_b2" runat="server" SelectionMode="Multiple" Height="288px" Width="168px"></asp:ListBox>
                        </td>
                        <th width="15%"><p>
                            <input onclick="Up()" type="button" value="↑" name="b3"  class="btn btn-mini btn-primary" />
                             </p>
                            <br />
                            <p>
                            <input onclick="Down()" type="button" value="↓" name="b4"  class="btn btn-mini btn-primary" />  </p>
                        </th>
                    </tr>
                </table>
            </div>
            <div class="ft">
                <div class="action-field text-center">
                    <input id="d_name" type="hidden" name="d_button" runat="server" />&nbsp;
                <input id="d_value" type="hidden" name="d_button" runat="server" />
                    <asp:Button ID="btnSave" runat="server" Text="保 存" CssClass="btn btn-sm btn-primary" OnClientClick="return checkform();" OnClick="btn_Click" />
                    &nbsp;&nbsp;&nbsp;
                <input type="button" onclick="parent.$.fancybox.close();" value="取 消" class="btn btn-sm btn-primary" />
                </div>
            </div>
        </div>
    </form>
</body>
</html>
