/*
 * Requires JQuery (Written using ver 1.2)
 * www.jquery.com
 */

$(document).ready(function() { 
 labelTransplant();
 textfieldClear();
});

/* */
function labelTransplant() {
 // Find labels
 var labels = $('label');

 // Grabb the 'for' attribute and text for each label
 jQuery.each(labels, function() {
   var label_for = $(this).attr('for');
   var label_text = $(this).text();

   // Find the corresponding input element
   if ('input#'+label_for) {

     // Set the field 'value' attribute to the label's text
     var target = 'input#'+label_for;
     $(target).attr('value', label_text);
   }
 });
}

/* */
function textfieldClear() {
  // Find text fields
  var targets = $('input[type="text"]');
  
  // Set listener on each text field
  jQuery.each(targets, function() {
  
    $(this).one('click', function() {
      $(this).attr({value: ""});
    });
  
  });
  
}