/* Minification failed. Returning unminified contents.
(428,69-70): run-time error JS1195: Expected expression: >
(428,98-100): run-time error JS1195: Expected expression: ||
(428,157-158): run-time error JS1195: Expected expression: >
(428,184-185): run-time error JS1004: Expected ';': )
(432,9-10): run-time error JS1002: Syntax error: }
(434,69-70): run-time error JS1195: Expected expression: >
(434,97-98): run-time error JS1004: Expected ';': )
(458,9-10): run-time error JS1002: Syntax error: }
(460,69-70): run-time error JS1195: Expected expression: >
(460,97-98): run-time error JS1004: Expected ';': )
(482,9-10): run-time error JS1002: Syntax error: }
(484,71-72): run-time error JS1195: Expected expression: >
(484,99-100): run-time error JS1004: Expected ';': )
(504,9-10): run-time error JS1002: Syntax error: }
(506,56-57): run-time error JS1004: Expected ';': {
(624,5-6): run-time error JS1002: Syntax error: }
(625,25-26): run-time error JS1195: Expected expression: )
(625,27-28): run-time error JS1004: Expected ';': {
(627,6-7): run-time error JS1195: Expected expression: ,
(628,23-24): run-time error JS1195: Expected expression: )
(628,25-26): run-time error JS1004: Expected ';': {
(636,6-7): run-time error JS1195: Expected expression: ,
(637,21-22): run-time error JS1195: Expected expression: )
(637,23-24): run-time error JS1004: Expected ';': {
(654,6-7): run-time error JS1195: Expected expression: ,
(655,21-22): run-time error JS1195: Expected expression: )
(655,23-24): run-time error JS1004: Expected ';': {
(857,69-70): run-time error JS1195: Expected expression: >
(857,81-82): run-time error JS1197: Too many errors. The file might not be a JavaScript file: .
 */
var id_w_item = 0, ar_w_item = [], onPlan = false, d_check_cpv = [], d_check_cav = [], spfu_classifier = []
    , cdb2_public_edit = false, cdb1_public_edit = false, is_privatization = false;

withPublic = true;

var award_withoutAuction = false;

var PrefixId = "";
var Id_From_Item = "";

$.widget("SySe.Tender_item", {
    options: {
        id_container: "",
        Position: "",
        anItem: "",
        id: "",
        number: 0,
    },
    _create: function () {
        if (!award_withoutAuction) {
            this.options.id = id_w_item++;
        }

        ar_w_item[ar_w_item.length] = this;

        this._render();

    },
    _render: function () {

        var aWD = document.createElement("div");
        aWD.setAttribute("class", "col-12");
        var el = this.options;
        PrefixId = "_" + el.id;
        Id_From_Item = PrefixId.substr(1, 1) - 1;
        var anItem = el.anItem;

        var prozorro_test_id = "";

        if (isPlaceTestMode && anItem.description != undefined) {
            description = anItem.description;
            if (description.uk_UA != undefined)
                description = description.uk_UA;

            if (description.indexOf(":") > -1)
                prozorro_test_id = description.substring(0, description.indexOf(":"));
        }

        var is_new = false;
        if (anItem.id == undefined) {
            anItem.id = hex_md5(Math.uuid(32, 16)); //"web_" + getUniqueId();    
            is_new = true;
        }

        var str = pn_w_item___id.outerHTML;

        if (!ReadOnly)
            str = str.replace(new RegExp("items\\[prozorro_test_id__\\]\\.", 'g'), "");

        str = str.replace(new RegExp("__id", 'g'), el.id)
            .replace(new RegExp("prozorro_test_id__", 'g'), prozorro_test_id)
            .replace("item_title__", (PMT == "dgfOtherAssets" || is_privatization ? arrLang[0][lang][956] : arrLang[0][lang][957]))
            .replace("address_title__", (tenderType == "nadra" ? arrLang[0][lang][1058] : (PMT == "dgfOtherAssets" || is_privatization ? arrLang[0][lang][958] : arrLang[0][lang][959])))
            ;

        $(aWD).append(str);


        if (tenderType == "timber")
            unit_dic = { MTQ: d_units.MTQ };
        else if (tenderType == "renewables")
            unit_dic = { KWT: d_units.KWT };
        else if (tenderType == "nadra")
            unit_dic = { H87: d_units.H87, MTQ: d_units.MTQ, MTK: d_units.MTK, KMT: d_units.KMT };
        else
            unit_dic = d_units;

        SetProzorroDicOption(unit_dic, $("#slw_item" + PrefixId + "_unit_code", $(aWD)), true);

        if (tenderType.includes("basicSell") || tenderType.includes("alienation")
            || tenderType.includes("legitimatePropertyLease") || tenderType.includes("commercialSell")
            || tenderType.includes("bankRuptcy") || tenderType.includes("regulationsPropertyLease")
            || tenderType.includes("commercialPropertyLease") || tenderType.includes("smallPrivatization")
            || tenderType.includes("largePrivatization") || tenderType.includes("nonperformingLoans")) {
            $("#pnw_item" + PrefixId + "_registrationDetails", $(aWD)).show();

            Ajax_syncGet((tenderType.includes("smallPrivatization") || tenderType.includes("largePrivatization") ? "Js/RegistryAssets/registrationStatus.json?v=" : "Js/rent/registrationState.json?v=") + version, function (data) {
                SetCBD3DicOption(data, $("#registrationStatus" + PrefixId, $(aWD)), true);
            });
            $('#registrationDate' + PrefixId, $(aWD)).attr('autocomplete', 'off').datepicker($.datepicker.regional["uk"]);
        }

        SetEditFormFields($("#pn_w_item" + PrefixId, $(aWD)));

        $("#pn_w_item" + PrefixId, $(aWD)).wSHdiv({ Title: (is_privatization ? "" : arrLang[0][lang][960]) + "№ " + el.number });

        this.element.html(aWD);

        if (anItem != {}) {
            if (anItem.description != undefined && anItem.description.uk_UA != undefined)
                anItem.description = anItem.description.uk_UA;

            if (anItem.classification != undefined) {
                if (cdb == 2)
                    anItem.classification_scheme = anItem.classification.scheme

                anItem.classification_id = anItem.classification.id;
                if (anItem.classification.description.uk_UA != undefined)
                    anItem.classification_description = anItem.classification.description.uk_UA;
                else
                    anItem.classification_description = anItem.classification.description;
            }

            if (tenderType == "nadra" && cdb == 3) {
                $('#pnw_item' + PrefixId + '_additionalClassifications', $(aWD)).hide();
            }
            else {
                if (anItem.additionalClassifications != undefined && anItem.additionalClassifications.length > 0) {
                    anItem.additionalClassifications_scheme = anItem.additionalClassifications[0].scheme
                    anItem.additionalClassifications_id = anItem.additionalClassifications[0].id;
                    if (anItem.additionalClassifications[0].description != undefined)
                        if (anItem.additionalClassifications[0].description.uk_UA != undefined)
                            anItem.additionalClassifications_description = anItem.additionalClassifications[0].description.uk_UA;
                        else
                            anItem.additionalClassifications_description = anItem.additionalClassifications[0].description;
                }
                else
                    anItem.additionalClassifications_scheme = 'NONE';
            }

            if (anItem.unit != undefined) {
                if (tenderType == "renewables")
                    anItem.unit_code = "KWT";
                else
                    anItem.unit_code = anItem.unit.code;

                if (d_units[anItem.unit_code] != undefined)
                    anItem.unit_name = d_units[anItem.unit_code].name_uk;
            }

            if (anItem.contractPeriod != undefined) {
                sd = anItem.contractPeriod.startDate;
                if (sd != undefined) {
                    anItem.contractPeriod_startDate_Date = sY_M_D_2DMY(sd);
                    anItem.contractPeriod_startDate = sd;
                }

                sd = anItem.contractPeriod.endDate;
                if (sd != undefined) {
                    anItem.contractPeriod_endDate_Date = sY_M_D_2DMY(sd);
                    anItem.contractPeriod_endDate = sd;
                }
            }

            if (anItem.requestLifeTime != undefined) {
                sd = anItem.requestLifeTime.dateFrom;
                if (sd != undefined) {
                    anItem.requestLifeTime_startDate_Date = sISO_8601_2_DMYHM(sd);
                }

                sd = anItem.requestLifeTime.dateTill;
                if (sd != undefined) {
                    anItem.requestLifeTime_endDate_Date = sISO_8601_2_DMYHM(sd);
                }
            }

            if (anItem.loadLifeTime != undefined) {
                sd = anItem.loadLifeTime.dateFrom;
                if (sd != undefined) {
                    anItem.loadLifeTime_startDate_Date = sISO_8601_2_DMYHM(sd);
                }

                sd = anItem.loadLifeTime.dateTill;
                if (sd != undefined) {
                    anItem.loadLifeTime_endDate_Date = sISO_8601_2_DMYHM(sd);
                }
            }

            if (anItem.address != undefined) {
                if (anItem.address.countryName != undefined) {
                    if (anItem.address.countryName.uk_UA != undefined)
                        anItem.address_countryName = anItem.address.countryName.uk_UA;
                    else
                        anItem.address_countryName = anItem.address.countryName;
                }

                anItem.address_postalCode = anItem.address.postalCode;

                anItem.address_region = anItem.address.region;
                if (anItem.address_region != undefined && anItem.address_region.uk_UA != undefined)
                    anItem.address_region = anItem.address_region.uk_UA;

                anItem.address_locality = anItem.address.locality;
                if (anItem.address_locality != undefined && anItem.address_locality.uk_UA != undefined)
                    anItem.address_locality = anItem.address_locality.uk_UA;

                if (anItem.address.streetAddress != undefined) {
                    anItem.address_streetAddress = anItem.address.streetAddress;
                    if (anItem.address_streetAddress != undefined && anItem.address_streetAddress.uk_UA != undefined)
                        anItem.address_streetAddress = anItem.address_streetAddress.uk_UA;
                }

                if (anItem.address.addressID != undefined) {
                    anItem.address_addressID = anItem.address.addressID.id;
                }
            }

            if (anItem.location != undefined) {
                anItem.location_latitude = anItem.location.latitude;
                anItem.location_longitude = anItem.location.longitude;
                anItem.location_elevation = anItem.location.elevation;
            }

            if (full_data.canQuestion == 'true'
                && cdb != 3) {
                $('#pn_item_control' + PrefixId, $(aWD)).show();

                $('#btn_item_add_question' + PrefixId, $(aWD)).css("display", "")
                    .click(function () { ShowFrame("Position_questions.aspx", '&id=' + oFormRecord.id + "&questionOf=item&relatedItem=" + anItem.id) });
            }
        }
        else {
            anItem.id = hex_md5(Math.uuid(32, 16)); //"web_" + getUniqueId();    
        }

        if (idForm == 0 || oFormRecord.status == "created" || anItem.is_new != undefined) {
            $('#pn_item_control' + PrefixId, $(aWD)).show();

            if (!(tenderType == "renewables" || tenderType == "timber" || tenderType == "nadra" || tenderType.includes('legitimatePropertyLease') || tenderType.includes("landSell") || tenderType.includes("landRental") || tenderType.includes("landArrested")))
                $('#btn_item_delete' + PrefixId, $(aWD)).css("display", "")
                    .click($.proxy(this, "Delete"));
        }

        if (tenderType.includes("bankRuptcy") && full_data.canPublic == 'true') {
            $('#pn_item_control' + PrefixId, $(aWD)).show();
            $('#btn_item_delete' + PrefixId, $(aWD)).css("display", "")
                .click($.proxy(this, "Delete"));
        }

        if (cdb == "1")
            $("#nw_item" + PrefixId + "_classification", $(aWD)).text("Код CAV")
        else if (cdb == "2") {

            if (is_privatization) {
                SetDicOption(d_dict, $("#slw_item" + PrefixId + "_additionalClassifications_scheme", $(aWD)), "privatization_AC", false);

                $("#pnw_item" + PrefixId + "_registrationDetails", $(aWD)).show();

                $("#lew_item" + PrefixId + "_quantity", $(aWD)).text(arrLang[0][lang][961]);

                SetDicOption(d_dict, $("#slw_item" + PrefixId + "_registrationDetails_status", $(aWD)), "registration_status", true);

                if (anItem.registrationDetails != undefined) {
                    anItem.registrationDetails_status = anItem.registrationDetails.status;

                    if (anItem.registrationDetails.status == "complete") {

                        if (anItem.registrationDetails.registrationDate != undefined) {
                            anItem.registrationDetails_registrationDateData = anItem.registrationDetails.registrationDate;
                            anItem.registrationDetails_registrationDate = sY_M_D_2DMY(anItem.registrationDetails.registrationDate);
                        }

                        anItem.registrationDetails_registrationID = anItem.registrationDetails.registrationID;
                    }
                }
                else
                    anItem.registrationDetails_status = "unknown";

                SetDicSearchOption(d_spfu_classifier, $("#slw_item" + PrefixId + "_property_type", $(aWD)), -1, false, arrLang[0][lang][962]);
                _property_type_value = get_property_type_value(anItem);
                $("#slw_item" + PrefixId + "_property_type", $(aWD)).val(_property_type_value);
            }
        }

        SetFormValues("w_item" + PrefixId + "_"
            , "description,description_en,location,quantity,classification_id,classification_description"
            + ",classification_scheme,additionalClassifications_scheme,additionalClassifications_id,additionalClassifications_description"
            + ",unit_code,unit_name,contractPeriod_startDate_Date,contractPeriod_endDate_Date,contractPeriod_startDate,contractPeriod_endDate"
            + ",address_countryName,address_postalCode,address_region,address_locality,address_streetAddress,address_addressID"
            + ",location_latitude,location_longitude,location_elevation"
            + ",requestLifeTime,requestLifeTime_startDate_Date,requestLifeTime_endDate_Date"
            + ",loadLifeTime,loadLifeTime_startDate_Date,loadLifeTime_endDate_Date"
            + ",registrationDetails_status,registrationDetails_registrationDate,registrationDetails_registrationDateData,registrationDetails_registrationID"
            , anItem, $(aWD));

        if (isDebugMode)
            SetFormValues("wd_item" + PrefixId + "_"
                , "description,description_en,location,quantity,classification_id,classification_description"
                + ",classification_scheme,additionalClassifications_scheme,additionalClassifications_id,additionalClassifications_description"
                + ",unit_code,unit_name,contractPeriod_startDate_Date,contractPeriod_endDate_Date,contractPeriod_startDate,contractPeriod_endDate"
                + ",address_countryName,address_postalCode,address_region,address_locality,address_streetAddress"
                + ",location_latitude,location_longitude,location_elevation"
                + ",requestLifeTime,requestLifeTime_startDate_Date,requestLifeTime_endDate_Date"
                + ",loadLifeTime,loadLifeTime_startDate_Date,loadLifeTime_endDate_Date"
                + ",registrationDetails_status,registrationDetails_registrationDate,registrationDetails_registrationDateData,registrationDetails_registrationID"
                , anItem, $(aWD));

        if (anItem.registrationDetails != undefined) {
            $("#registrationStatus" + PrefixId, $(aWD)).val(anItem.registrationDetails.registrationStatus);
            $("#registrationID" + PrefixId, $(aWD)).val(anItem.registrationDetails.registrationID);
            $("#registrationDate" + PrefixId, $(aWD)).val(sISO_8601_2_DMYHM(anItem.registrationDetails.registrationDate).substr(0, 10));
            $("#registrationDate_Time" + PrefixId, $(aWD)).val(sISO_8601_2_DMYHM(anItem.registrationDetails.registrationDate).substr(11, 5));
        }

        if (anItem.classification_id != undefined)
            $("#ew_item" + PrefixId + "_classification_id", $(aWD)).text(anItem.classification_id).show();

        if (cdb == 3 && !cdb3_dgf && !tenderType.includes('legitimatePropertyLease')
            && !tenderType.includes("landSell") && !tenderType.includes("landRental")
            && !tenderType.includes("landArrested") && !tenderType.includes('basicSell')
            && !tenderType.includes('alienation') && !tenderType.includes('commercialSell')
            && !tenderType.includes('bankRuptcy') && !tenderType.includes('simpleSell')
            && !tenderType.includes('regulationsPropertyLease') && !tenderType.includes('commercialPropertyLease')
            && !tenderType.includes('smallPrivatization') && !tenderType.includes('largePrivatization')
            && !tenderType.includes('nonperformingLoans')) {
            $("#pn_w_item" + PrefixId + "_location", $(aWD)).hide();
        }

        if (anItem.requestLifeTime == undefined) {
            $("#pn_item" + PrefixId + "_requestLifeTime", $(aWD)).hide();
        }

        if (anItem.loadLifeTime == undefined) {
            $("#pn_item" + PrefixId + "_loadLifeTime", $(aWD)).hide();
        }

        if (anItem.dgfItemType != undefined) {
            $("#dgfItemType" + PrefixId, $(aWD)).text(d_dgfItemType[anItem.dgfItemType].uk_UA)
            $("#pn_w_item" + PrefixId + "_dgfItemType", $(aWD)).show();
        }

        if (tenderType.includes('legitimatePropertyLease') || tenderType.includes("landSell")
            || tenderType.includes("landRental") || tenderType.includes("landArrested")
            || tenderType.includes("basicSell") || tenderType.includes("regulationsPropertyLease")
            || tenderType.includes("commercialPropertyLease") || tenderType.includes("alienation")
            || tenderType.includes("commercialSell") || tenderType.includes("bankRuptcy")
            || tenderType.includes('simpleSell') || tenderType.includes('smallPrivatization')
            || tenderType.includes('largePrivatization') || tenderType.includes('nonperformingLoans')) {
            $("#addressID" + PrefixId, $(aWD)).show();
        }

        if (tenderType.includes('legitimatePropertyLease')) {
            SetDicSearchOption(d_dict, $("#itemType" + PrefixId, $(aWD)), "itemType", false, "Виберіть значення");
            $("#pn_w_item" + PrefixId + "_itemType", $(aWD)).show();
            if (anItem.itemType != undefined) {
                $("#itemType" + PrefixId, $(aWD)).val(anItem.itemType);
            }
        }

        if (tenderType.includes("landSell") || tenderType.includes("landRental")) {
            Ajax_syncGet("Js/land/ownershipType.json?v=" + version, function (data) {
                SetCBD3DicOption(data, $("#land" + PrefixId + "_itemProps_ownershipType", $(aWD)), true);
            });

            $("#land" + PrefixId + "_itemProps", $(aWD)).show();

            $("#land" + PrefixId + "_itemProps_cadastralNumber", $(aWD)).mask("9999999999:99:999:9999");

            if (idForm == 0 || idForm.includes('web')) {
                $(".not_land" + PrefixId, $(aWD)).hide();
                $("#pnw_item" + PrefixId + "_classification", $(aWD)).hide();
            }
        }

        if (tenderType.includes("landArrested")) {
            Ajax_syncGet("Js/landArrested/ownershipType.json?v=" + version, function (data) {
                SetCBD3DicOption(data, $("#land" + PrefixId + "_itemProps_ownershipType", $(aWD)), true);
            });

            $("#land" + PrefixId + "_itemProps", $(aWD)).show();

            $("#land" + PrefixId + "_itemProps_cadastralNumber", $(aWD)).mask("9999999999:99:999:9999");

            if (idForm == 0 || idForm.includes('web')) {
                $(".not_land" + PrefixId, $(aWD)).hide();
                $("#pnw_item" + PrefixId + "_classification", $(aWD)).hide();
            }
        }

        if (tenderType.includes('basicSell') || tenderType.includes('simpleSell') || tenderType.includes('commercialSell')) {
            if (anItem.classification != undefined && anItem.classification.id != undefined) {
                basicSell_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));
            }

            if (anItem.basicSellItemType != undefined) {
                Ajax_syncGet("Js/basicSell/basicSellItemType.json?v=" + version, function (data) {
                    $("#basicSellItemType" + PrefixId, $(aWD)).text(data[anItem.basicSellItemType].uk_UA)
                });

                $("#pn_w_item" + PrefixId + "_basicSellItemType", $(aWD)).show();
            }
        }

        if (tenderType.includes('alienation')) {
            if (anItem.classification != undefined && anItem.classification.id != undefined) {
                alienation_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));
            }

            if (anItem.basicSellItemType != undefined) {
                Ajax_syncGet("Js/basicSell/basicSellItemType.json?v=" + version, function (data) {
                    $("#basicSellItemType" + PrefixId, $(aWD)).text(data[anItem.basicSellItemType].uk_UA)
                });

                $("#pn_w_item" + PrefixId + "_basicSellItemType", $(aWD)).show();
            }
        }

        if (tenderType.includes('bankRuptcy')) {
            if (anItem.classification != undefined && anItem.classification.id != undefined) {
                bankRuptcy_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));
            }
        }

        if (tenderType.includes('regulationsPropertyLease')) {
            if (anItem.classification != undefined && anItem.classification.id != undefined) {
                regulationsPropertyLease_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));
            }

            if (anItem.regulationsPropertyLeaseItemType != undefined) {
                Ajax_syncGet("Js/regulationsPropertyLease/regulationsPropertyLeaseItemType.json?v=" + version, function (data) {
                    $("#basicSellItemType" + PrefixId, $(aWD)).text(data[anItem.regulationsPropertyLeaseItemType].uk_UA)
                });

                $("#pn_w_item" + PrefixId + "_basicSellItemType", $(aWD)).show();
            }
        }

        if (tenderType_for_additionalClassification_cpvs.some(type => tenderType.includes(type)) || tenderType_for_additionalClassification_cvzu.some(type => tenderType.includes(type))
            || tenderType_for_additionalClassification_kvtspz.some(type => tenderType.includes(type))) {
            $(".cdb3_additionalClassifications" + PrefixId, $(aWD)).show();
            $("#pnw_item" + PrefixId + "_additionalClassifications", $(aWD)).hide();
        }

        if (tenderType_for_additionalClassification_cpvs.some(type => tenderType.includes(type))) {
            Ajax_syncGet("Js/cpvs/CPVS.json?v=" + version, function (data) {
                SetCBD3DicOption(data, $("#additionalClassifications" + PrefixId + "_cpvs", $(aWD)), true);
                d_new_cpvs = data;
            });

            $(".show_cpvs" + PrefixId, $(aWD)).show();

            if (tenderType.includes("bankRuptcy")) {
                $("#additionalClassifications" + PrefixId + "_cpvs", $(aWD)).attr("disabled", "disabled");
            }

            if (anItem.additionalClassifications != undefined) {
                let cpvs = [];
                for (var i = 0; i < anItem.additionalClassifications.length; i++) {
                    if (anItem.additionalClassifications[i].scheme == "CPVS") {
                        cpvs.push(anItem.additionalClassifications[i].id)
                    }
                }

                if (cpvs.length != 0) {
                    $("#additionalClassifications" + PrefixId + "_cpvs", $(aWD)).val(cpvs)
                }
            }
        }

        if (tenderType_for_additionalClassification_cvzu.some(type => tenderType.includes(type))) {
            Ajax_syncGet("Js/CVZU.json?v=" + version, function (data) {
                SetCBD3DicOption(data, $("#additionalClassifications" + PrefixId + "_cvzu", $(aWD)), true);
                d_cvzu = data;
            });

            if (tenderType.includes("landSell") || tenderType.includes("landRental") || tenderType.includes("landArrested")) {
                $(".show_cvzu" + PrefixId, aWD).show();
            }

            if (anItem.additionalClassifications != undefined) {
                let cvzu = [];
                for (var i = 0; i < anItem.additionalClassifications.length; i++) {
                    if (anItem.additionalClassifications[i].scheme == "CVZU") {
                        cvzu.push(anItem.additionalClassifications[i].id)
                    }
                }

                if (cvzu.length != 0) {
                    $("#additionalClassifications" + PrefixId + "_cvzu", $(aWD)).val(cvzu)
                }
            }
        }

        if (tenderType_for_additionalClassification_kvtspz.some(type => tenderType.includes(type))) {
            Ajax_syncGet("Js/kvtspz.json?v=" + version, function (data) {
                SetCBD3DicOption(data, $("#additionalClassifications" + PrefixId + "_kvtspz", $(aWD)), true);
                d_kvtspz = data;
            });

            $(".show_kvtspz" + PrefixId, $(aWD)).show();

            if (anItem.additionalClassifications != undefined) {
                let kvtspz = [];
                for (var i = 0; i < anItem.additionalClassifications.length; i++) {
                    if (anItem.additionalClassifications[i].scheme == "kvtspz") {
                        kvtspz.push(anItem.additionalClassifications[i].id)
                    }
                }

                if (kvtspz.length != 0) {
                    $("#additionalClassifications" + PrefixId + "_kvtspz", $(aWD)).val(kvtspz)
                }
            }
        }

        if (tenderType.includes('nonperformingLoans')) {
            if (anItem.classification != undefined && anItem.classification.id != undefined) {
                nonperformingLoans_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));
            }

            if (anItem.nonperformingLoansItemType != undefined) {
                $("#nonperformingLoansItemType_block" + PrefixId, $(aWD)).show();
                Ajax_syncGet("Js/nonperformingLoans/nonperformingLoansItemType.json?v=" + version, function (data) {
                    $("#nonperformingLoansItemType" + PrefixId, $(aWD)).text(data[anItem.nonperformingLoansItemType].uk_UA)
                });
            }

            if (anItem.value != undefined) {
                $("#item_value" + PrefixId, $(aWD)).val(anItem.value.amount);
            }

            if (anItem.overdueDuration != undefined) {
                overdueDuration = Iso8601DurationPeriod(anItem.overdueDuration);
                $("#item_overdueDuration_y" + PrefixId, $(aWD)).val(overdueDuration.period.variables.Y);
                $("#item_overdueDuration_m" + PrefixId, $(aWD)).val(overdueDuration.period.variables.M);
                $("#item_overdueDuration_d" + PrefixId, $(aWD)).val(overdueDuration.period.variables.D);
            }
        }

        if (tenderType.includes('smallPrivatization')) {
            assetItems_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));

            if (anItem.smallPrivatizationItemType != undefined) {
                Ajax_syncGet("Js/smallPrivatization/smallPrivatizationItemType.json?v=" + version, function (data) {
                    $("#smallPrivatization_itemType" + PrefixId, $(aWD)).text(data[anItem.smallPrivatizationItemType].uk_UA)
                });
            }
        }

        if (tenderType.includes('largePrivatization')) {
            assetItems_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));

            if (anItem.largePrivatizationItemType != undefined) {
                Ajax_syncGet("Js/largePrivatization/largePrivatizationItemType.json?v=" + version, function (data) {
                    $("#largePrivatization_itemType" + PrefixId, $(aWD)).text(data[anItem.largePrivatizationItemType].uk_UA)
                });
            }
        }

        if (tenderType.includes('commercialPropertyLease')) {
            if (anItem.classification != undefined && anItem.classification.id != undefined) {
                commercialPropertyLease_classification_change(anItem.classification.id, PrefixId, anItem.itemProps, $(aWD));
            }

            if (anItem.commercialPropertyLeaseItemType != undefined) {
                Ajax_syncGet("Js/commercialPropertyLease/commercialPropertyLeaseItemType.json?v=" + version, function (data) {
                    $("#basicSellItemType" + PrefixId, $(aWD)).text(data[anItem.commercialPropertyLeaseItemType].uk_UA)
                });

                $("#pn_w_item" + PrefixId + "_basicSellItemType", $(aWD)).show();
            }
        }

        if (is_privatization)
            slw_item_registrationDetails_status_onchange("w_item" + PrefixId, $(aWD))

        var _ac_el = $("#ew_item" + PrefixId + "_classification_id", $(aWD));
        var _ac_el_desc = $("#tw_item" + PrefixId + "_classification_description", $(aWD));

        _ac_el.change(function () {
            change_classification_code(PrefixId);
        });

        $("#ew_item" + PrefixId + "_unit_code", $(aWD)).change(function () {
            change_unit_code("slw_item" + PrefixId + "_unit_code");
        });

        if (tenderType == "timber" && cdb == 2 && (anItem.schema_properties != undefined || !ReadOnly || cdb2_public_edit))
            Add_timberProperties(anItem.schema_properties != undefined ? anItem.schema_properties.properties : undefined, PrefixId, $(aWD));

        if ((!ReadOnly || cdb2_public_edit || cdb1_public_edit && (is_new || !isDebugMode)) && !rent_rectification) {
            if (cdb == "1") {
                set_AC_CPV_DKPP(_ac_el, SelectItemsOn_cav, _ac_el_desc);
            }
            else {
                set_AC_CPV_DKPP(_ac_el, SelectItemsOn_cav_cpv, _ac_el_desc);

                if (is_privatization)
                    slPosition_additionalClassifications_scheme_onchange("w_item" + PrefixId, $(aWD));
                else {
                    var _ac_el = $("#ew_item" + PrefixId + "_additionalClassifications_id", $(aWD));
                    var _ac_el_desc = $("#tw_item" + PrefixId + "_additionalClassifications_description", $(aWD));
                    set_AC_CPV_DKPP(_ac_el, SelectItemsOn_cpvs, _ac_el_desc);
                }
            }

            _ac_el = $("#ew_item" + PrefixId + "_address_countryName", $(aWD));
            set_AC_Region(_ac_el, SelectItemsOn_country);

            if (tenderType == "nadra" && !ReadOnly) {
                $("#btAddKOATUU" + PrefixId, $(aWD)).show();

                $(".koatu", $(aWD)).each(function () { SetViewForm($(this)); });
            }
            else {
                _ac_el = $("#ew_item" + PrefixId + "_address_region", $(aWD));
                set_AC_Region(_ac_el, SelectItemsOn_Region);
            }

            if (is_privatization || tenderType == "comercial" || tenderType == "rent") {
                SetViewForm($("#pnw_item" + PrefixId + "_additionalClassifications", $(aWD)));
            }

            if (tenderType.includes("landSell") || tenderType.includes("landRental") || tenderType.includes("landArrested") || tenderType.includes("basicSell") || tenderType.includes("regulationsPropertyLease") || tenderType.includes("commercialPropertyLease") || tenderType.includes("alienation") || tenderType.includes("commercialSell") || tenderType.includes("bankRuptcy") || tenderType.includes('simpleSell') || tenderType.includes('nonperformingLoans')) {
                $("#btAddKOATUU" + PrefixId, $(aWD)).show();

                $(".koatu", $(aWD)).each(function () { SetViewForm($(this)); });
            }
        } else {
            $("#add_classifications" + PrefixId, $(aWD)).hide();
            SetViewForm($(aWD));
        }

    },
    ReadOnly: function () {
        SetViewForm(this.element);
    },
    Delete: function () {
        for (var i = 0; i < ar_w_item.length; i++)
            if (ar_w_item[i].element[0].id == this.element[0].id) {
                ar_w_item.splice(i, 1);
                break;
            }

        $(this.element).remove();
    },
    ReID: function () {
        var el = this.options;
        var anItem = el.anItem;

        var nid = hex_md5(Math.uuid(32, 16));

        trans_ids[anItem.id] = nid;

        if (anItem.init_id == undefined)
            anItem.init_id = anItem.id;
        else {
            trans_ids[anItem.init_id] = nid;
        }

        anItem.id = nid;

        SetEditForm($("#pn_w_item_" + el.id));
    },
    Save: function () {
        var el = this.options;
        var PrefixId = "_" + el.id;
        var anItem = el.anItem;
        var data = {};

        if (cdb != 3) {
            data.id = anItem.id;
        }

        bValid = false;

        if (!checkLength($("#ew_item" + PrefixId + "_description"), "", 1, 10000)) return;
        data.description = lastCheckValue;

        if (!tenderType.includes("landSell") && !tenderType.includes("landRental") && !tenderType.includes("landArrested")) {
            if (!checkfloat($("#ew_item" + PrefixId + "_quantity"), 0, 1000000000000.0)) return;
            data.quantity = lastCheckValue;


            if (cdb == 1)
                data.quantity = Math.round(data.quantity);
            else if (is_privatization)
                data.quantity = Math.round(data.quantity * 10000) / 10000;
            else
                data.quantity = Math.round(data.quantity * 1000) / 1000;
        }
        data.unit = {};
        if (!checkSelect($("#slw_item" + PrefixId + "_unit_code"), arrLang[0][lang][963])) return;
        data.unit.code = lastCheckValue;

        if (!withPublic || cdb != 3)
            data.unit.name = d_units[data.unit.code]["name_uk"];

        if (!tenderType.includes("landSell") && !tenderType.includes("landRental") && !tenderType.includes("landArrested")) {
            data.classification = {};
            if ($("#ew_item" + PrefixId + "_classification_id").prop("tagName").toLowerCase() == 'div') {
                if (!checkLength_div($("#ew_item" + PrefixId + "_classification_id"), "", 0, 1000)) return;
            } else {
                if (!checkLength($("#ew_item" + PrefixId + "_classification_id"), "", 0, 1000)) return;
            }
            data.classification.id = lastCheckValue;

            description = $("#tw_item" + PrefixId + "_classification_description").text();
            if (description.length == 0) {
                updateTips(arrLang[0][lang][964], "Y");
                return false;
            }

            if (!withPublic || cdb != 3)
                data.classification.description = description;

            if (cdb == 1 || cdb == 3)
                data.classification.scheme = "CAV";
            else {
                if (data.classification.id.substr(3, 1) == "0" && tenderType != "renewables") {
                    updateTips(arrLang[0][lang][965], "Y");
                    return false;
                }

                data.classification.scheme = (d_cav_v2[data.classification.id] != undefined ? "CAV-PS" : "CPV");
            }
        }
        if (tenderType == "nadra") {
            if (!strStartsWith(data.classification.id, "09") && !strStartsWith(data.classification.id, "14") &&
                !strStartsWith(data.classification.id, "15981") && !strStartsWith(data.classification.id, "411") &&
                !strStartsWith(data.classification.id, "76")) {
                updateTips("Для Продажу дозволів на користування надрами повинно бути вказано основну класифікацію \"09\", \"14\", \"15981\", \"411\", \"76\".", "Y");
                return false;
            }

            if (data.unit.code != "H87" && data.unit.code != "MTQ" && data.unit.code != "MTK" && data.unit.code != "KMT") {
                updateTips("Для Продажу дозволів на користування надрами повинно бути вказано тільки \"штуки\", \"метри кубічні\", \"метри квадратні\", \"кілометри\" ", "Y");
                return false;
            }
        }

        if (tenderType == "renewables") {
            if (false && data.classification.id != "09300000-2") {
                updateTips("Для Процедура розподілу квот повинно бути вказано основну класифікацію \"09300000-2\".", "Y");
                return false;
            }

            if (data.unit.code !== "KWT") {
                updateTips("Для Процедура розподілу квот повинно бути вказано тільки \"КВт\" ", "Y");
                return false;
            }

            data.unit.code = "KWT";
        }

        if (tenderType.includes('legitimatePropertyLease')) {
            data.itemType = $("#itemType" + PrefixId).val();
        }

        if (tenderType == "timber") {
            if (!strStartsWith(data.classification.id, "0341")) {
                updateTips("Для продажу деревини повинно бути вказано тільки основну класифікацію групи \"0341\".", "Y");
                return false;
            }

            if (data.unit.code !== "MTQ") {
                updateTips("Для продажу деревини повинно бути вказано тільки \"метри кубічні\" ", "Y");
                return false;
            }
        }

        if (tenderType == "rent" || is_privatization && $("#slw_item" + PrefixId + "_additionalClassifications_scheme").val() != "NONE") {
            data.additionalClassifications = [];

            _classification = {};
            if (!checkLength($("#ew_item" + PrefixId + "_additionalClassifications_id"), "", 1, 1000)) return;
            _classification.id = lastCheckValue;

            if (tenderType == "rent" && _classification.id != "PA01-7") {
                updateTips("Для оренди повинно бути вказано додаткову класифікацію \"PA01-7\"", "Y");
                return false;
            }

            description = $("#tw_item" + PrefixId + "_additionalClassifications_description").text();

            if (!withPublic || cdb != 3)
                _classification.description = description;

            _classification.scheme = (tenderType == "rent" ? "CPVS" : $("#slw_item" + PrefixId + "_additionalClassifications_scheme").val());

            data.additionalClassifications.push(_classification);
        }

        if (tenderType == "rent" && auctionType == "dgfOtherAssets") {
            rent_MinDate = Today();
            rent_MinDate.setYear(rent_MinDate.getFullYear() - 1);

            rent_MaxDate = Today();
            rent_MaxDate.setYear(rent_MaxDate.getFullYear() + 51);

            if ($("#dtpw_item" + PrefixId + "_contractPeriod_startDate_Date").val() > ""
                || $("#dtpw_item" + PrefixId + "_contractPeriod_endDate_Date").val() > "") {
                contractPeriod = {};
                if ($("#dtpw_item" + PrefixId + "_contractPeriod_startDate_Date").val() > "") {
                    if (!checkDate($("#dtpw_item" + PrefixId + "_contractPeriod_startDate_Date"), "", rent_MinDate, rent_MaxDate)) return;
                    contractPeriod.startDate = getISO_datetime(lastCheckValue, "00:00", cdb == 3);;
                }

                if ($("#dtpw_item" + PrefixId + "_contractPeriod_endDate_Date").val() > "") {
                    if (!checkDate($("#dtpw_item" + PrefixId + "_contractPeriod_endDate_Date"), "", rent_MinDate, rent_MaxDate)) return;
                    contractPeriod.endDate = getISO_datetime(lastCheckValue, "00:00", cdb == 3);;
                }

                data.contractPeriod = contractPeriod;
            }
        }

        if (is_privatization && $("#slw_item" + PrefixId + "_additionalClassifications_scheme").val() != "NONE") {
            data.additionalClassifications = [];

            _classification = {};
            if (!checkLength($("#ew_item" + PrefixId + "_additionalClassifications_id"), "", 1, 1000)) return;
            _classification.id = lastCheckValue;

            _classification.description = $("#tw_item" + PrefixId + "_additionalClassifications_description").text();

            _classification.scheme = (tenderType == "comercial" ? "CPVS" : $("#slw_item" + PrefixId + "_additionalClassifications_scheme").val());

            data.additionalClassifications.push(_classification);
        }

        if (member_type == "907" && cdb == 2) {
            if (data.additionalClassifications == undefined)
                data.additionalClassifications = [];

            _classification = {};
            _classification.id = "DA04-3";
            _classification.description = "Приватний";
            _classification.scheme = "CPVS";

            data.additionalClassifications.push(_classification);
        } else if (tenderType == "timber") {
            if (data.additionalClassifications == undefined)
                data.additionalClassifications = [];

            _classification = {};
            _classification.id = "QB49-3";
            _classification.scheme = "CPVS";

            if (cdb == 2)
                _classification.description = "З питань лісового господарства";

            data.additionalClassifications.push(_classification);
        }
        else if (member_type == "912") {
            if (data.additionalClassifications == undefined)
                data.additionalClassifications = [];

            _classification = {};
            _classification.id = "QB29-3";
            _classification.description = "З питань законодавства у сфері нерухомості";
            _classification.scheme = "CPVS";

            data.additionalClassifications.push(_classification);
        }

        if (tenderType_for_additionalClassification_cpvs.some(type => tenderType.includes(type)) && $("#additionalClassifications" + PrefixId + "_cpvs").val() != null) {
            if (!tenderType.includes("bankRuptcy")) {
                if (data.additionalClassifications == undefined) {
                    data.additionalClassifications = [];
                }

                for (var i = 0; i < $("#additionalClassifications" + PrefixId + "_cpvs").val().length; i++) {
                    let _classification = {};
                    _classification.id = $("#additionalClassifications" + PrefixId + "_cpvs").val()[i];
                    _classification.scheme = "CPVS";
                    data.additionalClassifications.push(_classification);
                }
            }
        }

        if (tenderType_for_additionalClassification_cvzu.some(type => tenderType.includes(type)) && $("#additionalClassifications" + PrefixId + "_cvzu").val() != null) {
            if (data.additionalClassifications == undefined) {
                data.additionalClassifications = [];
            }

            for (var i = 0; i < $("#additionalClassifications" + PrefixId + "_cvzu").val().length; i++) {
                let _classification = {};
                _classification.id = $("#additionalClassifications" + PrefixId + "_cvzu").val()[i];
                _classification.scheme = "CVZU";
                data.additionalClassifications.push(_classification);
            }
        }

        if (tenderType_for_additionalClassification_kvtspz.some(type => tenderType.includes(type)) && $("#additionalClassifications" + PrefixId + "_kvtspz").val() != null) {
            if (data.additionalClassifications == undefined) {
                data.additionalClassifications = [];
            }

            let _classification = {};
            _classification.id = $("#additionalClassifications" + PrefixId + "_kvtspz").val();
            _classification.scheme = "kvtspz";

            data.additionalClassifications.push(_classification);
        }

        var need_address = false;

        if (cdb == 2) {
            var d_check = (data.classification.scheme == "CAV-PS" ? d_check_cav : d_check_cpv)
            if (d_check.indexOf(data.classification.id) == -1)
                need_address = true;
        } else if (tenderType == "renewables")
            need_address = true;

        address = {};

        if (!checkLength($("#ew_item" + PrefixId + "_address_countryName"), "Країна", (need_address ? 5 : 0), 1000)) return;
        address.countryName = lastCheckValue;

        if (!checkLength($("#ew_item" + PrefixId + "_address_region"), "", (need_address ? 1 : 0), 1000)) return;
        address.region = lastCheckValue;

        if (!checkLength($("#ew_item" + PrefixId + "_address_locality"), "", (need_address && tenderType != "nadra" ? 1 : 0), 1000)) return;
        address.locality = lastCheckValue;

        if (!checkLength($("#ew_item" + PrefixId + "_address_postalCode"), "", 0, 10)) return;
        address.postalCode = lastCheckValue;

        if (lastCheckValue != '' && tenderType != "nadra"
            && !checkRegexp($("#ew_item" + PrefixId + "_address_postalCode"), /^\d{5}$/, arrLang[0][lang][970])) return;

        if (!checkLength($("#ew_item" + PrefixId + "_address_streetAddress"), "", (need_address && tenderType != "nadra" ? 1 : 0), 1000)) return;
        address.streetAddress = lastCheckValue;

        if (cdb == 3 && (tenderType.includes("landSell") || tenderType.includes("landRental")
            || tenderType.includes("landArrested") || tenderType.includes('legitimatePropertyLease')
            || tenderType.includes('basicSell') || tenderType.includes('alienation')
            || tenderType.includes('commercialSell') || tenderType.includes('bankRuptcy')
            || tenderType.includes('simpleSell') || tenderType.includes("regulationsPropertyLease")
            || tenderType.includes("commercialPropertyLease") || tenderType.includes("nonperformingLoans"))) {
            if ($("#ew_item" + PrefixId + "_address_addressID").val() != "") {
                address.addressID = { 'id': $("#ew_item" + PrefixId + "_address_addressID").val(), "scheme": "koatuu" };
            }
            else {
                if (!tenderType.includes('legitimatePropertyLease')) {
                    updateTips("Оберіть значенння з КОАТУУ.", "Y");
                    return;
                }
            }
        }

        if (cdb != 3 || tenderType.includes('legitimatePropertyLease') || tenderType.includes("landSell")
            || tenderType.includes("landRental") || tenderType.includes("landArrested")
            || tenderType.includes('basicSell') || tenderType.includes('regulationsPropertyLease')
            || tenderType.includes('commercialPropertyLease') || tenderType.includes('alienation')
            || tenderType.includes('commercialSell') || tenderType.includes('bankRuptcy')
            || tenderType.includes('simpleSell') || tenderType.includes('nonperformingLoans')) {
            data.location = {};
            if (!checkLength($("#ew_item" + PrefixId + "_location_latitude"), "", 0, 20)) return;
            if (lastCheckValue.length > 0) {
                if (!checkfloat($("#ew_item" + PrefixId + "_location_latitude"), 0, 1000.0)) return;
            }
            data.location.latitude = lastCheckValue.toString();

            if (!checkLength($("#ew_item" + PrefixId + "_location_longitude"), "", 0, 20)) return;
            if (lastCheckValue.length > 0) {
                if (!checkfloat($("#ew_item" + PrefixId + "_location_longitude"), 0, 1000.0)) return;
            }

            data.location.longitude = lastCheckValue.toString();

            if (!checkLength($("#ew_item" + PrefixId + "_location_elevation"), "", 0, 20)) return;
            if (lastCheckValue.length > 0) {
                if (!checkfloat($("#ew_item" + PrefixId + "_location_elevation"), 0, 1000.0)) return;
            }

            data.location.elevation = lastCheckValue.toString();
        }

        if ((tenderType.includes('basicSell') || tenderType.includes('regulationsPropertyLease')
            || tenderType.includes('commercialPropertyLease') || tenderType.includes('alienation')
            || tenderType.includes('commercialSell') || tenderType.includes('bankRuptcy')
            || tenderType.includes('nonperformingLoans'))
            && data.classification.id.substr(0, 2) == "04"
            && (data.location.latitude == "" || data.location.longitude == "" || data.location.elevation == "")) {
            updateTips("Заповнення значень 'Широта' і 'Довгота' обов'язкове. Оберіть місцезнаходження на карті або введіть координати вручну" + NeedDocuments, "Y");
            return;
        }

        if (is_privatization) {
            data.registrationDetails = {};

            data.registrationDetails.status = $("#slw_item" + PrefixId + "_registrationDetails_status").val();

            if (data.registrationDetails.status == "complete") {
                if (!isDebugMode || $("#dtpw_item" + PrefixId + "_registrationDetails_registrationDate").val() != "") {
                    if (!checkDate($("#dtpw_item" + PrefixId + "_registrationDetails_registrationDate"), "", dMinDate, Today())) return;
                    data.registrationDetails.registrationDate = getISO_datetime(lastCheckValue, "00:00", cdb == 3);;
                }

                if (!isDebugMode || $("#dtpw_item" + PrefixId + "_registrationDetails_registrationID").val() != "") {
                    if (!checkLength($("#ew_item" + PrefixId + "_registrationDetails_registrationID"), "", 0, 200)) return;
                    data.registrationDetails.registrationID = lastCheckValue
                }
            }
        }

        bValid = true;

        if (tenderType == "timber") {
            var _properties = getFormJSONAtId($("#pn_itemPropertiesPlace" + PrefixId));
            if (!bValid)
                return;

            if (cdb == 3) {
                Array.prototype.push.apply(data.additionalClassifications
                    , getClassificationsOnProperty(_properties
                        , "timberSortment,timberSpecies,timberClass,timberStorage,timberDiameter,timberProductionYear,timberProductionQuarter"));

                timberLength = ""; st_value = "";
                if ((st_value = _properties["timberLengthMin"]) != undefined) {
                    st_value = ("" + st_value).replace(".", ",");
                    if (st_value.indexOf(",") == -1)
                        st_value += ",0";
                    timberLength += st_value;
                }

                timberLength += " - ";

                if ((st_value = _properties["timberLengthMax"]) != undefined) {
                    st_value = ("" + st_value).replace(".", ",");
                    if (st_value.indexOf(",") == -1)
                        st_value += ",0";
                    timberLength += st_value;
                }

                if (timberLength.length > 3)
                    data.additionalClassifications.push({ scheme: "timberLength", id: timberLength });

                if (_properties["unitValue"] != undefined)
                    data.unitValue = { currency: "UAH", amount: _properties["unitValue"] }
            }
            else
                data.schema_properties = { code: "0341", version: "001", properties: _properties }
        }

        if (tenderType == "nadra" && cdb == 3) {
            var _properties = getFormJSONAtId($("#pn_itemPropertiesPlace" + PrefixId));
            if (!bValid)
                return;

            data.additionalClassifications = getClassificationsOnProperty(_properties, "subsoilUsageType");
        }

        if (cdb == 3) {
            address.countryName = { uk_UA: address.countryName, en_US: "" };
            address.region = { uk_UA: address.region, en_US: "" };
            address.locality = { uk_UA: address.locality, en_US: "" };
            address.streetAddress = { uk_UA: address.streetAddress, en_US: "" };

            data.description = { uk_UA: data.description };

            if (!withPublic) {
                data.unit.name = { uk_UA: data.unit.name, en_US: "", ru_RU: "" };
                if (!tenderType.includes("landSell") && !tenderType.includes("landRental") && !tenderType.includes("landArrested")) {
                    data.classification.description = { uk_UA: data.classification.description, en_US: "", ru_RU: "" };
                }
                if (data.additionalClassifications != undefined)
                    for (var i = 0; i < data.additionalClassifications.length; i++) {
                        data.additionalClassifications[i].description = { uk_UA: data.additionalClassifications[i].description, en_US: "", ru_RU: "" };
                    }
            }
        }

        data.address = address;

        if (cdb3_dgf) {
            var dgf_propertis = get_dgf_propertis($("#itemProps" + PrefixId + "_" + dgf_itemProps));
            if (Object.keys(dgf_propertis).length > 0) {
                data.itemProps = dgf_propertis;
            }
        }

        if (tenderType.includes('legitimatePropertyLease')) {
            var rent_propertis = get_rent_propertis($("#pnw_item" + PrefixId + "_" + $("#itemType" + PrefixId).val()), $("#itemType" + PrefixId).val(), PrefixId);
            let itemProps = "";
            if (Object.keys(rent_propertis).length > 0) {
                if ($("#itemType" + PrefixId).val() == "realEstate") {
                    itemProps = "reProps";
                    if (data.unit.code != "MTK") {
                        updateTips("Допустимі 'Одиниці виміру' \"метри квадратні\" ", "Y");
                        bValid = false;
                    }
                    delete data.quantity;
                } else if ($("#itemType" + PrefixId).val() == "jointPropertyComplex") {
                    itemProps = "jpcProps"
                    if (data.unit.code != "H87" && data.unit.code != "MTK") {
                        updateTips("Допустимі 'Одиниці виміру' \"штуки\" або \"метри квадратні\" ", "Y");
                        bValid = false;
                    }
                } else if ($("#itemType" + PrefixId).val() == "vehicle") {
                    itemProps = "vehicleProps"
                    if (data.unit.code != "H87") {
                        updateTips("Допустимі 'Одиниці виміру' \"штуки\" ", "Y");
                        bValid = false;
                    }
                }

                if (itemProps != "") {
                    data[itemProps] = rent_propertis;
                }
            }

            var registrationDetails_prop = get_registrationDetails_propertis(PrefixId);

            if (bValid) {
                data.registrationDetails = registrationDetails_prop;
            } else {
                return;
            }

            delete data.additionalClassifications;

            if (data.itemType == "realEstate" && withPublic) {
                delete data.unit;
            }
        }

        if (tenderType.includes("landSell") || tenderType.includes("landRental")) {
            data["itemProps"] = get_land_propertis($("#land" + PrefixId + "_itemProps"), PrefixId);

            if (!bValid) {
                return false;
            }

            if (withPublic) {
                delete data.unit;
            }
        }

        if (tenderType.includes("landArrested")) {
            data["itemProps"] = get_land_propertis($("#land" + PrefixId + "_itemProps"), PrefixId);

            if (!bValid) {
                return false;
            }

            if (withPublic) {
                delete data.unit;
            }
        }

        if (tenderType.includes("basicSell") || tenderType.includes("alienation")
            || tenderType.includes("commercialSell") || tenderType.includes("simpleSell")) {
            let basicSell_props = get_basicSell_propertis($("#basicSell_itemProps" + PrefixId + "_" + $("#basicSell_itemProps" + PrefixId + "_type").text()), PrefixId, $("#basicSell_itemProps" + PrefixId + "_type").text());
            if (Object.keys(basicSell_props).length != 0) {
                data["itemProps"] = basicSell_props
            }
        }

        if (tenderType.includes("bankRuptcy")) {
            let bankRuptcy_props = get_bankRuptcy_propertis($("#bankRuptcy_itemProps" + PrefixId + "_" + $("#bankRuptcy_itemProps" + PrefixId + "_type").text()), PrefixId, $("#bankRuptcy_itemProps" + PrefixId + "_type").text());
            if (Object.keys(bankRuptcy_props).length != 0) {
                data["itemProps"] = bankRuptcy_props
            }
        }

        if (tenderType.includes("regulationsPropertyLease")) {
            let regulationsPropertyLease_props = get_regulationsPropertyLease_propertis($("#regulationsPropertyLease_itemProps" + PrefixId + "_" + $("#regulationsPropertyLease_itemProps" + PrefixId + "_type").text()), PrefixId, $("#regulationsPropertyLease_itemProps" + PrefixId + "_type").text());
            if (Object.keys(regulationsPropertyLease_props).length != 0) {
                data["itemProps"] = regulationsPropertyLease_props
            }
        }

        if (tenderType.includes("nonperformingLoans")) {
            let nonperformingLoans_props = get_nonperformingLoans_propertis($("#nonperformingLoans_itemProps" + PrefixId + "_" + $("#nonperformingLoans_itemProps" + PrefixId + "_type").text()), PrefixId, $("#nonperformingLoans_itemProps" + PrefixId + "_type").text());
            if (Object.keys(nonperformingLoans_props).length != 0) {
                data["itemProps"] = nonperformingLoans_props
            }

            if ($("#item_value" + PrefixId).val() != "") {
                data.value = {
                    amount: parseFloat($("#item_value" + PrefixId).val()),
                    currency: "UAH"
                }
            }

            let overdueDuration_y, overdueDuration_m, overdueDuration_d;

            if ($("#item_overdueDuration_y" + PrefixId).val() != "") {
                if (!checkInt($("#item_overdueDuration_y" + PrefixId), 0, 50)) return;
                overdueDuration_y = lastCheckValue;
            }

            if ($("#item_overdueDuration_m" + PrefixId).val() != "") {
                if (!checkInt($("#item_overdueDuration_m" + PrefixId), 0, 12)) return;
                overdueDuration_m = lastCheckValue;
            }

            if ($("#item_overdueDuration_d" + PrefixId).val() != "") {
                if (!checkInt($("#item_overdueDuration_d" + PrefixId), 0, 31)) return;
                overdueDuration_d = lastCheckValue;
            }

            if (overdueDuration_y != undefined && overdueDuration_m != undefined && overdueDuration_d != undefined) {
                data.overdueDuration = "P" + overdueDuration_y + "Y" + overdueDuration_m + "M" + overdueDuration_d + "D";
            }
        }

        if (tenderType.includes("commercialPropertyLease")) {
            let commercialPropertyLease_props = get_commercialPropertyLease_propertis($("#commercialPropertyLease_itemProps" + PrefixId + "_" + $("#commercialPropertyLease_itemProps" + PrefixId + "_type").text()), PrefixId, $("#commercialPropertyLease_itemProps" + PrefixId + "_type").text());
            if (Object.keys(commercialPropertyLease_props).length != 0) {
                data["itemProps"] = commercialPropertyLease_props
            }
        }

        if (tenderType.includes("basicSell") || tenderType.includes("alienation")
            || tenderType.includes("commercialSell") || tenderType.includes("bankRuptcy")
            || tenderType.includes("regulationsPropertyLease") || tenderType.includes("commercialPropertyLease")
            || tenderType.includes("nonperformingLoans")) {
            var registrationDetails_prop = get_registrationDetails_propertis(PrefixId);

            if (bValid) {
                data.registrationDetails = registrationDetails_prop;
            } else {
                return;
            }
        }

        if (!bValid) {
            return;
        }

        return data;
    }
})


function AddEmpty_Tender_item(_panel) {
    var _el = { is_new: true };

    _el.address_countryName = oFormRecord.PE_address_countryName;
    _el.address_postalCode = oFormRecord.PE_address_postalCode;
    if (cdb != 3) {
        _el.address_region = oFormRecord.PE_address_region;
        _el.address_locality = oFormRecord.PE_address_locality;
    }
    _el.address_streetAddress = oFormRecord.PE_address_streetAddress;

    if (tenderType == "rent") { //&& !isDebugMode     
        _el.additionalClassifications_id = "PA01-7";
        _el.additionalClassifications_description = "Оренда";// VL: no transation   

        //   _el.unit_code = "MTK";    
    } else if (tenderType == "comercial") {//&& !isDebugMode  
        _el.additionalClassifications_id = "DA04-3";
        _el.additionalClassifications_description = 'Приватний';
        _el.unit_code = "MTK";
    } else if (tenderType == "timber") {
        _el.additionalClassifications_id = "QB49-3";
        _el.additionalClassifications_description = 'З питань лісового господарства';
        _el.unit_code = "MTQ";
    } else if (tenderType == "nadra") {
        _el.classification_scheme = "CPV";
        _el.unit_code = 'H87';
        _el.quantity = '1';

        _el.address_postalCode = "00000";
        _el.address_region = "---";
        _el.address_locality = "-";
        _el.address_streetAddress = "-";
    } else if (tenderType == "renewables") {
        _el.classification_scheme = "CPV";
        _el.classification_id = "09300000-2";
        _el.classification_description = "Електрична, теплова, сонячна та атомна енергія";
        _el.unit_code = 'KWT';
    }

    Add_Tender_item(_panel, _el, new_id);

    new_id++;

    Renumber_Tender_item(_panel);

    if (tenderType == "nadra") {
        $("#ew_item" + PrefixId + "_classification_id").text("14212420-0")
        $("#tw_item" + PrefixId + "_classification_description").text("Надра")
    }
}

function CopyEmpty_Tender_item(_panel) {
    var _el = {};

    _el.address_countryName = oFormRecord.PE_address_countryName;
    _el.address_postalCode = oFormRecord.PE_address_postalCode;
    _el.address_region = oFormRecord.PE_address_region;
    _el.address_locality = oFormRecord.PE_address_locality;
    _el.address_streetAddress = oFormRecord.PE_address_streetAddress;

    if (tenderType == "rent") { //&& !isDebugMode     
        _el.additionalClassifications_id = "PA01-7";
        _el.additionalClassifications_description = "Оренда";// VL: no transation   

        //   _el.unit_code = "MTK";    
    } else if (tenderType == "comercial" && !isDebugMode) {
        _el.additionalClassifications_id = "DA04-3";
        _el.additionalClassifications_description = 'Приватний';
        _el.unit_code = "MTK";
    } else if (tenderType == "timber") {
        _el.additionalClassifications_id = "QB49-3";
        _el.additionalClassifications_description = 'З питань лісового господарства';
        _el.unit_code = "MTQ";
    } else if (tenderType == "nadra") {
        _el.classification_scheme = "CPV";
        _el.classification_id = "14212420-0";

        _el.classification_description = "Надра";
        _el.unit_code = 'E50';
        _el.quantity = '1';
        _el.address_postalCode = "00000";
        _el.address_region = "---";
        _el.address_locality = "-";
        _el.address_streetAddress = "-";
    }
    Add_Tender_item(_panel, _el, new_id);

    new_id++;

    Renumber_Tender_item(_panel);

    if (tenderType == "nadra") {
        $("#ew_item" + PrefixId + "_classification_id").text("14212420-0")
    }

    $("#ew_item" + PrefixId + "_description").val($("#ew_item_" + Id_From_Item + "_description").val());
    $("#ew_item" + PrefixId + "_quantity").val($("#ew_item_" + Id_From_Item + "_quantity").val());
    $("#ew_item" + PrefixId + "_classification_id").text($("#ew_item_" + Id_From_Item + "_classification_id").text());
    $("#tw_item" + PrefixId + "_classification_description").text($("#tw_item_" + Id_From_Item + "_classification_description").text());
    $("#slw_item" + PrefixId + "_unit_code").val($("#slw_item_" + Id_From_Item + "_unit_code").val());
    $("#e" + PrefixId + "_4").val($("#e_" + Id_From_Item + "_4").val());
    $("#e" + PrefixId + "_3").val($("#e_" + Id_From_Item + "_3").val());
    $("#e" + PrefixId + "_7").val($("#e_" + Id_From_Item + "_7").val());
    $("#e" + PrefixId + "_8").val($("#e_" + Id_From_Item + "_8").val());
    $("#e" + PrefixId + "_9").val($("#e_" + Id_From_Item + "_9").val());
    $("#e" + PrefixId + "_10").val($("#e_" + Id_From_Item + "_10").val());
    $("#e" + PrefixId + "_12").val($("#e_" + Id_From_Item + "_12").val());
    $("#e" + PrefixId + "_13").val($("#e_" + Id_From_Item + "_13").val());
    $("#sl" + PrefixId + "_5").val($("#sl_" + Id_From_Item + "_5").val());
    $("#sl" + PrefixId + "_6").val($("#sl_" + Id_From_Item + "_6").val());
    $("#sl" + PrefixId + "_1").val($("#sl_" + Id_From_Item + "_1").val());
    $("#sl" + PrefixId + "_2").val($("#sl_" + Id_From_Item + "_2").val());
}

function Add_Tender_item(_panel, _item, _id, el_loc, index) {
    _panel.append(
        $(document.createElement("div"))
            .attr("id", "Tender_item_" + _id)
            .attr("class", "row mt-2 tender_item")
            .Tender_item({ id_container: _panel[0].id, Position: oFormRecord, anItem: _item, id: _id }));
    let currentIndex = (index != undefined ? index : new_id - 1);

    if (similar_procedures) {
        $("#buttonMap_" + currentIndex).show().click(function () {
            checkGetMap(currentIndex, el_loc);

            $("#map_" + currentIndex).show();
            $("#buttonMap_" + currentIndex).hide();
        });
        if (isOwn || idForm == 0) {
            checkGetMap(currentIndex, el_loc);

            $("#buttonMap_" + currentIndex).hide();
            $("#map_" + currentIndex).show();

        }
        if (index != undefined) {
            new_id++
        }
    }
}

function Add_Tender_item_withoutAuction(_panel, _item, _id, el_loc, index) {
    award_withoutAuction = true;
    _panel.append(
        $(document.createElement("div"))
            .attr("id", "Tender_item_" + _id)
            .attr("class", "row mt-2 tender_item")
            .Tender_item({ id_container: _panel[0].id, Position: oFormRecord, anItem: _item, id: _id }));
    award_withoutAuction = false;

    checkGetMap(_id, el_loc);

    $("#map_" + _id).show();
}

function Renumber_Tender_item(_panel) {
    var j = 1;

    var _id_container = _panel[0].id;

    for (var i = 0; i < ar_w_item.length; i++) {
        if (ar_w_item[i].options.id_container == _id_container) {

            $("#pn_w_item" + "_" + ar_w_item[i].options.id, _panel).wSHdiv('SetTitle', (is_privatization ? "" : arrLang[0][lang][972]) + "№ " + j, _panel);

            j++;
        }
    }
}

function change_unit_code(sl_id) {
    var descr_id = sl_id.replace("slw_", "tw_");

    $("#" + descr_id).text($("#" + sl_id).val());
}

function slPosition_additionalClassifications_scheme_onchange(obj, panel) {
    v_dk_dict = $("#sl" + obj + "_additionalClassifications_scheme", panel).val();

    $("#t" + obj + "_additionalClassifications_scheme", panel).text(v_dk_dict);

    _ac_el = $("#e" + obj + "_additionalClassifications_id", panel);
    _ac_el_desc = $("#t" + obj + "_additionalClassifications_description", panel);

    if (v_dk_dict == "NONE" || v_dk_dict == "specialNorms") {
        _ac_el.val("");
        _ac_el_desc.text("");
    }
    else {
        var fun_SelectItems;

        switch (v_dk_dict) {
            case "dk018": fun_SelectItems = SelectItemsOn_dk018; break;
            case "CPVS": fun_SelectItems = SelectItemsOn_cpvs; break;
        }

        set_AC_CPV_DKPP(_ac_el, fun_SelectItems, _ac_el_desc);
    }
}

function slw_item_registrationDetails_status_onchange(obj, panel) {

    registrationDetails_status = $("#sl" + obj + "_registrationDetails_status", panel).val();

    if (registrationDetails_status == "complete")
        $(".registrationDetails", $("#pn_" + obj, panel)).show();
    else
        $(".registrationDetails", $("#pn_" + obj, panel)).hide();
}

function slPosition_property_type_onchange(obj, panel, on_init) {
    property_type = $("#sl" + obj + "_property_type", panel).val();
    var _scheme = "", _scheme_item = "";

    if (property_type == "all")
        return;

    if (spfu_classifier[property_type].classifier.length > 1) {
        key_search_mask = "";
        $("#sl" + obj + "_additionalClassifications_scheme", panel).val(_scheme = "NONE");
        $("#e" + obj + "_additionalClassifications_id", panel).val("");
        $("#t" + obj + "_additionalClassifications_description", panel).text("");

        _scheme_item = GetItemById(d_dict, _scheme, "privatization_AC");

        $("#tsl" + obj + "_additionalClassifications_scheme", panel).text(_scheme_item.name);

        return;
    }

    v_dk_dict = spfu_classifier[property_type].classifier[0];

    if (spfu_classifier[property_type].detailedClassification) {
        key_search_mask = spfu_classifier[property_type].classifierId[0];
        var i = 2;
        for (; i < key_search_mask.length; i++)
            if (key_search_mask[i] == "0") {
                key_search_mask = key_search_mask.substr(0, i);
                break;
            }
    }
    else {
        key_search_mask = "";

        var _id = spfu_classifier[property_type].classifierId;
        $("#e" + obj + "_classification_id", panel).val(_id);
        $("#t" + obj + "_classification_description", panel).text(d_cav_cpv[_id]);
    }

    if (spfu_classifier[property_type].additionalClassifier != "") {
        $("#sl" + obj + "_additionalClassifications_scheme", panel).val(_scheme = "dk018");
        var _id = spfu_classifier[property_type].additionalClassifierId;
        $("#e" + obj + "_additionalClassifications_id", panel).val(_id);
        $("#t" + obj + "_additionalClassifications_description", panel).text(d_dk018[_id]);
    }
    else {
        $("#sl" + obj + "_additionalClassifications_scheme", panel).val(_scheme = "NONE");
        $("#e" + obj + "_additionalClassifications_id", panel).val("");
        $("#t" + obj + "_additionalClassifications_description", panel).text("");
    }

    _scheme_item = GetItemById(d_dict, _scheme, "privatization_AC");

    $("#tsl" + obj + "_additionalClassifications_scheme", panel).text(_scheme_item.name);
}

function get_property_type_value(anItem) {

    if (anItem.classification == undefined)
        return undefined;
    dk018_id = "";

    if (anItem.additionalClassifications != undefined)
        for (var j = 0; j < anItem.additionalClassifications.length; j++)
            if (anItem.additionalClassifications[j].scheme == "dk018") {
                dk018_id = anItem.additionalClassifications[j].id;
                break;
            }

    if (dk018_id != "") {
        for (var propertyName in spfu_classifier)
            if (spfu_classifier[propertyName].additionalClassifier == "DK018"
                && spfu_classifier[propertyName].additionalClassifierId == dk018_id)
                return propertyName;
    }

    for (var propertyName in spfu_classifier)
        if (spfu_classifier[propertyName].classifierId[0] == anItem.classification.id)
            return propertyName;

    return "900";
}

function get_property_type(anItem) {
    dk018_id = "";

    if (anItem.additionalClassifications != undefined)
        for (var j = 0; j < anItem.additionalClassifications.length; j++)
            if (anItem.additionalClassifications[j].scheme == "dk018") {
                dk018_id = anItem.additionalClassifications[j].id;
                break;
            }


    if (dk018_id != "") {
        for (var propertyName in spfu_classifier)
            if (spfu_classifier[propertyName].additionalClassifier == "DK018"
                && spfu_classifier[propertyName].additionalClassifierId == dk018_id) {
                return spfu_classifier[propertyName].title;
            }
    }

    for (var propertyName in spfu_classifier)
        if (spfu_classifier[propertyName].classifierId[0] == anItem.classification.id) {
            return spfu_classifier[propertyName].title;
        }

    return spfu_classifier["900"].title;
}

function change_classification_code(PrefixId) {
    classification = $("#ew_item" + PrefixId + "_classification_id").val();
}

function Add_timberProperties(obj, PrefixId, context) {
    var str = pn_timberProperties___rand_id.outerHTML, _rand_id = rand_id++;

    place = $("#pn_itemPropertiesPlace" + PrefixId, context);

    if (place.text() != "")
        return;

    str = str.replace(new RegExp("__rand_id", 'g'), _rand_id);

    place.append(str);
    obj_place = $("#pn_timberProperties_" + _rand_id, place);

    SetDicSearchOption(d_timber_species, $("[data-atid='species']", obj_place), -1, false, "Виберіть значення", undefined, "code", "breed");
    SetDicSearchOption(d_dict, $("[data-atid='class']", obj_place), "timber_class", false, "Виберіть значення");

    SetRangeOption($("[data-atid='productionDate']", obj_place), 2000, 2100, "Виберіть значення");
    SetRangeOption($("[data-atid='quarter']", obj_place), 1, 4, "Виберіть значення");

    if (obj != undefined)
        SetValuesAtId("assortment,species,class,storage,productionDate,quarter,minDiameter,maxDiameter,minLength,maxLength,itemPrice,lotPrice"
            , obj, obj_place);
}

function Get_timberProperties(obj) {
    var data = getFormJSONAtId(obj);

    if (!bValid)
        return;

    return data;
}

function getClassificationsOnProperty(_properties, names) {
    var _ar = [];

    var names = names.split(",");

    for (var i = 0; i < names.length; i++) {
        if (_properties[names[i]] != undefined)
            _ar.push({ scheme: names[i], id: _properties[names[i]] });
    }

    return _ar;
}

function getPropertyOnClassifications(Classifications) {
    var _properties = {};

    for (var i = 0; i < Classifications.length; i++)
        _properties[Classifications[i].scheme] = Classifications[i].id

    return _properties;
}

function sl_timberSortment_onchange(PrefixId) {
    obj_place = $("#pn_itemPropertiesPlace" + PrefixId);

    timberSortment = $("[data-atid='timberSortment']", obj_place).val();
    relatedTo = "timberSortment." + timberSortment;

    SetCBD3DicOption(d_timberClass, $("[data-atid='timberClass']", obj_place), true, relatedTo);
    SetCBD3DicOption(d_timberDiameter, $("[data-atid='timberDiameter']", obj_place), true, relatedTo);
}

var KOATUU_item_id, KOATUU_key, KOATUU_region, need_init__dgKOATUU = true, d_koatuu_region = {}, addressID = [];

function selectKOATUU(id) {
    KOATUU_item_id = id;

    if (d_koatuu == undefined)
        jQuery.getJSON("Js/koatuu.json?v=" + version, function (data) { d_koatuu = data; show_dgKOATUU(); });
    else
        show_dgKOATUU();
}

function show_dgKOATUU() {
    item_region = $("#tew_item_" + KOATUU_item_id + "_address_region").text();
    item_locality = $("#tew_item_" + KOATUU_item_id + "_address_locality").text();

    var dg = $("#dgKOATUU");
    dg.modal("show");
    enSelect = $("#sl_region", dg);
    $("#e_locality", dg).val(item_locality);

    enSelect.html('<option value="all">Виберіть значення</option>');

    for (var key in d_koatuu)
        if ((key.substr(2, 8) == "00000000")) {
            name = d_koatuu[key];
            enSelect.append(jQuery('<option value="' + key + '">' + name + '</option>'));

            if (item_region == name) {
                $("#sl_region", dg).val(key);
                $("#t_region_description", dg).text(key);
                KOATUU_region = key.substr(0, 2);
            }
        }
        else if (KOATUU_region == key.substr(0, 2) && item_locality == d_koatuu[key])
            $("#t_locality_description", dg).text(key);

    var _ac_el = $("#e_locality", dg);
    var _ac_el_desc = $("#t_locality_description", dg);

    set_AC_koatuu(_ac_el, SelectItemsOn_koatuu, _ac_el_desc);
}

function set_AC_koatuu(_elem, _source, _elem_desc) {
    _elem.autocomplete({
        source: function (request, response) {
            if (_elem_desc != undefined)
                _elem_desc.html("");
            _source(request, response);
        },
        select: function (event, ui) {
            var sItem = ui.item.label, f_space = sItem.indexOf(' ');

            _elem.val(sItem.substring(f_space + 1));

            if (_elem_desc != undefined)
                _elem_desc.text(sItem.substring(0, f_space));
            return false;
        }
    });

    setAutocompleteDesign_CPV_DKPP(_elem, _elem_desc);
}


function SelectItemsOn_koatuu(request, response) {
    key_search_mask = KOATUU_region;
    ar_SelectItems = [];

    var ret_items = 40, j = 0, pattern = request.term.toLowerCase();
    _dict = d_koatuu;

    for (var key in _dict)
        if ((key_search_mask == "" || strStartsWith(key, key_search_mask))
            && (key.toLowerCase().indexOf(pattern) >= 0 || _dict[key].toLowerCase().indexOf(pattern) >= 0)) {
            ar_SelectItems.push(key + " " + _dict[key]);

            if (ar_SelectItems.length > ret_items)
                break;
        }

    response(ar_SelectItems);
}

function sl_region_onchange() {
    var dg = $("#dgKOATUU");

    key = $("#sl_region", dg).val();

    if (key == "all") {
        KOATUU_region = "";
        $("#t_region_description", dg).text("");
    }
    else {
        $("#t_region_description", dg).text(key);
        KOATUU_region = key.substr(0, 2);

        $("#e_locality", dg).val("");
        $("#t_locality_description", dg).text("");
    }
}

function set_KOATUU() {
    var dg = $("#dgKOATUU");

    arr_Region = {
        '12': 'Дніпропетровська область', '14': 'Донецька область', '18': 'Житомирська область', '21': 'Закарпатська область',
        '23': 'Запорізька область', '26': 'Івано-Франківська область', '32': 'Київська область', '35': 'Кіровоградська область', '01': 'Автономна Республіка Крим',
        '05': 'Вінницька область', '07': 'Волинська область', '44': 'Луганська область', '46': 'Львівська область', '48': 'Миколаївська область', '51': 'Одеська область',
        '53': 'Полтавська область', '56': 'Рівненська область', '59': 'Сумська область', '61': 'Тернопільська область', '63': 'Харківська область', '65': 'Херсонська область',
        '68': 'Хмельницька область', '71': 'Черкаська область', '73': 'Чернівецька область', '74': 'Чернігівська область', '80': 'Київ', '85': 'Севастополь'
    };

    if ($("#t_region_description", dg).text() == "" || $("#t_locality_description", dg).text() == "")
        return;

    item_region = $("#sl_region option:selected", dg).text();
    item_locality = $("#e_locality", dg).val();
    id_koatuu = $("#t_locality_description").text();

    $("#ew_item_" + KOATUU_item_id + "_address_region").val(arr_Region[id_koatuu.substring(0, 2)]);
    $("#tew_item_" + KOATUU_item_id + "_address_region").text(arr_Region[id_koatuu.substring(0, 2)]);
    $("#ew_item_" + KOATUU_item_id + "_address_locality").val(item_locality);
    $("#tew_item_" + KOATUU_item_id + "_address_locality").text(item_locality);
    $("#ew_item_" + KOATUU_item_id + "_address_addressID").val(id_koatuu);

    dg.modal("hide");

}

function get_registrationDetails_propertis(id) {
    let data = {};
    dMinDate = sISO2date("19000101");
    dMaxDate = sISO2date("21000101");

    data.registrationStatus = $("#registrationStatus" + id).val();

    if (data.registrationStatus == "oldRegistration" || data.registrationStatus == "properlyRegistered") {
        if ($("#registrationID" + id).val() != "") {
            data.registrationID = $("#registrationID" + id).val();
        } else {
            updateTips("Вкажіть номер запису реєстрації", "Y");
            bValid = false;
        }

        if (!checkDate($("#registrationDate" + id), "", dMinDate, dMaxDate)) return;
        let _date = lastCheckValue;

        if (!checkTime($("#registrationDate_Time" + id))) {
            updateTips("Вкажіть час дати реєстрації", "Y");
            bValid = false;
        }

        data.registrationDate = getISO_datetime(_date, lastCheckValue, cdb == 3);
    }

    return data;
}

function get_item_type(id) {
    let item_type = "";

    if (id.substr(0, 2) == "04" || id.substr(0, 2) == "05" || id.substr(0, 2) == "06" || id.substr(0, 2) == "34" || id.substr(0, 2) == "03" || id.substr(0, 2) == "15") {
        switch (id.substr(0, 2)) {
            case "04":
                item_type = "RealEstateProps";
                break;
            case "05":
                item_type = "JointPropertyComplexProps";
                break;
            case "06":
                item_type = "LandProps";
                break;
            case "34":
                item_type = "VehicleProps";
                break;
            default:
                item_type = "";
                break;
        }
    } else {
        switch (id) {
            case "07121000-3":
                item_type = "RealEstateProps";
                break;
            case "07122000-0":
                item_type = "JointPropertyComplexProps";
                break;
            case "07123000-7":
                item_type = "LandProps";
                break;
            case "07126000-8":
                item_type = "VehicleProps";
                break;
            case "07221000-4":
                item_type = "RealEstateProps";
                break;
            case "07222000-1":
                item_type = "JointPropertyComplexProps";
                break;
            case "07223000-8":
                item_type = "LandProps";
                break;
            case "07226000-9":
                item_type = "VehicleProps";
                break;
            default:
                item_type = "";
                break;
        }
    }

    return item_type;
}

function set_additionalClassifications(obj, PrefixId, place) {
    let cvzu = [];

    for (var i = 0; i < obj.length; i++) {
        if (obj[i].scheme == "dm") {
            $('#additionalClassifications' + PrefixId, place).val(obj[i].id);
        } else {
            cvzu.push(obj[i].id)
        }
    }

    if (cvzu.length != 0) {
        $("#additionalClassifications" + PrefixId + "_cvzu", place).val(cvzu)
    }
}

function set_additionalClassifications_text() {
    for (var j = 0; j < oFormRecord.assetItems.length; j++) {
        let cvzu_html = "";

        for (var i = 0; i < oFormRecord.assetItems[j].additionalClassifications.length; i++) {
            if (oFormRecord.assetItems[j].additionalClassifications[i].scheme == "CVZU") {
                const cvzu_id = oFormRecord.assetItems[j].additionalClassifications[i].id;
                const cvzu_text = d_cvzu[cvzu_id].uk_UA;
                cvzu_html += `<span class="d-block mb-2"><span class="d-block">${cvzu_id}</span><small class="text-info">${cvzu_text}</small></span>`;
            }
        }

        $("#tadditionalClassifications_" + (j + 1) + "_cvzu").html(cvzu_html);
    }
}

function set_additionalClassifications_text() {
    for (var j = 0; j < oFormRecord.items.length; j++) {
        let cpvs_html = "";
        let cvzu_html = "";
        let kvtspz_html = "";

        for (var i = 0; i < oFormRecord.items[j].additionalClassifications.length; i++) {
            if (oFormRecord.items[j].additionalClassifications[i].scheme == "CPVS") {
                const cpvs_id = oFormRecord.items[j].additionalClassifications[i].id;
                const cpvs_text = d_new_cpvs[cpvs_id].uk_UA;
                cpvs_html += `<span class="d-block mb-2"><span class="d-block">${cpvs_id}</span><small class="text-info">${cpvs_text}</small></span>`;
            }

            if (oFormRecord.items[j].additionalClassifications[i].scheme == "CVZU") {
                const cvzu_id = oFormRecord.items[j].additionalClassifications[i].id;
                const cvzu_text = d_cvzu[cvzu_id].uk_UA;
                cvzu_html += `<span class="d-block mb-2"><span class="d-block">${cvzu_id}</span><small class="text-info">${cvzu_text}</small></span>`;
            }

            if (oFormRecord.items[j].additionalClassifications[i].scheme == "kvtspz") {
                const kvtspz_id = oFormRecord.items[j].additionalClassifications[i].id;
                const kvtspz_text = d_kvtspz[kvtspz_id].uk_UA;
                kvtspz_html += `<span class="d-block mb-2"><span class="d-block">${kvtspz_id}</span><small class="text-info">${kvtspz_text}</small></span>`;
            }
        }

        $("#tadditionalClassifications_" + j + "_cpvs").html(cpvs_html);
        $("#tadditionalClassifications_" + j + "_cvzu").html(cvzu_html);
        $("#tadditionalClassifications_" + j + "_kvtspz").html(kvtspz_html);
    }
};
