<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectionPage.aspx.cs" Inherits="SubPages_SelectionPage" %>

<!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 runat="server">
    <title>Selection Page</title>
	<script language="javascript" type="text/javascript" src="../Script/HScript.js"></script>
	<script language="javascript">
		
//		function page_onload(){
//			var selParent = window.opener.document.getElementById(Form1.hidTargetObjectName.value);
//			var selChild = Form1.selAvailable;
//			if ( selChild.options.length >0){
//				for (i=selChild.options.length-1; i>=0; i--){
//					for(j=0; j< selParent.options.length; j++){
//						if (selParent.options[j].value == selChild.options[i].value){
//							Form1.selSelected.options.add( new Option( selChild.options[i].value, selChild.options[i].value), 0); //Form1.selAvailable.options.length, 0, 0);
//							selChild.options.remove(i);
//							break;
//						}
//					}
//				}
//			}
//			else{
//				for(i=0; i< selParent.options.length; i++){
//					Form1.selSelected.options.add( new Option( selParent.options[i].value, selParent.options[i].value), Form1.selSelected.options.length); //Form1.selAvailable.options.length, 0, 0);
//				}
//			}			
//		}
		function page_onload(){
			var arParent = window.opener.document.getElementById(Form1.hidTargetObjectName.value).value.split("\n");
			var selChild = Form1.selAvailable;
			if ( selChild.options.length >0){
				for (i=selChild.options.length-1; i>=0; i--){
					for(j=0; j< arParent.length; j++){
						if (trim(arParent[j]) == selChild.options[i].value){
							Form1.selSelected.options.add( new Option( selChild.options[i].value, selChild.options[i].value), 0); //Form1.selAvailable.options.length, 0, 0);
							selChild.options.remove(i);
							break;
						}
					}
				}
			}
			else{
				for(i=0; i< arParent.length; i++){
					Form1.selSelected.options.add( new Option( arParent[i], selParent[i]), Form1.selSelected.options.length); //Form1.selAvailable.options.length, 0, 0);
				}
			}			
		}


		function toRight(){
			if ( Form1.txtNewValue.value != ""){
				insertAndSortASC ( Form1.selSelected, Form1.txtNewValue.value, Form1.txtNewValue.value);
				Form1.txtNewValue.value = "";
				Form1.txtNewValue.focus();
			}
			else
				ListAndSelectedOperation(Form1.selAvailable, Form1.selSelected, 1, Form1.hidMaxCount.value);
		}
		function toLeft(){
			ListAndSelectedOperation(Form1.selAvailable, Form1.selSelected, 2);
		}
		
		
		function Accept(){
			var opSource = Form1.selSelected;
			//var sel= window.opener.document.getElementById(Form1.hidTargetObjectName.value);
			var ar = new Array();
			for (i=0; i< opSource.length; i++){
				ar[i] = opSource[i].value;	
			}
			//window.opener.document.getElementById(Form1.hidTargetObjectName.value).innerHTML = s;
			//window.opener.document.getElementById('t').value = 'aa';
			parent.opener.changeSelectValue(Form1.hidTargetObjectName.value, ar);
			window.close();
		}
		function Cancel(){
			window.close();
		}
	</script>
</head>
  <body bgcolor="#dbdbd9" onload="page_onload()">
	
    <form id="Form1" method="post" runat="server">
		<input type="hidden" id="hidTargetObjectName" runat="server">
		<input type="hidden" id="hidMaxCount" runat="server">
		
		<table>
			<div align="center" id="divTitle" class="PageTitle_Edit" style="color: blue; size=14px" runat="server">Result SPEC List</div>
			
			<tr>
				<td valign="top">
					Available :
				</td>
				<td valign="center">
				</td>
				<td valign="top">
					Selected :
				</td>
			</tr>
			<tr>
				<td valign="top">
					<select id="selAvailable" multiple="true" size="10" style="width: 300px" runat="server" ondblclick="toRight()"></select><br><br>
					<input id="txtNewValue" type="text" style="width: 300px" runat="server">
				</td>
				<td valign="center">
					<input type="button" value=" >> " onclick="toRight()">
					<br>
					<input type="button" value=" << " onclick="toLeft()">
				</td>
				<td valign="top">
					<select id="selSelected" multiple="true" size="13" style="width: 300px" runat="server" ondblclick="toLeft()"></select>
				</td>
			</tr>
			<tr>
				<td colspan="3" align="center">
					<input type="button" value="Accept" onclick="Accept()">
					<input type="button" value="Cancel" onclick="Cancel()">
				</td>
			</tr>
		</table>
    </form>
	
  </body>
</html>
