//	选择需要移入的行
	var index=null;
	function selectDeceitReason(flag){ 
		
		var tblId=$(flag).parent().parent().attr("id");
		$("#la_cc_con_tblList2").attr("onclick","changeRight()");
		$("#la_cc_con_tblList1").attr("onclick","changeLeft()");
		$("#la_cc_con_tblList2").find("a").css("color","#007aff");
		$("#la_cc_con_tblList1").find("a").css("color","#007aff");
		$("#la_cc_con_"+tblId).removeAttr("onclick");
		$("#la_cc_con_"+tblId).find("a").css("color","#ccc");
		$(flag).css("background-color", "#e5e5e5").siblings().css("background-color", "#FFFFFF");
		index=$(flag).index();
	}
//	移入
	function changeRight(){
		if(index==null){
			alert("请选择需要移入的欺诈嫌疑信息！");
			return;
		}
		var tr=$("<tr onclick=\"selectDeceitReason(this)\"></tr>");
		var td=$("#tblList1 tr").eq(index).html();
		var text=$("#tblList1 tr").eq(index).find("td:eq(0)").find("input:eq(0)").val();
		$("#deceitMemo").removeAttr("readonly");
		if("99"==text){
			$("#othDeceitDesc").removeAttr("readonly");
		}
		$("#tblList1 tr").eq(index).remove();
		$(tr).append(td);
		$("#tblList2").append(tr);
		index=null;
	}
//	移出
	function changeLeft(){
		if(index==null){
			alert("请选择需要移出的欺诈嫌疑信息！");
			return;
		}
		var tr=$("<tr onclick=\"selectDeceitReason(this)\"></tr>");
		var td=$("#tblList2 tr").eq(index).html();
		var type=$("#tblList2 tr").eq(index).find("td:eq(0)").find("input:eq(0)").val();
		if("99"==type){
			$("#othDeceitDesc").val("");
			$("#othDeceitDesc").attr("readonly","readonly");
		}
		if($("#tblList2 tr").index()<=0){
			$("#deceitMemo").val("");
			$("#deceitMemo").attr("readonly","readonly");
		}
		$("#tblList2 tr").eq(index).remove();
		$(tr).append(td);
		$("#tblList1").append(tr);
		index=null;
	}
//	时间显示工具
	function jsonDateFormat(date,length){
		if(date==null || date==""){
			return "";
		}
		if(isNaN(date)){
			return date;
		}
	    var datetime = new Date();
	    datetime.setTime(date);
	    var year = datetime.getFullYear();
	    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
	    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
	    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
	    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
	    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
	    if(length==10){
	    	return year + "-" + month + "-" + date;
	    }else{
	    	return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
	    }
	}
	//新增
	function addDeceitReason(){
		$("#table_con span").attr("class","radio_no");
		AddAttr();
		$("#objId").val("");
		tbllist();
	}
	//初始化欺诈嫌疑描述
	function tbllist(){
		$("#tblList2 tr").each(function(i){
			var type=$("#tblList2 tr").eq(i).find("td:eq(0)").find("input:eq(0)").val();
			var code=$("#tblList2 tr").eq(i).find("td:eq(1)").find("input:eq(0)").val();
			var tr=$("<tr  id='"+type+code+"'  onclick=\"selectDeceitReason(this)\"></tr>");
			var td=$("#tblList2 tr").eq(0).html();
			$(tr).append(td);
			$("#tblList1").append(tr);
			$("#tblList2 tr").eq(0).remove();
			$("#othDeceitDesc").val("");
			$("#deceitMemo").val("");
			$("#feedbackContent").val("");
			$("#othDeceitDesc").attr("readonly","readonly");
			$("#deceitMemo").attr("readonly","readonly");
			$("#feedbackContent").attr("readonly","readonly");
		});
	}
	//保存\申请
	function saveDeceitReason(deceitState){
		if($("#tblList2 tr").length==0){
			alert("请移入欺诈嫌疑描述！");
			return;
		}
		var bool=true;
		var alt="";
		if(deceitState=="1"){
			alt="保存";
		}else{
			alt="申请";
		}
		$("#deceitReasonBtn").removeAttr("onclick");
		var claimNo=$("#claimNo").val();
		var othDeceitDesc=$("#othDeceitDesc").val();
		var deceitMemo=$("#deceitMemo").val();
		var deceitReason="";
		var objId=$("#objId").val();
		var dataVal="";
		$("#tblList2 tr").each(function(i){
			var deceitType=$(this).find("td:eq(0)").find("input:eq(0)").val();
			var deceitReasonCode=$(this).find("td:eq(1)").find("input:eq(0)").val();
			deceitReason+='{"deceitType":"' + deceitType + '","deceitReasonCode":"' + deceitReasonCode+ '"},';
			if("99"==deceitType){
				if(othDeceitDesc==""){
					alert("其他欺诈嫌疑描述不能为空！");
					bool=false;
					$("#deceitReasonBtn").attr("onclick","saveDeceitReason("+deceitState+")");
					return ;
				}
				
				if(othDeceitDesc.length>200){
					alert("其他欺诈嫌疑不能大于200个字符！");
					bool=false;
					$("#deceitReasonBtn").attr("onclick","saveDeceitReason("+deceitState+")");
					return ;
				}
				if(deceitMemo.length>200){
					alert("备注不能大于200个字符！");
					bool=false;
					$("#deceitReasonBtn").attr("onclick","saveDeceitReason("+deceitState+")");
					return ;
				}
			}
		});
		if(!bool){
			return ;
		}
		deceitReason="["+deceitReason.substring(0,deceitReason.length-1)+"]";
		dataVal='{"deceitState":"'+deceitState+'","objId":"'+objId+'","claimNo":"' + claimNo + '","deceitOthDesc":"' + othDeceitDesc+ '","deceitMemo":"' + deceitMemo+ '","deceitReason":' + deceitReason+'}';
		$.ajax({
			type:"POST",
			url:"requestSaveDeceitReason.do",
			contentType:"application/json; charset=UTF-8",
			data:dataVal,
			success:function(data){
				$("#deceitReasonBtn").attr("onclick","saveDeceitReason("+deceitState+")");
				alert(alt+"欺诈信息成功！");
				if(objId=data.objId){
					$("#"+data.objId).remove();
				}
				$("#objId").val(objId);
				var applyDate=data.clmDeceitInfo[0].applyDate==null?"":jsonDateFormat(data.clmDeceitInfo[0].applyDate,10);
				var tr=$("<tr id="+data.objId+"><th><span class=\"radio_no\"  applyDate=\""+applyDate+"\" onclick=\"selectDeceitReasonInfo(this)\"><input type=\"hidden\" value='"+objId+"'/></span></th></tr>");
                var createDate=data.clmDeceitInfo[0].createDate;
                var feedbackDate=data.clmDeceitInfo[0].feedbackDate;
                var feedbackUser=data.clmDeceitInfo[0].feedbackUser==null?"":data.clmDeceitInfo[0].feedbackUser;
				var td=$("<td>录入日期："+jsonDateFormat(createDate,10)+"</td><td>申请日期："+applyDate+"</td>"); 
				$(tr).append(td);
				if(feedbackDate!=null && feedbackDate!=""){
					$(tr).append("<td>反馈日期： "+jsonDateFormat(feedbackDate,10)+"</td><td>调查员："+feedbackUser+"</td>");
				}
				
				
				$("#table_con").append(tr);
				if(deceitState=="2"){
					forwardHistoryPage();
				}
			},
			error:function(){
				$("#deceitReasonBtn").attr("onclick","saveDeceitReason("+deceitState+")");
				alert(alt+"欺诈信息失败！");
			}
		});
	}
	//选择查看
	function selectDeceitReasonInfo(flag){
		tbllist();
		
		$("#table_con tr").each(function(i) {
			$("#table_con tr").find("span").attr("class", "radio_no");
		});
		$(flag).attr("class", "radio_yes");
		$("#objId").val($(flag).find("input:eq(0)").val());
		$.ajax({
			type:"POST",
			url:"requestQueryDeceitReason.do",
			contentType:"application/json; charset=UTF-8",
			data:'{"objId":"'+$("#objId").val()+'"}',
			error:function(){
			},
			success:function(data){
				$("#othDeceitDesc").val(data.clmDeceitInfo[0].othDeceitDesc);
				$("#deceitMemo").val(data.clmDeceitInfo[0].deceitMemo);
				$("#feedbackContent").val(data.clmDeceitInfo[0].feedbackContent);
				for ( var i = 0; i <data.clmDeceitDetail.length; i++) {
					var type=data.clmDeceitDetail[i].deceitType;
					var code=data.clmDeceitDetail[i].deceitCode;
					index=$("#"+type+code).index();
					changeRight();
				}
			}
		});
		if(""==$(flag).attr("applyDate")){
			AddAttr();
		}else{
			RemoveAttr();
		}
	}
	function AddAttr(){
		$("#deceitReasonBtn").css("color","#007aff");
		$("#deceitReasonBtns").css("color","#007aff");
		$("#deceitReasonBtn").attr("onclick","saveDeceitReason(1)");
		$("#deceitReasonBtns").attr("onclick","saveDeceitReason(2)");
	}
	function RemoveAttr(){
		$("#deceitReasonBtn").css("color","#ccc");
		$("#deceitReasonBtns").css("color","#ccc");
		$("#deceitReasonBtn").removeAttr("onclick");
		$("#deceitReasonBtns").removeAttr("onclick");
	}
//	跳转至上一页
	function forwardHistoryPage(){
		skip2OtherPageByClaimNo('../humanaudit/humanAuditMain.do',$("#claimNo").val());
//		$("#formId").attr("action","humanAuditMain.do");
//		$("#formId").attr("method","POST");
//		$("#formId").submit();
	}
function forwardAdit(claimNo){
		SkipByPost("../auditinfo/showauditdetail.do",{claimNo:claimNo});
	}