	// ===============================================================
	// Global Var
	// ===============================================================

	var PROPERTY_REC_PRODUCT_ID = -1;
	var PROPERTY_REC_PRODUCT_QTY = 0;
	var PROPERTY_REC_PRODUCT_TYPES = [];

	var PROPERTY_REC_CUSTOMER_INDEX = -1;
	var PROPERTY_REC_CUSTOMER_NAME = '';
	var PROPERTY_REC_CUSTOMER_TIN = '';
	var PROPERTY_REC_CUSTOMER_ADDRESS = '';

	var PROPERTY_REC_TRANSACTION_IDS = [];
	var PROPERTY_REC_TRANSACTION_REFNO = '';


	var ADD_QTY_BBI = null;
	var SUBTRACT_QTY_BBI = null;
	var CHANGE_QTY_BBI = null;

	var ADD_ITEM_BBI = null;
	var VOID_BBI = null;

	var OPEN_SEARCH_BBI = null;
	var CLOSE_SEARCH_BBI = null;

	var SCAN_BARCODE_CMD = null;
	var SCAN_LOYALTY_CMD = null;
	var SEARCH_CMD = null;

	var SEARCH_CUSTOMER_TXT = '';
	var SEARCH_DESC_TXT = '';

	var SAVE_BBI = null;

	var CUSTOMERS_BBI = null;
	var SEL_CUST_BBI = '';
	var DESEL_CUST_BBI = '';

	var RECEIPT = '';	

	var CART_DGV = null;
	var CUSTOMERS_DGV = null;

	var PRODUCT_BRANCH_LV = null;


	// ===============================================================
	// Initialize Controls
	// ===============================================================     
	function FORM_INITIALIZE()
	{

		// Initialize: Ribbon Buttons [Add Quantity]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ADD_QTY_BBI"))
		{
    		ADD_QTY_BBI = JSOC_ELEMENT.VAR_GET("ADD_QTY_BBI"); 

    		// Add OnClick event [Show Modal]
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_QTY_MODAL"))
			{
				ADD_QTY_BBI.onclick = 
					function()
					{	
						NEW_QTY = 1;

						INPUT_QTY = JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY"));
						NEW_QTY += INPUT_QTY;

						JSOC_ELEMENT.VAR_VALUE("PROD_QTY", NEW_QTY);
					}		
			}
			// Add OnClick event [Show Add/Edit Page]
			else
			{
				
			}
		}

		// Initialize: Ribbon Buttons [Subtract Quantity]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SUBTRACT_QTY_BBI"))
		{
    		SUBTRACT_QTY_BBI = JSOC_ELEMENT.VAR_GET("SUBTRACT_QTY_BBI"); 

    		// Add OnClick event [Show Modal]
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_QTY_MODAL"))
			{
				SUBTRACT_QTY_BBI.onclick = 
					function()
					{	
						NEW_QTY = 1;

						INPUT_QTY = JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY"));
						NEW_QTY = INPUT_QTY - NEW_QTY;

						if(NEW_QTY >= 1)
							JSOC_ELEMENT.VAR_VALUE("PROD_QTY", NEW_QTY);
					}		
			}
			// Add OnClick event [Show Add/Edit Page]
			else
			{
				
			}
		}


		// Initialize: Ribbon Buttons [Add Item]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ADD_ITEM_BBI"))
		{
    		ADD_ITEM_BBI = JSOC_ELEMENT.VAR_GET("ADD_ITEM_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_ADD_ITEM))
    		{
    			// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						//JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				// Add OnClick event
				ADD_ITEM_BBI.onclick = 
					function()
					{
						if(JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY")) > 0)
						{
							HTTP_ADD_ITEM(CALLBACK_HANDLER);
						}
						else
						{
							PROD_QTY.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
							PROD_QTY.focus();
							CALLBACK_METHOD(false);
						}
					}
    		}
		}

		// Initialize: Ribbon Buttons [Void Order]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("VOID_BBI"))
		{
    		VOID_BBI = JSOC_ELEMENT.VAR_GET("VOID_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_VOID))
    		{
    			// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						//JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				// Add OnClick event
				VOID_BBI.onclick = 
					function()
					{
						if(CART_DGV.ROW.COUNT() > 0)
						{
							alertify.confirm
							(
								'PeakPOS', 
								'Are you sure you want to cancel this transaction?',
								function()
								{
									HTTP_VOID
									(
										function(IS_SUCCESS)
										{
											if(IS_SUCCESS)
											{
												alertify.error('Transaction cancelled.', 'success');
											}
										}
									);	
								},
								function(){}
							).set('labels', {ok:'YES', cancel:'NO'});
						}
						
					}
    		}
		}


		// Initialize: Ribbon Buttons [Open/Show Search Bar]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("OPEN_SEARCH_BBI"))
		{
    		OPEN_SEARCH_BBI = JSOC_ELEMENT.VAR_GET("OPEN_SEARCH_BBI"); 
    		OPEN_SEARCH_BBI.onclick =
    			function()
    			{
    				$('.div-categories').addClass('d-none');
					$('.div-search').removeClass('d-none');

					$('#SEARCH_DESC_TXT').focus();
    			};
		}

		// Initialize: Ribbon Buttons [Close/Hide Search Bar]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CLOSE_SEARCH_BBI"))
		{
    		CLOSE_SEARCH_BBI = JSOC_ELEMENT.VAR_GET("CLOSE_SEARCH_BBI"); 
    		CLOSE_SEARCH_BBI.onclick =
    			function()
    			{
    				$('.div-search').addClass('d-none');
					$('.div-categories').removeClass('d-none');

					$('#SEARCH_DESC_TXT').val('');
					$('#CATEGORY_CMB').focus();
    			};
		}


		// Initialize: Ribbon Buttons [Scan Barcode]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SCAN_BARCODE_CMD"))
		{
    		SCAN_BARCODE_CMD = JSOC_ELEMENT.VAR_GET("SCAN_BARCODE_CMD"); 
    		SCAN_BARCODE_CMD.onclick = function(){Android.CALL('SCAN_BARCODE', 'SEARCH_DESC_TXT')};
		}


		// Initialize: Ribbon Buttons [Search]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD"))
		{
    		SEARCH_CMD = JSOC_ELEMENT.VAR_GET("SEARCH_CMD");
			SEARCH_CMD.onclick = function(){HTTP_SEARCH()};
		}


		// Initialize: Ribbon Buttons [Edit QTY Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("EDIT_QTY_BBI"))
		{
    		EDIT_QTY_BBI = JSOC_ELEMENT.VAR_GET("EDIT_QTY_BBI"); 

    		// Add OnClick event [Show Modal]
			EDIT_QTY_BBI.onclick = 
				function()
				{	
					if(CART_DGV.ROW.COUNT() > 0)
			    	{
			    		if($('#CART_DGV tr.table-warning').length >= 1)
						{
							if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_QTY_MODAL") == true)
							{
								// Clear Modal
								if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
								{
									JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
								}
										
								// Display Modal
								JSOC_ELEMENT.VAR_GET("ADD_ITEM_BBI").classList.add("d-none");
								JSOC_ELEMENT.VAR_GET("CHANGE_QTY_BBI").classList.remove("d-none");

								JSOC_ELEMENT.VAR_VALUE("PROD_QTY", PROPERTY_REC_PRODUCT_QTY);
								JSOC_DIALOG.VAR_MODAL("POS_QTY_MODAL", true);
								return;
							}								
						}
						else
						{
							alertify.error('No item selected.');
						}
			    	}
			    	else
					{
						alertify.error('No items in cart.');
					}
				};
		}


		// Initialize: Ribbon Buttons [Update Item QTY]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CHANGE_QTY_BBI"))
		{
    		CHANGE_QTY_BBI = JSOC_ELEMENT.VAR_GET("CHANGE_QTY_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_EDIT_QUANTITY))
    		{
    			// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						//JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				// Add OnClick event
				CHANGE_QTY_BBI.onclick = 
					function()
					{
						if(JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("PROD_QTY")) > 0)
						{
							HTTP_EDIT_QUANTITY(CALLBACK_HANDLER);
						}
						else
						{
							PROD_QTY.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
							PROD_QTY.focus();
							CALLBACK_METHOD(false);
						}
					}
    		}
		}





		// Initialize: Ribbon Buttons [Customers Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTOMERS_BBI"))
		{
    		CUSTOMERS_BBI = JSOC_ELEMENT.VAR_GET("CUSTOMERS_BBI"); 

    		// Add OnClick event [Show Modal]
			CUSTOMERS_BBI.onclick = 
				function()
				{	
			    	if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_CUSTOMERS_MODAL") == true)
					{
						// Clear Modal
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
						}
										
						// Display Modal

						//remove all highlights
						$('tr[id^="CUSTOMERS_DGV_ROW_"]').each(function(i, item) {
							$(this).removeClass('table-warning');
						});

						JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_MODAL", true);
						HTTP_LOAD_CUSTOMERS();
						return;
					}
				};
		}

		// Initialize: Ribbon Buttons [Search Customers]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CUSTOMER_CMD"))
		{
    		SEARCH_CUSTOMER_CMD = JSOC_ELEMENT.VAR_GET("SEARCH_CUSTOMER_CMD");
			SEARCH_CUSTOMER_CMD.onclick = function(){HTTP_LOAD_CUSTOMERS()};
		}


		// Initialize: Ribbon Buttons [Select Customer]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEL_CUST_BBI"))
		{
    		SEL_CUST_BBI = JSOC_ELEMENT.VAR_GET("SEL_CUST_BBI"); 
				
			// Add OnClick event
			SEL_CUST_BBI.onclick = 
				function()
				{
					if($('#CUSTOMERS_DGV tr.table-warning').length >= 1)
					{
						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID', PROPERTY_REC_CUSTOMER_INDEX);
						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_NAME', PROPERTY_REC_CUSTOMER_NAME);
						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_TIN', PROPERTY_REC_CUSTOMER_TIN);
						JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ADDRESS', PROPERTY_REC_CUSTOMER_ADDRESS);

						$('#DESEL_CUST_BBI').removeClass('d-none');

						JSOC_DIALOG.VAR_MODAL("POS_CUSTOMERS_MODAL", false);
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'No customer selected.',
							'Information',
							'OK', 'ERROR',
							function() {}
						);
					}
				}
		}

		// Initialize: Ribbon Buttons [Deselect Customer]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DESEL_CUST_BBI"))
		{
    		DESEL_CUST_BBI = JSOC_ELEMENT.VAR_GET("DESEL_CUST_BBI"); 
				
			// Add OnClick event
			DESEL_CUST_BBI.onclick = 
				function()
				{
					alertify.confirm
					(
						'PeakPOS', 'Are you sure you want to remove selected customer?', 
						
						function() 
						{ 
							PROPERTY_REC_CUSTOMER_INDEX = -1;
							PROPERTY_REC_CUSTOMER_NAME = '';
							PROPERTY_REC_CUSTOMER_TIN = '';
							PROPERTY_REC_CUSTOMER_ADDRESS = '';

							JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ID', 1);
							JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_NAME', '-');
							JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_TIN', '');
							JSOC_ELEMENT.VAR_VALUE('POS_CUSTOMER_ADDRESS', '');

							$('#DESEL_CUST_BBI').addClass('d-none');
							
						},
						
						function()
						{
							
						}
				    ).set('labels', {ok:'YES', cancel:'Cancel'});
				}
		}




		// Initialize: Ribbon Buttons [Transactions Modal]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("TRANSACTIONS_BBI"))
		{
    		TRANSACTIONS_BBI = JSOC_ELEMENT.VAR_GET("TRANSACTIONS_BBI"); 

    		// Add OnClick event [Show Modal]
			TRANSACTIONS_BBI.onclick = 
				function()
				{	
					if(CART_DGV.ROW.COUNT() <= 0)
					{
						if(JSVC_STR.VAR_IS_BLANK(PROPERTY_REC_TRANSACTION_REFNO) == true)
						{
							alertify.prompt('PeakPOS', 'Enter table number:', '', function(evt, value) {
								PROPERTY_REC_TRANSACTION_REFNO = value;
								HTTP_LOAD_ORDER();
							}, function() {
								PROPERTY_REC_TRANSACTION_REFNO = '';
							}).set('type', 'number');
						}
						else
						{
							JSOC_DIALOG.VAR_MESSAGE_BOX
							(
								'A transaction is currently loaded. Cannot load another transaction.',
								'Information',
								'OK', 'ERROR',
								function(){}
							);
						}
					}
					else
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							'The cart is not empty. Cannot load a transaction.',
							'Information',
							'OK', 'ERROR',
							function(){}
						);
					}
				};
		}



		// Initialize: Ribbon Buttons [Place Order]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("RESERVE_BBI"))
		{
    		RESERVE_BBI = JSOC_ELEMENT.VAR_GET("RESERVE_BBI"); 

    		if(JSVC_VAR.VAR_ISSET(HTTP_SAVE))
    		{
    			// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						if(IS_SUCCESS)
						{
							// Abort on failure
							if(IS_SUCCESS == false)
							{
								return;
							}
						
							// Show record saved messageBox
							//JSVC_INFO.VAR_RECORD_SAVED("");
						}
					}

    			// Add OnClick event [Show Modal]
				RESERVE_BBI.onclick = 
					function()
					{	
						if(CART_DGV.ROW.COUNT() > 0)
						{
							alertify.prompt
							(
								'PeakPOS', 
								'Enter table number:', 
								'', 
								function(evt, value) {
									HTTP_SAVE(CALLBACK_HANDLER, value);
								}, 
								function() {

								}
							).set('type', 'number');
						}
						else
						{
							alertify.error('No items in cart.');
						}
					};
    		}
    		
		}



		// Prepare onChange event
		// ...........................................
		var ON_CHANGE_EVENT = '';


		// Initialize: Input Controls
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CATEGORY_CMB"))
		{
			CATEGORY_CMB = JSOC_ELEMENT.VAR_GET("CATEGORY_CMB");      
			CATEGORY_CMB.onchange = 
				function()
				{
					//hide all
					$('div[id^="PRODUCT_BRANCH_LV_ROW_CAT_PRODUCT_ID_"]').parent().parent().each(function() {
						$(this).addClass('d-none');
					});

					//filter
					if(JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("CATEGORY_CMB")) === 0) {
						//show all
						$('div[id^="PRODUCT_BRANCH_LV_ROW_CAT_PRODUCT_ID_"]').parent().parent().each(function() {
							$(this).removeClass('d-none');
						});
					}
					else {
						$('div[id^="PRODUCT_BRANCH_LV_ROW_CAT_PRODUCT_CAT_PRODTYPE_ID_LV1_"]').each(function() {
							if(JSVC_NUM.VAR_NVALL($(this).html()) == JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE("CATEGORY_CMB"))) {
								$(this).parent().parent().removeClass('d-none');
							}
						});
					}
				};
		}
	}