$(document).ready(function(){
	
});
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(){
	//报案人信息
	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 accidentaddrtype = $("#divaccidentaddrtype_code").val();
	if(accidentaddrtype!=undefined&&accidentaddrtype!="")
		$("#accidentaddrtype").val(accidentaddrtype);
	var accidentDesc = reg($("#accidentDesc").val());
	
	var jsonStr= '{"claimNo":"' + claimNo + '","reportDate":"' + reportDate+ '","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 +'","accidentAddrType":"' + $("#accidentaddrtype").val()  +
	'","accidentDesc":"' + accidentDesc +'","accidentCode":"' + $("#accidentCode").val()  +
	'"}';
	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();
	if($("#accidentDate").val().length==0){
		alert("请填写出险日期。");
		return;
	} 
	if($("#firstDiagnoseDate").val().length==0){
		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;
	} 
	$("#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();
	if($("#reportDate").val().length==0){
		alert("请填写报案人报案日期。");
		return;
	} 
	if($("#idtype").val().length==0){
		alert("请选择报案人人证件类型。");
		return;
	}
	if($.trim($("#pid").val()).length==0){
		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;
	}
	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($.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_contractAddr").val()).length==0){
		alert("请填写申请人地址。");
		return;
	}
	if($.trim($("#sqr_postCode").val()).length==0){
		alert("请填写申请人邮编。");
		return;
	}
	if($("#accidentDate").val().length==0){
		alert("请填写出险日期。");
		return;
	} 
	if($("#firstDiagnoseDate").val().length==0){
		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;
	} 
	$("#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=="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{
				alert("数据录入信息保存失败。");
				$("#doneInfo").attr("onclick","doneAllInfo()");
			}
		}
	});
}


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

function initclaimacc(skipFlag){
	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]=="11"){
			$('#jinjiyake').attr('class','re_icon10 re_icon10_cur');
		}if(accTypes[i]=="10"){
			$('#dabingmenzhen').attr('class','re_icon11 re_icon11_cur');
		}
		if(accTypes[i]=="12"){
			$('#yaofanggouyao').attr('class','re_icon12 re_icon12_cur');
		}
		if(accTypes[i]=="13"){
			$('#tijian').attr('class','re_icon13 re_icon13_cur');
		}
		if(accTypes[i]=="14"){
			$('#girlDisease').attr('class','re_icon14 re_icon14_cur');
		}
		if(accTypes[i]=="15"){
			$('#aizibing').attr('class','re_icon15 re_icon15_cur');
		}
		if(accTypes[i]=="16"){
			$('#jinjiyiliao').attr('class','re_icon16 re_icon16_cur');
		}
		if(accTypes[i]=="17"){
			$('#tijianyumiao').attr('class','re_icon17 re_icon17_cur');
		}
		if(accTypes[i]=="18"){
			$('#xiantianxingjibing').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("删除事件信息成功！");
							if(otherIndex!=0){
								$("#eventInfoTbl tr:eq("+otherIndex+")").remove();
								otherIndex=0;
							}
						}else{
							alert("系统异常，删除事件信息失败。");
						}
					}
				});
			}
			
		}
}
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 skipTo(str){
	var params={};
	params['preno'] = str;
	SkipByPost("../dataenter/checkgrant.do",params);
}

/**
 * 729需求 cyj新增
 */
  function showHospitalDetailDiv(hospitalCode){
        if(hospitalCode==undefined){
        	hospitalCode="";
        }
		$.ajax({
			type : "POST", 
			url : "showHospitalDetail.do",
			data : {'hospitalCode':hospitalCode},
			error : function(){
				alert("系统错误，请稍后再试。");
			},
			success : function(data){
				$('#hospitalTbList').empty();
               var hospitalCapitalString="";
               var hospitalLevelString  ="";
               if(data!=null&&data.length>0){
            	   hospitalCapitalString = data[0].hospitalCapitalString;
            	   hospitalLevelString   = data[0].hospitalLevelString;
               }
               
               if(hospitalCapitalString==undefined){
            	   hospitalCapitalString="";
               }
               if(hospitalLevelString==undefined){
            	   hospitalLevelString="";
               }
               
               var hospitalTitle = $('<tr><th width="50%">医院等级</th><th width="50%">医院性质</th></tr>');
               var hospitalInfo  = $('<tr><td>'+hospitalLevelString+'</td><td>'+hospitalCapitalString+'</td></tr>');
               $('#hospitalTbList').append(hospitalTitle);
               $('#hospitalTbList').append(hospitalInfo);
               showDiv('hospitalResultDivId');
			}
		});  
  }



