﻿function ValidateForm(formid) {
    var form = document.getElementById(formid);
    
    var msg = "You have not filled the following fields of the form:\n\n";
    var details = ""; 
    for(var i=0;i<form.elements.length;i++) {
        var question = getQuestion(form.elements[i].name);


        if (question != null) {
            if (question.Name == "Postcode") {
                var country = document.getElementById("question|Country").value;
                if (country != "19185f99-e362-4c50-a8e5-4e19dd773684")
                    continue;
            }
        }
        
        if (question != null && question.AllowBlank == false && !form.elements[i].value)
            details += question.Name + "\n";
    }
    
    
    if (details.length > 0) {
        msg += details;
        alert(msg);
    }
    if((details.length == 0))
    {
        return true;
    }
    else
    {
        return false;
    }
}
function getQuestion(elementName) {
    for (var i = 0; i < formJSON.Pages[0].Sections[0].Questions.length; i++) {
        if (elementName.indexOf(formJSON.Pages[0].Sections[0].Questions[i].ID) != -1)
            return formJSON.Pages[0].Sections[0].Questions[i];
    }
    return null;
}

