function check(radioObj) {
    value = getCheckedValue(radioObj);
    if (value == 'Både mor og far') {
        hideDiv('omsorgsovertakelsesDatoDiv');
        hideMorUforContainer();
        document.getElementById("omsorgsovertakelsesDato").value = "";
    } else if (value == 'Alenefar' && getCheckedValue(document.forms['FpengerForm'].elements['adopsjon']) == 'false') {
        showDiv('omsorgsovertakelsesDatoDiv');
        hideMorUforContainer();
    } else if (value == 'Kun far') {
        hideDiv('omsorgsovertakelsesDatoDiv');
        showMorUforContainer();

    } else {
        hideDiv('omsorgsovertakelsesDatoDiv');
        hideMorUforContainer();
        document.getElementById("omsorgsovertakelsesDato").value = "";
    }
}

function oppdaterHjelp(tekst) {
    tekst = document.createTextNode(tekst);
    oldnode = document.getElementById('hjelpetekst').childNodes.item(0);
    document.getElementById('hjelpetekst').replaceChild(tekst, oldnode);
}

function firstFocus() {
    if (document.forms.length > 0) {
        var TForm = document.forms[0];
        var i;
        for (i = 0; i < TForm.length; i++) {
            if ((TForm.elements[i].type == "text") ||
                (TForm.elements[i].type == "textarea") ||
                (TForm.elements[i].type.toString().charAt(0) == "s")) {
                document.forms[0].elements[i];
                break;
            }
        }
    }
}

function toemfnr() {
    document.forms[0].fodselsnummer.value = document.forms[0].fodselsnummerinitielt.value;
    document.forms[0].fodselsnummerinitielt.value = '';
}

function kalkulator() {
    var forrige = document.referrer;
    if (forrige != null && forrige.indexOf("fpenger/fpenger") >= 0) {
        history.go(-1);
    }
    else {
        window.location = "<%=request.getContextPath()%>/fpenger/fpengerWizard.do";
    }
    function do_nothing() {
    }
}

function pushHelp(helpText) {
    document.getElementById("NAVhelpTxt").innerHTML = helpText;
}


function getRefToDiv(divID, oDoc) {
    if (document.getElementById) {
        return document.getElementById(divID);
    }
    if (document.all) {
        return document.all[divID];
    }
    if (!oDoc) {
        oDoc = document;
    }
    if (document.layers) {
        if (oDoc.layers[divID]) {
            return oDoc.layers[divID];
        } else {
            for (var x = 0, y; !y && x < oDoc.layers.length; x++) {
                y = getRefToDiv(divID, oDoc.layers[x].document);
            }
            return y;
        }
    }
    return false;
}


function showDiv(divID_as_a_string) {
    myReference = getRefToDiv(divID_as_a_string);
    if (!myReference) {
        return;
    }
    if (myReference.style) {
        myReference.style.visibility = 'visible';
    } else {
        myReference.visibility = 'show';
    }
}

function hideDiv(divID_as_a_string) {
    var myReference = getRefToDiv(divID_as_a_string);
    if (!myReference) {
        return;
    }
    if (myReference.style) {
        myReference.style.visibility = "hidden";
    } else {
        if (myReference.visibility) {
            myReference.visibility = "hide";
        } else {
            return;
        }
    }
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
            return radioObj.value;
        else
            return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

function checkAdopsjon(objValue) {
    value = getCheckedValue(objValue);
    if (value == 'true') {
        changeText('adopsjon');
    } else {
        changeText('fodsel');
    }
}

function showMorUforContainer(){
    $('#morUforDiv').show();
}

function hideMorUforContainer(){
     $('#morUforDiv').hide();
}

