/*Generated on:Wed Nov 28 2018 13:35:31 GMT+0100 (CET)*/
function includesString(string1, string2) {
    return string1.toLowerCase().includes(string2.toLowerCase());
}

async function ADisSettings(key) {
    var res;
    await ADisDB.ADisSettings.each((setting) => {
        if (setting.name == key) {
            res = setting.value;
        }
    });
    return res;
}

//=require ../node_modules/dexie/dist/dexie.js

// Create own MDisDB to use it later
//=require ../script/dexie_db.js

ADisDB.on("ready", () => {

    if (window.location.pathname === "/" || window.location.pathname === "/#") {

        // Get all available missions with there config
        $.getJSON("https://raw.josef-froehle.de/Dexus/automatic-dispose/master/all_missions.json", function (Response) {
            for (let i in Response) {
                ADis_AddAvailableMissions(Response[i]);
            }
        });

        function ADis_AddAvailableMissions(Mission) {
            return ADisDB.ADisAvailabelMissions.put({
                missionID: Mission.id,
                type: Mission.type,
                name: Mission.name,
                jsondata: Mission
            }).catch((err) => {
                console.error(err)
            })
        }
    }

    if (window.location.pathname.indexOf("/missions/") !== -1) {

        var MissionID;
        var MissionType;
        var MissionConfig;
        var CurrentTime;

        var MaxVehicleID = 86;

        $(document).ready(function () {
            setTimeout(function () {
                MissionID = document.location.pathname.substr(document.location.pathname.lastIndexOf("/") + 1);
                var help_el = $('a#mission_help');
                if (help_el.length > 0) {
                    MissionType = help_el[0].href.split("?")[0];
                    var re = /\d+$/i;
                    var found = MissionType.match(re);
                    MissionType = Number(found[0]);
                }
                CurrentTime = Math.floor(new Date().getTime() / 1000);
                console.log("MissionID", MissionID);
                console.log("MissionType", MissionType);
                console.log("CurrentTime", CurrentTime);
                if (MissionType !== null) {
                    ADis_CheckMissionAutomatic();
                }
            }, 150);
        });

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Grab Run Verbands Missions
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        function ADis_WorkVerbandMission() {
            ADisSettings('Alliance-Automatic').then((setting) => {
                var title = document.getElementById('missionH1');
                var isVerband = title.innerText.toLowerCase().includes("[verband]");
                if (setting && isVerband) {
                    if ($('#vehicle_show_table_all tr[vehicle_type="FuStW"] input[type="checkbox"]').size() > 0) {
                        $('#vehicle_show_table_all tr[vehicle_type="FuStW"] input[type="checkbox"]')[0].click();
                    } else if ($('#vehicle_show_table_all tr[vehicle_type="KTW Typ B"] input[type="checkbox"]').size() > 0) {
                        $('#vehicle_show_table_all tr[vehicle_type="KTW Typ B"] input[type="checkbox"]')[0].click();
                    }
                    if ($('#vehicle_show_table_all input[type="checkbox"]:checked').size() > 0) {
                        $('#mission_alarm_btn').click();
                    }
                }
            });
        }

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Grab Mission-Configuration from GitHub
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        function ADis_CheckMissionAutomatic() {

            if (MissionType != null) {
                AD_GetMissionConfiguration(MissionType);
            }

        }

        function AD_GetMissionConfiguration(MissionType) {
            return ADisDB.transaction('rw', [ADisDB.ADisMissionsOwn, ADisDB.ADisSettings, ADisDB.ADisAvailabelMissions], () => {
                return ADisDB.ADisAvailabelMissions.get({
                    type: MissionType.toString()
                }).then((availableMission) => {
                    console.log(availableMission);
                    if (availableMission != undefined && availableMission.jsondata) {
                        MissionConfig = availableMission.jsondata;
                        AD_StartAlarmProcess();
                    } else {
                        // var updateData = {
                        //     available: false,
                        //     next_check: CurrentTime + 60
                        // };
                        // ADis_UpdateOwnMissionsToDone(MissionID, updateData);
                    }
                });
            });

        }

        function AD_StartAlarmProcess() {
            console.log("  Automatic Dispose: Starte Alarmierungsprozess");


            setTimeout(function () // Process Fire Department
                {
                    Promise.resolve().then(async () => {
                            return await ADis_PrepareVehicleNeedList();
                        }).then(async () => {
                            return await ADis_CollectInvolvedVehicles();
                        }).then(async () => {
                            return await ADis_CollectPatients();
                        })
                        .then(async () => {
                            return await Promise.all([
                                ADis_ProcessEmergencyMedicalService(),
                                ADis_ProcessFireDepartment(),
                                ADis_ProcessPoliceDepartment(),
                                ADis_ProcessTechnicalEmergencyService(),
                                ADis_ProcessWaterRescue(),
                            ]).then((result) => {
                                var updateData = {
                                    last_check: CurrentTime,
                                    next_check: CurrentTime + 60
                                };
                                //ADis_UpdateOwnMissionsToDone(MissionID, updateData);
                                if (['adis-ownmissions', 'adis-krankentransporte', 'adis-verbandmission'].indexOf(window.name) != -1) {
                                    setTimeout(() => {
                                        $('#mission_alarm_btn').click();
                                    }, 250);
                                }
                            })
                        });

                }, 250);
        }

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Collect Involved Vehicles & Patients
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        var AD_Vehicles = {};
        var AD_Patients = {};

        function ADis_CollectInvolvedVehicles() {
            $("#mission_vehicle_driving tbody").find("tr").each(function () {
                var VehicleID = $(this).find("a").first().attr("href").substr($(this).find("a").first().attr("href").lastIndexOf("/") + 1);
                var VehicleName = $(this).find("a").first().text();
                var VehicleType = $(this).find("a").first().attr("vehicle_type_id");

                AD_Vehicles[VehicleID] = {
                    "id": VehicleID,
                    "name": VehicleName,
                    "type": VehicleType
                }
            });

            $("#mission_vehicle_at_mission tbody").find("tr").each(function () {
                var VehicleID = $(this).find("a").first().attr("href").substr($(this).find("a").first().attr("href").lastIndexOf("/") + 1);
                var VehicleName = $(this).find("a").first().text();
                var VehicleType = $(this).find("a").first().attr("vehicle_type_id");

                AD_Vehicles[VehicleID] = {
                    "id": VehicleID,
                    "name": VehicleName,
                    "type": VehicleType
                }
            });

            console.log("  Automatic Dispose: Bereits beteiligte Fahrzeuge:");
            console.log(AD_Vehicles);
            return AD_Vehicles;
        }

        function ADis_CollectPatients() {
            var PatientCounter = 0;

            $(".mission_patient").each(function () {
                var PatientName = $(this).text();
                var PatientNeedRTW = false;
                var PatientNeedNEF = false;
                var PatientNeedRTH = false;
                var PatientNeedLNA = false;
                var PatientNeedOrgL = false;
                var PatientNeedSEGKTWB = false;
                var PatientNeedTragehilfe = false;

                // Wir benötigen einen RTW oder KTW Typ B.
                if ($(this).find(".alert-danger").length > 0 && $(this).find(".alert-danger").text().indexOf("Wir benötigen einen RTW oder KTW Typ B") != -1) {
                    PatientNeedSEGKTWB = true;
                }

                // Wir benötigen einen RTW.
                if ($(this).find(".alert-danger").length > 0 && $(this).find(".alert-danger").text().indexOf("Wir benötigen ein RTW") != -1) {
                    PatientNeedRTW = true;
                }

                // Wir benötigen einen NEF.
                if ($(this).find(".alert-danger").length > 0 && $(this).find(".alert-danger").text().indexOf("Wir benötigen ein NEF") != -1) {
                    PatientNeedNEF = true;
                }

                // Wir benötigen einen RTH.
                if ($(this).find(".alert-danger").length > 0 && $(this).find(".alert-danger").text().indexOf("Wir benötigen ein RTH") != -1) {
                    PatientNeedRTH = true;
                }

                // Wir benötigen einen LNA.
                if ($(this).find(".alert-danger").length > 0 && $(this).find(".alert-danger").text().indexOf("Wir benötigen einen LNA") != -1) {
                    PatientNeedLNA = true;
                }

                // Wir benötigen einen OrgL.
                if ($(this).find(".alert-danger").length > 0 && $(this).find(".alert-danger").text().indexOf("Wir benötigen einen OrgL") != -1) {
                    PatientNeedOrgL = true;
                }

                // Wir benötigen eine Tragehilfe (z.B. durch ein LF).
                if ($(this).find(".alert-danger").length > 0 && $(this).find(".alert-danger").text().indexOf("Wir benötigen eine Tragehilfe") != -1) {
                    PatientNeedTragehilfe = true;
                }

                AD_Patients[PatientCounter] = {
                    "name": PatientName,
                    "need_RTW": PatientNeedRTW,
                    "need_NEF": PatientNeedNEF,
                    "need_RTH": PatientNeedRTH,
                    "need_LNA": PatientNeedLNA,
                    "need_OrgL": PatientNeedOrgL,
                    "need_SEG_KTWB": PatientNeedSEGKTWB,
                    "need_Tragehilfe": PatientNeedTragehilfe
                }

                PatientCounter++;
            });

            console.log("  Automatic Dispose: Patientenliste:");
            console.log(AD_Patients);
            return AD_Patients;
        }

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Process Emergency_Medical_Service
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        function ADis_ProcessEmergencyMedicalService() {

            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
            //      -
            //      -               Emergency Medical Service: Vehicles
            //      -
            //      -                   38:     KTW
            //      -                   28:     RTW
            //      -                   29:     NEF
            //      -                   74:     NAW
            //      -                   73:     GRTW
            //      -                   31:     RTH
            //      -                   55:     LNA
            //      -                   56:     OrgL
            //      -
            //      -                   58:     (SEG) KTW Typ B
            //      -                   59:     (SEG) ELW 1
            //      -                   60:     (SEG) GW-San
            //      -
            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

            if (typeof MissionConfig.emergency_medical_service == "object") // Wenn der EMS-Block in der Config definiert ist
            {
                if (Object.keys(AD_Patients).length >= 5) { // need LNA
                    ADis_VehiclesNeed["55"]++;
                }

                if (Object.keys(AD_Patients).length >= 10) { // need OrgL
                    ADis_VehiclesNeed["56"]++;
                }

                //$.each(AD_Patients, function (Key, Patient) {
                for (var Key in AD_Patients) {
                    var Patient = AD_Patients[Key];
                    if (MissionConfig.emergency_medical_service.use_KTW == true) {
                        if (!Patient.need_RTW && !Patient.need_NEF && !Patient.need_RTH)
                            ADis_VehiclesNeed["38"]++;
                    }

                    if (Patient.need_LNA && ADis_VehiclesNeed["55"] < 1)
                        ADis_VehiclesNeed["55"]++;

                    if (Patient.need_OrgL && ADis_VehiclesNeed["56"] < 1)
                        ADis_VehiclesNeed["56"]++;

                    if (Patient.need_Tragehilfe == true)
                        ADis_VehiclesNeed["0"]++;

                    if (MissionConfig.emergency_medical_service.use_RTW == true)
                        ADis_VehiclesNeed["28"]++;

                    if (MissionConfig.emergency_medical_service.use_NEF == true)
                        ADis_VehiclesNeed["29"]++;

                    if (MissionConfig.emergency_medical_service.use_RTH == true)
                        ADis_VehiclesNeed["31"]++;
                };

                // TODO: need to be refactored to make sure first KTW Typ B before RTW.
                if (MissionConfig.emergency_medical_service.use_SEG_ELW1_Only == "true") {
                    ADis_VehiclesNeed["59"]++;
                } else if (MissionConfig.emergency_medical_service.use_SEG_FULL == "true" || Object.keys(AD_Patients).length >= 3) {
                    ADis_VehiclesNeed["58"]++;
                    ADis_VehiclesNeed["58"]++; // 3x KTW Type B
                    ADis_VehiclesNeed["58"]++;
                    ADis_VehiclesNeed["59"]++;
                    ADis_VehiclesNeed["60"]++;
                }

                var VehicleTable;

                if ($("#vehicle_show_table_body_all").length > 0) {
                    VehicleTable = $("#vehicle_show_table_body_all");
                } else {
                    VehicleTable = $("#vehicle_show_table_body_rett");
                }

                VehicleTable.find(".vehicle_select_table_tr").each(function () {
                    try {
                        var VehicleID = $(this).attr("id").replace("vehicle_element_content_", "");
                        var VehicleType = $(this).attr("vehicle_type");
                        // var VehicleDistanceTime = $("#vehicle_sort_" + VehicleID).attr("sortvalue");
                    } catch (e) {
                        console.error("MOP ", e)
                    }
                    if (VehicleType == "KTW" && ADis_VehiclesNeed["38"] > 0) {
                        // console.log("  Automatic Dispose: Fahrzeug " + VehicleID + " " + $(this).attr("vehicle_type") + " markiert");
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["38"]--;
                    } else if ((VehicleType == "LF 20" || VehicleType == "LF 10" ||
                            VehicleType == "LF 8/6" || VehicleType == "LF 20/16" ||
                            VehicleType == "LF 10/6" || VehicleType == "LF 16-TS" ||
                            VehicleType == "HLF 20" || VehicleType == "TSF-W" ||
                            VehicleType == "TLF 2000" || VehicleType == "TLF 3000" ||
                            VehicleType == "TLF 8/8" || VehicleType == "TLF 8/18" ||
                            VehicleType == "TLF 16/24-Tr" || VehicleType == "TLF 16/25" ||
                            VehicleType == "TLF 16/45" || VehicleType == "TLF 20/40" ||
                            VehicleType == "TLF 20/40-SL" || VehicleType == "TLF 16") &&
                        ADis_VehiclesNeed["0"] + ADis_VehiclesNeed["1"] + ADis_VehiclesNeed["6"] + ADis_VehiclesNeed["7"] +
                        ADis_VehiclesNeed["8"] + ADis_VehiclesNeed["9"] + ADis_VehiclesNeed["30"] + ADis_VehiclesNeed["37"] +
                        ADis_VehiclesNeed["17"] + ADis_VehiclesNeed["18"] + ADis_VehiclesNeed["19"] + ADis_VehiclesNeed["20"] +
                        ADis_VehiclesNeed["21"] + ADis_VehiclesNeed["22"] + ADis_VehiclesNeed["23"] + ADis_VehiclesNeed["24"] +
                        ADis_VehiclesNeed["25"] + ADis_VehiclesNeed["26"] > 0) { // LF acts as 'Tragehilfe'
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["0"]--;
                    } else if (VehicleType == "NAW" && ADis_VehiclesNeed["28"] > 0 && ADis_VehiclesNeed["29"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["74"]--;
                        ADis_VehiclesNeed["28"]--;
                        ADis_VehiclesNeed["29"]--;
                    } else if (VehicleType == "GRTW" && ADis_VehiclesNeed["73"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["73"]--;
                    } else if (VehicleType == "RTW" && ADis_VehiclesNeed["28"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["28"]--;
                    } else if (VehicleType == "NEF" && ADis_VehiclesNeed["29"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["29"]--;
                    } else if (VehicleType == "RTH" && ADis_VehiclesNeed["31"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["31"]--;
                    } else if (VehicleType == "KdoW-LNA" && ADis_VehiclesNeed["55"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["55"]--;
                    } else if (VehicleType == "KdoW-OrgL" && ADis_VehiclesNeed["56"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["56"]--;
                    } else if (VehicleType == "KTW Typ B" && ADis_VehiclesNeed["58"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["58"]--;
                        ADis_VehiclesNeed["28"]--; // no need for RTW if KTW Type B is called
                    } else if (VehicleType == "ELW 1 (SEG)" && ADis_VehiclesNeed["59"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["59"]--;
                    } else if (VehicleType == "GW-San" && ADis_VehiclesNeed["60"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["60"]--;
                        ADis_VehiclesNeed["29"]--; // no need for NEF if GW-SAN is called
                        ADis_VehiclesNeed["29"]--; // no need for NEF if GW-SAN is called
                    }
                });
                return true;
            }
            return false;
        }

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Process Fire_Department
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        function ADis_ProcessFireDepartment() {

            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
            //      -
            //      -               Fire Department: Vehicles
            //      -
            //      -                    0:     LF 20
            //      -                    1:     LF 10
            //      -                    6:     LF 8/6
            //      -                    7:     LF 20/16
            //      -                    8:     LF 10/6
            //      -                    9:     LF 16-TS
            //      -                   30:     HLF 20
            //      -                   37:     TSF-W
            //      -
            //      -                   17:     TLF 2000
            //      -                   18:     TLF 3000
            //      -                   19:     TLF 8/8
            //      -                   20:     TLF 8/18
            //      -                   21:     TLF 16/24-Tr
            //      -                   22:     TLF 16/25
            //      -                   23:     TLF 16/45
            //      -                   24:     TLF 20/40
            //      -                   25:     TLF 20/40-SL
            //      -                   26:     TLF 16
            //      -
            //      -                    2:     DLK 23
            //      -                    3:     ELW 1
            //      -                   34:     ELW 2
            //      -                   36:     MTW
            //      -                   57:     FwK
            //      -
            //      -                    4:     RW
            //      -                    5:     GW-A
            //      -                   10:     GW-Öl
            //      -                   12:     GW-Mess
            //      -                   53:     GW-Dekon-P
            //      -                   27:     GW-Gefahrgut
            //      -                   33:     GW-Höhenrettung
            //      -
            //      -                   11:     GW-L2-Wasser
            //      -                   13:     SW 1000
            //      -                   14:     SW 2000
            //      -                   15:     SW 2000-Tr
            //      -                   16:     SW KatS
            //      -
            //      -                   71:     AB-MZB (see WaterRescue)
            //      -
            //      -                   46:     WLF
            //      -                   47:     AB-Rüst
            //      -                   48:     AB-Atemschutz
            //      -                   49:     AB-Öl
            //      -                   54:     AB-Dekon-P
            //      -                   62:     AB-Schlauch
            //      - 
            //      -                   75:     FLF
            //      -                   76:     Rettungstreppe
            //      -                   77:     AB-Gefahrgut
            //      -                   78:     AB-Einsatzleitung
            //      - 
            //      -                   83:     GW-Werkfeuerwehr
            //      -                   84:     ULF mit Löscharm
            //      -                   85:     TM 50
            //      -                   86:     Turbolöscher
            //      -
            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

            if (typeof MissionConfig.fire_department == "object") // Wenn der FD-Block in der Config definiert ist
            {
                console.log(ADis_VehiclesNeed);

                ADis_VehiclesNeed["0"] += parseInt(MissionConfig.fire_department.num_LF);
                ADis_VehiclesNeed["3"] += parseInt(MissionConfig.fire_department.num_ELW_1);
                ADis_VehiclesNeed["34"] += parseInt(MissionConfig.fire_department.num_ELW_2);
                ADis_VehiclesNeed["2"] += parseInt(MissionConfig.fire_department.num_DLK);
                ADis_VehiclesNeed["4"] += parseInt(MissionConfig.fire_department.num_RW);
                ADis_VehiclesNeed["57"] += parseInt(MissionConfig.fire_department.num_FwK);
                ADis_VehiclesNeed["5"] += parseInt(MissionConfig.fire_department.num_GW_A);
                ADis_VehiclesNeed["27"] += parseInt(MissionConfig.fire_department.num_GW_G);
                ADis_VehiclesNeed["10"] += parseInt(MissionConfig.fire_department.num_GW_Oel);
                ADis_VehiclesNeed["12"] += parseInt(MissionConfig.fire_department.num_GW_Mess);
                ADis_VehiclesNeed["11"] += parseInt(MissionConfig.fire_department.num_SW);
                ADis_VehiclesNeed["33"] += parseInt(MissionConfig.fire_department.num_GW_Hoeh);
                ADis_VehiclesNeed["53"] += parseInt(MissionConfig.fire_department.num_Dekon_P);
                ADis_VehiclesNeed["75"] += parseInt(MissionConfig.fire_department.num_FLF);
                ADis_VehiclesNeed["76"] += parseInt(MissionConfig.fire_department.num_Rettungstreppe);
                ADis_VehiclesNeed["83"] += parseInt(MissionConfig.fire_department.num_GW_Werkfeuerwehr);
                ADis_VehiclesNeed["84"] += parseInt(MissionConfig.fire_department.num_ULF_mit_Loescharm);
                ADis_VehiclesNeed["86"] += parseInt(MissionConfig.fire_department.num_Turboloescher);

                $("#vehicle_show_table_body_all").find(".vehicle_select_table_tr").each(function () {
                    var VehicleID = $(this).attr("id").replace("vehicle_element_content_", "");
                    var VehicleType = $(this).attr("vehicle_type");
                    var VehicleDistanceTime = $("#vehicle_sort_" + VehicleID).attr("sortvalue");

                    if ((VehicleType == "LF 20" || VehicleType == "LF 10" ||
                            VehicleType == "LF 8/6" || VehicleType == "LF 20/16" ||
                            VehicleType == "LF 10/6" || VehicleType == "LF 16-TS" ||
                            VehicleType == "HLF 20" || VehicleType == "TSF-W" ||
                            VehicleType == "TLF 2000" || VehicleType == "TLF 3000" ||
                            VehicleType == "TLF 8/8" || VehicleType == "TLF 8/18" ||
                            VehicleType == "TLF 16/24-Tr" || VehicleType == "TLF 16/25" ||
                            VehicleType == "TLF 16/45" || VehicleType == "TLF 20/40" ||
                            VehicleType == "TLF 20/40-SL" || VehicleType == "TLF 16") &&
                        ADis_VehiclesNeed["0"] + ADis_VehiclesNeed["1"] + ADis_VehiclesNeed["6"] + ADis_VehiclesNeed["7"] +
                        ADis_VehiclesNeed["8"] + ADis_VehiclesNeed["9"] + ADis_VehiclesNeed["30"] + ADis_VehiclesNeed["37"] +
                        ADis_VehiclesNeed["17"] + ADis_VehiclesNeed["18"] + ADis_VehiclesNeed["19"] + ADis_VehiclesNeed["20"] +
                        ADis_VehiclesNeed["21"] + ADis_VehiclesNeed["22"] + ADis_VehiclesNeed["23"] + ADis_VehiclesNeed["24"] +
                        ADis_VehiclesNeed["25"] + ADis_VehiclesNeed["26"] > 0) {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["0"]--;
                        if (VehicleType == "HLF 20" && ADis_VehiclesNeed["4"] > 0) // HLF 20 acts as RW
                        {
                            ADis_VehiclesNeed["4"]--;
                        }
                    } else if (VehicleType == "HLF 20" && ADis_VehiclesNeed["4"] > 0) // HLF 20 acts as RW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["0"]--;
                        ADis_VehiclesNeed["4"]--;
                    } else if ((VehicleType == "DLK 23" || VehicleType == "TM 50") && ADis_VehiclesNeed["2"] > 0) // DLK 23
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["2"]--;
                    } else if (VehicleType == "AB-Einsatzleitung" &&
                        ADis_VehiclesNeed["3"] + ADis_VehiclesNeed["34"] + ADis_VehiclesNeed["78"] > 0) // ELW 1 + ELW 2
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["3"]--;
                        ADis_VehiclesNeed["34"]--;
                    } else if (VehicleType == "ELW 2" && ADis_VehiclesNeed["3"] + ADis_VehiclesNeed["34"] > 0) // ELW 2
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["3"]--;
                        ADis_VehiclesNeed["34"]--;
                    } else if (VehicleType == "ELW 1" && ADis_VehiclesNeed["3"] > 0) // ELW 1
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["3"]--;
                    } else if (VehicleType == "MTW" && ADis_VehiclesNeed["36"] > 0) // MTW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["36"]--;
                    } else if (VehicleType == "FwK" && ADis_VehiclesNeed["57"] > 0) // FwK
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["57"]--;
                    } else if (VehicleType == "GWK" &&
                        ADis_VehiclesNeed["4"] > 0) // GWK acts as RW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["4"]--;
                        ADis_VehiclesNeed["39"]--;
                    } else if ((VehicleType == "RW" ||
                            VehicleType == "AB-Rüst") &&
                        ADis_VehiclesNeed["4"] > 0) // RW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["4"]--;
                    } else if ((VehicleType == "GW-A" ||
                            VehicleType == "AB-Atemschutz") &&
                        ADis_VehiclesNeed["5"] > 0) // GW-A
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["5"]--;
                    } else if ((VehicleType == "GW-Öl" ||
                            VehicleType == "AB-Öl") &&
                        ADis_VehiclesNeed["10"] > 0) // GW-Öl
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["10"]--;
                    } else if (VehicleType == "GW-Messtechnik" && ADis_VehiclesNeed["12"] > 0) // FwK
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["12"]--;
                    } else if ((VehicleType == "GW-L2-Wasser" ||
                            VehicleType == "SW 1000" ||
                            VehicleType == "SW 2000" ||
                            VehicleType == "SW 2000-Tr" ||
                            VehicleType == "SW Kats" ||
                            VehicleType == "AB-Schlauch") &&
                        ADis_VehiclesNeed["11"] > 0) // SW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["11"]--;
                    } else if ((VehicleType == "GW-Gefahrgut" ||
                            VehicleType == "AB-Gefahrgut") && ADis_VehiclesNeed["27"] > 0) // GW-Gefahrgut
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["27"]--;
                    } else if (VehicleType == "GW-Höhenrettung" && ADis_VehiclesNeed["33"] > 0) // GW-Höhenrettung
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["33"]--;
                    } else if ((VehicleType == "Dekon-P" ||
                            VehicleType == "AB-Dekon-P") &&
                        ADis_VehiclesNeed["53"] > 0) // Dekon-P
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["53"]--;
                    } else if (VehicleType == "GW-Werkfeuerwehr" &&
                        ADis_VehiclesNeed["83"] > 0) // GW-Werkfeuerwehr
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["83"]--;
                    } else if (VehicleType == "ULF mit Löscharm" &&
                        ADis_VehiclesNeed["84"] > 0) // ULF mit Löscharm
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["84"]--;
                    }
                    /*
                    else if (VehicleType == "TM 50" &&
                        ADis_VehiclesNeed["85"] > 0) // TM 50
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["85"]--;
                    } 
                    */
                    else if (VehicleType == "Turbolöscher" &&
                        ADis_VehiclesNeed["86"] > 0) // Turbolöscher
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["86"]--;
                    } else if (VehicleType == "FLF" &&
                        ADis_VehiclesNeed["75"] > 0) // FLF
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["75"]--;
                    } else if (VehicleType == "Rettungstreppe" &&
                        ADis_VehiclesNeed["76"] > 0) // Rettungstreppe
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["76"]--;
                    }
                });
                return true;
            }
            return false;
        }

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Process Police_Department
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        function ADis_ProcessPoliceDepartment() {

            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
            //      -
            //      -               Fire Department: Vehicles
            //      -
            //      -                   32:     FuStW
            //      -                   35:     leBefKw
            //      -                   50:     GruKw
            //      -                   51:     FüKw
            //      -                   52:     GefKw
            //      -                   72:     WaWe
            //      -                   61:     Polizeihubschrauber
            //      -                   79:     SEK - ZF
            //      -                   80:     SEK - MTF
            //      -                   81:     MEK - ZF
            //      -                   82:     MEK - MTF
            //      -
            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

            if (typeof MissionConfig.police_department == "object") // Wenn der FD-Block in der Config definiert ist
            {
                ADis_VehiclesNeed["32"] += parseInt(MissionConfig.police_department.num_FuStW);
                ADis_VehiclesNeed["35"] += parseInt(MissionConfig.police_department.num_leBefKw);
                ADis_VehiclesNeed["50"] += parseInt(MissionConfig.police_department.num_GruKw);
                ADis_VehiclesNeed["51"] += parseInt(MissionConfig.police_department.num_FueKw);
                ADis_VehiclesNeed["52"] += parseInt(MissionConfig.police_department.num_GefKw);
                ADis_VehiclesNeed["72"] += parseInt(MissionConfig.police_department.num_WaWe);
                ADis_VehiclesNeed["61"] += parseInt(MissionConfig.police_department.num_PHu);
                ADis_VehiclesNeed["79"] += parseInt(MissionConfig.police_department.num_SEK_ZF);
                ADis_VehiclesNeed["80"] += parseInt(MissionConfig.police_department.num_SEK_MTF);
                ADis_VehiclesNeed["81"] += parseInt(MissionConfig.police_department.num_MEK_ZF);
                ADis_VehiclesNeed["82"] += parseInt(MissionConfig.police_department.num_MEK_MTF);

                $("#vehicle_show_table_body_all").find(".vehicle_select_table_tr").each(function () {
                    var VehicleID = $(this).attr("id").replace("vehicle_element_content_", "");
                    var VehicleType = $(this).attr("vehicle_type");
                    var VehicleDistanceTime = $("#vehicle_sort_" + VehicleID).attr("sortvalue");

                    if (VehicleType == "FuStW" && ADis_VehiclesNeed["32"] > 0) // FuStW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["32"]--;
                    } else if (VehicleType == "leBefKw" && ADis_VehiclesNeed["35"] > 0) // leBefKw
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["35"]--;
                    } else if (VehicleType == "GruKw" && ADis_VehiclesNeed["50"] > 0) // GruKw
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["50"]--;
                    } else if (VehicleType == "FüKw" && ADis_VehiclesNeed["51"] > 0) // FüKw
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["51"]--;
                    } else if (VehicleType == "GefKw" && ADis_VehiclesNeed["52"] > 0) // GefKw
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["52"]--;
                    } else if (VehicleType == "WaWe 10" && ADis_VehiclesNeed["72"] > 0) // WaWe 10
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["72"]--;
                    } else if (VehicleType == "Polizeihubschrauber" && ADis_VehiclesNeed["61"] > 0) // PHu
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["61"]--;
                    } else if (VehicleType == "SEK - ZF" && ADis_VehiclesNeed["79"] > 0) // SEK-ZF
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["79"]--;
                    } else if (VehicleType == "SEK - MTF" && ADis_VehiclesNeed["80"] > 0) // SEK-MTF
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["80"]--;
                    } else if (VehicleType == "MEK - ZF" && ADis_VehiclesNeed["81"] > 0) // MEK-ZF
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["81"]--;
                    } else if (VehicleType == "MEK - MTF" && ADis_VehiclesNeed["82"] > 0) // MEK-MTF
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["82"]--;
                    }
                });
                return true;
            }
            return false;
        }

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Process Water_Rescue
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        function ADis_ProcessWaterRescue() {

            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
            //      -
            //      -               Water Rescue: Vehicles
            //      -
            //      -                   63:     GW-Taucher
            //      -                   64:     GW-Wasserrettung
            //      -                   69:     Tauchkraftwagen (handel it here;TechnicalEmergencyService)
            //      -
            //      -               Boote:
            //      -
            //      -                   66:     Anh MzB (handel it here;TechnicalEmergencyService)
            //      -                   67:     Anh SchlB (handel it here;TechnicalEmergencyService)
            //      -                   68:     Anh MzAB (handel it here;TechnicalEmergencyService)
            //      -                   70:     MZB
            //      -                   71:     AB-MZB (handel it here;FireDepartment)
            //      -
            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

            if (typeof MissionConfig.water_rescue == "object") {
                ADis_VehiclesNeed["63"] += parseInt(MissionConfig.water_rescue.num_GW_T);
                ADis_VehiclesNeed["64"] += parseInt(MissionConfig.water_rescue.num_GW_W);
                ADis_VehiclesNeed["70"] += parseInt(MissionConfig.water_rescue.num_MzB);

                $("#vehicle_show_table_body_all").find(".vehicle_select_table_tr").each(function () {
                    var VehicleID = $(this).attr("id").replace("vehicle_element_content_", "");
                    var VehicleDistanceTime = $("#vehicle_sort_" + VehicleID).attr("sortvalue");

                    if (($(this).attr("vehicle_type") == "GW-Taucher" ||
                            $(this).attr("vehicle_type") == "Tauchkraftwagen") && ADis_VehiclesNeed["63"] > 0) // GW-Taucher
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["63"]--;
                    } else if ($(this).attr("vehicle_type") == "GW-Wasserrettung" && ADis_VehiclesNeed["64"] > 0) // GW-Wasserrettung
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["64"]--;
                    } else if (($(this).attr("vehicle_type") == "MZB" || $(this).attr("vehicle_type") == "Anh MzB" ||
                            $(this).attr("vehicle_type") == "Anh MzAB" || $(this).attr("vehicle_type") == "Anh SchlB" ||
                            $(this).attr("vehicle_type") == "AB-MZB") && ADis_VehiclesNeed["66"] + ADis_VehiclesNeed["67"] + ADis_VehiclesNeed["68"] +
                        ADis_VehiclesNeed["70"] + ADis_VehiclesNeed["71"] > 0) // Boote
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["70"]--;
                    }
                });
                return true;
            }
            return false;
        }

        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        //  -
        //  -                   Process Technical Emergency Service
        //  -
        //  - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

        function ADis_ProcessTechnicalEmergencyService() {

            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
            //      -
            //      -               THW: Vehicles
            //      -
            //      -                   39:     GKW (see also FireDepartment)
            //      -                   40:     MTW-TZ
            //      -                   41:     MzKW
            //      -                   42:     LKW K 9
            //      -                   43:     BRmG R
            //      -
            //      -                   44:     Anh DLE
            //      -                   45:     MLW 5
            //      -                   65:     LKW 7 Lkr 19 tm
            //      -                   69:     Tauchkraftwagen (see WaterRescue)
            //      -
            //      -                   66:     Anh MzB (see WaterRescue)
            //      -                   67:     Anh SchlB (see WaterRescue)
            //      -                   68:     Anh MzAB (see WaterRescue)
            //      -
            //      -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

            if (typeof MissionConfig.technical_emergency_service == "object") {
                ADis_VehiclesNeed["39"] += parseInt(MissionConfig.technical_emergency_service.num_GKW);
                ADis_VehiclesNeed["40"] += parseInt(MissionConfig.technical_emergency_service.num_MTW_TZ);
                ADis_VehiclesNeed["41"] += parseInt(MissionConfig.technical_emergency_service.num_MzKW);
                ADis_VehiclesNeed["42"] += parseInt(MissionConfig.technical_emergency_service.num_LKW_K9);
                ADis_VehiclesNeed["43"] += parseInt(MissionConfig.technical_emergency_service.num_BRmG_R);
                ADis_VehiclesNeed["44"] += parseInt(MissionConfig.technical_emergency_service.num_Anh_DLE);
                ADis_VehiclesNeed["45"] += parseInt(MissionConfig.technical_emergency_service.num_MLW_5);
                ADis_VehiclesNeed["65"] += parseInt(MissionConfig.technical_emergency_service.num_LKW_7Lkr);

                $("#vehicle_show_table_body_all").find(".vehicle_select_table_tr").each(function () {
                    var VehicleID = $(this).attr("id").replace("vehicle_element_content_", "");
                    var VehicleDistanceTime = $("#vehicle_sort_" + VehicleID).attr("sortvalue");

                    if ($(this).attr("vehicle_type") == "GKW" && ADis_VehiclesNeed["39"] > 0) // GKW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["39"]--;
                    } else if ($(this).attr("vehicle_type") == "MTW-TZ" && ADis_VehiclesNeed["40"] > 0) // MTW-TZ
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["40"]--;
                    } else if ($(this).attr("vehicle_type") == "MzKW" && ADis_VehiclesNeed["41"] > 0) // MzKW
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["41"]--;
                    } else if ($(this).attr("vehicle_type") == "LKW K 9" && ADis_VehiclesNeed["42"] > 0) // LKW K 9
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["42"]--;
                    } else if ($(this).attr("vehicle_type") == "BRmG R" && ADis_VehiclesNeed["43"] > 0) // BRmG R
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["43"]--;
                    } else if ($(this).attr("vehicle_type") == "Anh DLE" && ADis_VehiclesNeed["44"] > 0) // Anh DLE
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["44"]--;
                    } else if ($(this).attr("vehicle_type") == "MLW 5" && ADis_VehiclesNeed["45"] > 0) // MLW 5
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["45"]--;
                    } else if ($(this).attr("vehicle_type") == "LKW 7 Lkr 19 tm" && ADis_VehiclesNeed["65"] > 0) // LKW 7 Lkr 19 tm
                    {
                        $("#vehicle_checkbox_" + VehicleID).click();
                        ADis_VehiclesNeed["65"]--;
                    }
                });
                return true;
            }
            return false;
        }

        var ADis_VehiclesNeed = {};

        function ADis_PrepareVehicleNeedList() {
            for (VehicleTypeID = 0; VehicleTypeID <= MaxVehicleID; VehicleTypeID++) {
                ADis_VehiclesNeed[VehicleTypeID] = 0;
            }
            for (VehicleTypeID = 0; VehicleTypeID <= MaxVehicleID; VehicleTypeID++) {
                ADis_CountInvolvedVehiclesOfType(VehicleTypeID);
            }
            console.log("ADis_PrepareVehicleNeedList: ok");
            return true;
        }

        function ADis_CountInvolvedVehiclesOfType(VehicleTypeID) {
            for (var Key in AD_Vehicles) {
                var Vehicle = AD_Vehicles[Key];
                if (Vehicle.type == VehicleTypeID) {
                    ADis_SelectCountVehicles(VehicleTypeID);
                }
            };

            $("#mission_vehicle_driving tbody, #mission_vehicle_at_mission tbody").find("tr").each(function () {
                if ($(this).find("a").first().attr("vehicle_type_id") == VehicleTypeID) {
                    ADis_SelectCountVehicles(VehicleTypeID);
                }
            });

            return;
        }

        function ADis_SelectCountVehicles(VehicleTypeID) {
            var VehicleTypeID = Number(VehicleTypeID);
            if ([38].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed[VehicleTypeID]--;
            } else if ([0, 1, 6, 7, 8, 9, 30, 37, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26].indexOf(VehicleTypeID) != -1) { // LF acts as 'Tragehilfe'
                // 30 acts as Rüstwagen
                if ([30].indexOf(VehicleTypeID) != -1) {
                    ADis_VehiclesNeed["4"]--;
                }
                // 0 acts as all LF
                ADis_VehiclesNeed["0"]--;
            } else if ([74].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["74"]--;
                ADis_VehiclesNeed["28"]--;
                ADis_VehiclesNeed["29"]--;
            } else if ([73].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["73"]--;
            } else if ([28].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["28"]--;
            } else if ([29].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["29"]--;
            } else if ([31].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["31"]--;
            } else if ([55].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["55"]--;
            } else if ([56].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["56"]--;
            } else if ([58].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["58"]--;
            } else if ([59].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["59"]--;
            } else if ([60].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["60"]--;
            } else if ([2].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["2"]--;
            } else if ([34, 78].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["3"]--;
                ADis_VehiclesNeed["34"]--;
            } else if ([3].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["3"]--;
            } else if ([36].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["36"]--;
            } else if ([57].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["57"]--;
            } else if ([4].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["4"]--;
                ADis_VehiclesNeed["39"]--;
            } else if ([4, 47].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["4"]--;
            } else if ([5, 48].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["5"]--;
            } else if ([10, 49].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["10"]--;
            } else if ([12].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["12"]--;
            } else if ([11, 13, 14, 15, 16].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["11"]--;
            } else if ([27, 77].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["27"]--;
            } else if ([33].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["33"]--;
            } else if ([53, 54].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["53"]--;
            } else if ([83].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["83"]--;
            } else if ([84].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["84"]--;
            } else if ([85].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["85"]--;
                ADis_VehiclesNeed["2"]--;
            } else if ([86].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["86"]--;
            } else if ([75].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["75"]--;
            } else if ([76].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["76"]--;
            } else if ([32].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["32"]--;
            } else if ([35].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["35"]--;
            } else if ([50].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["50"]--;
            } else if ([51].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["51"]--;
            } else if ([52].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["52"]--;
            } else if ([72].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["72"]--;
            } else if ([61].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["61"]--;
            } else if ([79].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["79"]--;
            } else if ([80].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["80"]--;
            } else if ([81].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["81"]--;
            } else if ([82].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["82"]--;
            } else if ([63, 69].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["63"]--;
            } else if ([64].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["64"]--;
            } else if ([66, 67, 68, 70, 71].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["70"]--;
            } else if ([39].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["39"]--;
                ADis_VehiclesNeed["4"]--; // Rüst
            } else if ([40].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["40"]--;
            } else if ([41].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["41"]--;
            } else if ([42].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["42"]--;
            } else if ([43].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["43"]--;
            } else if ([44].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["44"]--;
            } else if ([45].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["45"]--;
            } else if ([65].indexOf(VehicleTypeID) != -1) {
                ADis_VehiclesNeed["65"]--;
            }
        }

        function ADis_CheckNeedMoreVehicles() {
            var NeedMoreVehicles = false;

            for (var Key in ADis_VehiclesNeed) {
                var VehicleCount = ADis_VehiclesNeed[Key];
                if (VehicleCount > 0) {
                    NeedMoreVehicles = true;
                }
            };

            return NeedMoreVehicles;
        }
    }
});