<% url_options = params_for(:action => :add_existing) -%>
<% if request.xhr? -%>
<%= form_remote_tag :url => url_options,
                    :after => "$('#{loading_indicator_id(:action => :add_existing, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :add_existing)}');",
                    :complete => "$('#{loading_indicator_id(:action => :add_existing, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :add_existing)}');",
                    :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')",
                    :html => { :href => url_for(url_options),
                    :id => element_form_id(:action => :add_existing),
                    :class => 'create' } %>
<% else -%>
<%= form_tag url_options,
             :id => element_form_id(:action => :add_existing),
             :class => 'create' %>
<% end -%>

  <h4><%= active_scaffold_config.nested.label -%></h4>

  <% if request.xhr? -%>
    <div id="<%= element_messages_id(:action => :add_existing) %>" class="messages-container"></div>
  <% else -%>
    <%= render :partial => 'form_messages' %>
  <% end -%>

  <label for="<%= "record_#{active_scaffold_config.model}" %>"><%= active_scaffold_config.model.human_name %></label>
  <%# select_options = options_for_select(options_for_association(nested_association)) unless column.through_association? -%>
  <% select_options ||= options_for_select(active_scaffold_config.model.find(:all).collect {|c| [h(c.to_label), c.id]}) -%>
  <% unless select_options.empty? -%>
    <%= select_tag 'associated_id', '<option value="">' + as_(:_select_) + '</option>' + select_options %>
  <% end -%>

  <p class="form-footer">
    <%= submit_tag as_(:add), :class => "submit" %>
    <%= link_to as_(:cancel), params_for(:action => 'list'), :class => 'cancel' %>
    <%= loading_indicator_tag(:action => :add_existing, :id => params[:id]) %>
  </p>

</form>
<script type="text/javascript">
Form.focusFirstElement('<%= element_form_id(:action => :add_existing) -%>');
</script>
