<!--
// This function will trim leading and/or trailing spaces from a string
// arg = the value you wish to have trimmed..
// func = "left" for Ltrim(), "right" for RTrim() or "both" for Trim()

//===================================
function trim(arg,func) {
//===================================

var trimvalue = "";
arglen = arg.length;
if (arglen < 1) return trimvalue;

if (func == "left" || func== "both") {
i = 0;
pos = -1;
while (i < arglen) {
if (arg.charCodeAt(i) != 32 &&
!isNaN(arg.charCodeAt(i))) {
pos = i;
break;
}
i++;
}
}

if (func == "right" || func== "both") {
var lastpos = -1;
i = arglen;
while (i >= 0) {
if (arg.charCodeAt(i) != 32 &&
!isNaN(arg.charCodeAt(i))) {
lastpos = i;
break;
}
i--;
}
}

if (func == "left") {
trimvalue = arg.substring(pos,arglen-1);
}

if (func == "right") {
trimvalue = arg.substring(0,lastpos+1);
}

if (func == "both") {
trimvalue = arg.substring(pos,lastpos + 1);
}

return trimvalue;

}



function isEmail(argvalue){
	if (argvalue.indexOf(" ") != -1){
		return false;
	}
	else if (argvalue.indexOf("@") == -1){
		return false;
	}
	else if (argvalue.indexOf("@") == 0){
		return false;
	}
	else if (argvalue.indexOf("@") == (argvalue.length-1)){
		return false;
	}
	emailArray = argvalue.split("@");
	if (emailArray[1].indexOf(".") == -1){
		return false;
	}
	else if (emailArray[1].indexOf(".") == 0){
		return false;
	}
	else if (emailArray[1].charAt(emailArray[1].length-1) == "."){
		return false;
	}
	return true;
}



function checkform(){
	var aok = true;
	var message = "ERROR:\n";

	thefname = trim(document.register.fname.value,"both");
	thelname = trim(document.register.lname.value,"both");
	theaddr1 = trim(document.register.addr1.value,"both");
	thecity = trim(document.register.city.value,"both");
	thestate = trim(document.register.state.value,"both");
	thepostcode = trim(document.register.postcode.value,"both");
thecountry = trim(document.register.country.value,"both");

	theemail = trim(document.register.email.value,"both");
	thepwd = trim(document.register.pwd.value,"both");
	thepwd2  = trim(document.register.pwd2.value,"both");
	theterms = document.register.readterms.checked;
	
	
	
	pwdlen = thepwd.length;

	if (thefname == ''){
		aok = false;
		message = message + 'You must enter a first name!\n';
	}
	
	if (thelname == ''){
		aok = false;
		message = message + 'You must enter a last name!\n';
	}

	if (theaddr1 == ''){
		aok = false;
		message = message + 'You must enter your address!\n';
	}

	if (thecity == ''){
		aok = false;
		message = message + 'You must enter your city of residence!\n';
	}

	if (thestate == ''){
		aok = false;
		message = message + 'You must enter your state / county of residence!\n';
	}

	if (thepostcode == ''){
		aok = false;
		message = message + 'You must enter your postcode!\n';
	}

	if (thecountry == ''){
		aok = false;
		message = message + 'You must enter your country of residence!\n';
	}

	if (isEmail(theemail) == false){
		aok = false;
		message = message + 'Email Address is missing or incorrect!\n';
	}
	
	if (pwdlen < 8){
		aok = false;
		message = message + 'Password must be 8 characters or longer!\n';
	}
	
	if (thepwd != thepwd2){
		aok = false;
		message = message + 'The two passwords are different!\n';
	}
	
	if (theterms == false){
		aok = false;
		message = message + 'You must agree to the terms and conditions to use this facility!\n';
	}

	
	if (aok == false){
		alert(message);
	}
	return aok;
}
//-->
