function validateForm() {
    var name = document.getElementById('name');
    var phone = document.getElementById('phone');
    var email = document.getElementById('email');
    var company = document.getElementById('company');

    //cehck that data has being entered.
    if (name.value == '') {
        alert('Please enter a name.');
        name.focus();
        return false;
    }

    if (phone.value == '') {
        alert ('Please enter a contact number.');
        phone.focus();
        return false;
    }

    if (email.value == '') {
        alert('Please enter an email address.');
        email.focus();
        return false;
    }

    if (company.value == '') {
        alert('Please enter a company name.');
        company.focus();
        return false;
    }

    // Check for valid phone number (just check for invliad characters)
    if (isNaN(phone.value)) {
        alert('Please enter a valid phone number.');
        phone.focus();
        return false;
    }

    // Check that email is valid.
    if (!isValidEmail(email.value)) {
        alert('Please enter a valid email address.');
        email.focus();
        return false;
    }

    // Check that a product was chosen
    if (!document.getElementById('product_SM').checked
      && !document.getElementById('product_WebSMS').checked
      && !document.getElementById('product_E2S').checked
      && !document.getElementById('product_API').checked) {
        alert('Please choose a product to trial.');
        document.getElementById('product_SM').focus();
        return false;

    }

    return true;
}

//function to check valid email address
function isValidEmail(strEmail){
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    strEmail = document.forms[0].email.value;

    // search email text for regular exp matches
    if (strEmail.search(validRegExp) == -1) {
        return false;
    } 
    return true; 
}
