var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
if (document.location.href.match(/web2print/)) {
    document.write('<script type="text/javascript" src="' + basepath + '__/scripts/standorte.js" charset="UTF-8"></script>');
    document.write('<script type="text/javascript" src="' + basepath + '__/scripts/zusatz.js" charset="UTF-8"></script>');
    document.write('<script type="text/javascript" src="' + basepath + '__/scripts/akgrad.js" charset="UTF-8"></script>');
    document.write('<script type="text/javascript" src="' + basepath + '__/scripts/funktion.js" charset="UTF-8"></script>');
    document.write('<script type="text/javascript" src="' + basepath + '__/scripts/abteilungen.js" charset="UTF-8"></script>');
};
runOnLoad(function() {
    Ext.select('div[id^=cont_box]').each(function(el) {
        el.on('mouseover', function(ev, elm) {
            if (elm.className == 'fst') {
                elm.style.backgroundImage = 'url(/__/theme/default/img/bg_list_home_on.gif)';
            } else {
                Ext.get(elm).up('div.fst').dom.style.backgroundImage = 'url(/__/theme/default/img/bg_list_home_on.gif)';
            }
        });
        el.on('mouseout', function(ev, elm) {
            if (elm.className == 'fst') {
                elm.style.backgroundImage = 'url(/__/theme/default/img/bg_list_home.gif)';
            } else {
                Ext.get(elm).up('div.fst').dom.style.backgroundImage = 'url(/__/theme/default/img/bg_list_home.gif)';
            }
        });
    });
    Ext.select('div[id^=img_slider]').each(function(el) {
        var pics = el.select('.detpicmaxi');
        bgSlide(pics, 0);;
    });
    Ext.select('.galerie img').each(gallery);
    Ext.select('.galerietab img').each(gallery);
    var fade = function() {
        var rsim = Ext.select('img.ressortimage');
        var count = 1;
        var delay = 1;
        rsim.each(function(im) {
            if (count > 1) {
                window.setTimeout(function() {
                    im.fadeIn({
                        duration : delay,
                        callback : function(el) {
                            if (rsim.elements[rsim.elements.length - 1].id == el.id) {
                                var count = 1;
                                rsim.each(function(im) {
                                    if (count > 1 || count < rsim.elements.length - 1) {
                                        im.dom.style.visibility = 'hidden';
                                    }
                                });
                                window.setTimeout(function() {
                                    Ext.get(rsim.elements[rsim.elements.length - 1].id).fadeOut({
                                        duration : delay,
                                        callback : fade
                                    });
                                }, delay * 2000);
                            };
                        }
                    });
                }, count * delay * 2000);
            } else {
                im.dom.style.visibility = 'visible';
            };
            count++;
        });
    };
    fade();
});
runOnLoadFinish(function() {
    if (tabs.autotabs) {
        var h = 0;
        tabs.autotabs.items.each(function(t) {
            var th = t.bodyEl.getHeight();
            if (th > h) {
                h = th;
            };
        });
        tabs.autotabs.syncHeight(h + 50);
    };
});
var gallery = function(im) {
    im.on('click', function(ev, el) {
        var mPic = Ext.get('maingalerypic');
        var mTxt = Ext.get('mtxt');
        var gTxt = Ext.get('gtxt_' + el.id.split('_')[1]);
        if (mPic) {
            var url = el.src.replace(/\/thm\//, '/media/');
            if (url == mPic.dom.src) {
                return;
            };
            mPic.removeAllListeners();
            mPic.on('load', function() {
                mPic.fadeIn();
                mTxt.dom.innerHTML = gTxt.dom.innerHTML;
                mTxt.fadeIn();
            });
            mPic.shift({
                opacity : 0,
                callback : function() {
                    mPic.dom.src = url;
                }
            });
            mTxt.fadeOut();
        }
    });
};
var print_current_page = function() {
    window.print();
};
var empfehlen = function() {
    if (document.getElementById('contentmailmanager').style.display == 'block') {
        document.getElementById('contentmailmanager').style.display = 'none';
    } else {
        document.getElementById('contentmailmanager').style.display = 'block';
    };
};
var bookmark = function(el, module, id) {
    var url = 'index.html?_func=addbookmark&_nrdr=1&_mode=' + module + '&_id=' + id + '&_nc=' + getUniqueID();
    var linkfile = Ext.get(el);
    Ext.Ajax.request({
        url : url,
        method : 'get',
        success : function(req) {
            var param = decode(req.responseText);
            var bookmarkcount = Ext.get("bookmarked_sites_count");
            if (bookmarkcount) {
                bookmarkcount.dom.innerHTML = param.count;
            };
            if (linkfile) {
                linkfile.dom.title = param.title;
                /* linkfile.dom.innerHTML = param.text; */
                switch (param.status) {
                    case 'added' :
                        linkfile.dom.className = 'bookmark_saved bookmark_' + module + '_saved';
                        break;
                    case 'removed' :
                        linkfile.dom.className = 'bookmark bookmark_' + module;
                        break;
                }
            }
        }
    });
};
var toggleVisRow = function(el, changeImg, mode) {
    Ext.select('tr[class=' + el + ']').each(function(_el) {
        var showAsBlock = false;
        if (mode && (mode == 'block')) {
            showAsBlock = true;
        };
        var isDisplayed = _el.isDisplayed();
        display = (isDisplayed && !showAsBlock) ? "none" : (Ext.isIE ? "block" : "table-row");
        _el.setDisplayed(display);
        if (changeImg) {
            _im = Ext.get(el + '_pic');
            if (_im) {
                if (isDisplayed && !showAsBlock) {
                    _im.dom.src = basepath + '_/pics/bullet_arrow_right.gif';
                    document.cookie = el + "=none;";
                } else {
                    _im.dom.src = basepath + '_/pics/bullet_arrow_down.gif';
                    document.cookie = el + "=block;";
                }
            }
        }
    });
};
var bgSlide = function(slimg, c) {
    var pic = slimg.elements[c];
    var p = Ext.get(pic);
    p.fadeIn({
        duration : 2,
        callback : function() {
            c = c + 1;
            if (c >= slimg.getCount()) {
                c = 1;
                slimg.setStyle('display', 'none');
                slimg.elements[0].style.display = 'block';
            };
            window.setTimeout(function() {
                bgSlide(slimg, c);
            }, 2000);
        }
    });
};
/*
 * Web2print-Funktionen
 */
var previewCard = function(site) {
    var im = Ext.getDom('vcimg');
    var site = site || 1;
    var url = 'index.html?_func=vcimg&_site=' + site + '&' + Ext.Ajax.serializeForm('vcpreview') + '&dc=' + getUniqueID();
    if (im) {
        im.src = url;
    }
};
var previewPDF = function(id) {
    Ext.getDom('cont').disabled = false;
    var id = id || false;
    if (id) {
        var fld = Ext.select('input');
        fld.each(function(el) {
            if (el.dom.disabled) {
                el.dom.disabled = false;
                el.dom.enabled = true;
            }
        });
        var url = 'index.html?_func=vcpdf&_id=' + id + '&' + Ext.Ajax.serializeForm('vcpreview') + '&dc=' + getUniqueID();
        owin(url, {
            name : 'popupwin',
            width : screen.availWidth,
            height : screen.availHeight,
            scrollbars : 'yes',
            resizable : 'yes',
            left : 0,
            top : 0,
            toolbar : 'no',
            menubar : 'no'
        });
        fld.each(function(el) {
            if (el.dom.enabled) {
                el.dom.enabled = false;
                el.dom.disabled = true;
            }
        });
    }
};
var removeFromCard = function(id) {
    var url = 'index.html?_func=vsrmbasket&_nrdr=1&_mode=cards&_did=' + id + '&_nc=' + getUniqueID();
    Ext.Ajax.request({
        url : url,
        method : 'get',
        success : function(req) {
            document.location.reload();
        }
    });
}
var addToCard = function(id) {
    if (cmsForms['vcpreview'].fireEvent("submit")) {
        var url = 'index.html?_func=vsaddbasket&_nrdr=1&_mode=cards&_id=' + id + '&_nc=' + getUniqueID() + '&' + Ext.Ajax.serializeForm('vcpreview');
        Ext.Ajax.request({
            url : url,
            method : 'get',
            success : function(req) {
                var url = document.location.href.split('?');
                document.location.href = url[0] + '?_vskt=extendedBasket&_bxd=b2ec7cb535099de2e39d87325952ce3d';
            }
        });
    }
};
var setOrder = function(el) {
    switch (el.checked) {
        case true :
            setCookie('order[' + el.value + ']', el.value, '', '/');
            break;
        case false :
            now = new Date();
            setCookie('order[' + el.value + ']', '', now, '/');
            break;
    }
};
var htmlCleanUp = function(str) {
    var umlaute = [
        'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß', 'é', 'è', 'É', 'È', 'í', 'Í', 'á', '„', '“', 'ó', 'ñ', 'ú', 'å', 'ç', 'Ç', 'Ê', 'ê', 'æ', 'ï', 'Ï'
    ];
    var replace = [
        '&auml;', '&ouml;', '&uuml;', '&Auml;', '&Ouml;', '&Uuml;', '&szlig;', '&eacute;', '&egrave;', '&Eacute;', '&Egrave;', '&iacute;', '&Iacute;', '&aacute;', '&bdquo;', '&ldquo;', '&oacute;', '&ntilde;', '&uacute;', '&aring;', '&ccedil;', '&Ccedil;', '&Ecirc;', '&ecirc;', '&aelig;', '&iuml;', '&Iuml;'
    ];
    var num = 0;
    replace.each(function(uml) {
        var reg = '/' + uml + '/';
        reg = eval(reg);
        str = str.replace(reg, umlaute[num]);
        num++;
    });
};
var pauschalen = function(el, sc) {
    var lyb = 'ee26eb2d9b6f24e02b9a872d719147a4';
    var url = document.location.pathname + '?_lyb=' + lyb + '&_shc=' + sc;
    Ext.Ajax.request({
        url : url,
        success : function(req) {
            var o = decode(req.responseText);
            if (isObject(o) && o.html) {
                Ext.MessageBox.maxWidth = 800;
                var box = Ext.MessageBox.show({
                    title : '',
                    msg : 'Lade Daten...',
                    animEl : el,
                    modal : false
                });
                box.getDialog().on('hide', function() {
                    if (tabs.autotabspopup) {
                        tabs.autotabspopup.destroy();
                        delete tabs.autotabspopup;
                        Ext.select('div[id=gmap_80]').each(function(g) {
                            g.remove();
                        });
                        if (gMap.configs.gmap_80) {
                            delete gMap.configs.gmap_80;
                        }
                        if (gMap.maps.gmap_80) {
                            delete gMap.maps.gmap_80;
                        }
                    }
                });
                var txt = '<div id="dynpauschale" style="width:800px; height:600px; overflow-x:hidden; overflow-y:auto;">' + o.html + '</div>';
                txt = txt.replace(/kttab/g, 'kttabpopup');
                txt = txt.replace(/autotabs/g, 'autotabspopup');
                Ext.MessageBox.updateText(txt);
                txt.evalScripts();
                var dlg = Ext.MessageBox.getDialog();
                dlg.center();
                var dyn = Ext.get('dynpauschale');
                dyn.select('form').each(function(f) {
                    f.remove();
                });
                dyn.select('style').each(function(s) {
                    s.remove();
                });
                dyn.select('div[id=comments]').each(function(c) {
                    c.remove();
                });
                var autotabs = Ext.get('autotabspopup');
                if (autotabs) {
                    var tabcontent = dyn.select('div.tabcontent');
                    if (tabcontent.getCount() > 1) {
                        tabcontent.each(function(t) {
                            if (t.dom.id == '') {
                                t.dom.id = Ext.id();
                            };
                            if (trim(t.dom.innerHTML) != '') {
                                addTab(t.dom.id, 'autotabspopup', t.dom.getAttribute('title') || 'Infos');
                            }
                        });
                    }
                };
                if (tabs.autotabspopup) {
                    var h = 0;
                    tabs.autotabspopup.items.each(function(t) {
                        var th = t.bodyEl.getHeight();
                        if (th > h) {
                            h = th;
                        };
                    });
                    tabs.autotabspopup.syncHeight(h + 50);
                    tabs.autotabspopup.items.first().activate();
                }
            }
        }
    });
    return (false);
};
var pauschalenold = function(el, id, cat, mod) {
    var url = '/';
    if (mod && mod == 'content') {
        url += id;
    } else {
        var path = cat.split('/');
        /*
         * Gastronomie: 462 Camping: 461 Gastgeber: 423 Wellness: 577 Wandern: 754 Fahrrad: 1076 Camping: 1102
         * Wasserwandern: 1103 Touren Wandertouren: 603 Fahrradtouren: 604 Motorradtouren: 605
         */
        switch (Number(path[2])) {
            case 1076 :
                url += '1395';
                break;
            case 462 :
                url += '480';
                break;
            case 461 :
                url += '492';
                break;
            case 423 :
                url += '528';
                break;
            case 754 :
                url += '649';
                break;
            case 577 :
                /* case 1076 : */
            case 1102 :
            case 1103 :
                url += '419';
                break;
            case 603 :
                url += '411';
                break;
            case 604 :
                url += '425';
                break;
            case 605 :
                url += '450';
                break;
        };
        url += '?detID=' + id;
        url += '&_lyb=f0233c9787c2d65f89511c37ab3bce4c';
    };
    Ext.MessageBox.maxWidth = 800;
    var box = Ext.MessageBox.show({
        title : '',
        msg : 'Lade Daten...',
        animEl : el,
        modal : false
    });
    box.getDialog().on('hide', function() {
        if (tabs.autotabspopup) {
            tabs.autotabspopup.destroy();
            delete tabs.autotabspopup;
            Ext.select('div[id=gmap_80]').each(function(g) {
                g.remove();
            });
            if (gMap.configs.gmap_80) {
                delete gMap.configs.gmap_80;
            }
            if (gMap.maps.gmap_80) {
                delete gMap.maps.gmap_80;
            }
        }
    });
    Ext.Ajax.request({
        url : url,
        success : function(req) {
            /**
             * var treg = /<!--\sINHALT\s-->(.+)<!--\sINHALT\s-->/i; var bd = treg.exec(req.responseText); if (!bd) {
             * bd = treg.exec(req.responseText); };
             */
            var bd = decode(req.responseText);
            if (bd && bd.html) {
                var txt = '<div id="dynpauschale" style="width:800px; height:600px; overflow-x:hidden; overflow-y:auto;">' + bd.html + '</div>';
                txt = txt.replace(/kttab/g, 'kttabpopup');
                txt = txt.replace(/autotabs/g, 'autotabspopup');
                Ext.MessageBox.updateText(txt);
                txt.evalScripts();
                var dlg = Ext.MessageBox.getDialog();
                dlg.center();
                var dyn = Ext.get('dynpauschale');
                dyn.select('form').each(function(f) {
                    f.remove();
                });
                dyn.select('style').each(function(s) {
                    s.remove();
                });
                dyn.select('div[id=comments]').each(function(c) {
                    c.remove();
                });
                var autotabs = Ext.get('autotabspopup');
                if (autotabs) {
                    var tabcontent = dyn.select('div.tabcontent');
                    if (tabcontent.getCount() > 1) {
                        tabcontent.each(function(t) {
                            if (t.dom.id == '') {
                                t.dom.id = Ext.id();
                            };
                            addTab(t.dom.id, 'autotabspopup', t.dom.getAttribute('title') || 'Infos');
                        });
                    }
                };
                if (tabs.autotabspopup) {
                    var h = 0;
                    tabs.autotabspopup.items.each(function(t) {
                        var th = t.bodyEl.getHeight();
                        if (th > h) {
                            h = th;
                        };
                    });
                    tabs.autotabspopup.syncHeight(h + 50);
                    tabs.autotabspopup.items.first().activate();
                }
            } else {
                Ext.MessageBox.updateText('Infos konnten nicht geladen werden.');
            }
        }
    });
}
// deaktivieren der Boxen in den Tools
runOnLoad(function() {
    var dbfieldsoptfields = Ext.select('.dbfieldsoptfields');
    dbfieldsoptfields.each(function(el) {
        var kinder = el.select('.katalog_db_field');
        var elisvisible = 'none'
        kinder.each(function(elk) {
            if (elk.getStyle('display') == 'block') {
                elisvisible = 'block';
            }
        });
        el.setStyle('display', elisvisible);
    });
});
fixbottommenu = function() {
    var counter = 0;
    var c = 0;
    var bottommenu = Ext.select('.footmenuUL > li');
    var firstfive = [];
    var lastfive = [];
    bottommenu.each(function(el) {
        if (counter < 5) {
            c = counter;
            c = c + 5;
            tole = Ext.get(el);
            thele = Ext.get(bottommenu.elements[c]);
            thele.alignTo(tole, 'tl-bl', [
                0, 20
            ]);
        }
        counter = counter + 1;
    });
};
runOnLoad(fixbottommenu);


checkDistanceForm = function (element ){
    var citieselement = Ext.get(element);
    var distanceelement = Ext.get('disstance');
    
    if (citieselement.dom.value == ''){
        distanceelement.dom.style.display = 'none';
        distanceelement.dom.value = '';
    } else {
        distanceelement.dom.style.display = 'inline';
    }
  
}
