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 (pForm.txtBusinessName.value.trim() == "") l_strWarning += "<li><strong>Business Name:</strong> Cannot be empty</li>";
    if (pForm.txtDistributorName.value.trim() == "") l_strWarning += "<li><strong>Distributor Name:</strong> Cannot be empty</li>";

    if (pForm.radFormat[0].checked) {
        if (pForm.txtCity.value.trim() == "") l_strWarning += "<li><strong>City:</strong> Cannot be empty</li>";
        if (pForm.ddlState.options.selectedIndex < 1) l_strWarning += "<li><strong>State:</strong> Must Be selected</li>";
        if (!isValidZipCode(pForm.txtZip.value.trim())) l_strWarning += "<li><strong>Zip code:</strong> Invalid zip code</li>";
    } 
    
    if (pForm.radFormat[1].checked) {
        if (pForm.txtCanCity.value.trim() == "") l_strWarning += "<li><strong>City:</strong> Cannot be empty</li>";
        if (pForm.ddlProvince.options.selectedIndex < 1) l_strWarning += "<li><strong>Province:</strong> Must Be selected</li>";
        if (pForm.txtCanZip.value.trim() == "") l_strWarning += "<li><strong>Zip:</strong> Cannot be empty</li>";
    }
    
    if (pForm.radFormat[2].checked) {
        if (pForm.ddlCountry.options.selectedIndex < 1) l_strWarning += "<li><strong>Country:</strong> Must Be selected</li>";
    }
    
    if (pForm.txtPhone.value.trim() == "") l_strWarning += "<li><strong>Phone:</strong> Cannot be empty</li>";

    if (pForm.txtEmail.value.trim() != "") {
        var l_strEmailWarning = '';
        l_strEmailWarning = emailCheck(pForm.txtEmail.value, l_strEmailWarning);
        if (l_strEmailWarning != "") l_strWarning += "<li><strong>Email:</strong>" + l_strEmailWarning;
    }
    
    if (pForm.txtWebsite.value.trim() != "http://") {
        if (pForm.txtWebsite.value.substring(0,7) != "http://" && pForm.txtWebsite.value.substring(0,8) != "https://" ) l_strWarning += "<li><strong>Website:</strong> Please enter the full web address starting with http:// or https://";
    }
    
    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();
    }
}
