var dangqian = 0;
$(function(){
	//分页
	 var kuandu= $(".sliding_main").width();
	 var page='';
	 var spac = $("#numberOfPageShow").val();
	 if(spac != undefined){
		 page=Math.ceil(parseFloat($("#numberOfElements").val())/spac);
	 }else{
		 page=Math.ceil(parseFloat($("#numberOfElements").val())/6);
	 }
	 if(page<=1){
		 $(".sliding_left").hide();
		 $(".sliding_right").hide();
		 $(".sliding_px").css("margin-right","6px");
	 }
	 $(".sliding_left").hide();
	 var total = kuandu*page;
	 $(".sliding_con").css({"width":total});
	 $(".sliding_blo").css({"float":"left","width":kuandu});
	 
	 $(".sliding_right").click(function(){
			$(".sliding_left").show();
			if(kuandu*(dangqian+1)<total){
				dangqian++;
				$(".sliding_con").animate({right:kuandu*dangqian});
				}
			if(dangqian==page-1){
				$(".sliding_right").hide();
				$(".sliding_px").css("margin-right","6px");
			}
			var noticeNo = $("#current_notice_no_" + dangqian).val();
			changeButonStyle(noticeNo);

			if ($(".check_yes") != undefined) {
				$(".check_yes").removeClass("check_yes").addClass("check_no"); 
				$("#applyConsult").val("N");
			}
	   });
		
		$(".sliding_left").click(function(){
			$(".sliding_right").show();
			$(".sliding_px").css("margin-right","-60px");
			if(dangqian>0){
				dangqian--;
				$(".sliding_con").animate({right:kuandu*dangqian});
			}
			if(dangqian==0){
				$(".sliding_left").hide();
			}
			var noticeNo = $("#current_notice_no_" + dangqian).val();
			changeButonStyle(noticeNo);

			if ($(".check_yes") != undefined) {
				$(".check_yes").removeClass("check_yes").addClass("check_no"); 
				$("#applyConsult").val("N");
			}
	   });
		
		$(".check_no,.check_yes").click(function(){		
			if($(this).is(".check_yes")){
				$(this).removeClass("check_yes");
				$(this).addClass("check_no"); 
				$("#applyConsult").val("N");			
			} else{
				$(this).removeClass("check_no");
				$(this).addClass("check_yes"); 
				$("#applyConsult").val("Y");
			}		
		});

	changeButonStyle($("#current_notice_no_" + dangqian).val());
	if ($("#noticeP0000005_accompany") != undefined) {
		if($("#noticeP0000005_accompany").val()==''||$("#noticeP0000005_accompany").val()==null||$("#noticeP0000005_accompany").val()==undefined){
			$("#noticeP0000005_accompany").val("本公司将由                      与您电话预约后陪同您前往进行复检。");
		}
	}
	if ($("#noticeP0000007_bigMoney") != undefined&&$("#noticeP0000007_payAmt").val()!=undefined) {
		$("#noticeP0000007_bigMoney").val(Chinese($("#noticeP0000007_payAmt").val()));
	}
	if ($("#noticeP0000008_chsPayAmt") != undefined&&$("#noticeP0000008_payAmt").val()!=undefined) {
		$("#noticeP0000008_chsPayAmt").val(Chinese($("#noticeP0000008_payAmt").val()));
	}
});

function changeButonStyle(noticeNo){
	//是否需发起协谈	通知书编码	通知书名称
	//否	P0000002	02停止收费通知书-初审
	//否	P0000003	03法务会签申请及回复表
	//否	P0000004	04补充资料通知书
	//否	P0000005	05体检通知书
	//是	P0000006	06理赔决定通知书-拒赔
	//是	P0000007	07通融给付协议书
	//是	P0000008	08和解给付协议书
	//是	P0000009	09理赔决定通知书-其他
	//否	P0000011	11撤案通知书
	if ("P0000006" == noticeNo || "P0000007" == noticeNo || "P0000008" == noticeNo || "P0000009" == noticeNo) {
		$(".check_yes,.check_no").unbind("click");
		$(".check_yes,.check_no").bind("click", function(){
			if($(this).is(".check_yes")){
				$(this).removeClass("check_yes");
				$(this).addClass("check_no"); 
				$("#applyConsult").val("N");
			} else{
				$(this).removeClass("check_no");
				$(this).addClass("check_yes"); 
				$("#applyConsult").val("Y");
			}
		});
		$(".bot_btn_02").css("color","#007aff");
		$(".bot_btn_02").attr("onclick","saveNoticeInfo('02');");
	} else {
		$(".check_yes").removeClass("check_yes").addClass("check_no");
		$(".check_yes,.check_no").unbind("click");
		$(".bot_btn_02").css("color","#ccc");
		$(".bot_btn_02").removeAttr("onclick");
	}	
	
}


function saveNoticeInfo(flag) {
	var noticeNo = $("#current_notice_no_" + dangqian).val();
	var applyConsult = $("#applyConsult").val();
	var claimNo = $("#notice_claimNo").val();
	var iscomplete=false;//未发起协谈，是否需要完成操作
	var isallrefused=$("#isallrefused").val();//是否全部为拒赔 的理赔结论
	//flag:01save\02complete
	if (flag == "02" && applyConsult != "Y" && isallrefused=="1" && noticeNo=="P0000006") {
		//alert("请确认一个通知单提交给协谈！ ");
		//return;
		if(!confirm("该赔案尚未发起协谈，是否需要完成？")){
			iscomplete=false;
			return;
		}
		else{
			iscomplete=true;	
		}		
	}
	if (flag == "02" && applyConsult != "Y" && isallrefused=="2"){
		alert("请确认一个通知单提交给协谈！ ");
		return;
	}
	
	//P0000002  02停止收费通知书-初审
	//P0000003  03法务会签申请及回复表
	//P0000004  04补充资料通知书
	//P0000005 05体检通知书
	
	//P0000006  06理赔决定通知书-拒赔
	//P0000007  07通融给付协议书
	//P0000008  08和解给付协议书
	//P0000009  09理赔决定通知书-其他
	//P0000011  11撤案通知书
	var paramsStr = "claimNo=" + claimNo + "&noticeNo=" + noticeNo + "&applyConsult=" + applyConsult + "&saveFlag=" + flag;
	var noticeName = "";
	
	if (noticeNo == "P0000006") {
		noticeName = "理赔决定通知书";
		var pringDate = $("#noticeP0000006_pringDate").val();
		var objId = $("#noticeP0000006_objId").val();
		var denying = $("#noticeP0000006_denying").val();
		var infoTel=$("#p0000006InfoTel").val();
		paramsStr += "&pringDate=" + pringDate;
		paramsStr += "&objId=" + objId;
		paramsStr += "&denying=" + denying;
		paramsStr += "&infoTel=" + infoTel;
	} else if (noticeNo == "P0000007") {
		noticeName = "通融给付协议书";
		var objId = $("#noticeP0000007_objId").val();
		var accDesc = $("#noticeP0000007_accDesc").val();
		var descriptions = $("#noticeP0000007_descriptions").val();
		var payAmt = $("#noticeP0000007_payAmt").val();

		paramsStr += "&objId=" + objId;
		paramsStr += "&accDesc=" + accDesc;
		paramsStr += "&descriptions=" + descriptions;
		paramsStr += "&payAmt=" + payAmt;
	} else if (noticeNo == "P0000008") {
		noticeName = "和解给付协议书";

		var objId=$("#noticeP0000008_objId").val();
		var applicantName = $("#noticeP0000008_applicantName").val();
		var applicantPid = $("#noticeP0000008_applicantPid").val();
		var accDesc = $("#noticeP0000008_accDesc").val();
		var payAmt = $("#noticeP0000008_payAmt").val();
		var chsPayAmt = $("#noticeP0000008_chsPayAmt").val();

		paramsStr += "&objId=" + objId;
		paramsStr += "&applicantName=" + applicantName;
		paramsStr += "&applicantPid=" + applicantPid;
		paramsStr += "&accDesc=" + accDesc;
		paramsStr += "&payAmt=" + payAmt;
		paramsStr += "&chsPayAmt=" + chsPayAmt;
	} else if (noticeNo == "P0000009") {
		noticeName = "理赔决定通知书";

		var objId = $("#noticeP0000009_objId").val();
		var reason = $("#noticeP0000009_reason").val();
		var describes = $("#noticeP0000009_describes").val();
		var printDate = $("#noticeP0000009_printDate").val();
		var infoTel=$("#p0000009InfoTel").val();
		paramsStr += "&objId=" + objId;
		paramsStr += "&reason=" + reason;
		paramsStr += "&describes=" + describes;
		paramsStr += "&printDate=" + printDate;
		paramsStr += "&infoTel=" + infoTel;
		
	} else if (noticeNo == "P0000011") {
		noticeName = "撤案通知书";
		var objId = $("#noticeP0000011_objId").val();
		var moveReasonDesc = $("#noticeP0000011_moveReasonDesc").val();
		var printDate = $("#noticeP0000011_printDate").val();
		var infoTel = $("#phoneNo").val();
		var accTypeName = $("#accTypeName").val();
		paramsStr += "&objId=" + objId;
		paramsStr += "&moveReasonDesc=" + moveReasonDesc;
		paramsStr += "&printDate=" + printDate;
		paramsStr += "&infoTel=" + infoTel;
		paramsStr += "&accTypeName=" + accTypeName;
	}
	
	
	$.ajax({
		type:"POST",
		url:"saveClaimNotice.do",
		data:paramsStr,
		async: false,
		error:function(){
			alert("系统错误，请稍后再试。");
		},
		success:function(data){
			if(data.successFlag=="Y"){
				alert(noticeName + "保存成功。");
				if (flag == "02" && applyConsult == "Y" ) {
					//跳转到协谈申请页面
					var params = new Array();
					params["claimNo"] = claimNo;
					SkipByPost("queryConsultApply.do", params);
				}if (iscomplete==true) {
					//不发起协谈跳转到人工审核主页面
					var params = new Array();
					params["claimNo"] = claimNo;
					SkipByPost("humanAuditMain.do", params);
				}
			}else{
				alert(noticeName + "保存失败。");
			}
		}
	});
	
}

//拼接中国格式时间
function formatDate() {    
  var now1 = new Date();
  var   year=now1.getYear(); 
  if(year<=1900){
  	year=year+1900;
  }
  var   month=now1.getMonth()+1;     
  var   date=now1.getDate();      
  var time =  year+"年"+month+"月"+date+"日";    
  return time;
}  
//数字转大写
function Chinese(num){     
    if(!/^\d*(\.\d*)?$/.test(num))throw(new Error(-1, "Number is wrong!"));     
    var AA = new Array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖");     
    var BB = new Array("","拾","佰","仟","萬","億","圆","");     
    var CC = new Array("角", "分", "厘");     
    var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";     
    for(var i=a[0].length-1; i>=0; i--){     
        switch(k){     
            case 0 : re = BB[7] + re; break;     
            case 4 : if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0]))     
                         re = BB[4] + re; break;     
            case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;     
        }     
        if(k%4 == 2 && a[0].charAt(i)=="0" && a[0].charAt(i+2) != "0") re = AA[0] + re;     
        if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;     
    }     
    if(a.length>1){     
        re += BB[6];     
        for(var i=0; i<a[1].length; i++){     
            re += AA[a[1].charAt(i)] + CC[i];     
            if(i==2) break;     
        }   
//        if(a[1].charAt(0)=="0" && a[1].charAt(1)=="0"){  
//          re+="圆整";  
//        }    
    }
    else{  
        re+="圆";  
    }     
    return re;     
} 

//数字输入控制并转成大写
function clearNoNum(obj,id){
  obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
  obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.  
  obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
  obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
  obj.value=obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数  
  $("#" + id).val('');
  $("#" + id).val(Chinese(obj.value));
}  


