/***********************************************************
Scriptname: 	jquery.fiedlabel.js
Dependencies: 	jquery.1.4.3
Version: 		1.0 live
Description:	placing labels in input fields

Copyright: 		Webavance B.V. 2011 for Dusk!
Legal: 			Any use of this script without Webavance B.V.
				express written consent is prohibited
************************************************************/

(function($) {
	
	$.fn.fieldlabel = function(c) {
		var e = $(this);
		if (!c) c = {};
		
		c = $.extend({
			'clss': 'fieldlabel_islabel'
		}, c);
		
		e.find('label').each( function(i, j) {
			j = $(j);
			
			var nm = j.attr('for');
			var val = j.text();
			if (nm===undefined || nm.length==0 || val.length==0 || $('[name=' + nm + ']').length<1) return false;
			
			j.css({ display: 'none' });
			var inp = $('[name=' + nm + ']');
			
			inp
				.val(val)
				.attr({ lblval: val })
				.addClass(c.clss)
				.bind('focus', function() {
					if ($(this).val()==$(this).attr('lblval')) $(this).val('');
				})
				.bind('blur', function() {
					if ($(this).val().length==0) $(this).val($(this).attr('lblval'));
				});
		});
	};
	
})($);
