(function($) {

  $.fn.compact_form = function () {

    $('input.form-text[id]', $(this)).each(function() {
      if (id = $(this).attr('id')) {
        if (label = $('label[for="'+ id +'"]')) {
          $(label).hide();

          $(this).data('label_text', $(label).text().replace(":","").replace(/[\s]+$/,''));

          $(this).focus(function() {
            $(this).removeClass("no-value");
            if ($(this).val() == $(this).data('label_text')) {
              $(this).val('');
            }
          });

          $(this).blur(function() {
            if (!$(this).val()) {
              $(this).addClass("no-value");
              $(this).val($(this).data('label_text'));
            }
          });

          $(this).blur();

          if ($(this).data('label_text') == $(this).val()) {
            $(this).addClass("no-value");
          }
        }
      }
    });
  }
  
})(jQuery);

