

	
	// ===============================================================
	// 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 = "";
	var PROPERTY_PARENT_JOLINE = 0;

	var PROPERTY_REC_INVENTORY_ID = 0;
	
	// Cache
	// _______________________________________________________________________
	var PROPERTY_REC_POSRESERVE_ID = 0;
	var PROPERTY_REC_JORDER_ID = 0;
	var PROPERTY_LS_ID = 0;
	var PROPERTY_LS_ID2 = 0;
	var PROPERTY_LS_ID3 = 0;
	var PROPERTY_REC_POSRESERVE_CODE = -1;
	var PROPERTY_EDIT_MODE = false;
	var PROPERTY_EDIT_ROW_INDEX = -1;
	var INPUT_INSTANCE = null;
	var INPUT_INSTANCE2 = null;

	// Holder
	// _______________________________________________________________________
	var TOTAL_AMOUNT = 0;
	var PROPERTY_REC_STORAGE_ID = 0; // STORE
	var JO_HOLDER = "";
	var JO_LINE_HOLDER = "";
	var RES_HOLDER = "";
	var RES_LINE_HOLDER = "";
	var PROD_HOLDER = "";
	var CUS_HOLDER = "";

	var BRANCH_HOLDER = "";

	var RES_INDEX_HOLDER = 1;
	var JO_INDEX_HOLDER = 1;

	var STATIC_PROD_ID = 2; //NEW ITEM
	var STATIC_PROD_ID2 = 13; //OLD ITEM
	var STATIC_PROD_RET_ID = 10; //NEW EMPTY ITEM
	var STATIC_PROD_RET_ID2 = 14; //OLD EMPTY ITEM
	var REB_STOCKIN_QTY = 0; //NEW EMPTY QTY
	var REB_STOCKIN_QTY2 = 0; //OLD ITEM QTY
	
	// Buttons [Optional]
	// _______________________________________________________________________
	var RES_ADD_BBI = null;
	var RES_SAVE_BBI = null;
	var RES_GROSSCALL_BBI = null;
	var RES_APPROVE_BBI = null;
	var RES_PROCESSING_BBI = null;
	var RES_ADD_PRODUCT_BBI = null;

	var JO_SAVE_BBI = null;
	var JO_DELIVERED_BBI = null;
	var JO_CANCEL_BBI = null;

	var INVENTORY_BBI = null;

	var STOPER_BBI = 0;

	var SEARCH_CMD = null;

	// var PRINT_BBI = null;
	// var EXPORT_BBI = null;

	var IS_PROCESSING = 0;
	
	// Dialog Controls [Optional]
	// _______________________________________________________________________
	var REC_POSRESERVE_ACC_GROUP_ID_CMB = null;
	var REC_POSRESERVE_REC_CLIENT_ID_CMB = null;
	var REC_POSRESERVE_REFERENCE_CODE_TXT = null;
	var REC_POSRESERVE_DATE_EXPECTED_DTP = null;
	var REC_POSRESERVE_REMARKS_TXT = null;
	var REC_POSRESERVE_STATUS_CMB = null;
	var PARAM_REC_POSRESERVE_ID_FILE_FP = null;
	
	// DGV Controls
	// _______________________________________________________________________
	var POS_RESERVE_DGV = null;
	var PRODUCT_BRANCH_DGV = null;

	var JOB_ORDER_DGV = null;
	var JOB_ORDER_TASK_DELIVER_DGV = null;
	var JOB_ORDER_TASK_RETURN_DGV = null;

	var RES_LINE_HOLDER_DGV = null;
	var JO_LINE_HOLDER_DGV = null;
	var INVENTORY_DGV = null;

	var IS_APPROVE = 0;
	var IS_JO_STATUS = 0;
	var TOTAL_OUT = 0;
	var TOTAL_INVENTORY = 0;
	var UNPRO_GROSSCALL = 0;

	var JO_DELIVERED_RECEIPT = '';

	// ===============================================================
	// Initialize Controls
	// ===============================================================     
	function FORM_INITIALIZE()
	{
		// Initialize: Modals
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("MENU_UPLOAD_BBI_DIV"))
		{
			JSOC_STYLE.VAR_DISPLAY("MENU_UPLOAD_BBI_DIV", "DEFAULT");
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_MODAL") == true)
		{
			// Display Modal
			JSOC_DIALOG.VAR_MODAL("POS_RESERVE_MODAL", false);
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_NEW_MODAL") == true)
		{
			// Display Modal
			JSOC_DIALOG.VAR_MODAL("POS_RESERVE_NEW_MODAL", false);
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CUSTOMER_MODAL") == true)
		{
			// Display Modal
			JSOC_DIALOG.VAR_MODAL("CUSTOMER_MODAL", false);
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("JOB_ORDER_MODAL") == true)
		{
			// Display Modal
			JSOC_DIALOG.VAR_MODAL("JOB_ORDER_MODAL", false);
		}
		
		// Initialize: Ribbon Buttons [Add Item]
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("RES_ADD_BBI"))
		{
  		RES_ADD_BBI = JSOC_ELEMENT.VAR_GET("RES_ADD_BBI");     	
			
			// Add OnClick event [Show Modal]
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_NEW_MODAL"))
			{
				RES_ADD_BBI.onclick = 
					function()
					{		
						// Display Modal
						PROPERTY_REC_POSRESERVE_ID = 0;
						PROPERTY_REC_JORDER_ID = 0;
						PROPERTY_PARENT_ID = 0;
						PROPERTY_LS_ID = 0;
						PROPERTY_LS_ID2 = 0;
						PROPERTY_LS_ID3 = 0;
						PROPERTY_EDIT_ROW_INDEX = -1;
						PROPERTY_REC_JORDER_CODE = '';
						
						if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE2))
						{
							JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE2);
						}
						EDIT_HANDLER.REF_IS_MODIFIED = true;

						//JSOC_CMB.VAR_SELECTED_VALUE("REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB", "");
						JSOC_CMB.VAR_SELECTED_INDEX("REC_POSRESERVE_BRANCH_PRODUCT_ID_CMB", 9999);

						if(PRODUCT_BRANCH_DGV.ROW.COUNT() > 0)
							PRODUCT_BRANCH_DGV.ROW.CLEAR();

						JSOC_DIALOG.VAR_MODAL("POS_RESERVE_NEW_MODAL", true);
					}		
			}
			// Add OnClick event [Show Add/Edit Page]
			else
			{
				
			}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("RES_ADD_PRODUCT_BBI"))
		{
			RES_ADD_PRODUCT_BBI = JSOC_ELEMENT.VAR_GET("RES_ADD_PRODUCT_BBI");
			RES_ADD_PRODUCT_BBI.onclick = function(){HTTP_ADD_PRODUCT()};
		}

		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("INVENTORY_BBI"))
		{
			INVENTORY_BBI = JSOC_ELEMENT.VAR_GET("INVENTORY_BBI");
			INVENTORY_BBI.onclick = function(){HTTP_LOAD_INVENTORY()};
		}


		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("RES_GROSSCALL_BBI"))
		{
    		RES_GROSSCALL_BBI = JSOC_ELEMENT.VAR_GET("RES_GROSSCALL_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_RES_GROSS_CALL))
			{
				// 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
				RES_GROSSCALL_BBI.onclick = 
					function()
					{
						HTTP_RES_GROSS_CALL(CALLBACK_HANDLER);
					}
			}
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("RES_SAVE_BBI"))
		{
    		RES_SAVE_BBI = JSOC_ELEMENT.VAR_GET("RES_SAVE_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_RES_SAVE))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						STOPER_BBI = 0;
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				// Add OnClick event
				if(STOPER_BBI == 0)
				{
					RES_SAVE_BBI.onclick = 
						function()
						{
							STOPER_BBI = 1;
							IS_APPROVE = 0;
							IS_PROCESSING = 0;
							IS_JO_STATUS = 0;
							HTTP_RES_SAVE(CALLBACK_HANDLER);
						}
				}
				
			}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("RES_APPROVE_BBI"))
		{
    		RES_APPROVE_BBI = JSOC_ELEMENT.VAR_GET("RES_APPROVE_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_RES_SAVE))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						STOPER_BBI = 0;
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				if(STOPER_BBI == 0)
				{
					// Add OnClick event
					RES_APPROVE_BBI.onclick = 
						function()
						{
							STOPER_BBI = 1;
							IS_APPROVE = 1;
							IS_PROCESSING = 0;
							IS_JO_STATUS = 2;
							HTTP_RES_SAVE(CALLBACK_HANDLER);
						}
				}
			}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("RES_PROCESSING_BBI"))
		{
    		RES_PROCESSING_BBI = JSOC_ELEMENT.VAR_GET("RES_PROCESSING_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_RES_SAVE))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						STOPER_BBI = 0;
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				if(STOPER_BBI == 0)
				{
					// Add OnClick event
					RES_PROCESSING_BBI.onclick = 
						function()
						{
							STOPER_BBI = 1;
							IS_APPROVE = 1;
							IS_PROCESSING = 1;
							IS_JO_STATUS = 2;
							HTTP_RES_SAVE(CALLBACK_HANDLER);
						}
				}
			}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("JO_SAVE_BBI"))
		{
    		JO_SAVE_BBI = JSOC_ELEMENT.VAR_GET("JO_SAVE_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_JO_SAVE_LINE))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						STOPER_BBI = 0;
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				if(STOPER_BBI == 0)
				{
					// Add OnClick event
					JO_SAVE_BBI.onclick = 
						function()
						{
							STOPER_BBI = 1;
							IS_JO_STATUS = 2;
							HTTP_JO_SAVE(CALLBACK_HANDLER);
						}
				}
			}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("JO_DELIVERED_BBI"))
		{
    		JO_DELIVERED_BBI = JSOC_ELEMENT.VAR_GET("JO_DELIVERED_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_JO_SAVE))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER_DELIVER = 
					function(IS_SUCCESS)
					{
						STOPER_BBI = 0;
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}

						// //ANDROID CALL
						alertify.confirm
						(
							'PeakPOS', 'Print Deliver Receipt?', 
							function(){ Android.CALL('PRINT', '<html><body>' + JO_DELIVERED_RECEIPT + '</body></html>'); }, 
							function(){ JSVC_INFO.VAR_RECORD_SAVED(''); }
						).set('closable', false, 'labels', {ok:'YES', cancel:'NO'});

						//JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				if(STOPER_BBI == 0)
				{
					// Add OnClick event'
					JO_DELIVERED_BBI.onclick = 
						function()
						{
							STOPER_BBI = 1;
							IS_JO_STATUS = 4;
							HTTP_JO_SAVE(CALLBACK_HANDLER_DELIVER);
						}
				}
			}
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("JO_CANCEL_BBI"))
		{
    		JO_CANCEL_BBI = JSOC_ELEMENT.VAR_GET("JO_CANCEL_BBI");     
			if(JSVC_VAR.VAR_ISSET(HTTP_JO_CANCEL_RESERVATION))
			{
				// Prepare Save callback
				var CALLBACK_HANDLER = 
					function(IS_SUCCESS)
					{
						STOPER_BBI = 0;
						// Abort on failure
						if(IS_SUCCESS == false)
						{
							return;
						}
					
						// Show record saved messageBox
						JSVC_INFO.VAR_RECORD_SAVED('');
					}
				
				if(STOPER_BBI == 0)
				{
					// Add OnClick event
					JO_CANCEL_BBI.onclick = 
						function()
						{
							STOPER_BBI = 1;
							HTTP_JO_CANCEL_RESERVATION(CALLBACK_HANDLER);
						}
				}
			}
		}
		

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_POSRESERVE_REC_CLIENT_ID_CMB"))
		{
			REC_POSRESERVE_REC_CLIENT_ID_CMB = JSOC_ELEMENT.VAR_GET("REC_POSRESERVE_REC_CLIENT_ID_CMB");      	
			REC_POSRESERVE_REC_CLIENT_ID_CMB.onchange = 
				function()
				{
					if(REC_POSRESERVE_REC_CLIENT_ID_CMB.disabled == false)
					{
						EDIT_HANDLER.REF_IS_MODIFIED = true;
					}
				};
			REC_POSRESERVE_REC_CLIENT_ID_CMB.onkeypress = function(){REC_POSRESERVE_REC_CLIENT_ID_CMB.onchange();};
			REC_POSRESERVE_REC_CLIENT_ID_CMB.onpaste = function(){REC_POSRESERVE_REC_CLIENT_ID_CMB.onchange();};
			//REC_POSRESERVE_REC_CLIENT_ID_CMB.oninput = function(){REC_POSRESERVE_REC_CLIENT_ID_CMB.onchange();};							
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_POSRESERVE_REFERENCE_CODE_TXT"))
		{
			REC_POSRESERVE_REFERENCE_CODE_TXT = JSOC_ELEMENT.VAR_GET("REC_POSRESERVE_REFERENCE_CODE_TXT");      
			REC_POSRESERVE_REFERENCE_CODE_TXT.onchange = 
				function()
				{
					if(REC_POSRESERVE_REFERENCE_CODE_TXT.disabled == false)
					{
						EDIT_HANDLER.REF_IS_MODIFIED = true;
					}
				};
			REC_POSRESERVE_REFERENCE_CODE_TXT.onkeypress = function(){REC_POSRESERVE_REFERENCE_CODE_TXT.onchange();};
			REC_POSRESERVE_REFERENCE_CODE_TXT.onpaste = function(){REC_POSRESERVE_REFERENCE_CODE_TXT.onchange();};
			//REC_POSRESERVE_REFERENCE_CODE_TXT.oninput = function(){REC_POSRESERVE_REFERENCE_CODE_TXT.onchange();};
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_POSRESERVE_DATE_EXPECTED_DTP"))
		{
			REC_POSRESERVE_DATE_EXPECTED_DTP = JSOC_ELEMENT.VAR_GET("REC_POSRESERVE_DATE_EXPECTED_DTP");   
			JSOC_ELEMENT.VAR_VALUE(REC_POSRESERVE_DATE_EXPECTED_DTP, JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_NOW(), "YYYY-MM-DD" + "T00:00"));
			REC_POSRESERVE_DATE_EXPECTED_DTP.onchange = 
				function()
				{
					if(REC_POSRESERVE_DATE_EXPECTED_DTP.disabled == false)
					{
						EDIT_HANDLER.REF_IS_MODIFIED = true;
					}
				};
			REC_POSRESERVE_DATE_EXPECTED_DTP.onkeypress = function(){REC_POSRESERVE_DATE_EXPECTED_DTP.onchange();};
			REC_POSRESERVE_DATE_EXPECTED_DTP.onpaste = function(){REC_POSRESERVE_DATE_EXPECTED_DTP.onchange();};
			REC_POSRESERVE_DATE_EXPECTED_DTP.oninput = function(){REC_POSRESERVE_DATE_EXPECTED_DTP.onchange();};					
		}
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_POSRESERVE_REMARKS_TXT"))
		{
			REC_POSRESERVE_REMARKS_TXT = JSOC_ELEMENT.VAR_GET("REC_POSRESERVE_REMARKS_TXT");      
			REC_POSRESERVE_REMARKS_TXT.onchange = 
				function()
				{
					if(REC_POSRESERVE_REMARKS_TXT.disabled == false)
					{
						EDIT_HANDLER.REF_IS_MODIFIED = true;
					}
				};
			REC_POSRESERVE_REMARKS_TXT.onkeypress = function(){REC_POSRESERVE_REMARKS_TXT.onchange();};
			REC_POSRESERVE_REMARKS_TXT.onpaste = function(){REC_POSRESERVE_REMARKS_TXT.onchange();};
			//REC_POSRESERVE_REMARKS_TXT.oninput = function(){REC_POSRESERVE_REMARKS_TXT.onchange();};
		}
	};