<script type="text/javascript">
var local_host = "<%= request.host %>";

// var local_host = "<%= request.host_with_port %>"; // local test

if (local_host[0] == "g" && local_host[1] == "a") {
    local_host = "www." + local_host;
}

function hide_current_host_name(localhost) {
  $('input[type=checkbox]').each(function() {
    if ($(this).val() == local_host) {
      $(this).addClass("hide");
      $(this).next().addClass("hide");
    }
  });
}

$(document).ready(function() {

  $('.dept_options').hide();

  if ($("#ask_reply_status").val() == '轉介其他單位') {

    hide_current_host_name(local_host);

    $('.dept_options').show();
  }

  $("#ask_reply_status").change(function() {

    hide_current_host_name(local_host);

    $('.dept_options').slideUp();
    if ($(this).find('option:selected').attr('value') == '轉介其他單位') {
      $('.dept_options').slideDown();
    }
  });
});

</script>

<div id="ask_question_reply">
  <%= form_for @ask_reply, url: @url, method: @method do |f| %>
    <table class="table">
      <tr>
        <td><%= AskQuestion.human_attribute_name(:name) %>：<%= @ask_question.name %></td>
        <td><%= AskQuestion.human_attribute_name(:identity) %>：<%= @ask_question.identity %></td>
        <td><%= AskQuestion.human_attribute_name(:email) %>：<%= @ask_question.email %></td>
        <td><%= AskQuestion.human_attribute_name(:phone) %>：<%= @ask_question.phone %></td>
        <td><%= AskQuestion.human_attribute_name(:tax) %>：<%= @ask_question.tax %></td>
      </tr>
      <tr>
        <td colspan="5"><%= AskQuestion.human_attribute_name(:title) %>：<%= @ask_question.title %></td>
      </tr>
      <tr>
        <td colspan="5"><%= AskQuestion.human_attribute_name(:content) %>：<br/><%= @ask_question.content %></td>
      </tr>
      <tr>
        <td colspan="5">
          <%= f.label :content %>
          <br/> <%= f.text_area :content, rows: 10, style: 'width: 500px' %>
        </td>
      </tr>
      <tr>
        <td colspan="5">
          <%= f.label :comment %>
          <br/> <%= f.text_field :comment, style: 'width: 500px' %></td>
      </tr>
      <tr>
        <td colspan="5"><%= f.label :status %> <%= f.select :status, [
          ['待處理', '待處理'],
          ['已處理', '已處理'],
          ['轉介其他單位', '轉介其他單位']
        ] %></td>
      </tr>
      <tr>
        <td colspan="5" class="dept_options">
          <div class="checkbox">
<!--             <%= check_box("school", "depts", {:multiple => true}, (request.host + ":3000"), nil) %><%= label_tag((request.host + ":3000"), "測試站 3000") %>
            <%= check_box("school", "depts", {:multiple => true}, (request.host + ":4000"), nil) %><%= label_tag((request.host + ":4000"), "測試站 4000") %> -->
            <%= check_box("ask_reply", "depts", {:multiple => true}, "www.ga.ntu.edu.tw", nil) %><%= label_tag("www.ga.ntu.edu.tw", "總務處") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "sec.ga.ntu.edu.tw", nil) %><%= label_tag("sec.ga.ntu.edu.tw", "總務長室暨總務處秘書室") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "doc.ga.ntu.edu.tw", nil) %><%= label_tag("doc.ga.ntu.edu.tw", "文書組") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "general.ga.ntu.edu.tw", nil) %><%= label_tag("general.ga.ntu.edu.tw", "事務組") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "property.ga.ntu.edu.tw", nil) %><%= label_tag("property.ga.ntu.edu.tw", "保管組") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "construction.ga.ntu.edu.tw", nil) %><%= label_tag("construction.ga.ntu.edu.tw", "營繕組") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "cashier.ga.ntu.edu.tw", nil) %><%= label_tag("cashier.ga.ntu.edu.tw", "出納組") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "procurement.ga.ntu.edu.tw", nil) %><%= label_tag("procurement.ga.ntu.edu.tw", "採購組") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "fss.ga.ntu.edu.tw", nil) %><%= label_tag("fss.ga.ntu.edu.tw", "經營管理組") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "police.ga.ntu.edu.tw", nil) %><%= label_tag("police.ga.ntu.edu.tw", "駐警隊") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "social.ga.ntu.edu.tw", nil) %><%= label_tag("social.ga.ntu.edu.tw", "社科院總務分處") %>
            <%= check_box("ask_reply", "depts", {:multiple => true}, "medicine.ga.ntu.edu.tw", nil) %><%= label_tag("medicine.ga.ntu.edu.tw", "醫學院總務分處") %>
          </div>
        </td>
      </tr>  
      <tr>
        <td colspan="5">
          <%= f.label :send_email %><%= f.radio_button :send_email, 1, checked: @ask_reply.send_email? %><%= t('ask.yes') %>
          &nbsp;
          &nbsp;
          &nbsp;
          &nbsp;
          <%= f.radio_button :send_email, 0, checked: !@ask_reply.send_email? %><%= t('ask.no') %>
        </td>
      </tr>
      <tr>
        <td colspan="5">
          <div class="form-actions">
            <%= f.submit t('submit'), class: 'btn btn-primary' %>
            <%= f.button t('cancel'), type: 'reset', class: 'btn' %>
          </div>
        </td>
      </tr>
    </table>
  <% end %>
</div>
