/* 
 * Format initials fields
 * @author Bram Gerritsen 
 * @history 09-10-2009 16:03 - BG - Better version, fast typing ok now
 * @history 18-03-2010 09:08 - BG - Fixed tab key
 */
var FormInitials = new Class({
	
	Implements: [Options, Events],
	
	options: {
	},

	initialize: function(element, options)
	{
		this.setOptions(options);
		this.oInputElement = $(element);
		if (!this.oInputElement)
			return false;
		
		$(this.oInputElement).addEvent("keydown", function(event) 
		{
			if (event.key != 'tab')
			{
				event.stop();
			
				sInputValue = this.get('value');
				if (event.key == 'backspace')
				{
					sNewInputValue = sInputValue.substring(0, sInputValue.length-2);
				}
				else if (event.code >= 65 && event.code <= 90)
				{
					sNewInputValue = sInputValue.toUpperCase() + event.key.toUpperCase() + '.';
				}
				else
				{
					return false;
				}
				
				this.set('value', sNewInputValue);
			}
		});
	}
});