function checkFormFields(){

if (document.forms[0].xfirstname.value.length == 0){

alert('Please enter your first name.');

document.forms[0].xfirstname.focus();

return false;

}

if (document.forms[0].xlastname.value.length == 0){

alert('Please enter your last name.');

document.forms[0].xlastname.focus();

return false;

}

var emailStr=document.forms[0].xemail.value

var emailPat=/^(.+)@(.+)$/

var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

var validChars="\[^\\s" + specialChars + "\]"

var firstChars=validChars

var quotedUser="(\"[^\"]*\")"

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

var atom="(" + firstChars + validChars + "*" + ")"

var word="(" + atom + "|" + quotedUser + ")"

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

var matchArray=emailStr.match(emailPat)

if (matchArray==null) {

alert("The email address you entered is not valid, please verify.")

document.forms[0].xemail.focus();

return false;

}

var user=matchArray[1]

var domain=matchArray[2]

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The email address you entered is not valid, please verify.")

document.forms[1].xemail.focus();

return false;

}

var IPArray=domain.match(ipDomainPat)

if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {

if (IPArray[i]>255) {

alert("The email address you entered is not valid, please verify.")

document.forms[0].xemail.focus();

return false;

}

}

return true

}

// Domain is symbolic name

var domainArray=domain.match(domainPat)

if (domainArray==null) {

alert("The email address you entered is not valid, please verify.")

document.forms[0].xemail.focus();

return false;

}

var atomPat=new RegExp(atom,"g")

var domArr=domain.match(atomPat)

var len=domArr.length

if (domArr[domArr.length-1].length<2 || 

domArr[domArr.length-1].length>4) {

// the address must end in a two letter or three letter word.

alert("Your email address must end in a valid domain extension.")

document.forms[1].xemail.focus();

return false;

}

if (domArr[domArr.length-1].length<=3 && len<2) {

var errStr="The email address you entered is not valid, please verify."

alert(errStr)

document.forms[1].xemail.focus();

return false;

}

return true

}