	
	function ValidateRadio(rname) {
		// place any other field validations that you require here
		// validate myradiobuttons
		myOption = -1;
		for (i=0; i<orderform.elements[rname].length; i++) {
		if (orderform.elements[rname][i].checked) {
		myOption = i;
		}
		}
		if (myOption == -1) {
		return false;
		}
		
		return true;
		// place any other field validations that you require here
		//thisform.submit(); // this line submits the form after validation
	
	}
	
	
	function ValidateFreeSignup() { // From register/index.php - 
		// Gather title, fname, lname, email, phone and delivery method
		if (ValidateContactInput()) {
			if (ValidateAccessInput()) {
				return true;
			} 
		}
		return false;
	
	}
	
	function validateAddress(incoming) {
		var supported = 0;
		
		  if (window.RegExp) {
		    var tempStr = "a";
		    var tempReg = new RegExp(tempStr);
		    if (tempReg.test(tempStr)) supported = 1;
		  }
		
		  if (!supported) 
		    return (incoming.indexOf(".") > 2) && (incoming.indexOf("@") > 0);
		  
		  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		
		  var res1 = r1.test(incoming);
		  var res2 = r2.test(incoming);
		
		  var resString = (!res1 && res2);
		
		  
		  return resString;
	}	
	
	
	function ValidateEmailInput() {
		
		var iserr;
		iserr = false;
		
		var alertm;
		alertm = "";
		
		
		//--- Email Address
		myBlock = document.forms['orderform'].user_email;
		if (ie4) myBlock = document.all['user_email']; 
		if (ns4) myBlock = document.layers['user_email'];
		if (ns6) myBlock = document.getElementById('user_email');
		
		// exists - email
		if (myBlock.value == "") {
			alertm = "Please enter an email address\n";
			iserr = true;
			myBlock.focus();
		} else {
			
			if (!validateAddress(myBlock.value)) {
				alertm = "Your email address appears to\ncontain invalid formatting\n";
				iserr = true;
				myBlock.focus();
			}
			
			
		}
		

		if (iserr) {
			alert(alertm);
			return false;
		} 
		return true;
				
		
	
	
	}
	
	function ValidateContactInput() {
		var iserr;
		iserr = false;
		var alertm;
		alertm = "You must complete all fields : \n";
		
		// title
		if (!ValidateRadio('user_title')) {
			alertm += "- title \n";
			iserr = true;
		}
		
		// exists - first name
		if (document.orderform.user_firstname.value == "") {
			alertm += "- first name\n";
			iserr = true;
		} else {
		// length - first name
		if (document.orderform.user_firstname.value.length < 2) {
			alertm += "- FULL first name\n";
			iserr = true;
		}
		}
		// exists - last name
		if (document.orderform.user_lastname.value == "") {
			alertm += "- last name\n";
			iserr = true;
		} else {
		// length - last name
		if (document.orderform.user_lastname.value.length < 2) {
			alertm += "- FULL last name\n";
			iserr = true;
		}
		}
		
		// exists - email
		if (document.orderform.user_email.value == "") {
			alertm += "- email address\n";
			iserr = true;
		} else {
			if (document.orderform.validate_email.checked ) {
				if (!validateAddress(document.orderform.user_email.value)) {
					alertm += "- your email address appears to\ncontain invalid formatting\n";
					iserr = true;
				}
			}
			
		}
		

		if (iserr) {
			alert(alertm);
			return false;
		} 
		return true;
				
		
	
	
	}
	
	
	function ValidateAccessInput() { // From register/index.php - 
		// Validate both username and password
		if (ValidateAccessDetailsUsername()) {
			if (ValidateAccessDetailsPassword()) {
				return true;
			} 
		}
		return false;
	
	}
	
	//-----------------------------------------------------------------
	// ValidateAccessDetailsUsername()
	// Used for validating username, password and retype password
	//-----------------------------------------------------------------
	
	function ValidateAccessDetailsUsername() {
	
		var iserr;
		iserr = false;
		var alertm;
		alertm = "\n";
		
		
		
		// exists - username
		if (document.orderform.username.value == "") {
			alertm += "Please enter a username\n";
			iserr = true;
		} else {
			if (document.orderform.username.value.length > 12) {
				alertm += "\nYour username is too long\n";
				iserr = true;
			}
			if (document.orderform.username.value.length < 3) {
				alertm += "\nYour username must be at least 3 characters\n";
				iserr = true;
			}
		}
	
		
		if (iserr) {
			alert(alertm);
			return false;
		} 
		return true;
				
	}		
	
	//-----------------------------------------------------------------
	// ValidateAccessDetailsPassword()
	// Used for validating username, password and retype password
	//-----------------------------------------------------------------
	function ValidateAccessDetailsPassword() {
	
		var iserr;
		iserr = false;
		var alertm;
		alertm = "\n";
		
		
		// exists - password
		if (document.orderform.password.value == "") {
			alertm += "Please enter a password\n";
			iserr = true;
		} else {
			if (document.orderform.password.value.length > 12) {
				alertm += "\nYour password is too long\n";
				iserr = true;
			}
			if (document.orderform.password.value.length < 4) {
				alertm += "\nYour password must be at least 4 characters\n";
				iserr = true;
			}
		}
		
		// exists - password
		if (document.orderform.password.value != document.orderform.confirmpassword.value) {
			alertm += "Your passwords do not match\n";
			iserr = true;
		} 
		
		
		if (iserr) {
			alert(alertm);
			return false;
		} 
		return true;
				
	}		
	

	
	
	
		
