Bw.Widgets.Textfield =
{
	superclassName: "Bw.Widgets.Editable",
	selfclassName: "Bw.Widgets.Textfield",
	
	create: function (val)
	{
		var obj = document.createElement ("div");
		
		if (val) obj.setAttribute ("value", val);
		
		Bw.Core.bootstrap (obj, "Bw.Widgets.Textfield");
		
		return obj;
	},

	initialize: function ()
	{
		Bw.Widgets.Widget.initialize.call (this);
		
		this.maxlength = this.getAttribute ("maxlength");
		
		this.field = this.draw();
		this.appendChild (this.field);

		var a = this.getAttribute ("value");
		if (a != null) {
			this.setValue (a);
		}
		
		var self = this;
		
		this.onupdate = this.getAttribute ("onupdate");
		this.field.onchange = function () { self.changed(); }; 
		
		this.onfocus = this.getAttribute ("onfocus");
		this.field.onfocus = function () { self.focused(); }; 
		
		return false;
	},
	
	draw: function ()
	{
		var f = document.createElement ("input");
		f.style.width = "100%";
		f.autocomplete = "off";		

		if( this.maxlength != null )
		{
			f.maxLength = this.maxlength;
		}
		
		return f;
	},
	
	changed: function ()
	{
		if (this.onupdate) Bw.Util.call (this, this.onupdate);
	},
	
	focused: function ()
	{
		if (this.onfocus) Bw.Util.call (this, this.onfocus);
	},
	
	clear: function ()
	{
		this.setValue ("");
	},
	
	getValue: function ()
	{
		return this.field.value;
	},
	
	setValue: function (val)
	{
		this.field.value = val;
	},

	disable: function ()
	{
		this.disabled = true;
		this.field.disabled = true;
	},
	
	enable: function ()
	{
		this.disabled = false;
		this.field.disabled = false;
	}
};

