// 电子邮箱
function checkIsEmail(value) {
	var pattern =  /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if (!pattern.test(value)) {
		return false;
	} else {
		return true;
	}
}
//手机号码
function checkIsPhone(value) {
	var pattern=/^1[34578][0-9]{9}$/;
	if (!pattern.test(value)) {
		return false;
	} else {
		return true;
	}
}
// 身份证
function checkIsIdCard(value) {
	var pattern = /^([0-9]{18}|[0-9]{15}|[0-9]{17}x|[0-9]{17}X)$/;
	if (!pattern.test(value)) {
		return false;
	} else {
		return true;
	}
}
//银行卡号
function checkIsBankNum(value) {
	var pattern = /^([0-9]{19}|[0-9]{16})$/;
	if (!pattern.test(value)) {
		return false;
	} else {
		return true;
	}
}

jQuery.validator.addMethod("isEmail", function(value, element) {
	return this.optional(element) || checkIsEmail(value);
});
jQuery.validator.addMethod("isPhone", function(value, element) {
	return this.optional(element) || checkIsPhone(value);
});
jQuery.validator.addMethod("isIdcard", function(value, element) {
	return this.optional(element) || checkIsIdCard(value);
});
jQuery.validator.addMethod("isBankCard", function(value, element) {
	return this.optional(element) || checkIsBankNum(value);
});


function callObj(url, flag)
{
		if(flag == 'id_card_0'){
			$('#idcardFront').val(url);
		}else if(flag == 'id_card_1'){
			$('#idcardBehind').val(url);
		}else{
			$('#bankcardFront').val(url);
		}
}
function callBackUpload(response) {
    if(response.status==100){
        return false;
    }else{
    	//认证方式
		var realType = $("input[name='RadioGroup1']:checked").val();
		//如果是身份证
		if(1==realType){
	        if($("#idcardFront").val()==""){
	        	$("#idcardFront").val(response.url);
	        }else{
	        	$("#idcardBehind").val(response.url);
	        }
		}else{
			$("#bankcardFront").val(response.url);
			
		}
       // $("#test").append(_input);
    }
	}   

function callDelete(flag)
{
	if(flag == 'id_card_0'){
		$('#idcardFront').val('');
	}else if(flag == 'id_card_1'){
		$('#idcardBehind').val('');
	}else{
		$('#bankcardFront').val('');
	}
}
	
function isNumber(key) {
    return (key >= 48 && key <= 57) || (key >= 96 && key <= 105)
}

function isSpecialKey(key) {
    //8:backspace; 46:delete; 37-40:arrows; 36:home; 35:end; 9:tab; 13:enter
    return key == 8 || key == 46 || (key >= 37 && key <= 40) || key == 35 || key == 36 || key == 9 || key == 13
}
	
function isZM(key)
{
	 return key == 88
}
	
	//8: backspace  46: delete
	//48-57/96-105: 0-9	
function restrict_sfz_input(el) {
	el.bind('contextmenu', function(){
		return false;
	});
	// 屏蔽输入法
	el.css('ime-mode', 'disabled');
	
	el.bind('keydown', function(e) {
        var key = window.event ? e.keyCode : e.which;
        return (isSpecialKey(key)) || (isZM(key)) ||((isNumber(key) && !e.shiftKey));
    });
}