	

	function FORM_LOAD()
	{
		PRODUCT_BRANCH_DGV = DataGridView("PRODUCT_BRANCH_DGV");
		PRODUCT_DGV = DataGridView("PRODUCT_DGV");

		PRODUCT_BRANCH_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				// Delete Button
				// ...........................................
				if(PRODUCT_BRANCH_DGV.COLUMN.NAME(COL_INDEX) == "DELETE_CMD")
				{
					// Delete Unsaved Item
					if
					(
						PRODUCT_BRANCH_DGV.COLUMN.IS_EXISTS("CAT_PRODBRANCH_ID") &&
						JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_ID", ROW_INDEX)) <= 0
					)
					{
						PRODUCT_BRANCH_DGV.ROW.REMOVE_AT(ROW_INDEX);
					}
					// Delete Saved Item
					else
					{
						HTTP_DELETE
						(
							function(IS_SUCCESS)
							{
								console.log('Record Deleted.');
							}, 
							ROW_INDEX
						);				
					}
				}			
			}
		); 
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CAT_PRICEMDL_ID_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_CAT_PRICEMDL_ID_CMB");
			var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRICE_MODEL.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRICEMDL_STATUS', 2);

			JSCUS_SQL._CATEGORY._PRICE_MODEL.CUS_GET
			(
				GET_MAP_ARRAY,
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					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)
					{
						return;
					}

					var JSON_COUNT = JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT");
					var COUNTER = 1;

					while(COUNTER <= JSON_COUNT)
					{
						if
						(
							JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRICEMDL_SYSTEM_GENERATED", COUNTER)) == 2 ||
							JSVC_NUM.VAR_NVAL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRICEMDL_ACC_GROUP_ID", COUNTER)) == PROPERTY_PARENT_ID
						)
						JSOC_CMB.VAR_ADD
						(
							"SEARCH_CAT_PRICEMDL_ID_CMB",
							JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRICEMDL_ID", COUNTER),
							JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRICEMDL_DESCRIPTION", COUNTER)
						);
						COUNTER++;
					}

					JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_CAT_PRICEMDL_ID_CMB", 1);
					$('#SEARCH_CAT_PRICEMDL_ID_CMB').select2();
					HTTP_SEARCH();
				},
				true
			);
		}

		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CAT_PRODUCT_TYPE_CAT_PRODTYPE_ID_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("CAT_PRODUCT_TYPE_CAT_PRODTYPE_ID_CMB");
			JSOC_CMB.VAR_ADD("CAT_PRODUCT_TYPE_CAT_PRODTYPE_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Product Type");
			var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODTYPE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODTYPE_STATUS', 2);
			JSCUS_SQL._CATEGORY._PRODTYPE.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
				},
				"CAT_PRODUCT_TYPE_CAT_PRODTYPE_ID_CMB",
				true,
				2,
				GET_MAP_ARRAY 
			);
		}
	}

	function HTTP_SEARCH(NEW_ITEM_ID, EDITED_ROW_INDEX)
	{
		var GET_MAP_ARRAY;

		if(JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_CAT_PRICEMDL_ID_CMB")) != 1)
		{
			GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
			if(JSVC_VAR.VAR_ISSET("PROPERTY_PARENT_ID"))
				JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_ACC_GROUP_ID', PROPERTY_PARENT_ID);
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, "PARAM_CAT_PRODBRANCH_CAT_PRICEMDL_ID", JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_CAT_PRICEMDL_ID_CMB")));
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_STATUS', 2);

			JSOC_DIALOG.VAR_LOADING_SPINNER(true);
			JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_GET
			(
				GET_MAP_ARRAY,
				HTTP_SEARCH_CALLBACK,
				true
			); 		
		}
		else
		{
			GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
			if(JSVC_VAR.VAR_ISSET("PROPERTY_PARENT_ID"))
				JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_ACC_GROUP_ID', PROPERTY_PARENT_ID);
			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_STATUS', 2);

			JSOC_DIALOG.VAR_LOADING_SPINNER(true);
			JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_GET
			(
				GET_MAP_ARRAY,
				HTTP_SEARCH_CALLBACK,
				true
			); 	
		}
	}
	
	// ===============================================================
	// Request Search - PART.B
	// ===============================================================

	function HTTP_SEARCH_CALLBACK(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)
		{
			PRODUCT_BRANCH_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		PRODUCT_BRANCH_DGV.POPULATE_FROM_QUERY
		(
			JSON_OBJECT, 
			'',
			false,
			false,
			1,
			[2, 1]
		);

		var ROW_INDEX = 1;
		while(PRODUCT_BRANCH_DGV.ROW.COUNT() >= ROW_INDEX)
		{
			PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_AMOUNT_PRICE_HOLDER', ROW_INDEX - 1, PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_AMOUNT_PRICE', ROW_INDEX - 1));
			PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_POINT_HOLDER', ROW_INDEX - 1, PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_POINT', ROW_INDEX - 1));
			PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_QUANTITY_HOLDER', ROW_INDEX - 1, PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_QUANTITY', ROW_INDEX - 1));
			ROW_INDEX++;
		}

		// For Applying CFormat
		// _______________________________________________________________________	
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_AMOUNT_PRICE");
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_REORDER_POINT");
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_REORDER_QUANTITY");

		//second get
		if(JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_CAT_PRICEMDL_ID_CMB")) != 1)
		{
			var GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT_BRANCH.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
			if(JSVC_VAR.VAR_ISSET("PROPERTY_PARENT_ID"))
				JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODBRANCH_ACC_GROUP_ID', PROPERTY_PARENT_ID);
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, "PARAM_CAT_PRODBRANCH_CAT_PRICEMDL_ID", JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_CAT_PRICEMDL_ID_CMB")));

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

	function HTTP_SEARCH_CALLBACK2(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();
		
		var ROW_INDEX = 1;

		//Reset parent ID stored in dgv
		// _______________________________________________________________________
		while(PRODUCT_BRANCH_DGV.ROW.COUNT() >= ROW_INDEX)
		{
			PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_ID', ROW_INDEX - 1, 0);
			ROW_INDEX++;
		}

		// 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)
		{
			return;
		}

		var JSON_COUNT = JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT");
		var COUNTER = 1;
		var ROW_INDEX = 1;

		while(COUNTER <= JSON_COUNT)
		{
			while(PRODUCT_BRANCH_DGV.ROW.COUNT() >= ROW_INDEX)
			{
				if
				(
					JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_CAT_PRODUCT_ID', ROW_INDEX - 1)) ==
					JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_CAT_PRODUCT_ID", COUNTER))
				)
				{
					PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_ID', ROW_INDEX - 1, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_ID", COUNTER));
					
					PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_AMOUNT_PRICE', ROW_INDEX - 1, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_AMOUNT_PRICE", COUNTER));
					PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_AMOUNT_PRICE_HOLDER', ROW_INDEX - 1, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_AMOUNT_PRICE", COUNTER));
					PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_POINT', ROW_INDEX - 1, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_REORDER_POINT", COUNTER));
					PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_POINT_HOLDER', ROW_INDEX - 1, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_REORDER_POINT", COUNTER));
					PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_QUANTITY', ROW_INDEX - 1, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_REORDER_QUANTITY", COUNTER));
					PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_REORDER_QUANTITY_HOLDER', ROW_INDEX - 1, JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_PRODBRANCH_REORDER_QUANTITY", COUNTER));
					break;
				}
				ROW_INDEX++;
			}
			ROW_INDEX = 1;
			COUNTER++;
		}

		// For Applying CFormat
		// _______________________________________________________________________	
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_AMOUNT_PRICE");
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_REORDER_POINT");
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_REORDER_QUANTITY");
	}

	function LOAD_MAIN_PRODUCT(NEW_ITEM_ID, EDITED_ROW_INDEX)
	{
		//CLEAR DGV
		if(PRODUCT_DGV.ROW.COUNT() > 0)
			PRODUCT_DGV.ROW.CLEAR();

		// Actual Function
		GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._PRODUCT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("CAT_PRODUCT_TYPE_CAT_PRODTYPE_ID_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODUCT_CAT_PRODTYPE_ID_LV1', JSVC_NUM.VAR_NVAL(JSOC_CMB.VAR_SELECTED_VALUE("CAT_PRODUCT_TYPE_CAT_PRODTYPE_ID_CMB")));
		}
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_PRODUCT_STATUS', 2);

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._CATEGORY._PRODUCT.CUS_GET
		(
			GET_MAP_ARRAY,
			LOAD_MAIN_PRODUCT_CALLBACK,
			true
		); 		
	}
	
	// ===============================================================
	// Request Search - PART.B
	// ===============================================================

	function LOAD_MAIN_PRODUCT_CALLBACK(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)
		{
			PRODUCT_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		PRODUCT_DGV.POPULATE_FROM_QUERY
		(
			JSON_OBJECT, 
			'',
			false,
			false,
			1,
			[2, 1]
		);

		var ROW_INDEX = 1;
		var ROW_INDEX2 = 1;

		while(PRODUCT_BRANCH_DGV.ROW.COUNT() >= ROW_INDEX)
		{
			ROW_INDEX2 = 1;
			while(PRODUCT_DGV.ROW.COUNT() >= ROW_INDEX2)
			{
				if(JSVC_NUM.VAR_NVALL(PRODUCT_BRANCH_DGV.CELL.VALUE('CAT_PRODBRANCH_CAT_PRODUCT_ID', ROW_INDEX - 1)) == JSVC_NUM.VAR_NVALL(PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_ID', ROW_INDEX2 - 1)))
				{
					PRODUCT_DGV.ROW.DISPLAY(ROW_INDEX2 - 1, "none");
				}
				ROW_INDEX2++;
			}
			ROW_INDEX++;
		}
		// For Applying CFormat
		// _______________________________________________________________________	
	}

	function DGV_ADD_PRODUCT(CALLBACK_METHOD)
	{
		var ROW_INDEX = 1;
		var RName = "PRODUCT_DGV_ROW";
		while(PRODUCT_DGV.ROW.COUNT() >= ROW_INDEX)
		{
			RName = "PRODUCT_DGV_ROW_" + ROW_INDEX;
			if
			(
				PRODUCT_DGV.CELL.VALUE('IS_SELECT', ROW_INDEX - 1) == true &&
				document.getElementById(RName).style.display != 'none'
			)
			{
				var RINDEX = PRODUCT_BRANCH_DGV.ROW.COUNT();
				PRODUCT_BRANCH_DGV.ROW.INSERT_AT(RINDEX);
				PRODUCT_BRANCH_DGV.CELL.VALUE("ROW_COUNT", RINDEX, RINDEX + 1);
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_ID", RINDEX, "0");
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_CAT_PRODUCT_ID", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_ID', ROW_INDEX - 1));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_CAT_PRODUCT_ID_DESCRIPTION", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_DESCRIPTION', ROW_INDEX - 1));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_AMOUNT_PRICE", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_AMOUNT_PRICE', ROW_INDEX - 1));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_REORDER_POINT", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_REORDER_POINT', ROW_INDEX - 1));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_REORDER_QUANTITY", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_REORDER_QUANTITY', ROW_INDEX - 1));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_AMOUNT_PRICE_HOLDER", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_AMOUNT_PRICE', ROW_INDEX - 1));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_REORDER_POINT_HOLDER", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_REORDER_POINT', ROW_INDEX - 1));
				PRODUCT_BRANCH_DGV.CELL.VALUE("CAT_PRODBRANCH_REORDER_QUANTITY_HOLDER", RINDEX, PRODUCT_DGV.CELL.VALUE('CAT_PRODUCT_REORDER_QUANTITY', ROW_INDEX - 1));
			}
			ROW_INDEX++;
		}

		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_AMOUNT_PRICE");
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_REORDER_POINT");
		PRODUCT_BRANCH_DGV.COLUMN.CFORMAT("CAT_PRODBRANCH_REORDER_QUANTITY");

		JSOC_DIALOG.VAR_MODAL("PRODUCT_MODAL", false);
	}

	FORM_INITIALIZE();
	FORM_LOAD();