<%@ 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="subject_names" name="subject_names" placeholder="请选择"/>
		<input type="hidden" class="report-parameter" id="subject_ids" name="subject_ids"/>
	</label>
</div>
<script type="text/javascript">
$(function(){
	$('#exam_id').change(updateSubjects);
	$('#subject_names').click(function(){
		$('#subject-select-div').show();
	});
	$('#subject-select-all').click(function(){
		$('#subject-checkbox a').each(function(index, obj){
			//$(this).attr("checked","checked");
			if(!$(this).hasClass("curr")){
				$(this).addClass("curr");
			}
		});
	});
	$('#subject-clear-all').click(function(){
		$('#subject-checkbox a').each(function(index, obj){
			//$(this).removeAttr("checked");
			if($(this).hasClass("curr")){
				$(this).removeClass("curr");
			}
		});
	});
	$('#subject-save').click(function(){
		var value = new Array();
		var name = new Array();
		$('#subject-checkbox a').each(function(index, obj){
			if($(obj).hasClass('curr')){
				var a_value=$(obj).attr('value');
				var a_name=$(obj).attr('name');
				value.push(a_value);
				name.push(a_name);
			}
		})
		$('#subject_ids').val(value.join(','));
		if(name.length>1){
			$('#subject_names').val(name[0]+"...");
		}else{
			$('#subject_names').val(name.join(','));
		}
		$('#subject-select-div').hide();
	});
	
	updateSubjects();
})

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

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