/**
 * Этот "класс" является типа-наследником "класса" ComplexListFilter,
 * и обладает всей его функциональностью + обслуживает несколько чекбоксов.
 * decorate ComplexListFilter "constructor" behaviour
 */
LocationFilter = function() {
	// call parent "constructor" with this as scope
	ComplexListFilter.call(this, 'Расположение', '/filters/metro/', {
		selected: '#selected-stations',
		hidden: 'metro_station_id'
	});
	this.eshop				= false;
	this.near_metro			= false;
	this.near_trade_center	= false;
}

/**
 * Унаследуем все методы прототипа класса-родителя (ComplexListFilter)
 */
LocationFilter.prototype = {};
$.extend(LocationFilter.prototype, ComplexListFilter.prototype);

/**
 * Задаем значение для флажков чекбоксов.
 */
LocationFilter.prototype.setEshop = function(val) {
	this.eshop = val;
	this.updateSelectedList();
}
LocationFilter.prototype.setNearMetro = function(val) {
	this.near_metro = val;
	this.updateSelectedList();
}
LocationFilter.prototype.setNearTradeCenter = function(val) {
	this.near_trade_center = val;
	this.updateSelectedList();
}
/**
 * Немного магии. "Переопределим"
 * decorate ComplexListFilter behaviour
 */
LocationFilter.prototype.onload = function() {
	ComplexListFilter.prototype.onload.call(this);
	this.pane.find('#loc_eshop').attr('checked', this.eshop);
	this.pane.find('#loc_near_metro').attr('checked', this.near_metro);
	this.pane.find('#loc_near_trade_center').attr('checked', this.near_trade_center);
}
LocationFilter.prototype.finalize = function() {
	this.eshop				= this.pane.find('#loc_eshop').attr('checked');
	this.near_metro			= this.pane.find('#loc_near_metro').attr('checked');
	this.near_trade_center	= this.pane.find('#loc_near_trade_center').attr('checked');
	ComplexListFilter.prototype.finalize.call(this);
}

LocationFilter.prototype.selectionPaneVisible = function() {
	return ComplexListFilter.prototype.selectionPaneVisible.call(this) || 
		this.eshop || 
		this.near_metro || 
		this.near_trade_center;
}
LocationFilter.prototype.getSelectionHtml = function() {
	var parts = [];
	var stations = ComplexListFilter.prototype.getSelectionHtml.call(this);
	if (stations) {
		parts.push(stations);
	}
	if (this.eshop) {
		parts.push('Интернет-магазин');
	}
	if (this.near_metro) {
		parts.push('Рядом с метро');
	}
	if (this.near_trade_center) {
		parts.push('Рядом с торговым центром');
	}
	return parts.join(', ');
}
LocationFilter.prototype.getHiddenInputs = function() {
	var ret = ComplexListFilter.prototype.getHiddenInputs.call(this);
	if (this.eshop) {
		ret.push({name: 'eshop', value: 'on'});
	}
	if (this.near_metro) {
		ret.push({name: 'near_metro', value: 'on'});
	}
	if (this.near_trade_center) {
		ret.push({name: 'near_trade_center', value: 'on'});
	}
	return ret;
}