<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/taglib/c.tld" prefix="c"%>
<div class="input-top fl">
	<label class="label-text">
		<span class="help-inline">班级：</span> 
		<input type="text" class="input-small" id="class_names" name="class_names" placeholder="请选择"/>
		<input type="hidden" class="report-parameter" id="class_ids" name="class_ids"/>
	</label>
	
	<!-- <div id="class-select-div" class="popover fade bottom in popover-content2-span3" style="display:none;">
       <div class="arrow"></div>
       <h3 class="popover-title">班级代码</h3>
       <div class="popover-content2">
           <p class="popover-list">
           <a  href="#">123456</a><a class="curr" href="#">123456</a><a  href="#">123456</a><a  href="#">123456</a>
           </p>
           <ul id="class-checkbox">
		   </ul>
           <p class="popover-button">
           	<a class="btn btn-primary" type="submit" id="class-select-all">全选</a>
			<a class="btn" type="submit" id="class-unselect-all">清空</a>
			<a class="btn" type="submit" id="class-save">保存</a>
           </p>
       </div>             
    </div> -->
	
	
</div>
<script type="text/javascript">
$(function(){
	$('#exam_id').change(updateClasses);
	$('#class_names').click(function(){
		$('#class-select-div').show();
	});
	$('#class-select-all').click(function(){
		$('#class-checkbox a').each(function(index, obj){
			//$(this).attr("checked","checked");
			if(!$(this).hasClass("curr")){
				$(this).addClass("curr");
			}
		});
	});
	$('#class-unselect-all').click(function(){
		$('#class-checkbox a').each(function(index, obj){
			//$(this).removeAttr("checked");
			if($(this).hasClass("curr")){
				$(this).removeClass("curr");
			}
		});
	});
	$('#class-close').click(function(){
		$('#class-select-div').hide();
	});
	$('#class-save').click(function(){
		var value = new Array();
		var name = new Array();
		$('#class-checkbox a').each(function(index, obj){
			if($(obj).hasClass('curr')){
				var a_value=$(obj).attr('value');
				value.push("'"+a_value+"'");
				name.push(a_value);
			}
		})
		$('#class_ids').val(value.join(','));
		if(name.length>1){
			$('#class_names').val(name[0]+"...");
		}else{
			$('#class_names').val(name.join(','));
		}
		$('#class-select-div').hide();
	});
	
	updateClasses();
})

function updateClasses(){
	var exam_id = $('#exam_id option:selected').val();
	if(exam_id!=undefined && exam_id.length > 0){
		$.post('${ctx}/analysis/condition/classes.json',{"examId":exam_id,"schoolId":${school_id}},function(res){
			$('#class_ids').val('');
			$('#class_names').val('');
			$('#class-checkbox').html('');
			$.each(res,function(index,obj){
				//var row = $('<li class="checkbox"><input class="checkbox" type="checkbox" value="'+obj.name+'">'+obj.name+'</li>');
				var row = $('<a href="#" value="'+obj.name+'" onclick="addCss(this)">'+obj.name+'</a>');
				$('#class-checkbox').append(row);
			});
		});
	}
}

function addCss(obj){
	if($(obj).hasClass("curr")){
		$(obj).removeClass("curr");
	}else{
		$(obj).addClass("curr"); 
	}
}
</script>