<% provide :title, t('.title') %>
<%= render :partial => "sidebar" %>

<div class="content">
  <%= form_tag({:action => "diff"}, :method => :get) do %>
    <%= hidden_field_tag "title", params[:title] %>

    <table id="history" width="100%">
      <thead>
        <tr>
          <th>From</th>
          <th>To</th>
          <th>Date</th>
          <th>User</th>
          <th>Changes</th>
        </tr>
      </thead>
      <tfoot>
        <tr>
          <td colspan="2"><%= submit_tag "Compare" %></td>
        </tr>
      </tfoot>
      <tbody>
        <% @wiki_pages.each_with_index do |wiki_page, i| %>
          <tr class="<%= cycle 'even', 'odd' %>">
            <td><%= radio_button_tag "from", wiki_page.version, i == 1, :id => "from_#{wiki_page.version}" %></td>
            <td><%= radio_button_tag "to", wiki_page.version, i == 0, :id => "to_#{wiki_page.version}" %></td>
            <td><%= link_to wiki_page.updated_at.strftime("%Y-%m-%d %I:%M"), :action => "show", :title => wiki_page.title, :version => wiki_page.version %></td>
            <td><%= link_to wiki_page.author, :controller => :user, :action => :show, :id => wiki_page.user_id %></td>
            <td class="change"><%= page_change(wiki_page, @wiki_pages[i + 1]) %></td>
          </tr>
        <% end %>
      </tbody>
    </table>
  <% end %>

  <script type="text/javascript">
    var from;
    var to;

    function validateFrom(self)
    {
      if(Number(self.value) >= to) return false;
      from = new Number(self.value);
      return true;
    }

    function validateTo(self)
    {
      if(Number(self.value) <= from) return false;
      to = new Number(self.value);
      return true;
    }

    for(var i=1, elem; i <= <%= @wiki_pages.length %>; i++)
    {
      elem = $("from_"+i);
      elem.onclick = function() {return validateFrom(this);};
      if(elem.checked) from = i;

      elem = $("to_"+i);
      elem.onclick = function() {return validateTo(this);};
      if(elem.checked) to = i;
    }
  </script>
</div>


<%= render :partial => "footer" %>
