/*
 * label2value
 * jquery based script for using form labels as text field values
 * more info on http://cssglobe.com/post/1500/using-labels- 
 *
 * Copyright (c) 2008 Alen Grakalic (cssglobe.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */
var $j = jQuery.noConflict();
this.label2value = function(){	
	// CSS class names
	// put any class name you want
	// define this in external css (example provided)
	var inactive = "inactive";
	var active = "active";
	var focused = "focused";
	
	// function
	$j("label").each(function(){		
		obj = document.getElementById($j(this).attr("for"));
		if(($j(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){			
			$j(obj).addClass(inactive);			
			var text = $j(this).text();
			$j(this).css("display","none");			
			$j(obj).val(text);
			$j(obj).focus(function(){	
				$j(this).addClass(focused);
				$j(this).removeClass(inactive);
				$j(this).removeClass(active);								  
				if($j(this).val() == text) $j(this).val("");
			});	
			$j(obj).blur(function(){	
				$j(this).removeClass(focused);													 
				if($j(this).val() == "") {
					$j(this).val(text);
					$j(this).addClass(inactive);
				} else {
					$j(this).addClass(active);		
				};				
			});				
		};	
	});		
};
// on load
$j(document).ready(function(){	
	label2value();	
});
