<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*"%>
<%@page import="com.csc.library.entry.*,com.csc.library.database.*,com.csc.library.session.*"  %>
<%@page import="com.csc.library.components.*"  %>
<jsp:useBean id="TRE004_1" class="com.csc.library.system.Task" scope="page"/>
<%
	TRE004_1.setChannel(request,response);
	UIManager screen = (UIManager)TRE004_1.process("MultiEntry","TRE004",true);
	MultiLine multi = screen.getMultiLine("TRESERVER");
	multi.setLabelBox("check box");
	multi.goFirst();

	CheckNull chk = new CheckNull();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<link href ="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<script language='javascript' src="../JS/VIEWCALENDAR.js"></script>
<script type='text/javascript' src='../JS/SCREEN.js'></script>

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

function GoSave(){
	//confirmSave();
    alert("Gosave");
	}
function GoUpdate(){update();}
function GoDelete(){edelete();}
function GoSearch(){search();}

	function childMulti(record){
		with(document.cscform){
	    	window.open(__childMulti.value+".jsp?__cmd=&__gorec="+record+
		     "&__ack=edit&__employeeid="+__employeeid.value+
		     "&__headMulti="+__headMulti.value+
	    	 "&__companyid="+__companyid.value,"","width=600,height=300");
		}
	}

	function addMulti(){
		with(document.cscform){
	    	window.open(__childMulti.value+".jsp?__cmd=&__gorec=&__ack=add"+
		    "&__employeeid="+__employeeid.value+
		    "&__headMulti="+__headMulti.value+
	    	"&__companyid="+__companyid.value,"");
		}
	}

	function deleteMulti(){
		with(document.cscform){
	    	bCon=confirm(MyCode[4]);
	 	  	if (bCon==true)	{
				__cmd.value="DelChild";
				submit();
			}
		}
	}
	function getIt(data){
		with(window.parent.document.cscform){
			if( data.value == "2" ){
				if(	data.id == "1"){
					__total_noapp.value = parseInt(__total_noapp.value) - 1;
				}else if(data.id == ""){
					__byreserv.value =  parseInt(__byreserv.value) - 1;
				}
				data.id = "0";
				__total_approve.value =  parseInt(__total_approve.value) + 1;
				if(parseInt(__total_approve.value) > parseInt(__maxapp.value)){
					if(getLang()=="tha"){
						alert("! จำนวนรวมของผู้ได้รับการอนุมัติ เกินจำนวนผู้อบรมสูงสุด");
					}else{
						alert("! total approve for trainee is morethan maximum trainee in class.");
					}
					data.value = "1"
					getIt(data)
				}
			} else if(data.value == "3") {
				if(data.id == ""){
					__byreserv.value =  parseInt(__byreserv.value) - 1;
				}else if(data.id == "0"){
					__total_approve.value = parseInt(__total_approve.value) - 1;
				}
				data.id = "1";
				__total_noapp.value = parseInt(__total_noapp.value) + 1;
			} else {
				if(data.id == "1"){
					__total_noapp.value = parseInt(__total_noapp.value) - 1;
				}else if(data.id == "0"){
					__total_approve.value =  parseInt(__total_approve.value) - 1;
				}
				data.id = "";
				__byreserv.value = parseInt(__byreserv.value) + 1;
			}
		}
	}
	function setReserveOnload(){
		var tmpresv = 0;
		var tmpapp = 0;
		var tmp_noapp = 0;
		with(document.cscform){
			for(i=0;i<elements.length;i++){
				if(elements[i].type=="select-one"&&elements[i].value=="1"){
					++ tmpresv;
					elements[i].id = "";
				}else if(elements[i].type=="select-one"&&elements[i].value=="2"){
					++ tmpapp;
					elements[i].id = "0";
				}else if(elements[i].type=="select-one"&&elements[i].value=="3"){
					++ tmp_noapp;
					elements[i].id = "1";
				}
			}
		}
		with(window.parent.document.cscform){
			__byreserv.value = tmpresv;
			__total_approve.value = parseInt(__app_byHr.value) + parseInt(__app_byPlan.value) + parseInt(tmpapp);
			__total_noapp.value = tmp_noapp;
		}
	}
</script>
</head>

<body  leftmargin="0" topmargin="0"  onLoad="" ><div class="centered">
<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
<script language="javascript">initToolTips();</script>

<form name="cscform" method="post" action="TRE004_1.jsp">

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

<%=screen.InitialVariable()%>

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

	<input name="__cmd" type="hidden" value="">
	<input type="hidden" name="__calendar">
	<script language="javascript">getInputFormatDate();</script>
  	<input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>">
	<input type="hidden" name="__screen" value="TRE004">
	<input type="hidden" name="__multiTable" value="TRESERVER">
	<input type="hidden" name="__childMulti" value="TRE004_1">
	<input type="hidden" name="__gorec" value="">
	<input type="hidden" name="__trainingid" value="<%=screen.getDataLabel("TRAININGID")%>">
	<input type="hidden" name="__headMulti" value="TRE004">
	<input type="hidden" name="__companyid" value="<%=screen.getUProfile().get("companyid")%>">
	<input type="hidden" name="__fixCon" value="">

  <div align="center">
  <script language="JavaScript" src="../JS/HOTKEY.js"></script>
		<table  border="0" cellpadding="0" cellspacing="1" id="rsTable" name="rsTable"  bgcolor="#333333" class="maxsize" cols="9">
				<tr>
					<td nowrap width="5%" class="row3"><div align="center"><a href="javascript:sortTable(0, rsTable);"><script language='javascript'>swapLang('No');</script></a></div></td>
					<td nowrap width="10%" class="row3"><div align="center"><a href="javascript:sortTable(1, rsTable);"><script language='javascript'>swapLang('Status');</script></a></div></td>
					<td nowrap width="10%" class="row3"><div align="center"><a href="javascript:sortTable(2, rsTable);"><%=multi.getLabel("TRESERVER","RESERVERID")%></a></div></td>
					<td nowrap width="20%" class="row3"><div align="center"><a href="javascript:sortTable(3, rsTable);"><script language='javascript'>swapLang('Name Surname');</script></a></div></td>
					<td nowrap width="15%" class="row3"><div align="center"><a href="javascript:sortTable(4, rsTable);"><%=multi.getLabel("TRESERVER","EMP_POSITION")%></a></div></td>
					<td nowrap width="15%" class="row3"><div align="center"><a href="javascript:sortTable(5, rsTable);"><script language='javascript'>swapLang('BU 1');</script></a></div></td>
					<td nowrap width="15%" class="row3"><div align="center"><a href="javascript:sortTable(6, rsTable);"><script language='javascript'>swapLang('BU 2');</script></a></div></td>
					<td nowrap width="10%" class="row3"><div align="center"><a href="javascript:sortTable(7, rsTable);"><%=multi.getLabel("TRESERVER","RESDATE")%></a></div></td>
					<td nowrap width="5%" class="row3"><div align="center"><script language='javascript'>swapLang('Send Mail');</script></a></div></td>
				</tr>
                 <%
					multi.goFirst();
					ListBox listbox = new ListBox();
					listbox.setUProfile(screen.getUProfile());
					listbox.setonChange("getIt(this);");
					listbox.setValidCode(multi.getTable().getCurrentRecordManager().getField("status").getValidCode());
					//listbox.setChecked("");
				 	for(int i=1;!multi.eof();multi.next(),i++){
					listbox.setName("treserver$status$"+multi.getDataLabel("reserverid"));

					listbox.setChecked(chk.chkNullString(request.getParameter("__treserver$status$"+multi.getDataLabel("reserverid")),multi.getDataLabel("status")));
				 %>
				<tr>
					<td class="inframe" ><div align="center"><%=i%></div></td>
					<td class="inframe" ><div align="center"><%=listbox.process()%><input type="hidden" name="__selectstatus<%=i%>" value="<%=chk.chkNullString(request.getParameter("__treserver$status$"+multi.getDataLabel("reserverid")),multi.getDataLabel("status"))%>"></div></td>
					<td class="inframe" ><div align="center"><%=multi.getDataLabel("TRESERVER","RESERVERID")%></div></td>
					<td class="inframe" ><div align="left">&nbsp;<%=multi.getDataLabel("MEMPLOYEE","FULLNAME")%><input type="hidden" name="__empid<%=i%>" value="<%=multi.getDataLabel("reserverid")%>"></div></td>
					<td class="inframe" ><div align="left">&nbsp;<%=multi.getDataLabel("MPOSITION","TDESC")%></div></td>
					<td class="inframe" ><div align="left">&nbsp;<%=multi.getDataLabel("MBU1","TDESC")%></div></td>
					<td class="inframe" ><div align="left">&nbsp;<%=multi.getDataLabel("MBU2","TDESC")%></div></td>
					<td class="inframe" ><div align="center"><%=multi.getDataLabel("TRESERVER","RESDATE")%></div></td>
					<td class="inframe" ><div align="center"><input type="checkbox" name="listmail" id="<%=multi.getDataLabel("MEMPLOYEE","EMPLOYEEID")%>" value="<%=multi.getDataLabel("MEMPLOYEE","EMAIL")%>" <%=(multi.getDataLabel("MEMPLOYEE","EMAIL").equals(""))?"disabled":""%>></div></td>
                </tr>
                <%}%>
		</table>
	<script language='javascript'>setReserveOnload();</script>
</div>

<!----------BEGIN CSC ENDING ZONE ------------------------>

<input type="hidden" name="__systemstatus" value="">
<input type="hidden" name="__shortmessage" value="">
<script language="JavaScript">showMess();</script>
<input type="hidden" name="__actioned" value="">
<input type="hidden" name="__confirm" value="<%=request.getParameter("__confirm")%>">
<%
if("ack".equals(request.getParameter("__cmd"))){
%>
<script language="javascript">
	with(window.parent.document.cscform){
	   if(__confirm.value=="0" ||__confirm.value=="1" || __confirm.value=="2"){
			__cmd.value = "save";
		setInterval(submit(),3000);
		}


		//confirmSave();
		//confirmSaveIframe();
	}
</script>
<%
}
%>
<!----------END CSC ENDING ZONE -------------------------->
</form>
<%
screen.referLangOff();
%>
</body>
</html>