/*
	validation of the form for registration and edition
*/
var elmnt = document.registration;

function validate(aid){
	var msg = "";
	msg += checkEmail(elmnt.reg_email.value);
	var nm = elmnt.reg_pass.value;
	if (nm == "") {
		msg += "You didn't enter your password.\n";
	}
	else {
		if (nm.length < 3) {
			msg += "The password you entered is too short. The password has to have a minimum of 3 and a maximum of 15 characters. You can use alphanumerical values (letters and numbers); please, avoid special characters.\n";
		}
		else {
			if (nm.length > 15) {
				msg += "The password you entered is too long. The password has to have a minimum of 3 and a maximum of 15 characters. You can use alphanumerical values (letters and numbers); please, avoid special characters.\n";
			}
		}
		if (!validatePassword(nm)) {
			msg += "The password you entered contains some characters that are not allowed. The username has to have a minimum of 3 and a maximum of 15 characters. You can use alphanumerical values (letters and numbers); please, avoid special characters.\n";
		}
	}
	var nm1 = elmnt.reg_cpass.value;
	if (nm1 == "") {
		msg += "You didn't confirm your password.\n";
	}
	else {
		if (nm != nm1) {
		msg += "The confirm password field is not the same as the password field. Please, retype and try again.\n";
		}
	}

	nm = elmnt.reg_name.value;
	if (nm != "") {
		msg += checkUserName(nm);
	}

	nm = elmnt.reg_fname.value;
	if (nm != "") {
		if (nm.length > 45) {
			msg += "The first name you entered is too long – it can contain a maximum of 45 characters.\n";
		}
		else {
			if (!validateFName(nm)) {
				 msg += "Your first name contains characters that are not allowed. Please, retype it using only letters of the alphabet and try again.\n";
			}
		}
	}

	nm = elmnt.reg_lname.value;
	if (nm != "") {
		if (nm.length > 45) {
			msg += "The last name you entered is too long – it can contain a maximum of 45 characters.\n";
		}
		else {
			if (!validateFName(nm)) {
				 msg += "Your last name contains characters that are not allowed. Please, retype it using only letters of the alphabet and try again.\n";
			}
		}
	}

	var sel1 = elmnt.reg_gender.value;
	if (sel1 == 0) {msg += "You didn't specify your gender.\n";}
	sel1 = elmnt.reg_birth_month.value;
	if (sel1 == 0) {msg += "You didn't specify your month of birth.\n";}
	sel1 = elmnt.reg_birth_day.value;
	if (sel1 == 0) {msg += "You didn't specify your day of birth.\n";}
	sel1 = elmnt.reg_birth_year.value;
	if (sel1 == 0) {msg += "You didn't specify your year of birth.\n";}
	nm = elmnt.usernumber.value;
	msg += checkAutoCode(nm);

	if (msg.length > 0) {
		err = "Please, note the following problems:\n\n" + msg;
		alert(err);
	} else {
		elmnt.submit();
	}
	return;
}
///////////////////////////////////
function checkNumber() {
	var msg = "";
	nm = elmnt.usernumber.value;
	msg += checkAutoCode(nm);
	if (msg.length > 0) {
		err = "Please, note the following problems:\n\n" + msg;
		alert(err);
	} else {
		elmnt.submit();
	}
	return;
}