// NOTE: [This JS must loaded as last item]
JSTOOL_CUSTOMIZE.RECAPTION = function(){};

	// ===============================================================
	// Part 0 : Initialize Form
	// ===============================================================	
	JSTOOL_CUSTOMIZE.RECAPTION.DGV = null;
	JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV = null;
	JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_CMD = null;
	JSTOOL_CUSTOMIZE.RECAPTION.APPLY_CMD = null;
	JSTOOL_CUSTOMIZE.RECAPTION.CANCEL_CMD = null;
	
	JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ID_TXT = null;
	JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_URL_TXT = null;
	JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB = null;
	JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_CODE_TXT = null;
	JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_DESCRIPTION_TXT = null;
	JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_LSTRING_TXT = null;
				
	JSTOOL_CUSTOMIZE.RECAPTION.INPUT_INSTANCE = null;
	JSTOOL_CUSTOMIZE.RECAPTION.INPUT_INSTANCE_EDIT = null;
	JSTOOL_CUSTOMIZE.RECAPTION.CONFIG_URL = null;
	JSTOOL_CUSTOMIZE.RECAPTION.TOOL_TITLE = 'RECAPTION';


	/**
	 * Break hidden element list in string to array
	 */
	JSTOOL_CUSTOMIZE.RECAPTION.LIST_TO_ARRAY = function(LIST_STRING)
	{
		// Initialize
		// _______________________________________________________________________
		var HIDDEN_ELEMENTS = [];
		var RESULT_ELEMENTS = [];
	
		// Actual Function
		// _______________________________________________________________________
		if(JSVC_STR.VAR_IS_BLANK(LIST_STRING))
		{
			return [];
		}
		
		// Single Entry
		// _______________________________________________________________________
		if(JSVC_STR.VAR_CONTAINS(LIST_STRING, ",") == false)
		{
			return [LIST_STRING];
		}
		HIDDEN_ELEMENTS = LIST_STRING.split(",");
		
		// Remove empty
		// _______________________________________________________________________
		while(JSVC_ARR.VAR_EMPTY(HIDDEN_ELEMENTS) == false)
		{
			if(JSVC_STR.VAR_IS_BLANK(HIDDEN_ELEMENTS[0]) == false)
			{
				RESULT_ELEMENTS.push(HIDDEN_ELEMENTS[0]);
			}
			HIDDEN_ELEMENTS.shift();
		}	
		
		// Return result
		// _______________________________________________________________________
		return RESULT_ELEMENTS;
	};
	

	// ===============================================================
	// Part 1 : Initialize Form
	// ===============================================================
	
	/**
	 *	Show Customer Selection modal
	 *	@param CALLBACK_METHOD Optional Callback on successful action. Method(ID, DESCRIPTION)
	 *	@param CALLBACK_CONTROL Optional Modal will assign a value to a element on success.
	 */	
	JSTOOL_CUSTOMIZE.RECAPTION.SHOW = function
	(
		CONFIG_URL, CONFIG_LEVEL
	)
	{
		// Initialize New Configuration
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.RECAPTION.CONFIG_URL = CONFIG_URL;

		// Initialize
		// _______________________________________________________________________
		if(JSVC_VAR.VAR_ISSET(JSTOOL_CUSTOMIZE.RECAPTION.DGV) == false)
		{
			// Initialize Modal and DGV
			// ...........................................
			JSTOOL_CUSTOMIZE.RECAPTION.DGV = DataGridView("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_DGV");
			JSTOOL_CUSTOMIZE.RECAPTION.DGV.ON_CLICK
			(			
				function(COL_INDEX, ROW_INDEX)
				{
					if(COL_INDEX != JSTOOL_CUSTOMIZE.RECAPTION.DGV.COLUMN.INDEX("ROW_IS_SELECTED"))
					{
						JSTOOL_CUSTOMIZE.RECAPTION.DGV.CELL.VALUE("ROW_IS_SELECTED", ROW_INDEX, true);
					}
				}
			);   	
			
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV = DataGridView("RECAPTION_APPLY_MODAL_CATEGORY_CUSTOMIZE_DGV");
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ON_CLICK
			(			
				function(COL_INDEX, ROW_INDEX)
				{
					// Delete Button
					// ...........................................
					if(JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.COLUMN.NAME(COL_INDEX) == "DELETE_BBI")
					{
						// Delete Unsaved Item
						JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.REMOVE_AT(ROW_INDEX);
					}	
				}
			);   	
			
			JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ID_TXT = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_ID_TXT");
			JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_URL_TXT = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_URL_TXT");
			JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_ACC_LEVEL_ID_CMB");
			JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_CODE_TXT = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_CODE_TXT");
			JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_DESCRIPTION_TXT = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_DESCRIPTION_TXT");
			JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_LSTRING_TXT = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_LSTRING_TXT");
	
			JSTOOL_CUSTOMIZE.RECAPTION.INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("RECAPTION_MODAL_CATEGORY_CUSTOMIZE");			
		
			// Initialize: Button
			// ...........................................
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_CMD = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_RECAPTION_CMD");
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_CMD.onclick = function()
				{
					JSTOOL_CUSTOMIZE.RECAPTION.DIALOG_HIDE();
				};
				
			JSTOOL_CUSTOMIZE.RECAPTION.APPLY_CMD = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_APPLY_CMD");
			JSTOOL_CUSTOMIZE.RECAPTION.APPLY_CMD.onclick = function()
				{
					JSTOOL_CUSTOMIZE.RECAPTION.DIALOG_SAVE();
				};
				
			JSTOOL_CUSTOMIZE.RECAPTION.CANCEL_CMD = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_CANCEL_CMD");
			JSTOOL_CUSTOMIZE.RECAPTION.CANCEL_CMD.onclick = function()
				{
					JSOC_DIALOG.VAR_MODAL("RECAPTION_MODAL_CATEGORY_CUSTOMIZE", false);
				};
							
			// Foreign Field
			// ...........................................
			JSOC_CMB.VAR_CLEAR(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB);
			JSCUS_SQL._ACCOUNT._LEVEL.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(IS_SUCCESS, RESPONSE_STRING)
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB, "1");
					JSOC_CMB.VAR_TEXT
					(
						JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB,
						JSOC_CMB.VAR_SELECTED_INDEX(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB), 
						"-- EVERYONE -- "
					);
				},		
				JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB,
				true, 2
			);
		
			// Onetime Loading
			// ...........................................
			JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_LOAD_ELEMENTS();
		}
		
		// Clean Modal
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.CLEAR();
		JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(JSTOOL_CUSTOMIZE.RECAPTION.INPUT_INSTANCE);
		
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_URL_TXT, JSTOOL_CUSTOMIZE.RECAPTION.CONFIG_URL);
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_CODE_TXT,  JSCUS_CACHE.CONFIG_CODE + JSTOOL_CUSTOMIZE.RECAPTION.TOOL_TITLE);
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_DESCRIPTION_TXT, 'Replace captions in element');
		
		// New Data
		// _______________________________________________________________________
		if(JSVC_STR.VAR_IS_BLANK(CONFIG_URL))
		{
			// Initialize New Configuration
			// ...........................................
			JSTOOL_CUSTOMIZE.RECAPTION.CONFIG_URL =  JSVC_URL._CURRENT.VAR_PATH();
			
			// Apply Configuration
			// ...........................................
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ID_TXT, 0);
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_URL_TXT, JSTOOL_CUSTOMIZE.RECAPTION.CONFIG_URL);
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_LSTRING_TXT, "");
			JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB, "1");
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.CLEAR();
			
			// Display Modal
			// ...........................................
			JSOC_DIALOG.VAR_MODAL("RECAPTION_MODAL_CATEGORY_CUSTOMIZE", true);
		}
		
		// Load Data
		// _______________________________________________________________________
		else
		{
			JSTOOL_CUSTOMIZE.RECAPTION.LOAD
			(
				JSTOOL_CUSTOMIZE.RECAPTION.CONFIG_URL,
				CONFIG_LEVEL,
				function(CONFIG_ID, CONFIG_DATA, CONFIG_LEVEL)
				{
					// Apply Configuration
					// ...........................................
					JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ID_TXT, CONFIG_ID);
					JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_LSTRING_TXT, CONFIG_DATA);
					JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB, CONFIG_LEVEL);
					
					// On Load Action
					// ...........................................
					JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_RESTORE();
					
				
					// Display Modal
					// ...........................................
					JSOC_DIALOG.VAR_MODAL("RECAPTION_MODAL_CATEGORY_CUSTOMIZE", true);
				}
			);
		}
	};
	
	
	// ===============================================================
	// Part 2.A : Load Elements
	// ===============================================================
	JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_LOAD_ELEMENTS = function()
	{
		// Initialize
		// _______________________________________________________________________
		var LIST_OF_ELEMENTS = JSOC_ELEMENT.VAR_SUB_ELEMENTS(document.body, true, true, JSTOOL_CUSTOMIZE.TOOL_ELEMENT_IDS);

		
		// List down DGV
		// _______________________________________________________________________
		if(JSVC_ARR.VAR_EMPTY(LIST_OF_ELEMENTS) == false)
		{
			LIST_OF_ELEMENTS = JSVC_ARR.VAR_SORT(LIST_OF_ELEMENTS, 'ASC');
		}
		
		while(JSVC_ARR.VAR_EMPTY(LIST_OF_ELEMENTS) == false)
		{
			// Has inner HTML Tags
			// ...........................................
			if(JSVC_STR.VAR_CONTAINS(JSOC_ELEMENT.VAR_INNER_HTML(LIST_OF_ELEMENTS[0]), "<"))
			{
				LIST_OF_ELEMENTS.shift();
				continue;
			}
			
			// Filter and allow only the [A][DIV][SPAN][TD][TH][H1~H5] Tags
			// ...........................................
			if
			(
				JSVC_ARR.VAR_CONTAINS
				(
					['A', 'DIV', 'SPAN', 'TH', 'TD', 'H1', 'H2', 'H3', 'H4', 'H5', 'OPTION', 'LI'], 
					JSVC_STR.VAR_UCASE(JSOC_ELEMENT.VAR_GET(LIST_OF_ELEMENTS[0]).tagName)
				)
			)
			{
				JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_LOAD_ELEMENTS_ADD(LIST_OF_ELEMENTS[0]);
			}
			
			// To next loop
			// ...........................................
			LIST_OF_ELEMENTS.shift();
		}		
		
		// Update Row Count
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.RECAPTION.DGV.ROW.REFRESH_ROW_COUNT();
	};
		
		
	// ===============================================================
	// Part 2.B : Add Element
	// ===============================================================
	JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_LOAD_ELEMENTS_ADD = function(ELEMENT_ID)
	{
		JSTOOL_CUSTOMIZE.RECAPTION.DGV.ROW.ADD();
		JSTOOL_CUSTOMIZE.RECAPTION.DGV.CELL.VALUE("ELEMENT_ID", JSTOOL_CUSTOMIZE.RECAPTION.DGV.ROW.COUNT() - 1, ELEMENT_ID);
		JSTOOL_CUSTOMIZE.RECAPTION.DGV.CELL.VALUE("ELEMENT_CAPTION", JSTOOL_CUSTOMIZE.RECAPTION.DGV.ROW.COUNT() - 1, JSOC_ELEMENT.VAR_INNER_HTML(ELEMENT_ID));
	};
	

	
	// ===============================================================
	// Part 2.C : Restore Data from stored configuration
	// ===============================================================
	JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_RESTORE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var HIDDEN_ELEMENTS = JSTOOL_CUSTOMIZE.RECAPTION.LIST_TO_ARRAY
		(
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_LSTRING_TXT)
		);
		var CURRENT_DATA = null;
		
		// Multi-Entry
		// _______________________________________________________________________
		while(JSVC_ARR.VAR_EMPTY(HIDDEN_ELEMENTS) == false)
		{
			if(JSVC_STR.VAR_IS_BLANK(HIDDEN_ELEMENTS[0]) == false)
			{
				CURRENT_DATA = HIDDEN_ELEMENTS[0].split("::");
				JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_RESTORE_ADD(CURRENT_DATA[0], CURRENT_DATA [1]);
			}
			HIDDEN_ELEMENTS.shift();
		}
		JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.REFRESH_ROW_COUNT();
	};
	
	
	// ===============================================================
	// Part 2.D : Add Hidden Element
	// ===============================================================
	JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_RESTORE_ADD = function(ELEMENT_ID, ELEMENT_CAPTION)
	{
		if
		(
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.COLUMN.FIND('ELEMENT_ID', ELEMENT_ID, true) < 0
		)
		{
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.ADD();
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.CELL.VALUE("ELEMENT_ID", JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.COUNT() - 1, ELEMENT_ID);			
			JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.CELL.VALUE("ELEMENT_CAPTION", JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.COUNT() - 1, ELEMENT_CAPTION);			
		}
	};	
				
				
	// ===============================================================
	// Part 3 : Add Selected Item to Hidden list
	// ===============================================================	
	JSTOOL_CUSTOMIZE.RECAPTION.DIALOG_HIDE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var ROW_COUNT = JSTOOL_CUSTOMIZE.RECAPTION.DGV.ROW.COUNT();
		var ROW_INDEX = 0;		
		
		// Get selected option
		// _______________________________________________________________________
		while(ROW_COUNT > ROW_INDEX)
		{
			if(JSTOOL_CUSTOMIZE.RECAPTION.DGV.CELL.VALUE('ROW_IS_SELECTED', ROW_INDEX))
			{
				JSTOOL_CUSTOMIZE.RECAPTION.ON_SHOWN_RESTORE_ADD
				(
					JSTOOL_CUSTOMIZE.RECAPTION.DGV.CELL.VALUE('ELEMENT_ID', ROW_INDEX),
					JSTOOL_CUSTOMIZE.RECAPTION.DGV.CELL.VALUE('ELEMENT_CAPTION', ROW_INDEX)
				);
			}
			ROW_INDEX ++;
		}
		JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.REFRESH_ROW_COUNT();
	};
	
	
	// ===============================================================
	// Part 4 : Save Current Config
	// ===============================================================	
	JSTOOL_CUSTOMIZE.RECAPTION.DIALOG_SAVE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var ROW_COUNT = JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.ROW.COUNT();
		var ROW_INDEX = 0;		
		var RESULT_STRING = [];
		
		// Get selected option
		// _______________________________________________________________________
		while(ROW_COUNT > ROW_INDEX)
		{
			RESULT_STRING.push
			(
				JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.CELL.VALUE
				(
					'ELEMENT_ID', ROW_INDEX
				) + '::' +
				JSTOOL_CUSTOMIZE.RECAPTION.RECAPTION_DGV.CELL.VALUE
				(
					'ELEMENT_CAPTION', ROW_INDEX
				)
			);
			ROW_INDEX ++;
		}		
		
		// Sort Elements
		// _______________________________________________________________________
		RESULT_STRING.sort();
		
		// Convert to String
		// _______________________________________________________________________
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_LSTRING_TXT, RESULT_STRING.join());
		
		// Save item [Prepare]
		// _______________________________________________________________________
		var SAVE_MAP_ARRAY = JSCUS_SQL._CATEGORY._CUSTOMIZE.CUS_PREPARE_MAPPED_ARRAY_FOR_SAVE();
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_ID", JSVC_NUM.VAR_NVALL(JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ID_TXT)));				
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_URL", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_URL_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_CODE", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_CODE_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_DESCRIPTION", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_DESCRIPTION_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_LSTRING", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_LSTRING_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_SSTRING", '');					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_BIGINT", 0);
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_ACC_LEVEL_ID", JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.RECAPTION.CAT_CUSTOM_ACC_LEVEL_ID_CMB));	
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_STATUS", 2);

		// Declare Post Request Handler
		// _______________________________________________________________________
		var RESPONSE_HANDLER = function(IS_SUCCESS, HTTP_RESPONSE)
		{
			// Disable Dialogs
			// ...........................................
			CUS_SEND_DIALOG_TRY_DISMISS();
			
			// Handle Error
			// ...........................................
			if(IS_SUCCESS === false)
			{
				METHOD_UNABLE_TO_SEND_REQUEST(function(){});	
				return;
			}
			
			// Catch JSON Error
			// ...........................................
			else if(JSRC_JSON.REF_IS_JSTRING(HTTP_RESPONSE) == false)
			{
				METHOD_SERVER_ISSUE(function(){}, HTTP_RESPONSE);
				return;			
			}
				
			// Read Response
			// ...........................................
			else
			{
				// Load Response
				var JSON_OBJECT = JSRC_JSON.REF_CREATE(HTTP_RESPONSE);
				if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
				{
					METHOD_REQUEST_FAILURE(function(){}, JSON_OBJECT);
					return;
				}
				
				// Close Modal
				else
				{				
					JSTOOL_CUSTOMIZE.RECAPTION.SHOW_CONFIG_LIST_REFRESH(function(){});
					JSOC_DIALOG.VAR_MODAL("RECAPTION_MODAL_CATEGORY_CUSTOMIZE", false);											
				}
			}
		};
			
			
		// Save Item [Send Request]
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._CATEGORY._CUSTOMIZE.CUS_SAVE 
		(
			SAVE_MAP_ARRAY,
			RESPONSE_HANDLER
		);
	};
	
	
	
	// ===============================================================
	// Load Config Data
	// ===============================================================	
	JSTOOL_CUSTOMIZE.RECAPTION.LOAD = function(CONFIG_URL, CONFIG_LEVEL, CALLBACK_METHOD)
	{
		// Actual Function
		// _______________________________________________________________________
		GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._CUSTOMIZE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();		
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_CUSTOM_URL', CONFIG_URL);	
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_CUSTOM_ACC_LEVEL_ID', CONFIG_LEVEL);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_CUSTOM_CODE', JSCUS_CACHE.CONFIG_CODE + JSTOOL_CUSTOMIZE.RECAPTION.TOOL_TITLE);	
		/*
		JSVC_MAP_ARRAY.VAR_SET
		(
			GET_MAP_ARRAY, 'SEARCH_CAT_CUSTOM_ACC_ACCOUNT_ID_CMB', 'PARAM_CAT_CUSTOM_ACC_ACCOUNT_ID'
		);
		*/
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
				
				
		// LITE Search Mode
		// _______________________________________________________________________
		JSCUS_SQL._CATEGORY._CUSTOMIZE.CUS_GET_LITE
		(
			GET_MAP_ARRAY,
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				// Disable Dialogs
				// ...........................................
				CUS_SEND_DIALOG_TRY_DISMISS();
				
				// Validate
				// ...........................................
				if(IS_SUCCESS === false)
				{
					console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
					alert("Failed to load the page configuration.");
					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);
					alert("Failed to load the page configuration.");
					return;
				}
				
				// JSON Empty (Clears the DataGrodView)
				// ...........................................
				if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
				{
					CALLBACK_METHOD("");
					return;
				}
				else
				{
					CALLBACK_METHOD
					(
						JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_CUSTOM_ID", 1),
						JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_CUSTOM_LSTRING", 1),
						JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_CUSTOM_ACC_LEVEL_ID", 1)
					);
					return;
				}

			},
			true
		);
	};
	
	
	
	// ====================================================================================



	// ===============================================================
	// Apply existing configurations and hide elements.
	// ===============================================================	
	JSTOOL_CUSTOMIZE.RECAPTION.APPLY = function(CALLBACK_METHOD)
	{	
		// Apply Show Hides
		// _______________________________________________________________________
		var APPLY_RECAPTION_METHOD = function(JSON_OBJECT)
		{
			// Initialize
			// ...........................................
			var HIDDEN_ELEMENTS = [];
			var CURRENT_DATA = null;
			var JSON_COUNT = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT"));
			var JSON_INDEX = 0;
			
			// Hide Elements
			// ...........................................
			while(JSON_COUNT > JSON_INDEX)
			{
				HIDDEN_ELEMENTS = JSTOOL_CUSTOMIZE.RECAPTION.LIST_TO_ARRAY(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_CUSTOM_LSTRING", JSON_INDEX + 1));
				JSON_INDEX ++;
				
				while(JSVC_ARR.VAR_EMPTY(HIDDEN_ELEMENTS) == false)
				{
					CURRENT_DATA = HIDDEN_ELEMENTS[0].split('::');
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(CURRENT_DATA[0], false))
					{
						JSOC_ELEMENT.VAR_INNER_HTML(CURRENT_DATA[0], CURRENT_DATA[1]);
					}
					HIDDEN_ELEMENTS.shift();
				}
			}		
		};
		
		// Handle Callback of requesting Config data from server 
		// _______________________________________________________________________		
		// Validate JSON Response
		// ...........................................
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(JSTOOL_CUSTOMIZE_CONFIG_RECAPTION);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + JSTOOL_CUSTOMIZE_CONFIG_RECAPTION);
			alert("Failed to load the page configuration.");
			location.reload();
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// ...........................................
		APPLY_RECAPTION_METHOD(JSON_OBJECT);
		return;
	};

	
	// ====================================================================================


	// ===============================================================
	// Part 0.B : Initialize Form
	// ===============================================================	
	JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV = null;	
	JSTOOL_CUSTOMIZE.RECAPTION.ADD_CMD = null;
	
	/** 
	 * Show Modal with configuration list
	 */
	JSTOOL_CUSTOMIZE.RECAPTION.SHOW_CONFIG_LIST = function()
	{
		//JSOC_DIALOG.VAR_MODAL("CATEGORY_CUSTOMIZE_MODAL_MAIN_MENU", false);	
		
		
		// Initialize
		// _______________________________________________________________________
		if(JSVC_VAR.VAR_ISSET(JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV) == false)
		{
			// Initialize Modal
			JSTOOL_CUSTOMIZE.RECAPTION.INPUT_INSTANCE_EDIT = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_EDIT");			
		
			
			// Initialize DGV
			// ...........................................
			JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV = DataGridView("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_EDIT_DGV");
			JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV.ON_CLICK
			(			
				function(COL_INDEX, ROW_INDEX)
				{
					if(COL_INDEX == JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV.COLUMN.INDEX("OPEN_BBI"))
					{
						JSTOOL_CUSTOMIZE.RECAPTION.SHOW
						(
							JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV.CELL.VALUE
							(
								"CAT_CUSTOM_URL", ROW_INDEX
							),
							JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV.CELL.VALUE
							(
								"CAT_CUSTOM_ACC_LEVEL_ID", ROW_INDEX
							)							
						);
					}
				}
			);   				
			
			// Initialize: Button
			// ...........................................
			JSTOOL_CUSTOMIZE.RECAPTION.ADD_CMD = JSOC_ELEMENT.VAR_GET("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_EDIT_ADD_CMD");
			JSTOOL_CUSTOMIZE.RECAPTION.ADD_CMD.onclick = function()
			{
				JSTOOL_CUSTOMIZE.RECAPTION.SHOW("");
			};	
		}
		
		// Load Stored Configurations
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.RECAPTION.SHOW_CONFIG_LIST_REFRESH
		(
			function(IS_SUCCESS)
			{
				// Abort on failure
				// ...........................................
				if(IS_SUCCESS == false)
				{
					return;
				}
				
				// Show Modal
				// ...........................................
				JSOC_DIALOG.VAR_MODAL("RECAPTION_MODAL_CATEGORY_CUSTOMIZE_EDIT", true);			
			}
		);
	};
	
	/** 
	 * Populate Configuration List DGV
	 */
	JSTOOL_CUSTOMIZE.RECAPTION.SHOW_CONFIG_LIST_REFRESH = function(CALLBACK_METHOD)
	{	
		// Handle Callback of requesting Config data from server 
		// _______________________________________________________________________
		var CALLBACK_CONFIG = function(IS_SUCCESS, RESPONSE_STRING)
		{
			// Disable Dialogs
			// ...........................................
			CUS_SEND_DIALOG_TRY_DISMISS();
			
			// Validate
			// ...........................................
			if(IS_SUCCESS === false)
			{
				console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
				alert("Failed to load the page configuration.");
				CALLBACK_METHOD(false);
				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);
				alert("Failed to load the page configuration.");
				CALLBACK_METHOD(false);
				return;
			}
			
			// JSON Empty (Clears the DataGrodView)
			// ...........................................
			if(JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT")) <= 0)
			{
				JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV.ROW.CLEAR();
				CALLBACK_METHOD(true);
				return;
			}
			
			// Populate DGV
			// ...........................................
			JSTOOL_CUSTOMIZE.RECAPTION.EDIT_DGV.POPULATE_FROM_QUERY
			(
					JSON_OBJECT, 
					'',
					false,
					false,
					1,
					[2, 1]
			);
			
			CALLBACK_METHOD(true);
			return;
		};

		
		// Populate Parameters
		// _______________________________________________________________________
		GET_MAP_ARRAY = JSCUS_SQL._CATEGORY._CUSTOMIZE.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();		
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_CUSTOM_URL', JSVC_URL._CURRENT.VAR_PATH());	
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_CAT_CUSTOM_CODE', JSCUS_CACHE.CONFIG_CODE + JSTOOL_CUSTOMIZE.RECAPTION.TOOL_TITLE);		

		// Send Request
		// _______________________________________________________________________
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._CATEGORY._CUSTOMIZE.CUS_GET_RELATED
		(
			GET_MAP_ARRAY,
			CALLBACK_CONFIG
		);
	};
	
	
	
	// ===============================================================	
	// Load Required Script
	// ===============================================================	
	if(typeof JSCUS_SQL._ACCOUNT._LEVEL == 'undefined')
	{
		document.write('<script src="' + JSCUS_CACHE.SERVER_URL + '\/res\/comm\/account\/level.js"><\/script>');
	}

	JSTOOL_CUSTOMIZE.RECAPTION.APPLY();
	