/*class*/ SpinEdit = function (/*string*/ editId, /*string*/ upButtonId, /*string*/ downButtonId) {
	this.edit = document.getElementById(editId);
	this.edit.value = 0;
	addEventListener(this.edit, "blur", this, this.editBlur);

	this.upButton = document.getElementById(upButtonId);
	addEventListener(this.upButton, "click", this, this.upButtonClick);

	this.downButton = document.getElementById(downButtonId);
	addEventListener(this.downButton, "click", this, this.downButtonClick);
}

SpinEdit.prototype.increment = 1;
SpinEdit.prototype.max = Infinity;
SpinEdit.prototype.min = -Infinity;

SpinEdit.prototype.valueIsValid = function () {
	return !isNaN(this.edit.value);
}

SpinEdit.prototype.editBlur = function () {
	if (!this.valueIsValid()) {
		this._invalidValueMsg();
		return;
	}
	if (this.onchange) call(this.onchange, this.owner, this);
	if (this.onblur) this.onblur(this);
}

SpinEdit.prototype._invalidValueMsg = function () {
	alert("Значение '" + this.edit.value + "' не является числом.");
	this.edit.value = 0;
	if (this.onchange) call(this.onchange, this.owner, this);
}

SpinEdit.prototype.upButtonClick = function () {
	if (!this.valueIsValid()) {
		this._invalidValueMsg();
		return;
	}

	var newValue = this.edit.value - -this.increment;

	if (newValue > this.max) {
		if (this.wrap) this.edit.value = this.min;
	} else {
		this.edit.value = newValue;
	}

	if (this.onchange) call(this.onchange, this.owner, this);
}

SpinEdit.prototype.downButtonClick = function () {
	if (!this.valueIsValid()) {
		this._invalidValueMsg();
		return;
	}

	var newValue = this.edit.value - this.increment;

	if (newValue < this.min) {
		if (this.wrap) this.edit.value = this.max;
	} else {
		this.edit.value = newValue;
	}
	if (this.onchange) call(this.onchange, this.owner, this);
}

var SPINEDIT_JS = EVENTS_JS = true;