(function($){  
	$.labelsAsValues = function(classname) {
		if(classname == null) {
			var classname = 'as-value';	
		}
		
		$('label.'+classname).each(function(i){
			var target = $('#'+$(this).attr('for'));
			var value  = $(this).text();
			
			if(target) {
				$(this).css('display', 'none');
				
				if(target.val().length == 0) {
					target.val(value);
				}
				
				target.focus(function(){
					if($(this).val() == value) {
						$(this).val('');	
					}
				});
				
				target.blur(function(){
					if($(this).val().length == 0) {
						$(this).val(value);	
					}
				});

				target.closest('form').submit(function() {
					if (target.val() === value) {
						target.val('');
					}
				});
			}
		});
	};
})(jQuery); 
