$(document).ready(function () {
	
	$(".specTable").each(function(i , obj){
		specCheck("#spec_" + i);
	});
	
	function specCheck(spec_num) {
	    var max_num = 3;
	    var select_obj = $(document).find(spec_num + ' ul.selectList');
	    var input_obj = select_obj.find('input');
	    var checkbox_obj = select_obj.find('input:checkbox');
	    var notcheck_obj = select_obj.find('input:not(:checked)');
	    notcheck_obj.each(function () {
	        var class_str = $(this).attr('value');
	        var target_obj = $(spec_num + ' .specTable').find("." + class_str);
	        $(this).attr('disabled', 'disabled');
	        target_obj.hide();
	    });
	    checkbox_obj.click(function () {
	        var checked_obj = select_obj.find('input:checked');
	        var not_obj = select_obj.find('input:not(:checked)');
	        var checked_num = checked_obj.length;
	        checked_obj.each(function () {
	            var show_obj = $(spec_num + ' .specTable').find("." + $(this).attr('value'));
	            show_obj.show();
	        });
	        not_obj.each(function () {
	            var hide_obj = $(spec_num + ' .specTable').find("." + $(this).attr('value'));
	            hide_obj.hide();
	        });
	        if (checked_num >= max_num) {
	            not_obj.attr('disabled', 'disabled');
	        } else {
	            not_obj.removeAttr('disabled');
	        }
	    });
	};

});
