(function(){
  var inputSupport    = !!('placeholder' in document.createElement('input'));
  var textareaSupport = !!('placeholder' in document.createElement('textarea'));

  if (inputSupport && textareaSupport)
  {
    return;
  }

  $(":input").each(function(){
    var placeholder = $(this).attr('placeholder');
    if (!placeholder)
    {
      return;
    }
    $(this)
      .attr('placeholder', '')
      .attr('placeholder-save', placeholder)
      ;
    if (
      "" == $(this).val()
      || placeholder == $(this).val()
    )
    {
      $(this).val(placeholder);
      $(this).addClass("placeholder-value");
    }
    $(this).bind("focus", function(){
      $(this).removeClass("placeholder-value");
      if (placeholder == $(this).val())
      {
        $(this).val("");
      }
    });
    $(this).bind("blur", function(){
      $(this).removeClass("placeholder-value");
      if (
        "" == $(this).val()
        || placeholder == $(this).val()
      )
      {
        $(this).val(placeholder);
        $(this).addClass("placeholder-value");
      }
    });
  });
  $("form").bind("submit", function(){
    $(this).find(":input").each(function(){
      if (
        $(this).val()
        && $(this).attr("placeholder-save") == $(this).val()
      )
      {
        $(this).val("");
      }
    });
  });
})();


