var fixBlocks = function() {
    var c_overview_default_boxes = Ext.select('.ue_start_cnt');
    var maxh = 0;
    c_overview_default_boxes.each(function(el) {
        if (maxh < el.getHeight()) {
            maxh = el.getHeight();
        }
    });
    c_overview_default_boxes.each(function(el) {
        el.setHeight(maxh);
    });
};
function mailmanager() {
    var mm = document.getElementById('contentmailmanager');
    if (mm.style.display == 'block') {
        mm.style.display = 'none';
    } else {
        mm.style.display = 'block';
    };
};
// document.write('<scr'+'ipt src="/_/scripts/extensions/raphael.js"></scr'+'ipt>');
/*
 * runOnLoad(function() { Ext.QuickTips.interceptTitles = false; Ext.QuickTips.init(); Ext.select('.regdesc
 * .reglongdesc').each(function(el) { if (el.dom.innerHTML && el.dom.innerHTML !== '') { var master =
 * Ext.get(el.dom.parentNode); master.removeAllListeners(); } }); var evserie = Ext.get('editorext'); var endevents0 =
 * Ext.get('endevents0tablerow'); evserie.insertAfter(endevents0); });
 */
function checkChars(editor, html) {
    var maxChars = 160;
    html = html.split('\n').join('');
    if (editor.el.id.substring(0, 6) == "teaser") {
        if (Ext.util.Format.stripTags(html).length > maxChars) {
            // alert("Ihr Text bei dem Feld \""+editor.fieldLabel+"\" ist größer als "+ maxChars +" Zeichen");
            // editor.focus();
        }
    }
    /*
     * if (h != html) { /* editor.setValue(h); /*}
     */
};
/*
 * Ext.onReady(function() { if (document.documentElement.clientWidth) { var el = Ext.get('hauptcontainerrightwidth'); if
 * (document.documentElement.clientWidth % 2 != 0) { if (Ext.isIE) { el.dom.style.marginLeft = "0px"; } else {
 * el.dom.style.marginLeft = "-1px"; } } } });
 */
var webCamTimeOut;
function showWebcam(lnk) {
    var jetzt = new Date();
    var Zeit = jetzt.getTime()
    var lnk = Ext.get(lnk);
    var url = "http://www.badkissingen.de/flash/webcam/kglive.jpg?" + Zeit;
    var box = Ext.MessageBox.show({
        /* title : 'Webcam - Aktualisierung alle 30 Sec / refresh every 30 sec', */
        title : 'Webcam - Blick auf den Rosengarten (links) und das Wahrzeichen  Bad Kissingens -  den Regentenbau  (rechts)',
        msg : 'Loading',
        modal : false,
        width : 1100,
        height : 480,
        animEl : lnk,
        fn : function() {
            window.clearTimeout(webCamTimeOut);
            Ext.MessageBox.hide();
        }
    });
    var txt = '<div style="width:1024px; height: 384px;  overflow-x:hidden;overflow-y:auto;"><img id="webcamPic" src="' + url + '" width="1024"></div>';
    Ext.MessageBox.updateText(txt);
    Ext.MessageBox.getDialog().center();
    Ext.MessageBox.getDialog().resizeTo(1100, 480);
    webCamTimeOut = window.setTimeout("refreshWebCamPic()", 30000);
};
function refreshWebCamPic() {
    var jetzt = new Date();
    var Zeit = jetzt.getTime()
    var url = "http://www.badkissingen.de/flash/webcam/kglive.jpg?" + Zeit;
    var pic = Ext.get('webcamPic').dom.src = url;
    webCamTimeOut = window.setTimeout("refreshWebCamPic()", 30000);
}
var showAdressMap = function(id) {
    var map = Ext.get(id);
    if (!map) {
        var html = '<div id="' + id + '" style="height:500px; width:500px;" class="gmapmaps"></div>';
        Ext.MessageBox.show({
            title : 'Karte',
            msg : html,
            modal : false
        });
        var mconfig = {
            id : id,
            autozoom : true
        };
        initGMap(mconfig);
    } else {
        Ext.MessageBox.getDialog().show();
    }
};
if (typeof gotoMapPosition != 'undefined') {
    gotoMapPosition = gotoMapPosition.createInterceptor(function(doc, c, z) {
        if (doc.name == 'gmap_10' && z >= 1) {
            z--;
        };
        doc.map.setCenter(c, z);
        return (false);
    });
};
function showMediacenter(lnk) {
    var lnk = Ext.get(lnk);
    var url = "/r_1862";
    var box = Ext.MessageBox.show({
        title : 'Mediacenter',
        msg : '<img src="' + basepath + '__/images/indicator_tree.gif" style="vertical-align:middle;"> Loading',
        modal : false,
        width : 1024,
        height : 384,
        animEl : lnk,
        fn : function() {
            Ext.MessageBox.hide();
        }
    });
    Ext.Ajax.request({
        url : url,
        success : function(req) {
            var treg = /<!--\sCONTENT\s-->(.+)<!--\sCONTENT\s-->/gi;
            var bd = treg.exec(req.responseText.split(/\n/).join(''));
            if (bd && bd[1]) {
                var txt = bd[1];
                var dlg = box.getDialog();
                var swfs = {};
                txt.extractScripts().each(function(script) {
                    var swfreg = /\('([^']+)',\s'([^']+)',\s'([^']+)'\)/;
                    var movie = script.match(swfreg);
                    if (movie) {
                        var w = movie[2];
                        var h = movie[3];
                        var src = movie[1];
                        var id = getUniqueID();
                        txt += '<div style="text-align:center;" id="flash' + id + '"></div>';
                        var swf = new SWFObject(basepath + '_/flash/moviePlayer.swf', "flash" + id + "obj", w || 400, h || 362, "8");
                        swf.addParam('wmode', 'transparent');
                        swf.addParam('allowFullScreen', 'true');
                        swf.addVariable("skinSource", basepath + '_/flash/SkinUnderAllNoCaption.swf');
                        swf.addVariable("streamSource", src);
                        swf.addVariable("startPlay", 1);
                        swf.useExpressInstall(basepath + '_/flash/expressinstall.swf');
                        swfs[id] = swf;
                    }
                });
                box.updateText('<div style=\"width:576px; height:560px; overflow:auto;\">' + txt + '</div>');
                dlg.resizeTo(616, 610);
                for ( var id in swfs) {
                    swfs[id].write("flash" + id);
                }
            }
        }
    });
};
Ext.onReady(function() {
    var box;
    var swfs = {};
    var initlink = Ext.select('.extwndowlink');
    initlink.each(function(el) {
        var lnk = el.dom;
        var conf_title = 'Weitere Informationen';
        var conf_modal = true;
        var conf_width = 740;
        var conf_height = 460;
        var conf_display_header = true;
        Ext.MessageBox.maxWidth = 800;
        lnk.onclick = function() {
            box = Ext.MessageBox.show({
                title : conf_title,
                msg : 'Lade Daten...',
                animEl : lnk,
                modal : conf_modal,
                fn : function() {
                    for ( var id in swfs) {
                        Ext.get(swfs[id].attributes.id).remove(); // raus mit
                        // den SWFs
                    }
                    Ext.MessageBox.hide();
                }
            });
            if (conf_display_header == false) {
                box.getDialog().header.dom.style.display = 'none';
            }
            var url = lnk.href;
            Ext.Ajax.request({
                url : url,
                success : function(req) {
                    var treg = /<!--\sINHALT\s-->(.+)<!--\sINHALT\s-->/gi;
                    var bd = treg.exec(req.responseText.split(/\n/).join(''));
                    var swfHeight = 0;
                    if (bd && bd[1]) {
                        var txt = bd[1];
                        var scripttoeval;
                        swfs = {};
                        txt.extractScripts().each(function(script) {
                            var swfreg = /\('([^']+)',\s'([^']+)',\s'([^']+)'\)/;
                            var movie = script.match(swfreg);
                            if (script.substring(0, 8) == "loadGMap") {
                                scripttoeval = script;
                            };
                            if (movie) {
                                var w = parseInt(movie[2]) + 50;
                                var h = parseInt(movie[3]);
                                swfHeight = swfHeight + h;
                                var src = movie[1];
                                var id = getUniqueID();
                                txt += '<div id="flash' + id + '" style="text-align:center;"></div>';
                                var swf = new SWFObject(basepath + '_/flash/moviePlayer.swf', "flash" + id + "obj", w || 400, h || 362, "8");
                                swf.addParam('wmode', 'transparent');
                                swf.addParam('allowFullScreen', 'true');
                                swf.addVariable("skinSource", basepath + '_/flash/SkinUnderAllNoCaption.swf');
                                swf.addVariable("streamSource", src);
                                swf.addVariable("startPlay", 1);
                                swf.useExpressInstall(basepath + '_/flash/expressinstall.swf');
                                swfs[id] = swf;
                            }
                        });
                        txt = '<div id="mediacnt" style="width:' + (conf_width - 30) + 'px; overflow-x:hidden;overflow-y:auto;">' + txt + '</div>';
                        Ext.MessageBox.updateText(txt);
                        // txt.evalScripts();
                        var dlg = Ext.MessageBox.getDialog();
                        dlg.center();
                        var mediacnt = Ext.get('mediacnt');
                        if (mediacnt) {
                            mediacnt.select('.c_teaser').each(function(el) {
                                el.dom.style.display = "none";
                            });
                        };
                        if (dlg.size.height > 500) {
                            mediacnt.dom.style.height = "440px";
                            dlg.resizeTo(conf_width, 500);
                        } else {
                            dlg.resizeTo(conf_width, dlg.size.height + swfHeight);
                        };
                        for ( var id in swfs) {
                            swfs[id].write("flash" + id);
                        };
                        if (typeof scripttoeval != 'undefined') {
                            eval(scripttoeval);
                        }
                    }
                }
            });
            return (false);
        }
    });
});
var showHighscores = function(gnr) {
    var url = 'index.html?_func=shc&_gnr=' + gnr;
    Ext.Ajax.request({
        url : url,
        success : function(req) {
            var msg = Ext.MessageBox;
            var buttons = {
                ok : 'OK'
            };
            msg.show({
                title : 'Highscores',
                msg : req.responseText,
                buttons : buttons,
                modal : true,
                progress : false,
                closable : true,
                width : 500
            });
        }
    });
};
/** ** ALTZEUGS *** */
function embedkatalog(config) {
    // var conf = config.split(".");
    // config = conf[0];
    var fid = (new Date()).getTime() + "" + Math.floor((Math.random() * 8999) + 1000);
    if (config) {
        fid += '&configXML=' + config;
    }
    var domainurl = "http://www2009.badkissingen.de/flash/katalog.swf?t=" + fid;
    var oeTags = '<div style="margin-left:-10px;" id="klgflash"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + 'width="620" height="600"' + 'data="' + domainurl + '"' + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">' + '<param name="movie" value="' + domainurl + '" />' + '<param name="loop" value="false"/>' + '<param name="menu" value="false" />' + '<param name="quality" value="high" />' + '<param name="wmode" value="transparent" />'
        + '<param name="bgcolor" value="#FFFFFF" />' + '<embed src="' + domainurl + '" quality="high" bgcolor="#FFFFFF" wmode="transparent" width="620" height="600" name="katalog" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' + '<\/object></div>';
    document.write(oeTags);
}
function showPic(picurl) {
    var box = Ext.Msg.show({
        title : 'Details',
        msg : '<img src="' + picurl + '" id="ktlgpic">',
        animEl : Ext.get('klgflash')
    });
    Ext.get('ktlgpic').on('load', function(ev, el) {
        var box = Ext.get(el).getBox();
        var h = box.height + 50;
        var w = box.width;
        // Maximale Höhe limitieren: unten auskommentieren...
        /*
         * var maxheight = 750; if (h > maxheight){ var txt = '<img src="'+picurl+'" id="ktlgpic"
         * height="'+maxheight+'">'; Ext.MessageBox.updateText(txt); var box = Ext.get('ktlgpic').getBox(); h =
         * box.height+50; w = box.width; }
         */
        Ext.MessageBox.getDialog().resizeTo(w, h);
    });
};
runOnLoad(fixBlocks);
/* Socialmedia Plugin * */
socmed = {
    config : {},
    container : 'fb-root',
    show : function(config) {
        if (config && config.service) {
            this.config = config;
            switch (config.service) {
                case 'facebook_comments' :
                    this.show_facebook_comments();
                    break;
                default :
                    break;
            }
        }
        /**
         * <script src="http://connect.facebook.net/de_DE/all.js#xfbml=1"></script> <fb:comments
         * href="badkissingen.de/{c_href}" num_posts="5" width="476"></fb:comments>
         */
    },
    show_facebook_comments : function() {
        var url = this.config && this.config.url ? this.config.url : 'http://connect.facebook.net/de_DE/all.js#xfbml=1';
        LazyLoad.js(url, function() {
            /** Nachladen der Facebook API ** */
            var e = document.createElement('fb:comments');
            var myhref = this.config && this.config.href ? this.config.href : document.location.href;
            var num_posts = this.config && this.config.num_posts ? this.config.num_posts : 5;
            var width = this.config && this.config.width ? this.config.width : 400;
            e.setAttribute('href', myhref);
            e.setAttribute('num_posts', num_posts);
            e.setAttribute('width', width);
            Ext.get('fb-root').appendChild(e);
        }.createDelegate(this));
    }
};



