(function($){
  $.fn.placeholder = function(){
    var placeholder = $(this).attr('placeholder');
    if (placeholder)
      $(this)
        .focus(function(){
          var value = $(this).val();
          var placeholder = $(this).attr('placeholder');
          if(value == placeholder)
            $(this).val('');
          $(this).removeClass('placeholder');
        })
        .blur(function()
        {
          var value = $(this).val();
          var placeholder = $(this).attr('placeholder');
          if (value == '' || value == ' ' || value == placeholder)
            $(this).addClass('placeholder').val(placeholder);
        })
        .trigger('blur');
		
    $(this).each(function(){
      if (this.tagName == 'FORM')
        var f = this;
      else
        var f = $(this).closest('FORM');
			
      if (f && f.tagName == 'FORM')
        $(f).submit(function(){
          $('.placeholder', this).each(function(){
            var placeholder = $(this).data('placeholder');
            if($(this).val() == placeholder)
              $(this).val('');
          });
        });
    });
    return this;
  };
})(jQuery);
