var GB_ANIMATION = true;

// When 'pobox' is filled - 'pair street' + 'house number' is disabled. If any of the fields 'pair street' +
// 'house number' are filled in - 'pobox' is disabled.
// poboxId, streetId, houseNumberId can be both html ID or CLASS elements and shall be properly prefixed (with # or .).
function checkTwoFieldsByClassOnChange(class1, class2) {
            if ((($('.' + class1).attr('value') == '' || $('.' + class1).attr('value') == 'undefined')) && (($('.' + class2).attr('value') == '' || $('.' + class2).attr('value') == 'undefined')))
            {
                $('.' + class1).removeAttr('readonly');
                $('.' + class2).removeAttr('readonly');
            }
            else {
                if ($('.' + class1).attr('value') == '' || $('.' + class1).attr('value') == 'undefined') {
                    $('.' + class1).attr('readonly', true);
                }
                else {
                     $('.' + class2).attr('readonly', true);
                }
            }
}
function checkThreeFieldsByClassOnChange(class1, class2, class3) {
            if ((($('.' + class1).attr('value') == '' || $('.' + class1).attr('value') == 'undefined'))
                && (($('.' + class2).attr('value') == '' || $('.' + class2).attr('value') == 'undefined'))
                && (($('.' + class3).attr('value') == '' || $('.' + class3).attr('value') == 'undefined')))
            {
                $('.' + class1).removeAttr('readonly');
                $('.' + class2).removeAttr('readonly');
                $('.' + class3).removeAttr('readonly');
            }
            else {
                $('.' + class1).removeAttr('readonly');
                $('.' + class2).removeAttr('readonly');
                $('.' + class3).removeAttr('readonly');
                if ($('.' + class1).attr('value') == '' || $('.' + class1).attr('value') == 'undefined') {
                    $('.' + class1).attr('readonly', true);
                }

                if ($('.' + class2).attr('value') == '' || $('.' + class2).attr('value') == 'undefined') {
                    $('.' + class2).attr('readonly', true);
                }


                if ($('.' + class3).attr('value') == '' || $('.' + class3).attr('value') == 'undefined') {
                    $('.' + class3).attr('readonly', true);
                }

            }
}

function checkThreeFieldsByClassOnChangeOneCheckbox(class1, class2, class3) {
            if ((($('.' + class1).attr('checked') == false ))
                && (($('.' + class2).attr('value') == '' || $('.' + class2).attr('value') == 'undefined'))
                && (($('.' + class3).attr('value') == '' || $('.' + class3).attr('value') == 'undefined')))
            {
                $('.' + class1).removeAttr('disabled');
                $('.' + class2).removeAttr('readonly');
                $('.' + class3).removeAttr('readonly');
            }
            else {

                $('.' + class1).removeAttr('disabled');
                $('.' + class2).removeAttr('readonly');
                $('.' + class3).removeAttr('readonly');
                if ($('.' + class1).attr('checked') == false) {
                    $('.' + class1).attr('disabled', true);
                }

                if ($('.' + class2).attr('value') == '' || $('.' + class2).attr('value') == 'undefined') {
                    $('.' + class2).attr('readonly', true);
                }


                if ($('.' + class3).attr('value') == '' || $('.' + class3).attr('value') == 'undefined') {
                    $('.' + class3).attr('readonly', true);
                }

            }
}
function checkThreeFieldsByClassOnChangeTwoCheckbox(class1, class2, class3) {
            if ((($('.' + class1).attr('checked') == false ))
                && (($('.' + class2).attr('checked') == false ))
                && (($('.' + class3).attr('value') == '' || $('.' + class3).attr('value') == 'undefined')))
            {
                $('.' + class1).removeAttr('disabled');
                $('.' + class2).removeAttr('disabled');
                $('.' + class3).removeAttr('readonly');
            }
            else {

                $('.' + class1).removeAttr('disabled');
                $('.' + class2).removeAttr('disabled');
                $('.' + class3).removeAttr('readonly');
                if ($('.' + class1).attr('checked') == false) {
                    $('.' + class1).attr('disabled', true);
                }

                if ($('.' + class2).attr('checked') == false) {
                    $('.' + class2).attr('disabled', true);
                }


                if ($('.' + class3).attr('value') == '' || $('.' + class3).attr('value') == 'undefined') {
                    $('.' + class3).attr('readonly', true);
                }

            }
}
$(document).ready(function() { // After document is loaded
        // 
        // On load
        checkTwoFieldsByClassOnChange('uitstellentot',
                              'uitstellenjaren');
        checkThreeFieldsByClassOnChangeOneCheckbox('uitkeringsduurlevenslang',
        'uitkeringsduurtot',
        'uitkeringsduurjaren');
        checkThreeFieldsByClassOnChangeTwoCheckbox('overgangmedeverzekerde',
        'overganglangstlevende',
        'overgangpercent');

        // On change
        $('.uitstellentot, .uitstellenjaren').bind('change', function(){
            checkTwoFieldsByClassOnChange('uitstellentot',
                                  'uitstellenjaren');
        });
        $('.uitkeringsduurlevenslang, .uitkeringsduurtot, .uitkeringsduurjaren').bind('change', function(){
            checkThreeFieldsByClassOnChangeOneCheckbox('uitkeringsduurlevenslang','uitkeringsduurtot','uitkeringsduurjaren');
        });
        $('.overgangmedeverzekerde, .overganglangstlevende, .overgangpercent').bind('change', function(){
            checkThreeFieldsByClassOnChangeTwoCheckbox('overgangmedeverzekerde','overganglangstlevende','overgangpercent');
        });
        // END 

});

