$(function () {
	// 注册
	$('.xy-btn .a1').click(function () {
		$('.xy-show').hide();
	})
	$('.xy-show-con .title em').click(function () {
		$('.xy-show').hide();
	})

	//注册通用
	$('.hylb-box1 h6').click(function () {
		if ($('.hylb-1c1').css('display') == 'none') {
			$('.hylb-1c1').slideDown();
		} else {
			$('.hylb-1c1').hide();
		}
	})

	$('.hylb-box2 h6').click(function () {
		if ($('.hylb-1c2').css('display') == 'none') {
			$('.hylb-1c2').slideDown();
		} else {
			$('.hylb-1c2').hide();
		}
	})

	$('.hylb-1c1 span').each(function () {
		$(this).click(function () {
			$('.hylb-box1 h6 span').text($(this).text());
			$('.hylb-1c1').hide();
		})
	})

	$('.hylb-1c2 span').each(function () {
		$(this).click(function () {
			debugger;
			$('.hylb-box2 h6 span').text($(this).text());
			$('.hylb-box2 h6 span').attr("value",$(this).attr("value"));
			$('.hylb-1c2').hide();
		})
	})

	
	$('.hylb-1c4 span').each(function () {
		$(this).click(function () {
			debugger;
			$('.hylb-box4 h6 span').text($(this).text());
			$('.hylb-box4 h6 span').attr("value",$(this).attr("value"));
			$('.hylb-1c4').hide();
		})
	})
	$('.hylb-1c3 span').each(function () {
		$(this).click(function () {
			debugger;
			$('.hylb-box3 h6 span').text($(this).text());
			$('.hylb-box3 h6 span').attr("value",$(this).attr("value"));
			$('.hylb-1c3').hide();
		})
	})
   //性别
	$('.hylb-box4 h6').click(function () {
		if ($('.hylb-1c4').css('display') == 'none') {
			$('.hylb-1c4').slideDown();
		} else {
			$('.hylb-1c4').hide();
		}
	})
	$('.hylb-1c4 span').each(function () {
		$(this).click(function () {
			$('.hylb-box4 h6 span').text($(this).text());
			$('.hylb-1c4').hide();
		})
	})

	//法人类型
	$('.hylb-box3 h6').click(function () {
		if ($('.hylb-1c3').css('display') == 'none') {
			$('.hylb-1c3').slideDown();
		} else {
			$('.hylb-1c3').hide();
		}
	})
	$('.hylb-1c3 span').each(function () {
		$(this).click(function () {
			$('.hylb-box3 h6 span').text($(this).text());
			$('.hylb-1c3').hide();
		})
	})
	//鼠标移入span显示div
	$('.hylb-1c3 span').each(function () {
		$(this).mouseover(function () {
			$('.hylb-1c3').show();
		})
	})

	$('.hylb-1 span').each(function () {
		$(this).click(function () {
			debugger;
			if ($(this).text() == '港澳通行证') {
				$('.gjsh0').hide();
				$('.gjsh1').show();
				$('.gjsh3').show();
				$('.gjsh2').hide();
				$('.gjsh4').hide();
				$('.gjsh5').hide();
				$('.gjsh6').hide();
				$('.gjsh7').hide();
				$registertype = "gatxz";
			} else if ($(this).text() == '护照') {
				$('.gjsh2').show();
				$('.gjsh0').hide();
				$('.gjsh1').hide();
				$('.gjsh3').show();
				$('.gjsh4').hide();
				$('.gjsh5').hide();
				$('.gjsh6').hide();
				$('.gjsh7').hide();
				$registertype = "hz";
			} else if ($(this).text() == '身份证') {
				$('.gjsh0').show();
				$('.gjsh2').hide();
				$('.gjsh1').hide();
				$('.gjsh3').hide();
				$('.gjsh4').hide();
				$('.gjsh5').hide();
				$('.gjsh6').hide();
				$('.gjsh7').hide();
				$registertype = "sfz";
			}else if ($(this).text() == '港澳居民来往内地通行证') {
				$('.gjsh0').hide();
				$('.gjsh2').hide();
				$('.gjsh1').hide();
				$('.gjsh3').show();
				$('.gjsh4').show();
				$('.gjsh5').hide();
				$('.gjsh6').hide();
				$('.gjsh7').hide();
				$registertype = "gajm";
			}else if ($(this).text() == '台湾居民来往大陆通行证') {
				$('.gjsh0').hide();
				$('.gjsh2').hide();
				$('.gjsh1').hide();
				$('.gjsh3').show();
				$('.gjsh4').hide();
				$('.gjsh5').show();
				$('.gjsh6').hide();
				$('.gjsh7').hide();
				$registertype = "twjm";
			}else if ($(this).text() == '外国人永久居留身份证') {
				$('.gjsh0').hide();
				$('.gjsh2').hide();
				$('.gjsh1').hide();
				$('.gjsh3').show();
				$('.gjsh4').hide();
				$('.gjsh5').hide();
				$('.gjsh6').show();
				$('.gjsh7').hide();
				$registertype = "wgyjjlxk";
			}else if ($(this).text() == '外国人居留证或居留许可') {
				$('.gjsh0').hide();
				$('.gjsh2').hide();
				$('.gjsh1').hide();
				$('.gjsh3').show();
				$('.gjsh4').hide();
				$('.gjsh5').hide();
				$('.gjsh6').hide();
				$('.gjsh7').show();
				$registertype = "wgjlxk";
			}
		})
	})


	var onoff = true;
	$('.zck1 .eyes').click(function () {
		var oloK1 = $(this).parent().find('input');

		if (onoff) {
			//$(this).addClass('on');
			oloK1.attr('type', 'text');
			onoff = false;
		} else {
			//$(this).removeClass('on');
			oloK1.attr('type', 'password')
			onoff = true;
		}
	})
	//网络异常
	$('.crr-close em').click(function () {
		$('.webcrror').hide();
	})
	$('.right-cb1').click(function () {
		$('.webcrror').hide();
	})

	//法人注册
	$('.zck2 em').hover(function () {
		$('.zck2 p').show();
	}, function () {
		$('.zck2 p').hide();
	})
	//认证
	$('.face-rz1').click(function () {
		$('.face-cl1').show();
	})
	$('.face-close em').click(function () {
		$('.face-cl1').hide();
	})

	//找回密码
	$('.sjyzm-close em').click(function () {
		$('.sjyzm-box').hide();
	})
	$('.face-rz2').click(function () {
		$('.sjyzm-box').show();
	})

	var $registerState=false;

	//注册
	$('#zcbtn').click(function () {
		if (!$registerState)
		{
			$registerState=true;
		}else{
			return;
		}
		$("#zcbtn").css("display","none");
		$("#zczbtn").css("display","block");	
		var data = {};
		if ($registertype == "sfz") {
			//验证
			sfz_check_register();
			var zccode= getUrlSearch("code");
			if (!check_yzm()||!username_success || !certno_success ||!sfzqsqx_success || !sfzjsqx_success || !phone_success || !pwd_success||!qr_pwd_success) {
				$registerState=false;
				$("#zcbtn").css("display","block");
				$("#zczbtn").css("display","none");	
				return;
			}
			var sfzjssj= $("#certExpDate").val();
			if(sfzjssj=="长期")
			{
				sfzjssj="00000000"
			}
			data = {
				"name": $("#userName").val(), "idcard": $("#certNo").val(),
				"certEffDate": $("#certEffDate").val(), "certExpDate": sfzjssj,
				"phone": $("#phonecode").val(), "authLevel": "1",
				"password": $("#dlpwd").val(), "userType": "1",
				"code": $("#phone_code").val(),"sex":$('.hylb-box4 h6 span').attr("value"),
				"CernoType": "idcard","zccode":zccode
			};
		} else if ($registertype == "hz") {
			var nation =  $("#gjcode").attr("value");
			data = {
				"name": $("#userName").val(), "idcard": $("#hzbh").val(),
				"phone": $("#phonecode").val(), "authLevel": "1",
				"password": $("#dlpwd").val(), "userType": "1",
				"code": $("#phone_code").val(), "nation" : nation,"sex":$('.hylb-box4 h6 span').attr("value"),
				"CernoType": "passport"
			};
		} else if ($registertype == "gatxz") {
			var nation =  $("#gjcode").attr("value");
			data = {
				"name": $("#userName").val(), "idcard": $("#gatxzbh").val(),
				"phone": $("#phonecode").val(), "authLevel": "1",
				"password": $("#dlpwd").val(), "userType": "1","sex":$('.hylb-box4 h6 span').attr("value"),
				"code": $("#phone_code").val(), "nation" : nation,
				"CernoType": "kongAocard"
			};
		}else if ($registertype == "gajm") {
			//验证
			gajm_check_register();
			if (!check_yzm()||!username_success || !gajm_success || !phone_success || !pwd_success||!qr_pwd_success) {
				$registerState=false;
				return;
			}
			var nation =  $("#gjcode").attr("value");
			data = {
				"name": $("#userName").val(), "idcard": $("#gajmbh").val(),
				"phone": $("#phonecode").val(), "authLevel": "1",
				"password": $("#dlpwd").val(), "userType": "1",
				"code": $("#phone_code").val(), "nation" : nation,"sex":$('.hylb-box4 h6 span').attr("value"),
				"CernoType": "gajmcard"
			};
		}else if ($registertype == "twjm") {
			var nation =  $("#gjcode").attr("value");
			data = {
				"name": $("#userName").val(), "idcard": $("#twjmbh").val(),
				"phone": $("#phonecode").val(), "authLevel": "1",
				"password": $("#dlpwd").val(), "userType": "1",
				"code": $("#phone_code").val(), "nation" : nation,"sex":$('.hylb-box4 h6 span').attr("value"),
				"CernoType": "twjmcard"
			};
		}else if ($registertype == "wgyjjlxk") {
			var nation =  $("#gjcode").attr("value");
			data = {
				"name": $("#userName").val(), "idcard": $("#yjjlxkbh").val(),
				"phone": $("#phonecode").val(), "authLevel": "1",
				"password": $("#dlpwd").val(), "userType": "1",
				"code": $("#phone_code").val(), "nation" : nation,"sex":$('.hylb-box4 h6 span').attr("value"),
				"CernoType": "yjjlxkcard"
			};
		}else if ($registertype == "wgjlxk") {
			var nation =  $("#gjcode").attr("value");
			data = {
				"name": $("#userName").val(), "idcard": $("#jlxkbh").val(),
				"phone": $("#phonecode").val(), "authLevel": "1",
				"password": $("#dlpwd").val(), "userType": "1","deviceType":"PC","dataSource":"H000",
				"code": $("#phone_code").val(), "nation" : nation,"sex":$('.hylb-box4 h6 span').attr("value"),
				"CernoType": "jlxkcard"
			};
		}
		

		$.ajax({
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			url: window.location.origin + "/reg",
			type: "POST",
			data: JSON.stringify(data),
			dataType: "json",
			async: false,
			success: function (msg) {
				if (msg.code == "200") {
					if ($registertype == "sfz") {
						var href=window.location.origin 
						+ "/regok"
						+ $("#certNo").val() 
						+ "&type=" + $('.hylb-box1 h6 span').text() 
						+ "&phone=" + $("#phonecode").val()+"&name="+$("#userName").val();
						var backUrl = getUrlSearch("backUrl");
						if (backUrl != null && backUrl != "") {
							href = href + "&backUrl=" + backUrl;
						}
						window.location.href = href;
					} else if ($registertype == "hz") {
						var href=href = window.location.origin 
						+ "/regok" 
						+ $("#hzbh").val() + "&type=" + $('.hylb-box1 h6 span').text();
						var backUrl = getUrlSearch("backUrl");
						if (backUrl != null && backUrl != "") {
							href = href + "&backUrl=" + backUrl;
						}
						window.location.href = href;
					} else if ($registertype == "gatxz") {
						var href = window.location.origin 
						+ "/regok" 
						+ $("#gatxzbh").val() + "&type=" + $('.hylb-box1 h6 span').text();
						var backUrl = getUrlSearch("backUrl");
						if (backUrl != null && backUrl != "") {
							href = href + "&backUrl=" + backUrl;
						}
						window.location.href = href;
					}
					else if ($registertype == "twjm") {
						var href = window.location.origin 
						+ "/regok" 
						+ $("#twjmbh").val() + "&type=" + $('.hylb-box1 h6 span').text();
						var backUrl = getUrlSearch("backUrl");
						if (backUrl != null && backUrl != "") {
							href = href + "&backUrl=" + backUrl;
						}
						window.location.href = href;
					}
					else if ($registertype == "gajm") {
						var href = window.location.origin 
						+ "/regok" 
						+ $("#gajmbh").val() + "&type=" + $('.hylb-box1 h6 span').text();
						var backUrl = getUrlSearch("backUrl");
						if (backUrl != null && backUrl != "") {
							href = href + "&backUrl=" + backUrl;
						}
						window.location.href = href;
					}
				} else {
					$("#zcbtn").css("display","block");
					$("#zczbtn").css("display","none");	
					$registerState=false;
					alert(msg.message, 3);
				}
			},
			error: function () {
				$("#zcbtn").css("display","block");
				$("#zczbtn").css("display","none");	
				$registerState=false;
				alert(msg.message, 3);
			}
		});
		debugger;
	})
	// //注册
	// $('.zcpbtn').click(function () {
		
	// 	debugger;
	// })
	//姓名输入框失焦事件
	$("#userName").blur(function () {
		check_userchs();
	})
	//身份证输入框失焦事件
	$("#certNo").blur(function () {
		check_username(window.location.origin);
	})
	//护照输入框失焦事件
	$("#hzbh").blur(function () {
		check_username(window.location.origin);
	})
	//港澳居民来往内地通行证输入框失焦事件
	$("#gajmbh").blur(function () {
		check_username(window.location.origin);
	})
	//台湾居民来往大陆通行证输入框失焦事件
	$("#twjmbh").blur(function () {
		check_username(window.location.origin);
	})
	
	//港澳通行证输入框失焦事件
	$("#gatxzbh").blur(function () {
		check_username(window.location.origin);
	})
	//手机号输入框失焦事件
	$("#phonecode").blur(function () {
		check_phone(window.location.origin);
	})
	//登录密码输入框失焦事件
	$("#dlpwd").blur(function () {
		check_password();
	})
	//法人验证码输入框失焦事件
	$("#legalphonecode").blur(function () {
		check_fryzm();
	})
	//自然人验证码输入框失焦事件
	$("#phone_code").blur(function () {
		check_zrryzm();
	})	
	//开始日期输入框失焦事件
	$("#certEffDate").blur(function () {
		sfzksrqyz();
	})
	//结束日期输入框失焦事件
	$("#certExpDate").blur(function () {
		sfzjsrqyz();
	})
	//确认密码输入框失焦事件
	$("#qrpwd").blur(function () {
		check_same_password();
	})
	//关闭激活国家政务服务提示
	$("#gbjh").click(function () {
		$("#gjzhjhtip").css("display", "none");
	})
	//个人注册
	$('#naturalRegisterBtn').click(function () {
		$('.xy-show').show();
		$zctype="natural";
	})	
	//企业注册
	$('#legalRegisterBtn').click(function () {
		$('.xy-show').show();
		$zctype="legal";
	})
	//继续完成注册
	$('#tybjxbtn').click(function () {
		if ($zctype == "legal") {
			//跳转到法人注册界面
			var href = window.location.origin + "/regok";
			var backUrl = getUrlSearch("backUrl");
			if (backUrl != null && backUrl != "") {
				href = href + "?backUrl=" + backUrl;
			}
			window.location.href = href;
		} else {
			//跳转到自然人注册界面
			var href = window.location.origin + "/regok";
			var backUrl = getUrlSearch("backUrl");
			if (backUrl != null && backUrl != "") {
				href = href + "?backUrl=" + backUrl;
			}
			window.location.href = href;
		}
	})
	//信用代码输入框失焦事件
	$("#socialCreditNo").blur(function(){
		check_social_credit();		
	})
	//法定代表人输入框失焦事件
	$("#corporator").blur(function(){
		check_corporator();
	})
	
	//身份证号码校验及查询电话号码
	$("#idCard").blur(function(){
		if(isCardNo()){
			//realNameCheck(window.location.origin);
			searchNaturalWithIdCard(window.location.origin);
		}
	})

	//法人手机号码验证
	$("#legalphone").blur(function(){
		check_legalPhone(window.location.origin);
	})
	
	//法人发送短信验证码
	$("#btnSendSmsCode").click(function(){
		sendSmsMessage(window.location.origin);
	})
	//法人创建按钮
	$("#legalCommit").click(function(){
		submitLegalData(window.location.origin);
	})
	
	
	$(".hylb-1c3").mouseout(function (){  
		$(".hylb-1c3").hide();  
	}); 
})

//兼容IE低版本location.origin
if (window["context"] == undefined) {
    if (!window.location.origin) {
        window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
    }
    window["context"] = location.origin+"/V6.0";
}

function smscheck()
	{
		var data = {};
		if ($registertype == "sfz") {
			//验证
			//姓名
			check_userchs();
			//身份证号码
			if (!certno_success) {
				check_username(window.location.origin);
			}
			//身份证期限
			sfzjsrqyz();
			sfzksrqyz();
			//手机号
			if (!phone_success) {
				check_phone(window.location.origin);
			}
			if (!username_success || !certno_success ||!sfzqsqx_success || !sfzjsqx_success || !phone_success ) {
				return false;
			}else{
				return true;
			}

		} else  {
			check_userchs();
			//身份证号码
			if (!certno_success) {
				check_username(window.location.origin);
			}
			if (!username_success  || !phone_success ) {
				return false;
			}else{
				return true;
			}
		} 			
	}
//发送验证码
var count = 60; //间隔函数，1秒执行
var smscount2 = 0; //发送验证码次数
var InterValObj1; //timer变量，控制时间
var InterValObj2; //timer变量，控制时间
var curCount1=0; //当前剩余秒数
var curCount2=0; //当前剩余秒数
function sendMessage1() {
	if(!smscheck())
	{
		return;
	}
	if(smscount2>2)
	{
		count=300;
	}
	curCount1 = count;
	//设置button效果，开始计时
	$("#btnSendCode1").attr("disabled", "true");
	$("#btnSendCode1").val(+curCount1 + "秒再获取");
	InterValObj1 = window.setInterval(SetRemainTime1, 1000); //启动计时器，1秒执行一次
	//向后台发送处理数据
	//由AES进行加密电话号码	
	var phoneCodeByAes = encrypted($("#phonecode").val());
	var bs = new Base64();
	var	mobile = bs.encode(phoneCodeByAes);
	
	//var bs = new Base64();
	//var	mobile = bs.encode($("#phonecode").val());
	$.ajax({
		headers : {
			'Accept' : 'application/json',
			'Content-Type' : 'application/json'
		},
		type:"POST",
		url:window.location.origin+"/aip/v1/gov/person/sms",
		data:JSON.stringify({"mobile":mobile,"register":true}),
		contentType:"application/json;charset=utf-8",
		dataType: "text",
		success:function(msg){
			msg = $.trim(msg);
			if(msg == "电话号码已被注册"){
				document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">电话号码已注册。</span>';
			}else if(msg == "短信发送繁忙，请稍后再试！"){
				document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">短信发送繁忙，请稍后再试！</span>';
			}
			else if (msg == "短信发送成功"){
				smscount2+=1;
				document.getElementById("dxyzmtip").innerHTML = '<span class="rin1">'+msg+'</span>';
			}	else {
				document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">'+msg+'</span>';
			}		
		},
		error : function(msg){
			document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">发送短信过程中发送错误，请联系管理员。</span>';
		}
	});
}

function sendMessage2() {
	//禁用button
	$("#btnSendCode2").attr("disabled", "true");
	//向后台发送处理数据
	$.ajax({
		headers : {
			'Accept' : 'application/json',
			'Content-Type' : 'application/json'
		},
		type:"POST",
		url: window.location.origin + "/aip/v1/gov/person/send/sms",
		data: JSON.stringify({ "mobile": $jhsjh }),
		contentType: "application/json;charset=utf-8",
		success: function (data) {
			debugger;			
			var msg = $.trim(data.msg);
			if (msg == "短信发送成功") {
				curCount2 = count;		
				//开始计时		
				$("#btnSendCode2").val(+curCount2 + "秒再获取");
				InterValObj2 = window.setInterval(SetRemainTime2, 1000); //启动计时器，1秒执行一次
			} else {
				alert(data.msg, 3);
				//禁用button
				$("#btnSendCode2").removeAttr("disabled"); //启用按钮
				$("#btnSendCode2").val("重新发送");
				//发送失败后处理
				//document.getElementById("dxyzmtip").innerHTML = '<span class="rin1">'+msg+'</span>';
			}			
		},
		error : function(data){
			alert("发送短信过程中发送错误，请联系管理员。", 3);
			$("#btnSendCode2").removeAttr("disabled"); //启用按钮
			$("#btnSendCode2").val("重新发送");
			debugger;
			//document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">发送短信过程中发送错误，请联系管理员。</span>';
		}
	});

}

function SetRemainTime2() {
	if (curCount2 == 0) {
		window.clearInterval(InterValObj2); //停止计时器
		$("#btnSendCode2").removeAttr("disabled"); //启用按钮
		$("#btnSendCode2").val("重新发送");
	} else {
		curCount2--;
		$("#btnSendCode2").val(+curCount2 + "秒再获取");
	}
}

function SetRemainTime1() {
	if (curCount1 == 0) {
		window.clearInterval(InterValObj1); //停止计时器
		$("#btnSendCode1").removeAttr("disabled"); //启用按钮
		$("#btnSendCode1").val("重新发送");
	} else {
		curCount1--;
		$("#btnSendCode1").val(+curCount1 + "秒再获取");
	}
}

$(".passLvl").keyup(function () {
	var password = $(this).val();
	// var strong = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*])[\da-zA-Z~!@#$%^&*]{6,}$/;
	var pwdReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/;
	var modes = 0;
	for (i = 0; i < password.length; i++) {
		//测试每一个字符的类别并统计一共有多少种模式
		modes |= charMode(password.charCodeAt(i));
	}
	var level = bitTotal(modes);
	console.log(level)
	if (!pwdReg.test(password)) {
		$(".slevel").children().removeAttr("class").addClass('ruo');
	} else {
		if (level === 3) {
			$(".slevel").children().removeAttr("class").addClass('gao');
		} else if (level === 2) {
			$(".slevel").children().removeAttr("class").addClass('mid');
		}
	}

});
//计算出当前密码当中一共有多少种模式
function bitTotal(num) {
	var modes = 0;
	for (i = 0; i < 4; i++) {
		if (num & 1) {
			modes++;
		}
		num >>>= 1;
	}
	return modes;
}
function charMode(ch) {//测试某个字符是属于哪一类
	if (ch >= 48 && ch <= 57) { //数字
		return 1;
	}
	else if (ch >= 65 && ch <= 90) { //大写字母
		return 2;
	}
	else if (ch >= 97 && ch <= 122) { //小写
		return 4;
	}
	else {	//特殊字符
		return 8;
	}
}

function fhdl() {
	//href="http://zwfw-new.hunan.gov.cn"
	var backUrl = getUrlSearch("backUrl");
	if (backUrl != null && backUrl != "") {
		window.location.href = backUrl;
	} else {
		window.location.href = "/regok";
	}
}

function getUrlSearch(name) {
	// 未传参，返回空
	if (!name) return null;
	// 查询参数：先通过search取值，如果取不到就通过hash来取
	var after = window.location.search;
	after = after.substr(1) || window.location.hash.split('?')[1];
	// 地址栏URL没有查询参数，返回空
	if (!after) return null;
	// 如果查询参数中没有"name"，返回空
	if (after.indexOf(name) === -1) return null;

	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
	// 当地址栏参数存在中文时，需要解码，不然会乱码
	var r = decodeURI(after).match(reg);
	// 如果url中"name"没有值，返回空
	if (!r) return null;

	return r[2];
}

function jhgjzh() {
	debugger;
	var certNo = getUrlSearch("certno");
	var data = {
		"certNo": certNo
	};
	//调用国家账号激活接口
	$.ajax({
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json'
		},
		url: window.location.origin + "/aip/v1/gov/useractivebycertno",
		type: "POST",
		data: JSON.stringify(data),
		dataType: "json",
		async: false,
		success: function (msg) {
			if (msg.code == "90000") {
				$("#gjzhjhtip").css("display", "none");
				$("#jhcgtip").css("display", "block");
				setTimeout(function(){
					$("#jhcgtip").css("display", "none");
				}, 3000);
			} else if (msg.code == "90098") {
				$("#gjzhjhtip").css("display", "none");
				$("#yhyjhtip").css("display", "block");
				setTimeout(function(){
					$("#yhyjhtip").css("display", "none");
				}, 3000);
			} else {
				$("#gjzhjhtip").css("display", "none");
				$("#xtfmtip").css("display", "block");
				setTimeout(function(){
					$("#xtfmtip").css("display", "none");
				}, 3000);
			}
		},
		error: function () {
			$("#gjzhjhtip").css("display", "none");
			$("#xtfmtip").css("display", "block");
			setTimeout(function(){
				$("#xtfmtip").css("display", "none");
			}, 3000);
		}
	});
}

function sfz_check_register() {
	//姓名
	check_userchs();
	//身份证号码
	if (!certno_success) {
		check_username(window.location.origin);
	}
	//身份证期限
	sfzjsrqyz();
	sfzksrqyz();
	//手机号
	if (!phone_success) {
		check_phone(window.location.origin);
	}
	//密码校验
	check_password();
	check_same_password();
	//验证码校验
	check_yzm();
}

function gajm_check_register() {
	//姓名
	check_userchs();
	//身份证号码
	if (!certno_success) {
		check_username(window.location.origin);
	}
	//手机号
	if (!phone_success) {
		check_phone(window.location.origin);
	}
	//密码校验
	check_password();
	check_same_password();
	//验证码校验
	check_yzm();
}


        /*
         * 身份证15位编码规则：dddddd yymmdd xx p
         * dddddd：6位地区编码
         * yymmdd: 出生年(两位年)月日，如：910215
         * xx: 顺序编码，系统产生，无法确定
         * p: 性别，奇数为男，偶数为女
         *
         * 身份证18位编码规则：dddddd yyyymmdd xxx y
         * dddddd：6位地区编码
         * yyyymmdd: 出生年(四位年)月日，如：19910215
         * xxx：顺序编码，系统产生，无法确定，奇数为男，偶数为女
         * y: 校验码，该位数值可通过前17位计算获得
         *
         * 前17位号码加权因子为 Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]
         * 验证位 Y = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ]
         * 如果验证码恰好是10，为了保证身份证是十八位，那么第十八位将用X来代替
         * 校验位计算公式：Y_P = mod( ∑(Ai×Wi),11 )
         * i为身份证号码1...17 位; Y_P为校验码Y所在校验码数组位置
        */
	   function validateIdCard(idCard){
		//15位和18位身份证号码的正则表达式
		var regIdCard=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;

		//如果通过该验证，说明身份证格式正确，但准确性还需计算
		if(regIdCard.test(idCard)){
			if(idCard.length==18){
				var idCardWi=new Array( 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ); //将前17位加权因子保存在数组里
				var idCardY=new Array( 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ); //这是除以11后，可能产生的11位余数、验证码，也保存成数组
				var idCardWiSum=0; //用来保存前17位各自乖以加权因子后的总和
				for(var i=0;i<17;i++){
					idCardWiSum+=idCard.substring(i,i+1)*idCardWi[i];
				}
				var idCardMod=idCardWiSum%11;//计算出校验码所在数组的位置
				var idCardLast=idCard.substring(17);//得到最后一位身份证号码
				//如果等于2，则说明校验码是10，身份证号码最后一位应该是X
				if(idCardMod==2){
					if(idCardLast=="X"||idCardLast=="x"){
						return true;
					}else{
						return false;
					}
				}else{
					//用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
					if(idCardLast==idCardY[idCardMod]){
						return true;
					}else{
						return false;
					}
				}
			}
		}else{
			return false;
		}
	}