
function MSW_Form(obj)
{
	this.obj = $(obj);
};
MSW_Form.prototype.obj = null;



function MSW_Form_TextArea(obj)
{
	var thisObj = this;
	this.obj = $(obj);
	//this.obj.onkeydown = thisObj.catchKeyDown;
	this.obj.onkeydown = function(e) { return thisObj.catchKeyDown(e); };
	this.obj.onkeyup = function() { return thisObj.catchChange(); };
	this.obj.onchange = function() { return thisObj.catchChange(); };
}

MSW_Form_TextArea.prototype.obj = null;
MSW_Form_TextArea.prototype.maxLength = null;

MSW_Form_TextArea.prototype.limitLength = function(maxLength)
{
	this.maxLength = maxLength;
}

MSW_Form_TextArea.prototype.catchKeyDown = function(e)
{
	if (this.maxLength == null) return true;
	else if (e.which == 8) return true; // backspace
	else if (e.which == 9) return true; // tab
	else if (e.which >= 37 && e.which <= 40) return true; // arrow keys
	else if (e.which >= 16 && e.which <= 18) return true; // shift, ctrl, alt (no particular order)
	else if (e.which >= 112 && e.which <= 123) return true; // function keys
	//alert(e.which);
	if (this.obj.value.length >= this.maxLength) return false;
}

MSW_Form_TextArea.prototype.catchChange = function()
{
	if (this.maxLength == null) return true;
	else if (this.obj.value.length > this.maxLength)
	{
		this.obj.value = this.obj.value.substr(0, this.maxLength);
		return true;
	}
	
}



