function init(pErrorMsg) {
    if (pErrorMsg != "") {
        document.getElementById("formError").style.display = "block";
        document.getElementById("formError").innerHTML = pErrorMsg;
    } else {
        document.getElementById("formError").style.display = "none";
    }
}

function validate(pForm) {
    l_strWarning = ""

    if(document.getElementById('txtFirstName').value.trim() == '') l_strWarning += "<li><strong>First Name:</strong> Cannot be empty.</li>";
    if(!isAlpha(document.getElementById('txtFirstName').value)) l_strWarning += "<li><strong>First Name:</strong> Must contain alphabetic characters.</li>";

    if(document.getElementById('txtLastName').value.trim() == '') l_strWarning += "<li><strong>Last Name:</strong> Cannot be empty.</li>";
    if(!isAlpha(document.getElementById('txtLastName').value)) l_strWarning += "<li><strong>Last Name:</strong> Must contain alphabetic characters.</li>";

    if(document.getElementById('txtBusinessName').value.trim() == '') l_strWarning += "<li><strong>Business Name:</strong> Cannot be empty.</li>";

    if(document.getElementById('txtAddress1').value.trim() == '') l_strWarning += "<li><strong>Address:</strong> Cannot be empty.</li>";

    if (document.getElementById('radFormat_US').checked) {
        if (document.getElementById('txtCity').value.trim() == "") l_strWarning += "<li><strong>City:</strong> Cannot be empty</li>";
        if (document.getElementById('ddlState').options.selectedIndex < 1) l_strWarning += "<li><strong>State:</strong> Must Be selected</li>";
        if (!isValidZipCode(document.getElementById('txtZip').value.trim())) l_strWarning += "<li><strong>Zip code:</strong> Invalid zip code</li>";
    } 
    
    if (document.getElementById('radFormat_CN').checked) {
        if (document.getElementById('txtCanCity').value.trim() == "") l_strWarning += "<li><strong>City:</strong> Cannot be empty</li>";
        if (document.getElementById('ddlProvince').options.selectedIndex < 1) l_strWarning += "<li><strong>Province:</strong> Must Be selected</li>";
        if (document.getElementById('txtCanZip').value.trim() == "") l_strWarning += "<li><strong>Zip:</strong> Cannot be empty</li>";
    }
    
    if (document.getElementById('radFormat_IN').checked) {
        if (document.getElementById('ddlCountry').options.selectedIndex < 1) l_strWarning += "<li><strong>Country:</strong> Must Be selected</li>";
    }
    
    if (document.getElementById('txtDayPhone').value.trim() == "") l_strWarning += "<li><strong>Daytime Phone:</strong> Cannot be empty</li>";

    var l_strEmailWarning = '';
    l_strEmailWarning = emailCheck(document.getElementById('txtEmail').value, l_strEmailWarning);
    if (l_strEmailWarning != "") l_strWarning += "<li><strong>Email:</strong>" + l_strEmailWarning;

    if (l_strWarning != "") {
        document.getElementById("formError").style.display = "block";
        document.getElementById("formError").innerHTML= "<strong>The form cannot be submitted because\nthe following fields are invalid/incomplete:</strong><ul>" + l_strWarning + "</ul>";
        return false;
    } else {
        pForm.submit();
    }
}
