<%@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.*"%>

<%request.setCharacterEncoding("UTF-8");%>

<!-- Begin useBean -->

<jsp:useBean id="TEMPLATE_WORKFLOW" class="com.csc.library.system.Task" scope="page"/>
<jsp:setProperty name="TEMPLATE_WORKFLOW" property="appname" value="WELFARE" />
<jsp:setProperty name="TEMPLATE_WORKFLOW" property="classauthen" value="WorkflowUIAuthen" />
<jsp:useBean id="SCREENEMP" class="com.csc.library.system.Task" scope="page"/>
<jsp:setProperty name="SCREENEMP" property="appname" value="WELFARE" />

<%
TEMPLATE_WORKFLOW.setChannel(request,response);
SCREENEMP.setChannel(request,response);
//TEMPLATE_WORKFLOW.checkProfile();
UIManager screenSingle = (UIManager) TEMPLATE_WORKFLOW.process("SingleEntry","TEMPLATE_WORKFLOW");
HelpEntry screenEmp = (HelpEntry) SCREENEMP.process("HelpEntry","WELEXP_CPN_001HELP");

if( screenSingle == null ){
	return;
}
CheckNull chkNull = new CheckNull();

DbRecord db=new InitialRecord(screenSingle.getUProfile()).getDbRecord("MACCOUNT_EXP");
db.setColumn("*");
db.set("accountid","61201004");
db.set("companyid",(String)screenSingle.getUProfile().get("companyid"));
db.search();
String accountid=db.getString("accountid");
String accountdesc=db.getString("tdesc");

String sap_compid="",sap_buaid="",cost_center="";
DbRecord dbbranch=new InitialRecord(screenSingle.getUProfile()).getDbRecord("mbranch");
dbbranch.setColumn("*"); 
if(!chkNull.chkNullString(request.getParameter("bill_edit")).equals("true") ){
	dbbranch.set("branchid",(String)screenSingle.getUProfile().get("branch"));
	dbbranch.set("companyid",(String)screenSingle.getUProfile().get("companyid"));
	dbbranch.search();
	 sap_compid=dbbranch.getString("comid");
	 sap_buaid=dbbranch.getString("buaid");//(String)screenSingle.getUProfile().get("workarea");
	 //cost_center=dbbranch.getString("wel_cost2");
	 //cost_center=(String)screenSingle.getUProfile().get("costcenter");
	String empid = screenEmp.getUProfile().get("employeeid");
	screenEmp.getInquiry().setFilter(" employeeid = '"+empid+"' AND companyid = '"+screenEmp.getUProfile().get("companyid")+"'");
	screenEmp.process();
	screenEmp.nextRec();
	cost_center=chkNull.chkNullString(request.getParameter("__wf__costcenter"),screenEmp.getString("mcostcenter0","costcenter_sap"));
}
String costcenter =(String)screenSingle.getUProfile().get("costcenter");
%>
<!-- End useBean -->

<HTML>
	<HEAD>
		<TITLE>myNOTE : Business Process Management Service</TITLE>
		<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
		<!-- Begin Link -->
		<!-- Begin CSS Links -->
		<LINK REL="stylesheet" TYPE="text/css" HREF="../CSS/DDMENU.css" />
		<LINK REL="stylesheet" TYPE="text/css" HREF="../CSS/EMV_DEFAULT.css" />
		<LINK REL="stylesheet" TYPE="text/css" HREF="../CSS/EMV_LAYOUT.css" />
		<LINK REL="stylesheet" TYPE="text/css" HREF="../CSS/EMV_LAYOUT_TWO.css" />
		<LINK REL="stylesheet" TYPE="text/css" HREF="../CSS/EMV_TEXT.css" />
		<LINK REL="stylesheet" TYPE="text/css" HREF="../CSS/MYNOTE.css" />
		<!-- End CSS Links -->
		<!-- End Link -->
		<!-- Begin Import Script -->
		<!-- Begin script for Dropdown Menu -->
		<!-- DO NOT EDIT -->
		<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript" SRC="../JS/DDMENU.js"></SCRIPT>
		<!--[if lt IE 7]><SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript" SRC="../JS/IEHOVER-FIX.js"></SCRIPT><![endif]-->
		<!-- DO NOT EDIT -->
		<!-- End script for Dropdown Menu -->
		<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript" SRC="../JS/TABMENU.js"></SCRIPT>
		<!-- BEGIN FIX TAB BUG ON IE6 : DO NOT EDIT -->
		<!--[if lt IE 7]><SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript" SRC="../JS/TABMENU-IE6FIX.js"></SCRIPT><![endif]-->
		<!-- END FIX TAB BUG ON IE6 : DO NOT EDIT -->
		<!-- End script for Dropdown Menu -->
		<SCRIPT LANGUAGE="JavaScript" TYPE='text/JavaScript' SRC='../JS/UTILITIES.js'></SCRIPT>
		<SCRIPT LANGUAGE="JavaScript" TYPE='text/JavaScript' SRC='../JS/ACTIVE_OBJECT.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/MYNOTE_SCREEN.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/MYNOTE_MENU.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/SCREEN.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/DATEINPUT.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/VIEWCALENDAR.js'></SCRIPT>
		<SCRIPT TYPE='text/JavaScript' SRC='../JS/ICONSMENU.js'></SCRIPT>
		<SCRIPT LANGUAGE="JavaScript">setLang('<%=screenSingle.getUProfile().get("lang")%>');</SCRIPT>
		<!-- End Import Script -->
		<!--DWR INCLUDE-->
		<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 TYPE='text/javascript' SRC='/hr/dwr/interface/ExpenseGL.js'></SCRIPT>
		
		<!--DWR INCLUDE-->
		<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript">
		<!--
		ThaiCode[226]="ยอดที่เบิกได้=";
		EngCode[226]="Can request this value=";				
		ThaiCode[227]="ไม่สามารถเบิกได้เนื่องจากเบิกไปเต็มวงเงินแล้ว";
		EngCode[227]="Can request ,because overlimit";				
			setPageTitle(swap2String("Expense list"));

			setPageTitle(swap2String("Expense list"));
			var returnValue;
			
			function goHelp(helpName,inputName,condition){
				with( document.cscform ){
					var helpReturn;
					var temp;
					if( inputName == "bill_workarea" ){
						temp = __fixCon.value;
					 	//helpReturn="bill_workarea:WORKAREAID,bill_workarea_desc:TDESC";
						helpReturn="bill_workarea:branchid,bill_workarea_desc:TDESC";
						linkHelp_Return(helpName,helpReturn);
						__fixCon.value=temp;
					}else if( inputName == "bill_tobranch" ){
						temp = __fixCon.value;
					 	//helpReturn="bill_workarea:WORKAREAID,bill_workarea_desc:TDESC";
						helpReturn="bill_tobranch:branchid,bill_tobranch_desc:TDESC";
						linkHelp_Return(helpName,helpReturn);
						__fixCon.value=temp;
					}else if( inputName == "bill_cost_center" ){
						temp = __fixCon.value;
						helpReturn="bill_cost_center:accountid,bill_cost_center_desc:tdesc";
						linkHelp_Return(helpName,helpReturn);
						__fixCon.value=temp;
					}else if( inputName == "bill_budget" ){
						temp = __fixCon.value;
						helpReturn="bill_budget:BUDGETID,bill_budget_desc:TDESC";
						linkHelp_Return(helpName,helpReturn);
						__fixCon.value=temp;
					}
				}
			}
			
			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(help,input){
				with( document.cscform ){
					var param="BROWSE_HELP.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='<%=screenSingle.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="BROWSE_HELP.jsp?__helpName="+help+"&__fieldSearch="+input+"&__pageCall="+__screen.value+"&__fixCon="+fix;
					
					window.open(param,"Help","left=150,top=150,width=530,height=370,resizable=yes,scrollbars=yes,toolbar=no,status=yes");
					__fixCon.value = temp;
				}
			}
			
			function toolTip(desc){}
			
		function checkValid(){
					with(document.cscform){
						if(bill_cost_center.value.length==0){
								alert(MyCode[0]);
								bill_cost_center.focus();
						}else if(bill_starttime.value.length==0){
								alert(MyCode[0]);
								bill_starttime.focus();
						}else if(bill_endtime.value.length==0){
								alert(MyCode[0]);
								bill_endtime.focus();
						}else if(bill_remark.value.length==0){
								alert(MyCode[0]);
								bill_remark.focus();
						}else if (bill_nets.value.length==0 || (bill_nets.value*1)==0){
								alert(MyCode[0]);
								bill_nets.focus();
						}else if(bill_exp_costcenter.value.length==0){
								alert(MyCode[0]);
								bill_exp_costcenter.focus();
						}/*else if(bill_exp_compid.value.length==0){
								alert(MyCode[0]);
								bill_exp_compid.focus();
						}else if(bill_exp_buaid.value.length==0){
								alert(MyCode[0]);
								bill_exp_buaid.focus();
						}*/else if (bill_travel_date.value.length==0){
								alert(MyCode[0]);
								bill_travel_date.focus();
						}/*else if(bill_km.value.length==0||(bill_km.value*1)==0){
								alert(MyCode[0]);
								bill_km.focus();
						}*/else{
							var expbudget="{'employeeid':'"+__wf__employeeid.value+"','glcode':'"+__bill_name.options[__bill_name.selectedIndex].value+"','kms':'"+bill_km.value.replace(/,/g,"")+"','amtreq':'"+bill_nets.value.replace(/,/g,"")+"','billdate':'"+bill_date.value+"'}";
							dwr.engine.beginBatch();
							 dwr.engine.setOrdered(true);
							ExpenseGL.checkBudget(expbudget,resultBudget);
							dwr.engine.endBatch();
						}
					}
			}
	
	//properties in object [status,message,budget,amtreq,result,flag]
	var resultBudget=function(data1){ 
		returnValue=eval("("+data1+")");
		/*for (key in returnValue) {
     		 alert(key + ': ' + returnValue[key])
   			 }*/
		if(returnValue.flag==1){
			if((document.cscform.bill_nets.value.replace(/,/g,""))>(returnValue.result*1)){
				if((returnValue.result*1)>0){
						document.cscform.bill_nets.value=returnValue.result;
						insertComma(document.cscform.bill_nets);
						alert(MyCode[226]+" "+document.cscform.bill_nets.value);
						addRecord();
					}else{
						document.cscform.bill_nets.value=returnValue.result;
						insertComma(document.cscform.bill_nets);
						alert(MyCode[227]);						
					}
			}else{
			addRecord();
		}	
		}else{
			addRecord();
		}		
	};

			function addRecord(){	
				if( nullCheck() ){
					var isEdit = new Boolean(false);
					var listValue = new Array(30);
					//var record;
					var bill_record;

					//if( document.cscform.screen_record.value != '' && document.cscform.wf_record.value != '' ){
					if( document.cscform.screen_record.value != '' ){
						//record = document.cscform.wf_record.value;
						bill_record = document.cscform.screen_record.value;
						isEdit = true;
					}else{
						//record = window.opener.document.cscform.__wf__record.value;
						bill_record = window.opener.document.cscform.__wf__no_bill_record.value;
						//record++;
						bill_record++;
					}
					if( checkDupBillNo(document.cscform.bill_no.value, document.cscform.__bill_name.value, document.cscform.__bill_name.options[document.cscform.__bill_name.options.selectedIndex].text, isEdit) ){
						with(document.cscform){
							listValue[0]  = '<INPUT TYPE="checkbox" NAME="no_bill_checkboxs'+bill_record+'" VALUE="'+bill_no.value+'" ID="no_bill_checkboxs'+bill_record+'">';
							listValue[1]  = bill_travel_date.value;
							listValue[2]  = bill_no.value;
							listValue[3]  = '<A HREF="JavaScript:goEditNoBill(\''+bill_record+'\', false);">'+__bill_name.options[__bill_name.options.selectedIndex].text+'</A>';
							listValue[4]  = bill_nets.value;
							listValue[5]  = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$expendid$'+bill_no.value+'" VALUE="0" ID="hide_no_bill_expendid'+bill_no.value+'">';
							listValue[6]  = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$billdate$'+bill_no.value+'" VALUE="'+bill_date.value+'" ID="hide_no_bill_date'+bill_no.value+'">';
							listValue[7]  = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$billno$'+bill_no.value+'" VALUE="'+bill_no.value+'" ID="hide_no_bill_no'+bill_no.value+'">';
							listValue[8]  = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$costtype$'+bill_no.value+'" VALUE="'+__bill_name.value+'" ID="hide_no_bill_name'+bill_no.value+'">'+
											'<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$billname$'+bill_no.value+'" VALUE="'+ __bill_name.options[__bill_name.options.selectedIndex].text+'" ID="hide_bill_name_show'+bill_no.value+'">';
							listValue[9]  = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$nets$'+bill_no.value+'" VALUE="'+bill_nets.value+'" ID="hide_no_bill_nets'+bill_no.value+'">';
							listValue[10] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$hotelcompany$'+bill_no.value+'" VALUE="" ID="hide_no_bill_company'+bill_no.value+'">';
							listValue[11] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$hoteltaxno$'+bill_no.value+'" VALUE="" ID="hide_no_bill_taxno'+bill_no.value+'">';
							listValue[12] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$hoteladdr$'+bill_no.value+'" VALUE="" ID="hide_no_bill_addr'+bill_no.value+'">';
							listValue[13] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$hotelzipcode$'+bill_no.value+'" VALUE="" ID="hide_no_bill_zipcode'+bill_no.value+'">';
							listValue[14] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$amount$'+bill_no.value+'" VALUE="" ID="hide_no_bill_amount'+bill_no.value+'">';
							listValue[15] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$vat$'+bill_no.value+'" VALUE="" ID="hide_no_bill_vat'+bill_no.value+'">';
							listValue[16] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$workarea$'+bill_no.value+'" VALUE="'+bill_workarea.value+'" ID="hide_no_bill_workarea'+bill_no.value+'">';
							listValue[17] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$workarea_desc$'+bill_no.value+'" VALUE="'+bill_workarea_desc.value+'" ID="hide_no_bill_workarea_desc'+bill_no.value+'">';
							listValue[18] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$coscenter$'+bill_no.value+'" VALUE="'+bill_cost_center.value+'" ID="hide_no_bill_cost_center'+bill_no.value+'">';
							listValue[19] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$coscenter_desc$'+bill_no.value+'" VALUE="'+bill_cost_center_desc.value+'" ID="hide_no_bill_cost_center_desc'+bill_no.value+'">';
							listValue[20] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$budget$'+bill_no.value+'" VALUE="'+bill_budget.value+'" ID="hide_no_bill_budget'+bill_no.value+'">';
							listValue[21] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$budget_desc$'+bill_no.value+'" VALUE="'+bill_budget_desc.value+'" ID="hide_no_bill_budget_desc'+bill_no.value+'">';
							listValue[22] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$remark$'+bill_no.value+'" VALUE="'+bill_remark.value+'" ID="hide_remark'+bill_no.value+'">';
							listValue[23] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$billstatus$'+bill_no.value+'" VALUE="0" ID="hide_no_bill_status'+bill_no.value+'">';
							listValue[24] = bill_record;
							listValue[25] = bill_no.value;
							listValue[26] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$km$'+bill_no.value+'" VALUE="'+bill_km.value+'" ID="hide_no_bill_km'+bill_no.value+'">';
							listValue[27] = bill_remark.value;
							listValue[28] = bill_km.value;
							listValue[29] = bill_workarea_desc.value;
							
							listValue[30] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$tobranch$'+bill_no.value+'" VALUE="'+bill_tobranch.value+'" ID="hide_no_bill_tobranch'+bill_no.value+'">';
							listValue[31] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$tobranch_desc$'+bill_no.value+'" VALUE="'+bill_tobranch_desc.value+'" ID="hide_no_bill_tobranch_desc'+bill_no.value+'">';
							listValue[32] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$starttime$'+bill_no.value+'" VALUE="'+bill_starttime.value+'" ID="hide_no_bill_starttime'+bill_no.value+'">';
							listValue[33] = bill_starttime.value;
							listValue[34] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$endtime$'+bill_no.value+'" VALUE="'+bill_endtime.value+'" ID="hide_no_bill_endtime'+bill_no.value+'">';
							listValue[35] = bill_endtime.value;
							listValue[36] = bill_tobranch_desc.value;
							listValue[37] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$exp_costcenter$'+bill_no.value+'" VALUE="'+bill_exp_costcenter.value+'" ID="hide_no_bill_exp_costcenter'+bill_no.value+'">';
							listValue[38] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$travel_date$'+bill_no.value+'" VALUE="'+bill_travel_date.value+'" ID="hide_no_bill_travel_date'+bill_no.value+'">';
							listValue[39] = bill_workarea.value;
							listValue[40] = bill_tobranch.value;
							listValue[41] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$exp_compid$'+bill_no.value+'" VALUE="'+bill_exp_compid.value+'" ID="hide_no_bill_exp_compid'+bill_no.value+'">';
							listValue[42] = '<INPUT TYPE="hidden" NAME="__wf__texpend_cost_other$exp_buaid$'+bill_no.value+'" VALUE="'+bill_exp_buaid.value+'" ID="hide_no_bill_exp_buaid'+bill_no.value+'">';
						}
						if((document.cscform.oldtotal.value*1)>0&&(document.cscform.oldamount.value*1)>0){
								window.opener.document.cscform.__wf__total_no_bill.value=((document.cscform.oldtotal.value*1)-(document.cscform.oldamount.value*1));
								window.opener.document.cscform.__wf__total_no_bill.value=(window.opener.document.cscform.__wf__total_no_bill.value*1).toFixed(2);
								checkNumFloat(window.opener.document.cscform.__wf__total_no_bill,0,900000000);					
						}
						window.opener.addRecord('no_bill', listValue, isEdit);
						window.close();
					}
				}
			}

			function editRecord(record){ 
				var listValue = window.opener.getRecordInfo('no_bill', record);			
				if( listValue != null ){
				 document.cscform.oldtotal.value=window.opener.document.cscform.__wf__total_no_bill.value.replace(/,/g,"");
				 document.cscform.oldamount.value=listValue[5].replace(/,/g,"");
				
					with( document.cscform ){
						screen_record.value = record;
						//wf_record.value = listValue[0];
						bill_date.value = listValue[2];
						bill_no.value = listValue[3];
						__bill_name.value = listValue[4];
						bill_nets.value = listValue[5];
						//bill_company.value = listValue[6];
						//bill_taxno.value = listValue[7];
						//bill_addr.value = listValue[8];
						//bill_zipcode.value = listValue[9];
						//bill_amount.value = listValue[10];
						//bill_vat.value = listValue[11];
						bill_workarea.value = listValue[12];
						bill_workarea_desc.value = listValue[13];
						bill_cost_center.value = listValue[14];
						bill_cost_center_desc.value = listValue[15];
						bill_budget.value = listValue[16];
						bill_budget_desc.value = listValue[17];
						bill_remark.value = listValue[18];
						bill_km.value = listValue[19];
						bill_tobranch.value=listValue[20];				
						bill_tobranch_desc.value=listValue[21];
						bill_starttime.value=listValue[22]  ;
						bill_endtime.value=listValue[23] ;
						bill_exp_costcenter.value=listValue[24] ;
						bill_travel_date.value=listValue[25] ;
						bill_exp_compid.value=listValue[41] ;
						bill_exp_buaid.value=listValue[42] ;						
							
						bill_date.readOnly = true;
						document.getElementById("sp_date").style.display = "none";
						//bill_name.readOnly = true;
						bill_no.readOnly = true;
					}
				}
			}

			function checkDupBillNo(chk_bill_date, chk_bill_name, bill_name_desc, isEdit){
				/*with( window.opener ){
					if( isEdit == false ){
						var temp;
						var bill_record = document.cscform.__wf__no_bill_record.value;
						for( i = 1 ; i <= bill_record ; i++ ){
							temp = dwr.util.getValue("no_bill_name" + i);
							if( temp != '' ){
								temp = temp.substring(temp.indexOf(' value=')+7);
								temp = temp.substring(0, temp.indexOf(' '));
								if( chk_bill_date == dwr.util.getValue("no_bill_date_show" + i) && chk_bill_name == temp ){
									alert("รายการ "+bill_name_desc+" ซ้ำ");
									return false;
								}
							}
						}
					}

					return true;
				}*/
				return true;
			}

			function goCancel(){
				window.close();
			}

			function nullCheck(){
			if( chAction() ){
				with( document.cscform ){
					var fieldName = new Array();
					// split __notNull to array
					if( (__notNull.value != "") && (__notNull.value !=null) ){
						fieldName= __notNull.value.split(",");
					}
					for( i = 0 ; i < fieldName.length ; i++ ){
						var tmpelement = document.getElementsByName(fieldName[i]);
						for( index = 0 ; index < tmpelement.length ; index++ ){
							var tmp = tmpelement[index];
							if( tmp.type!= "hidden" && (tmp.value==null ||tmp.value=="") ){
								alert(MyCode[0]);
								tmp.focus();
								if( (typeof __actioned)!="undefined" ){
									__actioned.value="";
								}
								return false;
							}
						}
					}
				}
				return true;
			}else{
				return false;
			}
		}

		function disabledPage(){
			setDisabled(true);
			document.getElementById("sp_date").style.display = "none";
			document.getElementById("sp_mworkarea").style.display = "none";
			document.getElementById("sp_mcost_center").style.display = "none";
			document.getElementById("sp_tobranch").style.display = "none";
			document.getElementById("sp_mbudget").style.display = "none";
			document.getElementById("tr_button").style.display = "none";
		}
		
		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 checkNumFloatNotBlank(obj,limitstart,limitend) {
				with( document.cscform ){
					if(obj.value != "") {
						checkNumFloat(obj,limitstart,limitend)
					} else {
						obj.value = "1.00";	
					}
				}
			}		
			var emp_costcenter ="<%=costcenter%>";
			function postReturn(){
				with(document.cscform){
						var mycostcenter="<%if(!chkNull.chkNullString(request.getParameter("bill_edit")).equals("true") ){ out.print(cost_center);}%>";
						//if(mycostcenter.length>0){
							//mycostcenter=bill_exp_costcenter.value;	
						//}
						//alert(mycostcenter);
						/*
						if(bill_cost_center.value=="540211"|| bill_cost_center.value=="61201004"){
									if(window.opener.document.cscform.__wf__branchid.value=="01100" || window.opener.document.cscform.__wf__branchid.value=="1100"){
										bill_exp_costcenter.value="1100819";
									}else{ 
										bill_exp_costcenter.value=parseFloat(window.opener.document.cscform.__wf__branchid.value)+""+"799";
									}
						}else if(bill_cost_center.value=="540221"||bill_cost_center.value=="61201001"){
										bill_exp_costcenter.value=mycostcenter;
						}else{*/
						if(bill_cost_center.value=="61201001"){
								//bill_exp_costcenter.value="001HOF0610";
								search2(emp_costcenter);
						}else{
								bill_exp_costcenter.value=mycostcenter;
						}
						//}		
				}
			}
			function search2(costcenterid){
                SearchDWR.searchDBXMLAll(new Array("MCOSTCENTER0HELP","mcostcenter0.costcenter_sap","mcostcenter0:costcenterid = '"+costcenterid+"' ","false","langoff"),employee2);
            }

			var employee2 = function(data){
				var empRec=new Array("bill_exp_costcenter");
                if(data.length>0){
                    for(i=0; i<empRec.length; i++){
                        DWRUtil.setValue(empRec[i],data[0][i]);
                    }
                }else{
                    for(i=0; i<empRec.length;i++) {	
                        DWRUtil.setValue(empRec[i],"");
                    }
                }
            }
//-->
		</SCRIPT>
        <script type="text/javascript" src="../JS/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="../JS/jquery/js/jquery-ui.js"></script>
        <script type="text/javascript" src="../JS/jquery.blockUI.js"></script>
        <link href="../JS/jquery/css/redmond/jquery-ui-1.7.1.custom.css" rel="stylesheet" type="text/css">
		<script>		
		<%
					CscCalendar cs3=new CscCalendar();
					cs3.decDate(30);
			%>
			var date30=new Date(<%=cs3.getYear()%>, <%=cs3.getMonth()%>, <%=cs3.getDate()%>);
			function showDate(mypicker){
				$(function() {
					$("#"+mypicker.id).datepicker({dateFormat: "dd-mm-yy",showAnim: "fadeIn",showOn: "focus",direction: 'up',minDate: date30,maxDate:0});
				});
			}
			
		</script>			
	</HEAD>
	<BODY CLASS="body-popup">
		<FORM NAME="cscform" METHOD="post" ACTION="WELEXP_CPN_004_NO_BILL.jsp">
			<INPUT TYPE="hidden" NAME="__screen" VALUE="WELEXP_CPN_004_NO_BILL">
			<INPUT TYPE="hidden" NAME="__cmd" VALUE="">
			<INPUT TYPE="hidden" NAME="__help" VALUE="">
			<INPUT TYPE="hidden" NAME="__fixCon" VALUE="">
			<INPUT TYPE="hidden" NAME="__notNull" VALUE="bill_date,__bill_name,bill_nets,bill_workarea,">
			<INPUT TYPE="hidden" NAME="__language" VALUE="<%=screenSingle.getUProfile().get("lang")%>">
			<INPUT TYPE="hidden" NAME="__companyid" VALUE="<%=screenSingle.getUProfile().get("companyid")%>">
			<INPUT TYPE="hidden" NAME="__calendar" VALUE="">
			<INPUT TYPE="hidden" NAME="__wf__employeeid" VALUE="<%=request.getParameter("empid")%>">
			<INPUT TYPE="hidden" NAME="__server_date" value="<%=new CscCalendar().getDDMMYYYY()%>">
			<SCRIPT LANGUAGE="JavaScript">getInputFormatDate();</SCRIPT>

			<!--INPUT TYPE="hidden" NAME="wf_record" VALUE=""-->
			<INPUT TYPE="hidden" NAME="screen_record" VALUE="">
			<INPUT TYPE="hidden" NAME="bill_no" VALUE="<%=new CscCalendar().getTime()%>">
			<INPUT TYPE="hidden" NAME="oldtotal" VALUE="0">
			<INPUT TYPE="hidden" NAME="oldamount" VALUE="0">

			<!-- Begin Code -->
			<TABLE WIDTH="95%" 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">
							<TR>
								<TD COLSPAN="2" CLASS="column-title center"><SCRIPT LANGUAGE="JavaScript">swapLang('Expense list')</SCRIPT></TD>
							</TR>
							<TR>
								<TD WIDTH="25%" CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('วันที่ตามใบเสร็จ')</SCRIPT></TD>
								<TD WIDTH="75%" CLASS="column-input"><INPUT TYPE="text" NAME="bill_date"  id="bill_date" SIZE="10" VALUE="" onClick="showDate(this);" readonly <%if(!chkNull.chkNullString(request.getParameter("disable")).equals("true")){%>onFocus="showDate(this);"  onMouseDown="showDate(this);" <%}%>>&nbsp;<SPAN ID="sp_date" STYLE="display:;"><!--A HREF="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bill_date','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" ALT="Calendar" NAME="billDateImg" WIDTH="20" BORDER="0" ALIGN="absmiddle" ID="billDateImg" onClick="viewCal('bill_date')"></A--></SPAN></TD>
							</TR>
							<%
							DbRecord texpend_cost_other_dr = new InitialRecord(TEMPLATE_WORKFLOW.getUProfile()).getDbRecord("TEXPEND_COST_OTHER");
							ListBox listbox = new ListBox();
							listbox.setUProfile(TEMPLATE_WORKFLOW.getUProfile());
							listbox.setName("bill_name");
							//listbox.setValidCode(texpend_cost_other_dr.getField("COSTTYPE").getValidCode());
							//listbox.setTable("MGLHELP", "payment_code", "description", " status!='BI' ", "payment_code",TEMPLATE_WORKFLOW.getUProfile().get("lang"));
							listbox.setTable("MWELFAREHELP", "WELID", "TDESC", " welgid='0004' ", "WELID",TEMPLATE_WORKFLOW.getUProfile().get("lang"));
							%>
							<TR>
                              <TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Travel date')</SCRIPT></TD>
							  <TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_travel_date"  id="bill_travel_date" SIZE="10" VALUE="" onClick="showDate(this);" readonly <%if(!chkNull.chkNullString(request.getParameter("disable")).equals("true")){%>onFocus="showDate(this);"  onMouseDown="showDate(this);" <%}%>>
							    &nbsp;
							      <!--A HREF="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bill_date','','../IMAGES/BUTTON/SWAP/CALENDAR_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/CALENDAR20.gif" ALT="Calendar" NAME="billDateImg" WIDTH="20" BORDER="0" ALIGN="absmiddle" ID="billDateImg" onClick="viewCal('bill_date')"></A-->
							      </SPAN></TD>
						  </TR>
							<TR>
								<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('List')</SCRIPT></TD>
								<TD CLASS="column-input"><%=listbox.process()%></TD>
							</TR>
							<TR style="display:">
							 <TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Company Code')</SCRIPT></TD>
							  <TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_exp_compid"  size="15" maxLength="15" value="<%=sap_compid%>" class="disabled" readonly></TD>
						  </TR>
							<TR style="display:">
							<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Business Area')</SCRIPT>*</TD>
							  <TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_exp_buaid"  size="15" maxLength="15" value="<%=sap_buaid%>" class="disabled" readonly></TD>
						  </TR>
							<TR>
                              <TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Cost Center')</SCRIPT>/WBS*</TD>
							  <TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_exp_costcenter"  size="25" maxLength="20" value="<%=cost_center%>" class="disabled" readonly></TD>
						  </TR>
							<TR style="display:">
								<TD CLASS="column-label" nowrap><SCRIPT LANGUAGE="JavaScript">swapLang('Account Code')</SCRIPT></TD>
								<TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_cost_center" SIZE="10" MAXLENGTH="10" VALUE="<%=accountid%>" readonly class="disabled">&nbsp;<SPAN ID="sp_mcost_center" STYLE="display:;"><A HREF="JavaScript:goHelp('MACCOUNT_EXPHELP','bill_cost_center');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('cost_center_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/SEARCH20.gif" ALT="SEARCH" NAME="cost_center_image" WIDTH="20" HEIGHT="20" BORDER="0" ALIGN="absmiddle"></A>&nbsp;</SPAN><INPUT TYPE="text" NAME="bill_cost_center_desc" SIZE="60" VALUE="<%=accountdesc%>" class="disabled"></TD>
							</TR>	
							<TR>
								<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Begin Branch')</SCRIPT></TD>
								<TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_workarea" SIZE="30" MAXLENGTH="30" VALUE="">&nbsp;<SPAN ID="sp_mworkarea" STYLE="display:none;"><A HREF="JavaScript:goHelp('MBRANCHHELP','bill_workarea');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('workarea_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/SEARCH20.gif" ALT="SEARCH" NAME="workarea_image" WIDTH="20" HEIGHT="20" BORDER="0" ALIGN="absmiddle"></A>&nbsp;<INPUT TYPE="text" NAME="bill_workarea_desc" SIZE="60" VALUE="" class="disabled"></SPAN></TD>
							</TR>													
							<TR>
								<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('To Branch')</SCRIPT></TD>
								<TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_tobranch" SIZE="30" MAXLENGTH="30" VALUE="">&nbsp;<SPAN ID="sp_tobranch" STYLE="display:none;"><A HREF="JavaScript:goHelp('MBRANCHHELP','bill_tobranch');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('workarea_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/SEARCH20.gif" ALT="SEARCH" NAME="workarea_image" WIDTH="20" HEIGHT="20" BORDER="0" ALIGN="absmiddle"></A>&nbsp;<INPUT TYPE="text" NAME="bill_tobranch_desc" SIZE="60" VALUE="" class="disabled"></SPAN></TD>
							</TR>	
							<TR>
                              <TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Start time')</SCRIPT></TD>							  
							  <TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_starttime" onKeyPress="chkInteger()" onBlur="chkTime(this)" size="5" maxLength="4"  class="right"></TD>
							</TR>
							<TR>
								<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('End time')</SCRIPT></TD>
								<TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_endtime"  onkeypress="chkInteger()" onBlur="chkTime(this)" size="5" maxLength="4"  class="right">&nbsp;</TD>
							</TR>
							<TR style="display:none">
								<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('IO')</SCRIPT></TD>
								<TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_budget" SIZE="10" MAXLENGTH="10" VALUE="">&nbsp;<SPAN ID="sp_mbudget" STYLE="display:;"><A HREF="JavaScript:goHelp('MBUDGET_PTTHELP','bill_budget');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('budget_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)"><IMG SRC="../IMAGES/BUTTON/MAIN/SEARCH20.gif" ALT="SEARCH" NAME="budget_image" WIDTH="20" HEIGHT="20" BORDER="0" ALIGN="absmiddle"></A>&nbsp;</SPAN><INPUT TYPE="text" NAME="bill_budget_desc" SIZE="60" VALUE="" class="disabled"></TD>
							</TR>
																			
							<TR>
                              <TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Distance')</SCRIPT></TD>
							  <TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_km" SIZE="10" MAXLENGTH="10" VALUE="0.00" onBlur="checkNumFloatNotBlank(this,0,10000000);" onKeypress="checkWordNumber(this.value)" onFocus="callDelComma(this)" onKeyup="checkComma(this,2)" class="right">
							    <SCRIPT LANGUAGE="JavaScript">swapLang('km')</SCRIPT></TD>
						  </TR>
							<TR>
								<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Amount')</SCRIPT></TD>
								<TD CLASS="column-input"><INPUT TYPE="text" NAME="bill_nets" SIZE="10" MAXLENGTH="10" VALUE="0.00" onBlur="checkNumFloatNotBlank(this,0,10000000);" onKeypress="checkWordNumber(this.value)" onFocus="callDelComma(this)" onKeyup="checkComma(this,2)" class="right">&nbsp;<SCRIPT LANGUAGE="JavaScript">swapLang('Baht')</SCRIPT></TD>
							</TR>
							<TR>
								<TD CLASS="column-label"><SCRIPT LANGUAGE="JavaScript">swapLang('Location/Description')</SCRIPT></TD>
								<TD CLASS="column-input"><TEXTAREA NAME='bill_remark' COLS='50' ROWS='5' onKeyPress="chkSpecialStr(event);lockTextareaChar(this, 250);" onKeyUp="chkLimitTextArea(this,250);sysIsEdit();" onBlur="trimValue(this);" onFocus=""></TEXTAREA></TD>
							</TR>
						</TABLE>
					</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>
				<TR>
					<TD COLSPAN="3">&nbsp;</TD>
				</TR>
				<TR ID="tr_button" STYLE="display:;">
					<TD COLSPAN="3" CLASS="right">
						<A HREF="JavaScript:checkValid();"><IMG SRC="../IMAGES/MYNOTE/BUTTON/BUTTON_SUBMIT.gif" WIDTH="89" HEIGHT="37" BORDER="0"></A>
						<A HREF="JavaScript:goCancel();"><IMG SRC="../IMAGES/MYNOTE/BUTTON/BUTTON_CANCEL.gif" WIDTH="89" HEIGHT="37" BORDER="0"></A>
					</TD>
				</TR>
			</TABLE>
			<SCRIPT LANGUAGE="JavaScript">
						//document.cscform.bill_workarea.value=window.opener.document.cscform.__wf__branchid.value;
						//document.cscform.bill_workarea_desc.value=window.opener.document.cscform.__wf__branch.value;
			</SCRIPT>
			<%if( chkNull.chkNullString(request.getParameter("bill_edit")).equals("true") ){%>
			<SCRIPT LANGUAGE="JavaScript">editRecord('<%=chkNull.chkNullString(request.getParameter("bill_record"))%>');</SCRIPT>
			<%}else{%>
				<SCRIPT LANGUAGE="JavaScript">document.cscform.bill_exp_costcenter.value="<%=cost_center%>";postReturn();</SCRIPT>
			<%}%>
			<%if( chkNull.chkNullString(request.getParameter("disable")).equals("true") ){%>
			<SCRIPT LANGUAGE="JavaScript">disabledPage();</SCRIPT>
			<%}%>
		</FORM>
	</BODY>
</HTML>