
function validateFormOnSubmit(theForm) {
var reason = "";

	
  reason += validateSurname(theForm.surname);
  reason += validateAddress(theForm.address);
  reason += validatePhone(theForm.phone);
      
  if (reason != "") {
    
	alert("Please complete the following contact information to help us deal with your request:<br><br>\n" + reason);
    return false;
  }

  return true;
}



function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}


function validateSurname(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Please enter your Surname.<br>\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateAddress(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Please enter your Postcode.<br>\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Please enter your Phone Number.<br>\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


