 var index = 0;
 var otherIndex=0;
 var moneyIndex = 0;
 var medicalIndex=0;
$(function(){
	if($("#isBpo").val()=="Y"){
		saveTrAfter();
		saveOtherTrAfter();
		sumMoney('');
	}
	//高端可输入次数
	var itemCode1 = $("#billDetailTable").find("tr[id='000026']").find("INPUT[id='treatmentTime']");
	itemCode1.removeAttr("readOnly");
	var itemCode2 = $("#billDetailTable").find("tr[id='000027']").find("INPUT[id='treatmentTime']");
	itemCode2.removeAttr("readOnly");
	var itemCode3 = $("#billDetailTable").find("tr[id='000051']").find("INPUT[id='treatmentTime']");
	itemCode3.removeAttr("readOnly");
	var itemCode4 = $("#billDetailTable").find("tr[id='000053']").find("INPUT[id='treatmentTime']");
	itemCode4.removeAttr("readOnly");
	var itemCode5 = $("#billDetailTable").find("tr[id='000054']").find("INPUT[id='treatmentTime']");
	itemCode5.removeAttr("readOnly");
	var itemCode6 = $("#billDetailTable").find("tr[id='000056']").find("INPUT[id='treatmentTime']");
	itemCode6.removeAttr("readOnly");
	var itemCode7 = $("#billDetailTable").find("tr[id='000057']").find("INPUT[id='treatmentTime']");
	itemCode7.removeAttr("readOnly");
	var itemCode8 = $("#billDetailTable").find("tr[id='000065']").find("INPUT[id='treatmentTime']");
	itemCode8.removeAttr("readOnly");
	var itemCode9 = $("#billDetailTable").find("tr[id='000073']").find("INPUT[id='treatmentTime']");
	itemCode9.removeAttr("readOnly");
});

//function checkYesNoRe(obj,is,index){
//	//var actualPayment_h=actualPayment;		//剔除记录的发生金额
//	//var ownCostAmt_h=ownCostAmt;			//剔除记录的自付金额
//	var deductionsAmtSum_h=$("#deductionsAmtSum").val();								//免责扣款
//	var ownAmtSum_h=$("#ownAmtSum").val();											//自费金额
//	var divAmtSum_h=$("#divAmtSum").val();											//分类自付
//	
//	var actualPayment=$($("#rcptDrugsTbl [name=actualPayment]")[index]).val();		//剔除记录的发生金额
//	var ownCostAmt=$($("#rcptDrugsTbl [name=ownCostAmt]")[index]).val();			//剔除记录的自付金额
//	var deductionsAmtSum=$("#deductionsAmtSum").val();								//免责扣款
//	var ownAmtSum=$("#ownAmtSum").val();											//自费金额
//	var divAmtSum=$("#divAmtSum").val();											//分类自付
//	
//	if($(obj).hasClass("check_no")){
//		//若明细中勾选剔除，免责扣款=剔除记录的发生金额
//		$("#deductionsAmtSum").val(is);
//		//若自付金额=发生金额，自费金额=原自费金额-剔除记录的自付金额；
//		if(ownCostAmt==actualPayment){
//			$("#ownAmtSum").val($("#ownAmtSum").val()-ownCostAmt);
//		}
//		//若自付金额<发生金额，分类自付=原分类自付-剔除记录的自付金额；
//		if(ownCostAmt<actualPayment){
//			$("#divAmtSum").val($("#divAmtSum").val()-ownCostAmt);
//		}
//	}
//	if($(obj).hasClass("check_yes")){
//		var deductionsAmtSums=$("#deductionsAmtSums").val();
//		
//		$("#deductionsAmtSum").val(deductionsAmtSums);
//		$("#ownAmtSum").val(ownAmtSum_h);
//		$("#divAmtSum").val(divAmtSum_h);
//	}
//}
function checkOthNo(obj,index){
//	alert($(obj).parent().parent().find("input").eq(1).val());
//	明细中勾选剔除，与账单列表的联动关系：
//	若明细中勾选剔除，免责扣款=剔除记录的发生金额，
//	若自付金额=发生金额，自费金额=自费金额-剔除记录的自付金额；
//	若若自付金额<发生金额，分类自付=分类自付-剔除记录的自付金额；
	$("#billDetailTable tr").each(function(){
		var text=$(this).children("td:first").text();
		
		if(text==$(obj).parent().parent().find("input").eq(1).val()){
//			$(this).find("input").eq(1).val();
			
			if($(obj).attr("class")=="check_no"){
				var deductionsAmt=$(this).find("input").eq(5).val();
				var otheractualPayment=$(obj).parent().parent().find("input").eq(3).val();
				var otherownCostSAmt=$(obj).parent().parent().find("input").eq(5).val();
				var ownAmtSum=$("#ownAmtSum").val();
				if(deductionsAmt==""){
					deductionsAmt=0;
				}
				$(this).find("input").eq(5).val(((parseFloat(deductionsAmt)*100+parseFloat(otheractualPayment)*100)/100).toFixed(2));
				$("#deductionsAmtSum").val((parseFloat(otheractualPayment)+parseFloat($("#deductionsAmtSum").val())).toFixed(2));
//				$(this).find("input").eq(5).val($(obj).parent().parent().find("input").eq(3).val());
				if(parseFloat(otheractualPayment)==parseFloat(otherownCostSAmt)){
					var ownAmt = $.trim($(this).find("input").eq(1).val());
					if(ownAmt==""||isNaN(ownAmt)){
						ownAmt=0.0;
					}
					if((parseFloat(ownAmt)*100-parseFloat(otherownCostSAmt)*100)/100<0){
						alert("自费金额不可以小于0");
						$(obj).attr("class","check_yes");
						$(this).find("input").eq(5).val(deductionsAmt);
						return;
					}else{
						$(this).find("input").eq(1).val(((parseFloat(ownAmt)*100-parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
						$("#ownAmtSum").val((parseFloat(ownAmtSum)-parseFloat(otherownCostSAmt)).toFixed(2));
					}
				}
				if(parseFloat(otherownCostSAmt)<parseFloat(otheractualPayment)){
					var divAmt=$(this).find("input").eq(2).val();
					if(divAmt==""||isNaN(divAmt)){
						divAmt=0.0;
					}
					if((parseFloat(divAmt)*100-parseFloat(otherownCostSAmt)*100)/100<0){
						alert("分类自付不可以小于0");
						$(obj).attr("class","check_yes");
						$(this).find("input").eq(5).val(deductionsAmt);
						return;
					}else{
						$(this).find("input").eq(2).val(((parseFloat(divAmt)*100-parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
						$("#divAmtSum").val((parseFloat($("#divAmtSum").val())-parseFloat(otherownCostSAmt)).toFixed(2));
					}
			}
			return;
			}
		if($(obj).attr("class")=="check_yes"){				
			var deductionsAmt=$(this).find("input").eq(5).val();
			var otheractualPayment=$(obj).parent().parent().find("input").eq(3).val();
			var otherownCostSAmt=$(obj).parent().parent().find("input").eq(5).val();
			var ownAmtSum=$("#ownAmtSum").val();
			$(this).find("input").eq(5).val(((parseFloat(deductionsAmt)*100-parseFloat(otheractualPayment)*100)/100).toFixed(2));
			$("#deductionsAmtSum").val((parseFloat(otheractualPayment)-parseFloat($("#deductionsAmtSum").val())).toFixed(2));
				if(parseFloat(otheractualPayment)==parseFloat(otherownCostSAmt)){
					var ownAmt = $.trim($(this).find("input").eq(1).val());
					if(ownAmt==""||isNaN(ownAmt)){
						ownAmt=0.0;
					}
					$(this).find("input").eq(1).val(((parseFloat(ownAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
					$("#ownAmtSum").val(((parseFloat(ownAmtSum)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
				}
				if(parseFloat(otherownCostSAmt)<parseFloat(otheractualPayment)){
					var divAmt=$(this).find("input").eq(2).val();
					if(divAmt==""||isNaN(divAmt)){
						divAmt=0.0;
					}
					$(this).find("input").eq(2).val(((parseFloat(divAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
					$("#divAmtSum").val(((parseFloat($("#divAmtSum").val())*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
			}
			return;
			}
		}
	});
}
function dispatchClaimPage(){
	 $("#claimReceiptForm").attr("action","dispatcherClmInfoByMyTask.do");
	 $("#claimReceiptForm").submit();
}

function dispatcherEventPage(eventNo){
	if(eventNo!=""){
		$("#eventNo").val(eventNo);
	}
	$("#pageFrom").val($(".pageFrom").val());
	$("#claimReceiptForm").attr("action","dispatcherEventPage.do");
	$("#claimReceiptForm").submit();
	
}
function saveReceiptPage(){
	if($("#isBpo").val()=="Y"){
		saveTrAfter();//点击保存前执行清单信息中打勾后的操作
		saveOtherTrAfter();
		sumMoney('');//更新账单信息
//		dValue();
	}
	
	if (null == $("#invoiceNo").val() || undefined == $("#invoiceNo").val() || '' == $("#invoiceNo").val()) {
		alert("发票编号不能为空！");
		return;
	}
	if($.trim($("#spanCurrentcyName").html())!="人民币元"&&$("#exchangeRate").val()==""){
		alert("请填写汇率。");
		return;
	}
	
	if($.trim($("#spanCurrentcyName").html())=="人民币元"){
		$("#exchangeRate").val("1");
	}
    var billAmtSum = 0;
    var totalAmt =  0;
    if (null != $("#billAmtSum").val() && undefined != $("#billAmtSum").val() && '' != $("#billAmtSum").val()) {
    	billAmtSum = parseFloat($("#billAmtSum").val());
    }
    if($("#totalAmt").val()==null || $("#totalAmt").val() == undefined || $("#totalAmt").val()==""){
		alert("请输入收据总金额。");
		return;
	}
    if (null != $("#totalAmt").val() && undefined != $("#totalAmt").val() && '' != $("#totalAmt").val()) {
    	totalAmt = parseFloat($("#totalAmt").val());
    }
    
    if(convertSumMoney("billAmtSum")!=convertSumMoney("totalAmt")){
		alert("收据总金额和账单金额之和不一致！");
		return;
	}
	if((convertSumMoney("overallPay")+convertSumMoney("attachPay")).toFixed(2)!=convertSumMoney("medInsSum").toFixed(2)){
		alert("医保支付金额不一致(统筹支付和附加支付金额之和)。");
		return;
	}
	if(convertSumMoney("ownAmtSum").toFixed(2)!=convertSumMoney("rcptOwnAmt").toFixed(2)){
		alert("账单自费金额和收据自费金额不一致。");
		return;
	}
	if(convertSumMoney("rcptDivAmt").toFixed(2)!=convertSumMoney("divAmtSum").toFixed(2)){
		alert("账单分类自负金额和收据分类自负金额不一致。");
		return;
	}
	var trList = $("#billDetailTable").find("tr");
	var rcptDrugsTr = $("#rcptDrugsTbl").find("tr");
	var rcptOtherCostInfoTr = $("#rcptOtherCostInfoTbl").find("tr");
	/**
	 * 以下控制输入次数和对应金额
	 */
	//如果录入了物理治疗费录入了账单金额，控制次数为必须录入
	var itemBillAmt=$("#billDetailTable").find("tr[id='000026']").find("INPUT[id='billAmt']").val();
	var itemTreatmentTime=$("#billDetailTable").find("tr[id='000026']").find("INPUT[id='treatmentTime']").val();
	if((itemBillAmt!='') && (itemTreatmentTime=='')){
		alert("物理治疗费录入了账单金额，必须录入对应次数");
		return;
	}
	//如果录入了代替治疗费录入了账单金额，控制次数为必须录入
	var itemBillAmt2=$("#billDetailTable").find("tr[id='000027']").find("INPUT[id='billAmt']").val();
	var itemTreatmentTime2=$("#billDetailTable").find("tr[id='000027']").find("INPUT[id='treatmentTime']").val();
	if((itemBillAmt2!='') && (itemTreatmentTime2=='')){
		alert("代替治疗费录入了账单金额，必须录入对应次数");
		return;
	}
	var billAmtXiya=$("#billDetailTable").find("tr[id='000051']").find("INPUT[id='billAmt']").val();
	var itemTreatmentXiya=$("#billDetailTable").find("tr[id='000051']").find("INPUT[id='treatmentTime']").val();
	if((billAmtXiya!='')&&(itemTreatmentXiya=='')){
		alert("洗牙费录入了账单金额，必须录入对应次数");
		return;
	}
	var billAmtPou=$("#billDetailTable").find("tr[id='000053']").find("INPUT[id='billAmt']").val();
	var itemTreatmentPou=$("#billDetailTable").find("tr[id='000053']").find("INPUT[id='treatmentTime']").val();
	if((billAmtPou!='')&&(itemTreatmentPou=='')){
		alert("剖宫产产前超声检查费录入了账单金额，必须录入对应次数");
		return;
	}
	var billAmtPouAfter=$("#billDetailTable").find("tr[id='000054']").find("INPUT[id='billAmt']").val();
	var itemTreatmentPouAfter=$("#billDetailTable").find("tr[id='000054']").find("INPUT[id='treatmentTime']").val();
	if((billAmtPouAfter!='')&&(itemTreatmentPouAfter=='')){
		alert("剖宫产产后复查费录入了账单金额，必须录入对应次数");
		return;
	}
	var billAmtZheng=$("#billDetailTable").find("tr[id='000056']").find("INPUT[id='billAmt']").val();
	var itemTreatmentZheng=$("#billDetailTable").find("tr[id='000056']").find("INPUT[id='treatmentTime']").val();
	if((billAmtZheng!='')&&(itemTreatmentZheng=='')){
		alert("正常分娩产前超声检查费录入了账单金额，必须录入对应次数");
		return;
	}
	var billAmtZhengAfter=$("#billDetailTable").find("tr[id='000057']").find("INPUT[id='billAmt']").val();
	var itemTreatmentZhengAfter=$("#billDetailTable").find("tr[id='000057']").find("INPUT[id='treatmentTime']").val();
	if((billAmtZhengAfter!='')&&(itemTreatmentZhengAfter=='')){
		alert("正常分娩产后复查费录入了账单金额，必须录入对应次数");
		return;
	}
	var CLM_ACC_BILL_DETAIL="";
	CLM_ACC_BILL_DETAIL=$("#billDetailTable").find("tr[id='000065']").find("INPUT[id='billAmt']").val();
	var mentaldiseasetreatment=$("#billDetailTable").find("tr[id='000065']").find("INPUT[id='treatmentTime']").val();
	if((CLM_ACC_BILL_DETAIL!='')&&(mentaldiseasetreatment=='')){
		alert("精神疾病治疗费录入了账单金额，必须录入对应次数");
		return;
	}
	var amedi="";
	amedi=$("#billDetailTable").find("tr[id='000073']").find("INPUT[id='billAmt']").val();
	var amedical=$("#billDetailTable").find("tr[id='000073']").find("INPUT[id='treatmentTime']").val();
	if((amedi!='')&&(amedical=='')){
		alert("体检费录入了账单金额，必须录入对应次数");
		return;
	}
	var count=0;
	var wuli=$("#billDetailTable").find("tr[id='000026']").find("INPUT[id='treatmentTime']").val();
	var daiti=$("#billDetailTable").find("tr[id='000027']").find("INPUT[id='treatmentTime']").val();
	var xiya=$("#billDetailTable").find("tr[id='000051']").find("INPUT[id='treatmentTime']").val();
	var poucheck=$("#billDetailTable").find("tr[id='000053']").find("INPUT[id='treatmentTime']").val();
	var poucheckafter=$("#billDetailTable").find("tr[id='000054']").find("INPUT[id='treatmentTime']").val();
	var zhengcheck=$("#billDetailTable").find("tr[id='000056']").find("INPUT[id='treatmentTime']").val();
	var zhengcheckafter=$("#billDetailTable").find("tr[id='000057']").find("INPUT[id='treatmentTime']").val();
	var mentalillness=$("#billDetailTable").find("tr[id='000065']").find("INPUT[id='treatmentTime']").val();
	var amedical1=$("#billDetailTable").find("tr[id='000073']").find("INPUT[id='treatmentTime']").val();
	if(wuli!=''&&wuli!='0'&&wuli!=null){
		count=count+parseInt(wuli);
	}
	if(daiti!=''&&daiti!='0'&&daiti!=null){
		count=count+parseInt(daiti);
	}
	if(count>10){
		alert("物理治療費和代替治療費次数总和不能超過10次");
		return;
	}
	if(xiya>1){
		alert("洗牙费次数不能超过1次");
		return;
	}
	if(poucheck>3){
		alert("剖宫产产前超声检查费次数不能超过3次");
		return;
	}
	if(poucheckafter>2){
		alert("剖宫产产后复查费次数不能超过2次");
		return;
	}
	if(zhengcheck>2){
		alert("正常分娩产前超声检查费次数不能超过2次");
		return;
	}
	if(zhengcheckafter>1){
		alert("正常分娩产后复查费次数不能超过1次");
		return;
	}
	if(mentalillness>20){
		alert("精神疾病治疗费次数不能超过20次");
		return;
	}
	if(amedical1>1){
		alert("体检费次数不能超过1次");
		return;
	}
	/*var sumRcptDrugs = 0.00;
	for(var i=2;i<rcptDrugsTr.length;i++){
		var tr = $(rcptDrugsTr[i]);
		var actualPayment = tr.find("INPUT[id='actualPayment']");
		var actualPaymentfloat = parseFloat(actualPayment.val());
		if(actualPayment.val()!=""){
			sumRcptDrugs = sumRcptDrugs + actualPaymentfloat;
		}
	}
	for(var i=2;i<rcptOtherCostInfoTr.length;i++){
		var tr = $(rcptOtherCostInfoTr[i]);
		var otheractualPayment = tr.find("INPUT[id='otheractualPayment']");
		var otheractualPaymentfloat = parseFloat(otheractualPayment.val());
		if(otheractualPayment.val()!=""){
			sumRcptDrugs = sumRcptDrugs + otheractualPaymentfloat;
		}
	}
	if(parseFloat($("#billAmtSum").val())!=sumRcptDrugs){
		alert("账单金额和明细不一致！");
		return;
	}*/
	var jsonStr= "";
	var billInfo = "";
	var billDetails = "";
	var drugsDetails = "";
	var rcptOtherCostInfo = "";
	
	
	var receipttype = $("#divreceipttype_code").val(); 
	if(receipttype!=undefined&&receipttype!="")
	$("#receipttype").val(receipttype);
	var receiptNo = $("#receiptNo").val();
	var currencySymbol = $("#currencySymbol").val();
	var exchangeRate = $("#exchangeRate").val();
	var totalAmt = $("#totalAmt").val();
	var invoiceNo = $("#invoiceNo").val();
	var invoiceDate = $("#invoiceDate").val();
	var overallPay = $("#overallPay").val();
	var attachPay = $("#attachPay").val();
	var rcptOwnAmt = $("#rcptOwnAmt").val();
	var rcptDivAmt = $("#rcptDivAmt").val();
	var thirdPay = $("#thirdPay").val();
	billInfo+='{"receiptType":"' + $("#receipttype").val() + '","receiptNo":"' + receiptNo
	+ '","currencySymbol":"' + currencySymbol  +  '","exchangeRate":"' + exchangeRate
	+'","totalAmt":"' + totalAmt+'","invoiceDate":"' + invoiceDate+'","invoiceDate":"' + invoiceDate
	+'","overallPay":"' + overallPay+'","attachPay":"' + attachPay+'","ownAmt":"' + rcptOwnAmt
	+'","divAmt":"' + rcptDivAmt+'","thirdPay":"' + thirdPay+'","invoiceNo":"'+invoiceNo+'"}';
	
	
	
	
	for(var i=1;i<trList.length-1;i++){
		var tr = $(trList[i]);
		var trId=tr.attr("id");
		if(trId!="sumMoney"){
			var billAmt = tr.find("INPUT[id='billAmt']");
			var ownAmt = tr.find("INPUT[id='ownAmt']");
			var divAmt = tr.find("INPUT[id='divAmt']");
			var medIns = tr.find("INPUT[id='medIns']");
			if($("#isBpo").val()=="N"){
				var thirdPay = tr.find("INPUT[id='thirdPay']");
				var deductionsAmt = tr.find("INPUT[id='deductionsAmt']");
				var treatmentTime = tr.find("INPUT[id='treatmentTime']");
				if(billAmt.val()==""&&ownAmt.val()==""&&divAmt.val()==""&&medIns.val()==""&&deductionsAmt.val()==""&&thirdPay.val()==""){
					continue;
				}
				billDetails+='{"billItemCode":"' + trId + '","billAmt":"' + billAmt.val()+ '","ownAmt":"' + ownAmt.val()+
				'","divAmt":"' + divAmt.val()+'","medIns":"' + medIns.val()+'","thirdPay":"' + thirdPay.val()+'","deductionsAmt":"' + deductionsAmt.val()+'","treatmentTime":"' + treatmentTime.val()+'"},';
			}else{
				if(billAmt.val()==""&&ownAmt.val()==""&&divAmt.val()==""){
					continue;
				}
				billDetails+='{"billItemCode":"' + trId + '","billAmt":"' + billAmt.val()+ '","ownAmt":"' + ownAmt.val()+
				'","divAmt":"' + divAmt.val()+'","medIns":"' + medIns.val()+'"},';
			}
		}
		
	}
	billDetails = "["+billDetails.substring(0,billDetails.length-1)+"]";
	
	for(var i=2;i<rcptDrugsTr.length;i++){
		var tr = $(rcptDrugsTr[i]);
		var trId=tr.attr("id");
		if(trId=="addnewtr"){
			trId="";
		}
		var drugsCode = tr.find("INPUT[name='drugsCode']");
		var drugsName = tr.find("INPUT[name='drugsName']");
		var specifications = tr.find("INPUT[name='specifications']");
		var dosageForm = tr.find("INPUT[name='dosageForm']");
		var units = tr.find("INPUT[name='units']");
		var unitPrice = tr.find("INPUT[name='unitPrice']");
		var projectName = tr.find("SPAN[name='projectName']");
		var itemCode=tr.find("INPUT[name='drugitemCode']").val();
		if(($.trim(projectName.text())=="请选择")||(itemCode=="")||(itemCode==undefined)){
			projectName.text("");
			itemCode="0000000";
		}
		var quantity = tr.find("INPUT[name='quantity']");
		var actualPayment = tr.find("INPUT[name='actualPayment']");
//		var medicalInsType = tr.find("INPUT[name='medicalInsType']");
		var medicalInsType = tr.find("SPAN[name='sel_span']");
		if($.trim(medicalInsType.text())=="请选择"){
			medicalInsType.text("");
		}
		var ownRate = tr.find("INPUT[name='ownRate']");
		var ownCostAmt = tr.find("INPUT[name='ownCostAmt']");
		var rejectSpan = tr.find("SPAN");
		var isReject = "";
//		var excludeReason = tr.find("INPUT[id='excludeReason']");
		var excludeReason = tr.find("SPAN[name='t_sel_span']");
		if (excludeReason) {
			excludeReasonValue = $.trim(excludeReason.html());
		}
		if (!excludeReason) {
			excludeReason = tr.find("INPUT[name='excludeReason']");
			alert(excludeReason.html());
			excludeReasonValue = excludeReason.val();
		}
		if(rejectSpan.eq(2).attr("class")=="check_no"){
			isReject="N";
		}else{
			isReject="Y";
		}
		var costRate = 0.00;
		if(ownRate.val()!=""&&ownRate.val()!=undefined){
			costRate = ownRate.val();
		}
		if(drugsCode.val()==""&&drugsName.val()==""&&specifications.val()==""&&dosageForm.val()==""&&units.val()==""
			&&unitPrice.val()==""&&quantity.val()==""&&actualPayment.val()==""&&medicalInsType.val()==""&&ownRate.val()==""
			&&ownCostAmt.val()==""&&excludeReason.val()==""){
			continue;
		}
		if($("#isBpo").val()=="Y"){
			drugsDetails+='{"drugsCode":"' + drugsCode.val() + '","id":"' + trId +'","drugsName":"' + drugsName.val()+ '","specifications":"' + specifications.val()+
			'","dosageForm":"' + dosageForm.val()+'","units":"' + units.val()+'","unitPrice":"' + unitPrice.val()+
			'","quantity":"' + quantity.val()+'","actualPayment":"' + actualPayment.val()+'","medicalInsType":"' +  $.trim(medicalInsType.text())+
			'","ownRate":"' + costRate+'","ownCostAmt":"' + ownCostAmt.val()+
			'","billItemCode":"' + itemCode+'","projectName":"' + $.trim(projectName.text())+'"},';

		}else{
			drugsDetails+='{"drugsCode":"' + drugsCode.val() + '","id":"' + trId +'","drugsName":"' + drugsName.val()+ '","specifications":"' + specifications.val()+
			'","dosageForm":"' + dosageForm.val()+'","units":"' + units.val()+'","unitPrice":"' + unitPrice.val()+
			'","quantity":"' + quantity.val()+'","actualPayment":"' + actualPayment.val()+'","medicalInsType":"' +  $.trim(medicalInsType.text())+
			'","ownRate":"' + costRate+'","ownCostAmt":"' + ownCostAmt.val()+'","isReject":"' + isReject+
			'","excludeReason":"' + excludeReasonValue+'","billItemCode":"' + itemCode+'"},';

		}
	}
	drugsDetails = "["+drugsDetails.substring(0,drugsDetails.length-1)+"]";
	
	
	
	
	
	for(var i=2;i<rcptOtherCostInfoTr.length;i++){
		var tr = $(rcptOtherCostInfoTr[i]);
		var trId=tr.attr("id");
		if(trId=="addnewtr"){
			trId="";
		}
		var otherproductName = tr.find("INPUT[name='otherproductName']");
		var otherexpenseName = tr.find("SPAN[name='otherexpenseName']");
		var itemCode=tr.find("INPUT[name='otheritemCode']").val();
		if(($.trim(otherexpenseName.text())=="请选择")||(itemCode=="")||(itemCode==undefined)){
			itemCode="0000000";
		}
		
		var othermedicalInsType = tr.find("SPAN[name='sel_span_oth']");
		if($.trim(othermedicalInsType.text())=="请选择"){
			othermedicalInsType.text("");
		}
		var otherdrugsCode = tr.find("INPUT[name='otherdrugsCode']");
		var otheractualPayment = tr.find("INPUT[id='otheractualPayment']");
		var otherownCostRate = tr.find("INPUT[id='otherownCostRate']");
		var otherownCostSAmt = tr.find("INPUT[id='otherownCostSAmt']");
		var otherunitPrice = tr.find("INPUT[id='otherunitPrice']");
		var otherSpan = tr.find("SPAN");
		var isReject = "";
		var excludeReason = tr.find("INPUT[id='excludeReason']");
		if(otherSpan.eq(2).attr("class")=="check_no"){
			isReject="N";
		}else{
			isReject="Y";
		}
		var costRate = 0.00;
		if(otherownCostRate.val()!=""&&otherownCostRate.val()!=undefined){
			costRate = otherownCostRate.val();
		}
		if(otherproductName.val()==""&&$.trim(otherexpenseName.val())==""&&othermedicalInsType.val()==""&&otherdrugsCode.val()==""&&otheractualPayment.val()==""
			&&otherownCostRate.val()==""&&otherownCostSAmt.val()==""&&otherunitPrice.val()==""&&excludeReason.val()==""){
			continue;
		}
		if($("#isBpo").val()=="Y"){//otherproductName.val() +'","expenseName":"' + $.trim(otherexpenseName.text())
			rcptOtherCostInfo+='{"id":"' + trId + '","productName":"' + $.trim(otherexpenseName.text()) +'","expenseName":"' + otherproductName.val() + '","medicalInsType":"' + $.trim(othermedicalInsType.text())+
			'","drugsCode":"' + otherdrugsCode.val()+'","actualPayment":"' + otheractualPayment.val()+'","ownCostRate":"' + costRate+
			'","ownCostSAmt":"' + otherownCostSAmt.val()+'","billItemCode":"' + itemCode+'","unitPrice":"' + otherunitPrice.val()+
			'","projectName":"' + $.trim(otherexpenseName.text())+
			'"},';

		}else{
			rcptOtherCostInfo+='{"id":"' + trId + '","productName":"' + $.trim(otherexpenseName.text()) +'","expenseName":"' + otherproductName.val() + '","medicalInsType":"' + $.trim(othermedicalInsType.text())+
			'","drugsCode":"' + otherdrugsCode.val()+'","actualPayment":"' + otheractualPayment.val()+'","ownCostRate":"' + costRate+
			'","ownCostSAmt":"' + otherownCostSAmt.val()+'","billItemCode":"' + itemCode+'","unitPrice":"' + otherunitPrice.val()+
			'","projectName":"' + $.trim(otherexpenseName.text())+
			'","isReject":"' + isReject+'","excludeReason":"' + excludeReason.val()+'"},';

		}
	}
	rcptOtherCostInfo = "["+rcptOtherCostInfo.substring(0,rcptOtherCostInfo.length-1)+"]";
	
	//原来的收据信息
	var billInfoOld = "";
	var receiptNoOld = $("#receiptNoOld").val();
	var receipttypeOld = $("#receipttypeOld").val();
	var currencySymbolOld = $("#currencySymbolOld").val();
	var exchangeRateOld = $("#exchangeRateOld").val();
	var totalAmtOld = $("#totalAmtOld").val();
	var invoiceDateOld = $("#invoiceDateOld").val();
	var overallPayOld = $("#overallPayOld").val();
	var attachPayOld = $("#attachPayOld").val();
	var rcptOwnAmtOld = $("#rcptOwnAmtOld").val();
	var rcptDivAmtOld = $("#rcptDivAmtOld").val();
	var rcptThirdPayOld = $("#rcptThirdPayOld").val();
	billInfoOld+='{"receipttype":"' + receipttypeOld + '","receiptNo":"' + receiptNoOld
	+ '","currencySymbol":"' + currencySymbolOld  +  '","exchangeRate":"' 
	+ exchangeRateOld+ '","totalAmt":"' + totalAmtOld+'","invoiceDate":"' + invoiceDateOld
	+'","overallPay":"' + overallPayOld+'","attachPay":"' + attachPayOld+'","ownAmt":"' + rcptOwnAmtOld
	+'","divAmt":"' + rcptDivAmtOld+'","thirdPay":"' + rcptThirdPayOld+'"}';
	
	//原来的账单信息
	var billDetailsOld = "";
	var trListOld = $("#billDetailTableOld").find("tr");
	for(var i=0;i<trListOld.length-1;i++){
		var tr = $(trListOld[i]);
		var trIdOld=tr.attr("id");
		if(trIdOld!="sumMoney"){
			var billAmtOld = tr.find("INPUT[id='billAmtOld']");
			var ownAmtOld = tr.find("INPUT[id='ownAmtOld']");
			var divAmtOld = tr.find("INPUT[id='divAmtOld']");
			var medInsOld = tr.find("INPUT[id='medInsOld']");
			var thirdPayOld = tr.find("INPUT[id='thirdPayOld']");
			var deductionsAmtOld = tr.find("INPUT[id='deductionsAmtOld']");
			if(billAmtOld.val()==""&&ownAmtOld.val()==""&&divAmtOld.val()==""&&medInsOld.val()==""&&deductionsAmtOld.val()==""&&thirdPayOld.val()==""){
				break;
			}
			billDetailsOld+='{"billItemCode":"' + trIdOld + '","billAmt":"' + billAmtOld.val()+ '","ownAmt":"' + ownAmtOld.val()+
			'","divAmt":"' + divAmtOld.val()+'","medIns":"' + medInsOld.val()+'","thirdPay":"' + thirdPayOld.val()+'","deductionsAmt":"' + deductionsAmtOld.val()+'"},';
		}
		
	}
	billDetailsOld = "["+billDetailsOld.substring(0,billDetailsOld.length-1)+"]";
	//原来的清单信息药品明细
	var drugsDetailsOld = "";
	var rcptDrugsTrOld = $("#rcptDrugsTblOld").find("tr");
	for(var i=2;i<rcptDrugsTrOld.length;i++){
		var tr = $(rcptDrugsTrOld[i]);
		var trIdOld=tr.attr("id");
		if(trIdOld=="addnewtr"){
			trIdOld="";
		}
		var drugsCodeOld = tr.find("INPUT[id='drugsCodeOld']");
		var drugsNameOld = tr.find("INPUT[id='drugsNameOld']");
		var specificationsOld = tr.find("INPUT[id='specificationsOld']");
		var dosageFormOld = tr.find("INPUT[id='dosageFormOld']");
		var unitsOld = tr.find("INPUT[id='unitsOld']");
		var unitPriceOld = tr.find("INPUT[id='unitPriceOld']");
		var quantityOld = tr.find("INPUT[id='quantityOld']");
		var actualPaymentOld = tr.find("INPUT[id='actualPaymentOld']");
		var medicalInsTypeOld = tr.find("INPUT[id='medicalInsTypeOld']");
		var ownRateOld = tr.find("INPUT[id='ownRateOld']");
		var ownCostAmtOld = tr.find("INPUT[id='ownCostAmtOld']");
		var rejectSpanOld = tr.find("SPANOld");
		var isRejectOld = "";
		var excludeReasonOld = tr.find("INPUT[id='excludeReasonOld']");
		if(rejectSpanOld.attr("class")=="check_no"){
			isRejectOld="N";
		}else{
			isRejectOld="Y";
		}
		var costRateOld = 0.00;
		if(ownRateOld.val()!=""&&ownRateOld.val()!=undefined){
			costRateOld = ownRateOld.val()/100;
		}
		if(drugsCodeOld.val()==""&&drugsNameOld.val()==""&&specificationsOld.val()==""&&dosageFormOld.val()==""&&unitsOld.val()==""
			&&unitPriceOld.val()==""&&quantityOld.val()==""&&actualPaymentOld.val()==""&&medicalInsTypeOld.val()==""&&ownRateOld.val()==""
			&&ownCostAmtOld.val()==""&&excludeReasonOld.val()==""){
			break;
		}
		drugsDetailsOld+='{"drugsCode":"' + drugsCodeOld.val() + '","id":"' + trIdOld +'","drugsName":"' + drugsNameOld.val()+ '","specifications":"' + specificationsOld.val()+
		'","dosageForm":"' + dosageFormOld.val()+'","units":"' + unitsOld.val()+'","unitPrice":"' + unitPriceOld.val()+
		'","quantity":"' + quantityOld.val()+'","actualPayment":"' + actualPaymentOld.val()+'","medicalInsType":"' + medicalInsTypeOld.val()+
		'","ownRate":"' + costRateOld+'","ownCostAmt":"' + ownCostAmtOld.val()+'","isReject":"' + isRejectOld+
		'","excludeReason":"' + excludeReasonOld.val()+'","billItemCode":"' + "000009"+'"},';
	}
	drugsDetailsOld = "["+drugsDetailsOld.substring(0,drugsDetailsOld.length-1)+"]";
	
	//原来的其他费用清单
	var rcptOtherCostInfoOld = "";
	var rcptOtherCostInfoTrOld = $("#rcptOtherCostInfoTblOld").find("tr");
	for(var i=2;i<rcptOtherCostInfoTrOld.length;i++){
		var tr = $(rcptOtherCostInfoTrOld[i]);
		var trIdOld=tr.attr("id");
		if(trIdOld=="addnewtr"){
			trIdOld="";
		}
		var otherproductNameOld = tr.find("INPUT[id='otherproductNameOld']");
		var otherexpenseNameOld = tr.find("INPUT[id='otherexpenseNameOld']");
		var othermedicalInsTypeOld = tr.find("INPUT[id='othermedicalInsTypeOld']");
		var otherdrugsCodeOld = tr.find("INPUT[id='otherdrugsCodeOld']");
		var otheractualPaymentOld = tr.find("INPUT[id='otheractualPaymentOld']");
		var otherownCostRateOld = tr.find("INPUT[id='otherownCostRateOld']");
		var otherownCostSAmtOld = tr.find("INPUT[id='otherownCostSAmtOld']");
		var otherunitPriceOld = tr.find("INPUT[id='otherunitPriceOld']");
		var otherSpanOld = tr.find("SPANOld");
		var isRejectOld = "";
		var excludeReasonOld = tr.find("INPUT[id='excludeReasonOld']");
		if(otherSpanOld.attr("class")=="check_no"){
			isRejectOld="N";
		}else{
			isRejectOld="Y";
		}
		var costRateOld = 0.00;
		if(otherownCostRateOld.val()!=""&&otherownCostRateOld.val()!=undefined){
			costRateOld = otherownCostRateOld.val()/100;
		}
		if(otherproductNameOld.val()==""&&otherexpenseNameOld.val()==""&&othermedicalInsTypeOld.val()==""&&otherdrugsCodeOld.val()==""&&otheractualPaymentOld.val()==""
			&&otherownCostRateOld.val()==""&&otherownCostSAmtOld.val()==""&&otherunitPriceOld.val()==""&&excludeReasonOld.val()==""){
			break;
		}
		rcptOtherCostInfoOld+='{"id":"' + trIdOld + '","productName":"' + otherproductNameOld.val() +'","expenseName":"' + otherexpenseNameOld.val() + '","medicalInsType":"' + othermedicalInsTypeOld.val()+
		'","drugsCode":"' + otherdrugsCodeOld.val()+'","actualPayment":"' + otheractualPaymentOld.val()+'","ownCostRate":"' + costRateOld+
		'","ownCostSAmt":"' + otherownCostSAmtOld.val()+'","billItemCode":"' + "000009"+'","unitPrice":"' + otherunitPriceOld.val()+
		'","isReject":"' + isRejectOld+'","excludeReason":"' + excludeReasonOld.val()+'"},';

	}
	rcptOtherCostInfoOld = "["+rcptOtherCostInfoOld.substring(0,rcptOtherCostInfoOld.length-1)+"]";
	
	
	jsonStr = '{"rcptBill":' + billInfo +',"rcptBillDetail":' + billDetails+',"rcptDrugsList":' + drugsDetails+
	',"rcptOtherCostInfo":' + rcptOtherCostInfo+
	',"rcptBillOld":' + billInfoOld+',"rcptBillDetailOld":' + billDetailsOld+',"rcptDrugsListOld":' + drugsDetailsOld+',"rcptOtherCostInfoOld":' + rcptOtherCostInfoOld+
	',"claimNo":"' + $("#claimNo").val()+'","claimEventNo":"' + $("#claimEventNo").val()+'"}';
	$("#saveInfo").removeAttr("onclick");
	//判断发票号是否重复
	$.ajax({
		type:"POST",
		url:"checkInvoiceRepeat.do",
		data:"invoiceNo="+invoiceNo+"&&rcptNo="+receiptNo,
		error :function(){
			alert("收据信息保存失败");
		},
		success :function(data){
			if(data=="02"){
				if(confirm("所录收据信息重复，确认是否提交信息？")){
					$.ajax({
						type:"POST",
						contentType:"application/json; charset=UTF-8",
						url:"saveReceiptInfo.do",
						data:jsonStr,
						error :function(){
							alert("收据信息保存失败");
						},
						success :function(data){
							if(data=="00"){
								alert("收据信息保存成功。");
								dispatcherEventPage($("#claimEventNo").val());
							}else{
								alert("收据信息保存失败。");
							}
						}
					});
				}
			}else{
				$.ajax({
					type:"POST",
					contentType:"application/json; charset=UTF-8",
					url:"saveReceiptInfo.do",
					data:jsonStr,
					error :function(){
						alert("收据信息保存失败");
					},
					success :function(data){
						if(data=="00"){
							alert("收据信息保存成功。");
							dispatcherEventPage($("#claimEventNo").val());
						}else {
							alert("收据信息保存失败。");
						}
					}
				});
			}
		}
	});
}

function bundleTip(obj){
	//alert($(obj).parent());
	//var a=$(obj).parent().parent();
	//alert("=="+$(obj).parent().parent().html());
	var aa = $("#x888z");
	aa.removeAttr("id");
	var bb=$("#x889z");
	bb.removeAttr("id");
	var cc=$("#x890z");
	cc.removeAttr("id");
	var dd=$("#x891z");
	dd.removeAttr("id");
	var ee=$("#x892z");
	ee.removeAttr("id");
	var ff=$("#x893z");
	ff.removeAttr("id");
	$(obj).parent().parent().find("input").eq(0).attr("id","x888z");
	$(obj).parent().parent().find("input").eq(2).attr("id","x889z");
	$(obj).parent().parent().find("input").eq(3).attr("id","x890z");
	$(obj).parent().parent().find("input").eq(4).attr("id","x891z");
	$(obj).parent().parent().find("input").eq(5).attr("id","x892z");
	$(obj).parent().parent().find("input").eq(8).attr("id","x893z");
	
	
	$("#u-tip-div").remove();
	var ct = document.getElementById("current-tip");
	$(ct).removeAttr("id");
	
	$(obj).attr("id","current-tip");
	$(obj).parent.parent;
	var html = "<div class=\"sel_list\" id=\"u-tip-div\" style=\"display:block; margin:0 0 0 53px; width:164px; padding:0;\"><ul id=\"u-tip\" ></ul></div>";
	$(obj).parent("td:eq(0)").append(html);
	
	
}

function fillInVal(obj){
	hmGjypbm=$(obj).attr("data-code");
	$("#current-tip").val($(obj).html());
	$("#u-tip-div").remove();
//	alert($(obj).parent().parent().find("input").eq(0).val(1));
//	alert($(obj).parent().parent().find("input").eq(1).val());
//	alert($(obj).parent().parent().find("input").eq(2).val());
	  $.ajax({
	        type: "POST",  
	        url: "medicalSearchById.do",  
	        data:{objId:hmGjypbm},
	        success: function(data){
	        	$("#x888z").val(data.medical.hmGjypbm);
	        	$("#x889z").val(data.medical.hmMedSpec);
	        	$("#x890z").val(data.medical.hmMedForm);
	        	$("#x891z").val(data.medical.hmMedUnit);
	        	$("#x892z").val(data.medical.hmPrice);
	        	$("#x893z").val(data.medical.hmType);
//	        	$(obj).parent().parent().find("input").eq(0).val(data.medical.hmGjypbm);
//	        	$(obj).parent().parent().find("input").eq(3).val(data.medical.hmMedForm);
//	        	$(obj).parent().parent().find("input").eq(8).val(data.medical.hmType);
//	        	$("#u-tip").html("");
//	        	if(items.length>0){
//	        		for ( var i = 0; i < items.length; i++) {
//	        			$("#u-tip").append("<li onclick=\"fillInVal(this)\" onmouseover=\"changbackclrFn(this)\">"+items[i].hmMedChName+"</li>");
//	        		}
//	        	$("#units").val(data.hmGbId);
	        	}
	        	
	    }); 
}
function fillInOthVal(obj,objId){
	hmGjypbm=objId;
	$("#current-tip").val($(obj).html());
	$("#u-tip-div").remove();
//	alert($(obj).parent().parent().find("input").eq(0).val(1));
//	alert($(obj).parent().parent().find("input").eq(1).val());
//	alert($(obj).parent().parent().find("input").eq(2).val());
	  $.ajax({
	        type: "POST",  
	        url: "rcptOtherCostInfoSearchById.do",  
	        data:{objId:objId},
	        success: function(data){
	        	$("#x888z").val(data.clmTreatment.dtChName);
	        	$("#x889z").html(data.clmTreatment.dtItemName);
	        	$("#x890z").val(data.clmTreatment.dtGbId);
	        	//项目代码
	        	$("#x894z").val(data.clmTreatment.dtItemCode);
//	        	$("#x891z").val(data.clmTreatment.dtUnit);
//	        	$("#x892z").val(data.clmTreatment.dtItemName);
//	        	$(obj).parent().parent().find("input").eq(0).val(data.medical.hmGjypbm);
//	        	$(obj).parent().parent().find("input").eq(3).val(data.medical.hmMedForm);
//	        	$(obj).parent().parent().find("input").eq(8).val(data.medical.hmType);
//	        	$("#u-tip").html("");
//	        	if(items.length>0){
//	        		for ( var i = 0; i < items.length; i++) {
//	        			$("#u-tip").append("<li onclick=\"fillInVal(this)\" onmouseover=\"changbackclrFn(this)\">"+items[i].hmMedChName+"</li>");
//	        		}
//	        	$("#units").val(data.hmGbId);
	        	}
	        	
	    }); 
}
function bundleOthTip(obj){
	//alert($(obj).parent());
	//var a=$(obj).parent().parent();
	//alert("=="+$(obj).parent().parent().html());
	var aa = $("#x888z");
	aa.removeAttr("id");
	var bb=$("#x889z");
	bb.removeAttr("id");
	var cc=$("#x890z");
	cc.removeAttr("id");
	var dd=$("#x891z");
	dd.removeAttr("id");
	var ee=$("#x892z");
	ee.removeAttr("id");
	var ff=$("#x893z");
	ff.removeAttr("id");
	//项目代码
	var gg=$("#x894z");
	gg.removeAttr("id");
//	alert($(obj).parent().parent().find("input").eq(0).val(1));
//	alert($(obj).parent().parent().find("input").eq(1).val());
//	alert($(obj).parent().parent().find("input").eq(2).html());
	$(obj).parent().parent().find("input").eq(0).attr("id","x888z");
	$(obj).parent().parent().find("span").eq(0).attr("id","x889z");
	$(obj).parent().parent().find("input").eq(1).attr("id","x890z");
	//项目代码
	$(obj).parent().parent().find("input").eq(6).attr("id","x894z");
//	$(obj).parent().parent().find("input").eq(4).attr("id","x891z");
//	$(obj).parent().parent().find("input").eq(5).attr("id","x892z");
//	$(obj).parent().parent().find("input").eq(8).attr("id","x893z");
	
	
	$("#u-tip-div").remove();
	var ct = document.getElementById("current-tip");
	$(ct).removeAttr("id");
	
	$(obj).attr("id","current-tip");
	$(obj).parent.parent;
	var html = "<div class=\"sel_list\" id=\"u-tip-div\" style=\"display:block; margin:0 0 0 53px; width:164px; padding:0;\"><ul id=\"u-tip\" ></ul></div>";
	$(obj).parent("td:eq(0)").append(html);
	
	
}
function changbackclrFn(flag){
	$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
}

function addTr(strbuf){
	var isBpo=$("#isBpo").val();
	if(isBpo=="N"){//高端
		var tr = "<tr id=\"addnewtr\" onclick=\"choosEd(this)\">"+
//		"<td><input readonly=\"readonly\" id=\"drugsCode\" name=\"drugsCode\" type=\"text\" class=\"input i_s_60\" onclick=\"showDiv('open2')\"/></td>"+
		"<td><input id=\"drugsCode\" name=\"drugsCode\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<td><input id=\"drugsName\" name=\"drugsName\" type=\"text\" class=\"input i_s_60\"  autocomplete=\"off\" onfocus=\"bundleTip(this)\" onkeyup=\"medicalChoose(this)\" onkeydown=\"medicalChoose(this)\"/></td>"+
	    "<td><input id=\"specifications\" name=\"specifications\" type=\"text\" class=\"input i_s_60\"  /></td>"+
	    "<td><input readonly=\"readonly\" id=\"dosageForm\" name=\"dosageForm\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<td><input id=\"units\" name=\"units\" type=\"text\" class=\"input i_s_60\"  /></td>"+
	    "<td><input id=\"unitPrice\" onblur=\"checkMoney(this);\" name=\"unitPrice\" type=\"text\" class=\"input i_s_60\"  /></td>"+
	    "<td><input id=\"quantity\"  onblur=\"checkMoney(this);\" name=\"quantity\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<td><input id=\"actualPayment\"  onblur=\"checkMoney(this);\" name=\"actualPayment\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    //"<td><input id=\"medicalInsType\" readonly=\"readonly\" name=\"medicalInsType\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    
	    "<td><div class=\"select_d i_s_60\" id=\"medicalInsType1\" name=\"medicalInsType1\" >"+
		"<span class=\"sel_d_text\"> 请选择 </span>"+
		"<div class=\"sel_d_list i_ul_85\" style=\"display: none;\">"+
			"<ul><li code=\"甲类\">甲类</li><li code=\"乙类\">乙类</li><li code=\"丙类\">丙类</li><li code=\"其他\">其他</li></ul></div></div></td>"+
			
	    "<td><input id=\"ownRate\" onblur=\"checkRate(this);\" name=\"ownRate\" type=\"text\" class=\"input i_s_60\" />%</td>"+
	    "<td><input id=\"ownCostAmt\" onblur=\"checkMoneyM(this);\" name=\"ownCostAmt\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<c:if test=\"${isBpo=='N' }\"><td><span  class=\"check_no\"  onclick=\"cvtCheck(this)\"></span></td>"+
	    "<td colspan=\"2\">"+
	    "<div class=\"select_d i_s_100\" id=\"excludeReason\">"+
		"<span class=\"sel_d_text\" name=\"t_sel_span\"> "+
			"请选择"+
	"</span>"+
	"<div class=\"sel_d_list i_ul_125\" style=\"display: none;\">"+
		"<ul>"+
			"<li code=\"医保范围之外\">医保范围之外</li>"+
			"<li code=\"责任免除\">责任免除</li>"+
			"<li code=\"其他\" onclick=\"getPaging(this);\">其他</li>"+
		"</ul>"+
	"</div>"+
	"</div>"+
	    "</td></c:if>"+
	"</tr>";
	}else{
//		var myStr = strbuf.split(":");
//		var xstr = "";
//		for (var i=0;i<myStr.length-1 ;i++ ){ 
//			xstr +="<li code=\""+myStr[i]+"\">"+myStr[i]+"</li>";
//			} 
		var myStr = strbuf.split(":");
		var xstr = "";
		for (var i=0;i<myStr.length-1 ;i++ ){ 
			var itemCode=myStr[i].substring(0,6);
			var itemName=myStr[i].substring(7);
			xstr +="<li code=\""+itemName+"\" id=\""+itemCode+"\" onclick=\"checkDrugItemName(this.id)\">"+itemName+"</li>";
			} 
		var tr = "<tr id=\"addnewtr\" onclick=\"choosEd(this)\">"+
//		"<td><input readonly=\"readonly\" id=\"drugsCode\" name=\"drugsCode\" type=\"text\" class=\"input i_s_60\" onclick=\"showDiv('open2')\"/></td>"+
		"<td><input id=\"drugsCode\" name=\"drugsCode\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<td><input id=\"drugsName\" name=\"drugsName\" type=\"text\" class=\"input i_s_60\"  autocomplete=\"off\" onfocus=\"bundleTip(this)\" onkeyup=\"medicalChoose(this)\" onkeydown=\"medicalChoose(this)\"/></td>"+
	    "<td ><div class=\"select_d i_s_60\" id=\"projectName\"><span class=\"sel_d_text\" name=\"projectName\">请选择"+
			   "</span><div class=\"sel_d_list i_ul_85\" style=\"display: none;\"><ul>"+xstr+"</ul></div></div>" +
	    "</td>"+
	    "<td><input id=\"specifications\" name=\"specifications\" type=\"text\" class=\"input i_s_60\"  /></td>"+
	    "<td><input readonly=\"readonly\" id=\"dosageForm\" name=\"dosageForm\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<td><input id=\"units\" name=\"units\" type=\"text\" class=\"input i_s_60\"  /></td>"+
	    "<td><input id=\"unitPrice\" onblur=\"checkMoney(this);\" name=\"unitPrice\" type=\"text\" class=\"input i_s_60\"  /></td>"+
	    "<td><input id=\"quantity\"  onblur=\"checkMoney(this);\" name=\"quantity\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<td><input id=\"actualPayment\"  onblur=\"checkMoney(this);\" name=\"actualPayment\" type=\"text\" class=\"input i_s_60\" /></td>"+
	    "<td><div class=\"select_d i_s_60\" id=\"medicalInsType1\" name=\"medicalInsType1\" >"+
		"<span class=\"sel_d_text\"> 请选择 </span>"+
		"<div class=\"sel_d_list i_ul_85\" style=\"display: none;\">"+
			"<ul><li code=\"甲类\">甲类</li><li code=\"乙类\">乙类</li><li code=\"丙类\">丙类</li><li code=\"其他\">其他</li></ul></div></div></td>"+
			
	    "<td><input id=\"ownRate\" onblur=\"checkRate(this);\" name=\"ownRate\" type=\"text\" class=\"input i_s_60\" />%</td>"+
	    "<td><input id=\"ownCostAmt\" onblur=\"checkMoneyM(this);\" name=\"ownCostAmt\" type=\"text\" class=\"input i_s_60\" />" +
	    "<input id=\"drugitemCode\" name=\"drugitemCode\" type=\"hidden\" class=\"input i_s_60\"  /></td>"+
	"</tr>";
	}
	
	
	$("#rcptDrugsTbl").append(tr);
	selectedrug();
}

function selected(){
	$(".select_o").hover(
			function () {
				$(this).addClass("sel_o_over");
			},function () {
				$(this).removeClass("sel_o_over");
			}).on('click',function(){
				var _this = $(this),
				_bthis = $(this).find(".sel_o_list");
				if ( _this.attr('isopen') ) {
					_bthis.slideDown(0 , function(){
						_this.removeAttr('isopen');
					});			
				} else {
					_bthis.slideDown(0,function(){
						_this.attr('isopen',"1");
					});	
				}
			}).on('mouseleave',function(){
				var _thisa = $(this).find(".sel_o_list"),
				_this = $(this);
				_thisa.hide();
				_this.removeAttr('isopen');
			}),
			$(".select_o").find(".sel_o_list li").hover( function (){
				$(".select_o").addClass("sel_o_hov");		
			},function (){
				$(this).removeClass("sel_o_hov");	
			}).on('click',function(){
				var _this = $(this).html();
		
				var _thisText = $(this).closest(".select_o").find(".sel_o_text");
				_thisText.html(_this);
		
			});
}

function selectedrug(){
	$(".select_d").hover(
			function () {
				$(this).addClass("sel_d_over");
			},function () {
				$(this).removeClass("sel_d_over");
			}).on('click',function(){
				var _this = $(this),
				_bthis = $(this).find(".sel_d_list");
				if ( _this.attr('isopen') ) {
					_bthis.slideDown(0 , function(){
						_this.removeAttr('isopen');
					});			
				} else {
					_bthis.slideDown(0,function(){
						_this.attr('isopen',"1");
					});	
				}
			}).on('mouseleave',function(){
				var _thisa = $(this).find(".sel_d_list"),
				_this = $(this);
				_thisa.hide();
				_this.removeAttr('isopen');
			}),
			$(".select_d").find(".sel_d_list li").hover( function (){
				$(".select_d").addClass("sel_d_hov");		
			},function (){
				$(this).removeClass("sel_d_hov");	
			}).on('click',function(){
				var _this = $(this).html();
		
				var _thisText = $(this).closest(".select_d").find(".sel_d_text");
				_thisText.html(_this);
		
			});
}

function addOtherTr(strbuf){
	var isBpo=$("#isBpo").val();
	if(isBpo=="N"){
		var myStr = strbuf.split(":");
		var xstr = "";
		for (var i=0;i<myStr.length-1 ;i++ ){ 
			xstr +="<li code=\""+myStr[i].substring(7)+"\">"+myStr[i].substring(7)+"</li>";
			}  
		var tr = "<tr id=\"addnewtr\" onclick=\"choosOtherEd(this)\">"+
        "<td><input id=\"otherproductName\" name=\"otherproductName\" type=\"text\" class=\"input i_s_60\" autocomplete=\"off\" onfocus=\"bundleOthTip(this)\" onkeyup=\"otherCostInfoChoose(this)\" onkeydown=\"otherCostInfoChoose(this)\" /></td>"+
        //"<td><input id=\"otherexpenseName\" name=\"otherexpenseName\" type=\"text\" class=\"input i_s_60\" /></td>"+
        "<td><div class=\"select_o i_s_60\" id=\"otherexpenseName\"><span class=\"sel_o_text\" name=\"otherexpenseName\">请选择"+
		   "</span><div class=\"sel_o_list i_ul_85\" style=\"display: none;\"><ul>"+xstr+"</ul></div></div></td>" +
//        "<td><input id=\"othermedicalInsType\" name=\"othermedicalInsType\" type=\"text\" class=\"input i_s_60\" /></td>"+
        "<td><div class=\"select_o i_s_60\" id=\"medicalInsType1\" name=\"medicalInsType1\">"+
    	"<span class=\"sel_o_text\" name=\"sel_span_oth\"> 请选择 </span>"+
    	"<div class=\"sel_o_list i_ul_85\" style=\"display: none;\">"+
    		"<ul><li code=\"甲类\">甲类</li><li code=\"乙类\">乙类</li><li code=\"丙类\">丙类</li><li code=\"其他\">其他</li></ul></div></div></td>"+
    		
        "<td><input id=\"otherdrugsCode\" name=\"otherdrugsCode\" type=\"text\" class=\"input i_s_60\"  /></td>"+
        "<td><input id=\"otheractualPayment\" onblur=\"checkMoney(this);\" name=\"otheractualPayment\" type=\"text\" class=\"input i_s_60\" /></td>"+
        "<td><input id=\"otherownCostRate\" onblur=\"checkRateOth(this);\" name=\"otherownCostRate\" type=\"text\" class=\"input i_s_60\"  />%</td>"+
        "<td><input id=\"otherownCostSAmt\" onblur=\"checkMoneyOth(this);\" name=\"otherownCostSAmt\" type=\"text\" class=\"input i_s_60\" /></td>"+
        "<td><input id=\"otherunitPrice\"  onblur=\"checkMoney(this);\" name=\"otherunitPrice\" type=\"text\" class=\"input i_s_60\" /></td>"+
        "<td><span class=\"check_no\" onclick=\"cvtCheckOth(this)\"></span></td>"+
        "<td colspan=\"2\"><input type=\"text\" class=\" input i_s_100\" id=\"excludeReason\" name=\"excludeReason\" /></td>"+
      "</tr>";
	}else{
//		var myStr = strbuf.split(":");
//		var myStrCode=strbuf.split(",").subString
//		var xstr = "";
//		for (var i=0;i<myStr.length-1 ;i++ ){ 
//			xstr +="<li code=\""+myStr[i]+"\" onclick=\"checkItemName(this.id)\">"+myStr[i]+"</li>";
//			} 
		var myStr = strbuf.split(":");
		var xstr = "";
		for (var i=0;i<myStr.length-1 ;i++ ){ 
			var itemCode=myStr[i].substring(0,6);
			var itemName=myStr[i].substring(7);
			xstr +="<li code=\""+itemName+"\" id=\""+itemCode+"\" onclick=\"checkItemName(this.id)\">"+itemName+"</li>";
			} 
		var tr = "<tr id=\"addnewtr\" onclick=\"choosOtherEd(this)\">"+
	            "<td><input id=\"otherproductName\" name=\"otherproductName\" type=\"text\" class=\"input i_s_60\" autocomplete=\"off\" onfocus=\"bundleOthTip(this)\" onkeyup=\"otherCostInfoChoose(this)\" onkeydown=\"otherCostInfoChoose(this)\" /></td>"+
	            //"<td><input id=\"otherexpenseName\" name=\"otherexpenseName\" type=\"text\" class=\"input i_s_60\" /></td>"+
	            "<td><div class=\"select_o i_s_60\" id=\"otherexpenseName\"><span class=\"sel_o_text\" name=\"otherexpenseName\">请选择"+
	 		   "</span><div class=\"sel_o_list i_ul_85\" style=\"display: none;\"><ul>"+xstr+"</ul></div></div></td>" +
//	            "<td><input id=\"othermedicalInsType\" name=\"othermedicalInsType\" type=\"text\" class=\"input i_s_60\" /></td>"+
	            "<td><div class=\"select_o i_s_60\" id=\"medicalInsType1\" name=\"medicalInsType1\">"+
	        	"<span class=\"sel_o_text\" name=\"sel_span_oth\"> 请选择 </span>"+
	        	"<div class=\"sel_o_list i_ul_85\" style=\"display: none;\">"+
	        		"<ul><li code=\"甲类\">甲类</li><li code=\"乙类\">乙类</li><li code=\"丙类\">丙类</li><li code=\"其他\">其他</li></ul></div></div></td>"+
	        		
	            "<td><input id=\"otherdrugsCode\" name=\"otherdrugsCode\" type=\"text\" class=\"input i_s_60\"  /></td>"+
	            "<td><input id=\"otheractualPayment\" onblur=\"checkMoney(this);\" name=\"otheractualPayment\" type=\"text\" class=\"input i_s_60\" /></td>"+
	            "<td><input id=\"otherownCostRate\" onblur=\"checkRateOth(this);\" name=\"otherownCostRate\" type=\"text\" class=\"input i_s_60\"  />%</td>"+
	            "<td><input id=\"otherownCostSAmt\" onblur=\"checkMoneyOth(this);\" name=\"otherownCostSAmt\" type=\"text\" class=\"input i_s_60\" /></td>"+
	            "<td><input id=\"otherunitPrice\"  onblur=\"checkMoney(this);\" name=\"otherunitPrice\" type=\"text\" class=\"input i_s_60\" />" +
	            "<input id=\"otheritemCode\" name=\"otheritemCode\" type=\"hidden\" class=\"input i_s_60\" /></td>"+
	          "</tr>";
	}
	
	
	$("#rcptOtherCostInfoTbl").append(tr);
	selected();
}
function cvtCheck(obj){
	if($(obj).attr("class")=="check_no"){
		$(obj).attr("class","check_yes");
		$("#billDetailTable tr").each(function(){
			var text=$(this).children("td:first").text();
			
			if(text==$(obj).parent().parent().find("input").eq(1).val()){
//				$(this).find("input").eq(1).val();
				
				if($(obj).attr("class")=="check_no"){
					$(this).find("input").eq(5).val($(obj).parent().parent().find("input").eq(3).val());
					if($(obj).parent().parent().find("input").eq(3).val()==$(obj).parent().parent().find("input").eq(5).val()){
						if(isNaN($(this).find("input").eq(1).val())){
							$(this).find("input").eq(1).val(0);
						}
						$(this).find("input").eq(1).val(parseFloat($(this).find("input").eq(1).val())-parseFloat($(obj).parent().parent().find("input").eq(5).val()));
					}
					if(parseFloat($(obj).parent().parent().find("input").eq(5).val())<parseFloat($(obj).parent().parent().find("input").eq(3).val())){
						if(isNaN($(this).find("input").eq(2).val())){
							$(this).find("input").eq(2).val(0);
						}
						$(this).find("input").eq(2).val(parseFloat($(this).find("input").eq(2).val())-parseFloat($(obj).parent().parent().find("input").eq(5).val()));
					}
				}
				if($(obj).attr("class")=="check_yes"){
//					$(this).find("input").eq(5).val(parseFloat($(this).find("input").eq(5).val())-parseFloat($(obj).parent().parent().find("input").eq(3).val()));
					if($(obj).parent().parent().find("input").eq(3).val()==$(obj).parent().parent().find("input").eq(5).val()){
						if(isNaN($(this).find("input").eq(1).val())){
							$(this).find("input").eq(1).val(0);
						}
						$(this).find("input").eq(1).val(parseFloat($(this).find("input").eq(1).val())+parseFloat($(obj).parent().parent().find("input").eq(5).val()));
					}
					if(parseFloat($(obj).parent().parent().find("input").eq(5).val())<parseFloat($(obj).parent().parent().find("input").eq(3).val())){
						if(isNaN($(this).find("input").eq(2).val())){
							$(this).find("input").eq(2).val(0);
						}
						$(this).find("input").eq(2).val(parseFloat($(this).find("input").eq(2).val())+parseFloat($(obj).parent().parent().find("input").eq(5).val()));
					}
				}
				return;
			}
		});
	}else{
		$(obj).attr("class","check_no");
		$("#billDetailTable tr").each(function(){
			var text=$(this).children("td:first").text();
			
			if(text==$(obj).parent().parent().find("input").eq(1).val()){
//				$(this).find("input").eq(1).val();
				
				if($(obj).attr("class")=="check_no"){
					$(this).find("input").eq(5).val($(obj).parent().parent().find("input").eq(3).val());
					if($(obj).parent().parent().find("input").eq(3).val()==$(obj).parent().parent().find("input").eq(5).val()){
						var aaa = $(this).find("input").eq(1).val();
						if(aaa==""){
							aaa=0.0;
							if(!isNaN(aaa)){
								$(this).find("input").eq(1).val(parseFloat(aaa)-parseFloat($(obj).parent().parent().find("input").eq(5).val()));
							}
						}
					}
					if(parseFloat($(obj).parent().parent().find("input").eq(5).val())<parseFloat($(obj).parent().parent().find("input").eq(3).val())){
						if(isNaN($(this).find("input").eq(2).val())){
							$(this).find("input").eq(2).val(0);
						}
						$(this).find("input").eq(2).val(parseFloat($(this).find("input").eq(2).val())-parseFloat($(obj).parent().parent().find("input").eq(5).val()));
					}
				}
				if($(obj).attr("class")=="check_yes"){
//					$(this).find("input").eq(5).val(parseFloat($(this).find("input").eq(5).val())-parseFloat($(obj).parent().parent().find("input").eq(3).val()));
					if($(obj).parent().parent().find("input").eq(3).val()==$(obj).parent().parent().find("input").eq(5).val()){
						if(isNaN($(this).find("input").eq(1).val())){
							$(this).find("input").eq(1).val(0);
						}
						$(this).find("input").eq(1).val(parseFloat($(this).find("input").eq(1).val())+parseFloat($(obj).parent().parent().find("input").eq(5).val()));
					}
					if(parseFloat($(obj).parent().parent().find("input").eq(5).val())<parseFloat($(obj).parent().parent().find("input").eq(3).val())){
						if(isNaN($(this).find("input").eq(2).val())){
							$(this).find("input").eq(2).val(0);
						}
						$(this).find("input").eq(2).val(parseFloat($(this).find("input").eq(2).val())+parseFloat($(obj).parent().parent().find("input").eq(5).val()));
					}
				}
				return;
			}
		});
	}
}
function cvtCheckOth(obj){
//	function checkOthNo(obj,index){
//		alert($(obj).parent().parent().find("input").eq(1).val());
//		明细中勾选剔除，与账单列表的联动关系：
//		若明细中勾选剔除，免责扣款=剔除记录的发生金额，
//		若自付金额=发生金额，自费金额=自费金额-剔除记录的自付金额；
//		若若自付金额<发生金额，分类自付=分类自付-剔除记录的自付金额；
	if($(obj).attr("class")=="check_no"){
		$(obj).attr("class","check_yes");
		$("#billDetailTable tr").each(function(){
			var text=$(this).children("td:first").text();
			if(text==$(obj).parent().parent().find("span").eq(0).text()){
				var deductionsAmt=$(this).find("input").eq(5).val();
				var otheractualPayment=$(obj).parent().parent().find("input").eq(2).val();
				var otherownCostSAmt=$(obj).parent().parent().find("input").eq(4).val();
				var ownAmtSum=$("#ownAmtSum").val();
				if(deductionsAmt==""){
					deductionsAmt=0;
				}
//				var a = (parseFloat(deductionsAmt)*100+parseFloat(otheractualPayment)*100)/100;
				$(this).find("input").eq(5).val(((parseFloat(deductionsAmt)*100+parseFloat(otheractualPayment)*100)/100).toFixed(2));
				$("#deductionsAmtSum").val(((parseFloat(otheractualPayment)*100+parseFloat($("#deductionsAmtSum").val())*100)/100).toFixed(2));
//				$(this).find("input").eq(5).val(otheractualPayment);
					if(parseFloat(otheractualPayment)==parseFloat(otherownCostSAmt)){
						var ownAmt = $.trim($(this).find("input").eq(1).val());
						if(ownAmt==""||isNaN(ownAmt)){
							ownAmt=0.0;
						}
						if((parseFloat(ownAmt)*100-parseFloat(otherownCostSAmt)*100)/100<0){
							alert("自费金额不可以小于0");
							$(this).find("input").eq(5).val(deductionsAmt);
							$(obj).attr("class","check_no");
						}else{
							$(this).find("input").eq(1).val(((parseFloat(ownAmt)*100-parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
							$("#ownAmtSum").val(((parseFloat($("#ownAmtSum").val())*100-parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
						}
					}
					if(parseFloat(otherownCostSAmt)<parseFloat(otheractualPayment)){
						var divAmt=$(this).find("input").eq(2).val();
						if(divAmt==""||isNaN(divAmt)){
							divAmt=0.0;
						}
//						(number1 * 100 + number2 * 100) / 100
						if((parseFloat(divAmt)*100-parseFloat(otherownCostSAmt)*100)/100<0){
							alert("分类自付不可以小于0");
							$(this).find("input").eq(5).val(deductionsAmt);
							$(obj).attr("class","check_no");
						}else{
							$(this).find("input").eq(2).val(((parseFloat(divAmt)*100-parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
							$("#divAmtSum").val(((parseFloat($("#divAmtSum").val())*100-parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
						}
				}
				return;
			}
		});

	}else if($(obj).attr("class")=="check_yes"){
		$(obj).attr("class","check_no");
		$("#billDetailTable tr").each(function(){
			var text=$(this).children("td:first").text();
			
			if(text==$(obj).parent().parent().find("span").eq(1).val()){
				var deductionsAmt=$(this).find("input").eq(5).val();
				var otheractualPayment=$(obj).parent().parent().find("input").eq(2).val();
				var otherownCostSAmt=$(obj).parent().parent().find("input").eq(4).val();
				$(this).find("input").eq(5).val(((parseFloat(deductionsAmt)*100-parseFloat(otheractualPayment)*100)/100).toFixed(2));
				$("#deductionsAmtSum").val(((parseFloat($("#deductionsAmtSum").val())*100-parseFloat(otheractualPayment)*100)/100).toFixed(2));
					if(parseFloat(otheractualPayment)==parseFloat(otherownCostSAmt)){
						var ownAmt = $.trim($(this).find("input").eq(1).val());
						if(ownAmt==""||isNaN(ownAmt)){
							ownAmt=0.0;
						}
						$(this).find("input").eq(1).val(((parseFloat(ownAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
						$("#ownAmtSum").val(((parseFloat($("#ownAmtSum").val())*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
					}
					if(parseFloat(otherownCostSAmt)<parseFloat(otheractualPayment)){
						var divAmt=$(this).find("input").eq(2).val();
						if(divAmt==""||isNaN(divAmt)){
							divAmt=0.0;
						}
						$(this).find("input").eq(2).val(((parseFloat(divAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
						$("#divAmtSum").val(((parseFloat($("#divAmtSum").val())*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
				}
				return;
			}
		});
	}
}
function choosEd(flag){ 
	$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
	index=$(flag).index();
}
function choosOtherEd(flag){
	 
	$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
	otherIndex=$(flag).index();
}

function delTr(){
	if((index!=-1)&&($("#isBpo").val()=="Y")){			
		var rcptDrugsTr = $("#rcptDrugsBody").find("tr");
		var tr = $(rcptDrugsTr[index]);
		var id=tr.attr("id");
//		if(id=="addnewtr"||id==""){
//			$("#rcptDrugsBody tr:eq("+index+")").remove();
//		}else{
		if(confirm("确认删除此信息？")){
			if(id=="addnewtr"||id==""){
				$("#rcptDrugsBody tr:eq("+index+")").remove();
			}else{
				$.ajax({
			        cache: true,
			        type: "POST",
			        url:"delTr.do",
			        data:{"id":id},
			        async: false,
			        error: function(request) {
			            alert("删除失败！");
			        },
			        success: function(data) {
			        	alert("删除成功！");
			        	$("#rcptDrugsBody tr:eq("+index+")").remove();
			        	//删除药品清单同事更新账单信息
			    		
			    		var projectName = tr.find("SPAN[name='projectName']");
			    		var ownRate = tr.find("INPUT[name='ownRate']");
			    		var ownCostAmt = tr.find("INPUT[name='ownCostAmt']");
			    		var actualPayment = tr.find("INPUT[name='actualPayment']");
			    		var drugActualPaymentPlus=$("#drugActualPaymentPlus").html();
			    		var drugOwnCostAmtPlus=$("#drugOwnCostAmtPlus").html();
			    		var trList = $("#billDetailTable").find("tr");//账单层
			    		for(var j=1;j<trList.length-1;j++){
			    			var tr2=$(trList[j]);
			    			var itemName=tr2.find("INPUT[name='itemName']");
			    			var ownAmt=tr2.find("INPUT[name='ownAmt']");
			    			var divAmt=tr2.find("INPUT[name='divAmt']");
			    			var billAmt=tr2.find("INPUT[name='billAmt']");
			    			if($.trim(projectName.text())==itemName.val()){	
			    				var s=parseFloat(billAmt.val())-parseFloat(actualPayment.val());
			    				billAmt.val(s);				
			    				if(ownRate.val()=="100"||ownCostAmt.val()==actualPayment.val()){				
			    					var a=parseFloat(ownAmt.val())-parseFloat(ownCostAmt.val());
			    					ownAmt.val(a);
			    				}else{
			    					var b=parseFloat(divAmt.val())-parseFloat(ownCostAmt.val());
			    					divAmt.val(b);
			    				}	
			    			}
			    		}
			    		sumMoney('');//更新账单信息
			    		dValue();

			    		var d=drugActualPaymentPlus;
			    		if(actualPayment.val()!=""&&actualPayment.val()!="0")
			    			d=parseFloat(drugActualPaymentPlus)-parseFloat(actualPayment.val());
		    			if(d<=0)
			    			$("#drugActualPaymentPlus").html("0");
			    		else
			    			$("#drugActualPaymentPlus").html(d.toFixed(2));
		    			var e=drugOwnCostAmtPlus;
			    		if(ownCostAmt.val()!=""&&ownCostAmt.val()!="0")
			    			e=parseFloat(drugOwnCostAmtPlus)-parseFloat(ownCostAmt.val());
			    		if(e<=0)
			    			$("#drugOwnCostAmtPlus").html("0");
			    		else
			    			$("#drugOwnCostAmtPlus").html(e.toFixed(2));
			        }
			    });
			}
		}					
	}else if((index!=-1)&&($("#isBpo").val()!="Y")){
		$("#rcptDrugsBody tr:eq("+index+")").remove();
	}
	index=-1;
}

function delOtherTr(){ 
/*//	if(otherIndex!=0){
		if(otherIndex!=0){
			if($("#rcptOtherCostInfoTbl tr:eq("+otherIndex+")").find("span").eq(2).attr("class")=="check_yes"){
				$("#billDetailTable tr").each(function(){
					var text=$(this).children("td:first").text();
					if(text==$.trim($("#rcptOtherCostInfoTbl tr:eq("+otherIndex+")").find("span").eq(0).text())){
						var deductionsAmt=$(this).find("input").eq(5).val();
						var otheractualPayment=$("#rcptOtherCostInfoTbl tr:eq("+otherIndex+")").find("input").eq(2).val();
						var otherownCostSAmt=$("#rcptOtherCostInfoTbl tr:eq("+otherIndex+")").find("input").eq(4).val();
						var deductionsAmtSum=$("#deductionsAmtSum").val();
						$(this).find("input").eq(5).val(otheractualPayment);
						var a = ((parseFloat(deductionsAmt)*100-parseFloat(otheractualPayment)*100)/100).toFixed(2);
						$(this).find("input").eq(5).val(a);
						$("#deductionsAmtSum").val((parseFloat(deductionsAmtSum)-parseFloat(otheractualPayment)).toFixed(2));
							if(parseFloat(otheractualPayment)==parseFloat(otherownCostSAmt)){
								var ownAmt = $.trim($(this).find("input").eq(1).val());
								if(ownAmt==""||isNaN(ownAmt)){
									ownAmt=0.0;
								}
								$(this).find("input").eq(1).val(((parseFloat(ownAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
								$("#ownAmtSum").val((parseFloat($("#ownAmtSum").val())+parseFloat(otherownCostSAmt)).toFixed(2));
							}
							if(parseFloat(otherownCostSAmt)<parseFloat(otheractualPayment)){
								var divAmt=$(this).find("input").eq(2).val();
								if(divAmt==""||isNaN(divAmt)){
									divAmt=0.0;
								}
								$(this).find("input").eq(2).val(((parseFloat(divAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
								$("#divAmtSum").val((parseFloat($("#divAmtSum").val())+parseFloat(otherownCostSAmt)).toFixed(2));
						}
						return;
					}
				});
			}
			//删除其他费用清单同时更新账单信息
			var rcptOtherCostInfoTr = $("#rcptOtherCostInfoTbl").find("tr");//其他费用明细
			var tr = $(rcptOtherCostInfoTr[otherIndex]);
			var otherexpenseName = tr.find("SPAN[name='otherexpenseName']");//其他费用项目名称
			var otherownCostRate = tr.find("INPUT[id='otherownCostRate']");
			var otherownCostSAmt = tr.find("INPUT[id='otherownCostSAmt']");
			var otheractualPayment = tr.find("INPUT[id='otheractualPayment']");
			var otherActualPaymentPlus=$("#otherActualPaymentPlus").html();
			var otherownCostPlus=$("#otherownCostPlus").html();
			var trList = $("#billDetailTable").find("tr");//账单层
			for(var j=1;j<trList.length-1;j++){
				var tr2=$(trList[j]);
				var itemName=tr2.find("INPUT[name='itemName']");
				var ownAmt=tr2.find("INPUT[name='ownAmt']");
				var divAmt=tr2.find("INPUT[name='divAmt']");
				var billAmt=tr2.find("INPUT[name='billAmt']");
				if($.trim(otherexpenseName.text())==itemName.val()){	
					var s=parseFloat(billAmt.val())-parseFloat(otheractualPayment.val());
					billAmt.val(s);				
					if(otherownCostRate.val()=="100"||otherownCostSAmt.val()==otheractualPayment.val()){				
						var a=parseFloat(ownAmt.val())-parseFloat(otherownCostSAmt.val());
						ownAmt.val(a);
					}else{
						var b=parseFloat(divAmt.val())-parseFloat(otherownCostSAmt.val());
						divAmt.val(b);
					}	
				}
			}
			sumMoney('');//更新账单信息
			sumTreatmentTime('');
			var d=otherActualPaymentPlus-parseFloat(otheractualPayment.val());
			if(d<=0)
				$("#otherActualPaymentPlus").html("0");
			else
				$("#otherActualPaymentPlus").html(d);
			var e=otherownCostPlus-parseFloat(ownCostAmt.val());
			if(e<=0)
				$("#otherownCostPlus").html("0");
			else
				$("#otherownCostPlus").html(e);
			$("#rcptOtherCostInfoTbl tr:eq("+otherIndex+")").remove();
		}*/
	if((otherIndex!=-1)&&($("#isBpo").val()=="Y")){//传统
		var rcptOtherCostInfoTr = $("#receiptInfoBody").find("tr");//其他费用明细
		var tr = $(rcptOtherCostInfoTr[otherIndex]);
		var id=tr.attr("id");
		if(confirm("确认删除此信息？")){
			if(id=="addnewtr"||id==""){
				$("#receiptInfoBody tr:eq("+otherIndex+")").remove();
			}else{
				$.ajax({
			        cache: true,
			        type: "POST",
			        url:"delOtherTr.do",
			        data:{"id":id},
			        async: false,
			        error: function(request) {
			            alert("删除失败！");
			        },
			        success: function(data) {
			        	alert("删除成功！");		
			        	$("#receiptInfoBody tr:eq("+otherIndex+")").remove();
					//删除其他费用清单同时更新账单信息				
					var otherexpenseName = tr.find("SPAN[name='otherexpenseName']");//其他费用项目名称
					if($.trim(otherexpenseName.text())=="手术材料费"){
						otherexpenseName.text("手术费");
					}
					var otherownCostRate = tr.find("INPUT[id='otherownCostRate']");
					var otherownCostSAmt = tr.find("INPUT[id='otherownCostSAmt']");
					var otheractualPayment = tr.find("INPUT[id='otheractualPayment']");
					var otherActualPaymentPlus=$("#otherActualPaymentPlus").html();
					var otherownCostPlus=$("#otherownCostPlus").html();
					var trList = $("#billDetailTable").find("tr");//账单层
					for(var j=1;j<trList.length-1;j++){
						var tr2=$(trList[j]);
						var itemName=tr2.find("INPUT[name='itemName']");
						var ownAmt=tr2.find("INPUT[name='ownAmt']");
						var divAmt=tr2.find("INPUT[name='divAmt']");
						var billAmt=tr2.find("INPUT[name='billAmt']");
						if($.trim(otherexpenseName.text())==itemName.val()){	
							var s=parseFloat(billAmt.val())-parseFloat(otheractualPayment.val());
							billAmt.val(s);				
							if(otherownCostRate.val()=="100"||otherownCostSAmt.val()==otheractualPayment.val()){				
								var a=parseFloat(ownAmt.val())-parseFloat(otherownCostSAmt.val());
								ownAmt.val(a);
							}else{
								var b=parseFloat(divAmt.val())-parseFloat(otherownCostSAmt.val());
								divAmt.val(b);
							}	
						}
					}
					sumMoney('');//更新账单信息
					dValue();
					var d=otherActualPaymentPlus;
					if(otheractualPayment.val()!=""&&otheractualPayment.val()!="0")
						d=parseFloat(otherActualPaymentPlus)-parseFloat(otheractualPayment.val());
					if(d<=0)
						$("#otherActualPaymentPlus").html("0");
					else
						$("#otherActualPaymentPlus").html(d.toFixed(2));
					var e=otherownCostPlus;
					if(otherownCostSAmt.val()!=""&&otherownCostSAmt.val()!="0"){
						e=parseFloat(otherownCostPlus)-parseFloat(otherownCostSAmt.val());
					}
					if(e<=0)
						$("#otherownCostPlus").html("0");
					else
						$("#otherownCostPlus").html(e.toFixed(2));
					
			        }		     
				});
			}
		}
	}else if((otherIndex!=-1)&&($("#isBpo").val()!="Y")){
		if($("#receiptInfoBody tr:eq("+otherIndex+")").find("span").eq(2).attr("class")=="check_yes"){
			$("#billDetailTable tr").each(function(){
				var text=$(this).children("td:first").text();
				if(text==$.trim($("#receiptInfoBody tr:eq("+otherIndex+")").find("span").eq(0).text())){
					var deductionsAmt=$(this).find("input").eq(5).val();
					var otheractualPayment=$("#receiptInfoBody tr:eq("+otherIndex+")").find("input").eq(2).val();
					var otherownCostSAmt=$("#receiptInfoBody tr:eq("+otherIndex+")").find("input").eq(4).val();
					var deductionsAmtSum=$("#deductionsAmtSum").val();
				/*	$(this).find("input").eq(5).val(otheractualPayment);*/
					var a = ((parseFloat(deductionsAmt)*100-parseFloat(otheractualPayment)*100)/100).toFixed(2);
					$(this).find("input").eq(5).val(a);
					$("#deductionsAmtSum").val((parseFloat(deductionsAmtSum)-parseFloat(otheractualPayment)).toFixed(2));
						if(parseFloat(otheractualPayment)==parseFloat(otherownCostSAmt)){
							var ownAmt = $.trim($(this).find("input").eq(1).val());
							if(ownAmt==""||isNaN(ownAmt)){
								ownAmt=0.0;
							}
							$(this).find("input").eq(1).val(((parseFloat(ownAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
							$("#ownAmtSum").val((parseFloat($("#ownAmtSum").val())+parseFloat(otherownCostSAmt)).toFixed(2));
						}
						if(parseFloat(otherownCostSAmt)<parseFloat(otheractualPayment)){
							var divAmt=$(this).find("input").eq(2).val();
							if(divAmt==""||isNaN(divAmt)){
								divAmt=0.0;
							}
							$(this).find("input").eq(2).val(((parseFloat(divAmt)*100+parseFloat(otherownCostSAmt)*100)/100).toFixed(2));
							$("#divAmtSum").val((parseFloat($("#divAmtSum").val())+parseFloat(otherownCostSAmt)).toFixed(2));
					}
					return;
				}
			});
		}
		$("#receiptInfoBody tr:eq("+otherIndex+")").remove();
	}
	otherIndex=-1;
}

function moneyChoose(){
	$("#moneyTbl").html("");
	var countryName =$.trim($("#countryNameChoose").val());
	if(countryName==""){
		alert("请填写国家名称");
		return;
	}
    $.ajax({  
        type: "POST",  
        url: "countrySearch.do",  
        data:{countryName:countryName},
        success: function(data){
        	var items = data.moneys; 
        	 $.each(items, function(i, n){
        		 $("#moneyTbl").append("<tr id="+items[i].currencySymbol+" onclick=choosEd(this)>" +
               			"<td>"+items[i].countryName+"</td>"+
               			"<td id='chooseCountryName' >"+items[i].currencyChName+"</td>"+
               			"</tr>");
        	 });
        }  
    }); 
}

function medicalChoose(obj){
	$("#medicalTbl").html("");
	var medicalName =$(obj).val();
//	var medicalName =$.trim($("#medicalName").val());
	if(medicalName==null||medicalName==""){
		return;
	}
    $.ajax({  
        type: "POST",  
        url: "medicalSearch.do",  
        data:{medicalName:medicalName},
        success: function(data){
        	var items = data.medicalList; 
        	$("#u-tip").html("");
        	if(items.length>0){
        		for ( var i = 0; i < items.length; i++) {
        			var h = items[i].objId;
//        			alert(items[i].objId);
        			$("#u-tip").append("<li onclick=\"fillInVal(this)\" data-code="+h+" onmouseover=\"changbackclrFn(this)\" >"+items[i].hmMedChName+"</li>");
        			
        		}
        	}
//        	var items = data.medicalList; 
//        	 $.each(items, function(i, n){
//        		 $("#medicalTbl").append("<tr id="+items[i].hmGjypbm+" onclick=\"choosMedicalEd(this)\">" +
//               			"<td id='hmGjypbm'>"+items[i].hmGjypbm+"</td>"+
//               			"<td id='hmMedChName'>"+items[i].hmMedChName+"</td>"+
//               			"<td id='hmType' >"+items[i].hmType+"</td>"+
//               			"<td id='hmMedType'>"+items[i].hmMedType+"</td>"+
//               			"</tr>");
//        	 });
        }  
    }); 
}

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

function saveDiv(id) {
	var tr = $("#moneyTbl tr:eq("+index+")"); 
	var currencySymbol = tr.attr("id"); 
	$("#currencySymbol").val(currencySymbol);
	var spanCurrentcyName = tr.find("td[id='chooseCountryName']").html();
	$("#spanCurrentcyName").html(spanCurrentcyName);
	$.closePopupLayer(id);
}
function saveMedicalDiv(id) {
	var tr = $("#medicalTbl tr:eq("+medicalIndex+")"); 
	var drugsCode = tr.attr("id"); 
	var hmMedType = tr.find("td[id='hmMedType']").html();
	var drugsName = tr.find("td[id='hmMedChName']").html();
	var hmType = tr.find("td[id='hmType']").html();
	var drugstr = $("#rcptDrugsTbl tr:eq("+index+")");
	drugstr.find("INPUT[id='drugsCode']").val(drugsCode);
	drugstr.find("INPUT[id='drugsName']").val(drugsName);
	drugstr.find("INPUT[id='medicalInsType']").val(hmType);
	drugstr.find("INPUT[id='dosageForm']").val(hmMedType);
	
	$.closePopupLayer(id);
}

function sumMoney(moneyInput){
	checkMoney(moneyInput);
	
	var tr = $("#billDetailTable").find("tr");
	var billMoney = 0.00;
	var ownMoney = 0.00;
	var classOwnMoney = 0.00;
	var ybjfMoney = 0.00;
	var dsfzfMoney = 0.00;
	var kftzMoney = 0.00;
	var billAmtSum=$("#billAmtSum").val();
	var ownAmtSum=$("#ownAmtSum").val();
	var divAmtSum=$("#divAmtSum").val();
	var medInsSum=$("#medInsSum").val();
//	var medInsSum=$("#medInsSum").val();
	var medInsSumS=0.00;
	if($("#isBpo").val()=="Y"){
		var overallPay=$("#overallPay").val();
		var attachPay=$("#attachPay").val();
		if(overallPay!="")
			medInsSumS=medInsSumS+parseFloat(overallPay);
		if(attachPay!="")
			medInsSumS=medInsSumS+parseFloat(attachPay);
		$("#medInsSum").val(parseFloat(medInsSumS).toFixed(2));
	}
	medInsSum=$("#medInsSum").val();
	
	for(var i=1;i<tr.length-1;i++){
		var billAmt = $(tr[i]).find("INPUT[id='billAmt']").val();
		var ownAmt = $(tr[i]).find("INPUT[id='ownAmt']").val();
		var divAmt = $(tr[i]).find("INPUT[id='divAmt']").val();
		var medIns = $(tr[i]).find("INPUT[id='medIns']").val();
		var thirdPay = $(tr[i]).find("INPUT[id='thirdPay']").val();		
		var deductionsAmt = $(tr[i]).find("INPUT[id='deductionsAmt']").val();
		if(billAmt!=""){
			billMoney = billMoney+parseFloat(billAmt);
		}
		if(ownAmt!=""){
			ownMoney = ownMoney+parseFloat(ownAmt);
		}
		if(divAmt!=""){
			classOwnMoney = classOwnMoney+parseFloat(divAmt);
		}
		if(medIns!=""){
			ybjfMoney = ybjfMoney+parseFloat(medIns);
		}
		if(thirdPay!=""){
			dsfzfMoney = dsfzfMoney+parseFloat(thirdPay);
		}
		if(deductionsAmt!=""){
			kftzMoney = kftzMoney+parseFloat(deductionsAmt);
		}
		$("#billAmtSum").val(parseFloat(billMoney).toFixed(2));
		$("#ownAmtSum").val(parseFloat(ownMoney).toFixed(2));
		$("#divAmtSum").val(parseFloat(classOwnMoney).toFixed(2));
		if($("#isBpo").val()=="N")
			$("#medInsSum").val(parseFloat(ybjfMoney).toFixed(2));
		$("#thirdPaySum").val(parseFloat(dsfzfMoney).toFixed(2));
		$("#deductionsAmtSum").val(parseFloat(kftzMoney).toFixed(2));
		
		
	}
	//医保支付=(各账单项目的账单金额-自费金额-分类自负)/（账单层账单金额合计-自费金额合计-分类自负合计)*账单层医保支付合计
	if($("#isBpo").val()=="Y"){
		for(var j=1;j<tr.length-1;j++){
			var billAmt1 = $(tr[j]).find("INPUT[id='billAmt']").val();
			var ownAmt1 = $(tr[j]).find("INPUT[id='ownAmt']").val();
			var divAmt1 = $(tr[j]).find("INPUT[id='divAmt']").val();
			var a=(parseFloat(billAmt1)-parseFloat(ownAmt1)-parseFloat(divAmt1));
			var b=(parseFloat(billMoney)-parseFloat(ownMoney)-parseFloat(classOwnMoney));
			var med=0.00;
			if(a>0&&b>0){
				med=(a/b)*parseFloat(medInsSum);
				if(isNaN(med))
					$(tr[j]).find("INPUT[id='medIns']").val("");
				else
					$(tr[j]).find("INPUT[id='medIns']").val(parseFloat(med).toFixed(2));
			}else{
				$(tr[j]).find("INPUT[id='medIns']").val("");
			}
		}								
	}
	dValue();
}
//如果收据信息里面的统筹支付加附加支付的和不等于账单层中所有医保给付金额的和；那么就以统筹支付加附加支付的和为准，在账单层的医保给付金额补上差值
function dValue(){
	var medInsSumS=0.00;
	var medInsS=0.00;
	var tr = $("#billDetailTable").find("tr");
	if($("#isBpo").val()=="Y"){
		var overallPay=$("#overallPay").val();
		var attachPay=$("#attachPay").val();
		if(overallPay!="")
			medInsSumS=medInsSumS+parseFloat(overallPay);
		if(attachPay!="")
			medInsSumS=medInsSumS+parseFloat(attachPay);		
		$("#medInsSum").val(parseFloat(medInsSumS).toFixed(2));		
		for(var i=1;i<tr.length-1;i++){
			var medIns1 = $(tr[i]).find("INPUT[id='medIns']").val();						
			if(medIns1!=""){
				medInsS = medInsS+parseFloat(medIns1);
			}
		}
		var dvalue=parseFloat(medInsSumS)-parseFloat(medInsS);
		for(var j=1;j<tr.length-1;j++){
			var meds=$(tr[j]).find("INPUT[id='medIns']").val();
			if($(tr[j]).find("INPUT[id='billAmt']").val()!=""){//取第一行账单金额不为空的医保给付金额补上差值
				if(meds=="")
					meds=0;
				meds=parseFloat(meds)+parseFloat(dvalue);
				$(tr[j]).find("INPUT[id='medIns']").val(parseFloat(meds).toFixed(2));
				break;
			}			
		}				
	}
}
function checkMoney(moneyInput){
	if($(moneyInput).val()!=""){
//		var mny = /(^\d+$)|(^\d+.\d+$)/g;
		var mny = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
		if(!mny.test($(moneyInput).val())){
			$(moneyInput).val("");
		}
	}
}
function checkMoneyM(moneyInput){
	if($(moneyInput).val()!=""){
//		var mny = /(^\d+$)|(^\d+.\d+$)/g;
		var mny = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
		if(!mny.test($(moneyInput).val())){
			$(moneyInput).val("");
		}
		var a=parseFloat($(moneyInput).parent().parent().find("input").eq(9).val());
		var b=parseFloat($(moneyInput).parent().parent().find("input").eq(7).val());
		var m=Math.round(a/ b * 10000)/100.00;
		if(m>100){
			alert("请录入0%—100%的百分比！");
			$(moneyInput).parent().parent().find("input").eq(8).val("");
		}else{
			if(isNaN(m)){
				$(moneyInput).parent().parent().find("input").eq(8).val("");
				}
				else{
				$(moneyInput).parent().parent().find("input").eq(8).val(m);
				}
		}
	}
}
function checkMoneyOth(moneyInput){
	if($(moneyInput).val()!=""){
//		var mny = /(^\d+$)|(^\d+.\d+$)/g;
		var mny = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
		if(!mny.test($(moneyInput).val())){
			$(moneyInput).val("");
			
//			$(moneyInput).parent().parent().find("input").eq(8).val(parseFloat($(moneyInput).parent().parent().find("input").eq(9).val())/parseFloat($(moneyInput).parent().parent().find("input").eq(9).val()));
		}
		var a=parseFloat($(moneyInput).parent().parent().find("input").eq(4).val());
		var b=parseFloat($(moneyInput).parent().parent().find("input").eq(2).val());
		var m=Math.round(a/ b * 10000)/100.00;
		if(m>100){
			alert("请录入0%—100%的百分比！");
			$(moneyInput).parent().parent().find("input").eq(3).val("");
		}else{
			if(isNaN(m)){
				$(moneyInput).parent().parent().find("input").eq(3).val("");
			}else{
				$(moneyInput).parent().parent().find("input").eq(3).val(m);
			}
		}
	}
}
function sumTreatmentTime(treatmentTimeInput){
	checkCount(treatmentTimeInput);
	var tr2 =$("#billDetailTable").find("tr");
	var treatmentTimeSum = 0;
	for(var i=1;i<tr2.length-1;i++){
		var treatmentTime = $(tr2[i]).find("INPUT[id='treatmentTime']").val();
		if(treatmentTime!=""){
			treatmentTimeSum = treatmentTimeSum + parseInt(treatmentTime);
		}
		$("#treatmentTimeSum").val(parseInt(treatmentTimeSum));
	}
}
//检验次数输入的只能为整数
function checkCount(treatmentTimeInput){
	if($(treatmentTimeInput).val()!=""){
		var treat = /^([1-9][\d]{0,7}|0)?$/;
		if(!treat.test($(treatmentTimeInput).val())){
			$(treatmentTimeInput).val("");
		}
	}
}
//校验自付比例
function checkRate(rate){
	if($(rate).val()!=""){
//		var mny = /(^\d+$)|(^\d+.\d+$)/g;
		var mny = /^([1-9][\d]{0,7}|0)(\.[\d]{1,4})?$/;
		if(!mny.test($(rate).val())){
			$(rate).val("");
		}
	}
	if($(rate).val()!=""&&$(rate).val()!=undefined){
		var num = parseFloat($(rate).val());
		if(num>100||num<0){
			alert("请录入0%—100%的百分比！");
			$(rate).val("");
		}else{
			if($(rate).parent().parent().find("input[id=actualPayment]").val()!=""&&$(rate).parent().parent().find("input[id=actualPayment]").val()!=undefined){
			$(rate).parent().parent().find("input").eq(9).val(($(rate).parent().parent().find("input").eq(7).val()*$(rate).val()*0.01).toFixed(2));
			}
		};
	}
	
}
function checkRateOth(rate){
	if($(rate).val()!=""){
//		var mny = /(^\d+$)|(^\d+.\d+$)/g;
		var mny = /^([1-9][\d]{0,7}|0)(\.[\d]{1,4})?$/;
		if(!mny.test($(rate).val())){
			$(rate).val("");
		}
	}
	if($(rate).val()!=""&&$(rate).val()!=undefined){
		var num = parseFloat($(rate).val());
		if(num>100||num<0){
			alert("请录入0%—100%的百分比！");
			$(rate).val("");
		}else{
			if($(rate).parent().parent().find("input[id=otheractualPayment]").val()!=""&&$(rate).parent().parent().find("input[id=otheractualPayment]").val()!=undefined){
			$(rate).parent().parent().find("input").eq(4).val(($(rate).parent().parent().find("input").eq(2).val()*$(rate).val()*0.01).toFixed(2));
			}
		};
	};
	
};
function convertSumMoney(projectMoney){
	if (null != $("#"+projectMoney).val() && undefined != $("#"+projectMoney).val() && '' != $("#"+projectMoney).val()) {
		return parseFloat($("#"+projectMoney).val());
    }else{
    	return 0.00;
    }
};
function calcYbzfMoney(moneyInput,projectMoney,stuIndex){
	if(moneyInput!=""){
		sumMoney(moneyInput);
		projectMoney = $(moneyInput).val();
	}
	if($(moneyInput).val()!=""&&parseFloat($(moneyInput).val())<=0){
		return ;
	}
	var ybzfMoney = 0.00;
	var ybzfMoneySum = 0.00;
	var dsfzfMoneySum = 0.00;
	var dsfzfMoney = 0.00;
	var trList = $("#billDetailTable").find("tr");
	if(projectMoney!=0.00&&projectMoney!=""&&convertSumMoney("totalAmt")!=0.00){
		ybzfMoney = projectMoney/convertSumMoney("totalAmt")*(convertSumMoney("overallPay")+convertSumMoney("attachPay"));
		dsfzfMoney = projectMoney/convertSumMoney("totalAmt")*convertSumMoney("thirdPay");
		$("#billDetailTable").find("tr:eq("+(parseInt(stuIndex)+1)+")").find("INPUT[id='medIns']").val(ybzfMoney.toFixed(2));
		$("#billDetailTable").find("tr:eq("+(parseInt(stuIndex)+1)+")").find("INPUT[id='thirdPay']").val(dsfzfMoney.toFixed(2));
		for(var i=1;i<trList.length-1;i++){
			var tr = $(trList[i]);
			var medIns = tr.find("INPUT[id='medIns']");
			var thirdPay = tr.find("INPUT[id='thirdPay']");
			if(medIns.val()!=""){
				ybzfMoneySum +=parseFloat(medIns.val());	
			}
			if(thirdPay.val()!=""){
				dsfzfMoneySum +=parseFloat(thirdPay.val());
			}
		}
		$("#medInsSum").val(ybzfMoneySum.toFixed(2));
		$("#thirdPaySum").val(dsfzfMoneySum.toFixed(2));
	}else if(projectMoney==""&&convertSumMoney("totalAmt")!=0.00){
		if(stuIndex!=""){
			$("#billDetailTable").find("tr:eq("+(parseInt(stuIndex)+1)+")").find("INPUT[id='medIns']").val("");
			$("#billDetailTable").find("tr:eq("+(parseInt(stuIndex)+1)+")").find("INPUT[id='thirdPay']").val("");
		}
		for(var i=1;i<trList.length-1;i++){
			var tr = $(trList[i]);
			var trId=tr.attr("id");
			if(trId!="sumMoney"){
				var billAmt = tr.find("INPUT[id='billAmt']");
				var medIns = tr.find("INPUT[id='medIns']");
				var thirdPay = tr.find("INPUT[id='thirdPay']");
				if(billAmt.val()!=""){
					ybzfMoney = parseFloat(billAmt.val())/convertSumMoney("totalAmt")*(convertSumMoney("overallPay")+convertSumMoney("attachPay"));
					dsfzfMoney = parseFloat(billAmt.val())/convertSumMoney("totalAmt")*convertSumMoney("thirdPay");
					ybzfMoneySum+=ybzfMoney;
					dsfzfMoneySum+=dsfzfMoney;
					medIns.val(ybzfMoney.toFixed(2));
					thirdPay.val(dsfzfMoney.toFixed(2));
				}
			}
		}
		$("#medInsSum").val(ybzfMoneySum.toFixed(2));
		$("#thirdPaySum").val(dsfzfMoneySum.toFixed(2));
	}else{
		for(var i=1;i<trList.length;i++){
			var tr = $(trList[i]);
			var billAmt = tr.find("INPUT[id='billAmt']");
			var medIns = tr.find("INPUT[id='medIns']");
			var thirdPay = tr.find("INPUT[id='thirdPay']");
			if(billAmt.val()!=""){
				medIns.val(0.00);
				thirdPay.val(0.00);
			}
		}
	}
	for(var i=1;i<trList.length;i++){
		var billAmtSum=$("#billAmtSum").val();
		var ownAmtSum=$("#ownAmtSum").val();
		var divAmtSum=$("#divAmtSum").val();
		var medInsSum=0.00;
		if($("#isBpo").val()=="Y"){
			var medInsSumS=0.00;
			var overallPay=$("#overallPay").val();
			var attachPay=$("#attachPay").val();
			if(overallPay!="")
				medInsSumS=medInsSumS+parseFloat(overallPay);
			if(attachPay!="")
				medInsSumS=medInsSumS+parseFloat(attachPay);
			$("#medInsSum").val(parseFloat(medInsSumS).toFixed(2));
		}
		medInsSum=$("#medInsSum").val();
		var billAmt = $(trList[i]).find("INPUT[id='billAmt']").val();
		var ownAmt = $(trList[i]).find("INPUT[id='ownAmt']").val();
		var divAmt = $(trList[i]).find("INPUT[id='divAmt']").val();
		
		//医保支付=(各账单项目的账单金额-自费金额-分类自负)/（账单层账单金额合计-自费金额合计-分类自负合计)*账单层医保支付合计
		if($("#isBpo").val()=="Y"){
			var a=(parseFloat(billAmt)-parseFloat(ownAmt)-parseFloat(divAmt));
			var b=(parseFloat(billAmtSum)-parseFloat(ownAmtSum)-parseFloat(divAmtSum));
			var med=0.00;
			if(a>0&&b>0){
				med=((parseFloat(billAmt)-parseFloat(ownAmt)-parseFloat(divAmt))/(parseFloat(billAmtSum)-parseFloat(ownAmtSum)-parseFloat(divAmtSum)))*parseFloat(medInsSum);
				if(isNaN(med))
					$(trList[i]).find("INPUT[id='medIns']").val("");
				else
					$(trList[i]).find("INPUT[id='medIns']").val(parseFloat(med).toFixed(2));
			}else{
				$(trList[i]).find("INPUT[id='medIns']").val("");
			}
				
		}
	}
}
function otherCostInfoChoose(obj){
	$("#medicalTbl").html("");
	var otherexpenseName =$(obj).val();
	if(otherexpenseName==null||otherexpenseName==""){
		return;
	}
	   $.ajax({
	        type: "POST",  
	        url: "rcptOtherCostInfoSearchByName.do",  
	        data:{otherexpenseName:otherexpenseName},
			error :function(){
				alert("费用名称查询失败");
			},
	        success: function(data){
	        	var items = data.clmTreatment; 
	        	$("#u-tip").html("");
	        	if(items.length>0){
	        		for ( var i = 0; i < items.length; i++) {
	        			$("#u-tip").append("<li onclick=\"fillInOthVal(this,"+items[i].objId+")\" onmouseover=\"changbackclrFn(this)\" >"+items[i].dtChName+"</li>");
	        		}
	        	}
	        }  
	    }); 
}
function getPaging(obj){
	var text=$(obj).parent().parent().parent().parent();
	text.empty();
	var content="<input type=\"text\" class=\"input i_s_100\" id=\"excludeReason\" name=\"excludeReason\" />";
	text.html(content);
}
function save(){
	var drugsDetails="";
	var actualPaymentSum=0.00;
	var ownCostAmtSum=0.00;
	var rcptDrugsTr = $("#rcptDrugsTbl").find("tr");
	var trList = $("#billDetailTable").find("tr");//账单层
	for(var i=2;i<rcptDrugsTr.length;i++){
		var tr = $(rcptDrugsTr[i]);
		var trId=tr.attr("id");
		if(trId=="addnewtr"){
			trId="";
		}
		var drugsCode = tr.find("INPUT[name='drugsCode']");
		var drugsName = tr.find("INPUT[name='drugsName']");
		var projectName = tr.find("SPAN[name='projectName']");
		var specifications = tr.find("INPUT[name='specifications']");
		var dosageForm = tr.find("INPUT[name='dosageForm']");
		var units = tr.find("INPUT[name='units']");
		var unitPrice = tr.find("INPUT[name='unitPrice']");
		var quantity = tr.find("INPUT[name='quantity']");
		var actualPayment = tr.find("INPUT[name='actualPayment']");
//		var medicalInsType = tr.find("DIV[name='medicalInsType']");
		var medicalInsType = tr.find("SPAN[name='sel_span']");
		if($.trim(medicalInsType.text())=="请选择"){
			medicalInsType.text("");
		}
		var ownRate = tr.find("INPUT[name='ownRate']");
		var ownCostAmt = tr.find("INPUT[name='ownCostAmt']");
		var itemCode=tr.find("INPUT[name='drugitemCode']").val();
//		for(var j=1;j<trList.length-1;j++){
//			var tr2=$(trList[j]);
//			var itemName=tr2.find("INPUT[name='itemName']");
//			if($.trim(projectName.text())==itemName.val()){
//				itemCode=tr2.attr("id");
//			}
//		}
		if(($.trim(projectName.text())=="请选择")||($.trim(projectName.text())=="")||(itemCode=="")){
			projectName.text("");
			itemCode="0000000";
		}
		var rejectSpan = tr.find("SPAN");
		var costRate = 0.00;
		if(ownRate.val()!=""&&ownRate.val()!=undefined){
			costRate = ownRate.val();
		}
		if(actualPayment.val()!=null&&actualPayment.val()!=undefined&&actualPayment.val()!="")
			actualPaymentSum=actualPaymentSum+parseFloat(actualPayment.val());
		if(ownCostAmt.val()!=null&&ownCostAmt.val()!=undefined&&ownCostAmt.val()!="")
			ownCostAmtSum=ownCostAmtSum+parseFloat(ownCostAmt.val());
		if(drugsCode.val()==""&&drugsName.val()==""&&specifications.val()==""&&dosageForm.val()==""&&units.val()==""
			&&unitPrice.val()==""&&quantity.val()==""&&actualPayment.val()==""&&medicalInsType.val()==""&&ownRate.val()==""
			&&ownCostAmt.val()==""){
			continue;
		}
		drugsDetails+='{"drugsCode":"' + drugsCode.val() + '","id":"' + trId +'","drugsName":"' + drugsName.val()+ '","specifications":"' + specifications.val()+
		'","dosageForm":"' + dosageForm.val()+'","units":"' + units.val()+'","unitPrice":"' + unitPrice.val()+
		'","quantity":"' + quantity.val()+'","actualPayment":"' + actualPayment.val()+'","medicalInsType":"' + $.trim(medicalInsType.text())+
		'","ownRate":"' + costRate+'","ownCostAmt":"' + ownCostAmt.val()+'","billItemCode":"' + itemCode+'","projectName":"' + $.trim(projectName.text())+'"},';
	
	}
	if(drugsDetails.length==0){
		alert("请录入药品信息");
		return;
	}
	drugsDetails = "["+drugsDetails.substring(0,drugsDetails.length-1)+"]";
	jsonStr = '{"rcptDrugsList":' + drugsDetails+',"claimNo":"' + $("#claimNo").val()+'","receiptNo":"' + $("#receiptNo").val()+'","claimEventNo":"' + $("#claimEventNo").val()+'"}';

	$.ajax({
		type:"POST",
		contentType:"application/json; charset=UTF-8",
		url:"saveTr.do",
		data:jsonStr,
		error :function(){
			alert("药品信息收据信息保存失败");
		},
		success :function(data){
			if(data!=null){
				alert("药品明细信息保存成功。");
				showTrList(data);//遍历药品明细信息
				if(isNaN(actualPaymentSum))
					$("#drugActualPaymentPlus").html("0.00");
				else
					$("#drugActualPaymentPlus").html(parseFloat(actualPaymentSum).toFixed(2));
				if(isNaN(ownCostAmtSum))
					$("#drugOwnCostAmtPlus").html("0.00");
				else
					$("#drugOwnCostAmtPlus").html(parseFloat(ownCostAmtSum).toFixed(2));
				saveTrAfter();
				sumMoney('');//更新账单信息
//				dValue();
			}else {
				alert("药品明细信息保存失败。");
			}
		}
	});
}
function saveOtherTr(){
	var rcptOtherCostInfo="";
	var otheractualPaymentSum=0.00;
	var otherownCostSAmtSum=0.00;
	var rcptOtherCostInfoTr = $("#rcptOtherCostInfoTbl").find("tr");
	var trList = $("#billDetailTable").find("tr");//账单层
	for(var i=2;i<rcptOtherCostInfoTr.length;i++){
		var tr = $(rcptOtherCostInfoTr[i]);
		var trId=tr.attr("id");
		if(trId=="addnewtr"){
			trId="";
		}
		var otherproductName = tr.find("INPUT[name='otherproductName']");
		var otherexpenseName = tr.find("SPAN[name='otherexpenseName']");
//		if(otherexpenseName=="手术材料费"){
//			otherexpenseName="手术费";
//		}
//		var otherexpenseName = $("#x889z");
//		var othermedicalInsType = tr.find("INPUT[id='othermedicalInsType']");
		var othermedicalInsType = tr.find("SPAN[name='sel_span_oth']");
		if($.trim(othermedicalInsType.text())=="请选择"){
			othermedicalInsType.text("");
		}
		var otherdrugsCode = tr.find("INPUT[name='otherdrugsCode']");
//		var otherdrugsCode = $("#x890z");
		var otheractualPayment = tr.find("INPUT[id='otheractualPayment']");
		var otherownCostRate = tr.find("INPUT[id='otherownCostRate']");
		var otherownCostSAmt = tr.find("INPUT[id='otherownCostSAmt']");
		var otherunitPrice = tr.find("INPUT[id='otherunitPrice']");
		var costRate = 0.00;
		var itemCode=tr.find("INPUT[name='otheritemCode']").val();
//		var itemCode="";
//		for(var j=1;j<trList.length-1;j++){
//			var tr2=$(trList[j]);
//			var itemName=tr2.find("INPUT[name='itemName']");
//			if($.trim(otherexpenseName.text())==itemName.val()){
//				itemCode=tr2.attr("id");
//			}
//			if($.trim(otherexpenseName.text())=="手术材料费"){
//				itemCode="000003";
//			}
//			
//		}
		if(($.trim(otherexpenseName.text())=="请选择")||(itemCode=="")){
//			otherexpenseName.text("");
			itemCode="0000000";
		}
		if(otherownCostRate.val()!=""&&otherownCostRate.val()!=undefined){
			costRate = otherownCostRate.val();
		}
		if(otherproductName.val()==""&&$.trim(otherexpenseName.text())==""&&othermedicalInsType.val()==""&&otherdrugsCode.val()==""&&otheractualPayment.val()==""
			&&otherownCostRate.val()==""&&otherownCostSAmt.val()==""&&otherunitPrice.val()==""){
			continue;
		}
		if(otheractualPayment.val()!=null&&otheractualPayment.val()!=undefined&&otheractualPayment.val()!="")
			otheractualPaymentSum=otheractualPaymentSum+parseFloat(otheractualPayment.val());
		if(otherownCostSAmt.val()!=null&&otherownCostSAmt.val()!=undefined&&otherownCostSAmt.val()!="")
			otherownCostSAmtSum=otherownCostSAmtSum+parseFloat(otherownCostSAmt.val());
		rcptOtherCostInfo+='{"id":"' + trId + '","productName":"' + $.trim(otherexpenseName.text()) +'","expenseName":"' + otherproductName.val() + '","medicalInsType":"' + $.trim(othermedicalInsType.text())+
		'","drugsCode":"' + otherdrugsCode.val()+'","actualPayment":"' + otheractualPayment.val()+'","ownCostRate":"' + costRate+
		'","ownCostSAmt":"' + otherownCostSAmt.val()+'","billItemCode":"' + itemCode+'","unitPrice":"' + otherunitPrice.val()+
		'"},';
	}
	rcptOtherCostInfo = "["+rcptOtherCostInfo.substring(0,rcptOtherCostInfo.length-1)+"]";
	jsonStr = '{"rcptOtherCostInfo":' + rcptOtherCostInfo+',"claimNo":"' + $("#claimNo").val()+'","receiptNo":"' + $("#receiptNo").val()+'","claimEventNo":"' + $("#claimEventNo").val()+'"}';

	$.ajax({
		type:"POST",
		contentType:"application/json; charset=UTF-8",
		url:"saveOtherTr.do",
		data:jsonStr,
		error :function(){
			alert("其他费用清单信息保存失败");
		},
		success :function(data){
			if(data!=null){
				alert("其他费用清单信息保存成功。");
				showOtherTrList(data);//遍历其他费用清单
				if(isNaN(otheractualPaymentSum))
					otheractualPaymentSum="0.00";
				$("#otherActualPaymentPlus").html(parseFloat(otheractualPaymentSum).toFixed(2));//更新发生金额合计
				if(isNaN(otherownCostSAmtSum))
					otherownCostSAmtSum="0.00";
				$("#otherownCostPlus").html(parseFloat(otherownCostSAmtSum).toFixed(2));//更新自付金额合计
				
				saveOtherTrAfter();
				sumMoney('');//更新账单信息
				dValue();

			}else {
				alert("其他费用清单信息保存失败。");
			}
		}
	});
}

function showTrList(data){
	$("#rcptDrugsBody").html("");
	var strbuf=$("#strbuf").val();
//	var myStr = strbuf.split(":");
//	var xstr = "";
//	for (var i=0;i<myStr.length-1 ;i++ ){ 
//		xstr +="<li code=\""+myStr[i]+"\">"+myStr[i]+"</li>";
//	} 
	var myStr = strbuf.split(":");
	var xstr = "";
	var tr="";
	for (var i=0;i<myStr.length-1 ;i++ ){ 
		var itemCode=myStr[i].substring(0,6);
		var index=myStr[i].indexOf(',');
		var itemName=myStr[i].substring(index+1);
		xstr +="<li code=\""+itemName+"\" id=\""+itemCode+"\" onclick=\"checkItemName(this.id)\">"+itemName+"</li>";
		} 
	for(var i=0;i<data.length;i++){
		var rcptDrugs = data[i];
		 tr += "<tr id=\""+ rcptDrugs.id +"\" onclick=\"choosEd(this)\">"+
		"<td><input readonly=\"readonly\" id=\"drugsCode\" name=\"drugsCode\" type=\"text\" class=\"input i_s_60\" value=\""+ rcptDrugs.drugsCode +"\" /></td>"+
	    "<td ><input id=\"drugsName\" name=\"drugsName\" type=\"text\" class=\"input i_s_60\" autocomplete=\"off\" onfocus=\"bundleTip(this)\" onkeyup=\"medicalChoose(this)\" onkeydown=\"medicalChoose(this)\" value=\""+ rcptDrugs.drugsName +"\"/>" +
	    "</td>"+
	    "<td>" +
	    	"<div class=\"select_d i_s_60\" id=\"projectName\">" +
	    		"<span class=\"sel_d_text\" name=\"projectName\">"+ (rcptDrugs.projectName!=""?rcptDrugs.projectName:"请选择") +"</span>" +
	    		"<div class=\"sel_d_list i_ul_85\" style=\"display: none;\">" +
	    			"<ul>"+xstr+"</ul>" +
	    		"</div>" +
	    	"</div>" +
	    "</td>"+
	    "<td><input id=\"specifications\" name=\"specifications\" type=\"text\" class=\"input i_s_60\" value=\""+ (rcptDrugs.specifications==null?"":rcptDrugs.specifications) +"\" /></td>"+
	    "<td><input readonly=\"readonly\" id=\"dosageForm\" name=\"dosageForm\" type=\"text\" class=\"input i_s_60\" value=\""+ (rcptDrugs.dosageForm==null?"":rcptDrugs.dosageForm) +"\"/></td>"+
	    "<td><input id=\"units\" name=\"units\" type=\"text\" class=\"input i_s_60\" value=\""+ rcptDrugs.units +"\" /></td>"+
	    "<td><input id=\"unitPrice\" onblur=\"checkMoney(this);\" name=\"unitPrice\" type=\"text\" class=\"input i_s_60\" value=\""+ (rcptDrugs.unitPrice==null?"":rcptDrugs.unitPrice) +"\" /></td>"+
	    "<td><input id=\"quantity\"  onblur=\"checkMoney(this);\" name=\"quantity\" type=\"text\" class=\"input i_s_60\" value=\""+ (rcptDrugs.quantity==null?"":rcptDrugs.quantity) +"\"/></td>"+
	    "<td><input id=\"actualPayment\"  onblur=\"checkMoney(this);\" name=\"actualPayment\" type=\"text\" class=\"input i_s_60\" value=\""+ (rcptDrugs.actualPayment==null?"":rcptDrugs.actualPayment) +"\"/></td>"+
	 	"<td><div class=\"select_d i_s_60\" id=\"medicalInsType\" name=\"medicalInsType\" >"+
		"<span class=\"sel_d_text\" name=\"sel_span\">" +(rcptDrugs.medicalInsType!=""?rcptDrugs.medicalInsType:"请选择")+ "</span>"+
		"<div class=\"sel_d_list i_ul_85\" style=\"display: none;\">"+
			"<ul><li code=\"甲类\">甲类</li><li code=\"乙类\">乙类</li><li code=\"丙类\">丙类</li><li code=\"其他\">其他</li></ul></div></div></td>"+
			
	    "<td><input id=\"ownRate\" onblur=\"checkRate(this);\" name=\"ownRate\" type=\"text\" class=\"input i_s_60\" value=\""+ (rcptDrugs.ownRate==null?"":rcptDrugs.ownRate) +"\" />%</td>"+
	    "<td><input id=\"ownCostAmt\" onblur=\"checkMoneyM(this);\" name=\"ownCostAmt\" type=\"text\" class=\"input i_s_60\" value=\""+ (rcptDrugs.ownCostAmt==null?"":rcptDrugs.ownCostAmt) +"\" />" +
	    		"<input id=\"drugitemCode\" name=\"drugitemCode\" type=\"hidden\" class=\"input i_s_60\"  value=\""+ rcptDrugs.billItemCode +"\"/></td>"+	    
	    "</tr>";
		
		 
	}
	 $("#rcptDrugsBody").append(tr);
	selectedrug();
}

function showOtherTrList(data){
	
	$("#receiptInfoBody").html("");
	var strbuf=$("#strbuf").val();
//	var myStr = strbuf.split(":");
//	var xstr = "";
//	for (var i=0;i<myStr.length-1 ;i++ ){ 
//		xstr +="<li code=\""+myStr[i]+"\">"+myStr[i]+"</li>";
//	} 
	var myStr = strbuf.split(":");
	var xstr = "";
	var tr="";
	for (var i=0;i<myStr.length-1 ;i++ ){ 
		var itemCode=myStr[i].substring(0,6);
		var index=myStr[i].indexOf(',');
		var itemName=myStr[i].substring(index+1);
		xstr +="<li code=\""+itemName+"\" id=\""+itemCode+"\" onclick=\"checkItemName(this.id)\">"+itemName+"</li>";
		} 
	for(var i = 0 ; i < data.length; i++){
		
		var rcptOtherCostInfo = data[i];
		
		tr+= "<tr id=\"" + rcptOtherCostInfo.id + "\" onclick=\"choosOtherEd(this)\">"+
        "<td><input id=\"otherproductName\" name=\"otherproductName\" type=\"text\" class=\"input i_s_60\" autocomplete=\"off\" onfocus=\"bundleOthTip(this)\" onkeyup=\"otherCostInfoChoose(this)\" onkeydown=\"otherCostInfoChoose(this)\" value=\"" + rcptOtherCostInfo.expenseName + "\" /></td>"+
        "<td>" +
        	"<div class=\"select_o i_s_60\" id=\"otherexpenseName\">" +
        		"<span class=\"sel_o_text\" name=\"otherexpenseName\">" + (rcptOtherCostInfo.productName!=""?rcptOtherCostInfo.productName:"请选择") + "</span>" +
        		"<div class=\"sel_o_list i_ul_85\" style=\"display: none;\">" +
        			"<ul>"+xstr+"</ul>" +
        		"</div>" +
        	"</div>" +
        "</td>" +
        "<td>" +
        	"<div class=\"select_o i_s_60\" id=\"medicalInsType1\" name=\"medicalInsType1\" >"+
	        	"<span class=\"sel_o_text\" name=\"sel_span_oth\">" + (rcptOtherCostInfo.medicalInsType!=""?rcptOtherCostInfo.medicalInsType:"请选择") + "</span>"+
	        	"<div class=\"sel_o_list i_ul_85\" style=\"display: none;\">"+
	    			"<ul><li code=\"甲类\">甲类</li><li code=\"乙类\">乙类</li><li code=\"丙类\">丙类</li><li code=\"其他\">其他</li></ul>" +
	    		"</div>" +
	    	"</div>" +
	    "</td>"+
    	"<td><input id=\"otherdrugsCode\" name=\"otherdrugsCode\" type=\"text\" class=\"input i_s_60\" value=\"" + (rcptOtherCostInfo.drugsCode == null?"":rcptOtherCostInfo.drugsCode) + "\" /></td>"+
        "<td><input id=\"otheractualPayment\" onblur=\"checkMoney(this);\" name=\"otheractualPayment\" type=\"text\" class=\"input i_s_60\" value=\"" + (rcptOtherCostInfo.actualPayment == null ? "":rcptOtherCostInfo.actualPayment) + "\" /></td>"+
        "<td><input id=\"otherownCostRate\" onblur=\"checkRateOth(this);\" name=\"otherownCostRate\" type=\"text\" class=\"input i_s_60\" value=\"" + (rcptOtherCostInfo.ownCostRate == null ? "" : rcptOtherCostInfo.ownCostRate) + "\" />%</td>"+
        "<td><input id=\"otherownCostSAmt\" onblur=\"checkMoneyOth(this);\" name=\"otherownCostSAmt\" type=\"text\" class=\"input i_s_60\" value=\"" + (rcptOtherCostInfo.ownCostSAmt == null ? "" : rcptOtherCostInfo.ownCostSAmt) + "\" /></td>"+
        "<td><input id=\"otherunitPrice\"  onblur=\"checkMoney(this);\" name=\"otherunitPrice\" type=\"text\" class=\"input i_s_60\" value=\"" + (rcptOtherCostInfo.unitPrice == null ? "" : rcptOtherCostInfo.unitPrice) + "\" />" +
        		"<input id=\"otheritemCode\" name=\"otheritemCode\" type=\"hidden\" class=\"input i_s_60\" value=\"" + rcptOtherCostInfo.billItemCode +"\"/></td>"+
        "</tr>";
	}
	$("#receiptInfoBody").append(tr);
	selected();
}
function saveTrAfter(){
	var trList = $("#billDetailTable").find("tr");//账单层
	var rcptDrugsTr = $("#rcptDrugsTbl").find("tr");//药品明细
	var rcptOtherCostInfoTr = $("#rcptOtherCostInfoTbl").find("tr");//其他费用明细
	for(var c=1;c<trList.length-1;c++){
		var tr4=$(trList[c]);
		var itemName=tr4.find("INPUT[name='itemName']").val();
		var bool=false;
		var billAmt2=0.00;
		var ownAmt2=0.00;
		var divAmt2=0.00;
		for(var b=2;b<rcptOtherCostInfoTr.length;b++){
			var tr3=$(rcptOtherCostInfoTr[b]);
			var otherexpenseName = $.trim(tr3.find("SPAN[name='otherexpenseName']").text());//其他费用项目名称
			if(otherexpenseName=="手术材料费"){
				otherexpenseName="手术费";
			}
			if(itemName==otherexpenseName){
				var otherownCostRate=tr3.find("INPUT[name='otherownCostRate']").val();//自付比例
				var otherownCostSAmt=tr3.find("INPUT[name='otherownCostSAmt']").val();//自付金额
				var otheractualPayment=tr3.find("INPUT[name='otheractualPayment']").val();//发生金额
				billAmt2=billAmt2+parseFloat(otheractualPayment);
				if(otherownCostRate=="100"||otherownCostSAmt==otheractualPayment){
					ownAmt2=ownAmt2+parseFloat(otherownCostSAmt);
				}
				if(otherownCostRate!="100"&&otherownCostSAmt!=otheractualPayment&&otherownCostSAmt>0){
					divAmt2=divAmt2+parseFloat(otherownCostSAmt);
				}
				tr4.find("INPUT[name='billAmt']").val(parseFloat(billAmt2).toFixed(2));
				tr4.find("INPUT[name='ownAmt']").val(parseFloat(ownAmt2).toFixed(2));
				tr4.find("INPUT[name='divAmt']").val(parseFloat(divAmt2).toFixed(2));
				bool=true;
//				break;
			}
			
		}
		if(bool==false){
			tr4.find("INPUT[name='billAmt']").val("");
			tr4.find("INPUT[name='ownAmt']").val("");
			tr4.find("INPUT[name='divAmt']").val("");
		}
	}
	
	for(var i=1;i<trList.length-1;i++){
		var tr=$(trList[i]);
		var itemName=tr.find("INPUT[name='itemName']").val();				
		/*var billAmt=0.00;
		var ownAmt=0.00;
		var divAmt=0.00;*/
		var billAmta=tr.find("INPUT[name='billAmt']").val();
		var ownAmta=tr.find("INPUT[name='ownAmt']").val();
		var divAmta=tr.find("INPUT[name='divAmt']").val();
		if(billAmta==""){
			billAmta=0;
		}
		if(ownAmta==""){
			ownAmta=0;
		}
		if(divAmta==""){
			divAmta=0;
		}
		var billAmt=parseFloat(billAmta);
		var ownAmt=parseFloat(ownAmta);
		var divAmt=parseFloat(divAmta);
		for(var j=2;j<rcptDrugsTr.length;j++){
			var tr1=$(rcptDrugsTr[j]);
			var projectName=$.trim(tr1.find("SPAN[name='projectName']").text());//项目名称
			var ownRate=tr1.find("INPUT[name='ownRate']").val();//自付比例
			var ownCostAmt=tr1.find("INPUT[name='ownCostAmt']").val();//自付金额
			var actualPayment=tr1.find("INPUT[name='actualPayment']").val();//发生金额
			if(itemName==projectName){
				if(actualPayment!=""){
					billAmt=billAmt+parseFloat(actualPayment);
				}
				if(ownRate=="100"||ownCostAmt==actualPayment){
					if(ownCostAmt!=""){
						ownAmt=ownAmt+parseFloat(ownCostAmt);
					}
				}
				if(ownRate!="100"&&ownCostAmt!=actualPayment&&ownCostAmt>0){
					divAmt=divAmt+parseFloat(ownCostAmt);
				}
				tr.find("INPUT[name='billAmt']").val(parseFloat(billAmt).toFixed(2));
				tr.find("INPUT[name='ownAmt']").val(parseFloat(ownAmt).toFixed(2));
				tr.find("INPUT[name='divAmt']").val(parseFloat(divAmt).toFixed(2));				
			}
		}		
	}
}
function saveOtherTrAfter(){
	var trList = $("#billDetailTable").find("tr");//账单层
	var rcptOtherCostInfoTr = $("#rcptOtherCostInfoTbl").find("tr");//其他费用明细
	var rcptDrugsTr = $("#rcptDrugsTbl").find("tr");//药品明细
	for(var c=1;c<trList.length-1;c++){
		var tr4=$(trList[c]);
		var itemName=tr4.find("INPUT[name='itemName']").val();
		var bool=false;
		var billAmt2=0.00;
		var ownAmt2=0.00;
		var divAmt2=0.00;
		for(var a=2;a<rcptDrugsTr.length;a++){
			var tr3=$(rcptDrugsTr[a]);
			var projectName=$.trim(tr3.find("SPAN[name='projectName']").text());//项目名称
			if(itemName==projectName){
				var ownRate=tr3.find("INPUT[name='ownRate']").val();//自付比例
				var ownCostAmt=tr3.find("INPUT[name='ownCostAmt']").val();//自付金额
				var actualPayment=tr3.find("INPUT[name='actualPayment']").val();//发生金额
				if(ownRate==""){
					ownRate=0;
				}
				if(ownCostAmt==""){
					ownCostAmt=0;
				}
				if(actualPayment==""){
					actualPayment=0;
				}
				billAmt2=billAmt2+parseFloat(actualPayment);
				if(ownRate=="100"||ownCostAmt==actualPayment){
					ownAmt2=ownAmt2+parseFloat(ownCostAmt);
				}
				if(ownRate!="100"&&ownCostAmt!=actualPayment&&ownCostAmt>0){
					divAmt2=divAmt2+parseFloat(ownCostAmt);
				}
				tr4.find("INPUT[name='billAmt']").val(parseFloat(billAmt2).toFixed(2));
				tr4.find("INPUT[name='ownAmt']").val(parseFloat(ownAmt2).toFixed(2));
				tr4.find("INPUT[name='divAmt']").val(parseFloat(divAmt2).toFixed(2));
				bool=true;
//				break;
			}
		}
		if(bool==false){
			tr4.find("INPUT[name='billAmt']").val("");
			tr4.find("INPUT[name='ownAmt']").val("");
			tr4.find("INPUT[name='divAmt']").val("");
		}
	}
	
	
	
	for(var i=1;i<trList.length-1;i++){
		var tr=$(trList[i]);
		var itemName=tr.find("INPUT[name='itemName']").val();
		var billAmta=tr.find("INPUT[name='billAmt']").val();
		var ownAmta=tr.find("INPUT[name='ownAmt']").val();
		var divAmta=tr.find("INPUT[name='divAmt']").val();
		if(billAmta==""){
			billAmta=0;
		}
		if(ownAmta==""){
			ownAmta=0;
		}
		if(divAmta==""){
			divAmta=0;
		}
		var billAmt=parseFloat(billAmta);
		var ownAmt=parseFloat(ownAmta);
		var divAmt=parseFloat(divAmta);
		
		/*var billAmt=0.00;
		var ownAmt=0.00;
		var divAmt=0.00;*/
		for(var j=2;j<rcptOtherCostInfoTr.length;j++){
			var tr1=$(rcptOtherCostInfoTr[j]);
			var otherexpenseName = $.trim(tr1.find("SPAN[name='otherexpenseName']").text());//其他费用项目名称
			if(otherexpenseName=="手术材料费"){
				otherexpenseName="手术费";
			}
			var otherownCostRate=tr1.find("INPUT[name='otherownCostRate']").val();//自付比例
			var otherownCostSAmt=tr1.find("INPUT[name='otherownCostSAmt']").val();//自付金额
			var otheractualPayment=tr1.find("INPUT[name='otheractualPayment']").val();//发生金额
			if(itemName==otherexpenseName){
				if(otheractualPayment!=""){
					billAmt=billAmt+parseFloat(otheractualPayment);
				}
				if(otherownCostRate=="100"||otherownCostSAmt==otheractualPayment){
					if(otherownCostSAmt!=""){
						ownAmt=ownAmt+parseFloat(otherownCostSAmt);
					}
				}
				if(otherownCostRate!="100"&&otherownCostSAmt!=otheractualPayment&&otherownCostSAmt>0){
					divAmt=divAmt+parseFloat(otherownCostSAmt);
				}
				tr.find("INPUT[name='billAmt']").val(parseFloat(billAmt).toFixed(2));
				tr.find("INPUT[name='ownAmt']").val(parseFloat(ownAmt).toFixed(2));
				tr.find("INPUT[name='divAmt']").val(parseFloat(divAmt).toFixed(2));				
			}
		}
	}	
}
//function getSel(obj){
//	alert($(obj).parent().html());
//	var text=$(obj).parent();
//	var content="<div class=\"select i_s_24\" id=\"excludeReason\">"+
//				"<span class=\"sel_text\" name=\"t_sel_span\"> 请选择</span>"+
//				"<div class=\"sel_list i_ul_265\" style=\"display: none;\"><ul>"+
//		"<li code=\"医保范围之外\">医保范围之外</li>"+
//		"<li code=\"责任免除\">责任免除</li>"+
//		"<li code=\"其他\" onclick=\"getPaging(this);\">其他</li>"+
//		"</ul></div></div>";
//text.html(content);
//selected();
//}
//修改其他费用信息的项目名称把对应的项目代码放到隐藏控件otheritemCode中
function checkItemName(obj){
	var rcptOtherCostInfoTr = $("#receiptInfoBody").find("tr");
	var tr=$(rcptOtherCostInfoTr[otherIndex]);
	tr.find("INPUT[name='otheritemCode']").val(obj);
}
//修改药品信息的项目名称把对应的项目代码放到隐藏控件drugitemCode中
function checkDrugItemName(obj){
	var trList = $("#rcptDrugsBody").find("tr");
	var tr = $(trList[index]);
	tr.find("INPUT[name='drugitemCode']").val(obj);
}