//数字转大写
function Chinese(num){     
    if(!/^\d*(\.\d*)?$/.test(num))throw(new Error(-1, "Number is wrong!"));     
    var AA = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");     
    var BB = new Array("","拾","佰","仟","萬","億","圆","");     
    var CC = new Array("角", "分", "厘");     
    var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";     
    for(var i=a[0].length-1; i>=0; i--){     
        switch(k){     
            case 0 : re = BB[7] + re; break;     
            case 4 : if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0]))     
                         re = BB[4] + re; break;     
            case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;     
        }     
        if(k%4 == 2 && a[0].charAt(i)=="0" && a[0].charAt(i+2) != "0") re = AA[0] + re;     
        if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;     
    }     
    if(a.length>1){     
        re += BB[6];     
        for(var i=0; i<a[1].length; i++){     
            re += AA[a[1].charAt(i)] + CC[i];     
            if(i==2) break;     
        }   
//        if(a[1].charAt(0)=="0" && a[1].charAt(1)=="0"){  
//          re+="圆整";  
//        }    
    }
    else{  
        re+="圆";  
    }     
    return re;     
} 

//数字输入控制并转成大写
function clearNoNum(obj){
  obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
  obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.  
  obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
  obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
  obj.value=obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数  
  $("#chsPayAmt").val('');
  $("#chsPayAmt").val(Chinese(obj.value));
}  
 
//拼接中国格式时间
$(function(){	
	var a=$("#ch").val();
	$("#chinese").val(Chinese(a));
	$("#china").val(Chinese(a));
 	var now1 = new Date();
   var   year=now1.getYear(); 
   if(year<=1900){
   	year=year+1900;
   }
   var   month=now1.getMonth()+1;     
   var   date=now1.getDate();      
   var time =  year+"年"+month+"月"+date+"日";    
   
   $("#time").val(time);
   $("#time1").val(time);
   $("#time2").val(time);
   
     $("#saveAdjustmentNotiice").click(function(){
    	 aa();
     });
    
     
});

function aa(){
	$.ajax({
		type:"POST",
		url:"<%=request.getContextPath()%>/claim/notice/noticP0000013.do",
		data:"",
		error :function(){
			alert("系统错误，请稍后再试。");
		},
		success :function(data){
			if(data=="00"){
				alert("保存通知书成功。");
			}else{
				alert("保存通知书失败。");
			}
		}
	 });	
}

function paramsP0000013(data){
	var companyName=$("#P0000013companyNameTitle").html();
	companyName=companyName.replace("太保安联健康保险股份有限公司",data.companyName);
	$("#P0000013companyNameTitle").html(companyName);
	
	var companyNametwo=$("#P0000013companyNameBottom").html();
	if(companyNametwo!=''&&companyNametwo!=undefined){
		companyNametwo=companyNametwo.replace("太保安联健康保险股份有限公司",data.companyName);
	}
	$("#P0000013companyNameBottom").html(companyNametwo);

	
	
	
	 $("#iName").val(data.insureName);
	 $("#Name").val(data.appName);
	var idTypeName= checkIdType(data.idType);
//	 if(data.idType=='a'){
//		 $("#idtype").val("身份证");
//	 }
	 $("#idtype").val(idTypeName);
	 $("#pid").val(data.idCode );
	 $("#cNo").val(data.claimNo);
	 $("#regDate").val(data.regDate);
	 if(data.offsetCount != null ){
		 $("#offsetcount").val(data.offsetCount);
	 }else{
		 $("#offsetcount").val("0");
	 }
	 $("#offset").html("");
	 if(data!=null){
		 
		 if(data.offsets != null&&data.offsets!=""){
			 for(var j=0;j<data.offsets.length;j++){
				 $("#offset").append("<tr class='tzs_tab_li'><td>"+data.offsets[j].invoiceno+"<input type='hidden' value='"+data.offsets[j].receiptno+"'/></td><td>"+data.offsets[j].visitdate+"</td><td>"+data.offsets[j].amount+"</td><td>"+data.offsets[j].divamt+"</td><td>"+data.offsets[j].ownamt+"</td><td>"+data.offsets[j].deductionsamt+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" value=\""+data.offsets[j].thirdpay+"\" /></td></tr>");
		 }
			 $("#offset").append("<tr class='tzs_tab_li'><td colspan='2' align='center'>合计</td><td>"+data.offsetSum.tamt+"</td><td>"+data.offsetSum.tdivamt+"</td><td>"+data.offsetSum.townamt+"</td><td>"+data.offsetSum.tdeductionsamt+"</td><td>"+data.offsetSum.ttthirdpay+"</td></tr>");
		 }else{
			 $("#offset").append("<tr class='tzs_tab_li'><td height='13px'> </td><td></td><td></td><td></td><td></td><td></td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" /></td></tr>");
		 }
		 if(data.totalDeductAmt!= null ){
			 $("#totalDeductAmt").val(data.totalDeductAmt);
		 }else{
			 $("#totalDeductAmt").val("0.00");
		 }
		
		 $("#drugs").html("");
		 if(data.deducts!= null&&data.deducts!=""){
			 for(var i=0;i<data.deducts.length; i++){
				 $("#drugs").append("<tr class='tzs_tab_li'><td>"+data.deducts[i].receiptno+"<input type='hidden' value='"+data.deducts[i].invoiceno+"'/></td><td>"+data.deducts[i].drugsname+"</td><td>"+data.deducts[i].actualpayment+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" value=\""+data.deducts[i].excludereason+"\" /></td></tr>");
			 }
		 }else{
			 $("#drugs").append("<tr class='tzs_tab_li'><td  height='13px'></td><td></td><td></td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" /></td></tr>");
		 }
		 $("#poltable").html("");
		 if(data.polinfos != null&&data.polinfos!=""){
			 for(var m=0;m<data.polinfos.length; m++){
				 var calculated = data.polinfos[m].calculated;
				 if(calculated==""||calculated==null){
					 calculated="";
				 }
				 $("#poltable").append("<tr class='tzs_tab_li'><td>"+data.polinfos[m].policyno+"</td><td>"+data.polinfos[m].insureName+"<input type='hidden' value='"+data.polinfos[m].insureCode+"'/></td><td>"+data.polinfos[m].dutyname+"<input type='hidden' value='"+data.polinfos[m].delCode+"-"+data.polinfos[m].typeNo+"'/></td><td>"+data.polinfos[m].feeamt+"</td><td>"+data.polinfos[m].payratio+"</td><td>"+data.polinfos[m].payamt+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:42px;\" value=\""+calculated+"\" /></td></tr>");
			 }
		 }else{
			 $("#poltable").append("<tr class='tzs_tab_li'><td  height='13px'></td><td></td><td></td><td></td><td></td><td></td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" /></td></tr>");
		 }
		 
		
		 $("#fysum").val(data.offsettotalPayAmt);
		 if(data.compensatereceiptcount!= null){
			 $("#zysize").val(data.compensatereceiptcount);
		 }else{
			 $("#zysize").val("0");
		 }
		
		 $("#asi").html("");
		 if(data.compensates!=null&&data.compensates!=""){
			 for(var n=0;n<data.compensates.length; n++){
				 $("#asi").append("<tr class='tzs_tab_li'><td>"+data.compensates[n].receiptno+"</td><td>"+data.compensates[n].admissiondate+"</td><td>"+data.compensates[n].dischargedate+"</td><td>"+data.compensates[n].hospdays+"</td><td>"+data.compensates[n].deductionrdays+"</td><td><input type=\"text\" id=\"calculated\" style=\"width:120px;border:none;background:none;padding:0;height:42px;\" value=\""+data.compensates[n].deductionreason+"\" /></td></tr>");
			 }
		 }else{
			 $("#asi").append("<tr class='tzs_tab_li'><td  height='13px'></td><td></td><td></td><td></td><td></td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" /></td></tr>");
		 }
		
		 
		 $("#btsum").val(data.dePayAmt);
		 $("#aps").html(""); if(data.depolinfos!= null && data.depolinfos!=""){
			 for ( var j = 0; j < data.depolinfos.length; j++) {
				 var apsCalculated = data.depolinfos[j].calculated;
				 if(apsCalculated==""||apsCalculated==null){
					 apsCalculated="";
				 }
				 $("#aps").append("<tr class='tr'>"+"<td>"+data.depolinfos[j].policyno+"</td>"+"<td>"+data.depolinfos[j].insureName+"</td>"+"<td>"+data.depolinfos[j].dutyname+"</td>"+"<td>"+data.depolinfos[j].subsidyamt+"</td>"+"<td>"+data.depolinfos[j].freedays+"</td>"+"<td>"+data.depolinfos[j].payamt+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:42px;\" value=\""+apsCalculated+"\" /></td>"+"</tr>");
			 } 
		 }else{
			 $("#aps").append("<tr class='tzs_tab_li'><td  height='13px'></td><td></td><td></td><td></td><td></td><td></td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" /></td></tr>");
		 }
		
		 $("#deltotalhospdays").html(data.deltotalhospdays);
		 $("#fycountmoney").html(data.offsettotalPayAmt);
		 $("#detotalamt").html(data.dePayAmt);
		 $("#allmoney").html(data.totalPayAmt);
		 
		 $("#fgsmcp13").val(data.orgName);
		 $("#p0000013InfoTel").val(data.infoTel);
		 var now1 = new Date();
		   var   year=now1.getYear(); 
		   if(year<=1900){
		   	year=year+1900;
		   }
		   var   month=now1.getMonth()+1;     
		   var   date=now1.getDate();      
		   var time =  year+"年"+month+"月"+date+"日";   
		   $("#time2").val(time);
	 }
}


function paramsP0000021(data){
	var companyName=$("#P0000021companyNameTitle").html();
	companyName=companyName.replace("太保安联健康保险股份有限公司",data.companyName);
	$("#P0000021companyNameTitle").html(companyName);
	
	var companyNametwo=$("#P0000021companyNameBottom").html();
	if(companyNametwo!=''&&companyNametwo!=undefined){
		companyNametwo=companyNametwo.replace("太保安联健康保险股份有限公司",data.companyName);
	}
	$("#P0000021companyNameBottom").html(companyNametwo);	
	$("#policyCompany1").val(data.policyCompanyName);
	$("#iiName1").val(data.bankholdname);
	$("#bankname1").val(data.bankname);
	$("#acctnum1").val(data.acctnum);
	$("#applicantNameP21").val(data.policyCompanyName);
	 $("#iName1").val(data.insureName);
	 $("#name1").val(data.appName);
	 $("#iName2").val(data.insureName);
	 $("#pid2").val(data.idCode);
	 $("#irelationship").val("本人");
	var idTypeName= checkIdType(data.idType);
//	 if(data.idType=='a'){
//		 $("#idtype").val("身份证");
//	 }
	 $("#idtype").val(idTypeName);
	 $("#pid1").val(data.idCode );
	 $("#cNo1").val(data.claimNo);
	 $("#claimNoHid").val(data.cNo);
	 $("#cDate1").val(data.applyDate);
	 $("#bcxbody1").html("");
	 if(data!=null){
		 if(data.offsets != null&&data.offsets!=""){
			
			 for(var j=0;j<data.offsets.length;j++){
				 $("#bcxbody1").append("<tr class='tzs_tab_li'><td>"+data.offsets[j].visitdate+"</td><td>"+data.offsets[j].invoiceno+"<input type='hidden' value='"+data.offsets[j].receiptno+"'/></td><td>"+data.offsets[j].visithospital+"</td><td>"+data.offsets[j].amount+"</td><td>"+data.offsets[j].ownamt+"</td><td>"+data.offsets[j].divamt+"</td><td>"+data.offsets[j].medIns+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" value=\""+data.offsets[j].thirdpay+"\" /></td><td>"+data.offsets[j].deductionsamt+"</td></tr>");/*<td><input type=\"hidden\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" value=\""+(data.offsets[j].excludereason == null ?"" : data.offsets[j].excludereason)+"\" /></td>
*/				 
			 }
			 $("#bcxbody1").append("<tr class='tzs_tab_li'><td colspan='3' align='center'>合计</td><td>"+data.offsetSum.tamt+"</td><td>"+data.offsetSum.townamt+"</td><td>"+data.offsetSum.tdivamt+"</td><td>"+data.offsetSum.tmedIns+"</td><td>"+data.offsetSum.ttthirdpay+"</td><td>"+data.offsetSum.tdeductionsamt+"</td></tr>");
			 
			 //明细附表
			 var ownDetail ="";
			 var divDetail ="";
			 var deductionsDetail ="";
			 //自费扣减说明
			 var ownExcReason ="";
			 //分类扣减说明
			 var divExcReason ="";
			 //免责扣减说明
			 var deductionsExcReason ="";
			 if(data.offsets != null && data.offsets !=""){
				 for(var j=0;j<data.offsets.length;j++){
					 ownDetail += data.offsets[j].ownDetail + '<br>';
					 divDetail += data.offsets[j].divDetail + '<br>';
					 deductionsDetail += data.offsets[j].deductionsDetail + '<br>';
					 if(ownExcReason ==""){
						 ownExcReason = data.offsets[j].ownExcReason == null ?"" : data.offsets[j].ownExcReason;
					 }
					 if(divExcReason ==""){
						 divExcReason = data.offsets[j].divExcReason == null ?"" : data.offsets[j].divExcReason;
					 }
					 if(deductionsExcReason ==""){
						 deductionsExcReason = data.offsets[j].deductionsExcReason == null ?"" : data.offsets[j].deductionsExcReason;
					 }
					 
				 }
			 }
			 $("#ownDetailTD1").html(ownDetail);
			 $("#ownExcReasonTD1").html("<input type=\"text\" id=\"ownExcReasonID1\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" value=\""+ownExcReason+"\" /></td>");
			 $("#divDetailTD1").html(divDetail);
			 $("#divExcReasonTD1").html("<input type=\"text\" id=\"divExcReasonID1\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" value=\""+divExcReason+"\" /></td>");
			 $("#deductionsDetailTD1").html(deductionsDetail);
			 $("#deductionsExcReasonTD1").html("<input type=\"text\" id=\"deductionsExcReasonID1\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" value=\""+deductionsExcReason+"\" /></td>");

		 }else{
			$("#buchangxing").hide();
			$("#mingxifubiao").hide();
		 }
		
		 $("#bcxpfbody1").html("");
		 if(data.polinfos != null&&data.polinfos!=""){
			 for(var m=0;m<data.polinfos.length; m++){
				 var calculated = data.polinfos[m].calculated;
				 if(calculated==""||calculated==null){
					 calculated="";
				 }
				 $("#bcxpfbody1").append("<tr class='tzs_tab_li'><td>"+data.polinfos[m].policyno+"</td><td>"+data.polinfos[m].insureName+"<input type='hidden' value='"+data.polinfos[m].insureCode+"'/></td><td>"+data.polinfos[m].dutyname+"<input type='hidden' value='"+data.polinfos[m].delCode+"-"+data.polinfos[m].typeNo+"'/></td><td>"+data.polinfos[m].timefeeamt+"</td><td>"+data.polinfos[m].yearfeeamt+"</td><td>"+data.polinfos[m].payratio+"</td><td>"+data.polinfos[m].payamt+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:42px;\" value=\""+calculated+"\" /></td><td>"+data.polinfos[m].totalpayAmt+"</td></tr>");
			 }
		 }else{
			 $("#bcxpfbody1").append("<tr class='tzs_tab_li'><td  height='13px'></td><td></td><td></td><td></td><td></td><td></td><td></td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" /></td><td></td></tr>");
		 }
		 
		 $("#btxbody1").html("");
		 if(data.compensates!=null&&data.compensates!=""){
			 for(var n=0;n<data.compensates.length; n++){
				 $("#btxbody1").append("<tr class='tzs_tab_li'><td>"+data.compensates[n].admissiondate+"<input type='hidden' value='"+data.compensates[n].receiptno+"'/></td><td>"+data.compensates[n].dischargedate+"</td><td>"+data.compensates[n].hospdays+"</td><td>"+data.compensates[n].deductionrdays+"</td><td><input type=\"text\" id=\"calculated\" style=\"width:120px;border:none;background:none;padding:0;height:42px;\" value=\""+data.compensates[n].deductionreason+"\" /></td></tr>");
			 }
		 }else{
			 $("#butiexing").hide();
		 }
		
		 $("#btxpfbody1").html(""); 
		 if(data.depolinfos!= null && data.depolinfos!=""){
			 for ( var j = 0; j < data.depolinfos.length; j++) {
				 var apsCalculated = data.depolinfos[j].calculated;
				 var freeday = data.depolinfos[j].freedays;
				 if(apsCalculated==""||apsCalculated==null){
					 apsCalculated="";
				 }
				 if(freeday==""||freeday==null){
					 freeday="";
				 }
				 $("#btxpfbody1").append("<tr class='tr'>"+"<td>"+data.depolinfos[j].policyno+"</td>"+"<td>"+data.depolinfos[j].insureName+"</td>"+"<td>"+data.depolinfos[j].dutyname+"</td>"+"<td>"+data.depolinfos[j].subsidyamt+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:42px;\" value=\""+freeday+"\" /></td>"+"<td>"+data.depolinfos[j].payamt+"</td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:42px;\" value=\""+apsCalculated+"\" /></td>"+"</tr>");
			 } 
		 }else{
			 $("#btxpfbody1").append("<tr class='tzs_tab_li'><td  height='13px'></td><td></td><td></td><td></td><td></td><td></td><td><input type=\"text\" style=\"width:120px;border:none;background:none;padding:0;height:22px;\" /></td></tr>");
		 }
		 
		 
		 $("#qtxzbody1").html("");
		 if(data.otherpolinfos !=null && data.otherpolinfos!=""){
			 for ( var j = 0; j < data.otherpolinfos.length; j++) {
				 $("#qtxzbody1").append("<tr class='tr'>"+"<td>"+data.otherpolinfos[j].policyno+"</td>"+"<td>"+data.otherpolinfos[j].insureName+"</td>"+"<td>"+data.otherpolinfos[j].dutyname+"</td>"+"<td>"+data.otherpolinfos[j].totalPrem+"</td>"+"<td>"+data.otherpolinfos[j].patAmt+"</td>"+"<td>"+data.otherpolinfos[j].totalpayAmt+"</td><td>"+data.otherpolinfos[j].remainPrem+"</td>"+"</tr>");
			 } 
		 }else{
			 $("#qitaxianzhong").hide();
		 }
		
		// $("#deltotalhospdays").html(data.deltotalhospdays);
		 //$("#fycountmoney").html(data.offsettotalPayAmt);
		 //$("#detotalamt").html(data.dePayAmt);
		 $("#allmoney1").html(data.totalPayAmt);
		 $("#allmoneyCH1").html(data.totalCHPayAmt);
		 
		 $("#fgsmc1").val(data.orgName);
		 
		var now1 = new Date();
		   var   year=now1.getYear(); 
		   if(year<=1900){
		   	year=year+1900;
		   }
		   var   month=now1.getMonth()+1;     
		   var   date=now1.getDate();      
		   var time =  year+"年"+month+"月"+date+"日";   
		   $("#time2New").val(time);
	 }
}


function saveP0000013(){
	
	/*$("#saveP0000013").attr("onclick","");*/
	var iName = $("#iName").val();
	var Name = $("#Name").val();
	var idtype = $("#idtype").val();
	var pid = $("#pid").val();
	var cNo = $("#cNo").val();
	var regDate = $("#regDate").val();

	//遍历table1
	var plusString="";
	$("#offset").find("tr").each(function(){
		var tds=this.childNodes;
		var first=tds[0].outerText;
		var receiptno=$(tds[0]).find("input:eq(0)").val();
		if(first!="合计"){
			var lastObj=tds[tds.length-1].childNodes[0];
			var last=lastObj.value;
			if(tds.length-1==1){
				plusString+="{\"receiptno\":\""+receiptno+"\",\"thirdpay\":\""+checkSpecialFn(last)+"\"}";
			}else{
				plusString+="{\"receiptno\":\""+receiptno+"\",\"thirdpay\":\""+checkSpecialFn(last)+"\"},";
			}
		}
	});
	if(plusString.lastIndexOf(",")==plusString.length-1){
		plusString=plusString.substring(0,plusString.length-1);
	}
	var jsonString="["+plusString+"]";
	
	//遍历table2
	var plusString2="";
	$("#drugs").find("tr").each(function(){
		var tds2=this.childNodes;
		var first2=tds2[0].outerText;
		var receiptno2=$(tds2[0]).find("input:eq(0)").val();
		if(first2!="合计"){
			var lastObj2=tds2[tds2.length-1].childNodes[0];
			var last2=lastObj2.value;
			var itemAmt=tds2[1].outerText;
			
			if(tds2.length-1==1){
			plusString2+="{\"receiptNo2\":\""+receiptno2+"\",\"itemAmt\":\""+itemAmt+"\",\"deductionDes\":\""+checkSpecialFn(last2)+"\"}";
			}else{
				plusString2+="{\"receiptNo2\":\""+receiptno2+"\",\"itemAmt\":\""+itemAmt+"\",\"deductionDes\":\""+checkSpecialFn(last2)+"\"},";
				
			}
		}
	});

	if(plusString2.lastIndexOf(",")==plusString2.length-1){
		plusString2=plusString2.substring(0,plusString2.length-1);
	}
	var jsonString2="["+plusString2+"]";
	
	//遍历table3
	var plusString3="";
	$("#poltable").find("tr").each(function(){
		var tds3=this.childNodes;
		var first3=tds3[0].outerText;
		var second3=tds3[1].outerText;
		var third3=tds3[2].outerText;
		var fif3=$(tds3[4]).find("input:eq(0)").val();
		var classCode=$(tds3[1]).find("input:eq(0)").val();
		var delCodeTypeNo=$(tds3[2]).find("input:eq(0)").val();
		
		if(fif3==null || fif3==undefined || fif3=="null"){
			fif3=tds3[4].outerText;
		}
		if(first3!="合计"){
			var lastObj3=tds3[tds3.length-1].childNodes[0];
			var last3=lastObj3.value;
			if(tds3.length-1==1){
				
				plusString3+="{\"policyNo\":\""+first3+"\",\"classCodeName\":\""+second3+"\",\"delCode\":\""+third3+"\",\"prefunId\":\""+last3+"\",\"payRatio\":\""+fif3+"\",\"classCode\":\""+classCode+"\",\"delCodeTypeNo\":\""+delCodeTypeNo+"\"}";
			}else{
				plusString3+="{\"policyNo\":\""+first3+"\",\"classCodeName\":\""+second3+"\",\"delCode\":\""+third3+"\",\"prefunId\":\""+last3+"\",\"payRatio\":\""+fif3+"\",\"classCode\":\""+classCode+"\",\"delCodeTypeNo\":\""+delCodeTypeNo+"\"},";
			}
		}
	});

	if(plusString3.lastIndexOf(",")==plusString3.length-1){
		plusString3=plusString3.substring(0,plusString3.length-1);
	}
	var jsonString3="["+plusString3+"]";
	
	
	
	//遍历table4
	var plusString4="";
	$("#asi").find("tr").each(function(){
		var tds4=this.childNodes;
		var first4=tds4[0].outerText;
		var second4=tds4[1].outerText;
		var third4=tds4[2].outerText;
		if(first4!="合计"){
			var lastObj4=tds4[tds4.length-1].childNodes[0];
			var last4=lastObj4.value;
			if(tds4.length-1==1){
			plusString4+="{\"receiptNo4\":\""+first4+"\",\"admissionDate\":\""+second4+"\",\"dischargeDate\":\""+third4+"\",\"deductionReason4\":\""+last4+"\"}";
			}else{
				plusString4+="{\"receiptNo4\":\""+first4+"\",\"admissionDate\":\""+second4+"\",\"dischargeDate\":\""+third4+"\",\"deductionReason4\":\""+last4+"\"},";
			}
		}
	});

	if(plusString4.lastIndexOf(",")==plusString4.length-1){
		plusString4=plusString4.substring(0,plusString4.length-1);
	}
	var jsonString4="["+plusString4+"]";
	
	
	//遍历table5
	var plusString5="";
	$("#aps").find("tr").each(function(){
		var tds5=this.childNodes;
		var first5=tds5[0].outerText;
		var second5=tds5[1].outerText;
		var third5=tds5[2].outerText;
		if(first5!="合计"){
			var lastObj5=tds5[tds5.length-1].childNodes[0];
			var last5=lastObj5.value;
			if(tds5.length-1==1){
			plusString5+="{\"policyNo5\":\""+first5+"\",\"classCodeName5\":\""+second5+"\",\"delCode5\":\""+third5+"\",\"prefunId5\":\""+last5+"\"}";
			}else{
				plusString5+="{\"policyNo5\":\""+first5+"\",\"classCodeName5\":\""+second5+"\",\"delCode5\":\""+third5+"\",\"prefunId5\":\""+last5+"\"},";
			}
		}
	});

	if(plusString5.lastIndexOf(",")==plusString5.length-1){
		plusString5=plusString5.substring(0,plusString5.length-1);
	}
	var jsonString5="["+plusString5+"]";
	
	var infoTel=$("#p0000013InfoTel").val();
	$("#saveP0000013").attr("onclick","");
	$.ajax({
		type:"POST",
		url:"/claimserver/claim/notice/saveP0000013Edit.do",
		data:{"iName":iName,"Name":Name,"idtype":idtype,"pid":pid,"cNo":cNo,"regDate":regDate,"jsonString":jsonString,"jsonString2":jsonString2,"jsonString3":jsonString3,"jsonString4":jsonString4,"jsonString5":jsonString5,"infoTel":infoTel},
		error:function(){
			alert("保存失败");
		},
		success:function(data){
			if(data.message="success"){
				alert("保存成功!");
			}else{
				alert("保存失败!");
			}
		}
	});
}

function saveP0000021(){
	
	/*$("#saveP0000021").attr("onclick","");*/
	var iName = $("#iName1").val();
	var Name = $("#name1").val();
	var idtype = $("#idtype").val();
	var pid = $("#pid1").val();
	var cNo = $("#claimNoHid").val();
	var regDate = $("#cDate1").val();

	//遍历table1
	var plusString="";
	$("#bcxbody1").find("tr").each(function(i){
		var tds=this.childNodes;
		var first = $(this).find("td:eq(0)").text();
		if(first!="合计"){
			var lastObj=tds[tds.length-1].childNodes[0];
			var last=lastObj.value;
			var receiptno=$(tds[1]).find("input:eq(0)").val();
			var thirdpay = $(tds[7]).find("input:eq(0)").val();
			if(tds.length-1==1){
				plusString+="{\"receiptno\":\""+receiptno+"\",\"thirdpay\":\""+checkSpecialFn(thirdpay)+"\",\"excludereason\":\"\"}";
			}else{
				plusString+="{\"receiptno\":\""+receiptno+"\",\"thirdpay\":\""+checkSpecialFn(thirdpay)+"\",\"excludereason\":\"\"},";
			}
		}
	});
	if(plusString.lastIndexOf(",")==plusString.length-1){
		plusString=plusString.substring(0,plusString.length-1);
	}
	var jsonString="["+plusString+"]";
	
	//遍历table3
	var plusString3="";
	$("#bcxpfbody1").find("tr").each(function(){
		var tds3=this.childNodes;
		var first3=tds3[0].outerText;
		var second3=tds3[1].outerText;
		var third3=tds3[2].outerText;
		var fif3=$(tds3[5]).find("input:eq(0)").val();
		var classCode=$(tds3[1]).find("input:eq(0)").val();
		var delCodeTypeNo=$(tds3[2]).find("input:eq(0)").val();
		
		if(fif3==null || fif3==undefined || fif3=="null"){
			fif3=tds3[5].outerText;
		}
		if(first3!="合计"){
			var lastObj3=tds3[tds3.length-2].childNodes[0];
			var last3=lastObj3.value;
			if(tds3.length-1==1){
				
			plusString3+="{\"policyNo\":\""+first3+"\",\"classCodeName\":\""+second3+"\",\"delCode\":\""+third3+"\",\"prefunId\":\""+last3+"\",\"payRatio\":\""+fif3+"\",\"classCode\":\""+classCode+"\",\"delCodeTypeNo\":\""+delCodeTypeNo+"\"}";
			}else{
				plusString3+="{\"policyNo\":\""+first3+"\",\"classCodeName\":\""+second3+"\",\"delCode\":\""+third3+"\",\"prefunId\":\""+last3+"\",\"payRatio\":\""+fif3+"\",\"classCode\":\""+classCode+"\",\"delCodeTypeNo\":\""+delCodeTypeNo+"\"},";
			}
		}
	});

	if(plusString3.lastIndexOf(",")==plusString3.length-1){
		plusString3=plusString3.substring(0,plusString3.length-1);
	}
	var jsonString3="["+plusString3+"]";
	
	
	
	//遍历table4
	var plusString4="";
	$("#btxbody1").find("tr").each(function(){
		var tds4=this.childNodes;
		var first4=$(tds4[0]).find("input:eq(0)").val();
		var second4=tds4[0].outerText;
		var third4=tds4[1].outerText;
		if(first4!="合计"){
			var lastObj4=tds4[tds4.length-1].childNodes[0];
			var last4=lastObj4.value;
			if(tds4.length-1==1){
				plusString4+="{\"receiptNo4\":\""+first4+"\",\"admissionDate\":\""+second4+"\",\"dischargeDate\":\""+third4+"\",\"deductionReason4\":\""+last4+"\"}";
			}else{
				plusString4+="{\"receiptNo4\":\""+first4+"\",\"admissionDate\":\""+second4+"\",\"dischargeDate\":\""+third4+"\",\"deductionReason4\":\""+last4+"\"},";
			}
		}
	});

	if(plusString4.lastIndexOf(",")==plusString4.length-1){
		plusString4=plusString4.substring(0,plusString4.length-1);
	}
	var jsonString4="["+plusString4+"]";
	
	
	//遍历table5
	var plusString5="";
	$("#btxpfbody1").find("tr").each(function(){
		var tds5=this.childNodes;
		var first5=tds5[0].outerText;
		var second5=tds5[1].outerText;
		var third5=tds5[2].outerText;
		var mpeiday5=$(tds5[4]).find("input:eq(0)").val();
		if(first5!="合计"){
			var lastObj5=tds5[tds5.length-1].childNodes[0];
			var last5=lastObj5.value;
			if(tds5.length-1==1){
				plusString5+="{\"policyNo5\":\""+first5+"\",\"classCodeName5\":\""+second5+"\",\"delCode5\":\""+third5+"\",\"prefunId5\":\""+last5+"\",\"mpeiday5\":\""+mpeiday5+"\"}";
			}else{
				plusString5+="{\"policyNo5\":\""+first5+"\",\"classCodeName5\":\""+second5+"\",\"delCode5\":\""+third5+"\",\"prefunId5\":\""+last5+"\",\"mpeiday5\":\""+mpeiday5+"\"},";
			}
		}
	});

	if(plusString5.lastIndexOf(",")==plusString5.length-1){
		plusString5=plusString5.substring(0,plusString5.length-1);
	}
	var jsonString5="["+plusString5+"]";
	
	//遍历table6 附表明细
	var jsonString6="[{\"ownExcReason\":\""+$("#ownExcReasonID1").val()+"\",\"divExcReason\":\""+$("#divExcReasonID1").val()+"\",\"deductionsExcReason\":\""+$("#deductionsExcReasonID1").val()+"\"}]";
	
	$('#saveP0000021').removeAttr('onclick');
	$("#saveP0000021").attr("onclick","");
	$.ajax({
		type:"POST",
		url:"/claimserver/claim/notice/saveP0000021Edit.do",
		data:{"iName":iName,"Name":Name,"idtype":idtype,"pid":pid,"cNo":cNo,"regDate":regDate,"jsonString":jsonString,"jsonString3":jsonString3,"jsonString4":jsonString4,"jsonString5":jsonString5,"jsonString6":jsonString6},
		error:function(){
			alert("保存失败");
		},
		success:function(data){
			if(data.message="success"){
				alert("保存成功!");
			}else{
				alert("保存失败!");
			}
		}
	});
}

function printP0000013(){
	var haveEmail = $("#haveEmail").val();
	var isMail = $("#isMail").val();
	if (isMail == 'Y') {
		if (haveEmail == 'Y') {
			if (!confirm("客户选择电子邮件方式接收，是否继续打印？")) {
				return;
			}
		} else if (haveEmail == 'N') {
			if (!confirm("客户选择电子邮件方式接收，但邮箱地址为空，是否继续打印？")) {
				return;
			}
		}
	}
//	if(haveEmail == 'Y'){
//		if(!confirm("客户选择电子邮件方式接收，是否继续打印？")){
//			return ;
//		}
//	}else if(haveEmail == 'N'){
//		if(!confirm("客户选择电子邮件方式接收，但邮箱地址为空，是否继续打印？")){
//			return ;
//		}
//	}
	var objId = $("#cNo").val();
	var infoTel=$("#p0000013InfoTel").val();
	if(objId==null||objId==""){
		alert("没有获取到打印信息。");
		return;
	}
	$.ajax({
		type:"POST",
		url:"/claimserver/claim/notice/printP0000013Info.do",
		data:{"objId":objId,"infoTel":infoTel},
		error :function(){
			alert("系统错误，请稍后再试。");
		},
		success :function(data){
			if(data=="00"){
				alert("打印通知书成功。");
			}else{
				alert("打印通知书失败。");
			}
		}
	});
}

function printP0000021(){
	var haveEmail = $("#haveEmail").val();
	var isMail = $("#isMail").val();
	if (isMail == 'Y') {
		if (haveEmail == 'Y') {
			if (!confirm("客户选择电子邮件方式接收，是否继续打印？")) {
				return;
			}
		} else if (haveEmail == 'N') {
			if (!confirm("客户选择电子邮件方式接收，但邮箱地址为空，是否继续打印？")) {
				return;
			}
		}
	}
//	if(haveEmail == 'Y'){
//		if(!confirm("客户选择电子邮件方式接收，是否继续打印？")){
//			return ;
//		}
//	}else if(haveEmail == 'N'){
//		if(!confirm("客户选择电子邮件方式接收，但邮箱地址为空，是否继续打印？")){
//			return ;
//		}
//	}
	var objId = $("#claimNoHid").val();
	if(objId==null||objId==""){
		alert("没有获取到打印信息。");
		return;
	}
	$('#printP0000021').removeAttr('onclick');
	$.ajax({
		type:"POST",
		url:"/claimserver/claim/notice/printP0000021Info.do",
		data:{"objId":objId},
		error :function(){
			alert("系统错误，请稍后再试。");
		},
		success :function(data){
			if(data=="00"){
				alert("打印通知书成功。");
			}else{
				alert("打印通知书失败。");
			}
		}
	});
}

function checkIdType(idType){
	var reStr="";
	var type=["a","c","d","j","l"];
	var name=["身份证","护照","军官证","港澳台护照","台湾居民通行证"];
	for ( var i = 0; i < type.length; i++) {
		if(idType==type[i]){
			reStr=name[i];
			break ;
		}
	}
	return reStr;
	
}

function checkNum(flag){
	if($(flag).val()!=null && $(flag).val()!="null" && $(flag).val()!="" && $(flag).val()!=undefined){
		if(!isNaN($(flag).val())){
			var payratio=$(flag).val()*1;
			if(!/^(\d{1,2}|100)$/.test(payratio)){
				alert("请输入0-100之间的正整数！");
				$(flag).val("");
			}else{
				$(flag).val(payratio);
			}
		}else{
			alert("请输入0-100之间的正整数！");
			$(flag).val("");
		}
		
	}
	
}

function checkSpecialFn(flag){
	if(flag!=undefined&&flag!=''&&flag!=null){
		var enchar=["\'","\""];
		var cnchar=["’","”"];
		for ( var i = 0; i < enchar.length; i++) {
			if(flag.indexOf(enchar[i])!=-1){
				for ( var j = 0; j < flag.length; j++) {
					flag=flag.replace(enchar[i],cnchar[i]);
				}
			}
		}
	}
	return flag;
} 