
function validate(form) {
  var FirstName = document.getElementById('FirstName').value;
  var LastName = document.getElementById('LastName').value;
  var Email = document.getElementById('Email').value;
  var Company = document.getElementById('Company').value;
  var Telephone = document.getElementById('Telephone').value;
  var Message = document.getElementById('Message').value;
  var Code = document.getElementById('security_code').value;
  
  var NameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/; 
  var CompanyRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;  
  var EmailRegex = /^[a-z\d]+([\.\-_][a-z\d]+)*@[a-z\d]+([\.\-_][a-z\d]+)*\.[a-z]{2,5}/i;                  
  var TelephoneRegex = /(\(\d{3}\))|\d{3}[ \.-]?\d{3}[ \.-]?\d{4}/; 
  var MessageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  
  if(FirstName == "") {
    alert("You must enter your first name.");
	document.comments.FirstName.focus();
    return false;
  }
  if(!FirstName.match(NameRegex)) {
    alert("You have entered an invalid name.");
	document.comments.FirstName.focus();
    return false;
  }
  if(LastName == "") {
     alert("You must enter your last name.");
	 document.comments.LastName.focus();
    return false;
  }
  if(!LastName.match(NameRegex)) {
    alert("You have entered an invalid name.");
	document.comments.LastName.focus();
    return false;
  }
  if(Email == "") {
   alert("You must enter your email.");
   document.comments.Email.focus();
   return false;
  }
  if(!Email.match(EmailRegex)) {
    alert("You have entered an invalid email.");
	document.comments.Email.focus();
    return false;
  }
  if(Company != "" && !Company.match(CompanyRegex)) {
    alert("You have entered an invalid format.");
	document.comments.Company.focus();
    return false;
  }
  if(Telephone == "") {
   alert("You must enter your phone number.");
   document.comments.Telephone.focus();
   return false;
  }
  if(!Telephone.match(TelephoneRegex)) {
    alert("You have entered an invalid number.");
	document.comments.Telephone.focus();
    return false;
  }
  if(document.comments.Contact.value == "---")
  {
     alert("Please select a time to speak.");
     document.comments.Contact.focus();
     return false;
  }
  if(document.comments.Day.value == "---")
  {
     alert("Please select a day to speak.");
     document.comments.Day.focus();
     return false;
  }
  if(document.comments.Date1.value == "---")
  {
     alert("Please select a date to speak.");
     document.comments.Date1.focus();
     return false;
  }  
  if(Message == "") {
    alert("You must enter a message.");
	document.comments.Message.focus();
    return false;
  }
  if(Message.match(MessageRegex)) {
    alert("You have entered an invalid message.");
	document.comments.Message.focus();
    return false;
  }
  if(Code == "") {
   alert("You must enter the security code.");
   document.comments.security_code.focus();
   return false;
  }
  return true;
}

function CheckTA()
{
  var max=300, texthalt;

  texthalt=document.getElementById('Message').value;

  if (texthalt.length >= max)
	{
	document.getElementById('Message').value=texthalt.substring(0,max);
	document.getElementById('Message').value.blur();
	}
}

