<% content_for :head do %>
 <%= javascript_include_tag "admin/shop" %>
 <script type="text/javascript">
  // <![CDATA[
Event.observe(window, 'load', function() {
  var form = document.forms["delivery_form"];
  Event.observe(form, 'submit', function(event) {
    defrag(form, event);
  });
});
  // ]]>
 </script>
<% end %>
<%=h flash[:notice] %>
<%=h flash[:error] %>
<%= error_messages_for :delivery_trader %>
<%if @delivery_time %>
<% @delivery_time.each do|dt|%>
<%= dt.errors.full_messages.collect {|msg| content_tag("li", "#{msg}", :class => "err") }.join  if dt.errors.full_messages.size != 0%>
<%end%>
<%end%>
<% @delivery_fee.each do|df|%>
<%= df.errors.full_messages.collect {|msg| content_tag("li", "#{df.prefecture_name}の#{msg}", :class => "err") }.join  if df.errors.full_messages.size != 0%>
<%end%>

<table class="data2" cellspacing="1" cellpadding="0">
  <tr>
    <th>配送業者名 </th>
    <td><%= text_field "delivery_trader", "name" %></td>
  </tr>
  <tr>
    <th>伝票No.URL</th>
    <td><%= text_field "delivery_trader", "url" %></td>
  </tr>
</table>
<%= hidden_field_tag "delivery_trader[retailer_id]", session[:admin_user].retailer_id %>
<table class="data2" cellspacing="1" cellpadding="0">
    <tr>
<%  DeliveryTime::MAX_SIZE.times do |i|%>
<%time=nil-%>
<%time=@delivery_time[i].name unless @delivery_time[i].blank? -%>
<%code=@delivery_time[i].code unless @delivery_time[i].blank? -%>
<%- if i==0 || i%2 == 0 -%><tr><%end%>
    <th>配送時間<%=i+1%></th>
    <td><%= text_field "delivery_time[#{i}]", "name",:value=>time, :size => 20 %></td>
    <th>コード<%=i+1%></th>
    <td><%= text_field "delivery_time[#{i}]", "code",:value=>code, :size => 3 %></td>
<%-if i%2 >0%></tr><%end%>
  <%-end-%>
</table>

<br />
<h2>配送料登録</h2>
<br />
<p class="req"><span class="pnt">※</span>は必須入力です</p>
<table class="data2" cellspacing="1" cellpadding="0">
  <tr>
    <th>全国一律送料</th>
    <td colspan="3" style="width:580px"><%= text_field_tag "delivery_fee_all" %> 円に設定する　<%= button_to_function "反映", "fnSetDelivFee(47)" %>　</td>
  </tr>

<% @delivery_fee.each_with_index do |delivery_fee, i| %>
 <%- if i==0 || i%2 == 0 -%><tr><%end%>
   <th><%= delivery_fee.prefecture_name %> <span class="pnt">※</span></th>
  <td><%= number_field("delivery_fee[]", "price", :object => delivery_fee, :index=>i) %>円</td>
 <%-if i%2 >0%> </tr><%end%>
<%-end-%>

</table>
<div class="btn_box">
  <%= button_to_function " 前のページに戻る ", "form.action = '#{url_for :action => 'delivery_list'}'; form.submit()", :onclick => true, :class=>"btn" %>
  <%= image_tag("btn_side.gif", :width => "6", :height => "34", :class => "btn_side") %>
  <%= submit_tag "この内容で登録する", :class=>"btn" %>
  <%= image_tag("btn_side.gif", :width => "6", :height => "34", :class => "btn_side") %>
</div>

