﻿var Location = {
    siteUrl: '',
    txtLocation: '',

    init: function () {
        var acOptions = {
            max: 100,
            dataType: 'json',
            parse: function (data) {
                var parsed = [];
                for (var i = 0; i < data.length; i++) {
                    parsed[parsed.length] = {
                        data: data[i],
                        value: data[i].Name,
                        result: data[i].Name
                    };
                }
                return parsed;
            },
            formatItem: function (item) {
                return item.Name;
            },
            cacheLength: 0
        };

        $("#" + Location.txtLocation)
        .autocomplete(Location.siteUrl + "AutoComplete/Location.aspx", acOptions)
        .result(function (e,data) {
            $(this).next("input[type:hidden]").val(data.Code);
        });
    }
};
