//
function check_searchBox() {
	// search bank
	$("input#srchBank").keyup(function() {
		var passedValue = $("input#srchBank").val();
		if(passedValue.val!="") {
			$("div.suggest.one").css("display", "table-row");
			$.post("./includes/pre-register.php?action=searchRec&dest=srchBank", { passedValue: passedValue }, function(data) {
				$("div.suggest.one").html(data);
			});
		}
	});
	$("input#srchBank").blur(function() {
		if($("#srchBank").val()=="") {
			$("div.suggest.one").css("display", "none");
		}
	});
	// search bank account
	$("input#srchBankAcc").keyup(function() {
		var passedValue = $("input#srchBankAcc").val();
		if(passedValue.val!="") {
			$("div.suggest.two").css("display", "table-row");
			$.post("./includes/pre-register.php?action=searchRec&dest=srchBankAcc", { passedValue: passedValue }, function(data) {
				$("div.suggest.two").html(data);
			});
		}
	});
	$("input#srchBankAcc").blur(function() {
		if($("#srchBankAcc").val()=="") {
			$("div.suggest.two").css("display", "none");
		}
	});
	//
	// search income account
	$("input#srchIncAcc").keyup(function() {
		var passedValue = $("input#srchIncAcc").val();
		if(passedValue.val!="") {
			$("div.suggest.one").css("display", "table-row");
			$.post("./includes/pre-register.php?action=searchRec&dest=srchIncAcc", { passedValue: passedValue }, function(data) {
				$("div.suggest.one").html(data);
			});
		}
	});
	$("input#srchIncAcc").blur(function() {
		if($("#srchIncAcc").val()=="") {
			$("div.suggest.one").css("display", "none");
		}
	});
	// search expense account
	$("input#srchExpAcc").keyup(function() {
		var passedValue = $("input#srchExpAcc").val();
		if(passedValue.val!="") {
			$("div.suggest.two").css("display", "table-row");
			$.post("./includes/pre-register.php?action=searchRec&dest=srchExpAcc", { passedValue: passedValue }, function(data) {
				$("div.suggest.two").html(data);
			});
		}
	});
	$("input#srchExpAcc").blur(function() {
		if($("#srchExpAcc").val()=="") {
			$("div.suggest.two").css("display", "none");
		}
	});
	// search category
	$("input#srchCtgry").keyup(function() {
		var passedValue = $("input#srchCtgry").val();
		if(passedValue.val!="") {
			$("div.suggest.one").css("display", "table-row");
			$.post("./includes/pre-register.php?action=searchRec&dest=srchCtgry", { passedValue: passedValue }, function(data) {
				$("div.suggest.one").html(data);
			});
		}
	});
	$("input#srchCtgry").blur(function() {
		if($("#srchCtgry").val()=="") {
			$("div.suggest.one").css("display", "none");
		}
	});
	// search product
	$("input#srchProduct").keyup(function() {
		var passedValue = $("input#srchProduct").val();
		if(passedValue.val!="") {
			$("div.suggest.two").css("display", "table-row");
			$.post("./includes/pre-register.php?action=searchRec&dest=srchProduct", { passedValue: passedValue }, function(data) {
				$("div.suggest.two").html(data);
			});
		}
	});
	$("input#srchProduct").blur(function() {
		if($("#srchProduct").val()=="") {
			$("div.suggest.two").css("display", "none");
		}
	});
	// search vendor
	$("input#srchVendor").keyup(function() {
		var passedValue = $("input#srchVendor").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/pre-register.php?action=searchRec&dest=srchVendor", {passedValue:passedValue}, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	$("input#srchVendor").blur(function() {
		if($("#srchVendor").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});

}
/* ---------------------------------------------
-------------------- banks ---------------------
------------------------------------------------ */
function loadBanks(pageLimit) {
	$("div.dynamicData.one #loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+15;
	$.ajax({
		type: "POST",
		url: "./includes/pre-register.php?action=loadTable&dest=allBanks&myUser="+myUser+"&myRole="+myRole,
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("div.dynamicData.one #loading").css("display", "none");
			$("div.dynamicData.one .load_more_link").addClass('noneLink');
			$("div.dynamicData.one").append(result);
		}
	});
	return false;
}
function addNewBank() {
	swal({
		title: "Add Bank",
		text: 'Give a name to this bank',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(bankname=> {
		if (bankname) {
			$.post("./includes/pre-register.php?action=saveNew&dest=addBank&addedBy="+myUser, { bankname:bankname }, function(data) {
				var addedpos = data.search("added");
				if(addedpos==0) {
					var lastID = data.slice(6,21);
					swal({
						title: "Success!",
						text: "You successfully added new bank.",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=payAccs";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
	return false;
}
function check_editBank() {
	var bankID 		= $("#bankID").val();
	var txtBank 	= $("#txtBank").val();
	var slcStatus 	= $("#slcStatus").val();

	if(txtBank.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please select bank");
		$("#txtBank").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editBank&updatedBy="+myUser, { bankID:bankID, txtBank:txtBank, slcStatus:slcStatus }, function(data) {
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated bank record successfully.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=payAccs";
				}
			);
		} else {
			swal("Oops!", data, "error");

		}
		$("label.process").css("display", "none");
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function catchBank(recID) {
	$.post("./includes/pre-register.php?action=get_recInfo&dest=getBank", { recID: recID, myRole: myRole }, function(data) {
		$("div.twoCols.one header span").html('[1 row]');
		$("div.dynamicData.one").html(data);
	});
	$("div.suggest.one").css("display", "none");
}


/* -----------------------------------------------------
-------------------- bank accounts ---------------------
-------------------------------------------------------- */
function loadBankAccs(pageLimit) {
	$("div.dynamicData.two #loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+15;
	$.ajax({
		type: "POST",
		url: "./includes/pre-register.php?action=loadTable&dest=allBankAccs&myUser="+myUser+"&myRole="+myRole,
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("div.dynamicData.two #loading").css("display", "none");
			$("div.dynamicData.two .load_more_link").addClass('noneLink');
			$("div.dynamicData.two").append(result);
		}
	});
	return false;
}
function simplyAddBankAcc() {
	$("#checkReceipt, #switchReceipt").click(function(){
		$('div#switchReceipt').toggleClass("switchOn");
		if (document.getElementById("saReceipt").checked == true) {
			document.getElementById("saReceipt").checked = false;
		} else {
			document.getElementById("saReceipt").checked = true;
		}
	});
}
function check_addBankAcc() {
	var slcBank 	= $("#slcBank").val();
	var txtAccNum 	= $("#txtAccNum").val();
	var slcWhouse 	= $("#slcWhouse").val();
	var txtMaxAmnt 	= $("#txtMaxAmnt").val();
	var txtBalance 	= $("#txtBalance").val();


	if(slcBank.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please select bank");
		$("#slcBank").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.one").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	if(txtAccNum.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Provide account number");
		$("#txtAccNum").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	if(slcWhouse.length < 1) {
		$("#error3").css("display", "inline");
		$("#error3").html("Select office");
		$("#slcWhouse").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");

	$.post("./includes/pre-register.php?action=saveNew&dest=addBankAcc&addedBy="+myUser, { slcBank:slcBank, txtAccNum:txtAccNum,  slcWhouse:slcWhouse, txtMaxAmnt:txtMaxAmnt, txtBalance:txtBalance }, function(data) {
		var addedpos = data.search("added");
		$("label.process").css("display", "none");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			swal({
				title: "Success!",
				text: "You added new bank account successfully.",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=payAccs\
					&action=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function check_editBankAcc() {
	var bankAccID 	= $("#bankAccID").val();
	var bankAccName = $("#bankAccName").val();
	var slcWhouse 	= $("#slcWhouse").val();
	var txtMaxAmnt 	= $("#txtMaxAmnt").val();
	var slcStatus 	= $("#slcStatus").val();
	var txtBeginBalance 	= $("#txtBeginBalance").val();

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editBankAcc&updatedBy="+myUser, { bankAccID:bankAccID,  bankAccName:bankAccName,slcWhouse:slcWhouse, txtMaxAmnt:txtMaxAmnt, slcStatus:slcStatus, txtBeginBalance:txtBeginBalance }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated bank account successfully.",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=payAccs\
					&action=showInfo&recID="+bankAccID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function catchBankAcc(recID) {
	$.post("./includes/pre-register.php?action=get_recInfo&dest=getBankAcc", { recID: recID, myUser: myUser, myRole: myRole }, function(data) {
		$("div.twoCols.two header span").html('[1 row]');
		$("div.dynamicData.two").html(data);
	});
	$("div.suggest.two").css("display", "none");
}

/* ----------------------------------------------------------------
----------------------- financial accounts ------------------------
-----------------------------------------------------------------*/
function loadIncomeAcc(pageLimit) {
	$("div.dynamicData.one #loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+15;
	$.ajax({
		type: "POST",
		url: "./includes/pre-register.php?action=loadTable&dest=allIncAcc&myUser="+myUser+"&myRole="+myRole,
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("div.dynamicData.one #loading").css("display", "none");
			$("div.dynamicData.one .load_more_link").addClass('noneLink');
			$("div.dynamicData.one").append(result);
		}
	});
	return false;
}
function check_addFncAcc() {
	var accName 	= $("#accName").val();
	var accType 	= $("#accType").val();
	var accCode 	= $("#accCode").val();

	if(accName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide account name");
		$("#accName").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.one").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");

	$.post("./includes/pre-register.php?action=saveNew&dest=addFncAcc&addedBy="+myUser, { accName:accName, accType:accType, accCode:accCode }, function(data) {
		var addedpos = data.search("added");
		$("label.process").css("display", "none");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			swal({
				title: "Success!",
				text: "You added "+accType+" account successfully.",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=fncAccs";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function check_editFncAcc() {
	var accID 		= $("#accID").val();
	var accName 	= $("#accName").val();
	var accCode 	= $("#accCode").val();
	var slcStatus 	= $("#slcStatus").val();

	if(accName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide account name");
		$("#accName").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.one").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editFncAcc&updatedBy="+myUser, { accID:accID, accName:accName, accCode:accCode, slcStatus:slcStatus }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated finance account successfully.",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=fncAccs";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function catchIncAcc(recID) {
	$.post("./includes/pre-register.php?action=get_recInfo&dest=getIncAcc", { recID:recID,myUser:myUser,myRole:myRole }, function(data) {
		$("div.twoCols.one header span").html('[1 row]');
		$("div.dynamicData.one").html(data);
	});
	$("div.suggest.one").css("display", "none");
}
function delIncAcc(accID) {
	swal({
		title: "Are you sure?",
		text: "You going to delete this income account!",
		icon: "warning",
		dangerMode:true,
		buttons: ["Cancel","Yes, delete it!"]
	})
	.then(willDelete=> {
		if(willDelete) {
			$.post("./includes/pre-register.php?action=deleteRec&dest=delIncAcc", { accID:accID }, function(data) {
				if(data=="deleted") {
					swal({
						title: "Success!",
						text: "Selected income acount has been deleted.",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=fncAccs";
					});
				} else {
					swal("Oops", data, "error");
				}
			});
		}
	});
	return false;
}
/* ----------------------------------------------------------------- */
function loadExpAcc(pageLimit) {
	$("div.dynamicData.two #loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+15;
	$.ajax({
		type: "POST",
		url: "./includes/pre-register.php?action=loadTable&dest=allExpAcc&myUser="+myUser+"&myRole="+myRole,
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("div.dynamicData.two #loading").css("display", "none");
			$("div.dynamicData.two .load_more_link").addClass('noneLink');
			$("div.dynamicData.two").append(result);
		}
	});
	return false;
}
function catchExpAcc(recID) {
	$.post("./includes/pre-register.php?action=get_recInfo&dest=getExpAcc", { recID:recID,myUser:myUser,myRole:myRole }, function(data) {
		$("div.twoCols.two header span").html('[1 row]');
		$("div.dynamicData.two").html(data);
	});
	$("div.suggest.two").css("display", "none");
}
function delExpAcc(expID) {
	swal({
		title: "Are you sure?",
		text: "You going to delete this expense account!",
		icon: "warning",
		dangerMode:true,
		buttons: ["Cancel","Yes, delete it!"]
	})
	.then(willDelete=> {
		if(willDelete) {
			$.post("./includes/pre-register.php?action=deleteRec&dest=delExpAcc", { expID:expID }, function(data) {
				if(data=="deleted") {
					swal({
						title: "Success!",
						text: "Selected expense acount has been deleted.",
						icon: "success",
						timer: 1500,
						button: false
					})
						.then(value=> {
							window.location = "./workplace.php?role="+myRole+"&task=general&subtask=fncAccs";
						}
					);
				} else {
					swal("Oops", data, "error");
				}
			});
		}
	});
	return false;
}




/* ---------------------------------------------------------------
---------------------------- vendors -----------------------------
-----------------------------------------------------------------*/
function updateVndorBar() {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	$.ajax({
		type: "POST",
		url: "./includes/pre-register.php?action=setFoundNum&dest=vendors",
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadVendorsTwo(0,'+perPage+');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateVndorBar();
			}, 60000);
		}
	});
}
function loadVendors(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+ perPage;
	$.ajax({
		type: "POST",
		url: "./includes/pre-register.php?action=loadTable&dest=allVndors&myUser="+myUser+"&myRole="+myRole,
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable div#loading").css("display", "none");
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result);
		},
	});
	return false;
}
function loadVendorsTwo(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+ perPage;
	$.ajax({
		type: "POST",
		url: "./includes/pre-register.php?action=loadTable&dest=allVndors&myUser="+myUser+"&myRole="+myRole,
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable div#loading").css("display", "none");
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").html('<div id="record" class="header"><div class="cave button">Action</div><div class="cave vlong">Vendor Name</div><div class="cave smiddle">Phone Number</div><div class="cave middle">Address</div></div>');
			$("#dataTable").append(result);

			(function (){
				//
				$.ajax({
					type: "POST",
					url: "./includes/pre-register.php?action=setFoundNum&dest=vendors",
					cache: false,
					timeout: 2000,
					success: function(numRecs){
						$("#foundNum").html('<label id="count">'+numRecs+'</label> record(s) has been found\
						<span id="refresh"></span>');
					}
				});
				//
			})();
		},
	});
	return false;
}
function check_addVendor() {
	var txtName 			= $("#txtName").val();
	var txtPhone			= $("#txtPhone").val();
	var txtEmail 			= $("#txtEmail").val();
	var txtAddress 			= $("#txtAddress").val();
	var slcCountry 			= $("#slcCountry").val();
	var txtBeginBalance 	= $("#txtBeginBalance").val();

	if(txtName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Provide vendor's full name");
		$("#txtName").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.one").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	if(txtPhone.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Phone number is missing");
		$("#txtPhone").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	if(txtEmail.length > 0) {
		var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(!txtEmail.match(emailExp)) {
			$("#error3").css("display", "inline");
			$("#error3").html("invalid email address");
			$("#txtEmail").css("border-color", "#FF0000");
			if(window.innerWidth<=768) {
				$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
			}
			return false;
		} else { clearErrors(); }
	}

	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");

	$.post("./includes/pre-register.php?action=saveNew&dest=addVendor&addedBy="+myUser, { txtName:txtName, txtPhone:txtPhone, txtEmail:txtEmail, txtAddress:txtAddress, slcCountry:slcCountry, beginBalance:txtBeginBalance}, function(data) {
		var addedpos = data.search("added");
		$("label.process").css("display", "none");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			swal({
				title: "Success!",
				text: "You added new product successfully.",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=supply&subtask=vendors\
					&action=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function check_editVendor() {
	var vndID 				= $("#vndID").val();
	var txtName 			= $("#txtName").val();
	var txtPhone			= $("#txtPhone").val();
	var txtEmail 			= $("#txtEmail").val();
	var txtAddress 			= $("#txtAddress").val();
	var slcCountry 			= $("#slcCountry").val();
	var slcStatus 			= $("#slcStatus").val();
	var txtBeginBalance 	= $("#txtBeginBalance").val();

	if(txtName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Provide vendor's full name");
		$("#txtName").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.one").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	if(txtPhone.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Phone number is missing");
		$("#txtPhone").css("border-color", "#FF0000");
		if(window.innerWidth<=768) {
			$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
		}
		return false;
	} else { clearErrors(); }

	if(txtEmail.length > 0) {
		var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
		if(!txtEmail.match(emailExp)) {
			$("#error3").css("display", "inline");
			$("#error3").html("invalid email address");
			$("#txtEmail").css("border-color", "#FF0000");
			if(window.innerWidth<=768) {
				$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
			}
			return false;
		} else { clearErrors(); }
	}

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editVendor&updatedBy="+myUser, { vndID:vndID, txtName:txtName, txtPhone:txtPhone, txtEmail:txtEmail, txtAddress:txtAddress, slcCountry:slcCountry, slcStatus:slcStatus, beginBalance:txtBeginBalance }, function(data) {
		var addedpos = data.search("added");
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated vendor details successfully.",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=supply&subtask=vendors\
					&action=showInfo&recID="+vndID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function catchVendor(recID) {
	$.post("./includes/pre-register.php?action=get_recInfo&dest=getVendor", { recID:recID,myUser:myUser,myRole:myRole }, function(data) {
		$("div#foundNum").html('<label id="count">1</label> record has been selected.<span id="refresh"></span>');
		$("div#dataTable").html(data);
	});
	$("div.suggest").css("display", "none");
}
function delVendor(vndID) {
	swal({
		title: "Are you sure?",
		text: "You going to delete this vendor!",
		icon: "warning",
		dangerMode:true,
		buttons: ["Cancel","Yes, delete it!"]
	})
	.then(willDelete=> {
		if(willDelete) {
			$.post("./includes/pre-register.php?action=deleteRec&dest=delVendor", { vndID:vndID }, function(data) {
				if(data=="deleted") {
					swal({
						title: "Success!",
						text: "Selected vendor details has been deleted.",
						icon: "success",
						timer: 1500,
						button: false
					})
						.then(value=> {
						location.reload();
					});

				} else {
					swal("Oops", data, "error");
				}
			});
		}
	});
	return false;
}

/* ------------------------------------------------------------
--------------------------- settings --------------------------
--------------------------------------------------------------*/
function closeBblance() {
	swal({
		title: "Are you sure?",
		text: "You going to close begin balance!\nAnd once closed, it can't be used any more.",
		icon: "warning",
		dangerMode:true,
		buttons: ["Cancel","Yes, delete it!"]
	})
	.then(willDelete=> {
		if(willDelete) {
			$.post("./includes/pre-register.php?action=updateExist&dest=closeBblance&updatedBy="+myUser, function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully closed begin balance allowance.",
						icon: "success",
						timer: 1500,
						button: false
					})
						.then(value=> {
							window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
						}
					);
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
function chngBeginBlnce() {
	swal({
		title: "Begin Balance",
		text: 'Please provide amount value to begin with this system',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(amount=> {
		var amntReg = /[0-9]/;
		if (amount) {

			if(amount.match(amntReg)) {

				$.post("./includes/pre-register.php?action=updateExist&dest=chngBeginBlnce&updatedBy="+myUser,{ amount:amount, financeYr:financeYr },function(data){
					if(data=="updated") {
						swal({
							title: "Success!",
							text: "You successfully updated begin balance amount.",
							icon: "success",
							timer: 1500,
							button: false
						})
							.then(value=> {
								window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
							}
						);
					} else {
						swal("Oops!", data, "error");
					}
				});
			}
		}
	});
}
function closeFnYear() {
	swal({
		title: "Are you sure?",
		text: "You going to close financial year!\nAnd once closed, it can't be used any more.",
		icon: "warning",
		dangerMode:true,
		buttons: ["Cancel","Yes, Close Now!"]
	})
	.then(willDelete=> {
		if(willDelete) {
			swal({
				title: "Create new",
				text: 'Please provide new financial year',
				content: "input",
				buttons:["Cancel","Save"]
			})
			.then(fnyear=> {
				var dateReg = /^\d{4}\/\d{4}$/;
				if (fnyear === "") {
					if(fnyear.match(dateReg)) {
						$.post("./includes/pre-register.php?action=saveNew&dest=addFnYear&addedBy="+myUser,{ fnyear:fnyear },function(data){
							var addedpos = data.search("added");
							if(addedpos==0) {
								swal({
									title: "Success!",
									text: "You successfully created new financial year.",
									icon: "success",
									timer: 1500,
									button: false
								})
								.then(value=> {
									window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
								});
							} else {
								swal("Oops!", data, "error");
							}
						});
					}
				}
			});
		}
	});
}
function chngMinSlsPrc() {
	$.post("./includes/pre-register.php?action=updateExist&dest=editShowMinSlsPrce&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
				.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function editSystemVatVal() {

	swal({
		title: "System VAT",
		text: 'Please provide system vat percentage',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(vatPercentage=> {
		if (vatPercentage) {
			if(vatPercentage<=100 && vatPercentage>=0) {
				$.post("./includes/pre-register.php?action=updateExist&dest=editSystemVatVal&updatedBy="+myUser,{ vatPercentage:vatPercentage },function(data){
					if(data=="updated") {
						swal({
							title: "Success!",
							text: "You successfully updated system vat",
							icon: "success",
							timer: 1500,
							button: false
						})
						.then(value=> {
							location.reload();
						});
					} else {
						swal("Oops!", data, "error");
					}
				});
			}
		}
	});

}
function check_editSlsInfo() {
	var slsTitle	= $("#slsTitle").val();
	var txtFooter	= $("#txtRemarks").val();

	if(slsTitle.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide sales title");
		$("#slsTitle").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	if(txtFooter.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Provide sales footer");
		$("#txtRemarks").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editSlsInfo&updatedBy="+myUser, { slsTitle:slsTitle, txtFooter:txtFooter }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You successfully updted sales report info",
				icon: "success",
				timer: 1500,
				button: false,
			})
				.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function check_editSalesPrint() {
	var printTime	= $("#printTime").val();
	var printPaper	= $("#printPaper").val();

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editSalesPrint&updatedBy="+myUser, { printTime:printTime, printPaper:printPaper }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You successfully updted sales report info",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function chngWDrctRcpt() {
	$.post("./includes/pre-register.php?action=updateExist&dest=editWDrctRcpt&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
//
function chngInvoiceColor() {
	swal({
		title: "Invoice Color",
		text: 'Please provide rgb format color\ne.g 255,255,255',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=editInvClor&updatedBy="+myUser,{ newInvColor:value },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
//
function chngposLogoPath() {
	swal({
		title: "POS LOGO",
		text: 'Please provide POS logo path',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngposLogoPath&updatedBy="+myUser,{ posLogoPath:value },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
//
//
function chnTargetIP() {
	swal({
		title: "POS LOGO",
		text: 'Please provide POS logo path \neg.192.168.0.100',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chnTargetIP&updatedBy="+myUser,{ targetIP:value },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
//
function chngUserPayment() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngUserPayment&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					location.reload();
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngUserAsAdminSt() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngUserAsAdminSt&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					location.reload();
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngPrintOrder4BookSt() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngPrintOrder4BookSt&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					location.reload();
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngPrintOrderItemSt() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngPrintOrderItemSt&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					location.reload();
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngCoffeeDrinks() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngCoffeeDrinks&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngSingleCashier() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngSingleCashier&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngPrintToSingleLocation() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngPrintToSingleLocation&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngPrintHeader() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngPrintHeader&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngOrderType() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngOrderType&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngOrderDesgn() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngOrderDesgn&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					location.reload();
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngInvoiceHeader() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngInvoiceHeader&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngInvoiceFooter() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngInvoiceFooter&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngInvoiceContact() {
	swal({
		title: "Invoice Footer Contact",
		text: 'Please provide invoice footer contact',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngInvoiceContact&updatedBy="+myUser,{ value:value, financeYr:financeYr },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated quotation footer contact",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
function chngCoffeePrinterText() {
	swal({
		title: "Change Coffee Printer",
		text: 'Please provide Coffee Printer',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngCoffeePrinterText&updatedBy="+myUser,{ value:value, financeYr:financeYr },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated selected setting",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
function chngDrinksPrinterText() {
	swal({
		title: "Change Drinks Printer",
		text: 'Please provide Drinks Printer',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngDrinksPrinterText&updatedBy="+myUser,{ value:value, financeYr:financeYr },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated selected setting",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
function chngDrinksCoffePrinterText() {
	swal({
		title: "Change Coffee And Drinks Printer",
		text: 'Please provide Coffee And Drinks Printer',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngDrinksCoffePrinterText&updatedBy="+myUser,{ value:value, financeYr:financeYr },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated selected setting",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
function chngkitchenPrinterText() {
	swal({
		title: "Change Kitchen Printer",
		text: 'Please provide Kitchen Printer',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngkitchenPrinterText&updatedBy="+myUser,{ value:value, financeYr:financeYr },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated selected setting",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
function chngAccomInvoice() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngAccomInvoice&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngVenueInvoice() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngVenueInvoice&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
//
function chngRestInvoiceTxt(curValue) {
	swal({
		title: "Edit System Setting",
		text: 'Please check input value',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(newRestInvoiceVal=> {
		if (newRestInvoiceVal) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngRestInvoiceTxt&updatedBy="+myUser, { newRestInvoiceVal:newRestInvoiceVal }, function(data) {
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "Your changes has been saved.",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
							window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
						}
					);
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
	return false;
}
//
function chnghallUnitInvoiceTxt(curValue) {
	swal({
		title: "Edit System Setting",
		text: 'Please check input value',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(newhallUnitVal=> {
		if (newhallUnitVal) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chnghallUnitInvoiceTxt&updatedBy="+myUser, { newhallUnitVal:newhallUnitVal }, function(data) {
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "Your changes has been saved.",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
							window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
						}
					);
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
	return false;
}
//
function editInvClor(curValue) {
	var newInvColor = $("#txtTypeColor").val();
	//
	$.post("./includes/pre-register.php?action=updateExist&dest=editInvClor&updatedBy="+myUser, { newInvColor:newInvColor}, function(data) {
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
	//
	return false;
}
//
function chngInvoice_termsTxt(curValue) {
	swal({
		title: "Edit System Setting",
		text: 'Please check input value',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(newInvtermsVal=> {
		if (newInvtermsVal) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngInvoice_termsTxt&updatedBy="+myUser, { newInvtermsVal:newInvtermsVal }, function(data) {
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "Your changes has been saved.",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
							window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
						}
					);
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
	return false;
}
function check_editInvBanks() {
	var txtFooter	= $("#txtRemarks").val();

	if(txtFooter.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Provide sales footer");
		$("#txtRemarks").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=check_editInvBanks&updatedBy="+myUser, {txtFooter:txtFooter }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You successfully updted system settings",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function chngQuotationHeader() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngQuotationHeader&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngQuotationFooter() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngQuotationFooter&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngQuotationContact() {
	swal({
		title: "Quotation Footer Contact",
		text: 'Please provide quotation footer contact',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngQuotationContact&updatedBy="+myUser,{ value:value, financeYr:financeYr },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "You successfully updated quotation footer contact",
						icon: "success",
						timer: 1500,
						button: false
					})
					.then(value=> {
						window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}
function check_editGatePassInfo() {
	var gatePassTitle	= $("#gatePassTitle").val();
	var txtFooter	= $("#txtRemarks").val();

	if(gatePassTitle.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide sales title");
		$("#gatePassTitle").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	if(txtFooter.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Provide sales footer");
		$("#txtRemarks").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editGatePassInfo&updatedBy="+myUser, { gatePassTitle:gatePassTitle, txtFooter:txtFooter }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You successfully updted Gate Pass info",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function check_editPrptyClr() {
	var color1	= $("#color1").val();
	var color2	= $("#color2").val();
	var color3	= $("#color3").val();

	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");

	$.post("./includes/pre-register.php?action=updateExist&dest=editPrptyClr&updatedBy="+myUser, { color1:color1, color2:color2, color3:color3 }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated property colors successfully.",
				icon: "success",
				timer: 1500,
				button: false,
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function chngLoyaltyProgram() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngLoyaltyProgram&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
			.then(value=> {
				window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
			});
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngMinLoyaltyValue() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngMinLoyaltyValue&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngEnterGateByFees() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngEnterGateByFees&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngposHasLogo() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngposHasLogo&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngOrderrsFromClientPc() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngOrderrsFromClientPc&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			}).then(() => {
				location.reload();
			});
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngFoodStorageConsBased() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngFoodStorageConsBased&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			}).then(() => {
				location.reload();
			});
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngPrintAreas() {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngPrintAreas&updatedBy="+myUser,{ },function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			})
					.then(value=> {
					window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngGateFees() {
	swal({
		title: "Gate Fee",
		text: 'Please provide gate fee amount',
		content: "input",
		buttons:["Cancel","Save"]
	})
	.then(amount=> {
		var amntReg = /[0-9]/;
		if (amount) {
			if(amount.match(amntReg)) {
				$.post("./includes/pre-register.php?action=updateExist&dest=chngGateFees&updatedBy="+myUser,{ amount:amount, financeYr:financeYr },function(data){
					if(data=="updated") {
						swal({
							title: "Success!",
							text: "You successfully updated gate amount.",
							icon: "success",
							timer: 1500,
							button: false
						})
						.then(value=> {
								window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
							}
						);
					} else {
						swal("Oops!", data, "error");
					}
				});
			}
		}
	});
}
function chngGatePassHours() {
	swal({
		title: "Gate Fee Hours",
		text: 'Please provide gate fee fee available hours',
		content: "input",
		buttons:["Cancel","Save"]
	})
		.then(value=> {
		var amntReg = /[0-9]/;
		if (value) {
			if(value.match(amntReg)) {

				$.post("./includes/pre-register.php?action=updateExist&dest=chngGatePassHours&updatedBy="+myUser,{ value:value, financeYr:financeYr },function(data){
					if(data=="updated") {
						swal({
							title: "Success!",
							text: "You successfully updated gate fee hours.",
							icon: "success",
							timer: 1500,
							button: false
						})
						.then(value=> {
							window.location = "./workplace.php?role="+myRole+"&task=general&subtask=settings";
						});
					} else {
						swal("Oops!", data, "error");
					}
				});
			}
		}
	});
}

function chngSettingValue(type) {
	$.post("./includes/pre-register.php?action=updateExist&dest=chngSettingValue&updatedBy="+myUser,{type},function(data){
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "Your changes has been saved.",
				icon: "success",
				timer: 1500,
				button: false
			}).then(() => {
				location.reload();
			});
		} else {
			swal("Oops!", data, "error");
		}
	});
}
function chngSettingValue2(type, text, currValue) {
	console.log(type)
	// return false
	swal({
		title: "Change "+ text,
		text: 'Please provide new value eg. \n'+currValue,
		content: "input",
		buttons:["Cancel","Save"]
	}).then(value=> {
		if (value) {
			$.post("./includes/pre-register.php?action=updateExist&dest=chngSettingValue2&updatedBy="+myUser,{ value:value, type:type },function(data){
				if(data=="updated") {
					swal({
						title: "Success!",
						text: "Your changes has been saved.",
						icon: "success",
						timer: 1500,
						button: false
					}).then(() => {
						location.reload();
					});
				} else {
					swal("Oops!", data, "error");
				}
			});
		}
	});
}