<% content_for :head do %>
<script type="text/javascript">
// <![CDATA[
function updateSnippet() {
  var title = $F('campaign_name');
  var dir = $F('campaign_dir_name');
  if (title && dir) {
    $('snippet').value = "<"+"%= link_to_campaign '"+title+"', '"+dir+"' %>";
  }
  else {
    $('snippet').value = '';
  }
}
Event.observe(window, 'load', function() {
  updateSnippet();
  Event.observe('campaign_name', 'keyup', updateSnippet);
  Event.observe('campaign_dir_name', 'keyup', updateSnippet);
  Event.observe('snippet', 'focus', function(e) {
    e.target.select();
  });
});
// ]]>
</script>
<% end %>

<% form_for [:admin, @campaign] do |f| %>
  <%= f.error_messages %>
  <p class="req"><span class="pnt">※</span>は必須入力です</p>
  <table class="data" cellspacing="1" cellpadding="0">
    <tr>
      <th>キャンペーン名 <span class="pnt">※</span></th>
      <td><%= confirm_tag :text_field, :campaign, :name, :class => "data_l" %></td>
    </tr>
    <tr>
      <th>ディレクトリ名 <span class="pnt">※</span></th>
      <td><%= confirm_tag :text_field, :campaign, :dir_name, :class => "data_l" %></td>
    </tr>
    <tr>
      <th>開始日時 <span class="pnt">※</span></th>
      <td>
        <%= confirm_tag :calendar_date_select,
                        :campaign,:opened_at,
                       {:start_year => 5.years.ago.year,
                        :use_month_numbers => true, 
                        :end_year => Date.today.year} %>
      </td>
    </tr>
    <tr>
      <th>終了日時 <span class="pnt">※</span></th>
      <td>
        <%= confirm_tag :calendar_date_select,
                        :campaign,:closed_at,
                       {:start_year => 5.years.ago.year,
                        :use_month_numbers => true, 
                        :end_year => Date.today.year} %>
      </td>
    </tr>
    <tr>
      <th>申込制限数</th>
      <td><%= confirm_tag :text_field, :campaign, :max_application_number, :size => "5" %>件で終了ページに切り替え</td>
    </tr>
    <tr>
      <th>重複申込制御</th>
      <td><%= confirm_tag :check_box, :campaign, :repeat_application %> 重複申込を制御する</td>
    </tr>
    <tr>
      <th>商品ID</th>
      <td><%= confirm_tag :text_field, :campaign, :product_id, :class => "data_m" %></td>
    </tr>
    <tr>
      <th>リンク用タグ</th>
      <td><input type="text" size="80" id="snippet" readonly="readonly" /></td>
    </tr>
  </table>
  <div class="btn_box">
    <%= f.submit "この内容で登録する", :onclick => "return #{confirm_javascript_function("登録しても宜しいですか")}", :class => "btn" %>
    <%= image_tag("btn_side.gif", :width => "6", :height => "34", :class => "btn_side") %>
  </div>
<% end %>
