﻿(function($) {  
    // Run-once policy
    if (!$.loaded) $.loaded = {};
    if (!$.loaded["autocomplete"]) {
        $.loaded["autocomplete"] = true;
        
        $(document).ready(function() {
            $("input[rel=header_search]").each(function() {
                var txtThis = $(this);
                // "this" is from each()
                (function (txtThis) {
                    txtThis.autocomplete({
                        serviceUrl: '/ajax/get_search_hints.aspx',
                        onSelect: function(value, data) {
                            txtThis.closest("fieldset").find("input[type=submit]").get(0).click();
                        }
                    });
                })(txtThis);
            });
        });    
    }
})(jQuery);
