
function TextAreaObject(name) {

	this.name = name;
	this.lastKey = 0;
	this.maxChar = 0;
	this.charCount = 0;
	this.entryField = "";
	this.counterField = "";
	this.hasReturnKey = false;

	this.init = TextAreaObject_init;
	this.keyDown = TextAreaObject_keyDown;
	this.keyUp = TextAreaObject_keyUp;

}

function TextAreaObject_keyDown(event) {
	
	isKeyDownHandled = true;
	keyDownReturnValue = true;

	object = eval(this.name);
	
	if (isNav) object.lastKey = event.which;
	if (isIE) object.lastKey = window.event.keyCode;
	status = "key pressed " + object.lastKey;
		
	if (object.lastKey >= 112 && object.lastKey <= 123) {			
		isKeyDownHandled = false;
		return true;
	}
	
	if (object.lastKey == 9 ||
		object.lastKey == 16 ||
		object.lastKey == 17 ||
		object.lastKey == 18 ||
		object.lastKey == 20 ||
		object.lastKey == 27 ||
		object.lastKey == 34 ||
		object.lastKey == 35 ||
		object.lastKey == 36 ||
		object.lastKey == 37 || 
		object.lastKey == 38 || 
		object.lastKey == 39 || 
		object.lastKey == 40 ||
		object.lastKey == 45) {
			
		return true;
	}


	if (!object.hasReturnKey && object.lastKey == 13) {
		keyDownReturnValue = false;
		return false;
	}

	if (object.lastKey == 8 || object.lastKey == 46) {
		if (this.value.length > 0) object.charCount = this.value.length - 1;
		if (object.counterField != null) object.counterField.value = object.maxChar + "/" + object.charCount;
		return true;
	}	
	if (object.charCount == object.maxChar) {
		keyDownReturnValue = false;
		return false;	
	} 

	object.charCount = this.value.length + 1;
	if (object.counterField != null) object.counterField.value = object.maxChar + "/" + object.charCount;

		
	return true;
}

function TextAreaObject_keyUp(event) {

	isKeyUpHandled = true;
	keyUpReturnValue = true;

	object = eval(this.name);

	object.charCount = this.value.length;
	if (object.counterField != null) object.counterField.value = object.maxChar + "/" + object.charCount;
	if (currentTextAreaValue != this.value) valueChanged(this);

}

function TextAreaObject_init(anEntryField, aCounterField, aMaxChar, hasReturnKey) {

	this.lastKey = 0;
	this.maxChar = aMaxChar;
	this.charCount = 0;
	this.entryField = anEntryField;
	this.counterField = aCounterField;
	this.hasReturnKey = hasReturnKey;
	if (this.hasReturnKey == null) this.hasReturnKey = false;
	
	if (anEntryField != null) {
		anEntryField.onkeydown = this.keyDown;
		anEntryField.onkeyup = this.keyUp;
	}

	registerObject(anEntryField.name);

}


function NumberObject(name) {

	this.name = name;
	this.lastKey = 0;
	this.size = 0;
	this.scale = 0;
	this.maxValue = null;
	this.entryField = "";

	this.init = NumberObject_init;
	this.keyDown = NumberObject_keyDown;
	this.keyUp = NumberObject_keyUp;

}

function NumberObject_keyDown(event) {
	
	isKeyDownHandled = true;
	keyDownReturnValue = true;

	object = eval(this.name);
	object.lastValue = this.value;
	
	if (isNav) object.lastKey = event.which;
	if (isIE) object.lastKey = window.event.keyCode;
	status = "key pressed " + object.lastKey;
		
		
	if (object.lastKey >= 112 && object.lastKey <= 123) {			
		isKeyDownHandled = false;
		return true;
	}

	if (object.lastKey == 9) return true;
	if (object.hasSign && (object.lastKey == 109 || object.lastKey == 189)) {
		if (this.value.charAt(0) == '-') return false;
		if (this.value.length > 0) return false;
		return true;
	}
	if (object.lastKey == 8 || object.lastKey == 46) return true;
	if (object.lastKey == 37 || object.lastKey == 39) return true;

	if ((object.lastKey > 47 && object.lastKey < 58) || (object.lastKey > 95 && object.lastKey < 106)) {
		if (object.hasSign && this.value.charAt(0) == '-') 
			temp = this.value.substr(1, this.value.length -1);
		else
			temp = this.value;
		temp = temp.split(".");
		if (temp.length == 1) {
			if (temp[0].length < (object.size - object.scale)) return true;			
		} else if (temp.length == 2) {
			if ((temp[0].length + temp[1].length) < object.size) return true;	
		}

		return false;

	} 
	if (object.scale > 0 && object.lastKey == 190) {
		if (object.hasSign && this.value.charAt(0) == '-') 
			temp = this.value.substr(1, this.value.length -1);
		else
			temp = this.value;
		if (temp.length <= (object.size - object.scale) && this.value.indexOf(".") == "-1") return true
	}
	
	return false;
		

}

function NumberObject_keyUp(event) {

	isKeyUpHandled = true;
	keyUpReturnValue = true;

	object = eval(this.name);
	temp = this.value.split(".");
	if (temp.length == 2) {
		if (temp[0].length > (object.size - object.scale)) this.value = object.lastValue;	
		if (temp[1].length > object.scale) this.value = object.lastValue;	
	}
	if (currentEntryFieldValue != this.value) valueChanged(this);

}


function NumberObject_init(anEntryField, aSize, aScale, aMaxValue, hasSign) {

	this.lastValue = "";
	this.lastKey = 0;
	this.hasSign = hasSign;
	this.size = aSize;
	this.scale = aScale;
	this.maxValue = aMaxValue;
	this.entryField = anEntryField;
	
	if (this.hasSign == null) this.hasSign = false;

	anEntryField.onkeydown = this.keyDown;
	anEntryField.onkeyup = this.keyUp;
	
	registerObject(anEntryField.name);

}
