function validateAnswerSelection() {
    var btn = document.quiz.answers;
    var cnt = -1;
    for (var i = btn.length - 1; i > -1; i--) {
        if (btn[i].checked) {
            cnt = i;
            i = -1;
        }
    }
    return cnt > -1;
}

function validateNewQuiz() {
    String
    msg = '';
    if (document.quiz.author.value.length < 3) msg += "- 'Laget av' skal ha minst 3 tegn\n";
    if (document.quiz.title.value.length < 3) msg += "- 'Tittel' skal ha minst 3 tegn\n";
    if (msg != '') {
        msg = 'Det ble funnet feil:\n' + msg;
        alert(msg)
        return false;
    } else return true;
}

function submitNewQuiz(method) {
    if (validateNewQuiz()) {
        document.quiz.method.value = method;
        document.quiz.submit();
    } else return false;
}

function alertMessage(str){
    var msg = "Det ble funnet feil:\n" + str;
    window.alert(msg);
}

//restrict characters in text to max number and count remaining chars.
function characterCount(txt, name, textArea){
    var max = 255;
    var number = max - txt.length;
    if(txt.length > max){
       txt = txt.substring(0,max);
       document.getElementById(textArea).value = txt;
       number = max - txt.length;
       alert("Det er ikke tillatt med over 255 tegn i dette feltet");
    }
    document.getElementById(name).value=number + " / 255 tegn";
}