/**
 * Inline Labels
 */
function CS_InlineLabels(){}

CS_InlineLabels.prototype = 
{
	labels : {},
	
	/**
	 * Not implemented
	 */
	autoattach : false,
	
	id_indexes : false,
	
	labelcolor 	 : '#555',
	defaultcolor : '#000', 
	
	addLabel : function(field_name, label)
	{
		this.labels[field_name] = {
			"label" : label,
			"color" : null
		};
	},
	
	empty : function(obj)
	{
		var index = this._getFieldIndex(obj);
		if(obj.value == this.labels[index].label)
		{
			obj.value = '';
			
			if(this.labels[index].color)
			{
				obj.style.color = this.labels[index].color;
			}
		}
	},
	
	restore : function(obj)
	{
		if(obj.value == '')
		{
			var index = this._getFieldIndex(obj);
			
			obj.value = this.labels[index].label;
			
			if(obj.style.color)
			{
				this.labels[index].color = obj.style.color;
			}
			else
			{
				this.labels[index].color = this.defaultcolor;
			}
			
			obj.style.color = this.labelcolor;
		}
	},
	
	emptyAll : function(form)
	{
		for(field_name in this.labels)
		{
			this.empty(form[field_name]);
		}
	},
	
	restoreAll : function(form)
	{
		for(field_name in this.labels)
		{
			if(typeof form[field_name] == 'undefined')
			{
				alert(field_name + ' is undefined, you cannot label it!');
				break;
			}
			
			this.restore(form[field_name]);
		}
	},
	
	_getFieldIndex : function(obj)
	{
		if(this.id_indexes &&  typeof obj.id != 'undefined' && obj.id.length > 0)
		{
			return obj.id;
		}
		else if(typeof obj.name != 'undefined' && obj.name.length > 0)
		{
			return obj.name;
		}
		else
		{
			throw new Error('Unable to get index of field: ' + obj);
		}
	}
}