
function validateForm() {

        if (prenota.nome.value == "") { alert("Il campo Nome è vuoto."); return false; }
        if (prenota.cognome.value == "") { alert("Il campo Cognome è vuoto."); return false; } 
        if (prenota.email.value == "") { alert("Il campo Email è vuoto."); return false; } 
        else {
                if (echeck(prenota.email.value)==false){return false}
        }

        if (prenota.telefono.value == "") { alert("Il campo Telefono è vuoto."); return false; } 
        if (prenota.arrivo.value == "") { alert("Il campo Arrivo è vuoto."); return false; } 
        if (prenota.partenza.value == "") { alert("Il campo Partenza è vuoto."); return false; } 
        return true;
}

function echeck(str) {

                var at="@"
                var dot="."
                var lat=str.indexOf(at)
                var lstr=str.length
                var ldot=str.indexOf(dot)
                if (str.indexOf(at)==-1){
                   alert("Email non è corretto")
                   return false
                }

                if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
                   alert("Email non è corretto")
                   return false
                }

                if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
                    alert("Email non è corretto")
                    return false
                }

                 if (str.indexOf(at,(lat+1))!=-1){
                    alert("Email non è corretto")
                    return false
                 }

                 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
                    alert("Email non è corretto")
                    return false
                 }

                 if (str.indexOf(dot,(lat+2))==-1){
                    alert("Email non è corretto")
                    return false
                 }

                 if (str.indexOf(" ")!=-1){
                    alert("Email non è corretto")
                    return false
                 }

                 return true
}
