function simplfyAddRsrvtn() {
	//check if client check is checked or not
	$('[name="chkClient"]').change(function() {
		var chkClient 		= $('[name="chkClient"]').prop('checked');
		$('[name="clientID"], [name="clientName"], [name="clientPhone"], [name="clientEmail"], [name="qrCode"], [name="clientBalance"]').val('');
		$('[name="clientName"]').attr('placeholder', 'search by name');
		if(chkClient) {
			$('[name="clientName"]').attr('placeholder', 'name');
		}
	});
	// search client 4 reservation
	$('[name="clientName"]').keyup(function() {
		$('[name="clientID"], [name="clientBalance"]').val('');
		$(".suggest.customer").css('display', 'none');
		$(".suggest.customer").html('');
		$(".suggest.customer").addClass('loading');
	    var chkClient 		= $('[name="chkClient"]').prop('checked');
	    var clientName 		= $('[name="clientName"]').val();
	    if(!chkClient && clientName) {
	    	$('[name="clientPhone"]').val('');
	    	$(".suggest.customer").css('display', 'table-row');
	    	$.ajax({
				type: "POST",
				url: "./includes/reception.php?action=searchRec&dest=pickClient4Rsrvtn",
				data: 'passedValue='+clientName,
				cache: false,
				timeout: 2000,
				success: function(result) {
					$(".suggest.customer").removeClass('loading');
					$(".suggest.customer").html(result);
				},
			});
	    }
	});
	// payee type action
	$('[name="chkPayee"]').attr('disabled', 'disabled');
	$('[name="payeeName"]').attr('disabled', 'disabled');
	$('[name="payeePhone"]').prop('disabled', 'disabled');
	$('[name="payeeEmail"]').prop('disabled', 'disabled');
	$('[name="slcPayeeType"]').change(function() {
		var slcPayeeType 		= $('[name="slcPayeeType"]').val();
		if(slcPayeeType=="self") {
	    	$('[name="chkPayee"]').prop('checked', true);
			$('[name="chkPayee"]').prop('disabled', true);
			$('[name="payeeName"]').prop('disabled', true);
			$('[name="payeePhone"]').prop('disabled', true);
			$('[name="payeeEmail"]').prop('disabled', true);
		} else {
			$('[name="chkPayee"]').attr('disabled', false);
			$('[name="payeeName"]').attr('disabled', false);
			$('[name="payeePhone"]').prop('disabled', false);
			$('[name="payeeEmail"]').prop('disabled', false);
		}
	});
	// search payee
	$('[name="chkPayee"]').change(function() {
		var chkPayee 		= $('[name="chkPayee"]').prop('checked');
		$('[name="payeeID"], [name="payeeName"]').val('');
		$('[name="payeeName"]').attr('placeholder', 'search payee name');
		if(chkPayee) {
			$('[name="payeeName"]').attr('placeholder', 'name');
		}
	});
	$('[name="payeeName"]').keyup(function() {
		$('[name="payeeID"]').val('');
		$(".suggest.payee").css('display', 'none');
		$(".suggest.payee").html('');
		$(".suggest.payee").addClass('loading');
	    var chkPayee 		= $('[name="chkPayee"]').prop('checked');
	    var payeeName 		= $('[name="payeeName"]').val();
	    if(!chkPayee && payeeName) {
	    	$(".suggest.payee").css('display', 'table-row');
	    	$.ajax({
				type: "POST",
				url: "./includes/reception.php?action=searchRec&dest=pickPayee4Rsrvtn",
				data: 'passedValue='+payeeName,
				cache: false,
				timeout: 2000,
				success: function(result) {
					$(".suggest.payee").removeClass('loading');
					$(".suggest.payee").html(result);
				},
			});
	    }
	});
	// search identity
	$('[name="chkIdentity"]').change(function() {
		var chkIdentity 		= $('[name="chkIdentity"]').prop('checked');
		$('[name="identityID"], [name="identityName"]').val('');
		$('[name="identityName"]').attr('placeholder', 'search identity type');
		if(chkIdentity) {
			$('[name="identityName"]').attr('placeholder', 'name');
		}
	});
	$('[name="identityName"]').keyup(function() {
		$('[name="identityID"]').val('');
		$(".suggest.identity").css('display', 'none');
		$(".suggest.identity").html('');
		$(".suggest.identity").addClass('loading');
	    var chkIdentity 		= $('[name="chkIdentity"]').prop('checked');
	    var identityName 		= $('[name="identityName"]').val();
	    if(!chkIdentity && identityName) {
	    	$('[name="identityNo"]').val('');
	    	$(".suggest.identity").css('display', 'table-row');
	    	$.ajax({
				type: "POST",
				url: "./includes/reception.php?action=searchRec&dest=pickIdentity4Rsrvtn",
				data: 'passedValue='+identityName,
				cache: false,
				timeout: 2000,
				success: function(result) {
					$(".suggest.identity").removeClass('loading');
					$(".suggest.identity").html(result);
				},
			});
	    }
	});
	// payee type action
	$('[name="checkInTime"]').attr('disabled', 'disabled');
	$('[name="checkOutTime"]').attr('disabled', 'disabled');
	$('[name="slcResType"]').change(function() {
		var slcResType 		= $('[name="slcResType"]').val();
		if(slcResType=="hour") {
			$('[name="checkInTime"]').attr('disabled', false);
			$('[name="checkOutTime"]').attr('disabled', false);
		} else {
			$('[name="checkInTime"]').attr('disabled', 'disabled');
			$('[name="checkOutTime"]').attr('disabled', 'disabled');
		}
	});
	//search allocation
	$('[name="allocName"]').keyup(function() {
		$('[name="allocID"]').val('');
		$(".suggest.allocation").css('display', 'none');
		$(".suggest.allocation").html('');
		$(".suggest.allocation").addClass('loading');
	    var allocName 		= $('[name="allocName"]').val();
	    var slcResType 		= $('[name="slcResType"]').val();
	    var checkInDate 	= $('[name="checkInDate"]').val();
	    var checkInTime 	= $('[name="checkInTime"]').val();
	    var checkOutDate 	= $('[name="checkOutDate"]').val();
	    var checkOutTime 	= $('[name="checkOutTime"]').val();

	    if(checkInDate=='' || checkOutDate=='') {
			$(".error.checkOut").css("display", "inline");
			$(".error.checkOut").html("Select check in and check out days");
			$('[name="checkInDate"]').css("border-color", "#FF0000");
			$('[name="checkOutDate"]').css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }

    	$(".suggest.allocation").css('display', 'table-row');
    	$.ajax({
			type: "POST",
			url: "./includes/reception.php?action=searchRec&dest=pickAlloc4Rsrvtn",
			data: 'passedValue='+allocName+'&slcResType='+slcResType+'&checkInDate='+checkInDate+'&checkOutDate='+checkOutDate+'&checkInTime='+checkInTime+'&checkOutTime='+checkOutTime,
			cache: false,
			timeout: 2000,
			success: function(result) {
				$(".suggest.allocation").removeClass('loading');
				$(".suggest.allocation").html(result);
			},
		});
	});
	$('[name="txtDiscount"]').keyup(function() {
	    var price 	 = $('[name="pricePerDay"]').val();
	    var days 	 = $('[name="allocDays"]').val();
	    var discount = $('[name="txtDiscount"]').val();
	    var totalPrice = parseFloat(price*days);
		$('[name="totalPrice"]').val(parseFloat((price*days)-discount));
	});
}
function catchClient4Rsrvtn(clientID, clientName, phone, email, qrCode, balance) {
	$('[name="clientID"]').val(clientID);
	$('[name="clientName"]').val(clientName);
	$('[name="clientPhone"]').val(phone);
	$('[name="clientEmail"]').val(email);
	$('[name="qrCode"]').val(qrCode);
	$('[name="clientBalance"]').val(balance);
	$(".suggest.customer").css("display", "none");
}
function catchPayee4Rsrvtn(clientID, clientName, phone, email) {
	$('[name="payeeID"]').val(clientID);
	$('[name="payeeName"]').val(clientName);
	$('[name="payeeName"]').val(clientName);
	$('[name="payeePhone"]').val(phone);
	$('[name="payeeEmail"]').val(email);
	$(".suggest.payee").css("display", "none");
}
function catchIdentity4Rsrvtn(identityID, identityName) {
	$('[name="identityID"]').val(identityID);
	$('[name="identityName"]').val(identityName);
	$(".suggest.identity").css("display", "none");
}
function catchAlloc4Rsrvtn( allocID, shortName, longName, typeNamme, price, maxDiscount, amenities, daysDiff) {
	$('[name="allocID"]').val(allocID);
	$('[name="allocName"]').val(shortName+', '+longName);
	$('[name="longName"]').val(longName);
	$('[name="allocType"]').val(typeNamme);
	$('[name="allocAmenities"]').val(amenities);
    var slcResType 		= $('[name="slcResType"]').val();
	$('[name="pricePerDay"]').val(price);
	$('[name="allocDays"]').val(daysDiff);
	$('[name="txtDiscount"]').val(0);
	$('[name="totalPrice"]').val(parseFloat(price*daysDiff));
	$(".suggest.allocation").css("display", "none");
}
function check_addReservation() {
    var clientName 		= $('[name="clientName"]').val();
    var clientPhone 	= $('[name="clientPhone"]').val();
    var slcResType 		= $('[name="slcResType"]').val();
    var checkInDate 	= $('[name="checkInDate"]').val();
    var checkInTime 	= $('[name="checkInTime"]').val();
    var checkOutDate 	= $('[name="checkOutDate"]').val();
    var checkOutTime 	= $('[name="checkOutTime"]').val();
    var slcPayeeType 	= $('[name="slcPayeeType"]').val();
    var payeeName 		= $('[name="payeeName"]').val();
    var payeePhone 		= $('[name="payeePhone"]').val();
    var allocName 		= $('[name="allocName"]').val();
    var allocID 		= $('[name="allocID"]').val();

    if(!clientName) {
		$(".error.clientName").css("display", "inline");
		$(".error.clientName").html("Please select customer");
		$('[name="clientName"]').css("border-color", "#FF0000");			
		return false;
	}
	if(!clientPhone) {
		$(".error.clientPhone").css("display", "inline");
		$(".error.clientPhone").html("Customer phone is missing");
		$('[name="clientPhone"]').css("border-color", "#FF0000");			
		return false;
	}
	if(slcPayeeType=="other") {
		if(!payeeName) {
			$(".error.payeeName").css("display", "inline");
			$(".error.payeeName").html("Select payee");
			$('[name="payeeName"]').css("border-color", "#FF0000");			
			return false;
		}
		if(!payeePhone) {
			$(".error.payeePhone").css("display", "inline");
			$(".error.payeePhone").html("Payee phone is missing");
			$('[name="payeePhone"]').css("border-color", "#FF0000");			
			return false;
		}
	}
	if(!checkInDate || !checkOutDate) {
		$(".error.checkOut").css("display", "inline");
		$(".error.checkOut").html("Please select check in and check out");
		$('[name="checkInDate"]').css("border-color", "#FF0000");			
		$('[name="checkOutDate"]').css("border-color", "#FF0000");			
		return false;
	} 
	if(slcResType=="hour") {
		if(!checkInDate || !checkOutDate) {
			$(".error.checkOut").css("display", "inline");
			$(".error.checkOut").html("Please select check in and check out hours");
			$('[name="checkInTime"]').css("border-color", "#FF0000");			
			$('[name="checkOutTime"]').css("border-color", "#FF0000");			
			return false;
		} 
	}
	//
	if(!allocName || !allocID) {
		$(".error.allocName").css("display", "inline");
		$(".error.allocName").html("Select allocation");
		$('[name="allocName"]').css("border-color", "#FF0000");			
		return false;
	}
}
function simplfyTrnsfrRsrvtn(){
	$("#allocType").append(function() {
		var allocType	= $("#allocType").val();
		if(allocType== "hour") {
			$("input#timeIn, input#timeOut").css("display", "inline");
		} else {
			$("input#timeIn, input#timeOut").css("display", "none");
		}
		$("input#allocID, input#allocPrice, input#srchRoom").val('');
		$("div.displayInfo.alloc").css("display", "none");
	});
	//
	$("input#srchRoom").keyup(function(){
		var srchRoom	= $("#srchRoom").val();
		var allocType	= $("#allocType").val();
		
		var chkInDate 	= $("#chkInDate").val();
		var chkOutDate	= $("#chkOutDate").val();
		var timeIn 		= $("#timeIn").val();
		var timeOut		= $("#timeOut").val();
		
		if(chkInDate=='' || chkOutDate=='') {
			$("#error3").css("display", "inline");
			$("#error3").html("Select check in and check out days");
			$("#chkInDate, #chkOutDate").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }
		
		if(allocType=='night') {
			if(chkInDate == chkOutDate) {
				$("#error3").css("display", "inline");
				$("#error3").html("Select different days");
				$("#chkOutDate").css("border-color", "#FF0000");
				$('html, body').animate({ scrollTop: $(".record.three").offset().top }, 'slow');
				return false;
			} else { clearErrors(); }
			
		} else {
			if((chkInDate == chkOutDate) && (timeIn == timeOut) ) {
				$("#error3").css("display", "inline");
				$("#error3").html("Select different date time");
				$("#chkOutDate, #timeOut").css("border-color", "#FF0000");
				$('html, body').animate({ scrollTop: $(".record.three").offset().top }, 'slow');
				return false;
			} else { clearErrors(); }
			
		}
		if(srchRoom!="") {
			$("div.suggest.alloc").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchRoom4Rsrve", { srchRoom:srchRoom, allocType:allocType, chkInDate:chkInDate, chkOutDate:chkOutDate, timeIn:timeIn, timeOut:timeOut }, function(data) {
				$("div.suggest.alloc").html(data);
			});
		} else { $("div.suggest.alloc").css("display", "none"); }
		clearErrors();
	});
}
function catchAlloc4Trnsfr(allocID, allocName, pprtyInfo, price, maxDiscount, amenities, status) {
	$("#allocID").val(allocID);
	$("#allocPrice").val(price);
	$("#maxDiscount").val(maxDiscount);
	$("#srchRoom").val(allocName);
	$("p#allocName").html(allocName);
	var allocType = $("#allocType :selected").text();
	$("p#allocPrice").html('$'+maxDiscount+' ($'+price+' '+allocType+')');
	$("p#pprtyInfo").html(pprtyInfo);
	$("p#ameneties").html(amenities);
	$("div.displayInfo.alloc").css("display", "inline");
	$("div.suggest.alloc").css("display", "none");
}
function transferCheckIn(){
	var guestID		= $("#guestID").val();
	var txtGuest	= $("#txtGuest").val();
	var roomID		= $("#roomID").val();
	var checkInID	= $("#checkInID").val();
	var checkDetID	= $("#checkDetID").val();
	var invoiceID	= $("#invoiceID").val();
	var allocType	= $("#allocType").val();
	
	var chkInDate	= $("#chkInDate").val();
	var chkOutDate	= $("#chkOutDate").val();
	var timeIn		= $("#timeIn").val();
	var timeOut		= $("#timeOut").val();
	
	var srchRoom	= $("#srchRoom").val();
	var allocID		= $("#allocID").val();
	var allocPrice	= $("#allocPrice").val();
	var discount	= $("#discount").val();
	var oldDateIN	= $("#oldDateIN").val();
	
	if(txtGuest.length < 1 || guestID.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide guest");
		$("#txtGuest").css("border-color", "#FF0000");
		
		$("div.suggest").css("display", "none");
		return false;
	} else { clearErrors(); }
	
	if(allocType=='night') {
		if(chkInDate.length < 1 || chkOutDate.length < 1) {
			$("#error3").css("display", "inline");
			$("#error3").html("Select check in and check out days");
			$("#chkInDate, #chkOutDate").css("border-color", "#FF0000");
			$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
			return false;
		} else if(chkInDate == chkOutDate) {
			$("#error3").css("display", "inline");
			$("#error3").html("Select different days");
			$("#chkOutDate").css("border-color", "#FF0000");
			$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
			return false;
		} else { clearErrors(); }
		
	} else {
		if((chkInDate == chkOutDate) && (timeIn == timeOut) ) {
			$("#error3").css("display", "inline");
			$("#error3").html("Select different date time");
			$("#chkOutDate, #timeOut").css("border-color", "#FF0000");
			$('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow');
			return false;
		} else { clearErrors(); }
	}
	
	if(srchRoom.length < 1 || allocID.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("Select allocation to transfer");
		$("#srchRoom").css("border-color", "#FF0000");
		$('html, body').animate({ scrollTop: $(".record.three").offset().top }, 'slow');
		$("div.suggest.room").css("display", "none");
		return false;
	} else { clearErrors(); }
	
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("wait...");
	$("label.process").css("display", "inline");
	
	$.post("./includes/reception.php?action=updateExist&dest=trnsfrRoom&updatedBy="+myUser, { guestID:guestID, roomID:roomID, checkInID:checkInID, checkDetID:checkDetID, invoiceID:invoiceID, allocType:allocType, chkInDate:chkInDate, chkOutDate:chkOutDate, timeIn:timeIn, timeOut:timeOut, allocID:allocID, allocPrice:allocPrice, discount:discount, oldDateIN:oldDateIN },function(data){
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You transfered into other room.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reservation-workplace.php?role="+myRole+"&task=reservation&subtask=showInfo&recID="+checkInID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function check_editReservationDate() {
	var checkDetID		= $("#checkDetID").val();
	var checkInID 		= $("#checkInID").val();
	var guestID 		= $("#guestID").val();
	var chkInDate 		= $("#chkInDate").val();
	var chkOutDate 		= $("#chkOutDate").val();
	$("#btnAdd").attr("disabled", true);
	$("#btnAdd").html("wait...");
	$("div.suggest.one").css("display", "none");

	$.post("./includes/reception.php?action=updateExist&dest=editReservationDate&updatedBy="+myUser, { checkDetID:checkDetID, checkInID:checkInID, guestID:guestID, chkInDate:chkInDate, chkOutDate:chkOutDate}, function(data) {
		
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated invoice commission.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			}, function (){
				window.location = "./reservation-workplace.php?role="+myRole+"&task=reservation&subtask=showInfo&recID="+checkInID;
			});
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add");
	});
	return false;
}
function loadRsrvtion(pageLimit, perPage, period) {
	$("#dataTable #loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+ perPage+'&period='+ period+'&myWhouse='+myWhouse;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allCheckIn&myRole="+myRole+"&myUser="+myUser,
		data: dataString,
		dataType: 'json',
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable #loading").css("display", "none");
			$("#foundNum #count").html(result['numRecords']);
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result['records']);
		}
	});
	return false;
}
function check_searchBox() {
	$("input#srchCheckIn").keyup(function() {
		var passedValue = $("input#srchCheckIn").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchCheckIn", { passedValue: passedValue, myUser: myUser, myRole: myRole}, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	//
	$("input#srchCheckIn").blur(function() {
		if($("#srchCheckIn").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	//
	$("input#srchGnrtBill").keyup(function() {
		var passedValue = $("input#srchGnrtBill").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchGnrtBill", { passedValue: passedValue, myUser: myUser, myRole: myRole}, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	//
	$("input#srchRecpt").keyup(function() {
		var passedValue = $("input#srchRecpt").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchRecpt", { passedValue: passedValue, myRole: myRole, myWhouse:myWhouse}, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	//
	$("input#srchClient").keyup(function() {
		var passedValue = $("input#srchClient").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchClient", { passedValue: passedValue }, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	//
	$("input#srchExtrOrdr").keyup(function() {
		var passedValue = $("input#srchExtrOrdr").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchExtrOrdr", { passedValue: passedValue, myUser: myUser, myRole: myRole}, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
}
function catchCheckIn(recID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getCheckIn", { 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 cancelBooking(checkDetID, checkInID, total){
	swal({
		title: "Are you sure to cancel?",
		text: "You going to cancel this reservation completely!",
		type: "error",
		showCancelButton: true,
		confirmButtonColor: '#ad722d',
		confirmButtonText: 'Yes, cancel it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/reception.php?action=deleteRec&dest=cancelBooking", { checkDetID:checkDetID, checkInID:checkInID, total:total, myUser:myUser }, function(data) {
			if(data=="cancelled") {
				swal({
					title: "Success!",
					text: "Selected reservation record has been cancelled.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				},
					function () {
						location.reload();
					}
				);
			} else {
				swal("Oops", data, "error");
			}
		});
	});
	return false;
}



/*-------------------------------------------------------
--------------------------Checkout-----------------------
-------------------------------------------------------*/
function simplfyGnrteBill() {
	$("#slcBillType").change(function() {
	$("#txtGuest").val('');
	$("#reference").val('');
	$("#ttlAccFee").val('');
	$("#clientID").val('');
	$("p#pCName").html('N/A');
	$("p#pProperty").html('N/A');
	$("p#pCheckIns").html('N/A');
	$("p#pPeriod").html('N/A');
	$("p#pAccFee").html('N/A');
	$("p#pTtlAccFee").html('N/A');
	$("p#pTtlBar").html('N/A');
	$("p#pTtlExtra").html('N/A');
	$("p#pComm").html('N/A');
	$("p#pTvat").html('N/A');
	$("p#pTtlDiscount").html('N/A');
	$("p#pTtlDeposit").html('N/A');
	$("p#pTtlBlnce").html('N/A');
	$("div.displayInfo").css("display", "inline");
	$("div.suggest").css("display", "none");
	});
	//
	$("input#txtGuest").keyup(function(){
		var txtGuest	 = $("#txtGuest").val();
		var billType 	= $("#slcBillType").val();
		if(txtGuest!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=searchBill",{ passedValue:txtGuest, billType:billType }, function(data) {
				$("div.suggest").html(data);
			});
		} else { $("div.suggest").css("display", "none"); }
		clearErrors();
	});
}
function catchgGnrateBill(reference, clientID, clientName, clientPhone, totalDue, allocDetails, checkInPlsOut, quantityTxt, accFeeAmntTxt, ttlAccFee, ttlBarAmnt, ttlExtraAmnt, ttlDiscount,myBalance,vatvalue,commBalance) {
	$("#reference").val(reference);
	$("#ttlAccFee").val(parseFloat(ttlAccFee+commBalance));
	$("#clientID").val(clientID);
	$("#txtGuest").val(clientName);
	$("p#pCName").html(clientName+', '+clientPhone);
	$("p#pProperty").html(allocDetails);
	$("p#pCheckIns").html(checkInPlsOut);
	$("p#pPeriod").html(quantityTxt);
	$("p#pAccFee").html(accFeeAmntTxt);
	$("p#pTtlAccFee").html('$'+ttlAccFee);
	$("p#pTtlBar").html('$'+ttlBarAmnt);
	$("p#pTtlExtra").html('$'+ttlExtraAmnt);
	if(commBalance) $("p#pComm").html('$'+commBalance);
	else $("p#pComm").html('0');
	if(vatvalue) $("p#pTvat").html('$'+vatvalue);
	else $("p#pTvat").html('0');
	$("p#pTtlDiscount").html('$'+ttlDiscount);
	$("p#pTtlDeposit").html('$'+myBalance);
	$("p#pTtlBlnce").html('$'+totalDue);
	$("div.displayInfo").css("display", "inline");
	$("div.suggest").css("display", "none");
}
function check_gnrateBill() {
	var billType	= $("#slcBillType").val();
	var clientID	= $("#clientID").val();
	var reference	= $("#reference").val();
	var ttlAccFee	= $("#ttlAccFee").val();

  	if(reference.length < 1 || txtGuest.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please select customer name to pay");
		$("#txtGuest").removeClass("no-left");
		$("#txtGuest").css("border-color", "#FF0000");
		$("div.suggest").css("display", "none");
		return false;
   	} else { clearErrors(); }
	
	swal({
		title: "Are you sure?",
		text: "You going to generate invoice bill!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#a26926',
		confirmButtonText: 'Yes, generate it!',
		closeOnConfirm: false
	},
	function() {
		$("label.process").css("display", "inline");
		$("#btnSave").attr("disabled", true);
		$("#btnSave").html("Wait...");
		$.post("./includes/reception.php?action=saveNew&dest=addGnrteBill&addedBy="+myUser, { billType:billType, reference:reference, clientID:clientID, ttlAccFee:ttlAccFee}, function(data) {
		var addedpos = data.search("added");
		$("label.process").css("display", "none");
		if(addedpos==0) {
			swal({
				title: "Success!",
				text: "You successfully generated invoice bill",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reservation-workplace.php?role="+myRole+"&task=checkout\
					&subtask=showInfo&billType="+billType+"&reference="+reference;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Generate Bill");
		});	
	});
	return false;
}
function loadGnrteBill(pageLimit, perPage, period) {
	$("#dataTable #loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&perPage='+perPage;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allGnrteBill&myRole="+myRole,
		data: dataString,
		dataType: 'json',
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable #loading").css("display", "none");
			$("#foundNum #count").html(result['numRecords']);
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result['records']);
		}
	});
	return false;
}
function check_addGuest2Rsrve() {
	clearErrors();
	var clientName 		= $('[name="clientName"]').val();
	var clientID 		= $('[name="clientID"]').val();
    var clientPhone 	= $('[name="clientPhone"]').val();
    var slcResType 		= $('[name="slcResType"]').val();
    var checkInDate 	= $('[name="checkInDate"]').val();
    var checkInTime 	= $('[name="checkInTime"]').val();
    var checkOutDate 	= $('[name="checkOutDate"]').val();
    var checkOutTime 	= $('[name="checkOutTime"]').val();
    var allocName 		= $('[name="allocName"]').val();
    var allocID 		= $('[name="allocID"]').val();

    if(!clientName) {
		$(".error.clientName").css("display", "inline");
		$(".error.clientName").html("Please select customer");
		$('[name="clientName"]').css("border-color", "#FF0000");			
		return false;
	}
	if(!clientPhone) {
		$(".error.clientPhone").css("display", "inline");
		$(".error.clientPhone").html("Customer phone is missing");
		$('[name="clientPhone"]').css("border-color", "#FF0000");			
		return false;
	}
	if(!checkInDate || !checkOutDate) {
		$(".error.checkOut").css("display", "inline");
		$(".error.checkOut").html("Please select check in and check out");
		$('[name="checkInDate"]').css("border-color", "#FF0000");			
		$('[name="checkOutDate"]').css("border-color", "#FF0000");			
		return false;
	} 
	if(slcResType=="hour") {
		if(!checkInDate || !checkOutDate) {
			$(".error.checkOut").css("display", "inline");
			$(".error.checkOut").html("Please select check in and check out hours");
			$('[name="checkInTime"]').css("border-color", "#FF0000");			
			$('[name="checkOutTime"]').css("border-color", "#FF0000");			
			return false;
		} 
	}
	//
	if(!allocName || !allocID) {
		$(".error.allocName").css("display", "inline");
		$(".error.allocName").html("Select allocation");
		$('[name="allocName"]').css("border-color", "#FF0000");			
		return false;
	}
}
function activeBooking(checkDetID){
	swal({
		title: "Are you sure?",
		text: "You going to make this reservation confirmed!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#ad722d',
		confirmButtonText: 'Yes, activate it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/reception.php?action=updateExist&dest=activeBooking&updatedBy="+myUser, { checkDetID:checkDetID, myUser:myUser }, function(data) {
			if(data=="updated") {
				swal({
					title: "Success!",
					text: "Selected reservation record has been confirmed.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
				location.reload();
			} else {
				swal("Oops", data, "error");
			}
		});
	});
	return false;
}
function closeGenerate(gnrateID){
	swal({
		title: "Are you sure to cancel this bill?",
		text: "You are going to cancel this bill!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#ad722d',
		confirmButtonText: 'Yes, cancel it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/reception.php?action=updateExist&dest=closeGenerate&updatedBy="+myUser,{ gnrateID:gnrateID }, function(data){
			if(data=="updated") {
				swal({
					title: "Success",
					text: "Bill generate cancelled successfully",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				}, 
					function() {
						location.reload();	
					}
				);
			} else {
				swal("Oops!", data, "error");
			}
		});
	});
	return false;
}



/*-------------------------------------------------------
------------------------Cashier--------------------------
-------------------------------------------------------*/

function loadRecpts(pageLimit, perPage, period) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&period='+ period+'&perPage='+ perPage;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allRecpts&myRole="+myRole+"&myWhouse="+myWhouse,
		data: dataString,
		dataType: 'json',
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable #loading").css("display", "none");
			$("#foundNum #count").html(result['numRecords']);
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result['records']);
		}
	});
	return false;
}
function simplifyCashierAdd() {
	$("#slcPurpose").change(function() {
		$("#txtClient, #invoiceRef, #payeeID, #balance, #txtAmount, #txtInWords, #txtPaidBy").val('');	
		$("div.suggest").css("display", "none");
		//$("div.displayInfo").css("display", "none");
	});
	$("input#txtClient").keyup(function(){
		var txtClient 	= $("#txtClient").val();
		var slcPurpose 	= $("#slcPurpose").val();
		if(txtClient!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=client4rcpt", { passedValue:txtClient, slcPurpose:slcPurpose, myWhouse:myWhouse, myUser:myUser}, function(data) {
				$("div.suggest").html(data);
			});
		} else { $("div.suggest").css("display", "none"); }
		clearErrors();
	});
	//
	$("#txtAmount").keyup(function() {
		inWords($("#txtAmount").val());
		var txtDueAmount	= $("#txtDueAmount").val();
		var txtAmount	= $("#txtAmount").val();
		if(parseFloat(txtAmount)>parseFloat( txtDueAmount)){
			$("#txtAmount").val(txtDueAmount);
			inWords(txtAmount);
		}

	});
	//
	$.post("./includes/reception.php?action=searchRec&dest=myBankAccs", { bankID: 101, myWhouse:myWhouse }, function(data) {
		$("#slcBankAcc").html(data);
	});
	//
	$("#slcBankID").change(function() {
		var bankID = $("#slcBankID").val();
		if(bankID=="") {
			$("#slcBankAcc").html('');
		} else {
			$.post("./includes/reception.php?action=searchRec&dest=myBankAccs", { bankID: bankID, myWhouse:myWhouse }, function(data) {
				$("#slcBankAcc").html(data);
			});
		}
	});
	//
	$("#txtRemarks").keyup(function(){
		return tweetFeed(this, 500);
	});
}
function catchClient4Rcpt(gnrateID, payeeID, payeeName, payeePhone, totalDue, balance) {
	$("#invoiceRef").val(gnrateID);
	$("#payeeID").val(payeeID);
	$("#txtClient").val(payeeName);
	$("#txtPhone").val(payeePhone);
	$("#txtTotalDue").val(totalDue);
	$("#txtAmount, #txtDueAmount").val(balance);
	inWords($("#txtAmount").val());
	$("div.suggest").css("display", "none");
}
function check_addCashier() {
	var slcPurpose	= $("#slcPurpose").val();
	var invoiceRef	= $("#invoiceRef").val();
	var payeeID		= $("#payeeID").val();
	var balance		= parseFloat($("#balance").val());
	
	var txtAmount	= $("#txtAmount").val();
	var txtInWords	= $("#txtInWords").val();
	
	var slcBankID	= $("#slcBankID").val();
	var slcBankAcc	= $("#slcBankAcc").val();
	var txtCheque	= $("#txtCheque").val();
	
	var txtRemarks	= $("#txtRemarks").val();
	var transDate	= $("#transDate").val();
	
	if(payeeID.length < 1 || invoiceRef.length < 1 || txtClient.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please find payee person");
		$("#txtClient").css("border-color", "#FF0000");
		$("div.suggest").css("display", "none");
		return false;
	} else { clearErrors(); }
	
	if(txtAmount.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Amount value is missing");
		$("#txtAmount").css("border-color", "#FF0000");
		return false;
	} else if(Number(txtAmount) <= 0) {
		$("#error2").css("display", "inline");
		$("#error2").html("Amount must be greater than 0");
		$("#txtAmount").css("border-color", "#FF0000");
		return false;
	} else if(parseFloat(txtAmount) > parseFloat(balance)) {
		$("#error2").css("display", "inline");
		$("#error2").html("Amount can't be greater than $"+balance);
		$("#txtAmount").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(slcBankID.length < 1) {
		$("#error3").css("display", "inline");
		$("#error3").html("Please select bank");
		$("#slcBankID").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(slcBankAcc=="---" || slcBankAcc.length < 1) {
		$("#error3").css("display", "inline");
		$("#error3").html("Select bank account");
		$("#slcBankAcc").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");

	$.post("./includes/reception.php?action=saveNew&dest=addCashier&addedBy="+myUser, { myWhouse:myWhouse, slcPurpose:slcPurpose, invoiceRef:invoiceRef, payeeID:payeeID, txtAmount:txtAmount, txtInWords:txtInWords, slcBankID:slcBankID, slcBankAcc:slcBankAcc, txtCheque:txtCheque, txtRemarks:txtRemarks, transDate:transDate, balance:balance }, 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 receipt record successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reservation-workplace.php?role="+myRole+"&task=cashier&subtask=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;	
}



/*-------------------------------------------------------
------------------------Customers------------------------
-------------------------------------------------------*/
function loadClients(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&perPage='+perPage;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allClients&myRole="+myRole+"&myUser="+myUser,
		data: dataString,
		dataType: 'json',
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable #loading").css("display", "none");
			$("#foundNum #count").html(result['numRecords']);
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result['records']);
		}
	});
	return false;
}
function check_addClient() {
	var fullname	= $("#txtName").val();
	var gender		= $("#slcGender").val();
	var natnlity	= $("#slcNatlity").val();
	
	var phone		= $("#txtPhone").val();
	var qrCode		= $("#txtQrCode").val();
	var email		= $("#txtEmail").val();
	var address		= $("#txtAddress").val();
	var slcStatus	= $("#slcStatus").val();
	
	var facebook	= $("#txtFacebook").val();
	var twitter		= $("#txtTwitter").val();
		
	if(fullname.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please type full name");
		$("#txtName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(phone.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Don't forget phone number");
		$("#txtPhone").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(email.length > 0) {
		if(!email.match(emailExp)) {
			$("#error3").css("display", "inline");
			$("#error3").html("invalid email address");
			$("#txtEmail").css("border-color", "#FF0000");
			return false;
		}
	} else { clearErrors(); }
	
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("wait...");
	$("label.process").css("display", "inline");

	$.post("./includes/reception.php?action=saveNew&dest=addCustomer&addedBy="+myUser, { fullname:fullname, gender:gender, natnlity:natnlity, phone:phone, qrCode:qrCode, email:email, address:address, facebook:facebook, twitter:twitter, slcStatus:slcStatus },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 registered new profile book successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reservation-workplace.php?role="+myRole+"&task=customerMgt&subtask=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function check_editClient() {
	var clientID	= $("#clientID").val();
	var fullname	= $("#txtName").val();
	var gender		= $("#slcGender").val();
	var natnlity	= $("#slcNatlity").val();
	
	var phone		= $("#txtPhone").val();
	var email		= $("#txtEmail").val();
	var address		= $("#txtAddress").val();
	
	var facebook	= $("#txtFacebook").val();
	var twitter		= $("#txtTwitter").val();
	var bookedFor	= $("#bookedFor").val();
	var status		= $("#slcStatus").val();
		
	if(fullname.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please type full name");
		$("#txtName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(phone.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Don't forget phone number");
		$("#txtPhone").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(email.length > 0) {
		if(!email.match(emailExp)) {
			$("#error3").css("display", "inline");
			$("#error3").html("invalid email address");
			$("#txtEmail").css("border-color", "#FF0000");
			return false;
		}
	} else { clearErrors(); }
	
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("wait...");
	$("label.process").css("display", "inline");

	$.post("./includes/reception.php?action=updateExist&dest=editClient&updatedBy="+myUser, { clientID:clientID, fullname:fullname, gender:gender, natnlity:natnlity, phone:phone, email:email, address:address, facebook:facebook, twitter:twitter, status:status, bookedFor:bookedFor },function(data){
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated profile book successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reservation-workplace.php?role="+myRole+"&task=customerMgt&subtask=showInfo&recID="+clientID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}



/*-------------------------------------------------------
------------------------Services-------------------------
-------------------------------------------------------*/
function loadExtraOrdr(pageLimit, perPage, period) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&period='+period+'&perPage='+perPage+'&myWhouse='+myWhouse;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allExtraOrdr&myRole="+myRole+"&myUser="+myUser,
		data: dataString,
		dataType: 'json',
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable #loading").css("display", "none");
			$("#foundNum #count").html(result['numRecords']);
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result['records']);
		}
	});
	return false;
}
function simplyExraOrder() {
	$('fieldset.outside').css('display','none');
	$('[name="ordrFrom"]').change(function(){
		var ordrFrom = $('[name="ordrFrom"]').val();
		if(ordrFrom=='inside'){
			$('fieldset.outside').css('display','none');
			$('fieldset.inside').css('display','inline');
		} else {
			$('fieldset.inside').css('display','none');
			$('fieldset.outside').css('display','inline');
		}
	});
	//
	$('[name="prpType"]').change(function() {
		var prpType = $("#prpType").val();
		$.post("./includes/reception.php?action=searchRec&dest=pickProperty4Service", { prpType: prpType }, function(data) {
			$('[name="slcAlloc"]').html(data);
		});
	});
	// 
	$('[name="clientName"]').keyup(function() {
		$('[name="clientID"], [name="clientBalance"]').val('');
		$(".suggest.customer").css('display', 'none');
		$(".suggest.customer").html('');
		$(".suggest.customer").addClass('loading');
	    var chkClient 		= $('[name="chkClient"]').prop('checked');
	    var clientName 		= $('[name="clientName"]').val();
	    if(!chkClient && clientName) {
	    	$('[name="clientPhone"]').val('');
	    	$(".suggest.customer").css('display', 'table-row');
	    	$.ajax({
				type: "POST",
				url: "./includes/reception.php?action=searchRec&dest=pickClient4Service",
				data: 'passedValue='+clientName,
				cache: false,
				timeout: 2000,
				success: function(result) {
					$(".suggest.customer").removeClass('loading');
					$(".suggest.customer").html(result);
				},
			});
	    }
	});
	$('[name="slcExtra"]').change(function() {
		var slcExtra 	= $('[name="slcExtra"]').val();
		if(slcExtra!="---") {
			$.post("./includes/reception.php?action=searchRec&dest=getExtraCost", { slcExtra: slcExtra }, function(data) {
				$("input#txtCost").val(data);
				$("input#txtQnty").val(1);
				$("input#subTotal").val(data);
				$("input#total").val(data);
			});
		} else {
			$("input#txtCost").val('');
		}
		$("#discount").val(0);
		clearErrors();
	});
	//
	$("input#txtQnty").keyup("keyup change", function(e) {
		var quantity	= parseFloat($("#txtQnty").val());
		var costPrice	= parseFloat($("#txtCost").val());
		var discount 	= parseFloat($("#discount").val());
		
		if(quantity > 0 && costPrice > 0) {
			var subTotal = (quantity*costPrice);
			if(discount != 0 || discount != "") {
				if(discount>subTotal) {
					$("input#discount").val(0);
				}
				var total = (subTotal-discount);
			} else {
				var total = subTotal;
			}
			$("input#subTotal").val(subTotal);
			$("input#total").val(total);
		} else {
			$("input#subTotal, input#total").val(0);
		}
		clearErrors();
	});
	//
	$("input#txtCost").keyup("keyup change", function(e) {
		var quantity	= parseFloat($("#txtQnty").val());
		var costPrice	= parseFloat($("#txtCost").val());
		var subTotal 	= (quantity*costPrice);
		var discount	= parseFloat($("#discount").val());
		$("input#subTotal").val(subTotal);
		$("input#total").val(subTotal-discount);
		clearErrors();
	});
	$("input#discount").keyup("keyup change", function(e) {
		var quantity	= parseFloat($("#txtQnty").val());
		var costPrice	= parseFloat($("#txtCost").val());
		var subTotal 	= (quantity*costPrice);
		var discount	= parseFloat($("#discount").val());
		$("input#subTotal").val(subTotal);
		$("input#total").val(subTotal-discount);
		clearErrors();
	});
	//
	$('[name="clientName"]').keyup(function() {
		$('[name="clientID"], [name="clientBalance"]').val('');
		$(".suggest.customer").css('display', 'none');
		$(".suggest.customer").html('');
		$(".suggest.customer").addClass('loading');
	    var clientName 		= $('[name="clientName"]').val();
	    if(clientName) {
	    	$('[name="clientPhone"]').val('');
	    	$(".suggest.customer").css('display', 'table-row');
	    	$.ajax({
				type: "POST",
				url: "./includes/reception.php?action=searchRec&dest=pickClient4Rsrvtn",
				data: 'passedValue='+clientName,
				cache: false,
				timeout: 2000,
				success: function(result) {
					$(".suggest.customer").removeClass('loading');
					$(".suggest.customer").html(result);
				},
			});
	    }
	});
}
function catchClient(clientID, clientName, phone, balance) {
	$('[name="clientID"]').val(clientID);
	$('[name="clientName"]').val(clientName);
	$("div.suggest.customer").css("display", "none");
}
function addNewService() {
	var txtServiceName = $("#txtServiceName").val();
	var txtServiceCost = $("#txtServiceCost").val();
	
	if(!txtServiceName) {
		$("#error1").css("display", "inline");
		$("#error1").html("Service name is missing");
		$("#txtServiceName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	if(!txtServiceCost) {
		$("#error2").css("display", "inline");
		$("#error2").html("Please provide service cost");
		$("#txtServiceCost").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$("#btnAdd").attr("disabled", true);
	$("#btnAdd").html("wait...");

	$.post("./includes/reception.php?action=saveNew&dest=addNewService&addedBy="+myUser, { txtServiceName:txtServiceName, txtServiceCost:txtServiceCost }, function(data) {
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			//
        	$('[name="slcExtra"]').append(`<option value="${lastID}" selected="selected">${txtServiceName}</option>`);
			$("input#txtCost").val(txtServiceCost);
			$("input#txtQnty").val(1);
			$("input#subTotal").val(txtServiceCost);
			$("input#total").val(txtServiceCost);
			$("#addNewService").attr("checked",false);
			$("div.popupContainer").css("display","none");
			swal({
				title: "Success!",
				text: "You added new customer successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			});
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add");
	});
	return false;
}
function addExtraMeasure() {
	swal({
		title: "Add Extra Service Measure",
		text: 'Give a name to this measure',
		type: "input",
		showCancelButton: true,
		closeOnConfirm: false,
		animation: "slide-from-top",
		inputPlaceholder: "required",
	},
	function(measureName) {
		if (measureName === false) return false;
		if (measureName === "") {
			swal.showInputError("Please write measure name");
			return false
		}
		$.post("./includes/reception.php?action=saveNew&dest=addExtraMeasure&addedBy="+myUser, { measureName:measureName }, function(data) {
			var addedpos = data.search("added");
			if(addedpos==0) {
				var lastID = data.slice(6,21);
				swal({
					title: "Success!",
					text: "You successfully added new measure.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
				$.post("./includes/reception.php?action=get_recInfo&dest=getExtraMsr4Order", {lastID:lastID},function (data) {
        			$('[name="slcExtraMsr"]').append(`<option value="${lastID}" selected="selected">${measureName}</option>`);
				});
			} else {
				swal("Oops!", data, "error");
			}
		});
	});
	return false;
}
function add2List4Extra() {
	var slcExtra	= $("#slcExtra").val();			var slcExtra2	= $("#slcExtra :selected").text();
	var txtQnty		= $("#txtQnty").val();
	var slcExtraMsr		= $("#slcExtraMsr").val(); var slcExtraMsr2		= $("#slcExtraMsr :selected").text();
	var txtCost		= $("#txtCost").val();
	var subTotal	= Number(txtQnty*txtCost);
	var discount	= $("#discount").val();
	var total		= Number(subTotal-discount);
	
	if(slcExtra == "---") {
		$("#error4").css("display", "inline");
		$("#error4").html("Select extra service to add this order");
		$("#slcExtra").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(txtQnty.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("Quantity is missing");
		$("#txtQnty").css("border-color", "#FF0000");
		return false;
	} else if(Number(txtQnty) < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("Quantity must be greater than 0");
		$("#txtQnty").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(slcExtraMsr=="---") {
		$("#error4").css("display", "inline");
		$("#error4").html("Please provide measure");
		$("#slcExtraMsr").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(txtCost.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("Price can't be empty");
		$("#txtCost").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$(".theForm .list .listItem.zero").remove();
	$("div.list").append('<div class="listItem num'+num+'">\
		<div class="cave serial"></div>\
		<div class="cave large">\
			<input type="hidden" name="extraID[]" value="'+slcExtra+'" readonly="readonly" />\
			<input type="text" value="'+slcExtra2+'" readonly="readonly" />\
		</div>\
		<div class="cave vsmall">\
			<input type="hidden" name="extraMsrID[]" value="'+slcExtraMsr+'" readonly="readonly" />\
			<input type="hidden" name="ordQnty[]" value="'+txtQnty+'" readonly="readonly" />\
			<input type="text" value="'+txtQnty+' '+slcExtraMsr2+'" readonly="readonly" />\
		</div>\
		<div class="cave vsmall">\
			<input type="text" name="extraCost[]" value="$'+txtCost+'" readonly="readonly" />\
		</div>\
		<div class="cave vsmall subTtl"><input type="text" value="$'+subTotal+'" readonly="readonly" /></div>\
		<div class="cave vsmall"><input type="text" name="ordrDscnt[]" value="'+discount+'" readonly="readonly" /></div>\
		<div class="cave vsmall subTtl"><input type="text" value="$'+total+'" readonly="readonly" /></div>\
		<div class="cave last"><a id="remove" onclick="return removeItem('+num+');">remove</a></div>\
	</div>');
	
	$("select#slcExtra option:first").attr("selected", "selected");
	$("input#txtQnty, input#txtCost, input#subTotal, input#total").val('');
	$("input#discount").val(0);
	
	num++;
}
function check_addExtraOrder() {
	var ordrFrom	= $("#ordrFrom").val();
	var prpType		= $("#prpType").val();
	var slcAlloc	= $("#slcAlloc").val();
	
	var clientName	= $("#clientName").val();
	var clientID	= $("#clientID").val();
	
	var listItem 		= $('.listItem').find('input[name^="extraID"]').height();
	// var listItem = $("div.theForm .listItem").height();
	if(ordrFrom=="inside") {
		if(prpType.length < 1) {
			$("#error01").css("display", "inline");
			$("#error01").html("Please select property type");
			$("#prpType").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }
		
		if(slcAlloc=="---") {
			$("#error01").css("display", "inline");
			$("#error01").html("Select property");
			$("#slcAlloc").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }
		
	} else if(ordrFrom=="outside") {
		if(clientName.length < 1) {
			$("#error02").css("display", "inline");
			$("#error02").html("Select customer");
			$("#clientName").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }
		
	}
	if(listItem==null) {
		$("#error5").css("display", "inline");
		$("#error5").html("You must add at least one service to the list");
		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");
	
	return true;
}


/*-------------------------------------------------------
------------------------Quotation------------------------
-------------------------------------------------------*/

function loadQuotation(pageLimit, perPage, period) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&period='+period+'&perPage='+perPage+'&myWhouse='+myWhouse;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allQuotation&myRole="+myRole+"&myUser="+myUser,
		data: dataString,
		dataType: 'json',
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable #loading").css("display", "none");
			$("#foundNum #count").html(result['numRecords']);
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result['records']);
		}
	});
	return false;
}
function simplfyAddQuotation() {
	$(".restaurant-part").css('display','none');
	$(".service-part").css('display','none');
	$("#slcType").change(function() {
		var slcType = $("#slcType").val();
		if(slcType=='reservation'){
			$(".reservation-part").css('display','inline');
			$(".restaurant-part").css('display','none');
			$(".service-part").css('display','none');
		} else if(slcType=='restaurant'){
			$(".restaurant-part").css('display','inline');
			$(".reservation-part").css('display','none');
			$(".service-part").css('display','none');
		} else if(slcType=='service'){
			$(".restaurant-part").css('display','none');
			$(".reservation-part").css('display','none');
			$(".service-part").css('display','inline');
		}

	});

	$("#slcAllocType").change(function(){
		var slcAllocType = $("#slcAllocType").val();
		var chkInDate = $("#chkInDate").val();
		var chkOutDate = $("#chkOutDate").val();
		$.post("./includes/reception.php?action=searchRec&dest=getAllocationAmount",{ slcAllocType:slcAllocType, chkInDate:chkInDate, chkOutDate:chkOutDate }, function(data) {
			var data2 = data.split("||");
			var price = data2[0];
			var type  = data2[1]
			var group = data2[2]
			$("#txtDays").val(1);
			$("#txtPricePerday").val(price);
			$("#totalAccAmnt").val(price);
			$("#typeName").val(type);
			$("#groupName").val(group);
		});
	});
	//
	$("#txtPricePerday").keyup(function(){
		var txtDays = parseFloat($("#txtDays").val());
		var txtPricePerday = parseFloat($("#txtPricePerday").val());
		if(!txtPricePerday) txtPricePerday = 0;
		$("#totalAccAmnt").val(parseFloat(txtDays*txtPricePerday));
	});
	$("#txtDays").keyup(function(){
		var txtDays = parseFloat($("#txtDays").val());
		var txtPricePerday = parseFloat($("#txtPricePerday").val());
		if(!txtPricePerday) txtPricePerday = 0;
		$("#totalAccAmnt").val(parseFloat(txtDays*txtPricePerday));
	});
	//
	$("#slcMealOrder").change(function(){
		var slcMealOrder = $("#slcMealOrder").val();
		$.post("./includes/reception.php?action=searchRec&dest=getMealOrder",{ slcMealOrder:slcMealOrder }, function(data) {
			var data2 		= data.split("||");
			var itemName  	= data2[0];
			var packageName = data2[1];
			var costprice 	= data2[2]
			$("#txtMQty").val(1);
			$("#txtMCost").val(costprice);
			$("#totalMCost").val(costprice);
			$("#itemName").val(itemName);
			$("#packageName").val(packageName);
		});
	});
	//
	$("#txtMQty").keyup(function(){
		var txtMCost = parseFloat($("#txtMCost").val());
		var txtMQty  = parseFloat($("#txtMQty").val());
		if(!txtMQty) txtMQty = 0;
		$("#totalMCost").val(parseFloat(txtMCost*txtMQty));
	})
	//
	$("#slcExtra").change(function(){
		var slcExtra = $("#slcExtra").val();
		$.post("./includes/reception.php?action=searchRec&dest=getServiceOrder",{ slcExtra:slcExtra }, function(data) {
			var data2 		= data.split("||");
			var service  	= data2[0];
			var cost 		= data2[1];
			$("#txtSQty").val(1);
			$("#txtSCost").val(cost);
			$("#totalSCost").val(cost);
			$("#txtService").val(service);
		});
	});
	//
	$("#txtSQty").keyup(function(){
		var txtSQty = parseFloat($("#txtSQty").val());
		var txtSCost  = parseFloat($("#txtSCost").val());
		if(!txtSQty) txtSQty = 0;
		$("#totalSCost").val(parseFloat(txtSCost*txtSQty));
	})
}
function add2List4Quotation() {
	var slcType			= $("#slcType").val();
	if(slcType=='reservation'){
		var allocType		= $("#allocType").val();
		var chkInDate		= $("#chkInDate").val();
		var chkOutDate		= $("#chkOutDate").val();
		var slcAllocType	= $("#slcAllocType").val();
		var txtDays			= $("#txtDays").val();
		var txtPricePerday	= $("#txtPricePerday").val();
		var totalAccAmnt	= $("#totalAccAmnt").val();
		var typeName		= $("#typeName").val();
		var groupName		= $("#groupName").val();
		var slcRMeasure		= $("#slcRMeasure").val();
	
		if(!slcAllocType) {
			$("#eslcAllocType").css("display", "inline");
			$("#eslcAllocType").html("Select accommodation type");
			$("#slcAllocType").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }
		if(!txtPricePerday) {
			$("#etxtPricePerday").css("display", "inline");
			$("#etxtPricePerday").html("provide amount per day");
			$("#txtPricePerday").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }

		var reference   = slcAllocType;
		var measure 	= slcRMeasure;
		var orderDetail = groupName+', '+typeName;
		var qty 		= txtDays;
		var price 		= txtPricePerday;
		var total 		= parseFloat(qty*price);

	} else if(slcType=='restaurant'){
		var slcMealOrder	= $("#slcMealOrder").val();
		var itemName		= $("#itemName").val();
		var packageName		= $("#packageName").val();
		var txtMQty			= $("#txtMQty").val();
		var txtMCost		= $("#txtMCost").val();
		var totalMCost		= $("#totalMCost").val();
		var slcMMeasure		= $("#slcMMeasure").val();

		if(!slcMealOrder) {
			$("#eslcMealOrder").css("display", "inline");
			$("#eslcMealOrder").html("Please select item");
			$("#slcMealOrder").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }
		if(!txtMQty) {
			$("#etxtMQty").css("display", "inline");
			$("#etxtMQty").html("Qty is missing");
			$("#txtMQty").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }

		var reference   = slcMealOrder;
		var measure 	= slcMMeasure;
		var orderDetail = packageName+', '+itemName;
		var qty 		= txtMQty;
		var price 		= txtMCost;
		var total 		= parseFloat(totalMCost);
	
	} else if(slcType=='service'){
		var slcExtra	= $("#slcExtra").val();
		var txtService	= $("#txtService").val();
		var txtSQty		= $("#txtSQty").val();
		var txtSCost	= $("#txtSCost").val();
		var totalSCost	= $("#totalSCost").val();
		var slcSMeasure	= $("#slcSMeasure").val();
		
		if(!slcExtra) {
			$("#eslcExtra").css("display", "inline");
			$("#eslcExtra").html("Please select service type");
			$("#slcExtra").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }

		if(!txtSQty) {
			$("#etxtSQty").css("display", "inline");
			$("#etxtSQty").html("Provide service qty");
			$("#txtSQty").css("border-color", "#FF0000");
			return false;
		} else if(parseFloat(txtSQty)<1) {
			$("#etxtSQty").css("display", "inline");
			$("#etxtSQty").html("invalid quantity");
			$("#txtSQty").css("border-color", "#FF0000");
			return false;
		} else { clearErrors(); }

		var reference   = slcExtra;
		var measure 	= slcSMeasure;
		var orderDetail = txtService;
		var qty 		= txtSQty;
		var price 		= txtSCost;
		var total 		= totalSCost;

	}
	
	
	$(".theForm .list .listItem.zero").remove();
	$("div.list").append('<div class="listItem num'+num+'">\
		<div class="cave serial"></div>\
			<input type="hidden" name="itemID[]" value="'+reference+'" readonly="readonly" />\
			<input type="hidden" name="serviceType[]" value="'+slcType+'" readonly="readonly" />\
			<input type="hidden" name="quantity[]" value="'+qty+'" readonly="readonly" />\
			<input type="hidden" name="costPrice[]" value="'+price+'" readonly="readonly" />\
			<input type="hidden" name="totalPrice[]" value="'+total+'" readonly="readonly" />\
			<input type="hidden" name="measure[]" value="'+measure+'" readonly="readonly" />\
		<div class="cave medium">\
			<input type="text" value="'+slcType+'" readonly="readonly" />\
		</div>\
		<div class="cave large">\
			<input type="text" value="'+orderDetail+'" readonly="readonly" />\
		</div>\
		<div class="cave vsmall subTtl"><input type="text" value="'+qty+' '+measure+'" readonly="readonly" /></div>\
		<div class="cave vsmall"><input type="text" name="ordrDscnt[]" value="$'+price+'" readonly="readonly" /></div>\
		<div class="cave vsmall subTtl"><input type="text" value="$'+total+'" readonly="readonly" /></div>\
		<div class="cave last"><a id="remove" onclick="return removeItem('+num+');">remove</a></div>\
	</div>');
	
	num++;
}




/*-------------------------------------------------------
------------------------Gate Pass------------------------
-------------------------------------------------------*/

function smpfyGatePass() {
	$("#txtGuest").keyup(function(){
		var passedValue = $("input#txtGuest").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchGatePass", { passedValue: passedValue }, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
}
function catchGatePass(checkInDetID, propID, roomName, profileID, clientName, checkInDate, checkOutDate, title, footer) {
	$("input#guestID").val(profileID);
	$("input#checkInDetID").val(checkInDetID);
	$("input#txtGuest").val(clientName);
	$("#txtRemarks").val(title+' '+clientName+' oo Daganaaye ' +roomName+ ' '+footer);
	$("div.displayInfo").css("display", "inline");
	$("p#pGName").html(clientName);
	$("p#pRoom").html(roomName);
	$("p#pDateIn").html(checkInDate);
	$("p#pDateOut").html(checkOutDate);
	$("p#pReserveID").html('#'+checkInDetID);
	$("div.suggest").css("display", "none");
}
function check_gatePass() {
	var txtGuest		= $("#txtGuest").val();
	var guestID			= $("#guestID").val();
	var checkInDetID	= $("#checkInDetID").val();
	var txtRemarks		= $("#txtRemarks").val();
	
	if(txtGuest.length < 1 || guestID.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please select guest");
		$("#txtGuest").css("border-color", "#FF0000");
		$("div.suggest").css("display", "none");
		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");
	
	$.post("./includes/reception.php?action=saveNew&dest=addGatePass&addedBy="+myUser, { checkInDetID:checkInDetID, txtRemarks:txtRemarks }, 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: "Gate Pass has been registered successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reservation-workplace.php?role="+myRole+"&task=checkout&subtask=gatePass\
					&action=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}



/*---------------------------------------*/
function catchGnrtBill(recID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getGnrtBill", { 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 catchRecpt(recID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getRecpt", { recID:recID, 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 catchClient4Page(clientID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getClient", { clientID:clientID, 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 catchExtrOrdr(recID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getExtrOrdr", { 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");
}