// version: 0.9.2.11
addInit('do_setup_form_elements();');
var bIsCM = location.pathname.indexOf('/cm/') != -1;
if (sSite == 'home.php' || bIsCM) addInit('document.getElementById("div_login").style.visibility = "visible";');

function pos_menu_meta()
{
    /* schreibt den text aus oDivMeta (=hidden) in oSpanMeta (-> /includes/mandant_layout.inc.php) */
    
    var oSpanMeta = document.getElementById('span_menu_meta');
    var oDivMeta  = document.getElementById('div_menu_meta');
    
    if (oSpanMeta != null) oSpanMeta.innerHTML = oDivMeta.innerHTML;
}

function do_link_dynamic_openclose(poLink)
{
    var sBgImageSrc     = poLink.style.backgroundImage;
    var bLinkIsClose    = sBgImageSrc == '' || sBgImageSrc.indexOf('down') == -1;
    var oRelatedContent = poLink.nextSibling.nextSibling;
    var bIsFaqLink      = poLink.className.indexOf('_faq') != -1; 
    
    if (bIsFaqLink)
    {
        var bLinkIsClose = poLink.className.indexOf('faq_open') == -1;
        poLink.className = bLinkIsClose ? 'link_dynamic_openclose_faq_open' : 'link_dynamic_openclose_faq';
    }
    else
      poLink.style.backgroundImage = 'url(images/'+mandant+'/arrow_'+ (bLinkIsClose ? 'down' : 'right') +'.gif)';
    
    oRelatedContent.style.display = bLinkIsClose ? 'block' : 'none';
    
    poLink.blur(); /* sieht sonst nicht gut aus */
}

function do_field_dynamic_openclose(poCheckbox,pbDelValuesOnClose)
{
    do_field_dynamic_openclose_execute(poCheckbox,pbDelValuesOnClose);
}

function do_field_dynamic_openclose_execute(poCheckbox,pbDelValuesOnClose)
{
    var bCheckboxIsChecked = poCheckbox.checked;
    var oCheckboxParent    = poCheckbox.parentNode;// div
    var oRelatedContent    = poCheckbox.parentNode.nextSibling.className == 'field_dynamic_openclose_related_content' ? poCheckbox.parentNode.nextSibling : poCheckbox.parentNode.nextSibling.nextSibling;
    
    var sRgb = oCheckboxParent.className.indexOf('_rgb2') == -1 ? '' : '_rgb2'; // welche farbe hat die box gerade
    
    if(poCheckbox.type == 'checkbox')
    {
        oRelatedContent.style.display = bCheckboxIsChecked ? 'block' : 'none';
    }
    else if (poCheckbox.type == 'radio')
    {
        if (typeof(oActiveRadio) != 'undefined')
        {
            // die vorherige radiobox aus machen
            oActiveRadio.oRelatedContent.style.display = 'none';
            oActiveRadio.parent.className = 'div_field_dynamic_openclose div_field_dynamic_openclose_close'+sRgb;

            sRequiredFieldNames = '';
            var oFldRequired = document.forms[0].fld_required;
            get_related_field_names(oActiveRadio.oRelatedContent);
            oFldRequired.value = oFldRequired.value.replace(sRequiredFieldNames, '');
            if (pbDelValuesOnClose) disable_related_fields(oActiveRadio.oRelatedContent);//field-values leeren
        }
        
        // merken des aktuellen radios
        oActiveRadio                 = poCheckbox;
        oActiveRadio.parent          = oCheckboxParent;
        oActiveRadio.oRelatedContent = oRelatedContent;
        
        // content anzeigen
        oActiveRadio.oRelatedContent.style.display = 'block';
    }
    
    oCheckboxParent.className = bCheckboxIsChecked ? 'div_field_dynamic_openclose div_field_dynamic_openclose_open'+sRgb : 'div_field_dynamic_openclose div_field_dynamic_openclose_close'+sRgb;
        
    /*---- related-field-namen merken und in oFldRequired addieren oder replacen -> wird dann automatisch mitvalidiert ----*/
    sRequiredFieldNames = '';
    var oFldRequired = document.forms[0].fld_required;
    
    get_related_field_names(oRelatedContent);
    
    if (!bCheckboxIsChecked)
    {
        oFldRequired.value = oFldRequired.value.replace(sRequiredFieldNames, '');
        if (pbDelValuesOnClose) disable_related_fields(oRelatedContent);//field-values leeren
    }
    else
    {
        oFldRequired.value += sRequiredFieldNames;        
    }
    /*----/related-field-namen merken und addieren oder replacen ----*/
    
    poCheckbox.blur();
}


var sRequiredFieldNames = ''; 

function get_related_field_names(poObj)
{
    //sammelt die field-namen, in string sRequiredFieldNames
    for(var i=0; i<poObj.childNodes.length;i++)
    {
        oItem = poObj.childNodes[i];
        
        if (typeof(oItem.tagName) == 'undefined') continue;
        
        if (oItem.disabled) continue; //disabled fields duerfen nicht required sein
        
        if (oItem.name && oItem.name.indexOf('fld_') != -1)
        {
            sRequiredFieldNames += ',' + oItem.name;
        }
        
        if(oItem.childNodes)
        {
            get_related_field_names(oItem);
        }
    }
}

function disable_related_fields(poObj)
{
    for(var i=0; i<poObj.childNodes.length;i++)
    {
        oItem = poObj.childNodes[i];
        
        if (typeof(oItem.tagName) == 'undefined') continue;
        
        switch (oItem.tagName)
        {
            case 'INPUT':
            {
                // resettet, auch pflichtfeld-markierungen
                if (oItem.type == 'text') oItem.value   = '';
                
                if (oItem.type == 'checkbox')
                {
                  //force_checkbox_submit: unsichtbare checkbox, damit checkboxen immer gesendet werden(auch wenn nixchts gechecked ist), und ggf vorhandene werte ueberschreiben
                  if(oItem.className != 'force_checkbox_submit')
                    oItem.checked = false;
                }
                
                do_mark_field(oItem,false);
                
                break;
            }
            
            case 'SELECT':
            {
                // reset
                oItem.options[0].selected  = true;
                oItem.parentNode.oIcon.src = 'images/trans.gif';
            }
        }
         
        if(oItem.childNodes)
        {
            disable_related_fields(oItem);
        }
    }
}

/*---- main-menu over + out ----*/
var aImgMenuMainItem = new Array();
aImgMenuMainItem['left'] = new Image();
aImgMenuMainItem['left'].src = sRoot + '/images/toggo_kid/menu_main_item_inactive_left.gif';
aImgMenuMainItem['mid'] = new Image();
aImgMenuMainItem['mid'].src = sRoot + '/images/toggo_kid/menu_main_item_inactive_background.gif';
aImgMenuMainItem['right'] = new Image();
aImgMenuMainItem['right'].src = sRoot + '/images/toggo_kid/menu_main_item_inactive_right.gif';

aImgMenuMainItem['left_over'] = new Image();
aImgMenuMainItem['left_over'].src = sRoot + '/images/toggo_kid/menu_main_item_inactive_left_over.gif';
aImgMenuMainItem['mid_over'] = new Image();
aImgMenuMainItem['mid_over'].src = sRoot + '/images/toggo_kid/menu_main_item_inactive_background_over.gif';
aImgMenuMainItem['right_over'] = new Image();
aImgMenuMainItem['right_over'].src = sRoot + '/images/toggo_kid/menu_main_item_inactive_right_over.gif';

oDivLeft  = new Array(); 
oDivMid   = new Array(); 
oDivRight = new Array();

function do_mainmenu_over(piMenuNr)
{
    if (!oDivLeft[piMenuNr])  oDivLeft[piMenuNr]  = document.getElementById('div_menu_main_item_inactive_left_'+piMenuNr);
    if (!oDivMid[piMenuNr])   oDivMid[piMenuNr]   = document.getElementById('div_menu_main_item_inactive_mid_'+piMenuNr);
    if (!oDivRight[piMenuNr]) oDivRight[piMenuNr] = document.getElementById('div_menu_main_item_inactive_right_'+piMenuNr);
    
    oDivLeft[piMenuNr].className  = 'menu_main_item menu_main_item_inactive_left menu_main_item_inactive_left_over';
    oDivMid[piMenuNr].className   = 'menu_main_item menu_main_item_inactive menu_main_item_inactive_over';
    oDivRight[piMenuNr].className = 'menu_main_item menu_main_item_inactive_right menu_main_item_inactive_right_over';
}

function do_mainmenu_out(piMenuNr)
{
    oDivLeft[piMenuNr].className  = 'menu_main_item menu_main_item_inactive_left';
    oDivMid[piMenuNr].className   = 'menu_main_item menu_main_item_inactive';
    oDivRight[piMenuNr].className = 'menu_main_item menu_main_item_inactive_right';
}

function do_mainmenu_otherarea_over(piMenuNr)
{
    if (!oDivLeft[piMenuNr])  oDivLeft[piMenuNr]  = document.getElementById('div_menu_main_item_inactive_left_'+piMenuNr);
    if (!oDivMid[piMenuNr])   oDivMid[piMenuNr]   = document.getElementById('div_menu_main_item_inactive_mid_'+piMenuNr);
    if (!oDivRight[piMenuNr]) oDivRight[piMenuNr] = document.getElementById('div_menu_main_item_inactive_right_'+piMenuNr);
    
    oDivLeft[piMenuNr].className  = 'menu_main_item_otherarea menu_main_item_otherarea_inactive_left menu_main_item_otherarea_inactive_left_over';
    oDivMid[piMenuNr].className   = 'menu_main_item_otherarea menu_main_item_otherarea_inactive menu_main_item_otherarea_inactive_over';
    oDivRight[piMenuNr].className = 'menu_main_item_otherarea menu_main_item_otherarea_inactive_right menu_main_item_otherarea_inactive_right_over';
}

function do_mainmenu_otherarea_out(piMenuNr)
{
    oDivLeft[piMenuNr].className  = 'menu_main_item_otherarea menu_main_item_otherarea_inactive_left';
    oDivMid[piMenuNr].className   = 'menu_main_item_otherarea menu_main_item_otherarea_inactive';
    oDivRight[piMenuNr].className = 'menu_main_item_otherarea menu_main_item_otherarea_inactive_right';
}
/*----/main-menu over + out ----*/

function draw_wrapper_head(psContent)
{
    // bei Aufruf der Funktion wird entweder der Übergabestring oder ein zurueckbutton gemalt
    var oTd = document.getElementById('td_wrapper_head');
    
    oTd.innerHTML = typeof(arguments[0]) != 'undefined' ? psContent : '<a href="#" onclick="history.back();return false;"><img src="'+sRoot+'/images/toggo_kid/'+sLang+'/button_zurueck_wrapper.gif" /></a>';
}

function open_popup(psUrl)
{
    open_window(psUrl, psUrl.replace(/.php/, ''), 'width=500, height=504, scrollbars=1');
}
