<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/taglib/c.tld" prefix="c"%>
<label class="select-w">
	<span class="help-inline">学校：</span>
	<input type="text" class="span3" id="school_names" name="school_names" placeholder="请选择"/>
	<div class="school-select" style="display:none;" id="school-select-div">
		<ul id="school-checkbox">
		</ul>
		<div class="school-btn">
			<a class="btn btnmg" type="submit" id="school-select-all">全选</a>
			<a class="btn btnmg" type="submit" id="school-unselect-all">清空</a>
			<a class="btn btn-primary btnmg" type="submit" id="school-save">保存</a>
		</div>
	</div>
	<input type="hidden" class="report-parameter" id="school_ids" name="school_ids"/>
</label>

<script type="text/javascript">
//$('#school-select-div').css({position:absolute,zIndex:9999});
$('#exam_id').change(updateSchools);
	$('#school_names').click(function(){
		$('#school-select-div').show();
	});
	$('#school-select-all').click(function(){
		$('#school-checkbox input').each(function(index, obj){
			$(this).attr("checked","checked");
		});
	});
	$('#school-unselect-all').click(function(){
		$('#school-checkbox input').each(function(index, obj){
			$(this).removeAttr("checked");
		});
	});
	$('#school-save').click(function(event){
		event.preventDefault();
		var value = new Array();
		var name = new Array();
		$('#school-checkbox input:checked').each(function(index, obj){
			value.push(obj.value);
			name.push(obj.name);
		});
		$('#school_ids').val(value.join(','));
		if(name.length>1){
			$('#school_names').val(name[0]+"...");
		}else{
			$('#school_names').val(name.join(','));
		}
		$('#school-select-div').hide();
		//updateSchools();
	});

function updateSchools(){
	var exam_id = $('#exam_id option:selected').val();
	if(exam_id!=undefined && exam_id.length > 0){
		$.post('${ctx}/analysis/condition/schools.json',{"examId":exam_id},function(res){
			$('#school_ids').val('');
			$('#school_names').val('');
			$('#school-checkbox').empty();
			$.each(res,function(index,obj){
				var row = $('<li class="checkbox"><input class="checkbox" type="checkbox" name="'+obj.name+'" value="'+obj.id+'">'+obj.name+'</li>');
				$('#school-checkbox').append(row);
			});
		});
	}
}
</script>
