// Check document is ready
$(document).ready(function(){
    
// If at Insurance Declaration stage
    if ( $("#membershipform #hidmode").val() == "5" || $("#membershipform #hidmode").val() == 5 )
    {
        $("#membershipform #btnmsfsubmit").click(function () {
            var message = "";
            var error = false;
            if($("#membershipform #chkmsfinsurancedeclaration1").length > 0 )
            {
                if($("#membershipform #chkmsfinsurancedeclaration1:checked").val() != 1)
                {
                    error = true;
                    message = message + "Please confirm you agree with the Insurance Declaration.\n"
                }
            }
            if($("#membershipform #chkmsfdemandsandneeds1").length > 0)
            {
                if($("#membershipform #chkmsfdemandsandneeds1:checked").val() != 1)
                {
                    error = true;
                    message = message + "Please confirm you agree with the Demands and Needs Statement.\n";
                }
            }
            
            /* only process is the above warnings are not required */
            if (error !== true)
            {
                if($("#chkmsfinsurancedeclaration2:checked").val() === "1") { error = true; }
                if($("#chkmsfcriminaloffenceconviction1:checked").val() == "1") { error = true; }
                if($("#chkmsfinsolvency1:checked").val() === "1") { error = true; }
                    
                if (error === true)
                {
                    message = "We are sorry we are unable to continue with your online application.\nPlease call our membership services team on 1800 885919";
                }
            }
            
            if (error === true)
            {
                alert(message);
                return false;
            }
        });
    }
});
