<!--
$(document).ready(function ()
{
    BindSearch();
    //var prm = Sys.WebForms.PageRequestManager.getInstance();
    //prm.add_endRequest(BindSearch);

    // Username validation logic
    var results = $('#results');
    var spinner = $('#spinner');

    $('#search').keyup(function ()
    {
        // cache the 'this' instance as we need access to it within a setTimeout, where 'this' is set to 'window'
        var t = this; 
        
        // only run the check if the username has actually changed - also means we skip meta keys
        if (this.value != this.lastValue)
        {
            // the timeout logic means the ajax doesn't fire with *every* key press, i.e. if the user holds down
            // a particular key, it will only fire when the release the key.
                            
            if (this.timer) clearTimeout(this.timer);
            if (this.value == "")
            {
                results.stop().fadeTo(400, 0, function() { $('#results').hide() });
                results.html("");
                spinner.html("");
            }
            else
            {
                // show our holding text in the validation message space
                spinner.html('<img src="' + BasePath + 'jq/ajax-loader.gif" height="16" width="16" alt="Loading..." />');
                // fire an ajax request in 1/5 of a second
                this.timer = setTimeout(function () {
                    $.ajax({
                        url: BasePath + 'search_function.aspx',
                        data: 'action=search&value=' + t.value,
                        type: 'post',
                        cache: false,
                        success: function (html) {
                            results.stop().show().fadeTo(250, 1);
                            results.html(html);
                            spinner.html("");
                        }
                    });
                }, 200);
            }
            
            // copy the latest value to avoid sending requests when we don't need to
            this.lastValue = this.value;
        }
    });
});

function BindSearch()
{
    $("#results").hover(
        function(){
            $(this).stop().show().fadeTo(250, 1);
        },
        function(){
            $(this).stop().fadeTo(900, 0, function() { $(this).hide() });
        }); 
}

//-->
