<div id="popbox02" style="">
  <span class="f16 fontBlue">关联项目</span>
  <a href="javascript:void(0);" class="popClose" onclick="clickCanel();"></a>
  <%=form_tag url_for(:controller=>'student_work',:action=>'student_work_project',:homework=>@homework.id,:user_activity_id=>@user_activity_id,:is_in_course=>@is_in_course,:course_activity =>@course_activity),:id =>'student_work_relate_project',:class=>'resourcesSearchBox',:remote => true do %>
      <input type="text" name="project" placeholder="输入项目名称进行搜索" class="searchResourcePopup mb10" />
      <div class="cl"></div>
      <p id="no_search_result" class="c_red" style="width:220px;display: none">您当前尚未创建任何项目，请先创建项目再关联。</p>
      <ul id="search_project_list" class="maxHeight100"></ul>
      <p id="notes" class="c_red"></p>
      <div class="courseSendSubmit mt10"><a href="javascript:void(0);" class="sendSourceText" onclick="clickOK();">确定</a></div>
      <div class="courseSendCancel mt10"><a href="javascript:void(0);" class="sendSourceText" onclick="clickCanel();">取消</a></div>
      <div class="cl"></div>
  <% end %>
</div>
<script type="text/javascript">
    var lastSearchCondition = '';
    var count = 0;
    function search_pros(e){
        if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
        {
            return;
        }
        lastSearchCondition = $(e.target).val().trim();
        $.ajax({
            url: '<%= url_for(:controller => 'student_work', :action => 'search_user_projects') %>'+'?name='+ e.target.value,
            type:'get'
        });
    }

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

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

    $(document).ready(function(){
        $.ajax({
            url: '<%= url_for(:controller => 'student_work', :action => 'search_user_projects') %>'+'?first=1',
            type:'get'
        });
    });

    function clickOK() {
        var radio = $("input[name='projectName']:checked");
        if(radio.length < 1) {
            $("#notes").html("请先选择一个项目");
            return false;
        } else {
            $("#student_work_relate_project").submit();
        }
    }
</script>