function checkInput(status) {
	var allvars = _f_register.elements;
	var requiredList = '';
	var errorList = '';
	var notRequiredList = '';
	var tempvar;



	for (var i=0; i < allvars.length; i++) {
 	   tempvar = allvars[i].value;
	   if (allvars[i].required == "Y") {	

	       if ((tempvar.length < 1)) {  // check if the field is blank
		 errorList  += allvars[i].ename  + " - ";
		 errorList  += "Please enter a value \n";
		 continue;
		}
		if (tempvar.length < 3) {			// check that there are at least 3 chrs in each box
		 errorList  += allvars[i].ename  + " - ";
		 errorList  += "Please correct entry \n";
		 continue;
		}
	  }   // endif required = "Y"

		if (allvars[i].name =="_admin_contact_person") {    // check there are 2 names (first + surname) in the name box
		   var tempname = tempvar.split(' ');
		   if (tempname.length < 2) {
			 errorList  += allvars[i].ename  + " - ";
			 errorList  += "Please enter a first and last name \n";
		 	continue;
		   }
		}
		if (allvars[i].name == '_admin_address_1') {	// check that there are at least 2 words in the address
		  var tempadd = tempvar.split(' ')
	          if ((tempadd.length == 1) && (_f_register._admin_address_2.value.length < 5)) {
			 errorList  += allvars[i].ename  + " - ";
			 errorList  += "Please enter a street address \n";
		 	continue;
		  }
		}

		if (allvars[i].name == '_admin_postcode' || allvars[i].name == '_church_postcode') {	// check that the postcode seems properly formatted
		  if (tempvar.length < 5 || tempvar.length > 8) {
			 errorList  += allvars[i].ename  + " - ";
			 errorList  += "Please enter a valid postcode\n";			
			continue;
		  }
	  	  var pccheck = /^[A-Z]{1,2}\d+.*[A-Z]{2}$/i;
		  if (! tempvar.match(pccheck))
		  {
			 errorList  += allvars[i].ename  + " - ";
			 errorList  += "Please enter a valid postcode \n";			
		 	continue;
		  }
		} 

		if ((allvars[i].name == '_admin_tel_code') || ((allvars[i].name == '_church_tel_code') && (tempvar.length > 0))) {	// check for a valid phone code
		  if (((tempvar.substr(0,1) !='0') && (tempvar.substr(0,1) !='2')) && ((tempvar > 10000)  || (tempvar < 20))) {
			 errorList  += allvars[i].ename  + " - ";
			 errorList  += "Please enter a valid telephone code \n";			
		 	continue;

		  }
		} 
		if ((allvars[i].name == '_admin_tel') || ((allvars[i].name == '_church_telephone') && (tempvar.length > 0))) {	// check that there are at least 2 words in the address
		  if ((tempvar > 99999999)  || (tempvar < 100000) || (tempvar.substr(0,3) == "999")) {
			 errorList  += allvars[i].ename  + " - ";
			 errorList  += "Please enter a valid telephone number \n";			
		 	continue;
		  }
		} 

		if ((allvars[i].name == '_admin_email') || ((allvars[i].name == '_church_email') && (tempvar.length > 0))) {	// check for a correct email address
			var emuk = /^[a-z]+\d*@{1}\w+[.]{1}(\w*.?)[a-z]{2,3}(.uk)$/i;   // UK email addresses
			var emailall = tempvar.split(".")
			var emoth = /^[a-z]+\d*@{1}\w+[.]{1}(\w*.?)[a-z]{2,4}[^\.]/i;	// TLD email addresses (COM etc)

			 if (tempvar.match(emuk)) {
	  			 continue;
			 } else if (tempvar.match(emoth) && (emailall.length==2 || emailall.length==3)) {
	  			 continue;	
			 } else {
			  errorList  += allvars[i].ename  + " - ";
			  errorList  += "Please enter a valid UK email address \n";			
		 	 continue;
			}
		}
 	}

	if (errorList.length > 5) {
	 var msg  = "THERE ARE ERRORS ON YOUR FORM!\n";
	    msg += "==========================";
	    msg += "\n\nPlease correct the following items:\n\n";
	    msg += errorList + "\n\n";
	alert(msg);
	} else {
		_f_register._status.setAttribute("value",status);
		_f_register.submit();
	}
}

function help(id) {
   eval('document.all.help' + id + '.style.visibility="visible"');
}

function helphide(id) {
   eval('document.all.help' + id + '.style.visibility="hidden"');
}
