/**
 * @author buenger
 */
function IntegerInput (a_divId, a_formElementName) {
	
	this.id;
	this.name = "IntegerInput";
	this.type = "FormElement";
	
	var div;
	var formElement;
	var label;
	var formElementName;
	var _isRequired;
	var _isCheckable = true;
	var _isReadOnly = false;
	
	var _self = this;
	
	this.check = function() {
		return test();
	}
	
	this.value = function () {
		return formElement.value;
	}
	
	this.getCheckable = function () {
		return _isCheckable;
	}
		
	this.setCheckable = function(a_isCheckable) {
		_isCheckable = a_isCheckable;
		if (!_isCheckable) _self.unerror();
	}
	
	this.setReadOnly = function (a_readOnly) {
		_isReadOnly = a_readOnly;
		if (_isReadOnly) formElement.setAttribute ("readonly", "readonly");
		else formElement.removeAttribute("readonly");
	}
	
	this.getReadOnly = function () {
		return _isReadOnly;
	}
	
	this.error = function() {
		formElement.style.backgroundColor = "#F1E322";
		formElement.addEvent("blur", this.unerror);
	}
	
	this.unerror = function() {
		formElement.style.backgroundColor = "";
		formElement.removeEvent("blur", this.unerror);
	}
	
	this.remove = function () {
		div.parentNode.removeChild(div);
	}
	
	this.addDependency = function (a_id, a_valueFnc, a_compareFnc, a_handleFnc) {
		var el = Form.idMap[a_id];
		el.addEvent("propChange", function () {
			var value = el[a_valueFnc]();
			var compareResult = CompareFunctions[a_compareFnc](value);
			_self[a_handleFnc](compareResult);
		});
	}
	
	function test () {
		if (!isRequired()) return true;
		else return (_self.value().test(/[0-9]/) && _self.value().length > 0);
	}
	
	function init (a_divId, a_formElementName) {
		_self.id = a_divId;
		formElementName = a_formElementName;
		
		window.addEvent("load", handleWindowLoad);
	}
	
	function isRequired  () {
		return _isRequired;
	}
	
	this.getLabel = function() {
		return (label !== null) ? label.innerHTML.replace(/\*/g,"") : false;
	}
	
	function handleWindowLoad () {
		window.removeEvent("load", handleWindowLoad);
		
		div = $(_self.id);
		label = div.getElements("label")[0];
		
		formElement = $$('input[name='+formElementName+']')[0];
		formElement.addEvent("blur", handleValueChange);
		_isRequired = (formElement.getProperty("required") != null) ? true: false;
	}
	
	function handleValueChange () {
		_self.fireEvent("propChange");
	}
	
	//MOOTOOLS EVENTS
	$extend(this, new Events());
	
	init (a_divId, a_formElementName);
}
