var FormField = new Class({
	
	Implements: [Options, Events],
	options:{
		onBlur	: $empty,
		onFocus	: $empty,
		onKeyUp	: $empty
	},
	
	field			: undefined,
	name			: undefined,
	label			: undefined,
	gotMyOwnValue 	: false,
	links			: {},
	
	initialize: function(name, label, options)
	{
		this.name 	= name;
		this.label	= name;
		if($defined(label))
		{
			this.label	= label;
		}
		this.setOptions(options);
		this.createField();
	},
	
	createField: function()
	{
		this.wrapper 		= new Element("div", {"class":"fieldContainer"});
		this.labelElement	= new Element("label", {text:this.label}).inject(this.wrapper);
		this.field 			= new Element("input", {type:"text"}).inject(this.wrapper);
		this.field.addEvent("blur"	, this.fieldBlur.bind(this));
		this.field.addEvent("focus"	, this.fieldFocus.bind(this));
		this.field.addEvent("keyup"	, this.fieldKeyUp.bindWithEvent(this));
	},
	
	setMask: function(maskOptions)
	{
		if($defined(this.mask))
		{
			this.mask.remove();
		}
		
		this.mask = new meio.Mask(this.field, maskOptions);
	},
	
	fieldBlur: function()
	{
		this.fireEvent("onBlur", [this]);
	},
	
	fieldFocus: function()
	{
		this.fireEvent("onFocus", [this]);
	},
	
	fieldKeyUp: function()
	{
		this.gotMyOwnValue = true;
		
		if(this.getValue() == "")
		{
			this.gotMyOwnValue = false;
		}
		
		this.fireEvent("onKeyUp", [this]);
	},
	
	/*Public*/
	getValue: function()
	{
		return this.field.get("value");
	},
	
	setValue: function(value)
	{
		this.field.set("value", value);
	},
	
	getName: function()
	{
		return this.name;
	},
	
	inject: function(target, where)
	{
		this.wrapper.inject(target, where);
	},
	
	getLabel: function()
	{
		return this.label;
	},
	
	addLinkCallback: function(text, method)
	{
		this.links[text] = new Element("a", {href:"#", text:text}).inject(this.wrapper);
		this.links[text].addEvent("click", function(e){if(e)e.stop()});
		this.links[text].addEvent("click", method.pass(this));
	}
});