// CATEGORY_ADDRESS_BARANGAY GET
JSCUS_PG = function(){};
JSCUS_PG._FLAG = function(){};
JSCUS_PG._TOOL = 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;
	
	// ~~~~~
	
	/**
	 * 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;
	};
	
	
	/**
	 * 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);
				if(CURRENT_INDEX + 1 < JSOC_CMB.VAR_COUNT(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(){HTTP_SEARCH_LOAD_PAGE();}
		);

		// 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]
		// _______________________________________________________________________
		EXPORT_ALL_BBI = JSCUS_PG._TOOL.APPLY_BUTTON_SETUP
		(
			"EXPORT_ALL_BBI", function()
			{
				// Initialize
				// ...........................................
				JSOC_DIALOG.VAR_LOADING_SPINNER(true);		
				var CSV_DATA = "";
				
				// Generate CSV from collected data 
				// ...........................................
				var 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();
						JSRC_THREAD.REF_POST_DELAYED
						(
							function()
							{
								WAIT_WHILE_LOADING();
							},
							500
						);
					}
					else
					{
						JSRC_THREAD.REF_POST_DELAYED			
						(
							async function()
							{
								await JSRC_EXCEL.REF_EXPORT_FROM_STRING 
								(
									CSV_DATA, 'download.csv'
								);
								CUS_SEND_DIALOG_TRY_DISMISS();
							},
							100
						);
					}
				};
				
				// Wait while loading page. Convert page to csv
				// ...........................................
				var WAIT_WHILE_LOADING = function()
				{
					if
					(
						CUS_SEND_REQUEST_HAS_QUEUE() || PROPERTY_SEARCH_STATUS == true
					)
					{
						JSRC_THREAD.REF_POST_DELAYED
						(
							function()
							{
								WAIT_WHILE_LOADING();
							},
							500
						);							
					}
					else
					{
						CSV_DATA = JSRC_EXCEL.REF_TABLE_TO_CSV(DGV_ELEMENT_ID, CSV_DATA);
						LOAD_NEXT_PAGE();
					}
				};
				
				
				// Set to First page
				// ...........................................
				JSOC_CMB.VAR_SELECTED_INDEX(LOAD_PAGING_CMB, 0);
				LOAD_PAGING_CMB.onchange();
				JSRC_THREAD.REF_POST_DELAYED
				(
					function()
					{
						WAIT_WHILE_LOADING();
					},
					500
				);
			}
		);		
			
	};
	
	
	
	
	/**
	 * 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'
	)
	{
		// 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);

		// 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);
	};
	
	
	JSCUS_PG._TOOL.MIX = function(){};
	JSCUS_PG._TOOL.MIX.CACHE_JSON = null;
	
	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.
	 */
	JSCUS_PG._TOOL.MIX.SEARCH = function(CAT_MIX_ID = null, CAT_MIX_CODE = null, CAT_MIX_GROUP = 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
						);
			}
		);	
		
		// 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.COMMON.POPULATE_MIX(SELECT_ELEMENT, MIX_GROUP_ID, NULL_ITEM, SELECTED_ID, ORDER_BY, ORDER_DIRECTION);
	};
	
	
	/**
	 * 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)
	{
		// Initialize
		// ...........................................
		var PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.MIX.JSON();
		var PGCOMM_RESULT_VALUE = null;
		var PGCOMM_ROW_COUNT = 0;
		
		// Convert to string if not
		// ...........................................
		if(JSVC_VAR.VAR_IS_STRING(MIX_ID) == false)
		{
			MIX_ID = MIX_ID.toString();
		}
		
		// Apply Filter
		// ...........................................
		PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.MIX.SEARCH(MIX_ID);	
		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 PGTCOMM_JSON_OBJECT =JSCUS_PG._TOOL.MIX.JSON();
		var MIX_ID = [];
		var MIX_VALUE = [];
		
		// Convert to string if not
		// ...........................................
		if(JSVC_VAR.VAR_IS_STRING(MIX_GROUP_ID) == false)
		{
			MIX_GROUP_ID = MIX_GROUP_ID.toString();
		}
		
		// Filter MIX
		// ...........................................
		PGTCOMM_JSON_OBJECT = JSCUS_PG._TOOL.MIX.SEARCH(null, null, MIX_GROUP_ID);
		
		// Use Different Column
		// ...........................................
		if(JSVC_VAR.VAR_ISSET(TARGET_COLUMN))
		{
			DGV_ELEMENT.COLUMN.COPY(DGV_ELEMENT, COLUNM_INDEX, TARGET_COLUMN);
			COLUNM_INDEX = TARGET_COLUMN;
		}
		
		// Replace Value
		// ...........................................
		MIX_ID = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_MIX_ID");
		MIX_VALUE = JSRC_JSON.REF_READ_ALL(PGTCOMM_JSON_OBJECT, "CAT_MIX_DESCRIPTION");
		DGV_ELEMENT.COLUMN.REPLACE_FROM_ARRAY(COLUNM_INDEX, MIX_ID, MIX_VALUE, true);
	};
	

	/**
	 * 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 = null;
		}
		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, "-1", "-");
			}
			
			// 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, "-1", "-");
			}
			
			// 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, "-1", "-");
			}
			
			// 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, "-1", "-");
			}
			
			// 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, "-1", "-");
			}
				
			// 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;
		}
	};