function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateName(theForm.name);
  reason += validateEmail(theForm.email);

	if (reason != "") {
    alert("Some fields need correction:\n\n" + reason );
    return false;
  }
  return true;
}


function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#c2efcb'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateName(fld) {
    var error = "";
 
    if (fld.value == "" || fld.value == "Your Full Name") {
        fld.style.background = '#c2efcb'; 
        error = "Please enter your full name.\n\n";
	} else if (fld.value.length < 2) {
        fld.style.background = '#c2efcb';
        error = "Please enter your full name.\n\n";
    } else {
        fld.style.background = 'White';
    }
    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 = /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	var telusEmail = /@telus\.com/i;
   
    if (fld.value == "" || fld.value == "Your Email") {
        fld.style.background = '#c2efcb';
        error = "Please enter your email address.\n\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#c2efcb';
        error = "The email address you entered is not valid.\n\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#c2efcb';
        error = "Your email address contains illegal characters.\n\n";
	} else if (fld.value.match(telusEmail)) {
		fld.style.background = '#c2efcb';
        error = "You have entered a telus.com email address:\n" + fld.value + "\n\nTelus' Corporate Policy disallows the use of your work email address\nfor signing up. Sorry. Please use a different email address.\n\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}