$(function(){
//	var inputSource=$("#inputSource").val();
//	var infoList=$("#infoList").val();
//	if(inputSource=='05'&&infoList==''){//app录入方式       
//		alert("医疗机构不匹配！");
//	}
	var isGuarantee = $("#isGuarantee").attr("code");;
	if(isGuarantee=='Y'){
		$("#span1").html("*");
		$("#span2").html("*");
	 }else{
		$("#span1").html("");
		$("#span2").html("");
	}

	var ralationShip = $("#hiddenRelationship").val();
	var applyAgencyName = $("#hiddenApplyAgencyName").val();
	var applyHospitalName = $("#hiddenApplyHospitalName").val();
	if(ralationShip=="408"&& applyHospitalName!=''){//其他,医疗机构
		divformPerson.style.display='none';
		TPAInfo.style.display='none';
		hospitalInfo.style.display='block';
		
//		$("#appInsRelationship").val($("#hiddenRelationship").val());
//		$("#applyHospitalName").val($("#hospname").val());
 //		$("#applyAgencyName").val("");
 		//$("#isGuarantee").text("请选择");
 		$("#applyAgencyName").attr("disabled",true);
 		document.getElementById("Tpa").style.display = "none";
 		
 		$("#HospitalName").val($("#hospname").val());
 		$("#Hospitaladdr").val($("#hospAddr").val());
 		$("#hospitalType").val($("#hospType").val());
 		$("#hospitalContactPerson").val($("#hospContactPerson").val());
 		$("#hospitalContactPhone").val($("#hospPhone").val());
 		$("#hospitalFaxNo").val($("#hospFaxNo").val());
 		$("#hospitalBankAccountName").val($("#bankAccountName").val());
 		$("#hospitalBankName").val($("#hospBankName").val());
 		$("#hospitalBankAccountNo").val($("#hospBankAccountNo").val());
 		$("#hospitalInfo").find("#appEmail").val($("#hospMail").val());
 		
 		//$("#hospitalSpanpaymode").val($("#payType").val());
 		
	}else if(ralationShip=="408"&& applyAgencyName!=''){//其他，委托机构
		divformPerson.style.display='none';
		TPAInfo.style.display='block';
		hospitalInfo.style.display='none';
		
		$("#applyHospitalName").attr("disabled",true);
 		document.getElementById("Hospital").style.display = "none";
 		
 		$("#tpaName").val(applyAgencyName);
 		$("#tpaAddr").val($("#tAddr").val());
 		$("#tpaContactPerson").val($("#tContactPerson").val());
 		$("#tpaContactPhone").val($("#tPhone").val());
 		$("#tpaFaxNo").val($("#tFaxNo").val());
 		$("#tpaBankAccountName").val($("#tbankAccountName").val());
 		$("#tpaBankName").val($("#tBankName").val());
 		$("#tpaBankAccountNo").val($("#tBankAccountNo").val());
 		$("#TPAInfo").find("#appEmail").val($("#tMail").val());
 		//$("#tpaSpanpaymode").val($("#tpayType").val());
	
	}else{//个人
		divformPerson.style.display='block';
		TPAInfo.style.display='none';
		hospitalInfo.style.display='none';
		
		
		//$("#appInsRelationship").val($("#hiddenRelationship").val());
 		$("#appPid").val($("#hiddenPid").val());
 		$("#appName").val($("#hiddenName").val());
 		
 		if($("#hiddenSex").val()=='1'){
 			$("#appSex").text("男");
 		}else if($("#hiddenSex").val()=='2'){
 			$("#appSex").text("女");
 		}
 		
 		if($("#hiddenIidtype").val()=='a'){
 			$("#appIdtype").text("身份证");
 		}else if($("#hiddenIidtype").val()=='c'){
 			$("#appIdtype").text("护照");
 		}else if($("#hiddenIidtype").val()=='d'){
 			$("#appIdtype").text("军官证");
 		}else if($("#hiddenIidtype").val()=='j'){
 			$("#appIdtype").text("港澳台护照");
 		}else if($("#hiddenIidtype").val()=='l'){
 			$("#appIdtype").text("台湾居民通行证");
 		}
 		
 		$("#appPhone").val($("#hiddenPhone").val());
 		$("#appTel").val($("#hiddenTel").val());
 		$("#appContractAddr").val($("#hiddenContractAddr").val());
 		$("#appPostCode").val($("#hiddenPostCode").val());
 		$("#appEmail").val($("#hiddenEmail").val());
 		$("#appFax").val($("#hiddenFax").val());
 		$("#applyHospitalName").val("");
 		$("#applyAgencyName").val("");
 		//$("#isGuarantee").text("请选择");
 		$("#applyHospitalName").attr("disabled",true);
 		$("#applyAgencyName").attr("disabled",true);
 		document.getElementById("Hospital").style.display = "none";
 		document.getElementById("Tpa").style.display = "none";
		
	
	}
	
	
});






var productList='';
var index = -1;
//是否为医疗机构医疗信息标识
var yljgFlag='0';
$(function(){
	if($("#ylxxIllsBy_").val() !=''){
		showylxxDiv('init');
	}
	if($("#claimIllsBy_").val() !=''){
		showjvDiv('init');
	}
	if($("#sqxmIllsBy_").val() !=''){
		showsqxmDiv('init');
	}
	getProductList();
	calculateAmount("0");
});

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=\"\" class=\"input i_s_137 input_bot_line\"  onblur=\"calculateAmount('1');\" style=\"text-align:center;\"/></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 delProduct(){
	if(index!=-1){
    	$("#productList tr:eq("+index+")").remove();
		index=-1;
    	alert("删除成功");
    	calculateAmount("1");
	}else if(index == -1){
		alert("请选择需要删除的项目");
	}
	
}
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 saveAllInfo(flag){
	var channelType =  $("#channelType").val();
	var caseSource;
	var businessSource = $("#businesssource").val();
	if(channelType=="0"||channelType==""){
		caseSource = "3"; 
	}else if(channelType=="1"){
		caseSource = "2";
	}else if(channelType=="2"){
		caseSource = "1";
		
	}
	
	
	
	var PreauthorizationAcceptVo = {};
	var preTaskPre = {};
	var clmPerson = {};
	var insured = {};
	var partnerInfo = {};
	var hospitalInfo = {};
	var agentInfo =  {};
	var preClassLiabList = [];
	
	var preMedical = {};
	var preMedicalInfo={};
	var preProject = [];
	var isOk = true;
	var isok = true;
	var checkmoney = true;
	
	var preNo = $("#preNo").val();
	
	var auditBasis = $("#auditBasis").val(); //审核依据 by lirui20160616
	if(auditBasis.length>300){
		alert("审核依据长度超过最大限制，请重新输入！");
		return false;
	}
	
	
	//申请人信息
	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();
	
	//申请人必录信息校验
	if(!checkEmpty(appInsRelationship,"关系必录")){
		return;
	}
	if(appInsRelationship=='401'||appInsRelationship=='406'){
		if(!checkEmpty(appIdtype,"申请人证件类型必录")){
			return;
		}
		if(!checkEmpty(appPid,"申请人证件号码必录")){
			return;
		}
		if(appIdtype=='a' && !checkIdentityCardTrueOrFalse(appPid)){
			alert("申请人身份证输入不合法，请重新输入！");
			return false;
		}
		
		if(!checkEmpty(appName,"申请人姓名必录")){
			return;
		}
		if(!checkEmpty(appSex,"申请人性别必录")){
			return;
		}
		
		var reg = /^1[358][0-9]{9}$/;
		if(appPhone=='' && appTel==''){
			alert("申请人手机号码和固定电话两者必录其一");
			return false;
		}else{
			/*if(appPhone !='' && !checkMobile(appPhone)){
				alert("手机号码格式不正确");
				return false;
			}
			*/
			if($.trim($("#appPhone").val()).length!=0){
				if(!reg.test($.trim($("#appPhone").val()))){
					alert("申请人手机号码 填写格式不正确，请重新填写。");
					return;
				}
			}
			
			if(appTel !='' && !checkPhone(appTel)){
				alert("申请人联系电话填写格式不正确，请重新填写。");
				return false;
			}
		}
		if(appFax !='' && !checkFax(appFax)){
			return false;
		}
			if($("#appEmail").val().length!=0){
			if(!emailCheck($("#appEmail").val())){
				alert("申请人邮箱格式不正确，请重新录入。");
				return;
			}
		}
		
		if(isGuarantee=='Y'&&appEmail==''&&appFax==''){
			alert("邮箱或传真两者必录其一");
			return;
		}
		 
		
		
	}
	if(appInsRelationship =='408' && applyHospitalName=='' && applyAgencyName==''){
		alert("医疗机构或委托机构两者必录其一");
		return;
	}
	if(!checkEmpty(isGuarantee,"担保函必录")){
		return;
	}
	
	
	
	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;
	preTaskPre.caseSource = caseSource;
	preTaskPre.businessSource = businessSource ; 
	
	preTaskPre.isSendEmail=$("#isEmail").val();
	
	preTaskPre.auditBasis = auditBasis;
	
	//患者信息
	insured.name = $("#insName").html();
	insured.bthdate =$("#insBthdate").text();
	insured.idtype =$("#insIdtype").val();
	insured.sex =$("#insSex").val();
	insured.pid =$("#insPid").html();
	insured.phone =$("#insPhone").val();
	preTaskPre.insuredName =insured.name;
	preTaskPre.insuredPid=insured.pid;
	if($.trim($("#phone").val()).length!=0){
		if(!reg.test($.trim($("#phone").val()))){
			alert("患者手机号码 填写格式不正确，请重新填写。");
			return;
		}
	}
	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()==""){
		alert("医疗机构信息必录");
		return;
	}
	
	//医疗机构信息
	partnerInfo.medinsChnName = $("#partnerName").val();
	partnerInfo.chnAddress = $("#Hospitaladdr").val();
	partnerInfo.accountName = $("#hospitalBankAccountName").val();
	partnerInfo.accountNo = $("#hospitalBankAccountNo").val();
	partnerInfo.bankName = $("#hospitalBankName").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();
	
	
	//申请人-医疗机构信息
	if(applyHospitalName!=""){
		
		hospitalInfo.medinsChnName = $("#hospname").val();
		hospitalInfo.chnAddress = $("#Hospitaladdr").val();
		hospitalInfo.netType = "01";
		hospitalInfo.medinsNatrue = $("#hospitalType").val();
		hospitalInfo.accountName = $("#hospitalBankAccountName").val();
		hospitalInfo.accountNo = $("#hospitalBankAccountNo").val();
		hospitalInfo.bankName = $("#hospitalBankName").val();
		hospitalInfo.faxNumber = $("#faxNo").val();
		hospitalInfo.contact = $("#contactPerson").val();
		hospitalInfo.contactPhone = $("#contactPhone").val();
		hospitalInfo.email =$("#email").val();
		preTaskPre.applyHospitalName = applyHospitalName;
		preTaskPre.applyHospitalNamePartnerId = $("#applyHospitalNamePartnerId").val();
		
	}
	
	//申请人-委托机构
	if(applyAgencyName!=""){
		agentInfo.medinsChnName = $("#tpaname").val();
		agentInfo.chnAddress = $("#tpaAddr").val();
		agentInfo.netType = "02";
		agentInfo.accountName = $("#tpaBankAccountName").val();
		agentInfo.accountNo = $("#tpaBankAccountNo").val();
		agentInfo.bankName = $("#tpaBankName").val();
		agentInfo.faxNumber = $("#tpaFaxNo").val();
		agentInfo.contact = $("#tpaContactPerson").val();
		agentInfo.contactPhone = $("#tpaContactPhone").val();
		preTaskPre.applyAgencyName = applyAgencyName;
		preTaskPre.applyAgencyNamePartnerId = $("#applyAgencyNamePartnerId").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;
	}
	
	preMedical.visitReason = visitReason;
	preMedical.accidentDate = $("#accidentDate").val();
	preMedical.visitDate =hvisitDate ;
	preMedical.visitDateFirst = visitDateFirst;
	preMedical.report = $("#report").val();
	if($("#ylxxIllsBy_").val() == ""){
		alert("医疗信息医疗诊断必录");
		return;
	}
	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(isNaN(hospitalDay)){
		alert("住院天数应为数字");
		return false;
	}
	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_;
	
	
	/*if($("#productList").find("tr").length<1){
		alert("请输入费用信息！");
		return false;
	}*/
	

	$("#productList").find("tr").each(function(){
		
        if (isOk) {
    		if ("请选择" == $(this).find(".sel_text").html()) {
    			isOk = false;
    		}
        }
        if(isok){
        	if ($("#productList").find(".sel_text").html()!="请选择"&&null == $(this).find("input").val() || "" == $(this).find("input").val()) {
    			isok = false;
    		}
        }
        if(checkmoney){
        	var regu = "^[^0-9]+$"; 
        	var re = new RegExp(regu); 
        	if ($(this).find("input").val()!=null ||$(this).find("input").val()!="") {
        		
        		if (re.test($(this).find("input").val())) {
        			checkmoney = false;
        		}
        		
    		}
        }
		
		var preProjectInfo={};
		
		preProjectInfo.projectNo = $(this).find(".sel_text").attr("code");
		preProjectInfo.projectName = $(this).find(".sel_text").html();
		preProjectInfo.amtPre = $(this).find("input").val();
		preProject.push(preProjectInfo);
	});
	

    if (isOk == false) {
    	alert("请输入费用项目名称！");
		return;
    }
    if (isok == false) {
    	alert("请输入费用项目对应预授权申请金额！");
		return;
    }
    
    if(!checkmoney){
    	alert("请输入正确格式的预授权申请金额！");
		return;
    }
	
	preTaskPre.amtPre = $("#totalAmt").val();
	if(flag =='save'){
		preTaskPre.preState = "01";
		preTaskPre.preSubState = "02";
	}else{
		preTaskPre.preState = "02";
		preTaskPre.preSubState = "01";
	}
	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;

	 if(flag =='save'){
			$("#save").removeAttr("onclick");
		}else{
			$("#complete").removeAttr("onclick");
		}
	$.ajax({
		 type: "POST",  
	     url: "saveAllInfo.do",
	     data:JSON.stringify(PreauthorizationAcceptVo),
		 contentType:"application/json; charset=UTF-8",
	     success:function(data){
	    	 $("#preNo").val(data);
	    	 var params={};
	    	 if(flag=='save'){
	    		 alert("预授权受理信息，保存成功，生成预授权号："+data+"！");
	    		 
	    	 }else if(flag=='complete'){
	    		 alert("预授权受理完成，生成预授权号："+data+"！");
	    		 SkipByPost("taskpoolQuery.do",params);
	    	 }
	    	 if(flag =='save'){
		 			$("#save").attr("onclick","saveAllInfo('save')");
		 		}else{
		 			$("#complete").attr("onclick","saveAllInfo('complete')");
		 		}
	     },
	     error:function(data){
	    	alert(data) ;
	    	 if(flag =='save'){
	 			$("#save").attr("onclick","saveAllInfo('save')");
	 		}else{
	 			$("#complete").attr("onclick","saveAllInfo('complete')");
	 		}
	    	
	     }
	});
	
}

function calculateAmount(flag){
	$("#altText").css("display","none");
	if(($("#totalAmt").val()==null || $("#totalAmt").val()=="" ||$("#totalAmt").val()=="0")|| flag=="1"){
		var totalAmt=0;
		$("#productList").find("input").each(function(){
			var amt = $(this).val();
			if(amt ==''){
				amt =0;
			}
			totalAmt = totalAmt *1 +$(this).val()*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_query").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=\"9\">查询不到相关内容，请检查查询条件</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 code='"+isNull(h.id)+"' style=\"cursor:pointer\"  onclick=\"showSelectLineInfo(this,'"+isNull(h.medinsChnName)+"','"+isNull(h.id)+"')\" >" +
								"<td><input type='hidden' id ='fax' name='fax' 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.accountName)+"</td><td>"+isNull(h.bankName)+"</td><td>"+isNull(h.accountNo)+"</td><td>"+isNull(h.email)+"</td></tr>");
					
					}else{/**TPA*/
						$("#partnerTpa").append("<tr code='"+isNull(h.id)+"' style=\"cursor:pointer\"  onclick=\"showSelectLineInfo(this,'"+isNull(h.medinsChnName)+"','"+isNull(h.id)+"')\">" +
								"<td><input type='hidden' id ='fax' name='fax' value='"+isNull(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;
	}
}
//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(yljgFlag!='1'){
					$("#"+flag1).val(hosptailname);
					divformPerson.style.display='none';
					TPAInfo.style.display='none';
					hospitalInfo.style.display='block';
					$("#applyHospitalNamePartnerId").val($("#"+flag2).find("tr").eq(indexLine).attr("code"));
					 $("#HospitalName").val(hosptailname);
		             $("#Hospitaladdr").val($(td).eq("1").text());
		             $("#hospitalType").val($(td).eq("2").text());
		             $("#hospitalContactPerson").val($(td).eq("3").text());
		             $("#hospitalContactPhone").val($(td).eq("4").text());
		             $("#hospitalFaxNo").val($("#fax").val());
		             $("#hospitalBankAccountName").val($(td).eq("5").text());
		             $("#hospitalBankName").val($(td).eq("6").text());
		             $("#hospitalBankAccountNo").val($(td).eq("7").text());
		             
		            /* $("#hospType").val($(td).eq("2").text());
		    		 $("#hospContactPerson").val($(td).eq("3").text());
		    		 $("#hospPhone").val($(td).eq("4").text());
		    		 $("#hospFaxNo").val($(td).eq("4").text());
		    		 $("#bankAccountName").val($(td).eq("5").text());
		    		 $("#bankName").val($(td).eq("6").text());
		    		 $("#bankAccountNo").val($(td).eq("7").text());
					*/
					$("#partnerId").val($("#"+flag2).find("tr").eq(indexLine).attr("code"));
					$("#partnerName").val(hosptailname);
					$("#contactPerson").val($(td).eq("3").text());
					$("#faxNo").val($("#fax").val());
					$("#contactPhone").val($(td).eq("4").text());
					$("#email").val($(td).eq("8").text());
					
					$("#hospitalInfo").find("#appEmail").val($(td).eq("8").text());
					
			 		$("#applyAgencyName").attr("disabled",true);
			 		document.getElementById("Tpa").style.display = "none";
			 		document.getElementById("yljg").style.display = "none";
				}else if(yljgFlag =='1'){
					$("#partnerId").val($("#"+flag2).find("tr").eq(indexLine).attr("code"));
					$("#partnerName").val(hosptailname);
					$("#contactPerson").val($(td).eq("3").text());
					$("#faxNo").val($("#fax").val());
					$("#contactPhone").val($(td).eq("4").text());
					$("#email").val($(td).eq("8").text());
					$("#hospitalInfo").find("#appEmail").val($(td).eq("8").text());
				}
				
			}else if(flag3 == 'tpa'){
				$("#"+flag1).val(hosptailname);
				divformPerson.style.display='none';
				TPAInfo.style.display='block';
				hospitalInfo.style.display='none';
				$("#applyAgencyNamePartnerId").val($("#"+flag2).find("tr").eq(indexLine).attr("code"));
				 $("#tpaName").val(hosptailname);
				 $("#tpaAddr").val($(td).eq("1").text());
				 $("#tpaContactPerson").val($(td).eq("2").text());
				 $("#tpaContactPhone").val($(td).eq("3").text());
				 $("#tpafFaxNo").val($("#fax").val());
				 $("#tpaBankAccountName").val($(td).eq("4").text());
				 $("#tpaBankName").val($(td).eq("5").text());
				 $("#tpaBankAccountNo").val($(td).eq("6").text());
				 
				 $("#tname").val(hosptailname);
				 $("#tAddr").val($(td).eq("1").text());
				 $("#tContactPerson").val($(td).eq("2").text());
				 $("#tPhone").val($(td).eq("3").text());
				 $("#tFaxNo").val($("#fax").val());
				 $("#tbankAccountName").val($(td).eq("4").text());
				 $("#tBankName").val($(td).eq("5").text());
				 $("#tBankAccountNo").val($(td).eq("6").text());
				 $("#TPAInfo").find("#appEmail").val($(td).eq("7").text());
				 
				 $("#applyHospitalName").attr("disabled",true);
			 	document.getElementById("Hospital").style.display = "none";
		}
		yljgFlag='0';
		closeDiv(flag0);
	}
}
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 align=\"center\"><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 align=\"center\"><td colspan=\"3\">查询不到相关内容，请检查查询条件</td></tr>");
			}else{
	            $.each(items, function(i, n){
	             	$("#ylxx").append("<tr>" +
	             			"<th width=\"28%\"><span id='"+items[i].objId+"2' 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 align=\"center\"><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,pid2,certificates){
	var params = {};
	params['channelType'] = channelType;
	params['certificates'] = certificates;
	if(pid!=""){
		params['pid'] = pid;
	}else{
		params['pid'] = pid2;
	}
	
	SkipByPost("policyreturn.do",params);
}
 function openyljg(value){
	 yljgFlag=value;
	 showDiv('divformHospital');
 }

 
//申请人被保险人关系
 function relationshipChange(key){
	 var applyAgencyName = $("#applyAgencyName").val();
	 var applyHospitalName = $("#applyHospitalName").val();
 	if(key=="401" || key=="406"){//本人
 		divformPerson.style.display='block';
		TPAInfo.style.display='none';
		hospitalInfo.style.display='none';
 		//申请人信息
 		$("#appInsRelationship").val($("#hiddenRelationship").val());
 		$("#appPid").val($("#hiddenPid").val());
 		$("#appName").val($("#hiddenName").val());
 		
 		if($("#hiddenSex").val()=='1'){
 			$("#appSex").text("男");
 		}else if($("#hiddenSex").val()=='2'){
 			$("#appSex").text("女");
 		}
 		
 		if($("#hiddenIidtype").val()=='a'){
 			$("#appIdtype").text("身份证");
 		}else if($("#hiddenIidtype").val()=='c'){
 			$("#appIdtype").text("护照");
 		}else if($("#hiddenIidtype").val()=='d'){
 			$("#appIdtype").text("军官证");
 		}else if($("#hiddenIidtype").val()=='j'){
 			$("#appIdtype").text("港澳台护照");
 		}else if($("#hiddenIidtype").val()=='l'){
 			$("#appIdtype").text("台湾居民通行证");
 		}
 		
 		$("#appPhone").val($("#hiddenPhone").val());
 		$("#appTel").val($("#hiddenTel").val());
 		$("#appContractAddr").val($("#hiddenContractAddr").val());
 		$("#appPostCode").val($("#hiddenPostCode").val());
 		$("#appEmail").val($("#hiddenEmail").val());
 		$("#appFax").val($("#hiddenFax").val());
 		$("#applyHospitalName").val("");
 		$("#applyAgencyName").val("");
 		$("#isGuarantee").text("是");
 		$("#applyHospitalName").attr("disabled",true);
 		$("#applyAgencyName").attr("disabled",true);
 		document.getElementById("Hospital").style.display = "none";
 		document.getElementById("Tpa").style.display = "none";
		
	}else if(key=='408'){
		divformPerson.style.display='none';
		TPAInfo.style.display='none';
		hospitalInfo.style.display='none';
		$("#isGuarantee").text("是");
		$("#applyHospitalName").val("");
		$("#applyAgencyName").val("");
		$("#applyHospitalName").attr("disabled",false);
 		$("#applyAgencyName").attr("disabled",false);
 		document.getElementById("Hospital").style.display ="";
 		document.getElementById("Tpa").style.display = "";
		
		
	}else{
		divformPerson.style.display='block';
		TPAInfo.style.display='none';
		hospitalInfo.style.display='none';
		$("#appInsRelationship").val("");
 		$("#appIdtype").text("身份证");
 		$("#appPid").val("");
 		$("#appName").val("");
 		$("#appSex").text("男");
 		$("#appPhone").val("");
 		$("#appTel").val("");
 		$("#appContractAddr").val("");
 		$("#appPostCode").val("");
 		$("#appEmail").val("");
 		$("#appFax").val("");
 		$("#applyHospitalName").val("");
 		$("#applyAgencyName").val("");
 		$("#isGuarantee").text("是");
 		$("#applyHospitalName").attr("disabled",true);
 		$("#applyAgencyName").attr("disabled",true);
 		document.getElementById("Hospital").style.display = "none";
 		document.getElementById("Tpa").style.display = "none";
	}
}
 
 
 
//邮箱校验
 function emailCheck(str){
   var reg=/^([a-zA-Z0-9]+[_|-|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|-|.]?)*[a-zA-Z0-9]+.[a-zA-Z]{2,3}$/gi;
   return reg.test(str);  
    
 }
 
 //将就诊日起同步到医疗授权信息中
 function loadTime(){
	 var hvisitDate = $("#hvisitDate").val();
	 $("#visitDate").val(hvisitDate);
	 
 }
 

	
 
 
 function cxlxCheckBox(obj){
	 var dataCode=$(obj).attr("code");
	 $("#visitReason").find("span").removeClass().addClass("check_no");
	 $("#visitReason").find("span [code="+dataCode+"]").removeClass().addClass("check_yes");
	
 }
 
 function checkfbzk(obj){
	 var dataCode=$(obj).attr("code");
	 $("#prevalenceStatus").find("span").removeClass().addClass("check_no");
	 $("#prevalenceStatus").find("span [code="+dataCode+"]").removeClass().addClass("check_yes");
 }
 
 function checkzlxs(obj){
	 var dataCode=$(obj).attr("code");
	 $("#itemMode").find("span").removeClass().addClass("check_no");
	 $("#itemMode").find("span [code="+dataCode+"]").removeClass().addClass("check_yes");
 }
 //全选
function selectdedAll(obj){
	if ($("#checkAll").is(".check_no")) {
		$("#checkAll").removeClass().addClass("check_no");
		$("#preClassLiabList").find("tr td span").removeClass().addClass("check_yes");
	} else {
		$("#checkAll").removeClass().addClass("check_yes");
		$("#preClassLiabList").find("tr td span").removeClass().addClass("check_no");
	}
}
//支付方式
function selectedli(flag,flag2){
	if(flag2=='1'){
		$("#payType").val(flag);
	}else{
		$("#tpayType").val(flag);
	}
}

function changecolor(isGuarantee){
	if(isGuarantee=='Y'){
		$("#span1").html("*");
		$("#span2").html("*");
	 }else{
		$("#span1").html("");
		$("#span2").html("");
	}
}

function changeTotal(flag){
	var totalAmt1=$(flag).val();
	var totalAmt2=0;
	if(!validateNumber(flag)){
		calculateAmount('1');
		return ;
	}
	if(totalAmt1==null || totalAmt1=="" ||totalAmt1<=0){
		calculateAmount('1');
		return;
	}else{
		calculateAmount('1');
		totalAmt2=$("#totalAmt").val();
		}
		if(totalAmt1!=totalAmt2){
			$("#altText").css("display","");
		}else{
			$("#altText").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 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 checkFsMail(flag,flag2){
	if($(flag2).attr("class").indexOf("check_no")!=-1){
		var mail=null;
		if(flag=='1'){//个人
			mail=$("#divformPerson").find("#appEmail").val();
		}else if(flag=='2'){
			mail=$("#hospitalInfo").find("#appEmail").val();
		}else if(flag=='3'){
			mail=$("#TPAInfo").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;
			}
		}
		$("#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 openImage(sModino){//sModino预授权号
	var branchid = null;
	var inputSource = $("#inputSource").val();
	var channelType = $("#channelType").val();
	if(inputSource=='05'){
		branchid = $("#branchid").val();
	}else{
		branchid='80000000000009';
	}
	
	
	var casesource = null;
	if(channelType=='0'){//健康险
		casesource = '3';
	}else if(channelType=='1'){//寿险
		casesource = '2';
	}else if(channelType=='2'){//产险
		casesource = '1';
	}
	   //获取当前网址
    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+'',"预授权影像");
	
	
}