

	function FORM_LOAD()
	{
		// Initialize
		// _______________________________________________________________________	
		var DGV_ELEMENT_CHILD = null;
		var DGV_ELEMENT_CHILD_INDEX = 0;
		
		
		// Load DataGridVuew
		// _______________________________________________________________________	
		JOB_ORDER_DGV = DataGridView("JOB_ORDER_DGV");
		JOB_ORDER_TASK_DGV = DataGridView("JOB_ORDER_TASK_DGV");

		//JOB_ORDER_DGV.SETTING_ALLOW_USER_TO_ADD_ROWS = true;
		//JOB_ORDER_DGV.SETTING_EDITABLE = true;
		JOB_ORDER_DGV.ON_CLICK
		(			
			function(COL_INDEX, ROW_INDEX)
			{
				// If dialog supported
				// ...........................................
				if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("JOB_ORDER_MODAL") == true)
				{
					// Clear Modal
					

					// Display Modal
					PROPERTY_REC_JORDER_ID = JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_ID', ROW_INDEX);
					PROPERTY_REC_JORDER_CODE = JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_REFERENCE_NUMBER', ROW_INDEX);
					PROPERTY_EDIT_ROW_INDEX = ROW_INDEX;
					
					JSOC_DIALOG.VAR_MODAL("JOB_ORDER_MODAL", true);

					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_CODE_LBL", PROPERTY_REC_JORDER_CODE);
					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_REC_CLIENT_LBL", ': ' + JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_LASTNAME', ROW_INDEX));
					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_REC_CONTACT_LBL", ': ' + JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_CONTACT', ROW_INDEX));
					JSOC_ELEMENT.VAR_VALUE("REC_JORDER_REC_ADDRESS_LBL", ': ' + JOB_ORDER_DGV.CELL.VALUE('REC_CLIENT_MIDDLENAME', ROW_INDEX));

					JSOC_ELEMENT.VAR_VALUE("TOTAL_AMOUNT", JSVC_NUM.VAR_CFORMAT(JOB_ORDER_DGV.CELL.VALUE('REC_JORDER_AMOUNT', ROW_INDEX)));
					
					HTTP_LOAD();
					return;
				}
			}
		); 

		// Requires Authentication
		// _______________________________________________________________________
		PAGE_AUTH_REQUIRES_LOGIN(HTTP_POPULATE_RESULT);

		// Load CMB
		// _______________________________________________________________________
		if(JSOC_ELEMENT.VAR_ELEMENT_EXISTS("SEARCH_ACC_GROUP_ID_CMB") == true)
		{
			JSOC_CMB.VAR_CLEAR("SEARCH_ACC_GROUP_ID_CMB");
			JSOC_CMB.VAR_ADD("SEARCH_ACC_GROUP_ID_CMB", FLAG_BIGINT_NULL.toString(),"Any Branch");

			JSCUS_SQL._ACCOUNT._GROUP.CUS_GET_THEN_POPULATE_COMBOBOX
			(
				function(){ HTTP_POPULATE_RESULT(); },
				"SEARCH_ACC_GROUP_ID_CMB",
				true,
				2 
			);
		}

		// 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();
			}
		}
	};

	function HTTP_SEARCH()
	{
		var GET_MAP_ARRAY = JSCUS_SQL._RECORD._JOB_ORDER.CUS_PREPARE_MAPPED_ARRAY_FOR_GET();

		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_ACC_GROUP_ID', JSVC_NUM.VAR_NVALL(JSOC_CMB.VAR_SELECTED_VALUE(SEARCH_ACC_GROUP_ID_CMB)));
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_STATUS', 2);
		JSVC_MAP_ARRAY.VAR_SET(GET_MAP_ARRAY, 'PARAM_REC_JORDER_USER_ASSIGN', 1);

		JSOC_DIALOG.VAR_LOADING_SPINNER(true);
		JSCUS_SQL._RECORD._JOB_ORDER.CUS_GET
		(
			GET_MAP_ARRAY,
			HTTP_SEARCH_CALLBACK,
			true
		);
	}

	function HTTP_SEARCH_CALLBACK(IS_SUCCESS, RESPONSE_STRING)
	{
		// Disable Dialogs
		// _______________________________________________________________________
		CUS_SEND_DIALOG_TRY_DISMISS();

		//RESET DGV
		// _______________________________________________________________________
		JOB_ORDER_DGV.ROW.CLEAR();
		
		// 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)
		{
			JOB_ORDER_DGV.ROW.CLEAR();
			return;
		}

		// Populate DGV
		// _______________________________________________________________________
		JOB_ORDER_DGV.POPULATE_FROM_QUERY
		(
				JSON_OBJECT, 
				'',
				false,
				false,
				1,
				[2, 1]
		);
	}

	FORM_INITIALIZE();
	FORM_LOAD();