$().ready(function () {

    $('input#LocationTB').autocomplete(townscities, {
        minChars: 0,
        autoFill: false,
        width: 276,
        scrollHeight: 350,
        mustMatch: false,
        matchContains: true
    });

    var st = "bt";
    $('input#BusinessTB').result(function () {
        //console.log(arguments[1].value);
        $('input#ckey').val(arguments[1].value);
    });

    $("input[name='SearchType']").change(
        function () {
            st = $("input:radio[name='SearchType']:checked").val();
            if (st == "bn") {
                $('input#BusinessTB').unbind('.autocomplete');
            }
            else {
                $('input#BusinessTB').autocomplete(classalphasorts, {
                    minChars: 3,
                    autoFill: false,
                    width: 276,
                    scrollHeight: 350,
                    mustMatch: false,
                    matchContains: true,
                    formatItem: function (row, i, max) {
                        return row.key;
                    },
                    formatMatch: function (row, i, max) {
                        return row.key;
                    },
                    formatResult: function (row) {
                        return row.key;
                    }
                });
            }
        }
    );

    if (st == "bt") {
        $('input#BusinessTB').autocomplete(classalphasorts, {
            minChars: 3,
            autoFill: false,
            width: 276,
            scrollHeight: 350,
            mustMatch: false,
            matchContains: true,
            formatItem: function (row, i, max) {
                return row.key;
            },
            formatMatch: function (row, i, max) {
                return row.key;
            },
            formatResult: function (row) {
                return row.key;
            }
        });
    }
    else {
        $('input#BusinessTB').unbind('.autocomplete');
    }

    $('input#KeywordTB').autocomplete(keywords, {
        minChars: 0,
        autoFill: false,
        width: 276,
        scrollHeight: 350,
        mustMatch: false
    });

});