protected void ShowCorrectPanels()
        {
            ButtonRevert.Visible              = true;
            ButtonContinue.Visible            = true;
            ButtonPrintAndProcess.Visible     = false;
            ButtonNewOrder.Visible            = false;
            ButtonDestroyOrderAndBack.Visible = false;
            URLPopUpControlRentOut.Visible    = false;
            URLPopUpControlRentSwap.Visible   = false;

            HideAllPanels();

            switch (CurrentPanelLevel)
            {
            case 1:
                ButtonRevert.Visible             = false;
                PanelCustomerInformation.Visible = true;
                PanelCustomerInformation.Enabled = true;
                break;

            case 2:
                // check if required fields are filled
                if ((DropDownListCustomers.Text != "") && (TextBox_Description.Text != ""))
                {
                    if (LabelCustID.Text != DropDownListCustomers.SelectedValue)
                    {
                        LabelCustID.Text = DropDownListCustomers.SelectedValue;

                        DropDownListCustomerLocations.DataBind();
                        DropDownListProjects.DataBind();
                        DropDownListCustomerFreights.DataBind();

                        URLPopUpControlNewCustomerLocation.URLToPopup = "WebFormPopUp.aspx?uc=CustomerRelationLocationOverview&Id=" + LabelCustID.Text;
                        URLPopUpControlNewCustomerProject.URLToPopup  = "WebFormPopUp.aspx?uc=CustomerRelationProjectOverview&Id=" + LabelCustID.Text;
                    }
                    PanelCustomerInformation.Visible = true;
                    PanelCustomerDetails.Visible     = true;
                    PanelCustomerDetails.Enabled     = true;
                    EntityDataSourceMaterialsContractsAndAgreements.CommandParameters["CustID"].DefaultValue = LabelCustID.Text;
                }
                else
                {
                    CurrentPanelLevel = CurrentPanelLevel - 1;
                    ShowCorrectPanels();
                }
                break;

            case 3:
                WebUserControlEditOrderMaterials1.CustomerID  = new System.Guid(DropDownListCustomers.SelectedValue);
                WebUserControlEditOrderMaterials1.LocationID  = new System.Guid(DropDownListLocations.SelectedValue);
                WebUserControlEditAdvancePayments1.CustomerID = new System.Guid(DropDownListCustomers.SelectedValue);

                if (!DriverAndIdCheckOK())
                {
                    Page.RegisterClientScriptBlock("Alert", "<script>alert('Geef een chauffeur of kenteken op. Eén van deze twee velden is verplicht.');</script>");
                    LabelCurrentPanelLevel.Text = "2";
                    ShowCorrectPanels();
                    break;
                }

                // check if there is a freight to be linked
                LabelFreightGuid.Text = DropDownListCustomerFreights.SelectedValue;

                PanelCustomerInformation.Visible = true;
                PanelCustomerDetails.Visible     = true;
                PanelMaterials.Visible           = true;
                PanelMaterials.Enabled           = true;

                WebUserControlEditOrderMaterials1.LoadOrderLines();
                ButtonContinue.Visible = WebUserControlEditOrderMaterials1.OrderLines.Count > 0;
                break;

            case 4:
                PanelCustomerInformation.Visible = true;
                PanelCustomerDetails.Visible     = true;
                PanelMaterials.Visible           = true;
                PanelTotals.Visible = true;
                PanelTotals.Enabled = true;

                WebUserControlEditAdvancePayments1.LoadAPLines();
                ButtonPrintAndProcess.Visible = !WebUserControlEditAdvancePayments1.CustomerHasOpenAdvancePayments();
                ButtonContinue.Visible        = WebUserControlEditAdvancePayments1.CustomerHasOpenAdvancePayments();

                break;

            case 5:
                ButtonPrintAndProcess.Visible = true;
                ButtonContinue.Visible        = false;

                PanelCustomerInformation.Visible = true;
                PanelCustomerDetails.Visible     = true;
                PanelMaterials.Visible           = true;
                PanelTotals.Visible          = true;
                PanelAdvancePayments.Visible = true;
                PanelAdvancePayments.Enabled = true;

                // check if there are advance payments to correct, otherwise cycle to invoice
                if (!WebUserControlEditAdvancePayments1.CustomerHasOpenAdvancePayments())
                {
                    CurrentPanelLevel = CurrentPanelLevel + 1;
                    ShowCorrectPanels();
                }
                break;

            case 6:
                ButtonRevert.Visible              = false;
                ButtonContinue.Visible            = false;
                ButtonPrintAndProcess.Visible     = false;
                ButtonNewOrder.Visible            = true;
                ButtonDestroyOrderAndBack.Visible = true;

                PanelCustomerInformation.Visible = true;
                PanelCustomerDetails.Visible     = true;
                PanelMaterials.Visible           = true;
                PanelAdvancePayments.Visible     = true;
                PanelTotals.Visible = true;

                FrameShowInvoice.Attributes["src"] = "WebFormPopup.aspx?UC=ShowReport&d=DataSetInvoice&r=ReportInvoiceA4&Id=" + LabelGeneratedInvoiceId.Text.ToString();

                URLPopUpControlRentOut.Visible = true;
                string Identification = TextBox_YourDriverName.Text;
                if ((TextBox_YourTruckPlate.Text != "") && (Identification != ""))
                {
                    Identification = Identification + "/" + TextBox_YourTruckPlate.Text;
                }
                else
                {
                    Identification = TextBox_YourTruckPlate.Text;
                }
                URLPopUpControlRentOut.URLToPopup  = "WebFormPopup.aspx?UC=RentOut&LocId=" + DropDownListLocations.SelectedValue + "&CustId=" + DropDownListCustomers.SelectedValue + "&Identification=" + Identification + "&Description=" + TextBox_Description.Text;
                URLPopUpControlRentSwap.Visible    = true;
                URLPopUpControlRentSwap.URLToPopup = "WebFormPopup.aspx?UC=RentReturn&LocId=" + DropDownListLocations.SelectedValue + "&CustId=" + DropDownListCustomers.SelectedValue;

                //PanelPreviewInvoice.Style["display"] = "";
                PanelPreviewInvoice.Visible = true;
                PanelPreviewInvoice.Enabled = true;

                break;
            }
        }
        public void LoadFromFreight(Freight frg, bool ForceReload)
        {
            if ((LabelFreightGuid.Text != frg.Id.ToString()) || ForceReload)
            {
                ListItem        li  = null;
                FreightWeighing fgw = null;
                if (frg.FreightWeighing.Count > 0)
                {
                    fgw = frg.FreightWeighing.First <FreightWeighing>();
                }

                LabelOrderNr.Text        = frg.OurReference.ToString();
                TextBox_Description.Text = frg.Description;

                if (frg.FreightDirection == "To warehouse")
                {
                    // switch to purchase order
                    SwitchPurchaseType(InvoiceType.Buy);
                }
                else
                {
                    // switch to sales order
                    SwitchPurchaseType(InvoiceType.Sell);
                }

                // first load the customer, this is required for Freights
                DropDownListCustomers.DataBind();
                li = DropDownListCustomers.Items.FindByValue(frg.FromRelation.Id.ToString());
                if (li != null)
                {
                    li.Selected      = true;
                    LabelCustID.Text = li.Value;
                }

                DropDownListLocations.DataBind();
                li = DropDownListLocations.Items.FindByValue(frg.SourceOrDestinationLocation.Id.ToString());
                if (li != null)
                {
                    li.Selected = true;
                }

                DropDownListCustomerFreights.DataBind();
                li = DropDownListCustomerFreights.Items.FindByValue(frg.Id.ToString());
                if (li != null)
                {
                    li.Selected = true;
                    DropDownListCustomerFreights.SelectedIndex = DropDownListCustomerFreights.Items.IndexOf(li);
                }

                TextBox_YourTruckPlate.Text = frg.YourTruckPlate;
                TextBox_YourDriverName.Text = frg.YourDriverName;

                if (fgw != null)
                {
                    TextBoxFreightID.Text = fgw.Description;
                }

                WebUserControlEditOrderMaterials1.LoadFromFreight(frg);

                LabelFreightGuid.Text = frg.Id.ToString();
            }
        }