<!--

if(window.attachEvent)
    window.attachEvent("onload",setListeners);

  function setListeners(){
    inputList = document.getElementsByTagName("INPUT");
    for(i=0;i<inputList.length;i++){
      inputList[i].attachEvent("onpropertychange",restoreStyles);
      inputList[i].style.backgroundColor = "";
    }
    selectList = document.getElementsByTagName("SELECT");
    for(i=0;i<selectList.length;i++){
      selectList[i].attachEvent("onpropertychange",restoreStyles);
      selectList[i].style.backgroundColor = "";
    }
  }

  function restoreStyles(){
    if(event.srcElement.style.backgroundColor != "")
      event.srcElement.style.backgroundColor = "";
  }

function validateFormOnSubmit(contactform) {
	var reason = "";
	
	reason += validateName(contactform.name);
	reason += validateEmail(contactform.email);
	reason += validatePhone(contactform.tel);
	reason += validateMessage(contactform.enquiry);
	      
	  if (reason != "") {
	    alert("The fields highlighted in red text correction:\n\n" + reason);
	    return false;
	  }
	
	  return true;
	}
	
	function validateMessage(fld) {
	    var error = "";
	 
	    if (fld.value.length == 0) {
	        fld.style.color = 'Red'; 
	        error = "You didn't enter a message.\n"
	    } else if (fld.value == "Please enter the nature of your enquiry") {
		fld.style.color = 'Red'; 
	        error = "You didn't enter a message.\n";    
	    } else {
	        fld.style.color = '#898989';
	    }
	    return error;  
	}
	
	function validateName(fld) {
	    var error = "";
	    
	    if (fld.value == "") {
	        fld.style.color = 'Red'; 
	        error = "You didn't enter a name.\n";
	    } else if (fld.value == "Name") {
		fld.style.color = 'Red'; 
	        error = "You didn't enter a name.\n";    
	   } else {
	        fld.style.color = '#898989';
	    }
	    return error;
	}
	
	function trim(s)
	{
	  return s.replace(/^\s+|\s+$/, '');
	}
	
	function validateEmail(fld) {
	    var error="";
	    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
	    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	   
	    if (fld.value == "") {
	        fld.style.color = 'Red';
	        error = "You didn't enter an email address.\n";
	    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
	        fld.style.color = 'Red';
	        error = "Please enter a valid email address.\n";
	    } else if (fld.value.match(illegalChars)) {
	        fld.style.color = 'Red';
	        error = "The email address contains illegal characters.\n";
	    } else {
	        fld.style.color = '#898989';
	    }
	    return error;
	}
	
	function validatePhone(fld) {
	    var error = "";
	    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    
	
	   if (fld.value == "") {
	        error = "You didn't enter a phone number.\n";
	        fld.style.color = 'Red';
	    } else if (isNaN(parseInt(stripped))) {
	        error = "The phone number contains illegal characters.\n";
	        fld.style.color = 'Red';
	    } else if (!(stripped.length == 11)) {
	        error = "The phone number is the wrong length. Make sure you included an area code.\n";
	        fld.style.color = 'Red';
	    } else {
		fld.style.color = '#898989';    
	    }
	    return error;
	}
	
	
  
  
//-->


