<% provide(:title, 'Email Change Confirmation') %>
<div id="email-update-information" class="message-wrapper hidden">
  <div class="left"><%= image_tag 'content/icon_information_big.png',  :size=>'96x96' %></div>
  <div class="message">
    <h2>Success!</h2>
    Your email has been changed. You will receive a notice email to your old email address.
  </div>
</div>
<div id="email-update-alert" class="message-wrapper hidden">
  <div class="left"><%= image_tag 'content/icon_alert_big.png',  :size=>'96x96' %></div>
  <div class="message">
    <h2>Please Note:</h2>
    This is either an expired or invalid email change confirmation link.
  </div>
</div>

<script type="text/javascript">

  function postFinalizeUpdateEmail(token) {
      var url = "/api/users/update_email/" + token;
      return $.ajax({
          type: "POST",
          dataType: "json",
          url: url,
          async: true,
          processData: false
      });
  }

  function showUpdateEmailSuccess() {
      $('#email-update-information').show()
  }

  function showUpdateEmailFailure() {
      $('#email-update-alert').show()
  }

  $(function() {

      // check if this is a valid token
      postFinalizeUpdateEmail(gon.update_email_token)
              .done(showUpdateEmailSuccess)
              .fail(showUpdateEmailFailure)
  })


</script>


