
function validate (myForm) {
	var msg, show;
	
	msg = "<p style=\"font-family: Arial, Helvetica, sans-serif;color: #56b24d;;font-size: 88%;font-weight: bold;\">The following required fields have not been completed:<br /><br />\n";
	show = false;
	
	// Test that each mandatory field has been filled in
	
	if (myForm.name.value == "") {
		msg = msg + "Name?<br />\n";
		show = true;
	}

	if (myForm.tel.value == "") {
		msg = msg + "Telephone No?<br />\n";
		show = true;
	}

	if (myForm.park.value == "") {
		msg = msg + "Park Name?<br />\n";
		show = true;
	}

	if (myForm.time.value == "") {
		msg = msg + "Best time to call?<br />\n";
		show = true;
	}


   	// Calls emailcheck function to ensure a valid email address has been entered
	
	if (emailcheck(myForm.email.value) == false) {
		msg = msg + "Email Address?<br /><br />\n";
		show = true;
	}
	

	msg = msg + '</p>';
	
	/* 	if a field has been left blank then display a message to the user otherwise
		submit the form to formmail
	*/
	
	if (show) {
		msgbox(msg);
		return false;
	}
	else {
		return true;
	}
}


function msgbox(msg) {
	// Calculate screen size so the message box is centered
	var ah = (screen.availHeight - 30 - 300) / 2;
    var aw = (screen.availWidth - 10 - 350) / 2;
	
	msgwindow=window.open("","","width=350,height=250,left=" + aw + ",top=" + ah);
	msgwindow.document.write('<title>Missing Details</title>');
	msgwindow.document.write(msg);
	msgwindow.document.write('<br><center><form><input type="button" value="Return to Form" onClick="window.close()"></form></center>');
	msgwindow.document.close();
	msgwindow.document.bgColor="white";
	msgwindow.document.body.font="Arial";
	return true;
}


function emailcheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if ((str==null)||(str=="")){
			return false
		}
	
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		 
		 if (str.indexOf(dot)+1==lstr){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}