function LinkedCombo( settings ) {
	this._element = $( settings.id );
	this._url = settings.url || null;
	this._params = settings.params || {};
	this._paramsCallback = settings.paramsCallback || function(){};

	this._slave = null;

	this.init();
}


LinkedCombo.prototype = {
	init: function() {
		this._element.observe( 'change', this.changed.bind( this ) );
	},

	changed: function() {
		if( this._slave == undefined ) {
			return;
		}

		if( this._url == undefined ) {
			this._slave.update.call( this._slave, {} );
			return;
		}

		if( this._element.getValue() == -1 ) {
			this._slave.reset.call( this._slave );
			return;
		}

		var me = this;
		var params = {
			value: me._element.getValue()
		};

		for( i in this._params ) {
			params[i] = this._params[i];
		}

		this._paramsCallback.call( this, params );

		new Ajax.Request( this._url, {
			method: 'get',
			evalJS:	true,
			onComplete: LinkedCombo.onComplete,
			onFailure: LinkedCombo.onFailure,
			parameters: params,
			onSuccess: function( response ) {
				me._slave.update.call( me._slave, response );
			}
		});
	},

	update: function( data ) {
		if( data.responseJSON.length < 1 ) {
		  alert( 'Ничего не найдено!' );
		  return;
		}
		this.reset();
		this._element.enable();
		for( i in data.responseJSON ) {
			this._element.options[this._element.options.length] = new Option( data.responseJSON[i], i );
		}
	},

	reset: function() {
		this._element.disable();
		this._element.options.length = 1;
		if( this._slave != undefined ) {
			this._slave.reset.call( this._slave );
		}
	},

	addSlave: function( slave ) {
		this._slave = slave;
	}

};


LinkedCombo.onComplete = function(){};

LinkedCombo.onFailure = function(){};