function setFocusContact(){
	document.form.firstname.focus();
}
function setFocusLogin(){
	document.frmLogin.username.focus();
}
function setFocusPwd(){
	document.pwdforgot.username.focus();
}
function setFocusReg() {
	document.frmReg.firstname.focus();
}
function setFocusRegEmail() {
	document.frmReg.username.focus();
}
function setFocusEvent() {
	document.form1.name.focus();
}
function setFocusNews() {
	document.form2.headline.focus();
}

function validate(theForm){

	var OK = 1;
	var sMsg = 'The following errors occurred:\n';

	if (theForm.enquiry.value == ''){
		sMsg = sMsg + ' - no enquiry message supplied\n';
		theForm.enquiry.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.email.value==''){ 
		sMsg = sMsg + ' - no email address supplied\n'; 
		theForm.email.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.email.value != ''){
		if(checkEmail(theForm.email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.email.value);
			theForm.email.focus();
			theForm.valid.value = 0;
			OK = 0;
		}
	}
	if(theForm.lastname.value==''){
		OK = 0;
		sMsg = sMsg + ' - no lastname supplied\n';
		theForm.lastname.focus();
		theForm.valid.value = 0;
	}
	if(theForm.firstname.value==''){
		OK = 0;
		sMsg = sMsg + ' - no firstname supplied\n';
		theForm.firstname.focus();
		theForm.valid.value = 0;
	}

	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateEmail(theForm){

	var OK = 1;
	var sMsg = 'The following error occurred:\n\n';

	if (theForm.email.value==''){ 
		sMsg = sMsg + ' - no email address supplied\n'; 
		theForm.email.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.email.value != ''){
		if(checkEmail(theForm.email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.email.value);
			theForm.email.focus();
			theForm.valid.value = 0;
			OK = 0;
		}
	}
	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

// email

function checkEmail(strng) {
var error="";
//if (strng == "") {
//   error = "You didn't enter an email address.\n";
//}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = " - enter a valid email address\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = " - email address contains illegal characters.\n";
       }
    }
return error;    
}


function validateForm1(theForm){

	var OK = 1;
	var sMsg = 'The following errors occurred:\n';

	if(theForm.org_email.value==''){
		OK = 0;
		sMsg = sMsg + ' - no organisation email address supplied\n';
		theForm.org_email.focus();
		theForm.valid.value = 0;
	}
	if (theForm.org_email.value != ''){
		if(checkEmail(theForm.org_email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.org_email.value);
			theForm.org_email.focus();
			theForm.valid.value = 0;
			OK = 0;
		}
	}
	if(theForm.org_phone.value==''){
		OK = 0;
		sMsg = sMsg + ' - no organisation phone number supplied\n';
		theForm.org_phone.focus();
		theForm.valid.value = 0;
	}
	if (theForm.org_desc.value.length > 4000){
		sMsg = sMsg + ' - organisation description too long\n';
		theForm.org_desc.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if(theForm.org.value==''){
		OK = 0;
		sMsg = sMsg + ' - no organisation supplied\n';
		theForm.org.focus();
		theForm.valid.value = 0;
	}
	if(theForm.website.value==''){
		OK = 0;
		sMsg = sMsg + ' - no website supplied\n';
		theForm.website.focus();
		theForm.valid.value = 0;
	}
	if(theForm.country.value==''){
		OK = 0;
		sMsg = sMsg + ' - no country supplied\n';
		theForm.country.focus();
		theForm.valid.value = 0;
	}
	if(theForm.town.value==''){
		OK = 0;
		sMsg = sMsg + ' - no town supplied\n';
		theForm.town.focus();
		theForm.valid.value = 0;
	}
	if(theForm.time.value==''){
		OK = 0;
		sMsg = sMsg + ' - no event time supplied\n';
		theForm.time.focus();
		theForm.valid.value = 0;
	}
	if(theForm.time.value.length > 255){
		OK = 0;
		sMsg = sMsg + ' - event time text supplied too long\n';
		theForm.time.focus();
		theForm.valid.value = 0;
	}
	if(theForm.venue.value==''){
		OK = 0;
		sMsg = sMsg + ' - no event venue supplied\n';
		theForm.venue.focus();
		theForm.valid.value = 0;
	}
	if(theForm.venue.value.length > 255){
		OK = 0;
		sMsg = sMsg + ' - event venue text supplied too long\n';
		theForm.venue.focus();
		theForm.valid.value = 0;
	}
	if(theForm.description.value==''){
		OK = 0;
		sMsg = sMsg + ' - no event description supplied\n';
		theForm.description.focus();
		theForm.valid.value = 0;
	}
	if(theForm.description.value.length > 2000){
		OK = 0;
		sMsg = sMsg + ' - event description text supplied too long\n';
		theForm.description.focus();
		theForm.valid.value = 0;
	}
	if(theForm.name.value==''){
		OK = 0;
		sMsg = sMsg + ' - no event name supplied\n';
		theForm.name.focus();
		theForm.valid.value = 0;
	}
	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateForm2(theForm){

	var OK = 1;
	var sMsg = 'The following errors occurred:\n';

	if (theForm.description.value == ''){
		sMsg = sMsg + ' - no news text supplied\n';
		theForm.description.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.description.value.length > 4000){
		sMsg = sMsg + ' - news text supplied too long\n';
		theForm.description.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if(theForm.headline.value==''){
		OK = 0;
		sMsg = sMsg + ' - no headline supplied\n';
		theForm.headline.focus();
		theForm.valid.value = 0;
	}

	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateForm3(theForm){

	var OK = 1;
	var sMsg = 'The following errors occurred:\n';

	if(theForm.country.value==''){
		OK = 0;
		sMsg = sMsg + ' - no country supplied\n';
		theForm.country.focus();
		theForm.valid.value = 0;
	}
	if(theForm.postcode.value==''){
		OK = 0;
		sMsg = sMsg + ' - no postcode supplied\n';
		theForm.postcode.focus();
		theForm.valid.value = 0;
	}
	if(theForm.town.value==''){
		OK = 0;
		sMsg = sMsg + ' - no town supplied\n';
		theForm.town.focus();
		theForm.valid.value = 0;
	}
	if(theForm.address1.value==''){
		OK = 0;
		sMsg = sMsg + ' - no address supplied\n';
		theForm.address1.focus();
		theForm.valid.value = 0;
	}
	if(theForm.org.value==''){
		OK = 0;
		sMsg = sMsg + ' - no organisation supplied\n';
		theForm.org.focus();
		theForm.valid.value = 0;
	}
	if(theForm.position.value==''){
		OK = 0;
		sMsg = sMsg + ' - no job title supplied\n';
		theForm.position.focus();
		theForm.valid.value = 0;
	}
	if(theForm.password.value.length < 4){
		OK = 0;
		sMsg = sMsg + ' - min password length is 4 characters\n';
		theForm.password.focus();
		theForm.valid.value = 0;
	}
	if(theForm.password.value!==theForm.password2.value){
		OK = 0;
		sMsg = sMsg + ' - passwords supplied do not match\n';
		theForm.password2.focus();
		theForm.valid.value = 0;
	}	
	if(theForm.email.value==''){
		OK = 0;
		sMsg = sMsg + ' - no organisation email address supplied\n';
		theForm.email.focus();
		theForm.valid.value = 0;
	}
	if (theForm.email.value != ''){
		if(checkEmail(theForm.email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.email.value);
			theForm.email.focus();
			theForm.valid.value = 0;
			OK = 0;
		}
	}
	if(theForm.surname.value==''){
		OK = 0;
		sMsg = sMsg + ' - no lastname supplied\n';
		theForm.surname.focus();
		theForm.valid.value = 0;
	}
	if(theForm.firstname.value==''){
		OK = 0;
		sMsg = sMsg + ' - no firstname supplied\n';
		theForm.firstname.focus();
		theForm.valid.value = 0;
	}

	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateComment(theForm){

	var OK = 1;
	var sMsg = 'The following errors occurred:\n';

	if (theForm.comment.value == ''){
		sMsg = sMsg + ' - no comment supplied\n';
		theForm.comment.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.comment.value.length > 2000){
		sMsg = sMsg + ' - comment text supplied too long\n';
		theForm.comment.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.email.value != ''){
		if(checkEmail(theForm.email.value) != "") {
			sMsg = sMsg + checkEmail(theForm.email.value);
			theForm.email.focus();
			theForm.valid.value = 0;
			OK = 0;
		}
	}
	if(theForm.alias.value==''){
		OK = 0;
		sMsg = sMsg + ' - no name supplied\n';
		theForm.alias.focus();
		theForm.valid.value = 0;
	}

	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateArticle(theForm){

	var OK = 1;
	var sMsg = 'The following errors occurred:\n';

	if (theForm.text.value == ''){
		sMsg = sMsg + ' - no article supplied\n';
		theForm.text.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	if (theForm.text.value.length > 5000){
		sMsg = sMsg + ' - article text supplied too long\n';
		theForm.text.focus(); 
		theForm.valid.value = 0;
		OK = 0;
	}
	
	if(theForm.title.value==''){
		OK = 0;
		sMsg = sMsg + ' - no title supplied\n';
		theForm.title.focus();
		theForm.valid.value = 0;
	}

	if (OK==1) {
		theForm.valid.value = 1;
		return true;
	} else {
		alert(sMsg);
		return false;
	}
}

function validateLogin(Form){
	var LoginForm = Form;
	var OK = 1;
	var sMsg = 'Please check:\n';
	
	if (LoginForm.password.value == '') {
	    OK = 0;
	    sMsg = sMsg + '- no password supplied\n';
		LoginForm.password.focus();
	}
    else if ((LoginForm.password.value.length < 5) || (LoginForm.password.value.length > 20)) {
	   OK = 0;
       sMsg = sMsg + '- password is the wrong length\n';
	   LoginForm.password.focus();
    }
	
	if(LoginForm.username.value==''){
		OK = 0;
		sMsg = sMsg + '- no username supplied\n';
		LoginForm.username.focus();
	}
    else if ((LoginForm.username.value.length < 4) || (LoginForm.username.value.length >= 50)) {
        OK = 0;
	    sMsg = sMsg +  '- username is the wrong length\n';
	    LoginForm.username.focus();
    }
	
	if (OK == 0){
	   alert(sMsg);
	   return false;
	} 
	else
	{ return true; }
}
	
// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length > 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}
