<% content_for :header_tags do %>
    <%= stylesheet_link_tag 'attach_screenshot', :plugin => 'redmine_attach_screenshot' %>
    <%= javascript_include_tag 'attach_screenshot', :plugin => 'redmine_attach_screenshot' %>
<% end %>
<span id="attachments_fields">
  <span>
    <%= file_field_tag 'attachments[1][file]', :size => 30, :id => nil, :class => 'file',
          :onchange => "checkFileSize(this, #{Setting.attachment_max_size.to_i.kilobytes}, '#{escape_javascript(l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)))}');"  -%>
    <label class="inline"><%= l(:label_optional_description) %><%= text_field_tag 'attachments[1][description]', '', :size => 60, :id => nil, :class => 'description' %></label>
    <%= link_to_function(image_tag('delete.png'), 'removeFileField(this)', :title => (l(:button_delete))) %>
  </span>
</span>
<small><%= link_to l(:label_add_another_file), '#', :onclick => 'addFileField(); return false;' %>
(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</small>
<br />
<br />
<% if @issue %>
<% if @issue.new_record? %>
    <label>
<% end %>
<%= l(:label_screenshots) %>
<% if @issue.new_record? %>
    </label>
<% else %>
    <br />
<% end %>
<span id="attach_applet" style="display: none; position: fixed; top: 50px; left: 10px; border: solid 1px #BBB;"></span>
<span id="screenshots_fields">
<%= submit_tag l(:button_add), :onclick => 'showAttachScreen(); return false;'%>
</span>
<small><%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>
</small>
<br />
<span id="screenshots"></span>
<br />

<script type="text/javascript">
    function showAttachScreen() {
        document.getElementById('attach_applet').style.display = 'block';
        document.getElementById('attach_applet').innerHTML = '<applet codebase="<%= url_for(:only_path => false, :controller => 'welcome')%>plugin_assets/redmine_attach_screenshot/javascripts/" code="com.axmor.redmine.uploader.Uploader.class" archive="uploader_applet.jar" height="600" width="700" MAYSCRIPT>'+
                                                             '<param name="label.image" value="<%= l(:label_image) %>">' +
                                                             '<param name="label.button.paste" value="<%= l(:label_button_paste) %>">' +
                                                             '<param name="label.button.attach" value="<%= l(:button_attach) %>">' +
                                                             '<param name="label.button.cancel" value="<%= l(:button_cancel) %>">' +
                                                             '<param name="error.close.msg" value="<%= l(:error_close_msg) %>">' +
                                                             '<param name="error.close.title" value="<%= l(:error_close_title) %>">' +
                                                             '<param name="attach.url" value="<%= url_for(:only_path => false, :controller => 'welcome')%>attach_screenshot">' +
                                                             '<param name="error.attach.msg" value="<%= l(:error_attach_msg) %>">' +
                                                             '<param name="error.attach.title" value="<%= l(:error_attach_title) %>">'	 +
                                                             '<param name="rss.key" value="<%= User.current.rss_key %>">'	 +
                                                             'Applet</applet>';
    }
    function addAttachScreen(fileId) {
        var s = document.createElement("span");
        s.id = fileId;
        s.className = "screen_thumb";

        var s1 = document.createElement("span");
        s1.className = "st1";
        var s2 = document.createElement("span");
        s2.className = "st2";

        var im = document.createElement("img");
        im.src = "<%= url_for(:only_path => false, :controller => 'welcome')%>attach_screenshot?id=" + fileId;

        var b = document.createElement("input");
        b.type = "image";
        b.src = "<%= url_for(:only_path => false, :controller => 'welcome')%>images/delete.png"
        b.setAttribute("onClick", "deleteAttachScreen('" + fileId + "'); return false;");

        var i = document.createElement("input");
	    i.type = "image";
	    i.src = "<%= url_for(:only_path => false, :controller => 'welcome')%>images/lightning.png";
	    i.setAttribute("onClick", "addLinkToAttachScreen('" + fileId + "'); return false;");

        var d = document.createElement("input");
        d.name = "screenshots[" + fileId + "][description]";
        d.type = "text";
        d.size = 15;

        s1.appendChild(im);
        s.appendChild(s1);
        s2.appendChild(d);
        s2.appendChild(b);
        s2.appendChild(i);
        s.appendChild(s2);

        p = document.getElementById("screenshots");
        p.appendChild(s);
    }
</script>
<% end %>
