/**
* BF Formover Class
* Formover class automatically applies, and allows the application of the class 'over' to an input, textarea and selects label and fieldset when the element is focused.
*
* @author   Andy Burton <andyburton@bfinternet.co.uk>
* @link     http://www.bfinternet.co.uk
*
* @version  1.00
*
* Modifications:
* None
*
* Attributes:
* strName       - Object name
* arrInputs     - Document Input Elements
* arrTextareas  - Document Textarea Elements
* arrSelects    - Document Select Elements
*
* Methods:
* constructor ()
* AutoLoad ()
* Get (strType)
* GetInputs ()
* GetTextareas ()
* GetSelects ()
* GetAll ()
* Apply (arrTypes)
* ApplyInputs ()
* ApplyTextareas ()
* ApplySelects ()
* ApplyAll ()
* loadDate ()
*/



/*
* Constructor Function
*/

function Formover (strName)
{
	
	this.strName		= strName;
	this.arrInputs		= false;
	this.arrTextareas	= false;
	this.arrSelects		= false;
	
	objWol.Add (new Array (this.strName, 'AutoLoad()'));
	
}

/*
* Formover.AutoLoad Function
* Auto get and apply the formover
*/

Formover.prototype.AutoLoad = function ()
{
	
	this.GetAll ();
	this.ApplyAll ();
	
}

/*
* Formover.Get Function
* Get the elements
*/

Formover.prototype.Get = function (strType)
{
	
	return document.getElementsByTagName (strType);
	
}

/*
* Formover.GetInputs Function
* Get the document input elements
*/

Formover.prototype.GetInputs = function ()
{
	
	
	this.arrInputs	= this.Get ('input');
	
}

/*
* Formover.GetTextareas Function
* Get the document textarea elements
*/

Formover.prototype.GetTextareas = function ()
{
	
	this.arrTextareas	= this.Get ('textarea');
	
}

/*
* Formover.GetSelects Function
* Get the document select elements
*/

Formover.prototype.GetSelects = function ()
{
	
	this.arrSelects	= this.Get ('select');
	
}

/*
* Formover.GetAll Function
* Get the all the document form elements
*/

Formover.prototype.GetAll = function ()
{
	
	this.GetInputs ();
	this.GetTextareas ();
	this.GetSelects ();
	
}

/*
* Formover.Apply Function
* Apply the formover to the given elements
*/

Formover.prototype.Apply = function (arrElements)
{
	
	for (var i = 0; i < arrElements.length; i++)
	{
		
		if (arrElements[i].type != 'button' && arrElements[i].type != 'submit')
		{
			
			arrElements[i].onfocus = function ()
			{
				
				if (this.value == 'DD/MM/YYYY HH:MM' || this.value == 'DD/MM/YYYY')
				{
					
					this.value = '';
					
				}
				
				if (this.id)
				{
					
					var arrLabels = document.getElementsByTagName ('label');
					
					for (var l = 0; l < arrLabels.length; l++)
					{
						
						if (arrLabels[l].htmlFor == this.id)
						{
							
							if (arrLabels[l].className == '')
							{
								
								arrLabels[l].className = 'over';
								
							}
							else
							{
								
								arrLabels[l].className += ' over';
								
							}
							
						}
						
					}
					
				}
				
				var nodeParent		= this.parentNode;
				var strParentTag	= nodeParent.tagName
				
				while (strParentTag.toLowerCase () != 'fieldset')
				{
					
					nodeParent		= nodeParent.parentNode;
					strParentTag	= nodeParent.tagName;
					
				}
				
				if (strParentTag.toLowerCase () == 'fieldset')
				{
					
					if (nodeParent.className == '')
					{
						
						nodeParent.className	= 'over';
						
					}
					else
					{
						
						nodeParent.className += ' over';
						
					}
					
				}
					
				this.onblur = function ()
				{
					
					if (this.id)
					{
						
						var arrLabels = document.getElementsByTagName ('label');
						
						for (var l = 0; l < arrLabels.length; l++)
						{
							
							if (arrLabels[l].htmlFor == this.id)
							{
								
								if (arrLabels[l].className == 'over')
								{
									
									arrLabels[l].className = '';
									
								}
								else
								{
									
									arrLabels[l].className = arrLabels[l].className.replace (' over', '');
									
								}
								
							}
							
						}
						
					}
					
					var nodeParent		= this.parentNode;
					var strParentTag	= nodeParent.tagName
					
					while (strParentTag.toLowerCase () != 'fieldset')
					{
						
						nodeParent		= nodeParent.parentNode;
						strParentTag	= nodeParent.tagName;
						
					}
					
					if (strParentTag.toLowerCase () == 'fieldset')
					{
						
						if (nodeParent.className == 'over')
						{
							
							nodeParent.className = '';
							
						}
						else
						{
							
							nodeParent.className = nodeParent.className.replace (' over', '');
							
						}
						
					}
					
				}
				
			}
			
		}
		
	}
	
}

/*
* Formover.ApplyInputs Function
* Apply the formover to the input elements
*/

Formover.prototype.ApplyInputs = function ()
{
	
	this.Apply (this.arrInputs);
	
}

/*
* Formover.ApplyTextareas Function
* Apply the formover to the textarea elements
*/

Formover.prototype.ApplyTextareas = function ()
{
	
	this.Apply (this.arrTextareas);
	
}

/*
* Formover.ApplySelects Function
* Apply the formover to the select elements
*/

Formover.prototype.ApplySelects = function ()
{
	
	this.Apply (this.arrSelects);
	
}

/*
* Formover.ApplyAll Function
* Apply the formover to the form elements
*/

Formover.prototype.ApplyAll = function ()
{
	
	this.ApplyInputs ();
	this.ApplyTextareas ();
	this.ApplySelects ();
	
}

/*
* Formover.loadDate Function
* load the date value
*/

Formover.prototype.loadDate = function (obj)
{
	
	if (obj.value == '')
	{
		
		obj.value	= 'DD/MM/YYYY HH:MM';
		
	}
	
}
