function setlabeltext()
{
	var inputs = $$('input.labeltext[type=text], input.labeltext[type=password], textarea.labeltext');
	for (var i=0; i<inputs.length; i++)
	{
		var label;
		
		if (inputs[i].getAttribute('title') == '' || inputs[i].getAttribute('title') == null)
			label = $F(inputs[i]);
		else
		{
			label = inputs[i].getAttribute('title');
			inputs[i].setAttribute('title', '');
		}
			
		inputs[i].setAttribute('label', label);
			
		if (inputs[i].value == '' && inputs[i].getAttribute('type') != 'password') inputs[i].value = label;
		if (inputs[i].value == label && inputs[i].getAttribute('type') != 'password') inputs[i].addClassName('label');
		
		if (inputs[i].getAttribute('type') == 'password')
		{
			inputs[i].setAttribute('label-field', 'password-field-label-'+i);
			if (inputs[i].id == '') inputs[i].id = 'password-field-'+i;
			var labelfield = new Element('input', { id: 'password-field-label-'+i, type: 'text', value: label });
			labelfield.setAttribute('password-field', inputs[i].id);
			labelfield.className = inputs[i].className;
			labelfield.addClassName('label');
			labelfield.onfocus = function() {
					$(this).hide();
					$(this.getAttribute('password-field')).show().focus();
				};
			if (inputs[i].value != '') labelfield.hide();
			inputs[i].insert({ after: labelfield });
			if (inputs[i].value == '') inputs[i].hide();
		}
		else
		{
			inputs[i].onfocus = function()
			{
				if (this.value == this.getAttribute('label')) 
				{
					this.value = '';
					$(this).removeClassName('label');
				}
			};
			if (inputs[i].hasClassName('loginlabel'))
			{
				inputs[i].onchange = function()
				{
					$(this).up().select('input.loginlabel[type=password]').each(function(pwd) {
						if (pwd.value != '' && !pwd.visible())
						{
							$(pwd.getAttribute('label-field')).hide();
							pwd.show();
						}
					});
				};
			}
		}
		inputs[i].onblur = function()
		{
			if (this.value == '')
			{ 
				if (this.getAttribute('label-field') != '' && this.getAttribute('label-field') != null)
				{
					$(this).hide();
					$(this.getAttribute('label-field')).show();
				}
				else
				{
					this.value = this.getAttribute('label');
					$(this).addClassName('label');
				}
			}
			else if (this.type == 'text' && $(this).hasClassName('loginlabel'))
			{
				$(this).up().select('input.loginlabel[type=password]').each(function(pwd) {
					if (pwd.value != '' && !pwd.visible())
					{
						$(pwd.getAttribute('label-field')).hide();
						pwd.show();
					}
				});
			}
		};
	}
}
function $LF(el)
{
	var value = ($(el) ? $_F(el) : '');
	if ($(el) && value == $(el).getAttribute('label')) value = '';
	return value;
}

if (window.$F)
{
	window.$_F = window.$F;
	window.$F = window.$LF;
}

document.observe('dom:loaded', function() { setlabeltext(); });