(function($){$.fn.extend({label:function(theOptions){if(typeof(theOptions)=='string')theOptions={text:theOptions};theOptions=$.extend({emptyClass:"empty",changedClass:"changed",populateFrom:"title",text:null,removeOnSubmit:true},theOptions);return this.each(function(){var self=$(this);if(theOptions.removeOnSubmit)self.parents('form:first').submit(function(){$('input.'+theOptions.emptyClass).val('');});if(self.is(':password')){createClone(self);self.blur(function(){if(self.val().length<=0){self.data('child').show();self.hide();}});}
else{self.click(function(){if(self.val()==getText())self.val('');}).keypress(function(){if(self.val().length>0)setState(self);}).blur(function(){setState(self);}).focus(function(){if(self.val()==getText())self.val('');}).data('oClass',self.attr('class'));$.trim(self.val());setState(self);}
function setState(element){val=$.trim($(element).val());if(val.length<=0||val==getText()){$(element).removeClass(theOptions.changedClass).addClass(theOptions.emptyClass).val(getText());}
else{$(element).removeClass(theOptions.emptyClass).addClass(theOptions.changedClass);}}
function createClone(element){var _parent=element;var _child=$("<input type='text' />").attr({style:_parent.attr('style'),value:getText()}).addClass('textInput '+theOptions.emptyClass).data('parent',_parent).focus(function(){_parent.show().focus();$(this).hide()});_parent.data('child',_child).focus(function(){$(this).addClass(theOptions.changedClass)}).blur(function(){$(this).removeClass(theOptions.changedClass)}).hide().after(_child);}
function getText(){if(theOptions.text)return theOptions.text;if($.isFunction(theOptions.populateFrom))return eval(theOptions.populateFrom)();if(theOptions.populateFrom.toLowerCase()=='label')return $("label[for='"+self.attr("id")+"']").text();return self.attr(theOptions.populateFrom);}});},labelDestroy:function(){var self=$(this);self.unbind("focus",$.label).unbind("blur",$.label).unbind('keypress',$.label).unbind('click',$.label).removeClass().addClass(self.data('oClass'));self.each(function(){if($(this).data('parent')){$(this).data('parent').show();$(this).remove();}})}});})(jQuery);