﻿$(function() {
    $(".country-ac").autocomplete(countries, {
        minChars: 0,
        width: 220,
        scrollHeight: 300,
        scroll: true,
        matchContains: false,
        autoFill: false,

        formatItem: formatCountryItem,
        formatMatch: formatCountryMatch,
        formatResult: formatCountryResult
    }).result(function(event, item) {
        $(this).attr("title", item.Name);
    });
});

function formatCountryItem(row, i, max) {
    return "<span class='name'>" + row.Name + "</span><span class='code'>(" + row.Code + ")</span><span class='en'>" + row.NameEn + "</span>";
}

function formatCountryMatch(row, i, max) {
    return row.Name + " " + row.NameEn + " " + row.Code;
    //row.NameEn;
}

function formatCountryResult(row) {
    return row.Name;
}

