       defers.push d
       encrypt(element.value, (result_string)->
         element.value = result_string.toString()
-        console.log "#{element.name} finished encryption"
         d.resolve()
       )
 

    if contains(element.name, encryption_source_names)
      element.value = ""

write_target = (buffer, data)->
  target_name = $("*[data-encrypt-target]").attr("name")
  if target_name[0]
    encrypt(buffer, (result_string) ->
      data[0].value =result_string.toString()
      #data.push {name: target_name, value: result_string.toString()}
      console.log data
    )
  else
    console.error("No target defined")

  single_defer = $.Deferred()
  group_defer = $.Deferred()
  single_encryption(form, values, (result) ->
    single_defer.resolve()
  )
  $.when(single_defer).done(()->
    group_encryption(form, values, (result) ->
      group_defer.resolve()
    )
  )
  $.when(single_defer, group_defer).done(() ->
    reinsert_values values
    form.submit()
  )

  #  source_encryption_names = find_names_for(form, "*[data-encrypt-source]")
