<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.*,com.csc.library.system.*,com.csc.library.utilities.*,com.csc.library.session.*,com.csc.library.database.*,com.csc.library.components.*,java.util.*"%>
<jsp:useBean id="REM003" class="com.csc.library.system.Task" scope="page" />
<jsp:useBean id="REMINDER_PERIOD_PRO" class="com.csc.library.system.Task" scope="page" />
<%
REM003.setChannel(request ,response);
ProcessEntry screen=(ProcessEntry)REM003.process("ProcessEntry","Process");
screen.process();

CheckNull chk = new CheckNull();
String lang = screen.getUProfile().get("lang");
String screenname = screen.getUProfile().get("lang").equalsIgnoreCase("tha")?"ระยะเวลาการแจ้งเตือนการพ้นทดลองงาน":"Notifications of Probation Period";
String tname = "สร้าง ระยะเวลาการแจ้งเตือนการพ้นทดลองงาน";
String ename = "Generate Notifications of Parobation Period";
String cmd = chk.chkNullString(request.getParameter("__cmd"));

REMINDER_PERIOD_PRO.setChannel(request, response);
HelpEntry reminder_period_pro = (HelpEntry) REMINDER_PERIOD_PRO.process("HelpEntry","MREMINDER_PERIOD_PROHELP");

if(cmd.equalsIgnoreCase("save")){
	response.setHeader("Refresh", "5;url=REM003.jsp");
}
%>

<html ng-app="myHR">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<link type="text/css" rel="stylesheet" href="../CSS/TISCO.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/jquery-2.1.3.min.js"></script>
		<script type='text/javascript' src="../JS/bootstrap.js"></script>
		<script language="JavaScript" src="../JS/SCREEN.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 src="../JS/jquery-1.11.2.js" type="text/javascript"></script>
		<script src="../JS/jquery-ui-1.11.4.js" type="text/javascript"></script>
		<script type='text/javascript' src='/hr/dwr/interface/SearchDWR.js'></script>
		<script type='text/javascript' src='/hr/dwr/engine.js'></script>
		<script language="javascript">setLang("<%=screen.getUProfile().get("lang")%>");</script>
		<script language="javascript">getTitleName();</script>
		<style>

		.onclickplus { cursor: pointer; }

		</style>
		<script language="javascript">

		function process() {
			with(document.cscform){
				bCon=confirm(getLang() === "tha"?'<%=tname%>':'<%=ename%>');
				if (bCon==true)	{
					setBeforeProcess();
					__cmd.value = "save";
					submit();
				}
			}
		}

		function setBeforeProcess(){
			with(document.cscform){
				var indexdata = "";
				$('.selected').each(function(index){
					if(indexdata.length > 0){
						indexdata += "," + $(this).val();
					} else {
						indexdata += $(this).val();
					}
				});
				__condition$reminderdata.value = indexdata;

				$('.timeset').each(function(index){
					if($(this).val() === "0.00"){
						$(this).val("8.00");
					}
				});
			}
		}

		function goHelp(helpName,inputName){
			var fixCon;
			var helpReturn;
			if(inputName.indexOf("__condition$reminder_sending") != -1){
				helpReturn=inputName+":reminderid";
				linkHelp_Return(helpName,helpReturn);
			}else if(inputName.indexOf("__condition$reminder_return") != -1){
				helpReturn=inputName+":reminderid";
				linkHelp_Return(helpName,helpReturn);
			}
		}

		function checkNumInt(obj,min,max){
			if (obj.value != "") {
				obj.value = parseFloat(obj.value)+""; // แปลงจาก 01234 เป็น 1234
				if (min >= 0 && max > 0) 	{
					callMaxMin(obj,min,max); // ตรวจดูว่าค่าที่กรอกเกินค่าสูงสุด หรือต่ำกว่าค่าต่ำสุดหรือไม่
				}
				insertComma(obj); //123456 ==> 123,456
			} else {
				obj.value = 0;
			}
		}

		$(function() {
			$('#imgadd').on('click',function(){ addRow(); });
			$('#imgdelete').on('click',function(){ delRow(); });
			$('#imgprocess').on('click',function(){ process(); });

			var reccount = '<%=reminder_period_pro.inq.recCount()%>';
			if(reccount === "0"){
				addRow();
			}

			$('#selectall').on('change',function(){
				if($(this).prop('checked')){
					$('.selected').prop('checked',true);
				} else {
					$('.selected').prop('checked',false);
				}
			});

			$('.dataindex').on('change','.selected',function(){
				var chk = true;
				$('.dataindex .selected').each(function(index){
					if(!$(this).prop('checked')){
						chk = false;
					}
				});
				$('#selectall').prop('checked',chk);
			});

			function addRow(){
				$('#selectall').prop('checked',false);
				sysIsEdit();
				var line = parseInt( $('#line').val() );
				if($(".dataindex").last().index() === -1){
					line = 0;
				}
				line++;
				$('#line').val(line);
				$('#maintable')
				.append($('<tr>').attr('class','dataindex')
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','checkbox')
					.attr('class','selected')
					.attr('value',line) )
				)
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','text')
					.attr('name','__condition$day_period'+line)
					.attr('size','4')
					.attr('maxlength','4')
					.attr('value','0')
					.attr('class','numeric')
					.attr('onkeypress','chkInteger(event);')
					.attr('onkeyup','sysIsEdit();')
					.attr('onblur','checkNumInt(this,0,900000000);')
					.attr('onfocus','callDelComma(this);')
					.attr('alt','<%=reminder_period_pro.getLabel("DAY_PERIOD")%>')
					.attr('onmousemver',"toolTip('<%=reminder_period_pro.getLabel("DAY_PERIOD")%>')")
					.attr('onmouseout',"toolTip()") )
				)
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','text')
					.attr('name','__condition$day_sending'+line)
					.attr('size','4')
					.attr('maxlength','4')
					.attr('value','0')
					.attr('class','numeric')
					.attr('onkeypress','chkInteger(event);')
					.attr('onkeyup','sysIsEdit();')
					.attr('onblur','checkNumInt(this,0,900000000);')
					.attr('onfocus','callDelComma(this);')
					.attr('alt','<%=reminder_period_pro.getLabel("DAY_SENDING")%>')
					.attr('onmousemver',"toolTip('<%=reminder_period_pro.getLabel("DAY_SENDING")%>')")
					.attr('onmouseout',"toolTip()") )
				)
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','text')
					.attr('name','__condition$reminder_sending'+line)
					.attr('size','10')
					.attr('maxlength','10')
					.attr('value','')
					.attr('onkeypress','chkSpecialStr(event);')
					.attr('onkeyup','sysIsEdit();')
					.attr('onblur','trimValue(this);')
					.attr('onfocus','this.select();')
					.attr('alt','<%=reminder_period_pro.getLabel("REMINDER_SENDING")%>')
					.attr('onmousemver',"toolTip('<%=reminder_period_pro.getLabel("REMINDER_SENDING")%>')")
					.attr('onmouseout',"toolTip()")
					,"&nbsp;"
					,$('<a>')
					.attr('href',"javascript:goHelp('MREMINDERHELP','__condition$reminder_sending"+line+"');")
					.attr('onmousemver',"MM_swapImage('__reminder_sending_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)")
					.attr('onmouseout',"MM_swapImgRestore()")
					.append(
						$('<img>')
						.attr('src',"../IMAGES/BUTTON/MAIN/SEARCH20.gif")
						.attr('alt',"SEARCH")
						.attr('name',"__reminder_sending_image")
						.attr('width',"20")
						.attr('height',"20")
						.attr('border',"0")
						.attr('align',"absmiddle")
					) )
				)
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','text')
					.attr('name','__condition$time_sending'+line)
					.attr('size','4')
					.attr('maxlength','5')
					.attr('value','0.00')
					.attr('class','numeric timeset')
					.attr('onkeypress','chkInteger(event);')
					.attr('onkeyup','sysIsEdit();')
					.attr('onblur','chkTime(this);')
					.attr('onfocus','this.select();')
					.attr('alt','<%=reminder_period_pro.getLabel("TIME_SENDING")%>')
					.attr('onmousemver',"toolTip('<%=reminder_period_pro.getLabel("TIME_SENDING")%>')")
					.attr('onmouseout',"toolTip()") )
				)
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','text')
					.attr('name','__condition$day_return'+line)
					.attr('size','4')
					.attr('maxlength','4')
					.attr('value','0')
					.attr('class','numeric')
					.attr('onkeypress','chkInteger(event);')
					.attr('onkeyup','sysIsEdit();')
					.attr('onblur','checkNumInt(this,0,900000000);')
					.attr('onfocus','callDelComma(this);')
					.attr('alt','<%=reminder_period_pro.getLabel("DAY_RETURN")%>')
					.attr('onmousemver',"toolTip('<%=reminder_period_pro.getLabel("DAY_RETURN")%>')")
					.attr('onmouseout',"toolTip()") )
				)
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','text')
					.attr('name','__condition$reminder_return'+line)
					.attr('size','10')
					.attr('maxlength','10')
					.attr('value','')
					.attr('onkeypress','chkSpecialStr(event);')
					.attr('onkeyup','sysIsEdit();')
					.attr('onblur','trimValue(this);')
					.attr('onfocus','this.select();')
					.attr('alt','<%=reminder_period_pro.getLabel("REMINDER_RETURN")%>')
					.attr('onmousemver',"toolTip('<%=reminder_period_pro.getLabel("REMINDER_RETURN")%>')")
					.attr('onmouseout',"toolTip()")
					,"&nbsp;"
					,$('<a>')
					.attr('href',"javascript:goHelp('MREMINDERHELP','__condition$reminder_return"+line+"');")
					.attr('onmousemver',"MM_swapImage('__reminder_return_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)")
					.attr('onmouseout',"MM_swapImgRestore()")
					.append(
						$('<img>')
						.attr('src',"../IMAGES/BUTTON/MAIN/SEARCH20.gif")
						.attr('alt',"SEARCH")
						.attr('name',"__reminder_return_image")
						.attr('width',"20")
						.attr('height',"20")
						.attr('border',"0")
						.attr('align',"absmiddle")
					) )
				)
				.append( $('<td>').attr('align','center')
				.append(
					$('<input>')
					.attr('type','text')
					.attr('name','__condition$time_return'+line)
					.attr('size','4')
					.attr('maxlength','5')
					.attr('value','0.00')
					.attr('class','numeric timeset')
					.attr('onkeypress','chkInteger(event);')
					.attr('onkeyup','sysIsEdit();')
					.attr('onblur','chkTime(this);')
					.attr('onfocus','this.select();')
					.attr('alt','<%=reminder_period_pro.getLabel("TIME_RETURN")%>')
					.attr('onmousemver',"toolTip('<%=reminder_period_pro.getLabel("TIME_RETURN")%>')")
					.attr('onmouseout',"toolTip()") )
				) );
			}

			function delRow(){
				var numindex = "";
				$(".selected").each(function(index){
					if($(this).prop("checked")){
						if(numindex.length > 0){
							numindex += "," + index;
						} else {
							numindex += index;
						}
					}
				});

				var arrindex = numindex.split(",");
				for(var i=arrindex.length-1; i>=0; i--){
					var element_index = ":eq("+arrindex[i]+")";
					$(".dataindex"+element_index).remove();
				};

				if($(".dataindex").last().index() === -1){
					addRow();
				}
				$('#selectall').prop('checked',false);
				sysIsEdit();
			}
		});

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

			<form name="cscform" method="post" action="REM003.jsp">
				<input type="hidden" name="__cmd" value=""/>
				<input type="hidden" name="__screen" value="REM003"/>
				<input type="hidden" name="__help" value=""/>
				<input type="hidden" name="__companyid" value="<%=screen.getUProfile().get("companyid")%>"/>
				<input type="hidden" name="__notNull" value=""/>
				<input type="hidden" name="__fixCon" value=""/>
				<input type="hidden" name="__referPage" value=""/>
				<input type="hidden" name="__process" value=""/>
				<input type="hidden" name="__tname" value="<%=tname%>"/>
				<input type="hidden" name="__ename" value="<%=ename%>"/>
				<input type="hidden" name="__ptype" value=""/>
				<input type="hidden" name="__chkhelp" value=""/>
				<input type="hidden" name="__prclass" value="GenerateReminderQueueAuto"/>
				<input type="hidden" name="__condition$reminderdata" value=""/>
				<input type="hidden" name="__condition$reminderfield" value="day_period,day_sending,reminder_sending,time_sending,time_sending,day_return,reminder_return,time_return"/>
				<input type="hidden" name="__ele" value=""/>
				<%=screen.getTagConfirm()%>
				<br/>
				<table border="0" cellpadding="0" cellspacing="0" class="maxsize">
					<tr>
						<td class="header" colspan="2" >REM003, <%=screenname%>&nbsp;</td>
					</tr>
					<tr>
						<td>
							<table border="0" cellpadding="0" cellspacing="0" class="inframe">
								<tr>
									<td class="blankspace"></td>
								</tr>
								<%
								if(cmd.equalsIgnoreCase("save")){
									%>
									<tr>
										<td colspan="2" align="center">Processing...<br><br><img src="../IMAGES/loading2.gif" id="loading"></td>
									</tr>
									<%
								} else {
									%>
									<tr>
										<td>
											<table class="tablewithborder" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" style="width:70%" align="center" id="maintable">
												<tr>
													<td class="row1" align="center" rowspan="2"><input type="checkbox" id="selectall"></td>
													<td class="row1" align="center" rowspan="2"><%=reminder_period_pro.getLabel("DAY_PERIOD")%></td>
													<td class="row1" align="center" colspan="3"><span swlang code="SW013185">Sending</span></td>
													<td class="row1" align="center" colspan="3"><span swlang code="SW013186">Return</span></td>
												</tr>
												<tr>
													<td class="row1" align="center"><%=reminder_period_pro.getLabel("DAY_SENDING")%></td>
													<td class="row1" align="center"><%=reminder_period_pro.getLabel("REMINDER_SENDING")%></td>
													<td class="row1" align="center"><%=reminder_period_pro.getLabel("TIME_SENDING")%></td>
													<td class="row1" align="center"><%=reminder_period_pro.getLabel("DAY_RETURN")%></td>
													<td class="row1" align="center"><%=reminder_period_pro.getLabel("REMINDER_RETURN")%></td>
													<td class="row1" align="center"><%=reminder_period_pro.getLabel("TIME_RETURN")%></td>
												</tr>
												<%
												int line = 0;
												reminder_period_pro.process();
												while(reminder_period_pro.nextRec()){
													line++;
													%>
													<tr class="dataindex">
														<td align="center"><input type="checkbox" class="selected" value="<%=line%>"></td>
														<td align="center">
															<input type="text" name="__condition$day_period<%=line%>" size="4" maxlength="4" value="<%=reminder_period_pro.getString("DAY_PERIOD")%>" class="numeric" onkeypress="chkInteger(event);" onkeyup="sysIsEdit();" onblur="checkNumInt(this,0,900000000);" onfocus="callDelComma(this);" alt="Probation Period (Days)" onmousemver="toolTip('Probation Period (Days)')" onmouseout="toolTip()">
														</td>
														<td align="center">
															<input type="text" name="__condition$day_sending<%=line%>" size="4" maxlength="4" value="<%=reminder_period_pro.getString("DAY_SENDING")%>" class="numeric" onkeypress="chkInteger(event);" onkeyup="sysIsEdit();" onblur="checkNumInt(this,0,900000000);" onfocus="callDelComma(this);" alt="Sending Evaluation (Days)" onmousemver="toolTip('Sending Evaluation (Days)')" onmouseout="toolTip()">
														</td>
														<td align="center">
															<input type="text" name="__condition$reminder_sending<%=line%>" size="10" maxlength="10" value="<%=reminder_period_pro.getString("REMINDER_SENDING")%>" onkeypress="chkSpecialStr(event);" onkeyup="sysIsEdit();" onblur="trimValue(this);" onfocus="this.select();" alt="Reminder ID" onmousemver="toolTip('Reminder ID')" onmouseout="toolTip()">
															<a href="javascript:goHelp('MREMINDERHELP','__condition$reminder_sending<%=line%>');" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__reminder_sending_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__reminder_sending_image" width="20" height="20" border="0" align="absmiddle"></a>
														</td>
														<td align="center">
															<input type="text" name="__condition$time_sending<%=line%>" size="4" maxlength="5" value="<%=reminder_period_pro.getString("TIME_SENDING")%>" class="numeric timeset" onkeypress="chkInteger(event);" onkeyup="sysIsEdit();" onblur="chkTime(this);" onfocus="this.select();" alt="Time for Sending [HHMM]" onmousemver="toolTip('Time for Sending [HHMM]')" onmouseout="toolTip()">
														</td>
														<td align="center">
															<input type="text" name="__condition$day_return<%=line%>" size="4" maxlength="4" value="<%=reminder_period_pro.getString("DAY_RETURN")%>" class="numeric" onkeypress="chkInteger(event);" onkeyup="sysIsEdit();" onblur="checkNumInt(this,0,900000000);" onfocus="callDelComma(this);" alt="Return Evaluation (Days)" onmousemver="toolTip('Return Evaluation (Days)')" onmouseout="toolTip()">
														</td>
														<td align="center">
															<input type="text" name="__condition$reminder_return<%=line%>" size="10" maxlength="10" value="<%=reminder_period_pro.getString("REMINDER_RETURN")%>" onkeypress="chkSpecialStr(event);" onkeyup="sysIsEdit();" onblur="trimValue(this);" onfocus="this.select();" alt="Reminder ID" onmousemver="toolTip('Reminder ID')" onmouseout="toolTip()">
															<a href="javascript:goHelp('MREMINDERHELP','__condition$reminder_return<%=line%>');" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('__reminder_return_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="__reminder_return_image" width="20" height="20" border="0" align="absmiddle"></a>
														</td>
														<td align="center">
															<input type="text" name="__condition$time_return<%=line%>" size="4" maxlength="5" value="<%=reminder_period_pro.getString("TIME_RETURN")%>" class="numeric timeset" onkeypress="chkInteger(event);" onkeyup="sysIsEdit();" onblur="chkTime(this);" onfocus="this.select();" alt="Time for Return [HHMM]" onmousemver="toolTip('Time for Return [HHMM]')" onmouseout="toolTip()">
														</td>
													</tr>
													<%
												}
												%>
											</table>
											<input type="hidden" name="__condition$line" id="line" value="<%=line%>"/>
										</td>
									</tr>
									<tr>
										<td class="blankspace"></td>
									</tr>
									<tr>
										<td  class="buttonline" colspan="7">
											<div align="center">
												<button type="button" class="btn btn-primary width100" class="onclickplus" id="imgadd" swlang code="SW013165" >ADD</button>&nbsp;
												<button type="button" class="btn btn-primary width100" class="onclickplus" id="imgdelete" swlang code="SW000123">DELETE</button>&nbsp;
												<button type="button" class="btn btn-primary width100"  class="onclickplus" id="imgprocess" swlang code="SW013173" >PROCESS</button>
											</div>
										</td>
									</tr>
									<%
								}
								%>
								<tr>
									<td class="blankspace"></td>
								</tr>
							</table>
						</td>
					</tr>
					<tr >
						<td class="bottom" >
						</td>
					</tr>
				</table>
				<script language="JavaScript">checkConfirm();</script>
			</form>
		</div>
	</body>
</html>