<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*"%>
<jsp:useBean id="AS03_1" class="com.csc.library.system.Task" scope="page" />
<%AS03_1.setChannel(request, response);%>
<%
	HelpEntry screen = (HelpEntry) AS03_1.process("HelpEntry","AS03_1");
	CheckNull chk=new CheckNull();
	String fixcon=chk.chkNullString(request.getParameter("__fixCon"));

	if(fixcon.length()>0){
		screen.setMaxLine(200);
		screen.process();
	}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
		<script  language="JavaScript" src="../JS/SCREEN.js"></script>

		<script type='text/javascript' src='../JS/ICONSMENU.js'></script>
		<script language='javascript' src='../JS/HOTKEY.js'></script>
		<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>

		<script language="JavaScript" type="text/JavaScript">
			<!--
				function MM_preloadImages() { //v3.0
					var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
					var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
					if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
				}


				function MM_swapImgRestore() { //v3.0
					var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
				}

				function MM_findObj(n, d) { //v4.01
					var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
					d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
					if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
					for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
					if(!x && d.getElementById) x=d.getElementById(n); return x;
				}

				function MM_swapImage() { //v3.0
					var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
					if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
				}

				function showHelp(page){
					window.open(page,"Help","left=150,top=150,width=700,height=500,toolbar=no,status=yes,scrollbars=yes");
				}


				function showAnswer(fixcon,asgid){
					var page="AS03HELP_3.jsp?__fixCon="+fixcon+"&__asgid="+asgid;
					window.open(page,"Help","left=150,top=150,width=700,height=500,toolbar=no,status=yes,scrollbars=yes");
				}

		//-----------------------------------Onload ------------------------------------

				function getOrderOption(objform){
					with(objform){
						newDestList = new Array(objform.__asgrouplist.options.length );
						var mystr="";
						var len=0;
						if((typeof __masgid.length)!="undefined"){
							for(i=0;i<__masgid.length;i++){
								len=newDestList.length;
								if(mystr!=__masgid[i].value){
									newDestList[len]=new Option(__masgid[i].value+"            "+__masgdesc[i].value,__masgid[i].value);
									newDestList[++len]=new Option("            "+__mascode[i].value+"           "+__masdesc[i].value,__masid[i].value);
									mystr=__masgid[i].value
								}else{
								newDestList[len]=new Option("            "+__mascode[i].value+"           "+__masdesc[i].value,__masid[i].value);
								}
							}
							return newDestList;
							}else{
								if((typeof __masgid)!="undefined"){
									newDestList[len]=new Option(__masgid.value+"            "+__masgdesc.value,__masgid.value);
									newDestList[++len]=new Option("            "+__mascode.value+"            "+__masdesc.value,__masid.value);								
									return newDestList;
								}
							}
						}
					}	
				
				function showMyObj(){
					if((typeof document.cscform.__masgid)!="undefined"){
						writeToOption(getOrderOption(document.cscform),getMyChildoption());
					}
				}

		//------------------------------------ End OnLOAD---------------------------------
		//--------------------------- add MyOption-----------------------
		// Compare two options within a list by VALUES
				function compareOptionValues(a, b){
					// Radix 10: for numeric values
					// Radix 36: for alphanumeric values
					var sA = parseInt( a.value, 36 );
					var sB = parseInt( b.value, 36 );
					return sA - sB;
				}
				// Compare two options within a list by TEXT

				function compareOptionText(a, b){
					// Radix 10: for numeric values
					// Radix 36: for alphanumeric values
					var sA = parseInt( a.text, 36 );
					var sB = parseInt( b.text, 36 );
					return sA - sB;
				}

				function findKey(objOption,myList){
					for ( var j = 0 ; j < objOption.length; j++ ){
						for(var i=0;i < myList.length;i++){
							if(objOption[j].value == myList.options[i].value){
								alert("รหัส " + myList.options[i].value + " มีอยู่ในรายการแล้ว\nกรุณาตรวจสอบด้วยนะครับ");
								return true;
							}//if
						}//for
					}	//for
					return false;
				}

				function delteOption(objmyList){
					for(i=objmyList.length;i > 0;i--){
						if(objmyList.options[i-1].selected == true){
							objmyList.options[i-1]  = null;
						}
					}
				}


				function setMyaslist(objmyList){
					var myStr="";
					for(i=0;i <objmyList.length;i++){
						if(objmyList.options[i].value.indexOf("#")>-1){
							myStr+=objmyList.options[i].value;
						}
						//	alert(myStr);
					}
					return myStr;
				}

				function getMyParenastype(){
					return window.parent.getMyastype();
				}

				function setmFixcon(asgroup){
					return "asgid='"+asgroup+"'";
				}

				function getMyChildoption(){
					//alert(document.forms[0].__asgrouplist.length);
					return document.forms[0].__asgrouplist;
				}

				function addOption(objOption){
					addToOption(objOption,getMyChildoption()) ;
				} // End of addOption()


				function onmyDblClick(objmyList){
					console.log(objmyList);
					for(i=objmyList.length;i > 0;i--){
						if(objmyList.options[i-1].selected == true){
							showAnswer(setmFixcon(objmyList.options[i-1].value),objmyList.options[i-1].value);
						}
					}
				}

				function addToOption(objOption,destList){
					var lengthAll=parseInt(objOption.length)+parseInt(destList.options.length);
					newDestList = new Array( lengthAll );
					var clen=0;
					for( len = 0; len <destList.options.length; len++ ){
						if ( destList.options[ len ] != null ){
							newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
							clen++;				
						}
					}
					for ( var j = 0 ; j < objOption.length; j++ ){
						if ( objOption[ j ] != null ){
							newDestList[ clen ] = objOption[ j ];
							clen++;
						}
					}
					newDestList.sort( compareOptionValues );
					for( var i = destList.options.length - 1; i >= 0; i-- )	{
						if ( destList.options[i] != null  ){
						destList.options[i]       = null;
						}
					}
					/*for ( var j = 0; j < newDestList.length; j++ ){
						if ( newDestList[ j ] != null ){
							destList.options[ j ] =new Option(newDestList[ j ].text,newDestList[ j ].value);
						}
					}*/
					writeToOption(newDestList,destList);
				} // End of addToOption()


				function writeToOption(newDestList,destList){
					for ( var j = 0; j < newDestList.length; j++ ){
						if ( newDestList[ j ] != null ){
							destList.options[ j ] =new Option(newDestList[ j ].text,newDestList[ j ].value);
						}
					}
				}
			//----------------------------------------------------
			//-->
		</script>
	</head>
	<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"   onLoad="showMyObj();">

		<form name="cscform" method="post" action="#">

			<!----------BEGIN CSC INITIAL ZONE ------------------------>

			<%//=screen.InitialVariable()%>

			<!----------END CSC INITIAL ZONE -------------------------->

			<input type="hidden" name="__cmd" value="">
			<input type="hidden" name="__help" value="">
			<input type="hidden" name="__fixCon" value="">
			<input type="hidden" name="_astype" value="">
			<input type="hidden" name="__pageCall" value="<%=request.getParameter("__screen")%>">
			<input type="hidden" name="__language" value ="<%=screen.getUProfile().get("lang")%>"> 
			<%
				if(fixcon.length()>0){
					while(screen.nextRec()){
			%>
			<input type="hidden" name="__masgid" value="<%=screen.getString("asgid")%>">
			<input type="hidden" name="__masgdesc" value="<%=screen.getString("masgroup","tdesc")%>">
			<input type="hidden" name="__masid" value="<%=screen.getString("asgid")%>#<%=screen.getString("asid")%>,">
			<input type="hidden" name="__mascode" value="<%=screen.getString("massess","asid")%>">
			<input type="hidden" name="__masdesc"  value="<%=screen.getString("massess","tdesc")%>">
			<%
					}
				}
			%>
			<div align="center">
				<table class="inframe" width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#666666">
					<tr>
						<td width="15%" nowrap class="title1"><div align="center"><strong> <script language="javascript">swapLang('Code');</script></strong></div></td>
						<td   nowrap class="title1"><div align="center"><strong> <script language="javascript">swapLang('Description');</script></strong></div></td>
					</tr>
					<tr bgcolor="#FFFFFF" >
						<td colspan="2" class="inner"> 
							<select name="__asgrouplist" style="width:600px;height:500px;" size="15" multiple    onDblClick="onmyDblClick(this.form.__asgrouplist);"></select> 
						</td>
					</tr>
				</table>
			</div>
		</form>
	</body>
</html>
