var index = -1;
var rightName='';
var _li='';
$(function(){
	getRightName();
	showAuditRight();
	if($("#r1").val()=="1"){
		$("#choose1").removeClass("check_no1");
		$("#choose1").addClass("check_yes1");
	}
	if($("#r2").val()=="1"){
		$("#choose2").removeClass("check_no1");
		$("#choose2").addClass("check_yes1");
	}
	if($("#r3").val()=="1"){
		$("#choose3").removeClass("check_no1");
		$("#choose3").addClass("check_yes1");
	}
	
		//复选框
		$(".check_yes1,.check_no1").click(function(){
			  if($(this).is(".check_yes1")){
				$(this).removeClass("check_yes1");
				$(this).addClass("check_no1"); 
			  
			  }else{
					$(this).removeClass("check_no1");
			        $(this).addClass("check_yes1");
			}
		 });
	
});

function showAuditRight(){
	
	$.ajax({
		 type: "POST",  
	     url: "showAuditRight.do",
	     data:"",
	     success:function(data){
	    	for(var i = 0 ;i< data.length;i++){
	    		var info= data[i];
	    		geInitRiskCode(info.rName);
	    		var tr = "<tr id=\""+info.functionId+"\" onclick=\"choosEd(this)\">"+
	    		"<input type=\"hidden\" readonly=\"readonly\" code=\""+info.roleId+"\" value=\""+info.roleId+"\"/>"+
	    		"<td><div class=\"select i_s_100 mar_cen\"> <span class=\"sel_text\">"+info.rName+"</span><div class=\"sel_list i_ul_125\" style=\"display:none;\"><ul>" +
	    		rightName +
	    		"</ul></div></div></td>"+
	    		"<td><div class=\"select i_s_60 mar_cen\"> <span class=\"sel_text\">"+info.rCode+"</span><div class=\"sel_list i_ul_85\" style=\"display:none;\">" +
	    				" <ul>"+_li+"</ul> </div></div></td>" +
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.dieMaxAmt)+"\" value=\""+isNull(info.dieMaxAmt)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.deformityMaxAmt)+"\"  value=\""+isNull(info.deformityMaxAmt)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.seriousIllnessMaxAmt)+"\" value=\""+isNull(info.seriousIllnessMaxAmt)+"\"></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.outpatientMaxAmt)+"\" value=\""+isNull(info.outpatientMaxAmt)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.inHospitalMedicalMaxAmt)+"\" value=\""+isNull(info.inHospitalMedicalMaxAmt)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.inHospitalSubsidyMaxAmt)+"\" value=\""+isNull(info.inHospitalSubsidyMaxAmt)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.accommodationMaxAmt)+"\" value=\""+isNull(info.accommodationMaxAmt)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.settlementMaxAmt)+"\" value=\""+isNull(info.settlementMaxAmt)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt1)+"\" value=\""+isNull(info.maxAmt1)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt2)+"\" value=\""+isNull(info.maxAmt2)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt3)+"\" value=\""+isNull(info.maxAmt3)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt4)+"\" value=\""+isNull(info.maxAmt4)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt5)+"\" value=\""+isNull(info.maxAmt5)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt6)+"\" value=\""+isNull(info.maxAmt6)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt7)+"\" value=\""+isNull(info.maxAmt7)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt8)+"\" value=\""+isNull(info.maxAmt8)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt9)+"\" value=\""+isNull(info.maxAmt9)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt10)+"\" value=\""+isNull(info.maxAmt10)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt11)+"\" value=\""+isNull(info.maxAmt11)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt12)+"\" value=\""+isNull(info.maxAmt12)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt13)+"\" value=\""+isNull(info.maxAmt13)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt14)+"\" value=\""+isNull(info.maxAmt14)+"\"/></td>"+
	    				" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" maxlength=\"12\" code=\""+isNull(info.maxAmt15)+"\" value=\""+isNull(info.maxAmt15)+"\"/></td>"+
	    	    "</tr>";
	    		
	    		$("#auditRightList").append(tr);
	    		
	    	}
	    	selected();	
	     },
	     error:function(data){
	    	 
	     }
	});
}

function getRightName(){
	$.ajax({
		 type: "POST",  
	     url: "getRightName.do",
	     data:"",
	     success:function(data){
	    	for(var i = 0 ;i< data.length;i++){
	    		var info= data[i];
	    		rightName += "<li onclick=\"getRiskCode(this);\">"+info.roleName+"</li>";
	    	}
	     },
	     error:function(data){
	    	 
	     }
	});
	

}

function geInitRiskCode(riskName){
	
	$.ajax({
		 type: "POST",  
	     url: "getRightCode.do",
	     data:"name="+riskName,
	     async : false,
	     success:function(data){
	    	 _li = '';
	    	for(var i = 0 ;i<data.length;i++){
	    		var info= data[i];
	    		_li +="<li id=\""+info.id+"\">"+info.roleLevel+"</li>";
	    	}
	     },
	     error:function(data){
	    	 alert("111");
	     }
	});
	
}

function getRiskCode(obj){
	var  riskName = obj.innerHTML;
	var _thisText = $("#auditRightList tr:eq("+index+")").find(".sel_text:eq(1)");
	var _thisUl = $("#auditRightList tr:eq("+index+")").find("ul:eq(1)");
	_thisText.html("请选择");
	_thisUl.html("");
	 
	$.ajax({
		 type: "POST",  
	     url: "getRightCode.do",
	     data:"name="+riskName,
	     success:function(data){
	    	for(var i = 0 ;i<data.length;i++){
	    		var info= data[i];
	    		_thisUl.append("<li id=\""+info.id+"\">"+info.roleLevel+"</li>");
	    	};
	    	$(".select").find(".sel_list li").hover( function (){
				$(this).addClass("sel_hov");		
			},function (){
				$(this).removeClass("sel_hov");	
			}).on('click',function(){
				var _this = $(this).html();
				var _id= $(this).attr("id");
				var flag="1";
				$('#auditRightList').find("tr").each(function(){
					if( _id== $(this).find("input:eq(0)").val()){
						flag = "2";
						return false;
					}
				});
				if(flag =="2"){
					alert("已存在相同的授权信息,请确认");
					return;
				}else{
					var _thisText = $(this).closest(".select").find(".sel_text");
					_thisText.html(_this);
					var _thisRoleId = $("#auditRightList tr:eq("+index+")").find("input:eq(0)");
					var selectRoleId = $(this).attr("id");
					_thisRoleId.val(selectRoleId);
				}
				
			});
	     },
	     error:function(data){
	    	 
	     }
	});
}	

function addTr(){
	var tr = "<tr id=\"addnewtr\" onclick=\"choosEd(this)\">"+
	"<input type=\"hidden\" value=\"\" code=\"\" readonly=\"readonly\"/>"+
	"<td><div class=\"select i_s_100 mar_cen\"> <span id=\"riskname\" class=\"sel_text\">请选择</span><div class=\"sel_list i_ul_125\" style=\"display:none;\"><ul>" +
	rightName +
	"</ul></div></div></td>"+
	"<td><div class=\"select i_s_60 mar_cen\"> <span id=\"riskcode\" class=\"sel_text\">请选择</span><div class=\"sel_list i_ul_85\" style=\"display:none;\">" +
			" <ul id=\"emplevel\"> </ul> </div></div></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			" <td><input type=\"text\" class=\"input i_s_60 input_bot_line\" style=\"text-align: center;\" code=\"\" maxlength=\"12\" /></td>" +
			
    "</tr>";
	var html = $("#auditRightList").html();
	$("#auditRightList").html(html+tr);
	selected();	
}

function delTr(){
	
	if(index!=-1){
		if (confirm("是否确认删除?")) {
			var id = $("#auditRightList tr:eq("+index+")").attr("id").trim();
			if(id != "addnewtr"){
				$.ajax({
					 type: "POST",  
				     url: "deleteAuditRight.do",
				     data:"id="+id,
				     async : false,
				     success:function(data){
				    	 $("#auditRightList tr:eq("+index+")").remove();
						index=-1;
				    	 alert("删除成功");
				     },
				     error:function(data){
				    	 alert("删除失败");
				     }
				});
			}else{
				$("#auditRightList tr:eq("+index+")").remove();
				index=-1;
		    	 alert("删除成功");
			}
			
		}
	}else if(index == -1){
		alert("请选择需要删除的终审权限");
	}
	
}

function choosEd(flag){
	 
	$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
	index=$(flag).index();

}

function selected(){
	$(".select").hover( function () {
		$(this).addClass("sel_over");
	},function () {
		$(this).removeClass("sel_over");
	}).on('click',function(){
		var _this = $(this),
			_bthis = $(this).find(".sel_list");
		if ( _this.attr('isopen') ) {
			_bthis.slideUp(0 , function(){
				_this.removeAttr('isopen');
			});			
		} else {
			_bthis.slideDown(0,function(){
				_this.attr('isopen',"1");
			});	
		}
	}).on('mouseleave',function(){
		var _thisa = $(this).find(".sel_list"),
			_this = $(this);
		_thisa.hide();
		_this.removeAttr('isopen');
	}),
	$(".select").find(".sel_list li").hover( function (){
		$(".select").addClass("sel_hov");		
	},function (){
		$(this).removeClass("sel_hov");	
	}).on('click',function(){
		var _this = $(this).html();
		var _id= $(this).attr("id");
		var flag="1";
		$('#auditRightList').find("tr").each(function(){
			if( _id== $(this).find("input:eq(0)").val()){
				flag = "2";
				return false;
			}
		});
		if(flag =="2"){
			alert("已存在相同的授权信息,请确认");
			return;
		}else{
			var _thisText = $(this).closest(".select").find(".sel_text");
			_thisText.html(_this);
			var _thisRoleId = $("#auditRightList tr:eq("+index+")").find("input:eq(0)");
			var selectRoleId = $(this).attr("id");
			_thisRoleId.val(selectRoleId);
		}
	});
}
function saveLPRight(){
	var r1,r2,r3;
	if($("#choose1").is(".check_yes1")){
		r1="1";
	}else{
		r1="0";
	}
	if($("#choose2").is(".check_yes1")){
		r2="1";
	}else{
		r2="0";
	}
	if($("#choose3").is(".check_yes1")){
		r3="1";
	}else{
		r3="0";
	}
	
	var jsonStr = '{"r1":"'+r1+'",'
	 +'"r2":"'+r2+'",'
	 +'"r3":"'+r3+'"'
	 +'}';
	$.ajax({
		 type: "POST",  
	     url: "saveLPRight.do",
	     data:jsonStr,
	     dataType:"json",
		 contentType:"application/json; charset=UTF-8",
	     success:function(data){
	    	 alert("保存成功");
	     },
	     error:function(data){
	    	alert(data) ;
	     }
	});
}

function saveSimpleRight(){
	var flag = "1";
	
	$("#simple").find("input").each(function(i,n){
		if($(this).attr("code") != $(this).val()){
			flag = "3";
			return false;
		}
	});
	$("#simple").find("input").each(function(i,n){
		if($(this).val() == ''){
			flag = "2";
			return false;
		}
	});
	$("#simple").find("input").each(function(i,n){
		var mny = /(^\d+$)|(^\d+.\d+$)/g;
		if(!mny.test($(this).val())){
			flag = "4";
			return false;
		}
		
	});
	
	if(flag == "1"){
		alert("没有做修改，无需保存");
		return;
	}else if(flag == "2"){
		alert("所有设置均不能为空，请仔细核对");
		return;
	}else if(flag == "4"){
		alert("所有设置必须为数字，请仔细核对");
		return;
	}else if(flag == "3"){
		var id=$("#simple").find("input:eq(0)").val();
		var dieMaxAmt =$("#simple").find("input:eq(1)").val();
		var deformityMaxAmt =$("#simple").find("input:eq(2)").val();
		var seriousIllnessMaxAmt =$("#simple").find("input:eq(3)").val();
		var outpatientMaxAmt =$("#simple").find("input:eq(4)").val();
		var inHospitalMedicalMaxAmt =$("#simple").find("input:eq(5)").val();
		var inHospitalSubsidyMaxAmt =$("#simple").find("input:eq(6)").val();
		var accommodationMaxAmt =$("#simple").find("input:eq(7)").val();
		var settlementMaxAmt =$("#simple").find("input:eq(8)").val();
		var maxAmt1 =$("#simple").find("input:eq(9)").val();
		var maxAmt2 =$("#simple").find("input:eq(10)").val();
		var maxAmt3 =$("#simple").find("input:eq(11)").val();
		var maxAmt4 =$("#simple").find("input:eq(12)").val();
		var maxAmt5 =$("#simple").find("input:eq(13)").val();
		var maxAmt6 =$("#simple").find("input:eq(14)").val();
		var maxAmt7 =$("#simple").find("input:eq(15)").val();
		var maxAmt8 =$("#simple").find("input:eq(16)").val();
		var maxAmt9 =$("#simple").find("input:eq(17)").val();
		var maxAmt10 =$("#simple").find("input:eq(18)").val();
		var maxAmt11 =$("#simple").find("input:eq(19)").val();
		var maxAmt12 =$("#simple").find("input:eq(20)").val();
		var maxAmt13 =$("#simple").find("input:eq(21)").val();
		var maxAmt14 =$("#simple").find("input:eq(22)").val();
		var maxAmt15 =$("#simple").find("input:eq(23)").val();
		var jsonStr = '{"id":"'+id+'",'
		  +'"dieMaxAmt":"'+dieMaxAmt+'",'
		  +'"deformityMaxAmt":"'+deformityMaxAmt+'",'
		  +'"seriousIllnessMaxAmt":"'+seriousIllnessMaxAmt+'",'
		  +'"outpatientMaxAmt":"'+outpatientMaxAmt+'",'
		  +'"inHospitalMedicalMaxAmt":"'+inHospitalMedicalMaxAmt+'",'
		  +'"inHospitalSubsidyMaxAmt":"'+inHospitalSubsidyMaxAmt+'",'
		  +'"accommodationMaxAmt":"'+accommodationMaxAmt+'",'
		  +'"settlementMaxAmt":"'+settlementMaxAmt+'",'
		  +'"maxAmt1":"'+maxAmt1+'",'
		  +'"maxAmt2":"'+maxAmt2+'",'
		  +'"maxAmt3":"'+maxAmt3+'",'
		  +'"maxAmt4":"'+maxAmt4+'",'
		  +'"maxAmt5":"'+maxAmt5+'",'
		  +'"maxAmt6":"'+maxAmt6+'",'
		  +'"maxAmt7":"'+maxAmt7+'",'
		  +'"maxAmt8":"'+maxAmt8+'",'
		  +'"maxAmt9":"'+maxAmt9+'",'
		  +'"maxAmt10":"'+maxAmt10+'",'
		  +'"maxAmt11":"'+maxAmt11+'",'
		  +'"maxAmt12":"'+maxAmt12+'",'
		  +'"maxAmt13":"'+maxAmt13+'",'
		  +'"maxAmt14":"'+maxAmt14+'",'
		  +'"maxAmt15":"'+maxAmt15+'"'
		  +'}';
		
		$.ajax({
			 type: "POST",  
		     url: "saveSimpleRight.do",
		     data:jsonStr,
		     dataType:"json",
			 contentType:"application/json; charset=UTF-8",
		     success:function(data){
		    	 $("#simple").find("input:eq(1)").attr("code",dieMaxAmt);
		    	 $("#simple").find("input:eq(2)").attr("code",deformityMaxAmt);
		    	 $("#simple").find("input:eq(3)").attr("code",seriousIllnessMaxAmt);
		    	 $("#simple").find("input:eq(4)").attr("code",outpatientMaxAmt);
		    	 $("#simple").find("input:eq(5)").attr("code",inHospitalMedicalMaxAmt);
		    	 $("#simple").find("input:eq(6)").attr("code",inHospitalSubsidyMaxAmt);
		    	 $("#simple").find("input:eq(7)").attr("code",accommodationMaxAmt);
		    	 $("#simple").find("input:eq(8)").attr("code",settlementMaxAmt);
		    	 $("#simple").find("input:eq(9)").attr("code",maxAmt1);
		    	 $("#simple").find("input:eq(10)").attr("code",maxAmt2);
		    	 $("#simple").find("input:eq(11)").attr("code",maxAmt3);
		    	 $("#simple").find("input:eq(12)").attr("code",maxAmt4);
		    	 $("#simple").find("input:eq(13)").attr("code",maxAmt5);
		    	 $("#simple").find("input:eq(14)").attr("code",maxAmt6);
		    	 $("#simple").find("input:eq(15)").attr("code",maxAmt7);
		    	 $("#simple").find("input:eq(16)").attr("code",maxAmt8);
		    	 $("#simple").find("input:eq(17)").attr("code",maxAmt9);
		    	 $("#simple").find("input:eq(18)").attr("code",maxAmt10);
		    	 $("#simple").find("input:eq(19)").attr("code",maxAmt11);
		    	 $("#simple").find("input:eq(20)").attr("code",maxAmt12);
		    	 $("#simple").find("input:eq(21)").attr("code",maxAmt13);
		    	 $("#simple").find("input:eq(22)").attr("code",maxAmt14);
		    	 $("#simple").find("input:eq(23)").attr("code",maxAmt15);
		    	 alert("保存成功");
		     },
		     error:function(data){
		    	alert(data) ;
		     }
		});
	}
	
}

function saveRoleRight(){
	var flag="1";
	var changeStr  ='';
	var jsonStr= "";
	$("#auditRightList").find("input").each(function(){
		if(!$(this).val()){
			flag="2";
			return false;
		}
	});
	$("#auditRightList").find("input").each(function(){
		var mny = /(^\d+$)|(^\d+.\d+$)/g;
		if(!mny.test($(this).val())){
			flag = "3";
			return false;
		}
	});
	if(flag == "2"){
		alert("所有设置均不能为空，请仔细核对");
		return;
	}else if(flag == "3"){
		alert("所有设置必须为数字，请仔细核对");
		return;
	}
	
	$("#auditRightList").find("tr").each(function(){
		var changeFlag = "1";
		$(this).find("input").each(function(){
			if($(this).val() != $(this).attr("code")){
				changeFlag ="2";
				return false;
			}
		});
		if(changeFlag =="2"){
			var id=$(this).attr("id");
			if(id =='addnewtr'){
				id='';
			}
			var roleId=$(this).find("input:eq(0)").val();
			var dieMaxAmt =$(this).find("input:eq(1)").val();
			var deformityMaxAmt =$(this).find("input:eq(2)").val();
			var seriousIllnessMaxAmt =$(this).find("input:eq(3)").val();
			var outpatientMaxAmt =$(this).find("input:eq(4)").val();
			var inHospitalMedicalMaxAmt =$(this).find("input:eq(5)").val();
			var inHospitalSubsidyMaxAmt =$(this).find("input:eq(6)").val();
			var accommodationMaxAmt =$(this).find("input:eq(7)").val();
			var settlementMaxAmt =$(this).find("input:eq(8)").val();
			var maxAmt1 =$(this).find("input:eq(9)").val();
			var maxAmt2 =$(this).find("input:eq(10)").val();
			var maxAmt3 =$(this).find("input:eq(11)").val();
			var maxAmt4 =$(this).find("input:eq(12)").val();
			var maxAmt5 =$(this).find("input:eq(13)").val();
			var maxAmt6 =$(this).find("input:eq(14)").val();
			var maxAmt7 =$(this).find("input:eq(15)").val();
			var maxAmt8 =$(this).find("input:eq(16)").val();
			var maxAmt9 =$(this).find("input:eq(17)").val();
			
			var maxAmt10 =$(this).find("input:eq(18)").val();
			var maxAmt11 =$(this).find("input:eq(19)").val();
			var maxAmt12 =$(this).find("input:eq(20)").val();
			var maxAmt13 =$(this).find("input:eq(21)").val();
			var maxAmt14 =$(this).find("input:eq(22)").val();
			var maxAmt15 =$(this).find("input:eq(23)").val();
			changeStr +='{"id":"'+id+'","roleId":"'+roleId+'","name":"资金","status":"1","type":"AMOUNT","dieMaxAmt":"'+dieMaxAmt+'","deformityMaxAmt":"'+deformityMaxAmt+
			'","seriousIllnessMaxAmt":"'+seriousIllnessMaxAmt+'","outpatientMaxAmt":"'+outpatientMaxAmt+'","inHospitalMedicalMaxAmt":"'+inHospitalMedicalMaxAmt+
			'","inHospitalSubsidyMaxAmt":"'+inHospitalSubsidyMaxAmt+'","accommodationMaxAmt":"'+accommodationMaxAmt+'","settlementMaxAmt":"'+settlementMaxAmt+'","maxAmt1":"'+maxAmt1+'","maxAmt2":"'+maxAmt2+'","maxAmt3":"'+maxAmt3+'","maxAmt4":"'+maxAmt4+'","maxAmt5":"'+maxAmt5+'","maxAmt6":"'+maxAmt6+'","maxAmt7":"'+maxAmt7+'","maxAmt8":"'+maxAmt8+'","maxAmt9":"'+maxAmt9+'","maxAmt10":"'+maxAmt10+'","maxAmt11":"'+maxAmt11+'","maxAmt12":"'+maxAmt12+'","maxAmt13":"'+maxAmt13+'","maxAmt14":"'+maxAmt14+'","maxAmt15":"'+maxAmt15+
			'"},';
		}
		
	});
	if(changeStr ==''){
		alert("没有做修改，无需保存");
		return;
	}
	changeStr = "["+changeStr.substring(0,changeStr.length-1)+"]";
	jsonStr = '{"ids":"","resource":' + changeStr+'}';
	$.ajax({
		 type: "POST", 
		 contentType:"application/json; charset=UTF-8",
	     url: "saveAuditRight.do",
	     data:jsonStr,
	     dataType:"json",
	     success:function(data){
	    	 alert("保存成功");
	    	 SkipByPost("auditRightSet.do","");
	     },
	     error:function(data){
	    	alert(data) ;
	     }
	});
	
}
function isNull(a){
	if(a==null){
		return 0;
	}else{
		return a;
	}
}
