/**
 * This plugin is used to generate a textbox with default input
 */
(function($) {
	
	$.fn.simpleTextbox = function(options) {
		var opts = $.extend({}, $.fn.simpleTextbox.defaults, options);
		
		if (opts.inputId != '') {
			var myInput = $('#' + opts.inputId);
		}
		
		//////////////////////////////////////////////////////////////
		//	Bind change event of the textbox
		$(this).bind("change", function(e){
			if (opts.inputId != '')
				$(myInput).val($(this).val());

			var textVal = $.trim($(this).val());
			if (textVal=="" || textVal==opts.emptyText) {
				$(this).val(opts.emptyText);
				$(this).addClass(opts.emptyClass);
			}
			else
				$(this).removeClass(opts.emptyClass);
		});

		//////////////////////////////////////////////////////////////
		//	Bind focus event of the textbox
		$(this).focus(function(){
			if ($.trim($(this).val()) == opts.emptyText)
				$(this).val('');
			$(this).removeClass(opts.emptyClass);
		});

		$(this).blur(function(){
			if ($.trim($(this).val()) == "") {
				$(this).val(opts.emptyText);
				$(this).addClass(opts.emptyClass);
			}
		});

		//////////////////////////////////////////////////////////////
		//	Initially set change to the default
		if ($(this).val() == '' || $(this).val() == opts.emptyText)
			$(this).trigger('change');
	};
	
	$.fn.simpleTextbox.defaults = {
		emptyClass : "",
		emptyText : "",
		inputId : ""
	};

})(jQuery);
