<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.*,com.csc.library.system.*,com.csc.library.session.*,com.csc.library.utilities.*,com.csc.library.components.*;"%>
<jsp:useBean id="M360" scope="page" class="com.csc.library.system.Task"/>
<%
	M360.setChannel(request ,response);
	UIManager screen = (UIManager) M360.process("SingleEntry","APS360_CONFIG");
	CheckNull chk = new CheckNull();
	String bu2 = chk.chkNullString(request.getParameter("__bu2"));
	String bu2desc = chk.chkNullString(request.getParameter("__bu2desc"));

	DbInquiry inq1 = new InitialInquiry(screen.getUProfile()).getDbInquiry("M360CONFIG");
	inq1.setFilter(" bu2 = '"+bu2+"'");
	inq1.refresh();
	inq1.next();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html ng-app="myHR">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css"/>
		<link href="../CSS/bootstrap.css" rel="stylesheet"  type="text/css">
		<link href="../CSS/bootstrap_csc_backend.css" rel="stylesheet"  type="text/css">

		<script type='text/javascript' src='../JS/SCREEN.js'></script>
		<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
		<script type='text/javascript' src="../JS/bootstrap.js"></script>
		<script src="../JS/angular-1.3.15/angular.js" type="text/javascript"></script>
		<script src="../JS/ANGULAR/SCREEN_ANGULAR.js" type="text/javascript"></script>
		<script language="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">getTitleName();</script>
		<style>
			.center {
				text-align: center;
			}
		</style>
		<script>
			$(document).ready(function(){
				countseq();
			});

			function goHelp(helpName,inputName){
				var helpReturn;
				if(inputName=="__bu2" ){
					helpReturn="__bu2:bu2id,__bu2desc:tdesc";
				}
				linkHelp_Return(helpName,helpReturn);
			}

			function postReturn(){
				document.cscform.submit();
			}

			function add(){
				setSubData()
				with(document.cscform){
					var bu2 = $("input[name='__bu2']").val() + "," + $("input[name='__subdata']").val()
					var fixCon="bu2id not in('"+bu2.replace( new RegExp(',', 'g'), "','")+"')";
					if(bu2 != ""){
						linkHelp_ReturnMulti( "MBU2HELP" , "BU2ID", fixCon );
					}else{
						alert("กรุณาเลือก สายงาน ก่อน")
					}
				}
			}

			function linkHelp_ReturnMulti( helpName, inputName, fixCon ){
				with(document.cscform){
					if(fixCon == null){
						fixCon = __fixCon.value;
					}
					var param="PRU085.jsp?__helpName="+helpName+"&__helpReturn="+inputName+"&__pageCall="+__screen.value+"&__fixCon=" +fixCon+"&__checkVerify=off";
					PopupCenterTop( param, "popup", 900, 600);
				}
			}

			function PopupCenterTop( url, winName, w, h) {
				var width = w || DEFAULT_WIN_WIDTH;
				var height = h || DEFAULT_WIN_HEIGHT;
				var left = ( screen.width ) ? ( screen.width-width )/2 : 0;
				var OpenWindow;
				features = 'height=' + height + ',width=' + width + ',top=30,left=' + left + ', resizable=yes, toolbar=no , scrollbars=yes , status=yes';
				OpenWindow = window.open( url , winName , features);
				OpenWindow.focus();
				return OpenWindow;
			}

			function findDuplicate(data){
				with(document.cscform){
					var tmp = data.split("$");
					chkbox = document.getElementById("c_"+tmp[0]);
					if(chkbox!=null){
						return true
					}
					return false;
				}
			}

			function backPage_ReturnMulti(valueList){
				var tmp = valueList.split("$");
				if(tmp.length>=2){
					addRowToTable(tmp);
				}
			}

			function addRowToTable( data ) {
				// data[0] = bu2id
				// data[1] = companyid
				// data[2] = tdesc
				// data[3] = edesc
				var tbl = document.getElementById("tblMulti");
				var lastRow = tbl.rows.length;
				// if there's no header row in the table, then iteration = lastRow + 1
				var iteration = lastRow;
				/*
				var chkOutList = document.getElementById("checkOutList");
				var lastOutList=chkOutList.value.substring(0,chkOutList.value.indexOf(","));
				if(lastOutList!=""){
					iteration=lastOutList;
					chkOutList.value=chkOutList.value.replace(lastOutList+",","");
				}*/

				var row = tbl.insertRow(lastRow);

				// cell 1
				var cell1 = row.insertCell(0);
				cell1.className = "center seq";

				//  cell 2
				var cell2 = row.insertCell(1);
				cell2.className = "center";
				var checkNode = document.createElement("input");
				checkNode.name="__checkbox";
				checkNode.type="checkbox";
				checkNode.value=data[0];
				checkNode.id="c_"+data[0];
				cell2.appendChild(checkNode);

				// cell 3
				var cell3 = row.insertCell(2);
				cell3.className = "buid";
				var textNode = document.createTextNode( data[0] );
				cell3.appendChild(textNode);

				//  cell4
				var cell4 = row.insertCell(3);
				var textNode = document.createTextNode( data[2] );
				cell4.appendChild(textNode);

				//  cell5
				var cell5 = row.insertCell(4);
				var textNode = document.createTextNode( data[3] );
				cell5.appendChild(textNode);

				countseq();
			}

			function countseq(){
				var i = 0;
				$(".seq").each(function(){
					i++;
					$(this).text(i);
				});
			}

			function delChild(){
				removeRowFromTable()
				countseq();
			}

			function removeRowFromTable() {
				var tbl = document.getElementById("tblMulti");
				for( loop=1; loop<tbl.rows.length; loop++ ){
					chk =tbl.rows[loop].getElementsByTagName("INPUT")[0];
					if(chk!=null && chk.checked){
						tbl.deleteRow(loop);
						loop--;
					}
				} //for
			}

			function setSubData(){
				with(document.cscform){
					var helpname = "MBU2HELP"
					__apsgroup.value = "MBU2";

					var subdata = "";
					var tmp = "";
					var tbl = document.getElementById("tblMulti");
					for( loop=1; loop<tbl.rows.length; loop++ ){
						chk =tbl.rows[loop].getElementsByTagName("INPUT")[0];
						if( chk!=null ){
							tmp += chk.value +",";
						}
					} //for
					subdata = tmp.substring(0, tmp.length-1)
					subdata =subdata.replace(/,/g, ",");
					__subdata.value = subdata;
					__checkList.value = tmp;
				}
			}

			function GoSave(){
				//var count = $(".buid").length;
				//console.log("ALL BU == "+count);
				setSubData();
				confirmSave();
			}
			function GoDelete(){
				edelete();
			}
			function GoSearch(){
				search();
			}

		</script>
	</head>

	<body leftmargin="0" topmargin="0" onLoad="MM_preloadImages('../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif')"  >
		<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
		<script language="javascript">initToolTips();</script>
		<form name="cscform" method="post" action="?">
			<!----------BEGIN CSC INITIAL ZONE ------------------------>
			<%=screen.InitialVariable()%>
			<!----------END CSC INITIAL ZONE -------------------------->
			<input name="__cmd" type="hidden" value=""/>
			<input name="__screen" type="hidden" value="APS360_CONFIG"/>
			<input name="__calendar" type="hidden"/>
			<input name="__notNull" type="hidden" value=""/>
			<input name="__help" type="hidden" value=""/>

			<script language="javascript">getInputFormatDate();</script>
			<input name="__language" type="hidden" value="<%=screen.getUProfile().get("lang")%>"/>
			<input name="__companyid" type="hidden" value='<%=screen.getUProfile().get("companyid")%>'/>
			<input name="__ack" type="hidden" value=""/>
			<input name="__fixCon" type="hidden" value=""/>
			<input type="hidden" name="__checkList" value="<%=screen.getRecord().getString("subdata").replaceAll("'", "") %>">
			<input type="hidden" name="__apsgroup" value="<%=chk.chkNullString(request.getParameter("__apsgroup"))%>">
			<input type="hidden" name="__subdata" value ="<%=chk.chkNullString(request.getParameter("__cmd")).equals("")?chk.chkNullString(inq1.getString("subdata")) : chk.chkNullString(request.getParameter("__subdata"))%>">
			<script language="javascript">initToolTips();</script>
			<script language="javascript">
			var swap = new swaplang();
			document.write(Icons("APS360_CONFIG, กำหนดสายการประเมิน 360 องศา"));
			</script>

			<br/>
			<div align="center">
				<table cellpadding="0"  cellspacing="0" class="largest">
					<tr>
						<td class="header">M360_CONFIG, กำหนดสายการประเมิน 360 องศา</td>
					</tr>
					<tr>
						<td>
							<br/>
							<table border="1" cellpadding="0" cellspacing="0" class="largest" align="center">
								<tr>
									<td>
										<table cellspacing="0" cellpadding="0" class="inframe">
											<tr>
												<td></td>
												<td></td>
											</tr>
											<%
											  DbRecord mbu2= new InitialRecord(screen.getUProfile()).getDbRecord("mbu2");
											%>
											<tr>
												<td class="columnlabel"><%=mbu2.getDescription()%>&nbsp;</td>
												<td>
													<input type="Text" name="__bu2" size="10" maxlength="10" value="<%=bu2%>" onkeypress="chkSpecialKey(event);" onkeyup="sysIsEdit();" onblur="trimValue(this);" onfocus="this.select();" alt="สายงาน" onmousemver="toolTip('สายงาน')" onmouseout="toolTip()">&nbsp;
														<a href="javascript:goHelp('MBU2HELP','__bu2');" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__bu2_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__bu2_image" width="20" height="20" border="0" align="absmiddle"></a>
													<input name="__bu2desc" type="text" readonly size="80" value="<%=bu2desc%>">
												</td>
											</tr>
											<tr>
												<td>&nbsp;</td>
												<td>&nbsp;</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
							<br/>
							<table border="1" cellpadding="0" cellspacing="0" align="center" class="largest">
								<tr>
									<td>
										<table cellpadding="0" cellspacing="0" class="inframe" >
											<tr>
												<td>
													<table border="0" cellpadding="0" cellspacing="1" bordercolor="#3366CC" cols=9 bgcolor="#666666" class="inframe tablewithborder" id="tblMulti" name="rsTable">
														<tr bgcolor="#3366CC">
															<td class="row3" align="center"><span swlang code='SW000193'>seq</span></td>
															<td class="row3" align="center"><span swlang code='SW000015'>Select</span></td>
															<td class="row3" align="center"><span swlang code='SW000011'>Code</span></td>
															<td class="row3" align="center"><span swlang code='SW011717'>Description(Thai)</span></td>
															<td class="row3" align="center"><span swlang code='SW011718'>Description(Eng)</span></td>
														</tr>
														<%
															if(inq1.recCount()>0){
																String data = chk.chkNullString(request.getParameter("__cmd")).equals("")?chk.chkNullString(inq1.getString("subdata")) : chk.chkNullString(request.getParameter("__subdata"));
																if(data.equals("")){
																	data = "";
																}
																// out.print("data ="+data+"</br>");
																if( !data.equals("")){
																	String[] arrA = data.split(",");
																	for(int i = 0; i<arrA.length; i++){
																		String buid = arrA[i];
																		DbInquiry inq = new InitialInquiry(screen.getUProfile()).getDbInquiry("MBU2");

																		inq.setColumn("*");
																		inq.setFilter("bu2id = '"+buid+"'");
																		inq.refresh();
																		inq.next();
														%>

														<tr>
															<td class="center seq" ></td>
															<td align="center"><input type="checkbox" name="__checkbox" id="c_<%=buid%>" value="<%=buid%>" /></td>
															<td class="buid" ><%=buid%></td>
															<td ><%=inq.getString("tdesc")%></td>
															<td><%=inq.getString("edesc")%></td>
														</tr>
														<%
																	}
																}
															}
														%>
													</table>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr bordercolor="0069B3">
						<td class="blankspace"></td>
					</tr>
					<tr bordercolor="0069B3">
						<td class="blankspace"></td>
					</tr>
					<tr>
						<td  class="buttonline" colspan="7"><div align="center">
							<button type="button" class="btn btn-primary width100" swlang code="SW013163" onClick="checkAll();">Select All</button>&nbsp;
							<button type="button" class="btn btn-primary width100" swlang code="SW013164" onClick="decheckAll();">Deselect All</button>&nbsp;
							<button type="button" class="btn btn-primary width100" swlang code="SW013165" onClick="add();">Add</button>&nbsp;
							<button type="button" class="btn btn-primary width100" swlang code="SW013166" onClick="delChild();">Delete</button>
						</div>
						</td>
					</tr>
					<tr bordercolor="0069B3">
						<td class="blankspace"></td>
					</tr>
					<tr bordercolor="0069B3">
						<td class="blankspace"></td>
					</tr>
					<tr bordercolor="0069B3">
						<td class="bottom"></td>
					</tr>
				</table>
			</div>
			<!----------BEGIN CSC ENDING ZONE ------------------------>
			<%=screen.endJSP()%>
			<!----------END CSC ENDING ZONE -------------------------->
		</form>
	</body>
</html>
