 
   # set textareas to autosize
   $('textarea').autosize()
+
+  # set an OAuth expiration callback
+  if get_cookie 'access_token_expires_at'
+    authorization_expires_in = parseInt(get_cookie('access_token_expires_at')) - Date.now()
+    console.log "Disabling submit in #{authorization_expires_in}ms"
+    setTimeout ->
+      disable_submit()
+    , authorization_expires_in
 
 # set the author name using Google profile information
 set_author_name = (callback) ->

  else
    window.location.href + new_hash
  history.pushState(null,$(selected).text(),new_url)

build_collection_editor_from_capabilities = (capabilities_url) ->
  $.ajax capabilities_url,

  history.replaceState(null,'',window.location.href.replace("#{location.hash}",hash_string))
  return params

expires_in_to_date = (expires_in) ->
  cookie_expires = new Date
  cookie_expires.setTime(cookie_expires.getTime() + expires_in * 1000)
  return cookie_expires

set_cookie = (key, value, expires_in) ->
  cookie = "#{key}=#{value}; "
  cookie += "expires=#{expires_in_to_date(expires_in).toUTCString()}; "
  cookie += "path=#{window.location.pathname.substring(0,window.location.pathname.lastIndexOf('/')+1)}"
  document.cookie = cookie

