window.addEvent('domready', function(){
    /* ################# ZIA BEGIN ################# */
        if($('tx-powermail-pi1_fieldset_66') && $('tx-powermail-pi1_fieldset_67') && $('tx-powermail-pi1_fieldset_68')){
            $('tx-powermail-pi1_fieldset_66').setStyle('display', 'none');  
            $('tx-powermail-pi1_fieldset_67').setStyle('display', 'none');
            $('tx-powermail-pi1_fieldset_68').setStyle('display', 'none');
            
            $$('.tx_powermail_pi1_fieldwrap_html_289')[0].getFirst().setStyle('visibility', 'hidden');
            $$('.tx_powermail_pi1_fieldwrap_html_290')[0].getFirst().setStyle('visibility', 'hidden');
            $$('.tx_powermail_pi1_fieldwrap_html_301')[0].getFirst().setStyle('visibility', 'hidden');
            $$('.tx_powermail_pi1_fieldwrap_html_302')[0].getFirst().setStyle('visibility', 'hidden');
            $$('.tx_powermail_pi1_fieldwrap_html_313')[0].getFirst().setStyle('visibility', 'hidden');
            $$('.tx_powermail_pi1_fieldwrap_html_314')[0].getFirst().setStyle('visibility', 'hidden');
            $$('.tx_powermail_pi1_fieldwrap_html_325')[0].getFirst().setStyle('visibility', 'hidden');
            $$('.tx_powermail_pi1_fieldwrap_html_326')[0].getFirst().setStyle('visibility', 'hidden');        
        }
        
        // first
        label_first = new Element('label', {
            'html': 'Möchten Sie eine Begleitperson anmelden?'
        });
        
        checkbox_first = new Element('input', {
            'type': 'checkbox',
            'id': 'check1',
            'value': 1
        });
        
        extraBox_first = new Element('div', {
            'class': 'tx_powermail_pi1_fieldwrap_html'
        }).adopt(label_first).adopt(checkbox_first);
            
        // second
        label_second = new Element('label', {
            'html': 'Möchten Sie eine weitere Begleitperson anmelden?'
        });
        
        checkbox_second = new Element('input', {
            'type': 'checkbox',
            'id': 'check2',
            'value': 1
        });
        
        extraBox_second = new Element('div', {
            'class': 'tx_powermail_pi1_fieldwrap_html'
        }).adopt(label_second).adopt(checkbox_second);
        
        // third
        label_third = new Element('label', {
            'html': 'Möchten Sie eine weitere Begleitperson anmelden?'
        });
        
        checkbox_third = new Element('input', {
            'type': 'checkbox',
            'id': 'check3',
            'value': 1
        });
        
        extraBox_third = new Element('div', {
            'class': 'tx_powermail_pi1_fieldwrap_html'
        }).adopt(label_third).adopt(checkbox_third);
        
        //styles
        label_first.setStyles({
            'width': 300,
            'text-align': 'left'
        });
        
        label_second.setStyles({
            'width': 300,
            'text-align': 'left'
        });
        
        label_third.setStyles({
            'width': 300,
            'text-align': 'left'
        });
        
        
        
        if ($('tx-powermail-pi1_fieldset_66') && $('tx-powermail-pi1_fieldset_67') && $('tx-powermail-pi1_fieldset_68')){
            extraFieldset_first = new Element('fieldset').adopt(extraBox_first);    
            extraFieldset_first.inject($('tx-powermail-pi1_fieldset_65'), 'after');
            
            extraFieldset_second = new Element('fieldset').adopt(extraBox_second).setStyle('display', 'none');    
            extraFieldset_second.inject($('tx-powermail-pi1_fieldset_66'), 'after');
            
            extraFieldset_third = new Element('fieldset').adopt(extraBox_third).setStyle('display', 'none');    
            extraFieldset_third.inject($('tx-powermail-pi1_fieldset_67'), 'after');
            
            checkbox_first.addEvent('click', function(){
                extraFieldset_first.setStyle('display', 'none');
                $('tx-powermail-pi1_fieldset_66').setStyle('display', 'block'); 
                extraFieldset_second.setStyle('display', 'block');  
            });
            
            checkbox_second.addEvent('click', function(){
                extraFieldset_second.setStyle('display', 'none');
                $('tx-powermail-pi1_fieldset_67').setStyle('display', 'block'); 
                extraFieldset_third.setStyle('display', 'block');  
            });
            
            checkbox_third.addEvent('click', function(){
                extraFieldset_third.setStyle('display', 'none');
                $('tx-powermail-pi1_fieldset_68').setStyle('display', 'block');
            });
            
            if ($('uid300').value == '---') $('uid300').setProperty('value', '');
            if ($('uid312').value == '---') $('uid312').setProperty('value', '');
            if ($('uid324').value == '---') $('uid324').setProperty('value', '');
            
            $$('DIV.tx_powermail_pi1_fieldwrap_html_337')[0].getFirst().addEvent('click', function(){
                fireForm('zia');
                return false;
            });
        }
    /* ################# ZIA END ################# */
    
    /* ################# PANTA BEGIN ################# */
        if($('tx-powermail-pi1_fieldset_70') && $('tx-powermail-pi1_fieldset_71') && $('tx-powermail-pi1_fieldset_72') && $('tx-powermail-pi1_fieldset_73')){        
            var header = new Element('img', {
                'src': 'uploads/pics/banner.png', 
                'width': 600,
                'height': 218
            });
            
            header.inject($$('DIV.tx-powermail-pi1_formwrap_23')[0], 'top');
            
            $$('.tx_powermail_pi1_fieldwrap_html_355')[0].getFirst().setStyles({
                'margin-bottom': 10,
                'width': 300,
                'display': 'none'
            });
            
            $$('.tx_powermail_pi1_fieldwrap_html_357')[0].setStyles({
                'padding-left': 20,
                'width': 390
            });
            
            $$('.powermail_check_inner_uid355_0')[0].setStyles({
                'margin-bottom': 0,
                'width': 'auto',
                'padding-left': 20
            });
            
            $$('.powermail_check_inner_uid355_0')[0].getLast().setStyles({
                'width': 300
            });
            
            $$('.powermail_check_inner_uid355_1')[0].setStyles({
                'margin-bottom': 0,
                'width': 'auto',
                'padding-left': 20
            });
            
            $$('.powermail_check_inner_uid355_1')[0].getLast().setStyles({
                'width': 300
            });
            
            if (checkedFormElem($('anmeldeformular_panta_rhei'), $('uid355_1'))){
                $$('.tx_powermail_pi1_fieldwrap_html_357')[0].setStyle('display', 'block');
                if (checkedFormElem($('anmeldeformular_panta_rhei'), $('uid357_0'))){
                    $('tx-powermail-pi1_fieldset_73').setStyle('display', 'block');    
                } else $('tx-powermail-pi1_fieldset_73').setStyle('display', 'none');    
            } else {
                $('uid357_0').checked = false;
                $('uid357_1').checked = false;
                $('tx-powermail-pi1_fieldset_73').setStyle('display', 'none');    
                $$('.tx_powermail_pi1_fieldwrap_html_357')[0].setStyle('display', 'none');
            }   
            
            if ($('uid362').value == '---') $('uid362').setProperty('value', '');        
            
            $('uid355_1').addEvents({
                'click': function(){
                    if (checkedFormElem($('anmeldeformular_panta_rhei'), $('uid355_1'))){
                        $$('.tx_powermail_pi1_fieldwrap_html_357')[0].setStyle('display', 'block');
                        if (checkedFormElem($('anmeldeformular_panta_rhei'), $('uid357_0'))){
                            $('tx-powermail-pi1_fieldset_73').setStyle('display', 'block');    
                        } else $('tx-powermail-pi1_fieldset_73').setStyle('display', 'none');    
                    } else {
                        $('tx-powermail-pi1_fieldset_73').setStyle('display', 'none');    
                        $$('.tx_powermail_pi1_fieldwrap_html_357')[0].setStyle('display', 'none');
                    }
                }
            });
            
            $('uid357_0').addEvents({
                'click': function(){
                    if (checkedFormElem($('anmeldeformular_panta_rhei'), $('uid357_0'))){
                        $('tx-powermail-pi1_fieldset_73').setStyle('display', 'block');    
                    } else $('tx-powermail-pi1_fieldset_73').setStyle('display', 'none');    
                }
            });
            
            $('uid357_1').addEvents({
                'click': function(){
                    $('tx-powermail-pi1_fieldset_73').setStyle('display', 'none');    
                }
            });
            
            $$('INPUT.powermail_submit_uid358')[0].addEvent('click', function(){
                fireForm('panta');
                return false;
            });
        }    
    /* ################# PANTA END ################# */
});

function fireForm(formname){
    if (formname == 'zia'){
        //$('zia_ti_anmeldung').addEvent('submit', function(){
            if (!checkedElem($('check1'))){
                if ($('uid300').value == '') $('uid300').setProperty('value', '---');
            }
            
            if (!checkedElem($('check2'))){
                if ($('uid312').value == '') $('uid312').setProperty('value', '---');
            }
            
            
            if (!checkedElem($('check3'))){
                if ($('uid324').value == '') $('uid324').setProperty('value', '---');
            }
            
            Cookie.dispose('fe_typo_user');
            $('zia_ti_anmeldung').submit();
        //});
    }
    
    if (formname == 'panta'){
        if (!checkedFormElem($('anmeldeformular_panta_rhei'), $('uid357_0'))){
            if ($('uid362').value == '') $('uid362').setProperty('value', '---');
        }
        
        if (checkedFormElem($('anmeldeformular_panta_rhei'), $('uid357_1'))){
            $('uid362').setProperty('value', '---');
        }
        
        Cookie.dispose('fe_typo_user');
        $('anmeldeformular_panta_rhei').submit();
    }
}

function checkedElem(elem){
    var checkedElem = $('zia_ti_anmeldung').getElements('input:checked');
    var state = false;
    
    checkedElem.each(function(item){
        if (item.id == elem.id) state = true;
    });
    
    return state;
}

function checkedFormElem(form, elem){
    var checkedElem = form.getElements('input:checked');
    var state = false;
    
    checkedElem.each(function(item){
        if (item.id == elem.id) state = true;
    });
    
    return state;
}

