function form_validation(name) {
	var input_value = document.getElementsByName(name)[0].value;
	var regx = /^[a-zA-Z0-9]+$/;
	if (!regx.test(input_value)) {
		information(name + " must be number!");
		if (name == "username") {
			$('#usrmsg').show();
			document.getElementsByName('username')[0].value = "";
			document.getElementsByName('username')[0].style.border = "1px solid red";
		}

		else if (name == "password") {
			$('#pwdmsg').show();
			document.getElementsByName('password')[0].value = "";
			document.getElementsByName('password')[0].style.border = "1px solid red";
		}
	} else {
		document.getElementsByName(name)[0].style.border = "1px solid #ddd";
		if (name == "username")
			$('#usrmsg').hide();
		else if (name == "password")
			$('#pwdmsg').hide();
	}
}

function clean() {
	document.getElementsByName('username')[0].value = "";
	document.getElementsByName('password')[0].value = "";
	document.getElementsByName('retype_pwd')[0].value = "";
}
function register(scope) {
	var userName = $('#username').val();
	var password = $('#password').val();
	var rePassword = $("#retype_pwd").val();
	$.post('register', {
		userName : userName,
		password : password,
		scope:scope
	}, function(data) {
		if (data.success) {
			window.location.replace("registerSuccess.jsp");
		} else {
			information(data.failedMessage);
			// $('#registerMsg').html($.i18n.prop('msgRegister'));
		}
	}, "json");
}

function password_validation(scope) {
	var null_flag = 0;
	var user_name = document.getElementsByName('username')[0].value;
	var retype_pwd = document.getElementsByName('retype_pwd')[0].value;
	var input_pwd = document.getElementsByName('password')[0].value;

	if (user_name == "") {
		$('#usrmsg').show();
		document.getElementsByName('username')[0].value = "";
		document.getElementsByName('username')[0].style.border = "1px solid red";
		null_flag = 1;
	} else {
		$('#usrmsg').hide();
		document.getElementsByName('username')[0].style.border = "";
	}

	if (input_pwd == "") {
		$('#pwdmsg').show();
		document.getElementsByName('password')[0].value = "";
		document.getElementsByName('password')[0].style.border = "1px solid red";
		null_flag = 1;
	} else {
		$('#pwdmsg').hide();
		document.getElementsByName('password')[0].style.border = "";
	}
	if (input_pwd != retype_pwd) {
		$('#rtpmsg').show();
		document.getElementsByName('retype_pwd')[0].value = "";
		document.getElementsByName('retype_pwd')[0].style.border = "1px solid red";
		null_flag = 1;
	} else {
		$('#rtpmsg').hide();
		document.getElementsByName('retype_pwd')[0].style.border = "";
	}
	if (null_flag == 0)
		register(scope);
}