function init() {
	showSignup();
}

function validateForm( form ) {
	checkEmpty( form.email, "Please enter your e-mail address" );
	checkEmail( form.email );
	if( !isRemember() ) {
		checkEmpty( form.password, "Please enter your password" );
	}
	if( isSignup() ) {
		checkEmpty( form.first_name, "Please enter your first name" );
		checkEmpty( form.last_name, "Please enter your last name" );
		checkEmpty( form.passwordAgain, "Please repeat your password" );
		if( form.passwordAgain.value != form.password.value ) {
			form.password.value =
				form.passwordAgain.value = "";
			throw { field: form.password, msg: "Your password does not match" };
		}
	}
	form.passwordAgain.disabled = true; // No need to submit it
	return true;
}

function isLogin() {
	return getFieldValue( document.forms.login.accountexist ) == "1";
}

function isSignup() {
	return getFieldValue( document.forms.login.accountexist ) == "0";
}

function isRemember() {
	return getFieldValue( document.forms.login.accountexist ) == "-1";
}

function showSignup() {
	document.getElementById( "btn_login" ).style.display = isLogin() ? "block" : "none";
	document.getElementById( "btn_remind" ).style.display = isLogin() ? "block" : "none";
	
	document.getElementById( "btn_signup" ).style.display = isSignup() ? "none" : "block";
	document.getElementById( "signup_name" ).style.display =
		document.getElementById( "signup_password" ).style.display = isSignup() ? "block" : "none";
	document.getElementById( "btn_signin" ).style.visibility =
		document.getElementById( "msg_create" ).style.visibility = isSignup() ? "visible" : "hidden";

	document.getElementById( "btn_password" ).style.visibility = isRemember() ? "visible" : "hidden";
	document.getElementById( "signin_password" ).style.visibility = isRemember() ? "hidden" : "visible";
}

function showRemindPwd() {
	setFieldValue( document.forms.login.accountexist, -1 );
	showSignup();
}

function showCreateAccount() {
	setFieldValue( document.forms.login.accountexist, 0 );
	showSignup();
}