function JCSmartFilter(ajaxURL, viewMode, params)
{
this.ajaxURL = ajaxURL;
this.form = null;
this.timer = null;
this.cacheKey = '';
this.cache = [];
this.viewMode = viewMode;
if (params && params.SEF_SET_FILTER_URL)
{
this.bindUrlToButton('set_filter', params.SEF_SET_FILTER_URL);
this.sef = true;
}
if (params && params.SEF_DEL_FILTER_URL)
{
this.bindUrlToButton('del_filter', params.SEF_DEL_FILTER_URL);
}
}
JCSmartFilter.prototype.keyup = function(input)
{
if(!!this.timer)
{
clearTimeout(this.timer);
}
this.timer = setTimeout(BX.delegate(function(){
this.reload(input);
}, this), 500);
};
JCSmartFilter.prototype.click = function(checkbox)
{
if(!!this.timer)
{
clearTimeout(this.timer);
}
this.timer = setTimeout(BX.delegate(function(){
this.reload(checkbox);
}, this), 500);
};
JCSmartFilter.prototype.reload = function(input)
{
if (this.cacheKey !== '')
{
//Postprone backend query
if(!!this.timer)
{
clearTimeout(this.timer);
}
this.timer = setTimeout(BX.delegate(function(){
this.reload(input);
}, this), 1000);
return;
}
this.cacheKey = '|';
this.position = BX.pos(input, true);
this.form = BX.findParent(input, {'tag':'form'});
if (this.form)
{
var values = [];
values[0] = {name: 'ajax', value: 'y'};
this.gatherInputsValues(values, BX.findChildren(this.form, {'tag': new RegExp('^(input|select)$', 'i')}, true));
for (var i = 0; i < values.length; i++)
this.cacheKey += values[i].name + ':' + values[i].value + '|';
if (this.cache[this.cacheKey])
{
this.curFilterinput = input;
this.postHandler(this.cache[this.cacheKey], true);
}
else
{
if (this.sef)
{
var set_filter = BX('set_filter');
set_filter.disabled = true;
}
this.curFilterinput = input;
BX.ajax.loadJSON(
this.ajaxURL,
this.values2post(values),
BX.delegate(this.postHandler, this)
);
}
}
};
JCSmartFilter.prototype.updateItem = function (PID, arItem)
{
if (arItem.PROPERTY_TYPE === 'N' || arItem.PRICE)
{
/*var select_min = $('#arFilter_'+ PID +'_MIN'),
select_max = $('#arFilter_'+ PID +'_MAX'),
min_val,
max_val;
if (select_min.length && select_max.length && arItem.VALUES)
{
if (arItem.VALUES.MIN)
{
if (parseInt(arItem.VALUES.MIN.FILTERED_VALUE) > 0)
min_val = arItem.VALUES.MIN.FILTERED_VALUE;
else
min_val = arItem.VALUES.MIN.VALUE;
select_min.styler('destroy');
select_min.empty();
$('