<%@ Page Language="c#" Inherits="Web.User.SelectSignUpField" EnableEventValidation="false" CodeBehind="SelectSignUpField.aspx.cs" %>
<!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" language="javascript">
    var URLParams = new Object() ;
    var aParams = document.location.search.substr(1).split('&') ;
    for (i=0 ; i < aParams.length ; i++) {
	    var aParam = aParams[i].split('=') ;
	    URLParams[aParam[0]] = aParam[1] ;
    }
    
    // 加入已选
    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;
             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.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() {
    
	var sel=document.myform.d_b2;
	var nLen = sel.length;
	var str1="";
	var str2="";
	for (var i=0;i<nLen;i++) {
	    if (sel.options[i].value != "" && sel.options[i].text!="")
	    {
		    if (i>0) 
		    {str2+=",";str1+=",";}
		    str2+=sel.options[i].value;
		    str1+=sel.options[i].text;
		}
	}
	
	document.myform.d_name.value=str1;
	document.myform.d_value.value=str2;
	
	return true ;
	
}



function initData() 
{
	var selectTo=document.myform.d_b2;
	var valueList = parent.window.dialogArguments.ReturnMoreClassValue().split(",");
	var nameList = parent.window.dialogArguments.ReturnMoreClassText().split(",");
	for(var loop=0;loop<valueList.length;loop++)
	{
                           
             var optionName = nameList[loop] ;
             var optionValue = valueList[loop] ;                        
             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 delayClose(type,menuId)
{
 parent.$.fancybox.close();
            //关闭后刷新布局列表
            parent.location = "managesignUp.aspx?type="+type+"&menuId=" + menuId;
}

    </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 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:ListBox ID="d_b1" runat="server" SelectionMode="Multiple" Height="288px" Width="230px">
                        </asp:ListBox>
                    </td>
                    <td width="15%" align="center">
                        <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="288px" Width="230px">
                        </asp:ListBox>
                    </td>
                    <td width="15%">
                        <input onclick="Up()" type="button" value="↑" name="b3" class="btn btn-mini btn-info" />
                        <br />
                        <br />
                        <input onclick="Down()" type="button" value="↓" name="b4" class="btn btn-mini btn-info" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="ft">
            <div class="action-field text-center">
                <asp:Button ID="btnSave" runat="server" CssClass="btn btn-sm btn-primary" Text="确定" OnClientClick="return checkform();" OnClick="btnSave_Click" />&nbsp;&nbsp;
                <asp:Button ID="btnClose" runat="server" CssClass="btn btn-sm btn-primary" Text="取消" OnClick="btnClose_Click" />
            </div>
        </div>
    </div>
    <input id="d_name" type="hidden" name="d_button" runat="server" />
    <input id="d_value" type="hidden" name="d_button" runat="server" />
    </form>
</body>
</html>
