function isValidEmail(emailAddress) {
   var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}
var FieldList = "";
var checkboxMessage=""
var HighLightColour = '#FFCCCC';
// Compulsary Field Checker
function checkCompulsory(form) {
var keyword="_compulsory";
if (document.images) {
 for (i=0;i<form.length;i++) {
   var tempobj=form.elements[i];  
   if (tempobj.name.substring((tempobj.name.length-keyword.length),(tempobj.name.length))==keyword.toString()) {
    //Type checker text / textarea / selectionbox
    //alert(tempobj.name)
    shortFieldName=tempobj.name.substring(0,tempobj.name.length-keyword.length);
    shortFieldName=shortFieldName.slice(5);
    shortFieldName=shortFieldName.replace("_"," ")
    if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==0)) {
     // Trims 'Form_' and '_compulsory' from names for display to user
     FieldList += shortFieldName + "\n";
     tempobj.style.backgroundColor=HighLightColour;
    } else if (tempobj.type=="checkbox"&&!tempobj.checked){
     if (checkboxMessage==''){
      checkboxMessage='\nPlease ensure that you have selected:\n';
     }
     tempobj.style.backgroundColor=HighLightColour
     checkboxMessage += shortFieldName+"\n";
    }
        }
  }
  
 }
}
function ValidateForm() {
var emailMessage = "";
 
alertMessage = "We did not get all the information we need from you.\n Please fill in the following field(s):\n\n";
// Check all compulsory fields are filled.
checkCompulsory(document.contactForm);
// Email validation.
if (document.contactForm.form_Email_compulsory.value == ""){
//FieldList = FieldList + "Email Address\n"; // Message to user.
} else {
 validEmail = isValidEmail(document.contactForm.form_Email_compulsory.value);
 if (validEmail == false) {
 document.contactForm.form_Email_compulsory.style.backgroundColor=HighLightColour;
 emailMessage = "\nPlease enter a valid email address"; // Message to user.
 }
};
 
// Submit form or display message.
if (FieldList == "" && emailMessage == ""){
document.contactForm.submit();
} else { 
   if (FieldList != "") {
      alertMessage += FieldList+checkboxMessage;
   }
 
   if (emailMessage != "") {
      alertMessage += emailMessage;
   }
   // Clear off existing messages
   FieldList = ''
   checkboxMessage = ''
   alert(alertMessage);
};
}