<%@ Page Language="C#" EnableEventValidation="false" CodeBehind="managesearchSelectBigClass.aspx.cs" Inherits="Web.User.managesearchSelectBigClass" %>

<!DOCTYPE html>
<!--[if lt IE 9]><html class="lte-ie8"><![endif]-->
<!--[if gt IE 8]><!-->
<html>
<!--<![endif]-->
<head>
    <title>栏目选择</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!--#include file="../Css/head.htm"-->

    <script 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;
							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));
							}  
					} 
				}                       
				checkform();
			}
			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));
							}  
			           
				}  
				checkform();          
			}

			// 从已选中删除
			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--;
					}
			     }
			     checkform();
			}
			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;
               	}
               	checkform();			  
			}

			// 排序：向上移动
			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;
				checkform();
			}

			// 排序：向下移动
			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;
				checkform();
			}

			// 提交处理
			function checkform() {
			    var selectFrom=document.getElementById("d_b2");
			    var optionName="";
			    var optionValue="";
			   for(var loop=0;loop<selectFrom.options.length;loop++)
				{ 
					optionName = optionName + "|" + selectFrom.options[loop].text ;
					optionValue = optionValue + "|" + selectFrom.options[loop].value ;
				} 
				var itemName = document.getElementById("hiddenName");
				var itemValue = document.getElementById("hiddenValue");
				itemName.value = optionName+"|";
				itemValue.value = optionValue+"|"; 
     	
				window.close();
			}
			function getDuplicatedBigClass()
			{
			    var itemName = document.getElementById("hiddenName").value;

			    var itemValue = document.getElementById("hiddenValue").value;
			    InitSelectedBigClass(itemName, itemValue);
			}
			function InitSelectedBigClass(itemName, itemValue)
			{

			    var arrayName = itemName.split('|') ; 
			    var arrayValue = itemValue.split('|') ;
			    var selectedFrom = document.getElementById("d_b2");
			    for(var loop=0; loop<arrayName.length-1; loop++)
			    {
			        if(arrayName[loop]!="")
			        {
			        selectedFrom.add(new Option(arrayName[loop], arrayValue[loop]));
			        }
			    }
			}
    </script>

</head>
<body>
    <form id="myform" method="post" runat="server">
    <div class="edit-func-box func-box">
        <div class="bd">
            <table class="edit-table">
                <tr>
                    <td width="15%">
                    </td>
                    <td align="center">
                        可选栏目
                    </td>
                    <td>
                    </td>
                    <td align="center">
                    已选栏目
                    </td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:ListBox ID="d_b1" runat="server" SelectionMode="Multiple" Height="242px" Width="170px">
                        </asp:ListBox>
                    </td>
                    <td width="15%" >
                        <p>
                            <input onclick="Add()" type="button" value=" → " name="b1" class="btn btn-mini btn-info" />
                        </p>
                        <br />
                        <p>
                            <input onclick="Del()" type="button" value=" ← " name="b1" class="btn btn-mini btn-info" />
                        </p>
                        <br />
                        <p>
                            <input onclick="AddAll()" type="button" value=" >> " name="b1" class="btn btn-mini btn-info" />
                        </p>
                        <br />
                        <p>
                            <input onclick="DelAll()" type="button" value=" << " name="b1" class="btn btn-mini btn-info" />
                            <div width="50" height="8">
                            </div>
                        </p>
                    </td>
                    <td>
                        <asp:ListBox ID="d_b2" runat="server" SelectionMode="Multiple" Height="242px" Width="170px">
                        </asp:ListBox>
                    </td>
                    <td width="15%">
                        <p>
                        <input onclick="Up()" type="button" value="↑" name="b3" class="btn btn-mini btn-info" />
                        </p>
                        <br />
                        <p>
                        <input onclick="Down()" type="button" value="↓" name="b4" class="btn btn-mini btn-info" />
                        </p>
                    </td>
                </tr>
            </table>
        </div>
        <div class="ft">
            <div class="action-field text-center">
                <asp:Button ID="Submit" runat="server" OnClick="Submit_Click" Text="确 定" CssClass="btn btn-sm btn-primary" />
                <input id="hiddenName" type="hidden" runat="server" />
                <input id="hiddenValue" type="hidden" runat="server" />
            </div>
        </div>
    </div>
    <font color="red">
        使用方法：<br />左侧框中为网站中所有可被搜索的栏目，右侧框中为栏目集合后的搜索范围，将需要进行搜索的栏目选择到右侧框中再点击确定按钮即可。<br /><br />
        注意：<br />初始化默认不选择栏目将会自动取所有栏目，若选择过栏目范围，之后右侧框中不选择栏目范围则视为尚未选取栏目，可能导致搜索不到内容。</font>
    <script type="text/javascript">
        getDuplicatedBigClass();
    </script>
    </form>
</body>
</html>