<!--
/* checks for no spaces at start */
function notBlank(str) {
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) != " ")
			return true
	}
	return false
}

/* checks for blank strings */
function notNull(str) {
	if (str.length == 0 )
		return false
	else 
		return true
}

function ValidateEmail(sEmail) {
	if (sEmail.length > 100) {
    	return false
  	} else { 
    	var sChar = ""
    	var bSeenAT = false
    	var bSeenDOT = false
    	var sLastChar = ""
    	for (var i=0; i < sEmail.length; i++) {
      		sChar = sEmail.charAt(i)
      		if (sChar == "@") { if (i == 0 || i == sEmail.length-1 || bSeenAT || sChar == sLastChar || sLastChar == ".") { return false } else { bSeenAT = true } }
      		if (sChar == ".") { if (i == 0 || i == sEmail.length-1 || sChar == sLastChar || sLastChar == "@") { return false } else { bSeenDOT = true } }
      		if (sChar == " ") { return false }
      		sLastChar = sChar
    	}
    	if (bSeenAT && bSeenDOT) { return true } else { return false }
  	}
}

function trim(inputString) {
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces it with one space. If something besides
	// a string is passed in (null, custom object, etc.) then return the input.
	if (typeof inputString != "string") { return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") { // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue; // Return the trimmed string back to the user
} 

function make_selections(f){
	var errMsg, valid;
	valid = true
	errMsg = "";
	
	// Username
	if (!notNull(f.joinusername.value) && !notBlank(f.joinusername.value)){
		errMsg = errMsg + "\n- Username is required.";
		f.joinusername.focus();
		valid = false;
	}
	else{
		if (f.joinusername.value.length < 4){
			errMsg = errMsg + "\n- Username is invalid. Please choose a Username with 4 or more characters.";
			f.joinusername.focus();
			valid = false;
		}
	}
	
	// Password
	if (!notNull(f.txtuserpassword.value) && !notBlank(f.txtuserpassword.value)){
		errMsg = errMsg + "\n- Password is required.";
		f.txtuserpassword.focus();
		valid = false;
	}
	else{
		if (f.txtuserpassword.value.length < 4){
			errMsg = errMsg + "\n- Password is invalid. Please choose a Password with 4 or more characters.";
			f.txtuserpassword.focus();
			valid = false;
		}
		else {
			if (f.txtuserpassword.value == f.joinusername.value){
				errMsg = errMsg + "\n- Password is invalid. Your password cannot be your username.";
				f.txtuserpassword.focus();
				valid = false;
			}
			else {
				if (f.txtuserpassword.value != f.verifypassword.value){
					errMsg = errMsg + "\n- Your verified Password must match your original entry.";
					f.verifypassword.focus();
					valid = false;
				}
			}
		}
	}
	
	// Email address
	if (!notNull(f.email.value) && !notBlank(f.email.value)){
		errMsg = errMsg + "\n- Email Address is required.";
		f.email.focus();
		valid = false;
	}
	else {
		if (!ValidateEmail(f.email.value)) {
			errMsg = errMsg + '\n- Email Address is invalid.';
			f.email.focus();
			valid = false;
		}
		else {
			if (f.email.value.indexOf('hotmail.com.au')>-1) {
				errMsg = errMsg + '\n- Your Email Address: \'hotmail.com.au\' is not valid - please change to hotmail.com';
				f.email.focus();
				valid = false;
			}
			else {
				if (f.email.value != f.emailverify.value){
					errMsg = errMsg + "\n- Your confirmed Email Address must match your original entry.";
					f.emailverify.focus();
					valid = false;
				}
			}
		}
	}
	
	// Terms & Conditions
	if (f.agreeterms.checked==false) {
		errMsg = errMsg + "\n- You must agree to the Terms and Conditions.";
		valid = false;
	}
	
	// Code of Ethics
	if (f.agreeethics.checked==false) {
		errMsg = errMsg + "\n- You must agree to the Code of Ethics.";
		valid = false;
	}
	
	// Of age
	if (f.agreeage.checked==false) {
		errMsg = errMsg + "\n- You must verify that you are 18 years of age or over.";
		valid = false;
	}
	
	// Check if form valid and alert user if necessary
	if ( valid == true ) {
		return true;
	}
	else {
		alert('The following error(s) occurred:'+errMsg);
		return false;
	}
}

function submitform() {
	if(document.registration.onsubmit()) {
		document.registration.submit();
	}
}
//-->