var modalId =  "easy_project_com-ajax_modal-time_entries-new";
var m = document.getElementById(modalId);
if(!m) {
  m=document.createElement("div");m.style.display="none";m.id=modalId;
  document.body.appendChild(m);
}
m.innerHTML = "<%= j render('easy_time_entries/form', formats: [:html]) %>";
m.querySelector('.form-actions').remove();
showModal(m.id);
var $m = $('#' + m.id);
$m.dialog('option', {
  buttons: [
    {
      text: '<%=j l(:button_create) %>',
      click: function() {$(this).find('form:first').submit();}, 'class': 'button-positive'
    },
    {
      text: '<%=j l(:button_cancel) %>',
      click: function() {$(this).dialog('close');}, 'class': 'button'
    }
  ]
});
$m.find('#time_entry_hours').focus();
commentId = $m.find('.spent_on')[0].id;
$m.find("#project_id").change(function(event){
  fillFormTextAreaFromCKEditor(commentId);
  if (event.target.value !== '') {
    $.get('<%= j bulk_time_entries_path(project_changed: '1', format: 'js').html_safe %>', $(event.target.form).serialize());
  }
});
$m.find("#issue_id").change(function(event) {
  fillFormTextAreaFromCKEditor(commentId);
  $.get('<%= j bulk_time_entries_path(issue_changed: '1', format: 'js', project_id: @project).html_safe %>', $(event.target.form).serialize());
});
$m.find(".timeentry-activity").change(function(event) {
  fillFormTextAreaFromCKEditor(commentId);
  $.get('<%= j bulk_time_entries_path(activity_changed: '1', format: 'js', project_id: @project).html_safe %>', $(event.target.form).serialize());

});
