SBN.Account = new Object();
SBN.Account.claimedUsernames = new Hash();

SBN.Account.checkUsername = function() {
  val = escape($F('user_username'));
  if (val.length < 2) {
    $('username_availability').innerHTML = "";
  } else {
    new Ajax.Updater(
      'username_availability',
      SBN.Account.usernameSearchUrl,
      {
        asynchronous:true,
        evalScripts:true,
        onComplete:function(request){Element.hide('search_spinner')},
        onLoading:function(request){Element.show('search_spinner')},
        parameters:'username=' + val
      }
    ); 
  } 
}

SBN.Account.openClaimAccountModal = function() {
  SBN.openModalWithContents("Please wait while we set up your new account. If you're claiming many old blog accounts, this may take a few moments.");
}

SBN.Account.alreadyClaimedAccount = function() {
  if (SBN.Account.claimedUsernames[$F('legacy_blog_id') + "-" + $F('legacy_nickname')] == true) {
    $('claim_account_error').show();
    Element.update("claim_account_error", "You have already claimed this account.");
    new Effect.Highlight("claim_account_error",{});
    return true;
  } else {
    return false;
  }
}

SBN.Account.claimAccount = function(legacy_blog_id, username) {
  SBN.Account.claimedUsernames[legacy_blog_id + "-" + username] = true;
}

SBN.Account.forgotLegacyPassword = function(url) {
  url = url + '?legacy_blog_id=' + $F('legacy_blog_id');
  window.open(url); 
}