	// ===============================================================
	// Global Var
	// ===============================================================
	
	// Edit Handler
	// _______________________________________________________________________
	var EDIT_HANDLER = function(){};	
	EDIT_HANDLER.REF_IS_MODIFIED = false;
	EDIT_HANDLER.HAS_NEWLY_SAVED_DATA = false;
	var PROPERTY_PARENT_ID = 0;
	var PROPERTY_PARENT_DESCRIPTION = "";
	
	
	// Cache
	// _______________________________________________________________________
	var PROPERTY_MODE_ID = -1;
	var PROPERTY_REC_INVENTORY_ID = -1;
	var PROPERTY_EDIT_MODE = false;
	var PROPERTY_EDIT_ROW_INDEX = -1;
	var INPUT_INSTANCE = null;
	
	
	// Buttons [Optional]
	// _______________________________________________________________________
	var ADD_BBI = null;
	var SAVE_BBI = null;
	var DELETE_BBI = null;
	var CANCEL_BBI = null;
	var NAVIGATION_BACK_BBI = null;
	
	var LOAD_MORE_BBI = null;
	var LOAD_PREV_BBI = null;
	var LOAD_NEXT_BBI = null;
	var LOAD_PAGING_CMB = null;
	var LOAD_PAGING_IGNORE_NEXT_REQUEST = false;
	
	var SEARCH_CMD = null;
	var PRINT_BBI = null;
	var EXPORT_BBI = null;
	
	
	// Dialog Controls [Optional]
	// _______________________________________________________________________
	var POSITIVE_STOCKFLOW_CMB = null;
	var NEGATIVE_STOCKFLOW_CMB = null;
	var ADJUSTMENT_TXT = null;
	var BAG_QUANTITY_TXT = null;
	var CONTENT_QUANTITY_TXT = null;
	var REC_INVENTORY_QUANTITY_TXT = null;
	var REC_STOCKCARD_REMARKS_TXT = null;

	var BACKDATE_DTP = null;
	
	// DGV Controls
	// _______________________________________________________________________
	var INVENTORY_DGV = null;
	var INVENTORY_LAST_GET_MAP_ARRAY = null;


	// ===============================================================
	// Initialize Controls
	// ===============================================================     
	function FORM_INITIALIZE()
	{
		// Load Cache Parent Data [Add Redirects if this is a required data.]
		// ...........................................
		if(JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_ID_INVENTORY"))
		{
			PROPERTY_PARENT_ID = JSVC_COOKIE.VAR_READ("PROPERTY_PARENT_ID_INVENTORY");
		}	
		else
		{
			//window.location = JSCUS_CACHE.AUTH_REDIRECT_URL[JSCUS_CACHE.LOGIN_CLASS];
			//window.close();
		}
		if(JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_DESCRIPTION_INVENTORY"))
		{
			PROPERTY_PARENT_DESCRIPTION = JSVC_COOKIE.VAR_READ("PROPERTY_PARENT_DESCRIPTION_INVENTORY");
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAGE_PARENT_DESCRIPTION_TXT") == true)
			{
				JSOC_ELEMENT.VAR_VALUE("PAGE_PARENT_DESCRIPTION_TXT", PROPERTY_PARENT_DESCRIPTION);			
			}
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAGE_PARENT_DESCRIPTION_LBL") == true)
			{
				JSOC_ELEMENT.VAR_VALUE("PAGE_PARENT_DESCRIPTION_LBL", PROPERTY_PARENT_DESCRIPTION);			
			}
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PAGE_TITLE_LBL") == true)
			{
				JSOC_ELEMENT.VAR_VALUE("PAGE_TITLE_LBL", JSOC_ELEMENT.VAR_VALUE("PAGE_TITLE_LBL") + " : " + PROPERTY_PARENT_DESCRIPTION);	
			}
		}	
		else
		{
			//window.location = JSCUS_CACHE.AUTH_REDIRECT_URL[JSCUS_CACHE.LOGIN_CLASS];	
		}
	
		// Restore Cache on reload
		// ...........................................	
		if
		(
			JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_ID_INVENTORY") || 
			JSVC_COOKIE.VAR_ISSET("PROPERTY_PARENT_DESCRIPTION_INVENTORY")
		)
		{
			  window.onbeforeunload = function(event)
			  {
					// Get Current Root path
					var CURRENT_ROOT_PATH = JSCUS_CACHE.ROOT_PATH + JSVC_STR.VAR_MID(JSVC_STR.VAR_DLEFT(JSCUS_CACHE.AUTH_REDIRECT_URL[JSCUS_CACHE.LOGIN_CLASS], JSCUS_CACHE.SERVER_URL.length), 1, 1);
				
					// Cache Primary Key
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_ID_INVENTORY', 
						PROPERTY_PARENT_ID, 
						5, 
						CURRENT_ROOT_PATH
					);
					
					// Cache Description
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_DESCRIPTION_INVENTORY', 
						PROPERTY_PARENT_DESCRIPTION, 
						5, 
						CURRENT_ROOT_PATH
					);
			  };
		}
		
		// Assign Fixed Parent (Must remove auto-populate at ch.js and HTTP_PARENT_LOAD at eh.js)
		// ...........................................
		/*
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PARENT_SELECT_CMB"))
		{
			JSOC_CMB.VAR_ADD
			(
				"PARENT_SELECT_CMB", 
				PROPERTY_PARENT_ID,
				PROPERTY_PARENT_DESCRIPTION
			);
		}
		*/
		
		
 		// Cache Class Properties
		// ...........................................
		if(JSVC_COOKIE.VAR_ISSET("PROPERTY_REC_INVENTORY_ID"))
		{
			PROPERTY_REC_INVENTORY_ID = JSVC_COOKIE.VAR_READ("PROPERTY_REC_INVENTORY_ID");
		}	
		if(JSVC_COOKIE.VAR_ISSET("PROPERTY_EDIT_MODE"))
		{
			PROPERTY_EDIT_MODE = JSVC_COOKIE.VAR_READ("PROPERTY_REC_INVENTORY_ID");
		}
	
		// Initialize: Modals
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVENTORY_MODAL") == true)
		{
			// Display Modal
			JSOC_DIALOG.VAR_MODAL("INVENTORY_MODAL", false);
		}
				
		// Initialize: Ribbon Buttons [Add Item]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ADD_BBI"))
		{
    		ADD_BBI = JSOC_ELEMENT.VAR_GET("ADD_BBI");     	
			
			// Add OnClick event [Show Modal]
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVENTORY_MODAL"))
			{
				ADD_BBI.onclick = 
					function()
					{		
						// Display Modal
						PROPERTY_REC_INVENTORY_ID = FLAG_BIGINT_NULL;
						PROPERTY_EDIT_ROW_INDEX = -1;
						
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
						}
						EDIT_HANDLER.REF_IS_MODIFIED = true;
						JSOC_DIALOG.VAR_MODAL("INVENTORY_MODAL", true);
					};					
			}
			// Add OnClick event [Show Add/Edit Page]
			else
			{
				
			}
		}	
		
		// Initialize: Ribbon Buttons [Save Changes]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SAVE_BBI"))
		{
    		SAVE_BBI = JSOC_ELEMENT.VAR_GET("SAVE_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_SAVE))
			{
				// 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
				SAVE_BBI.onclick = function()
				{
					if(JSVC_STR.VAR_IS_BLANK(JSOC_ELEMENT.VAR_VALUE(BACKDATE_DTP)) == false )
					{
						JSOC_DIALOG.VAR_MESSAGE_BOX
						(
							"You are creating backdate stock adjustment. Do you want to continue?", 
							"Backdate Stock Adjustment", 
							JSOC_DIALOG.MSGBOX_TYPE_YES_NO,
							JSOC_DIALOG.MSGBOX_ICON_QUESTION,
							function(RETURNED_RESULT)
							{
								if(RETURNED_RESULT == JSOC_DIALOG.MSGBOX_YES)
								{
									HTTP_SAVE(CALLBACK_HANDLER);
								}
							}
						)
					}
					else
					{
						HTTP_SAVE(CALLBACK_HANDLER);
					}
				};
			}
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CANCEL_BBI"))
		{
    		CANCEL_BBI = JSOC_ELEMENT.VAR_GET("CANCEL_BBI");      		
		}
		
		// Initialize: Ribbon Buttons [Add Back Link (to parent page)]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("NAVIGATION_BACK_BBI"))
		{
    		NAVIGATION_BACK_BBI = JSOC_ELEMENT.VAR_GET("NAVIGATION_BACK_BBI");  
			
			// Add OnClick event
			NAVIGATION_BACK_BBI.onclick = 
				function()
				{
				};
		}
		
		// Initialize: Ribbon Buttons [Add Forward Link (to child page)]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("NAVIGATION_BACK_BBI"))
		{
    		NAVIGATION_BACK_BBI = JSOC_ELEMENT.VAR_GET("NAVIGATION_BACK_BBI");  
			
			// Add OnClick event
			NAVIGATION_BACK_BBI.onclick = 
				function()
				{
				};	
		}
		
		// Initialize: Load more items to the list
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LOAD_MORE_BBI"))
		{
    		LOAD_MORE_BBI = JSOC_ELEMENT.VAR_GET("LOAD_MORE_BBI");  
			LOAD_MORE_BBI.onclick = 
				function()
				{
					HTTP_SEARCH_LOAD_MORE();
				};
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LOAD_PREV_BBI"))
		{
    		LOAD_PREV_BBI = JSOC_ELEMENT.VAR_GET("LOAD_PREV_BBI");  
			LOAD_PREV_BBI.onclick = 
				function()
				{
					var CURRENT_INDEX = JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB);
					if(CURRENT_INDEX > 0)
					{
						JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB, CURRENT_INDEX - 1);
						LOAD_PAGING_CMB.onchange();
					}
				};
		}		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LOAD_NEXT_BBI"))
		{
    		LOAD_NEXT_BBI = JSOC_ELEMENT.VAR_GET("LOAD_NEXT_BBI");  
			LOAD_NEXT_BBI.onclick = 
				function()
				{
					var CURRENT_INDEX = JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB);
					if(CURRENT_INDEX + 1 < JSOC_CMB.VAR_COUNT(LOAD_PAGING_CMB))
					{
						JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB, CURRENT_INDEX + 1);
						LOAD_PAGING_CMB.onchange();
					}
				};
		}		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("LOAD_PAGING_CMB"))
		{
    		LOAD_PAGING_CMB = JSOC_ELEMENT.VAR_GET("LOAD_PAGING_CMB");  
			LOAD_PAGING_CMB.onchange = 
				function()
				{
					HTTP_SEARCH_LOAD_PAGE();
				};
		}

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

		// Initialize: Ribbon Buttons [Add Print]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("PRINT_BBI"))
		{
			PRINT_BBI = JSOC_ELEMENT.VAR_GET("PRINT_BBI");
			PRINT_BBI.onclick = function()
			{
				window.print();
			};
		}		
		
		// Initialize: Ribbon Buttons [Add Search]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("EXPORT_BBI"))
		{
			EXPORT_BBI = JSOC_ELEMENT.VAR_GET("EXPORT_BBI");
			EXPORT_BBI.onclick = function()
			{
				JSOC_DIALOG.VAR_LOADING_SPINNER(true);
				JSRC_THREAD.REF_POST_DELAYED			
				(
					async function()
					{
						await JSRC_EXCEL.REF_EXPORT('INVENTORY_DGV');
						CUS_SEND_DIALOG_TRY_DISMISS();
					},
					100
				);
			};
		}		

		
		// Prepare onChange event
		// ...........................................
		var ON_CHANGE_EVENT = '';
		
		
		// Initialize: Input Controls
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POSITIVE_STOCKFLOW_CMB"))
		{
			POSITIVE_STOCKFLOW_CMB = JSOC_ELEMENT.VAR_GET("POSITIVE_STOCKFLOW_CMB");      	
			POSITIVE_STOCKFLOW_CMB.onchange = 
				function()
				{
					if(POSITIVE_STOCKFLOW_CMB.disabled == false)
					{
						EDIT_HANDLER.REF_IS_MODIFIED = true;
					}
					
					if(JSOC_CMB.VAR_SELECTED_VALUE(POSITIVE_STOCKFLOW_CMB) == "2")
					{
						JSOC_ELEMENT.VAR_READONLY(PRICE_TXT, false);
						JSOC_ELEMENT.VAR_ENABLED(PRICE_TXT,  true);
					}
					else
					{
						JSOC_ELEMENT.VAR_READONLY(PRICE_TXT, true);
						JSOC_ELEMENT.VAR_ENABLED(PRICE_TXT,  false);
					}
				};
			POSITIVE_STOCKFLOW_CMB.onkeypress = function(){POSITIVE_STOCKFLOW_CMB.onchange();};
			POSITIVE_STOCKFLOW_CMB.onpaste = function(){POSITIVE_STOCKFLOW_CMB.onchange();};						
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("NEGATIVE_STOCKFLOW_CMB"))
		{
			NEGATIVE_STOCKFLOW_CMB = JSOC_ELEMENT.VAR_GET("NEGATIVE_STOCKFLOW_CMB");      	
			NEGATIVE_STOCKFLOW_CMB.onchange = 
				function()
				{
					if(NEGATIVE_STOCKFLOW_CMB.disabled == false)
					{
						EDIT_HANDLER.REF_IS_MODIFIED = true;
					}
				};
			NEGATIVE_STOCKFLOW_CMB.onkeypress = function(){NEGATIVE_STOCKFLOW_CMB.onchange();};
			NEGATIVE_STOCKFLOW_CMB.onpaste = function(){NEGATIVE_STOCKFLOW_CMB.onchange();};						
		}
		
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_INVENTORY_QUANTITY_TXT"))
		{
			REC_INVENTORY_QUANTITY_TXT = JSOC_ELEMENT.VAR_GET("REC_INVENTORY_QUANTITY_TXT");      	
			REC_INVENTORY_QUANTITY_TXT.onchange = function()
			{
				// Positive
				// ...........................................
				if(PROPERTY_MODE_ID == 1)
				{
					JSOC_ELEMENT.VAR_VALUE
					(
						'RESULT_TXT', 
						(
							JSOC_ELEMENT.VAR_VALUE_NVAL('CURRENT_TXT') +
							JSOC_ELEMENT.VAR_VALUE_NVAL('REC_INVENTORY_QUANTITY_TXT')
						)
					);						
				}
				
				//Negative
				// ...........................................
				else if(PROPERTY_MODE_ID == 2)
				{
					JSOC_ELEMENT.VAR_VALUE
					(
						'RESULT_TXT', 
						(
							JSOC_ELEMENT.VAR_VALUE_NVAL('CURRENT_TXT') -
							JSOC_ELEMENT.VAR_VALUE_NVAL('REC_INVENTORY_QUANTITY_TXT')
						)
					);						
				}
				
				// Adjustment
				// ...........................................
				else
				{
					JSOC_ELEMENT.VAR_VALUE
					(
						'RESULT_TXT', 
						JSOC_ELEMENT.VAR_VALUE_NVAL('REC_INVENTORY_QUANTITY_TXT')
					);							
				}

			};
			REC_INVENTORY_QUANTITY_TXT.onkeypress = function(){REC_INVENTORY_QUANTITY_TXT.onchange();};
			REC_INVENTORY_QUANTITY_TXT.onpaste = function(){REC_INVENTORY_QUANTITY_TXT.onchange();};						
		}	
		
			
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("BAG_QUANTITY_TXT"))
		{
			BAG_QUANTITY_TXT = JSOC_ELEMENT.VAR_GET("BAG_QUANTITY_TXT");      	
			BAG_QUANTITY_TXT.onchange = function()
			{
				RECOMPUTE_INVENTORY_BALANCE();
			};
			BAG_QUANTITY_TXT.onkeypress = function(){BAG_QUANTITY_TXT.onchange();};
			BAG_QUANTITY_TXT.onpaste = function(){BAG_QUANTITY_TXT.onchange();};						
		}			
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CONTENT_QUANTITY_TXT"))
		{
			CONTENT_QUANTITY_TXT = JSOC_ELEMENT.VAR_GET("CONTENT_QUANTITY_TXT");      	
			CONTENT_QUANTITY_TXT.onchange = function()
			{
				RECOMPUTE_INVENTORY_BALANCE();
			};
			CONTENT_QUANTITY_TXT.onkeypress = function(){CONTENT_QUANTITY_TXT.onchange();};
			CONTENT_QUANTITY_TXT.onpaste = function(){CONTENT_QUANTITY_TXT.onchange();};						
		}					
		
			
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("BACKDATE_DTP"))
		{
			BACKDATE_DTP = JSOC_ELEMENT.VAR_GET("BACKDATE_DTP");  
		BACKDATE_DTP.dataset.onedit = "false";
			
			BACKDATE_DTP.onchange = function()
			{
				BACKDATE_DTP.dataset.onedit = "true";
			};
			BACKDATE_DTP.onkeydown = function(e)
			{
				if(event.which == 13 || event.keyCode == 13 || event.key === 'Enter')
				{
					BACKDATE_DTP.dataset.onedit = "false";
					HTTP_RELOAD_QTY_BACKDATE(null);
				}
			};
			BACKDATE_DTP.onfocusout = function()
			{
				if(BACKDATE_DTP.dataset.onedit == "true")
				{
					BACKDATE_DTP.dataset.onedit = "false";
					HTTP_RELOAD_QTY_BACKDATE(null);
				}
			};
		}
			
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REMARKS_TXT"))
		{
			REMARKS_TXT = JSOC_ELEMENT.VAR_GET("REMARKS_TXT");      	
			REMARKS_TXT.onchange = function(){};
			REMARKS_TXT.onkeypress = function(){REMARKS_TXT.onchange();};
			REMARKS_TXT.onpaste = function(){REMARKS_TXT.onchange();};						
		}
				
		
		// Initialize: Default Settings
		// ...........................................
		// FORM_PREPARE_DEFAULT_SETTINGS();   	
	};
	
	RECOMPUTE_INVENTORY_BALANCE = function()
	{
		if(PROPERTY_MODE_ID != 3)
		{
			JSOC_ELEMENT.VAR_VALUE
			(
				REC_INVENTORY_QUANTITY_TXT, 
				(
					JSOC_ELEMENT.VAR_VALUE_NVAL('BAG_QUANTITY_TXT') * 
					JSOC_ELEMENT.VAR_VALUE_NVAL('NET_CONTENT_TXT')
				) + JSOC_ELEMENT.VAR_VALUE_NVAL('CONTENT_QUANTITY_TXT')
			);	
			REC_INVENTORY_QUANTITY_TXT.onchange();										
		}	
		else
		{
			JSOC_ELEMENT.VAR_VALUE
			(
				REC_INVENTORY_QUANTITY_TXT, 
				(
					(
						JSOC_ELEMENT.VAR_VALUE_NVAL('BAG_QUANTITY_TXT') * 
						JSOC_ELEMENT.VAR_VALUE_NVAL('NET_CONTENT_TXT')
					) + JSOC_ELEMENT.VAR_VALUE_NVAL('CONTENT_QUANTITY_TXT')
				)
			);	
			REC_INVENTORY_QUANTITY_TXT.onchange();	
				
				
			JSOC_ELEMENT.VAR_VALUE
			(
				REC_INVENTORY_QUANTITY_TXT, 
				JSOC_ELEMENT.VAR_VALUE_NVAL('REC_INVENTORY_QUANTITY_TXT') - 
				JSOC_ELEMENT.VAR_VALUE_NVAL('CURRENT_TXT')
			);	
			
							
			if(JSOC_ELEMENT.VAR_VALUE_NVAL(REC_INVENTORY_QUANTITY_TXT) > 0)
			{
				JSOC_CMB.VAR_SELECTED_VALUE('ADJUST_STOCKFLOW_CMB', '5');
			}			
			else if(JSOC_ELEMENT.VAR_VALUE_NVAL(REC_INVENTORY_QUANTITY_TXT) < 0)
			{
				JSOC_CMB.VAR_SELECTED_VALUE('ADJUST_STOCKFLOW_CMB', '4');				
				JSOC_ELEMENT.VAR_VALUE_NVAL
				(
					REC_INVENTORY_QUANTITY_TXT, 
					JSOC_ELEMENT.VAR_VALUE_NVAL(REC_INVENTORY_QUANTITY_TXT) * -1
				); 
			}		
			
				
		}	
	};