// validate the form
function checkReistration(theForm){
	var why_migrate = theForm.account_type;
	var member_title = theForm.title;
	var firstname = theForm.firstname;
	var surname = theForm.surname;
	var email = theForm.email;
	//var AccLogin = theForm.username;
	var AccPassword = theForm.password;
	var ConfirmPass = theForm.password_confirm;

	//if (theForm.account_type == 'select-one') {
		//alert(why_migrate.value);
		if (why_migrate.value == 0){
			//alert(why_migrate.value);
			alert("Please select the reason why you want to migrate.");
			return false;
		}
	//}

	if (member_title.value == 0){
		alert("Please select your Title.");
		return false;
	}

	if (isEmpty(firstname)){
		alert("Please provide your Given Name / First Name.");
		return false;
	}

	if (isEmpty(surname)){
		alert("Please provide your Surname / Last Name.");
		return false;
	}

	if (isEmpty(email)){
		alert("Please provide your email address.");
		return false;
	}
	else if (!emailCheck(email.value)){
		email.focus();
		email.select();
		return false;
	}
/*
	var username=trimSpaces(AccLogin.value);
	if ( username == ""){
		alert("Please choose a username");
		AccLogin.focus();
		AccLogin.select();
		return false;
	}
	else if (username.length<2){
			alert("The minimum length of username is 2 chars");
			AccLogin.focus();
			AccLogin.select();
			return false;
		}
	else if (!validateUsername(username)){
		alert("Only characters from a-z and number\nfrom 0-9 are allowed in the username");
		AccLogin.focus();
		AccLogin.select();
		return false;
	}
*/
	var password=trimSpaces(AccPassword.value);
	if (password == ""){
			alert("Please choose a password");
			AccPassword.focus();
			AccPassword.select();
			return false;
	}
	else if (password.length<4){
			alert("The minimum length of password is 4 chars");
			AccPassword.focus();
			AccPassword.select();
			return false;
	}

	var confirmPass = trimSpaces(ConfirmPass.value);
	if ( confirmPass == ""){
			alert("Please re-type your password");
			ConfirmPass.focus();
			ConfirmPass.select();
			return false;
	}

	if (password != confirmPass ){
			alert("Your retyped password does not match. Please try again.");
			AccPassword.focus();
			AccPassword.select();
			return false;
	}

	return true;
}

// check the username, valid chars: a-z, 0-9
function validateUsername(username){
	username=username.toUpperCase();
	var theChar;
	for(index=0;index<username.length;index++){
		theChar=username.charCodeAt(index);
		if (!((theChar>=48 && theChar<=57) || (theChar>=65 && theChar<=97))){
			return false;
		}
	}
	return true;
}

function testIsValidObject(objToTest) {
		if (null == objToTest) {
			return false;
		}
		if ("undefined" == typeof(objToTest) ) {
			return false;
		}
		return true;

	}
