/* ---------------------------------------------------------------
----------------------- search boxes  ----------------------------
------------------------------------------------------------------ */
function check_searchBox() {
	// search customer
	$("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#srchClient").blur(function() {
		if($("#srchClient").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	// search event
	$("input#srchEvent").keyup(function() {
		var passedValue = $("input#srchEvent").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchEvent", { passedValue: passedValue }, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	$("input#srchEvent").blur(function() {
		if($("#srchEvent").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	// search event order
	$("input#srchEventOrdr").keyup(function() {
		var passedValue = $("input#srchEventOrdr").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchEventOrdr", { passedValue: passedValue, myWhouse: myWhouse, myRole: myRole }, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	$("input#srchEventOrdr").blur(function() {
		if($("#srchEventOrdr").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	// search extra service register
	$("input#srchExtra").keyup(function() {
		var passedValue = $("input#srchExtra").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchExtra", { passedValue: passedValue }, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	$("input#srchExtra").blur(function() {
		if($("#srchExtra").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	// search extra order
	$("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);
			});
		}
	});
	$("input#srchExtrOrdr").blur(function() {
		if($("#srchExtrOrdr").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	// search receipt
	$("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#srchRecpt").blur(function() {
		if($("#srchRecpt").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	// search refund
	$("input#srchRefund").keyup(function() {
		var passedValue = $("input#srchRefund").val();
		if(passedValue.val!="") {
			$("div.suggest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchRefund", { passedValue: passedValue, myRole: myRole, myWhouse:myWhouse}, function(data) {
				$("div.suggest").html(data);
			});
		}
	});
	$("input#srchRefund").blur(function() {
		if($("#srchRefund").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
	// search checkIn
	$("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");
		}
	});
	// search Generate Bill
	$("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#srchGnrtBill").blur(function() {
		if($("#srchGnrtBill").val()=="") {
			$("div.suggest").css("display", "none");
		}
	});
}
/* ---------------------------------------------------------------
-------------------------- reservations --------------------------
------------------------------------------------------------------ */

function updateRsrveBar(period) {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=checkIns&myWhouse="+myWhouse+"&period="+period,
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadRsrveTwo(0,'+perPage+',\''+period+'\');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateRsrveBar(period);
			}, 60000);
		}
	});
}
function loadRsrvtion(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=allCheckIn&myRole="+myRole+"&myUser="+myUser,
		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 addClient() {
	var popCName = $("#popCName").val();
	var popCPhone = $("#popCPhone").val();
	var popCEmail = $("#popCEmail").val();
	
	if(popCName.length < 1) {
		$("#clientErr1").css("display", "inline");
		$("#clientErr1").html("Please type full name");
		$("#popCName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(popCPhone.length < 1) {
		$("#clientErr2").css("display", "inline");
		$("#clientErr2").html("Don't forget phone number");
		$("#popCPhone").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(popCEmail.length > 0) {
		if(!popCEmail.match(emailExp)) {
			$("#clientErr3").css("display", "inline");
			$("#clientErr3").html("invalid email address");
			$("#popCEmail").css("border-color", "#FF0000");
			return false;
		}
	} else { clearErrors(); }
	
	$("#btnAdd").attr("disabled", true);
	$("#btnAdd").html("wait...");
	$("div.suggest.one").css("display", "none");

	$.post("./includes/finance.php?action=saveNew&dest=addClient&addedBy="+myUser, { cname:popCName, cphone:popCPhone, cemail:popCEmail, myWhouse:myWhouse }, function(data) {
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			//
			$("input#clientID").val(lastID);
			$("input#txtClient").val(popCName);
			$("p#pName").html(popCName);
			$("p#pPhone").html(popCPhone);
			$("p#pBalance").html(0);
			$("div.displayInfo.client").css("display", "inline");
			$("#clientForm").attr("checked",false);
			$("div.popupContainer").css("display","none");
			swal({
				title: "Success!",
				text: "You added new customer successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			});
			$("#popCName, #popCPhone, #popCEmail").val("");
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add");
	});
	return false;
}
function loadRsrveTwo(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=allCheckIn&myRole="+myRole+"&myUser="+myUser,
		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 long">Bill To</div>\
                <div class="cave smiddle">Guest(s) Details</div>\
                <div class="cave lshort">Rooms Num.</div>\
                <div class="cave lshort">Status</div>\
                <div class="cave smiddle">Date</div>\
			</div>');
			$("#dataTable").append(result);
			(function (){
				//
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=checkIns&myWhouse="+myWhouse+"&period="+period,
					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 simplfyAddRsrvtn() {
	$("input#timeIn, input#timeOut").css("display","none");
	//
	$("input#txtGuest").keyup(function(){
		var txtGuest = $("#txtGuest").val();
		if(txtGuest!="") {
			$("div.suggest.guest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchGuest",{ passedValue:txtGuest, myRole:myRole, myUser:myUser}, function(data) {
				$("div.suggest.guest").html(data);
			});
		}
	   clearErrors();
	});
	$("#allocType").change(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('');
	});
	var after1year	= Number(thisYear)+1;
	/*var picker	= new Pikaday({
		field: document.getElementById("chkInDate"),
		firstDay: 6,
		yearRange: [thisYear,after1year],
	});
	//
	var picker	= new Pikaday({
		field: document.getElementById("chkOutDate"),
		firstDay: 6,
		yearRange: [thisYear,after1year],
	});*/
	var startDate,
    endDate,
    updateStartDate = function() {
		startPicker.setStartRange(startDate);
        endPicker.setStartRange(startDate);
        endPicker.setMinDate(startDate);
    },
    updateEndDate = function() {
		startPicker.setEndRange(endDate);
        startPicker.setMaxDate(endDate);
        endPicker.setEndRange(endDate);
    },
    startPicker = new Pikaday({
		field: document.getElementById("chkInDate"),
		yearRange: [thisYear,after1year],
        onSelect: function() {
			startDate = this.getDate();
            updateStartDate();
        }
    }),
    endPicker = new Pikaday({
		field: document.getElementById('chkOutDate'),
		yearRange: [thisYear,after1year],
        onSelect: function() {
			endDate = this.getDate();
            updateEndDate();
        }
    }),
    _startDate = startPicker.getDate(),
    _endDate = endPicker.getDate();
	if (_startDate) {
		startDate = _startDate;
        updateStartDate();
    }
	if (_endDate) {
		endDate = _endDate;
        updateEndDate();
    }
	//
	$("#slcPriceType").bind("change", function(e) { 
		var slcPriceType= $("#slcPriceType").val();
		var dateIn		= $("#dateIn").val();
		var dateOut		= $("#dateOut").val();
		
		if(slcPriceType=="night"){
			$("input#dateIn").css("display","none");
			$("input#dateOut").css("display","none");
		} else {
			$("input#dateIn").css("display","inline");
			$("input#dateOut").css("display","inline");
		}
	});
	//
	$("input#chkInDate, input#chkOutDate").on("blur change", function(){
		$("#srchRoom, #allocID, #allocPrice, #maxDiscount, #discount").val('');
		$("p#allocName, p#allocPrice, p#pprtyInfo, p#ameneties").html('N/A');
	});
	//
	$("input#srchRoom").keyup(function(){
		$("#allocID, #allocPrice, #maxDiscount, #discount").val('');
	
		$("p#allocName, p#allocPrice, p#pprtyInfo, p#ameneties").html('N/A');
	
		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();
	});
	//
	$("input#discount").on("keyup change", function(){
		clearErrors();
		$("#error7").removeClass("hint");
		var discount 	= parseFloat($("input#discount").val());
		var maxDiscount = parseFloat($("input#maxDiscount").val());
		if(discount == maxDiscount) {
			$("#error7").addClass("hint");
			$("#error7").css("display", "inline");
			$("#error7").html("Discount is equal to actual price");
			$("input#discount").css("border-color", "#F93");
		} else if(discount > maxDiscount) {
			$("#error7").css("display", "inline");
			$("#error7").html("Discount is greater than actual price");
			$("input#discount").css("border-color", "#FF0000");
		} 
	});
	//
	$("input#txtPayee").keyup(function(){
		var txtPayee = $("#txtPayee").val();
		$("#txtPayee").val();
		if(txtPayee!="") {
			$("div.suggest.payee").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchPayee4Rrsve",{ passedValue:txtPayee }, function(data) {
			$("div.suggest.payee").html(data);
			});
		} else { $("div.suggest.payee").css("display", "none"); }
		clearErrors();
	});
}
function simplfyAddQuotation() {
	$(".record.restaurant-part").css('display','none');
	$(".record.service-part").css('display','none');
	$("#slcType").change(function() {
		var slcType = $("#slcType").val();
		if(slcType=='reservation'){
			$(".record.reservation-part").css('display','inline');
			$(".record.restaurant-part").css('display','none');
			$(".record.service-part").css('display','none');
		} else if(slcType=='restaurant'){
			$(".record.restaurant-part").css('display','inline');
			$(".record.reservation-part").css('display','none');
			$(".record.service-part").css('display','none');
		} else if(slcType=='service'){
			$(".record.restaurant-part").css('display','none');
			$(".record.reservation-part").css('display','none');
			$(".record.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;

	}
	
	
	$("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++;
}
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,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable div#loading").css("display", "none");
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result);
		},
	});
	return false;
}
function check_addQuotation() {
	var txtGuest	= $("#txtGuest").val();
	var guestID	= $("#guestID").val();
	
	var listItem = $("div.theForm .listItem").height();
	
	if(!guestID) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please select client");
		$("#txtGuest").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }

	if(listItem<1) {
		$("#error5").css("display", "inline");
		$("#error5").html("You must add at least one order to the list");
		if(window.innerWidth<=768) { $('html, body').animate({ scrollTop: $(".record.four").offset().top }, 'slow'); }
		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");
	
	return true;
}
function catchGuest4Rsrve(clientID, clientName, phone, balance) {
	$("#guestID").val(clientID);
	$("p#pName").html(clientName);
	$("#txtGuest").val(clientName);
	$("p#pPhone").html(phone);
	$("p#pBalance").html('$'+balance);
	$("div.displayInfo.guest").css("display", "inline");
	$("div.suggest.guest").css("display", "none");
}
function addPrfle4Pop() {
	var fullname	= $("#popName").val();
	var gender		= $("#popGender").val();
	var natnlity	= $("#popNatlity").val();
	
	var phone		= $("#popPhone").val();
	var qrCode		= $("#popQrCode").val();
	var email		= $("#popEmail").val();
	var address		= $("#popAddress").val();
	var slcStatus	= $("#slcStatus").val();
	var facebook	= $("#popFacebook").val();
	var twitter		= $("#popTwitter").val();
	var booked		= $("#popBooked").val();
		
	if(fullname.length < 1) {
		$("#perror1").css("display", "inline");
		$("#perror1").html("Please type full name");
		$("#popName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(phone.length < 1) {
		$("#perror2").css("display", "inline");
		$("#perror2").html("Don't forget phone number");
		$("#popPhone").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(email.length > 0) {
		if(!email.match(emailExp)) {
			$("#perror3").css("display", "inline");
			$("#perror3").html("invalid email address");
			$("#popEmail").css("border-color", "#FF0000");
			return false;
		}
	} else { clearErrors(); }
	
	$("#btnAdd").attr("disabled", true);
	$("#btnAdd").html("wait...");
	$("div.suggest.one").css("display", "none");

	$.post("./includes/reception.php?action=saveNew&dest=addPrfleLong&addedBy="+myUser, { fullname:fullname, gender:gender, natnlity:natnlity, phone:phone, qrCode:qrCode, email:email, address:address, facebook:facebook, twitter:twitter, slcStatus:slcStatus, booked:booked},function(data){
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			//
			$("input#guestID").val(lastID);
			$("input#txtGuest").val(fullname);
			$("p#pName").html(fullname);
			$("p#pPhone").html(phone);
			$("p#pBalance").html(0);
			$("div.displayInfo.guest").css("display", "inline");
			$("#clientForm").attr("checked",false);
			$("div.popupContainer, div.suggest").css("display","none");
			swal({
				title: "Success!",
				text: "You added new profile successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			});
			$("input#popName, input#popPhone, input#popEmail, input#popAddress, input#popFacebook, input#popTwitter").val("");
			$("select#popGender:first, select#popGender:first, select#popBooked:first").attr("selected", "selected");
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add Profile");
	});
	return false;
}
function addPayee4Rsrve() {
	var fullname	= $("#popName2").val();
	var phone		= $("#popPhone2").val();
	var email		= $("#popEmail2").val();
		
	if(fullname.length < 1) {
		$("#perror11").css("display", "inline");
		$("#perror11").html("Please type full name");
		$("#popName2").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(phone.length < 1) {
		$("#perror12").css("display", "inline");
		$("#perror12").html("Don't forget phone number");
		$("#popPhone2").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(email.length > 0) {
		if(!email.match(emailExp)) {
			$("#perror13").css("display", "inline");
			$("#perror13").html("invalid email address");
			$("#popEmail2").css("border-color", "#FF0000");
			return false;
		}
	} else { clearErrors(); }
	
	$("div.suggest.payee").css("display", "none");
	$.post("./includes/reception.php?action=saveNew&dest=addClient&addedBy="+myUser, { fullname:fullname, phone:phone, email:email }, function(data) {
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			//
			$("input#payeeID").val(lastID);
			$("input#txtPayee").val(fullname);
			$("div.popupContainer").css("display","none");
			swal({
				title: "Success!",
				text: "You added new customer successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			});
			$("#payee").attr("checked",false);
			$("input#popName2, input#popPhone2, input#popEmail2").val("");
		} else {
			swal("Oops!", data, "error");
		}
	});
	return false;
}
function addIdentity() {
	var popIdentity = $("#popIdentity").val();
		
	if(popIdentity.length < 1) {
		$("#perror10").css("display", "inline");
		$("#perror10").html("Please type identity");
		$("#popIdentity").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$("#btnAdd").attr("disabled", true);
	$("#btnAdd").html("wait...");
	$("div.suggest.one").css("display", "none");

	$.post("./includes/reception.php?action=saveNew&dest=addIdentity&addedBy="+myUser, {popIdentity:popIdentity}, function(data) {
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			//
			$("#slcIdentity").append('<option value="'+lastID+'" selected="selected">'+popIdentity+'</option>');
			$("#identity").attr("checked",false);
            $("div.popupContainer").css("display", "none");
			swal({
				title: "Success!",
				text: "You added identity successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			});
			$("#popIdentity").val("");
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add Identity");
	});
	return false;
}
function catchAlloc4Rsrv(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 catchPayee4Rsrve(clientID, clientName) {
	$("input#payeeID").val(clientID);
	$("input#txtPayee").val(clientName);
	$("div.suggest.payee").css("display", "none");
}
function check_addReservation() {
	var txtGuest		= $("#txtGuest").val(); 
	var guestID			= $("#guestID").val(); 
	var allocType		= $("#allocType").val();
	var srchRoom		= $("#srchRoom").val();
	var allocID			= $("#allocID").val();
	var allocPrice		= $("#allocPrice").val();
	var maxDiscount		= $("#maxDiscount").val();
	var discount		= $("#discount").val();
	
	var chkInDate		= $("#chkInDate").val();
	var chkOutDate		= $("#chkOutDate").val();
	var timeIn			= $("#timeIn").val();
	var timeOut			= $("#timeOut").val();
	
	var status			= $("#status").val();
	var payType			= $("#payType").val();
	var payeeID			= $("#payeeID").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");			
			return false;
		} else if(chkInDate == chkOutDate) {			
			$("#error3").css("display", "inline");
			$("#error3").html("Select different days");
			$("#chkOutDate").css("border-color", "#FF0000");
			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");
			return false;
		} else { clearErrors(); }
		
	}
	if(srchRoom.length < 1 || allocID.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("Select allocation to reserve");
		$("#srchRoom").css("border-color", "#FF0000");		
		$("div.suggest.room").css("display", "none");
		return false;
	} else { clearErrors(); }
	
	if(parseFloat(discount) > parseFloat(maxDiscount)) {
		$("#error7").css("display", "inline");
		$("#error7").html("Discount is greater than actual price");
		$("input#discount").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(status.length < 1 || status=="---") {
		$("#error5").css("display", "inline");
		$("#error5").html("Select reservation status");
		$("#status").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(payType=="other") {
		if(payeeID.length < 1) {
			$("#error6").css("display", "inline");
			$("#error6").html("Select payee profile");
			$("#txtPayee").css("border-color", "#FF0000");
			$("div.suggest.payee").css("display", "none");
			return false;
		} else { clearErrors(); }
	}
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");
	return true;
}
function check_addGuest2Rsrve() {
	var txtGuest		= $("#txtGuest").val(); 
	var guestID			= $("#guestID").val(); 
	var slcIdentity		= $("#slcIdentity").val();
	var txtIdentyNo		= $("#txtIdentyNo").val();
	
	var allocType		= $("#allocType").val();
	var srchRoom		= $("#srchRoom").val();
	var allocID			= $("#allocID").val();
	var allocPrice		= $("#allocPrice").val();
	var maxDiscount		= parseFloat($("#maxDiscount").val());
	var discount		= parseFloat($("#discount").val());
	
	var chkInDate		= $("#chkInDate").val();
	var chkOutDate		= $("#chkOutDate").val();
	var timeIn			= $("#timeIn").val();
	var timeOut			= $("#timeOut").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 == 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.length < 1 || allocID.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("Select allocation to reserve");
		$("#srchRoom").css("border-color", "#FF0000");
		$('html, body').animate({ scrollTop: $(".record.four").offset().top }, 'slow');
		$("div.suggest.room").css("display", "none");
		return false;
	} else { clearErrors(); }
	
	if(discount > maxDiscount) {
		$("#error7").css("display", "inline");
		$("#error7").html("Discount is greater than actual price");
		$("input#discount").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");
	return true;
}
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 delBooking(checkInID,payeeID){
	swal({
		title: "Are you sure to delete?",
		text: "You going to remove this reservation from online booking!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#DD6B55',
		confirmButtonText: 'Yes, delete it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/reception.php?action=deleteRec&dest=delBooking", { checkInID:checkInID, payeeID:payeeID }, function(data) {
			if(data=="deleted") {
				swal({
					title: "Success!",
					text: "Selected reservation record has been deleted.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
				var count = $("label#count").html();
				$("label#count").html(count-1);
				$("a.masax.rec"+checkInID).parents("#record").fadeOut(500);
			} else {
				swal("Oops", data, "error");
			}
		});
	});
	return false;
}
function approveBooking(checkInID,payeeID,myWhouse){
	swal({
		title: "Are you sure to Approve?",
		text: "You going to make this reservation from Booked into Confirmed!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#DD6B55',
		confirmButtonText: 'Yes, Approve it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/reception.php?action=deleteRec&dest=approveBooking", { checkInID:checkInID, payeeID:payeeID, myWhouse:myWhouse, myUser:myUser }, function(data) {
			if(data=="approved") {
				swal({
					title: "Success!",
					text: "Selected reservation record has been confirmed.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
			} else {
				swal("Oops", data, "error");
			}
		});
	});
	return false;
}
function activeBooking(checkDetID){
	swal({
		title: "Are you sure?",
		text: "You going to make this reservation confirmed!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#DD6B55',
		confirmButtonText: 'Yes, activate it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/reception.php?action=deleteRec&dest=activeBooking", { checkDetID:checkDetID, myUser:myUser }, function(data) {
			if(data=="approved") {
				swal({
					title: "Success!",
					text: "Selected reservation record has been confirmed.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
			} else {
				swal("Oops", data, "error");
			}
		});
	});
	return false;
}
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: '#DD6B55',
		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;
}

//---------------------------------------------------------------//
function updateCheckIn(checkDetID){
	var txtGuest	= $("#txtGuest").val(); 
	var guestID		= $("#guestID").val();
	var allocType	= $("#allocType").val();
	var chkInDate	= $("#chkInDate").val();
	var chkOutDate	= $("#chkOutDate").val();
	var timeIn		= $("#timeIn").val();
	var timeOut		= $("#timeOut").val();
	
	if(txtGuest.length < 1 || guestID.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide guest");
		$("#txtGuest").css("border-color", "#FF0000");
		
		$("div.suggest.guest").css("display", "none");
		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(); }
	}
	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");
	return true;	
}
function simplfyUpdateRsrvtn() {
	$("input#txtGuest").keyup(function(){
		var txtGuest = $("#txtGuest").val();
		if(txtGuest!="") {
			$("div.suggest.guest").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=srchGuest",{ passedValue:txtGuest, myRole:myRole, myUser:myUser}, function(data) {
				$("div.suggest.guest").html(data);
			});
		} else { $("div.suggest.guest").css("display", "none"); }
	   clearErrors();
	});
	$("#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");
	});
	//
	var after1year = Number(thisYear)-1;
	var picker = new Pikaday({
		field: document.getElementById("chkOutDate"),
		firstDay: 6,
		minDate: new Date(minDate),
		maxDate: new Date(lastDate),
		yearRange: [after1year,thisYear],
	});
}
//-------------------Room Transfer-----------------------------//
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");
	});
	//
	var after1year = Number(thisYear);
	var picker  = new Pikaday({
		field: document.getElementById("chkInDate"),
		firstDay: 6,
		minDate: new Date(minDate),
		maxDate: new Date(maxDate),
		yearRange: [after1year,thisYear],
		onSelect: function() {
			picker2.setMinDate(this.getDate());
		}
	});
	var picker2  = new Pikaday({
		field: document.getElementById("chkOutDate"),
		firstDay: 6,
		yearRange: [after1year,thisYear],
		minDate: new Date(minDate),
		onSelect: function() {
		}
	});
	//
	$("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 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 = "./reception.php?role="+myRole+"&task=reserve&subtask=showInfo&recID="+checkInID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}

/* ---------------------------------------------------------------
---------------------- profile management  -----------------------
------------------------------------------------------------------ */

function updateClientBar() {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=clients",
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadClientsTwo(0,'+perPage+');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateClientBar();
			}, 60000);
		}
	});
}
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,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable div#loading").css("display", "none");
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result);
		},
	});
	return false;
}
function loadClientsTwo(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,
		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 xlmiddle">Fullname</div>\
                <div class="cave middle">Mobile</div>\
                <div class="cave lmiddle">Email</div>\
                <div class="cave short">Status</div>\
			</div>');
			$("#dataTable").append(result);
			(function (){
				//
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=clients",
					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_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=addPrfleLong&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 = "./reception.php?role="+myRole+"&task=prflBook&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 = "./reception.php?role="+myRole+"&task=prflBook&subtask=showInfo&recID="+clientID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
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");
}

/* ---------------------------------------------------------------
------------------------- event register  ------------------------
------------------------------------------------------------------ */

function updateEventBar() {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=events",
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadEventsTwo(0,'+perPage+');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateEventBar();
			}, 60000);
		}
	});
}
function loadEvents(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&perPage='+perPage;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allEvents&myRole="+myRole+"&myUser="+myUser,
		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 loadEventsTwo(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&perPage='+perPage;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allEvents&myRole="+myRole+"&myUser="+myUser,
		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 long">Event</div>\
                <div class="cave lshort">Event Cost</div>\
                <div class="cave lshort">Status</div>\
                <div class="cave lshort">Added Date</div>\
                <div class="cave lshort">Updated Date</div>\
			</div>');
			$("#dataTable").append(result);
			(function (){
				//
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=events",
					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_addEvent() {
	var txtName		= $("#txtName").val();
	var txtCost		= $("#txtCost").val();
		
	if(txtName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide event name");
		$("#txtName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(txtCost.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Don't forget event cost");
		$("#txtCost").css("border-color", "#FF0000");
		return false;
	} else if(txtCost <= 0) {
		$("#error2").css("display", "inline");
		$("#error2").html("Invalid event cost, must be greater than 0");
		$("#txtCost").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=addEvent&addedBy="+myUser, { txtName:txtName, txtCost:txtCost }, function(data) {
		$("label.process").css("display", "none");
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			swal({
				title: "Success!",
				text: "You registered new event successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=event&subtask=eventReg";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function check_editEvent() {
	var eventID		= $("#eventID").val();
	var txtName		= $("#txtName").val();
	var txtCost		= $("#txtCost").val();
	var slcStatus	= $("#slcStatus").val();
		
	if(txtName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide event name");
		$("#txtName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(txtCost.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Don't forget event cost");
		$("#txtCost").css("border-color", "#FF0000");
		return false;
	} else if(txtCost <= 0) {
		$("#error2").css("display", "inline");
		$("#error2").html("Invalid event cost, must be greater than 0");
		$("#txtCost").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=updateExist&dest=editEvent&updatedBy="+myUser, { eventID:eventID, txtName:txtName, txtCost:txtCost, slcStatus:slcStatus }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated event details successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=event&subtask=eventReg";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function delEvent(eventID) {
	swal({
		title: "Are you sure?",
		text: "You going to delete this event!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#DD6B55',
		confirmButtonText: 'Yes, delete it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/prptyMgt.php?action=deleteRec&dest=delEvent", { eventID:eventID }, function(data) {
			if(data=="deleted") {
				swal({
					title: "Success!",
					text: "Event record has been deleted successfully.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
				var count = $("label#count").html();
				$("label#count").html(count-1);
				$("a.masax.rec"+eventID).parents("#record").fadeOut(500);
			} else {
				swal("Oops", data, "error");
			}
		});
		return false;
	});
}
function catchEvent4Page(eventID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getEvent", { eventID:eventID, 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");
}

/* ---------------------------------------------------------------
--------------------------- event order  -------------------------
------------------------------------------------------------------ */

function updateEventOrdBar(period) {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	var dataString = 'myRole='+myRole+'&myWhouse='+myWhouse;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=eventOrder&period="+period,
		cache: false,
		data: dataString,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadEventOrderTwo(0,'+perPage+',\''+period+'\');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateEventOrdBar(period);
			}, 10000);
		}
	});
}
function loadEventOrder(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=allEventOrder&myRole="+myRole+"&myUser="+myUser,
		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 addClient4Pop() {
	var fullname	= $("#popName").val();
	var phone		= $("#popPhone").val();
	var email		= $("#popEmail").val();
		
	if(fullname.length < 1) {
		$("#perror1").css("display", "inline");
		$("#perror1").html("Please type full name");
		$("#popName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(phone.length < 1) {
		$("#perror2").css("display", "inline");
		$("#perror2").html("Don't forget phone number");
		$("#popPhone").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(email.length > 0) {
		if(!email.match(emailExp)) {
			$("#perror3").css("display", "inline");
			$("#perror3").html("invalid email address");
			$("#popEmail").css("border-color", "#FF0000");
			return false;
		}
	} else { clearErrors(); }
	
	$("button.btnAdd").attr("disabled", true);
	$("button.btnAdd").html("wait...");
	$("div.suggest.client").css("display", "none");

	$.post("./includes/reception.php?action=saveNew&dest=addClient&addedBy="+myUser, { fullname:fullname, phone:phone, email:email},function(data){
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			//
			$("input#clientID").val(lastID);
			$("input#txtClient").val(fullname);
			$("p#pName").html(fullname);
			$("p#pPhone").html(phone);
			$("p#pBalance").html(0);
			$("div.displayInfo.client").css("display", "inline");
			$("#lean_overlay").fadeOut(200);
			$("div.popupContainer, div.suggest").css("display","none");
			swal({
				title: "Success!",
				text: "You added new customer successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			});
			$("input#popName, input#popPhone, input#popEmail").val("");
		} else {
			swal("Oops!", data, "error");
		}
		$("button.btnAdd").attr("disabled", false);
		$("button.btnAdd").html("Add Customer");
	});
	return false;
}
function simplyEventOrder() {
	$("#addNew").leanModal({top : 160, overlay : 0.6, closeButton: "span.close" });
	$("input#txtClient").keyup(function(){
		var txtClient	= $("#txtClient").val();
		var pageFrom 	= 'eventOrder';
		$("#txtClient").val();
		if(txtClient!="") {
			$("div.suggest.client").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=pickClient",{ passedValue:txtClient, pageFrom:pageFrom }, function(data) {
				$("div.suggest.client").html(data);
			});
		} else { $("div.suggest.client").css("display", "none"); }
		clearErrors();
	});
	//
	$("#slcEvent").change(function() {
		var slcEvent	= $("#slcEvent").val();
		if(slcEvent!="") {
			$.post("./includes/reception.php?action=searchRec&dest=getEventCost", { slcEvent:slcEvent }, function(data) {
				$("input#eventCost").val('$'+data);
			});
		} else {
			$("input#eventCost").val('');
		}
		clearErrors();
	});
	//
	$("#checkUnit, #switchUnit").click(function(){ 
		$('div#switchUnit').toggleClass("switchOn");
		if (document.getElementById("sameUnit").checked == true) {
			document.getElementById("sameUnit").checked = false;
		} else {
			document.getElementById("sameUnit").checked = true;
		}
	});
}
function catchClient(clientID, clientName, phone, balance) {
	$("#clientID").val(clientID);
	$("div.infoWrap p#pName").html(clientName);
	$("#txtClient").val(clientName);
	$("div.infoWrap p#pPhone").html(phone);
	$("div.infoWrap p#pBalance").html('$'+balance);
	$("div.displayInfo.client").css("display", "inline");
	$("div.suggest.client").css("display", "none");
}
function check_addEventOrder() {
	var txtClient	= $("#txtClient").val();
	var clientID	= $("#clientID").val();
	var slcEvent	= $("#slcEvent").val();
	var eventCost	= $("#eventCost").val();
	var attendees	= $("#attendees").val();
	var foodCost	= $("#foodCost").val();	
	var byPerson	= $("input#sameUnit:checked").val();
	if(byPerson!="on") { var byPerson="no"; } else { var byPerson="yes"; }
	
	if(txtClient.length < 1 || clientID.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please select customer");
		$("#txtClient").css("border-color", "#FF0000");
		$("div.suggest").css("display","none");
		return false;
	} else { clearErrors(); }
	
	if(slcEvent.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Select event to order");
		$("#slcEvent").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(attendees.length < 1) {
		$("#error3").css("display", "inline");
		$("#error3").html("How many people will attend");
		$("#attendees").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=addEventOrder&addedBy="+myUser, { myWhouse:myWhouse, clientID:clientID, slcEvent:slcEvent, eventCost:eventCost, attendees:attendees, foodCost:foodCost, costType:byPerson }, function(data) {
		$("label.process").css("display", "none");
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			swal({
				title: "Success!",
				text: "You added new event order successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=event&subtask=eventOrd\
					&action=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function catchEventOrder4Page(orderID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getEventOrder", { orderID:orderID, 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");
}


/* ---------------------------------------------------------------
------------------------- extra register  ------------------------
------------------------------------------------------------------ */

function updateExtraBar() {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=extras",
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadExtraTwo(0,'+perPage+');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateExtraBar();
			}, 60000);
		}
	});
}
function loadExtras(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&perPage='+perPage;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allExtras&myRole="+myRole+"&myUser="+myUser,
		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 loadExtraTwo(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&perPage='+perPage;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allExtras&myRole="+myRole+"&myUser="+myUser,
		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 long">Service</div>\
                <div class="cave lshort">Service Cost</div>\
                <div class="cave lshort">Status</div>\
                <div class="cave lshort">Added Date</div>\
                <div class="cave lshort">Updated Date</div>\
			</div>');
			$("#dataTable").append(result);
			(function (){
				//
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=extras",
					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_addExtra() {
	var txtName		= $("#txtName").val();
	var txtCost		= $("#txtCost").val();
		
	if(txtName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide service name");
		$("#txtName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(txtCost.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Don't forget service cost");
		$("#txtCost").css("border-color", "#FF0000");
		return false;
	} else if(txtCost <= 0) {
		$("#error2").css("display", "inline");
		$("#error2").html("Invalid service cost, must be greater than 0");
		$("#txtCost").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=addExtra&addedBy="+myUser, { txtName:txtName, txtCost:txtCost }, function(data) {
		$("label.process").css("display", "none");
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			swal({
				title: "Success!",
				text: "You registered new extra service successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=extra&subtask=extraReg";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}
function check_editExtra() {
	var extraID		= $("#extraID").val();
	var txtName		= $("#txtName").val();
	var txtCost		= $("#txtCost").val();
	var slcStatus	= $("#slcStatus").val();
		
	if(txtName.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please provide service name");
		$("#txtName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(txtCost.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Don't forget service cost");
		$("#txtCost").css("border-color", "#FF0000");
		return false;
	} else if(txtCost <= 0) {
		$("#error2").css("display", "inline");
		$("#error2").html("Invalid service cost, must be greater than 0");
		$("#txtCost").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=editExtra&updatedBy="+myUser, { extraID:extraID, txtName:txtName, txtCost:txtCost, slcStatus:slcStatus }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated extra service successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=extra&subtask=extraReg";
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;
}
function delExtra(extraID) {
	swal({
		title: "Are you sure?",
		text: "You going to delete this extra service!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '#DD6B55',
		confirmButtonText: 'Yes, delete it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/prptyMgt.php?action=deleteRec&dest=delExtra", { extraID:extraID }, function(data) {
			if(data=="deleted") {
				swal({
					title: "Success!",
					text: "Extra record has been deleted successfully.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
				var count = $("label#count").html();
				$("label#count").html(count-1);
				$("a.masax.rec"+extraID).parents("#record").fadeOut(500);
			} else {
				swal("Oops", data, "error");
			}
		});
		return false;
	});
}
function catchExtra4Page(extraID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getExtra", { extraID:extraID, 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");
}


/* ---------------------------------------------------------------
----------------------- extra service order  ---------------------
------------------------------------------------------------------ */

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");
}

function updateExtraOrdrBar(period) {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	var dataString = 'period='+period+'&perPage='+perPage+'&myWhouse='+myWhouse;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=extraOrdr&myRole="+myRole+"&myUser="+myUser,
		cache: false,
		data: dataString,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadExtraOrdrTwo(0,'+perPage+',\''+period+'\');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateExtraOrdrBar(period);
			}, 60000);
		}
	});
}
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,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable div#loading").css("display", "none");
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result);
		},
	});
	return false;
}
function loadExtraOrdrTwo(pageLimit, perPage) {
	$("#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,
		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 lshort">Order No.</div>\
                <div class="cave xlmiddle">Order Details</div>\
                <div class="cave middle">No. of services ordered</div>\
                <div class="cave lshort">Amount</div>\
                <div class="cave lshort">Status</div>\
			</div>');
			$("#dataTable").append(result);
			(function (){
				//
				var dataString = 'period='+period+'&perPage='+perPage+'&myWhouse='+myWhouse;
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=extraOrdr&myRole="+myRole+"&myUser="+myUser,
					data: dataString,
					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 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 bank.",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
				$.post("./includes/reception.php?action=get_recInfo&dest=getExtraMsr4Order", {lastID:lastID},function (data) {
					$("select#slcExtraMsr").html(data);
				});
			} else {
				swal("Oops!", data, "error");
			}
		});
	});
	return false;
}
function simplyExraOrder() {
	$("div.column.outside").css("display", "none");
	$("select#ordrFrom").change(function() {
		var ordrFrom = $("#ordrFrom").val();
		if(ordrFrom=="outside") {
			$("div.column.outside").css("display", "inline");
			$("div.column.inside").css("display", "none");
		} else {
			$("div.column.outside").css("display", "none");
			$("div.column.inside").css("display", "inline");
		}
	});
	$("#addNew").leanModal({top : 160, overlay : 0.6, closeButton: "span.close" });
	$("input#txtClient").keyup(function(){
		var txtClient	= $("#txtClient").val();
		var pageFrom 	= 'extraOrder';
		$("#txtClient").val();
		if(txtClient!="") {
			$("div.suggest.client").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=pickClient",{ passedValue:txtClient, pageFrom:pageFrom }, function(data) {
				$("div.suggest.client").html(data);
			});
		} else { $("div.suggest.client").css("display", "none"); }
		clearErrors();
	});
	//
	$("select#prpType").change(function() {
		var prpType = $("#prpType").val();
		$("div.record.two div.column.right #leftPrt").html('Select Property<span id="red">*</span>');
		$("select#slcAlloc").css("display", "inline");
		$("select#slcTable").css("display", "none");
		//
		$.post("./includes/restaurant.php?action=searchRec&dest=getAlloc4Meal", { prpType: prpType }, function(data) {
		
			$("select#slcAlloc").html(data);
		});
		clearErrors();
	});
	//
	$("select#slcExtra").change(function() {
		var slcExtra 	= $("#slcExtra").val();
		
		if(slcExtra!="---") {
			$.post("./includes/reception.php?action=searchRec&dest=getExtraCost", { slcExtra: slcExtra }, function(data) {
				$("input#txtCost").val(data);
			});
		} else {
			$("input#txtCost").val('');
		}
		$("input#txtQnty, input#subTotal, input#total").val('');
		$("#discount").val(0);
		clearErrors();
	});
	//
	$("input#txtQnty").bind("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#discount").bind("keyup change", function(e) {
		var discount = parseFloat($("#discount").val());
		var subTotal = parseFloat($("#subTotal").val());
		
		if($("input#txtQnty").val()!="" && $("input#txtQnty").val()!=0) {
			if(discount != 0 || discount != "") {
				if(discount>subTotal) {
					var total = (subTotal);
					$("input#discount").val(0);
				} else {
					var total = (subTotal-discount);	
				}
				$("input#total").val(total);
			} else {
				$("input#total").val(subTotal);
			}
		} else {
			$("input#discount").val('');
			$("input#txtQnty").focus();
		}
		clearErrors();
	});
	//
	var yearLater = Number(thisYear)+1;
	var picker = new Pikaday({
		field: document.getElementById("deadLine"),
		minDate: new Date(today),
		firstDay: 6,
		yearRange: [thisYear,yearLater],
	});
}
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(); }
	
	$("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 txtClient	= $("#txtClient").val();
	var clientID	= $("#clientID").val();
	
	var listItem = $("div.theForm .listItem").height();
	
	if(ordrFrom=="inside") {
		if(prpType.length < 1) {
			$("#error1").css("display", "inline");
			$("#error1").html("Please select property type");
			$("#prpType").css("border-color", "#FF0000");
			if(window.innerWidth<=768) { $('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow'); }
			return false;
		} else { clearErrors(); }
		
		if(slcAlloc=="---") {
			$("#error2").css("display", "inline");
			$("#error2").html("Select property");
			$("#slcAlloc").css("border-color", "#FF0000");
			if(window.innerWidth<=768) {
				$('html, body').animate({ scrollTop: $(".record.two .column.right").offset().top }, 'slow'); }
			return false;
		} else { clearErrors(); }
		
	} else if(ordrFrom=="outside") {
		if(txtClient.length < 1 || clientID.length < 1) {
			$("#error3").css("display", "inline");
			$("#error3").html("Select customer");
			$("#txtClient").css("border-color", "#FF0000");
			if(window.innerWidth<=768) { $('html, body').animate({ scrollTop: $(".record.two").offset().top }, 'slow'); }
			return false;
		} else { clearErrors(); }
		
	}
	
	if(listItem<1) {
		$("#error5").css("display", "inline");
		$("#error5").html("You must add at least one service to the list");
		if(window.innerWidth<=768) { $('html, body').animate({ scrollTop: $(".record.four").offset().top }, 'slow'); }
		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("Wait...");
	
	return true;
}
function check_editExtraOrder(){
alert('great');
return false;	
}
function delExtraOrdrList(recNum, detailID, extraID, orderID){
	swal({
		title: "Are you sure to delete?",
		text: "You going to remove this service from this extra Order!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: '##6d3179',
		confirmButtonText: 'Yes, remove it!',
		closeOnConfirm: false
	},
	function() {
		$.post("./includes/reception.php?action=deleteRec&dest=delExtraOrdItm",{ detailID:detailID, extraID:extraID, orderID:orderID }, function(data){
			if(data=="deleted") {
				$("div.list div.listItem.num"+recNum).find("input").val("");
				$("div.list div.listItem.num"+recNum).fadeOut(500, function(){ $(this).remove(); });
				swal({
					title: "Success",
					text: "Meal you selected has been removed permenantly",
					type: "success",
					timer: 1500,
					showConfirmButton: false
				});
			} else {
				swal("Oops!", data, "error");
			}
		});
	});
	return false;
}
function add2NewList4Extra(){
	var slcExtra	= $("#slcExtra").val();			var slcExtra2	= $("#slcExtra :selected").text();
	var orderID 	= $("#orderID").val();
	var detailID    = $("#detailID").val();
	var extraID    	= $("#extraID").val();
	var txtQnty		= $("#txtQnty").val();
	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(txtCost.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("Price can't be empty");
		$("#txtCost").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	/**/
	
	/*$.post("./includes/receprion.php?action=saveNew&dest=addNewExtra4ExtraOrder&addedBy="+myUser, { orderID:orderID, extraID:extraID, slcExtra:slcExtra, slcExtra:slcExtra ,txtQnty:txtQnty, txtCost:txtCost, subTotal:subTotal, discount:discount, total:total}, 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 meal for this Meal order successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					location.reload();
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
	});*/
	return false;
}
/* ---------------------------------------------------------------
----------------------- Generate Bill ----------------------------
------------------------------------------------------------------ */

function updateGnrteBillBar() {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=gnrteBill",
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, <a onclick="return loadGnrteBillTwo(0,'+perPage+');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateGnrteBillBar();
			}, 60000);
		}
	});
}
function loadGnrteBill(pageLimit, perPage) {
	$("#dataTable div#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,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable div#loading").css("display", "none");
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result);
		},
	});
	return false;
}
function loadGnrteBillTwo(pageLimit, perPage) {
	$("#dataTable div#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,
		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 lshort">Invoice No.</div>\
                <div class="cave long">Bill To</div>\
                <div class="cave lshort">Property</div>\
                <div class="cave lshort">Total Amount</div>\
                <div class="cave smiddle">Generated Date</div>\
			</div>');
			$("#dataTable").append(result);
			(function (){
				//
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=gnrteBill",
					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 closeGenerate(gnrateID){
	swal({
		title: "Are you sure to cancel this bill?",
		text: "You are going to cancel a generated bill order!",
		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;
}
function simplfyGnrteBill() {
	$("#slcBillType").change(function() {
		$("#txtGuest").val('');
		$("div.displayInfo").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").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=updateExist&dest=gnrateBill&updatedBy="+myUser, { billType:billType, reference:reference, clientID:clientID, ttlAccFee:ttlAccFee}, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You successfully generated invoice bill",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=checkOut&subtask=gnrateBill\
					&action=showInfo&billType="+billType+"&reference="+reference;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Generate Bill");
		});	
	});
	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");
}


/* ----------------------------------------------------------------
----------------------------- cashier -----------------------------
------------------------------------------------------------------- */

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 updateRecptBar(period) {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	var dataString = 'period='+ period+'&myRole='+ myRole+'&myWhouse='+ myWhouse;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=receipts",
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, \
				<a onclick="return loadRecptTwo(0,'+perPage+',\''+period+'\');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateRecptBar(period);
			}, 60000);
		}
	});
}
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,
		cache: false,
		timeout: 2000,
		success: function(result){
			$("#dataTable div#loading").css("display", "none");
			$(".load_more_link").addClass('noneLink');
			$("#dataTable").append(result);
		},
	});
	return false;
}
function loadRecptTwo(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,
		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 middle">RV Number</div>\
                <div class="cave long">Payee Name</div>\
                <div class="cave lshort">Amount</div>\
                <div class="cave middle">Invoice Paid</div>\
			</div>');
			$("#dataTable").append(result);
			(function (){
				//
				var dataString2 = 'period='+ period+'&myRole='+ myRole+'&myWhouse='+ myWhouse;
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=receipts",
					data: dataString2,
					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 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());
	});
	//
	$("#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);
	});
	//
	var yearBefore = Number(thisYear)-1;
	var picker = new Pikaday({
		field: document.getElementById("transDate"),
		firstDay: 6,
		maxDate: new Date(today),
		yearRange: [yearBefore,thisYear],
	});
}
function catchClient4Rcpt(invoiceRef, payeeID, slcPurpose, payeeName, guestName, totalDue, balance) {
	$("#invoiceRef").val(invoiceRef);
	$("#payeeID").val(payeeID);
	$("#txtClient, #txtPaidBy").val(payeeName);
	$("#totalDue").val(totalDue);
	$("#txtAmount, #balance").val(balance);
	inWords($("#txtAmount").val());
	//
	if(slcPurpose != 'extraService') { $("p.guestName").show(); } else { $("p.guestName").hide(); }
	if(slcPurpose != 'deposit') { $("p.totalDue").show(); } else { $("p.totalDue").hide(); }
	$("p#pGuestName").html(payeeName);
	$("p#pTotalDue").html('$'+totalDue);
	$("p#pBalance").html('$'+balance);
	$("div.displayInfo").css("display", "inline");
	$("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 txtPaidBy	= $("#txtPaidBy").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(); }
	
	if(txtPaidBy.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("This field can't be empty");
		$("#txtPaidBy").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, txtPaidBy:txtPaidBy, 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 = "./reception.php?role="+myRole+"&task=cashier&subtask=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;	
}
function check_editCashier() {
	var receiptID	= $("#receiptID").val();
	var recptType	= $("#recptType").val();
	var totalDue	= parseFloat($("#totalDue").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 txtPaidBy	= $("#txtPaidBy").val();
	var txtRemarks	= $("#txtRemarks").val();
	
	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.1) {
		$("#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) && recptType!="deposit") {
		$("#error2").css("display", "inline");
		$("#error2").html("Amount can't be more 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(); }
	
	if(txtPaidBy.length < 1) {
		$("#error4").css("display", "inline");
		$("#error4").html("This field can't be empty");
		$("#txtPaidBy").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnUpdate").attr("disabled", true);
	$("#btnUpdate").html("Wait...");
	
	$.post("./includes/reception.php?action=updateExist&dest=editCashier&updatedBy="+myUser, { recptType:recptType, receiptID:receiptID, txtAmount:txtAmount, txtInWords:txtInWords, slcBankID:slcBankID, slcBankAcc:slcBankAcc, txtCheque:txtCheque, txtPaidBy:txtPaidBy, txtRemarks:txtRemarks }, function(data) {
		$("label.process").css("display", "none");
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated receipt record successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=cashier&subtask=showInfo&recID="+receiptID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnUpdate").attr("disabled", false);
		$("#btnUpdate").html("Update");
	});
	return false;	
}


/* ----------------------------------------------------------------
----------------------------- refund -----------------------------
------------------------------------------------------------------- */

function catchRefund(recID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getRefund", { 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 updateRefundBar() {
	var perPage = $("#slcPerPage").val();
	var period = $("#slcPeriod").val();
	var count = $("label#count").html();
	var dataString = 'myRole='+ myRole+'&myWhouse='+ myWhouse;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=refund",
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, \
				<a onclick="return loadRefundTwo(0,'+perPage+',\''+period+'\');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateRefundBar();
			}, 60000);
		}
	});
}
function loadRefund(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=allRefund&myRole="+myRole+"&myWhouse="+myWhouse,
		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 loadRefundTwo(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=allRefund&myRole="+myRole+"&myWhouse="+myWhouse,
		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 middle">PV Number</div><div class="cave long">Paid To</div><div class="cave lshort">Amount</div><div class="cave short">Invoice</div><div class="cave lshort">Date</div>></div>');
			$("#dataTable").append(result);
			
			(function (){
				//
				var dataString = 'myRole='+ myRole+'&myWhouse='+ myWhouse;
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=refund",
					data: dataString,
					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 catchRefundAmont(gnrateID, payeeID, checkInID, payeeName, ttlDepost, balance){
	$("#clientID").val(payeeID);
	$("#txtCustomer").val(payeeName);
	$("#txtBalance").val(balance);
	$("#checkInID").val(checkInID);
	$("#txtAmount").val(balance);
	inWords($("#txtAmount").val());
	$("p#pCName").html(payeeName);
	$("p#pCAmount").html('$'+ttlDepost);
	$("p#pCBalance").html('$'+balance);
	$("div.displayInfo").css("display", "inline");
	$("div.suggest.one").css("display", "none");
}
function simplifyRefundAdd(){
	$("#txtCustomer").keyup(function(){
		var passedValue = $("#txtCustomer").val();
 		$("#txtCustomer").val();
		if(passedValue!="") {
			$("div.suggest.one").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=pickRefund",{ passedValue:passedValue}, function(data) {
			$("div.suggest.one").html(data);
			});
		} else { $("div.suggest.one").css("display", "none"); }
		clearErrors();
	});
	//
	$("#slcBankID").change(function() {
		var bankID = $("#slcBankID").val();
		if(bankID=="") {
			$("#slcBankAcc").html('');
		} else {
			$.post("./includes/finance.php?action=searchRec&dest=myBankAccs", { bankID: bankID, myWhouse:myWhouse }, function(data) {
				$("#slcBankAcc").html(data);
			});
		}
	});
	//
	$("#txtRemarks").keyup(function(){
		return tweetFeed(this, 500);
	});
	//
	$("#txtAmount").keyup(function() {
		inWords($("#txtAmount").val());
	});
	//
	var kahor1sano = Number(sanadkan)-1;
	var picker = new Pikaday({
		field: document.getElementById("transDate"),
		firstDay: 6,
		maxDate: new Date(maanta),
		yearRange: [kahor1sano,sanadkan],
	});
}
function check_addRefund(){
	var txtCustomer	= $("#txtCustomer").val();
	var clientID	= $("#clientID").val();
	var txtBalance	= $("#txtBalance").val();
	var slcBankID	= $("#slcBankID").val();
	var slcBankAcc	= $("#slcBankAcc").val();
	var txtCheque	= $("#txtCheque").val();
	var txtAmount	= $("#txtAmount").val();
	var txtInWords	= $("#txtInWords").val();
	var txtRemarks	= $("#txtRemarks").val();
	var transDate   = $("#transDate").val();
	var checkInID   = $("#checkInID").val();

 	if(txtCustomer.length < 1 || clientID.length < 1) {
		$("#error1").css("display", "inline");
		$("#error1").html("Please type customer name");
		$("#txtCustomer").css("border-color", "#FF0000");
		$("div.suggest.one").css("display", "none");
		return false;
	} else { clearErrors(); }
 	
	if(slcBankID.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Please select bank name");
		$("#slcBankID").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(slcBankAcc=="---" || slcBankAcc.length < 1) {
		$("#error2").css("display", "inline");
		$("#error2").html("Select bank account");
		$("#slcBankAcc").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	 
	if(txtAmount.length < 1) {
		$("#error3").css("display", "inline");
		$("#error3").html("Amount value is missing");
		$("#txtAmount").css("border-color", "#FF0000");
		return false;
	} else if(txtAmount< 0.1) {
		$("#error3").css("display", "inline");
		$("#error3").html("Amount must be greater than 0");
		$("#txtAmount").css("border-color", "#FF0000");
		return false;
	}else { clearErrors(); }
	
	if(Number(txtAmount) > txtBalance) {
		$("#error3").css("display", "inline");
		$("#error3").html("Amount can't be greater than $"+txtBalance);
		$("#txtAmount").css("border-color", "#FF0000");
 		return false;
	} else { clearErrors(); }
	
	$("label.process").css("display", "inline");
	$("#btnSave").attr("disabled", true);
	$("#btnSave").html("wait...");
	return false;
  	$.post("./includes/reception.php?action=saveNew&dest=addRefund&addedBy="+myUser, { clientID:clientID, txtCustomer:txtCustomer, slcBankID:slcBankID, slcBankAcc:slcBankAcc, txtCheque:txtCheque, txtAmount:txtAmount, txtInWords:txtInWords, txtRemarks:txtRemarks, myWhouse:myWhouse, txtBalance:txtBalance, checkInID:checkInID, transDate:transDate},function(data){
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			swal({
				title: "Success!",
				text: "You added refund record successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			},
				function() {
					window.location = "./reception.php?role="+myRole+"&task=refund&subtask=showInfo&recID="+lastID;
				}
			);
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnSave").attr("disabled", false);
		$("#btnSave").html("Save");
	});
	return false;
}

/* ----------------------------------------------------------------
---------------------------- 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 = "./reception.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;
}

/* ----------------------------------------------------------------
----------------------- All Rooms --------------------------------
-----------------------------------------------------------------*/
function updateRoomsBar() {
	var perPage = $("#slcPerPage").val();
	var count = $("label#count").html();
	var dataString = '&myUser='+myUser+'&myRole='+ myRole;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=setFoundNum&dest=rooms",
		data: dataString,
		cache: false,
		timeout: 2000,
		success: function(result){
			if(result != count){
				$("#refresh").html('records changed, \
				<a onclick="return loadRoomsTwo(0,'+perPage+');">refresh now!</a>');
				(function blink(){
					$("span#refresh a").fadeOut(500).fadeIn(500, blink);
				})();
			}
			setTimeout(function(){
				updateRoomsBar();
			}, 60000);
		}
	});
}
function loadRooms(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+ pageLimit+'&perPage='+ perPage+'&myUser='+myUser+'&myRole='+myRole;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allRooms",
		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 loadRoomsTwo(pageLimit, perPage) {
	$("#dataTable div#loading").css("display", "inline");
	var dataString = 'pageLimit='+pageLimit+'&perPage='+perPage;
	dataString += '&myUser='+myUser+"&myRole="+myRole;
	$.ajax({
		type: "POST",
		url: "./includes/reception.php?action=loadTable&dest=allRooms",
		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 long">Property</div><div class="cave lmiddle">Price</div><div class="cave middle">Status</div></div>');
			$("#dataTable").append(result);
			(function (){
				//
				$.ajax({
					type: "POST",
					url: "./includes/reception.php?action=setFoundNum&dest=rooms",
					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 catchCheckRooms(recID) {
	$.post("./includes/reception.php?action=get_recInfo&dest=getCheckRooms", { 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 simplifyRooms() {
	var after1year	= Number(sanadkan)+1;
	var picker	= new Pikaday({
		field: document.getElementById("dateOne"),
		firstDay: 6,
		minDate: new Date(maanta),
		yearRange: [sanadkan,after1year],
	});
	//
	var picker	= new Pikaday({
		field: document.getElementById("dateTwo"),
		firstDay: 6,
		minDate: new Date(maanta),
		yearRange: [sanadkan,after1year],
	});
}

/*-------------------------------------------------------------------------------------
-------------------------- commission ------------------------------------------------
---------------------------------------------------------------------------------------*/

function addNewCommissioner() {
	var popCName = $("#popCName").val();
	var popCPhone = $("#popCPhone").val();
	
	if(popCName.length < 1) {
		$("#comm3").css("display", "inline");
		$("#comm3").html("Please type full name");
		$("#popCName").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(popCPhone.length < 1) {
		$("#comm4").css("display", "inline");
		$("#comm4").html("Don't forget phone number");
		$("#popCPhone").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$("#btnAdd").attr("disabled", true);
	$("#btnAdd").html("wait...");
	$("div.suggest.one").css("display", "none");

	$.post("./includes/reception.php?action=saveNew&dest=addNewCommissioner&addedBy="+myUser, { cname:popCName, cphone:popCPhone}, function(data) {
		var addedpos = data.search("added");
		if(addedpos==0) {
			var lastID = data.slice(6,21);
			//
			$("input#commissionerID").val(lastID);
			$("input#popTxtComm").val(popCName);

			$("div.suggest.commissioner").css("display", "inline");
			$("#addNewCommissioner").attr("checked",false);
			$("div.popupContainer").css("display","none");
			swal({
				title: "Success!",
				text: "You added new commissioner successfully.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			});
			$("#popCName, #popCPhone").val("");
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add");
	});
	return false;
}
function simplifyReservShow() {
	$("input#popTxtComm").keyup(function() {
		var popTxtComm = $("#popTxtComm").val();
		if(popTxtComm!="") {
			$("div.suggest.commissioner").css("display", "table-row");
			$.post("./includes/reception.php?action=searchRec&dest=pickCommissioner",{ passedValue:popTxtComm }, function(data) { 
				$("div.suggest.commissioner").html(data);
			});
		} else { $("div.suggest.commissioner").css("display", "none"); }
		clearErrors();
	});
	var after1year	= Number(thisYear)+1;
	var startDate,
    endDate,
    updateStartDate = function() {
		startPicker.setStartRange(startDate);
        endPicker.setStartRange(startDate);
        endPicker.setMinDate(startDate);
    },
    updateEndDate = function() {
		startPicker.setEndRange(endDate);
        startPicker.setMaxDate(endDate);
        endPicker.setEndRange(endDate);
    },
    startPicker = new Pikaday({
		field: document.getElementById("chkInDate"),
		yearRange: [thisYear,after1year],
        onSelect: function() {
			startDate = this.getDate();
            updateStartDate();
        }
    }),
    endPicker = new Pikaday({
		field: document.getElementById('chkOutDate'),
		yearRange: [thisYear,after1year],
        onSelect: function() {
			endDate = this.getDate();
            updateEndDate();
        }
    }),
    _startDate = startPicker.getDate(),
    _endDate = endPicker.getDate();
	if (_startDate) {
		startDate = _startDate;
        updateStartDate();
    }
	if (_endDate) {
		endDate = _endDate;
        updateEndDate();
    }

}
function catchCommissioner(commissionerID, commissioner, phone) {
	$("#commissionerID").val(commissionerID);
	$("#popTxtComm").val(commissioner);
	$("div.suggest.commissioner").css("display", "none");
}
//
function editInvoiceCommission() {
	var popTxtComm 		= $("#popTxtComm").val();
	var commissionerID 	= $("#commissionerID").val();
	var invocID 		= $("#invocID").val();
	var popTxtAmount 	= $("#popTxtAmount").val();
	
	if(popTxtComm.length < 1 || commissionerID.length < 1 || invocID.length < 1) {
		$("#comm1").css("display", "inline");
		$("#comm1").html("Please provide commissioner");
		$("#popTxtComm").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	if(popTxtAmount.length < 1) {
		$("#comm2").css("display", "inline");
		$("#comm2").html("Please provide amount");
		$("#popTxtAmount").css("border-color", "#FF0000");
		return false;
	} else if(parseFloat(popTxtAmount)<0.001) {
		$("#comm2").css("display", "inline");
		$("#comm2").html("Amount must greater then zero(0)");
		$("#popTxtAmount").css("border-color", "#FF0000");
		return false;
	} else { clearErrors(); }
	
	$("#btnAdd").attr("disabled", true);
	$("#btnAdd").html("wait...");
	$("div.suggest.one").css("display", "none");

	$.post("./includes/reception.php?action=updateExist&dest=editInvoiceCommission&updatedBy="+myUser, { commissionerID:commissionerID, popTxtAmount:popTxtAmount, invocID:invocID}, function(data) {
		
		if(data=="updated") {
			swal({
				title: "Success!",
				text: "You updated invoice commission.",
				type: "success",
				timer: 1500,
				showConfirmButton: false
			}, function (){
				location.reload();
			});
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add");
	});
	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 = "./reception.php?role="+myRole+"&task=reserve&subtask=showInfo&recID="+checkInID;
			});
		} else {
			swal("Oops!", data, "error");
		}
		$("#btnAdd").attr("disabled", false);
		$("#btnAdd").html("Add");
	});
	return false;
}