/*
 * jQuery autoClear (input text auto clear when clicked)
 * @copyright Stephan Paquet http://stephanpaquet.com


	# version 1.0
		version original
		 
 #version 1.1
	- now the check is on focus to replace on click  
 */

jQuery.fn.autoclear = function(param) {
	// for each matched elements
	this.each(
		function() {
			var jNode = $( this );
			var title = $( this ).attr('title');
			$(this).attr('title', '')
			
			// when the box is empty we display the title like tips
			if( $(this).val() == '' )
			{
				$(this).val(title);
			}
			
			// on focus...
			$(this).focus(
				function(){
					// when the input is the same of the title we clean it
					if(title == $(this).val())
					{
						$(this).val('');
					}					
				}
			);

			// on blur
			$(this).blur(
				function(){
					// if the input value is empty, we display the title
					if($(this).val() == '')
					{
						$(this).val(title);
					}
					
				}
			);
			
			// the form parent of the input
			$(this).parents('form').submit(
				function() {
					// we do not want to sent the actual content when it's the same of the title
					if(title == (jNode).val()) {	
						(jNode).val('');
					}
			}) ;
	
		}
	);
	return this;
};
