function NoSpc(obj) {
	obj.value = obj.value.replace(/^\s+/g, '');
}

function checkSelected() {
	var emailID = document.regform.emailAddress;
	re = /[0-9][0-9]/;
	al = /[a-z]/;
	var e = regform.elements;

	if (document.regform.emailAddress.value == null
			|| document.regform.emailAddress.value == "") {
		alert("Email address is a required field, please enter your details.");
		regform.emailAddress.focus();
		return false;
	}

	if (echeck(emailID.value) == false) {
		emailID.value = "";
		emailID.focus();
		return false;
	}

	if (document.regform.password.value == null
			|| document.regform.password.value == "") {
		alert("Password is a required field, please enter your password.");
		regform.password.focus();
		return false;
	}
	if (e['password'].value != "") {
		if (e['password'].value.length < 6) {
			alert("Please ensure that your password has between 6 and 9 characters including at least 2 numbers!");
			regform.password.value="";
			e['password'].focus();
			return false;
		}
	}
	if (e['password'].value != "") {
		if (e['password'].value.length > 9) {
			alert("Please ensure that your password has between 6 and 9 characters including at least 2 numbers!");
			regform.password.value="";
			e['password'].focus();
			return false;
		}
	}
	if (!re.test(e['password'].value)) {
		alert("Please ensure that your password has between 6 and 9 characters including at least 2 numbers!");
		regform.password.value="";
		e['password'].focus();
		return false;
	}
	if (!al.test(e['password'].value)) {
		alert("Please ensure that your password has between 6 and 9 characters including at least 2 numbers!");
		regform.password.value="";
		e['password'].focus();
		return false;
	}
	if (document.regform.confirmPassword.value == null
			|| document.regform.confirmPassword.value == "") {
		alert("Re-enter Password is a required field, please re-enter your password.");
		regform.confirmPassword.focus();
		return false;
	}
	if (e['password'].value != e['confirmPassword'].value) {
		alert('Your passwords do not match. Please type more carefully.');
		regform.confirmPassword.value="";
		e['confirmPassword'].focus();
		return false;
	}

	if (document.regform.title.value == null
			|| document.regform.title.value == ""
			|| document.regform.title.value == "0") {
		alert("Title is a required field, please select one.");
		regform.title.focus();
		return false;
	}

	if (document.regform.firstName.value == null
			|| document.regform.firstName.value == "") {
		alert("First name is a required field, please enter your details.");
		regform.firstName.focus();
		return false;
	}

	if (document.regform.surName.value == null
			|| document.regform.surName.value == "") {
		alert("Surname is a required field, please enter your details.");
		regform.surName.focus();
		return false;
	}
	if (document.regform.companyName.value == null
			|| document.regform.companyName.value == "") {
		alert("Company name is a required field, please enter your details.");
		regform.companyName.focus();
		return false;
	}
	if (document.regform.sector.value == null
			|| document.regform.sector.value == ""
			|| document.regform.sector.value == "0") {
		alert("Sector is a required field, please select one.");
		regform.sector.focus();
		return false;
	}
	if (document.regform.approach.value == null
			|| document.regform.approach.value == ""
			|| document.regform.approach.value == "0") {
		alert("Please indicate if your approach to employee volunteering is global, national or regional.");
		regform.approach.focus();
		return false;
	}
	if (document.regform.bitcInfo.value == null
			|| document.regform.bitcInfo.value == ""
			|| document.regform.bitcInfo.value == "0") {
		alert("'How Did You Hear About Us?' is a required field, please select one.");
		regform.bitcInfo.focus();
		return false;
	}

	var chkBox = document.getElementsByTagName('input');

	for (i = 0; i < chkBox.length; i++) {

		if (chkBox[i] != null && chkBox[i].id == 'termsId') {
			if (!chkBox[i].checked) {
				alert("Please read the terms and conditions and tick the box before proceeding");
				return false;
				
			} 
		}

	}

	return true;

}

function popitup(url) {

	newwindow = window.open(url, 'name',
			"resizable=no,width=820,height=610,left=100,top=50,scrollbars=yes");

	if (window.focus) {
		newwindow.focus();
	}
	return false;
}

function echeck(str) {

	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	if (str.indexOf(at) == -1) {
		alert("Please check that your email address is entered correctly.");
		return false;
	}

	if (str.indexOf(at) == -1 || str.indexOf(at) == 0
			|| str.indexOf(at) == lstr) {
		alert("Please check that your email address is entered correctly.");
		return false;
	}

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0
			|| str.indexOf(dot) == lstr) {
		alert("Please check that your email address is entered correctly.");
		return false;
	}

	if (str.indexOf(at, (lat + 1)) != -1) {
		alert("Please check that your email address is entered correctly.");
		return false;
	}

	if (str.substring(lat - 1, lat) == dot
			|| str.substring(lat + 1, lat + 2) == dot) {
		alert("Please check that your email address is entered correctly.");
		return false;
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		alert("Please check that your email address is entered correctly.");
		return false;
	}

	if (str.indexOf(" ") != -1) {
		alert("Please check that your email address is entered correctly.");
		return false;
	}

	return true;
}

/*function ValidatePassword() {

 re = /[0-9][0-9]/;
 var e = regform.elements;
 if (e['password'].value != "") {
 if (e['password'].value.length < 6) {
 alert("Password must contain at least six characters!");
 e['password'].focus();
 return false;
 }
 }
 if (!re.test(e['password'].value)) {
 alert("Password must contain at least two numbers (0-9)!");
 e['password'].focus();
 return false;
 }

 return true; 
 }*/

/*
 * function ValidateConfirmPassword(){ var e = regform.elements; if
 * (e['password'].value != e['confirmPassword'].value) { alert('Your passwords
 * do not match. Please type more carefully.'); e['confirmPassword'].focus();
 * return false; } return true; }
 */
function setAction(target) {

	if (target == 0) {
		document.regform.submit();
	}
}

