//# 邮件地址正则
//var regEmail = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
//
//# 检验mail
//function checkmail(){
//
//	var email=document.getElementById("mail").value;
//
//	# Email 合法性
//	flag=regEmail.test(email);
//
//	if(!flag){
//
//		document.getElementById("regmail").innerHTML = "<div class=\"Error\">邮箱非标准格式，请确认后重新输入！</div>";
//
//		# 返回值设定
//		return false;
//
//	}else{
//		# 输入正确
//		document.getElementById("regmail").innerHTML = "<div class=\"reg_next\">欢迎您加入立刻保！</div>";
//
//		# 返回值设定
//		return true;
//
//	}
//
//
//}
//
//function checkfistpassword(){
//	var aa=document.getElementById("password1");
//	var pw=aa.value;	
//	if(pw.length<6){
//		document.getElementById("reg_ps").innerHTML = '<div class="Error">密码由6-16个英文字母加数字或符号的字符组成</div>';
//		aa.focus();
//		return false;
//	}else{
//		document.getElementById("reg_ps").innerHTML = "<div class=\"reg_next\">&nbsp;</div>";
//		return true;
//	}
//}
////# 校验密码
//
//function checkpassword(){
//
//	var pw1=document.getElementById("password1").value;
//	var pw2=document.getElementById("password2").value;
//
//	if(pw1 != pw2){
//		//# 设置焦点
//		document.getElementById("regpass").innerHTML = "<div class=\"Error\">您两次输入的密码不一致，请再次确认！</div>";
//
//		//# 返回值设定
//		return false;
//
//	}else{
//		if(isNull(pw1)){
//			document.getElementById("regpass").innerHTML = "<div class=\"Error\">密码不能为空！</div>";
//
//			//# 返回值设定
//			return false;
//		}
//
//		document.getElementById("reg_ps").innerHTML = "";
//		document.getElementById("regpass").innerHTML = "";
//		document.getElementById("Submit").disabled = false;
//
//		//# 返回值设定
//		return true;
//	}
//
//
//}
//
////# 校验空值
//function isNull(str){
//
//	if(str == ""){
//		//# 返回值设定
//		return true;
//	}else{
//		return false;
//	}
//
//}
//
//
//function funcChecktoSubmit(){
//
//	with(document.reg){
//
//		for(i=0;i<elements.length;i++) {
//			switch(elements[i].name) {
				//# ----------------
				//# 邮箱校验
				//# ----------------
//				case "mail":
//				if(!funcNullCheck(elements[i],"邮箱不能为空",true)){
//					return false;
//				}
//				if(!funcLengthCheckValue(elements[i],255,"邮箱长度不能超过255个字符")){
//					return false;
//				}
//				if(!funcMailFormatCheck(elements[i],true)){
//					return false;
//				}
//				break;
//				# ----------------
//				# 身份证校验
//				# ----------------
//				case "roc_id":
//				if(!funcNullCheck(elements[i],"身份证不能为空",true)){
//					return false;
//				}
//				if(!funcLengthCheckValue(elements[i],18,"身份证长度为18位或15位")){
//					return false;
//				}
//				if(!funcMinLengthCheckValue(elements[i],15,"身份证长度为18位或15位",true)){
//					return false;
//				}
// 			
//
//				break;
//				# ----------------
//				# 密码校验
//				# ----------------
//				case "password1":
//				if(!funcNullCheck(elements[i],"密码不能为空",true)){
//					return false;
//				}
//				if(!funcLengthCheckValue(elements[i],16,"密码长度不能超过16个字符",true)){
//					return false;
//				}
//				if(!funcMinLengthCheckValue(elements[i],6,"密码长度不能小于6个字符",true)){
//					return false;
//				}
//				break;
//				# ----------------
//				# 密码校验
//				# ----------------
//				case "password2":
//				if(!funcNullCheck(elements[i],"密码不能为空",true)){
//					return false;
//				}
//				if(!funcLengthCheckValue(elements[i],16,"密码长度不能超过16个字符",true)){
//					return false;
//				}
//				if(!funcMinLengthCheckValue(elements[i],6,"密码长度不能小于6个字符",true)){
//					return false;
//				}
//				break;
//			}
//		}
//
//
//	}
//	return true;
//}



$(document).ready(function(){
	$.formValidator.initConfig({onError:function(msg){alert(msg)}});
	$("#roc_id").formValidator({onshow:"请输入您的证件号码作为用户名",onfocus:"",oncorrect:"欢迎加入立刻贷",onempty:"证件号码不能为空"});
	$("#password1").formValidator({onshow:"密码由6-15个英文字母加数字或符号的字符组成",onfocus:"密码由6-15个英文字母加数字或符号的字符组成",oncorrect:"密码合法"}).InputValidator({min:6,max:15,onerror:"密码由6-15个英文字母加数字或符号的字符组成"});
	$("#password2").formValidator({onshow:"请再一次输入密码",onfocus:"两次密码必须一致",oncorrect:"密码一致"}).InputValidator({min:6,max:15,onerror:"密码由6-15个英文字母加数字或符号的字符组成"}).CompareValidator({desID:"password1",operateor:"=",onerror:"2次密码不一致,请确认"});
	$("#read").formValidator({onshow:"",onfocus:"请仔细阅读服务条款",oncorrect:""}).InputValidator({min:1,onerror:"请仔细阅读服务条款"});
	
    $("#roc_id").blur(function(){  
    	
    	var rocidval  = $('#roc_id').val();
    	rocidval      = ToSbcCase(rocidval); 
    	$('#roc_id').val(rocidval);
   
    });	
	
});


var regpassport = /^[A-Z\d]{7,9}$/ ;
var regjunguan  = /^[A-Z\d]{6}$/ ;
var regcompany  = /^[\w\d]{6,}$/ ;

function checkform(){
	if($.formValidator.PageIsValid('1')){
//		if(allEmpty()){
//			//是否有证件类型
//			if(null == document.getElementById("id_type")){
//				return true;
//			}else{
//				if(checkid()){
//					return true;
//				}else{
//					return false;
//				}			
//			}
//		}else{
//			return false;
//		}
		if(checkid()){
			return true;
		}else{
			return false;
		}			
	}else{
		return false;
	}
}

function checkid(){
	
	var type = $('#id_type').val();
	var id   = $('#roc_id').val();
	var flag;
	if(type == "0"){
		flag = regcompany.test(id);
		if(!flag){
			alert("您的组织机构代码证编号有误");
			$("#roc_id").select();
			$("#roc_id")[0].scrollIntoView();
			return false;
		}
		return true;
	}
	
	if(type == "1"){
		if(isCardID(id) == true){
			return true;
		}else{
			alert(isCardID(id));
			$("#roc_id").select();
			$("#roc_id")[0].scrollIntoView();
			return false;
		}
	}
	
	if(type == "2"){
		flag = regpassport.test(id);
		if(!flag){
			alert("您的护照格式有误");
			$("#roc_id").select();
			$("#roc_id")[0].scrollIntoView();
			return false;
		}
		return true;
	}
	
	if(type == "3"){
		flag = regjunguan.test(id);
		if(!flag){
			alert("您的军官证格式有误");
			$("#roc_id").select();
			$("#roc_id")[0].scrollIntoView();
			return false;
		}
		return true;
	}
	return true;
	
}

// 全角转换为半角函数
function ToSbcCase(str) { 
 var tmp = ""; 
 for(var i=0;i<str.length;i++) { 
	 if(str.charCodeAt(i)>65248&&str.charCodeAt(i)<65375) { 
	    tmp += String.fromCharCode(str.charCodeAt(i)-65248); 
	 } else { 
	    tmp += String.fromCharCode(str.charCodeAt(i)); 
	 } 
 } 
 return tmp; 
}

