// NOTE: [Must this JS loaded as last item]


	// ===============================================================
	// Initialize Form
	// ===============================================================
	function FORM_LOAD()
	{
		// Load DataGridVuew
		// _______________________________________________________________________	
		MEMBER_DGV = DataGridView("MEMBER_DGV");
		MEMBER_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				// Delete Button
				// ...........................................
				if(MEMBER_DGV.COLUMN.NAME(COL_INDEX) == "DELETE_CMD")
				{
					HTTP_DELETE
					(
						function(IS_SUCCESS)
						{
							console.log('Record Deleted.');
						}, 
						ROW_INDEX
					);
				}			
	
				// Change Password Button
				// ...........................................
				else if(MEMBER_DGV.COLUMN.NAME(COL_INDEX) == "CHANGE_PASSWORD_CMD")
				{
					CUS_ADMIN_CHANGE_PASSWORD(ROW_INDEX);		
				}	
				
				// If dialog supported
				// ...........................................
				else if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("MEMBER_MODAL") == true)
				{
					// Clear Modal
					if(JSVC_VAR.VAR_ISSET(INPUT_INSTANCE))
					{
						JSOC_WINDOW.VAR_INPUT_INSTANCE_RESTORE(INPUT_INSTANCE);
					}
						
					// Display Modal
					PROPERTY_ACC_ACCOUNT_ID = MEMBER_DGV.CELL.VALUE('ACC_ACCOUNT_ID', ROW_INDEX);
					PROPERTY_EDIT_ROW_INDEX = ROW_INDEX;
					JSOC_DIALOG.VAR_MODAL("MEMBER_MODAL", true);
					HTTP_LOAD();
					
					// Enable Password Input
					JSOC_STYLE.VAR_DISPLAY("PASSWORD_ROW", "NONE");
					JSOC_ELEMENT.VAR_VALUE("ACC_ACCOUNT_PASSWORD_TXT", FLAG_NVARCHAR_NULL);
					JSOC_STYLE.VAR_DISPLAY("PASSWORD_CONFIRM_ROW", "NONE");
					JSOC_ELEMENT.VAR_VALUE("ACC_ACCOUNT_PASSWORD_CONFIRM_TXT", FLAG_NVARCHAR_NULL);
					return;
				}
				
				// Open View / Edit Page
				// ...........................................
				else
				{
					// Cache Primary Key
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_ID', 
						MEMBER_DGV.CELL.VALUE('ACC_ACCOUNT_ID', ROW_INDEX), 
						5, 
						JSCUS_CACHE.SERVER_URL
					);
					JSVC_COOKIE.VAR_ADD
					(
						'PROPERTY_PARENT_DESCRIPTION', 
						MEMBER_DGV.CELL.VALUE('ACC_ACCOUNT_USERNAME', ROW_INDEX), 
						5, 
						JSCUS_CACHE.SERVER_URL
					);
					
					// Open EditPage
					window.location='member_info.htm';				
				}

			}
		);   

		
		// Show Progress
		// _______________________________________________________________________	
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		
		// Requires Authentication
		// _______________________________________________________________________	
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);			
		
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACC_ACCOUNT_ACC_LEVEL_ID_CMB") == true)
		{
			JSCUS_SQL._ACCOUNT._LEVEL.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("ACC_ACCOUNT_ACC_LEVEL_ID_CMB", 0);
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_ACC_LEVEL_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_ACC_ACCOUNT_ACC_LEVEL_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_ACC_LEVEL_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Level");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_ACC_ACCOUNT_ACC_LEVEL_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("ACC_ACCOUNT_ACC_LEVEL_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_ACC_ACCOUNT_ACC_LEVEL_ID_CMB", 0);
					}				 
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("MEMBER_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("MEMBER_MODAL");
					}
					
					// Forward populate complete event.
					HTTP_POPULATE_RESULT();		
				},
				"ACC_ACCOUNT_ACC_LEVEL_ID_CMB",
				false,
				2
			);
		}
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACC_ACCOUNT_ACC_GROUP_ID_CMB") == true)
		{
			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("ACC_ACCOUNT_ACC_GROUP_ID_CMB", 0);
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_ACC_GROUP_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_ACC_ACCOUNT_ACC_GROUP_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Group");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_ACC_ACCOUNT_ACC_GROUP_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("ACC_ACCOUNT_ACC_GROUP_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_ACC_ACCOUNT_ACC_GROUP_ID_CMB", 0);
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("MEMBER_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("MEMBER_MODAL");
					}
					
					// Forward populate complete event.
					HTTP_POPULATE_RESULT();		
				},
				"ACC_ACCOUNT_ACC_GROUP_ID_CMB",
				false,
				2
			);
		}
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACC_ACCOUNT_ADD_RESOURCE_ID_CMB") == true)
		{
			JSCUS_SQL._ADDON._RESOURCE.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("ACC_ACCOUNT_ADD_RESOURCE_ID_CMB", 0);
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_ADD_RESOURCE_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_ACC_ACCOUNT_ADD_RESOURCE_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_ADD_RESOURCE_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Resource");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_ACC_ACCOUNT_ADD_RESOURCE_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("ACC_ACCOUNT_ADD_RESOURCE_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_ACC_ACCOUNT_ADD_RESOURCE_ID_CMB", 0);
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("MEMBER_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("MEMBER_MODAL");
					}
					
					// Forward populate complete event.
					HTTP_POPULATE_RESULT();		
				},
				"ACC_ACCOUNT_ADD_RESOURCE_ID_CMB",
				false,
				2
			);
		}
		
		// Foreign Key [Fixed]
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACC_ACCOUNT_SYS_GENDER_ID_CMB") == true)
		{
			JSCUS_SQL._SYSTEM._GENDER.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function()
				{
					// Set Default index
					JSOC_CMB.VAR_SELECTED_INDEX("ACC_ACCOUNT_SYS_GENDER_ID_CMB", 0);
					
					// Copy items to edit control
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_SYS_GENDER_ID_CMB") == true)
					{
						JSOC_CMB.VAR_CLEAR("SEARCH_ACC_ACCOUNT_SYS_GENDER_ID_CMB");
						JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_SYS_GENDER_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Gender");
						JSOC_ELEMENT.VAR_INNER_HTML("SEARCH_ACC_ACCOUNT_SYS_GENDER_ID_CMB", JSOC_ELEMENT.VAR_INNER_HTML("ACC_ACCOUNT_SYS_GENDER_ID_CMB"), true);
						JSOC_CMB.VAR_SELECTED_INDEX("SEARCH_ACC_ACCOUNT_SYS_GENDER_ID_CMB", 0);
					}				
					
					// Update Modal Settings
					if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("MEMBER_MODAL") == true)
					{
						INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("MEMBER_MODAL");
					}
					
					// Forward populate complete event.
					HTTP_POPULATE_RESULT();		
				},
				"ACC_ACCOUNT_SYS_GENDER_ID_CMB",
				false,
				2
			);
		}
		
		// Status		
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_STATUS_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_ACC_ACCOUNT_STATUS_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_STATUS_CMB", "0","Any Status");
			JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_STATUS_CMB", "1","Inactive");
			JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_STATUS_CMB", "2","Active");
			JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_STATUS_CMB", "3","Closed");
			JSOC_CMB.VAR_ADD("SEARCH_ACC_ACCOUNT_STATUS_CMB", "4","Completed");
		}			
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("ACC_ACCOUNT_STATUS_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("ACC_ACCOUNT_STATUS_CMB");
			JSOC_CMB.VAR_ADD("ACC_ACCOUNT_STATUS_CMB", "1","Inactive");
			JSOC_CMB.VAR_ADD("ACC_ACCOUNT_STATUS_CMB", "2","Active");
			JSOC_CMB.VAR_ADD("ACC_ACCOUNT_STATUS_CMB", "3","Closed");
			JSOC_CMB.VAR_ADD("ACC_ACCOUNT_STATUS_CMB", "4","Completed");
			JSOC_CMB.VAR_SELECTED_VALUE("ACC_ACCOUNT_STATUS_CMB", "2");
		}
		
		
		
		// Get Modal Instance (Add Modal Adjustment before this line)
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("MEMBER_MODAL") == true)
		{
			INPUT_INSTANCE = JSOC_WINDOW.VAR_INPUT_INSTANCE_CLONE("MEMBER_MODAL");
		}
		
		
		// Add Search Events for the SEARCH_CMD - Button
		// _______________________________________________________________________	
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD"))
		{
			var SEARCH_CMD = JSOC_ELEMENT.VAR_GET("SEARCH_CMD");
			SEARCH_CMD.onclick = HTTP_SEARCH;
		}
		
		
		// Add Search Events for the SEARCH_DESCRIPTION_TXT - TextInput
		// _______________________________________________________________________		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_USERNAME_TXT"))
		{
			var SEARCH_ACC_ACCOUNT_USERNAME_TXT = JSOC_ELEMENT.VAR_GET("SEARCH_ACC_ACCOUNT_USERNAME_TXT");
			SEARCH_ACC_ACCOUNT_USERNAME_TXT.onkeydown = 
				function() 
				{ 
					return function(e) 
					{
						if
						(
							(
								e.which == 13 || 
								e.keyCode == 13 || 
								e.key === "Enter"
							) &&
							JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_CMD")
						)
						{
							HTTP_SEARCH();
						}
					};
				}();;		
		}
		
		
		// Pre-Load Items (uncomment if no foreign key pre-fetch)
		// _______________________________________________________________________	
		if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
		{
			HTTP_SEARCH();
		}
		
		
		// Disable Dialogs
		// _______________________________________________________________________	
		CUS_SEND_DIALOG_TRY_DISMISS();
	}
	
	
	// ===============================================================
	// Populate Foreign Keys
	// ===============================================================
	function HTTP_POPULATE_RESULT(IS_SUCCESS, HTTP_RESPONSE)
	{
		// Disable Dialogs
		CUS_SEND_DIALOG_TRY_DISMISS();
			
		// Handle Error
		if(IS_SUCCESS === false)
		{
			alert("Unable to populate lists.");
		}
		else
		{
			// Disable Dialogs
			if(CUS_SEND_REQUEST_HAS_QUEUE() == false)
			{
				HTTP_SEARCH();
			}
		}
	}

	
	// ===============================================================
	// Request Search - PART.A
	// ===============================================================
	function HTTP_SEARCH()
	{
		GET_MAP_ARRAY = JSCUS_SQL._ACCOUNT._MEMBER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();	
		// JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_PARENT_ID', PROPERTY_PARENT_ID));		// Parent ID Sample
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_SERVER_ID_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_SERVER_ID', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_SERVER_ID_TXT"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_ACC_LEVEL_ID_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_ACC_LEVEL_ID', JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_ACC_ACCOUNT_ACC_LEVEL_ID_CMB"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_ACC_GROUP_ID_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_ACC_GROUP_ID', JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_ACC_ACCOUNT_ACC_GROUP_ID_CMB"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_ADD_RESOURCE_ID_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_ADD_RESOURCE_ID', JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_ACC_ACCOUNT_ADD_RESOURCE_ID_CMB"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_USERNAME_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_USERNAME', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_USERNAME_TXT"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_AUTH_CODE_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_AUTH_CODE', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_AUTH_CODE_TXT"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_FIRST_NAME_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_FIRST_NAME', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_FIRST_NAME_TXT"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_MIDDLE_NAME_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_MIDDLE_NAME', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_MIDDLE_NAME_TXT"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_LAST_NAME_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_LAST_NAME', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_LAST_NAME_TXT"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_POSITION_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_POSITION', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_POSITION_TXT"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_SYS_GENDER_ID_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_SYS_GENDER_ID', JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_ACC_ACCOUNT_SYS_GENDER_ID_CMB"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_STATUS_CMB") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_STATUS', JSOC_CMB.VAR_SELECTED_VALUE("SEARCH_ACC_ACCOUNT_STATUS_CMB"));
		}
		
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_ACCOUNT_SYSTEM_GENERATED_TXT") == true)
		{
			JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ACC_ACCOUNT_SYSTEM_GENERATED', JSOC_ELEMENT.VAR_VALUE("SEARCH_ACC_ACCOUNT_SYSTEM_GENERATED_TXT"));
		}
		
		
		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._ACCOUNT._MEMBER.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_SEARCH_CALLBACK,
			true
		);        		
	}
	
	
	// ===============================================================
	// Request Search - PART.B
	// ===============================================================
	function HTTP_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();
		
		// Validate
		// _______________________________________________________________________
		if(IS_SUCCESS === false)
		{
			alert("CONNECTION ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// Validate JSON Response
		// _______________________________________________________________________
		var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
		if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
		{
			alert("REQUEST ERROR: \n" + RESPONSE_STRING);
			return;
		}
		
		// JSON Empty (Clears the DataGrodView)
		// _______________________________________________________________________
		if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
		{
			MEMBER_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		MEMBER_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				false,
				false,
				1,
				[2, 1]
		);
		
		// For Applying CFormat
		/*
		MEMBER_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				false,
				true,
				1,
				[2, 1]
		);
		*/
		
		// Initialize
		// _______________________________________________________________________	
		var WEBTABLE_DATE = null;
		var ROW_INDEX = 0;
	
	
		// DateTime Format
		// _______________________________________________________________________	

	}
	
	// ===============================================================
	// Begin Processing the Page
	// ===============================================================
	FORM_INITIALIZE();
	FORM_LOAD();