// JavaScript Document

function validate(form)  {
  	msg = "Please fill in the following required fields:\n";  
	if(document.form.Name.value=="") {msg+="\nName";}
	if(document.form.Message.value == "") {msg+="\nMessage";}
	// email validation and verification
	if(document.form.EmailFrom.value=="") {msg+="\nEmail";}

// ----- check for spaces which are invalid -----

var sp = document.form.EmailFrom.value.indexOf(" ")
if (sp != -1) {
    alert("Invalid email address, can't use spaces!")

    document.form.EmailFrom.focus();
    return false
   }


// ----- is there a @ ?-----

var str = document.form.EmailFrom.value.indexOf("@")
var c = str+1
if (str == -1) {
    alert("Invalid email address, no @!")
    document.form.EmailFrom.focus();
    return false
   }

// ----- is there a period? -----

var pr = document.form.EmailFrom.value.indexOf(".",str)
if (pr == -1) {
    alert("Invalid email address, no period, '.', or period before the @")
    document.form.EmailFrom.focus();
    return false
   }

// ----- are there at least 2 characters between the @ and . -----


if (pr - str - 1 < 2) {
  alert("There must be at least 2 characters between the '@' and '.'")
   return false
}


// ----- are there at least 2 characters after the period? -----

var x = document.form.EmailFrom.value.length - pr -1
if ( x < 2 ) {
  alert("There must be at least 2 characters after the period!")
   return false;
                        }

           if (msg != "Please fill in the following required fields:\n") {
                            alert(msg);
            return false; 
                        } else { 
                            return true; 
                        }
                    }

