old_pva_init = window.onload;
window.onload = pva_init;
function pva_init(){

        now = new Date();

        year = now.getFullYear();

        year--;

        min_year = year-5;

        obj_fld_gewinnermittlung_jahr = document.getElementById('fld_gewinnermittlung_jahr');

        obj_fld_gewinnermittlung_jahr.removeChild(obj_fld_gewinnermittlung_jahr.options[0]);

        while (year>min_year){

                option_year = document.createElement('OPTION');

                obj_fld_gewinnermittlung_jahr.options.add(option_year);

                option_year.value = year;

                option_year.innerHTML = year;

                year--;

        }

        selected_year = obj_fld_gewinnermittlung_jahr.value;

        js_yearupdate(selected_year);

        

        obj_form = document.getElementById('form_pva');

        

        obj_sonderabschreibung = obj_form.sonderabschreibung;

        if (obj_sonderabschreibung[0].checked){

                js_sonderabschreibung_enable();

                

        }

        else{

                js_sonderabschreibung_disable();

        }

        

        obj_umsatzsteuer_andere_veranlagung = obj_form.umsatzsteuer_andere_veranlagung;

        if (obj_umsatzsteuer_andere_veranlagung[1].checked){

                js_umsatzsteuer_andere_veranlagung_text_enable();

        }

        else

        {

                js_umsatzsteuer_andere_veranlagung_text_disable();

        }

        if (old_pva_init){
            old_pva_init();
        }

}



function js_yearchange(obj) {

        js_yearupdate(obj.value);

}



function js_yearupdate(current_year){

        current_year = parseInt(current_year);

        obj_container_fragebogen = document.getElementById('container_fragebogen');

        col_spans = obj_container_fragebogen.getElementsByTagName('span');

        for (i=0;i<col_spans.length;i++){

                if (col_spans[i].className=='year'){

                        col_spans[i].innerHTML = current_year;

                }

                if (col_spans[i].className=='year1'){

                        col_spans[i].innerHTML = current_year+1;

                }

        }

}



function js_sonderabschreibung_enable() {

        obj_form = document.getElementById('form_pva');

        obj_subcontainer_sonderabschreibung = document.getElementById('subcontainer_sonderabschreibung');

        obj_inputs = obj_subcontainer_sonderabschreibung.getElementsByTagName('input');

        for (i=0;i<obj_inputs.length;i++){

                obj_inputs[i].disabled = '';

                

                obj_sonderabschreibung_ruecklage = obj_form.sonderabschreibung_ruecklage;

                if (obj_sonderabschreibung_ruecklage[0].checked){

                        js_ruecklage_enable();

                }

                else {

                        js_ruecklage_disable();

                }



                obj_sonderabschreibung_verteilung = obj_form.sonderabschreibung_verteilung;

                if (obj_sonderabschreibung_verteilung[3].checked){

                        js_sonderabschreibung_verteilung_andere_enable();

                }

                else{

                        js_sonderabschreibung_verteilung_andere_disable();

                }

        }

}



function js_sonderabschreibung_disable() {

        obj_subcontainer_sonderabschreibung = document.getElementById('subcontainer_sonderabschreibung');

        obj_inputs = obj_subcontainer_sonderabschreibung.getElementsByTagName('input');

        for (i=0;i<obj_inputs.length;i++){

                obj_inputs[i].disabled = 'disabled';

        }

}



function js_ruecklage_enable() {

        obj_sonderabschreibung_ruecklage_hoehe = document.getElementById('fld_sonderabschreibung_ruecklage_hoehe');

        obj_sonderabschreibung_ruecklage_hoehe.disabled = '';

}



function js_ruecklage_disable() {

        obj_sonderabschreibung_ruecklage_hoehe = document.getElementById('fld_sonderabschreibung_ruecklage_hoehe');

        obj_sonderabschreibung_ruecklage_hoehe.disabled = 'disabled';

        obj_sonderabschreibung_ruecklage_hoehe.style.border = '1px solid';

        document.getElementById('label_sonderabschreibung_ruecklage_hoehe').style.color = '';

}



function js_sonderabschreibung_verteilung_andere_disable(){

        obj_sonderabschreibung_verteilung_andere = document.getElementById('fld_sonderabschreibung_verteilung_andere');

        obj_sonderabschreibung_verteilung_andere.disabled = 'disabled';

        obj_sonderabschreibung_verteilung_andere.style.border = '1px solid';

        document.getElementById('label_sonderabschreibung_verteilung_andere').style.color = '';

}



function js_sonderabschreibung_verteilung_andere_enable(){

        obj_sonderabschreibung_verteilung_andere = document.getElementById('fld_sonderabschreibung_verteilung_andere');

        obj_sonderabschreibung_verteilung_andere.disabled = '';

}



function js_umsatzsteuer_andere_veranlagung_text_disable() {

        obj_umsatzsteuer_andere_veranlagung_text = document.getElementById('fld_umsatzsteuer_andere_veranlagung_text');

        obj_umsatzsteuer_andere_veranlagung_text.disabled = 'disabled';

        obj_umsatzsteuer_andere_veranlagung_text.style.border = '1px solid';

        document.getElementById('label_umsatzsteuer_andere_veranlagung_text').style.color = '';

}



function js_umsatzsteuer_andere_veranlagung_text_enable() {

        obj_umsatzsteuer_andere_veranlagung_text = document.getElementById('fld_umsatzsteuer_andere_veranlagung_text');

        obj_umsatzsteuer_andere_veranlagung_text.disabled = '';

}



function js_formsubmit(obj) {

        

        arr_errors = new Array();

        section_count = 0;

        

        obj_field = obj.absender_name;

        obj_label = document.getElementById('label_absender_name');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push('Absender: Bitte geben Sie einen Namen ein!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        obj_field = obj.absender_strasse;

        obj_label = document.getElementById('label_absender_strasse');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push('Absender: Bitte geben Sie eine Strasse ein!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        obj_field = obj.absender_plz;

        obj_label = document.getElementById('label_absender_plz');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push('Absender: Bitte geben Sie eine PLZ ein!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        obj_field = obj.absender_ort;

        obj_label = document.getElementById('label_absender_ort');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push('Absender: Bitte geben Sie einen Ort ein!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        section_count++;

        section_name = 'Allgemeine Angaben';

        

        obj_field = obj.allgemein_telefon;

        obj_label = document.getElementById('label_allgemein_telefon');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie eine Telefonnummer ein!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }



        obj_field = obj.allgemein_email;

        obj_label = document.getElementById('label_allgemein_email');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie eine Emailadresse ein!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        obj_field = obj.finanzamt;

        obj_label = document.getElementById('label_finanzamt');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie das Finanzamt an!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        obj_field = obj.finanzamt_strasse;

        obj_label = document.getElementById('label_finanzamt_strasse');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie die Strasse des Finanzamts an!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }



        obj_field = obj.finanzamt_plz;

        obj_label = document.getElementById('label_finanzamt_plz');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie die PLZ des Finanzamts an!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        obj_field = obj.finanzamt_ort;

        obj_label = document.getElementById('label_finanzamt_ort');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie den Ort des Finanzamts an!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }



        obj_field = obj.steuernummer;

        obj_label = document.getElementById('label_steuernummer');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie Ihre Steuernummer an!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        section_count++;

        section_name = 'Anschaffung, Abschreibungsmöglichkeiten:';

        

        obj_field = obj.fertigstellung;

        obj_label = document.getElementById('label_fertigstellung');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie an wann die PV-Anlage fertiggestellt wurde!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }



        obj_field = obj.abschreibungsmethode;

        obj_label = document.getElementById('label_abschreibungsmethode');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie an welche Abschreibungsmethode wir für Sie geltend machen sollen!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }



        if (obj.sonderabschreibung[0].checked){

                obj_field = obj.sonderabschreibung_ruecklage_hoehe;

                obj_label = document.getElementById('label_sonderabschreibung_ruecklage_hoehe');

                if (obj.sonderabschreibung_ruecklage[0].checked){

                        if (!js_trim(obj_field.value).length>0){

                                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie die HÃƒÂ¶he der RÃƒÂ¼cklage an!')

                                obj_label.style.color = '#FF0000';

                                obj_field.style.border = '1px solid #FF0000';

                        }

                        else {

                                obj_label.style.color = '';

                                obj_field.style.border = '';

                        }

                }

                else {

                        obj_label.style.color = '';

                        obj_field.style.border = '';

                }

                

                obj_field = obj.sonderabschreibung_verteilung_andere;

                obj_label = document.getElementById('label_sonderabschreibung_verteilung_andere');

                if (obj.sonderabschreibung_verteilung[3].checked){

                        if (!js_trim(obj_field.value).length>0){

                                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie die gewÃƒÂ¼nschte Verteilung an!')

                                obj_label.style.color = '#FF0000';

                                obj_field.style.border = '1px solid #FF0000';

                        }

                        else {

                                obj_label.style.color = '';

                                obj_field.style.border = '';

                        }

                }

                else {

                        obj_label.style.color = '';

                        obj_field.style.border = '';

                }

                

        }

        else{

                obj_field = obj.sonderabschreibung_ruecklage_hoehe;

                obj_label = document.getElementById('label_sonderabschreibung_ruecklage_hoehe');

                obj_label.style.color = '';

                obj_field.style.border = '';

                obj_field = obj.sonderabschreibung_verteilung_andere;

                obj_label = document.getElementById('label_sonderabschreibung_verteilung_andere');

                obj_label.style.color = '';

                obj_field.style.border = '';

        }



        section_count++;

        section_name = 'Betriebseinnahmen:';



        obj_field = obj.betriebseinnahmen;

        obj_label = document.getElementById('label_betriebseinnahmen');

        if (!js_trim(obj_field.value).length>0){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie die Betriebseinnahmen an!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else {

                obj_label.style.color = '';

                obj_field.style.border = '';

        }



        section_count++;

        section_name = 'Umsatzsteuer:';



        obj_field = obj.umsatzsteuer_andere_veranlagung_text;

        obj_label = document.getElementById('label_umsatzsteuer_andere_veranlagung_text');

        if (obj.umsatzsteuer_andere_veranlagung[1].checked){

                if (!js_trim(obj_field.value).length>0){

                        arr_errors.push(section_count + '. ' + section_name + ' Bitte geben Sie die weitere TÃƒÂ¤tigkeit an, fÃƒÂ¼r die Sie zur Umsatzsteuer veranlagt werden!')

                        obj_label.style.color = '#FF0000';

                        obj_field.style.border = '1px solid #FF0000';

                }

                else {

                        obj_label.style.color = '';

                        obj_field.style.border = '';

                }       

        }



        section_count++;

        section_name = 'Sonstiges:';



        obj_field = obj.fld_ok

        obj_label = document.getElementById('label_ok');

        if (!obj_field.checked){

                arr_errors.push(section_count + '. ' + section_name + ' Bitte markieren Sie noch das letzte Häckchen!')

                obj_label.style.color = '#FF0000';

                obj_field.style.border = '1px solid #FF0000';

        }

        else{

                obj_label.style.color = '';

                obj_field.style.border = '';

        }

        

        if (arr_errors.length>0){

                error_message = '';

                for (i=0;i<arr_errors.length;i++){

                        error_message += arr_errors[i] + '\n';

                }

                alert(error_message);

                return false;

        }

        

        return true;

}

// Leerzeichen hinten und vorne bei einem String Objekt wegschneiden
function js_trim(string) {
    return string.replace(/^\s*|\s*$/,'');
}
