<%= content_for(:header_tags) do %>
    <%= import_ke(enable_at: false) %>
<% end %>
<h3 style="float: left">
  <%=l(:label_system_message)%>
</h3><br/>
<div style="padding-top: 20px; padding-left: 5px;">
  <%= form_for(@admin_messages, :html => {:id =>'system_messages-form'}) do |f| %>
      <li>
        <label><span class="">*</span>&nbsp;<%= l(:field_title) %>&nbsp;&nbsp;：</label>
        <input type="text" name="system_message[subject]" class="hwork_input_news" id="system_message_subject" width="576px" onblur="regexTitle($(this));" maxlength="255" placeholder="255个字符以内" value="">
        <p id="title_notice_span" class="ml55"></p>
      </li>
      <li>
        <label class="fl" >&nbsp;&nbsp;<span class="c_red"></span>&nbsp;<%= l(:field_description) %>&nbsp;&nbsp;：</label>
        <%= f.kindeditor :description,:width=>'87.5%',:editor_id=>'system_message_editor' %>
        <p id="content_notice_span" class="ml55"></p>
      </li>
      <div>
        <p id="content_notice_span" class="ml55"></p>
      </div>
      <div class="cl"></div>
      <div class="actions">
        <%= link_to l(:label_submit), "javascript:void(0)", :class => "btn_message_free", :onclick => "system_message_editor.sync();submit_message();" %>
      </div>
  <% end %>
</div>
<script>
    function system_message_length() {
        var obj = system_message_editor.html();
        if (obj.length > 10000) {
            $("#content_notice_span").text("内容过长，超过10000个字符");
            $("#content_notice_span").css('color', '#ff0000');
            $("#content_notice_span").focus();
            return false;
        }
        else {
            $("#content_notice_span").text("填写正确");
            $("#content_notice_span").css('color', '#008000');
            return true;
        }
    }
    function regexTitle(obj){
        var title = obj.val();
        if(title.length == 0)
        {
            $("#title_notice_span").text("标题不能为空").css("color", "#ff0000").focus();
            return false;
        }
        else if(title.length > 255)
        {
            $("#title_notice_span").text("标题长度过长，不能超过255个字符").css("color", "#ff0000").focus();
            return false;
        }
        else{
            $("#title_notice_span").text("填写正确").css("color", "#008000");
            return true;
        }
    }
    function submit_message() {

        if (system_message_length() && regexTitle($("#system_message_subject"))) {
            $("#system_messages-form").submit();
        }
    }
</script>

