function initializeTaskMetadataInputs(urls) {
    $('.ltPoslDog').each(function (index, value) {
        initialiteTypeahead(urls.docTypes, $(value), $(value).nextAll('input').first().val(),
            'id',
            generateRow(
                ["docType", "name"],
                ["docType", "name"],
                ["30%", "70%"]),
            function (items, i, item) {
                items.push({
                    id: item.Id,
                    name: item.Name,
                    docType: item.IdView,
                    row: i,
                    localization: item.Localization
                });
            }, function (item) {
                $(value).nextAll('input').first().val(item.id);
                return { selected: true, value: item.docType };
            }
        );
    });

    $('.ltMNClassification').each(function (index, value) {
        initialiteTypeahead(urls.classifications, $(value), $(value).nextAll('input').first().val(),
            'id',
            generateRow(
                ["description", "code"],
                ["name", "acType"],
                ["80%", "20%"]),
            function (items, i, item) {
                items.push({
                    id: item.AnQid,
                    name: item.AcTypeDesc,
                    acType: item.AcType,
                    row: i,
                    localization: item.Localization
                });
            }, function (item) {
                $(value).nextAll('input').first().val(item.id);
                return { selected: true, value: item.acType };
            }
        );
    });

    $('.ltDobavitelj, .ltKupec').each(function (index, value) {
        initialiteTypeahead(urls.partners, $(value), $(value).nextAll('input').first().val(),
            'id',
            generateRow(
                ["company", "title", "address", "post", "vatNumber"],
                ["id", "name_only", "address", "zip_code", "vat"],
                ["30%", "20%", "20%", "10%", "20%"]),
            function (items, i, item) {
                items.push({
                    id: item.Id,
                    name: i + '|' + (item.Code || '') + '|' + (item.Name || '') + '|' + (item.VAT || ''),
                    name_only: item.Name,
                    vat: item.VAT,
                    isVat: item.isVAT,
                    address: item.Address,
                    complete_address: item.Address + (!item.ZipCode ? "" : ", " + item.ZipCode) + (!item.VAT ? "" : ", " + item.VAT),
                    zip_code: item.ZipCode,
                    row: i,
                    localization: item.Localization
                });
            }, function (item) {
                $(value).nextAll('input').first().val(item.id);
                return { selected: true, value: item.id };
            }
        );
    });

    initialiteTypeahead(urls.workers, $('.ltSubj'), $('.ltSubj').nextAll('input').first().val(),
        'id',
        generateRow(
            ["worker"],
            ["id"],
            ["100%"]),
        function (items, i, item) {
            items.push({
                id: item.Worker,
                row: i,
                localization: item.Localization
            });
        }, function (item) {
            $('.ltSubj').nextAll('input').first().val(item.id);
            return { selected: true, value: item.id };
        }
    );


    $('.ltOddelekAct').typeahead({
        display: 'item.name2',
        source: function (request, response) {
            $.post(urls.departments, { search: request })
                .done(function (data) {
                    var items = [];
                    $.each(data, function (i, item) {
                        items.push({
                            id: item.AcSubject,
                            name: i + '|' + (item.AcSubject || '') + '|' + (item.AcName2 || '') + '|' + (item.AcName3 || ''),
                            name2: item.AcName2,
                            name3: item.AcName3,
                            row: i
                        });
                    });
                    response(items);
                });
        },
        minLength: 0,
        items: 100,
        updater: function (item) {
            $(this.$element[0]).nextAll('input').first().val(item.id);
            return item;
        },
        highlighter: Object,
        displayText: function (item) {
            var row = "";
            var pos = item.row;
            if (pos === 0) {
                row += '<table class="table">';
                row += '<thead><tr class="row">';
                row += '<th width="40%">' + $('#LocDepartment').val()+'</th>';
                row += '<th width="30%">' + $('#LocName').val()+ ' 2</th>';
                row += '<th width="30%">' + $('#LocName').val() + ' 3</th>';
                row += '</tr></thead>';
                row += '<tbody>';
            }
            else {
                row += '<table class="table">';
                row += '<tbody >';
            }
            row += '<tr class="row">';
            row += '<td width="40%">' + item.id + '</td>';
            row += '<td width="30%">' + item.name2 + '</td>';
            row += '<td width="30%">' + item.name3 + '</td>';
            row += '</tr>';
            row += '</tbody></table>';
            return row;
        },
        afterSelect: function (item) {
            this.$element[0].value = item.id;
        }
    });

    $('.typeahead_3').on("click", function () {
        $(this).typeahead('lookup');
    });
}