function toggleRadio() {
    deRadio = document.getElementById('radiocontainer');
    if (deRadio.className == "fullradio") {
        deRadio.className = "midiradio";
    } else {
        deRadio.className = "fullradio";
    }
}

function popupRadio(theURL, winName, features, timer) { //v2.2
    var timer = $get(timer).control;
    timer._stopTimer();

    window.open(theURL, winName, features);
    deRadio = document.getElementById('radiocontainer');
    deRadio.innerHTML = "<div class=\"radiogone\">De radio is in een extern window geopend.</div>";
}

function closeRadioPopup() {
    if (false == KCORadio.closed) {
        KCORadio.close();
    } else {
        alert('Window already closed!');
    }
}

function checkRefid(field) {
    var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    var ok = "yes";
    var temp;
    for (var i = 0; i < field.value.length; i++) {
        temp = "" + field.value.substring(i, i + 1);
        if (valid.indexOf(temp) == "-1") ok = "no";
    }
    if (ok == "no") {
        alert("Invalid entry! Only characters and numbers (no spaces) are accepted! for a reference name");
        field.focus();
        field.select();
    } 
}


function numbersonly(myfield, e, dec) {
    var key;
    var keychar;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;

    keychar = String.fromCharCode(key);

    // control keys
    if ((key == null) || (key == 0) || (key == 8) ||
		(key == 9) || (key == 13) || (key == 27))
        return true;

    // numbers
    else if ((("0123456789").indexOf(keychar) > -1))
        return true;

    // decimal point jump
    else if (dec && (keychar == ".")) {
        myfield.form.elements[dec].focus();
        return false;
    }
    else
        return false;
}

function altijdNul(myfield) {
    //alert(this)
    if (myfield.value.length == 0) {
        myfield.value = "0";
    }
}

function resetNullvalue(myfield) {
    if (myfield.value == '0') {
        myfield.value = 1;
    }
    myfield.value = myfield.value.replace(/\D/gi, '');

    if (myfield.value == '')
        myfield.value = 1;
}


function Validate() {
    var foundNawErrors = false;
    var errorMessage = '';

    $('.formulier fieldset.naw .required').each(function() {
        if ($(this).hasClass('firstname')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - voornaam\r\n';
                foundNawErrors = true;
            }
        }
        if ($(this).hasClass('lastname')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - achternaam\r\n';
                foundNawErrors = true;
            }
        }
        if ($(this).hasClass('address')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - adres\r\n';
                foundNawErrors = true;
            }
        }
        if ($(this).hasClass('addressnumber')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - huisnummer\r\n';
                foundNawErrors = true;
            }
        }
        if ($(this).hasClass('postalcode')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - postcode\r\n';
                foundNawErrors = true;
            }
        }
        if ($(this).hasClass('email')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - email\r\n';
                foundNawErrors = true;
            }
        }
        if ($(this).hasClass('phone1')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - telefoon overdag\r\n';
                foundNawErrors = true;
            }
        }

        if ($(this).hasClass('rekeningnummer')) {
            if (this.value.length == 0 && this.value == '') {
                errorMessage += ' - rekeningnummer\r\n';
                foundNawErrors = true;
            }
        }

    });


    var foundSeries = false;
    $('.formulier fieldset.series .requiredSerie').each(function() {
        if (this.value.length != 0 && this.value != '0')
            foundSeries = true;
    });


    var valid = true;
    if (foundNawErrors) {
        alert('Niet alle verplichte NAW gegevens zijn ingevuld:\r\n' + errorMessage);
        valid = false;
    }
    else {
        if (!foundSeries) {
            alert('U heeft geen enkele serie geselecteerd');
            valid = false;
        }
    }

    return valid;
}

