//Reset contact form colours
function resetContactFormColours(theForm) {
	theForm.contact_firstname.style.background = '#FFF';
	theForm.contact_surname.style.background = '#FFF';
	theForm.contact_address1.style.background = '#FFF';
	theForm.contact_address2.style.background = '#FFF';
	theForm.contact_city.style.background = '#FFF';
	theForm.contact_county.style.background = '#FFF';
	theForm.contact_postalcode.style.background = '#FFF';
	theForm.contact_phone.style.background = '#FFF';
	theForm.contact_email.style.background = '#FFF';
	theForm.contact_contactmethod.style.background = '#FFF';
	theForm.contact_query.style.background = '#FFF';
}

//Validate an empty field
function validateEmpty(fld, helperMSG) {
    var error = "";
  
    if (fld.value.length == 0) {
        fld.style.background = '#FFD5D5'; 
        error = helperMSG
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;   
}

//Validate an empty combo box
function validateEmptyCombo(fld, helperMSG) {
    var error = "";
  
    if (fld.value == 0) {
        fld.style.background = '#FFD5D5'; 
        error = helperMSG
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;   
}

//Email validation
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.background = '#FFD5D5';
        error = "* You must enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#FFD5D5';
        error = "* You must enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#FFD5D5';
        error = "* The email address contains illegal characters.\n";
    } else {
        fld.style.background = '#FFFFFF';
    }
    return error;
}