<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="java.util.*,java.io.*"%>
<%@page import="com.csc.library.util.download.*"%>
<%@page import="com.csc.library.util.ManageDocumentService"%>
<%@page import="com.csc.library.databean.util.FileUtil"%>
<%@page import="com.csc.library.approve.*,com.csc.library.databean.*"%>
<%@page import="com.csc.library.entry.*,com.csc.library.utilities.*"%>
<%@page import="com.csc.library.session.*"%>
<%@page import="com.csc.library.components.*,com.csc.library.report.ReportUDF"%>

<%request.setCharacterEncoding("UTF-8");%>
<jsp:useBean id="welexp003c1" class="com.csc.library.system.Task" scope="page"/>
<jsp:setProperty name="welexp003c1" property="appname" value="WELFARE" />
<jsp:setProperty name="welexp003c1" property="classauthen" value="WorkflowUIAuthen" />
<%
welexp003c1.setChannel(request,response);
welexp003c1.checkProfile();
if( welexp003c1.getUProfile() != null ){
	DbRecord borrow_emp=new InitialRecord(welexp003c1.getUProfile()).getDbRecord("texpend_summary_emp");
	DbRecord borrow_emp_date=new InitialRecord(welexp003c1.getUProfile()).getDbRecord("Texpend_summary_emp_date");
	ReportUDF rf=new ReportUDF();
	CheckNull chkNull = new CheckNull();
	String collaborator=chkNull.chkNullString(request.getParameter("collaborator")); 
	String pedestalstatus[]=rf.getSystemCode("PEDESTAL_TYPE",welexp003c1.getUProfile().get("lang"));		
	boolean isstep1=Boolean.parseBoolean(java.net.URLDecoder.decode(chkNull.chkNullString(request.getParameter("isstep1"))));		
	String keyvalue[];										
	/*				for(int n=0;n<module.length;n++){
							keyvalue=module[n].split(",");
							pedestalstatus+= "<option value='"+keyvalue[0]+"'>"+keyvalue[1]+"</option>";	
					}*/
	String vehiclestatus[]=rf.getSystemCode("EXPEND_STAT",welexp003c1.getUProfile().get("lang"));	

					
%>
<HTML>
	<HEAD>
		<TITLE>myNOTE : Business Process Management Service</TITLE>
		<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
		<LINK HREF="../CSS/MYNOTE.css" REL="stylesheet" TYPE="text/css">
		<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/SearchDWR.js'></script>  	   
	   <script type='text/javascript' src='/hr/dwr/interface/ExchangerateCtrl.js'></script>		
       <script type='text/javascript' src='/hr/dwr/interface/CheckExpendDwr.js'></script>	   	   
	   <script type='text/javascript' src='/hr/dwr/interface/Summary_emp_dateCtrl.js'></script>		
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/SCREEN.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/MYNOTE_SCREEN.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/VIEWCALENDAR.js'></SCRIPT>
		<SCRIPT LANGUAGE="JavaScript">setLang('<%=welexp003c1.getUProfile().get("lang")%>');</SCRIPT>
		<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript">
		ThaiCode[311]="ข้อมูลไม่ถูกต้อง วันที่ต้องอยู่ในช่วง ";
		EngCode[311]="invalid date between ";		
		ThaiCode[312]="กรุณาระบุ หมายเลขเอกสารการคืนเงิน";
		EngCode[312]="invalid document no ,please insert document no ";		

		
			var empdateCache = { };
			var reqArray=new Array(11);
			var msg="";
			
		  function saveValue(flag) {
		  
		 if(checkPeriodDate()&&checkValid()){
				  var summary_emp_date ={}
					hiddenDiv();
					dwr.engine.beginBatch();
					 for(key in empdateCache){
							summary_emp_date=empdateCache[key];
							Summary_emp_dateCtrl.setEmpdate(summary_emp_date);
					 }
					filldate();
					setItemvalue();
					CheckExpendBean(reqArray,allItem);	
					
					var summary_emp ={expendid:null , employeeid:null , companyid:null , collaborator:null , collaboratordesc:null , startdate:null , enddate:null , starttime:null , endtime:null , costcenter:null , budget:null , costcenterdesc:null , budgetdesc:null , borrowid:null , borrowid_account:null , 	borrowcost:null , refundno:null , 	 refundcost:null , 	 daycount:null , 	 allowday:null , 	 allowcost:null , 	 vehiclecost:null , remarks:null ,pedestalcost:null ,moneytype:null}
					dwr.util.getValues(summary_emp);
					window.opener.writeSummaryemp(summary_emp);
					 dwr.engine.endBatch({
									async:false
									});			  
					displayDiv();
					if(flag)
								window.close();
				}
			}			
						
		function CheckExpendBean(reqArray,allItem){
  			   CheckExpendDwr.checkAllItems(reqArray,allItem);					   
		}

		function setItemvalue(){
			var exptype=window.opener.document.cscform.__wf__exp_type.value;
			var provinceid=window.opener.document.cscform.__wf__provinceid.value;
			var countryid=window.opener.document.cscform.__wf__countryid.value;
			var locationtype=window.opener.document.cscform.__wf__location_type.value;
			var trav_by=window.opener.document.cscform.__wf__trav_by.value;
			var trav_type=window.opener.document.cscform.__wf__trav_type.value;
			var stdate=window.opener.document.cscform.__wf__startdate.value;
			var endate=window.opener.document.cscform.__wf__enddate.value;
			with(document.cscform){	
							reqArray[0]="301#"+collaborator.value+"#0# #"+stdate+"#"+exptype+"#"+locationtype+"#"+provinceid+"#"+countryid+"#"+endate+"#"+trav_by+"#"+trav_type+"# # # #"+parseFloat(allowday.value);
							reqArray[1]="302#"+collaborator.value+"#0# #"+stdate+"#"+exptype+"#"+locationtype+"#"+provinceid+"#"+countryid+"#"+endate+"#"+trav_by+"#"+trav_type;
							reqArray[2]="304#"+collaborator.value+"#0# #"+stdate+"#"+exptype+"#"+locationtype+"#"+provinceid+"#"+countryid+"#"+endate+"#"+trav_by+"#"+trav_type;
			}			
		}
						
						
		var allItem = function(data1){
		 msg="";
			for(var i=0;i<data1.length;i++){
					if(data1[i]!=null){						
							var vdata=data1[i].split('#');
							setValueExpend(vdata);
					}
			}
		}		
		
			function setValueExpend(data){
				with(document.cscform){	
						if(data[8]=="301"){
								var exch=parseFloat(exrate[moneytype.options[moneytype.selectedIndex].value]);
								allowcost.value=formatCurrency(data[5]*exch);	
						}else if(data[8]=="302"){ 
							pedestalcost.value=data[5]*parseFloat(pedestalday.value);
						}else if(data[8]=="304"){
							vehiclecost.value=data[5]*parseFloat(vehicleday.value);
						}
				}
			}
						
								
		function goHelp(helpName,inputName){
				with(document.cscform){
				var helpReturn="",fcon="";
				var temp = __fixCon.value;
					if(inputName == "collaborator"){
						var emplist=window.opener.document.cscform.__wf__texpend_summary_emp_list.value.split(",");
						var empfilter=""; 
							if(emplist.length>0){
									empfilter=" and employeeid not in(";
									for(var k=0;k<emplist.length;k++){
											empfilter+="'"+emplist[k]+"'"
											if(k<emplist.length-1){
													empfilter+=",";
											}
									}
									empfilter+=") ";
							}
							if(parseFloat(borrowcost.value.replace(","))==0){
							__fixCon.value="employeeid in (select  employeeid from texpend_emp where expendid='"+expendid.value+"' and rstatus!='1' and bstatus !='1')"+empfilter;
							}else{
							__fixCon.value="employeeid in (select  employeeid from texpend_emp where expendid='"+expendid.value+"' and employeeid ='"+employeeid.value+"')"+empfilter;
							}
						helpReturn="collaborator:employeeid,collaboratordesc:fullname";
						linkHelp_Return_search(helpName,helpReturn);
					}if(inputName == "costcenter"){
						helpReturn="costcenter:costcenterid,costcenterdesc:tdesc";
						linkHelp_Return_search(helpName,helpReturn);
					}else if(inputName == "budget"){
									if(costcenter.value.length>0){
												temp = __fixCon.value;
												__fixCon.value = "costcenterid='"+costcenter.value+"'";
												helpReturn="budget:budgetid,budgetdesc:tdesc";
												linkHelp_Return(helpName,helpReturn);
												__fixCon.value=temp;								
										}else{
												alert(MyCode[0]);
												costcenter.focus();
										}						
					}else if(inputName == "locate_from"){
						helpReturn="locate_from:tranid,locate_fromdesc:tdesc";
						linkHelp_Return(helpName,helpReturn);
					}
					__fixCon.value=temp;	
					}				
			}		
						
			function linkHelp_Return(help,input){
				with( document.cscform ){
					var param="EMV_PRU084.jsp?__helpName="+help+"&__helpReturn="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value+"&__checkVerify=off&__langOn=off";
					window.open(param,"Help","left=150,top=150,width=530,height=370,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
				}
			}
			
			function loadFromParent(keyid){
				dwr.engine.beginBatch();
					var obj=window.opener.loadDataEmp(keyid);
					dwr.util.setValues(obj);
					filldate();
					 dwr.engine.endBatch();
			}
			
			function gendate(){
				with(document.cscform){
						if(checkPeriodDate()&&checkValid()){
						empdateCache = { };
						dwr.engine.beginBatch();
						Summary_emp_dateCtrl.generate(collaborator.value,startdate.value,enddate.value);
						filldate();				
						calculateDate();		
  					   dwr.engine.endBatch();
					   }
				}
			}
			
			function checkValid(){
					with(document.cscform){
						if(collaborator.value.length==0){
								alert(MyCode[0]);
								collaborator.focus();
								return false;
						}else if(parseFloat(refundcost.value)>0 && refundno.value.length==0){
								alert(MyCode[312]);								
								refundno.focus();		
								return false;						
						}
						return true;
					}
			}
			
			function checkPeriodDate(){
				var bdate=$("enddate").value.split("-");
				var cdate=new Date(bdate[2],bdate[1]-1,bdate[0]);
						bdate=window.opener.document.cscform.__wf__startdate.value.split("-");
				var stdate=new Date(bdate[2],bdate[1]-1,bdate[0]);
						bdate=window.opener.document.cscform.__wf__enddate.value.split("-");
				var endate=new Date(bdate[2],bdate[1]-1,bdate[0]);
				var st=Math.ceil(stdate.getTime());
				var cu=Math.ceil(cdate.getTime());
				var en=Math.ceil(endate.getTime());	
				if(cu<st || cu>en){
						//alert(MyCode[311]+" "+window.opener.document.cscform.__wf__startdate.value +"  -   "+window.opener.document.cscform.__wf__enddate.value);
						//return false;
						window.opener.document.cscform.__wf__outoflimit.value="1";
				}
				return true;
		}
			
			function calculateDate(){
				with(document.cscform){
				 		var day=1000*60*60;
						var bdate=startdate.value.split("-");
						var stdate=new Date(bdate[2],bdate[1]-1,bdate[0]);
								stdate.setHours(parseFloat(starttime.value.substring(0,starttime.value.indexOf("."))));
								stdate.setMinutes(parseFloat(starttime.value.substring(starttime.value.indexOf("."),starttime.value.length)));
						var bdate=enddate.value.split("-");
						var endate=new Date(bdate[2],bdate[1]-1,bdate[0]);
								endate.setHours(parseFloat(endtime.value.substring(0,endtime.value.indexOf("."))));
								endate.setMinutes(parseFloat(endtime.value.substring(endtime.value.indexOf("."),endtime.value.length)));
						var st=Math.ceil(stdate.getTime());
						var en=Math.ceil(endate.getTime());	
						var diff=(en-st)/day;
						var diffday=diff/24;
						var diffhour=diff%24;
						var dd=parseInt(diffday)+1;
								if(diffhour>12)
								      dd=parseFloat(dd)+1;
								else if(diffhour>6)
										dd+=".50";
										else 
											dd+=".00";
								
						daycount.value=formatCurrency(dd);
					}
			}
			
			function changeValue(indexkey,changename,owner){
					var obj=empdateCache[indexkey];					
					eval("obj.	"+changename+"="+owner.value);							
					if(changename=="pedestalstatus"){		
						if(owner.value!="0"){
								$("allowancestatus"+indexkey).disabled=true;
								$("allowancestatus"+indexkey).value="0";
								eval("obj.allowancestatus=0");
						}else{
							$("allowancestatus"+indexkey).disabled=false;
						}
					}
					empdateCache[indexkey]=obj;
			}
			
			
			function filldate() {
					empdateCache = { };
			  		Summary_emp_dateCtrl.getEmpdate(function(empdatectrl) {
						dwr.util.removeAllRows("empdate_body", { filter:function(tr) { 
						  return (tr.id != "empdate_pattern");
						}
						
						}); 
					
						var empdate, id; 
						var alcount=0,vcount=0,pcount=0;
						empdatectrl.sort(function(p1, p2) { return p1.dateid.localeCompare(p2.dateid); });	
						var disabled="<%=(isstep1)?"":" disabled "%>";						
						for (var i = 0; i < empdatectrl.length; i++) {
						  empdate = empdatectrl[i];
						  id = empdate.dateid;
						  dwr.util.cloneNode("empdate_pattern", { idSuffix:id });
						  dwr.util.setValue("empdate_dateid"+id,empdate.dateid); 
						  dwr.util.setValue("dateid"+id,empdate.dateid); 
						  var pse="",chk=" selected ";						  
						  <%
						  for(int n=0;n<pedestalstatus.length;n++){
							keyvalue=pedestalstatus[n].split(",");
						   %>
						   if(empdate.pedestalstatus=="<%=keyvalue[0]%>")
						   	pse+= "<option value='<%=keyvalue[0]%>' "+chk+"><%=keyvalue[1]%></option>";	
						   else
							pse+= "<option value='<%=keyvalue[0]%>'><%=keyvalue[1]%></option>";	
						<%
							}
						  %>						  
 						  $("empdate_pedestalstatus"+id).innerHTML="<select id=\"pedestalstatus"+id+"\" onchange=\"changeValue('"+empdate.dateid+"','pedestalstatus',this) \""+disabled+">"+pse+"</select>";
						  dwr.util.setValue("pedestalstatus"+id,empdate.pedestalstatus); 
						  pse="";
						  <%
						  for(int n=0;n<vehiclestatus.length;n++){
							keyvalue=vehiclestatus[n].split(",");
						   %> 
						   if(empdate.vehiclestatus=="<%=keyvalue[0]%>")
						   	pse+= "<option value='<%=keyvalue[0]%>' "+chk+"><%=keyvalue[1]%></option>";	
						   else
							pse+= "<option value='<%=keyvalue[0]%>'><%=keyvalue[1]%></option>";	
						<%
							}
						  %>						  
						  $("empdate_vehiclestatus"+id).innerHTML="<select id=\"vehiclestatus"+id+"\" onchange=\"changeValue('"+empdate.dateid+"','vehiclestatus',this) \""+disabled+">"+pse+"</select>";
						  dwr.util.setValue("vehiclestatus"+id,empdate.vehiclestatus);
						  var pse="";
						  <%
						  for(int n=0;n<vehiclestatus.length;n++){
							keyvalue=vehiclestatus[n].split(",");
						   %>
						   if(empdate.allowancestatus=="<%=keyvalue[0]%>")
						   	pse+= "<option value='<%=keyvalue[0]%>' "+chk+"><%=keyvalue[1]%></option>";	
						   else
							pse+= "<option value='<%=keyvalue[0]%>'><%=keyvalue[1]%></option>";	
						<%
							}
						  %>	
						  var tmpdis=disabled; 
						  if(disabled.length==0){
						  		if(empdate.pedestalstatus!="0"){
										disabled=" disabled ";
								}
						  }					  
						  $("empdate_allowancestatus"+id).innerHTML="<select id=\"allowancestatus"+id+"\" onchange=\"changeValue('"+empdate.dateid+"','allowancestatus',this) \""+disabled+">"+pse+"</select>";
						  dwr.util.setValue("allowancestatus"+id,empdate.allowancestatus);					  
						  if(empdate.allowancestatus=="1") alcount+=1;
						  if(empdate.vehiclestatus=="1") vcount+=1;
						  if(empdate.pedestalstatus!="0") pcount+=1;					   
						 document.getElementById("empdate_pattern" + id).style.display = "";  // officially we should use table-row, but IE prefers "" for some reason
						 empdateCache[id] = empdate;
						 
						 disabled=tmpdis;						 
						}
						with(document.cscform){
								allowday.value=alcount;
								vehicleday.value=vcount;
								pedestalday.value=pcount;
						}

			  });
			}
			
var exrate={};
		
		function fillExchange(types){
		  ExchangerateCtrl.getExchange(function(exchangectrl) {
		
			var exchange, id;
			exchangectrl.sort(function(p1, p2) { return p1.exchangeid.localeCompare(p2.exchangeid); });
			var isstep1="<%=isstep1%>";			
			var str="<select id=\"moneytype\" disabled>";
				if(isstep1=="true"){
					str="<select id=\"moneytype\">";		
				}
			for (var i = 0; i < exchangectrl.length; i++) {
			  exchange = exchangectrl[i];		
			  str+="<option value=\""+exchange.exchangeid+"\"";
			  if(exchange.exchangeid==types)
			  	str+=" selected ";
			  str+=">"+exchange.exchangedesc+"</option>";
			 exrate[exchange.exchangeid]=exchange.amount;
			}
			 $("__moneytype").innerHTML=str;
		  });
		  
		}			
			
			function hiddenDiv(){
				with(document.cscform){
					 msg="";
					 reqArray=new Array(11);
					 btsubmit.style.display="none";
					 showtxt.innerHTML="<p align='center'><img src='./IMAGES/WAITING.gif'><BR><font color='red' ><B>"+MyCode[210]+"</H3></font><p>";
				}
			}
			
			function displayDiv(){
						with(document.cscform){
								 btsubmit.style.display="";
								 showtxt.innerHTML="";
							}	
			}					
			
			function postReturn(){
					getBorrowed();
					searchCostcenter();
			}
			
			function getBorrowed(){
			with(document.cscform){
			SearchDWR.searchDBXMLAll(new Array("TEXPEND_EMPHELP", "texpend_emp.borrow_cost", "texpend_emp:employeeid = '"+collaborator.value+"' and expendid='"+expendid.value+"'", "false", "langOn"), function(data){
							if(data.length>0){ 
									borrowcost.value=data[0][0];
							}
					});
				}
			}
			
			function formatCurrency(num) {
					num = num.toString().replace(/\|\,/g,'');
					if(isNaN(num))
						num = "0";
						sign = (num == (num = Math.abs(num)));
						num = Math.floor(num*100+0.50000000001);
						cents = num%100;
						num = Math.floor(num/100).toString();
					if(cents<10)
						cents = "0" + cents;
					for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
						num = num.substring(0,num.length-(4*i+3))+','+
						num.substring(num.length-(4*i+3));
						return (((sign)?'':'-') +  num + '.' + cents);
			}			
			
			
			function searchCostcenter(){
				with(document.cscform){			
						SearchDWR.searchDBXMLAll(new Array("MBUDGET_PTTHELP", "mbudget_ptt.budgetid,mbudget_ptt.tdesc", "mbudget_ptt:costcenterid = '"+costcenter.value+"'", "false", "langOn"), function(data){
										if(data.length>0){  
													budget.value=data[0][0];
													budgetdesc.value=data[0][1];
										}else{
													budget.value="";
													budgetdesc.value="";
										}
								});						
					}
			}
					
			function linkHelp_SendToReturn(help,input){
				with( document.cscform ){
					var param = "BROWSE_USER.jsp?__helpName="+help+"&__helpReturn="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value+"&__checkVerify=off&__langOn=off";
					window.open(param,"Help","left=150,top=150,width=530,height=370,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
				}
			}
			
			function linkHelp_Return_search(help,input){
				with( document.cscform ){
					var param="BROWSE_WELFAREHELP.jsp?__helpName="+help+"&__helpReturn="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value+"&__checkVerify=off&__langOn=off";
					window.open(param,"Help","left=150,top=150,width=530,height=370,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
				}
			}		
						
			function linkHelp_Return(help,input){
				with( document.cscform ){
					var param="EMV_PRU084.jsp?__helpName="+help+"&__helpReturn="+input+"&__pageCall="+__screen.value+"&__fixCon="+__fixCon.value+"&__checkVerify=off&__langOn=off";
					window.open(param,"Help","left=150,top=150,width=530,height=370,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
				}
			}
			function linkHelpWF(help,input){
				with(document.cscform){
					var temp = __fixCon.value;
					var fix = "wf_id='"+wf_id.value+"' and wf_ver='"+wf_ver.value+"' and initiator='<%=welexp003c1.getUProfile().get("actor")%>' and (wf_status<>'4' and wf_status<>'6' and wf_status<>'3' and wf_status<>'8' and wf_status<>'A' and wf_status<>'B')";
					var param="EMV_PRU084.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall="+__screen.value+"&__fixCon="+fix;
					alert("param is:"+param);
					window.open(param,"Help","left=150,top=150,width=530,height=370,resizable=yes,scrollbars=yes,toolbar=no,status=yes");
					__fixCon.value = temp;
				}
			}		
			
		function chkInputDate(obj) {
		var temp = obj.value;
		var tempdate = obj.value.split("-");
		var chk = true;
		//ตรวจสอบดูว่าพิมเป็นตัวอักษรหรือไม่
		if (!chkIntNotChar (temp)) {
			alert(MyAlert[30]); 
			obj.value = datePresent(); 
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ากรอกตัวเลขครบแปดหลักแล้วหรือไม่
		else if ((obj.value.length < 8) && (obj.value.length > 0)) { 
			alert(MyAlert[31]); 
			obj.value = datePresent();
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่าถ้ากรอกวันที่ครบแปดตัวเลขแล้ว กรอก วัน เดือน ปี ถูกต้องหรือไม่ ( โดยเรียก script checkTrueDay(str) )
		else if ( (tempdate[0].length == 2) && (tempdate[1].length == 2) && (tempdate[2].length == 4) && (temp.length > 0 ) && (!checkTrueDay(delWordDate(temp))) ) {
			alert(MyAlert[31]);
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ากรอก วันเป็นเลขสองหลัก เดือนเป็นเลขสองหลัก และปีเป็นเลขสี่หลักหรือป่าว
		else if ( (tempdate[0].length != 2 || tempdate[1].length != 2 || tempdate[2].length != 4) && temp.length > 0  ) {
			alert(MyAlert[31]);
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ากรอกวันเกินสิบตัวเลขหรือไม่ ( กรณีที่เกิดคือ copy คำมาแปะอาจเป็นภาษาไทย หรือ อักษร )
		else if ( (temp != delWordDate(obj.value)) && (temp.length > 10) ) {
			obj.value = datePresent(); 
			alert(MyAlert[31]); 
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่ารูปแบบวันที่อยู่ในรูปของ ddmmyyyy หรือ dd-mm-yyyy แล้วหรือยัง
		else if ( tempdate.length != 3 ) 	{
			obj.value = datePresent();
			alert(MyAlert[31]); 
			obj.select();
			chk = false;
		}
		//ตรวจสอบดูว่า วันที่กรอกเป็นเลขสองหลัก เดือนเป็นเลขสองหลัก และปีเป็นเลขสี่หลักหรือไม่
		else if (  (tempdate[0].length != 2) && (tempdate[1].length != 2) && (tempdate[2].length != 4)  )   {
			obj.value = datePresent();
			alert(MyAlert[31]); 
			obj.select();
			chk = false;
		}
		return chk; //ถ้ากรอกวันที่ถูกต้องตามเงื่อนไขแล้วจะ retrun เป็น true
	}		
					
					
		function transferRate(res,des){
				with(document.cscform){
						var rate =parseFloat(exrate[moneytype.options[moneytype.selectedIndex].value]);
						des.value=formatCurrency(parseFloat(res.value)*rate);
				}
		}
											
</script>
		<STYLE TYPE="text/css">
		<!--
			.style1 {
			color: #FFFFFF;
			font-weight: bold;
			}
		-->
		</STYLE>
	</HEAD>
	<BODY onLoad="MM_preloadImages('../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif')">
		<FORM NAME="cscform" METHOD="post" ACTION="WELEXP003C2.jsp">
			<INPUT TYPE="hidden" NAME="__screen" VALUE="WELEXP003C2">
			<INPUT TYPE="hidden" NAME="__cmd" VALUE="">
			<INPUT TYPE="hidden" NAME="__fixCon" VALUE="">
			<INPUT TYPE="hidden" NAME="__help" VALUE="">
			<INPUT TYPE="hidden" NAME="__language" VALUE="<%=welexp003c1.getUProfile().get("lang")%>">
			<INPUT TYPE="hidden" NAME="__companyid" VALUE="<%=welexp003c1.getUProfile().get("companyid")%>">
			<INPUT TYPE="hidden" NAME="companyid"  id="companyid" VALUE="<%=welexp003c1.getUProfile().get("companyid")%>">
			<INPUT TYPE="hidden" NAME="__calendar" VALUE="">
			<INPUT TYPE="hidden" NAME="expendid" id="expendid" VALUE="<%=request.getParameter("expendid")%>">
			<INPUT TYPE="hidden" NAME="employeeid"  id="employeeid" VALUE="<%=request.getParameter("employeeid")%>">
			<INPUT TYPE="hidden" NAME="vehicleday"  id="vehicleday" VALUE="">
			<INPUT TYPE="hidden" NAME="pedestalday"  id="pedestalday" VALUE="">
			<INPUT TYPE="hidden" NAME="__server_date"  id="__server_date" VALUE="<%=new CscCalendar().getDDMMYYYY()%>">
			<SCRIPT LANGUAGE="JavaScript">getInputFormatDate();</SCRIPT>			

			<TABLE WIDTH="580" BORDER="0" ALIGN="center" CELLPADDING="0" CELLSPACING="0">
  				<TR>
    				<TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-T-L.gif" WIDTH="5" HEIGHT="5"></TD>
    				<TD HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/T.gif" WIDTH="100%" HEIGHT="5"></TD>
	    			<TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-T-R.gif" WIDTH="5" HEIGHT="5"></TD>
  				</TR>
  				<TR>
	    			<TD WIDTH="5" BACKGROUND="../IMAGES/MYNOTE/L2.gif"><FONT COLOR="#FFFFFF"></FONT></TD>
    				<TD >
      					<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="1" CLASS="txt01">
      						<td width="34%">
							<TR BGCOLOR="#EFF7FA">
							<TD  COLSPAN="2" class="column-title"><DIV ALIGN="CENTER"><B><script language="javascript">swapLang("รายละเอียดผู้เดินทางและร่วมเดิมทาง");</script></B></DIV></TD>
							</TR>
													<TR>
													<TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("collaborator").getDescription()%></td>
													<TD width="66%" NOWRAP="nowrap" CLASS="desc"><DIV ALIGN="left"><INPUT TYPE="text" NAME="collaborator" id="collaborator"  size="10" VALUE="" ><%if(isstep1){%><A HREF="javascript:goHelp('MEMPLOYEEHELP','collaborator')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('999','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/SEARCH20.gif" ALT="SEARCH" NAME="employee_image2" WIDTH="20" HEIGHT="20" BORDER="0" ALIGN="absmiddle"></A><%}%>
													    <INPUT TYPE="text" SIZE="50" NAME="collaboratordesc" id="collaboratordesc"  VALUE="" class="disabled" readonly></DIV></TD>
													</TR>
													<TR>
                                                      <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("startdate").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><DIV ALIGN="left">
													    <INPUT TYPE="text" NAME="startdate" id="startdate" VALUE="<%=new CscCalendar().getDDMMYYYY()%>" SIZE="10" MAXLENGTH="10" ONKEYPRESS="chkInteger();" ONBLUR="chkInputDate(this);" ONKEYUP="formatDate(this);" ONFOCUS="this.select();"  >
                                                        <%if(isstep1){%><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" alt="calendar" name="Image1" border="0" align="absmiddle" id="Image1" onClick="viewCal('startdate')"></a><%}%><script language="javascript">swapLang('Time');</script>
                                                        <INPUT TYPE="text" NAME="starttime" id="starttime" VALUE="0.00" MAXLENGTH="5" SIZE="5"  class="numeric" onKeyPress="checkWordNumber(this.value,event);" onKeyUp="sysIsEdit();checkComma(this,2);" onBlur="checkNumFloat(this,0,900000000);" onFocus="callDelComma(this);">
													  </DIV></TD>
						  </TR>
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("enddate").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><INPUT TYPE="text" NAME="enddate" id="enddate" VALUE="<%=new CscCalendar().getDDMMYYYY()%>" SIZE="10" MAXLENGTH="10" ONKEYPRESS="chkInteger();" ONBLUR="chkInputDate(this);" ONKEYUP="formatDate(this);" ONFOCUS="this.select();">
                                                        <%if(isstep1){%><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)"><img src="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" alt="calendar" name="Image11" border="0" align="absmiddle" id="Image11" onClick="viewCal('enddate')"></a><%}%><script language="javascript">swapLang('Time');</script>
                                                      <INPUT TYPE="text" NAME="endtime" id="endtime" VALUE="0.00" MAXLENGTH="5" SIZE="5"  class="numeric" onKeyPress="checkWordNumber(this.value,event);" onKeyUp="sysIsEdit();checkComma(this,2);" onBlur="checkNumFloat(this,0,900000000);" onFocus="callDelComma(this);"></TD>
						  </TR>
						  							<%if(isstep1){%>
													<TR>
													  <TD align="right" nowrap  class="column-label"><script language="javascript">swapLang('Display date');</script></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><a href="#"><IMG HEIGHT=37 SRC="../IMAGES/MYNOTE/BUTTON/BUTTON_GEN.gif" WIDTH=89 BORDER=0 onClick="gendate()"></a></TD>
						  							</TR>
						  							<%}%>
													<TR>
													  <TD colspan="2" nowrap  class='column-title'><div align="left"><script language="javascript">swapLang('Travel date')</script></div></td>
						  </TR>
													<TR>
													  <TD colspan="2" align="right" nowrap  class="column-input"><TABLE WIDTH="100%" BORDER="0" ALIGN="center" CELLPADDING="0" CELLSPACING="0">
                                                        <TR>
                                                          <TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-T-L.gif" WIDTH="5" HEIGHT="5"></TD>
                                                          <TD HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/T.gif" WIDTH="100%" HEIGHT="5"></TD>
                                                          <TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-T-R.gif" WIDTH="5" HEIGHT="5"></TD>
                                                        </TR>
                                                        <TR>
                                                          <TD WIDTH="5" BACKGROUND="../IMAGES/MYNOTE/L2.gif"></TD>
                                                          <TD VALIGN="middle"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="1" ID="tbChild">
                                                              <TR class="row-header">
                                                                <TD width="20%" ><%=borrow_emp_date.getField("dateid").getDescription()%></TD>
                                                                <TD width="23%" class="column-header" ><%=borrow_emp_date.getField("pedestalstatus").getDescription()%></TD>
                                                                <TD width="29%" class="column-header"><%=borrow_emp_date.getField("vehiclestatus").getDescription()%></TD>
                                                                <TD width="28%" class="column-header"><%=borrow_emp_date.getField("allowancestatus").getDescription()%></TD>
                                                              </TR>
                                                              <tbody id="empdate_body">
                                                                <tr id="empdate_pattern" style="display:none;">
                                                                  <td class="columnobject1"><span id="empdate_dateid"></span></td>
                                                                  <td class="columnobject1"><span id="empdate_pedestalstatus"></span></td>
                                                                  <td class="columnobject1"><span id="empdate_vehiclestatus"></span></td>
                                                                  <td class="columnobject1"><span id="empdate_allowancestatus"></span></td>
																   <input type="hidden" id="dateid" >
                                                                </tr>
                                                              </tbody>
                                                          </TABLE></TD>
                                                          <TD WIDTH="5" BACKGROUND="../IMAGES/MYNOTE/R2.gif"></TD>
                                                        </TR>
                                                        <TR>
                                                          <TD WIDTH="5" BACKGROUND="../IMAGES/MYNOTE/L2.gif"></TD>
                                                          <TD CLASS="column-data" align="center"><BR>
                                                              <div align="center"></div></TD>
                                                          <TD WIDTH="5" BACKGROUND="../IMAGES/MYNOTE/R2.gif"></TD>
                                                        </TR>
                                                        <TR>
                                                          <TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-B-L.gif" WIDTH="5" HEIGHT="5"></TD>
                                                          <TD HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/B.gif" WIDTH="100%" HEIGHT="5"></TD>
                                                          <TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-B-R.gif" WIDTH="5" HEIGHT="5"></TD>
                                                        </TR>
                                                      </TABLE></td>
						  </TR>
													<TR>
                                                      <TD align="right" nowrap bgcolor=#0099cc class="column-label"><%=borrow_emp.getField("costcenter").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><DIV ALIGN="left">
													    <INPUT TYPE="text" NAME="costcenter" id="costcenter"  size="10" VALUE="" >
													    <%if(isstep1){%><A HREF="javascript:goHelp('MCOSTCENTER0HELP','costcenter')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('999','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/SEARCH20.gif" ALT="SEARCH" NAME="employee_image2" WIDTH="20" HEIGHT="20" BORDER="0" ALIGN="absmiddle"></A><%}%>
                                                          <INPUT TYPE="text" SIZE="50" NAME="costcenterdesc" id="costcenterdesc"  VALUE="" readonly class="disabled">
													    </DIV></TD>
						  </TR>
													<TR>
                                                      <TD align="right" nowrap bgcolor=#0099cc class="column-label"><%=borrow_emp.getField("budget").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><DIV ALIGN="left">
													    <INPUT TYPE="text" NAME="budget" id="budget"  VALUE="" size="10" >
													    <%if(isstep1){%><A HREF="javascript:goHelp('MBUDGET_PTTHELP','budget')" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('999','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/SEARCH20.gif" ALT="SEARCH" NAME="employee_image2" WIDTH="20" HEIGHT="20" BORDER="0" ALIGN="absmiddle"></A><%}%>
                                                          <INPUT TYPE="text" SIZE="50" NAME="budgetdesc" id="budgetdesc"  VALUE="" readonly class="disabled">
													    </DIV></TD>
						  </TR>
													
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("borrowid").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><INPUT TYPE="text" NAME="borrowid" id="borrowid"  size="30" VALUE=""  class="disabled" readonly></TD>
						  </TR>
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("borrowid_account").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><INPUT TYPE="text" NAME="borrowid_account" id="borrowid_account"  size="30" VALUE="" ></TD>
						  </TR>
													<TR>
                                                      <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("borrowcost").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    <input type="text" name="borrowcost" size="10" maxlength="10" value="0.00"  class="numeric"  disabled/>
													  </span>
												      <script language="javascript">swapLang("Baht");</script></TD>
						  </TR>
													<TR>
                                                      <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("refundno").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><INPUT TYPE="text" NAME="refundno" id="refundno"  size="30" VALUE="" ></TD>
						  </TR>
													<TR>
                                                      <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("refundcost").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    <input type="text" name="refundcost" size="10" maxlength="10" value="0.00"  class="numeric" onKeyPress="checkWordNumber(this.value,event);" onKeyUp="sysIsEdit();checkComma(this,2);" onBlur="checkNumFloat(this,0,900000000);" onFocus="callDelComma(this);"/>
													  </span>
													    <script language="javascript">swapLang("Baht");</script></TD>
						  </TR>
													
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("daycount").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    <input type="text" name="daycount" id="daycount" size="5" maxlength="5" value="0" disabled  class="numeric"/>
													  </span></TD>
						  </TR>
													<TR>
													  <TD align="right" nowrap bgcolor=#0099cc class="column-label"><%=borrow_emp.getField("moneytype").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span id="__moneytype"></span></TD>
						  </TR>
						  
						  							<%if(isstep1){%>
													<TR>
													  <TD align="right" nowrap  class="column-label"><script language="javascript">swapLang('Calculate allowance')</script></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><a href="javascript:saveValue(false);"><IMG SRC="../IMAGES/MYNOTE/BUTTON/BUTTON_CALCULATE.gif" WIDTH="101" HEIGHT="37" BORDER="0" ALT="Add"></a></TD>
												  </TR>
												  <%}%>
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("allowday").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    <input type="text" name="allowday" id="allowday" size="5" maxlength="5" value="0"  class="numeric" disabled/>
													  </span></TD>
						  </TR>
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("allowcost").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    <input type="text" name="allowcost" id="allowcost" size="10" maxlength="10" value="0.00" disabled class="numeric"/>
													  </span></TD>
						  </TR>
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("vehiclecost").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    <input type="text" name="vehiclecost"  id="vehiclecost" size="10" maxlength="10" value="0.00" disabled  class="numeric"/>
													  </span></TD>
						  </TR>
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("pedestalcost").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    <input type="text" name="pedestalcost"  id="pedestalcost" size="10" maxlength="10" value="0.00" disabled  class="numeric"/>
													  </span></TD>
											  </TR>
													<TR>
													  <TD align="right" nowrap  class="column-label"><%=borrow_emp.getField("remarks").getDescription()%></td>
													  <TD NOWRAP="nowrap" CLASS="desc"><span class="column-input">
													    				<textarea NAME='remarks' id="remarks" COLS='80' ROWS='4' onKeyPress="chkSpecialStr(event);" onKeyUp="chkLimitTextArea(this,1000);sysIsEdit();" onBlur="trimValue(this);" ></textarea>
													  </span></TD>
						  </TR>
      				  </TABLE>
    				</FONT></TD>
    				<TD WIDTH="5" BACKGROUND="../IMAGES/MYNOTE/R2.gif"><FONT COLOR="#FFFFFF"></FONT></TD>
  				</TR>
	  			<TR>
    				<TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-B-L.gif" WIDTH="5" HEIGHT="5"></TD>
    				<TD HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/B.gif" WIDTH="100%" HEIGHT="5"></TD>
    				<TD WIDTH="5" HEIGHT="5"><IMG SRC="../IMAGES/MYNOTE/C-B-R.gif" WIDTH="5" HEIGHT="5"></TD>
	  			</TR>
			</TABLE>
			<BR>
			<TABLE WIDTH="500"  BORDER="0" ALIGN="center" CELLPADDING="0" CELLSPACING="0" CLASS="thai03">
  				<TR>
    				<TD><SPAN id="showtxt"></SPAN><DIV ALIGN="right"  id="btsubmit"> <%if(isstep1){%><A HREF="JavaScript:saveValue(true);"><IMG SRC="../IMAGES/MYNOTE/BUTTON/BUTTON_SUBMIT.gif" WIDTH="89" HEIGHT="37" BORDER="0"></A><%}%><A HREF="JavaScript:window.close();"><IMG SRC="../IMAGES/MYNOTE/BUTTON/BUTTON_CANCEL.gif" WIDTH="89" HEIGHT="37" BORDER="0"></A></DIV></TD>
  				</TR>
			</TABLE>
			<%
				if(collaborator.length()>0){
				%>
				<script language="javascript">
				loadFromParent("<%=collaborator%>");
				getBorrowed();
				</script>
				<%		
				}else{
			%>
				<script language="javascript">
						document.cscform.costcenter.value=window.opener.document.cscform.__wf__costcenter.value;
						document.cscform.budget.value=window.opener.document.cscform.__wf__budget.value;				
						document.cscform.costcenterdesc.value=window.opener.document.cscform.mcostcenter0_tdesc.value;
						document.cscform.budgetdesc.value=window.opener.document.cscform.budgetdesc.value;										
				</script>			
			<%}%>
				<script language="javascript">
				         fillExchange();
						document.cscform.startdate.value=window.opener.document.cscform.__wf__startdate.value;
						document.cscform.enddate.value=window.opener.document.cscform.__wf__enddate.value;
						document.cscform.borrowcost.value=window.opener.document.cscform.__wf__borrow_cost.value;
						document.cscform.borrowid.value=window.opener.document.cscform.__wf__expendid.value;						
				</script>
			<%if(!isstep1){%>
			<script language="javascript">setDisabled(true);</script>		
			<%}%>
			
    </FORM>
</BODY>
</HTML>
<%}%>