function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateFName(theForm.first_name);
  reason += validateLName(theForm.last_name);
  reason += validatePhone(theForm.phone);
  reason += validateCompany(theForm.company);
  reason += validateFreeEmail(theForm.email);
  


  if (reason != "") {
    alert("Please complete all the required fields.\n\n" + reason );
    return false;
  }
  return true;
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#ffc9bb'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateFName(fld) {
    var error = "";
 
    if (fld.value == "" || fld.value == "Your First Name") {
        fld.style.background = '#ffc9bb'; 
        error = "Please enter your First Name.\n";
	} else if (fld.value.length < 2) {
        fld.style.background = '#c2efcb';
        error = "Please enter your First Name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCompany(fld) {
    var error = "";
 
    if (fld.value == "" || fld.value == "Your Company Name") {
        fld.style.background = '#ffc9bb'; 
        error = "Please enter your Company.\n";
	} else {
        fld.style.background = 'White';
    }
    return error;
}


function validateLName(fld) {
    var error = "";
 
    if (fld.value == "" || fld.value == "Your Last Name") {
        fld.style.background = '#ffc9bb'; 
        error = "Please enter your Last Name.\n";
	} else if (fld.value.length < 2) {
        fld.style.background = '#c2efcb';
        error = "Please enter your Last Name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    var error = "";
 
    if (fld.value == "" || fld.value == "Your Phone Number") {
        fld.style.background = '#ffc9bb'; 
        error = "Please enter your Phone Number.\n";
	} else if (fld.value.length < 10) {
        fld.style.background = '#c2efcb';
        error = "Please enter a 10 digit Phone Number.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateFreeEmail(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;
	var hotmailEmail = /@hotmail\.com/i;
	var liveEmail = /@live\.com/i;
	var gmailEmail = /@gmail\.com/i;
	var yahooEmail = /@yahoo\.com/i;
	var sympaticoEmail = /@sympatico\.ca/i;
	var rogersEmail = /@rogers\.com/i;
   
    if (fld.value == "" || fld.value == "Your Email") {
        fld.style.background = '#ffc9bb';
        error = "Please enter your Email Address.\n\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#ffc9bb';
        error = "The email address you entered is not valid.\n\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#ffc9bb';
        error = "Your email address contains illegal characters.\n\n";
	} else if (fld.value.match(telusEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Telus 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 if (fld.value.match(hotmailEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Hotmail email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work  email address.\n\n";
	} else if (fld.value.match(liveEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Windows Live email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work  email address.\n\n";
	} else if (fld.value.match(gmailEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a gMail email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work  email address.\n\n";
	} else if (fld.value.match(yahooEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Yahoo email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work email address.\n\n";
	} else if (fld.value.match(sympaticoEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Sympatico email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work email address.\n\n";
	} else if (fld.value.match(rogersEmail)) {
		fld.style.background = '#ffc9bb';
        error = "You have entered a Rogers email address:\n" + fld.value + "\n\nTo protect our intellectual  property we require that you use your Business / Office / Work email address for signing up. \n\nSorry. Please use your Business / Office / Work email address.\n\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}