//###INSERT FROM HERE BETWEEN YOUR JAVASCRIPT TAGS######
//########################################################

//Insert Required fields within quotes separated by comma. Make sure to use the correct name as used in the
//form fields. Do not change the name of the email field from "Email" as it is used in the
//validation routine	
required = new Array("Nome", "Cognome", "Indirizzo" , "Email")

//Validation Routines
//##############DO NOT CHANGE FROM HERE##################
var emailregex = /^[a-z][a-z\-\_0-9\.]+@[a-z-_0-9\.]+\.[a-z]{2,4}$/i
var notgiven = ""
//============Check if a field is blank================
function isBlank(s) {
 var len=s.length
 var i
 for(i=0;i<len;++i) {
  if(s.charAt(i)!=" ") return false
 }
 return true
}

//================Email Address validation routine=========
function correct_email(str) {
        return emailregex.test(str)
}

function validateEmail() {
	if(!correct_email(document.forms[0].Email.value)) {
		alert("La Email inserita non risulta valida")
		document.forms[0].Email.focus()
		document.forms[0].Email.select()
		return false	
	}
	return true
}

//==============Check if a field is blank===========

function validate(fieldName,fieldValue) {
	if(isBlank(fieldValue)) {
		notgiven += fieldName + ", "	
 }
}

//=Validate fields and send Form if OK or generate proper alert message=====
function validateForm() {
validation = true
for(var i=0; i < required.length; ++i) {
	ele = eval("document.forms[0]." + required[i])
	 validate(ele.name, ele.value)
}
if (notgiven != "") {
	notgiven += " devono essere compilati."
	alert(notgiven)
	notgiven = ""	
	validation = false
}
if (!validateEmail()) {
	validation = false
}
if (!validation) {
	return false
}
else document.forms[0].submit()
}
//########################################################
//####INSERT UPTO HERE BETWEEN YOUR JAVASCRIPT TAGS#####
//-->