REG_ERRORS = {
	'email':"Email address is invalid",
	'password':"Password must be min 5 chars",
	'agree':"You need to agree to the general terms!"
};


function checkRegistration() {
	form = document.Register;

	re = /^([a-z0-9_.-]|\+)+@{1}[a-z0-9_-]+\.{1}[a-z0-9_-]+.*$/i;


	clearRegError();
	unmark(form.email);
	unmark(form.passwd);
	unmark(form.agree);

	// Check if the email is filled in
	if( form.email.value == "" ) {
		mark(form.email);
		printRegError( REG_ERRORS['email'] );
		return false;

	} else if( !re.test(form.email.value) ) {
		mark(form.email);
		printRegError( REG_ERRORS['email'] );
		return false;

	}

	// Check if the password  is filled in and is longer than 5
	if( form.passwd.value.length < 5 || form.passwd.value.length > 10 ) {
		mark(form.passwd);
		printRegError( REG_ERRORS['password'] );
		return false;
	}

	// Check if agree is checked
	if( !form.agree.checked ) {
		mark(form.agree);
		printRegError( REG_ERRORS['agree'] );
		return false;
	}

	return true;
}

function mark(elem) {
	elem.style.borderColor = "#FF0000";
}

function unmark(elem) {
	elem.style.borderColor = "";
}

function printRegError( str ) {
	e = document.getElementById("JSRegError");
	e.innerHTML = str;
	e.className = "account_error";
	e.style.display = "block";
}

function clearRegError() {
	e = document.getElementById("JSRegError");
	e.innerHTML = "";
	e.className = "";
	e.style.display = "none";
}

function show( str_or_elem ) {
	elem = ( typeof(str_or_elem) ==  "string" ) ? document.getElementById(str_or_elem) : elem = str_or_elem;
	elem.style.display = "block";
}

function hide( str_or_elem ) {
	elem = ( typeof(str_or_elem) ==  "string" ) ? document.getElementById(str_or_elem) : elem = str_or_elem;
	elem.style.display = "none";
}

