       dataType: 'json'
       crossDomain: true
       error: (jqXHR, textStatus, errorThrown) ->
-        $('#results').append($('<div/>',{class: 'alert alert-danger', role: 'alert'}).text("Error in Google Books AJAX call for identifier #{gb_id}"))
-        console.log jqXHR
-        console.log errorThrown
-        console.log "AJAX Error: #{textStatus}"
-      success: (data) ->
-        console.log "#{identifier_type} query #{identifier} Google Books result:"
-        console.log data
+        if jqXHR.responseJSON.error.errors[0].domain == 'usageLimits'
+          unless $('#gb_quota_error').length
+            $('#results').append($('<div/>',{id: 'gb_quota_error', class: 'alert alert-danger', role: 'alert'}).text("Error in Google Books AJAX call: Google Books API Quota daily limit exceeded. Please try again tomorrow for improved results."))
+        else
+          $('#results').append($('<div/>',{class: 'alert alert-danger', role: 'alert'}).text("Error in Google Books AJAX call for identifier #{identifier}"))
+          console.log jqXHR
+          console.log errorThrown
+          console.log "AJAX Error: #{textStatus}"
+      success: (data) ->
+        # console.log "#{identifier_type} query #{identifier} Google Books result:"
+        # console.log data
         if data and data.items and (data.items.length > 0)
           for item in data.items
             gb_biblio_query(item.id, score)

html_id = (input) ->
  input.replace(/[\/:$.,'-]/g,'_')

# wrap values in single quotes and backslash-escape single-quotes
fusion_tables_escape = (value) ->
  "'#{value.replace(/'/g,"\\\'")}'"

fusion_tables_query = (query, callback, error_callback) ->
  console.log "Query: #{query}"
  switch query.split(' ')[0]
    when 'SELECT'
      $.ajax "#{FUSION_TABLES_URI}/query?sql=#{query}&key=#{GOOGLE_API_KEY}",
        type: 'GET'
        dataType: 'json'
        crossDomain: true
        error: (jqXHR, textStatus, errorThrown) ->
          # $('#results').append($('<div/>',{class: 'alert alert-danger', role: 'alert'}).text("Error in Fusion Tables AJAX call."))
          console.log jqXHR
          console.log errorThrown
          console.log "AJAX Error: #{textStatus}"
          error_callback() if error_callback?
          console.log "Retrying Fusion Tables query: #{query}"
          fusion_tables_query(query, callback, error_callback)
        success: (data) ->
          console.log "Fusion Tables result for #{query}:"
          console.log data
          if callback?
            callback(data)

ht_rights = (usRightsString) ->
  if usRightsString? and (usRightsString.toLowerCase() == 'full view')
    return ''

ia_query = (ia_id, level = 0) ->
  if ia_id not in QUERIED_IDS['ia']
    QUERIED_IDS['ia'].push ia_id
    $.ajax "#{API_GATEWAY_URI}/ht-ia/ia/#{ia_id}",
      type: 'GET'
      cache: true
      dataType: 'json'
      crossDomain: true
      error: (jqXHR, textStatus, errorThrown) ->
        $('#results').append($('<div/>',{class: 'alert alert-danger', role: 'alert'}).text('Error in Book Aligner IA/HT AJAX call.'))
        console.log errorThrown
        console.log "AJAX Error: #{textStatus}"
      success: (data) ->
        if data.length
          process_ht_id(result.ht_identifier, (1 - level) * parseInt(result.score)) for result in data
          if level == 0
            ht_query(result.ht_identifier,1) for result in data
    $.ajax "#{API_GATEWAY_URI}/ia-gb/ia/#{ia_id}",
      type: 'GET'
      cache: true
      dataType: 'json'
      crossDomain: true
      error: (jqXHR, textStatus, errorThrown) ->
        $('#results').append($('<div/>',{class: 'alert alert-danger', role: 'alert'}).text('Error in Book Aligner IA/GB AJAX call.'))
        console.log errorThrown
        console.log "AJAX Error: #{textStatus}"
      success: (data) ->
        if data.length
          process_gb_id(result.gb_identifier, (1 - level) * 100) for result in data
          if level == 0
            gb_query(result.gb_identifier,1) for result in data

ia_url = (ia_id) ->
  "https://archive.org/details/#{ia_id}"
