var productList='';
var index = -1;
var applyPresonInfo='';

//$(function() {
//	$("#saveInfo").attr("onclick");
//	$("#saveInfo").trigger("click");
//	$(document).ready(function(){ 
//		$("#saveInfo").attr("onclick");
//	});
//});

$(function(){
	var inputSource=$("#inputSource").val();
	var infoList=$("#infoList").val();
	if(inputSource=='05'&&infoList==''){//app录入方式       
		alert("医疗机构不匹配！");
	}
	if($("#ylxxIllsBy_").val() !='' && $("#ylxxIllsBy_").val()!=undefined){
		showylxxDiv('init');
	}
	if($("#claimIllsBy_").val() !='' && $("#claimIllsBy_").val() !=undefined){
		showjvDiv('init');
	}
	if($("#sqxmIllsBy_").val() !='' && $("#sqxmIllsBy_").val()!=undefined){
		showsqxmDiv('init');
	}
	getProductList();
	if($("#totalAmt").val()==null ||$("#totalAmt").val()==""){
		calculateAmount();
	}
	if($("#amt").val()==null ||$("#amt").val()==""){
		addPrejectAmt();
	}
	
	if($("#preState").val()=="02" && $("#preSubState").val()=="04"){
		$("#saveInfo").removeAttr("onclick");
		$("#shjlBtn").removeAttr("onclick");
		if($("#preAuditRes").val()=="Y"){
			$("#noticeBtn").attr("onclick","showBotOpen('botOpen2',this)");
		}else{
			$("#noticeBtn").attr("onclick","showBotOpen('botOpen3',this)");
		}
		$("#submitBtn").attr("onclick","saveAllInfo('complete')");
		if($("#hangup"))
			$("#hangup").removeAttr("onclick");
	}
	//挂起状态，仅影像可以看，其他remove
	if($("#preState").val()=="02" && $("#preSubState").val()=="07"){
		$("#saveInfo").removeAttr("onclick");
		$("#cancel").removeAttr("onclick");
		$("#hangup").removeAttr("onclick");
		$("#shjlBtn").removeAttr("onclick");
		$("#noticeBtn").removeAttr("onclick");
		$("#submitBtn").removeAttr("onclick");
	}
	
		
//		$("#shjlBtn").removeAttr("onclick");
//		$("#noticeBtn").removeAttr("onclick");
//		$("#submitBtn").removeAttr("onclick");
//	}else{
//		$("#shjlBtn").attr("onclick","showBotOpen('botOpen1',this)");
//		$("#noticeBtn").attr("onclick","showBotOpen('botOpen2',this)");
//		$("#submitBtn").attr("onclick","submitData('complete')");
//	}
	consAppHospitalFn('','applyHospital','applyAgency','');
	checkSex('');
	applyPresonInfo=$("#SHcon1").html();
	var dpaId=$("#applyHospitalNamePartnerId").val();
	var tpaId=$("#applyAgencyNamePartnerId").val();
	if(dpaId!=null && dpaId!=""){
		checkApplyInfoFn('1','');
	}else if(tpaId!=null && tpaId!=""){
		checkApplyInfoFn('','1');
	}
	
});

function selectedAllFn(flag){
	if($(flag).is(".check_no")){
		$("#preClassLiabList tr").each(function (){
			$(this).find("td:eq(0)").find("span").attr("class","check_yes");
		});
	}else{
		$("#preClassLiabList tr").each(function (){
			$(this).find("td:eq(0)").find("span").attr("class","check_no");
		});
	}
}

function subselectedAllFn(flag){
	if($(flag).is(".check_yes")){
		$("#allSelected").attr("class","check_no");
	}else{
		var bool=true;
		$("#preClassLiabList tr").each(function (){
			if($(this).find("td:eq(0)").find("span").is(".check_no")){
				bool=false;
				return ;
			}
		});
		if(bool){
			$("#allSelected").attr("class","check_yes");
		}
	}
}


function selected(){
	/*selectBox*/
	$(".select").hover( function () {
		$(this).addClass("sel_over");
	},function () {
		$(this).removeClass("sel_over");
	}).on('click',function(){
		var _this = $(this),
			_bthis = $(this).find(".sel_list");
		if ( _this.attr('isopen') ) {
			_bthis.slideUp(0 , function(){
				_this.removeAttr('isopen');
			});			
		} else {
			_bthis.slideDown(0,function(){
				_this.attr('isopen',"1");
			});	
		}
	}).on('mouseleave',function(){
		var _thisa = $(this).find(".sel_list"),
			_this = $(this);
		_thisa.hide();
		_this.removeAttr('isopen');
	}),
	$(".select").find(".sel_list li").hover( function (){
		$(this).addClass("sel_hov");		
	},function (){
		$(this).removeClass("sel_hov");	
	}).on('click',function(){
		var _this = $(this).html();
		var _code=$(this).attr("code");
		var _thisText = $(this).closest(".select").find(".sel_text");
		_thisText.attr("code",_code);
		_thisText.html(_this);
	});
}

function getProductList(){
	
	$.ajax({
		 type: "POST",  
	     url: "searchAmtProduct.do",
	     data:"",
	     async : false,
	     success:function(data){
	    	 var item = data.billTemplateConfigList;
	    	 productList = '';
	    	for(var i = 0 ;i<item.length;i++){
	    		var info= item[i];
	    		productList +="<li code=\""+info.itemCode+"\">"+info.itemName+"</li>";
	    	}
	     },
	     error:function(data){
	     }
	});
}



var selecti = 0;
function addProduct(){
	var tr = "<tr id=\"addnewtr\" onclick=\"choosEd(this)\">"+
	"<td><div class=\"select select"+selecti+" i_s_100 mar_cen\"><span class=\"sel_text\" code=\"\" >请选择</span>"+
	"<div class=\"sel_list i_ul_125\" style=\"display: none;\" >"+
	"<ul>"+productList+"</ul>"+
	"</div></div></td>"+
	"<td><input type=\"text\" value=\"\"  onblur=\"addPrejectAmt();\" class=\"input i_s_137 input_bot_line\" style=\"text-align:center;\"/></td>"+
	"<td width=\"26%\"><input type=\"text\" class=\"input i_s_60\"  onblur=\"calculateAmount();\"/></td>"+
	"<td width=\"25%\"><input type=\"text\" class=\"input i_s_60\" /></td>"+
	"</tr>";
	$("#productList").append(tr);
	
	/*selectBox*/
	$(".select"+selecti).hover( function () {
		$(this).addClass("sel_over");
	},function () {
		$(this).removeClass("sel_over");
	}).on('click',function(){
		var _this = $(this),
			_bthis = $(this).find(".sel_list");
		if ( _this.attr('isopen') ) {
			_bthis.slideUp(0 , function(){
				_this.removeAttr('isopen');
			});			
		} else {
			_bthis.slideDown(0,function(){
				_this.attr('isopen',"1");
			});	
		}
	}).on('mouseleave',function(){
		var _thisa = $(this).find(".sel_list"),
			_this = $(this);
		_thisa.hide();
		_this.removeAttr('isopen');
	}),
	$(".select"+selecti).find(".sel_list li").hover( function (){
		$(this).addClass("sel_hov");		
	},function (){
		$(this).removeClass("sel_hov");	
	}).on('click',function(){
		var _this = $(this).html();
		var _code=$(this).attr("code");
		var _thisText = $(this).closest(".select").find(".sel_text");
		_thisText.attr("code",_code);
		_thisText.html(_this);
	});
	selecti++;
}

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

}

/**疾病诊断查询**/
function jbcheckQuery(){
	if($("#jbcontent").val()==""){
		alert("请输入疾病信息");
		return;
	}
	$("#jbzd").html("");
    $.ajax({  
        type: "POST",  
        url: "jbcheckQuery.do",  
        data:{content:$("#jbcontent").val()},// 你的formid
       // data:{content:$("#jbcontent").val(),classType:$("#accidentCode").val()},
        success: function(data){  
            var items = data.diagnosisItemList;  
            //$("#insureData").empty();
            
            $.each(items, function(i, n){
             	$("#jbzd").append("<tr>" +
             			"<th width=\"28%\"><span id='"+items[i].objId+"' code='"+items[i].illcode+"' name='"+items[i].illname+"' class='check_no' onclick='checksp(this.id)'></span></th>" +
             			"<td width=\"12%\">"+items[i].illcode+"</td>" +
             			"<td width=\"60%\" >"+items[i].illname+" </td>" +
             			"</tr>");
            });  
        }  
    });   
} 


function calculateAmount(){
//	$("#altText1").css("display","none");
	$("#altText2").css("display","none");
	var totalAmt=0;
	$("#productList tr").each(function(){
		
		var amt = $(this).find("td:eq(2) input").val();
		if(amt ==''){
			amt =$(this).find("td:eq(1) input").val();
			$(this).find("td:eq(2) input").val(amt);
//			amt=0;
		}
		totalAmt = totalAmt *1 +amt*1;
	});
		$("#totalAmt").val(totalAmt);
}

function checkEmpty(key,value){
	if(key=='' || key==undefined){
		alert(value);
		return false;
	}else{
		return true;
	}
}

function queryHosiptal(flag){
	var partnerName;
	var partnerType="";
	if(flag=='dpa'){/**直付医院*/
		partnerName=$("#yiyuan").val();
		partnerType = "01";
	}else{/**TPA*/
		partnerName=$("#Tpa").val();
		partnerType="02";
	}
	if(partnerName ==null || partnerName ==""){
		alert("查询条件不能为空！");
		return false;
	}
	$.ajax({
		type:"POST",
		url:"findPartnerInfo.do",
		data:{"partnerName":partnerName,"partnerType":partnerType},
		error:function(){
			alert("查询失败！");
			return;
		},
		success:function(data){
			$("#partnerHospital").html('');
			$("#partnerTpa").html('');
			
			if(data==null || data==""){
				if(flag=='dpa'){/**直付医院*/
					$("#partnerHospital").append("<tr><td colspan=\"8\">查询不到相关内容，请检查查询条件</td></tr>");
				}else{/**TPA*/
					$("#partnerTpa").append("<tr><td colspan=\"7\">查询不到相关内容，请检查查询条件</td></tr>");
				}
			}else{
				for(var i= 0; i < data.length; i++){
					var h = data[i];
					if(flag=='dpa'){/**直付医院*/
						$("#partnerHospital").append("<tr style=\"cursor:pointer\"  onclick=\"showSelectLineInfo(this,'"+isNull(h.medinsChnName)+"','"+isNull(h.id)+"')\"  code='"+isNull(h.id)+"'>" +
								"<td><input type=\"hidden\" id=\"partnerName\" value='"+isNull(h.medinsChnName)+"'/>"+
										"<input type=\"hidden\" id=\"partnerAddr\" value='"+isNull(h.chnAddress)+"'/>"+
										"<input type=\"hidden\" id=\"partnerType\" value='"+isNull(h.medinsNatrue)+"'/>"+
										"<input type=\"hidden\" id=\"contactPerson\" value='"+isNull(h.contact)+"'/>"+
										"<input type=\"hidden\" id=\"contactPhone\" value='"+isNull(h.contactPhone)+"'/>"+
//										"<input type=\"hidden\" id=\"payMode\" value='"+h.payMode+"'/>"+
										"<input type=\"hidden\" id=\"bankAccountNo\" value='"+isNull(h.accountNo)+"'/>"+
										"<input type=\"hidden\" id=\"bankAccountName\" value='"+isNull(h.accountName)+"'/>"+
//										"<input type=\"hidden\" id=\"bankCode\" value='"+h.bankCode+"'/>"+
//										"<input type=\"hidden\" id=\"currencyCode\" value='"+h.currencyCode+"'/>"+
//										"<input type=\"hidden\" id=\"isValid\" value='"+h.isValid+"'/>"+
										"<input type=\"hidden\" id=\"bankName\" value='"+isNull(h.bankName)+"'/>"+
//										"<input type=\"hidden\" id=\"payModeName\" value='"+h.payModeName+"'/>"+
										"<input type=\"hidden\" id=\"objid\" value='"+isNull(h.id)+"'/>"+
										"<input type=\"hidden\" id=\"hospitalType\" value='"+isNull(h.medinsNatrue)+"'/>"+
										"<input type=\"hidden\" id=\"email\" value='"+isNull(h.email)+"'/>"+
										"<input type=\"hidden\" id=\"faxNo\" value='"+isNull(h.faxNumber)+"'/>"+
										isNull(h.medinsChnName)+"</td><td>"+isNull(h.chnAddress)+"</td><td>"+isNull(h.medinsNatrue)+"</td><td>"+isNull(h.contact)+"</td>" +
								"<td>"+isNull(h.contactPhone)+"</td><td>"+isNull(h.faxNumber)+"</td><td>"+isNull(h.email)+"</td></tr>");
					}else{/**TPA*/
						$("#partnerTpa").append("<tr style=\"cursor:pointer\"  onclick=\"showSelectLineInfo(this,'"+isNull(h.medinsChnName)+"','"+isNull(h.id)+"')\" >" +
								"<td><input type=\"hidden\" id=\"partnerName\" value='"+h.medinsChnName+"'/>"+
								"<input type=\"hidden\" id=\"partnerAddr\" value='"+h.chnAddress+"'/>"+
								"<input type=\"hidden\" id=\"partnerType\" value='"+h.netType+"'/>"+
								"<input type=\"hidden\" id=\"contactPerson\" value='"+h.contact+"'/>"+
								"<input type=\"hidden\" id=\"contactPhone\" value='"+h.contactPhone+"'/>"+
//								"<input type=\"hidden\" id=\"payMode\" value='"+h.payMode+"'/>"+
								"<input type=\"hidden\" id=\"bankAccountNo\" value='"+h.accountNo+"'/>"+
								"<input type=\"hidden\" id=\"bankAccountName\" value='"+h.accountName+"'/>"+
//								"<input type=\"hidden\" id=\"bankCode\" value='"+h.bankCode+"'/>"+
//								"<input type=\"hidden\" id=\"currencyCode\" value='"+h.currencyCode+"'/>"+
//								"<input type=\"hidden\" id=\"isValid\" value='"+h.isValid+"'/>"+
								"<input type=\"hidden\" id=\"bankName\" value='"+h.bankName+"'/>"+
//								"<input type=\"hidden\" id=\"payModeName\" value='"+h.payModeName+"'/>"+
								"<input type=\"hidden\" id=\"objid\" value='"+h.id+"'/>"+
								"<input type=\"hidden\" id=\"hospitalType\" value='"+h.medinsNatrue+"'/>"+
								"<input type=\"hidden\" id=\"email\" value='"+h.email+"'/>"+
								"<input type=\"hidden\" id=\"faxNo\" value='"+h.faxNumber+"'/>"+isNull(h.medinsChnName)+"</td><td>"+isNull(h.chnAddress)+"</td><td>"+isNull(h.contact)+"</td>" +
								"<td>"+isNull(h.contactPhone)+"</td><td>"+isNull(h.accountName)+"</td><td>"+isNull(h.bankName)+"</td><td>"+isNull(h.accountNo)+"</td><td>"+isNull(h.email)+"</td></tr>");
					}
				}
			}
		}
	});
	
}
function isNull(a){
	
	if(a==null){
		return "";
	}else if(a=="Y"){
		return "是";
	}else if(a=="N"){
		return "否";
	}else{
		return a=="null"?"":a==undefined?"":a;
	}
}
//flag0-div名称  flag1-input flag2-tbodyid flag3-医院类型
function selectDataLine(flag0,flag1,flag2,flag3){
	if(indexLine==null){
		alert("请选择一条数据！");
		return ;
	}else{
		var td=$("#"+flag2).find("tr").eq(indexLine).html();
		var hosptailname = $(td).eq("0").text();
		if(flag3 == 'dpa'){
			if(flag1!=''&& !$("#applyHospitalName").attr("disabled")){
				$("#"+flag1).val(isNull(hosptailname));
			}
			$("#partnerId").val(isNull($("#"+flag2).find("tr").eq(indexLine).attr("code")));
			$("#partnerName").val(isNull(hosptailname));
			$("#contactPerson").val(isNull($(td).eq("3").text()));
			$("#faxNo").val(isNull($(td).eq("5").text()));
			$("#contactPhone").val(isNull($(td).eq("4").text()));
			$("#email").val(isNull($(td).eq("6").text()));
			setHospitalInfoFn("dpa",$("#"+flag2).find("tr").eq(indexLine).html());
		}else{
			$("#"+flag1).val(isNull(hosptailname));
			setHospitalInfoFn("tpa",$("#"+flag2).find("tr").eq(indexLine).html());
			checkApplyInfoFn("","1");
		}
		consAppHospitalFn('','applyHospital','applyAgency','');
		closeDiv(flag0);
	}
}
function setHospitalInfoFn(flag,data){
	if(flag=='dpa'){
		if($("#applyHospitalName").attr("disabled")){
			return ;
		}else{
			checkApplyInfoFn("1","");
			$("#applyHospitalNamePartnerId").val(isNull($(data).find("#objid").val()));
			$("#HospitalName").val(isNull($(data).find("#partnerName").val()));
			$("#Hospitaladdr").val(isNull($(data).find("#partnerAddr").val()));
			$("#hospitalType").val(isNull($(data).find("#hospitalType").val()=="null"?"":$(data).find("#hospitalType").val()));
			$("#hospitalContactPerson").val(isNull($(data).find("#contactPerson").val()));
			$("#hospitalContactPhone").val(isNull($(data).find("#contactPhone").val()));
			$("#hospitalFaxNo").val(isNull($(data).find("#faxNo").val()));
			$("#hospitalBankAccountName").val(isNull($(data).find("#bankAccountName").val()));
			$("#hospitalBankName").val(isNull($(data).find("#bankName").val()));
			$("#hospitalBankAccountNo").val(isNull($(data).find("#bankAccountNo").val()));
			$("#hospitalDivpaymodetype").val(isNull($(data).find("#payModeName").val()));
			$("#hospitalInfo").find("#appEmail").val(isNull($(data).find("#email").val()));
		}
	}else{
		if($("#tpaName").attr("disabled")){
			return ;
		}else{
			$("#applyAgencyNamePartnerId").val(isNull($(data).find("#objid").val()));
			$("#tpaName").val(isNull($(data).find("#partnerName").val()));
			$("#tpaAddr").val(isNull($(data).find("#partnerAddr").val()));
			$("#tpaContactPerson").val(isNull($(data).find("#contactPerson").val()));
			$("#tpaContactPhone").val(isNull($(data).find("#contactPhone").val()));
			$("#tpaFaxNo").val(isNull($(data).find("#faxNo").val()));
			$("#tpaBankAccountName").val(isNull($(data).find("#bankAccountName").val()));
			$("#tpaBankName").val(isNull($(data).find("#bankName").val()));
			$("#tpaBankAccountNo").val(isNull($(data).find("#bankAccountNo").val()));
			$("#tpaDivpaymodetype").val(isNull($(data).find("#payModeName").val()));
			$("#applyTpaTbl").find("#appEmail").val(isNull($(data).find("#email").val()));
		}
	}
}
var indexLine=null;
function showSelectLineInfo(flag0,flag1,flag2){
	$(flag0).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
	indexLine=$(flag0).index();
}


//-----------------------------------------------医疗授权信息 医疗诊断
function showjbzdForm(){
	$("#jbzd").html("");
	$("#jbcontent").val("");
	showDiv('jbzdForm');
}

//疾病诊断
/**疾病诊断查询**/
function jbcheckQuery(){
	
	if($("#jbcontent").val()==""){
		alert("请输入疾病信息");
		return;
	}
	$("#jbzd").html("");
    $.ajax({  
        type: "POST",  
        url: "jbcheckQuery.do",  
        data:{content:$("#jbcontent").val()},// 你的formid
       // data:{content:$("#jbcontent").val(),classType:$("#accidentCode").val()},
        success: function(data){  
            var items = data.diagnosisItemList;  
            //$("#insureData").empty();
            if(items==null || items=="" || items.length<1){
            	$("#jbzd").append("<tr><td colspan=\"3\">查询不到相关内容，请检查查询条件</td></tr>");
			}else{
            $.each(items, function(i, n){
             	$("#jbzd").append("<tr>" +
             			"<th width=\"28%\"><span id='"+items[i].objId+"' code='"+items[i].illcode+"' name='"+items[i].illname+"' class='check_no' onclick='checksp(this.id)'></span></th>" +
             			"<td width=\"12%\">"+items[i].illcode+"</td>" +
             			"<td width=\"60%\" >"+items[i].illname+" </td>" +
             			"</tr>");
            });  
			}
        }  
    });   
} 
function checksp(id){
	if($("#"+id).is(".check_no")){
		$("#"+id).attr("class","check_yes");
	}else{
		$("#"+id).attr("class","check_no");
	}
}

function showjvDiv(flag){
	$("#jbresultData").html("");
	var claimIllsBy_ = $("#claimIllsBy_").val();
	var illTypes = claimIllsBy_.split("_");
	for(var i=0;i<illTypes.length;i++){
		var ill = illTypes[i].split(",");
		$("#jbresultData").append("<tr>" +
				"<td width=\"23%\">"+ill[0]+"</td>" +
				"<td width=\"45%\">"+ill[1]+"</td>" +
				"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"deljbresultData(this,'"+ill[0]+","+ill[1]+"')\"></a></td>" +
				"</tr>");
	}
	if(flag!='init'){
		showDiv("jbresult");
	}
	
	
}
/**疾病诊断保存*/
function saveDiv(id) {
	var jibing = 0;
	var jbname="";
//	$("#jbresultData").html("");
//	$("#claimIllsBy_").val("");
	$("#jbzd").find("span").each(function() {
		if ($(this).is(".check_yes")){
			if(jibing==0){
				jbname = $(this).attr("code")+","+$(this).attr("name");
				if($("#claimIllsBy_").val()==""){
					$("#claimIllsBy_").val($(this).attr("code")+","+$(this).attr("name"));
					$("#jbresultData").append("<tr>" +
							"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
							"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
							"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"deljbresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
							"</tr>");
				}else{
					if($("#claimIllsBy_").val().indexOf($(this).attr("code"))<0){
						$("#claimIllsBy_").val($("#claimIllsBy_").val()+'_'+$(this).attr("code")+","+$(this).attr("name"));
						$("#jbresultData").append("<tr>" +
								"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
								"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
								"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"deljbresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
								"</tr>");
					}
				}
			}else{
				if($("#claimIllsBy_").val().indexOf($(this).attr("code"))<0){
					$("#claimIllsBy_").val($("#claimIllsBy_").val()+'_'+$(this).attr("code")+","+$(this).attr("name"));
					$("#jbresultData").append("<tr>" +
							"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
							"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
							"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"deljbresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
							"</tr>");
				}
			}
			jibing = jibing+1;
			
		}
	});
	var illTypes = $("#claimIllsBy_").val().split("_");
	var showname = illTypes[0].replace(","," ");
	$("#clmIll").val(showname);
	
	if(illTypes.length>1)
		$("#clmIll").val(showname+"....");
	$.closePopupLayer(id);
}
/**疾病列表查询删除当前*/
function deljbresultData(data,illCode){
	if(confirm("确认删除当前行？")){
		var trcurrent = $(data).parent().parent();
		trcurrent.remove();
		delClaimIll(illCode); 
	}
}

function delClaimIll(value){
	var claimIllsBy_ = $("#claimIllsBy_").val();
	var illTypes = claimIllsBy_.split("_");
	var i = 0 ;
	//判断是否已经保存了这个 索赔事故性质
	var flag = 0;
	for(; illTypes != '' && i < illTypes.length ; i++ ){
		if(illTypes[i]==value){
			illTypes[i] = '00';
			flag = 1;
			break;
		}
	}
	if(flag==1){
		var illTypesNew = '';
		i = 0;
		var position = 0;
		for(; illTypes != '' && i < illTypes.length ; i++ ){
			if(illTypes[i]!='00'){
				if(position==0){
					illTypesNew = illTypes[i];
				}else{
					illTypesNew = illTypesNew + '_' + illTypes[i];
				}
				position++; 
			}
		}
		$("#claimIllsBy_").val(illTypesNew);
		var tr = $("#illTblList").find("tr");
		var bodytr = $("#jbresultData").find("tr");
		if(tr.length+bodytr.length>2){
			if(tr.length>1){
				var code = $(tr[1]).find("td:eq(0)");
				var name = $(tr[1]).find("td:eq(1)");
				$("#clmIll").val(code.text()+" "+name.text()+"....");
			}else{
				var code = $(bodytr[0]).find("td:eq(0)");
				var name = $(bodytr[0]).find("td:eq(1)");
				$("#clmIll").val(code.text()+" "+name.text()+"....");
			}
		}else if(tr.length+bodytr.length>1){
			if(tr.length>1){
				var code = $(tr[1]).find("td:eq(0)");
				var name = $(tr[1]).find("td:eq(1)");
				$("#clmIll").val(code.text()+" "+name.text());
			}else{
				var code = $(bodytr[0]).find("td:eq(0)");
				var name = $(bodytr[0]).find("td:eq(1)");
				$("#clmIll").val(code.text()+" "+name.text());
			}
		}else{
			$("#clmIll").val("");
		}
	} 

}
//-----------------------------------------------医疗授权信息 医疗诊断


//-----------------------------------------------医疗信息 医疗诊断
function showylxxForm(){
	$("#ylxx").html("");
	$("#ylxxcontent").val("");
	showDiv('ylxxForm');
}

//疾病诊断
/**疾病诊断查询**/
function ylxxcheckQuery(){
	
	if($("#ylxxcontent").val()==""){
		alert("请输入疾病信息");
		return;
	}
	$("#ylxx").html("");
    $.ajax({  
        type: "POST",  
        url: "jbcheckQuery.do",  
        data:{content:$("#ylxxcontent").val()},// 你的formid
       // data:{content:$("#jbcontent").val(),classType:$("#accidentCode").val()},
        success: function(data){
            var items = data.diagnosisItemList;  
            //$("#insureData").empty();
            if(items==null || items=="" || items.length<1){
            	$("#ylxx").append("<tr><td colspan=\"3\">查询不到相关内容，请检查查询条件</td></tr>");
			}else{
	            $.each(items, function(i, n){
	             	$("#ylxx").append("<tr>" +
	             			"<th width=\"28%\"><span id='"+items[i].objId+"' code='"+items[i].illcode+"' name='"+items[i].illname+"' class='check_no' onclick='checksp(this.id)'></span></th>" +
	             			"<td width=\"12%\">"+items[i].illcode+"</td>" +
	             			"<td width=\"60%\" >"+items[i].illname+" </td>" +
	             			"</tr>");
	            });  
        }  }
    });   
}
function showylxxDiv(flag){
	$("#ylxxresultData").html("");
	var claimIllsBy_ = $("#ylxxIllsBy_").val();
	var illTypes = claimIllsBy_.split("_");
	for(var i=0;i<illTypes.length;i++){
		var ill = illTypes[i].split(",");
		$("#ylxxresultData").append("<tr>" +
				"<td width=\"23%\">"+ill[0]+"</td>" +
				"<td width=\"45%\">"+ill[1]+"</td>" +
				"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"deljbresultData(this,'"+ill[0]+","+ill[1]+"')\"></a></td>" +
				"</tr>");
	}
	if(flag!='init'){
		showDiv("ylxxresult");
	}
	
	
}
/**疾病诊断保存*/
function saveylxxDiv(id) {
	var jibing = 0;
//	$("#jbresultData").html("");
//	$("#claimIllsBy_").val("");
	$("#ylxx").find("span").each(function() {
		if ($(this).is(".check_yes")){
			if(jibing==0){
				if($("#ylxxIllsBy_").val()==""){
					$("#ylxxIllsBy_").val($(this).attr("code")+","+$(this).attr("name"));
					$("#ylxxresultData").append("<tr>" +
							"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
							"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
							"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"delylxxresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
							"</tr>");
				}else{
					if($("#ylxxIllsBy_").val().indexOf($(this).attr("code"))<0){
						$("#ylxxIllsBy_").val($("#ylxxIllsBy_").val()+'_'+$(this).attr("code")+","+$(this).attr("name"));
						$("#ylxxresultData").append("<tr>" +
								"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
								"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
								"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"delylxxresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
								"</tr>");
					}
				}
			}else{
				if($("#ylxxIllsBy_").val().indexOf($(this).attr("code"))<0){
					$("#ylxxIllsBy_").val($("#ylxxIllsBy_").val()+'_'+$(this).attr("code")+","+$(this).attr("name"));
					$("#ylxxresultData").append("<tr>" +
							"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
							"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
							"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"delylxxresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
							"</tr>");
				}
			}
			jibing = jibing+1;
			
		}
	});
	var illTypes = $("#ylxxIllsBy_").val().split("_");
	var showname = illTypes[0].replace(","," ");
	$("#ylxxclmIll").val(showname);
	
	if(illTypes.length>1)
		$("#ylxxclmIll").val(showname+"....");
	$.closePopupLayer(id);
}
/**疾病列表查询删除当前*/
function delylxxresultData(data,illCode){
	if(confirm("确认删除当前行？")){
		var trcurrent = $(data).parent().parent();
		trcurrent.remove();
		delylxxClaimIll(illCode); 
	}
}

function delylxxClaimIll(value){
	var claimIllsBy_ = $("#ylxxIllsBy_").val();
	var illTypes = claimIllsBy_.split("_");
	var i = 0 ;
	//判断是否已经保存了这个 索赔事故性质
	var flag = 0;
	for(; illTypes != '' && i < illTypes.length ; i++ ){
		if(illTypes[i]==value){
			illTypes[i] = '00';
			flag = 1;
			break;
		}
	}
	if(flag==1){
		var illTypesNew = '';
		i = 0;
		var position = 0;
		for(; illTypes != '' && i < illTypes.length ; i++ ){
			if(illTypes[i]!='00'){
				if(position==0){
					illTypesNew = illTypes[i];
				}else{
					illTypesNew = illTypesNew + '_' + illTypes[i];
				}
				position++; 
			}
		}
		$("#ylxxIllsBy_").val(illTypesNew);
		var tr = $("#ylxxList").find("tr");
		var bodytr = $("#ylxxresultData").find("tr");
		if(tr.length+bodytr.length>2){
			if(tr.length>1){
				var code = $(tr[1]).find("td:eq(0)");
				var name = $(tr[1]).find("td:eq(1)");
				$("#ylxxclmIll").val(code.text()+" "+name.text()+"....");
			}else{
				var code = $(bodytr[0]).find("td:eq(0)");
				var name = $(bodytr[0]).find("td:eq(1)");
				$("#ylxxclmIll").val(code.text()+" "+name.text()+"....");
			}
		}else if(tr.length+bodytr.length>1){
			if(tr.length>1){
				var code = $(tr[1]).find("td:eq(0)");
				var name = $(tr[1]).find("td:eq(1)");
				$("#ylxxclmIll").val(code.text()+" "+name.text());
			}else{
				var code = $(bodytr[0]).find("td:eq(0)");
				var name = $(bodytr[0]).find("td:eq(1)");
				$("#ylxxclmIll").val(code.text()+" "+name.text());
			}
		}else{
			$("#ylxxclmIll").val("");
		}
	} 

}
//-----------------------------------------------医疗信息 医疗诊断


//-----------------------------------------------授权项目
function showsqxmForm(){
	$("#sqxm").html("");
	$("#sqxmcontent").val("");
	showDiv('sqxmForm');
}

//授权诊断
/**授权查询**/
function sqxmcheckQuery(){
	
	if($("#sqxmcontent").val()==""){
		alert("请输入授权项目信息");
		return;
	}
	$("#sqxm").html("");
    $.ajax({  
        type: "POST",  
        url: "sqxmcheckQuery.do",  
        data:{content:$("#sqxmcontent").val()},// 你的formid
       // data:{content:$("#jbcontent").val(),classType:$("#accidentCode").val()},
        success: function(data){  
            var items = data.preProjectList;  
            //$("#insureData").empty();
            if(items==null || items=="" || items.length<1){
            	$("#sqxm").append("<tr><td colspan=\"3\">查询不到相关内容，请检查查询条件</td></tr>");
			}else{
	            $.each(items, function(i, n){
	             	$("#sqxm").append("<tr>" +
	             			"<th width=\"28%\"><span id='"+items[i].objId+"'code='"+items[i].projectNo+"'name='"+items[i].projectName+"'class='check_no' onclick='checksp(this.id)'></span></th>" +
	             			"<td width=\"12%\">"+items[i].projectNo+"</td>" +
	             			"<td width=\"60%\">"+items[i].projectName+"</td>" +
	             			"</tr>");
	            });  
        	}
        }  
    });   
}
function showsqxmDiv(flag){
	$("#sqxmresultData").html("");
	var claimIllsBy_ = $("#sqxmIllsBy_").val();
	var illTypes = claimIllsBy_.split("_");
	for(var i=0;i<illTypes.length;i++){
		var ill = illTypes[i].split(",");
		$("#sqxmresultData").append("<tr>" +
				"<td width=\"23%\">"+ill[0]+"</td>" +
				"<td width=\"45%\">"+ill[1]+"</td>" +
				"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"deljbresultData(this,'"+ill[0]+","+ill[1]+"')\"></a></td>" +
				"</tr>");
	}
	if(flag!='init'){
		showDiv("sqxmresult");
	}
	
	
}
/**授权项目保存*/
function savesqxmDiv(id) {
	var jibing = 0;
	var jbname="";
//	$("#jbresultData").html("");
//	$("#claimIllsBy_").val("");
	$("#sqxm").find("span").each(function() {
		if ($(this).is(".check_yes")){
			if(jibing==0){
				jbname = $(this).attr("code")+","+$(this).attr("name");
				if($("#sqxmIllsBy_").val()==""){
					$("#sqxmIllsBy_").val($(this).attr("code")+","+$(this).attr("name"));
					$("#sqxmresultData").append("<tr>" +
							"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
							"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
							"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"delsqxmresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
							"</tr>");
				}else{
					if($("#sqxmIllsBy_").val().indexOf($(this).attr("code"))<0){
						$("#sqxmIllsBy_").val($("#sqxmIllsBy_").val()+'_'+$(this).attr("code")+","+$(this).attr("name"));
						$("#sqxmresultData").append("<tr>" +
								"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
								"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
								"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"delsqxmresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
								"</tr>");
					}
				}
			}else{
				if($("#sqxmIllsBy_").val().indexOf($(this).attr("code"))<0){
					$("#sqxmIllsBy_").val($("#sqxmIllsBy_").val()+'_'+$(this).attr("code")+","+$(this).attr("name"));
					$("#sqxmresultData").append("<tr>" +
							"<td width=\"23%\">"+$(this).attr("code")+"</td>" +
							"<td width=\"45%\">"+$(this).attr("name")+"</td>" +
							"<td width=\"21%\"><a  style=\"cursor: pointer;\" class=\"icon_del\" onclick=\"delylxxresultData(this,'"+$(this).attr("code")+","+$(this).attr("name")+"')\"></a></td>" +
							"</tr>");
				}
			}
			jibing = jibing+1;
			
		}
	});
	var illTypes = $("#sqxmIllsBy_").val().split("_");
	var showname = illTypes[0].replace(","," ");
	$("#sqxmclmIll").val(showname);
	if(illTypes.length>1)
		$("#sqxmclmIll").val(showname+"....");

	$.closePopupLayer(id);
}
/**疾病列表查询删除当前*/
function delsqxmresultData(data,illCode){
	if(confirm("确认删除当前行？")){
		var trcurrent = $(data).parent().parent();
		trcurrent.remove();
		delsqxmClaimIll(illCode); 
	}
}

function delsqxmClaimIll(value){
	var claimIllsBy_ = $("#sqxmIllsBy_").val();
	var illTypes = claimIllsBy_.split("_");
	var i = 0 ;
	//判断是否已经保存了这个 索赔事故性质
	var flag = 0;
	for(; illTypes != '' && i < illTypes.length ; i++ ){
		if(illTypes[i]==value){
			illTypes[i] = '00';
			flag = 1;
			break;
		}
	}
	if(flag==1){
		var illTypesNew = '';
		i = 0;
		var position = 0;
		for(; illTypes != '' && i < illTypes.length ; i++ ){
			if(illTypes[i]!='00'){
				if(position==0){
					illTypesNew = illTypes[i];
				}else{
					illTypesNew = illTypesNew + '_' + illTypes[i];
				}
				position++; 
			}
		}
		$("#sqxmIllsBy_").val(illTypesNew);
		var tr = $("#sqxmList").find("tr");
		var bodytr = $("#sqxmresultData").find("tr");
		if(tr.length+bodytr.length>2){
			if(tr.length>1){
				var code = $(tr[1]).find("td:eq(0)");
				var name = $(tr[1]).find("td:eq(1)");
				$("#sqxmclmIll").val(code.text()+" "+name.text()+"....");
			}else{
				var code = $(bodytr[0]).find("td:eq(0)");
				var name = $(bodytr[0]).find("td:eq(1)");
				$("#sqxmclmIll").val(code.text()+" "+name.text()+"....");
			}
		}else if(tr.length+bodytr.length>1){
			if(tr.length>1){
				var code = $(tr[1]).find("td:eq(0)");
				var name = $(tr[1]).find("td:eq(1)");
				$("#sqxmclmIll").val(code.text()+" "+name.text());
			}else{
				var code = $(bodytr[0]).find("td:eq(0)");
				var name = $(bodytr[0]).find("td:eq(1)");
				$("#sqxmclmIll").val(code.text()+" "+name.text());
			}
		}else{
			$("#sqxmclmIll").val("");
		}
	} 

}
//-----------------------------------------------医疗信息 医疗诊断



function goStep(channelType,pid){
	var params = {};
	params['channelType'] = channelType;
	params['pid'] = pid;
	SkipByPost("policyreturn.do",params);
}

//进入预授权审核任务池页面 任务池查询
function submitPageFormFn(){
	$("#formId").attr("action","examinePoolsQuery.do");
	$("#formId").attr("method","POST");
	$("#formId").submit();
}

//进入预授权审核页面
function enterExamineFn(flag){
	$("#preNo").val(flag);
	$("#formId").attr("action","enterExamine.do");
	$("#formId").attr("method","POST");
	$("#formId").submit();
}
//费用项目
function selectedFn(flag){
	var projectNo=$(flag).val();
	var projectName=$(flag).text();
	$(flag).parent("ul").parent("div").parent("div").find("span:eq(0)").find("input:eq(0)").val(projectNo);
	$(flag).parent("ul").parent("div").parent("div").find("span:eq(0)").find("input:eq(1)").val(projectName);
}

function saveAllInfo(flag){
	var reqUrl="requestSaveData.do";
	var PreauthorizationAcceptVo = {};
	var preTaskPre = {};
	var clmPerson = {};
	var insured = {};
	var partnerInfo = {};
	var preClassLiabList = [];
	
	var preMedical = {};
	var preMedicalInfo={};
	var preProject = [];
	
	
	var preNo = $("#preNo").val();
	//申请人信息
//	var appInsRelationship = $("#appInsRelationship").html();
	var appInsRelationship = $("#appInsRelationship").attr("code");
	var applyHospitalName = $("#applyHospitalName").val();
	var applyAgencyName = $("#applyAgencyName").val();
	var isGuarantee = $("#isGuarantee").attr("code");
	var appIdtype = $("#appIdtype").attr("code");
	var appPid = $("#appPid").val();
	var appName = $("#appName").val();
	var appSex = $("#appSex").attr("code");
	var appPhone = $("#appPhone").val();
	var appTel = $("#appTel").val();
	var appContractAddr = $("#appContractAddr").val();
	var appPostCode = $("#appPostCode").val();
	var appEmail = $("#appEmail").val();
	var appFax = $("#appFax").val();
	var code=$("#SHcon1").find("table:eq(0) tr:eq(0)>td:eq(0)").find("div:eq(0)").find("span:eq(0)").attr("code");
	var applyAgencyNamePartnerId=null;
	var applyHospitalNamePartnerId=null;
	if($("#applyTpaTbl").css("display")!='none'){
		applyAgencyNamePartnerId=$("#applyAgencyNamePartnerId").val();
	}else if($("#applyHospitalTbl").css("display")!='none'){
		applyHospitalNamePartnerId=$("#applyHospitalNamePartnerId").val();
	}
	var preAmt=$("#totalAmt").val();//核准额
	var appAmt=$("#preProjectPremTbl tr:eq("+$("#preProjectPremTbl tr:gt(0)").length+")").find("td:eq(0)").find("input:eq(0)").val();//申请额
	var auditBasis = $("#auditBasis").val(); //审核依据 by lirui20160616
	
	if(auditBasis.length>300){
		alert("审核依据长度超过最大限制，请重新输入！");
		return false;
	}
	
	if(code=='401'){
		//申请人必录信息校验
		if(!checkEmpty(appInsRelationship,"关系必录")){
			return;
		}
//		if(appInsRelationship =='408' && applyHospitalName=='' && applyAgencyName==''){
//			alert("医疗机构或委托机构两者必录其一");
//			return;
//		}
		if(!checkEmpty(isGuarantee,"担保函必录")){
			return;
		}
		if(!checkEmpty(appIdtype,"证件类型必录")){
			return;
		}
		if(!checkEmpty(appPid,"证件号码必录")){
			return;
		}
		if(appIdtype=='a' && !checkIdentityCard(appPid)){
			alert("身份证输入不合法");
			return false;
		}
		if(!checkEmpty(appName,"姓名必录")){
			return;
		}
		if(!checkEmpty(appSex,"性别必录")){
			return;
		}
		
		if(appPostCode!=null&&appPostCode!=undefined&&appPostCode!=""){
			var re= /^[1-9][0-9]{5}$/;
			if(!re.test(appPostCode)){
				alert("请输入正确的邮政编码");
				return false;
			}
		}
		
		//传真校验
		if(appFax!=null&&appFax!=undefined&&appFax!=""){
			if(!checkfoxNo(appFax)){
				alert("请输入正确的传真号码");
				return false;
			}
		}
		
		if(appPhone=='' && appTel==''){
			alert("手机号码和固定电话两者必录其一");
			return false;
		}else{
			
			var reg = /^1[34578][0-9]{9}$/;
			if($.trim(appPhone).length!=0&&$.trim(appPhone).length!=11){
				alert("手机号码长度必须为11位。");
				return false;
			}
			if($.trim(appPhone).length!=0){
				if(!reg.test($.trim(appPhone))){
					alert("手机号码格式不正确，请重新填写。");
					return false;
				}
			}
			if(appTel !='' && !checkPhone(appTel)){
				return false;
			}
		}
		
		if(!checkMail(appEmail)){
			return false;
		}
		var appEmail = $("#appEmail").val();
		var appFax = $("#appFax").val();
		if((appEmail==null || appEmail=="" )&&(appFax==null ||appFax=="") && $("#isGuarantee").attr("code")=="Y"){
			alert("邮箱地址与传真号码两者必录其一");
			return false;
		}
		
		
	}else if(code=='408'){
		if($("#applyHospitalNamePartnerId").val()==null && $("#applyAgencyNamePartnerId").val()==null ){
			alert("医疗机构与委托机构两者必录其一！");
			return false;
		}
	}
	preTaskPre.preNo =preNo;
	//申请人信息
	clmPerson.name = appName;
	clmPerson.sex =appSex;
	clmPerson.idtype =appIdtype;
	clmPerson.pid =appPid;
	clmPerson.phone =appPhone;
	clmPerson.tel =appTel;
	clmPerson.email =appEmail;
	clmPerson.postCode =appPostCode;
	clmPerson.contractAddr =appContractAddr;
	clmPerson.fax =appFax;
	preTaskPre.applicantName=appName;
	preTaskPre.appInsRelationship=appInsRelationship;
	preTaskPre.applicantPid =appPid;
	preTaskPre.applyHospitalName=applyHospitalName;
	preTaskPre.applyAgencyName = applyAgencyName;
	preTaskPre.isGuarantee=isGuarantee;
	if(code=='408'){
		preTaskPre.applyHospitalNamePartnerId=applyHospitalNamePartnerId;
		preTaskPre.applyAgencyNamePartnerId=applyAgencyNamePartnerId;
	}else{
		preTaskPre.applyHospitalNamePartnerId=null;
		preTaskPre.applyAgencyNamePartnerId=null;;
	}

	
	preTaskPre.amtPre=appAmt; // 申请总额
	preTaskPre.amtApp=preAmt;
	
	preTaskPre.isSendEmail=$("#isEmail").val();
	preTaskPre.auditBasis = auditBasis;
	
	
	//患者信息
	insured.name = $("#insName").html();
	insured.bthdate =$("#insBthdate").html();
	insured.idtype =$("#insIdtype").val();
	insured.sex =$("#insSex").val();
	insured.pid =$("#insPid").html();
	insured.phone =$("#insPhone").val();
	insured.companyName =$("#insCompanyName").html();
	$("#preClassLiabList").find("tr").each(function(){
		var preClassLiabInf={};
		preClassLiabInf.policyno = $(this).find("td:eq(1)").html();
		preClassLiabInf.classname = $(this).find("td:eq(2)").html();
		preClassLiabInf.classcode = $(this).find("td:eq(3)").html();
		preClassLiabInf.delName = $(this).find("td:eq(4)").html();
		preClassLiabInf.delCode = $(this).find("td:eq(5)").html();
		if($(this).find("td:eq(0)").find("span").is(".check_yes")){
			preClassLiabInf.selected = "1";
			
		}else{
			preClassLiabInf.selected = "0";
		}
		preClassLiabList.push(preClassLiabInf);
	});
	//医疗机构信息
	
	if($("#partnerName").val()==null|| $("#partnerName").val()==""){
		alert("请填写医疗机构信息！");
		return ;
	}
	
	
	partnerInfo.medinsChnName = $("#partnerName").val();
	partnerInfo.faxNumber = $("#faxNo").val();
	partnerInfo.contact = $("#contactPerson").val();
	partnerInfo.contactPhone = $("#contactPhone").val();
	preTaskPre.doctorName = $("#doctorName").val();
	partnerInfo.email =$("#email").val();
	preTaskPre.hospitalName = $("#partnerName").val();
	
	preTaskPre.guaranteeAmt=$("#guaranteeAmt").val();
	preTaskPre.guaranteeMatter=$("#guaranteeMatter").val();
	
	//医疗信息
	var visitReason = "";
	var hvisitDate =$("#hvisitDate").val();
	var visitDateFirst = $("#visitDateFirst").val();
	$("#visitReason").find("span").each(function(){
		if($(this).is(".check_yes")){
			visitReason = $(this).attr("code");
		}
	});
	var prevalenceStatus = "";
	$("#prevalenceStatus").find("span").each(function(){
		if($(this).is(".check_yes")){
			prevalenceStatus = $(this).attr("code");
		}
	});
	if(!checkEmpty(visitReason,"就诊原因必录")){
		return;
	}
	if(!checkEmpty(hvisitDate,"就诊日期必录")){
		return;
	}
	if(!checkEmpty(visitDateFirst,"就诊日期必录")){
		return;
	}
	if(!checkEmpty(prevalenceStatus,"体格检查结果必录")){
		return;
	}
	if(!checkMail(appEmail)){
		return false;
	}
	preMedical.visitReason = visitReason;
	preMedical.accidentDate = $("#accidentDate").val();
	preMedical.visitDate =hvisitDate ;
	preMedical.visitDateFirst = visitDateFirst;
	preMedical.report = $("#report").val();
	preMedical.illzdname=$("#ylxxIllsBy_").val();
	preMedical.prevalenceStatus =prevalenceStatus;
	preMedical.physiqueCheck=$("#physiqueCheck").val();
	preMedical.labCheck = $("#labCheck").val();
	preMedical.diseaseHistory = $("#diseaseHistory").val();
	
	//医疗授权信息
	var itemMode = "";
	$("#itemMode").find("span").each(function(){
		if($(this).is(".check_yes")){
			itemMode = $(this).attr("code");
		}
	});
	
	if(!checkEmpty(itemMode,"诊疗形式必录")){
		return;
	}
	var visitDate =$("#visitDate").val();
	if(!checkEmpty(visitDate,"就诊日期必录")){
		return;
	}
	var hospitalDay = $("#hospitalDay").val();
	if(itemMode == '02'){
		if(!checkEmpty(hospitalDay,"住院天数必录")){
			return;
		};
	}
	var claimIllsBy_ = $("#claimIllsBy_").val();
	if(!checkEmpty(claimIllsBy_,"医疗诊断必录")){
		return;
	}
	var sqxmIllsBy_ = $("#sqxmIllsBy_").val();
	if(!checkEmpty(sqxmIllsBy_,"授权项目必录")){
		return;
	}
	preMedicalInfo.itemMode = itemMode;
	preMedicalInfo.visitDate = visitDate;
	preMedicalInfo.hospitalDay = hospitalDay;
	preMedicalInfo.illzdname = claimIllsBy_;
	preMedicalInfo.preProject = sqxmIllsBy_;
	var bool=true;
	$("#productList").find("tr").each(function(){
		var preProjectInfo={};
		if(!bool){
			return ;
		}
		if(($(this).find(".sel_text").attr("code")==null || $(this).find(".sel_text").attr("code")=="")
			|| ($(this).find("input").eq(0).val()==null || $(this).find("input").eq(0).val()=="")
			|| ($(this).find("input").eq(1).val()==null || $(this).find("input").eq(1).val()=="")){
			alert("请将费用项目填写完整 ！");
			bool=false;
			return;
		}else{
			preProjectInfo.projectNo = $(this).find(".sel_text").attr("code");
			preProjectInfo.projectName = $(this).find(".sel_text").html();
			preProjectInfo.amtPre = $(this).find("input").eq(0).val();
			preProjectInfo.amtApp = $(this).find("input").eq(1).val();
			preProjectInfo.describe = $(this).find("input").eq(2).val();
			preProject.push(preProjectInfo);
			bool=true;
		}
	});
	if(!bool){
		return;
	}
	
	
	
//	preTaskPre.amtPre = $("#totalAmt").html();
	if(flag =='complete'){
		if($("#setValue").val()=="Y"){
			preTaskPre.preState = "04";
			preTaskPre.preSubState = "05";
		}else if($("#setValue").val()=="N"){
			preTaskPre.preState = "05";
			preTaskPre.preSubState = "05";
		}
		reqUrl="requestSubmitData.do";
	}else if(flag=="save"){
		preTaskPre.preState = "02";
		preTaskPre.preSubState = "02";
	}else if(flag=="agree"){
		preTaskPre.preState = "02";
		preTaskPre.preSubState = "02";
	}else if(flag=="noagree"){
		preTaskPre.preState = "02";
		preTaskPre.preSubState = "06";
	}
	preTaskPre.partnerId = $("#partnerId").val();
	PreauthorizationAcceptVo.preTaskPre = preTaskPre;
	PreauthorizationAcceptVo.clmPerson = clmPerson;
	PreauthorizationAcceptVo.insured =insured;
	PreauthorizationAcceptVo.partnerInfo = partnerInfo;
	PreauthorizationAcceptVo.preClassLiabList =preClassLiabList;
	PreauthorizationAcceptVo.preMedical =preMedical;
	PreauthorizationAcceptVo.preMedicalInfo =preMedicalInfo;
	PreauthorizationAcceptVo.preProject= preProject;
	//短信（被保人姓名和手机号码）
	var inputSource=$("#inputSource").val();
	var bbrname = $("#insName").html();
	$.ajax({
		 type: "POST",  
	     url: reqUrl,
	     data:JSON.stringify(PreauthorizationAcceptVo),
		 contentType:"application/json; charset=UTF-8",
	     success:function(data){
	    	 if(flag=='save'){
	    		 if(eval(data)){
	    			 alert("预授权审核保存成功!");
	    		 }else{
	    			 alert("预授权审核保存失败!");
	    		 }
	    		
	    	 }else if(flag=='complete'){
	    		 if(eval(data)){
	    			 alert("预授权审核完成!");
	    				var params={};
	    				//展示短信 modify chc 20150428修改弹出框显示逻辑
	    				if($("#inputSource").val()=="05"){
	    					sendApp2Pre(preNo,appName,appPid,appPhone,"1",$("#personId").val());//App预授权短信实时发送,flag==1代表APP端-预授权审核结论通知
	    				}else{
	    					showSmsContent(preNo,bbrname);//理赔预授权短信展示
	    				}
	    				
	    		 }else{
	    			 alert("预授权审核失败!");
	    		 }
	    		
	    	 }
	     },
	     error:function(data){
	     }
	});
	$("#shjlBtn").attr("onclick","showBotOpen('botOpen1',this)");
	
}


//时间显示工具
function jsonDateFormat(date,length,sep){
	if(date==null || date==""){
		return "";
	}
	if(isNaN(date)){
		return date;
	}
    var datetime = new Date();
    datetime.setTime(date);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    if(length==10){
    	return year + sep + month + sep + date;
    }else{
    	return year + sep + month + sep + date+" "+hour+":"+minute+":"+second;
    }
}
var estimate="";
function setValueFn(flag){
	$("#setValue").val(flag);
	estimate=$("#setValue").val();
	$("#botOpen1").css("display","none");
	$("#lock_click_bg").hide();
//	$("#saveInfo").attr("onclick","saveAllInfo('save')");
	if("Y"==estimate){
		$("#noticeBtn").attr("onclick","showBotOpen('botOpen2',this)");
		saveAllInfo("agree");
	}
	if("N"==estimate){
		$("#noticeBtn").attr("onclick","showBotOpen('botOpen3',this)");
		saveAllInfo("noagree");
	}
	var preAmt=$("#totalAmt").val();//核准额
	
	var appAmt=$("#preProjectPremTbl tr:eq("+$("#preProjectPremTbl tr:gt(0)").length+")").find("td:eq(0)").find("input:eq(0)").val();//申请额
	var preNo = $("#preNo").val();
	$.ajax({
		type : "POST",
		url : "requestExamineVerdict.do",
		data : {"preAmt":preAmt,"appAmt":appAmt,"val":estimate,"preNo":preNo},
		success : function(data) {
			if(!data){
				var params={};
				alert("超出审核权限！");
				SkipByPost("examinePoolsQuery.do",params);
			}else{
				//如果权限足够
//				直接通过
				$("#submitBtn").attr("onclick","saveAllInfo('complete')");
			}
		},
		error : function(data) {
		}
	});
	
	
	
	//$("#saveInfo").bind("click",function(){saveAllInfo('save');});
	
}


//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
function changeisGuarantee(flag){
	if(flag=="Y"){
		$("#appEmail").parent("td").parent("tr").find("th:eq(0)").html("<span class=\"txt_blue\">*</span>邮箱地址：");
		$("#appFax").parent("td").parent("tr").find("th:eq(1)").html("<span class=\"txt_blue\">*</span>传真号码：");
	}else{
		$("#appEmail").parent("td").parent("tr").find("th:eq(0)").text("邮箱地址：");
		$("#appFax").parent("td").parent("tr").find("th:eq(1)").text("传真号码：");
	}
}


//根据与被保人关系控制医疗机构是否可修改
function consAppHospitalFn(flag,flag2,flag3,flag4){
	//获取与被保人关系
	var code=$("#SHcon1").find("table:eq(0) tr:eq(0)>td:eq(0)").find("div:eq(0)").find("span:eq(0)").attr("code");
	if(flag4!=null && flag4!=""){
		code=flag4;
	}
	$("#"+flag2).css("display","");
	$("#"+flag3).css("display","");
	$("#applyHospitalName").attr("disabled",false);
	$("#applyAgencyName").attr("disabled",false);
//	若选择的不是“其他”，控制医疗机构和委托机构不可录入；
//	若选择“其他”，医疗机构或委托机构必录其一；
	if(code=="408"){
//		$("#SHcon1").find("input:text").each(function(){
//			$(this).val('');
//		});
//		$("#appSex").attr("code","1");
//		$("#appSex").text("男");
		
		var appHospName=$("#applyHospitalName").val();
		var appAgencyName=$("#applyAgencyName").val();
		if(appHospName!=null && appHospName!=""){
			$("#"+flag3).css("display","none");
			$("#applyAgencyName").attr("disabled",true);
		}
		if(appAgencyName!=null && appAgencyName!=""){
			$("#"+flag2).css("display","none");
			$("#applyHospitalName").attr("disabled",true);
		}

		if(flag==1){
			showDiv('divformHospital');
		}else if(flag==2){
			showDiv('divformTpa');
		}else{
			return ;
		}
	}else{
		if(code=="401"){
			var isg=$("#isGuarantee").attr("code");
			changeisGuarantee(isg);
//			$("#partnerId").val('');
			if(applyPresonInfo!=null && applyPresonInfo!="" && applyPresonInfo !=undefined){
				$("#SHcon1").find("#appPid").val($(applyPresonInfo).find("#appPid").val());
				var appIdtype=$(applyPresonInfo).find("#appIdtype").attr("code");
				
				checkSex(appIdtype);
				
				$("#SHcon1").find("#appName").val($(applyPresonInfo).find("#appName").val());
				$("#SHcon1").find("#appPhone").val($(applyPresonInfo).find("#appPhone").val());
				$("#SHcon1").find("#appTel").val($(applyPresonInfo).find("#appTel").val());
				$("#SHcon1").find("#appContractAddr").val($(applyPresonInfo).find("#appContractAddr").val());
				$("#SHcon1").find("#appPostCode").val($(applyPresonInfo).find("#appPostCode").val());
				$("#SHcon1").find("#appEmail").val($(applyPresonInfo).find("#appEmail").val());
				$("#SHcon1").find("#appFax").val($(applyPresonInfo).find("#appFax").val());
				
			}
		}else{
//			$("#SHcon1").find("input:text").each(function(){
//				$(this).val('');
//			});
//			$("#appSex").attr("code","1");
//			$("#appSex").text("男");
		}
		$("#"+flag2).css("display","none");
		$("#"+flag3).css("display","none");
		$("#applyHospitalName").val("");
		$("#applyAgencyName").val("");
		$("#applyHospitalName").attr("disabled",true);
		$("#applyAgencyName").attr("disabled",true);
		checkApplyInfoFn("","");
		return; 
	}
}
//如果证件类型是身份证，则自动填充性别
function checkSex(flag){
	var appIdtype=$("#appIdtype").attr("code");
	if(flag!=null && flag!=""){
		appIdtype=flag;
	}
	var scode,sname;
	if($("#appPid").val()==null || $("#appPid").val()==""){
		return ;
	}else{
		if("a"==appIdtype){
			var appPid=$("#appPid").val();
			var sexCode=appPid.substring(16,17);
			scode=sexCode%2==0?2:1;
			sname=scode==1?"男":"女";
			$("#sexOption").html("<span class=\"sel_text\" code='"+scode+"' id=\"appSex\">"+sname+"</span>");
		}else{
			$("#sexOption").val("<span class=\"sel_text\" code=\"1\" id=\"appSex\">男</span><div class=\"sel_list i_ul_265\" style=\"display: none;\" id=\"sexOption\"><ul><li code=\"1\">男</li><li code=\"2\">女</li></ul></div>");
		}
	}
}
//单选 //flag td的id,flag1 class所属标签,flag2 this
function radioSelect(flag,flag1,flag2){
	$("#"+flag).find(flag1).each(function (){
			$(this).removeClass();
			$(this).attr("class","check_no");
	});
}
function selectedli(flag,flag2){
	if(flag2=='1'){
		$("#hospitalpaytype").val(flag);
	}else{
		$("#tpapaytype").val(flag);
	}
}

function checkApplyInfoFn(flag,flag1){
	if(flag=="" && flag1==""){
		$("#applypresonTbl").css("display","");
		$("#applyHospitalTbl").css("display","none");
		$("#applyTpaTbl").css("display","none");
		$("#queryPartnerInfoBtn").css("display","");
	}
	if(flag!=""){
		$("#applyHospitalTbl").css("display","");
		$("#applypresonTbl").css("display","none");
		$("#applyTpaTbl").css("display","none");
		$("#queryPartnerInfoBtn").css("display","none");
		
	}
	if(flag1!=""){
		$("#applyHospitalTbl").css("display","none");
		$("#applypresonTbl").css("display","none");
		$("#applyTpaTbl").css("display","");
		$("#queryPartnerInfoBtn").css("display","");
	}
}
//校验电子邮箱
function checkMail(flag){
	if(flag==null || flag==""){
		return true;
	}
	 var reg=/^([a-zA-Z0-9]+[_|-|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|-|.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
	  if(!reg.test(flag)){
	   alert("电子邮箱格式不正确，请重新输入!");
	   return false;
	  }else{
		  return true;
	  }
	  
}

function getApplyDpaAndTpaInfo(flag){
	$.ajax({
		type : "POST",
		url : "findPartnerInfo.do",
		data :{"partnerName":partnerName,"partnerType":partnerType},
		success : function(data) {
			if("P0000050"==flag){
				p0000050Fn(data);
			}else if("P0000051"==flag){
				p0000051Fn(data);
			}else if("P0000052"==flag){
				p0000052Fn(data);
			}
		},
		error : function(data) {
			alert("不能找到通知书，请手工填写！");
			return false;
		}
	});
}

function delProduct(){
	if(index!=-1){
    	$("#productList tr:eq("+index+")").remove();
		index=-1;
    	alert("删除成功");
    	calculateAmount();
	}else if(index == -1){
		alert("请选择需要删除的项目");
	}
	addPrejectAmt();
}
function addPrejectAmt(){
	$("#altText1").css("display","none");
//	$("#altText2").css("display","none");
	var totalAmt=0;
	$("#preProjectPremTbl tr:gt(0):lt("+($("#preProjectPremTbl tr:gt(0)").length-1)+")").each(function(){
			var amt=$(this).find("td:eq(1)").find("input").val();
			if(amt==''){
				amt=0;
			}
		totalAmt=totalAmt*1+amt*1;
	});
	$("#preProjectPremTbl tr:eq("+$("#preProjectPremTbl tr:gt(0)").length+")").find("td:eq(0)").find("input:eq(0)").val(totalAmt);
}
//function checkNumberAmt(){
//	var value=$("#guaranteeAmt").val();
//	if(value==""){
//		return ;
//	}else{
//		if(isNaN(value)){
//			alert("请输入一个正确的金额！");
//			$("#guaranteeAmt").val();
//		}else{
//			if((!isNaN(value)&&value<0)|| value.indexOf("-")!=-1){
//				alert("请输入一个非负数的金额！");
//				$("#guaranteeAmt").val();
//			}else{
//				value=parseFloat(value).toFixed(2);
//				if(value.length>15){
//					alert("请输入一个有效的金额！");
//					$("#guaranteeAmt").val();
//				}else{
//					$("#guaranteeAmt").val();
//				}
//			}
//		}
//	}
//}

function checkTelIsChinese(flag){
	var reg=/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/;
	var regm=/^[1][34578][0-9]{9}$/; 
	if(reg.test($(flag).val())|| regm.test($(flag).val())){
		return true;
	}else{
		alert("您输入的联系方式不正确！");
		return false;
	}
}

//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\





//#################################通知书查询 打印################################################
function saveNotice(flag,operation,flag2){
//	$(flag2).removeAttr("onclick");
	if("P0000050"==flag){
		saveP0000050Fn(operation);
	}else if("P0000051"==flag){
		saveP0000051Fn(operation);
	}else if("P0000052"==flag){
		saveP0000052Fn(operation);
	}
//	$(flag2).attr("onclick","saveNotice('"+flag+"','"+operation+"',"+flag2+")");
}


function saveP0000050Fn(operation){
	var p0000050={};
	var preAuthorizationExamineVo={};
	 //预授权号
	 p0000050.preNo=$("#P0000050notice").find("#preNoText").val();
	 
	var p0000050Info=$("#P0000050notice").find("#noticeInfo");
	p0000050.applyHospitalName=$(p0000050Info).find("#tblOne tr:eq(0)").find("td input:eq(0)").val();//医疗机构
	p0000050.applyAgencyName=$(p0000050Info).find("#tblOne tr:eq(0)").find("td input:eq(1)").val();//委托机构
	p0000050.fax=$(p0000050Info).find("#tblOne tr:eq(1)").find("td:eq(0) input").val();//传真号码
	p0000050.tel=$(p0000050Info).find("#tblOne tr:eq(1)").find("td:eq(1) input").val();//电话号码
	
	p0000050.patientName=$(p0000050Info).find("#tblTwo tr:eq(1)").find("td:eq(0) input").val();//患者姓名
	var bthdate=$(p0000050Info).find("#tblTwo tr:eq(1)").find("td:eq(1) input").val();//患者出生日期
	p0000050.bthdate=bthdate.replace(/\//g,"-");
	p0000050.patientSex=$(p0000050Info).find("#tblTwo tr:eq(2)").find("td:eq(0) input").val();//患者性别
	p0000050.patientTel=$(p0000050Info).find("#tblTwo tr:eq(2)").find("td:eq(1) input").val();//联系电话
	p0000050.patientType=$(p0000050Info).find("#tblTwo tr:eq(3)").find("td:eq(0) input").val();//证件类型
	p0000050.patientPid=$(p0000050Info).find("#tblTwo tr:eq(3)").find("td:eq(1) input").val();//有效证件号码
	
	p0000050.policyNo=$(p0000050Info).find("#tblTwo tr:eq(4)").find("td:eq(0) input").val();//保单号
	p0000050.valid=$(p0000050Info).find("#tblTwo tr:eq(4)").find("td:eq(1) input").val();//保险有效期

	p0000050.companyName=$(p0000050Info).find("#tblTwo tr:eq(5)").find("td:eq(0) input").val();//单位名称
	p0000050.personName=$(p0000050Info).find("#tblTwo tr:eq(6)").find("td:eq(0) input").val();//申请人
	p0000050.itemMode=$(p0000050Info).find("#tblTwo tr:eq(7)").find("td:eq(0) input").val();//诊疗形式
	var visitDate=$(p0000050Info).find("#tblTwo tr:eq(8)").find("td:eq(0) input").val();//就诊日期
	p0000050.visitDate=visitDate.replace(/\//g,"-");
	p0000050.hospitalDay=$(p0000050Info).find("#tblTwo tr:eq(8)").find("td:eq(1) input").val();//住院天数
	p0000050.illZdName=$(p0000050Info).find("#tblTwo tr:eq(9)").find("td:eq(0) input").val();//医疗诊断（icd10）
	p0000050.preProject=$(p0000050Info).find("#tblTwo tr:eq(10)").find("td:eq(0) input").val();//医疗诊断（icd10）
	p0000050.guaranteeAmtMax=$("#p0000050MaxAmt").val();//最高担保金额
//	p0000050.guaranteeAmt=$("#p0000050GuaranteeAmt").val();//分项担保限额
	p0000050.guaranteeAmt=$("#guaranteeAmt").val();//分项担保限额//暂用此处
	p0000050.guaranteeMatter=$("#p0000050GuaranteeMatter").val();//除外事项
	p0000050.infoTel=$("#p0000050InfoTel").val();
	
	var preProjectList=[];
	$("#divPreProjectPremTbl tr:gt(0):lt("+($("#divPreProjectPremTbl tr:gt(0)").length-1)+")").each(function(){
//	 $("#divPreProjectPremTbl tr:gt(0)").each(function (){
		 var preProject={};
		 preProject.amtProject=$(this).find("input:eq(0)").val();// 费用项目名称
		 preProject.amtPre= $(this).find("input:eq(1)").val();// 预授权申请金额
		 preProject.amtApp= $(this).find("input:eq(2)").val();// 预授权核准金额
		 preProject.describe=$(this).find("input:eq(3)").val();// 备注
		 preProjectList.push(preProject);
	 });
	 preAuthorizationExamineVo.p0000050=p0000050;
	 preAuthorizationExamineVo.operation=operation;
	 preAuthorizationExamineVo.noticeNo="P0000050";
	 preAuthorizationExamineVo.preNo=p0000050.preNo;
	 preAuthorizationExamineVo.preProjectList=preProjectList;
	 
	 $.ajax({
			type : "POST",
			url : "requestExamineNotice.do",
			contentType:"application/json; charset=UTF-8",
			data : JSON.stringify(preAuthorizationExamineVo),
			success : function(data) {
				if("2"==operation){
					if(data){
						alert("打印成功");
					}else{
						alert("打印失败");
					}
					
				}else{
					alert("保存成功");
				}
				
			},
			error : function(data) {
				if("2"==operation){
					alert("打印失败");
				}else{
					alert("保存失败");
				}
				return false;
			}
		});
	 
}
function saveP0000051Fn(operation){
	var p0000051={};
	var preAuthorizationExamineVo={};
	p0000051.preNo=$("#P0000051notice").find("#preNoText").val();//预授权号
	
	var p0000051Info=$("#P0000051notice").find("#noticeInfo");
	p0000051.applicantName=$(p0000051Info).find("input:eq(0)").val();// 申请人
	p0000051.refuse=$(p0000051Info).find("input:eq(1)").val();// 拒绝理由
	
	p0000051.patientName=$(p0000051Info).find("#tblOne tr:eq(0)").find("td:eq(0) input").val();// 患者姓名
	var bthdate=$(p0000051Info).find("#tblOne tr:eq(0)").find("td:eq(1) input").val();// 患者出生日期
	p0000051.bthdate=bthdate.replace(/\//g,"-");
	p0000051.patientSex=$(p0000051Info).find("#tblOne tr:eq(1)").find("td:eq(0) input").val();// 患者性别
	p0000051.patientTel=$(p0000051Info).find("#tblOne tr:eq(1)").find("td:eq(1) input").val();// 联系电话
	p0000051.	patientType=$(p0000051Info).find("#tblOne tr:eq(2)").find("td:eq(0) input").val();// 证件类型
	p0000051.patientPid=$(p0000051Info).find("#tblOne tr:eq(2)").find("td:eq(1) input").val();// 有效证件号码
	p0000051.patientEmail=$(p0000051Info).find("#tblOne tr:eq(3)").find("td:eq(0) input").val();// 邮件地址
	p0000051.policyno=$(p0000051Info).find("#tblOne tr:eq(3)").find("td:eq(1) input").val();// 保单号
	p0000051.companyName=$(p0000051Info).find("#tblOne tr:eq(4)").find("td:eq(0) input").val();// 单位名称
	
	p0000051.hospitalName=$(p0000051Info).find("#tblTwo tr:eq(0)").find("td:eq(0) input").val();// 医疗机构
	p0000051.hospitalFax=$(p0000051Info).find("#tblTwo tr:eq(0)").find("td:eq(1) input").val();// 传真号码
	p0000051.contactPerson=$(p0000051Info).find("#tblTwo tr:eq(1)").find("td:eq(0) input").val();// 联系人
	p0000051.hospitalTel=$(p0000051Info).find("#tblTwo tr:eq(1)").find("td:eq(1) input").val();// 联系电话
	p0000051.doctorName=$(p0000051Info).find("#tblTwo tr:eq(2)").find("td:eq(0) input").val();// 主治/主刀医生姓名
	p0000051.hospitalEmail=$(p0000051Info).find("#tblTwo tr:eq(2)").find("td:eq(1) input").val();// 邮件地址
	
	p0000051.visitReason=$(p0000051Info).find("#tblThree tr:eq(0)").find("td:eq(0) input").val();// 就诊原因
	var accidentDate=$(p0000051Info).find("#tblThree tr:eq(0)").find("td:eq(1) input").val();// 意外/病症出现日期
	p0000051.accidentDate=accidentDate.replace(/\//g,"-");
	var visitDate=$(p0000051Info).find("#tblThree tr:eq(1)").find("td:eq(0) input").val();// 本次就诊日期
	p0000051.visitDate=visitDate.replace(/\//g,"-");
	
	var visitDateFirst=$(p0000051Info).find("#tblThree tr:eq(1)").find("td:eq(1) input").val();// 初诊日期
	p0000051.visitDateFirst=visitDateFirst.replace(/\//g,"-");
	p0000051.report=$(p0000051Info).find("#tblThree tr:eq(2)").find("td:eq(0) input").val();// 主诉
	p0000051.illzdname=$(p0000051Info).find("#tblThree tr:eq(2)").find("td:eq(1) input").val();// 医疗诊断（ICD10）
	p0000051.prevalenceStatus=$(p0000051Info).find("#tblThree tr:eq(3)").find("td:eq(0) input").val();// 发病状况
	p0000051.physiqueCheck=$(p0000051Info).find("#tblThree tr:eq(4)").find("td:eq(0) input").val();// 体格检查结果
	p0000051.labCheck=$(p0000051Info).find("#tblThree tr:eq(5)").find("td:eq(0) input").val();// 实验室检查结果
	p0000051.diseaseHistory=$(p0000051Info).find("#tblThree tr:eq(6)").find("td:eq(0) input").val();// 既往疾病及治疗史
	
	
	 preAuthorizationExamineVo.p0000051=p0000051;
	 preAuthorizationExamineVo.operation=operation;
	 preAuthorizationExamineVo.noticeNo="P0000051";
	 preAuthorizationExamineVo.preNo=p0000051.preNo;
	 
	 $.ajax({
			type : "POST",
			url : "requestExamineNotice.do",
			contentType:"application/json; charset=UTF-8",
			data : JSON.stringify(preAuthorizationExamineVo),
			success : function(data) {
				if("2"==operation){
					alert("打印成功");
				}else{
					alert("保存成功");
				}
			},
			error : function(data) {
				if("2"==operation){
					alert("打印失败");
				}else{
					alert("保存失败");
				}
				return false;
			}
		});
}
function saveP0000052Fn(operation){
	var preAuthorizationExamineVo={};
	var p0000052={};
	var p0000052Info=$("#P0000052notice").find("#noticeInfo");
	 //预授权号
	 p0000052.preNo=$("#P0000052notice").find("#preNoText").val();
	 p0000052.applicantName=$(p0000052Info).find("input:eq(0)").val();
	 p0000052.meetSituation=$(p0000052Info).find("input:eq(1)").val();
	 //患者信息
	 p0000052.patientName=$(p0000052Info).find("#tblOne tr:eq(0)").find("td:eq(0) input").val();
	 var bthDate=$(p0000052Info).find("#tblOne tr:eq(0)").find("td:eq(1) input").val();//患者出生日期
	 p0000052.bthDate= bthDate.replace(/\//g,"-");
	 p0000052.patientSex=$(p0000052Info).find("#tblOne tr:eq(1)").find("td:eq(0) input").val();//患者性别
	 p0000052.patientTel=$(p0000052Info).find("#tblOne tr:eq(1)").find("td:eq(1) input").val();//联系电话
	 p0000052.patientType=$(p0000052Info).find("#tblOne tr:eq(2)").find("td:eq(0) input").val();//证件类型
	 p0000052.patientPid=$(p0000052Info).find("#tblOne tr:eq(2)").find("td:eq(1) input").val();//有效证件号码
	 p0000052.patientEmail=$(p0000052Info).find("#tblOne tr:eq(3)").find("td:eq(0) input").val();//邮件地址
	 p0000052.policyno=$(p0000052Info).find("#tblOne tr:eq(3)").find("td:eq(1) input").val();//保单号
	 p0000052.companyName=$(p0000052Info).find("#tblOne tr:eq(4)").find("td:eq(0) input").val();//单位名称
	 //医疗信息
	 p0000052.hospitalName=$(p0000052Info).find("#tblTwo tr:eq(0)").find("td:eq(0) input").val();//医疗机构
	 p0000052.hospitalFax=$(p0000052Info).find("#tblTwo tr:eq(0)").find("td:eq(1) input").val();//传真号码
	 p0000052.contactPerson=$(p0000052Info).find("#tblTwo tr:eq(1)").find("td:eq(0) input").val();//联系人
	 p0000052.hospitalTel=$(p0000052Info).find("#tblTwo tr:eq(1)").find("td:eq(1) input").val();//联系电话
	 p0000052.doctorName=$(p0000052Info).find("#tblTwo tr:eq(2)").find("td:eq(0) input").val();//主治/主刀医生姓名
	 p0000052.hospitalEmail=$(p0000052Info).find("#tblTwo tr:eq(2)").find("td:eq(1) input").val();//邮件地址
	 p0000052.visitReason=$(p0000052Info).find("#tblThree tr:eq(0)").find("td:eq(0) input").val();//就诊原因
	 var accidentDate=$(p0000052Info).find("#tblThree tr:eq(0)").find("td:eq(1) input").val();//意外/病症出现日期
	 
	 p0000052.accidentDate= accidentDate.replace(/\//g,"-");
	 
	 var visitDate=$(p0000052Info).find("#tblThree tr:eq(1)").find("td:eq(0) input").val();//本次就诊日期
	 
	 p0000052.visitDate=visitDate.replace(/\//g,"-");
	 
	 var visitDateFirst=$(p0000052Info).find("#tblThree tr:eq(1)").find("td:eq(1) input").val();//初诊日期
	 p0000052.visitDateFirst= visitDateFirst.replace(/\//g,"-");
	 
	 p0000052.report=$(p0000052Info).find("#tblThree tr:eq(2)").find("td:eq(0) input").val();//主诉
	 p0000052.illzdname=$(p0000052Info).find("#tblThree tr:eq(2)").find("td:eq(1) input").val();//医疗诊断（icd10）
	 p0000052.prevalenceStatus=$(p0000052Info).find("#tblThree tr:eq(3)").find("td:eq(0) input").val();//发病状况
	 p0000052.physiqueCheck=$(p0000052Info).find("#tblThree tr:eq(4)").find("td:eq(0) input").val();//体格检查结果
	 p0000052.labCheck=$(p0000052Info).find("#tblThree tr:eq(5)").find("td:eq(0) input").val();//实验室检查结果
	 p0000052.diseaseHistory=$(p0000052Info).find("#tblThree tr:eq(6)").find("td:eq(0) input").val();//既往疾病及治疗史
	 
	 preAuthorizationExamineVo.p0000052=p0000052;
	 preAuthorizationExamineVo.operation=operation;
	 preAuthorizationExamineVo.noticeNo="P0000052";
	 preAuthorizationExamineVo.preNo=p0000052.preNo;
	 
	 $.ajax({
			type : "POST",
			url : "requestExamineNotice.do",
			contentType:"application/json; charset=UTF-8",
			data : JSON.stringify(preAuthorizationExamineVo),
			success : function(data){
				if("2"==operation){
					alert("打印成功");
				}else{
					alert("保存成功");
				}
			},
			error :function(data){
				if("2"==operation){
					alert("打印失败");
				}else{
					alert("保存失败");
				}
				return ;
			}
		});
}



































function printNoticeFn(flag,flag2){
	$(flag2).removeAttr("onclick");
	var preNo=$("#preNo").val();
	var operation="1";
	$("#number").val(1);
	showDiv(flag);
	//查询请求
	requestJson='{"noticeNo":"'+flag+'","preNo":"'+preNo+'","operation":"'+operation+'"}';
	$("#botOpen1").css("display","none");
	$.ajax({
		type : "POST",
		url : "requestExamineNotice.do",
		contentType:"application/json; charset=UTF-8",
		data : requestJson,
		success : function(data) {
			$(flag2).attr("onclick","printNoticeFn('"+flag+"',this)");
			if("P0000050"==flag){
				p0000050Fn(data);
			}else if("P0000051"==flag){
				p0000051Fn(data);
			}else if("P0000052"==flag){
				p0000052Fn(data);
			}
		},
		error : function(data) {
			$(flag2).attr("onclick","printNoticeFn('"+flag+"',this)");
			alert("不能找到通知书，请手工填写！");
			return false;
		}
	});
	
}
function p0000050Fn(flag){
	var d = new Date();
	var vYear = d.getFullYear();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	$("#p0000050Y").val(vYear);
	$("#p0000050M").val(vMon);
	$("#p0000050D").val(vDay);
	$("#P0000050notice").find("div:eq(0)").find("b").text("预授权号："+flag.preNo);//预授权号
	$("#P0000050notice").find("div:eq(0)").find("input").val(flag.preNo);//预授权号
	if(flag.p0000050==null || flag.p0000050==""){
		return ;
	}
	var p0000050Info=$("#P0000050notice").find("#noticeInfo");
	$(p0000050Info).find("#tblOne tr:eq(0)").find("td input:eq(0)").val(flag.p0000050.applyHospitalName);//医疗机构
	$(p0000050Info).find("#tblOne tr:eq(0)").find("td input:eq(1)").val(flag.p0000050.applyAgencyName);//委托机构
	$(p0000050Info).find("#tblOne tr:eq(1)").find("td:eq(0) input").val(flag.p0000050.fax);//传真号码
	$(p0000050Info).find("#tblOne tr:eq(1)").find("td:eq(1) input").val(flag.p0000050.tel);//电话号码
	
	$(p0000050Info).find("#tblTwo tr:eq(1)").find("td:eq(0) input").val(flag.p0000050.patientName);//患者姓名
	$(p0000050Info).find("#tblTwo tr:eq(1)").find("td:eq(1) input").val(jsonDateFormat(flag.p0000050.bthdate,10,"/"));//患者出生日期
	$(p0000050Info).find("#tblTwo tr:eq(2)").find("td:eq(0) input").val(flag.p0000050.patientSex);//患者性别
	$(p0000050Info).find("#tblTwo tr:eq(2)").find("td:eq(1) input").val(flag.p0000050.patientTel);//联系电话
	$(p0000050Info).find("#tblTwo tr:eq(3)").find("td:eq(0) input").val(flag.p0000050.patientType);//证件类型
	$(p0000050Info).find("#tblTwo tr:eq(3)").find("td:eq(1) input").val(flag.p0000050.patientPid);//有效证件号码
	$(p0000050Info).find("#tblTwo tr:eq(4)").find("td:eq(0) input").val(flag.p0000050.policyNo);//保单号
	$(p0000050Info).find("#tblTwo tr:eq(4)").find("td:eq(1) input").val(flag.p0000050.valid);//保险有效期

	$(p0000050Info).find("#tblTwo tr:eq(5)").find("td:eq(0) input").val(flag.p0000050.companyName);//单位名称
	$(p0000050Info).find("#tblTwo tr:eq(6)").find("td:eq(0) input").val(flag.p0000050.personName);//申请人
	$(p0000050Info).find("#tblTwo tr:eq(7)").find("td:eq(0) input").val(flag.p0000050.itemMode);//诊疗形式
	$(p0000050Info).find("#tblTwo tr:eq(8)").find("td:eq(0) input").val(jsonDateFormat(flag.p0000050.visitDate,10,"/"));//就诊日期
	$(p0000050Info).find("#tblTwo tr:eq(8)").find("td:eq(1) input").val(flag.p0000050.hospitalDay);//住院天数
	$(p0000050Info).find("#tblTwo tr:eq(9)").find("td:eq(0) input").val(flag.p0000050.illZdName);//医疗诊断（icd10）
	$(p0000050Info).find("#tblTwo tr:eq(10)").find("td:eq(0) input").val(flag.p0000050.preProject);//医疗诊断（icd10）
	$("#p0000050GuaranteeMatter").val(flag.p0000050.guaranteeMatter);//除外事项
	$("#p0000050GuaranteeAmt").val(flag.p0000050.guaranteeAmt);
	$("#p0000050MaxAmt").val(flag.p0000050.guaranteeAmtMax);
//	var tblPremTitile=$("	<tr><th>费用项目</th><th>预授权申请金额</th><th>预授权核准金额</th><th>备注</th></tr>");
//	$("#tblPrem").remove("tr:gt(0)");
//	$("#tblPrem").append(tblPremTitile);
	var premAmt=0;
	var premApp=0;
	$.ajax({
		type : "POST",
		url : "requestpreProjectList.do",
		data : {"preNo":flag.preNo},
		success : function(data) {
			if(data!=null && data!=""){
				var tabletext="<table id=\"divPreProjectPremTbl\" class=\"tzs_tab_li\" style=\"padding:0px;margin:0px;width:100%;border:0px;\"><tr><td class=\"input i_s_150\">费用项目</td><td>预授权申请金额</td><td>预授权核准金额</td><td>备注</td></tr>";
				for ( var i = 0; i < data.length; i++) {
					var obj=data[i];
					premAmt=Number(premAmt)+Number(obj.amtPre);
					premApp=Number(premApp)+Number(obj.amtApp);
					tabletext+="<tr><td><input type=\"text\"  style=\"border:0px;\" class=\"input i_s_150\" value='"+obj.projectName+"'/></td>"+
		        		"<td><input type=\"text\" onblur=\"addNoticePrejectAmt('1','premAmt')\"  style=\"border:0px;\" class=\"input i_s_150\" value='"+(obj.amtPre==null?"0":obj.amtPre)+"'/></td>"+
		        		"<td><input type=\"text\"  onblur=\"addNoticePrejectAmt('2','premApp')\"   style=\"border:0px;\" class=\"input i_s_150\" value='"+(obj.amtApp==null?"0":obj.amtApp)+"'/></td>"+
		        		"<td><input type=\"text\"  style=\"border:0px;\" class=\"input i_s_150\" value='"+(obj.describe==null?"":obj.describe)+"'/></td></tr>";
					
//					$("#premAmt").val(premAmt);
//					$("#premApp").val(premApp);
				}
				tabletext+="<tr><td class=\"input i_s_150\">合计</td><td id=\"premAmt\">"+premAmt+"</td><td id=\"premApp\">"+premApp+"</td><td>&nbsp;</td></tr>"+
									"</table>";
				$("#tblPrem").html(tabletext);
			}else{
				$("#tblPrem").html("<table id=\"divPreProjectPremTbl\" class=\"tzs_tab_li\" style=\"padding:0px;margin:0px;width:100%\"><tr><td class=\"input i_s_150\">费用项目</td><td>预授权申请金额</td><td>预授权核准金额</td><td>备注</td></tr>"+
				"<tr><td>合计</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"
				+"</table>");
			}
		},
		error : function(data) {
			return false;
		}
	});
}
function addNoticePrejectAmt(flag,flag2){
	var totalAmt=0;
	 $("#divPreProjectPremTbl tr:gt(0)").each(function (){
		 var amt=$(this).find("td:eq("+flag+")").find("input").val();
			if(amt=='' || amt ==undefined ){
				amt=0;
			}
		totalAmt=totalAmt*1+amt*1;
	 });
		$("#"+flag2).text(totalAmt);
		$("#p0000050MaxAmt").val($("#premApp").text());
}

function checkfoxNo( foxNo ) { 
	var phoneRegWithArea = /^[0][1-9]{2,3}-[0-9]{5,10}$/; 
	var phoneRegNoArea = /^[1-9]{1}[0-9]{5,8}$/; 
	if( foxNo.length > 9 ) { 
	if( phoneRegWithArea.test(foxNo) ){ 
	return true; 
	}else{ 
	return false; 
	} 
	}else{ 
	if( phoneRegNoArea.test( foxNo ) ){ 
	return true; 
	}else{ 
	return false; 
	} 
	} 
	} 


function p0000051Fn(flag){
	$("#P0000051notice").find("div:eq(0)").find("b").text("预授权号："+flag.preNo);//预授权号
	$("#P0000051notice").find("div:eq(0)").find("input").val(flag.preNo);//预授权号
	if(flag.p0000051==null || flag.p0000051==""){
		return ;
	}
	var p0000051Info=$("#P0000051notice").find("#noticeInfo");
	$(p0000051Info).find("input:eq(0)").val(flag.p0000051.applicantName);// 申请人
	$(p0000051Info).find("input:eq(1)").val(flag.p0000051.refuse);// 拒绝理由
	
	$(p0000051Info).find("#tblOne tr:eq(0)").find("td:eq(0) input").val(flag.p0000051.patientName);// 患者姓名
	$(p0000051Info).find("#tblOne tr:eq(0)").find("td:eq(1) input").val(jsonDateFormat(flag.p0000051.bthdate,10,"/"));// 患者出生日期
	$(p0000051Info).find("#tblOne tr:eq(1)").find("td:eq(0) input").val(flag.p0000051.patientSex);// 患者性别
	$(p0000051Info).find("#tblOne tr:eq(1)").find("td:eq(1) input").val(flag.p0000051.patientTel);// 联系电话
	$(p0000051Info).find("#tblOne tr:eq(2)").find("td:eq(0) input").val(flag.p0000051.patientType);// 证件类型
	$(p0000051Info).find("#tblOne tr:eq(2)").find("td:eq(1) input").val(flag.p0000051.patientPid);// 有效证件号码
	$(p0000051Info).find("#tblOne tr:eq(3)").find("td:eq(0) input").val(flag.p0000051.patientEmail);// 邮件地址
	$(p0000051Info).find("#tblOne tr:eq(3)").find("td:eq(1) input").val(flag.p0000051.policyno);// 保单号
	$(p0000051Info).find("#tblOne tr:eq(4)").find("td:eq(0) input").val(flag.p0000051.companyName);// 单位名称
	
	$(p0000051Info).find("#tblTwo tr:eq(0)").find("td:eq(0) input").val(flag.p0000051.hospitalName);// 医疗机构
	$(p0000051Info).find("#tblTwo tr:eq(0)").find("td:eq(1) input").val(flag.p0000051.hospitalFax);// 传真号码
	$(p0000051Info).find("#tblTwo tr:eq(1)").find("td:eq(0) input").val(flag.p0000051.contactPerson);// 联系人
	$(p0000051Info).find("#tblTwo tr:eq(1)").find("td:eq(1) input").val(flag.p0000051.hospitalTel);// 联系电话
	$(p0000051Info).find("#tblTwo tr:eq(2)").find("td:eq(0) input").val(flag.p0000051.doctorName);// 主治/主刀医生姓名
	$(p0000051Info).find("#tblTwo tr:eq(2)").find("td:eq(1) input").val(flag.p0000051.hospitalEmail);// 邮件地址
	
	$(p0000051Info).find("#tblThree tr:eq(0)").find("td:eq(0) input").val(flag.p0000051.visitReason);// 就诊原因
	$(p0000051Info).find("#tblThree tr:eq(0)").find("td:eq(1) input").val(jsonDateFormat(flag.p0000051.accidentDate,10,"/"));// 意外/病症出现日期
	$(p0000051Info).find("#tblThree tr:eq(1)").find("td:eq(0) input").val(jsonDateFormat(flag.p0000051.visitDate,10,"/"));// 本次就诊日期
	$(p0000051Info).find("#tblThree tr:eq(1)").find("td:eq(1) input").val(jsonDateFormat(flag.p0000051.visitDateFirst,10,"/"));// 初诊日期
	$(p0000051Info).find("#tblThree tr:eq(2)").find("td:eq(0) input").val(flag.p0000051.report);// 主诉
	$(p0000051Info).find("#tblThree tr:eq(2)").find("td:eq(1) input").val(flag.p0000051.illzdname);// 医疗诊断（ICD10）
	$(p0000051Info).find("#tblThree tr:eq(3)").find("td:eq(0) input").val(flag.p0000051.prevalenceStatus);// 发病状况
	$(p0000051Info).find("#tblThree tr:eq(4)").find("td:eq(0) input").val(flag.p0000051.physiqueCheck);// 体格检查结果
	$(p0000051Info).find("#tblThree tr:eq(5)").find("td:eq(0) input").val(flag.p0000051.labCheck);// 实验室检查结果
	$(p0000051Info).find("#tblThree tr:eq(6)").find("td:eq(0) input").val(flag.p0000051.diseaseHistory);// 既往疾病及治疗史
}
function p0000052Fn(flag){
	//预授权号
	$("#P0000052notice").find("div:eq(0)").find("input").val(flag.preNo);
	$("#P0000052notice").find("div:eq(0)").find("b").text("预授权号："+flag.preNo);
	if(flag.p0000052==null || flag.p0000052==""){
		return ;
	}
	var p0000052Info=$("#P0000052notice").find("#noticeInfo");
	$(p0000052Info).find("input:eq(0)").val(flag.p0000052.applicantName);
	$(p0000052Info).find("input:eq(1)").val(flag.p0000052.meetSituation);
	//患者信息
	$(p0000052Info).find("#tblOne tr:eq(0)").find("td:eq(0) input").val(flag.p0000052.patientName);
	$(p0000052Info).find("#tblOne tr:eq(0)").find("td:eq(1) input").val(jsonDateFormat(flag.p0000052.bthDate,10,"/"));//患者出生日期
	$(p0000052Info).find("#tblOne tr:eq(1)").find("td:eq(0) input").val(flag.p0000052.patientSex);//患者性别
	$(p0000052Info).find("#tblOne tr:eq(1)").find("td:eq(1) input").val(flag.p0000052.patientTel);//联系电话
	$(p0000052Info).find("#tblOne tr:eq(2)").find("td:eq(0) input").val(flag.p0000052.patientType);//证件类型
	$(p0000052Info).find("#tblOne tr:eq(2)").find("td:eq(1) input").val(flag.p0000052.patientPid);//有效证件号码
	$(p0000052Info).find("#tblOne tr:eq(3)").find("td:eq(0) input").val(flag.p0000052.patientEmail);//邮件地址
	$(p0000052Info).find("#tblOne tr:eq(3)").find("td:eq(1) input").val(flag.p0000052.policyno);//保单号
	$(p0000052Info).find("#tblOne tr:eq(4)").find("td:eq(0) input").val(flag.p0000052.companyName);//单位名称
	//医疗信息
	$(p0000052Info).find("#tblTwo tr:eq(0)").find("td:eq(0) input").val(flag.p0000052.hospitalName);//医疗机构
	$(p0000052Info).find("#tblTwo tr:eq(0)").find("td:eq(1) input").val(flag.p0000052.hospitalFax);//传真号码
	$(p0000052Info).find("#tblTwo tr:eq(1)").find("td:eq(0) input").val(flag.p0000052.contactPerson);//联系人
	$(p0000052Info).find("#tblTwo tr:eq(1)").find("td:eq(1) input").val(flag.p0000052.hospitalTel);//联系电话
	$(p0000052Info).find("#tblTwo tr:eq(2)").find("td:eq(0) input").val(flag.p0000052.doctorName);//主治/主刀医生姓名
	$(p0000052Info).find("#tblTwo tr:eq(2)").find("td:eq(1) input").val(flag.p0000052.hospitalEmail);//邮件地址
	$(p0000052Info).find("#tblThree tr:eq(0)").find("td:eq(0) input").val(flag.p0000052.visitReason);//就诊原因
	$(p0000052Info).find("#tblThree tr:eq(0)").find("td:eq(1) input").val(jsonDateFormat(flag.p0000052.accidentDate,10,"/"));//意外/病症出现日期
	$(p0000052Info).find("#tblThree tr:eq(1)").find("td:eq(0) input").val(jsonDateFormat(flag.p0000052.visitDate,10,"/"));//本次就诊日期
	$(p0000052Info).find("#tblThree tr:eq(1)").find("td:eq(1) input").val(jsonDateFormat(flag.p0000052.visitDateFirst,10,"/"));//初诊日期
	$(p0000052Info).find("#tblThree tr:eq(2)").find("td:eq(0) input").val(flag.p0000052.report);//主诉
	$(p0000052Info).find("#tblThree tr:eq(2)").find("td:eq(1) input").val(flag.p0000052.illzdname);//医疗诊断（icd10）
	$(p0000052Info).find("#tblThree tr:eq(3)").find("td:eq(0) input").val(flag.p0000052.prevalenceStatus);//发病状况
	$(p0000052Info).find("#tblThree tr:eq(4)").find("td:eq(0) input").val(flag.p0000052.physiqueCheck);//体格检查结果
	$(p0000052Info).find("#tblThree tr:eq(5)").find("td:eq(0) input").val(flag.p0000052.labCheck);//实验室检查结果
	$(p0000052Info).find("#tblThree tr:eq(6)").find("td:eq(0) input").val(flag.p0000052.diseaseHistory);//既往疾病及治疗史
}

/**短信内容展示*/
function showSmsContent(preNo,bbrname){
	 var sms_clmPerson;
	 if($('#clmPerson').attr('class')=="check_yes"){
		   sms_clmPerson = 1;

	   }else{
			sms_clmPerson = 0;
	   }
	 
	var operator = $("#operator").val();
	$.ajax({
        cache: true,
        type: "POST",
        url:"showsmscontent.do",
        data:{"preNo":preNo,"bbrName":bbrname,"operator":operator,"sms_clmPerson":sms_clmPerson},
        async: false,
        error: function(request) {
            alert("展示短信失败！");
        },
        success: function(data) {
        	var ba_ms = data[0];
        	$("#ba_ms").text(ba_ms);//被保人
//        	UC00048 
        	if($("#isEmail").val()=="Y"){
        		$("#noticeSendEmailApply").attr("class","check_yes");
        		var mail=$("#applypresonTbl").find("#appEmail").val();
        		if(mail==null || mail=="" || mail==undefined){
        			mail=$("#applyHospitalTbl").find("#appEmail").val();
        		}
        		if(mail==null || mail=="" || mail==undefined){
        			mail=$("#applyTpaTbl").find("#appEmail").val();
        		}
        		$("#applyEmail").val(mail);        		
        		$("#checkIsEmail").css("display","");
        		
        		//标题的显示校验
            	$("#preSmsTit").css("display","none");
    			$("#preSmsAndNoticeTit").css("display","none");
    			$("#preNoticeTit").css("display","none");
    			
    			$("#bbrSms1").css("display","none");
    			$("#bbrSms2").css("display","none");
    			
        		if($("#setValue").val()=="N"){//审核不通过
        			$("#preNoticeTit").css("display","");
        		}else{
        			$("#preSmsAndNoticeTit").css("display","");
        			$("#bbrSms1").css("display","");
        			$("#bbrSms2").css("display","");
        		}
        	}else{
        		$("#preSmsTit").css("display","");
        		$("#bbrSms1").css("display","");
    			$("#bbrSms2").css("display","");
        	}
        	
//        	UC00048
        	showDiv('openMse');
        	
        }
    });
	
	
}

/***发送*/
function sendSmsContent(preNo,bbrname){
	 var sms_clmPerson;
	 if($('#clmPerson').attr('class')=="check_yes"){
		   sms_clmPerson = 1;

	   }else{
			sms_clmPerson = 0;
	   }
	   var operator = $("#operator").val();
	   
	   var applySendEmail=$("#applyEmail").val();
	   
	   
	   if($("#setValue").val()=="N"){//审核不通过
		   sms_clmPerson = 0;
	   }
	   if($("#noticeSendEmailApply").attr("class").indexOf("check_yes")!=-1){
		   var applyEmail=$("#checkIsEmail").find("#applyEmail");
		   checkApplySendEmailFn(applyEmail);
	   }
	$.ajax({
        cache: true,
        type: "POST",
        url:"sendsmscontent.do",
        data:{"preNo":preNo,"bbrName":bbrname,"operator":operator,"sms_clmPerson":sms_clmPerson,"applySendEmail":applySendEmail},
        async: false,
        error: function(request) {
            alert("发送短信失败！");
        },
        success: function(data) { 
        	if(sms_clmPerson=='1' ){
        		if(data){
					 closeDiv('openMse');
	        		 alert("短信发送成功！");
	        		 $("#operator").val('');
				}
       	}
        	}
        	
       
    });
	submitPageFormFn();
}

function changeTotal(flag,flag2){
	var totalAmt1=$(flag).val();
	var totalAmt2=0;
	if(!validateNumber(flag)){
		if(flag2=="1"){//申请金额
			addPrejectAmt();
		}else{//核准金额
			calculateAmount();
		}
		return ;
	}
	if(totalAmt1==null || totalAmt1=="" ||totalAmt1<=0){
		if(flag2=="1"){//申请金额
			addPrejectAmt();
		}else{//核准金额
			calculateAmount();
		}
		return;
	}else{
		if(flag2=="1"){//申请金额
			addPrejectAmt();
			totalAmt2=$("#amt").val();
		}else{//核准金额
			calculateAmount();
			totalAmt2=$("#totalAmt").val();
		}
		if(totalAmt1!=totalAmt2){
			$("#altText"+flag2).css("display","");
		}else{
			$("#altText"+flag2).css("display","none");
		}
		$(flag).val(totalAmt1);
	}
}
function validateNumber(flag){
	var value=$(flag).val();
	if(value==""){
		alert("请输入金额！");
		return false;
	}else{
		if(isNaN(value)){
			alert("请输入一个正确的金额！");
			return false;
		}else{
			if((!isNaN(value)&&value<=0)|| value.indexOf("-")!=-1){
				alert("请输入一个非负数且不为0的金额！");
				return false;
			}else{
				value=parseFloat(value).toFixed(2);
				if(value.length>15){
					alert("请输入一个有效的金额！");
					return false;
				}else{
					$(flag).val(value);
					return true;
				}
			}
		}
	}
}



function checkFsMail(flag,flag2){
	if($(flag2).attr("class").indexOf("check_no")!=-1){
		var mail=null;
		if(flag=='1'){//个人
			mail=$("#applypresonTbl").find("#appEmail").val();
		}else if(flag=='2'){
			mail=$("#applyHospitalTbl").find("#appEmail").val();
		}else if(flag=='3'){
			mail=$("#applyTpaTbl").find("#appEmail").val();
		}
		if(mail==null||mail==undefined||mail==""){
			alert("请录入邮箱地址！");
			$(flag2).attr("class","check_yes");
			return;
		}else{
			if(!checkMail(mail)){
				$(flag2).attr("class","check_yes");
				return;
			}
		}
		$("#applyEmail").val(mail);
		$("#isEmail").val("Y");
	}else{
		$("#isEmail").val("N");
	}
}
function checkMailTwoFn(flag,flag2){
	if($(flag).val()==null || $(flag).val()==""){
		if($(flag2).attr("class").indexOf("check_yes")!=-1){
			alert("如需发送通知书邮件,请录入邮箱地址!");
			$(flag2).attr("class","check_no");
			return ;
		}
	}else{
		if(!checkMail($(flag).val())){
			$(flag2).attr("class","check_no");
			return ;
		}else{
			$("#applyEmail").val($(flag).val());
		}
	}
}

function checkApplySendEmailFn(flag){
	if(!checkMail($(flag).val())){
		$(flag).val('');
		return ;
	}
}



//打开影像
function openImage(sModino){//sModino预授权号
	var branchid = null;
	var inputSource = $("#inputSource").val();
	var casesource = $("#casesource").val();
	if(inputSource=='05'){
		branchid = $("#branchid").val();
		if(casesource=="1"){
			branchid="80000000000009";
		}
	}else{
		branchid='80000000000009';
	}
	   //获取当前网址
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址
    var localhostPath = curWwwPath.substring(0, pos);
	 
	//预授权影像
    window.open(localhostPath+'/claimserver/inspection/clmtask/imageInfo.do?claimNo='+sModino+'&flag=4&branchid='+branchid+'&inputSource='+inputSource+'&casesource='+casesource+'',"预授权影像");
	
	
}

//App预授权短信
function sendApp2Pre(preNo,appName,appPid,appPhone,flag,personId){
		$.ajax({
	        cache: true,
	        type: "POST",
	        url:"sendApp2PreSmscontent.do",
	        data:{"preNo":preNo,"appName":appName,"appPid":appPid,"appPhone":appPhone,"flag":flag,"personId":personId},
	        async: false,
	        error: function(request) {
	            alert("发送短信失败！");
	        },
	        success: function(data) { 
	        	if(data){
	        		 alert("短信发送成功！");
				}
	        }
	    });
	
	
	submitPageFormFn();	
	
}

