/// <summary>
    /// Initialize the edit form for a new flight (blank fields) or for editing of an existing flight
    /// </summary>
    /// <param name="idFlight">-1 for a new flight, otherwise the ID of the flight to load</param>
    /// <param name="fForceLoad">True to force load (e.g., an admin mode, or CFI editing a user's flight)</param>
    public void SetUpNewOrEdit(int idFlight, bool fForceLoad = false)
    {
        LogbookEntry le = new LogbookEntry()
        {
            User = Page.User.Identity.Name
        };

        InitBasicControls();

        // Initialize our logbook entry from the db or make it a new entry
        bool fAdminMode = (CurrentUser.CanSupport && (util.GetStringParam(Request, "a").Length > 0));

        IsAdmin = fForceLoad || fAdminMode;

        FlightID = idFlight;

        if (!le.FLoadFromDB(FlightID, Page.User.Identity.Name, LogbookEntry.LoadTelemetryOption.LoadAll, IsAdmin))
        {
            // if this isn't found, try again with a new flight (but tell the user of the error)
            lblError.Text = le.ErrorString;
            FlightID      = (le = new LogbookEntry()
            {
                User = Page.User.Identity.Name
            }).FlightID;
        }

        // check for CFI signing mode
        if (fForceLoad && !le.IsNewFlight)
        {
            if (le.User.CompareOrdinal(Page.User.Identity.Name) != 0 && le.CanEditThisFlight(Page.User.Identity.Name))
            {
                pnlPublic.Visible = pnlPictures.Visible = false;
                FlightUser        = le.User; // save the name of the owner of the flight.
            }
            else
            {
                throw new MyFlightbookException(String.Format(CultureInfo.InvariantCulture, "attempt by {0} to edit non-owned flight (owned by {1}) by non-instructor!", Page.User.Identity.Name, le.User));
            }
        }

        // Enable Admin Signature fix-up
        if (!le.IsNewFlight && le.CFISignatureState != LogbookEntryBase.SignatureState.None)
        {
            lblSigSavedHash.Text   = le.DecryptedFlightHash;
            lblSigCurrentHash.Text = le.DecryptedCurrentHash;

            if (le.CFISignatureState == LogbookEntry.SignatureState.Invalid)
            {
                pnlSigEdits.Visible = true;
                LogbookEntry leNew   = LogbookEntry.LogbookEntryFromHash(lblSigCurrentHash.Text);
                LogbookEntry leSaved = LogbookEntry.LogbookEntryFromHash(lblSigSavedHash.Text);
                rptDiffs.DataSource = leSaved.CompareTo(leNew, CurrentUser.UsesHHMM);
                rptDiffs.DataBind();
            }

            if (fAdminMode)
            {
                LogbookEntry.SignatureSanityCheckState sscs = le.AdminSignatureSanityCheckState;
                pnlAdminFixSignature.Visible = true;
                lblSigSavedState.Text        = le.CFISignatureState.ToString();
                lblSigSanityCheck.Text       = sscs.ToString();
            }
        }

        // If the user has entered another flight this session, default to that date rather than today
        if (Session[keyLastEntryDate] != null && FlightID == LogbookEntry.idFlightNew)
        {
            le.Date = (DateTime)Session[keyLastEntryDate];
        }

        // see if we have a pending in-progress flight
        if (FlightID == LogbookEntry.idFlightNew && Session[keySessionInProgress] != null)
        {
            le = (LogbookEntry)Session[keySessionInProgress];
        }
        Session[keySessionInProgress] = null; // clear it out regardless.

        UseLastTail = true;

        // If a repeat or a reverse is requested, then clone and/or reverse it.
        le = CloneOrReverse(le);

        // If this is a shared flight, initialize from that.
        le = SharedFlight(le);

        // If we're setting up a new flight and last flight had an ending hobbs, initialize with that
        // clear the cookie, if present, regardless.
        HttpCookie c = Request.Cookies[keyCookieLastEndingHobbs];

        if (c != null)
        {
            if (le.IsNewFlight)
            {
                decimal hobbsEnd;
                if (decimal.TryParse(c.Value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out hobbsEnd))
                {
                    le.HobbsStart = hobbsEnd;
                }
            }
            Response.Cookies[keyCookieLastEndingHobbs].Expires = DateTime.Now.AddDays(-1);   // clear it.
        }

        SetUpAircraftForFlight(le);

        InitFormFromLogbookEntry(le);

        bool fCanDoVideo = EarnedGrauity.UserQualifies(Page.User.Identity.Name, Gratuity.GratuityTypes.Videos);

        mfbMFUFlightImages.IncludeVideos = fCanDoVideo;
        mfbVideoEntry1.CanAddVideos      = fCanDoVideo;
        mfbVideoEntry1.FlightID          = le.FlightID;
        lblPixForFlight.Text             = fCanDoVideo ? Resources.LogbookEntry.HeaderImagesVideosForFlight : Resources.LogbookEntry.HeaderImagesForFlight;

        FinalizeSetupForFlight(le);

        mfbDate.Focus();
    }