// ------------------------------------------------------------------------------------------------------------------
/*
User Interface Helpers
(c) 2007 Rob Watkins
This code is free to use for any purpose, provided the copyright notice and credit to original author is maintained.
The code is provided AS IS. No guarantee is made on the fitness of this code for any purpose. Use at your own risk.
The documentation file must be kept with this source on redistribution.

Usage: (Requires: tiny_common.js)
~~~~~

*/
var UI =
{
	isTextEdit:function(ido)
	{
		if(ido = Utils.get(ido))
			return ido && ((ido.nodeName.toUpperCase() == 'INPUT' && (ido.type && (ido.type.toUpperCase() == 'TEXT'))) || (ido.nodeName.toUpperCase() == 'TEXTAREA'));
		else
			return false;
	},
	
	createInput:function(name)
	{
		var b = null;
		
		try
		{
			// IE. Is retarded. (http://msdn2.microsoft.com/en-us/library/ms534184.aspx)
			b = document.createElement(Utils.formatString('<input name="{0}">', [name]));
		}
		catch(e)	{	}
		
		if(!b)
		{
			var b = document.createElement('input');
			b.name = name;
		}
		
		return b;
	},
	
	makeDateBox:function(ido) { this.makeDateBoxes([ido]); },
	
	makeDateBoxes:function(idoarr)
	{
		for(var i = 0; i < idoarr.length; i++)
			Evt.trackEvent('blur', this.dateBoxChangedHandler, idoarr[i]);
	},

	makeTouchable:function(ido) { this.makeTouchables([ido]); },
	
	makeTouchables:function(idoarr)
	{
		for(var i = 0; i < idoarr.length; i++)
			Evt.trackEvent('focus', this.touchableEditEnteredHandler, idoarr[i]);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	setValidationGroup:function(button, group)
	{
		button = Utils.get(button);
		button.validationGroup = group;
		
		Evt.trackMouse(button, {click: function(e, id, pt, data) { UI.validationGroup = data.validationGroup; }, data:button});
	},
	
	validationGroup:null,
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
	dateBoxChangedHandler:function(e, id)
	{
		var o = Utils.get(id);		
		var d = Utils.Date.guess(o.value);
		
		o.value = d != null ? Utils.Date.format(d, 'gb') : '';
	},
	
	touchableEditEnteredHandler:function(e, id)
	{
		var o = Utils.get(id);
		if(!o.touched || (typeof(o) == 'undefined') )
		{
			o.value = '';
			o.touched = true;
			Utils.removeClass(o, 'hui_touchable');
		}
	}
	
};