function checkRequiredField(elmtID) {
    var field = document.getElementById(elmtID);

    if (field.value === "") {
        field.classList.add("empty-required");
        return false;
    } else {
        field.classList.remove("empty-required");
        return true;
    }
}

var isNameFilled = false;
var isUsernameFilled = false;
var isPasswordFilled = false;
var isEmailFilled = false;
var isPhoneFilled = false;
var isPasswordMatch = false;


document.getElementById("confirm-password").onkeyup = function () {
    var confirmField = document.getElementById("confirm-password");
    var passwordField = document.getElementById("password");

    if (confirmField.value !== passwordField.value) {
        confirmField.classList.add("not-match");
        passwordField.classList.add("not-match");
        isPasswordMatch = false;
    } else {
        confirmField.classList.remove("not-match");
        passwordField.classList.remove("not-match");
        isPasswordMatch = true;
    }
};


document.getElementById("name").onkeyup = function () {
    isNameFilled = checkRequiredField("name");
};

document.getElementById("username").onkeyup = function () {
    isUsernameFilled = checkRequiredField("username");
};

document.getElementById("password").onkeyup = function () {
    isPasswordFilled = checkRequiredField("password");
};

document.getElementById("email").onkeyup = function () {
    isEmailFilled = checkRequiredField("email");
};

document.getElementById("phone").onkeyup = function () {
    isPhoneFilled = checkRequiredField("phone");
};

document.getElementById("register-form").onkeyup = function () {
    var submitBtn = document.getElementById("sign-up-btn");

    if (isNameFilled &&
        isUsernameFilled &&
        isPasswordFilled &&
        isEmailFilled &&
        isPhoneFilled &&
        isPasswordMatch) {
        submitBtn.removeAttribute("disabled");
    } else {
        submitBtn.setAttribute("disabled", "true");
    }
};