function register() {
	if($F('password') != $F('password2')) {
		alert('两次密码输入不同，请重新输入');
		$('password').value = '';
		$('password2').value = '';
		$('password').focus();
		return;
	}
	if($F('birth-year') == '0' || $F('birth-month') == '0' || $F('birth-date') == '0') {
		alert('生日输入有误');
		return;
	}

	var username,sex,birthday;
	username = $F('username');
	$A(document.getElementsByName("radioSex")).each(function(sexElement){
		if(sexElement.checked == true) 
			sex = sexElement.value;
    });
	birthday = $F('birth-year') + '-' + $F('birth-month') + '-' +  $F('birth-date');

	$('btnRegister').style.display = 'none';
	$('committing-register').style.display = '';
    
    var pars = 'ajax&username=' + encodeURIComponent(username) + 
    	'&password=' + encodeURIComponent($F('password')) + "&email=" + encodeURIComponent($F('email')) +
		"&nickname=" + encodeURIComponent($F('nickname')) + "&sex=" + sex + "&birthday=" + birthday +
		"&d=" + (new Date() * 1);

	new Ajax.Request('?',{
		method: 'post', 
		parameters: pars, 
		onSuccess: function(originalRequest) {
			new Insertion.After('btnRegister',originalRequest.responseText);
		},
		onFailure: function(originalRequest) {
			alert('注册失败,请稍后再试');
			regFailure();
		}
	});
}

function regFailure() {
	$('btnRegister').style.display = '';
	$('committing-register').style.display = 'none';
}

function regResult(errCode,msg) {
	if(errCode == 0) {
		alert('注册成功，请记住你的博客屋地址 http://' + msg + '.bokewu.com');
		if(rd.indexOf("http://") != 0)
			document.location = 'http://' + msg + '.bokewu.com/';
		else
			document.location = rd;
	}
	else if(errCode == 1) {
		alert('用户名已经存在，请更换用户名');
		regFailure();
		$('username').value = '';
		$('username').focus();
	}
	else {
		alert(msg);
		regFailure();
	}
}