<%@ Page Language="c#" Inherits="WebApp.Wpdcc.selectSchools" CodeBehind="selectSchools.aspx.cs" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>子站选择</title>
    <meta name="description" content="overview &amp; stats" />
    <!--#include file = "../assets/head.htm" -->
</head>
<body class="no-skin">
    <form id="myform" method="post" runat="server">
        <div class="main-content-inner">

            <!-- /section:basics/content.breadcrumbs -->

            <div class="page-content">
                <!-- PAGE CONTENT BEGINS -->
                <div class="row">
                    <div class="col-xs-12">
                        <asp:ScriptManager ID="ScriptManager1" runat="server">
                        </asp:ScriptManager>
                        <div class="function-hd">
                            <div class="search-box fr">
                            </div>
                            <div class="action-field">
                                可选服务器：
                                <asp:DropDownList ID="ddlServerList" runat="server">
                                </asp:DropDownList>
                                &nbsp;<asp:Button ID="btnQuery" CssClass="btn btn-sm btn-primary" runat="server" Text="查看" OnClick="btnQuery_Click" />
                            </div>
                            <!--/action-field-->
                        </div>
                        <br />
                        <table class="table table-striped table-bordered">
                            <tr>
                                <td colspan="2">
                                    <div align="center">
                                        可选子站
                                    </div>
                                </td>
                                <td></td>
                                <td colspan="2">
                                    <div align="center">
                                        已选子站
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td width="15%"></td>
                                <td>
                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                                        <ContentTemplate>
                                            <asp:ListBox ID="d_b1" runat="server" SelectionMode="Multiple" Height="232px" Width="168px"></asp:ListBox>
                                        </ContentTemplate>
                                        <Triggers>
                                            <asp:AsyncPostBackTrigger ControlID="btnQuery" EventName="Click" />
                                        </Triggers>
                                    </asp:UpdatePanel>
                                </td>
                                <td width="15%" align="center">
                                    <p>
                                        <input onclick="Add()" type="button" value=" → " name="b1" class="btn btn-xs btn-primary">
                                    </p>
                                    <p>
                                        <input onclick="Del()" type="button" value=" ← " name="b1" class="btn btn-xs btn-primary">
                                    </p>
                                    <p>
                                        <input onclick="AddAll()" type="button" value=">>" name="b1" class="btn btn-xs btn-primary">
                                    </p>
                                    <p>
                                        <input onclick="DelAll()" type="button" value="<<" name="b1" class="btn btn-xs btn-primary">
                                        
                                    </p>
                                </td>
                                <td>
                                    <asp:ListBox ID="d_b2" runat="server" SelectionMode="Multiple" Height="232px" Width="168px"></asp:ListBox>
                                </td>
                                <td width="15%">
                                    <input onclick="Up()" type="button" value="↑" name="b3" class="btn btn-xs btn-primary">
                                    <br/>
                                    <br/>
                                    <input onclick="Down()" type="button" value="↓" name="b4" class="btn btn-xs btn-primary">
                                    <div width="50" height="8">
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                
                                <td colspan="5" align="center">
                                    <input type="button" value="确定" class="btn btn-sm btn-primary" onclick="checkform();">&nbsp;&nbsp;&nbsp;
                                    <input type="button" value="取消" class="btn btn-sm btn-primary" name="btnClose" onclick="parent.$.fancybox.close();">
                                </td>
                            </tr>
                        </table>
                    </div>
                    <input id="d_name" type="hidden" name="d_button" runat="server">
                    <input id="d_value" type="hidden" name="d_button" runat="server">
                </div>
            </div>
        </div>
    </form>
    <script language="javascript">
        // 加入已选
        function Add() {
            var selectFrom = document.myform.d_b1;
            var selectTo = document.myform.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;
                    for (var i = 0; i < selectTo.options.length; i++) {
                        if (optionValue == selectTo.options[i].value) {
                            flag = true;
                            break;
                        }
                    }

                    if (flag == true) {
                        alert("“" + selectFrom.options[loop].text + "”已被选择!");
                    }
                    else {
                        selectTo.add(new Option(optionName, optionValue));
                    }
                }
            }

        }
        function AddAll() {
            var selectFrom = document.myform.d_b1;
            var selectTo = document.myform.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.myform.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.myform.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.myform.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.myform.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() {
            //parent.window.dialogArguments.DelAll();
            parent.DelAll();
            var selectFrom = document.myform.d_b2;
            for (var loop = 0; loop < selectFrom.options.length; loop++) {
                var optionName = selectFrom.options[loop].text;
                var optionValue = selectFrom.options[loop].value;
                //parent.window.dialogArguments.checkform(optionName,optionValue);
                parent.checkform(optionName, optionValue);
            }
            //window.close();
            parent.$.fancybox.close();
        }
    </script>
</body>

</html>



