<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="com.csc.library.entry.HelpEntry,com.csc.library.system.*,com.csc.library.utilities.*,com.csc.library.session.*,com.csc.library.components.*,com.csc.library.report.*,java.util.*;"%>
<jsp:useBean id="SWAPLANGEDIT" class="com.csc.library.system.Task" scope="page" />
<jsp:useBean id="MultiSave" class="com.csc.library.dwr.Multisave" scope="page" />
<%
SWAPLANGEDIT.setChannel(request, response);
HelpEntry screen = (HelpEntry) SWAPLANGEDIT.process("HelpEntry","SWAPLANGSHOW");

CheckNull chk=new CheckNull();
ThaiUtilities thail = new ThaiUtilities();
String condition=thail.ASCII2Unicode(chk.chkNullString(request.getParameter("__fixCon")));
String numpage = chk.chkNullString(request.getParameter("__goPage"),"1");
String cmd = chk.chkNullString(request.getParameter("__cmd"),"");
String jsonHeader = chk.chkNullString(request.getParameter("__jsonHeader"),"");
String objJSON = chk.chkNullString(request.getParameter("__objJSON"),"");
String siteid = chk.chkNullString(request.getParameter("__siteid"),"");
String moduleImport = chk.chkNullString(request.getParameter("__moduleImport"),"");
String module_search = chk.chkNullString(request.getParameter("checkboxmodule"),"CENTER");
String searchthai = chk.chkNullString(request.getParameter("__searchthai"),"");
String searcheng = chk.chkNullString(request.getParameter("__searcheng"),"");
String searchcodeid = chk.chkNullString(request.getParameter("__searchcodeid"),"");

int nextrec = 1;
if(siteid != ""){
	DbInquiry inq_swaplang_detail = new InitialInquiry(screen.getUProfile()).getDbInquiry("SWAPLANG_DETAIL");
	inq_swaplang_detail.setColumn("CODEID");
	inq_swaplang_detail.setFilter("SITEID = '"+siteid+"' AND CODEID LIKE 'SW%'");
	inq_swaplang_detail.setOrderBy("CODEID DESC");
	inq_swaplang_detail.refresh();
	inq_swaplang_detail.first();
	while(inq_swaplang_detail.next()){
		nextrec += Integer.parseInt(inq_swaplang_detail.getString("CODEID").replaceAll("SW",""));
		break;
	}
	inq_swaplang_detail.closeConnection();
}

//--------------------- Set MultiSave Bean ---------------------------------
String tableName = "swaplang_detail";
String[] tableField = new String[]{"line_no", "siteid", "codeid", "thai", "eng", "module"};
MultiSave.setUProfile(screen.getUProfile());
MultiSave.setNextRecord(nextrec);
MultiSave.setTable(tableName);
MultiSave.setField(tableField);
MultiSave.setJsonHeader(jsonHeader);

if (cmd.equalsIgnoreCase("save")) {
	System.out.println("*********************** save condition ***********************");
	MultiSave.setObjJson(objJSON);
	MultiSave.saveRecord();
	cmd = "savecomplete";
}

if (cmd.equalsIgnoreCase("delete")) {
	System.out.println("*********************** delete condition ***********************");
	MultiSave.setObjJson(objJSON);
	MultiSave.deleteRecord();
	cmd = "deletecomplete";
}

if (cmd.equalsIgnoreCase("addchild")) {
	System.out.println("*********************** addchild condition **********************");
	searchcodeid = "";
	objJSON = "{\"savejson\":[{\"line_no\":\"0\",\"siteid\":\""+siteid+"\",\"codeid\":\""+searchcodeid+"\",\"thai\":\""+searchthai+"\",\"eng\":\""+searcheng+"\",\"module\":\""+module_search+"\"}]}";
	MultiSave.setObjJson(objJSON);
	MultiSave.saveRecord();
	//condition = "siteid='"+siteid+"' and line_no="+String.valueOf(nextrec);
	condition = "siteid='"+siteid+"' and thai='' and eng=''";
}

if (cmd.equalsIgnoreCase("import")) {
	System.out.println("*********************** import condition ***********************");
	MultiSave.setSiteId(siteid);
	MultiSave.setJsonHeader("changelanguage");
	MultiSave.setObjJson(objJSON);
	MultiSave.ImportXmlToSave();
	cmd = "importcomplete";
}

ReportUDF udf = new ReportUDF();
String[] listModule = udf.getSystemCode("MODULETYPE_SWAPLANG",screen.getUProfile().get("lang"));

ListBox listboxStandard = new ListBox();
listboxStandard.setUProfile(screen.getUProfile());
listboxStandard.setName("Module_option"); //ชื่อ ListBox
listboxStandard.setValidCode("MODULETYPE_SWAPLANG"); //tag Systemcode ที่เรียกใช้
listboxStandard.setDisable("false");
listboxStandard.setChecked("01");

int maxLine = 50;
screen.setMaxLine(maxLine);
screen.getInquiry().setFilter(condition);
screen.process();
screen.getInquiry().setOrderBy("CODEID ASC");
screen.getInquiry().refresh();
%>
<html ng-app="myHR">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<link href="../CSS/TISCO.css" rel="stylesheet" type="text/css"/>
		<link href="../CSS/bootstrap.css" rel="stylesheet"  type="text/css">
		<link href="../CSS/bootstrap_csc_backend.css" rel="stylesheet"  type="text/css">
		<script type="text/javascript" src="../JS/jquery-2.1.3.min.js"></script>
		<script type='text/javascript' src="../JS/bootstrap.js"></script>
		<script  language="JavaScript" src="../JS/SCREEN.js"></script>
		<script type='text/javascript' src="../JS/ICONSMENU.js"></script>
		<script language='javascript' src="../JS/HOTKEY.js"></script>
		<script language='javascript'>setLang('<%=screen.getUProfile().get("lang")%>');</script>
		<script src="../JS/jquery-1.11.2.js" type="text/javascript"></script>
		<script src="../JS/jquery-ui-1.11.4.js" type="text/javascript"></script>
		<script type='text/javascript' src='/hr/dwr/interface/ChkDuplicateValue.js'></script>
		<script type='text/javascript' src='/hr/dwr/interface/export_xml.js'></script>
		<script type='text/javascript' src='/hr/dwr/engine.js'></script>
		<script type='text/javascript' src='/hr/dwr/util.js'></script>
		<script src="../JS/angular-1.3.15/angular.js"></script>
		<script type='text/JavaScript' SRC='../JS/ANGULAR/SCREEN_ANGULAR.js'></script>
		<link href="../CSS/jquery-ui-csc.css" rel="stylesheet" type="text/css"/>
		<style>
		input:focus { background-color: #99ccff; }
		.texterror { background-color: red; }
		.lineerror { background-color: red; }
		.portlet-import { cursor: pointer; }
		.portlet-export { cursor: pointer; }
		.portlet-delete { cursor: pointer; }
		.portlet-popup { position: absolute; display: block; }
		.swaplang_search_hide { display: none; }
		.swaplang_search_show { }
		.New_type { }
		.style1 {font-size: 12px}
		.bgwhite {background-color: white}
		</style>
		<script language="JavaScript" type="text/JavaScript">

		var strCMD = "<%=cmd%>";
		var lang = "<%=screen.getUProfile().get("lang")%>";
		switch (strCMD) {
			case "savecomplete":
			if(lang === 'tha'){
				alert('บันทึกเรียบร้อย');
			} else {
				alert('Save Data Successful');
			}
			break;
			case "importcomplete":
			if(lang === 'tha'){
				alert('นำเข้าข้อมูลเรียบร้อย');
			} else {
				alert('Import Data Successful');
			}
			break;
			case "deletecomplete":
			if(lang === 'tha'){
				alert('ลบเรียบร้อย');
			} else {
				alert('Delete Data Successful');
			}
			break;
		}

		//------------------- Global Variable -----------------------//
		var inputvalue;
		var jsObjJSON = {};
		var jsonArray = [];

		function alertSiteId(){
			if(lang === 'tha'){
				alert('กรุณาเลือกไซด์');
			} else {
				alert('Please Choose SiteID');
			}
		}

		function GoSearch(){
			with(document.cscform){
				var filterheal="";
				var modulecodition = setAndGetCheckedValueModule();
				filterheal=checkCondition(filterheal,__siteid,"siteid");
				filterheal=checkCondition(filterheal,__searchthai,"thai");
				filterheal=checkCondition(filterheal,__searcheng,"eng");
				filterheal=checkCondition(filterheal,__searchcodeid,"codeid");
				if(modulecodition != ""){
					filterheal=checkFilter(filterheal);
					filterheal+="module in("+modulecodition.substring(0,modulecodition.length-1)+")";
				}
				__fixCon.value=filterheal;
				//console.log(__fixCon.value);
				search();
			}
		}

		function setAndGetCheckedValueModule(){
			var modulecodition = "";
			$('input[name="checkboxmodule"]:checked').each(function() {
				var getvalue = $(this).val();
				modulecodition += "'"+getvalue+"'";
				modulecodition += ","
			});
			$('input[name="__getcheckvalue"]').val(modulecodition);
			return modulecodition;
		}

		function checkFilter(fil){
			if(fil.length>0)
			fil+=" and ";
			return fil;
		}

		function checkCondition(filcon,objname,targetname){
			with(document.cscform){
				if(objname.value.length>0 && targetname === "siteid"){
					filcon=checkFilter(filcon);
					filcon+= targetname+"='"+objname.value+"'";
				} else if (objname.value.length>0){
					filcon=checkFilter(filcon);
					var find = '"';
					var repOriginalValue = new RegExp(find, 'g');
					var value = objname.value;
					value = value.replace(repOriginalValue,'\\\"');
					filcon+= "upper("+targetname+") like upper('%"+value+"%')";
				}
				return filcon;
			}
		}

		function GoDelete(){}
		function GoUpdate(){}
		function goHelp(helpName,inputName){
			with(document.cscform){
				var helpReturn;
				var fixcon=__fixCon.value;
				__fixCon.value="";
				if(inputName==="__siteid" ){ helpReturn="__siteid:siteid"; }
				linkHelp_Return(helpName,helpReturn);
				__fixCon.value=fixcon;
			}
		}

		function linkHelp(input){
			var param="PRU084.jsp?__helpName=MSITENAMEHELP&__helpReturn="+input+":siteid&__pageCall=SWAPLANGEDIT&__fixCon=&__checkVerify=off";
			win = window.open(param,"Help","left=150,top=150,width=600,height=400,toolbar=no,status=yes,scrollbars=yes,resizable=yes");
			if(window.focus){win.focus();}
		}

		function GoClean(){
			with(document.cscform){
				decheckAll();
				__siteid.value="";
				__searchcodeid.value="";
				__searchthai.value="";
				__searcheng.value="";
				__cmd.value="";
			}
		}

		function checkEmpty(){
			with(document.cscform){
				if(__siteid.value === ""){
					__siteid.focus();
					return true;
				}
				return false;
			}
		}

		function goPage(page){
			with(document.cscform){
				__goPage.value=page;
				submit();
			}
		}

		function GoSave() {
			with(document.cscform){
				var obj = { savejson : jsonArray };
				$.extend(true, jsObjJSON, obj);
				//console.log("jsObjJSON ==> "+JSON.stringify( jsObjJSON ));
				__objJSON.value = JSON.stringify( jsObjJSON );
				__cmd.value = "save";
				submit();
			}
		}

		function deleteChild() {
			with(document.cscform){
				var deleteArray = [];
				var i = 1;
				var obj = { savejson : deleteArray };
				$(".delcb").each(function(index,value){
					if($(this).is(':checked')){
						var value = $(this).val().split("$");
						deleteArray.push({"siteid":value[0],"line_no":value[1]});
						i++;
					}
				});
				$.extend(true, jsObjJSON, obj);
				//console.log("jsObjJSON ==> "+JSON.stringify( jsObjJSON ));
				__objJSON.value = JSON.stringify( jsObjJSON );
				__cmd.value = "delete";
				submit();
			}
		}

		function addChild(){
			with(document.cscform){
				if(!checkEmpty()){
					setAndGetCheckedValueModule();
					__fixCon.value = "";
					__cmd.value = "addchild";
					submit();
				} else {
					alertSiteId();
				}
			}
		}

		function GoExport(){
			with(document.cscform){
				var chk = true;
				var getRadioLangValue = $('input[name="exportradio"]:checked').val();
				var getRadioConditionValue = $('input[name="conditionradio"]:checked').val();

				var getSiteID = "";
				if($('input[name="siteid_export"]').val() !== ""){
					getSiteID = $('input[name="siteid_export"]').val();
				} else {
					alertSiteId();
					chk = false;
				}

				var chkArray = [];
				var getTypeExport = $('input[name="type_exportradio"]:checked').val();
				if(getTypeExport === "OLD"){
					getRadioLangValue = "OLD";
				}
				$('input[name="module_export"]:checked').each(function() {
					var getCode = $(this).val();
					chkArray.push(getCode);
				});
				if(chkArray.length === 0){ //CheckModule
					if(lang === 'tha'){
						alert('กรุณาเลือก Module');
					} else {
						alert('Please Choose Module');
					}
					chk = false;
				}
				if(chk){
					//console.log("getSiteID  ==> "+getSiteID+", getRadioLangValue  ==> "+getRadioLangValue+", getRadioConditionValue  ==> "+getRadioConditionValue+", chkArray  ==> "+chkArray+", getTypeExport  ==> "+getTypeExport);
					export_xml.export_zip(getSiteID, getRadioLangValue, getRadioConditionValue, chkArray, getTypeExport, callBackJ);
					$("#modal_export_file").dialog('close');
				}
			}
		}

		function callBackJ(data){
			var filename = data;
			var param="../FileDownload.jsp?uploadfield=export_xml.xmlmenu&filename="+filename;
			win = window.open(param,"Export File");
		}

		function swaptype(obj){
			with(document.cscform){
				/*
				var type_swap = document.getElementById("New_type");
				var data = obj.value;
				if( data == "NEW"){
					type_swap.style.display = "";
				} else {
					type_swap.style.display = "none";
				}
				*/
			}
		}

		function enterPress(event){
			if(event.keyCode === 13){
				document.getElementById('GoSearch').focus();
			}
		}

		$(document).ready(function(){
			var beforeinput = "";
			$(".inputcode").focus(function() {
				beforeinput = $(this).val();
			});
			$(".inputcode").change(function() {
				var this_attr_name = $(this).attr('name');
				var this_module = this_attr_name;
				this_module = this_module.replace("CODEID","MODULE");
				var this_siteid = this_attr_name;
				this_siteid = this_siteid.replace("CODEID","SITEID");

				var this_codeid_value = $(this).val();
				var this_module_value = $("select[name$='"+this_module+"']").val();
				var this_siteid_value = $("input[name$='"+this_siteid+"']").val();
				var chk = true;

				$(".inputcode").each(function(){
					var each_attr_name = $(this).attr('name');
					each_attr_name = each_attr_name.replace("CODEID","MODULE");
					var chkmodule = $("select[name$='"+each_attr_name+"']").val();
					each_attr_name = each_attr_name.replace("MODULE","SITEID");
					var chksiteid = $("input[name$='"+each_attr_name+"']").val();
					var chkcodeid = $(this).val();

					if($(this).attr('name') !== this_attr_name){
						if(this_siteid_value === chksiteid && this_codeid_value === chkcodeid && this_module_value === chkmodule){
							chk = false;
						}
					}
				});

				if(chk){
					chkDuplicateValue(this_siteid_value, this_codeid_value, this_module_value, this_attr_name, beforeinput);
				} else {
					var data = ["TRUE", this_attr_name, beforeinput];
					callBackBoolean(data);
				}
			});

			function chkDuplicateValue(siteid, codeid, module, inputname, beforeinput){
				ChkDuplicateValue.process(siteid, codeid, module, inputname, beforeinput, callBackBoolean);
			}

			function callBackBoolean(data){
				if(data[0] === "TRUE"){
					if(lang === 'tha'){
						alert('รหัสภาษาซ้ำ\nกรุณากรอกรหัสภาษาใหม่');
					} else {
						alert('CODEID Has Duplicate\nPlease Try Again');
					}
					$("input[name$='"+data[1]+"']").val(data[2]);
				} else {
					setObjValue(data[1]);
				}
			}
			$( ".swaplang_chkinput input" ).focus(function() {
				inputvalue = $(this).val();
				$(this).blur(function(){
					if($(this).val() != inputvalue){
						setObjValue($(this).attr('name'));
					}
				});
			});

			$( ".swaplang_chkinput select" ).change(function() {
				setObjValue($(this).attr('name'));
			});

			function setObjValue(dataname){
				var inputname = dataname.split("$");
				var siteid = inputname[1];
				var line_no = inputname[2];

				inputname = "__SITEID$"+siteid+"$"+line_no;
				var siteid = $("input[name$='"+inputname+"']").val();

				inputname = "__CODEID$"+siteid+"$"+line_no;
				var codeid = $("input[name$='"+inputname+"']").val();

				inputname = "__THAI$"+siteid+"$"+line_no;
				var thai = $("input[name$='"+inputname+"']").val();

				inputname = "__ENG$"+siteid+"$"+line_no;
				var eng = $("input[name$='"+inputname+"']").val();

				inputname = "__MODULE$"+siteid+"$"+line_no;
				var module = $("select[name$='"+inputname+"']").val();

				setObjArray(line_no, siteid, codeid, thai, eng, module);
				//console.log("jsonArray ==> "+JSON.stringify( jsonArray ));
			}

			function setObjArray(line_no, siteid, codeid, thai, eng, module){
				var chk = true;
				for (var i=0; i<jsonArray.length; i++){
					if (jsonArray[i]["line_no"]) {
						var valueOldLineNo = jsonArray[i]["line_no"];
						var valueOldSiteId = jsonArray[i]["siteid"];
						if(valueOldLineNo === line_no && valueOldSiteId === siteid){
							jsonArray[i]["line_no"] = line_no;
							jsonArray[i]["siteid"] = siteid;
							jsonArray[i]["codeid"] = codeid;
							jsonArray[i]["thai"] = thai;
							jsonArray[i]["eng"] = eng;
							jsonArray[i]["module"] = module;
							chk = false;
						}
					}
				}

				if(chk){
					jsonArray.push({"line_no":line_no, "siteid":siteid, "codeid":codeid, "thai":thai, "eng":eng, "module":module});
				}
			}

			//----------------- Set Dialog UI import  -------------------
			$("#modal_import_file").dialog({
				autoOpen: false,
				minHeight: 100,
				width: 600,
				modal: true,
				closeOnEscape: true,
				draggable: false,
				resizable: false,
				buttons: {
					'Yes': function(){
						callbackimport();
					},
					'No': function(){
						$(this).dialog('close');
					}
				}
			});
			$("#modal_export_file").dialog({
				autoOpen: false,
				minHeight: 200,
				width: 500,
				modal: true,
				closeOnEscape: true,
				draggable: false,
				resizable: false,
				buttons: {
					'Yes': function(){
						GoExport();
					},
					'No': function(){
						$(this).dialog('close');
					}
				}
			});
			$("#modal_confirm_delete").dialog({
				autoOpen: false,
				minHeight: 100,
				width: 350,
				modal: true,
				closeOnEscape: true,
				draggable: false,
				resizable: false,
				buttons: {
					'Yes': function(){
						deleteChild();
						$(this).dialog('close');
					},
					'No': function(){
						$(this).dialog('close');
					}
				}
			});

			//----------------- delete -------------------
			$(".portlet-delete").click( function() {
				$("#modal_confirm_delete").dialog( "option", "position", { my: "center top", at: "center top+200", of: window } ).dialog('open');
			});
			//----------------- export -------------------
			$(".portlet-export").click( function() {
				setModuleExport();
				$("input[name='siteid_export']").val($("input[name='__siteid']").val());
				$("#modal_export_file").dialog( "option", "position", { my: "center top", at: "center top+200", of: window } ).dialog('open');
			});

			//------ function Export -------
			function setModuleExport(){
				var mainModule = "";
				$(".module_main").each(function(){
					if($(this).prop('checked')){
						if(mainModule !== ""){
							mainModule += ",";
						}
						mainModule += $(this).val();
					}
				});

				var mainArray = mainModule.split(",");
				//console.log("Main module ==> "+mainArray);
				$(".module_export").each(function(){
					if($.inArray( $(this).val(), mainArray ) !== -1){
						$(this).prop('checked',true);
						//console.log("true");
					} else {
						$(this).prop('checked',false);
						//console.log("false");
					}
				});
			}

			//----------------- import -------------------
			$(".portlet-import").click( function() {
				if(!checkEmpty()){
					$("#modal_import_file").dialog( "option", "position", { my: "center top", at: "center top+200", of: window } ).dialog('open');
				} else {
					alertSiteId();
				}
			});

			$('#filesimport').on('change', function(evt) {
				var files = evt.target.files; // FileList object
				$('#filesimportlist').empty();
				// Loop through the FileList
				for (var i = 0, f; f = files[i]; i++) {

					var reader = new FileReader();

					// Closure to capture the file information.
					reader.onload = (function(theFile) {
						return function(e) {
							// Print the contents of the file
							var span = document.createElement('span');
							span.innerHTML = ['<p filename="'+theFile.name+'">',e.target.result,'</p>'].join('');
							document.getElementById('filesimportlist').insertBefore(span, null);
						};
					})(f);
					reader.readAsText(f);
				}
			});

			//------ function Import -------
			function callbackimport(){
				with(document.cscform){
					$("#modal_import_file").dialog( "close" );
					var jsonXmlArray = {"changelanguage":""};
					jsonXmlArray.changelanguage = setXMLtoJSONSwapLang();
					//console.log("jsonXmlArray ==> "+JSON.stringify( jsonXmlArray ));
					__objJSON.value = JSON.stringify(jsonXmlArray);
					__cmd.value = "import";
					submit();
				}
			}

			function setXMLtoJSONSwapLang(){
				var jsonArrayMenu = [];

				$('#filesimportlist > span').each(function(){
					var $tag_p = $(this).find('p');
					var $tag_changelanguage = $(this).find('changelanguage');
					var filename = $tag_p.attr('filename');
					var importlang = getImportLang(filename);
					var importmudule = getImportModuleName(filename);
					$tag_changelanguage.children().each(function(){
						var codeid = $(this).prop("tagName");
						var thistext = $(this).html().replace("<!--[CDATA[","").replace("]]-->","");
						var thai = "";
						var eng = "";
						if(importlang === "THA") {
							thai = thistext;
						} else if(importlang === "ENG") {
							eng = thistext;
						}
						setObjArrayMenu(codeid, thai, eng, importmudule, jsonArrayMenu);
					});
				});

				return jsonArrayMenu;
			}

			function setObjArrayMenu(codeid, thai, eng, importmudule, jsonArrayMenu){
				var chk = true;
				for (var i=0; i<jsonArrayMenu.length; i++){
					if (jsonArrayMenu[i]["codeid"]) {
						var valueOldCodeID = jsonArrayMenu[i]["codeid"];
						if(valueOldCodeID === codeid){
							jsonArrayMenu[i]["codeid"] = codeid;
							if(thai !== "") {
								jsonArrayMenu[i]["thai"] = thai;
							}
							if(eng !== "") {
								jsonArrayMenu[i]["eng"] = eng;
							}
							if(jsonArrayMenu[i]["module"] !== importmudule) {
								jsonArrayMenu[i]["module"] = "CENTER";
							} else {
								jsonArrayMenu[i]["module"] = importmudule;
							}
							chk = false;
						}
					}
				}

				if(chk){
					jsonArrayMenu.push({"codeid":codeid, "thai":thai, "eng":eng, "module":importmudule});
				}

				return jsonArrayMenu;
			}

			function getImportLang(filename){
				var importlang = "";
				if(filename.indexOf("ENG") > -1) {
					importlang = "ENG";
				} else if(filename.indexOf("THA") > -1) {
					importlang = "THA";
				}
				return importlang;
			}

			function getImportModuleName(filename){
				var modulename = "";
				if(filename.indexOf("COMPANY") > -1) {
					modulename = "OI";
				} else if(filename.indexOf("PERSONAL") > -1) {
					modulename = "PSN";
				} else if(filename.indexOf("TA") > -1) {
					modulename = "TA";
				} else if(filename.indexOf("PAYROLL") > -1) {
					modulename = "PR";
				} else if(filename.indexOf("TRAINING") > -1) {
					modulename = "TRN";
				} else if(filename.indexOf("MYNOTE") > -1) {
					modulename = "WF";
				} else if(filename.indexOf("APPRAISAL") > -1) {
					modulename = "APP";
				} else if(filename.indexOf("WELFARE") > -1) {
					modulename = "WEL";
				} else if(filename.indexOf("RECRUIT") > -1) {
					modulename = "REC";
				} else if(filename.indexOf("EMPVIEW") > -1) {
					modulename = "EMP";
				} else if(filename.indexOf("SETTING") > -1) {
					modulename = "SS";
				} else if(filename.indexOf("EXAM") > -1) {
					modulename = "EXAM";
				} else {
					moduleName = filename.split("_")[1];
				}
				return modulename;
			}
		});

		//-->
		</script>
	</head>
	<body>
		<div id="toolTipLayer" style="position:absolute; visibility: hidden"></div>
		<script language="javascript">initToolTips();</script>
		<form name="cscform" method="post" action="SWAPLANGEDIT.jsp">

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

			<%=screen.InitialVariable()%>

			<!----------END CSC INITIAL ZONE -------------------------->
			<input type="hidden" name="__cmd" value=""/>
			<input type="hidden" name="__help" value=""/>
			<input type="hidden" name="__notNull" value=""/>
			<input type="hidden" name="__helpReturn" value=""/>
			<input type="hidden" name="__helpName" value=""/>
			<input type="hidden" name="__pageCall" value=""/>
			<input type="hidden" name="__referPage" value=""/>
			<input type="hidden" name="__language" value="<%=screen.getUProfile().get("lang")%>"/>
			<input type="hidden" name="__lockPage" value=""/>
			<input type="hidden" name="__goPage" value=""/>
			<input type="hidden" name="__calendar"/>
			<input type="hidden" name="__screen" value="SWAPLANGEDIT"/>
			<input type="hidden" name="__webid"/>
			<input type="hidden" name="__readposter"/>
			<input type="hidden" name="__employeeid" value=""/>
			<input type="hidden" name="__docno" value=""/>
			<input type="hidden" name="__formulaid" value=""/>
			<input type="hidden" name="__fixCon" value="<%=condition%>"/>
			<input type="hidden" name="__orderBy" value="<%=request.getParameter("__orderBy")%>"/>
			<input type="hidden" name="__companyid"  value="<%=screen.getUProfile().get("companyid")%>"/>
			<input type="hidden" name="__complainid" value=""/>
			<input type="hidden" name="__getcheckvalue" value="<%=request.getParameter("__getcheckvalue")%>"/>
			<input type="hidden" name="__objJSON" value=""/>
			<input type="hidden" name="__moduleImport" value=""/>
			<input type="hidden" name="__jsonHeader" value="savejson"/>
			<script language="javascript">getInputFormatDate();</script>

			<%
			String[] getCheckValue = {"'start'"};
			String checkNull = request.getParameter("__getcheckvalue");
			if(checkNull!=null && !checkNull.isEmpty()){
				getCheckValue = checkNull.split(",");
			}
			%>

			<script language="JavaScript" src="../JS/HOTKEY.js"></script>
			<script language="javascript">
			var titlename=swap2String('Swap Language Edit');
			document.write(Icons("SWAPLANGEDIT,"+titlename));
			</script>

			<br/>
			<div align="center">
				<table cellpadding="0" cellspacing="0" class="largest">
					<tr>
						<td colspan="2" class="header" >SWAPLANGEDIT, <script language="javascript">swapLang(titlename);</script>&nbsp;</td>
					</tr>
					<tr>
						<td>
							<table class="maxsize" border="0" align="center" cellpadding="0" cellspacing="1">
								<tr>
									<td colspan="12" class="blankspace">
										<table width="638" border="0" align="center" cellpadding="0" cellspacing="1" class="inframe">
											<tr>
												<td colspan="2" class="blankspace"></td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("siteid")%>&nbsp;</td>
												<td class="columnobject1"><%=screen.getInput("siteid")%></td>
											</tr>
											<tr>
												<td class="columnlabel"></td>
												<td class="columnobject1">---------------------------------Search---------------------------------</td>
											</tr>
											<tr>
												<td class="columnlabel">Module&nbsp;</td>
												<td class="columnobject1">
													<table width="200" border="0" align="left" cellpadding="0" cellspacing="1">
														<%
														int count = 0;
														for(int i = 0;i<listModule.length;i++){
															if(i%4==0){
																%>
																<tr>
																	<%
																}
																boolean createCheckedBox = false;
																for(int j =0;j<getCheckValue.length;j++){//Check CheckBox when CheckBox is checked
																	String foo = getCheckValue[j];
																	if(foo.indexOf("'") != -1){ //Check Null Value
																		if(getCheckValue[j].split("'")[1].equals(listModule[i].split(",")[0])){
																			createCheckedBox = true;
																		}
																	}
																}
																if(createCheckedBox){
																	%>
																	<td class="columnobject1">
																		<input type="checkbox" value=<%=listModule[i].split(",")[0]%> name="checkboxmodule" class="module_main" checked/>&nbsp;<%=listModule[i].split(",")[1]%>
																	</td>
																	<%
																} else {
																	%>
																	<td class="columnobject1">
																		<input type="checkbox" value=<%=listModule[i].split(",")[0]%> name="checkboxmodule" class="module_main"/>&nbsp;<%=listModule[i].split(",")[1]%>
																	</td>
																	<%
																}
																count = count + 1;
																if(count>0&&count%4==0){
																	%>
																</tr>
																<%
																count = 0;
															}
														}
														%>
													</table>
												</td>
											</tr>
											<tr>
												<td class="columnlabel">&nbsp;</td>
												<td class="columnobject1">
													<button type="button" class="btn btn-primary width100" swlang code="SW002185" onClick="checkAll();">SELECT ALL</button>
													<button type="button" class="btn btn-primary width100" swlang code="SW013164" onClick="decheckAll();">DESELECT ALL</button>
												</td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("CODEID")%>&nbsp;</td>
												<td class="columnobject1"><input type="Text" name="__searchcodeid" size="50" value="<%=searchcodeid%>" onkeydown="enterPress(event)"></td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("THAI")%>&nbsp;</td>
												<td class="columnobject1"><input type="Text" name="__searchthai" size="50" value="<%=searchthai%>" onkeydown="enterPress(event)"></td>
											</tr>
											<tr>
												<td class="columnlabel"><%=screen.getLabel("ENG")%>&nbsp;</td>
												<td class="columnobject1"><input type="Text" name="__searcheng" size="50" value="<%=searcheng%>" onkeydown="enterPress(event)"></td>
											</tr>
											<tr>
												<td class="columnlabel">&nbsp;</td>
												<td>
													<button type="button" class="btn btn-primary width100" swlang code="SW013168" onClick="GoSearch();">SEARCH</button>
													<span class="portlet-export"><button type="button" class="btn btn-primary width100" swlang code="SW013178">EXPORT</button></span>

												</td></tr>
											<tr>
												<td colspan="2" class="columnlabel"></td>
											</tr>
										</table>
										<br/>
										<div align="right" class="style1"><%=screen.getPageTag()%></div>
										<table width="638" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#808080" class="inframe tablewithborder" id="resultData">
											<tr class="title1">
												<td width="2%" class="row3" align="center"><swaplang code="SW000289"></swaplang></td>
												<td width="4%" nowrap class="row3" align="center"><swaplang code="SW001393"></swaplang></td>
												<td width="5%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","siteid")%></td>
												<td width="15%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","codeid")%></td>
												<td width="25%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","thai")%></td>
												<td width="25%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","eng")%></td>
												<td width="23%" nowrap class="row3" align="center"><%=screen.getLabel("swaplang_detail","module")%></td>
											</tr>
											<%
											if (numpage.indexOf("+") >= 0 || numpage.indexOf("-") >= 0){
												numpage = numpage.substring(1, numpage.length());
											}

											int i = (maxLine * Integer.parseInt(numpage)) - (maxLine - 1);
											while (screen.nextRec()) {
												if(screen.checkLinePage()){
													int line_no = Integer.parseInt(screen.getString("swaplang_detail","line_no"));
													String row_siteid = screen.getString("swaplang_detail","siteid");
													ListBox listbox1 = new ListBox();
													listbox1.setUProfile(screen.getUProfile());
													listbox1.setName("MODULE$"+row_siteid+"$"+line_no); //ชื่อ ListBox
													listbox1.setValidCode("MODULETYPE_SWAPLANG"); //tag Systemcode ที่เรียกใช้
													listbox1.setDisable("false");
													listbox1.setChecked(screen.getString("swaplang_detail","module"));
													%>
													<tr align="center">
														<td><input class="delcb" type="checkbox" name="__DEL$<%=row_siteid%>$<%=line_no%>" value="<%=row_siteid%>$<%=line_no%>"></td>
														<td><%=i%></td>
														<td><%=row_siteid%><input type="hidden" name="__SITEID$<%=row_siteid%>$<%=line_no%>" value="<%=row_siteid%>"></td>
														<td><input type="Text" name="__CODEID$<%=row_siteid%>$<%=line_no%>" size="12" value="<%=screen.getString("swaplang_detail","codeid")%>" class="inputcode"></td>
														<td class="swaplang_chkinput"><input type="Text" name="__THAI$<%=row_siteid%>$<%=line_no%>" size="30" value="<%=screen.getString("swaplang_detail","thai")%>"></td>
														<td class="swaplang_chkinput"><input type="Text" name="__ENG$<%=row_siteid%>$<%=line_no%>" size="30" value="<%=screen.getString("swaplang_detail","eng")%>"></td>
														<td class="swaplang_chkinput"><%=listbox1.process()%></td>
													</tr>
													<%
												}
												if(screen.outLinePage()){ break; }
												i++;
											}
											%>
										</table>
									</td>
								</tr>
								<tr>
									<td colspan="2" class="blankspace"></td>
								</tr>

								<tr>
									<td  class="buttonline" colspan="7"><div align="center">
										<button type="button" class="btn btn-primary width100" swlang code="SW013165" onClick="addChild();">ADD</button>&nbsp;
										<span class="portlet-import"><button type="button" class="btn btn-primary width100" swlang code="SW013167" >BROWSE</button></span>&nbsp;
										<span class="portlet-delete"><button type="button" class="btn btn-primary width100" swlang code="SW013166" >Delete</button></span>
									</div>
									</td>
								</tr>
								<tr>
									<td colspan="2" class="blankspace">
						    		<output id="filesimportlist"></output>
									</td>
								</tr>
								<tr>
									<td colspan="2" class="bottom"></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</div>

			<!---------- POPUP Jquery UI ------------------------>
			<div id="modal_import_file" class="portlet-popup" title="Import File">
				<div id="dialog_tips" align="center">
					<swaplang code="SW011600"></swaplang> :: SWAPLANG.xml
				</div>
				<br/>
				<input type="file" id="filesimport" name="filesimport[]" accept="text/xml,text/json,text/txt" multiple />
			</div>

			<div id="modal_confirm_delete" class="portlet-popup" title="Confirm Delete?">
				<span>
					<swaplang code="SW011601"></swaplang>
				</span>
			</div>

			<div id="modal_export_file" class="portlet-popup" title="Export File">
				<table border="1" class="inframe bgwhite">
					<tr>
						<td width="150">&nbsp;&nbsp;<%=screen.getLabel("siteid")%>&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input name="siteid_export" size="10" readonly="true" alt="SITEID" onmousemver="toolTip('SITEID')" type="Text"/>
							<a href="javascript:linkHelp('siteid_export');" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('siteid_export_image','','../IMAGES/BUTTON/SWAP/SEARCH_SWAP20.gif',1)">
								<img src="../IMAGES/BUTTON/MAIN/SEARCH20.gif" alt="SEARCH" name="siteid_export_image" align="absmiddle" border="0" height="20" width="20"/>
							</a>
						</td>
					</tr>
					<tr>
						<td width="80">&nbsp;&nbsp;Module&nbsp;</td>
						<td width="350">
							<table border="0" align="left" cellpadding="0" cellspacing="1" class="inner2">
								<%
								count = 0;
								for(i = 0;i<listModule.length;i++){
									if(i%2==0){
										%><tr><%
									}
									%>
									<td class="columnobject1">&nbsp;&nbsp;<input type="checkbox" value=<%=listModule[i].split(",")[0]%> name="module_export" class="module_export"/>&nbsp;<%=listModule[i].split(",")[1]%>&nbsp;&nbsp;</td>
									<%
									count = count + 1;
									if(count>0&&count%4==0){
										%></tr><%
										count = 0;
									}
								}
								%>
							</table>
						</td>
					</tr>
					<tr style="display: none;">
						<td width="150">&nbsp;&nbsp;Condition Value&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input type="radio" name="conditionradio" value="MODULE" checked>&nbsp;Module</input>&nbsp;
							<input type="radio" name="conditionradio" value="CENTER">&nbsp;Center</input>&nbsp;
						</td>
					</tr>
					<tr style="display: none;">
						<td>&nbsp;&nbsp;Type Export&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input onclick="swaptype(this);" type="radio" name="type_exportradio" value="OLD">&nbsp;OLD</input>&nbsp;
							<input onclick="swaptype(this);" type="radio" name="type_exportradio" value="NEW" checked>&nbsp;NEW</input>&nbsp;
						</td>
					</tr>
					<tr style="display: none;" id="New_type">
						<td>&nbsp;&nbsp;Language Export&nbsp;</td>
						<td>&nbsp;&nbsp;
							<input type="radio" name="exportradio" value="ALL" checked>&nbsp;All</input>&nbsp;
							<input type="radio" name="exportradio" value="THAI">&nbsp;Thai</input>&nbsp;
							<input type="radio" name="exportradio" value="ENG">&nbsp;Eng</input>&nbsp;
						</td>
					</tr>
				</table>
			</div>
		</form>
	</body>
</html>