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

	// ===============================================================
	// Part 0 : Initialize Form
	// ===============================================================	
	JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_CMD = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.LOAD_COLUMNS_CMD = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.APPLY_CMD = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CANCEL_CMD = null;
	
	JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ID_TXT = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_URL_TXT = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_CODE_TXT = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_DESCRIPTION_TXT = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_SSTRING_TXT = null;
				
	JSTOOL_CUSTOMIZE.DGVREORDER.INPUT_INSTANCE = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.INPUT_INSTANCE_EDIT = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.CONFIG_URL = null;
	JSTOOL_CUSTOMIZE.DGVREORDER.TOOL_TITLE = 'DGVREORDER';
	
	JSTOOL_CUSTOMIZE.DGVREORDER.FOCUSED_COL_INDEX = -1;
	JSTOOL_CUSTOMIZE.DGVREORDER.FOCUSED_ROW_INDEX = -1;
	JSTOOL_CUSTOMIZE.DGVREORDER.FOCUSED_SEL_INDEX = -1;


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

		// Initialize
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV = DataGridView("DGVREORDER_APPLY_MODAL_CATEGORY_CUSTOMIZE_DGV");
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				// Delete Button
				// ...........................................
				if(JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.COLUMN.NAME(COL_INDEX) == "DELETE_BBI")
				{
					// Delete Unsaved Item
					JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.REMOVE_AT(ROW_INDEX);
				}	
			}
		);   	
		
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ON_FOCUS
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				JSTOOL_CUSTOMIZE.DGVREORDER.FOCUSED_COL_INDEX = COL_INDEX;
				JSTOOL_CUSTOMIZE.DGVREORDER.FOCUSED_ROW_INDEX = ROW_INDEX;
				JSTOOL_CUSTOMIZE.DGVREORDER.FOCUSED_SEL_INDEX = -1;
			}
		);   	
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ON_FOCUS_OUT
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				JSTOOL_CUSTOMIZE.DGVREORDER.FOCUSED_SEL_INDEX = JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.ELEMENT(COL_INDEX, ROW_INDEX).selectionStart;
			}
		);   
								
		JSTOOL_CUSTOMIZE.DGVREORDER.LOAD_COLUMNS_CMD = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_LOAD_COLUMNS_CMD");
		JSTOOL_CUSTOMIZE.DGVREORDER.LOAD_COLUMNS_CMD.onclick = function()
		{
			JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS_COLUMNS();
		};
		
		
		JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ID_TXT = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_ID_TXT");
		JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_URL_TXT = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_URL_TXT");
		JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_ACC_LEVEL_ID_CMB");
		JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_CODE_TXT = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_CODE_TXT");
		JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_DESCRIPTION_TXT = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_DESCRIPTION_TXT");
		JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_LSTRING_TXT");
		JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_SSTRING_TXT = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CAT_CUSTOM_SSTRING_TXT");

		JSTOOL_CUSTOMIZE.DGVREORDER.INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE");			
	
		// Initialize: Button
		// ...........................................
		JSTOOL_CUSTOMIZE.DGVREORDER.APPLY_CMD = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_APPLY_CMD");
		JSTOOL_CUSTOMIZE.DGVREORDER.APPLY_CMD.onclick = function()
			{
				JSTOOL_CUSTOMIZE.DGVREORDER.DIALOG_SAVE();
			};
			
		JSTOOL_CUSTOMIZE.DGVREORDER.CANCEL_CMD = JSOC_ELEMENT.VAR_GET("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_CANCEL_CMD");
		JSTOOL_CUSTOMIZE.DGVREORDER.CANCEL_CMD.onclick = function()
			{
				JSOC_DIALOG.VAR_MODAL("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE", false);
			};
						
		// Foreign Field
		// ...........................................
		JSOC_CMB.VAR_CLEAR(JSTOOL_CUSTOMIZE.DGVREORDER.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.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB, "1");
				JSOC_CMB.VAR_TEXT
				(
					JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB,
					JSOC_CMB.VAR_SELECTED_INDEX(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB), 
					"-- EVERYONE -- "
				);
			},		
			JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB,
			true, 2
		);
	
		// Onetime Loading
		// ...........................................
		JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS();
		
		// Clean Modal
		// _______________________________________________________________________
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.CLEAR();
		JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(JSTOOL_CUSTOMIZE.DGVREORDER.INPUT_INSTANCE);
		
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_URL_TXT, JSTOOL_CUSTOMIZE.DGVREORDER.CONFIG_URL);
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_CODE_TXT,  JSCUS_CACHE.CONFIG_CODE + JSTOOL_CUSTOMIZE.DGVREORDER.TOOL_TITLE);
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_DESCRIPTION_TXT, 'Re-arrange the DGV.COlumns order');
		
		// New Data
		// _______________________________________________________________________
		if(JSVC_STR.VAR_IS_BLANK(CONFIG_URL))
		{
			// Initialize New Configuration
			// ...........................................
			JSTOOL_CUSTOMIZE.DGVREORDER.CONFIG_URL =  JSVC_URL._CURRENT.VAR_PATH();
			
			// Apply Configuration
			// ...........................................
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ID_TXT, 0);
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_URL_TXT, JSTOOL_CUSTOMIZE.DGVREORDER.CONFIG_URL);
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT, "");
			JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB, "1");
			JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.CLEAR();
			
			// Display Modal
			// ...........................................
			if(JSOC_CMB.VAR_COUNT('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB') <= 0)
			{
				alert('No DGV elements found');
				JSOC_DIALOG.VAR_MODAL("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_EDIT", false);
				JSOC_DIALOG.VAR_MODAL("CATEGORY_CUSTOMIZE_MODAL_MAIN_MENU", true);
			}				
			else
			{
				JSOC_DIALOG.VAR_MODAL("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE", true);
			}	
		}
		
		// Load Data
		// _______________________________________________________________________
		else
		{
			JSTOOL_CUSTOMIZE.DGVREORDER.LOAD
			(
				JSTOOL_CUSTOMIZE.DGVREORDER.CONFIG_URL,
				CONFIG_LEVEL,
				function(CONFIG_ID, CONFIG_DATA, CAT_CUSTOM_SSTRING, CONFIG_LEVEL)
				{
					// Apply Configuration
					// ...........................................
					JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ID_TXT, CONFIG_ID);
					JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT, CONFIG_DATA);
					JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_SSTRING_TXT, CAT_CUSTOM_SSTRING);
					JSOC_CMB.VAR_SELECTED_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_ACC_LEVEL_ID_CMB, CONFIG_LEVEL);
					
					// On Load Action
					// ...........................................
					JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_RESTORE();
					
					// Display Modal
					// ...........................................
					if(JSOC_CMB.VAR_COUNT('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB') <= 0)
					{
						alert('No DGV elements found');
						JSOC_DIALOG.VAR_MODAL("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_EDIT", false);
						JSOC_DIALOG.VAR_MODAL("CATEGORY_CUSTOMIZE_MODAL_MAIN_MENU", true);
					}				
					else
					{
						JSOC_DIALOG.VAR_MODAL("DGVREORDER_MODAL_CATEGORY_CUSTOMIZE", true);
					}	
				}
			);
		}
	};
	
	
	// ===============================================================
	// Part 2.A : Load Elements
	// ===============================================================
	JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS = function()
	{
		// Initialize
		// _______________________________________________________________________
		var LIST_OF_ELEMENTS = JSOC_ELEMENT.VAR_SUB_ELEMENTS(document.body, true, true, JSTOOL_CUSTOMIZE.TOOL_ELEMENT_IDS);
		JSOC_CMB.VAR_CLEAR('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB');
		
		// 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 no inner HTML Tags
			// ...........................................
			if(JSVC_STR.VAR_CONTAINS(JSOC_ELEMENT.VAR_INNER_HTML(LIST_OF_ELEMENTS[0]), "<") == false)
			{
				LIST_OF_ELEMENTS.shift();
				continue;
			}
			
			// Abort Select Modals
			// ...........................................
			else if(JSVC_STR.VAR_CONTAINS_LEFT(LIST_OF_ELEMENTS[0], 'SELECT_MODAL_'))
			{
				LIST_OF_ELEMENTS.shift();
				continue;				
			}
			
			// Filter and allow only the [DIV][TABLE] Tags, and DGV Post-fix
			// ...........................................
			else if
			(
				JSVC_STR.VAR_CONTAINS_RIGHT(LIST_OF_ELEMENTS[0], '_DGV') &&
				JSVC_ARR.VAR_CONTAINS
				(
					['DIV', 'TABLE'], 
					JSVC_STR.VAR_UCASE(JSOC_ELEMENT.VAR_GET(LIST_OF_ELEMENTS[0]).tagName)
				)
			)
			{
				JSOC_CMB.VAR_ADD('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB', LIST_OF_ELEMENTS[0], LIST_OF_ELEMENTS[0]);
			}
			
			// To next loop
			// ...........................................
			LIST_OF_ELEMENTS.shift();
		}		
	};
		
	
	// ===============================================================
	// Part 2.A : Load Elements (List down columns)
	// ===============================================================
	JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS_COLUMNS = function(SKIP_VALIDATION = false)
	{		
		// Load DGV Columns
		// _______________________________________________________________________
		var ON_ALLOW_ACTION = function()
		{
			// Clear DGV
			// ...........................................
			JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.CLEAR();
			
			// Abort if nothing selected
			// ...........................................
			var SELECTED_INDEX = JSOC_CMB.VAR_SELECTED_INDEX('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB');
			if(SELECTED_INDEX < 0)
			{
				return;
			}
			
			// Initialize
			// ...........................................
			var SELECTED_DGV_NAME = JSOC_CMB.VAR_SELECTED_VALUE('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB');
			var LIST_OF_ELEMENTS = JSOC_ELEMENT.VAR_SUB_ELEMENTS(SELECTED_DGV_NAME + '_HEADER', true, true, []);
			
			// GET COLUMNS
			// ...........................................
			while(JSVC_ARR.VAR_EMPTY(LIST_OF_ELEMENTS) == false)
			{
				if
				(
					JSVC_STR.VAR_CONTAINS
					(
						JSOC_ELEMENT.VAR_INNER_HTML(LIST_OF_ELEMENTS[0]),
						'<',
						false
					)
				)
				{
					JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS_ADD
					(
						JSVC_STR.VAR_DLEFT(LIST_OF_ELEMENTS[0], (SELECTED_DGV_NAME + '_HEADER_').length),
						'-- HTML Tags --'
					);
				}
				
				else
				{
					JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS_ADD
					(
						JSVC_STR.VAR_DLEFT(LIST_OF_ELEMENTS[0], (SELECTED_DGV_NAME + '_HEADER_').length),
						JSOC_ELEMENT.VAR_INNER_HTML(LIST_OF_ELEMENTS[0])
					);			
				}

				LIST_OF_ELEMENTS.shift();
			}
			
			// Update Row Count
			// ...........................................
			JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.REFRESH_ROW_COUNT();
		};
		
		// Ask for user action
		// _______________________________________________________________________
		if
		(
			SKIP_VALIDATION == false && 
			JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.COUNT() > 0
		)
		{
			JSOC_DIALOG.VAR_MESSAGE_BOX
			(
				'Do you want to override the current settings?', 
				'Load DataGridView', 
				JSOC_DIALOG.MSGBOX_TYPE_YES_NO,
				JSOC_DIALOG.MSGBOX_ICON_QUESTION,
				function(RESULT_BUTTON)
				{
					if(RESULT_BUTTON == JSOC_DIALOG.MSGBOX_YES)
					{
						ON_ALLOW_ACTION();
					}				
				},
				CUSTOM_CONFIG_SETTINGS
			);	
		}
		else
		{
			ON_ALLOW_ACTION();
		}
	};
	
	
	// ===============================================================
	// Part 2.B : Add Element
	// ===============================================================
	JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS_ADD = function(ELEMENT_ID, ELEMENT_HEADER)
	{
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.ADD();
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE("ELEMENT_ID", JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.COUNT() - 1, ELEMENT_ID);
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE("ELEMENT_HEADER", JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.COUNT() - 1, ELEMENT_HEADER);
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE("ELEMENT_ORDER", JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.COUNT() - 1, JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.COUNT());
	};
	

	
	// ===============================================================
	// Part 2.C : Restore Data from stored configuration
	// ===============================================================
	JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_RESTORE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var SELECTED_DGV = JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_SSTRING_TXT);
		var CUSTOM_ELEMENTS = JSTOOL_CUSTOMIZE.DGVREORDER.LIST_TO_ARRAY
		(
			JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT)
		);
		var CURRENT_DATA = null;
		
		// Replace Current DGV List
		// _______________________________________________________________________
		JSOC_CMB.VAR_SELECTED_VALUE('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB', SELECTED_DGV);
		JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_LOAD_ELEMENTS_COLUMNS(true);
		
		// Multi-Entry
		// _______________________________________________________________________
		while(JSVC_ARR.VAR_EMPTY(CUSTOM_ELEMENTS) == false)
		{
			if(JSVC_STR.VAR_IS_BLANK(CUSTOM_ELEMENTS[0]) == false)
			{
				CURRENT_DATA = CUSTOM_ELEMENTS[0].split("::");
				JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_RESTORE_ADD
				(
					CURRENT_DATA[0], 
					CURRENT_DATA [1]
				);
			}
			CUSTOM_ELEMENTS.shift();
		}
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.REFRESH_ROW_COUNT();
	};
	
	
	// ===============================================================
	// Part 2.D : Add Hidden Element
	// ===============================================================
	JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_RESTORE_ADD = function
	(
		ELEMENT_ID, 
		ELEMENT_ORDER
	)
	{
		var ROW_INDEX = JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.COLUMN.INDEX_OF("ELEMENT_ID", ELEMENT_ID, false);	
		if(ROW_INDEX >= 0)
		{
			JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE("ELEMENT_ORDER", ROW_INDEX, ELEMENT_ORDER);	
		}
	};
	
				
	// ===============================================================
	// Part 3 : Add Selected Item to Hidden list
	// ===============================================================	
	JSTOOL_CUSTOMIZE.DGVREORDER.DIALOG_CALC = function()
	{
		// Initialize
		// _______________________________________________________________________
		var ROW_COUNT = JSTOOL_CUSTOMIZE.DGVREORDER.DGV.ROW.COUNT();
		var ROW_INDEX = 0;		
		
		// Get selected option
		// _______________________________________________________________________
		while(ROW_COUNT > ROW_INDEX)
		{
			if(JSTOOL_CUSTOMIZE.DGVREORDER.DGV.CELL.VALUE('ROW_IS_SELECTED', ROW_INDEX))
			{
				JSTOOL_CUSTOMIZE.DGVREORDER.ON_SHOWN_RESTORE_ADD
				(
					JSTOOL_CUSTOMIZE.DGVREORDER.DGV.CELL.VALUE('ELEMENT_ID', ROW_INDEX)
				);
			}
			ROW_INDEX ++;
		}
		JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.REFRESH_ROW_COUNT();
	};
	
	
	// ===============================================================
	// Part 4 : Save Current Config
	// ===============================================================	
	JSTOOL_CUSTOMIZE.DGVREORDER.DIALOG_SAVE = function()
	{
		// Abort on validation failure
		// _______________________________________________________________________
		if(JSTOOL_CUSTOMIZE.DGVREORDER.DIALOG_VALIDATE() == false)
		{
			return;
		}
		
		// Initialize
		// _______________________________________________________________________
		var ROW_COUNT = JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.COUNT();
		var ROW_INDEX = 0;		
		var RESULT_STRING = [];
		
		// Get selected option
		// _______________________________________________________________________
		while(ROW_COUNT > ROW_INDEX)
		{
			RESULT_STRING.push
			(
				JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE
				(
					'ELEMENT_ID', ROW_INDEX
				) + '::' +
				JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE
				(
					'ELEMENT_ORDER', ROW_INDEX
				)
			);
			ROW_INDEX ++;
		}		
		
		// Sort Elements
		// _______________________________________________________________________
		RESULT_STRING.sort();
		
		// Convert to String
		// _______________________________________________________________________
		JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT, RESULT_STRING.join());
		if(JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT).length > 5012)
		{
			alert('Config become too large.');
			return;
		}
		
		// 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.DGVREORDER.CAT_CUSTOM_ID_TXT)));				
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_URL", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_URL_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_CODE", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_CODE_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_DESCRIPTION", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_DESCRIPTION_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_LSTRING", JSOC_ELEMENT.VAR_VALUE(JSTOOL_CUSTOMIZE.DGVREORDER.CAT_CUSTOM_LSTRING_TXT));					
		JSVC_MAP_ARRAY.VAR_SET(SAVE_MAP_ARRAY, "PARAM_CAT_CUSTOM_SSTRING", JSOC_CMB.VAR_SELECTED_VALUE('DGVREORDER_MODAL_CATEGORY_CUSTOMIZE_DGV_SELECTION_CMB'));					
		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.DGVREORDER.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.DGVREORDER.SHOW_CONFIG_LIST_REFRESH(function(){});
					JSOC_DIALOG.VAR_MODAL("DGVREORDER_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
		);
	};
	
	
	// ===============================================================
	// Part 4.B : Validate config before Saving 
	// ===============================================================	
	JSTOOL_CUSTOMIZE.DGVREORDER.DIALOG_VALIDATE = function()
	{
		// Initialize
		// _______________________________________________________________________
		var ROW_COUNT = JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.ROW.COUNT();
		var ROW_INDEX = 0;
		var ORDER_INDEX = 0;
		var CURRENT_ORDER = 0;
		
		// Check Orders
		// _______________________________________________________________________
		while(ROW_COUNT > ROW_INDEX)
		{
			CURRENT_ORDER = JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE('ELEMENT_ORDER', ROW_INDEX);
			ORDER_INDEX = 0;
			
			while(ROW_COUNT > ORDER_INDEX)
			{
				// Skip Current Row
				// ...........................................
				if(ROW_INDEX == ORDER_INDEX)
				{
					ORDER_INDEX ++;
					continue;
				}
				
				// Redundant Order
				// ...........................................
				if(CURRENT_ORDER == JSTOOL_CUSTOMIZE.DGVREORDER.DGVREORDER_DGV.CELL.VALUE('ELEMENT_ORDER', ORDER_INDEX))
				{
					alert('Redundant order : ' + CURRENT_ORDER);
					return false;
				}
				
				// To next loop
				// ...........................................
				ORDER_INDEX ++;
			}
			
			ROW_INDEX ++;
		}
		
		// Success
		// _______________________________________________________________________
		return true;
	};
	
	// ===============================================================
	// Load Config Data
	// ===============================================================	
	JSTOOL_CUSTOMIZE.DGVREORDER.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.DGVREORDER.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_SSTRING", 1),
						JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_CUSTOM_ACC_LEVEL_ID", 1)
					);
					return;
				}

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



	// ===============================================================
	// Apply existing configurations and hide elements.
	// ===============================================================	
	JSTOOL_CUSTOMIZE.DGVREORDER.APPLY = function(DGV_CONTROL)
	{	
		// Validate JSON Response
		// _______________________________________________________________________	
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(JSTOOL_CUSTOMIZE_CONFIG_DGV_REORDER);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			console.error("REQUEST ERROR: \n" + JSTOOL_CUSTOMIZE_CONFIG_DGV_REORDER);
			alert("Failed to load the page configuration.");
			location.reload();
			return;
		}
		
		
		// Initialize
		// _______________________________________________________________________	
		var ORDER_ELEMENTS = [];
		var ORDER_ELEMENTS_INDEX = [];
		var ORDER_ELEMENTS_INDEX_FINAL = [];
		
		var CURRENT_DATA_BLOCK = null;
		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)
		{
			// Skip unrelated DGV
			// ...........................................
			if(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_CUSTOM_SSTRING", JSON_INDEX + 1) != DGV_CONTROL)
			{
				JSON_INDEX ++;
				continue;
			}
			
			
			// Retrieve Current Settings
			// ...........................................
			CURRENT_DATA_BLOCK = JSTOOL_CUSTOMIZE.DGVREORDER.LIST_TO_ARRAY(JSRC_JSON.REF_READ(JSON_OBJECT, "CAT_CUSTOM_LSTRING", JSON_INDEX + 1));
			ORDER_ELEMENTS = [];
			ORDER_ELEMENTS_INDEX = [];
			ORDER_ELEMENTS_INDEX_FINAL = [];
			JSON_INDEX ++;

			
			// Prepare Reorder Config
			// ...........................................
			while(JSVC_ARR.VAR_EMPTY(CURRENT_DATA_BLOCK) == false)
			{
				CURRENT_DATA = CURRENT_DATA_BLOCK[0].split('::');
				ORDER_ELEMENTS.push(CURRENT_DATA[0]);
				ORDER_ELEMENTS_INDEX.push(CURRENT_DATA[1]);
				CURRENT_DATA_BLOCK.shift();
			}
			
			
			// Order elements according to index
			// ...........................................
			while(ORDER_ELEMENTS.length > ORDER_ELEMENTS_INDEX_FINAL.length)
			{
				ORDER_ELEMENTS_INDEX_FINAL.push
				(
					ORDER_ELEMENTS
					[
						ORDER_ELEMENTS_INDEX.indexOf
						(
							(ORDER_ELEMENTS_INDEX_FINAL.length + 1).toString()
						)
					]
				);		
			}
			
			
			
			
			// Reorder Elements
			// ...........................................
			while(JSVC_ARR.VAR_EMPTY(ORDER_ELEMENTS_INDEX_FINAL) == false)
			{
				JSOC_ELEMENT.VAR_GET(DGV_CONTROL + '_HEADER').append(JSOC_ELEMENT.VAR_GET(DGV_CONTROL + '_HEADER_' + ORDER_ELEMENTS_INDEX_FINAL[0]));
				JSOC_ELEMENT.VAR_GET(DGV_CONTROL + '_ROW').append(JSOC_ELEMENT.VAR_GET(DGV_CONTROL + '_ROW_' + ORDER_ELEMENTS_INDEX_FINAL[0]));
				ORDER_ELEMENTS_INDEX_FINAL.shift();
			}
		}		
	};

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


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

	