<div class="boxContainer" style="height: auto;">
  <div>
    <div class="sendText fl mr10" style="width: auto">发送到</div>
    <div class="cl"></div>
  </div>
  <!--<div class="resourcePopupClose"> <a href="javascript:void(0);" class="resourceClose" onclick="closeModal();"></a></div>-->
  <div class="fl">
    <!--<input type="text" name="search" placeholder="输入课程ID或者名称搜索" class="subjectSearch fr" />-->
    <input type="text" id="search_course_input" value="<%= @search %>"  name="search" placeholder="输入课程ID或者名称搜索" class="mt10 mb10 course-search" />
  </div>
  <div id="send_homework_to_course_form">
    <%= render :partial => "users/send_homework_to_course_form", :locals => {:user => user, :courses => courses, :send_id => send_id} %>
  </div>
</div>
<script type="text/javascript">
    function send_submit() {
        var checkboxs = $("input[name='course_ids[]']:checked");
        if(checkboxs.length == 0) {
            $("#choose_courses_notice").text("请先选择课程");
        } else{
            $("#choose_courses_notice").text("");
            $("#choose_course_list_form").submit();
            hideModal();
        }
    }
    var lastSearchCondition = '';
    var count = 0;
    function search_courses(e){
        if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
        {
            return;
        }
        lastSearchCondition = $(e.target).val().trim();
        $.ajax({
            url: '<%= url_for(:controller => 'users', :action => 'choose_user_course') %>'+'?search='+ e.target.value+'&send_id=<%=send_id %>',
            type:'get',
            data: {is_observe:true},
            success: function(data){  },
            beforeSend: function(){ $(this).addClass('ajax-loading'); },
            complete: function(){ $(this).removeClass('ajax-loading'); }
        });
    }

    function throttle(method,context,e){
        clearTimeout(method.tId);
        method.tId=setTimeout(function(){
            method.call(context,e);
        },500);
    }

    //查询项目
    $("input[name='search']").on('input', function (e) {
        throttle(search_courses,window,e);
    });

</script>