<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DownServerList.aspx.cs"
    Inherits="PowerEasy.Module.General.WebSite.User.Accessories.DownServerList" %>

<%@ Import Namespace="Resources" %>
<!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 id="Head1" runat="server">
    <title></title>
    <base target="_self" />
</head>
<body>
    <form id="MainForm" runat="server">
    <%
        downserverInput = PowerEasy.Framework.Common.DataSecurity.HtmlEncode(Request.QueryString["OpenerText"]);%>
    <div style="text-align: center">
        <table width='99%' border='0' cellpadding='2' cellspacing='0' class='model_info_table'>
            <tr class='model_info_title' style="height: 22">
                <td valign="top">
                    <b>
                        <asp:Localize ID="Localize1" Text="<%$ Res: User_Accessories_DownServerList_Localize1,已经选定的下载服务器： %>"
                            runat="server" /></b>
                </td>
                <td align="right">
                    <a href="javascript:Close();">
                        <asp:Localize ID="Localize2" Text="<%$ Res: User_Accessories_DownServerList_Localize2,返回 %>"
                            runat="server" />&gt;&gt;</a>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="text" id="KeyList" size="60" maxlength="200" readonly="readonly" class="inputxt" />
                </td>
                <td align="center">
                    <input type="button" runat="server" class="input_button" name="del1" onclick="del(1)"
                        value="<%$ Res: User_Accessories_DownServerList_del1,删除最后 %>" />
                    <input type="button" runat="server" class="input_button" name="del2" onclick="del(0)"
                        value="<%$ Res: User_Accessories_DownServerList_del2,删除全部 %>" />
                </td>
            </tr>
        </table>
        <br />
        <table width='99%' border='0' cellpadding='2' cellspacing='0' class='model_info_table'>
            <tr class='model_info_title'>
                <td>
                    <b><font color="red"></font>
                        <asp:Localize ID="Localize3" Text="<%$ Res: User_Accessories_DownServerList_Localize3,列表： %>"
                            runat="server" /></b>
                </td>
                <td align="right">
                    <asp:TextBox ID="TxtDownServer" CssClass="inputxt" runat="server"></asp:TextBox>&nbsp;&nbsp;<asp:Button
                        ID="BtnSearch" runat="server" CssClass="input_button" Text="<%$ Res: User_Accessories_DownServerList_BtnSearch , 查找 %>" />
                </td>
            </tr>
            <tr>
                <td valign="top" colspan="2">
                    <asp:Repeater ID="RepDownServers" runat="server" OnItemDataBound="RepDownServers_ItemDataBound">
                        <HeaderTemplate>
                            <table width='100%' border='0' cellpadding='2' cellspacing='0' class='model_info_table'>
                                <tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <td align="center">
                                <pe:ExtendedLabel HtmlEncode="false" ID="LblServerName" runat="server" Text=""></pe:ExtendedLabel>
                            </td>
                            <%
                                i++;%>
                            <%
                                if (i % 4 == 0 && i > 1)
                                {%>
                            </tr><tr>
                                <%
                                    }%>
                        </ItemTemplate>
                        <FooterTemplate>
                            </tr></table>
                        </FooterTemplate>
                    </asp:Repeater>
                </td>
            </tr>
            <tr class="tdbg">
                <td align="center" colspan="2">
                    <a href="javascript:" onclick="addall('<%=allDownServer%>')">
                        <asp:Localize ID="Localize4" Text="<%$ Res: User_Accessories_DownServerList_Localize4,增加以上所有下载服务器 %>"
                            runat="server" /></a>
                </td>
            </tr>
        </table>
    </div>

    <script language="javascript" type="text/javascript">
        var parentDoc = opener;
        if (opener == null) {
            parentDoc = parent;
        }

        document.getElementById("KeyList").value = parentDoc.document.getElementById("<%=downserverInput%>").value;
        
        function Close() {
            parent.$('#expose').click();
        }
        function add(obj) {
            if (obj == "") { return false; }
            if (parentDoc.document.getElementById("<%=downserverInput%>").value == "") {
                parentDoc.document.getElementById("<%=downserverInput%>").value = obj;
                document.getElementById("KeyList").value = parentDoc.document.getElementById("<%=downserverInput%>").value;
                return false;
            }
            var singleKey = obj.split("|");
            var ignoreKey = "";
            for (i = 0; i < singleKey.length; i++) {
                if (checkKey(parentDoc.document.getElementById("<%=downserverInput%>").value, singleKey[i])) {
                    ignoreKey = ignoreKey + singleKey[i] + " ";
                }
                else {
                    parentDoc.document.getElementById("<%=downserverInput%>").value = parentDoc.document.getElementById("<%=downserverInput%>").value + "|" + singleKey[i];
                    document.getElementById("KeyList").value = opener.document.getElementById("<%=downserverInput%>").value;
                }
            }
            if (ignoreKey != "") {
                alert(ignoreKey + "<%=DynamicPageResources.User_Accessories_DownServerList_JSErr%>");
            }
        }
        function addall(obj) {
            document.getElementById("KeyList").value = obj;
            parentDoc.document.getElementById("<%=downserverInput%>").value = obj;
        }
        function del(num) {
            if (num == 0 || parentDoc.document.getElementById("<%=downserverInput%>").value == "" || parentDoc.document.getElementById("<%=downserverInput%>").value == "|") {
                parentDoc.document.getElementById("<%=downserverInput%>").value = "";
                document.getElementById("KeyList").value = "";
                return false;
            }

            var strDel = parentDoc.document.getElementById("<%=downserverInput%>").value;
            var s = strDel.split("|");
            parentDoc.document.getElementById("<%=downserverInput%>").value = strDel.substring(0, strDel.length - s[s.length - 1].length - 1);
            document.getElementById("KeyList").value = parentDoc.document.getElementById("<%=downserverInput%>").value;
        }

        function checkKey(Keylist, thisKey) {
            if (Keylist == thisKey) {
                return true;
            }
            else {
                var s = Keylist.split("|");
                for (j = 0; j < s.length; j++) {
                    if (s[j] == thisKey)
                        return true;
                }
                return false;
            }
        }
    </script>

    </form>
</body>
</html>
