var strength = {
    0: "Heel zwak ☹",
    1: "Slecht ☹",
    2: "Zwak ☹",
    3: "Oke ☺",
    4: "Zo sterk als een be(e)r(enklauw) ☻"
}

var password = document.getElementById('password');
var meter = document.getElementById('password-strength-meter');
var text = document.getElementById('password-strength-text');

password.addEventListener('input', function()
{
    var val = password.value;
    var result = zxcvbn(val);

    // Update the password strength meter
    meter.value = result.score;

    // Update the text indicator
    if(val !== "")
    {
        text.innerHTML = "Wachtwoord sterkte: " + "<strong>" +
        strength[result.score] + "</strong>" +
        "<span class='feedback'>" +
        result.feedback.warning + " " +
        result.feedback.suggestions + "</span>";
    }
    else {
        text.innerHTML = "";
    }
});

var strengthherh = {
    0: "Komt niet overeen",
    1: "Goed op weg ☹",
    2: "Bijna ☹",
    3: "Bijna ☺",
    4: "Helemaal goed ☻"
}

var passwordherh = document.getElementById('password');
var herhaalherh = document.getElementById('herhaal');
var meterherh = document.getElementById('herhaal-vergelijker-meter');
var textherh = document.getElementById('herhaal-vergelijker-text');

herhaalherh.addEventListener('input', herhaalcheck);
passwordherh.addEventListener('input', herhaalcheck);

function herhaalcheck() {
    var valherh = passwordherh.value;
    var resultherh = herhaalherh.value;

    var compareNum = 0;

    var l = 0+Math.min(valherh.length, resultherh.length);
    var lmax = 0+Math.max(valherh.length, resultherh.length);
    for( i=0; i<l; i++) {
        if( valherh.charAt(i) == resultherh.charAt(i)) compareNum++;
    }
    meterherh.value = (Math.floor((compareNum/lmax)*4));

    // Update the text indicator
    if(valherh !== "") {
        textherh.innerHTML = "Overeenkomsten: " + "<strong>" +
        strengthherh[meterherh.value] + "</strong>";
    }
    else {
        textherh.innerHTML = "";
    }
}

var passwordherh = document.getElementById('password');
var registertext = document.getElementById('register-button');
var username = document.getElementById('username');
var email = document.getElementById('email');

herhaalherh.addEventListener('input', registercheck);
passwordherh.addEventListener('input', registercheck);

function registercheck() {
    var geheim = document.getElementById('geheim');
    // Update the text indicator
    if(meterherh.value == 4 && meter.value >= 3) {
        registertext.innerHTML = "<input type='submit' name='registreer' class='reactButton formButton' value='"+geheim.value+"'/>";
    }
    else {
        registertext.innerHTML = "Kies een goed wachtwoord";
    }
}
