// CATEGORY_ADDRESS_BARANGAY GET
JSCUS_PG = function(){};
JSCUS_PG._FLAG = function(){};
JSCUS_PG._TOOL = function(){};
JSCUS_PG._PGNAION = function(){};
	
	
	// ~~~~~

	JSCUS_PG._FLAG.NVARCHAR = 1;	
	JSCUS_PG._FLAG.DECIMAL = 2;	
	JSCUS_PG._FLAG.BIGINT = 3;
	JSCUS_PG._FLAG.INT = 4;
	JSCUS_PG._FLAG.TINYINT = 5;
	
	JSCUS_PG._FLAG.DATETIME = 6;
	JSCUS_PG._FLAG.DATETIME_BEGIN_OF_DATE = 7;
	JSCUS_PG._FLAG.DATETIME_END_OF_DATE = 8;
	
	JSCUS_PG._FLAG.PGNATION_DEFAULT_PAGES = 20;
	
	// ~~~~~
	
	/**
	 * Load data, assigns null-flag values as nesccessary
	 */
	JSCUS_PG._TOOL.VALUE_IN = function
	(
		ELEMENT_ID, PARAM_NAME, DATA_TYPE, MAP_ARRAY
	)
	{
		// Initialize
		// ...........................................
		var ELEMENT_VALUE = '';
		
		// Abort if element does not exists
		// ...........................................
		if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS(ELEMENT_ID) == false ||
			JSOC_STYLE.VAR_IS_VISIBLE(ELEMENT_ID) == false
		)
		{
			return;
		}
		
		// Load Data
		// ...........................................
		if(JSOC_ELEMENT.VAR_TYPE_IS(ELEMENT_ID, "SELECT"))
		{
			ELEMENT_VALUE = JSOC_CMB.VAR_SELECTED_VALUE(ELEMENT_ID);
		}
		else if
		(
			JSOC_ELEMENT.VAR_TYPE_IS(ELEMENT_ID, "INPUT", "CHECKBOX") &&
			JSOC_ELEMENT.VAR_TYPE_IS(ELEMENT_ID, "INPUT", "RADIO") 
		)
		{
			if(JSOC_ELEMENT.VAR_VALUE(ELEMENT_ID))
			{
				ELEMENT_VALUE = JSOC_ELEMENT.VAR_VALUE(ELEMENT_ID);
			}
			else
			{
				ELEMENT_VALUE = false;
			}
		}
		else
		{
			ELEMENT_VALUE = JSOC_ELEMENT.VAR_VALUE(ELEMENT_ID);
		}
		
		// VARCHAR
		// ...........................................
		if(DATA_TYPE == JSCUS_PG._FLAG.NVARCHAR)
		{
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);
			return;	
		}
		
		// DECIMAL
		// ...........................................
		if(DATA_TYPE == JSCUS_PG._FLAG.DECIMAL)
		{
			if(JSVC_STR.VAR_IS_BLANK(ELEMENT_VALUE))
			{
				ELEMENT_VALUE = FLAG_DECIMAL_NULL;
			}
			else
			{
				ELEMENT_VALUE = JSVC_NUM.VAR_NVAL(ELEMENT_VALUE);
			}
			
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);
			return;	
		}
		
		// BIGINT
		// ...........................................
		if(DATA_TYPE == JSCUS_PG._FLAG.BIGINT)
		{
			if(JSVC_STR.VAR_IS_BLANK(ELEMENT_VALUE))
			{
				ELEMENT_VALUE = FLAG_BIGINT_NULL;
			}
			else
			{
				ELEMENT_VALUE = JSVC_NUM.VAR_NVALL(ELEMENT_VALUE);
			}
			
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);			
			return;	
		}
		
		// INT
		// ...........................................
		if(DATA_TYPE == JSCUS_PG._FLAG.INT)
		{
			if(JSVC_STR.VAR_IS_BLANK(ELEMENT_VALUE))
			{
				ELEMENT_VALUE = FLAG_INT_NULL;
			}
			else
			{
				ELEMENT_VALUE = JSVC_NUM.VAR_NVALL(ELEMENT_VALUE);
			}
			
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);			
			return;	
		}
		
		// TINYINT
		// ...........................................
		if(DATA_TYPE == JSCUS_PG._FLAG.TINYINT)
		{
			if(JSVC_STR.VAR_IS_BLANK(ELEMENT_VALUE))
			{
				ELEMENT_VALUE = FLAG_TINYINT_NULL;
			}
			else
			{
				ELEMENT_VALUE = JSVC_NUM.VAR_NVALL(ELEMENT_VALUE);
			}
			
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);			
			return;	
		}		
		
		// DATETIME
		// ...........................................
		if(DATA_TYPE == JSCUS_PG._FLAG.DATETIME)
		{
			if(JSVC_VAR.VAR_ISSET(ELEMENT_VALUE))
			{
				ELEMENT_VALUE = JSVC_NUM.VAR_NVALL(ELEMENT_VALUE);
			}
			else
			{
				JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, FLAG_DATETIME_NULL);	
				return;
			}
			
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);			
			return;	
		}			
		
		// DATETIME - Beginning of date
		// ...........................................
		if(JSCUS_PG._FLAG.DATETIME_BEGIN_OF_DATE == JSCUS_PG._FLAG.DATETIME)
		{
			if(JSVC_VAR.VAR_ISSET(ELEMENT_VALUE))
			{
				ELEMENT_VALUE = JSVC_NUM.VAR_NVALL(ELEMENT_VALUE);
			}
			else
			{
				JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, FLAG_DATETIME_NULL);	
				return;
			}
			
			ELEMENT_VALUE = JSVC_DATE.VAR_FORMAT(ELEMENT_VALUE, "YYYY-MM-DD") + " 00:00:00.000000";
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);			
			return;	
		}	

		// DATETIME - End of date
		// ...........................................
		if(JSCUS_PG._FLAG.DATETIME_END_OF_DATE == JSCUS_PG._FLAG.DATETIME)
		{
			if(JSVC_VAR.VAR_ISSET(ELEMENT_VALUE))
			{
				ELEMENT_VALUE = JSVC_NUM.VAR_NVALL(ELEMENT_VALUE);
			}
			else
			{
				JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, FLAG_DATETIME_NULL);	
				return;
			}
			
			ELEMENT_VALUE = JSVC_DATE.VAR_FORMAT(ELEMENT_VALUE, "YYYY-MM-DD") + " 23:59:59.999999";
			JSVC_MAP_ARRAY.VAR_SET(MAP_ARRAY, PARAM_NAME, ELEMENT_VALUE);			
			return;	
		}			
	};
	
	
	/**
	 * Prepare Buttons
	 */
	JSCUS_PG._TOOL.APPLY_BUTTON_SETUP = function
	(
		BUTTON_ID, BUTTON_ON_CLICK_FUNCTION
	)
	{
		// Abort if button does not exists
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(BUTTON_ID) == false)
		{
			return;
		}
		
		// Setup Button
		// ...........................................
		var BUTTON_ELEMENT = JSOC_ELEMENT.VAR_GET(BUTTON_ID);  
		
		// Add Event
		// ...........................................
		BUTTON_ELEMENT.onclick = BUTTON_ON_CLICK_FUNCTION;
		
		// Return Result
		// ...........................................
		return BUTTON_ELEMENT;
	};
	
	
	/**
	 * Export All : Collected Data
	 */	
	JSCUS_PG._TOOL.EXPORT_ALL = function(){};
	JSCUS_PG._TOOL.EXPORT_ALL.DGV_ELEMENT_ID = "";
	JSCUS_PG._TOOL.EXPORT_ALL.CSV_DATA = "";
	JSCUS_PG._TOOL.EXPORT_ALL.EXPORT_ALL_SCEDULLER = null;
	
	// 1 - JSCUS_PG._TOOL.EXPORT_ALL.WAIT_WHILE_LOADING(); 2 - JSCUS_PG._TOOL.EXPORT_ALL.LOAD_NEXT_PAGE(); 3 - Complete and Write to File;
	JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS = [];			
	
	
	/**
	 * Export All : Load Next Page
	 */	
	JSCUS_PG._TOOL.EXPORT_ALL.LOAD_NEXT_PAGE = function()
	{
		if(JSOC_CMB.VAR_COUNT(LOAD_PAGING_CMB) - 1 > JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB))
		{
			LOAD_NEXT_BBI.onclick();
			JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS.push(1);	// WAIT_WHILE_LOADING
		}
		else
		{
			JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS.push(3);
		}		
	};
	
	
	/**
	 * Export All : Wait while loading page
	 */	
	JSCUS_PG._TOOL.EXPORT_ALL.WAIT_WHILE_LOADING = function()
	{
		if
		(
			CUS_SEND_REQUEST_HAS_QUEUE() || PROPERTY_SEARCH_STATUS == true
		)
		{
			JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS.push(1); // WAIT_WHILE_LOADING			
		}
		else
		{
			JSCUS_PG._TOOL.EXPORT_ALL.CSV_DATA += JSRC_EXCEL.REF_TABLE_TO_CSV
			(
				JSCUS_PG._TOOL.EXPORT_ALL.DGV_ELEMENT_ID, true
			);
			JSCUS_PG._TOOL.EXPORT_ALL.LOAD_NEXT_PAGE();
		}		
	};	
	
	
	/**
	 * Prepare Common type of Buttons
	 */	
	JSCUS_PG._TOOL.INITIALIZE_COMMON_BUTTONS = function(DGV_ELEMENT_ID)
	{
		// Initialize: Load more items to the list
		// _______________________________________________________________________
		LOAD_MORE_BBI = JSCUS_PG._TOOL.APPLY_BUTTON_SETUP
		(
			"LOAD_MORE_BBI", function(){HTTP_SEARCH_LOAD_MORE();}
		);
		LOAD_PREV_BBI = JSCUS_PG._TOOL.APPLY_BUTTON_SETUP
		(
			"LOAD_PREV_BBI", function()
			{
				var CURRENT_INDEX = JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB);
				if(CURRENT_INDEX > 0)
				{
					JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB, CURRENT_INDEX - 1);
					LOAD_PAGING_CMB.onchange();
				}
			}
		);		
		LOAD_NEXT_BBI = JSCUS_PG._TOOL.APPLY_BUTTON_SETUP
		(
			"LOAD_NEXT_BBI", function()
			{
				var CURRENT_INDEX = JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB);
				JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB, CURRENT_INDEX + 1);
				LOAD_PAGING_CMB.onchange();
			}
		);
		LOAD_PAGING_CMB = JSCUS_PG._TOOL.APPLY_COMMON_SETUP
		(
			"LOAD_PAGING_CMB", null, 
			function()
			{
				if(typeof HTTP_SEARCH_LOAD_PAGE != 'undefined')
				{
					HTTP_SEARCH_LOAD_PAGE();
				}
				else if(typeof HTTPPG_SET != 'undefined')
				{
					HTTPPG_SET(JSOC_CMB.VAR_SELECTED_INDEX("LOAD_PAGING_CMB"));
				}
			}
		);
		
		JSCUS_PG._TOOL.APPLY_BUTTON_SETUP("LOAD_P01_BBI", function(){HTTPPG_ADJUST(1);});
		JSCUS_PG._TOOL.APPLY_BUTTON_SETUP("LOAD_P10_BBI", function(){HTTPPG_ADJUST(10);});
		JSCUS_PG._TOOL.APPLY_BUTTON_SETUP("LOAD_P100_BBI", function(){HTTPPG_ADJUST(100);});
		
		JSCUS_PG._TOOL.APPLY_BUTTON_SETUP("LOAD_N01_BBI", function(){HTTPPG_ADJUST(-1);});
		JSCUS_PG._TOOL.APPLY_BUTTON_SETUP("LOAD_N10_BBI", function(){HTTPPG_ADJUST(-10);});
		JSCUS_PG._TOOL.APPLY_BUTTON_SETUP("LOAD_N100_BBI", function(){HTTPPG_ADJUST(-100);});
		
		

		// Initialize: Ribbon Buttons [Add Print]
		// _______________________________________________________________________
		PRINT_BBI = JSCUS_PG._TOOL.APPLY_BUTTON_SETUP("PRINT_BBI", function(){window.print();});
	
		// Initialize: Ribbon Buttons [Add Search]
		// _______________________________________________________________________
		EXPORT_BBI = JSCUS_PG._TOOL.APPLY_BUTTON_SETUP
		(
			"EXPORT_BBI", function()
			{
				JSOC_DIALOG.VAR_LOADING_SPINNER(true);
				JSRC_THREAD.REF_POST_DELAYED			
				(
					async function()
					{
						await JSRC_EXCEL.REF_EXPORT_TO_CSV
						(
							DGV_ELEMENT_ID, 'download.csv' //, 'octet/stream'
						);
						CUS_SEND_DIALOG_TRY_DISMISS();
					},
					100
				);
			}
		);	
		
		
		// Initialize: Ribbon Buttons [Add Search]
		// _______________________________________________________________________
		JSCUS_PG._TOOL.EXPORT_ALL.DGV_ELEMENT_ID = DGV_ELEMENT_ID;
		EXPORT_ALL_BBI = JSCUS_PG._TOOL.APPLY_BUTTON_SETUP
		(
			"EXPORT_ALL_BBI", function()
			{
				// Prepare Timer
				// ...........................................
				if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.EXPORT_ALL.EXPORT_ALL_SCEDULLER))
				{
					return;	
				}
				JSCUS_PG._TOOL.EXPORT_ALL.EXPORT_ALL_SCEDULLER = setInterval
				(
					async function()
					{
						if(JSVC_ARR.VAR_EMPTY(JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS) == false)
						{
							var ON_QUEUE = JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS.shift();	
							if(ON_QUEUE == 1)
							{
								JSCUS_PG._TOOL.EXPORT_ALL.WAIT_WHILE_LOADING();
							}
							else if(ON_QUEUE == 2)
							{
								JSCUS_PG._TOOL.EXPORT_ALL.LOAD_NEXT_PAGE();
							}
							else if(ON_QUEUE == 3)
							{
								// Write to file
								// ***********************************
								await JSRC_EXCEL.REF_EXPORT_FROM_STRING 
								(
									JSCUS_PG._TOOL.EXPORT_ALL.CSV_DATA, 'download.csv'
								);
								
								// Clear Timer
								// ***********************************
								clearInterval(JSCUS_PG._TOOL.EXPORT_ALL.EXPORT_ALL_SCEDULLER);
								JSCUS_PG._TOOL.EXPORT_ALL.CSV_DATA = "";
								JSCUS_PG._TOOL.EXPORT_ALL.EXPORT_ALL_SCEDULLER = null;
								JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS = [];
								
								// Clear Progress Dialog
								// ***********************************
								CUS_SEND_DIALOG_TRY_DISMISS();
							}
						}
					}, 
					100
				);
				
				// Initialize
				// ...........................................
				JSOC_DIALOG.VAR_LOADING_SPINNER(true);		
				JSCUS_PG._TOOL.EXPORT_ALL.CSV_DATA = "";
					
				// Set to First page
				// ...........................................
				JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB, 0);
				LOAD_PAGING_CMB.onchange();	
				JSCUS_PG._TOOL.EXPORT_ALL.PENDING_ACTIONS.push(1);	
			}
		);		
	};
	
	
	/**
	 * Prepare onChange event (for common action)
	 */
	JSCUS_PG._TOOL.APPLY_COMMON_SETUP = function
	(
		DECLARED_ELEMENT_ID, 
		ADDITIONAL_ACTION = null, 
		CUSTOM_EVENT = null,
		ENABLE_ON_INPUT = false
	)
	{
		// Abort if not exists
		// ...........................................
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(DECLARED_ELEMENT_ID) == false)
		{
			return;
		}
		
		// Declare Variable
		// ...........................................
		var DECLARED_ELEMENT_VAR = JSOC_ELEMENT.VAR_GET(DECLARED_ELEMENT_ID);  

		// Action taken if element exists
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(ADDITIONAL_ACTION))
		{
			ADDITIONAL_ACTION(DECLARED_ELEMENT_VAR);
		}
		
		// Setup events
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(CUSTOM_EVENT))
		{
			DECLARED_ELEMENT_VAR.onchange = CUSTOM_EVENT;				
		}
		else
		{
			DECLARED_ELEMENT_VAR.onchange = function()
			{
				if(DECLARED_ELEMENT_VAR.disabled == false)
				{
					EDIT_HANDLER.REF_IS_MODIFIED = true;
				}
			};
		}
		DECLARED_ELEMENT_VAR.onkeypress = function(){DECLARED_ELEMENT_VAR.onchange();};
		DECLARED_ELEMENT_VAR.onpaste = function(){DECLARED_ELEMENT_VAR.onchange();};
		
		// Apply OnInput event if requested
		// ...........................................
		if(ENABLE_ON_INPUT)
		{
			DECLARED_ELEMENT_VAR.oninput = function(){DECLARED_ELEMENT_VAR.onchange();};	
		}
		
		// Return Result
		// ...........................................
		return DECLARED_ELEMENT_VAR;

	};


	/**
	 * Prepare DTP, with quick  (for common action)
	 */
	JSCUS_PG._TOOL.APPLY_DTP_FROM_TO_SETUP = function
	(
		DTP_FIELD_ID,
		
		DTP_DEFAULT_VALUE = null,
		SEARCH_EXACT_DTP_DEFAULT_VALUE = null,
		SEARCH_FROM_DTP_DEFAULT_VALUE = null,
		SEARCH_TO_DTP_DEFAULT_VALUE = null,
		DTP_DEFAULT_DATE_RANGE = 3
	)
	{
		// Suggest IDs from the field id
		// ...........................................	
		var DTP_ELEMENT = null;
		var SEARCH_QUICK_ACCESS_CMB_ELEMENT = null;
		var SEARCH_FROM_DTP_ELEMENT = null;
		var SEARCH_TO_DTP_ELEMENT = null;
		
		var DTP_ID = DTP_FIELD_ID + '_DTP';
		var SEARCH_QUICK_ACCESS_CMB_ID = 'SEARCH_' + DTP_FIELD_ID + '_CMB';
		var SEARCH_EXACT_DTP_ID = 'SEARCH_' + DTP_FIELD_ID + '_DTP';
		var SEARCH_FROM_DTP_ID = 'SEARCH_' + DTP_FIELD_ID + '_FROM_DTP';
		var SEARCH_TO_DTP_ID = 'SEARCH_' + DTP_FIELD_ID + '_TO_DTP';
				
		// Handle Optional Values
		// ...........................................	
		DTP_DEFAULT_VALUE = JSVC_VAR.VAR_OPTIONAL(DTP_DEFAULT_VALUE, JSVC_DATE.VAR_NOW());
		SEARCH_EXACT_DTP_DEFAULT_VALUE = JSVC_VAR.VAR_OPTIONAL(SEARCH_EXACT_DTP_DEFAULT_VALUE, JSVC_DATE.VAR_NOW());
		SEARCH_FROM_DTP_DEFAULT_VALUE = JSVC_VAR.VAR_OPTIONAL(SEARCH_FROM_DTP_DEFAULT_VALUE, JSVC_DATE.VAR_ADD('DAY', -7, JSVC_DATE.VAR_NOW()));
		SEARCH_TO_DTP_DEFAULT_VALUE = JSVC_VAR.VAR_OPTIONAL(SEARCH_TO_DTP_DEFAULT_VALUE, JSVC_DATE.VAR_NOW());
		
		// Prepare Modal DTP
		// ...........................................	
		DTP_ELEMENT = JSCUS_PG._TOOL.APPLY_COMMON_SETUP
		(
			DTP_ID, 
			function(INIT_ELEMENT)
			{
				JSOC_ELEMENT.VAR_VALUE(INIT_ELEMENT, JSVC_DATE.VAR_FORMAT(DTP_DEFAULT_VALUE, "YYYY-MM-DD" + "T00:00"));
			}, 
			null, true
		);
	
		// Prepare Search Exact DTP
		// ...........................................		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_EXACT_DTP_ID))
		{
			JSOC_ELEMENT.VAR_VALUE(SEARCH_EXACT_DTP_ID, JSVC_DATE.VAR_FORMAT(SEARCH_EXACT_DTP_DEFAULT_VALUE, "YYYY-MM-DD") + "T00:00");
		}
				
		// Prepare Date~From Element
		// ...........................................	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_FROM_DTP_ID))
		{
			SEARCH_FROM_DTP_ELEMENT = JSOC_ELEMENT.VAR_GET(SEARCH_FROM_DTP_ID);

			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_QUICK_ACCESS_CMB_ID))
			{
				SEARCH_FROM_DTP_ELEMENT.onchange = function()
				{
					if(SEARCH_FROM_DTP_ELEMENT.disabled == false)
					{
						JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_QUICK_ACCESS_CMB_ELEMENT, JSOC_DTP.FLAG_CUSTOM.toString());
					}
				};
			}
			else
			{
				JSOC_ELEMENT.VAR_VALUE(SEARCH_FROM_DTP_ELEMENT, JSVC_DATE.VAR_FORMAT(SEARCH_FROM_DTP_DEFAULT_VALUE, "YYYY-MM-DD") + "T00:00");
			}
		}
		
		// Prepare Date~To element
		// ...........................................	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_TO_DTP_ID))
		{
			SEARCH_TO_DTP_ELEMENT = JSOC_ELEMENT.VAR_GET(SEARCH_TO_DTP_ID);

			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_QUICK_ACCESS_CMB_ID))
			{
				SEARCH_TO_DTP_ELEMENT.onchange = function()
				{
					if(SEARCH_TO_DTP_ELEMENT.disabled == false)
					{
						JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_QUICK_ACCESS_CMB_ELEMENT, JSOC_DTP.FLAG_CUSTOM.toString());
					}
				};
			}
			else
			{
				JSOC_ELEMENT.VAR_VALUE(SEARCH_TO_DTP_ELEMENT, JSVC_DATE.VAR_FORMAT(SEARCH_TO_DTP_DEFAULT_VALUE, "YYYY-MM-DD") + "T00:00");
			}					
		}
		
		// Prepare Quick access dropdown
		// ...........................................	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_QUICK_ACCESS_CMB_ID))
		{
			// Initialize
			SEARCH_QUICK_ACCESS_CMB_ELEMENT = JSOC_ELEMENT.VAR_GET(SEARCH_QUICK_ACCESS_CMB_ID);
			JSOC_DTP.VAR_CREATE_LIST(SEARCH_QUICK_ACCESS_CMB_ELEMENT);
			/*# NEW_LINE #*/	
			// Setup onChange event
			SEARCH_QUICK_ACCESS_CMB_ELEMENT.onchange = function()
			{
				if(SEARCH_QUICK_ACCESS_CMB_ELEMENT.disabled == false)
				{
					JSOC_DTP.VAR_DATESET_ASSIGN
					(
						SEARCH_FROM_DTP_ID, 
						SEARCH_TO_DTP_ID, 
						SEARCH_QUICK_ACCESS_CMB_ELEMENT
					);
				}
			};
			/*# NEW_LINE #*/	
			// Set to this week
			JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_QUICK_ACCESS_CMB_ELEMENT, DTP_DEFAULT_DATE_RANGE.toString()); 
			SEARCH_QUICK_ACCESS_CMB_ELEMENT.onchange();
		}
		
		// Return Result
		// ...........................................	
		return [
					DTP_ELEMENT,
					SEARCH_QUICK_ACCESS_CMB_ELEMENT,
					SEARCH_FROM_DTP_ELEMENT,
					SEARCH_TO_DTP_ELEMENT			
			   ];
	};
	
	
	/**
	 * Populate dropdown from JSON
	 */
	JSCUS_PG._TOOL.FORM_LOAD_COMBOBOX_FROM_JSON = function
	(
		COMBOBOX_ID,
		SEARCH_COMBOBOX_ID,
		MODAL_ID,
		LIBRARY_ADDRESS,
		MODAL_INSTANCE,
		
		ID_FIELD,
		DESCRIPTION_FIELD,
		STATUS_FIELD,
		
		DEFAULT_FIELD = "-",
		SEARCH_DEFAULT_FIELD = "Any"
	)
	{
		// If element, then replace to id
		// _______________________________________________________________________	
		if(JSVC_VAR.VAR_IS_ELEMENT(COMBOBOX_ID))
		{
			COMBOBOX_ID = COMBOBOX_ID.id;
		}
		if(JSVC_VAR.VAR_IS_ELEMENT(SEARCH_COMBOBOX_ID))
		{
			SEARCH_COMBOBOX_ID = SEARCH_COMBOBOX_ID.id;
		}		
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(COMBOBOX_ID) == true)
		{
			// Reset Dropdown
			// ...........................................
			JSOC_CMB.VAR_CLEAR(COMBOBOX_ID);		
			if(JSVC_VAR.VAR_ISSET(DEFAULT_FIELD))
			{
				JSOC_CMB.VAR_ADD(COMBOBOX_ID, FLAG_BIGINT_NULL.toString(), DEFAULT_FIELD);
			}
			

			// Filter data	
			// ...........................................
			JSON_DATA = JSRC_JSON.REF_CREATE(LIBRARY_ADDRESS.CUS_GET_QUICK());
			JSON_DATA = JSRC_JSON.REF_SEARCH
			(
				JSRC_JSON.REF_CREATE(JSON_DATA),
				['`' + STATUS_FIELD + '` == 2']
			);
				
			// Populate Result		
			// ...........................................
			JSOC_CMB.VAR_ADD_FROM_JSON
			(
					COMBOBOX_ID, 
					JSON_DATA, 
					ID_FIELD, 
					DESCRIPTION_FIELD, 	
					true			
			);
		
			// Set Default index
			// ...........................................
			JSOC_CMB.VAR_SELECTED_INDEX(COMBOBOX_ID, 0);
			
			// Copy items to edit control
			// ...........................................
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_COMBOBOX_ID) == true)
			{
				JSOC_CMB.VAR_CLEAR(SEARCH_COMBOBOX_ID);
				JSOC_CMB.VAR_ADD(SEARCH_COMBOBOX_ID, FLAG_BIGINT_NULL.toString(), SEARCH_DEFAULT_FIELD);
				JSOC_ELEMENT.VAR_INNER_HTML(SEARCH_COMBOBOX_ID, JSOC_ELEMENT.VAR_INNER_HTML(COMBOBOX_ID), true);
				JSOC_CMB.VAR_SELECTED_INDEX(SEARCH_COMBOBOX_ID, 0);
				$('.BSSP_' + SEARCH_COMBOBOX_ID).selectpicker('refresh');
			}				
			
			// Update Modal Settings
			// ...........................................
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(MODAL_ID) == true)
			{
				MODAL_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE(MODAL_ID);
			}
	
			// Forward populate complete event.
			// ...........................................
			$('.BSSP_' + COMBOBOX_ID).selectpicker('refresh');
		}
		
		else if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_COMBOBOX_ID) == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS(COMBOBOX_ID) == false
		)
		{
			// Reset Dropdown
			// ...........................................
			JSOC_CMB.VAR_CLEAR(SEARCH_COMBOBOX_ID);		
			if(JSVC_VAR.VAR_ISSET(SEARCH_DEFAULT_FIELD))
			{
				JSOC_CMB.VAR_ADD(SEARCH_COMBOBOX_ID, FLAG_BIGINT_NULL.toString(), SEARCH_DEFAULT_FIELD);
			}

			// Filter data	
			// ...........................................
			JSON_DATA = JSRC_JSON.REF_CREATE(LIBRARY_ADDRESS.CUS_GET_QUICK());
			JSON_DATA = JSRC_JSON.REF_SEARCH
			(
				JSRC_JSON.REF_CREATE(JSON_DATA),
				['`' + STATUS_FIELD + '` == 2']
			);
				
			// Populate Result		
			// ...........................................
			JSOC_CMB.VAR_ADD_FROM_JSON
			(
					SEARCH_COMBOBOX_ID, 
					JSON_DATA, 
					ID_FIELD, 
					DESCRIPTION_FIELD, 	
					true			
			);
	
			// Set Default index
			// ...........................................
			JSOC_CMB.VAR_SELECTED_INDEX(SEARCH_COMBOBOX_ID, 0);
					
			// Forward populate complete event.		
			// ...........................................
			$('.BSSP_' + SEARCH_COMBOBOX_ID).selectpicker('refresh');	
		}		 
	};


	/**
	 * Prepare dropdown from database data
	 */
	JSCUS_PG._TOOL.FORM_LOAD_COMBOBOX_FROM_DATABASE = function
	(
		COMBOBOX_ID,
		SEARCH_COMBOBOX_ID,
		MODAL_ID,
		LIBRARY_ADDRESS,
		MODAL_INSTANCE,
		
		ID_FIELD,
		DESCRIPTION_FIELD,
		STATUS_FIELD,
		
		DEFAULT_FIELD = "-",
		SEARCH_DEFAULT_FIELD = "Any"
	)
	{
		// If element, then replace to id
		// _______________________________________________________________________	
		if(JSVC_VAR.VAR_IS_ELEMENT(COMBOBOX_ID))
		{
			COMBOBOX_ID = COMBOBOX_ID.id;
		}
		if(JSVC_VAR.VAR_IS_ELEMENT(SEARCH_COMBOBOX_ID))
		{
			SEARCH_COMBOBOX_ID = SEARCH_COMBOBOX_ID.id;
		}		
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(COMBOBOX_ID) == true)
		{
			// Reset Dropdown
			// ...........................................
			JSOC_CMB.VAR_CLEAR(COMBOBOX_ID);		
			if(JSVC_VAR.VAR_ISSET(DEFAULT_FIELD))
			{
				JSOC_CMB.VAR_ADD(COMBOBOX_ID, FLAG_BIGINT_NULL.toString(), DEFAULT_FIELD);
			}
			

			// Filter data	
			// ...........................................
			JSON_DATA = JSRC_JSON.REF_CREATE(LIBRARY_ADDRESS.CUS_GET_QUICK());
			JSON_DATA = JSRC_JSON.REF_SEARCH
			(
				JSRC_JSON.REF_CREATE(JSON_DATA),
				['`' + STATUS_FIELD + '` == 2']
			);
				
			// Populate Result		
			// ...........................................
			JSOC_CMB.VAR_ADD_FROM_JSON
			(
					COMBOBOX_ID, 
					JSON_DATA, 
					ID_FIELD, 
					DESCRIPTION_FIELD, 	
					true			
			);
		
			// Set Default index
			// ...........................................
			JSOC_CMB.VAR_SELECTED_INDEX(COMBOBOX_ID, 0);
			
			// Copy items to edit control
			// ...........................................
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_COMBOBOX_ID) == true)
			{
				JSOC_CMB.VAR_CLEAR(SEARCH_COMBOBOX_ID);
				JSOC_CMB.VAR_ADD(SEARCH_COMBOBOX_ID, FLAG_BIGINT_NULL.toString(), SEARCH_DEFAULT_FIELD);
				JSOC_ELEMENT.VAR_INNER_HTML(SEARCH_COMBOBOX_ID, JSOC_ELEMENT.VAR_INNER_HTML(COMBOBOX_ID), true);
				JSOC_CMB.VAR_SELECTED_INDEX(SEARCH_COMBOBOX_ID, 0);
				$('.BSSP_' + SEARCH_COMBOBOX_ID).selectpicker('refresh');
			}				
			
			// Update Modal Settings
			// ...........................................
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(MODAL_ID) == true)
			{
				MODAL_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE(MODAL_ID);
			}
	
			// Forward populate complete event.
			// ...........................................
			$('.BSSP_' + COMBOBOX_ID).selectpicker('refresh');
		}
		
		else if
		(
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS(SEARCH_COMBOBOX_ID) == true &&
			JSOC_ELEMENT.VAR_ELEMENT_EXISTS(COMBOBOX_ID) == false
		)
		{
			// Reset Dropdown
			// ...........................................
			JSOC_CMB.VAR_CLEAR(SEARCH_COMBOBOX_ID);		
			if(JSVC_VAR.VAR_ISSET(SEARCH_DEFAULT_FIELD))
			{
				JSOC_CMB.VAR_ADD(SEARCH_COMBOBOX_ID, FLAG_BIGINT_NULL.toString(), SEARCH_DEFAULT_FIELD);
			}

			// Filter data	
			// ...........................................
			JSON_DATA = JSRC_JSON.REF_CREATE(LIBRARY_ADDRESS.CUS_GET_QUICK());
			JSON_DATA = JSRC_JSON.REF_SEARCH
			(
				JSRC_JSON.REF_CREATE(JSON_DATA),
				['`' + STATUS_FIELD + '` == 2']
			);
				
			// Populate Result		
			// ...........................................
			JSOC_CMB.VAR_ADD_FROM_JSON
			(
					SEARCH_COMBOBOX_ID, 
					JSON_DATA, 
					ID_FIELD, 
					DESCRIPTION_FIELD, 	
					true			
			);
	
			// Set Default index
			// ...........................................
			JSOC_CMB.VAR_SELECTED_INDEX(SEARCH_COMBOBOX_ID, 0);
					
			// Forward populate complete event.		
			// ...........................................
			$('.BSSP_' + SEARCH_COMBOBOX_ID).selectpicker('refresh');	
		}		 
	};
	
	
	/**
	 * Common Populatables
	 */
	JSCUS_PG._TOOL.COMMON = function(){};
	
	
	/**
	 * Load Region to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param MIX_GROUP_ID Int/String Group in Mix to populate.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 */
	JSCUS_PG._TOOL.COMMON.POPULATE_MIX = function
	(
		SELECT_ELEMENT, MIX_GROUP_ID, 
		NULL_ITEM = "-", SELECTED_ID = "-1", 
		ORDER_BY = null, ORDER_DIRECTION = 'ASC'
	)
	{
		JSCUS_PG._TOOL.MIX.POPULATE_DROPDOWN
		(
			SELECT_ELEMENT, MIX_GROUP_ID, null,
			NULL_ITEM, SELECTED_ID, 
			ORDER_BY, ORDER_DIRECTION
		);
	};
	
	
	
	JSCUS_PG._TOOL.MIX = function(){};
	JSCUS_PG._TOOL.MIX.CACHE_JSON = null;
	
	
	/**
	 * Retrieve full JSON of mix settings
	 */
	JSCUS_PG._TOOL.MIX.JSON = function()
	{
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.MIX.CACHE_JSON) == false)
		{
			JSCUS_PG._TOOL.MIX.CACHE_JSON = JSRC_JSON.REF_CREATE(JSCUS_SQL._CATEGORY._MIXSETTING.CUS_GET_QUICK());
		}
		return JSCUS_PG._TOOL.MIX.CACHE_JSON;
	};	
	
	
	/**
	 * Apply filter to MIX JSON
	 * @param CAT_MIX_ID Optional ID of mix.
	 * @param CAT_MIX_CODE Optional Code of mix.
	 * @param CAT_MIX_GROUP Optional Group of mix.
	 * @param CAT_MIX_PARENT_ID Optional for searching parent-child relationship records.
	 */
	JSCUS_PG._TOOL.MIX.SEARCH = function(CAT_MIX_ID = null, CAT_MIX_CODE = null, CAT_MIX_GROUP = null, CAT_MIX_PARENT_ID = null)
	{
		// Filter List
		// ...........................................
		var PGTADDR_JSON_OBJECT = JSCUS_PG._TOOL.MIX.JSON();
		var PGTADDR_JSON_OBJECT_PREFILTER = null;
		var ARR_INDEX = 0;
		
		// Abort if null
		// ...........................................
		if(CAT_MIX_ID == null && CAT_MIX_CODE == null && CAT_MIX_GROUP == null)
		{
			return;
		}	
			
		// Filter Data
		// ..........................................
		var KEYS = Object.keys(PGTADDR_JSON_OBJECT.CAT_MIX_ID).filter
		(
			function(key)
			{			
				return (
							CAT_MIX_ID == null || PGTADDR_JSON_OBJECT.CAT_MIX_ID[key] == CAT_MIX_ID
						) &&
						(
							 CAT_MIX_CODE == null || PGTADDR_JSON_OBJECT.CAT_MIX_CODE[key] == CAT_MIX_CODE
						) &&
						(
							 CAT_MIX_GROUP == null || PGTADDR_JSON_OBJECT.CAT_MIX_GROUP[key] == CAT_MIX_GROUP
						) &&
						(
							CAT_MIX_PARENT_ID == null || JSVC_STR.VAR_CONTAINS_LEFT(PGTADDR_JSON_OBJECT.CAT_MIX_LONGDATA[key], 'PARENT:[' + CAT_MIX_PARENT_ID + ']')
						);
			}
		);	
		
		// Populate Data
		// ..........................................		
		PGTADDR_JSON_OBJECT_PREFILTER = PGTADDR_JSON_OBJECT;
		PGTADDR_JSON_OBJECT = {};
		PGTADDR_JSON_OBJECT.JSON_COUNT = KEYS.length;
		PGTADDR_JSON_OBJECT.CAT_MIX_ID = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_CODE = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_GROUP = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_GROUP_NAME = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_DESCRIPTION = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_LONGDATA = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_REMARKS = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_SORT_INDEX = {};
		PGTADDR_JSON_OBJECT.CAT_MIX_STATUS = {};
		
		while(KEYS.length > ARR_INDEX)
		{
			PGTADDR_JSON_OBJECT.CAT_MIX_ID[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_ID[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_CODE[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_CODE[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_GROUP[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_GROUP[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_GROUP_NAME[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_GROUP_NAME[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_DESCRIPTION[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_DESCRIPTION[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_LONGDATA[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_LONGDATA[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_REMARKS[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_REMARKS[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_SORT_INDEX[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_SORT_INDEX[KEYS[ARR_INDEX]];
			PGTADDR_JSON_OBJECT.CAT_MIX_STATUS[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MIX_STATUS[KEYS[ARR_INDEX]];
			
			ARR_INDEX ++;
		}
		
		// Return Result
		// ..........................................	
		return PGTADDR_JSON_OBJECT;
	};
	
	
	/**
	 * Load Region to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param MIX_GROUP_ID Int/String Group in Mix to populate.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 * @param ORDER_BY String (Optional, default = null) Field to apply order [CAT_MIX_ID, CAT_MIX_CODE, CAT_MIX_GROUP, CAT_MIX_GROUP_NAME, CAT_MIX_DESCRIPTION, CAT_MIX_SORT_INDEX]
	 * @param ORDER_DIRECTION String (Optional, default = ASC) ASC / DESC
	 */
	JSCUS_PG._TOOL.MIX.POPULATE = function(SELECT_ELEMENT, MIX_GROUP_ID, NULL_ITEM = "-", SELECTED_ID = "-1", ORDER_BY = null, ORDER_DIRECTION = 'ASC')
	{
		JSCUS_PG._TOOL.MIX.POPULATE_DROPDOWN
		(
			SELECT_ELEMENT, MIX_GROUP_ID, null, NULL_ITEM, SELECTED_ID, ORDER_BY, ORDER_DIRECTION
		);
	};
	
	
		
	/**
	 * Load Region to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param MIX_GROUP_ID Int/String Group in Mix to populate.
	 * @param CAT_MIX_PARENT_ID Optional for searching parent-child relationship records.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 */
	JSCUS_PG._TOOL.MIX.POPULATE_DROPDOWN = function
	(
		SELECT_ELEMENT, MIX_GROUP_ID, CAT_MIX_PARENT_ID = null,
		NULL_ITEM = "-", SELECTED_ID = "-1", 
		ORDER_BY = null, ORDER_DIRECTION = 'ASC'
	)
	{
		// Convert to string if not
		// ...........................................
		if(JSVC_VAR.VAR_IS_STRING(MIX_GROUP_ID) == false)
		{
			MIX_GROUP_ID = MIX_GROUP_ID.toString();
		}
		
		// Set NULL Item
		// ...........................................
		JSOC_CMB.VAR_CLEAR(SELECT_ELEMENT);
		if(JSVC_STR.VAR_IS_BLANK(NULL_ITEM) == false)
		{
			JSOC_CMB.VAR_ADD(SELECT_ELEMENT, "-1", NULL_ITEM);
		}
		
		// Abort if null
		// ...........................................
		if(JSVC_NUM.VAR_NVAL(MIX_GROUP_ID) <= 0)
		{
			return;
		}		
			
		// Filter MIX
		// ...........................................
		PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.MIX.SEARCH(null, null, MIX_GROUP_ID, CAT_MIX_PARENT_ID);

		// Abort if no rows found
		// ...........................................
		if(JSRC_JSON.REF_READ_NVAL(PGTCOMM_JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			return;
		}
		
		// Apply Sorting
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(ORDER_BY))
		{
			PGTCOMM_JSON_OBJECT = JSRC_JSON.REF_ORDER_BY(PGTCOMM_JSON_OBJECT, ORDER_BY, ORDER_DIRECTION);
		}
		
		// Populate CMB
		// ...........................................
		JSOC_CMB.VAR_ADD_FROM_JSON
		(
			SELECT_ELEMENT, PGTCOMM_JSON_OBJECT, 	
			'CAT_MIX_ID', 'CAT_MIX_DESCRIPTION', 
			true, false				
		);						

		// Set Default Value
		// ...........................................
		JSOC_CMB.VAR_SELECTED_VALUE(SELECT_ELEMENT, SELECTED_ID);
	};
	
	
	/**
	 * Cache for the JSCUS_PG._TOOL.MIX.VALUE_FROM_ID(), for speed up redundant encounter of same ID
	 */
	JSCUS_PG._TOOL.MIX.VALUE_FROM_ID_MIX_ARRAY = [];
	
	
	/**
	 * Load Mix JSON from ID
	 * @param MIX_ID ID of mix
	 */
	JSCUS_PG._TOOL.MIX.JSON_FROM_ID = function(MIX_ID)
	{
		// Convert to string if not
		// ...........................................
		if(JSVC_VAR.VAR_IS_STRING(MIX_ID) == false)
		{
			MIX_ID = MIX_ID.toString();
		}
		
		// Load from cache
		// ...........................................
		if(JSCUS_PG._TOOL.MIX.VALUE_FROM_ID_MIX_ARRAY.hasOwnProperty(MIX_ID))
		{
			return JSCUS_PG._TOOL.MIX.VALUE_FROM_ID_MIX_ARRAY[MIX_ID];
		}
		
		// Search from MIX query
		// ...........................................
		JSCUS_PG._TOOL.MIX.VALUE_FROM_ID_MIX_ARRAY[MIX_ID] = JSCUS_PG._TOOL.MIX.SEARCH(MIX_ID);
		
		// Return result
		// ...........................................
		return JSCUS_PG._TOOL.MIX.VALUE_FROM_ID_MIX_ARRAY[MIX_ID];
		
	};
	
	
	/**
	 * Load Mix from ID
	 * @param MIX_ID ID of mix
	 * @param ELEMENT_TO_PUT_VALUE Optional For applying the result value directly to the element.
	 */
	JSCUS_PG._TOOL.MIX.VALUE_FROM_ID = function(MIX_ID, ELEMENT_TO_PUT_VALUE = null)
	{
		// Get JSON from MIX dataset
		// ...........................................
		var PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.MIX.JSON_FROM_ID(MIX_ID);
		var PGCOMM_ROW_COUNT = JSRC_JSON.REF_READ_NVALL(PGTCOMM_JSON_OBJECT, "JSON_COUNT");
		
		// No Data at result
		// ...........................................
		if(PGCOMM_ROW_COUNT <= 0)
		{
			return null;
		}	
		PGCOMM_RESULT_VALUE = JSRC_JSON.REF_READ(PGTCOMM_JSON_OBJECT, "CAT_MIX_DESCRIPTION", 1);
		
		// Apply to element
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(ELEMENT_TO_PUT_VALUE))
		{
			JSOC_ELEMENT.VAR_VALUE(ELEMENT_TO_PUT_VALUE, PGCOMM_RESULT_VALUE);
		}	
		
		// Return result
		// ...........................................
		return PGCOMM_RESULT_VALUE;
	};
	
	
	/**
	 * Replace Columns of MixID with MixValue 
	 * @param DGV_ELEMENT DGV to replace
	 * @param COLUNM_INDEX Column in DGV.
	 * @param MIX_GROUP_ID String (Optional)ID of MIX Group
	 * @param TARGET_COLUMN String (Optional) If want to replace separate column when replace condition is met.
	 */
	JSCUS_PG._TOOL.MIX.REPLACE = function(DGV_ELEMENT, COLUNM_INDEX, MIX_GROUP_ID, TARGET_COLUMN = null)
	{
		// Initialize
		// ...........................................
		var MIX_ROW_COUNT = DGV_ELEMENT.ROW.COUNT();
		var MIX_ROW_INDEX = 0;

		// Use Different Column
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(TARGET_COLUMN) == false)
		{
			TARGET_COLUMN = COLUNM_INDEX;
		}
		
		// Replace Value
		// ...........................................
		while(MIX_ROW_COUNT > MIX_ROW_INDEX)
		{
			DGV_ELEMENT.CELL.VALUE
			(
				TARGET_COLUMN, MIX_ROW_INDEX,
				JSCUS_PG._TOOL.MIX.VALUE_FROM_ID
				(
					DGV_ELEMENT.CELL.VALUE(COLUNM_INDEX, MIX_ROW_INDEX)
				)
			);
			MIX_ROW_INDEX ++;
		}
	};
	

	/**
	 * Populate Address Modules
	 */
	JSCUS_PG._TOOL.ADDRESS = function(){};
	
	JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_REGION = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PROVINCE = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_MUNICIPALITY = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_BARANGAY = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PUROK = null;
	
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_ID = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_VALUE = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_ID = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_VALUE = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_ID = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_VALUE = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_ID = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_VALUE = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_ID = null;
	JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_VALUE = null;
	
	// ~~~~~
	
	JSCUS_PG._TOOL.ADDRESS.JSON_REGION = function()
	{
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_REGION) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_REGION = JSRC_JSON.REF_CREATE(JSCUS_SQL._CATEGORY._ADDRESS_REGION.CUS_GET_QUICK());
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_REGION;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_REGION_ID = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_REGION();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_ID) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_ID = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_REGION_ID");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_ID;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_REGION_VALUE = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_REGION();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_VALUE) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_VALUE = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_REGION_DESCRIPTION");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_REGION_VALUE;
	};

	// ~~~~~

	JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE = function()
	{
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PROVINCE) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PROVINCE = JSRC_JSON.REF_CREATE(JSCUS_SQL._CATEGORY._ADDRESS_PROVINCE.CUS_GET_QUICK());
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PROVINCE;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE_ID = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_ID) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_ID = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_PROVINCE_ID");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_ID;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE_VALUE = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_VALUE) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_VALUE = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_PROVINCE_DESCRIPTION");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PROVINCE_VALUE;
	};
	
	// ~~~~~
	
	JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY = function()
	{
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_MUNICIPALITY) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_MUNICIPALITY = JSRC_JSON.REF_CREATE(JSCUS_SQL._CATEGORY._ADDRESS_MUNICIPALITY.CUS_GET_QUICK());
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_MUNICIPALITY;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY_ID = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_ID) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_ID = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_MUNICIPALITY_ID");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_ID;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY_VALUE = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_VALUE) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_VALUE = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_MUNICIPALITY_DESCRIPTION");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_MUNICIPALITY_VALUE;
	};
	
	// ~~~~~
	
	JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY = function()
	{
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_BARANGAY) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_BARANGAY = JSRC_JSON.REF_CREATE(JSCUS_SQL._CATEGORY._ADDRESS_BARANGAY.CUS_GET_QUICK());
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_BARANGAY;	
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY_ID = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_ID) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_ID = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_BARANGAY_ID");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_ID;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY_VALUE = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_VALUE) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_VALUE = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_BARANGAY_DESCRIPTION");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_BARANGAY_VALUE;
	};	
		
	// ~~~~~
	
	JSCUS_PG._TOOL.ADDRESS.JSON_PUROK = function()
	{
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PUROK) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PUROK = JSRC_JSON.REF_CREATE(JSCUS_SQL._CATEGORY._ADDRESS_PUROK.CUS_GET_QUICK());
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_JSON_PUROK;			
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_PUROK_ID = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_PUROK();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_ID) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_ID = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_PUROK_ID");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_ID;
	};
	JSCUS_PG._TOOL.ADDRESS.JSON_PUROK_VALUE = function()
	{
		var ADDR_JSON = JSCUS_PG._TOOL.ADDRESS.JSON_PUROK();
		if(JSVC_VAR.VAR_ISSET(JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_VALUE) == false)
		{
			JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_VALUE = JSRC_JSON.REF_READ_ALL(ADDR_JSON, "CAT_PUROK_DESCRIPTION");
		}
		return JSCUS_PG._TOOL.ADDRESS.CACHE_REPLACE_PUROK_VALUE;
	};	
		
	// ~~~~~
	
	/**
	 * Replace Columns of AddressID with AddressValue 
	 * @param DGV_ELEMENT DGV to replace
	 * @param COLUNM_INDEX Column in DGV.
	 * @param TARGET_COLUMN String (Optional) If want to replace separate column when replace condition is met.
	 */
	JSCUS_PG._TOOL.ADDRESS.REPLACE_REGION = function(DGV_ELEMENT, COLUNM_INDEX, TARGET_COLUMN = null)
	{
		// Initialize
		// ...........................................
		var PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_REGION();
		var ADDRESS_ID = [];
		var ADDRESS_VALUE = [];
		
		// Use Different Column
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(TARGET_COLUMN))
		{
			DGV_ELEMENT.COLUMN.COPY(COLUNM_INDEX, TARGET_COLUMN);
			COLUNM_INDEX = TARGET_COLUMN;
		}
		
		// Replace Value
		// ...........................................
		ADDRESS_ID = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_REGION_ID");
		ADDRESS_VALUE = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_REGION_DESCRIPTION");
		DGV_ELEMENT.COLUMN.REPLACE_FROM_ARRAY(COLUNM_INDEX, ADDRESS_ID, ADDRESS_VALUE, true);
	};
	
	
	/**
	 * Replace Columns of AddressID with AddressValue 
	 * @param DGV_ELEMENT DGV to replace
	 * @param COLUNM_INDEX Column in DGV.
	 * @param TARGET_COLUMN String (Optional) If want to replace separate column when replace condition is met.
	 */
	JSCUS_PG._TOOL.ADDRESS.REPLACE_PROVINCE = function(DGV_ELEMENT, COLUNM_INDEX, TARGET_COLUMN = null)
	{
		// Initialize
		// ...........................................
		var PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE();
		var ADDRESS_ID = [];
		var ADDRESS_VALUE = [];
		
		// Use Different Column
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(TARGET_COLUMN))
		{
			DGV_ELEMENT.COLUMN.COPY(COLUNM_INDEX, TARGET_COLUMN);
			COLUNM_INDEX = TARGET_COLUMN;
		}
		
		// Replace Value
		// ...........................................
		ADDRESS_ID = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_PROVINCE_ID");
		ADDRESS_VALUE = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_PROVINCE_DESCRIPTION");
		DGV_ELEMENT.COLUMN.REPLACE_FROM_ARRAY(COLUNM_INDEX, ADDRESS_ID, ADDRESS_VALUE, true);
	};
	
	
	/**
	 * Replace Columns of AddressID with AddressValue 
	 * @param DGV_ELEMENT DGV to replace
	 * @param COLUNM_INDEX Column in DGV.
	 * @param TARGET_COLUMN String (Optional) If want to replace separate column when replace condition is met.
	 */
	JSCUS_PG._TOOL.ADDRESS.REPLACE_MUNICIPALITY = function(DGV_ELEMENT, COLUNM_INDEX, TARGET_COLUMN = null)
	{
		// Initialize
		// ...........................................
		var PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY();
		var ADDRESS_ID = [];
		var ADDRESS_VALUE = [];
		
		// Use Different Column
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(TARGET_COLUMN))
		{
			DGV_ELEMENT.COLUMN.COPY(COLUNM_INDEX, TARGET_COLUMN);
			COLUNM_INDEX = TARGET_COLUMN;
		}
		
		// Replace Value
		// ...........................................
		ADDRESS_ID = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_MUNICIPALITY_ID");
		ADDRESS_VALUE = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_MUNICIPALITY_DESCRIPTION");
		DGV_ELEMENT.COLUMN.REPLACE_FROM_ARRAY(COLUNM_INDEX, ADDRESS_ID, ADDRESS_VALUE, true);
	};
	

	/**
	 * Replace Columns of AddressID with AddressValue 
	 * @param DGV_ELEMENT DGV to replace
	 * @param COLUNM_INDEX Column in DGV.
	 * @param TARGET_COLUMN String (Optional) If want to replace separate column when replace condition is met.
	 */
	JSCUS_PG._TOOL.ADDRESS.REPLACE_BARANGAY = function(DGV_ELEMENT, COLUNM_INDEX, TARGET_COLUMN = null)
	{
		// Initialize
		// ...........................................
		var PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY();
		var ADDRESS_ID = [];
		var ADDRESS_VALUE = [];
		
		// Use Different Column
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(TARGET_COLUMN))
		{
			DGV_ELEMENT.COLUMN.COPY(COLUNM_INDEX, TARGET_COLUMN);
			COLUNM_INDEX = TARGET_COLUMN;
		}
		
		// Replace Value
		// ...........................................
		ADDRESS_ID = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_BARANGAY_ID");
		ADDRESS_VALUE = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_BARANGAY_DESCRIPTION");
		DGV_ELEMENT.COLUMN.REPLACE_FROM_ARRAY(COLUNM_INDEX, ADDRESS_ID, ADDRESS_VALUE, true);
	};
	
		
	/**
	 * Load Region to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param PARENT_ID Int/String Country of regions to display.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 */
	JSCUS_PG._TOOL.ADDRESS.POPULATE_REGION = function(SELECT_ELEMENT, PARENT_ID, NULL_ITEM = "-", SELECTED_ID = "-1")
	{
		try
		{	
			// Filter List
			// ...........................................
			var PGTADDR_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_REGION();
			var PGTADDR_JSON_OBJECT_PREFILTER = null;
			var ROW_COUNT = 0;
			var ARR_INDEX = 0;
			
			// Insert blank line
			// ...........................................
			JSOC_CMB.VAR_CLEAR(SELECT_ELEMENT);
			if(JSVC_VAR.VAR_ISSET(NULL_ITEM))
			{
				JSOC_CMB.VAR_ADD(SELECT_ELEMENT, SELECTED_ID, NULL_ITEM);
			}
			
			// Abort if null
			// ...........................................
			if(JSVC_NUM.VAR_NVAL(PARENT_ID) <= 0)
			{
				return;
			}		
			
			// Filter Data
			// ..........................................
			var KEYS = Object.keys(PGTADDR_JSON_OBJECT.CAT_REGION_CAT_COUNTRY_ID).filter
			(
				function(key){return PGTADDR_JSON_OBJECT.CAT_REGION_CAT_COUNTRY_ID[key] == PARENT_ID.toString()}
			);
			
			PGTADDR_JSON_OBJECT_PREFILTER = PGTADDR_JSON_OBJECT;
			PGTADDR_JSON_OBJECT = {};
			PGTADDR_JSON_OBJECT.JSON_COUNT = KEYS.length;
			PGTADDR_JSON_OBJECT.CAT_REGION_ID = {};
			PGTADDR_JSON_OBJECT.CAT_REGION_DESCRIPTION = {};
			
			while(KEYS.length > ARR_INDEX)
			{
				PGTADDR_JSON_OBJECT.CAT_REGION_ID[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_REGION_ID[KEYS[ARR_INDEX]];
				PGTADDR_JSON_OBJECT.CAT_REGION_DESCRIPTION[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_REGION_DESCRIPTION[KEYS[ARR_INDEX]];
				ARR_INDEX ++;
			}
			
			
/*
			PGTADDR_JSON_OBJECT = JSRC_JSON.REF_SEARCH
			(
				PGTADDR_JSON_OBJECT, '`CAT_REGION_CAT_COUNTRY_ID` = ' + PARENT_ID.toString(), 1
			);
*/
			ROW_COUNT = JSRC_JSON.REF_READ_NVALL(PGTADDR_JSON_OBJECT, "JSON_COUNT");
			
			
			// Populate Data
			// ...........................................
			if(ROW_COUNT > 0)
			{
				JSOC_CMB.VAR_ADD_FROM_JSON
				(
					SELECT_ELEMENT, 
					PGTADDR_JSON_OBJECT, 	
					'CAT_REGION_ID', 'CAT_REGION_DESCRIPTION', 
					true, false				
				);
			}
			
			// Set Default index
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(SELECTED_ID))
			{
				JSOC_CMB.VAR_SELECTED_VALUE(SELECT_ELEMENT, SELECTED_ID.toString());
			}
			
			// Call dropdown updated event
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange))
			{
				JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange();	
			}	
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.POPULATE_REGION',
					['SELECT_ELEMENT', SELECT_ELEMENT],
					['PARENT_ID', PARENT_ID],
					['NULL_ITEM', NULL_ITEM],
					['SELECTED_ID', SELECTED_ID]
				]
			);
			throw ERR;
		}
	};
	
	
	/**
	 * Load Province to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param PARENT_ID Int/String Region of provinces to display.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 */
	JSCUS_PG._TOOL.ADDRESS.POPULATE_PROVINCE = function(SELECT_ELEMENT, PARENT_ID, NULL_ITEM = "-", SELECTED_ID = "-1")
	{
		try
		{
			// Filter List
			// ...........................................
			var PGTADDR_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE();
			var PGTADDR_JSON_OBJECT_PREFILTER = null;
			var ROW_COUNT = 0;
			var ARR_INDEX = 0;
			
			// Insert blank line
			// ...........................................
			JSOC_CMB.VAR_CLEAR(SELECT_ELEMENT);
			if(JSVC_VAR.VAR_ISSET(NULL_ITEM))
			{
				JSOC_CMB.VAR_ADD(SELECT_ELEMENT, SELECTED_ID, NULL_ITEM);
			}
			
			// Abort if null
			// ...........................................
			if(JSVC_NUM.VAR_NVAL(PARENT_ID) <= 0)
			{
				return;
			}
			
			// Filter Data
			// ...........................................
			var KEYS = Object.keys(PGTADDR_JSON_OBJECT.CAT_PROVINCE_CAT_REGION_ID).filter
			(
				function(key){return PGTADDR_JSON_OBJECT.CAT_PROVINCE_CAT_REGION_ID[key] == PARENT_ID.toString()}
			);
			
			PGTADDR_JSON_OBJECT_PREFILTER = PGTADDR_JSON_OBJECT;
			PGTADDR_JSON_OBJECT = {};
			PGTADDR_JSON_OBJECT.JSON_COUNT = KEYS.length;
			PGTADDR_JSON_OBJECT.CAT_PROVINCE_ID = {};
			PGTADDR_JSON_OBJECT.CAT_PROVINCE_DESCRIPTION = {};
			
			while(KEYS.length > ARR_INDEX)
			{
				PGTADDR_JSON_OBJECT.CAT_PROVINCE_ID[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_PROVINCE_ID[KEYS[ARR_INDEX]];
				PGTADDR_JSON_OBJECT.CAT_PROVINCE_DESCRIPTION[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_PROVINCE_DESCRIPTION[KEYS[ARR_INDEX]];
				ARR_INDEX ++;
			}
			
			/*
			PGTADDR_JSON_OBJECT = JSRC_JSON.REF_SEARCH
			(
				PGTADDR_JSON_OBJECT, '`CAT_PROVINCE_CAT_REGION_ID` = ' + PARENT_ID.toString(), 1
			);
			*/
			ROW_COUNT = JSRC_JSON.REF_READ_NVALL(PGTADDR_JSON_OBJECT, "JSON_COUNT");
			
			// Populate Data
			// ...........................................
			if(ROW_COUNT > 0)
			{
				JSOC_CMB.VAR_ADD_FROM_JSON
				(
					SELECT_ELEMENT, 
					PGTADDR_JSON_OBJECT, 	
					'CAT_PROVINCE_ID', 'CAT_PROVINCE_DESCRIPTION', 
					true, false				
				);
			}
			
			// Set Default index
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(SELECTED_ID))
			{
				JSOC_CMB.VAR_SELECTED_VALUE(SELECT_ELEMENT, SELECTED_ID.toString());
			}
			
			// Call dropdown updated event
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange))
			{
				JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange();	
			}				
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.POPULATE_PROVINCE',
					['SELECT_ELEMENT', SELECT_ELEMENT],
					['PARENT_ID', PARENT_ID],
					['NULL_ITEM', NULL_ITEM],
					['SELECTED_ID', SELECTED_ID]
				]
			);
			throw ERR;
		}
	};
	
	
	/**
	 * Load Municipality to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param PARENT_ID Int/String Province of municipalities to display.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 */
	JSCUS_PG._TOOL.ADDRESS.POPULATE_MUNICIPALITY = function(SELECT_ELEMENT, PARENT_ID, NULL_ITEM = "-", SELECTED_ID = "-1")
	{
		try
		{
			// Filter List
			// ...........................................
			var PGTADDR_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY();
			var PGTADDR_JSON_OBJECT_PREFILTER = null;
			var ROW_COUNT = 0;
			var ARR_INDEX = 0;
			
			// Insert blank line
			// ...........................................
			JSOC_CMB.VAR_CLEAR(SELECT_ELEMENT);
			if(JSVC_VAR.VAR_ISSET(NULL_ITEM))
			{
				JSOC_CMB.VAR_ADD(SELECT_ELEMENT, SELECTED_ID, NULL_ITEM);
			}
			
			// Abort if null
			// ...........................................
			if(JSVC_NUM.VAR_NVAL(PARENT_ID) <= 0)
			{
				return;
			}
			
			// Filter Data
			// ...........................................
			var KEYS = Object.keys(PGTADDR_JSON_OBJECT.CAT_MUNICIPALITY_CAT_PROVINCE_ID).filter
			(
				function(key){return PGTADDR_JSON_OBJECT.CAT_MUNICIPALITY_CAT_PROVINCE_ID[key] == PARENT_ID.toString()}
			);
			
			PGTADDR_JSON_OBJECT_PREFILTER = PGTADDR_JSON_OBJECT;
			PGTADDR_JSON_OBJECT = {};
			PGTADDR_JSON_OBJECT.JSON_COUNT = KEYS.length;
			PGTADDR_JSON_OBJECT.CAT_MUNICIPALITY_ID = {};
			PGTADDR_JSON_OBJECT.CAT_MUNICIPALITY_DESCRIPTION = {};
			
			while(KEYS.length > ARR_INDEX)
			{
				PGTADDR_JSON_OBJECT.CAT_MUNICIPALITY_ID[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MUNICIPALITY_ID[KEYS[ARR_INDEX]];
				PGTADDR_JSON_OBJECT.CAT_MUNICIPALITY_DESCRIPTION[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_MUNICIPALITY_DESCRIPTION[KEYS[ARR_INDEX]];
				ARR_INDEX ++;
			}
			
			/*
			PGTADDR_JSON_OBJECT = JSRC_JSON.REF_SEARCH
			(
				PGTADDR_JSON_OBJECT, '`CAT_MUNICIPALITY_CAT_PROVINCE_ID` = ' + PARENT_ID.toString(), 1
			);
			*/
			ROW_COUNT = JSRC_JSON.REF_READ_NVALL(PGTADDR_JSON_OBJECT, "JSON_COUNT");
			
			// Populate Data
			// ...........................................
			if(ROW_COUNT > 0)
			{
				JSOC_CMB.VAR_ADD_FROM_JSON
				(
					SELECT_ELEMENT, 
					PGTADDR_JSON_OBJECT, 	
					'CAT_MUNICIPALITY_ID', 'CAT_MUNICIPALITY_DESCRIPTION', 
					true, false				
				);
			}
			
			// Set Default index
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(SELECTED_ID))
			{
				JSOC_CMB.VAR_SELECTED_VALUE(SELECT_ELEMENT, SELECTED_ID.toString());
			}
			
			// Call dropdown updated event
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange))
			{
				JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange();	
			}			
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.POPULATE_MUNICIPALITY',
					['SELECT_ELEMENT', SELECT_ELEMENT],
					['PARENT_ID', PARENT_ID],
					['NULL_ITEM', NULL_ITEM],
					['SELECTED_ID', SELECTED_ID]
				]
			);
			throw ERR;
		}
	};
	
	
	/**
	 * Load Barangay to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param PARENT_ID Int/String Municipality of barangays to display.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 */
	JSCUS_PG._TOOL.ADDRESS.POPULATE_BARANGAY = function(SELECT_ELEMENT, PARENT_ID, NULL_ITEM = "-", SELECTED_ID = "-1")
	{
		try
		{	
			// Filter List
			// ...........................................
			var PGTADDR_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY();
			var PGTADDR_JSON_OBJECT_PREFILTER = null;
			var ROW_COUNT = 0;
			var ARR_INDEX = 0;
			
			// Insert blank line
			// ...........................................
			JSOC_CMB.VAR_CLEAR(SELECT_ELEMENT);
			if(JSVC_VAR.VAR_ISSET(NULL_ITEM))
			{
				JSOC_CMB.VAR_ADD(SELECT_ELEMENT, SELECTED_ID, NULL_ITEM);
			}
			
			// Abort if null
			// ...........................................
			if(JSVC_NUM.VAR_NVAL(PARENT_ID) <= 0)
			{
				return;
			}
			
			// Filter Data
			// ...........................................
			var KEYS = Object.keys(PGTADDR_JSON_OBJECT.CAT_BARANGAY_CAT_MUNICIPALITY_ID).filter
			(
				function(key){return PGTADDR_JSON_OBJECT.CAT_BARANGAY_CAT_MUNICIPALITY_ID[key] == PARENT_ID.toString()}
			);
			
			PGTADDR_JSON_OBJECT_PREFILTER = PGTADDR_JSON_OBJECT;
			PGTADDR_JSON_OBJECT = {};
			PGTADDR_JSON_OBJECT.JSON_COUNT = KEYS.length;
			PGTADDR_JSON_OBJECT.CAT_BARANGAY_ID = {};
			PGTADDR_JSON_OBJECT.CAT_BARANGAY_DESCRIPTION = {};
			
			while(KEYS.length > ARR_INDEX)
			{
				PGTADDR_JSON_OBJECT.CAT_BARANGAY_ID[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_BARANGAY_ID[KEYS[ARR_INDEX]];
				PGTADDR_JSON_OBJECT.CAT_BARANGAY_DESCRIPTION[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_BARANGAY_DESCRIPTION[KEYS[ARR_INDEX]];
				ARR_INDEX ++;
			}
			
			/*
			PGTADDR_JSON_OBJECT = JSRC_JSON.REF_SEARCH
			(
				PGTADDR_JSON_OBJECT, '`CAT_BARANGAY_CAT_MUNICIPALITY_ID` = ' + PARENT_ID.toString(), 1
			);
			*/
			ROW_COUNT = JSRC_JSON.REF_READ_NVALL(PGTADDR_JSON_OBJECT, "JSON_COUNT");
			
			// Populate Data
			// ...........................................
			if(ROW_COUNT > 0)
			{
				JSOC_CMB.VAR_ADD_FROM_JSON
				(
					SELECT_ELEMENT, 
					PGTADDR_JSON_OBJECT, 	
					'CAT_BARANGAY_ID', 'CAT_BARANGAY_DESCRIPTION', 
					true, false				
				);
			}
			
			// Set Default index
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(SELECTED_ID))
			{
				JSOC_CMB.VAR_SELECTED_VALUE(SELECT_ELEMENT, SELECTED_ID.toString());
			}
			
			// Call dropdown updated event
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange))
			{
				JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange();	
			}		
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.POPULATE_BARANGAY',
					['SELECT_ELEMENT', SELECT_ELEMENT],
					['PARENT_ID', PARENT_ID],
					['NULL_ITEM', NULL_ITEM],
					['SELECTED_ID', SELECTED_ID]
				]
			);
			throw ERR;
		}
	};
	
	
	/**
	 * Load Purok to dropdown element
	 * @param SELECT_ELEMENT String/ElementObject ID of select element
	 * @param PARENT_ID Int/String Barangay of puroks to display.
	 * @param NULL_ITEM String (Optional) Text to display for NOT-YET-SELECTED option. Pass null to skip this feature. Default = "-"
	 * @param SELECTED_ID Int/String (Optional) Default value of dropdown. Pass null to skip this feature. Default = -1. 
	 */
	JSCUS_PG._TOOL.ADDRESS.POPULATE_PUROK = function(SELECT_ELEMENT, PARENT_ID, NULL_ITEM = "-", SELECTED_ID = "-1")
	{
		try
		{
			// Filter List
			// ...........................................
			var PGTADDR_JSON_OBJECT = JSCUS_PG._TOOL.ADDRESS.JSON_PUROK();
			var PGTADDR_JSON_OBJECT_PREFILTER = null;
			var ROW_COUNT = 0;
			var ARR_INDEX = 0;
			
			// Insert blank line
			// ...........................................
			JSOC_CMB.VAR_CLEAR(SELECT_ELEMENT);
			if(JSVC_VAR.VAR_ISSET(NULL_ITEM))
			{
				JSOC_CMB.VAR_ADD(SELECT_ELEMENT, SELECTED_ID, NULL_ITEM);
			}
				
			// Abort if null
			// ...........................................
			if(JSVC_NUM.VAR_NVAL(PARENT_ID) <= 0)
			{
				return;
			}
			
			// Filter Data
			// ...........................................
			var KEYS = Object.keys(PGTADDR_JSON_OBJECT.CAT_PUROK_CAT_BARANGAY_ID).filter
			(
				function(key){return PGTADDR_JSON_OBJECT.CAT_PUROK_CAT_BARANGAY_ID[key] == PARENT_ID.toString()}
			);
			
			PGTADDR_JSON_OBJECT_PREFILTER = PGTADDR_JSON_OBJECT;
			PGTADDR_JSON_OBJECT = {};
			PGTADDR_JSON_OBJECT.JSON_COUNT = KEYS.length;
			PGTADDR_JSON_OBJECT.CAT_PUROK_ID = {};
			PGTADDR_JSON_OBJECT.CAT_PUROK_DESCRIPTION = {};
			
			while(KEYS.length > ARR_INDEX)
			{
				PGTADDR_JSON_OBJECT.CAT_PUROK_ID[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_PUROK_ID[KEYS[ARR_INDEX]];
				PGTADDR_JSON_OBJECT.CAT_PUROK_DESCRIPTION[(ARR_INDEX + 1).toString()] = PGTADDR_JSON_OBJECT_PREFILTER.CAT_PUROK_DESCRIPTION[KEYS[ARR_INDEX]];
				ARR_INDEX ++;
			}
			
			/*
			PGTADDR_JSON_OBJECT = JSRC_JSON.REF_SEARCH
			(
				PGTADDR_JSON_OBJECT, '`CAT_PUROK_CAT_BARANGAY_ID` = ' + PARENT_ID.toString(), 1
			);
			*/
			ROW_COUNT = JSRC_JSON.REF_READ_NVALL(PGTADDR_JSON_OBJECT, "JSON_COUNT");
			
			// Populate Data
			// ...........................................
			if(ROW_COUNT > 0)
			{
				JSOC_CMB.VAR_ADD_FROM_JSON
				(
					SELECT_ELEMENT, 
					PGTADDR_JSON_OBJECT, 	
					'CAT_PUROK_ID', 'CAT_PUROK_DESCRIPTION', 
					true, false				
				);
			}
			
			// Set Default index
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(SELECTED_ID))
			{
				JSOC_CMB.VAR_SELECTED_VALUE(SELECT_ELEMENT, SELECTED_ID.toString());
			}
			
			// Call dropdown updated event
			// ...........................................
			if(JSVC_VAR.VAR_ISSET(JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange))
			{
				JSOC_ELEMENT.VAR_GET(SELECT_ELEMENT).onchange();	
			}			
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.POPULATE_PUROK',
					['SELECT_ELEMENT', SELECT_ELEMENT],
					['PARENT_ID', PARENT_ID],
					['NULL_ITEM', NULL_ITEM],
					['SELECTED_ID', SELECTED_ID]
				]
			);
			throw ERR;
		}
	};
	

	/**
	 * Load Region from Primary Key ID
	 * @param ADDRESS_ID ID of address 
	 * @param BASE_INDEX Base Index of JSON (default = 1)
	 * @return String 
	 */
	JSCUS_PG._TOOL.ADDRESS.REGION_FROM_ID = function(ADDRESS_ID, BASE_INDEX = 1)
	{
		try
		{
			// Filter-out Address
			// ...........................................
			var ADDR_JSON_DATA = JSRC_JSON.REF_WHERE
			(
				JSCUS_PG._TOOL.ADDRESS.JSON_REGION(), 
				'CAT_REGION_ID', ADDRESS_ID
			);
			
			// Return Result
			// ...........................................
			if(ADDR_JSON_DATA.JSON_COUNT > 0)
			{
				return ADDR_JSON_DATA.CAT_REGION_DESCRIPTION[BASE_INDEX.toString()];
			}
			else
			{
				return null;
			}
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.REGION_FROM_ID',
					['ADDRESS_ID', ADDRESS_ID]
				]
			);
			throw ERR;			
		}
	};
	
		
	/**
	 * Load Province from Primary Key ID
	 * @param ADDRESS_ID ID of address 
	 * @param BASE_INDEX Base Index of JSON (default = 1)
	 * @return String 
	 */
	JSCUS_PG._TOOL.ADDRESS.PROVINCE_FROM_ID = function(ADDRESS_ID, BASE_INDEX = 1)
	{
		try
		{
			// Filter-out Address
			// ...........................................
			var ADDR_JSON_DATA = JSRC_JSON.REF_WHERE
			(
				JSCUS_PG._TOOL.ADDRESS.JSON_PROVINCE(), 
				'CAT_PROVINCE_ID', ADDRESS_ID
			);
			
			// Return Result
			// ...........................................
			if(ADDR_JSON_DATA.JSON_COUNT > 0)
			{
				return ADDR_JSON_DATA.CAT_PROVINCE_DESCRIPTION[BASE_INDEX.toString()];
			}
			else
			{
				return null;
			}
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.PROVINCE_FROM_ID',
					['ADDRESS_ID', ADDRESS_ID]
				]
			);
			throw ERR;			
		}
	};
	
	
	/**
	 * Load Municipality from Primary Key ID
	 * @param ADDRESS_ID ID of address 
	 * @param BASE_INDEX Base Index of JSON (default = 1)
	 * @return String 
	 */
	JSCUS_PG._TOOL.ADDRESS.MUNICIPALITY_FROM_ID = function(ADDRESS_ID, BASE_INDEX = 1)
	{
		try
		{
			// Filter-out Address
			// ...........................................
			var ADDR_JSON_DATA = JSRC_JSON.REF_WHERE
			(
				JSCUS_PG._TOOL.ADDRESS.JSON_MUNICIPALITY(), 
				'CAT_MUNICIPALITY_ID', ADDRESS_ID
			);
			
			// Return Result
			// ...........................................
			if(ADDR_JSON_DATA.JSON_COUNT > 0)
			{
				return ADDR_JSON_DATA.CAT_MUNICIPALITY_DESCRIPTION[BASE_INDEX.toString()];
			}
			else
			{
				return null;
			}
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.MUNICIPALITY_FROM_ID',
					['ADDRESS_ID', ADDRESS_ID]
				]
			);
			throw ERR;			
		}
	};
	
	
	/**
	 * Load Barangay from Primary Key ID
	 * @param ADDRESS_ID ID of address 
	 * @param BASE_INDEX Base Index of JSON (default = 1)
	 * @return String 
	 */
	JSCUS_PG._TOOL.ADDRESS.BARANGAY_FROM_ID = function(ADDRESS_ID, BASE_INDEX = 1)
	{
		try
		{
			// Filter-out Address
			// ...........................................
			var ADDR_JSON_DATA = JSRC_JSON.REF_WHERE
			(
				JSCUS_PG._TOOL.ADDRESS.JSON_BARANGAY(), 
				'CAT_BARANGAY_ID', ADDRESS_ID
			);
			
			// Return Result
			// ...........................................
			if(ADDR_JSON_DATA.JSON_COUNT > 0)
			{
				return ADDR_JSON_DATA.CAT_BARANGAY_DESCRIPTION[BASE_INDEX.toString()];
			}
			else
			{
				return null;
			}
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.BARANGAY_FROM_ID',
					['ADDRESS_ID', ADDRESS_ID]
				]
			);
			throw ERR;			
		}
	};
	
	
	/**
	 * Load Purok from Primary Key ID
	 * @param ADDRESS_ID ID of address 
	 * @param BASE_INDEX Base Index of JSON (default = 1)
	 * @return String 
	 */
	JSCUS_PG._TOOL.ADDRESS.PUROK_FROM_ID = function(ADDRESS_ID, BASE_INDEX = 1)
	{
		try
		{
			// Filter-out Address
			// ...........................................
			var ADDR_JSON_DATA = JSRC_JSON.REF_WHERE
			(
				JSCUS_PG._TOOL.ADDRESS.JSON_PUROK(), 
				'CAT_PUROK_ID', ADDRESS_ID
			);
			
			// Return Result
			// ...........................................
			if(ADDR_JSON_DATA.JSON_COUNT > 0)
			{
				return ADDR_JSON_DATA.CAT_PUROK_DESCRIPTION[BASE_INDEX.toString()];
			}
			else
			{
				return null;
			}
		}
		catch(ERR)
		{
			console.log
			(
				[
					'JSCUS_PG._TOOL.ADDRESS.PUROK_FROM_ID',
					['ADDRESS_ID', ADDRESS_ID]
				]
			);
			throw ERR;			
		}
	};
	
	// =================================================================================
	
	JSCUS_PG._TOOL.VERIFY_GET = function(){};
	
	/**
	 * Show Messagebox for Get verify failure
	 * @param String IS_SUCCESS
	 * @param String RESPONSE_STRING
	 * @return returns array [JSON, HAS_DATA, IS_ERROR, ERR_MESSAGE]
	 */
	JSCUS_PG._TOOL.VERIFY_GET.VERIFY = function(IS_SUCCESS, RESPONSE_STRING)
	{
		// Result 
		// ............................................
		var RESULT_ARRAY = [];
				
		// Validate
		// ............................................
		if(IS_SUCCESS === false)
		{
			console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
			RESULT_ARRAY.push(null);
			RESULT_ARRAY.push(false);
			RESULT_ARRAY.push(true);
			RESULT_ARRAY.push("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return RESULT_ARRAY;
		}
			
		// 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);
			RESULT_ARRAY.push(null);
			RESULT_ARRAY.push(false);
			RESULT_ARRAY.push(true);
			RESULT_ARRAY.push("REQUEST ERROR: \n" + RESPONSE_STRING);
			return RESULT_ARRAY;
		}
			
		// JSON Empty (Clears the DataGrodView)
		// ............................................
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			RESULT_ARRAY.push(null);
			RESULT_ARRAY.push(false);
			RESULT_ARRAY.push(false);
			RESULT_ARRAY.push(null);
			return RESULT_ARRAY;
		}			
		
		// Success
		// ............................................
		RESULT_ARRAY.push(JSON_OBJECT);
		RESULT_ARRAY.push(true);
		RESULT_ARRAY.push(false);
		RESULT_ARRAY.push(null);
		return RESULT_ARRAY;
	};		
	
	
	// =================================================================================
	
	JSCUS_PG._TOOL.VERIFY_SAVE = {};
	
	// =================================================================================
	
	/**
	 * Checks the Http Save request result 
	 * @param String IS_SUCCESS
	 * @param String RESPONSE_STRING
	 * @return returns array [JSON, HAS_DATA, IS_ERROR, ERR_MESSAGE]
	 */
	JSCUS_PG._TOOL.VERIFY_SAVE.VERIFY = function(IS_SUCCESS, RESPONSE_STRING)
	{
		return JSCUS_PG._TOOL.VERIFY_GET.VERIFY(IS_SUCCESS, RESPONSE_STRING);
	};
	
	// =================================================================================
	
	/**
	 * Show Messagebox for Save verify failure
	 * @param String INPUT_ELEMENT or Element
	 * @param String MESSAGE_STRING Error message
	 * @param Function Callback(boolean IS_SUCCESS) method
	 */
	JSCUS_PG._TOOL.VERIFY_SAVE.MSGBOX_ON_FAIL = function(INPUT_ELEMENT, MESSAGE_STRING, CALLBACK_METHOD)
	{
		JSOC_DIALOG.VAR_MESSAGE_BOX
		(
			MESSAGE_STRING, 
			'Information',
			'OK', 'WARNING',
			function()
			{
				INPUT_ELEMENT.style.borderColor = JSCUS_CACHE.SITE_ON_ERROR_BORDER_COLOR;
				INPUT_ELEMENT.focus();			
				if(JSVC_VAR.VAR_ISSET(CALLBACK_METHOD))
				{
					CALLBACK_METHOD(false);
				}
			}
		);			
	};
	
	
	/**
	 * Checks if zero, or negative value is given. SUpports Input and Select
	 * @param String or Element
	 * @param String Description of field
	 * @param Function Callback(boolean IS_SUCCESS) method
	 * @returns boolean If failed, returns false
	 */
	JSCUS_PG._TOOL.VERIFY_SAVE.ZERO_NEGATIVE = function
	(
		INPUT_ELEMENT, FIELD_NAME, CALLBACK_METHOD, 
		ALLOW_ZERO = false, 
		ALLOW_NEGATIVE = false
	)
	{
		try
		{
			// Initialize
			// ...........................................
			var INPUT_ELEMENT = JSOC_ELEMENT.VAR_GET(INPUT_ELEMENT);
			var INPUT_VALUE = 0;
			var IS_FAILED = false;
			var IS_ZERO = false;
			var IS_NEGATIVE = false;
			
			// Select
			// ...........................................
			if(INPUT_ELEMENT.tagName == "SELECT")
			{
				INPUT_VALUE = JSOC_CMB.VAR_SELECTED_VALUE_NVAL(INPUT_ELEMENT);
			}
			
			// Input
			// ...........................................
			else
			{
				INPUT_VALUE = JSOC_ELEMENT.VAR_VALUE_NVAL(INPUT_ELEMENT);
			}
			
			// Check if Zero
			// ...........................................
			if(ALLOW_ZERO == false && INPUT_VALUE == 0)
			{
				IS_FAILED = true;
				IS_ZERO = true;
			}
			else if(ALLOW_NEGATIVE == false && INPUT_VALUE < 0)
			{
				IS_FAILED = true;
				IS_NEGATIVE = true;
			}
			
			// Invalid Dropdown
			// ...........................................
			if(INPUT_ELEMENT.tagName == "SELECT" && IS_FAILED)
			{
				JSCUS_PG._TOOL.VERIFY_SAVE.MSGBOX_ON_FAIL
				(
					INPUT_ELEMENT, 'Invalid ' + FIELD_NAME + '.', CALLBACK_METHOD
				);					
			}
			
			// Raise onFailure Action : Zero Value
			// ...........................................
			if(IS_FAILED && IS_ZERO)
			{
				JSCUS_PG._TOOL.VERIFY_SAVE.MSGBOX_ON_FAIL
				(
					INPUT_ELEMENT, FIELD_NAME + ' cannot be zero(0).', CALLBACK_METHOD
				);			
			}
	
			// Raise onFailure Action : Negative Value
			// ...........................................
			if(IS_FAILED && IS_NEGATIVE)
			{
				JSCUS_PG._TOOL.VERIFY_SAVE.MSGBOX_ON_FAIL
				(
					INPUT_ELEMENT, FIELD_NAME + ' cannot be negative.', CALLBACK_METHOD
				);			
			}
					
			// Return Result
			// ...........................................
			return (IS_FAILED == false);
		}
		catch(ERR)
		{
			console.log
			(
				'JSCUS_PG._TOOL.VERIFY.ZERO_NEGATIVE',
				[
					['INPUT_ELEMENT', INPUT_ELEMENT],
					['FIELD_NAME', FIELD_NAME],
					['CALLBACK_METHOD', CALLBACK_METHOD],
					['ALLOW_ZERO', ALLOW_ZERO],
					['ALLOW_NEGATIVE', ALLOW_NEGATIVE]
				]
			);
			throw ERR;
		}
	};
	
	
	/**
	 * Checks if zero, or negative value is given. SUpports Input and Select
	 * @param INPUT_DATA (String or Element, Strng Field Name)
	 * @param Function Callback(boolean IS_SUCCESS) method
	 * @returns boolean If failed, returns false
	 */
	JSCUS_PG._TOOL.VERIFY_SAVE.ZERO_NEGATIVE_GROUP = function
	(
		INPUT_DATA, CALLBACK_METHOD, 
		ALLOW_ZERO = false, 
		ALLOW_NEGATIVE = false
	)
	{
		try
		{
			// Initialize
			// ...........................................
			var INPUT_COUNT = INPUT_DATA.length;
			var INPUT_INDEX = 0;
			
			// Apply all verification
			// ...........................................
			while(INPUT_COUNT > INPUT_INDEX)
			{
				if
				(
					JSCUS_PG._TOOL.VERIFY_SAVE.ZERO_NEGATIVE
					(
						INPUT_DATA[INPUT_INDEX][0], INPUT_DATA[INPUT_INDEX][1], 
						CALLBACK_METHOD, ALLOW_ZERO, ALLOW_NEGATIVE
					) == false
				)
				{
					return false;
				}				
				INPUT_INDEX ++;
			}
			
			// Return Success
			// ...........................................
			return true;
		}
		catch(ERR)
		{
			console.log
			(
				'JSCUS_PG._TOOL.VERIFY_SAVE.ZERO_NEGATIVE_GROUP',
				[
					['INPUT_DATA', INPUT_DATA],
					['CALLBACK_METHOD', CALLBACK_METHOD],
					['ALLOW_ZERO', ALLOW_ZERO],
					['ALLOW_NEGATIVE', ALLOW_NEGATIVE]
				]
			);
			throw ERR;
		}
	};
	

	/**
	 * Checks if matches the min/max length f value is given.
	 * @param String or Element
	 * @param String Description of field
	 * @param Function Callback(boolean IS_SUCCESS) method
	 * @returns boolean If failed, returns false
	 */
	JSCUS_PG._TOOL.VERIFY_SAVE.STRING = function
	(
		INPUT_ELEMENT, FIELD_NAME, CALLBACK_METHOD, 
		MIN_LENGTH = 1,
		MAX_LENGTH = 90000
	)
	{
		try
		{
			// Initialize
			// ...........................................
			var INPUT_ELEMENT = JSOC_ELEMENT.VAR_GET(INPUT_ELEMENT);
			var INPUT_VALUE = 0;
			var IS_FAILED = false;
			var IS_MIN_FAILED = false;
			var IS_MAX_FAILED = false;
			
			// Input
			// ...........................................
			INPUT_VALUE = JSOC_ELEMENT.VAR_VALUE(INPUT_ELEMENT);

			// Check if Zero
			// ...........................................
			if(MIN_LENGTH > JSVC_STR.VAR_LEN(INPUT_VALUE))
			{
				IS_FAILED = true;
				IS_MIN_FAILED = true;
			}
			else if(MAX_LENGTH < JSVC_STR.VAR_LEN(INPUT_VALUE))
			{
				IS_FAILED = true;
				IS_MAX_FAILED = true;
			}
			
			// Raise onFailure Action : Zero Value
			// ...........................................
			if(IS_FAILED && IS_MIN_FAILED)
			{
				JSCUS_PG._TOOL.VERIFY_SAVE.MSGBOX_ON_FAIL
				(
					INPUT_ELEMENT, FIELD_NAME + ' must have minimum length of (' + MIN_LENGTH.toString() + ').', CALLBACK_METHOD
				);			
			}
	
			// Raise onFailure Action : Negative Value
			// ...........................................
			if(IS_FAILED && IS_MAX_FAILED)
			{
				JSCUS_PG._TOOL.VERIFY_SAVE.MSGBOX_ON_FAIL
				(
					INPUT_ELEMENT, FIELD_NAME + ' has too many data (up to ' + IS_MAX_FAILED.toString() + ')', CALLBACK_METHOD
				);			
			}
					
			// Return Result
			// ...........................................
			return (IS_FAILED == false);
		}
		catch(ERR)
		{
			console.log
			(
				'JSCUS_PG._TOOL.VERIFY_SAVE.STRING',
				[
					['INPUT_ELEMENT', INPUT_ELEMENT],
					['FIELD_NAME', FIELD_NAME],
					['CALLBACK_METHOD', CALLBACK_METHOD],
					['MIN_LENGTH', MIN_LENGTH],
					['MAX_LENGTH', MAX_LENGTH]
				]
			);
			
			throw ERR;
		}
	};
	
	
	/**
	 * Checks if matches the min/max length f value is given.
	 * @param INPUT_DATA (String or Element, Strng Field Name)
	 * @param String Description of field
	 * @param Function Callback(boolean IS_SUCCESS) method
	 * @returns boolean If failed, returns false
	 */
	JSCUS_PG._TOOL.VERIFY_SAVE.STRING_GROUP = function
	(
		INPUT_DATA, CALLBACK_METHOD, 
		MIN_LENGTH = 1,
		MAX_LENGTH = 90000
	)
	{
		try
		{
			// Initialize
			// ...........................................
			var INPUT_COUNT = INPUT_DATA.length;
			var INPUT_INDEX = 0;
			
			// Apply all verification
			// ...........................................
			while(INPUT_COUNT > INPUT_INDEX)
			{
				if
				(
					JSCUS_PG._TOOL.VERIFY_SAVE.STRING
					(
						INPUT_DATA[INPUT_INDEX][0], INPUT_DATA[INPUT_INDEX][1], 
						CALLBACK_METHOD, MIN_LENGTH, MAX_LENGTH
					) == false
				)
				{
					return false;
				}				
				INPUT_INDEX ++;
			}
			
			// Return Success
			// ...........................................
			return true;
		}
		catch(ERR)
		{
			console.log
			(
				'JSCUS_PG._TOOL.VERIFY_SAVE.STRING_GROUP',
				[
					['INPUT_DATA', INPUT_DATA],
					['CALLBACK_METHOD', CALLBACK_METHOD],
					['MIN_LENGTH', MIN_LENGTH],
					['MAX_LENGTH', MAX_LENGTH]
				]
			);
			throw ERR;
		}		
	};
	
	
	
	/**
	 * Updates the total pages dropdown. Call this at every successful get result (table wide requsts only, not for limited calls). 
	 * ROW_COUNT int Total JSON_COUNT returned from the get request
	 * CACHED_GET_PARAM MapArray Last used GET requests parameters
	 * PAGINATION_CMB String ID of pagination dropdown element.
	 */
	JSCUS_PG._PGNAION.UPDATE = function(ROW_COUNT, CACHED_GET_PARAM, PAGINATION_CMB)
	{
		try
		{
			// Abort if no paging function enabled
			// _______________________________________________________________________
			if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS(PAGINATION_CMB) == false)
			{
				LOAD_PAGING_IGNORE_NEXT_REQUEST = false;
				return;
			}


			// Get Current Page
			// _______________________________________________________________________
			var C_PAGE = JSVC_NUM.VAR_STRIP_DECIMAL
			(
				JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['PARAM_SKIP']) / 
				JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['PARAM_LIMIT'])
			) + 1;
				
							
			// If more than one, Compute Max page from current search condition and result columns
			// _______________________________________________________________________
			if(ROW_COUNT > 0)
			{			
				// Populate newly found pages
				// ..................................................................
				while(JSOC_CMB.VAR_COUNT(PAGINATION_CMB) < C_PAGE)
				{
					JSOC_CMB.VAR_ADD
					(
						PAGINATION_CMB, 
						(JSOC_CMB.VAR_COUNT(PAGINATION_CMB) + 1).toString(), 
						(JSOC_CMB.VAR_COUNT(PAGINATION_CMB) + 1).toString()
					);				
				}
				
				// Select Current page from dropdown
				// ..................................................................
				JSOC_CMB.VAR_SELECTED_INDEX(PAGINATION_CMB, C_PAGE - 1);	
			}
			
			
			// if nothing found
			// _______________________________________________________________________
			else if(JSOC_CMB.VAR_COUNT(PAGINATION_CMB) == 0)
			{
				JSOC_CMB.VAR_ADD(PAGINATION_CMB, "1", "1");		
				JSOC_CMB.VAR_SELECTED_INDEX(PAGINATION_CMB, 0);
			}
			
			
			// Reset Current page index to last known valid index
			// _______________________________________________________________________
			else
			{
				JSOC_CMB.VAR_SELECTED_INDEX
				(
					PAGINATION_CMB, 
					JSOC_CMB.VAR_COUNT(PAGINATION_CMB) - 1
				);
			}		
			
			// If count is less than Page limit, remove pages
			// _______________________________________________________________________
			if
			(
				ROW_COUNT < JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['PARAM_LIMIT']) && 
				JSOC_CMB.VAR_COUNT(PAGINATION_CMB) > 1
			)
			{
				// Initialize
				// ..................................................................
				var C_PAGE_RMV = C_PAGE;
				 
				// Adjust it totaly no return in current request
				// ..................................................................
				if(ROW_COUNT <= 0)
				{
					C_PAGE_RMV --;
				}
				
				// Remove until it reaches the current requst page
				// ..................................................................
				while(JSOC_CMB.VAR_COUNT(PAGINATION_CMB) > C_PAGE_RMV)
				{
					JSOC_CMB.VAR_REMOVE(PAGINATION_CMB, JSOC_CMB.VAR_COUNT(PAGINATION_CMB) - 1);
				}
			}
				
		}
		catch(ERR)
		{
			console.error
			(
				'JSCUS_PG._PGNAION.UPDATE'
				[
					['ROW_COUNT', ROW_COUNT],
					['CACHED_GET_PARAM', CACHED_GET_PARAM],
					['PAGINATION_CMB', PAGINATION_CMB]
				]
			);
			throw ERR;
		}
	};
	
	
	/**
	 * Prepares GetMappedArray of pagination search. Returns if success (true) or not (false)
	 * PAGE_INDEX int Index of the page to search. (e.g. For Page 1, pass 0)
	 * CACHED_GET_PARAM MapArray Last used mapped array
	 */
	JSCUS_PG._PGNAION.PAGE = function(PAGE_INDEX, CACHED_GET_PARAM)
	{
		try
		{
			// Abort if no GET cache is found
			// _______________________________________________________________________		
			if(JSVC_VAR.VAR_ISSET(CACHED_GET_PARAM) == false || PAGE_INDEX < 0)
			{
				return false;
			}	
			
			// Update Paging row count
			// _______________________________________________________________________
			CACHED_GET_PARAM['PARAM_SKIP'] = JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['PARAM_LIMIT']) * PAGE_INDEX;	
			
			// Return Result
			// _______________________________________________________________________
			return true;
		}
		catch(ERR)
		{
			console.error
			(
				'JSCUS_PG._PGNAION.PAGE'
				[
					['PAGE_INDEX', PAGE_INDEX],
					['CACHED_GET_PARAM', CACHED_GET_PARAM]
				]
			);		
			throw ERR;	
		}
	};
	

	/**
	 * Prepares GetMappedArray of pagination search. Returns if success (true) or not (false)
	 * PAGE_INDEX int Index of the page to search. (e.g. For Page 1, pass 0)
	 * CACHED_GET_PARAM MapArray Last used mapped array
	 */
	JSCUS_PG._PGNAION.ADD = function(PAGINATION_CMB, ADJUST_PAGE_INDEX, CACHED_GET_PARAM)
	{
		try
		{
			// Abort if no GET cache is found
			// _______________________________________________________________________		
			if(JSVC_VAR.VAR_ISSET(CACHED_GET_PARAM) == false || ADJUST_PAGE_INDEX == 0)
			{
				return false;
			}	
			
			// If add and current page is max
			// _______________________________________________________________________
			if
			(
				ADJUST_PAGE_INDEX > 0 &&
				JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['HTTPPG_LAST_COUNT']) < JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['PARAM_LIMIT'])
			)
			{
				return false;
			}
			
			// Update Paging row count
			// _______________________________________________________________________
			var NEW_PAGE_INDEX = JSOC_CMB.VAR_SELECTED_INDEX(PAGINATION_CMB) + ADJUST_PAGE_INDEX;
			
			// Adjust if over max (up to 20 pages only)
			// .............................
			if(JSCUS_PG._FLAG.PGNATION_DEFAULT_PAGES > JSOC_CMB.VAR_COUNT(PAGINATION_CMB))
			{
				NEW_PAGE_INDEX = JSOC_CMB.VAR_COUNT(PAGINATION_CMB) - 1;
				if(CACHED_GET_PARAM['PARAM_SKIP'] == JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['PARAM_LIMIT']) * NEW_PAGE_INDEX)
				{
					return false;
				}
			}
			
			// Adjust if under min
			// .............................
			if(NEW_PAGE_INDEX < 0)
			{
				if(JSOC_CMB.VAR_SELECTED_INDEX(PAGINATION_CMB) == 0)
				{
					return false;
				}
				NEW_PAGE_INDEX = 0;
			}
			
			// Set Actual Page
			// .............................
			CACHED_GET_PARAM['PARAM_SKIP'] = JSVC_NUM.VAR_NVALL(CACHED_GET_PARAM['PARAM_LIMIT']) * NEW_PAGE_INDEX;	
			
			// Return Result
			// _______________________________________________________________________
			return true;
		}
		catch(ERR)
		{
			console.error
			(
				'JSCUS_PG._PGNAION.ADD'
				[
					['PAGINATION_CMB', PAGINATION_CMB],
					['ADJUST_PAGE_INDEX', ADJUST_PAGE_INDEX],
					['CACHED_GET_PARAM', CACHED_GET_PARAM]
				]
			);		
			throw ERR;	
		}
	};
	
		
	/**
	 * Resets the pagination dropdown. Call this everytime the LastMapArray is updated.
	 * PAGINATION_CMB String ID of pagination dropdown element.
	 */
	JSCUS_PG._PGNAION.CLEAR = function(PAGINATION_CMB)
	{
		JSOC_CMB.VAR_CLEAR(PAGINATION_CMB);
		while(JSCUS_PG._FLAG.PGNATION_DEFAULT_PAGES > JSOC_CMB.VAR_COUNT(PAGINATION_CMB))
		{
			JSOC_CMB.VAR_ADD
			(
				PAGINATION_CMB, 
				(JSOC_CMB.VAR_COUNT(PAGINATION_CMB) + 1).toString(), 
				(JSOC_CMB.VAR_COUNT(PAGINATION_CMB) + 1).toString()
			);
		}
		JSOC_CMB.VAR_SELECTED_INDEX(PAGINATION_CMB, 0);
	};
	