
function isPhoneValid(phone){
	
	if(isEmptyString(phone)){
		return false;
	}
	
	return (/^((13[0-9])|(15[^4,\\D])|(18[0,3,5-9])|(14[0-9]))+\d{8}$/).test(phone);
}

function isEmailValid(email){
	
	if(isEmptyString(email)){
		return false;
	}
	
	if(email.length > 39){
		return false;
	}
	
	return (/^(\w)+([-+.]\w+)*\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/).test(email);
}

function isNicknameValid(nickname){
	
	if(isEmptyString(nickname)){
		return false;
	}
	
	return (/^[a-zA-Z0-9-_.\u4e00-\u9fa5]{1,20}$/).test(nickname);
}

function isPasswordValid(password){
	
	if(isEmptyString(password)){
		return false;
	}

	var len = password.length;
	return (len > 5 && len < 17);	
//	return (/^[a-zA-Z0-9-_.~!@#$%^&*]{6,16}$/).test(password);
}

function isEmptyString(str){
	return (str == null || str.length == 0);	
}

function getRootPath() {
	var strFullPath = window.document.location.href;
	var strPath = window.document.location.pathname;
	var pos = strFullPath.indexOf(strPath);
	var prePath = strFullPath.substring(0, pos);
	var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
	return prePath + postPath;
}

function reloadImg(captchaId){
	var appRoot = getRootPath();
	var obj = document.getElementById(captchaId);
	obj.src =  appRoot + "/captcha.show?param=" + Math.random();
}

var isUsernameValid = false;

function setUsernameValid(flag) {
	isUsernameValid = flag;
}

function getUsernameValid() {
	return isUsernameValid;
}


/*function checkEmailAvailability(email){
	$.ajax({
		type:"post",
		dataType: "text",
		url: "https://218.104.200.245:18445/authorise/checkuserinfo",
		contentType: "application/x-www-form-urlencoded; charset=utf-8",
		data: "email="+ email,
		async:false,
		callback:funcTest,

		success: function(res) {
			alert('ok');
			showResponseForEmail(res);
		},
		error: function(res) {
			alert('erro');
			showUsernameErrorInfo("邮箱已经使用");
		}
	});
	
}

function checkPhoneAvailability(phone){
	$.ajax({ url: "checkPhone.ajax", 
		dataType: "text", 
		data: "phone="+ phone,
		async:false,
		success: function(response) {
			showResponseForPhone(response);
		},
		error: function(res) {
			showNoResponseForPhone();
		}
	});
	
	$.ajax({
		type:"post",
		dataType: "text", 
		url: "checkPhone.ajax",
		contentType: "application/x-www-form-urlencoded; charset=utf-8",
		data: "phone="+ phone,
		async:false,
		success: function(response) {
			showResponseForPhone(response);
		},
		error: function(res) {
			showUsernameErrorInfo("éªŒè¯æ‰‹æœºå·å¤±è´¥ï¼Œè¯·æ£€æŸ¥ç½‘ç»œçŠ¶æ€");
		}
	});
}*/

/*function showUsernameErrorInfo(errorInfo){
//	document.getElementById("username").className = 'input_1_error';
	
	var usernameNote = document.getElementById("usernameNote");
	usernameNote.innerHTML = errorInfo;
	usernameNote.className = "note_error";
//	usernameNote.style.color="red";
	
}*/
