function checkUserName(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var userName = $("#"+input_id).val();
	if(userName == '') {
		warning(span_id, '用户名不能为空!');
		return false;
	}
	var unLen = /^[\w\u4E00_\u9FA5\uF900_\uFA2D]*$/;
	if(!unLen.test(userName)){
		warning(span_id, '用户名非法!');
		return false;
	}
	if(userName.length < 5 || userName.length > 15) {
		warning(span_id, userName.length < 5 ? '用户名不能小于5个字符' : '用户名不能超过 15 个字符');
		return false;
	}
	ajaxresponse(span_id,'op=checkusername&username='+userName);
	return true;
}
function warning(obj, msg) {
	$("#"+obj).show();
	$("#"+obj).empty();
	$("#"+obj).append('<img src="img/check_error.gif" width="13" height="13">' + msg);
}
function ajaxresponse(objname, data) {
	var flag = false;
	$.ajax({
		url:'do.php?ac=82cadccca8ab9980d40a3b88a43e2cab&' + data,
		type: "GET",
		dataType: "html",
		async: false,
		success: function (obj){
			obj = $(obj).find("#xiaoxi").text();
			if(obj.indexOf('succeed') > -1) {
				$("#"+objname).show();
				$("#"+objname).empty();
				$("#"+objname).append('<img src="img/check_right.gif" width="13" height="13">');
				flag = true;
			} else {
				warning(objname,obj);
				flag = false;
			}
		}
	});
	return flag;
}
function checkPassword(pwd,chkpswd,password) {
	$('#'+chkpswd).hide();
	var password = $('#'+password).val();
	if(password.length<6){
		warning(pwd, '密码必须大于6位!');	
		return false;
	}
	if(password == '' || /[\'\"\\]/.test(password)) {
		warning(pwd, '密码空或包含非法字符');
		return false;
	} else {
		$("#"+pwd).show();
		$("#"+pwd).empty();
		$("#"+pwd).append('<img src="img/check_right.gif" width="13" height="13">');
	}
	return true;
}
function checkPassword2(pwd2) {
	var password = $('#password').val();
	var password2 = $('#password2').val();
	if(password2 == ''){
		warning(pwd2, '确认密码不能为空');
		return false;
	}
	if(password != password2) {
		warning(pwd2, '两次输入的密码不一致');
		return false;
	} else {
		$("#"+pwd2).show();
		$("#"+pwd2).empty();
		$("#"+pwd2).append('<img src="img/check_right.gif" width="13" height="13">');
	}
	return true;
}
function checkPwd(pwd){
	if (pwd == "") {
		$("#chkpswd").attr("class","psdiv0");
	} else if (pwd.length < 6) {
		$("#chkpswd").attr("class","psdiv1");
		$("#chkpswdcnt").empty();
		$("#chkpswdcnt").append("太短");
	} else if(!isPassword(pwd) || !/^[^%&]*$/.test(pwd)) {
		$("#chkpswd").attr("class","psdiv0");
	} else {
		var csint = checkStrong(pwd);
		switch(csint) {
			case 1:
				$("#chkpswdcnt").empty();
				$("#chkpswdcnt").append("很弱");
				$("#chkpswd").attr("class","psdiv"+(csint + 1));
				break;
			case 2:
				$("#chkpswdcnt").empty();
				$("#chkpswdcnt").append("一般");
				$("#chkpswd").attr("class","psdiv"+(csint + 1));
				break;
			case 3:
				$("#chkpswdcnt").empty();
				$("#chkpswdcnt").append("很强");
				$("#chkpswd").attr("class","psdiv"+(csint + 1));
				break;
		}
	}
}
function isChn(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var str = $("#"+input_id).val();
	var reg = /^([A-Z]|[a-z]|[\d]|[\u0391-\uFFE5])*$/;
	if(str == ''){
		warning(span_id, '公司名称不能为空');
		return false;
	}
	if(!reg.test(str)){
		warning(span_id, '公司名称不能含有特殊符号');
		return false;
	}else{
		$("#"+span_id).show();
		$("#"+span_id).empty();
		$("#"+span_id).append('<img src="img/check_right.gif" width="13" height="13">');
	}
	return true;
}
function chkdistrict(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var str = $("select[name="+input_id+"] option:selected").val();
	if(str == ''||str == undefined){
		warning(span_id, '请选择区域');
		return false;
	}else{
		var districtlist = new Array()
		districtlist = ['(包括:北京市、天津市、河北省、山西省、内蒙古自治区)','(包括:辽宁省、吉林省、黑龙江省)','(包括:陕西省、甘肃省、青海省、宁夏回族自治区、新疆维吾尔族自治区)','(包括:上海市、江苏省、浙江省、安徽省、福建省、江西省、山东省)','(包括:河南省、湖北省、湖南省)','(包括:广东省、海南省、广西壮族自治区)','(包括:重庆市、四川省、贵州省、云南省、西藏自治区)','(包括:香港特别行政区、澳门特别行政区、台湾省)'];
		$("#"+span_id).show();
		$("#"+span_id).empty();
		$("#"+span_id).append('<img src="img/check_right.gif" width="13" height="13">'+districtlist[str]);
	}
	return true;
}
function Name(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var str = $("#"+input_id).val();
	var reg = /^[\u4e00-\u9fa5a-z]+$/i;
	if(str == ''){
		warning(span_id, '联系人名称不能为空');
		return false;
	}
	if(!reg.test(str)){
		warning(span_id, '联系人名称不能含有数字和特殊符号');
		return false;
	}else{
		$("#"+span_id).show();
		$("#"+span_id).empty();
		$("#"+span_id).append('<img src="img/check_right.gif" width="13" height="13">');
		}
	return true;
}
function Email(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var email = $("#"+input_id).val();
	var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(!myreg.test(email)){
		warning(span_id, '邮箱为空或非法');
		return false;
	}else{
		$("#"+span_id).show();
		$("#"+span_id).empty();
		$("#"+span_id).append('<img src="img/check_right.gif" width="13" height="13">');
		}
	return true;
}
function Mobile_Card(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var card = $("#"+input_id).val();
	var mobile = /^[^\u4e00-\u9fa5a-zA-Z]+$/;
	if(card == ''){
		warning(span_id, '手机号码不能为空');
		return false;
	}
	if(!mobile.test(card)){
		warning(span_id, '手机号码不能含有汉字和英文');
		return false;
	}else{
		$("#"+span_id).show();
		$("#"+span_id).empty();
		$("#"+span_id).append('<img src="img/check_right.gif" width="13" height="13">');
		}
	return true;
}
function fixed_Card(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var card = $("#"+input_id).val()
	var mobile = /^[^\u4e00-\u9fa5a-zA-Z]+$/;
	if(card == ''){
		warning(span_id, '联系电话不能为空');
		return false;
	}
	if(!mobile.test(card)){
		warning(span_id, '联系电话不能含有汉字和英文');
		return false;
	}else{
		$("#"+span_id).show();
		$("#"+span_id).empty();
		$("#"+span_id).append('<img src="img/check_right.gif" width="13" height="13">');
		}
	return true;
}
function checkSeccode(input_id,span_id) {
	var seccodeVerify = $('#'+input_id).val();
	return ajaxresponse(span_id, 'op=checkseccode&seccode='+seccodeVerify);
}
function updateseccode() {
	var img = 'do.php?ac=seccode&rand='+Math.random();
	if($('#img_seccode')) {
		$('#img_seccode').attr('src',img);
	}
}
function seccode() {
	var img = 'do.php?ac=seccode&rand='+Math.random();
	$("#seccode_img").empty();
	$("#seccode_img").append('<img id="img_seccode" src="'+img+'" align="absmiddle">');
}
function isPassword(str){
	if (str.length < 3) return false;
	var len;
	var i;
	len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) return false;
	}
	return true;
}
function checkStrong(pwd){
	modes=0; 
	for (i=0;i<pwd.length;i++){ 
		modes|=charMode(pwd.charCodeAt(i)); 
	} 
	
	return bitTotal(modes);
}
function bitTotal(num){ 
	modes=0; 
	for (i=0;i<4;i++){ 
		if (num & 1) modes++; 
		num>>>=1; 
	} 
	return modes; 
}
function charMode(iN){ 
	if (iN>=48 && iN <=57) //数字 
	return 1; 
	if (iN>=65 && iN <=90) //大写字母 
	return 2; 
	if (iN>=97 && iN <=122) //小写 
	return 4; 
	else 
	return 8; //特殊字符 
}
/*注册*/
function register_sub(){
	var numbername 	= checkUserName('username','checknumberid','userName1');
	if(numbername == false){
		tishi();
		$('#username').select();
		return false;
	}
	
	var password = checkPassword('checkpassword','chkpswd','password');
	if(password == false){
		tishi();
		$('#password').select();
		return false;
	}
	var password2 = checkPassword2('checkpassword2');
	if(password2 == false){
		tishi();
		$('#password2').select();
		return false;
	}
	var email = Email('email','checkemail','Email_');
	if(email == false){
		tishi();
		$('#email').select();
		return false;
	}
	var yanzhengma = checkSeccode('seccode','checkseccode');
	if(yanzhengma == false){
		tishi();
		$('#seccode').select();
		return false;
	}
	
	var gongsi = isChn('cpyname','checkcpyname','companyName1');
	if(gongsi == false){
		tishi();
		$('#cpyname').select();
		return false;
	}

	var district = chkdistrict('co_district','checkdistrict','district');
	if(district == false){
		tishi();
		return false;
	}

	var username = Name('contact','checkusername','cnName');
	if(username == false){
		tishi();
		$('#contact').select();
		return false;
	}
	
	var card = Mobile_Card('card','checkcard','mobile');
	if(card == false){
		tishi();
		$('#card').select();
		return false;
	}
	
	var guhua = fixed_Card('fixed','checkfixed','tel');
	if(guhua == false){
		tishi();
		$('#fixed').select();
		return false;
	}
	return true;
}

function Register(){
	$("#username").focus(function(){
		$("#checknumberid").hide();
		$("#userName1").show();
	});
	$("#username").blur(function(){
		checkUserName('username','checknumberid','userName1');
	});
	
	$("#password").focus(function(){
		$("#checkpassword").hide();
		$("#chkpswd").show();
	});
	$("#password").blur(function(){
		checkPassword('checkpassword','chkpswd','password');
	});
	
	$("#password2").focus(function(){
		$("#checkpassword2").hide();
	});
	$("#password2").blur(function(){
		checkPassword2('checkpassword2');
	});
	
	$("#cpyname").focus(function(){
		$("#checkcpyname").hide();
		$("#companyName1").show();
	});
	$("#cpyname").blur(function(){
		isChn('cpyname','checkcpyname','companyName1');
	});
	
	$("select[name=co_district]").change(function(){
		chkdistrict('co_district','checkdistrict','district');
	});
	
	$("#contact").focus(function(){
		$("#checkusername").hide();
		$("#cnName").show();
	});
	$("#contact").blur(function(){
		Name('contact','checkusername','cnName');
	});
	
	$("#email").focus(function(){
		$("#checkemail").hide();
		$("#Email_").show();
	});
	$("#email").blur(function(){
		Email('email','checkemail','Email_');
	});
	seccode();
	$("#card").focus(function(){
		$("#checkcard").hide();
		$("#mobile").show();
	});
	$("#card").blur(function(){
		Mobile_Card('card','checkcard','mobile');
	});
	
	$("#fixed").focus(function(){
		$("#checkfixed").hide();
		$("#tel").show();
	});
	$("#fixed").blur(function(){
		fixed_Card('fixed','checkfixed','tel');
	});
	
	$("#seccode").blur(function(){
		checkSeccode('seccode','checkseccode');
	});	
	
}

///////*个人信息*///////
function private_sub(input_id,span_id,tiaojian_id){
	$("#"+tiaojian_id).hide();
	var userName = $("#"+input_id).val();
	if(userName == '') {
		warning(span_id, '称呼不能为空!');
		return false;
	}
	if(userName.length < 2 || userName.length > 20) {
		warning(span_id, userName.length < 2 ? '称呼不能小于2个字符' : '称呼不能超过 20 个字符');
		return false;
	}
	$("#"+span_id).show();
	$("#"+span_id).empty();
	$("#"+span_id).append('<img src="img/check_right.gif" width="13" height="13">');
	return true;
}
function private_bind(){
	$("#truename").focus(function(){
		$("#truename3").hide();
		$("#truename2").show();
	});
	$("#truename").blur(function(){
		 private_sub('truename','truename3','truename2');
	});
		
	$("#email").focus(function(){
		$("#checkemail").hide();
		$("#Email_").show();
	});
	$("#email").blur(function(){
		Email('email','checkemail','Email_');
	});
	$("#card").focus(function(){
		$("#checkcard").hide();
		$("#mobile").show();
	});
	$("#card").blur(function(){
		Mobile_Card('card','checkcard','mobile');
	});
	
	$("#fixed").focus(function(){
		$("#checkfixed").hide();
		$("#tel").show();
	});
	$("#fixed").blur(function(){
		fixed_Card('fixed','checkfixed','tel');
	});
}
function private(){
	var numbername 	=  private_sub('truename','truename3','truename2');
	if(numbername == false){
		tishi();
		return false;
	}
	var email = Email('email','checkemail','Email_');
	if(email == false){
		tishi();
		return false;
	}
	var card = Mobile_Card('card','checkcard','mobile');
	if(card == false){
		tishi();
		return false;
	}
	var guhua = fixed_Card('fixed','checkfixed','tel');
	if(guhua == false){
		tishi();
		return false;
	}
	return true;
}
///////*企业信息*///////
function enterprise_sub(){
	var gongsi = isChn('co_name','checkcpyname','co_name1');
	if(gongsi == false){
		tishi();
		return false;
	}
	var district = chkdistrict('co_district','checkdistrict','district');
	if(district == false){
		tishi();
		return false;
	}
	var username = Name('co_contact','checkusername','cnName');
	if(username == false){
		tishi();
		return false;
	}
	var guhua = fixed_Card('co_telephone','checkfixed','tel');
	if(guhua == false){
		tishi();
		return false;
	}
	var card = Mobile_Card('co_mobilephone','checkcard','mobile');
	if(card == false){
		tishi();
		return false;
	}
	return true;
}
function enterprise_bind(){
	$("#co_name").focus(function(){
		$("#checkcpyname").hide();
		$("#co_name1").show();
	});
	$("#co_name").blur(function(){
		isChn('co_name','checkcpyname','co_name1');
	});
	
	$("select[name=co_district]").change(function(){
		chkdistrict('co_district','checkdistrict','district');
	});
	
	$("#co_contact").focus(function(){
		$("#checkusername").hide();
		$("#cnName").show();
	});
	$("#co_contact").blur(function(){
		Name('co_contact','checkusername','cnName');
	});
	$("#co_mobilephone").focus(function(){
		$("#checkcard").hide();
		$("#mobile").show();
	});
	$("#co_mobilephone").blur(function(){
		Mobile_Card('co_mobilephone','checkcard','mobile');
	});
	
	$("#co_telephone").focus(function(){
		$("#checkfixed").hide();
		$("#tel").show();
	});
	$("#co_telephone").blur(function(){
		fixed_Card('co_telephone','checkfixed','tel');
	});	
}
function tishi(){alert("您的资料未填写完整或填写有误,请重新检查！");}
