﻿$(function () {
    $(".txtnmUser").autocomplete({
        source: function (request, response) {
            $.getJSON("/Service/Account/AccountService.svc/GetListAccountByName/" + $(".txtnmUser").val() + "/0", ResultAutoComplete);
            function ResultAutoComplete(results) {
                response($.map(results, function (item) {
                    return {
                        label: item.Value,
                        value: item.Key
                    }
                }));
            }
        },
        minLength: 4
    });


    $(".txtnmGroup").autocomplete({
        source: function (request, response) {
            $.getJSON("/Service/Group/Configuration/GroupConfigurationService.svc/GetListGroupByName/" + $(".txtnmGroup").val(), ResultAutoComplete);
            function ResultAutoComplete(results) {
                response($.map(results, function (item) {
                    return {
                        label: item.Title + ' ( ' + item.Url + ' )',
                        value: item.Url
                    }
                }));
            }
        },
        minLength: 4
    });

    $('input[id$=idText]').autocomplete({
        source: function (request, response) {
            $.getJSON("/Service/Account/AccountService.svc/GetListAccountByName/" + $('input[id$=idText]').val() + "/1", ResultAutoComplete);
            function ResultAutoComplete(results) {
                response($.map(results, function (item) {
                    return {
                        label: item.Value,
                        value: item.Value
                    }
                }));
            }
        },
        select: function (event, ui) {
            Friendship.Search();
        },
        minLength: 4
    });

    $("#txtSearchInvite").autocomplete({
        source: function (request, response) {
            $.getJSON("/Service/Account/AccountService.svc/GetListAccountByName/" + $("#txtSearchInvite").val() + "/1", ResultAutoComplete);
            function ResultAutoComplete(results) {
                response($.map(results, function (item) {
                    return {
                        label: item.Value,
                        value: item.Value
                    }
                }));
            }
        },
        select: function (event, ui) {
            $("#txtSearchInvite").attr("value", ui.item.value);
            GroupControl.GetSearchInvite();
        },
        minLength: 4
    });

});
