<% # encoding: utf-8 %>

  <%= f.error_messages %>
	
  <div class="field">
    <%= f.label :category %><br />
	<%= f.select :bulletin_category_id, @bulletin_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ]} %>
  </div>
  
  <div class="field">
    <%= f.label :image, t('announcement.image') %><br />
    <%= f.file_field :image %>
	<% if @bulletin.image.file %>
	  <%= check_box_tag 'bulletin[image_del]' %>
	  <%= t('announcement.刪除已上傳檔案') %>
	<% end %>
  </div>
  
  <div class="field">
    <%= f.label :title %><br />
    <%#= f.text_field :title %>
	<%= f.fields_for :title_variable, (@bulletin.new_record? ? @bulletin.build_title_variable : @bulletin.title_variable) do |f| %>
	  <% @site_valid_locales.each do |locale| %>
		<%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %>
		<%= f.text_field locale, :style => "width:130px" %>
	  <% end %>
	<% end %>
  </div>
  
  <div class="field">
    <%= f.label :subtitle %><br />
    <%#= f.text_area :subtitle,  :rows => 10, :cols => 40 %>
	<%= f.fields_for :subtitle_variable, (@bulletin.new_record? ? @bulletin.build_subtitle_variable : @bulletin.subtitle_variable) do |f| %>
	  <% @site_valid_locales.each do |locale| %>
		<%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %>
		<%= f.text_area locale,  :rows => 10, :cols => 40 %>
	  <% end %>
	<% end %>
  </div>
  
  <div class="field">
    <%= f.label :text %><br />
    <%#= f.text_area :text,  :rows => 10, :cols => 40 %>
	<%= f.fields_for :text_variable, (@bulletin.new_record? ? @bulletin.build_text_variable : @bulletin.text_variable) do |f| %>
	  <% @site_valid_locales.each do |locale| %>
		<%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %>
		<%= f.text_area locale,  :rows => 10, :cols => 40 %>
	  <% end %>
	<% end %>
  </div>
  
  <div class="field">
    <%= f.label :postdate %><br />
    <%= f.date_select :postdate, :order => [:year, :month, :day], :use_month_numbers => true %>
    <%#= date_select("bulletin", "postdate", :use_month_numbers => true) %>
  </div>
  
  <div class="field">
    <%= f.label :deadline %><br />
    <%= f.date_select :deadline, :use_month_numbers => true, :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year'}  %>
    <%#= f.date_select :deadline, :order => [:year, :month, :day],:default => 1.years.from_now, :use_month_numbers => true  %>
  </div>
  
  <div class="field">
    <%= f.label :url %><br />
    <%= f.text_field :url, :size => 60 %>
  </div>
  
  
  
  <div id='bulletin_files' class="bulletin_files_block <%= @class %>">
	
	<div id='add_bulletin_file' class="info_input bulletin_files_block">
		<h2>Bulletin files</h2>
		<%= hidden_field_tag 'bulletin_file_field_count', @bulletin.bulletin_files.count %>
		<a href="#" class="add"><%= t(:add) %></a>
	</div>
	
	<%#= render :partial => 'file', :locals => { :bulletin_files => @bulletin.bulletin_files , :f => f} %>
	
	
	<% @bulletin.bulletin_files.each_with_index do |bulletin_file, i| %>
		<%#= fields_for "bulletin[bulletin_files][]", bulletin_file do |f| %>
		<%= f.fields_for :bulletin_files, bulletin_file do |f| %>
			<%= render :partial => 'bulletin_file', :object => bulletin_file, :locals => {:f => f, :i => i} %>
		<% end %>
	<% end %>	
	
  </div>
  
  <br />
  <br />
  
  
  <div class="actions">
    <%= f.submit %>
  </div>
  
  

<% content_for :page_specific_javascript do %>
	<%= javascript_include_tag "bulletin_form" %>
	<script>
		$('#add_bulletin_file a.add').live('click', function(){
			var new_id = $(this).prev().attr('value');
			var old_id = new RegExp("new_bulletin_files", "g");
			$(this).prev().attr('value', parseInt(new_id) + 1);
		  $('#bulletin_files').append(("<%= escape_javascript(add_attribute 'bulletin_file', f, :bulletin_files) %>").replace(old_id, new_id));
		});
	</script>
<% end %>
 