var code = 9999; //在全局定义验证码 
var path = window.document.location.pathname;
var pathRoot = path.substring(0, path.substring(1).indexOf('/') + 1);//项目根路径
//姓名校验
var username_success = false;
//身份证号码校验（包括重复注册）
var certno_success = false;
//港澳居民来往内地通行证校验（包括重复注册）
var gajm_success = false;
//台湾居民来往大陆通行证校验（包括重复注册）
var twjm_success = false;
//身份证期限核验（校验格式）
var sfzqsqx_success = false;
var sfzjsqx_success = false;
//手机号校验 （包括重复性）
var phone_success=false;
//登录密码、确认密码校验
var pwd_success=false;

//开始时间结束事件，有效期失败
var timeErrorMap=new Map();

var qr_pwd_success=false;


var $registertype="sfz"
//根据身份证判断性别
function setGender(id) {
	var a = id.charAt(16);
	var b = id.charAt(2);
	if (Number(a) % 2 != 0) {
		$("input[type=radio][name=sex][value=M]").attr("checked", 'checked');
	} else {
		$("input[type=radio][name=sex][value=F]").attr("checked", 'checked');
	}
}

function onlyNum() {
	if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
		event.returnvalue = false;
}
function submitBtn(basePath) {
	if (!check_form(basePath)) {
		alert("请完善信息后再进行提交！");
		return false;
	}


	var grcityname = "";
	var grareaname = "";
	var grstreetname = "";
	var cityname = $("#city").find("option:selected").text();
	var countyname = $("#county").find("option:selected").text();
	var streetname = $("#street").find("option:selected").text();
	if (cityname == "--请选择--") {
		grcityname = "";
	} else {
		grcityname = cityname;
	}
	if (countyname == "--请选择--") {
		grareaname = "";
	} else {
		grareaname = countyname;
	}
	if (streetname == "--请选择--") {
		grstreetname = "";
	} else {
		grstreetname = streetname;
	}
	var res = confirm("确定要提交注册信息吗？");

	if (res == true) {
		var isSubmit = false;
		$.blockUI({ message: "<h1>正在提交注册信息，请稍候……</h1>" });
		$.ajax({
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			url: basePath + "/aip/v1/gov/person/register",
			type: "POST",
			data: JSON.stringify({
				"name": $("#person_name").val(), "sex": $("input[name='sex']:checked").val(), "certEffDate": $("#certEffDate").val(), "certExpDate": $("#certExpDate").val(),
				"idcard": $("#certificate_no").val(), "phone": $("#mobile_no").val(), "authLevel": "1", "user_name": $("#user_name").val(),
				"addr": $("#residence_address").val(), "email": $("#email").val(), "password": $("#password").val(), "userType": "1",
				"province": $("#city").val(), "city": $("#county").val(), "county": $("#street").val(), "code": $("#phone_code").val(),
				"provincename": grcityname, "cityname": grareaname, "countyname": grstreetname, "phone_code": $("#phone_code").val(), "CernoType": $("#certificateType").val()
			}),
			dataType: "json",
			async: false,
			success: function (msg) {
				if (msg.code != "200") {
					alert(msg.message, 3);
				} else {
					isSubmit = true;
				}
				$.unblockUI();
			},
			error: function () {
				isSubmit = false;
				$.unblockUI();
			}
		});
		if (isSubmit) {
			sumitval("1", basePath)
		}
	}



}

function sumitval(type, basePath) {
	var personname = $("#person_name").val();
	if (type == "1") {
		window.location.href = basePath + "/hnvirtualhall/register/jsp/realname_auth.jsp" +
			"?personname=" + escape(escape($("#person_name").val()))
			+ "&idcard=" + escape(escape($("#certificate_no").val()))
			+ "&userType=" + escape(escape("1"));
	} else if (type == "2") {
		alert("抱歉！注册失败。", 3);
	} else if (type == "3") {
		alert("抱歉！您注册的账户已存在，注册失败。", 3);
	} else {
		alert("抱歉！请检查您的输入与参数是否正确，注册失败。", 3);
	}
}

function reginfo() {
	$("#progressery").fadeIn();
	$(".pop_bg").fadeIn();
}

function cancel() {
	$("#progressery").fadeOut();
	$(".pop_bg").fadeOut();
}
function check_form(basePath) {

	if (check_agree() == false) {
		return false;
	}
	if (checkcertificateType() == false) {
		//document.getElementById('certificateType').focus();
		return false;
	}
	if (check_username(basePath) == false) {
		//document.getElementById('certificate_no').focus();
		return false;
	}
	
	if (check_certificate_legal(basePath) == false) {
		//document.getElementById('certificate_no').focus();
		return false;
	}
	
	if (check_sex() == false) {
		return false;
	}
	if (check_password() == false) {
		//document.getElementById('password').focus();
		return false;
	}
	if (check_same_password() == false) {
		//document.getElementById('same_password').focus();
		return false;
	}
	if (check_userchs(basePath) == false) {
		//document.getElementById('person_name').focus();
		return false;
	}
	if (checklegal('labuserchs', basePath) == false) {
		//document.getElementById('person_name').focus();
		return false;
	}
	if (check_user_name(basePath) == false) {
		//document.getElementById('user_name').focus();
		return false;
	}
	if (check_phone(basePath) == false) {
		//document.getElementById('mobile_no').focus();
		return false;
	}

	if (check_verifyCode(basePath) == false) {
		//document.getElementById('phone_code').focus();
		return false;
	}

	if (check_email() == false) {
		//document.getElementById('email').focus();
		return false;
	}
	if (check_city() == false) {
		//document.getElementById('city').focus();
		return false;
	}
	if (check_residence_address() == false) {
		//document.getElementById('residence_address').focus();
		return false;
	}



	return true;
}

function check_sex(basePath) {
	var sex = $('input:radio[name="sex"]:checked').val();
	if (sex == undefined) {
		return false;
	}
}

function check_verifyCode(basePath) {
	var code = $("#phone_code").val();
	if (code == "") {
		return false;
	}
}


function check_agree() {
	if ($('#agree').is(':checked')) {
		return true;
	} else {
		alert("您还未同意平台注册协议！", 1);
		return false;
	}
}

function checkcertificateType() {//验证证件类型
	var certificateType_type = $("#certificateType").val();
	if (certificateType_type == "idcard" || certificateType_type == "passport" || certificateType_type == "kongAocard") {
		if (certificateType_type == "passport") {
			$("#sfzhtml").html("<b>*</b>护照号码：");
			$("#labela").html("请填写您的护照号码");
		} else if (certificateType_type == "kongAocard") {
			$("#sfzhtml").html("<b>*</b>港澳通行证号：");
			$("#labela").html("请填写您的港澳通行证号");
		} else {
			$("#sfzhtml").html("<b>*</b>身份证号：");
			$("#labela").html("请填写您的第二代居民身份证号");

		}
		$("#certificateType_type").html("<font color='green'><b> √已选择证件类型。<b></font> ");
		return true;
	} else {
		$("#certificateType_type").html("<font color='red'><b> x请选择证件类型。<b></font> ");
		return false;
	}
}
function check_userchs() {
	//中文名check
	var userName = $("#userName").val().replace(/^\s+|\s+$/g, "");//去空格
	var reg=/^[a-zA-Z\u4e00-\u9fa5]+$/;
	if (userName.length < 1) {
		document.getElementById("userNametip").innerHTML = '<span class="cin1">请输入您的姓名。</span>';
		return false;
	} else if (!reg.test(userName) || userName.length < 2) {
		document.getElementById("userNametip").innerHTML = '<span class="cin1">请输入两位以上（含两位）合法的姓名。</span>';
		return false;
	} else {
		document.getElementById("userNametip").innerHTML = '<span class="rin1">您输入的姓名符合规范。</span>';
	}
	username_success=true;
	return true;
}

function check_user_name(basePath) {
	var regCode = /[`~!@#$%^&*()_+<>?:"{},.\/;'[\]|\|·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
	var regCN = /[\u4e00-\u9fa5]/;
	document.frm1.user_name.value = document.frm1.user_name.value.replace(/^\s+|\s+$/g, "");//去空格
	var user_name = document.frm1.user_name.value;
	if (user_name.length < 4) {
		document.getElementById("labuname").innerHTML = "<font color='red'><b>×用户名长度不能少于4位！<b></font>";
		return false;
	} else if (regCode.test(user_name) || regCN.test(user_name)) {
		document.getElementById("labuname").innerHTML = "<font color='red'><b> ×用户名中不能包含特殊字符和中文。<b></font>";
		return false;
	}
	if (document.frm1.user_name.value.length > 12 || document.frm1.user_name.value.length < 4) {
		document.getElementById("labuname").innerHTML = "<font color='red'><b> ×请至少输入4-12个字符。<b></font>";
		return false;
	} else {
		var isSuccess = true;
		$.blockUI({ message: "<h1>正在验证用户名，请稍候……</h1>" });
		$.ajax({
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			url: basePath + "/aip/v1/gov/person/check",
			type: "POST",
			data: JSON.stringify({ "workno": user_name }),
			success: function (msg) {
				msg = $.trim(msg);
				var obj = eval("(" + msg + ")");
				if (obj == false) {
					$("#labuname").html("<font color='red'><b> ×用户名已存在</b></font>");
					isSuccess = false;
				} else {
					$("#labuname").html("<font color='green'><b> √您输入的用户名符合规范。<b></font> ");
				}
				$.unblockUI();
			},
			error: function () {
				$.unblockUI();
			}
		});
		return isSuccess;
	}
}
function check_phone(basePath) {
	var mobile = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
	var shouji = $("#tel").val().replace(/^\s+|\s+$/g, "");
	if (shouji.length < 1) {
		document.getElementById("teltip").innerHTML = '<span class="cin1">请输入您的手机号码。</span>';
		$('#btnSendCode1').attr("disabled","disabled"); 
		return false;
	} else if (!mobile.test(shouji) && shouji.length > 0) {
		document.getElementById("teltip").innerHTML = '<span class="cin1">手机号码输入错误，请重新核对。</span>';
		$('#btnSendCode1').attr("disabled","disabled"); 
		return false;
	} else {
		//$.blockUI({message: "<h1>正在验证手机号，请稍候……</h1>"});
		$.ajax({
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			url: basePath + "/aip/v1/gov/person/check",
			type: "POST",
			data: JSON.stringify({ "phone": shouji }),
			success: function (msg) {
				msg = $.trim(msg);
				var obj = eval("(" + msg + ")");
				if (obj == false) {
					document.getElementById("teltip").innerHTML = '<span class="cin1">该手机号码已注册。</span>';
					phone_success = false;
					$('#btnSendCode1').attr("disabled","disabled"); 
				} else {
					document.getElementById("teltip").innerHTML = '<span class="rin1">您输入的手机号码符合规范。</span>';
					if (curCount1 == 0) {
						$("#btnSendCode1").removeAttr("disabled"); //启用按钮
					} 
					//$("#btnSendCode1").removeAttr("disabled"); 
					phone_success = true;
				}
				//$.unblockUI();
			},
			error: function () {
				document.getElementById("teltip").innerHTML = '<span class="gin1">验证手机号是否合法过程中发生错误，请稍后再试。</span>';
				phone_success = false;
				$('#btnSendCode1').attr("disabled","disabled"); 
				//$.unblockUI();
			}
		});
		return true;
	}
}

function check_yzm() {
	//验证码验证
	if ($("#phone_code").val().length < 1) {
		document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">请输入验证码。</span>';
		return false;
	} else{
		return true;
	}
}
function check_password() {
	//用户密码设置
	if ($("#dlpwd").val().length < 1) {
		document.getElementById("dlpwdtip").innerHTML = '<span class="cin1">请输入您的登录密码。</span>';
		return false;
	} 
	else if ($("#dlpwd").val().length > 0 && $("#dlpwd").val().length < 6) {
		document.getElementById("dlpwdtip").innerHTML = '<span class="cin1">请至少输入6-16个字符。</span>';
		return false;
	} 
	//验证密码，只能输入数字，字母，下划线。
	var validatePassword = /^[a-zA-Z0-9_]{6,16}$/;
	if (!validatePassword.test($("#dlpwd").val())) {
		document.getElementById("dlpwdtip").innerHTML = '<span class="cin1">密码由数字、下划线、字母组成。</span>';
		return false;
	} else {
		document.getElementById("dlpwdtip").innerHTML = '<span class="rin1">您输入的登录密码符合规范。</span>';
	}
	return true;
}

function check_zrryzm() {
	//法人注册验证码验证
	var yzm=$("#phone_code").val();
	var reg=/^[0-9]{6,6}$/;
	 if(!reg.test(yzm))
	{
		document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">短信验证码输入错误！</span>';
	}else
	{
		document.getElementById("dxyzmtip").innerHTML = '<span class="rin1">短信验证码输入正确！</span>';
	}	
}

function check_same_password() {
	//用户密码比较
	if ($("#qrpwd").val().length < 1) {
		document.getElementById("qrpwdtip").innerHTML = '<span class="cin1">请输入确认登录密码。</span>';
		pwd_success=false;
		qr_pwd_success=false;
		return false;
	} 
	else if ($("#qrpwd").val() != $("#dlpwd").val()) {
		document.getElementById("qrpwdtip").innerHTML = '<span class="cin1">您两次输入的密码不一致，请重新输入。</span>';
		pwd_success=false;
		qr_pwd_success=false;
		return false;
	}
	else {
		document.getElementById("qrpwdtip").innerHTML = '<span class="rin1">您输入的登录密码符合规范。</span>';
		pwd_success=true;
		qr_pwd_success=true;
	}
	return true;
}
function check_email() {
	//邮箱check
	document.frm1.email.value = document.frm1.email.value.replace(/^\s+|\s+$/g, "");//去空格
	if (document.frm1.email.value.length > 0) {
		if (isEmail(document.frm1.email.value) == false) {
			document.getElementById("labemail").innerHTML = "<font color='red'><b> ×您输入的电子邮箱无效。<b></font>";
			return false;
		} else {
			document.getElementById("labemail").innerHTML = "<font color='green'><b> √您输入的邮箱符合规范。<b></font>";
			return true;
		}
	} else {
		return true;
	}
}
function isEmail(strEmail) {
	if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
		return true;
	} else {
		return false;
	}
}
/* 
 * （验证地址格式：不能以数字、字母或者下划线开头）
 */
function check_city() {
	document.frm1.city.value = document.frm1.city.value.replace(/^\s+|\s+$/g, "");//去空格
	document.frm1.county.value = document.frm1.county.value.replace(/^\s+|\s+$/g, "");//去空格
	document.frm1.street.value = document.frm1.street.value.replace(/^\s+|\s+$/g, "");//去空格
	var objcity = document.frm1.city.value;
	var objcounty = document.frm1.county.value;
	var objstreet = document.frm1.street.value;
	if (objcity.length > 0) {
		if ((objcity.length > 0) && (objcounty.length > 0) && (objstreet.length > 0)) {
			document.getElementById("realadress").innerHTML = "<font color='green'><b> √您的地址符合规范。<b></font>";
			return true;
		} else {
			if (objcity == "810000" || objcity == "820000" || objcity == "710000") {
				document.getElementById("realadress").innerHTML = "<font color='green'><b> √您的地址符合规范。<b></font>";
			} else {
				document.getElementById("realadress").innerHTML = "<font color='red'><b> 请选择完整的联系地址。<b></font>";
				return false;
			}

		}
	} else {
		document.getElementById("realadress").innerHTML = "<font color='red'><b> ×请选择完整的联系地址。<b></font>。";
		return false;
	}
}
/* 
 * （验证地址格式：不能以数字、字母或者下划线开头）
 */
function check_residence_address() {
	var reg = /^[^\w]/;
	document.frm1.residence_address.value = document.frm1.residence_address.value.replace(/^\s+|\s+$/g, "");//去空格
	var obj = document.frm1.residence_address.value;
	if (obj.length > 0) {
		if (reg.test(obj)) {
			document.getElementById("aresidence_address_msg").innerHTML = "<font color='green'><b> √您输入的地址符合规范。<b></font>";
			return true;
		} else {
			document.getElementById("aresidence_address_msg").innerHTML = "<font color='red'><b> ×不能以数字、字母或者下划线开头。<b></font>";
			return false;
		}
	} else {
		document.getElementById("aresidence_address_msg").innerHTML = "<font color='red'><b> ×请填写居住地址。<b></font>";
		return false;
	}
}

function changecity(city, basePath) {
	$("#county").html("<option value=''>--请选择--</option>");
	$("#street").html("<option value=''>--请选择--</option>");
	$.blockUI({ message: "<h1>正在拼命加载区县数据，请稍候……</h1>" });
	$.ajax({
		type: "GET",
		url: basePath + "/aip/v1/gov/person/city?type=1&code=" + city,
		async: false,
		success: function (msg) {
			msg = $.trim(msg);//msg.json;
			$("#county").html(msg);
			$.unblockUI();
		},
		error: function () {
			$.unblockUI();
		}
	});
	//}
}
function changecounty(county, basePath) {
	$("#street").html("<option value=''>--请选择--</option>");
	$.blockUI({ message: "<h1>正在拼命加载乡镇街道数据，请稍候……</h1>" });
	$.ajax({
		type: "GET",
		url: basePath + "/aip/v1/gov/person/city?type=2&code=" + county,
		async: false,
		success: function (msg) {
			msg = $.trim(msg);//msg.json;
			$("#street").html(msg);
			$.unblockUI();
		},
		error: function () {
			$.unblockUI();
		}
	});
}

//汉字50个
function checksum(chars) {
	var sum = 0;
	for (var i = 0; i < chars.length; i++) {
		var c = chars.charCodeAt(i);
		if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
			sum++;
		}
		else {
			sum += 2;
		}
	}
	return sum;
}

function isCardNo(code) {

	// 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
	var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
	if (reg.test(code) === false) {
		//alert("身份证输入不合法");  
		return false;
	} else {
		if (code.length == 15) {
			code = cardfive(code);
		}
		//18位身份证需要验证最后一位校验位
		if (code.length == 18) {
			code = code.split('');
			//∑(ai×Wi)(mod 11)
			//加权因子
			var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
			//校验位
			var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
			var sum = 0;
			var ai = 0;
			var wi = 0;
			for (var i = 0; i < 17; i++) {
				ai = code[i];
				wi = factor[i];
				sum += ai * wi;
			}
			var last = parity[sum % 11];
			if (parity[sum % 11] != code[17]) {
				tip = "校验位错误";
				return false;
			}
			//注册的时候不需要性别
			//    if(code[16]%2==0){
			// 	   $("input[name='sex']").eq(1).prop("checked",true);
			//    }else{
			// 	   $("input[name='sex']").eq(0).prop("checked",true);
			//    }
		}

	}
	return true;
}
function cardfive(code) {
	var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
	var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
	var cardTemp = 0, i;
	code = code.substr(0, 6) + '19' + code.substr(6, code.length - 6);
	for (i = 0; i < 17; i++) {
		cardTemp += code.substr(i, 1) * arrInt[i];
	}
	code += arrCh[cardTemp % 11];
	return code;
}




function check_certificate_legal(basePath) {
	var kongAocardno = new RegExp("/^[HMhm]{1}([0-9]{10}|[0-9]{8})$/");//港澳通行证正则
	var passportno = new RegExp("/^1[45][0-9]{7}$|G[0-9]{8}$|P\.[0-9]{7}$|S[0-9]{7,8}$|D[0-9]{7,8}$/");//护照正则

	var filter_ga = /^[a-zA-Z0-9]{5,21}$/; //港澳通行证
	var filter_hz = /^[a-zA-Z0-9]{3,21}$/;  //护照

	//身份证注册类型
	if ($registertype == "sfz") {
		var certno = $("#certNo").val().replace(/^\s+|\s+$/g, "");//去空格
		$.ajax({
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			url: basePath + "/aip/v1/gov/person/idcard/check",
			type: "POST",
			data: JSON.stringify(
					{ 
						"idNumber": certno, 
						"name":	$("#userName").val()
					}),
			success: function (msg) {
				msg = $.trim(msg);
				var obj = eval("(" + msg + ")");
				if (obj == false) {
						document.getElementById("certNotip").innerHTML = '<span class="gin1">' + msg +'。</span>';	
					return false;
				} else {
					return true;
				}					
			},
			error: function () {
				document.getElementById("certNotip").innerHTML = '<span class="gin1">验证身份证是否合法过程中发生错误，请稍后再试。</span>';	
				return false;
			}
		});
	}
	//护照
	else if ($registertype == "hz") {
		var hz = $("#hzbh").val().replace(/^\s+|\s+$/g, "");//去空格
		$.ajax({
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			url: basePath + "/aip/v1/gov/person/certificate/check",
			type: "POST",
			data: JSON.stringify(
					{ 
						"idNumber": hz, 
						"idType": "414",
						"name":	$("#userName").val(),
						"nation": $("#gjcode").attr("value")
						
					}),
			success: function (msg) {
				msg = $.trim(msg);
				var obj = eval("(" + msg + ")");
				if (obj == false) {
						document.getElementById("hzbhtip").innerHTML = '<span class="gin1">' + msg +'。</span>';	
					return false;
				} else {
					return true;
				}					
			},
			error: function () {
				document.getElementById("hzbhtip").innerHTML = '<span class="gin1">验证护照是否合法过程中发生错误，请稍后再试。</span>';	
				return false;
			}
		});
		
	}
	//港澳通行证
	else if ($registertype == "gatxz") {
		var gatxz = $("#gatxzbh").val().replace(/^\s+|\s+$/g, "");//去空格
		$.ajax({
			headers: {
				'Accept': 'application/json',
				'Content-Type': 'application/json'
			},
			url: basePath + "/aip/v1/gov/person/certificate/check",
			type: "POST",
			data: JSON.stringify(
					{ 
						"idNumber": gatxz, 
						"idType": "517",
						"name":	$("#userName").val(),
						"nation": $("#gjcode").text()						
					}),
			success: function (msg) {
				msg = $.trim(msg);
				var obj = eval("(" + msg + ")");
				if (obj == false) {
						document.getElementById("gatxztip").innerHTML = '<span class="gin1">' + msg +'。</span>';	
					return false;
				} else {
					return true;
				}					
			},
			error: function () {
				document.getElementById("gatxztip").innerHTML = '<span class="gin1">验证港澳通行证是否合法过程中发生错误，请稍后再试。</span>';	
				return false;
			}
		});
	}
	
}
function checklegal(id, basePath) {
	var isSuccess = true;
	if (isSuccess) {
		if (id == "labuserchs") {
			var person_name = $("#person_name").val();
			if (person_name != "") {
				check_userchs(basePath);
			} else {
				return false;
			}

		} else {
			var card_no = $("#certificate_no").val();
			if (card_no != "") {
				check_username(basePath);
			} else {
				return false;
			}
		}
	}
	return isSuccess;
}



var timer;
var countdown = 60;//定义每格60秒可以重新获取一次验证码
function settime(basePath) {
	return setInterval(function () {
		if (countdown == 0) {
			$("#butyzm").css({ "background-color": "#e1f3ff" });
			$("#butyzm").css({ "background-color": "#1a60b6" });
			$("#butyzm").css({ "border": "1px solid #448aca" });
			$("#butyzm").css({ "cursor": "pointer" });
			$("#butyzm").attr("onclick", "submitYzm('" + basePath + "')");

			$("#dxyzmgs").val("1");
			$("#butyzm").html("获取验证码");
			countdown = 60;
			clearInterval(timer);
			timer === undefined;
			//		        return false;
		} else if (countdown == 60) {
			$("#butyzm").css({ "background-color": "grey" });
			$("#butyzm").css({ "color": "white" });
			$("#butyzm").css({ "border": "none" });
			$("#butyzm").css({ "cursor": "not-allowed" });
			$("#butyzm").attr("onclick", "");

			$("#dxyzmgs").val("2");
			$("#butyzm").html(countdown + "s重新发送");
			countdown--;
		} else {
			$("#butyzm").html(countdown + "s重新发送");
			countdown--;
		}
	}, 1000);
}

/**
 *获取短信验证码
 */
function submitYzm(basePath) {
	debugger;
	var bs = new Base64();
	var	mobile = bs.encode($("#tel").val());
	$.ajax({
		headers: {
			'Accept': 'application/json',
			'Content-Type': 'application/json'
		},
		type: "POST",
		url: basePath + "/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>';
				//$("#lxrsj").html("<em id='labshouji'><font color='red'><b> ×电话号码已注册</b></font></em>");
			}else if(msg == "短信发送繁忙，请稍后再试！"){
				document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">短信发送繁忙，请稍后再试！</span>';
			}  else {
				document.getElementById("dxyzmtip").innerHTML = '<span class="cin1">'+msg+'</span>';
			}

		},
		error: function (msg) {
			document.getElementById("dxyzmtip").innerHTML = '<span class="gin1">发送验证码过程中发生错误，请稍后再试。</span>';
			//alert(msg, 1);
		}
	});
}

/**
 * 判断是否是短信验证
 * @returns {Boolean}
 */
function isSMSValidate() {
	if ("Y" == $("#login_validate").val()) {
		return true;
	} else {
		return false;
	}
}

/**
 * 获取当前日期
 */
function getNowFormatDate() {
	var date = new Date();
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if (month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if (strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = year.toString()  + month.toString()  + strDate.toString();
	return currentdate;
}

/**
 * 开始日期校验
 * 
 */
function sfzksrqyz() {
	//开始日期
	var ksrq = $("#certEffDate").val().replace(/^\s+|\s+$/g, "");
	var reg = /^([\d]{4}(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-8])))))|((((([02468][048])|([13579][26]))00)|([0-9]{2}(([02468][048])|([13579][26]))))(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-9])))))$/;
	var currentDate= getNowFormatDate();
	if (ksrq.length != 8) {
		document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';
		sfzqsqx_success = false;
		timeErrorMap.set("start", "false");
		return;
	} else if (1900 > ksrq || ksrq > currentDate) {
		document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';
		sfzqsqx_success = false;
		timeErrorMap.set("start", "false");
		return;
	} else if (!reg.test(ksrq)) {
		document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';
		sfzqsqx_success = false;
		timeErrorMap.set("start", "false");
		return;
	} else {
		sfzqsqx_success = true;
		timeErrorMap.delete("start");
		if (timeErrorMap.size == 0) {
			document.getElementById("sfzqxtip").innerHTML = '<span class="rin1">日期格式正确。</span>';
		}
	}
	//结束日期
	var jsrq = $("#certExpDate").val().replace(/^\s+|\s+$/g, "");
	if (jsrq != "长期" && jsrq != "") {
		jsrq = parseInt(jsrq);
		ksrq = parseInt(ksrq);
		if (ksrq >= jsrq) {
			sfzqsqx_success = false;
			document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';
		}
	}
}

/**
 * 结束日期校验
 * 
 */
function sfzjsrqyz() {
	//结束日期
	var jsrq = $("#certExpDate").val().replace(/^\s+|\s+$/g, "");
	var reg = /^([\d]{4}(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-8])))))|((((([02468][048])|([13579][26]))00)|([0-9]{2}(([02468][048])|([13579][26]))))(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-9])))))$/;

	 if (jsrq=="长期") {
		sfzjsqx_success=true;
		timeErrorMap.delete("end");
		if(timeErrorMap.size == 0){
			document.getElementById("sfzqxtip").innerHTML = '<span class="rin1">日期格式正确。</span>';
		}
	}else if (jsrq.length != 8) {
		document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';
		sfzjsqx_success=false;
		timeErrorMap.set("end","false");
		return;
	} else if (!reg.test(jsrq)) {
		document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';
		sfzjsqx_success=false;
		timeErrorMap.set("end","false");
		return;
	}else{
		sfzjsqx_success=true;
		timeErrorMap.delete("end");
		if(timeErrorMap.size == 0){
			document.getElementById("sfzqxtip").innerHTML = '<span class="rin1">日期格式正确。</span>';
		}
	}
	//开始日期
	var ksrq = $("#certEffDate").val().replace(/^\s+|\s+$/g, "");
	if (jsrq != "长期"&&ksrq!="") {
		jsrq = parseInt(jsrq);
		ksrq = parseInt(ksrq);
		if (ksrq >= jsrq) {
			sfzjsqx_success=false;
			document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';
		}
	}
}

/**
 * 选择年限后根据开始日期计算结束日期
 * 
 */
function sfzqxkz(year) {
	//开始日期
	var ksrq=$("#certEffDate").val().replace(/^\s+|\s+$/g, "");
	var reg=  /^([\d]{4}(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-8])))))|((((([02468][048])|([13579][26]))00)|([0-9]{2}(([02468][048])|([13579][26]))))(((0[13578]|1[02])((0[1-9])|([12][0-9])|(3[01])))|(((0[469])|11)((0[1-9])|([12][0-9])|30))|(02((0[1-9])|(1[0-9])|(2[0-9])))))$/;
	
	if(ksrq.length!=8)
	{
		document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';	
	}else if(!reg.test(ksrq))
	{
		document.getElementById("sfzqxtip").innerHTML = '<span class="cin1">日期填写错误。</span>';	
	}else
	{
		document.getElementById("sfzqxtip").innerHTML = '<span class="rin1">日期填写正确。</span>';			
	}
	var nf=parseInt(ksrq.substring(0,4));
	var rq=ksrq.substring(4);
	if(year=="5")
	{
		$("#certExpDate").val(nf+5+rq);
	}else if(year=="10"){
		$("#certExpDate").val(nf+10+rq);
	}else if(year=="20"){
		$("#certExpDate").val(nf+20+rq);
	}else if(year=="长期"){
		$("#certExpDate").val("长期");
	}
}

$(function () {
	var oli = $(".plist li");
	$(".plist li").click(function () {
		if ($(this).hasClass("down")) {
			$(this).css("height", "");
			$(this).removeClass("down")
		} else {
			for (var i = 0; i < oli.length; i++) {
				$(".plist li").css("height", "");
				$(".plist li").removeClass("down")
			}
			$(this).css("height", "auto");
			$(this).addClass("down")
		}
	});
	//codes();
	// $("#VerifyCode1").on('click',codes);
	$(".right-nav-myfw").css("display", "none");

});
