<%@ page language="java" contentType="application/x-javascript; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.qmth.qrzk.repository.utils.General"%>
<%@ taglib uri="/WEB-INF/taglib/c.tld" prefix="c"%>

<c:set var="ctx" value="<%=General.getBasePath(request)%>" scope="request"/>
function courseChange(url,role) {
	resetSelect();
	var obj = {
		"id" : $("#course").val()
	};
	var Course = JSON.stringify(obj);
	$.ajax({
		type : "POST",
		url : url + "/question/loadQuestionType",
		data : Course,
		contentType : "application/json; charset=utf-8",
		dataType : "json",
		success : function(callback) {
			var html = $("#typeId").html();
			callback = eval(callback);
			for (var i = 0; i < callback.length; i++) {
				html += "<option value=\"" + callback[i].id + "\" id=\""+callback[i].id+"_type\">"
						+ callback[i].name + "</option>";
			}
			$("#typeId").html(html);
		}
	});
	$.ajax({
		type : "POST",
		url : url + "/question/loadBook",
		data : Course,
		contentType : "application/json; charset=utf-8",
		dataType : "json",
		success : function(callback) {
			var html = $("#bookId").html();
			callback = eval(callback);
			for (var i = 0; i < callback.length; i++) {
				html += "<option value=\"" + callback[i].id + "\"  id=\""+callback[i].id+"\" selected=\"selected\">"
						+ callback[i].name + "</option>";
			}
			$("#bookId").html(html);
		}
	});
	if(role=='7'||role=='6'){
		
	}else{
		$("#setBy").empty();
		$.ajax({
			type : "POST",
			url : url + "/question/loadTeacherName",
			data : Course,
			contentType : "application/json; charset=utf-8",
			dataType : "json",
			success : function(callback) {
				var html = $("#setBy").html();
				callback = eval(callback);
				for (var i = 0; i < callback.length; i++) {
					html += "<option value=\"" + callback[i].id + "\">"
							+ callback[i].name + "</option>";
				}
				$("#setBy").html(html);
			}
		});
	}
}
function resetSelect(){
	$("#typeId option:gt(0)").remove();
	$("#bookId option:gt(0)").remove();
}
function questionChange(operate){
	var id=$("#typeId").val();
	if(operate=="edit"){
		var typeId=$("#questionType").val();
//		if(typeId=="1"){//原来单选现在多选
			if(id=="2"){
				$(".RadioContent").hide();
				$("#Choose").show();
				$("#answer-content").hide();
				$("#answer_td").text("选项及答案*");
				var ReHtml='<div class="CheckboxContent" id="CheckboxContent">'+
					'<table style="width:100%">'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="A" class="validate[required] checkbox "/>A.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="A_checkbox_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="B" class="validate[required] checkbox "/>B.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="B_checkbox_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="C" class="validate[required] checkbox "/>C.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="C_checkbox_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="D" class="validate[required] checkbox "/>D.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="D_checkbox_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="E" class="validate[required] checkbox "/>E.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="E_checkbox_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '</table></div>';
				$("#Choose").append(ReHtml);
			}else if(id=="1"){
				$(".RadioContent").show();
				$(".CheckboxContent").hide();
			}else{
				$("#answer_td").text("答案");
				$("#answer-content").show();
				$("#Choose").hide();
			}
//		}else if(typeId=="2"){//原来多选
			if(id=="1"){//现在单选
				$(".CheckboxContent").hide();
				$(".RadioContent").hide();
				$("#Choose").show();
				$("#answer-content").hide();
				$("#answer_td").text("选项及答案*");
				var ReHtml='<div class="RadioContent" id="RadioContent">'+
					'<div>'+
					'<table style="width:100%">'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="A" class="validate[required] radio "/>A.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="A_radio_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="B" class="validate[required] radio "/>B.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="B_radio_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="C" class="validate[required] radio "/>C.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="C_radio_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '<tr><td style="width:30px;"><input type="checkbox" name="optionsCKs"value="D" class="validate[required] radio "/>D.</td>'
						+     '<td><div class="col-lg-5 col-sm-5" id="D_radio_input" contenteditable="true" style="height:25px;"></div></td></tr>'
						+ '</table></div>';
				$("#Choose").append(ReHtml);
			}else if(id=="2"){
				$(".RadioContent").hide();
				$(".CheckboxContent").show();
			}else{
				$("#answer_td").text("答案");
				$("#answer-content").show();
				$("#Choose").hide();
			}
//		}else{
//			if(id=="1"){
//				
//			}else if(id=="2"){
//				
//			}
//		}
	}else{
		if(id=="1"){
			$("#answer_td").text("选项及答案");
			$("#Choose").show();
	        $(".RadioContent").show();
	        $(".CheckboxContent").hide();
	        $("#answer-content").hide();
	        $(".radioAdd").html("");
		}else if(id=="2"){
			$("#answer_td").text("选项及答案");
			$("#Choose").show();
	        $(".CheckboxContent").show();
	        $(".RadioContent").hide();
	        $("#answer-content").hide();
	        $(".checkboxAdd").html("");
		}else{
			$("#answer_td").text("答案");
			$("#answer-content").show();
			$("#Choose").hide();
		}
	}
}
 
function clean(){
	if (!$(".CheckboxContent").is(":hidden")) {
        $(".CheckboxContent").html("");
    }
    if (!$(".RadioContent").is(":hidden")) {
        $(".RadioContent").html("");
    }
}
function add(){
	if(($(".CheckboxContent .row").length=="26")&&(!$(".CheckboxContent").is(":hidden"))){
		alert("无法继续添加选项!");
		//$.messager.alert('提示','无法继续添加选项!');
		return;
	}else if(($(".RadioContent .row").length=="26")&&(!$(".RadioContent").is(":hidden"))){
		alert("无法继续添加选项!");
		//$.messager.alert('提示','无法继续添加选项!');
		return;
	}
	var Arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
	if (!$(".CheckboxContent").is(":hidden")) {
		var v=Arr[$(".CheckboxContent .row").length];
		var id=v+"_"+"checkbox_input";
		var input=v+"_"+"checkbox_hidden";
        $(".CheckboxContent").append
        (" <div class=\"row\"><label class=\"col-lg-1 col-sm-1 checkbox-inline\"><input type=\"checkbox\"  name=\"optionsCKs\" value="+v+"  class=\"validate[required] checkbox\" />" 
        		+ v + ".</label><a  onclick=\"del(this)\" href=\"javascript:void(0)\">删除</a><div class=\"col-lg-5 col-sm-5\"><input class=\"validate[required] text-input  listInput\" id="
        		+id+"   style=\"width: 350px;\" readonly=\"readonly\" /></div><div id="+v+"_checkbox_div class=\"list\" field=\"answer\" name=\"答案\" title=\"点击输入内容\"><input type=\"hidden\" id="+input+" /></div></div>");
    }
    if (!$(".RadioContent").is(":hidden")) {
    	var v=Arr[$(".RadioContent .row").length];
    	var id=v+"_"+"radio_input";
    	var input=v+"_"+"radio_hidden";
        $(".RadioContent").append
        (" <div class=\"row\"><label class=\"col-lg-1 col-sm-1\"><input class=\"validate[required] radio \" type=\"radio\" name=\"optionsRadios\"   value="+v+" />" 
        		+v + ".</label><a  onclick=\"del(this)\" href=\"javascript:void(0)\">删除</a> <div class=\"col-lg-5 col-sm-5\"><input class=\"validate[required] text-input listInput\" id="
        		+id+"   style=\"width: 350px;\" readonly=\"readonly\" /></div><div id="+v+"_radio_div class=\"list\" field=\"answer\" name=\"答案\" title=\"点击输入内容\"><input type=\"hidden\" id="+input+" /></div></div>");
    }
}
function del($this){
	$this=$($this);
	var str=$this.parent().find("input").val();
	var num=str.charCodeAt()-65;
	$this.parent().remove();
	var Arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
	if (!$(".CheckboxContent").is(":hidden")) {
		$(".CheckboxContent .row").each(function(i){
			if(i>=num){
				var v=Arr[i];
				var text_value=$("#"+Arr[i+1]+"_checkbox_hidden").val();
				 var input_value=$("#"+Arr[i+1]+"_checkbox_input").val();
				var id=v+"_"+"checkbox_input";
				var input=v+"_"+"checkbox_hidden";
				if(input_value==""){
					$(this).html("<label class=\"col-lg-1 col-sm-1 checkbox-inline\"><input type=\"checkbox\"  name=\"optionsCKs\" value="+v+"  class=\"validate[required] checkbox\" />" 
			        		+ v + ".</label><a  onclick=\"del(this)\" href=\"javascript:void(0)\">删除</a><div class=\"col-lg-5 col-sm-5\"><input class=\"validate[required] text-input  listInput\" id="
			        		+id+"   style=\"width: 350px;\" readonly=\"readonly\"  value=''   /></div><div id="+v+"_checkbox_div class=\"list\" field=\"answer\" name=\"答案\" title=\"点击输入内容\"><input type=\"hidden\" id="+input+" /></div>");
				}else{
					$(this).html("<label class=\"col-lg-1 col-sm-1 checkbox-inline\"><input type=\"checkbox\"  name=\"optionsCKs\" value="+v+"  class=\"validate[required] checkbox\" />" 
			        		+ v + ".</label><a  onclick=\"del(this)\" href=\"javascript:void(0)\">删除</a><div class=\"col-lg-5 col-sm-5\"><input class=\"validate[required] text-input  listInput\" id="
			        		+id+"   style=\"width: 350px;\" readonly=\"readonly\"  value="+input_value+"   /></div><div id="+v+"_checkbox_div class=\"list\" field=\"answer\" name=\"答案\" title=\"点击输入内容\"><input type=\"hidden\" id="+input+" /></div>");
				}
				$("#"+input).val(text_value);
			}
		});
	}
	if (!$(".RadioContent").is(":hidden")) {
		 $(".RadioContent .row").each(function(i){
			 if(i>=num){
				 var v=Arr[i];
				 var text_value=$("#"+Arr[i+1]+"_radio_hidden").val();
				 var input_value=$("#"+Arr[i+1]+"_radio_input").val();
				 var id=v+"_"+"radio_input";
				 var input=v+"_"+"radio_hidden";
				 if(input_value==""){
					 $(this).html("<label class=\"col-lg-1 col-sm-1\"><input class=\"validate[required] radio \" type=\"radio\" name=\"optionsRadios\"   value="+v+" />" 
				        		+v + ".</label><a  onclick=\"del(this)\" href=\"javascript:void(0)\">删除</a> <div class=\"col-lg-5 col-sm-5\"><input class=\"validate[required] text-input listInput\" id="
				        		+id+"   style=\"width: 350px;\" readonly=\"readonly\"  value=''        /></div><div id="+v+"_radio_div class=\"list\" field=\"answer\" name=\"答案\" title=\"点击输入内容\"><input type=\"hidden\" id="+input+"   /></div>");
				 }else{
					 $(this).html("<label class=\"col-lg-1 col-sm-1\"><input class=\"validate[required] radio \" type=\"radio\" name=\"optionsRadios\"   value="+v+" />" 
				        		+v + ".</label><a  onclick=\"del(this)\" href=\"javascript:void(0)\">删除</a> <div class=\"col-lg-5 col-sm-5\"><input class=\"validate[required] text-input listInput\" id="
				        		+id+"   style=\"width: 350px;\" readonly=\"readonly\"  value=" +input_value+ "        /></div><div id="+v+"_radio_div class=\"list\" field=\"answer\" name=\"答案\" title=\"点击输入内容\"><input type=\"hidden\" id="+input+"   /></div>");
				 }
				 $("#"+input).val(text_value);
			 }
		});
	 }
}


function getRadioData(){
	var length=$("input[name=optionsRadios]").length.toString();		//radio的个数
	if(length<2){
		alert("单项选择题选项至少应该为2个");
		//$.messager.alert('提示','单项选择题选项至少应该为2个');
		return "false";
	}
	var str=$("input[name=optionsRadios]:checked").val();				//被选中的按钮
	var code=str.charCodeAt();											//被选中按钮转ascii
	var correctOption=code-65;											//被选中的-65转成与数据库对应的数据
	var arr = new Array();
	var arr1=new Array();
	for(var i=0;i<length;i++){
		var isCorrectOption=0;
		if(i==correctOption){
			isCorrectOption=1;
		}
		var str=(String.fromCharCode(i+65));
		arr1.push($("#"+str+"_radio_input").html());
		var obj = {
			"id" : $("#"+str+"_radio_id").val(),
			"optionNo" : i,
			"isCorrectOption" : isCorrectOption,
			"content" : $("#"+str+"_radio_input").html(),
			"contentWord" : "",
			"summary" :$("#"+str+"_radio_input").text()
		};
		arr.push(JSON.stringify(obj));
	}
	
	var nary=arr1.sort();
	for(var i=0;i<arr1.length;i++){
		if(nary[i]==nary[i+1]){
			alert("保存失败,选项内容重复---");
			//$.messager.alert('提示','保存失败,选项内容重复');
			return "false";
		}
	}
	return arr;
}

function getRadioIds(){
	var length=$("input[name=optionsRadios]").length.toString();		//radio的个数
	if(length<2){
		alert("单项选择题选项至少应该为2个");
		//$.messager.alert('提示','单项选择题选项至少应该为2个');
		return "false";
	}
	var str=$("input[name=optionsRadios]:checked").val();				//被选中的按钮
	var code=str.charCodeAt();											//被选中按钮转ascii
	var correctOption=code-65;											//被选中的-65转成与数据库对应的数据
	var arr = new Array();
	var arr1=new Array();
	for(var i=0;i<length;i++){
		var isCorrectOption=0;
		if(i==correctOption){
			isCorrectOption=1;
		}
		var str=(String.fromCharCode(i+65));
		arr1.push($("#"+str+"_radio_input").html());
		var obj = {
			"id" :  $("#"+str+"_radio_id").val(),
			"optionNo" : i,
			"isCorrectOption" : isCorrectOption,
			"content" : $("#"+str+"_radio_input").html(),
			"contentWord" : "",
			"summary" :$("#"+str+"_radio_input").text()
		};
		arr.push(JSON.stringify(obj));
	}
	var nary=arr1.sort();
	for(var i=0;i<arr1.length;i++){
		if(nary[i]==nary[i+1]){
			alert("保存失败,选项内容重复");
			//$.messager.alert('提示','保存失败,选项内容重复');
			return "false";
		}
	}
	return arr;
}

function getCheckBoxData(){
	var length=$("input[name=optionsCKs]").length.toString();
	if(length<3){
		alert("多项选择题选项至少应该为3个");
		//$.messager.alert('提示','多项选择题选项至少应该为3个');
		return "false";
	}
	var strarr = new Array();
	var arr1=new Array();
	 $("input[name=optionsCKs]:checked").each(function(){
		strarr.push( $(this).val());
	 });
	var correctArr=new Array();
	
	for(var i=0;i<strarr.length;i++){
		var code=strarr[i].charCodeAt();
		var correctOption=code-65;
		correctArr.push(correctOption);
	}
	var arr = new Array();
	for(var i=0;i<length;i++){
		var isCorrectOption=0;
		if($.inArray(i, correctArr)!=-1){
			isCorrectOption=1;
		}
		var str=(String.fromCharCode(i+65));
		arr1.push($("#"+str+"_checkbox_input").html());
		var obj = {
				"id" : $("#"+str+"_checkbox_id").val(),
				"optionNo" : i,
				"isCorrectOption" : isCorrectOption,
				"content" : $("#"+str+"_checkbox_input").html(),
				"contentWord" : "",
				"summary" :	$("#"+str+"_checkbox_input").text()
		};
		arr.push(JSON.stringify(obj));
	}
	var nary=arr1.sort();
	for(var i=0;i<arr1.length;i++){
		if(nary[i]==nary[i+1]){
			alert("保存失败,选项内容重复");
			//$.messager.alert('提示','保存失败,选项内容重复');
			return "false";
		}
	}
	
	return arr;
}

function getCheckBoxIds(){
	var length=$("input[name=optionsCKs]").length.toString();
	if(length<3){
		alert("多项选择题选项至少应该为3个");
		//$.messager.alert('提示','多项选择题选项至少应该为3个');
		return "false";
	}
	var strarr = new Array();
	 $("input[name=optionsCKs]:checked").each(function(){
		strarr.push( $(this).val());
	});
	var correctArr=new Array();
	var arr1=new Array();
	for(var i=0;i<strarr.length;i++){
		var code=strarr[i].charCodeAt();
		var correctOption=code-65;
		correctArr.push(correctOption);
	}
	var arr = new Array();
	for(var i=0;i<length;i++){
		var isCorrectOption=0;
		if($.inArray(i, correctArr)!=-1){
			isCorrectOption=1;
		}
		var str=(String.fromCharCode(i+65));
		arr1.push($("#"+str+"_checkbox_input").html());
		var obj = {
				"id" : $("#"+str+"_checkbox_id").val(),
				"optionNo" : i,
				"isCorrectOption" : isCorrectOption,
				"content" : $("#"+str+"_checkbox_input").html(),
				"contentWord" : "",
				"summary" :	$("#"+str+"_checkbox_input").text()
		};
		arr.push(JSON.stringify(obj));
	}
	var nary=arr1.sort();
	for(var i=0;i<arr1.length;i++){
		if(nary[i]==nary[i+1]){
			alert("保存失败,选项内容重复");
			//$.messager.alert('提示','保存失败,选项内容重复');
			return "false";
		}
	}
	return arr;
}

function validationBodyAnswer(){
	if($("#body-content").text()==""){
		alert("题干不能为空");
		//$.messager.alert('提示','题干不能为空');
		return false;
	}
	var typeId=$("#typeId").val();
	if(!(typeId=='1'||typeId=='2')){
		if ($("#answer-content").text()==""){
			alert("答案不能为空");
			//$.messager.alert('提示','答案不能为空');
			return false;
		}else{
			return true;
		}
	}else{ 
		return true;
	}
	
}

function goSave(url,str){
	var isValid =  $("#questionUpdateFrm").validationEngine('validate');
	if(isValid){
		if(validationBodyAnswer()){
			//var tt=new Date($("#createdTime").val().replace(/-/g,   "/"));     					//格式化时间
			var tt=$("#setTime").val();
			var courseId=$("#course").val();														//课程id
			var typeId=$("#typeId").val();															//题型id
			var bookId=$("#bookId").val();															//教材id
			var estimateDifficultyCode=$('input[name="estimateDifficultyCode"]:checked').val();		//预计难度
			var assessmentDemand=$('input[name="assessmentDemand"]:checked').val();						//考核要求
			var abilityCode=$('input[name="abilityCode"]:checked').val();							//认知层次
			var chapter=$("#chapter").val();														//章
			var section=$("#section").val();														//节
			var item=$("#item").val();																//目
			var page=$("#ye").val();																//页
			var score=$("#score").val();															//满分值
			var body=$("#body-content").html();														//题干
			var bodySummary=$("#body-content").text();
			var answer="";
			var answerSummary="";
			var arr = new Array();
			if(!(typeId=='1'||typeId=='2')){
				answer=$("#answer-content").html();													//答案
				answerSummary=$("#answer-content").text();
			}else{
				if(typeId=='1'){
					arr=getRadioIds();
					if(arr=="false"){
						return;
					}
				}else if(typeId=='2'){
					arr=getCheckBoxIds();
					if(arr=="false"){
						return;
					}
				}
			}
			var answerSheet=$("#answerSheet").html();														//题卡
			var enableTime=tt;
			var setBy=$("#setBy").val();															//命题人
			var setTeacherName=$('#setBy option:selected').text();  								//命题人名称
			var remark=$("#remark").val();															//备注
			var createdTime=tt;																		//创建日期
			var createdBy=$("#createdBy").val();														//创建人
			var updatedTime=tt;																		//更新日期
			var updatedBy=$("#createdBy").val();														//更新人
	
			var obj = {
					"questionNo" : "", 
					"courseId" : courseId,																	//课程id
					"typeId": typeId,																		//题型id
					"bookId" : bookId,																		//教材id
					"estimateDifficultyCode" : estimateDifficultyCode,										//预计难度
					"assessmentDemand" : assessmentDemand,													//层次
					"abilityCode" : abilityCode,															//认知层次
					"chapter" : chapter,																	//章
					"section" : section,																	//节
					"item" : item,																			//目
					"page" : page,																			//页
					"score" :  score,																		//满分值
					"body" : body,																			//题干
					"bodySummary" :bodySummary,
					"answer" : answer,																		//答案
					"answerSummary" : answerSummary,
					"answerSheet":answerSheet,																//题卡
					"enableTime" : enableTime,
					"setTime" : createdTime,																//命题时间
					"setBy" : setBy,																		//命题人
					"setTeacherName" : setTeacherName,								    					//命题人名称
					"remark" : remark, 																		//备注
					"createdTime" : createdTime,															//创建日期
					"createdBy" : createdBy,																	//创建人
					"updatedTime" : updatedTime,															//更新日期
					"updatedBy" : updatedBy																		//更新人
				};
			var Question = JSON.stringify(obj);
			
			$(document).mask('正在保存中，请稍等...');
			$.ajax({
				type : "POST",
				url : url + "/question/insert",
				data : "{Question:" + Question + ",arr:" + "[" + arr + "]" + "}", 
				contentType : "application/json; charset=utf-8",
				dataType : "json",
				success : function(callback) {
					$(document).unmask();
					callback = eval(callback);
					if(str=="save"){
						//alert("新增试题成功!");
						//$.messager.alert('提示','新增试题成功!');
						$.messager.alert('提示', "新增试题成功!", 'info', function () {
							location.href="${ctx}/question/view/"+callback.id;
	                	});
					}else if(str=="saveAdd"){
						$.messager.alert('提示', "新增试题成功!", 'info');
						$('#body-content').html('');
						$('#A_radio_input').html('');
						$('#B_radio_input').html('');
						$('#C_radio_input').html('');
						$('#D_radio_input').html('');
						
						$('#A_checkbox_input').html('');
						$('#B_checkbox_input').html('');
						$('#C_checkbox_input').html('');
						$('#D_checkbox_input').html('');
						$('#E_checkbox_input').html('');
						
						
						$("input:radio[name='optionsRadios']:checked").removeAttr("checked");						
						$("input:checkbox[name='optionsCKs']:checked").removeAttr("checked");
						
						$('#answer-content').html('');
						$('#answerSheet').html('');
						$('#remark').val('');
						$('#infoTable tr:gt(0)').remove();
					}
					
				}
			});
		}
	}
}
function update(url){
	var isValid =  $("#questionUpdateFrm").validationEngine('validate');
	if(isValid){
		if(validationBodyAnswer()){
			//var tt=new Date($("#createdTime").val().replace(/-/g,   "/"));     					//格式化时间
			var tt=$("#setTime").val();
			var questionId=$("#questionId").val();
			var courseId=$("#course").val();														//课程id
			var typeId=$("#typeId").val();															//题型id
			var bookId=$("#bookId").val();															//教材id
			var estimateDifficultyCode=$('input[name="estimateDifficultyCode"]:checked').val();		//预计难度
			var assessmentDemand=$('input[name="assessmentDemand"]:checked').val();					//考核要求
			var abilityCode=$('input[name="abilityCode"]:checked').val();							//认知层次
			var chapter=$("#chapter").val();														//章
			var section=$("#section").val();														//节
			var item=$("#item").val();																//目
			var page=$("#ye").val();																//页
			var score=$("#score").val();															//满分值
			var body=$("#body-content").html();														//题干
			var bodySummary=$("#body-content").text();
			var answer="";
			var answerSummary="";
			var arr = new Array();
			if(!(typeId=='1'||typeId=='2')){
				answer=$("#answer-content").html();													//答案
				answerSummary=$("#answer-content").text();
			}else{
				if(typeId=='1'){
					arr=getRadioData();
					if(arr=="false"){
						return;
					}
				}else if(typeId=='2'){
					arr=getCheckBoxData();
					if(arr=="false"){
						return;
					}
				}
			}
			var answerSheet=$("#answerSheet").html();														//题卡
			var enableTime=tt;
			var setBy=$("#setBy").val();															//命题人
			var setTeacherName=$('#setBy option:selected').text();  								//命题人名称
			var remark=$("#remark").val();															//备注
			var setTime=tt;	//命题日期
			var createdTime=tt;																		//创建日期
			var createdBy=$("#createdBy").val();														//创建人
			var updatedTime=tt;																		//更新日期
			var updatedBy=$("#createdBy").val();														//更新人
			var statusCode=$("#statusCode").val();
			var assessmentDemand=$('input[name="assessmentDemand"]:checked').val();
			
			var obj = {
					"id" : questionId,
					"questionNo" : "", 
					"courseId" : courseId,																	//课程id
					"typeId": typeId,																		//题型id
					"bookId" : bookId,																		//教材id
					"estimateDifficultyCode" : estimateDifficultyCode,										//预计难度
					"assessmentDemand" : assessmentDemand,													//考核要求
					"abilityCode" : abilityCode,															//认知层次
					"chapter" : chapter,																	//章
					"section" : section,																	//节
					"item" : item,																			//目
					"page" : page,																			//页
					"score" :  score,																		//满分值
					"body" : body,																			//题干
					"bodySummary" :bodySummary,
					"answer" : answer,																		//答案
					"answerSummary" : answerSummary,
					"answerSheet":answerSheet,
					"enableTime" : enableTime,
					"setTime" : createdTime,																//命题时间
					"setBy" : setBy,																		//命题人
					"statusCode" : statusCode,
					"setTeacherName" : setTeacherName,								    					//命题人名称
					"remark" : remark, 																		//备注
					"createdTime" : createdTime,															//创建日期
					"createdBy" : createdBy,																	//创建人
					"updatedTime" : updatedTime,															//更新日期
					"updatedBy" : updatedBy,																//更新人
					"assessmentDemand" : assessmentDemand
				};
			var Question = JSON.stringify(obj);
			$.ajax({
				type : "POST",
				url : url + "/question/update",
				data : "{Question:" + Question + ",arr:" + "[" + arr + "]" + "}", 
				contentType : "application/json; charset=utf-8",
				dataType : "json",
				success : function(callback) {
					callback = eval(callback);
					alert("试题修改成功!");
					//$.messager.alert('提示','试题修改成功!');
					location.href="${ctx}/question/view/"+callback.id;
				}
			});
		}
	}
}


