
/*

	Text Input Clearer - jQuery plug-in
	
	

	-----------------------------------------------------------------------------------------------------------------------------

*/

(function($){



$.fn.TextInputClearer = function(options)
{
	
	var o = jQuery.extend({//Default values
		blurSuccess: function(){},
		blurFail: function(){}
	},options);	
	
	return this.each(function(){//Loop through each parent element
		
		var defaultValue = ($(this).attr('rel') && $(this).attr('rel').length > 0) ? jQuery.trim($(this).attr('rel').toLowerCase()) : null;
		
		$(this).click(function(){//click event
			var curValue = ($(this).val() && $(this).val().length > 0) ? jQuery.trim($(this).val().toLowerCase()) : null;
			if((defaultValue && curValue) && (defaultValue == curValue))$(this).val('');
		}).focus(function(){//focus event
			var curValue = ($(this).val() && $(this).val().length > 0) ? jQuery.trim($(this).val().toLowerCase()) : null;
			if((defaultValue && curValue) && (defaultValue == curValue))$(this).val('');
		}).blur(function(){
			var curValue = ($(this).val() && $(this).val().length > 0) ? jQuery.trim($(this).val().toLowerCase()) : null;
			if(!curValue)
			{
				$(this).val($(this).attr('rel'));
				jQuery.proxy(o.blurFail,this)();
			} else {
				jQuery.proxy(o.blurSuccess,this)();
			}
		});
	});
	
	
};
		  
})(jQuery);

































