Premier.Web.TextBox = 
	function(el)
	{	
		if (arguments.length > 0)
		{
			this.init(el);
		}
	}

Premier.Web.TextBox.prototype.init = 
	function(el)
	{
		if (typeof el == 'string') 
		{
			this.el = YAHOO.util.Dom.get(el);
		}
		else
		{
			this.el = el;
		}
		YAHOO.util.Event.addListener(this.el, 'focus', Premier.Web.TextBox.OnFocus);
		YAHOO.util.Event.addListener(this.el, 'blur', Premier.Web.TextBox.OnBlur);
	}

Premier.Web.TextBox.prototype.toString = 
	function()
	{
		return this.el.value;
	}

Premier.Web.TextBox.ClearSelection = 
	function(el)
	{
		if (typeof el == 'string') 
		{
			this.el = YAHOO.util.Dom.get(el);
		}
		else
		{
			this.el = el;
		}
		Premier.Web.Selection.clear(this.el);
	}

Premier.Web.TextBox.OnBlur = 
	function(e)
	{
		var el = YAHOO.util.Event.getTarget(e);
		
		// do not do anything if no value entered
		
		if (el.value == '') return true;

		// get field's attributes
		
		var lowerCase = Premier.Web.GetAttribute('boolean', el, 'lowercase', false);
		var upperCase = Premier.Web.GetAttribute('boolean', el, 'uppercase', false);
		var spaceLess = Premier.Web.GetAttribute('boolean', el, 'spaceless', false);

		// format data entered as necessary
		
		var finalValue = el.value;
		
		if (lowerCase) finalValue =finalValue.toLowerCase();	
		if (upperCase) finalValue =finalValue.toUpperCase();	
		if (spaceLess)
		{
			var re = /\s/g;
			var finalValue = finalValue.replace(re, '');
		}
		
		el.value = finalValue;
		return true;
		
	}

Premier.Web.TextBox.OnFocus = 
	function(e)
	{
		// automatically highlight text when the field gains focus
		YAHOO.util.Event.getTarget(e).select();
	}


