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

	// ===============================================================
	// Part 0 : Initialize Form
	// ===============================================================	
	JSTOOL_CUSTOMIZE.SHOWHIDE.DGV = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.HIDE_CMD = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.APPLY_CMD = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.CANCEL_CMD = null;
	
	JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ID_TXT = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_URL_TXT = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_CODE_TXT = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_DESCRIPTION_TXT = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_LSTRING_TXT = null;
				
	JSTOOL_CUSTOMIZE.SHOWHIDE.INPUT_INSTANCE = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.INPUT_INSTANCE_EDIT = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.CONFIG_URL = null;
	JSTOOL_CUSTOMIZE.SHOWHIDE.TOOL_TITLE = 'ELEMENT_SHOW';


	/**
	 * Break hidden element list in string to array
	 */
	JSTOOL_CUSTOMIZE.SHOWHIDE.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.SHOWHIDE.SHOW = function
	(
		CONFIG_URL, CONFIG_LEVEL
	)
	{
		// Initialize New Configuration
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.SHOWHIDE.CONFIG_URL = CONFIG_URL;

		// Initialize
		// _______________________________________________________________________
		if(JSVC_VAR.VAR_ISSET(JSTOOL_CUSTOMIZE.SHOWHIDE.DGV) == false)
		{
			// Initialize Modal and DGV
			// ...........................................
			JSTOOL_CUSTOMIZE.SHOWHIDE.DGV = DataGridView("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE_DGV");
			JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.ON_CLICK
			(			
				function(COL_INDEX, ROW_INDEX)
				{
					if(COL_INDEX != JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.COLUMN.INDEX("ROW_IS_SELECTED"))
					{
						JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.CELL.VALUE("ROW_IS_SELECTED", ROW_INDEX, true);
					}
				}
			);   	
			
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV = DataGridView("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_DGV");
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ON_CLICK
			(			
				function(COL_INDEX, ROW_INDEX)
				{
					// Delete Button
					// ...........................................
					if(JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.COLUMN.NAME(COL_INDEX) == "DELETE_BBI")
					{
						// Delete Unsaved Item
						JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.REMOVE_AT(ROW_INDEX);
					}	
				}
			);   	
			
			JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ID_TXT = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_ID_TXT");
			JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_URL_TXT = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_URL_TXT");
			JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_ACC_LEVEL_ID_CMB");
			JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_CODE_TXT = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_CODE_TXT");
			JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_DESCRIPTION_TXT = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_DESCRIPTION_TXT");
			JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_LSTRING_TXT = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_LSTRING_TXT");
	
			JSTOOL_CUSTOMIZE.SHOWHIDE.INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE");			
		
			// Initialize: Button
			// ...........................................
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDE_CMD = JSOC_ELEMENT.VAR_GET("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE_HIDE_CMD");
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDE_CMD.onclick = function()
				{
					JSTOOL_CUSTOMIZE.SHOWHIDE.DIALOG_HIDE();
				};
				
			JSTOOL_CUSTOMIZE.SHOWHIDE.APPLY_CMD = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_APPLY_CMD");
			JSTOOL_CUSTOMIZE.SHOWHIDE.APPLY_CMD.onclick = function()
				{
					JSTOOL_CUSTOMIZE.SHOWHIDE.DIALOG_SAVE();
				};
				
			JSTOOL_CUSTOMIZE.SHOWHIDE.CANCEL_CMD = JSOC_ELEMENT.VAR_GET("SHOWHIDE_HIDDEN_MODAL_CATEGORY_CUSTOMIZE_CANCEL_CMD");
			JSTOOL_CUSTOMIZE.SHOWHIDE.CANCEL_CMD.onclick = function()
				{
					JSOC_DIALOG.VAR_MODAL("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE", false);
				};
							
			// Foreign Field
			// ...........................................
			JSOC_CMB.VAR_CLEAR(JSTOOL_CUSTOMIZE.SHOWHIDE.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.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB, "1");
					JSOC_CMB.VAR_TEXT
					(
						JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB,
						JSOC_CMB.VAR_SELECTED_INDEX(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB), 
						"-- EVERYONE -- "
					);
				},		
				JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB,
				true, 2
			);
		
			// Onetime Loading
			// ...........................................
			JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_LOAD_ELEMENTS();
		}
		
		// Clean Modal
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.CLEAR();
		JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(JSTOOL_CUSTOMIZE.SHOWHIDE.INPUT_INSTANCE);
		
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_URL_TXT, JSTOOL_CUSTOMIZE.SHOWHIDE.CONFIG_URL);
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_CODE_TXT,  JSCUS_CACHE.CONFIG_CODE + JSTOOL_CUSTOMIZE.SHOWHIDE.TOOL_TITLE);
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_DESCRIPTION_TXT, 'Hide listed elements from UI');
		
		// New Data
		// _______________________________________________________________________
		if(JSVC_STR.VAR_IS_BLANK(CONFIG_URL))
		{
			// Initialize New Configuration
			// ...........................................
			JSTOOL_CUSTOMIZE.SHOWHIDE.CONFIG_URL =  JSVC_URL._CURRENT.VAR_PATH();
			
			// Apply Configuration
			// ...........................................
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ID_TXT, 0);
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_URL_TXT, JSTOOL_CUSTOMIZE.SHOWHIDE.CONFIG_URL);
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_LSTRING_TXT, "");
			JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB, "1");
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.CLEAR();
			
			// Display Modal
			// ...........................................
			JSOC_DIALOG.VAR_MODAL("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE", true);
		}
		
		// Load Data
		// _______________________________________________________________________
		else
		{
			JSTOOL_CUSTOMIZE.SHOWHIDE.LOAD
			(
				JSTOOL_CUSTOMIZE.SHOWHIDE.CONFIG_URL,
				CONFIG_LEVEL,
				function(CONFIG_ID, CONFIG_DATA, CONFIG_LEVEL)
				{
					// Apply Configuration
					// ...........................................
					JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ID_TXT, CONFIG_ID);
					JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_LSTRING_TXT, CONFIG_DATA);
					JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_ACC_LEVEL_ID_CMB, CONFIG_LEVEL);
					
					// On Load Action
					// ...........................................
					JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_RESTORE();
					
				
					// Display Modal
					// ...........................................
					JSOC_DIALOG.VAR_MODAL("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE", true);
				}
			);
		}
	};
	
	
	// ===============================================================
	// Part 2.A : Load Elements
	// ===============================================================
	JSTOOL_CUSTOMIZE.SHOWHIDE.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)
		{
			JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_LOAD_ELEMENTS_ADD(LIST_OF_ELEMENTS[0]);
			LIST_OF_ELEMENTS.shift();
		}		
		
		// Update Row Count
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.ROW.REFRESH_ROW_COUNT();
	};
		
		
	// ===============================================================
	// Part 2.B : Add Hidden Element
	// ===============================================================
	JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_LOAD_ELEMENTS_ADD = function(ELEMENT_ID)
	{
		JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.ROW.ADD();
		JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.CELL.VALUE("ELEMENT_ID", JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.ROW.COUNT() - 1, ELEMENT_ID);
	};
	

	
	// ===============================================================
	// Part 2.C : Restore Data from stored configuration
	// ===============================================================
	JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_RESTORE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var HIDDEN_ELEMENTS = JSTOOL_CUSTOMIZE.SHOWHIDE.LIST_TO_ARRAY
		(
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_LSTRING_TXT)
		);

		// Multi-Entry
		// _______________________________________________________________________
		while(JSVC_ARR.VAR_EMPTY(HIDDEN_ELEMENTS) == false)
		{
			if(JSVC_STR.VAR_IS_BLANK(HIDDEN_ELEMENTS[0]) == false)
			{
				JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_RESTORE_ADD(HIDDEN_ELEMENTS[0]);
			}
			HIDDEN_ELEMENTS.shift();
		}
		JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.REFRESH_ROW_COUNT();
	};
	
	
	// ===============================================================
	// Part 2.D : Add Hidden Element
	// ===============================================================
	JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_RESTORE_ADD = function(ELEMENT_ID)
	{
		if
		(
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.COLUMN.FIND('ELEMENT_ID', ELEMENT_ID, true) < 0
		)
		{
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.ADD();
			JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.CELL.VALUE("ELEMENT_ID", JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.COUNT() - 1, ELEMENT_ID);			
		}
	};	
				
				
	// ===============================================================
	// Part 3 : Add Selected Item to Hidden list
	// ===============================================================	
	JSTOOL_CUSTOMIZE.SHOWHIDE.DIALOG_HIDE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var ROW_COUNT = JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.ROW.COUNT();
		var ROW_INDEX = 0;		
		
		// Get selected option
		// _______________________________________________________________________
		while(ROW_COUNT > ROW_INDEX)
		{
			if(JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.CELL.VALUE('ROW_IS_SELECTED', ROW_INDEX))
			{
				JSTOOL_CUSTOMIZE.SHOWHIDE.ON_SHOWN_RESTORE_ADD
				(
					JSTOOL_CUSTOMIZE.SHOWHIDE.DGV.CELL.VALUE('ELEMENT_ID', ROW_INDEX)
				);
			}
			ROW_INDEX ++;
		}
		JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.REFRESH_ROW_COUNT();
	};
	
	
	// ===============================================================
	// Part 4 : Save Current Config
	// ===============================================================	
	JSTOOL_CUSTOMIZE.SHOWHIDE.DIALOG_SAVE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var ROW_COUNT = JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.ROW.COUNT();
		var ROW_INDEX = 0;		
		var RESULT_STRING = [];
		
		// Get selected option
		// _______________________________________________________________________
		while(ROW_COUNT > ROW_INDEX)
		{
			RESULT_STRING.push
			(
				JSTOOL_CUSTOMIZE.SHOWHIDE.HIDDEN_DGV.CELL.VALUE
				(
					'ELEMENT_ID', ROW_INDEX
				)
			);
			ROW_INDEX ++;
		}		
		
		// Sort Elements
		// _______________________________________________________________________
		RESULT_STRING.sort();
		
		// Convert to String
		// _______________________________________________________________________
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.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.SHOWHIDE.CAT_CUSTOM_ID_TXT)));				
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_URL", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_URL_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_CODE", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_CODE_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_DESCRIPTION", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.CAT_CUSTOM_DESCRIPTION_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_LSTRING", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.SHOWHIDE.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.SHOWHIDE.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.SHOWHIDE.SHOW_CONFIG_LIST_REFRESH(function(){});
					JSOC_DIALOG.VAR_MODAL("SHOWHIDE_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.SHOWHIDE.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.SHOWHIDE.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.SHOWHIDE.APPLY = function()
	{
		// Apply Show Hides
		// _______________________________________________________________________
		var APPLY_SHOWHIDE_METHOD = function(JSON_OBJECT)
		{
			// Initialize
			// ...........................................
			var HIDDEN_ELEMENTS = [];
			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.SHOWHIDE.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)
				{
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(HIDDEN_ELEMENTS[0], false))
					{
						JSOC_STYLE.VAR_DISPLAY(HIDDEN_ELEMENTS[0], "DEFAULT");
					}
					HIDDEN_ELEMENTS.shift();
				}
			}		
		};
		
		// Handle Callback of requesting Config data from server 
		// _______________________________________________________________________
		// Validate JSON Response
		// ...........................................
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(JSTOOL_CUSTOMIZE_CONFIG_SHOWHIDE);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + JSTOOL_CUSTOMIZE_CONFIG_SHOWHIDE);
			alert("Failed to load the page configuration.");
			location.reload();
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// ...........................................
		APPLY_SHOWHIDE_METHOD(JSON_OBJECT);
		return;
	};

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


	// ===============================================================
	// Part 0.B : Initialize Form
	// ===============================================================	
	JSTOOL_CUSTOMIZE.SHOWHIDE.EDIT_DGV = null;	
	JSTOOL_CUSTOMIZE.SHOWHIDE.ADD_CMD = null;
	
	/** 
	 * Show Modal with configuration list
	 */
	JSTOOL_CUSTOMIZE.SHOWHIDE.SHOW_CONFIG_LIST = function()
	{
		// Initialize
		// _______________________________________________________________________
		if(JSVC_VAR.VAR_ISSET(JSTOOL_CUSTOMIZE.SHOWHIDE.EDIT_DGV) == false)
		{
			// Initialize Modal
			JSTOOL_CUSTOMIZE.SHOWHIDE.INPUT_INSTANCE_EDIT = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE_EDIT");			
		
			
			// Initialize DGV
			// ...........................................
			JSTOOL_CUSTOMIZE.SHOWHIDE.EDIT_DGV = DataGridView("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE_EDIT_DGV");
			JSTOOL_CUSTOMIZE.SHOWHIDE.EDIT_DGV.ON_CLICK
			(			
				function(COL_INDEX, ROW_INDEX)
				{
					if(COL_INDEX == JSTOOL_CUSTOMIZE.SHOWHIDE.EDIT_DGV.COLUMN.INDEX("OPEN_BBI"))
					{
						JSTOOL_CUSTOMIZE.SHOWHIDE.SHOW
						(
							JSTOOL_CUSTOMIZE.SHOWHIDE.EDIT_DGV.CELL.VALUE
							(
								"CAT_CUSTOM_URL", ROW_INDEX
							),
							JSTOOL_CUSTOMIZE.SHOWHIDE.EDIT_DGV.CELL.VALUE
							(
								"CAT_CUSTOM_ACC_LEVEL_ID", ROW_INDEX
							)							
						);
					}
				}
			);   				
			
			// Initialize: Button
			// ...........................................
			JSTOOL_CUSTOMIZE.SHOWHIDE.ADD_CMD = JSOC_ELEMENT.VAR_GET("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE_EDIT_ADD_CMD");
			JSTOOL_CUSTOMIZE.SHOWHIDE.ADD_CMD.onclick = function()
			{
				JSTOOL_CUSTOMIZE.SHOWHIDE.SHOW("");
			};	
		}
		
		// Load Stored Configurations
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.SHOWHIDE.SHOW_CONFIG_LIST_REFRESH
		(
			function(IS_SUCCESS)
			{
				// Abort on failure
				// ...........................................
				if(IS_SUCCESS == false)
				{
					return;
				}
				
				// Show Modal
				// ...........................................
				JSOC_DIALOG.VAR_MODAL("SHOWHIDE_MODAL_CATEGORY_CUSTOMIZE_EDIT", true);			
			}
		);
	};
	
	/** 
	 * Populate Configuration List DGV
	 */
	JSTOOL_CUSTOMIZE.SHOWHIDE.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.SHOWHIDE.EDIT_DGV.ROW.CLEAR();
				CALLBACK_METHOD(true);
				return;
			}
			
			// Populate DGV
			// ...........................................
			JSTOOL_CUSTOMIZE.SHOWHIDE.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.SHOWHIDE.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.SHOWHIDE.APPLY();
	