// NOTE: [This JS must loaded as last item]


	// ===============================================================
	// Initialize Form
	// ===============================================================
	function FORM_LOAD()
	{
		// Initialize
		// _______________________________________________________________________	
		var DGV_ELEMENT_CHILD = null;
		var DGV_ELEMENT_CHILD_INDEX = 0;
		
		// Load DataGridVuew
		// _______________________________________________________________________	
		POS_RESERVE_DGV = DataGridView("POS_RESERVE_DGV");
		PRODUCT_BRANCH_DGV = DataGridView("PRODUCT_BRANCH_DGV");

		// Show Progress
		// _______________________________________________________________________	
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		// Requires Authentication
		// _______________________________________________________________________	
		//PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);			
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);			
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_POSRESERVE_ACC_GROUP_ID_CMB") == true)
		{
			// Set Default Item, if used in DataGridView
			JSOC_CMB.VAR_ADD("REC_POSRESERVE_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(), "Select Branch");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._GROUP.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("REC_POSRESERVE_ACC_GROUP_ID_CMB", 0);
					
					// Clone to DGV Cell if ComboBox Exists
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_DGV_ROW_REC_POSRESERVE_ACC_GROUP_ID") == true)
					{
						DGV_ELEMENT_CHILD = JSOC_ELEMENT.VAR_SUB_ELEMENTS("POS_RESERVE_DGV_ROW_REC_POSRESERVE_ACC_GROUP_ID");
						DGV_ELEMENT_CHILD_INDEX = 0;
						while(DGV_ELEMENT_CHILD.length > DGV_ELEMENT_CHILD_INDEX)
						{
							if
							(
								DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].tagName == "SELECT" &&
								JSVC_STR.VAR_IS_BLANK(DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX].id.toString())
							)
							{
								JSOC_ELEMENT.VAR_INNER_HTML
								(
									DGV_ELEMENT_CHILD[DGV_ELEMENT_CHILD_INDEX], 
									JSOC_ELEMENT.VAR_INNER_HTML("REC_POSRESERVE_ACC_GROUP_ID_CMB")
								);
							}	
							DGV_ELEMENT_CHILD_INDEX ++;
						}
					}
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB");
						//JSOC_CMB.VAR_ADD("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Group");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("REC_POSRESERVE_ACC_GROUP_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB", 0);
						$('#SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB').select2();
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("POS_RESERVE_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("POS_RESERVE_MODAL");
					}
					
					// Forward populate complete event.
					// $('#REC_POSRESERVE_ACC_GROUP_ID_CMB').select2({
					// 	dropdownParent: $('#POS_RESERVE_MODAL')
					// });
					HTTP_POPULATE_RESULT();		
				},
				"REC_POSRESERVE_ACC_GROUP_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB") == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("REC_POSRESERVE_ACC_GROUP_ID_CMB") == false
		)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB");
			//JSOC_CMB.VAR_ADD("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Group");
			// To use custom populate
			// var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._GROUP.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_', JSCUS_SQL._SYSTEM._STATUS.STATUS_ACTIVE);	
			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB", 0);
					
					// Forward populate complete event.		
					$('#SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB').select2();
					HTTP_POPULATE_RESULT();
				},		
				"SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB",
				true, 2
				// , GET_MAP_ARRAY 
			);
		}

		LOAD_USERS();

		// Pre-Load Items (uncomment if no foreign key pre-fetch)
		// _______________________________________________________________________	
		if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
		{
			//HTTP_SEARCH();
		}
		
		// Disable Dialogs
		// _______________________________________________________________________	
		CUS_SEND_DIALOG_TRY_DISMISS();
	};

	function LOAD_USERS()
	{
		JSOC_CMB.VAR_CLEAR("SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB");
		JSOC_CMB.VAR_ADD("SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB", FLAG_BIGINT_NULL.toString(), "Select Sales Agent");
		$('#SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB').select2();

		if(JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB)) <= 0)
			return;

		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB") == true
		)
		{
			// To use custom populate
			var GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._MEMBER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

			var RESPONSE_HANDLER =
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				// Disable Dialogs
				// _______________________________________________________________________
				CUS_SEND_DIALOG_TRY_DISMISS();

				// Validate
				// _______________________________________________________________________
				if(IS_SUCCESS === false)
				{
					console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// Validate JSON Response
				// _______________________________________________________________________
				var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
				if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
				{
					console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
					return;
				}

				// Populate to CMB
				// _______________________________________________________________________
				var JSON_COUNT = JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT");

				for(var i = 1; i <= JSON_COUNT; i++)
				{
					if(JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "ACC_ACCOUNT_ACC_GROUP_ID", i)) == JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB)))
					{
						JSOC_CMB.VAR_ADD("SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB"
							, JSRC_JSON.REF_READ(JSON_OBJECT, "ACC_ACCOUNT_ID", i)
							, JSRC_JSON.REF_READ(JSON_OBJECT, "ACC_ACCOUNT_NAME", i)
						);
					}
				}

				JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB", 0);
					
				// Forward populate complete event.		
				$('#SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB').select2();
			}

			JSOC_DIALOG.VAR_LOADING_SPINNER(true);
			JSCUS_SQL._ACCOUNT._MEMBER.CUS_GET
			(
				GET_MAP_ARRAY,
				RESPONSE_HANDLER,
				true
			);
		}
	};

	function LOAD_BRANCH_PRODUCT()
	{
		var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_CAT_PRICEMDL_ID', 1);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_ACC_GROUP_ID', JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB)));
		
		var RESPONSE_HANDLER =
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				// Disable Dialogs
				// _______________________________________________________________________
				CUS_SEND_DIALOG_TRY_DISMISS();

				// Validate
				// _______________________________________________________________________
				if(IS_SUCCESS === false)
				{
					console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// Validate JSON Response
				// _______________________________________________________________________
				BRANCH_PROD_HOLDER = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
				if(JSRC_JSON.REF_IS_SUCCESS(JORDER_HOLDER) === false)
				{
					console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
					return;
				}

				HTTP_DISPLAY_DATA();
			}

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_GET
		(
			GET_MAP_ARRAY,
			RESPONSE_HANDLER,
			true
		);
	};

	function LOAD_CLIENT_PS(ROW_INDEX)
	{
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._CLIENT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_CLIENT_ID', 1);
		
		var RESPONSE_HANDLER =
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				// Disable Dialogs
				// _______________________________________________________________________
				CUS_SEND_DIALOG_TRY_DISMISS();

				// Validate
				// _______________________________________________________________________
				if(IS_SUCCESS === false)
				{
					console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// Validate JSON Response
				// _______________________________________________________________________
				var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
				if(JSRC_JSON.REF_IS_SUCCESS(JORDER_HOLDER) === false)
				{
					console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
					return;
				}

				POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_PRICING_USED", ROW_INDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRICEMDL_DESCRIPTION", 1));
			}

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._CLIENT.CUS_GET
		(
			GET_MAP_ARRAY,
			RESPONSE_HANDLER,
			true
		);
	};
	
	
	// ===============================================================
	// Populate Foreign Keys
	// ===============================================================
	function HTTP_POPULATE_RESULT(IS_SUCCESS, HTTP_RESPONSE)
	{
		// Disable Dialogs
		CUS_SEND_DIALOG_TRY_DISMISS();
			
		// Handle Error
		if(IS_SUCCESS === false)
		{
			alert("Unable to populate lists.");
		}
		else
		{
			// Disable Dialogs
			if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
			{
				//HTTP_SEARCH();
			}
		}
	};

	
	// ===============================================================
	// Request Search - PART.A
	// ===============================================================
	function HTTP_SEARCH()
	{
		if(JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB)) <= 0)
		{
			JSOC_DIALOG.VAR_MESSAGE_BOX
			(
				'Branch is required.', 
				'Information',
				'OK', 'WARNING',
				function(){	}
			);
			return;
		}

		JORDER_HOLDER = null;
		JORDER_CTR = 1;

		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._JOB_ORDER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_DATE_POST_FROM', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("SEARCH_REC_POSRESERVE_DATE_RECORDED_FROM_DTP"), "YYYY-MM-DD") + " 00:00:00.000000");
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_DATE_POST_TO', JSVC_DATE.VAR_FORMAT(JSOC_ELEMENT.VAR_VALUE("SEARCH_REC_POSRESERVE_DATE_RECORDED_TO_DTP"), "YYYY-MM-DD") + " 23:59:59.999999");
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_ACC_GROUP_ID', JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_REC_POSRESERVE_ACC_GROUP_ID_CMB)));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_USER_ASSIGN', JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_REC_POSRESERVE_ACC_ACCOUNT_ID_CMB)));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_LONG_B_FROM', 1);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_LONG_B_TO', 1);

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._JOB_ORDER.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_SEARCH_CALLBACK,
			true
		);
	}
	
	// ===============================================================
	// Request Search - PART.A
	// ===============================================================
	function HTTP_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();

		// Clear DGV
		// _______________________________________________________________________
		POS_RESERVE_DGV.ROW.CLEAR();

		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		JORDER_HOLDER = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JORDER_HOLDER) === false)
		{
			console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JORDER_HOLDER, "JSON_COUNT") <= 0)
		{
			POS_RESERVE_DGV.ROW.CLEAR();
			return;
		}

		if(JSRC_JSON.REF_READ(JORDER_HOLDER, "JSON_COUNT") > 0)
		{
			BRANCH_PROD_HOLDER = null;
			LOAD_BRANCH_PRODUCT();
		}

	};

	function HTTP_DISPLAY_DATA()
	{
		var JSON_COUNT = JSRC_JSON.REF_READ(JORDER_HOLDER, "JSON_COUNT");
		if(JORDER_CTR <= JSON_COUNT)
		{
			var RINDEX = POS_RESERVE_DGV.ROW.COUNT();
			POS_RESERVE_DGV.ROW.INSERT_AT(RINDEX);
			POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_ID", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_JORDER_ID", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_ACC_GROUP_ID", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_JORDER_ACC_GROUP_ID", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DESCRIPTION", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_JORDER_DESCRIPTION", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_REFERENCE_NUMBER", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_JORDER_REFERENCE_NUMBER", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DECIMAL_A", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_JORDER_DECIMAL_A", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_CLIENT_FIRSTNAME", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_CLIENT_FIRSTNAME", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_CLIENT_LASTNAME", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_CLIENT_LASTNAME", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_CLIENT_NAME", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_CLIENT_FIRSTNAME", JORDER_CTR) + " " + JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_CLIENT_LASTNAME", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_CLIENT_CONTACT", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_CLIENT_CONTACT", JORDER_CTR));
			POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DATE_POST", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_JORDER_DATE_POST", JORDER_CTR));
			//POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DATE_POST_RAW", RINDEX, JSRC_JSON.REF_READ(JORDER_HOLDER, "REC_JORDER_DATE_POST_RAW", JORDER_CTR));
			
			LOAD_CLIENT_PS(RINDEX);
			HTTP_GET_RESERVED_ITEMS(JSVC_NUM.VAR_NVALL(POS_RESERVE_DGV.CELL.VALUE('REC_JORDER_ID', RINDEX)));
		}
	}

	function HTTP_GET_RESERVED_ITEMS(POSRESERVE_ID)
	{
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._JOB_ORDER_TASK.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_TASK_LONG_A_FROM', JSVC_NUM.VAR_NVALL(POSRESERVE_ID));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_TASK_LONG_A_TO', JSVC_NUM.VAR_NVALL(POSRESERVE_ID));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_TASK_DECIMAL_A_FROM', 1);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_TASK_DECIMAL_A_TO', 1);

		var RESPONSE_HANDLER = 			
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				// Disable Dialogs
				// ...........................................
				CUS_SEND_DIALOG_TRY_DISMISS();

				// Validate
				// _______________________________________________________________________
				if(IS_SUCCESS === false)
				{
					console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// Validate JSON Response
				// _______________________________________________________________________
				var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
				if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
				{
					console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// JSON Empty (Clears the DataGrodView)
				// _______________________________________________________________________
				if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
				{
					CALLBACK_METHOD(false);
				}

				var INDEX = 1;
				var JSON_COUNT = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT"));

				while(JSON_COUNT >= INDEX)
				{
					var RINDEX = POS_RESERVE_DGV.ROW.COUNT();
					if(INDEX == 1)
					{
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_TASK_ITEMS", RINDEX-1, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_QTY_TARGET", INDEX)) + " X " + JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_DESCRIPTION", INDEX));
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_AMOUNT_USED", RINDEX-1, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_AMT_TARGET", INDEX));
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_AMOUNT_USED_TOTAL", RINDEX-1, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_QTY_TARGET", INDEX)) * JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_AMT_TARGET", INDEX))));
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_PROD_COST", RINDEX-1, "0.00");
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT", RINDEX-1, "0.00");
					}
					else
					{
						POS_RESERVE_DGV.ROW.INSERT_AT(RINDEX);
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_TASK_ITEMS", RINDEX, JSVC_NUM.VAR_CFORMAT(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_QTY_TARGET", INDEX)) + " X " + JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_DESCRIPTION", INDEX));
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_AMOUNT_USED", RINDEX, JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_AMT_TARGET", INDEX));
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_AMOUNT_USED_TOTAL", RINDEX-1, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_QTY_TARGET", INDEX)) * JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_AMT_TARGET", INDEX))));
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_PROD_COST", RINDEX, "0.00");
						POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT", RINDEX, "0.00");
					}

					var BPRODCTR = 1;
					while(JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(BRANCH_PROD_HOLDER, "JSON_COUNT")) >= BPRODCTR)
					{
						if
						(
							JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_DECIMAL_B", INDEX)) ==
							JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(BRANCH_PROD_HOLDER, "CAT_PRODUCT_ID", BPRODCTR))
						)
						{
							if(INDEX == 1)
							{
								POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_PROD_COST", RINDEX-1, JSRC_JSON.REF_READ(BRANCH_PROD_HOLDER, "CAT_PRODBRANCH_AMOUNT_PRICE", BPRODCTR));
								POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT", RINDEX-1, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_PROD_COST", RINDEX-1)) - JSVC_NUM.VAR_NVAL(POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_AMOUNT_USED", RINDEX-1))));
								POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT_TOTAL", RINDEX-1, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT", RINDEX-1)) * JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_QTY_TARGET", INDEX))));
							}
							else
							{
								POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_PROD_COST", RINDEX, JSRC_JSON.REF_READ(BRANCH_PROD_HOLDER, "CAT_PRODBRANCH_AMOUNT_PRICE", BPRODCTR));
								POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT", RINDEX, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_PROD_COST", RINDEX)) - JSVC_NUM.VAR_NVAL(POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_AMOUNT_USED", RINDEX))));
								POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT_TOTAL", RINDEX, JSVC_NUM.VAR_CFORMAT(JSVC_NUM.VAR_NVAL(POS_RESERVE_DGV.CELL.VALUE("REC_JORDER_DISCOUNT", RINDEX)) * JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_JORDER_TASK_QTY_TARGET", INDEX))));
							}
							break;
						}
						BPRODCTR++;
					}


					// <th id="POS_RESERVE_DGV_HEADER_" style="cursor: pointer;">Items</th>
					// <th id="POS_RESERVE_DGV_HEADER_REC_JORDER_PRICING_USED" style="cursor: pointer;">Pricing</th>¶
					// <th id="POS_RESERVE_DGV_HEADER_REC_JORDER_PROD_COST" style="display: none;">Product Amount</th>
					// <th id="POS_RESERVE_DGV_HEADER_REC_JORDER_DISCOUNT" style="cursor: pointer;">Discount</th>

					INDEX++;
				}

				if(JORDER_CTR < JSRC_JSON.REF_READ(JORDER_HOLDER, "JSON_COUNT"))
				{
					JORDER_CTR++;
					HTTP_DISPLAY_DATA();
					console.log(1);
				}
			};

		
		JSCUS_SQL._RECORD._JOB_ORDER_TASK.CUS_GET
		(
			GET_MAP_ARRAY,
			RESPONSE_HANDLER,
			true
		);	
	}
				
	// ===============================================================
	// Begin Processing the Page
	// ===============================================================
	FORM_INITIALIZE();
	FORM_LOAD();