function countdown() {
  var length = $(this).val().length;  
  var maxLength = $(this).attr('maxlength');
  // bind on key up event  
  $(this).keyup(function(){  
    var new_length = $(this).val().length;
    
    if (new_length > maxLength) {
      $(this).val($(this).val().substring(0, maxLength));
      new_length = maxLength;
    }
    
    var remaining_chars = maxLength - new_length;
    var remaining_text = remaining_chars == 1 ? ' character remaining' : ' characters remaining';
    $(this).parent().find('.counter').html(remaining_chars + remaining_text);
  });  

  $(this).keyup();
};

$(document).ready(function() {
	$('#loginPasswordGuide, div#signup input#password-guide').focus(function() {
		$(this).hide();
		$("#loginPassword, div#signup input#user_password").show().focus();
	});

  $("form:not([onsubmit], .no-wait)").submit(function() {
	  if ($(this).attr('id') == 'login-form') {
			$("input#source-page").val(window.location.href);
			return true;
	  }
	
	  var error_fields = $("input.formfielderror,textarea.formfielderror", $(this));
      var classes = $(this).attr('class').split(" ");
      var no_validate = false;

      for(var i=0; i<classes.length; i++) {
         if (classes[i] == 'no-validate') {
            no_validate = true;
         }
     }

      $("input[type='submit']", $(this)).val("Processing...").attr('disabled', 'true');
      return true;
  });

	$("p#notice").animate( { opacity: 1}, 10000 ).fadeOut(2000);
	$("ul.just-purchased li.unlocked").animate({backgroundPosition:"(0px -500px)"}, {duration:15000});
	
  $('div#summary div.left input.text').click(function(){
      $(this).select();
  });
 
});
