
function $(id) {
    return document.getElementById(id);
}

function validateContactForm() {
    var title = $('title').getElementsByTagName('INPUT');
    var check_count = 0;
    for (var i = 0; i < title.length; i++) {
        if (title[i].checked) {
            check_count++;
        }
    }
    if (!check_count) {
        alert('Please select a title.');
        return false;
    }
    if (!$('firstname').value.length) {
        alert('Please enter a first name.');
        $('firstname').focus();
        return false;
    }
    if (!$('lastname').value.length) {
        alert('Please enter a last name.');
        $('lastname').focus();
        return false;
    }
    if (!$('organization').value.length) {
        alert('Please enter an organization/company name.');
        $('organization').focus();
        return false;
    }
    if ($('country').selectedIndex == '0') {
        alert('Please select a country.');
        $('country').focus();
        return false;
    }
    if (!$('email').value.length) {
        alert('Please enter an email.');
        $('email').focus();
        return false;
    }
    var regex = /^[a-z0-9\._-]+@([a-z0-9_-]+\.)+[a-z]{2,6}$/i;
    if (!regex.test($('email').value)) {
        alert('Please enter a valid email.');
        $('email').focus();
        return false;
    }
    return true;
}

function validateWhitePapersForm() {
    var checked_count = 0;
    var checkboxes = $('articles').getElementsByTagName('INPUT');
    for (var i = 0; i < checkboxes.length; i++) {
        if (checkboxes[i].checked) {
            checked_count++;
        }
    }
    if (checked_count == 0) {
        alert('Please select at least one article.');
        return false;
    }
    return true;
}


