// NOTE: [This JS must loaded as last item]
	var CACHE_ARRAY_SHIFT_ID = null;
	var CACHE_ARRAY_SHIFT_DESCRIPTION = null;
	var CACHE_ARRAY_SHIFT_START = null;
	var CACHE_ARRAY_SHIFT_END = null;
	
	// ===============================================================
	// Initialize Form
	// ===============================================================
	function FORM_LOAD()
	{
		// Initialize
		// _______________________________________________________________________		
		
		// Show Progress
		// _______________________________________________________________________	
		//SOC_DIALOG.VAR_LOADING_SPINNER(true);
		
		
		// Requires Authentication
		// _______________________________________________________________________	
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_PRELOAD_DATA);	
	}


	// ===============================================================
	// Preload Data
	// ===============================================================

	function HTTP_PRELOAD_DATA(IS_SUCCESS, HTTP_RESPONSE)
	{
		// Disable Dialogs
		CUS_SEND_DIALOG_TRY_DISMISS();
			
		// Handle Error
		if(IS_SUCCESS === false)
		{
			alert("Unable to load data.");
		}
		else
		{						
			if(JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID > 0)
			{
				HTTP_PRELOAD_SHIFT();
			}
							
			PRELOAD_POS_SHIFT
			(
				function(IS_SUCCESS, RESPONSE)
				{
					CUS_SEND_DIALOG_TRY_DISMISS();
					if(IS_SUCCESS)
					{
						if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("DEVICE_ID_LBL")) 
						{
							JSOC_ELEMENT.VAR_VALUE('DEVICE_ID_LBL', JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID);
						}
					}
				}
			);
		}
	};


	function HTTP_PRELOAD_SHIFT()
	{
		// Actual Function
		// _______________________________________________________________________
		GET_MAP_ARRAY = JSCUS_SQL._RECORD._POS_SHIFT.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();			
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_SHIFT_ACC_GROUP_ID', JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ACC_GROUP_ID);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_SHIFT_ACC_DEVICE_ID', JSCUS_SQL._RECORD._POSDEVICE._LOGIN.REC_POSDEVICE_ID);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_SHIFT_ACC_ACCOUNT_ID', JSCUS_SQL._ACCOUNT._LOGIN.ACC_ACCOUNT_ID);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_SHIFT_STATUS', 0);
		
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_FIELD', 'REC_SHIFT_TIME_BEGIN');
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_ORDER_TYPE', 'DESC');
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_LIMIT', 10);				

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._POS_SHIFT.CUS_GET
		(
			GET_MAP_ARRAY,
			function(IS_SUCCESS, RESPONSE_STRING)
			{
				// Disable Dialogs
				// _______________________________________________________________________
				CUS_SEND_DIALOG_TRY_DISMISS();
				
				// Validate
				// _______________________________________________________________________
				if(IS_SUCCESS === false)
				{
					console.error("CONNECTION ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// Validate JSON Response
				// _______________________________________________________________________
				var JSON_OBJECT = JSRC_JSON.REF_CREATE(RESPONSE_STRING);
				if(JSRC_JSON.REF_IS_SUCCESS(JSON_OBJECT) === false)
				{
					console.error("REQUEST ERROR: \n" + RESPONSE_STRING);
					return;
				}
				
				// JSON Empty (Clears the DataGrodView)
				// _______________________________________________________________________
				if(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT") <= 0)
				{
					return;
				}		
				
				
				// Populate Shift Array
				// _______________________________________________________________________
				var JSON_COUNT = JSVC_NUM.VAR_NVALL(JSRC_JSON.REF_READ(JSON_OBJECT, "JSON_COUNT"));
				var JSON_INDEX = 1;
				var BEGIN_DATE = null;
				var END_DATE = null;
				
				CACHE_ARRAY_SHIFT_ID = [];
				CACHE_ARRAY_SHIFT_DESCRIPTION = [];
				CACHE_ARRAY_SHIFT_START = [];
				CACHE_ARRAY_SHIFT_END = [];
		
				while(JSON_COUNT >= JSON_INDEX)
				{
					
					if(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_SHIFT_STATUS", JSON_INDEX) == '2')
					{
						CACHE_ARRAY_SHIFT_ID.unshift('-1');
						CACHE_ARRAY_SHIFT_DESCRIPTION.unshift('Current Shift');
						CACHE_ARRAY_SHIFT_START.unshift(null);
						CACHE_ARRAY_SHIFT_END.unshift(null);
					}
					else
					{	
						BEGIN_DATE = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_SHIFT_TIME_BEGIN", JSON_INDEX);
						END_DATE = JSRC_JSON.REF_READ(JSON_OBJECT, "REC_SHIFT_TIME_END", JSON_INDEX);			
						BEGIN_DATE = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(BEGIN_DATE), "MMM DD, YYYY hh:mm TT");
						END_DATE = JSVC_DATE.VAR_FORMAT(JSVC_DATE.VAR_TO_DATE(END_DATE), "MMM DD, YYYY hh:mm TT");

						CACHE_ARRAY_SHIFT_ID.push(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_SHIFT_ID", JSON_INDEX));
						CACHE_ARRAY_SHIFT_DESCRIPTION.push(BEGIN_DATE + ' ~ ' + END_DATE);
						CACHE_ARRAY_SHIFT_START.push(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_SHIFT_TIME_BEGIN", JSON_INDEX));
						CACHE_ARRAY_SHIFT_END.push(JSRC_JSON.REF_READ(JSON_OBJECT, "REC_SHIFT_TIME_END", JSON_INDEX));
					}
					
					JSON_INDEX ++;
				}		
			},
			true
		); 				
	};
		
	// ===============================================================
	// Begin Processing the Page
	// ===============================================================
	FORM_INITIALIZE();
	FORM_LOAD();