<!--
$(document).ready(function () {
    var listing_results = $('#ctl00_ctl00_cph_content_listing_results');
    var listing_spinner = $('#listing_spinner');

    var category = document.getElementById('ctl00_ctl00_cph_content_search_category');
    var brand = document.getElementById('ctl00_ctl00_cph_content_search_brand');
    var nameex = document.getElementById('ctl00_ctl00_cph_content_search_name');

    var jcategory = $('#ctl00_ctl00_cph_content_search_category');
    var jbrand = $('#ctl00_ctl00_cph_content_search_brand');
    var jnameex = $('#ctl00_ctl00_cph_content_search_name');

    //results.animate({opacity: 0}, 0);

    jcategory.keyup(function () { search_listing(); });
    jbrand.keyup(function () { search_listing(); });
    jnameex.keyup(function () { search_listing(); });
	
    function search_listing () {
        // only run the check if the data has actually changed - also means we skip meta keys
        var c = category.value; if (c == "Enter Category") c = "";
        var b = brand.value; if (b == "Enter Brand") b = "";
        var n = nameex.value; if (n == "Enter Name") n = "";
        if (c != category.lastValue || b != brand.lastValue || n != nameex.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 (jcategory.timer) clearTimeout(jcategory.timer);

            if (c == "" && b == "" && n == "")
            {
                //listing_results.fadeOut();
                //listing_results.animate({opacity: 0}, 150);
                listing_results.html("");
                listing_spinner.html("");
            }
            else
            {
                // show our holding text in the validation message space
                listing_spinner.html('<img src="' + BasePath + 'jq/ajax-loader.gif" height="16" width="16" />');
                // fire an ajax request in 1/5 of a second
                jcategory.timer = setTimeout(function () {
                    //alert("Category: " + c);
                    //alert("Brand: " + b);
                    //alert("Name: " + n);
                    $.ajax({
                        url: BasePath + 'search_listing.aspx',
                        data: 'Category=' + c + '&Brand=' + b + '&NameEx=' + n,
                        type: 'post',
                        cache: false,
                        success: function (html) {
                            //listing_results.animate({opacity: 1}, 250);
                            //listing_results.fadeIn();
                            listing_results.html(html);
                            listing_spinner.html("");
                        }
                    });
                }, 350);
            }
            
            // copy the latest value to avoid sending requests when we don't need to
            category.lastValue = c;
            brand.lastValue = b;
            nameex.lastValue = n;
        }
    }
});
//-->
