function validateForm()
{
 if(!emailCheck(document.forms[0].email.value))
 {
    return false;
 }
 if(isEmpty(document.forms[0].firstname.value))
 {
   alert('Please include your first name');
   return false;
 }
 if(isEmpty(document.forms[0].surname.value))
 {
   alert('Please include your surname');
   return false;
 }
 if(isEmpty(document.forms[0].companyname.value))
 {
   alert('Please include your company name');
   return false;
 }
 if(isEmpty(document.forms[0].companyaddress.value))
 {
   alert('Please include your company address');
   return false;
 }
 if(isEmpty(document.forms[0].phone.value))
 {
   alert('Please include your phone number');
   return false;
 }
 return true;
}

function isEmpty(checkString)
{
  if(checkString == "")
  {
    return true;
  }
  else
  {
    return false;
  }
}

function emailCheck (emailStr) {

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 + ")"
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

if (user.match(userPat)==null) {
    // user is not valid
    alert("Email address error - the username doesn't seem to be valid.")
    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(" Email address error - destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Email address error - the domain name doesn't seem to be valid.")
    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>3) {
   // the address must end in a two letter or three letter word.
   alert("The email address must end in a three-letter domain, or two letter country.")
   return false
}

if (domArr[domArr.length-1].length==2 && len<3) {
  // var errStr="The email address ends in two characters, which is a country"
   //errStr+=" code.  Country codes must be preceded by "
  // errStr+="a hostname and category (like com, co, pub, pu, etc.)"
  // alert(errStr)
 //  return false
}

if (domArr[domArr.length-1].length==3 && len<2) {
   var errStr="The email address is missing a hostname!"
   alert(errStr)
   return false
}

return true;
}
