
function validateFormOnSubmit(theForm) {

var reason = "";

  reason += validateSurname(theForm.surname);
  reason += validatePostcode(theForm.postcode);
  reason += validatePhone(theForm.phone);
  
  /*if (theForm.mobile.length > 0)
  {
  reason += validateMobile(theForm.mobile);	
  }*/
 
 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;  
}

//SURNAME
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+$/, '');
}



//POSTCODE
function validatePostcode(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 stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

  	if (isNaN(parseInt(stripped))) {
        error = "Please enter your Phone Number.<br>\n";
        fld.style.background = 'Yellow';
	}
  
  	else if (!(stripped.length > 5 )) {
        error = "error, telephone number appears to be incorrect, please check...<br>\n";
        fld.style.background = 'Yellow';
    }
	else if (!(stripped.length < 15 )) {
        error = "error, telephone number appears to be incorrect, please check...<br>\n";
        fld.style.background = 'Yellow';
    }
	else {
        fld.style.background = 'White';
    }
	
    return error;
}
