<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />
<style>
.boderTbl {border-collapse:collapse;border:none;}
.boderTbl th{text-align:center;vertical-align:middle;border:1px solid #000000;padding:0px;}
.boderTbl td{text-align:center;vertical-align:middle;border:1px solid #000000;padding:0px;}

.absPos{
	position:absolute;top:0px;left:0px;
}
.remarkTextarea{
	height: 100%;
	width: 100%;
	resize: none;
	border-width: 0px;
	background-color: #F3F3F3;
}
.input1{
	border-left-style: none;border-top-style: none;border-right-style: none;border-bottom-style: solid;border-bottom-width: 1px;
	text-align: center;
	font-size:12px;
	background-color: #F3F3F3;
	width: 25px;
}
.input2{
	border-style:none;
	text-align: center;
	font-size:12px;
	width: 30px;
	height: 30px;
	margin: 0px;
}
.writeBg{
	background-color: #FFFFFF;
}
.grayBg{
	background-color: #E0E9E3;
}
.normalChapter{
	font-weight: normal;
	font-size:12px;
	background-color: #FFFFFF;
	width: 95px;
}
.importantChapter{
	font-weight: bold;
	font-size:14px;
	background-color: #d6edfe;
	width: 95px;
}

.myMargin1{
	margin-right: 10px;
}
.myMargin3{
	margin-right: 30px;
}
.myMargin4{
	margin-left: 3px;
}
.myTd1{
	width: 35px;
	text-align: left;
}

.myTd2{
	text-align: left;
}

.logDiv{
	margin-bottom: 10px;
	border-style: solid;
	border-width: 1px;
	border-color: #000000;
}
</style>
<%@ include file="../common/top2.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/validator.js"></script>
<%@ include file="../common/validation.jsp"%>
<title><c:if test="${skel != null}">细目表详情</c:if><c:if test="${skel == null}">新建细目表</c:if></title>
</head>
<body style="margin:0;">
<input type="hidden" id="totalScore" value="0"/>
<div id="skelInfoDiv" style="width:2000px;padding: 0;position: fixed; z-index: 1; height: 95px; background-color: #FFF;">
	<table class="searchTable" style="width: 830px;clear:both;margin-top: 3px;margin-left: 2px;">
		<tr>
			<th>课程：</th>
			<td style="padding:0px 5px;width:270px;">
				<input type="hidden" id="courseId" value="${course.id}"/>
				${course.showName}
			</td>
			<th>教材：</th>
			<td style="padding:0px 5px;width:270px;">
				<input type="hidden" id="bookId" value="${book.id}"/>
				${book.name}
			</td>
		</tr>
		<tr>
			<th style="width: 160px;">预计难度比例（%）：</th>
			<td>
				<c:if test="${course.skelCfg == null}"><span style="color: red;">未配置，请与业务管理员联系</span></c:if>
				<c:if test="${course.skelCfg != null}">
				${fn:formatScore(course.skelCfg.estimateDifficulty1Percent)}:${fn:formatScore(course.skelCfg.estimateDifficulty2Percent)}:${fn:formatScore(course.skelCfg.estimateDifficulty3Percent)}:${fn:formatScore(course.skelCfg.estimateDifficulty4Percent)}
				允许浮动值：${fn:formatScore(course.skelCfg.estimateDifficultyOffset)}
				</c:if>
			</td>
			<th style="width: 160px;">认知层次比例（%）：</th>
			<td style="padding:0px 5px;">
				<c:if test="${course.skelCfg == null}"><span style="color: red;">未配置，请与业务管理员联系</span></c:if>
				<c:if test="${course.skelCfg != null}">
				${fn:formatScore(course.skelCfg.ability1Percent)}:${fn:formatScore(course.skelCfg.ability2Percent)}:${fn:formatScore(course.skelCfg.ability3Percent)}:${fn:formatScore(course.skelCfg.ability4Percent)}
				允许浮动值：${fn:formatScore(course.skelCfg.abilityOffset)}
				</c:if>
			</td>
		</tr>
		<tr>
			<th>细目表名称：<input type="hidden" id="name" value="<c:out value='${name}'/>"/></th>
			<td style="padding:0px 5px;">${name}</td>
			<td colspan="2" align="center">
<div id="btnDiv" style="visibility: hidden;">
<c:if test="${canSkelEdit}">
				<button class="btn myMargin3" id="saveSkeleton">保存</button>
</c:if>
<c:if test="${skel != null}">
				<button class="btn myMargin3" id="goExport">导出</button>
</c:if>
<c:if test="${sessionScope.web_session_user.id == task.curDealer && (task.status=='TO_CREATE_SKEL') && task.paperSkeleton != null}">
				<button class="btn myMargin3" id="submitSkelToAudit">提交审核</button>
</c:if>
<c:if test="${sessionScope.web_session_user.id == task.curDealer && task.status=='TO_AUDIT_SKEL'}">
				<button class="btn myMargin3" id="openAuditWin">审核细目表</button>
</c:if>
				<button class="btn" id="goBack">关闭</button>
</div>
			</td>
		</tr>
	</table>
</div>
<!-- 细目表Table区域Begin -->
<c:if test="${book.chapterSize > 0}">
<div id='skelHeadDiv' style="visibility: hidden;position: fixed;z-index: 1;background-color: #FFF;left: 2px;width:10000px;">
	<table class="boderTbl" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<th id="headTd" style="width:126px;height:100px;" colspan="2" rowspan="2"></th>
			<c:forEach items="${questionTypes}" var="type">
			<th colspan="4" tdType='quesType' style="height: 66px;">
			<div>${type.name}</div>
			<div>每题：<input textType="quesTypeText" quesTypeId='${type.id}' type="text" class="input1" value="${fn:formatScore(type.defaultScore)}" maxlength="2"/> 分</div>
			<div>题量:<input textType="quesQuantityText" type="text" class="input1" maxlength="2"/></div>
			</th>
			</c:forEach>
			<th rowspan="2" style="width:56px;">小计</th>
			<th rowspan="2" style="width:50px;">
				<div>合计</div>
				<div id="wishScore"></div>
			</th>
		</tr>
		<tr>
		<c:forEach items="${questionTypes}" var="type">
			<c:forEach var="x" begin="1" end="4">
				<td headVerticalColor='true' tdType='upperLetter' style="width:30px;height:34px;">${fn:toUpperLetter(x)}</td>
			</c:forEach>
		</c:forEach>
		</tr>
	</table>
</div>
<div id='skelBodyDiv' style="visibility: hidden;position: absolute;margin-bottom: 5px;left: 2px;width:10000px;z-index: 0;">
	<table class="boderTbl" cellpadding="0" cellspacing="0" border="0">
		<c:forEach var="x" begin="1" end="${book.chapterSize}" step="1">
		<c:forEach var="y" begin="1" end="4">
		<tr>
			<c:if test="${y==1}">
			<td rowspan="4" <c:if test="${canSkelEdit}">title="双击设置/取消重点章节"</c:if> class="normalChapter" style="cursor: pointer;width: 95px" tdType='chapterNo' onselectstart="return false"><span>第${x}章节</span><span style="visibility: hidden;">*</span></td>
			</c:if>
			<td needColor='true' style="width:30px;">${fn:toUpperRoman(y)}</td>
			<c:forEach items="${questionTypes}" var="type" varStatus="u">
			<c:forEach var="z" begin="1" end="4">
				<c:set var="detailKey" value="${x}|${y}|${u.index + 1}|${z}"/>
				<td needColor='true' style="width:30px;border-color: #A7A7A7;
				<c:if test="${z == 1}">border-left-color:#000000;</c:if>
				<c:if test="${z == 4}">border-right-color:#000000;</c:if>
				<c:if test="${y == 1}">border-top-color:#000000;</c:if>
				<c:if test="${y == 4}">border-bottom-color:#000000;</c:if>"><input textType="quesNum" type="text" class="input2 writeBg" value="${skel.skeletonDetailMap[detailKey]}" maxlength="2"/></td>
			</c:forEach>
			</c:forEach>
			<td needColor='true' style="width:56px;" tdType='subtotal' sumType='chapterToQuesTypeSubtotal'></td>
			<c:if test="${y==1}">
			<td tdType='amount' style="width:50px;" rowspan="4" sumType='chapterToQuesTypeAmount'></td>
			</c:if>
		</tr>
		</c:forEach>
		</c:forEach>
		<tr>
			<td colspan="2" style="height:30px;">小计</td>
			<c:forEach items="${questionTypes}" var="type">
			<c:forEach var="x" begin="1" end="4">
				<td bodyVerticalColor='true' tdType='subtotal' sumType='quesTypeToChapterSubtotal'></td>
			</c:forEach>
			</c:forEach>
			<td tdType='amount' sumType='totalSum' colspan="2" rowspan="2"></td>
		</tr>
		<tr>
			<td colspan="2" style="height:30px;">合计</td>
			<c:forEach items="${questionTypes}" var="type">
				<td tdType='amount' colspan="4" sumType='quesTypeToChapterAmount'></td>
			</c:forEach>
		</tr>
		<tr>
			<td colspan="2">试卷结构</td>
			<td colspan="${fn:length(questionTypes) * 4 + 2}">
				<table class="boderTbl" cellpadding="0" cellspacing="0" border="0" width="100%">
					<tr>
						<c:forEach var="x" begin="1" end="4" varStatus="i">
						<td height="24" style="background-color:#d9fdc8; border-top-width: 0px;<c:if test="${i.first}">border-left-width: 0px;</c:if>">${fn:toUpperLetter(x)}</td>
						</c:forEach>
						<c:forEach var="x" begin="1" end="4" varStatus="i">
						<td height="24" style="background-color:#e6e1c1; border-top-width: 0px;<c:if test="${i.last}">border-right-width: 0px;</c:if>">${fn:toUpperRoman(x)}</td>
						</c:forEach>
					</tr>
					<tr>
						<c:forEach var="x" begin="1" end="4" varStatus="i">
						<td tdType='amount' sumType='amountDiffi' height="30" width="12.5%" style="border-bottom-width: 0px;<c:if test="${i.first}">border-left-width: 0px;</c:if>"></td>
						</c:forEach>
						<c:forEach var="x" begin="1" end="4" varStatus="i">
						<td tdType='amount' sumType='amountAbility' height="30" width="12.5%" style="border-bottom-width: 0px;<c:if test="${i.last}">border-right-width: 0px;</c:if>"></td>
						</c:forEach>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="2">备注</td>
			<td colspan="${fn:length(questionTypes) * 4 + 2}" style="height:80px;padding: 5px;">
				<c:if test="${!canSkelEdit}"><textarea class="remarkTextarea" readonly="readonly"><c:out value="${skel.remark}"/></textarea></c:if>
				<c:if test="${canSkelEdit}"><textarea class="remarkTextarea" id="remark" placeholder="请输入备注信息"><c:out value="${skel.remark}"/></textarea></c:if>
			</td>
		</tr>
		<tr>
			<td colspan="${fn:length(questionTypes) * 4 + 4}" style="text-align: left;">
			<div style="margin:5px 0 5px 10px">
			说明：
			<div>1.预计难度：A.易；  B.中等偏易；  C.中等偏难；  D.难</div>
			<div>2.认知层次：I.识记；  II.理解；  III.简单应用；  IV.综合应用</div>
			</div>
			</td>
		</tr>
	</table>
</div>
</c:if>
<!-- 细目表Table区域End -->
    
<!-- 隐藏功能区Begin -->
<div style="display: none;">
    <div id="menu" class="easyui-menu">
	    <div id="m-leftQuesType" data-options="disabled:true">←左移</div>
	    <div id="m-rightQuesType" data-options="disabled:true">→右移</div>
	    <div id="m-copyQuesType">复制新题型</div>
	    <div id="m-delQuesType" data-options="disabled:true">删除题型</div>
	</div>
	
	<div id="normalSubmitDiv" title="选择下一个处理人" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,maximizable:false,resizable:false,iconCls:'icon-import'" style="width:490px;height:260px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;margin-top: 10px;">
        	<form action="#" id="formForNormalSubmit">
        		<input type="hidden" name="taskId" value="${task.id}"/>
				<table cellpadding="5">
					<tr>
						<td nowrap="nowrap" valign="top">下一个处理人</td>
						<td>
							<select name="nextDealer"><c:forEach items="${task.nextDealers}" var="dealer"><option value="${dealer.id}" <c:if test="${dealer.id==task.defaultNextDealer}">selected="selected"</c:if>>${dealer.name}</option></c:forEach></select>
						</td>
					</tr>
					<tr>
						<td nowrap="nowrap" valign="top">备注</td>
						<td>
							<textarea rows="5" cols="50" name="remark" id="remarkForNormalSubmit"></textarea>
							<div id="countForNormalSubmit"></div>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<button class="btn myMargin3" id="saveNormalSubmitBtn">确定</button>
							<button class="btn" id="cancelNormalSubmitBtn">取消</button>
						</td>
					</tr>
				</table>
            </form>
        </div>
    </div>
	
    <div id="auditDiv" title="提交审核结果" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,maximizable:false,resizable:false,iconCls:'icon-import'" style="width:490px;height:280px;padding:5px;overflow-x: hidden;">
        <div id="barcode-scan" style="font-size: 12px;margin-top: 10px;">
        	<form action="#" id="formForAudit">
        		<input type="hidden" name="taskId" value="${task.id}"/>
				<table cellpadding="5">
					<tr>
						<td nowrap="nowrap">审核结果</td>
						<td>
							<input type="radio" name="auditResult" id="approved" value="2" checked="checked"/><label for="approved" class="myMargin3">通过</label>
							<input type="radio" name="auditResult" id="rejected" value="4"/><label for="rejected">驳回</label>
						</td>
					</tr>
					<tr>
						<td nowrap="nowrap" valign="top">下一个处理人</td>
						<td>
							<span id="nextDealersSpan"><select name="nextDealer"><c:forEach items="${task.nextDealers}" var="dealer"><option value="${dealer.id}" <c:if test="${dealer.id==task.defaultNextDealer}">selected="selected"</c:if>>${dealer.name}</option></c:forEach></select></span>
							<span id="preDealersSpan" style="display: none;"><select name="nextDealer"><c:forEach items="${task.preDealers}" var="dealer"><option value="${dealer.id}">${dealer.name}</option></c:forEach></select></span>
						</td>
					</tr>
					<tr>
						<td nowrap="nowrap" valign="top">审核意见</td>
						<td>
							<textarea rows="5" cols="50" name="remark" id="remarkForAudit"></textarea>
							<div id="countForAudit"></div>
							<div>
								<select id="normalAuditText" style="display: none;" onchange="changeAuditRemark()">
									<option value="">--请选择常用审核意见--</option>
									<option value="难度分布不符合大纲要求">难度分布不符合大纲要求</option>
									<option value="认知层次分布不符合大纲要求">认知层次分布不符合大纲要求</option>
									<option value="总题数不合理">总题数不合理</option>
									<option value="没有标注重点章节">没有标注重点章节</option>
								</select>
							</div>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<button class="btn myMargin3" id="saveAuditBtn">确定</button>
							<button class="btn" id="cancelAuditBtn">取消</button>
						</td>
					</tr>
				</table>
            </form>
        </div>
    </div>
    
    <div>
	    <form id="downloadForm" action="#">
	    </form>
    </div>
</div>
<!-- 隐藏功能区End -->
</body>
</html>
<script language="javascript">
function getCurDateStr(){
	var nowDate = new Date();
	var monthStr = (nowDate.getMonth() + 1)+"";
	if(monthStr.length == 1){
		monthStr = '0' + monthStr;
	}
	var dayStr = (nowDate.getDate())+"";
	if(dayStr.length == 1){
		dayStr = '0' + dayStr;
	}
	var dateStr = nowDate.getFullYear() + monthStr + dayStr;
	return dateStr;
}

var perDiffiSize = 4;//预计难度的个数 
var perAbilitySize = 4;//认知层次的个数
var editable = ${canSkelEdit};
var keyschapter = [];

var abilityPercent = [];
var estimateDifficultyPercent = [];
<c:if test="${course.skelCfg != null}">
abilityPercent[0] = [${course.skelCfg.ability1Percent-course.skelCfg.abilityOffset},${course.skelCfg.ability1Percent+course.skelCfg.abilityOffset}];
abilityPercent[1] = [${course.skelCfg.ability2Percent-course.skelCfg.abilityOffset},${course.skelCfg.ability2Percent+course.skelCfg.abilityOffset}];
abilityPercent[2] = [${course.skelCfg.ability3Percent-course.skelCfg.abilityOffset},${course.skelCfg.ability3Percent+course.skelCfg.abilityOffset}];
abilityPercent[3] = [${course.skelCfg.ability4Percent-course.skelCfg.abilityOffset},${course.skelCfg.ability4Percent+course.skelCfg.abilityOffset}];
estimateDifficultyPercent[0] = [${course.skelCfg.estimateDifficulty1Percent-course.skelCfg.estimateDifficultyOffset},${course.skelCfg.estimateDifficulty1Percent+course.skelCfg.estimateDifficultyOffset}];
estimateDifficultyPercent[1] = [${course.skelCfg.estimateDifficulty2Percent-course.skelCfg.estimateDifficultyOffset},${course.skelCfg.estimateDifficulty2Percent+course.skelCfg.estimateDifficultyOffset}];
estimateDifficultyPercent[2] = [${course.skelCfg.estimateDifficulty3Percent-course.skelCfg.estimateDifficultyOffset},${course.skelCfg.estimateDifficulty3Percent+course.skelCfg.estimateDifficultyOffset}];
estimateDifficultyPercent[3] = [${course.skelCfg.estimateDifficulty4Percent-course.skelCfg.estimateDifficultyOffset},${course.skelCfg.estimateDifficulty4Percent+course.skelCfg.estimateDifficultyOffset}];
</c:if>

var chapterSize = <c:if test="${book.chapterSize == null}">0</c:if><c:if test="${book.chapterSize != null}">${book.chapterSize}</c:if>;

var CUR_TD;

var VERTICALCOLOR = "#e0cff2";
var HORIZONTALCOLOR = "#daf2f2";
var NORMALCOLOR = "#ffffff";

$(document).ready(function(){
	if(chapterSize <= 0){
		$.messager.alert('提示','该教材对应的章数设置不正确，请联系管理员修改后再试!', 'error');
	}
	<c:if test="${course.skelCfg == null}">
		$.messager.alert('提示','该课程未配置细目表参数，请联系管理员修改后再试!', 'error');
	</c:if>
	{//初始化审核意见输入框字符数控制
		$("#remarkForNormalSubmit").keydown(function(){
	    	calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
	    });
	    $("#remarkForNormalSubmit").keyup(function(){
	    	calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
	    });
	    $("#remarkForNormalSubmit").keypress(function(){
	    	calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
	    });
		$("#remarkForAudit").keydown(function(){
	    	calculate_byte(200,'remarkForAudit','countForAudit');
	    });
	    $("#remarkForAudit").keyup(function(){
	    	calculate_byte(200,'remarkForAudit','countForAudit');
	    });
	    $("#remarkForAudit").keypress(function(){
	    	calculate_byte(200,'remarkForAudit','countForAudit');
	    });
	}

    $('#goBack').click(function(){
    	if(window.parent){
    		var appElement = window.parent.$('[ng-controller=paperTaskDetailCtrl]');
    		var $scope = window.parent.angular.element(appElement).scope();
    		$scope.closeSkelModal();
    	}else{
    		window.close();
    	}
    });
	
	$("#submitSkelToAudit").click(function(){
		<c:if test="${task.paperSkeleton == null}">
		$.messager.alert('提示', "未创建细目表，不能提交，请先创建细目表!", 'error');
		</c:if>
		<c:if test="${task.paperSkeleton != null}">

    	$.messager.confirm("操作提示", "提交审核之前请确定是否已经保存细目表，点击“OK”继续。", function (data) {
	        if (data) {
				calculate_byte(200,'remarkForNormalSubmit','countForNormalSubmit');
				$("#normalSubmitDiv").window({top:$(document).scrollTop() + 100});
				$('#normalSubmitDiv').window('open');
	        }
    	});
		</c:if>
	});
	
	$("#saveNormalSubmitBtn").click(function(){
		$.messager.confirm("操作提示", "您确定要提交审核吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在处理，请稍等...');
	        	var param = $('#formForNormalSubmit').serialize();
	        	$.post('${ctx}/taskCenter/normalSubmit',param,function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				try{
	    					reloadParentWin();
	    				}catch(e){
	    					//do nothing
	    				}
	    				reloadWin();
	    			}
	    		});
	        }
	    });
		return false;
	});
	
	$("#cancelNormalSubmitBtn").click(function(){
    	$('#normalSubmitDiv').window('close');
		return false;
    });
    
    $("#openAuditWin").click(function(){
    	$.messager.confirm("操作提示", "提交审核之前请确定是否已经保存细目表，点击“OK”继续。", function (data) {
	        if (data) {
				calculate_byte(200,'remarkForAudit','countForAudit');
				$("#auditDiv").window({top:$(document).scrollTop() + 100});
				$('#auditDiv').window('open');
	        }
    	});
	});
    
    $("input[name='auditResult']").click(function(){
    	if($("#approved").attr("checked")){
			$("#nextDealersSpan").show();
			$("#nextDealersSpan").find("select").attr("disabled",false);
			$("#preDealersSpan").hide();
			$("#preDealersSpan").find("select").attr("disabled",true);
			$("#normalAuditText").hide();
		}else{
			$("#nextDealersSpan").hide();
			$("#nextDealersSpan").find("select").attr("disabled",true);
			$("#preDealersSpan").show();
			$("#preDealersSpan").find("select").attr("disabled",false);
			$("#normalAuditText").show();
		}
    });
	
	$("#saveAuditBtn").click(function(){
		$.messager.confirm("操作提示", "您确定要提交审核结果吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在提交，请稍等...');
	        	var param = $('#formForAudit').serialize();
	        	$.post('${ctx}/taskCenter/saveAuditResult',param,function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				try{
	    					reloadParentWin();
	    				}catch(e){
	    					//do nothing
	    				}
	    				reloadWin();
	    			}
	    		});
	        }
	    });
		return false;
	});
	
	$("#cancelAuditBtn").click(function(){
    	$('#auditDiv').window('close');
		return false;
    });
    
    /**
    $('#goPrint').click(function(){
    	window.open('${ctx}/paperSkeleton/printView?id=${skel.id}');
    });
    **/
    
    $('#goExport').click(function(){
    	$(document).mask('正在生成细目表Excel文件，请稍等...');
    	$.ajax({
    		type : "POST",
    		url : '${ctx}/paperSkeleton/export/${skel.id}',
    		data : {}, 
    		success : function(res) {
    			$(document).unmask();
    			if(res.flag=='success'){
    				$("#downloadForm").attr("action","${ctx}/attachment/download/" + res.att.id);
    				$("#downloadForm").submit();
    			}else{
    				$.messager.alert('提示', "生成细目表Excel文件失败，请刷新后操作!", 'error');
    			}
    		}
    	});
    	return false;
    });
	 
    $('#saveSkeleton').click(function(){
    	var courseId = $('#courseId').val();
    	var bookId = $('#bookId').val();
    	var name = $.trim($('#name').val());
    	var remark = $('#remark').val();
    	$('#name').val(name);
    	var hasErr = false;
    	var quesTypeArr = [];
    	$("[textType='quesTypeText']").each(function(index){
			var text = $(this);
    		var score = text.val();
    		if(score == ''){
    			$.messager.alert('提示','请输入题型分值!', 'error',function(){
    				text.focus();
        		});
    			hasErr = true;
        		return false;
    		}
    		quesTypeArr[index] = {
    							'quesTypeId' : text.attr('quesTypeId'),
    							'score' : score - 0
    							};
    	});
    	if(hasErr){
    		return false;
    	}
    	var quesTypeScores = "";
    	for(var i=0;i<quesTypeArr.length;i++){
    		var scoreStr = quesTypeArr[i].quesTypeId + ":" + quesTypeArr[i].score;
    		quesTypeScores = quesTypeScores + scoreStr;
    		if(i < quesTypeArr.length-1){
    			quesTypeScores = quesTypeScores + ",";
    		}
    	}

    	var importantChapterArr = [];
    	$("[tdType='chapterNo']").each(function(index){
    		if($(this).hasClass("importantChapter")){
    			importantChapterArr[importantChapterArr.length] = index + 1;
    		}
    	});
    	if(importantChapterArr.length == 0){
    		$.messager.alert('提示','请设置重点章节（双击章节单元格即可）!', 'error',function(){
    			//do nothing
    		});
    		return false;
    	}
		var quesTypeSize = quesTypeArr.length;//题型的数量
		var trPerTdSize = quesTypeSize * perDiffiSize;//每行的单元格数量
    	var skeletonDetailArr = [];
    	$("[textType='quesNum']").each(function(index){
    		var text = $(this);
    		var quesNum = text.val();
    		if(quesNum != ''){
    			quesNum = quesNum - 0;
    			skeletonDetailArr[skeletonDetailArr.length] = {
    				'quesTypeNo' : parseInt(index % trPerTdSize / perDiffiSize) + 1,
    				'chapterNo' : parseInt(parseInt(index / trPerTdSize) / perAbilitySize) + 1,
    				'quesNum' : quesNum,
    				'estimateDifficulty' : index % trPerTdSize % perDiffiSize + 1,
    				'ability' : parseInt(index / trPerTdSize) % perAbilitySize + 1
    			};
    		}
    	});
    	if(skeletonDetailArr.length == 0){
    		$.messager.alert('提示','题量不能为0，请输入题量!', 'error',function(){
    			//do nothing
    		});
    		return false;
    	}
    	if($("#totalScore").val() - 0 > 100){
    		$.messager.alert('提示','总分值超过了100分，请重新输入题量!', 'error');
    		return false;
    	}
    	if($("#totalScore").val() - 0 < 100){
    		$.messager.alert('提示','总分值未满100分，请继续输入题量!', 'error');
    		return false;
    	}
    	
    	var amountDiffiOk = true;
    	$("[divType='amountDiffi']").each(function(index){
    		if(index % 2 == 0){
    			if($(this).html().toLowerCase().replace(/ /g, "").indexOf("color:black") < 0){
    				amountDiffiOk = false;
    			}
    		}
    		return amountDiffiOk;
    	});
    	if(!amountDiffiOk){
    		$.messager.alert('提示', "预计难度比例不符合要求，请按照规定的预计难度比例来修改题量分布!", 'error');
    		return false;
    	}
    	
    	var amountAbilityOk = true;
    	$("[divType='amountAbility']").each(function(index){
    		if(index % 2 == 0){
    			if($(this).html().toLowerCase().replace(/ /g, "").indexOf("color:black") < 0){
    				amountAbilityOk = false;
    			}
    		}
    		return amountAbilityOk;
    	});
    	if(!amountAbilityOk){
    		$.messager.alert('提示', "认知层次比例不符合要求，请按照规定的认知层次比例来修改题量分布!", 'error');
    		return false;
    	}
    	
    	<c:if test="${hasPaper}">
    	$.messager.confirm("操作提示", "已有按照该细目表组卷的试卷，保存之后系统自动过滤不符合的试题，同时会重置及格分数预估表。是否确定保存？", function (data) {
	        if (data) {
	    </c:if>
		    	$(document).mask('正在保存数据，请稍等...');
		    	$.ajax({
					type : 'POST',
					url : '${ctx}/paperSkeleton/save',
					data : JSON.stringify({
							'id' : '${skel.id}',
							'taskId' : '${taskId}',
							'courseId' : courseId,
							'bookId' : bookId,
							'name' : name,
							'chapterSize' : chapterSize,
							'remark' : remark,
							'quesTypeScores' : quesTypeScores,
							'keyChapters' : importantChapterArr.join(','),
							'skeletonDetailArr' : skeletonDetailArr
						}),
					dataType: "json",
		            contentType: "application/json",
					success : function(callback) {
						$(document).unmask();
						if(callback.flag == 'success'){
							<c:if test="${skel == null}">
								try{
									reloadParentWin();
								}catch(e){
									//do nothing
								}
							</c:if>
							$.messager.alert('提示', callback.msg, 'info', function () {
								<c:if test="${skel == null}">
								$(document).mask('正在加载，请稍等...');
								window.location.href = "${ctx}/paperSkeleton/viewskeletondetail/" + callback.paperSkeleton.id;
								</c:if>
		                    });
						}else{
							$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
						}
					}
				});
		<c:if test="${hasPaper}">
	        }
		});
    	</c:if>
    });
    
    {//初始化细目表的位置
    	<c:if test="${book.chapterSize > 0}">
    	/**
    	var div1 = document.getElementById('nothingDiv');
		var div2 = document.getElementById('noticeDiv');
		var tbl = document.getElementById('skelHeadDiv');
		
		tbl.style.top = (div1.offsetTop + div1.offsetHeight) + 'px';
		tbl.style.left = div1.offsetLeft + 'px';
		div2.style.marginTop = (tbl.offsetHeight + 10) + 'px';
		**/
		</c:if>
		if(1 == 1){
			var skelInfoDiv = $("#skelInfoDiv");
			var skelHeadDiv = $("#skelHeadDiv");
			var skelBodyDiv = $("#skelBodyDiv");
			
			//skelHeadDiv.width(skelHeadDiv.width());
			skelHeadDiv.css("top",skelInfoDiv.height());

			skelBodyDiv.width(skelBodyDiv.children("table").eq(0).width() + 10);
			skelBodyDiv.css("top",skelInfoDiv.height() + skelHeadDiv.height() - 1);
		}
    }
    {//设置斜分割线
    	lineHeadTd();
    	$("[tdType='subtotal']").each(function(){
    		lineSubtotalTd($(this).get(0));
    	});
    	$("[tdType='amount']").each(function(){
    		lineAmountTd($(this).get(0));
    	});
    	$('#skelHeadDiv').css('visibility','visible');
    	$('#skelBodyDiv').css('visibility','visible');
    }
    if(editable){//设置/取消重点章节
    	$("[tdType='chapterNo']").each(function(){
    		$(this).dblclick(function(){
        		var span1 = $(this).find("span").eq(1);
        		if($(this).hasClass("normalChapter")){
        			$(this).removeClass("normalChapter");
        			$(this).addClass("importantChapter");
        			span1.css("visibility","visible");
        		}else{
        			$(this).removeClass("importantChapter");
        			$(this).addClass("normalChapter");
        			span1.css("visibility","hidden");
        		}
            });
    	});
    }
    {//输入题型分值，各统计值级联更新
    	$("[textType='quesTypeText']").each(function(){
    		//background-color: #F3F3F3;
    		var val = $(this).val() - 0;
			if(!val || val <= 0){
				$(this).css({'background-color': '#FFFF99'});
			}else{
				$(this).css({'background-color': '#F3F3F3'});
			}
			if(editable){
	    		$(this).keyup(function(e){
	    			var val = $(this).val() - 0;
	    			if(!val || val <= 0){
	    				val = '';
	    				$(this).css({'background-color': '#FFFF99'});
	    			}else{
	    				$(this).css({'background-color': '#F3F3F3'});
	    			}
	    			$(this).val(val);
	    			calcStat();
	    			calcWishScore();
	    		});
			}else{
    			$(this).attr("readonly","readonly");
			}
    	});
    }
    {//输入题量，各统计值级联更新
    	$("[textType='quesNum']").each(function(indexForQuesNum){
    		if(editable){
    			$(this).keydown(function(e){
    				var keyCode = e.keyCode;
	    			if(keyCode == 37){//按向左键
	        			var prevTd = $(this).parents("td").eq(0).prev();
	    				if(prevTd.length == 1 && prevTd.find("[textType='quesNum']").length == 1){
	    					var text = prevTd.find("[textType='quesNum']").eq(0);
	    					text.focus();
	        				text.select();
	    					return false;
	    				}else{
	    					return true;
	    				}
	    			}else if(keyCode == 38){//按向上键
	    				var curTr = $(this).parents("tr").eq(0);
	    				var prevTr = curTr.prev();
	        			var curHasChapterNo = curTr.children().eq(0).attr("tdType") == "chapterNo";
	        			var prevHasChapterNo = prevTr.children().eq(0).attr("tdType") == "chapterNo";
	        			var curTd = $(this).parents("td").eq(0);
	        			var curTdIndex = curTd.index();
	        			if(curHasChapterNo){
	        				curTdIndex = curTdIndex - 1;
	        			}
	        			var prevTdIndex = prevHasChapterNo?(curTdIndex + 1):curTdIndex;
	        			var prevTd = prevTr.children().eq(prevTdIndex);
	        			if(prevTd.length == 1 && prevTd.find("[textType='quesNum']").length == 1){
	    					var text = prevTd.find("[textType='quesNum']").eq(0);
	    					text.focus();
	        				text.select();
	    					return false;
	    				}else{
	    					return true;
	    				}
	    			}else if(keyCode == 39){//按向右键
	    				var nextTd = $(this).parents("td").eq(0).next();
	    				if(nextTd.length == 1 && nextTd.find("[textType='quesNum']").length == 1){
	    					var text = nextTd.find("[textType='quesNum']").eq(0);
	    					text.focus();
	        				text.select();
	    					return false;
	    				}else{
	    					return true;
	    				}
	    			}else if(keyCode == 40){//按向下键
	    				var curTr = $(this).parents("tr").eq(0);
	    				var nextTr = curTr.next();
	        			var curHasChapterNo = curTr.children().eq(0).attr("tdType") == "chapterNo";
	        			var nextHasChapterNo = nextTr.children().eq(0).attr("tdType") == "chapterNo";
	        			var curTd = $(this).parents("td").eq(0);
	        			var curTdIndex = curTd.index();
	        			if(curHasChapterNo){
	        				curTdIndex = curTdIndex - 1;
	        			}
	        			var nextTdIndex = nextHasChapterNo?(curTdIndex + 1):curTdIndex;
	        			var nextTd = nextTr.children().eq(nextTdIndex);
	        			if(nextTd.length == 1 && nextTd.find("[textType='quesNum']").length == 1){
	        				var text = nextTd.find("[textType='quesNum']").eq(0);
	        				text.focus();
	        				text.select();
	    					return false;
	    				}else{
	    					return true;
	    				}
	    			}
    			});
	    		$(this).keyup(function(e){
	    			var keyCode = e.keyCode;
	    			if(keyCode != 13){
		    			if(keyCode == 37 || keyCode == 38 || keyCode == 39 || keyCode == 40
		    					|| keyCode == 8 || keyCode == 9 || keyCode == 16 || keyCode == 17 || keyCode == 18
		    					 || keyCode == 91|| keyCode == 46){
			    			calcStat();
		    				return false;
		    			}
		    			var val = $(this).val() - 0;
		    			if(!val || val <= 0){
		    				val = '';
		    			}
		    			$(this).val(val);
		    			calcStat();
		    			var quesTypeArr = $("[textType='quesTypeText']");
		    			var quesTypeSize = quesTypeArr.size();//题型的数量
		    			var trPerTdSize = quesTypeSize * perDiffiSize;//每行的单元格数量
		    			var indexForType = parseInt(indexForQuesNum % trPerTdSize / perDiffiSize);
		    			var qqt = $("[textType='quesQuantityText']").eq(indexForType).val() - 0;
		    			var qtcaObj = $("[divType='quesTypeToChapterAmount']").eq(2*indexForType + 1);
		    			var qtca = qtcaObj.text() - 0;
	    				if(qtca < qqt){
	    					qtcaObj.html("<span style='font-weight:bold;color:#ff9900'>" + qtca + "</span>");
	    				}else if(qtca > qqt){
	    					qtcaObj.html("<span style='font-weight:bold;color:red'>" + qtca + "</span>");
		    				$.messager.alert('提示', '实际输入的题量大于了预设的题量，请重新输入', 'error', function () {
		    					$("[textType='quesNum']").eq(indexForQuesNum).select();
			    	        });
	    				}else{
	    					qtcaObj.html("<span style='font-weight:normal;color:black'>" + qtca + "</span>");
	    				}
	    			}
	    		});
    		}else{
    			$(this).attr("readonly","readonly");
    		}
    		
    		$(this).mouseover(function(){
    			var curTr = $(this).parents("tr").eq(0);
    			var hasChapterNo = curTr.children().eq(0).attr("tdType") == "chapterNo";
    			var curTd = $(this).parents("td").eq(0);
    			var curTdIndex = curTd.index();
    			if(hasChapterNo){
    				curTdIndex = curTdIndex - 1;
    			}
    			$("[headVerticalColor='true']").eq(curTdIndex - 1).css('background',VERTICALCOLOR);
    			$("[bodyVerticalColor='true']").eq(curTdIndex - 1).css('background',VERTICALCOLOR);
    			var allTrs = curTr.parent().children();
    			allTrs.each(function(index){
    				if(index < chapterSize * 4){
    					var hasChapterNoT = $(this).children().eq(0).attr("tdType") == "chapterNo";
    					$(this).children().eq(hasChapterNoT?(curTdIndex + 1):curTdIndex).find("[textType='quesNum']").css('background',VERTICALCOLOR);
    				}
    			});
    		});
    		
    		$(this).mouseout(function(){
    			var curTr = $(this).parents("tr").eq(0);
    			var hasChapterNo = curTr.children().eq(0).attr("tdType") == "chapterNo";
    			var curTd = $(this).parents("td").eq(0);
    			var curTdIndex = curTd.index();
    			if(hasChapterNo){
    				curTdIndex = curTdIndex - 1;
    			}
    			$("[headVerticalColor='true']").eq(curTdIndex - 1).css('background',NORMALCOLOR);
    			$("[bodyVerticalColor='true']").eq(curTdIndex - 1).css('background',NORMALCOLOR);
    			var allTrs = curTr.parent().children();
    			allTrs.each(function(index){
    				if(index < chapterSize * 4){
    					var hasChapterNoT = $(this).children().eq(0).attr("tdType") == "chapterNo";
    					$(this).children().eq(hasChapterNoT?(curTdIndex + 1):curTdIndex).find("[textType='quesNum']").css('background',NORMALCOLOR);
    				}
    			});
    		});
    		
    	});
    }
    {//背景色变化
    	$("[needColor='true']").each(function(){
    		$(this).mouseover(function(){
    			var curTr = $(this).parents("tr").eq(0);
    			curTr.find("[needColor='true']").css('background',HORIZONTALCOLOR);//当鼠标移上变#cc99ff
    			curTr.find("[textType='quesNum']").css('background',HORIZONTALCOLOR);//当鼠标移上变#cc99ff
    		});
    		
    		$(this).mouseout(function(){
    			var curTr = $(this).parents("tr").eq(0);
    			curTr.find("[needColor='true']").css('background',NORMALCOLOR);//当鼠标移上变#ffffff
    			curTr.find("[textType='quesNum']").css('background',NORMALCOLOR);//当鼠标移上变#ffffff
    		});
    	});
    
    	$("[headVerticalColor='true'],[bodyVerticalColor='true']").each(function(){
    		$(this).mouseover(function(){
    			var curTd = $(this);
    			var curTdIndex = 0;
    			if(curTd.attr("headVerticalColor") == "true"){
    				curTdIndex = $("[headVerticalColor='true']").index(curTd[0]);
    				$("[bodyVerticalColor='true']").eq(curTdIndex).css('background',VERTICALCOLOR);
    			}else{
    				curTdIndex = $("[bodyVerticalColor='true']").index(curTd[0]);
    				$("[headVerticalColor='true']").eq(curTdIndex).css('background',VERTICALCOLOR);
    			}
    			curTdIndex = curTdIndex + 1;

    			curTd.css('background',VERTICALCOLOR);
    			var allTrs = $("#skelBodyDiv").children("table").children().children();
    			allTrs.each(function(index){
    				if(index < chapterSize * 4){
    					var hasChapterNoT = $(this).children().eq(0).attr("tdType") == "chapterNo";
    					$(this).children().eq(hasChapterNoT?(curTdIndex + 1):curTdIndex).find("[textType='quesNum']").css('background',VERTICALCOLOR);
    				}
    			});
    		});
    		
    		$(this).mouseout(function(){
    			var curTd = $(this);
    			var curTdIndex = 0;
    			if(curTd.attr("headVerticalColor") == "true"){
    				curTdIndex = $("[headVerticalColor='true']").index(curTd[0]);
    				$("[bodyVerticalColor='true']").eq(curTdIndex).css('background',NORMALCOLOR);
    			}else{
    				curTdIndex = $("[bodyVerticalColor='true']").index(curTd[0]);
    				$("[headVerticalColor='true']").eq(curTdIndex).css('background',NORMALCOLOR);
    			}
    			curTdIndex = curTdIndex + 1;

    			curTd.css('background',NORMALCOLOR);
    			var allTrs = $("#skelBodyDiv").children("table").children().children();
    			allTrs.each(function(index){
    				if(index < chapterSize * 4){
    					var hasChapterNoT = $(this).children().eq(0).attr("tdType") == "chapterNo";
    					$(this).children().eq(hasChapterNoT?(curTdIndex + 1):curTdIndex).find("[textType='quesNum']").css('background',NORMALCOLOR);
    				}
    			});
    		});
    	});
    }
    $(window).scroll(function(){
    	var hLeft=$(document).scrollLeft();
    	if($('#skelHeadDiv').css('left') != (2 - hLeft)){
    		$('#skelHeadDiv').css('left',2 - hLeft);
    	}
    });
    {//题型右键菜单
    	$("[tdType='quesType']").each(function(){
        	$(this).contextmenu(function(e){
        		//var qtId = $(this).next().attr('qtId');
        		//if(qtId != null && qtId != ''){
    	    		//curQtPanel = $(this).parent();
    	    		CUR_TD = $(this);
    	    		//显示快捷菜单
    	    		var left = e.pageX;
    	    		var top = e.pageY;
    	    		$('#menu').height(88);
    	    		$('#menu').width(150);
    	            $('#menu').menu('show', {
    	                'left': left,
    	                'top': top
    	            });
    	            var index = CUR_TD.parent().children().index(CUR_TD);
    	            $('#menu').menu(((index == 1)?'disableItem':'enableItem'),$('#m-leftQuesType')[0]);
    	            $('#menu').menu(((index == CUR_TD.parent().children().size() - 3)?'disableItem':'enableItem'),$('#m-rightQuesType')[0]);
        		//}
                return false;
            });
        });
        
        $("#m-leftQuesType").click(function(){
        	if($('#menu').menu('getItem', $(this)[0]).disabled){
        		return false;
        	}
        	
        	var index = CUR_TD.parent().children().index(CUR_TD);
        	{//交换“题型”单元格
        		var prevTd = CUR_TD.prev();
        		CUR_TD.insertBefore(prevTd);
        	}
        	moveTds(index,true);
        });
        
        $("#m-rightQuesType").click(function(){
        	if($('#menu').menu('getItem', $(this)[0]).disabled){
        		return false;
        	}
        	
        	var index = CUR_TD.parent().children().index(CUR_TD);
        	{//交换“题型”单元格
        		var nextTd = CUR_TD.next();
            	CUR_TD.insertAfter(nextTd);
        	}
        	moveTds(index,false);
        });
        
        $("#m-copyQuesType").click(function(){
        	alert('TODO!');
        });
        
        $("#m-delQuesType").click(function(){
        	alert('TODO!');
        });
    }
	//提交审核
	$('#submitAudit').click(function(){
		$.messager.confirm("操作提示", "您确定要提交审核吗？", function (data) {
	        if (data) {
	        	$(document).mask('正在提交审核，请稍等...');
	        	var param = {"skeletonId":'${skel.id}'};
	        	$.post('${ctx}/paperSkeleton/submitAudit',param,function(res){
	    			$(document).unmask();
	    			if(res.flag=='failed'){
	    	           $.messager.alert('提示', res.msg, 'error', function () {
	    	        	   //do nothing
	    	           });
	    	           return false;
	    			}else{
	    				reloadWin();
	    			}
	    		});
	        }
	    });
	});
	
    calcStat();
    var keyChapters = '${skel.keyChapters}';
    if(keyChapters != ''){
	    var keyChapterArr = keyChapters.split(',');
	    for(var i=0;i<keyChapterArr.length;i++){
	    	var tdTmp = $("[tdType='chapterNo']").eq(keyChapterArr[i]-1);
	    	tdTmp.removeClass("normalChapter");
	    	tdTmp.addClass("importantChapter");
	    	tdTmp.find("span").eq(1).css("visibility","visible");
	    }
    }
    {
    	$("[textType='quesQuantityText']").each(function(index){
    		
    	});
    }
    {//输入每个题型的总题量，控制下面的题量输入
    	$("[textType='quesQuantityText']").each(function(index){
    		$(this).val($("[divType='quesTypeToChapterAmount']").eq(2*index+1).text()-0);
    		var val = $(this).val() - 0;
			if(!val || val <= 0){
				$(this).val("");
				$(this).css({'background-color': '#FFFF99'});
			}else{
				$(this).css({'background-color': '#F3F3F3'});
			}
			calcWishScore();
			if(editable){
	    		$(this).keyup(function(e){
	    			var val = $(this).val() - 0;
	    			if(!val || val <= 0){
	    				val = '';
	    				$(this).css({'background-color': '#FFFF99'});
	    			}else{
	    				$(this).css({'background-color': '#F3F3F3'});
	    			}
	    			$(this).val(val);
	    			calcWishScore();
	    		});
			}else{
    			$(this).attr("readonly","readonly");
			}
    	});
    }

	$('#btnDiv').css('visibility','visible');
});

function reloadWin(){
	$(document).mask('正在加载，请稍等...');
	window.location.reload();
}

function reloadParentWin(){
	if(window.parent){
		var appElement = window.parent.$('[ng-controller=paperTaskDetailCtrl]');
		var $scope = window.parent.angular.element(appElement).scope();
		$scope.createSkelToView();
	}else{
		window.opener.location.reload();
	}
}

function calcWishScore(){
	var total = 0;
	$("[textType='quesQuantityText']").each(function(index){
		var quantity = $(this).val() - 0;
		if(!quantity){
			quantity = 0;
		}
		var per = $("[textType='quesTypeText']").eq(index).val() - 0;
		if(!per){
			per = 0;
		}
		total = total + quantity*per;
	});
	if(total < 100){
		$("#wishScore").html("<span style='font-weight:bold;color:#ff9900'>" + total + "</span>");
	}else if(total > 100){
		$("#wishScore").html("<span style='font-weight:bold;color:red'>" + total + "</span>");
	}else{
		$("#wishScore").html("<span style='font-weight:bold;color:black'>" + total + "</span>");
	}
}

function calcStat(){
	var chapterToQuesTypeSubtotalForScore = 0;//统计行上面的小计分数
	var chapterToQuesTypeSubtotalForNum = 0;//统计行上面的小计题量
	var chapterToQuesTypeAmountForScore = 0;//统计行上面的合计分数
	var chapterToQuesTypeAmountForNum = 0;//统计行上面的合计题量
	var quesTypeToChapterSubtotalForScores = [];//统计行上面的小计分数
	var quesTypeToChapterSubtotalForNums = [];//统计行上面的小计题量
	var totalSumForScore = 0;//总计分数
	var totalSumForNum = 0;//总计题量
	var diffiScoreArr = [0,0,0,0];//用于统计不同"预计难度"的分值
	var diffiNumArr = [0,0,0,0];//用于统计不同"预计难度"的题量
	var abilityScoreArr = [0,0,0,0];//用于统计不同"认知层次"的分值
	var abilityNumArr = [0,0,0,0];//用于统计不同"认知层次"的题量
	var quesTypeArr = $("[textType='quesTypeText']");
	var quesTypeScoreArr = [];
	quesTypeArr.each(function(index){
		var cellVal = $(this).val();
		cellVal = (cellVal == '')?0:(cellVal - 0);
		quesTypeScoreArr[index] = cellVal;
	});
	var quesTypeSize = quesTypeArr.size();//题型的数量
	var trPerTdSize = quesTypeSize * perDiffiSize;//每行的单元格数量
	for(var i=0;i<trPerTdSize;i++){
		quesTypeToChapterSubtotalForScores[i] = 0;
		quesTypeToChapterSubtotalForNums[i] = 0;
	}
	
	var chapterToQuesTypeSubtotalArr = $("[divType='chapterToQuesTypeSubtotal']");
	var chapterToQuesTypeAmountArr = $("[divType='chapterToQuesTypeAmount']");
	$("[textType='quesNum']").each(function(index){
		var cellVal = $(this).val();
		if(cellVal != ''){
			cellVal = cellVal - 0;
			chapterToQuesTypeSubtotalForNum += cellVal;
			chapterToQuesTypeAmountForNum += cellVal;
			totalSumForNum += cellVal;
			
			var cellScore = cellVal * quesTypeScoreArr[parseInt((parseInt(index % trPerTdSize) / perDiffiSize))];
			chapterToQuesTypeSubtotalForScore += cellScore;
			chapterToQuesTypeAmountForScore += cellScore;
			totalSumForScore += cellScore;
			
			quesTypeToChapterSubtotalForNums[index % trPerTdSize] += cellVal;
			quesTypeToChapterSubtotalForScores[index % trPerTdSize] += cellScore;
			
			diffiScoreArr[index % perDiffiSize] += cellScore;
			diffiNumArr[index % perDiffiSize] += cellVal;
			abilityScoreArr[parseInt(index / trPerTdSize) % perAbilitySize] += cellScore;
			abilityNumArr[parseInt(index / trPerTdSize) % perAbilitySize] += cellVal;
			//alert('quesTypeToChapterSubtotalForScores[' + (index % trPerTdSize) + ']=' + quesTypeToChapterSubtotalForScores[index % trPerTdSize]);
		}
		if(parseInt(index % trPerTdSize) == (trPerTdSize - 1)){
			var rowIndex = parseInt(index / trPerTdSize);
			chapterToQuesTypeSubtotalArr.eq(rowIndex * 2 + 1).text(chapterToQuesTypeSubtotalForNum);
			chapterToQuesTypeSubtotalArr.eq(rowIndex * 2).text(chapterToQuesTypeSubtotalForScore);
			chapterToQuesTypeSubtotalForScore = 0;
			chapterToQuesTypeSubtotalForNum = 0;
		}
		if(parseInt(index % (trPerTdSize * perAbilitySize)) == (trPerTdSize * perAbilitySize - 1)){
			var rowIndex = parseInt(index / (trPerTdSize * perAbilitySize));
			chapterToQuesTypeAmountArr.eq(rowIndex * 2 + 1).text(chapterToQuesTypeAmountForNum);
			chapterToQuesTypeAmountArr.eq(rowIndex * 2).text(chapterToQuesTypeAmountForScore);
			chapterToQuesTypeAmountForScore = 0;
			chapterToQuesTypeAmountForNum = 0;
		}
	});
	var quesTypeToChapterAmountArr = $("[divType='quesTypeToChapterAmount']");
	var amountScore = 0;
	var amountNum = 0;
	$("[divType='quesTypeToChapterSubtotal']").each(function(index){
		if(index % 2 == 0){
			$(this).text(quesTypeToChapterSubtotalForScores[parseInt(index / 2)]);
			amountScore += quesTypeToChapterSubtotalForScores[parseInt(index / 2)];
		}else{
			$(this).text(quesTypeToChapterSubtotalForNums[parseInt(index / 2)]);
			amountNum += quesTypeToChapterSubtotalForNums[parseInt(index / 2)];
		}
		if(index % 8 == 7){
			quesTypeToChapterAmountArr.eq(2*parseInt(index / 8)).text(amountScore);
			quesTypeToChapterAmountArr.eq(2*parseInt(index / 8) + 1).text(amountNum);
			amountScore = 0;
			amountNum = 0;
		}
	});
	$("[divType='amountDiffi']").each(function(index){
		if(index % 2 == 0){
			var score = diffiScoreArr[parseInt(index / 2)] - 0;
			if(estimateDifficultyPercent.length == 0){
				$(this).html("<span style='font-weight:bold;color:red'>" + score + "</span>");
			}else{
				if(score < estimateDifficultyPercent[index / 2][0]){
					$(this).html("<span style='font-weight:bold;color:#ff9900'>" + score + "</span>");
				}else if(score > estimateDifficultyPercent[index / 2][1]){
					$(this).html("<span style='font-weight:bold;color:red'>" + score + "</span>");
				}else{
					$(this).html("<span style='font-weight:normal;color:black'>" + score + "</span>");
				}
			}
		}else{
			$(this).text(diffiNumArr[parseInt(index / 2)]);
		}
	});
	$("[divType='amountAbility']").each(function(index){
		if(index % 2 == 0){
			var score = abilityScoreArr[parseInt(index / 2)] - 0;
			if(abilityPercent.length == 0){
				$(this).html("<span style='font-weight:bold;color:red'>" + score + "</span>");
			}else{
				if(score < abilityPercent[index / 2][0]){
					$(this).html("<span style='font-weight:bold;color:#ff9900'>" + score + "</span>");
				}else if(score > abilityPercent[index / 2][1]){
					$(this).html("<span style='font-weight:bold;color:red'>" + score + "</span>");
				}else{
					$(this).html("<span style='font-weight:normal;color:black'>" + score + "</span>");
				}
			}
		}else{
			$(this).text(abilityNumArr[parseInt(index / 2)]);
		}
	});
	
	var totalSumArr = $("[divType='totalSum']");
	totalSumArr.eq(1).text(totalSumForNum);
	totalSumForScore = totalSumForScore - 0;
	if(totalSumForScore < 100){
		totalSumArr.eq(0).html("<span style='font-weight:bold;color:#ff9900'>" + totalSumForScore + "</span>");
	}else if(totalSumForScore == 100){
		totalSumArr.eq(0).html("<span style='font-weight:bold;color:black'>" + totalSumForScore + "</span>");
	}else{
		totalSumArr.eq(0).html("<span style='font-weight:bold;color:red'>" + totalSumForScore + "</span>");
	}
	$("#totalScore").val(totalSumForScore);
}

function moveTds(quesTypeTdIndex,isLeft){
	var myIndex = quesTypeTdIndex - (isLeft?1:0);
	{//交换“小计”单元格
		var divArr = $("[divType='quesTypeToChapterSubtotal']");
		var needExchangeSize = 2 * perDiffiSize;//每列2个，一个题型对应4列
		for(var i=0;i<needExchangeSize;i++){
			var ecDiv1 = divArr.eq(needExchangeSize * (myIndex - 1) + i);
			var ecDiv2 = divArr.eq(needExchangeSize * myIndex + i);
			var tmp = ecDiv1.html();
			ecDiv1.html(ecDiv2.html());
			ecDiv2.html(tmp);
		}
	}
	{//交换“合计”单元格
		var divArr = $("[divType='quesTypeToChapterAmount']");
		var needExchangeSize = 2 * 1;//每列2个，一个题型对应1列
		for(var i=0;i<needExchangeSize;i++){
			var ecDiv1 = divArr.eq(needExchangeSize * (myIndex - 1) + i);
			var ecDiv2 = divArr.eq(needExchangeSize * myIndex + i);
			var tmp = ecDiv1.html();
			ecDiv1.html(ecDiv2.html());
			ecDiv2.html(tmp);
		}
	}
	{//交换“题量”单元格
		var textArr = $("[textType='quesNum']");
		var quesTypeSize = $("[tdType='quesType']").size();
		var trPerTdSize = quesTypeSize * perDiffiSize;//每行的单元格数量
		var needExchangeSize = perDiffiSize * perAbilitySize * chapterSize;//一个章节有4行
		for(var i=0;i<needExchangeSize;i++){
			var ecText1 = textArr.eq(trPerTdSize * parseInt(i / perDiffiSize) + (myIndex - 1) * perDiffiSize + (i % perDiffiSize));
			var ecText2 = textArr.eq(trPerTdSize * parseInt(i / perDiffiSize) + myIndex * perDiffiSize + (i % perDiffiSize));
			var tmp = ecText1.val();
			ecText1.val(ecText2.val());
			ecText2.val(tmp);
		}
	}
}

function lineHeadTd() {
	<c:if test="${book.chapterSize > 0}">
	var td = document.getElementById('headTd');
	var x1 = td.offsetLeft;
	var y1 = td.offsetTop;
	var x2 = x1 + td.offsetWidth;
	var y2 = y1 + td.offsetHeight;
	var color = '#003399';
	{
		var newX1 = x1 + 70;
		var newY1 = y1;
		var newX2 = x2;
		var newY2 = y2 - 40;
		paintObliqueLine(td,newX1,newY1,newX2,newY2,color);
		paintObliqueText(td,newX1 + 25,newY1 + 5,'题');
		paintObliqueText(td,newX1 + 25 + 13,newY1 + 5 + 13,'型');
	}
	{
		var newX1 = x1 + 30;
		var newY1 = y1;
		var newX2 = x2;
		var newY2 = y2;
		paintObliqueLine(td,newX1,newY1,newX2,newY2,color);
		paintObliqueText(td,newX1 + 25,newY1 + 5,'预');
		paintObliqueText(td,newX1 + 25 + 13,newY1 + 5 + 13,'估');
		paintObliqueText(td,newX1 + 25 + 13*2,newY1  + 5 + 13*2,'难');
		paintObliqueText(td,newX1 + 25 + 13*3,newY1  + 5 + 13*3,'度');
	}
	{
		var newX1 = x1;
		var newY1 = y1 + 30;
		var newX2 = x2;
		var newY2 = y2;
		paintObliqueLine(td,newX1,newY1,newX2,newY2,color);
		paintObliqueText(td,newX1 + 15,newY1 - 17,'数');
		paintObliqueText(td,newX1 + 15 + 15,newY1 - 17 + 10,'量');
	}
	{
		var newX1 = x1;
		var newY1 = y1 + 60;
		var newX2 = x2 - 40;
		var newY2 = y2;
		paintObliqueLine(td,newX1,newY1,newX2,newY2,color);
		paintObliqueText(td,newX1 + 15,newY1 - 15,'认');
		paintObliqueText(td,newX1 + 15 + 15,newY1 - 15 + 9,'知');
		paintObliqueText(td,newX1 + 15 + 15*2,newY1 - 15 + 9*2,'层');
		paintObliqueText(td,newX1 + 15 + 15*3,newY1 - 15 + 9*3,'次');
	}
	paintObliqueText(td,x1 + 5,y2 - 17,'考核内容');
	</c:if>
}

function lineSubtotalTd(td){
	var jTd = $(td);
	var sumType = jTd.attr('sumType');
	var x1 = td.offsetLeft;
	var y1 = td.offsetTop;
	var x2 = x1 + td.offsetWidth;
	var y2 = y1 + td.offsetHeight;
	var color = '#000000';
	{
		var newX1 = x1;
		var newY1 = y1;
		var newX2 = x2;
		var newY2 = y2;
		paintObliqueLine(td,newX1,newY1,newX2,newY2,color,true);
		paintObliqueText(td,newX1 + 3,newY1 + 3,0,sumType);
	}
	paintObliqueText(td,x2 - 18,y2 - 15,0,sumType);
}

function lineAmountTd(td){
	var jTd = $(td);
	var parentTd = jTd.parents("td");
	var sumType = jTd.attr('sumType');
	var pX1 = (parentTd.length == 1)?parentTd.get(0).offsetLeft:0;
	var pY1 = (parentTd.length == 1)?(parentTd.get(0).offsetTop + 1):0;
	var x1 = pX1 + td.offsetLeft;
	var y1 = pY1 + td.offsetTop;
	var x2 = x1 + td.offsetWidth;
	var y2 = y1 + td.offsetHeight;
	var color = '#000000';
	{
		var newX1 = x1;
		var newY1 = y1;
		var newX2 = x2;
		var newY2 = y2;
		paintObliqueLine(td,newX1,newY1,newX2,newY2,color,true);
		paintObliqueText(td,newX1 + 8,newY1 + 8,0,sumType);
	}
	paintObliqueText(td,x2 - 22,y2 - 22,0,sumType);
}

function paintObliqueLine(td, x1, y1, x2, y2, color,fromRight) {
	for (var i = x1 + 1; i < x2; i++) {
		var x = i;
		var y = fromRight?(y2 - (y2 - 1.0*y1) / (x2 - x1) * (x - x1)):((y2 - 1.0*y1) / (x2 - x1) * (x - x1) + y1);
		y = parseInt(y);
		var oDiv=document.createElement("div");
		oDiv.innerHTML = "<div style='position: absolute; left: "
			+ x + "px; top: " + y + "px;background-color: "
			+ color + ";width:1px;height:1px;padding:0px;margin:0px;'></div>";
		td.appendChild(oDiv);
	}
}

function paintObliqueText(td, x,y,text,divType){
	var oDiv=document.createElement("div");
	oDiv.innerHTML = '<div' + (divType?(' divType="' + divType + '"'):'') + ' style="position: absolute; left: ' + x + 'px; top: ' + y + 'px;background: transparent; font-size:9pt;">' + text + '</div>';
	td.appendChild(oDiv);
}

function changeAuditRemark(){
	if($("#normalAuditText").val() != ""){
		$("#remarkForAudit").val($("#normalAuditText").val());
	}
}
</script>