<%@ page import="com.csc.library.entry.*"  contentType="text/html;charset=UTF-8"%>
<jsp:useBean id="REC410HELP" scope="page" class="com.csc.library.system.Task"/>
<%
		REC410HELP.setChannel(request ,response);
		HelpEntry screen=(HelpEntry) REC410HELP.process("HelpEntry","REC410HELP");
		screen.process();
		screen.nextRec();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css">
<script type='text/javascript' src='../JS/SCREEN.js'></script>
<script type='text/javascript' src='../JS/RECSCREEN.js'></script>
<script language='javascript' src='../JS/HOTKEY.js'></script>
<script language='javascript' src='../JS/EMPLOYEE.js'></script>
<script language="javascript">setLang('<%=screen.getUProfile().get("lang")%>');</script>
<script language="javascript">getTitleName();</script>
<script type='text/javascript' src='../JS/ICONSMENU.js'></script>
<script src="../JS/VIEWCALENDAR.js"></script>
<script type='text/javascript' src='/hr/dwr/interface/SearchDWR.js'></script>
<script type='text/javascript' src='/hr/dwr/engine.js'></script>
<script type='text/javascript' src='/hr/dwr/util.js'></script>
<script type="text/javascript" src="/hr/dwr/interface/SystemCode.js"></script>
<script type="text/javascript" src="/hr/dwr/interface/CscCalendar.js"></script>
<script language="JavaScript">

function chkType(){
	chkId();
	with(document.cscform){	
		var message="";
		if(appType.selectedIndex==0){
			if(document.cscform.peopleid.value.length<13){
				if(getLang()=="tha"){
					message="หมายเลขบัตรประชาชนน้อยกว่า 13 หลัก, ดำเนินการต่อหรือไม่?";
				}else{
					message="Your Citizen ID less than 13 digit, Proceed?";
				}
				con=confirm(message);
				if(con)				
					searchApp(peopleid.value);
				else				
					document.cscform.peopleid.focus();
			}
			else 
				searchApp(peopleid.value);
		}
		else 
			searchEmp(peopleid.value);
	}	
}

function searchApp(appid){
	SearchDWR.searchAll(new Array("Mapplicant","applicantid,applydate,applicantstatus","id_people='"+appid+"'",""), {

	  callback:function(data) {
		dwr.util.removeAllRows('appList');		  
		if(data.length>0&&data[0][2]=="0")	{
			document.getElementById("mytable").style.display = "";	
			var cellFuncs = [
				function(data1) { return "<a href=\"javascript:goPages('"+data1[0]+"');\">"+data1[0]+"</a>"; },
				function(data1) { return data1[1]; },
				function(data1) { return "กำลังพิจารณา"; },
				function(data1) { return ""; },
				function(data1) { return ""; },
				function(data1) { return ""; },
				function(data1) { return ""; },
				function(data1) { return ""; },
				function(data1) { return ""; }
				];
				dwr.util.addRows( "appList",data, cellFuncs, {
				  escapeHtml:false,	
				  cellCreator:function(options) {
				    var td = document.createElement("td");
				    td.align="center";
				    return td;
				  }
				});
			}
		else if(data.length>0&&data[0][2]!="0")	{		
			SearchDWR.searchDBXMLAll(new Array("REC410HELP","mappointment.applicantid,mapplicant.applydate,mcandidatere.candidatestatus|desc,mappointment.interviewdate,mappointment.interviewtime,mappointment.interviewroom,mappointment.interviewplace,mappointment.comments",
			"MAPPOINTMENT:applicantid='"+data[0][0]+"'",
			"false","langon"), {
		
			  callback:function(data2) {	
				dwr.util.removeAllRows('appList');			  
				document.getElementById("mytable").style.display = "";
				var status = statusDesc(data[0][2]);
				if(data2.length>0)	{
					var i =1;
					var cellFuncs = [
						function(data1) { return "<a href=\"javascript:goPages('"+data1[0]+"');\">"+data1[0]+"</a>"; },
						function(data1) { return data1[1]; },
						function(data1) { return status; },
						function(data1) { return i++; },
						function(data1) { return data1[3]; },
						function(data1) { return data1[4]; },
						function(data1) { return data1[5]; },
						function(data1) { return data1[6]; },
						function(data1) { return data1[7]; },
						function(data1) { return data1[8]; }
						];
						dwr.util.addRows( "appList",data2, cellFuncs, {
						  escapeHtml:false,	
						  cellCreator:function(options) {
							var td = document.createElement("td");
							td.align="center";
							return td;
						  }
						});
					}
					else {
						var cellFuncs = [
						function(data1) { return "<a href=\"javascript:goPages('"+data1[0]+"');\">"+data1[0]+"</a>"; },
						function(data1) { return data1[1]; },
						function(data1) { return "กำลังพิจารณา"; },
						function(data1) { return ""; },
						function(data1) { return ""; },
						function(data1) { return ""; },
						function(data1) { return ""; },
						function(data1) { return ""; },
						function(data1) { return ""; }
						];
						dwr.util.addRows( "appList",data, cellFuncs, {
						  escapeHtml:false,	
						  cellCreator:function(options) {
							var td = document.createElement("td");
							td.align="center";
							return td;
						  }
						});					
					}
			}	
			});
		}			
		else{		
			document.getElementById("mytable").style.display = "none";	
			dwr.util.removeAllRows('appList');	
			//alert(swap2String("No Data Found!!"));
			bCon=confirm(swap2String("Fill new application?"));
			if (bCon==true)	{
				with(document.cscform){
					__id_people.value=appid;
					action = "REC610.jsp";
					submit();		
				}		
			}	
		}
	}	
	});
}

function searchEmp(appid){
	SearchDWR.searchAll(new Array("Workflow_data","initiator,screen_value,wf_status","initiator='"+appid+"' and wf_id='5002' and wf_status!='D' ",""), {
	  callback:function(data) {
		dwr.util.removeAllRows('appList');		  
		if(data.length>0)	{
			document.getElementById("mytable").style.display = "";	
			SearchDWR.searchAll(new Array("Mapplicant","applicantid,applydate,applicantstatus,employeeid","employeeid='"+appid+"'",""), {
			  callback:function(datax) {
			  	if(datax.length>0){
					SearchDWR.searchDBXMLAll(new Array("REC410HELP","mappointment.applicantid,mapplicant.applydate,mcandidatere.candidatestatus|desc,mappointment.interviewdate,mappointment.interviewtime,mappointment.interviewroom,mappointment.interviewplace,mappointment.comments",
					"MAPPOINTMENT:applicantid='"+datax[0][0]+"'",
					"false","langon"), {					
						callback:function(data2) {
							dwr.util.removeAllRows('appList');			  
							document.getElementById("mytable").style.display = "";
							if(data2.length>0)	{
								var status = statusDesc(data[0][2]);
								var i =1;
								var cellFuncs = [
								function(data1) { return data1[0]; },
								function(data1) { return data1[1]; },
								function(data1) { return status; },
								function(data1) { return i++; },
								function(data1) { return data1[3]; },
								function(data1) { return data1[4]; },
								function(data1) { return data1[5]; },
								function(data1) { return data1[6]; },
								function(data1) { return data1[7]; },
								function(data1) { return data1[8]; }
								];
								dwr.util.addRows( "appList",data2, cellFuncs, {
				     			  escapeHtml:false,	
									cellCreator:function(options) {
									var td = document.createElement("td");
									td.align="center";
									td.className="nowrap";
									return td;
									}
								});
							}
								else {
									var cellFuncs = [
									function(data1) { return getData("__wf__jobDesc",data1[1]); },
									function(data1) { return "-"; },
									function(data1) { return getTagStatus(data1[2],data1[0],getData("__wf__jobcodeid",data1[1]),getData("__wf__jobDesc",data1[1]),getData("__wf__requestid",data1[1])); },
									function(data1) { return "-"; },
									function(data1) { return "-"; },
									function(data1) { return "-"; },
									function(data1) { return "-"; },
									function(data1) { return "-"; },
									function(data1) { return "-"; }
									];
									dwr.util.addRows( "appList",data, cellFuncs, {
										  escapeHtml:false,	
										cellCreator:function(options) {
											var td = document.createElement("td");
											td.align="center";
											td.className="nowrap";
											return td;
										}
									});				
								}
							}	
						});
					}
					else {
						var cellFuncs = [
						function(data1) { return getData("__wf__jobDesc",data1[1]); },
						function(data1) { return "-"; },
						function(data1) { return getTagStatus(data1[2],data1[0],getData("__wf__jobcodeid",data1[1]),getData("__wf__jobDesc",data1[1]),getData("__wf__requestid",data1[1])); },
						function(data1) { return "-"; },
						function(data1) { return "-"; },
						function(data1) { return "-"; },
						function(data1) { return "-"; },
						function(data1) { return "-"; },
						function(data1) { return "-"; }
						];
						dwr.util.addRows( "appList",data, cellFuncs, {
							  escapeHtml:false,	
							cellCreator:function(options) {
								var td = document.createElement("td");
								td.align="center";
								td.className="nowrap";
								return td;
							}
						});				
					}				
				}
			});
		}			
		else{		
			document.getElementById("mytable").style.display = "none";	
			dwr.util.removeAllRows('appList');	
			//alert(swap2String("No Data Found!!"));
			bCon=confirm(swap2String("Fill new application?"));
			if (bCon==true)	{
				window.open("RWF002.jsp","WF","left=150,top=150,width=600,height=600,toolbar=yes,status=yes,scrollbars=yes,resizable=yes");	
			}	
		}
	}	
	});
}

function getData(field,data){
	var dataList = data.split("#");
	//alert(dataList);
	for(i=0;i<dataList.length;i++){
		if(dataList[i].indexOf(field)!=-1){
			var value = dataList[i].split(",");
			return value[1];
		}
	}
	return "n/a";
}

function getTagStatus(data,empid,job,jobdesc,reqid){
	if(data=="1")
		return "รอการอนุมัติ"
	else if(data=="4"){
		SearchDWR.searchAll(new Array("MAPPLICANT","applicantid,referee1positionid","employeeid='"+empid+"' and referee1positionid='"+job+"'",""), function(data){
			if(data.length>0){
				dwr.util.setValue("__applicantid",data[0][0]);
			}
		});
	dwr.util.setValue("__referee1positionid",job);
	dwr.util.setValue("__requestid",reqid);		
	return "<a href='javascript:goApp(\""+jobdesc+"\")'>อนุมัติให้เข้าสู่กระบวนการคัดเลือก("+reqid+")</a>";		
	}
	else return "ไม่อนุมัติ";
}

function goApp(jobdesc){
	with(document.cscform){
	  //__applicantid.value = appid;
	  //__referee1positionid.value = jobid;
	  __referee1position_desc.value = jobdesc;
	  __employeeid.value = "<%=screen.getUProfile().get("employeeid")%>";
	//  action = "REC201.jsp";
		action="REC201.jsp?__setpage=edit";
	  __cmd.value="search";
	  submit();
	}	
}

function statusDesc(status){
 if(status>=3)
 	return "สัมภาษณ์แล้ว";
else if(status=2)
	return "นัดสัมภาษณ์";
}

function chkEnter(){
	if (window.event.keyCode == 13){
		//alert(window.event.keyCode);	
		//alert("xxx");	
		//searchApp(document.cscform.peopleid.value);
	}
}

function chkId(){
	with(document.cscform){	
		if(appType.selectedIndex==1){
			peopleid.value="<%=screen.getUProfile().get("employeeid")%>";
			peopleid.disabled=true;
		}
		else{
			peopleid.disabled=false;			
		}
	}	
}

function goPages(appid){
  		with(document.cscform){
			  __applicantid.value = appid
			 // action = "REC201.jsp";
			  __cmd.value="search";
			  action="REC201.jsp?__setpage=edit";
			  submit();
		}
}

</script>
<style type="text/css">
<!--
span#fullname {
	color: #FF0000;
}
td.nowrap{
	white-space: nowrap;
	}
-->
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="">
<form name="cscform" method="post" action="REC410.jsp">
	 

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

<%=screen.InitialVariable()%>

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

  <input type="hidden"name="__screen"  value="REC410"> 
	  <input type="hidden" name="__help"  size="50" value="">
	  <input name="__fixCon" type="hidden" value="">
	  <input type="hidden" name="__cmd"  value="">
	  <input type="hidden" name="__companyid" value="<%=screen.getUProfile().get("companyid")%>"> 
	  <input type="hidden" name="__referPage" value="">
	  <input type="hidden" name="__notNull" value="">
   	 <input type="hidden" name="__calendar">        
    <input type="hidden" name="__language"	value ="<%=screen.getUProfile().get("lang")%>">
  <script language="javascript">getInputFormatDate();</script>  
     <input type="hidden" name="__id_people">      
     <input type="hidden" name="__applicantid">          
     <input type="hidden" name="__employeeid">           
     <input type="hidden" name="__referee1positionid">           
     <input type="hidden" name="__referee1position_desc">                    
     <input type="hidden" name="__requestid" value="">     
          

	 
	 <div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>

	 <div class="centered"> <br>

		<table width="100%"  align="center" cellpadding="0" cellspacing="0" class="normal">
		  <tr class="header"> 
			<td  class="header" align="right">REC410, 
			  <script language="javascript">swapLang('Sign in');</script></td>
		  </tr>
		
		  <tr > 
			<td colspan="2"> 
			  <div align="center"> 
				<center>
				  <table cellpadding="0"  cellspacing="0" class="maxsize" >
                    <tr>
                      <td align="center" nowrap><select name="appType" onChange="chkId()" ><option value="0"><script language="javascript">swapLang('Outsider');</script></option><option value="1"><script language="javascript">swapLang('Insider');</script></option></select>&nbsp;
                        <script language="javascript">swapLang('People ID/Employee ID');</script>
                        &nbsp;
                        <input type="text" name="peopleid" size="15" maxlength="13" ></td>
                    </tr>
                    <tr>
                      <td align="center" colspan="4"><a href="javascript:chkType(document.cscform.peopleid.value)"><img src="../IMAGES/BUTTON/OK.gif" width="73" height="23" border="0">
                        
                      </a></td>
                    </tr>
                    <tr>
                      <td  colspan="4" height="400">
                      <table border="0" cellpadding="0" cellspacing='1' bgcolor="#333333" class="maxsize" STYLE="display:none" id="mytable">
   		<tbody id="head">
   		<tr>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Applied Position");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Apply Date");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Status");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Interview No.");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Interview Date");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Interview Time");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Interview Room");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Interview Place");</script></div></td>
	   		<td class="row3"><div align="center"><script language="javascript">swapLang("Remark");</script></div></td>
	   		</tr> 	
		</tbody>	 
		<tbody id="appList" >
		  </tbody>	 
   		</table>                      </td>
                    </tr>
                  </table>
				</center>
			  </div></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>