$(function(){
	if($("#stype").val()=="2"){
		divCustomInfo.style.display="block";//选怪姓+名+性别+出生日期
		$("#content").hide();//隐藏上面的输入框
	}
	if($("#stype").val()=="3"){//查询条件是保单号
		divCusInfo.style.display="none";
	}
	if($("#stype").val()=="1"){//查询条件是保单号
		$("#content").hide();//隐藏上面的输入框
	}
	
	if ($("#pageFrom").val()!= '') {
		$("#search").hide();
		divCusInfo.style.display="none";
		getHumanQuery();
	}
	policy1.style.display="none";
	policy2.style.display="block";
	divCusInfo.style.display="block";
	policyList1.style.display="none";
	policyList2.style.display="block";
	policyList3.style.display="none";
	$("#branchName").hide();
	$("#branchId").hide();
});


function changeValue(val) {
	  $("#formId2").val(val);
}

function insureQuery(policyNo,classcode,sPid,policyInterSource,sGrpattr,branchid,sIdtype,familyFlag){
	
	var idtype=$("#certificates").val();
	if(idtype==""){
		idtype = sIdtype;
	}
	var searchType = $("#stype").val();
	var searchContent = $("#searchContent").val();
	var pageFrom = $("#pageFrom").val();
	var claimNo = $("#claimNo").val();
	var searchSername = $("#sername").val();
	var searchName = $("#name").val();
	var searchSex = $("#sex").val();
	var searchBirthday = $("#birthday").val();
    var channelType = $("#channelType").val();
	SkipByPost("querypolicyinfo.do",{policyNo:policyNo,classcode:classcode,sPid:sPid,policyInterSource:policyInterSource,sGrpattr:sGrpattr,branchid:branchid,searchType:searchType,searchContent:searchContent,pageFrom:pageFrom,claimNo:claimNo,searchSername:searchSername,searchName:searchName,searchSex:searchSex,searchBirthday:searchBirthday,channelType:channelType,sIdtype:idtype,familyFlag:familyFlag});
}

function policyinfo(){
	SkipByPost("policyListQuery.do");
}


function gohistory(){
	var params={};
	params['sIdtype']=$("#sIdtype").val();
	params['pageFrom']=$("#pageFrom").val();
	params['content']=$("#searchContent").val();
	params['stype']=$("#searchType").val();
	params['pid']=$("#pid").val();
	params['claimNo']=$("#claimNo").val();
	params['sername']=$("#searchSername").val();
	params['name']=$("#searchName").val();
	params['sex']=$("#searchSex").val();
	params['birthday']=$("#searchBirthday").val();
	params['channelType']=$("#channelType").val();
	
	SkipByPost("policyreturn.do",params);
	//SkipByPost("policyListQuery.do",params);
}




var stch=false;//防止重点
function initInsure(){
	$("#stype").val("1");//默认为被保险人身份证号查询
}
function insureSelectChange(val,flag){
	$("#policyList1").find("#policyList").html("");
	$("#policyList2").find("#policyList").html("");
	$("#policyList3").find("#policyList").html("");
	$("#paper").val("");
	$("#content").val("");
	var estimate= true;
	if(val=="2"&&flag==null){
		divCustomInfo.style.display="block";//选怪姓+名+性别+出生日期
		divCusInfo.style.display="none";
		policyList1.style.display="none";
		policyList2.style.display="block";
		policyList3.style.display="none";
		$("#branchName").hide();
		$("#branchId").hide();
		estimate = false;
		$("#content").hide();//隐藏上面的输入框
	}else if((val == "5"&&flag==null)){
		$("#content").val("");
		$("#content").show();
		divCustomInfo.style.display="none";
		divCusInfo.style.display="block";
		policyList1.style.display="none";
		policyList2.style.display="none";
		policyList3.style.display="block";
		$("#branchName").hide();
		$("#branchId").hide();
		estimate = false;
	}else if(val == "1"&&flag!=null){
		divCustomInfo.style.display="none";
		divCusInfo.style.display="block";
		policyList1.style.display="block";
		policyList2.style.display="none";
		policyList3.style.display="none";
		$("#branchName").show();
		$("#branchId").show();
		$("#content").hide();//隐藏上面的输入框
		estimate = false;
	}else if((val == "3"&&flag!=null)){
		$("#content").val("");
		$("#content").show();
		divCustomInfo.style.display="none";
		divCusInfo.style.display="none";
		policyList1.style.display="none";
		policyList2.style.display="none";
		policyList3.style.display="block";
		$("#branchName").hide();
		$("#branchId").hide();
	}else{
		$("#content").val("");
		$("#content").show();
		divCustomInfo.style.display="none";
		divCusInfo.style.display="none";
		policyList1.style.display="none";
		policyList2.style.display="block";
		policyList3.style.display="none";
		$("#branchName").hide();
		$("#branchId").hide();
	}
	
	if(val=="1"&&estimate){
		divCustomInfo.style.display="none";
		divCusInfo.style.display="block";//被保人证件号码
		policyList1.style.display="none";
		policyList2.style.display="block";
		policyList3.style.display="none";
		$("#branchName").hide();
		$("#branchId").hide();
		$("#content").hide();//隐藏上面的输入框
	}
	$("#stype").val(val);//默认为被保险人身份证号查询
}
function sexSelectChange(val){
	$("#sex").val(val);//性别
}

function getCityBypro(){
	if ($("#stype").val() == '1' || $("#stype").val() == '5') {
		if ($("#certificates").val() == "") {
			alert("请选择证件类型");
			return false;
		}
	}
	var channelType = $("#channelType").val();
	if($("#stype").val()=='1' || $("#stype").val() == '5'){
		if($("#certificates").val()=='a'){
			if(($("#paper").val().length!=15 && $("#paper").val().length!=18)){
				alert("身份证长度必须为15位或18位");
				return false;
			}
		}else {
			if($("#paper").val()==""){
				alert("被保人证件号不能为空!");
				return false;
			}
		}
		
	}
	if($("#stype").val()=='3'&&channelType !='2'){
		if($("#content").val().length!=15){
			alert("保单号长度必须为15位");
			return false;
		}
		$("#searchContent").val($("#content").val());
	}else if($("#stype").val()=='1'){
		$("#searchContent").val($("#paper").val());
	}else{
		$("#searchContent").val($("#content").val());
	}

	if($("#stype").val()=='2'){
		if($("#sername").val()==null || $("#sername").val()==""){
			alert("姓不能为空");
			return false;
		}
		if($("#name").val()==null || $("#name").val()==""){
			alert("名不能为空");
			return false;
		}
		if($("#sex").val()==null || $("#sex").val()==""){
			alert("性别不能为空");
			return false;
		}
		if($("#birthday").val()==null || $("#birthday").val()==""){
			alert("生日不能为空");
			return false;
		}
	}

	$("#policyList1").find("#policyList").html("");
	$("#policyList2").find("#policyList").html("");
	$("#policyList3").find("#policyList").html("");
    $.ajax({
        type: "POST",  
        async: false, 
        url: "querypolicylist.do", 
        data: {unitName:$("#unitName").val(),stype:$("#stype").val(),content:$("#content").val(),sername:$("#sername").val(),name:$("#name").val(),sex:$("#sex").val(),birthday:$("#birthday").val(),channelType:channelType,paper:$("#paper").val(),certificates:$("#certificates").val(),branchId:$("#branchId").val()},
        success: function(data){
        	closeLoading();//去掉进度条
        	//var itemsEval=eval(data);
        	
        	if(data==null || data==""){
        		if(channelType=="2"){
        			if($("#stype").val()=="1"){
            			$("#policyList1").find("#policyList").append("<tr><td colspan=\"6\">查询不到相关内容，请检查查询条件</td></tr>");
        			}else{
            			$("#policyList3").find("#policyList").append("<tr><td colspan=\"6\">查询不到相关内容，请检查查询条件</td></tr>");
        			}
        		}else{
        			$("#policyList2").find("#policyList").append("<tr><td colspan=\"6\">查询不到相关内容，请检查查询条件</td></tr>");
        		}
        	}
        	
        	for(var i = 0;i<data.length;i++){
        		var n = data[i];
        		if(channelType=="2"){
            		if($("#stype").val()=="1"){
            			$("#policyList1").find("#policyList").append("<tr><td  onclick=\"openEventWindow('"+n.applicationNo+"')\" style=\"cursor: pointer;\"  >"+n.policyNo+"</td><td>"+judgeIsNull(n.tbrName)+"</td><td>"+judgeIsNull(n.xzmc)+"</td><td>"+judgeIsNull(n.sDescribe)+"</td><td>"+judgeIsNull(n.sValdate)+"</td></tr>");
            		}else{
            			$("#policyList3").find("#policyList").append("<tr><td  onclick=\"openEventWindow('"+n.applicationNo+"')\" style=\"cursor: pointer;\"  >"+n.policyNo+"</td><td>"+judgeIsNull(n.tbrName)+"</td><td>"+judgeIsNull(n.xzmc)+"</td><td>"+judgeIsNull(n.sPname)+"</td><td>"+judgeIsNull(n.sPid)+"</td><td>"+judgeIsNull(n.sDescribe)+"</td><td>"+judgeIsNull(n.sValdate)+"</td></tr>");
            		}
        		}else{
        			if(n.familyFlag=='1'){
        				$("#policyList2").find("#policyList").append("<tr><td  onclick=\"insureQuery('"+n.policyNo+"','"+n.classcode+"','"+n.sPid+"','"+n.policyInterSource+"','"+n.sGrpattr+"','"+n.branchid+"','"+n.sIdtype+"','1')\" style=\"cursor: pointer;\"  >"+n.policyNo+"<b class=\"sild_icon_sz\">家</b></td><td>"+judgeIsNull(n.tbrName)+"</td><td>"+judgeIsNull(n.xzmc)+"</td><td>"+judgeIsNull(n.sPname)+"</td><td>"+judgeIsNull(n.sPid)+"</td><td>"+judgeIsNull(n.sDescribe)+"</td><td>"+judgeIsNull(n.sValdate)+"</td><td>"+xubaojudge(n.sIscom)+"</td><td>"+judge(n.sAutoadd)+"</td></tr>");
                	}else{
            			$("#policyList2").find("#policyList").append("<tr><td  onclick=\"insureQuery('"+n.policyNo+"','"+n.classcode+"','"+n.sPid+"','"+n.policyInterSource+"','"+n.sGrpattr+"','"+n.branchid+"','"+n.sIdtype+"','0')\" style=\"cursor: pointer;\"  >"+n.policyNo+"</td><td>"+judgeIsNull(n.tbrName)+"</td><td>"+judgeIsNull(n.xzmc)+"</td><td>"+judgeIsNull(n.sPname)+"</td><td>"+judgeIsNull(n.sPid)+"</td><td>"+judgeIsNull(n.sDescribe)+"</td><td>"+judgeIsNull(n.sValdate)+"</td><td>"+xubaojudge(n.sIscom)+"</td><td>"+judge(n.sAutoadd)+"</td></tr>");
            		}
        		}
        	}
        		
       	}
    });
	
	//document.forms["formId2"].submit();
} 

function getHumanQuery(){
	var channelType = $("#channelType").val();
	$("#policyList").html("");
	  $.ajax({  
	        type: "POST",  
	        async: false, 
	        url: "querypolicylist.do", 
	        data: {stype:"1",paper:$("#pid").val(),channelType:channelType,certificates:"a"},  
	        success: function(data){
	        	closeLoading();//去掉进度条
	        	//var itemsEval=eval(data);
	        	
	        	if(data==null || data==""){
	        		$("#policyList").append("<tr><td colspan=\"6\">查询不到相关内容，请检查查询条件</td></tr>");
	        	}
	        	
	        	for(var i = 0;i<data.length;i++){
	        		var n = data[i];
	        		if(n.familyFlag=='1'){
	        			$("#policyList").append("<tr><td  onclick=\"insureQuery('"+n.policyNo+"','"+n.classcode+"','"+n.sPid+"','"+n.policyInterSource+"','"+n.sGrpattr+"','"+n.branchid+"','"+n.sIdtype+"','1')\" style=\"cursor: pointer;\"  >"+n.policyNo+"<b class=\"sild_icon_sz\">家</b></td><td>"+n.xzmc+"</td><td>"+n.sDescribe+"</td><td>"+n.sValdate+"</td><td>"+xubaojudge(n.sIscom)+"</td><td>"+judge(n.sAutoadd)+"</td></tr>");           	
	        		}else{
	        			$("#policyList").append("<tr><td  onclick=\"insureQuery('"+n.policyNo+"','"+n.classcode+"','"+n.sPid+"','"+n.policyInterSource+"','"+n.sGrpattr+"','"+n.branchid+"','"+n.sIdtype+"','0')\" style=\"cursor: pointer;\"  >"+n.policyNo+"</td><td>"+n.xzmc+"</td><td>"+n.sDescribe+"</td><td>"+n.sValdate+"</td><td>"+xubaojudge(n.sIscom)+"</td><td>"+judge(n.sAutoadd)+"</td></tr>");
	        		}
	        	}
	        } 
	    });   
}



function clmquery() {
	if($("#claimNo").val()==null || $("#claimNo").val()=="") {
		alert("查询内容不能为空，并且为赔案号！");
		return false;
	}
	if($("#claimNo").val().length<10){
		alert("赔案号长度位数不正确！");
		return false;
	}
	document.getElementById('clmquery').submit();
	//alert("3333");
	
}

function checkInsure(){
	//姓名+性别+出生日期查询类型为2，如果不为2时需要校验查询内容content
	if(($("#stype").val()=="3")){ 
		if($("#content").val()==null || $("#content").val()==""){
			alert("查询内容不能为空！");
			return false;
		}
	}
	getCityBypro();
}

//回车查询
function enterQuery(){
	 var event = window.event||arguments.callee.caller.arguments[0];
	 if(event.keyCode==13){
		 checkInsure();
	 }
}

function judge(a){
	if(a==""){
		return "";
	}
	if(a=='N'){
		return "否";
	}else if(a=='Y'){
		return "是";
	}else if(a==0){
		return "否";
	}else if(a==1){
		return "是";
	}	
}

function xubaojudge(a){
	if(a=='0'){
		return "是";
	}else if(a=='2'){
		return "否";
	}else{
		return "";
	}	
}

function judgeIsNull(a){
	if(a=="" || a==null){
		return "";
	}else{
		return a;
	}
}

//单选

$(".radio_yes,.radio_no").click(function(){ 
	  
	  if($(this).is(".radio_yes")){
	    
		$(this).removeClass("radio_yes");
		$(this).addClass("radio_no"); 
	  }
	  
	  else{
			var obj=  $(".radio_yes");
			obj.removeClass("radio_yes");          
			obj.addClass("radio_no"); 
			$(this).removeClass("radio_no");
	        $(this).addClass("radio_yes");
	        $("#channelType").val($(this).attr("channelValue"));
	}
});

//打开影像
	function openImage(sModino){//sModino批单号
		var branchid = $("#branchid").val();
		   //获取当前网址
	    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=3&branchid='+branchid+'',"保全影像");
		
		
	}

	
	//单位名称选项模糊查询
	
	function unitSearch(){
		
		$.ajax({  
	        type: "POST",  
	        async: false, 
	        url: "searchUnit.do", 
	        data: {unitName:$("#key-word").val()},  
	        success: function(data){
	        	for ( var i = 0; i < data.length; i++) {
					$("#context-unit").append("<tr><td>data[i].sappname</td></tr>");
				}
	        }  
	    });   
	}

	//选中本行
	function selectRow(flag){
		$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
		$("#selectUnit").val("");
		$("#selectUnit").val($(flag).find("td:eq(0)").html());
	}
	
	//单位名称弹出层确定按钮
	function saveSelect(){
		$("#content").val($("#selectUnit").val());
		closeDiv("open1");
	}
	function certificate(val){
		$("#paper").val("");
		$("#certificates").val(val);
	}
	
	function searchChoose(channelType){
		if(channelType == 1 || channelType == 0){
			divCustomInfo.style.display="none";
			divCusInfo.style.display="block";
			policy1.style.display="none";
			policy2.style.display="block";
			policyList1.style.display="none";
			policyList2.style.display="block";
			policyList3.style.display="none";
			$("#branchName").hide();
			$("#branchId").hide();
			$("#content").hide();
		}
		if(channelType == 2){
			divCustomInfo.style.display="none";
			divCusInfo.style.display="block";
			policy1.style.display="block";
			policy2.style.display="none";
			policyList1.style.display="block";
			policyList2.style.display="none";
			policyList3.style.display="none";
			$("#branchName").show();
			$("#branchId").show();
			$("#content").hide();
		}
	}
	
	//点击保单号把投保单号传得到url并且跳转页面
	function openEventWindow(tbdh) {
		$.ajax({
			type:"POST",
			url:getRootPath()+"/ecm/ryxpolicy.do",
			data:{"key_":"ryx_policy_info"},
			error :function(){
				alert("调用产险新影像服务失败！");
				return ;
			},
			success :function(data){
				url=data;
				var params={};
				params["zdzh"]=tbdh;
				params["dzlx"]='A';
				params["fromType"]='11';
				openNewByPost(url,params);
			}
		});
	 }
	
	function insertBranchId(val){
		$("#branchId").val(val);
	}