

function isEmailAddr (s){ 
	var rv = false
	if ((s == null) || (s.length == 0)) 
       	rv = false;
 	 else {
		var reEmail =/([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		
		rv = reEmail.test(s)
    }
	if(rv){
		return rv
	}else{
		return false
	}
}
 
function eventvalidation(theForm){
	if (theForm.name.value == ""){
    	alert("Please enter the event name.");
    	theForm.name.focus();
    	return (false);
  	}
	if (theForm.startdate.value == ""){
    	alert("Please enter the start date of the event.");
    	theForm.startdate.focus();
    	return (false);
  	}
	if (theForm.enddate.value == ""){
    	alert("Please enter the end date of the event.");
    	theForm.enddate.focus();
    	return (false);
  	}
	var startdate = new Date(theForm.startdate.value)
	var enddate = new Date(theForm.enddate.value)
	if(enddate < startdate){
    	alert("End date can't be earlier than start date");
    	theForm.enddate.focus();
    	return (false);
	}
	if (theForm.eventtime.value == ""){
    	alert("Please enter the start and end time of your event.\ne.g. 1am - 6pm");
    	theForm.eventtime.focus();
    	return (false);
  	}
	if (theForm.location.value == ""){
    	alert("Please enter the location of the event.");
    	theForm.location.focus();
    	return (false);
  	}
	if (theForm.public.checked){
		
		if (theForm.registrationdetails.value == ""){
		alert("Please enter the registration details.");
		theForm.registrationdetails.focus();
		return (false);
		}
   	}
	if (theForm.orgname.value == ""){
	alert("Please enter the organisers name.");
	theForm.orgname.focus();
	return (false);
	}
	if (!isEmailAddr(theForm.orgemail.value)){
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		theForm.orgemail.focus();
		return (false);
	}
	if (theForm.orgphone.value == ""){
	alert("Please enter the organisers phone number.");
	theForm.orgphone.focus();
	return (false);
	}
	return (true);
}

