<div class="sn-innner-content">
  <div class="sn-row sn-bg-white">
    <div class="sn-content-position sn-hidden"> 您的位置：<%= link_to "首页", organization_path(@organization), :class => "sn-link-grey2" %> &gt;
      <%=link_to  @org_subfield.name, organization_path(@organization, :org_subfield_id => @org_subfield.id), :class => "sn-link-grey2" %> &gt;
      <%= link_to @subdomain.name, org_subfield_sub_domain_sub_document_comments_path(:sub_domain_id => @subdomain.id, :org_subfield_id => @org_subfield.id), :class => "sn-link-grey2" %> &gt;
      <a  class = "sn-link-grey2"><%= @document.title  %></a></div>
  </div>
  <div class="sn-inner-newslist">
    <h2 class="sn-inner-newsh2 sn-hidden"><%= @document.title %></h2>
    <div class="sn-inner-newscon">
      <p class=" sn-inner-psmall">来源：<%= @organization.name %> 发布时间：<%= format_date(@document.created_at) %></p>
      <p class=" sn-inner-pcon"><%= @document.content.html_safe %></p>
    </div>
  </div>
  <!--回复-->
  <% if User.current.logged? %>
      <% comments_for_doc = @document.children.reorder("created_at desc") %>
      <% count = @document.children.count() %>
      <div class="sn-replybox">
        <h2 class="sn-reply-h2">留言板<span class="sn-fr sn-f14 sn-font-grey3 sn-mt10"><%= count %>条留言</span></h2>
        <%= form_for :org_comment, :url => {:action => 'add_reply_in_doc',:controller => 'sub_document_comments', :id => @document.id, :flag => true}, :html => {:multipart => true, :id => 'message_form', :class => "sn-reply-form", } do |f| %>
            <textarea class="sn-reply-text" name="sub_content" id="text_submain"></textarea>
            <%#= f.kindeditor :sub_content,:width=>'99%',:height => '100px;',:editor_id=>'message_content_editor', :class => "sn-reply-text" %>
            <div class="sn-reply-btnbox">
              <a href="javascript:void(0)" onclick = "org_new_files_upload()" class = "submit-btn">发表</a>
            </div>
            <p id="sub_domain_reply" style="display: none;color: #ff0000">内容不能为空</p>
            <%#= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'message_content_editor.html("");', :class => " grey_btn fr c_white mt10 mr5" %>
        <% end %>

        <div class="sn-reply-comment">
          <h2 class="sn-comment-h2">全部评论</h2>

            <div id="newstyle_reply_div_<%= document.id %>" style="display:<%= count == 0 ? 'none' : 'block' %>">
              <% comments_for_doc.each_with_index  do |reply,i| %>
                  <div class="sn-comment-listbox">
                    <a href="javascript:void(0)"  class="sn-reply-userpic fl"><img  src="images/img-news-con.jpg" width="824" height="522" alt="" /></a>
                    <%= link_to User.find(reply.creator_id).realname, user_url_in_org(reply.creator_id), :class => "sn-reply-username fl" %><span class="fl"><%= time_from_now(reply.created_at) %></span>
                    <div class="fl sn-reply-usertxt ">
                      <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id => reply.id, :content=> reply.content} %>
                      <%#= reply.content.html_safe unless reply.content.nil? %>
                    </div>
                    <!--<a href="javascript:void(0)" target="_blank" class="sn-reply-zan fl">（100）</a>-->
                    <div class="cl"></div>
                  </div>
              <% end %>
            </div>
            <% if count > 3 %>
                <div class="sn-reply-more">
                  <a id="reply_btn_<%= document.id %>" onclick="expand_reply('#newstyle_reply_div_<%= document.id %>','#reply_btn_<%=document.id%>')" data-count="<%= count %>" data-init="0" href="javascript:void(0)" value="show_help">
                    展开更多
                  </a>
                </div>
            <% end %>
          </div>
      </div>
  <% end %>
</div>

<script>
    $(document).ready(function(){
        var replyCount = $(".sn-comment-listbox").size();
        if (replyCount >3){
            for(var i= 3; i < replyCount+1; i++){
                $(".sn-comment-listbox").eq(i).hide();
            }
        }
    });
    function expand_reply(container, btnid) {
        var target = $(container).children();
        var btn = $(btnid);
        if (btn.data('init') == '0') {
            btn.data('init', 1);
            btn.html('收起回复');
            target.show();
        } else {
            btn.data('init', 0);
            btn.html('展开更多');
            target.hide();
            target.eq(0).show();
            target.eq(1).show();
            target.eq(2).show();
        }
    }

    //验证搜索时输入字
    function regexName_submain(content) {
        var name = $.trim($("#name").val());
        if (name.length == 0) {
            $("#project_name_span").text(content);
            $("#project_name_span").css('color', '#ff0000');
            $("#project_name_span").focus();
            return false;
        }
        else {
            $("#project_name_span").text("");
            return true;
        }
    }

    function org_new_files_upload(){
        var name = $.trim($("#text_submain").val());
//        content = $("#text_submain").val();
        if (name.length == 0) {
            $("#sub_domain_reply").show();
        }
        else {
            $("#message_form").submit();
        }
    }
</script>