var blg = true;

$(document).ready(

		function() {

			$("#dpa").unbind();
			var iscommon = $("#isBpo").val();
			var inputsource = $("#inputsource").val();

			if ("1" == $("#caseSource").val()
					&& (iscommon == "Y" || inputsource == "05")) { // 产险影像
				callEcm($("#claimNo").val(), "");
			} else { // 寿险或产险高端的影像
				window.open('../inspection/clmtask/imageInfo.do?claimNo='
						+ $("#claimNo").val(), "影像");
			}
			// 当页面载入完成时获取所有省级地区
			$.ajax({

				type : "POST",
				url : "getProvince.do",
				data : "",
				error : function() {
					alert("获取省份失败");
					return;
				},
				success : function(data) {
					for (var i = 0; i < data.length; i++) {
						var province = data[i];
						$("#provinceContext").append(
								"<li id=" + province.areaCode
										+ " onclick=\"getProvinceCode(this)\">"
										+ province.areaName + "</li>");
						$("#provinceContextcenter").append(
								"<li id=" + province.areaCode
										+ " onclick=\"getProvinceCode(this)\">"
										+ province.areaName + "</li>");
					}
					$(".select").find(".sel_list li").hover(function() {
						$(this).addClass("sel_hov");
					}, function() {
						$(this).removeClass("sel_hov");
					}).on(
							'click',
							function() {
								var _this = $(this).html();

								var _thisText = $(this).closest(".select")
										.find(".sel_text");
								_thisText.html(_this);

							});
				}

			});
		});

function selectPayType(flag) {
	$(flag).attr("value") == '1' ? $(flag).val("0") : $(flag).val("1");
}
/**非自动件check事件**/
function selectClaimType(obj){
	$(obj).attr('value') == "4" ? $(obj).attr('value',"5") : $(obj).attr('value',"4");
}

function selectIsMail(flag) {
	$(flag).val() == 'Y' ? $(flag).val('N') : $(flag).val('Y');
}

// 根据所选省份获取市
function findCity(provinceCode) {
	$("#citySpan").html("请选择市");
	$("#cityContext").html("");
	$("#citySpancenter").html("请选择市");
	$("#cityContextcenter").html("");
	$.ajax({

		type : "POST",
		url : "findCity.do",
		data : {
			"provinceCode" : provinceCode
		},
		error : function() {
			alert("获取市级单位失败");
			return;
		},
		success : function(data) {
			for (var i = 0; i < data.length; i++) {
				var city = data[i];
				$("#cityContext").append(
						"<li id=\"" + city.areaCode
								+ "\" onclick=\"getCityCode(this)\">"
								+ city.areaName + "</li>");
				$("#cityContextcenter").append(
						"<li id=\"" + city.areaCode
								+ "\" onclick=\"getCityCode(this)\">"
								+ city.areaName + "</li>");
			}
			// 选中
			$(".select").find(".sel_list li").hover(function() {
				$(this).addClass("sel_hov");
			}, function() {
				$(this).removeClass("sel_hov");
			}).on('click', function() {
				var _this = $(this).html();

				var _thisText = $(this).closest(".select").find(".sel_text");
				_thisText.html(_this);

			});
		}

	});
}
// 获取所选省份
var provinceName = null;
var provinceCode = null;
function getProvinceCode(obj) {

	provinceCode = obj.id;
	$("#hosCityCode").val("");
	$("#hosProvince").val(provinceCode);
	$("#hosCityCodecenter").val("");
	$("#hosProvincecenter").val(provinceCode);
	provinceName = obj.innerHTML;
	findCity(provinceCode);
}

// 获取所选市的代码
var cityCode = null;
function getCityCode(obj) {
	cityCode = obj.id;
	$("#hosCityCode").val(cityCode);
	$("#hosCityCodecenter").val(cityCode);
}

function queryMyTask() {
	SkipByPost("queryMyTask.do", {});
}
/**
 * 跳转保单详情页面
 * 
 * @param policyNo
 * @param claimNo
 * @param pid
 * @param classcode
 */
function policyInfoquery(policyNo, claimNo, pid, classcode, policyInterSource,
		sGrpattr, branchid, familyFlag) {
	SkipByPost("policyInfo.do", {
		policyNo : policyNo,
		claimNo : claimNo,
		pid : pid,
		classcode : classcode,
		policyInterSource : policyInterSource,
		sGrpattr : sGrpattr,
		branchid : branchid,
		familyFlag : familyFlag
	});
}
function dispatcherEventPage(eventNo) {
	if (eventNo != "") {
		$("#eventNo").val(eventNo);
	}
	$("#dispatchEventPage").attr("action", "dispatcherEventPage.do");
	$("#dispatchEventPage").submit();

}

function operAllInfo() {
	/**claimType**/
	var claimType = $("#auto").attr("value");
	if(claimType==null|| claimType=="" ||claimType==undefined ||claimType=="undefined"){
		claimType="";
	}	
	var isQuest = $("#quest").attr("value");

	// 高端
	var isBpo = "";
	// 高端
	if ($("#isbpo").hasClass("check_yes")) {
		isBpo = "N";
	} else {
		isBpo = "Y";
	}

	// 被保人信息
	var lifeReportNo = $("#clamlIfeReportNo").val();
	var taskCaseSource = $("#taskCaseSource").val();
	if ((lifeReportNo == null || lifeReportNo == "") && taskCaseSource != '3') {
		if ($.trim($("#customerInfoName").val()) == ""
				|| $.trim($("#customerInfoName").val()) == null) {
			alert("请填写被保人姓名。");
			return;
		}
		if ($.trim($("#customerInfoSex").attr("code")) == ""
				|| $.trim($("#customerInfoSex").attr("code")) == null) {
			alert("请填写被保人性别。");
			return;
		}
		if ($.trim($("#customerInfoIdtype").attr("code")) == ""
				|| $.trim($("#customerInfoIdtype").attr("code")) == null) {
			alert("请填写被保人证件类型。");
			return;
		}
		if ($.trim($("#customerInfoPid").val()) == ""
				|| $.trim($("#customerInfoPid").val()) == null) {
			alert("请填写被保人证件号。");
			return;
		}
		if ($("#claimDate").val().length == 0) {
			alert("请填写索赔日期。");
			return;
		}
	}

	// 报案人信息
	var claimNo = $.trim($("#claimNo").val());
	var reportDate = $.trim($("#reportDate").val());
	var repInsRelationship = $("#divrepInsRelationship_code").val();
	if (repInsRelationship != undefined && repInsRelationship != "")
		$("#repInsRelationship").val(repInsRelationship);
	var idtype = $.trim($("#dividtype_code").val());
	if (idtype != undefined && idtype != "")
		$("#idtype").val(idtype);
	var pid = $.trim($("#pid").val());
	var pname = $.trim($("#pname").val());
	var sex = $.trim($("#divsex_code").val());
	if (sex != undefined && sex != "")
		$("#sex").val(sex);
	var phone = $.trim($("#phone").val());
	var tel = $("#tel").val();
	var contractAddr = $.trim($("#contractAddr").val());
	var postCode = $.trim($("#postCode").val());
	var email = $.trim($("#email").val());
	// 申请人信息
	var sqrappInsRelationship = $("#divSqrappInsRelationship_code").val();
	if (sqrappInsRelationship != undefined && sqrappInsRelationship != "") {
		$("#sqrappInsRelationship").val(sqrappInsRelationship);
	}
	var sqridtype = $.trim($("#divSqridtype_code").val());
	if (sqridtype != undefined && sqridtype != "")
		$("#sqridtype").val(sqridtype);
	var sqr_pid = $.trim($("#sqr_pid").val());
	var sqr_pname = $.trim($("#sqr_pname").val());
	var sqrsex = $.trim($("#divSqrsex_code").val());
	if (sqrsex != undefined && sqrsex != "")
		$("#sqrsex").val(sqrsex);
	var sqr_phone = $.trim($("#sqr_phone").val());
	var sqr_tel = $.trim($("#sqr_tel").val());
	var sqr_contractAddr = $.trim($("#sqr_contractAddr").val());
	var sqr_email = $.trim($("#sqr_email").val());
	var sqr_postCode = $.trim($("#sqr_postCode").val());
	// 出险信息
	var accidentDate = $("#accidentDate").val();
	var firstDiagnoseDate = $("#firstDiagnoseDate").val();
	var claimDate = $("#claimDate").val();
	var accidentaddrtype = $("#divaccidentaddrtype_code").val();
	if (accidentaddrtype != undefined && accidentaddrtype != "")
		$("#accidentaddrtype").val(accidentaddrtype);
	var accidentDesc = reg($("#accidentDesc").val());
	var isAppInsruedSame = "";
	if ($("#check_sqrBbr").hasClass("check_yes")) {
		isAppInsruedSame = "Y";
	} else if ($("#check_sqrBbr").hasClass("check_no")) {
		isAppInsruedSame = "N";
	}
	var isAppRepSame = "";
	if ($("#check_sqrBar").hasClass("check_yes")) {
		isAppRepSame = "Y";
	} else if ($("#check_sqrBar").hasClass("check_no")) {
		isAppRepSame = "N";
	}
	var is_mail = "";
	if ($("#is_mail").hasClass("check_yes")) {
		is_mail = "Y";
	} else if ($("#is_mail").hasClass("check_no")) {
		is_mail = "N";
	}

	// 报案不成功修改出险人信息
	var customerInfoName = $.trim($("#customerInfoName").val());
	var customerInfoSex = $.trim($("#customerInfoSex").attr("code"));
	var customerInfoIdtype = $.trim($("#customerInfoIdtype").attr("code"));
	var customerInfoPid = $.trim($("#customerInfoPid").val());
	var customerno = $.trim($("#customerno").val());
	// 修改被保险人信息
	var customerInfoPhone = $.trim($("#customerInfoPhone").val());
	var customerInfoFtele = $.trim($("#customerInfoFtele").val());
	var customerInfoFaddr = $.trim($("#customerInfoFaddr").val());
	var customerInfoFzip = $.trim($("#customerInfoFzip").val());
	var customerInfoEmail = $.trim($("#customerInfoEmail").val());

	if (lifeReportNo != null && lifeReportNo != "") {
		customerInfoName = $.trim($("#customerInfoName").html());
		customerInfoPid = $.trim($("#customerInfoPid").html());
	}

	var jsonStr = '{"claimNo":"' + claimNo + '","reportDate":"' + reportDate
			+ '","isBpo":"' + isBpo + '","isQuest":"' + isQuest
			+ '","repInsRelationship":"' + $("#repInsRelationship").val()
			+ '","idtype":"' + $("#idtype").val() + '","pid":"' + pid
			+ '","pname":"' + pname + '","sex":"' + $("#sex").val()
			+ '","phone":"' + phone + '","tel":"' + tel + '","contractAddr":"'
			+ contractAddr + '","postCode":"' + postCode + '","email":"'
			+ email + '","sqrappInsRelationship":"'
			+ $("#sqrappInsRelationship").val() + '","sqridtype":"'
			+ $("#sqridtype").val() + '","sqr_pid":"' + sqr_pid
			+ '","sqr_pname":"' + sqr_pname + '","sqrsex":"'
			+ $("#sqrsex").val() + '","sqr_phone":"' + sqr_phone
			+ '","sqr_tel":"' + sqr_tel + '","sqr_contractAddr":"'
			+ sqr_contractAddr + '","claimIllsBy_":"'
			+ $("#claimIllsBy_").val() + '","sqr_email":"' + sqr_email
			+ '","sqr_postCode":"' + sqr_postCode + '","sqrApplicantId":"'
			+ $("#sqrPersonId").val() + '","accTypesBy_":"'
			+ $("#accTypesBy_").val() + '","accidentDate":"' + accidentDate
			+ '","firstDiagnoseDate":"' + firstDiagnoseDate + '","claimDate":"'
			+ claimDate + '","accidentAddrType":"'
			+ $("#accidentaddrtype").val() + '","accidentDesc":"'
			+ accidentDesc + '","isAppInsruedSame":"' + isAppInsruedSame
			+ '","isAppRepSame":"' + isAppRepSame + '","is_mail":"' + is_mail
			+ '","accidentCode":"' + $("#accidentCode").val()
			+ '","customerInfoName":"' + customerInfoName
			+ '","customerInfoSex":"' + customerInfoSex
			+ '","customerInfoIdtype":"' + customerInfoIdtype
			+ '","customerInfoPid":"' + customerInfoPid + '","customerno":"'
			+ customerno + '","customerInfoPhone":"' + customerInfoPhone
			+ '","customerInfoFtele":"' + customerInfoFtele
			+ '","customerInfoFaddr":"' + customerInfoFaddr
			+ '","customerInfoFzip":"' + customerInfoFzip
			+ '","customerInfoEmail":"' + customerInfoEmail + '","claimType":"'+claimType+'"}';
	return jsonStr;
}
function reg(s) {
	var re = new RegExp("\"", "g");
	var s2 = s.replace(re, "\\\"");
	re = new RegExp("[\r\n]", "g");
	s3 = s2.replace(re, "");
	var re1 = new RegExp("(^\\s*)|(\\s*$)", "g");
	s4 = s3.replace(re1, "");
	return s4;
}

function saveAllInfo() {
	var jsonStr = operAllInfo();
	var isBpo = "Y";
	// 高端
	if ($("#isbpo").hasClass("check_yes")) {
		isBpo = "N";
	} else {
		isBpo = "Y";
	}
	if ($("#accidentDate").val().length == 0) {
		alert("请填写出险日期。");
		return;
	}
	if (blg) {
		/*
		 * if ($("#firstDiagnoseDate").val().length == 0) { alert("请填写初次就诊日期。");
		 * return; }
		 */
		if ($("#claimIllsBy_").val().length == 0) {
			alert("请选择疾病诊断信息。");
			return;
		}
	}

	if ($("#accidentaddrtype").val().length == 0) {
		alert("请选择出险地区。");
		return;
	}

	if ($("#claimDate").val().length == 0) {
		alert("请填写索赔日期。");
		return;
	}

	var accidentDateTxt = $("#accidentDate").val();
	var firstDiagnoseDateTxt = $("#firstDiagnoseDate").val();
	var fdd = parseInt(firstDiagnoseDateTxt.replace("-", "").replace("-", ""));
	var adt = parseInt(accidentDateTxt.replace("-", "").replace("-", ""));
	var reportDateTxt = $("#reportDate").val();
	var claimDateTxt = $("#claimDate").val();
	var rdt = parseInt(reportDateTxt.replace("-", "").replace("-", ""));
	var cdt = parseInt(claimDateTxt.replace("-", "").replace("-", ""));
	if (cdt < rdt) {
		alert("索赔日期不能早于报案日期。");
		return;
	}
	if (fdd < adt) {
		alert("初次就诊日期不能早于出险日期。");
		return;
	}

	if ($("#accidentCode").val().length == 0) {
		alert("请选择出险类型。");
		return;
	}
	if ($("#accTypesBy_").val().length == 0) {
		alert("请选择索赔事故性质。");
		return;
	}
	if ($.trim($("#accidentDesc").val()).length == 0) {
		alert("请填写出险经过。");
		return;
	}
	if ($("#accidentDesc").val().length > 200) {
		alert("出险经过超出200个字数范围。");
		return;
	}
	$("#saveInfo").removeAttr("onclick");

	$.ajax({
		type : "POST",
		contentType : "application/json; charset=UTF-8",
		url : "saveAllInfo.do",
		data : jsonStr,
		error : function() {
		},
		success : function(data) {
			if (data == "00") {
				alert("数据录入信息保存成功。");
				$("#saveInfo").attr("onclick", "saveAllInfo()");
			} else {
				alert("数据录入信息保存失败。");
				$("#saveInfo").attr("onclick", "saveAllInfo()");
			}
		}
	});
}

function doneAllInfo() {
	var jsonStr = operAllInfo();
	var isBpo = "Y";
	// 高端
	if ($("#isbpo").hasClass("check_yes")) {
		isBpo = "N";
	} else {
		isBpo = "Y";
	}
	if ($("#reportDate").val().length == 0) {
		alert("请填写报案人报案日期。");
		return;
	}

	if ($("#repRelationshipSpan").html() == "请选择关系") {
		alert("请选择报案人与被保人关系。");
		return;
	}
	if ($("#cardType").html() == "请选择类型") {
		alert("请选择报案人证件类型。");
		return;
	}
	if ($("#spansex").html() == "请选择性别") {
		alert("请选择报案人性别。");
		return;
	}

	if ($("#idtype").val().length == 0) {
		alert("请选择报案人人证件类型。");
		return;
	}
	if ($.trim($("#pid").val()).length == 0) {
		alert("请填写报案人证件号码。");
		return;
	}
	if ($("#idtype").val() == "a") {
		if (!checkIdentityCardTrueOrFalse($("#pid").val())) {
			alert("报案人身份证号码格式有误，请重新录入。");
			return;
		}
	}
	if ($.trim($("#pname").val()).length == 0) {
		alert("请填写报案人姓名。");
		return;
	}
	if ($("#sex").val().length == 0) {
		alert("请选择报案人性别。");
		return;
	}
	if ($.trim($("#phone").val()).length == 0
			&& $.trim($("#tel").val()).length == 0) {
		alert("请填写报案人移动电话或固话。");
		return;
	}
	var reg = /^1[0-9]{10}$/;
	if ($.trim($("#phone").val()).length != 0
			&& $.trim($("#phone").val()).length != 11) {
		alert("报案人手机号码长度必须为11位。");
		return;
	}
	if ($.trim($("#phone").val()).length != 0) {
		if (!reg.test($.trim($("#phone").val()))) {
			alert("报案人手机号码 填写格式不正确，请重新填写。");
			return;
		}
	}
	if ($("#postCode").val().length != 0) {
		if ($("#postCode").val().length != 6) {
			alert("报案人邮编需为6位数字。");
			return;
		} else {
			var regpc = /^[0-9]*$/;
			if (!regpc.test($("#postCode").val())) {
				alert("报案人邮编录入格式不正确，请重新录入。");
				return;
			}
		}
	}
	if ($("#email").val().length != 0) {
		if (!emailCheck($("#email").val())) {
			alert("报案人邮箱格式不正确，请重新录入。");
			return;
		}
	}
	if ($("#spanSqrappInsRelationship").html() == "请选择关系") {
		alert("请选择申请人与被保人关系。");
		return;
	}
	if ($("#spanSqrIdType").html() == "请选择类型") {
		alert("请选择申请人证件类型。");
		return;
	}
	if ($("#spansqrsex").html() == "请选择性别") {
		alert("请选择申请人性别。");
		return;
	}
	if ($("#sqrappInsRelationship").val().length == 0) {
		alert("请选择申请人与被保人关系。");
		return;
	}
	if ($("#sqridtype").val().length == 0) {
		alert("请选择申请人证件类型。");
		return;
	}
	if ($("#sqrsex").val().length == 0) {
		alert("请选择申请人性别。");
		return;
	}
	if ($.trim($("#sqr_pid").val()).length == 0) {
		alert("请填写申请人证件号码。");
		return;
	}
	if ($("#sqridtype").val() == "a") {
		if (!checkIdentityCardTrueOrFalse($("#sqr_pid").val())) {
			alert("申请人身份证号码格式有误，请重新录入。");
			return;
		}
	}

	if ($.trim($("#sqr_pname").val()).length == 0) {
		alert("请填写申请人姓名。");
		return;
	}
	if ($.trim($("#sqr_phone").val()).length == 0
			&& $.trim($("#sqr_tel").val()).length == 0) {
		alert("请填写申请人移动电话或固话。");
		return;
	}
	if ($.trim($("#sqr_phone").val()).length != 0
			&& $.trim($("#sqr_phone").val()).length != 11) {
		alert("申请人手机号码长度必须为11位。");
		return;
	}
	if ($.trim($("#sqr_phone").val()).length != 0) {
		if (!reg.test($("#sqr_phone").val())) {
			alert("申请人手机号码 填写格式不正确，请重新填写。");
			return;
		}
	}
	if ($("#sqr_email").val().length != 0) {
		if (!emailCheck($("#sqr_email").val())) {
			alert("申请人邮箱格式不正确，请重新录入。");
			return;
		}
	}
	if ($("#payTbbody").find("tr").length == 0) {
		alert("请录入至少一位领款人信息。");
		return;
	}
	if ($("#accidentDate").val().length == 0) {
		alert("请填写出险日期。");
		return;
	}
	/*
	 * if ($("#firstDiagnoseDate").val().length == 0) { alert("请填写初次就诊日期。");
	 * return; }
	 */
	if ($("#claimDate").val().length == 0) {
		alert("请填写索赔日期。");
		return;
	}

	var accidentDateTxt = $("#accidentDate").val();
	var firstDiagnoseDateTxt = $("#firstDiagnoseDate").val();
	var fdd = parseInt(firstDiagnoseDateTxt.replace("-", "").replace("-", ""));
	var adt = parseInt(accidentDateTxt.replace("-", "").replace("-", ""));
	var reportDateTxt = $("#reportDate").val();
	var claimDateTxt = $("#claimDate").val();
	var rdt = parseInt(reportDateTxt.replace("-", "").replace("-", ""));
	var cdt = parseInt(claimDateTxt.replace("-", "").replace("-", ""));
	if (cdt < rdt) {
		alert("索赔日期不能早于报案日期。");
		return;
	}
	if (fdd < adt) {
		alert("初次就诊日期不能早于出险日期。");
		return;
	}
	if ($("#accidentaddrtype").val().length == 0) {
		alert("请选择出险地区。");
		return;
	}
	if ($("#claimIllsBy_").val().length == 0) {
		alert("请选择疾病诊断信息。");
		return;
	}
	if ($("#accidentCode").val().length == 0) {
		alert("请选择出险类型。");
		return;
	}
	if ($("#accTypesBy_").val().length == 0) {
		alert("请选择索赔事故性质。");
		return;
	}
	if ($.trim($("#accidentDesc").val()).length == 0) {
		alert("请填写出险经过。");
		return;
	}
	if ($("#accidentDesc").val().length > 200) {
		alert("出险经过超出200个字数范围。");
		return;
	}
	// data:{"cliamNo":$("#claimNo").val()},
	// bool
	var checkedInsurePolicyFlag = $("#checkedInsurePolicyFlag").val();
	var insName = "";
	var insIdtype = "";
	var insPid = "";
	if ($.trim($("#customerInfoName").val()) == "") {
		insName = $("#customerInfoName").html();
	} else {
		insName = $.trim($("#customerInfoName").val());
	}

	if ($.trim($("#customerInfoIdtype").attr("code")) == "") {
		insIdtype = $("#customerInfoIdtype").attr("code");
	} else {
		insIdtype = $.trim($("#customerInfoIdtype").attr("code"));
	}

	if ($.trim($("#customerInfoPid").val()) == "") {
		insPid = $("#customerInfoPid").html();
	} else {
		insPid = $.trim($("#customerInfoPid").val());
	}
	$.ajax({
		type : "POST",
		url : "checkedRcptBilldetails.do",
		data : {
			"claimNo" : $("#claimNo").val(),
			"isQuest" : $("#quest").attr("value"),
			"insName" : insName,
			"insIdtype" : insIdtype,
			"insPid" : insPid
		},
		error : function() {
			alert("数据录入信息保存失败。");
		},
		success : function(data) {
			if (data == "errorName") {
				alert("被保人姓名不匹配,请修改!");
				return;

			} else if (data == "errorId") {
				alert("被保人证件信息不匹配,请修改!");
				return;
			} else if (data == "error") {
				alert("系统异常,请联系开发人员进行协助解决");
				return;
			} else if (data == "errorRcpt") {
				alert("请录入大于0的重症监护天数！");
				return;
			}else if(data == "errorBankCode"){
				alert("领款人银行代码为空，请修改！");
				applyDataEnterAjaxFn(jsonStr);
			}else if(data == "errorBankAccountNo"){
				alert("领款人银行账号为空，请修改！");
				applyDataEnterAjaxFn(jsonStr);
			}else if(data == "errorBankName"){
				alert("领款人银行名称为空，请修改！");
				applyDataEnterAjaxFn(jsonStr);
			}else if(data == "Y"){
				applyDataEnterAjaxFn(jsonStr);
			}
		}
	});

}

function applyDataEnterAjaxFn(jsonStr) {
	$("#doneInfo").removeAttr("onclick");
	$.ajax({
		type : "POST",
		contentType : "application/json; charset=UTF-8",
		url : "doneDataEnterInfo.do",
		data : jsonStr,
		error : function() {
		},
		success : function(data) {
			if (data.flag == "010") {
				alert("没有查到保单！");
				$("#doneInfo").attr("onclick", "doneAllInfo()");
				return;
			}
			if (data.flag == "00") {
				alert("数据录入完成，待质检！");
				$("#doneInfo").attr("onclick", "doneAllInfo()");
			} else if (data.flag == "02") {
				alert("数据录入完成！");
				// location.href='../claim/filedCase/requestPools.do';
				location.href = '../dataenter/showlist.do';
				document.onmousedown = click;
			} else if (data.flag == "03") {
				alert("此数据录入信息已提交，请做后续处理。");
				$("#doneInfo").attr("onclick", "doneAllInfo()");
			} else {
				if (data.errorMsg != null) {
					alert(data.errorMsg);
				} else {
					alert("数据录入信息保存失败。");
				}
				$("#doneInfo").attr("onclick", "doneAllInfo()");
			}
		}
	});
}

/**
 * 索赔事故性质
 */

function displayImageMsg() {
	var tmpEroMsg = $("#errorMsg").val();
	if (null != tmpEroMsg && "" != tmpEroMsg) {
		// alert(tmpEroMsg);
		$("#imageSys").removeClass("displayN");
	}
}

function unDisplayImageMsg(imageSys) {
	$("#" + imageSys).addClass("displayN");
}

function initclaimacc(skipFlag) {
	// 影像系统返回的错误信息
	displayImageMsg();

	if (skipFlag != undefined && skipFlag != "") {
		$("#SHcon10").css("display", "block");

	}
	// accTypesBy_
	var accTypesStr = $("#accTypesBy_").val();
	var accTypes = accTypesStr.split("_");
	var i = 0;
	for (; accTypes != '' && i < accTypes.length; i++) {
		if (accTypes[i] == "01") {
			$('#shenggu').attr('class', 're_icon1 re_icon1_cur');
		}
		if (accTypes[i] == "02") {
			$('#shangchang').attr('class', 're_icon2 re_icon2_cur');
		}
		if (accTypes[i] == "03") {
			$('#zhongda').attr('class', 're_icon3 re_icon3_cur');
		}
		if (accTypes[i] == "04") {
			$('#menzhen').attr('class', 're_icon4 re_icon4_cur');
		}
		if (accTypes[i] == "05") {
			$('#zhuyuanyiliao').attr('class', 're_icon5 re_icon5_cur');
		}
		if (accTypes[i] == "06") {
			$('#zhuyuanbutie').attr('class', 're_icon6 re_icon6_cur');
		}
		if (accTypes[i] == "07") {
			$('#nvxingshengyu').attr('class', 're_icon7 re_icon7_cur');
		}
		if (accTypes[i] == "08") {
			$('#dentisty').attr('class', 're_icon8 re_icon8_cur');
		}
		if (accTypes[i] == "09") {
			$('#onculist').attr('class', 're_icon9 re_icon9_cur');
		}
		if (accTypes[i] == "10") {
			$('#menzhendabing').attr('class', 're_icon11 re_icon11_cur');
		}
		if (accTypes[i] == "11") {
			$('#jinjiyake').attr('class', 're_icon10 re_icon10_cur');
		}
		if (accTypes[i] == "12") {
			$('#buymedicine').attr('class', 're_icon12 re_icon12_cur');
		}
		if (accTypes[i] == "13") {
			$('#medical').attr('class', 're_icon13 re_icon13_cur');
		}
		if (accTypes[i] == "14") {
			$('#girlDisease').attr('class', 're_icon14 re_icon14_cur');
		}
		if (accTypes[i] == "15") {
			$('#aids').attr('class', 're_icon15 re_icon15_cur');
		}
		if (accTypes[i] == "16") {
			$('#emergencymedical').attr('class', 're_icon16 re_icon16_cur');
		}
		if (accTypes[i] == "17") {
			$('#medicalvaccine').attr('class', 're_icon17 re_icon17_cur');
		}
		if (accTypes[i] == "18") {
			$('#congenitaldisease').attr('class', 're_icon18 re_icon18_cur');
		}
		if (accTypes[i] == "19") {
			$('#xinxueguan').attr('class', 're_icon19 re_icon19_cur');
		}
		if (accTypes[i] == "20") {
			$('#guzhe').attr('class', 're_icon20 re_icon20_cur');
		}
	}

}

function saveClaimAcc(method, value) {
	if (method == 'add') {
		var accTypesStr = $("#accTypesBy_").val();
		var accTypes = accTypesStr.split("_");
		var i = 0;
		// 判断是否已经保存了这个 索赔事故性质
		var flag = 0;
		for (; accTypes != '' && i < accTypes.length; i++) {
			if (accTypes[i] == value) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			if ($("#accTypesBy_").val() == '') {
				$("#accTypesBy_").val(value);
			} else {
				$("#accTypesBy_").val($("#accTypesBy_").val() + "_" + value);
			}
		}
	}

	if (method == 'del') {
		var accTypesStr = $("#accTypesBy_").val();
		var accTypes = accTypesStr.split("_");
		var i = 0;
		// 判断是否已经保存了这个 索赔事故性质
		var flag = 0;
		for (; accTypes != '' && i < accTypes.length; i++) {
			if (accTypes[i] == value) {
				accTypes[i] = '00';
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			var accTypesNew = '';
			i = 0;
			var position = 0;
			for (; accTypes != '' && i < accTypes.length; i++) {
				if (accTypes[i] != '00') {
					if (position == 0) {
						accTypesNew = accTypes[i];
					} else {
						accTypesNew = accTypesNew + '_' + accTypes[i];
					}
					position++;
				}
			}

			$("#accTypesBy_").val(accTypesNew);
		}
	}

}

// 事件删除
var otherIndex = 0;
function delEventTr() {
	var tr = $("#eventInfoTbl tr:eq(" + otherIndex + ")");
	var claimNo = $("#evntForClaimNo").val();
	var trId = tr.attr("id");
	if (trId != "" && trId != undefined) {
		if (confirm("是否确认删除该事件及收据信息？")) {
			$.ajax({
				type : "POST",
				url : "delEventInfoForClaim.do",
				data : 'claimNo=' + claimNo + '&&eventNo=' + trId,
				error : function() {
				},
				success : function(data) {
					if (data == "00") {
						alert("系统异常，删除事件信息失败！");

					} else {
						var accs = [];
						accs = data.split("_");
						$("#accTypesBy_").val(data);
						$('#shenggu').attr('class', 're_icon1 re_icon1');
						$('#shangchang').attr('class', 're_icon2');
						$('#zhongda').attr('class', 're_icon3');
						$('#menzhen').attr('class', 're_icon4');
						$('#zhuyuanyiliao').attr('class', 're_icon5');
						$('#zhuyuanbutie').attr('class', 're_icon6');
						$('#nvxingshengyu').attr('class', 're_icon7');
						$('#dentisty').attr('class', 're_icon8');
						$('#onculist').attr('class', 're_icon9');
						$('#menzhendabing').attr('class', 're_icon11');
						$('#jinjiyake').attr('class', 're_icon10');
						$('#buymedicine').attr('class', 're_icon12');
						$('#medical').attr('class', 're_icon13');
						$('#girlDisease').attr('class', 're_icon14');
						$('#aids').attr('class', 're_icon15');
						$('#emergencymedical').attr('class', 're_icon16');
						$('#medicalvaccine').attr('class', 're_icon17');
						$('#congenitaldisease').attr('class', 're_icon18');

						for (var int = 0; int < accs.length; int++) {
							var type = accs[int];
							if (type == "01") {
								$('#shenggu').attr('class',
										're_icon1 re_icon1_cur');
							} else if (type == "02") {
								$('#shangchang').attr('class',
										're_icon2 re_icon2_cur');
							} else if (type == "03") {
								$('#zhongda').attr('class',
										're_icon3 re_icon3_cur');
							} else if (type == "04") {
								$('#menzhen').attr('class',
										're_icon4 re_icon4_cur');
							} else if (type == "05") {
								$('#zhuyuanyiliao').attr('class',
										're_icon5 re_icon5_cur');
							} else if (type == "06") {
								$('#zhuyuanbutie').attr('class',
										're_icon6 re_icon6_cur');
							} else if (type == "07") {
								$('#nvxingshengyu').attr('class',
										're_icon7 re_icon7_cur');
							} else if (type == "08") {
								$('#dentisty').attr('class',
										're_icon8 re_icon8_cur');
							} else if (type == "09") {
								$('#onculist').attr('class',
										're_icon9 re_icon9_cur');
							} else if (type == "11") {
								$('#jinjiyake').attr('class',
										're_icon10 re_icon10_cur');
							} else if (type == "10") {
								$('#menzhendabing').attr('class',
										're_icon11 re_icon11_cur');
							} else if (type == "12") {
								$('#buymedicine').attr('class',
										're_icon12 re_icon12_cur');
							} else if (type == "13") {
								$('#medical').attr('class',
										're_icon13 re_icon13_cur');
							} else if (type == "14") {
								$('#girlDisease').attr('class',
										're_icon14 re_icon14_cur');
							} else if (type == "15") {
								$('#aids').attr('class',
										're_icon15 re_icon15_cur');
							} else if (type == "16") {
								$('#emergencymedical').attr('class',
										're_icon16 re_icon16_cur');
							} else if (type == "17") {
								$('#medicalvaccine').attr('class',
										're_icon17 re_icon17_cur');
							} else if (type == "18") {
								$('#congenitaldisease').attr('class',
										're_icon18 re_icon18_cur');
							} else if (type == "19") {
								$('#xinxueguan').attr('class',
										're_icon19 re_icon19_cur');
							} else if (type == "20") {
								$('#guzhe').attr('class',
										're_icon20 re_icon20_cur');
							}

						}
						alert("删除事件信息成功。");
						if (otherIndex != 0) {
							$("#eventInfoTbl tr:eq(" + otherIndex + ")")
									.remove();
							otherIndex = 0;
						}
					}
				}
			});
		}

	}
}
function choosEventEd(flag) {

	$(flag).css("background-color", "#e5e5e5").siblings().css(
			"background-color", "#FFFFFF");
	otherIndex = $(flag).index();
}

function onlychoose(obj) {
	if ($(obj).hasClass("check_no")) {
		$(obj).attr("class", "check_yes");
	} else {
		$(obj).attr("class", "check_no");
	}

}
function checkMoney(moneyInput) {
	if ($(moneyInput).val() != "") {
		// var mny = /(^\d+$)|(^\d+.\d+$)/g;
		var mny = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
		if (!mny.test($(moneyInput).val())) {
			$(moneyInput).val("");
		}
	}
}
// 邮箱校验
function emailCheck(str) {
	// var pattern =/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
	var pattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return pattern.test(str);
}

function skipTo(str) {
	var params = {};
	params['preno'] = str;
	// SkipByPost("checkgrant.do",params);
	SkipByPost(
			"javascript:openWindow('<%=request.getContextPath()%>/dataenter/checkgrant.do')",
			params);
}
// 产险银行名称模糊查询
function tipSearch(flag) {
	var bankname = null;
	if (flag == '1') {
		bankname = $("#propertyBankName").val();
	} else if (flag == '2') {
		bankname = $("#propertyCenterBankName").val();
	}
	$
			.ajax({
				type : "POST",
				url : "../virementoperation/queryPropertyBank.do",
				data : {
					"bankname" : bankname
				},
				error : function() {
				},
				success : function(data) {
					if (flag == '1') {
						var ul = $("<ul id=\"tip\"></ul>");
						if (data.length > 0) {
							for (var i = 0; i < data.length; i++) {
								$(ul)
										.append(
												"<li style=\"background-color:#FFFFFF\" onmouseover=\"changbackclrFn(this)\" onblur=\"displayNone('1')\" onclick=\"selectedCompanyInfoFn('"
														+ data[i].bankName
														+ "','"
														+ data[i].bankGroupCode
														+ "','1')\">"
														+ data[i].bankName
														+ "</li>");
							}
							$("#tip-div").html(ul);
							$("#tip-div").css("display", "");
						} else {
							$("#tip-div").css("display", "none");
						}
					} else if (flag == '2') {
						var ul = $("<ul id=\"top\"></ul>");
						if (data.length > 0) {
							for (var i = 0; i < data.length; i++) {
								$(ul)
										.append(
												"<li style=\"background-color:#FFFFFF\" onmouseover=\"changbackclrFn(this)\" onblur=\"displayNone('2')\" onclick=\"selectedCompanyInfoFn('"
														+ data[i].bankName
														+ "','"
														+ data[i].bankGroupCode
														+ "','2')\">"
														+ data[i].bankName
														+ "</li>");
							}
							$("#top-div").html(ul);
							$("#top-div").css("display", "");
						} else {
							$("#top-div").css("display", "none");
						}
					}

				}
			});
}

function selectedCompanyInfoFn(bankName, bankGroupCode, flag) {
	if (flag == '1') {
		$("#isnoPropertyBankName").val(bankName);
		$("#propertyBankName").val(bankName);
		$("#propertyBankType").val(bankGroupCode);
		$("#tip-div").css("display", "none");
	} else if (flag == '2') {
		$("#isnoBankName").val(bankName);
		$("#propertyCenterBankName").val(bankName);
		$("#propertyCenterBankType").val(bankGroupCode);
		$("#top-div").css("display", "none");
	}

}

function changbackclrFn(flag) {
	$(flag).css("background-color", "#e5e5e5").siblings().css(
			"background-color", "#FFFFFF");
}
function displayNone(flag) {
	if (flag == '1') {
		$("#tip").css("display", "none");
	} else if (flag == '2') {
		$("#top").css("display", "none");
	}

}

// 根据证件类型修改性别
function onclickIdtype(Idtype) {
	if (Idtype != "a") {
		$("#customerInfoPid").val("");
		$("#customerInfoSex1").attr("class", "sel_list i_ul_265");
	}
}

// 根据身份证号显示性别
function changSex() {
	if ($("#customerInfoIdtype").attr("code") == "a") {
		if (!checkIdentityCardTrueOrFalse($.trim($("#customerInfoPid").val()))) {
			alert("被保人身份证号码格式有误，请重新录入。");
			return;
		} else {
			var pid = $.trim($("#customerInfoPid").val());
			if (pid.length == "15") {
				var i = pid.substr(pid.length - 1, 1);
				ismanandwoman(i);
			} else if (pid.length == "18") {
				var i = pid.substr(pid.length - 2, 1);
				ismanandwoman(i);
			}
		}
	}
}

function ismanandwoman(i) {
	if (i % 2 == 0) {
		$("#customerInfoSex").html("女");
		$("#customerInfoSex").attr("code", "2");
		$("#customerInfoSex1").removeAttr("class");
	} else {
		$("#customerInfoSex").html("男");
		$("#customerInfoSex").attr("code", "1");
		$("#customerInfoSex1").removeAttr("class");
	}
}

// 产险/寿险、健康险提交至BPO
function saveBpo(claimNo, caseSource, sendFlag,appHeJin) {
	if ("2" == sendFlag) {
		alert("调用接口失败，没有获取到保单信息");
	} else {

		var r = confirm("是否要提交BPO");
		if (r == true) {
			if (caseSource == 1) {
				var lifeReportNo = $("#clamlIfeReportNo").val();
				if (lifeReportNo == "" || lifeReportNo == null) {
					alert("还未报案在提交");
					return;
				}
			}

			$("#saveBpo").css("color", "#ccc");
			$("#saveBpo").removeAttr("onclick");
			$.ajax({
				type : "POST",
				url : "updateReportcaseEcmstatus.do",
				data : {
					"claimNo" : claimNo,
					"caseSource" : caseSource,
					"sendFlag" : sendFlag,
					"appHeJin" :appHeJin
				},
				error : function() {
					alert("提交BPO失败");
					$("#saveBpo").css("color", "#007aff");
					$("#saveBpo").attr("onclick",
							"saveBpo('" + claimNo + "','" + caseSource + "')");
				},
				success : function(data, status) {
					if (data == "success") {
						alert("提交BPO成功");
						$("#saveInfo").css("color", "#ccc");
						$("#saveInfo").removeAttr("onclick");
						$("#doneInfo").css("color", "#ccc");
						$("#doneInfo").removeAttr("onclick");
					} else if (data == "resuccess") {
						alert("影像已处理成功！");
						$("#saveInfo").css("color", "#007aff");
						$("#saveInfo").attr("onclick", "saveAllInfo()");
						$("#doneInfo").css("color", "#007aff");
						$("#doneInfo").attr("onclick", "doneAllInfo()");
					} else if (data == "fail") {
						alert("异常情况，请联系维护人员检查");
					}
				}
			});
		}
	}
}

// 不予受理
function revokedFiledCase(claimNo) {

	var isQuest = $("#quest").attr("value");
	if (confirm("是否确认不予受理？")) {
		$.ajax({
			type : "POST",
			url : "/claimserver/claim/filedCase/requestRevokedFiledCase.do",
			data : {
				"claimNo" : claimNo,
				"isQuest" : isQuest
			},
			error : function(data) {
				alert("不予受理失败");
			},
			success : function(data) {
				if (data.errMsg == "" || data.errMsg == null) {
					var insureName = data.reMap.insureName;
					var xzName = data.reMap.xzName;
					var policyno = data.reMap.policyno;
					var reportName = data.reMap.reportName;
					var idcard = data.reMap.idcard;
					var currentDate = data.reMap.currentDate;
					var branchName = data.reMap.branchName;
					var clmAccAndReportType = data.reMap.clmAccAndReportType;
					$("#notGrantOp").find("#policyno").html(policyno);
					$("#notGrantOp").find("#insureName").html(insureName);
					$("#notGrantOp").find("#reportName").html(reportName);
					$("#notGrantOp").find("#idcard").html(idcard);
					$("#notGrantOp").find("#currentDate").val(currentDate);
					$("#notGrantOp").find("#clmAccAndReportType").html(
							xzName);
					$("#notGrantOp").find("#branchName").html(branchName);
					//REQHOP1-161014-1427 理赔通知书优化 lujibin 20161226 
        			$("#notGrantOp").find("#name1").val(data.reMap.appName);
        			$("#notGrantOp").find("#cNo1").val(data.reMap.claimNo);
        			$("#notGrantOp").find("#cDate1").val(data.reMap.applyDate);
        			$("#notGrantOp").find("#iName1").val(insureName);
        			$("#notGrantOp").find("#pid1").val(idcard);
        			$("#notGrantOp").find("#iName2").val(insureName);
        			$("#notGrantOp").find("#pid2").val(idcard);
        			$("#notGrantOp").find("#p0000001InfoTel").val(data.reMap.p0000001InfoTel);
        			//REQHOP1-161014-1427 理赔通知书优化 lujibin 20161226 
					showDiv('notGrantOp');
				} else {
					alert(data.errMsg);
				}
			}
		});

	}
}

/** 不予受理通知书打印 */
function printBYCL() {
	var reason = $("#reason").val();
	if (reason == "" || reason == null) {
		alert("不予受理原因不能为空");
		return;
	}
	var param = {};
	var claimNo = $("#notGrantOp").find("#cNo1").val();
	var policyno = $("#notGrantOp").find("#policyno").html();
	var insureName = $("#notGrantOp").find("#insureName").html();
	var reportName = $("#notGrantOp").find("#reportName").html();
	var idcard = $("#notGrantOp").find("#idcard").html();
	var reason = $("#notGrantOp").find("#reason").val();
	var currentDate = $("#notGrantOp").find("#currentDate").val();
	var clmAccAndReportType = $("#notGrantOp").find("#clmAccAndReportType")
			.html();
	var branchName = $("#notGrantOp").find("#branchName").html();
	var appName=$("#notGrantOp").find("#name1").val();

	param['claimNo'] = claimNo;
	param['idcard'] = idcard;
	param['insureName'] = insureName;
	param['currentDate'] = currentDate;
	param['policyno'] = policyno;
	param['reason'] = reason;
	param['reportName'] = reportName;
	param['clmAccAndReportType'] = clmAccAndReportType;
	param['branchName'] = branchName;
	param['infoTel'] = $("#p0000001InfoTel").val();
	param['appName']=appName;
	
	$.ajax({
		type : "POST",
		url : "/claimserver/claim/notification/printBYSL.do",
		data : param,
		async : false,
		success : function(data) {
			if (data == '0000000') {
				alert("操作成功");
				window.location = "/claimserver/dataenter/queryMyTask.do";
			} else {
				alert("操作失败");
			}
		},
		error : function(data) {
			alert("操作失败");
		}
	});
}

//产线回退(RPL11-160707-301) txb，2016/12/01
function backChan(slan) {
	var claimNo=$("#claimNo").val();
	var reasonR = $("#reasonR").val();
	if(reasonR == "" || reasonR == null){
		alert("退回原因内容为空");
	}else{
		$.ajax({
			type : "POST",
			url : "backChanXian.do",
			data : {
				"claimNo" : claimNo,
				"reasonR" : reasonR,
				"slan" :    slan,
			},
			success : function(data) {
				if (data == '0000000') {
					alert("操作成功");
					closeDiv('open3');
					window.location = "/claimserver/dataenter/queryMyTask.do";
				} else {
					alert("操作失败");
				}
			},
		});
	}
}