<!-- http://webdeveloper.beforeseven.com/jquery/default-text-field-value-disappears-focus -->
var active_color = '#000'; // Colour of user provided text
var inactive_color = '#231F20'; // Colour of default text

$(document).ready(function() {

		$('input:password').each( function() {

			$(this).prev("label").hide();
			
			var value = this.value;
			var name  = this.name;
							
			$(this).hide();
			$(this).after("<input type=\"text\" value=\"" + value + "\" size=\"30\" class=\"default-value password\">");
			
			$(this).blur( function() {
				if( this.value == '' ) {
					$(this).hide();
					$(this).next(".password").show();
				}
			})

		});


  $(".default-value").css("color", inactive_color);
  var default_values = new Array();


		$(".password").focus(function() {
			$(this).hide();
			var default_value = this.value;
			
			var password_field = $(this).prev("input:password").get(0);
			$(password_field).show().trigger("focus");
			if ( default_value == password_field.value ) {
				password_field.value = "";
			}
			
		});

  $(".default-value:not(.password)").focus(function() {
    if (!default_values[this.id]) {
      default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
      this.value = '';
      this.style.color = active_color;
    }
    // used by inputs and textareas 
    $(this).blur(function() {
      if (this.value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
      // clear the red error background when appropriate
      else if (this.value != default_values[this.id] && $(this).parent(".fieldWithErrors").length > 0) {
        this.style.background = 'transparent';
      }
    });
  });

  // NB - special case the select and textarea since neither can use the default-value bits above

  // NB - 12 april 2008 nicole says back to black text, no inactive color
  // setup the select as inactive when necessary
  // select = $("#store_information_product_type")[0];
  // if (select.selectedIndex < 2)
  //   $(select).css("color", inactive_color);

  $("#store_information_product_type").focus(function() {
    // if (this.selectedIndex < 2) {
    //   this.style.color = active_color;
    // }

    $(this).change(function() {
      // set it back to inactive if a valid selection hasn't been made
      // if (this.selectedIndex < 2) {
      //   this.style.color = inactive_color;
      //   // clear the red error background when appropriate
      // } else if (this.selectedIndex > 1 && $(this).parent(".fieldWithErrors").length > 0) {
      //   this.style.color = active_color;
      //   this.style.background = 'rgb(255,255,254)'; // see screen.css #retailSignup select
      // } else if (this.selectedIndex > 1) {
      //   this.style.color = active_color;
      // }

      if (this.selectedIndex > 1 && $(this).parent(".fieldWithErrors").length > 0) {
        this.style.color = active_color;
        this.style.background = 'rgb(255,255,254)'; // see screen.css #retailSignup select
      }
    });
  });


  // setup the textarea as inactive when necessary 
  textarea = $("#store_information_product_labels_and_brands")[0];
  id = textarea ? textarea.id : null;
  if ( id ) {
	 if (!default_values[id])
	    default_values[id] = $("#store_information_product_labels_and_brands_default").text();
	  if ($(textarea).text() == default_values[id])
	    $(textarea).css("color", inactive_color);
	
  }
 
  // for the product textarea
  $("#store_information_product_labels_and_brands").focus(function() {
    value = this.value;
    if (value == default_values[this.id]) {
      this.value = ''
      this.style.color = active_color;
    }

    // when edit is done
    $(this).blur(function() {
      value = this.value;
      if (value == '') {
        this.style.color = inactive_color;
        this.value = default_values[this.id];
      }
      // clear the red error background when appropriate
      else if (value != default_values[this.id] && $(this).parent(".fieldWithErrors").length > 0) {
        this.style.background = 'transparent';
      }
    });
  });

});