// Arun District Council
//
// Date: 24th April 2008. Author Mike Knight
//
function FormOnLoad() {
	if (location.search.indexOf("mysql=4525") > 0) {
		var now = new Date();
		var today = "";
		if (now.getDate() < 10) { today = "0" + now.getDate(); } else { today = now.getDate(); }
		today = today + "-";
		if ((now.getMonth() + 1) < 10) { today = today + "0" + (now.getMonth() + 1) ; } else { today = today + (now.getMonth() + 1); }
		today = today + "-" + now.getFullYear();
		document.getElementById("today").innerHTML = today;
		document.getElementById("personName").select();
		document.getElementById("personName").focus();
	}
}
function ValidEmail(emailAddress) {
	if (emailAddress == "") {
		return true;
	} else {
		if (emailAddress.length < 3) {
			return false;
		} else {
			if (emailAddress.indexOf("@") < 1) {
				return false;
			} else {
				return true;
			}
		}
	}
}
function ValidateEcoTownForm() {
	var wordArray = document.getElementById("comments").value.split(" ");
	if (document.getElementById("personName").value == "") {
		alert("Please enter your name");
		document.getElementById("personName").select();
		document.getElementById("personName").focus();
	} else {
		if (document.getElementById("address1").value == "") {
			alert("Please enter your address");
			document.getElementById("address1").select();
			document.getElementById("address1").focus();
		} else {
			if (document.getElementById("postcode").value == "") {
				alert("Please enter your postcode");
				document.getElementById("postcode").select();
				document.getElementById("postcode").focus();
			} else {
				if (document.getElementById("comments").value == "") {
					alert("Please enter your comments");
					document.getElementById("comments").select();
					document.getElementById("comments").focus();
				} else {
					if (wordArray.length > 250) {
						alert("You are limited to a maximum of 250 words");
						document.getElementById("comments").select();
						document.getElementById("comments").focus();
					} else {
						if (!ValidEmail(document.getElementById("email").value)) {
							alert("Please enter a valid email address");
							document.getElementById("email").select();
							document.getElementById("email").focus();
						} else {
							document.ecotownForm.submit();
						}
					}
				}
			}
		}
	}
}
