﻿function $(s) { return document.getElementById(s); }
function pop(title, width, height, filename) {
    thefile = filename;
    var w = 480, h = 340;
    w = screen.availWidth;
    h = screen.availHeight;
    var leftPos = (w - width) / 2, topPos = (h - height) / 2;
    popbox = window.open(thefile, title, "status=yes,toolbar=no,scrollbars=yes,resizable=yes,directories=no,menubar=no,width=" + width + ",height=" + height + ",top=" + topPos + ",left=" + leftPos);
    if (popbox != null) {
        if (popbox.opener == null) {
            popbox.opener = self;
        }
    }
}

function loadGoogleMap(m, lon, lat, txt, zoom, onlymap) {
    if (GBrowserIsCompatible()) {
        var map = new GMap2($(m));

        map.enableDoubleClickZoom();
        map.enableContinuousZoom();
        map.enableScrollWheelZoom();

        if (lon != "" && lat != "") {
            if (isNaN(zoom)) zoom = 13;
            map.setCenter(new GLatLng(lat, lon), zoom);
        }
        if ($(m).offsetHeight >= 300) {
            var ovcontrol = new GOverviewMapControl(new GSize(100, 100));
            map.addControl(ovcontrol);
            map.addControl(new GMapTypeControl());
            map.addMapType(G_PHYSICAL_MAP);
            var extLargeMapControl = new ExtLargeMapControl();
            map.addControl(extLargeMapControl);
        } else {
            map.addControl(new GSmallMapControl());
        }

        function createMarker(point, number) {
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function () {
                if (txt != "") {
                    marker.openInfoWindowHtml(txt);
                }
            });
            return marker;
        }
        if (lon != "" && lat != "" && onlymap != true) {
            var point = new GLatLng(lat, lon);
            map.addOverlay(createMarker(point, 1));
        }
        return map;
    }
}
function formatDate(d) {
    var sDat = formNrUndTen(d.getDate()) + "." + formNrUndTen(d.getMonth() + 1) + "." + d.getYear();
    return sDat;
}
function formNrUndTen(i) {
    if (i < 10) {
        return "0" + String(i);
    } else {
        return i;
    }
}


var screenW = 1000;
var screenH = 701;
function getScreenHW() {
    if (document.documentElement.clientWidth) {
        screenW = document.documentElement.clientWidth + document.documentElement.scrollLeft;
        screenH = document.documentElement.clientHeight + document.documentElement.scrollTop;

    } else {
        screenW = window.outerWidth;
        screenH = window.outerHeight;
    }
}

var intImgVal = null;
var glImg = null;
function showImage(src) {

    var dv = openDiv();

    dv.style.display = 'none';

    var img = new Image();
    img.src = src;

    document.getElementById('dv').appendChild(img);

    glImg = img;
    intImgVal = setInterval("imgLoaded()", 100);

    var topPos = 50;
    var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
    var dsoctop = document.all ? iebody.scrollTop : pageYOffset
    var topPos = 20 + dsoctop;

    //dv.style.left = leftPos + 'px';
    dv.style.top = topPos + 'px';
    //dv.style.display='';
    img = null;

    document.body.appendChild(dv);
}

function imgLoaded() {
    if (glImg.width > 0) {
        removeBgWaiting();
        document.getElementById('dv').style.width = glImg.width + 'px';
        document.getElementById('dvcont').style.display = '';
        clearInterval(intImgVal);
    }
}

function openDiv() {
    getScreenHW();
    var divBg = document.createElement("DIV");
    divBg.id = "divbg";
    divBg.style.position = "absolute";
    divBg.innerHTML = "<br><br><br><center><img src='App_Themes/cms/images/waiting.gif' border=0></center>";
    divBg.style.top = 0;
    divBg.style.left = 0;
    divBg.style.width = (screenW) + 'px';
    divBg.style.height = (screenH + 1000) + 'px';
    divBg.style.zIndex = 100;
    document.body.appendChild(divBg);

    var dvCont = document.createElement("DIV");
    dvCont.id = "dvcont";
    dvCont.style.position = "absolute";
    dvCont.style.top = 0;
    dvCont.style.left = 0;
    dvCont.style.zIndex = 150;
    dvCont.style.textAlign = "center";
    dvCont.style.width = "100%";
    dvCont.style.paddingTop = "20px";

    var dv = document.createElement("DIV");
    dv.id = "dv";
    dv.style.width = "800px";
    dv.style.height = "10px";
    dv.style.backgroundColor = '#ffffff';
    dv.style.position = "relative";
    dv.style.marginLeft = String((screenW - 820) / 2) + 'px';

    var dvClose = document.createElement("DIV");
    var format = "png";
    if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("MSIE 7") <= 0) {
        format = "gif";
    }
    dvClose.innerHTML = "<img src='images/gallery_close." + format + "' border='0'/>";
    dvClose.style.position = "absolute";
    dvClose.style.right = "0px";
    dv.appendChild(dvClose);

    dvCont.appendChild(dv);
    document.body.appendChild(dvCont);

    dv.onclick = closeDiv;
    divBg.onclick = closeDiv;
    dvCont.onclick = closeDiv;

    return dvCont;
}

function removeBgWaiting() {
    if (document.getElementById('divbg')) document.getElementById('divbg').innerHTML = '';
}

function closeDiv() {
    //document.getElementById('divbg').style.display='none';
    document.body.removeChild(document.getElementById('divbg'));
    document.body.removeChild(document.getElementById('dvcont'));
}

function showVisitedCard(contactKey) { //Contact Details
    var dv = openDiv();
    var topPos = 50;
    var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
    var dsoctop = document.all ? iebody.scrollTop : pageYOffset
    var topPos = 20 + dsoctop;
    dv.style.top = topPos + 'px';
    dv.innerHTML += "<iframe id='ifrContactDetail' width='820' height='600' border='0' frameborder=0 src='module/contacts/visitcard.aspx?contactkey=" + contactKey + "&theme=" + glTheme + "&LNG=" + glLng + "'></iframe>";
    setTimeout("removeBgWaiting();", 1000);
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            if (obj.style.position != "absolute") {
                curtop += obj.offsetTop
            }
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            if (obj.style.display != "none") {
                curleft += obj.offsetLeft
            }
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}




/* Navigation */
var oGlOpenMenu = null;
var glIntv = null;
function navigationShowSubmenu(o) {

    hideNavigationSubmenu();

    for (i = 0; i < o.childNodes.length; i++) {
        var oChild = o.childNodes[i];
        if (oChild.tagName == "UL") {
            //oChild.style.top = findPosY(o);
            //oChild.style.top = "30px";
            //var oX = findPosX(o);
            var oX = 20;
            var pos = jQuery(o).position();
            oX = pos.left;

            oChild.style.left = oX + "px";
            oChild.style.display = '';
            oGlOpenMenu = oChild;
        }
    }

}

function hideNavigationSubmenu() {
    if (glIntv != null) window.clearTimeout(glIntv);
    if (oGlOpenMenu != null) {
        oGlOpenMenu.style.display = 'none';
    }
}

document.onmousedown = function (e) {
    setTimeout("hideNavigationSubmenu();", 200);
}

document.onmouseover = function (e) {

    if (!e) e = window.event;

    var src = null;
    if (e.srcElement) {
        src = e.srcElement;
    } else {
        src = e.target;
    }

    if (src && (src.tagName == "A" || src.tagName == "LI" || src.tagName == "UL")) {
        window.clearTimeout(glIntv);
    } else {
        window.clearTimeout(glIntv);
        glIntv = window.setTimeout("hideNavigationSubmenu();", 3000);
    }
}

var glClSettings = [];
var glClTempInd = 0;
var glClIntv = [];


function contentlistFadeinOutStart(idn) {
    contentlistFadeinOutLoad(idn);
    setInterval(function callFunc() { contentlistFadeinOutLoad(idn) }, 10000);
}

function contentlistFadeinOutLoad(idn) {
    //0 ... Index, 1 ... TableId, 2 ... ArrayContent, 3 ... Interval
    var ar = glClSettings[idn];
    var indx = ar[0];
    var itms = ar[2];

    var tbl = document.getElementById(ar[1]);
    tbl.style.filter = "alpha(opacity=0)"
    glClIntv[idn] = setInterval(function callFuncEffect() { contentlistEffectIn(tbl, idn) }, 50);

    if (itms.length < indx) indx = 0;

    module_contentliste_contentliste.getContentData(itms[indx], idn, contentlistFadeinOutLoad_callBack);

    //-------------------------------------
    indx++;
    var tmpAr = [];
    tmpAr[0] = indx;
    tmpAr[1] = ar[1];
    tmpAr[2] = ar[2];
    glClSettings[idn] = tmpAr;
}

function contentlistEffectIn(tbl, idn) {

    var alph = tbl.style.filter.replace("alpha(opacity=", "").replace(")", "");
    alph = parseInt(alph) + 5;
    tbl.style.filter = "alpha(opacity=" + alph + ")";

    if (alph >= 100) {
        clearInterval(glClIntv[idn]);
    }

}

function contentlistFadeinOutLoad_callBack(response) {

    var ds = response.value;
    var tempInd = ds.Tables[0].Rows[0].Idn;
    var ar = glClSettings[tempInd];
    var tbl = document.getElementById(ar[1]);
    var tds = tbl.getElementsByTagName('TD');

    if (ds != null && typeof (ds) == "object" && ds.Tables != null && ds.Tables[1] != null) {
        var s = new Array();
        for (var i = 0; i < ds.Tables[1].Rows.length; i++) {
            var sUrl = glMenuId + "_" + ds.Tables[1].Rows[i].ID + "_content_" + ds.Tables[1].Rows[i].Title + ".aspx?LNG=" + glLng
            tds[0].innerHTML = "<a href='" + sUrl + "'>" + ds.Tables[1].Rows[i].Title + "</a>";
            tds[1].innerHTML = ds.Tables[1].Rows[i].Shorttext + "<div class='more'>" + "<a href='" + sUrl + "'>" + locMore + "</a></div>";
            tds[0].id = "contentlist1_" + ds.Tables[1].Rows[i].ID;
            tds[1].id = "contentlist2_" + ds.Tables[1].Rows[i].ID;
        }
    } else {
        //alert("Error. [3001] " + response.request.responseText); 
    }
}

function writeJaApplet(sStil, sWidth, sHeight, sImg, sUrlHref) {
    if (navigator.javaEnabled()) {
        var str = '<applet code="' + sStil + '" codebase="module/java_applet/" width="' + sWidth + '" height="' + sHeight + '">';
        str += '<param name=image value="' + sImg + '">';
        str += '<param name="speed" value="30">';
        str += '<param name=href value="' + sUrlHref + '">';
        str += '<img src="' + sImg + '" width="' + sWidth + '" border=0 alt="">';
        str += '</applet>';
    } else {
        str += '<img src="' + sImg + '" border=0 alt="">';
    }
    document.write(str);
}

/*function eventShowParticipants() {
var dv = openDiv();
    
var topPos = 50;
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
var dsoctop=document.all? iebody.scrollTop : pageYOffset
var topPos = 20 + dsoctop;              
dv.style.top = topPos + 'px';
    
var ifr = document.createElement("IFRAME");
ifr.id = "ifrEventParticipant";
ifr.style.width = "820px";
ifr.style.height = "600px";
ifr.frameborder="0";
ifr.src = "module/event/participants.aspx?eventkey="+eventKey+"&theme="+glTheme
dv.appendChild(ifr);
setTimeout("removeBgWaiting();",1000);
}*/

function contAni() {
    this.arIds;
    this.indx = 0;
    this.effect = "1";
    this.start = startAni;

    function startAni() {
        var o = this;
        setTimeout(function () { chngAni(o); }, 7000);
    }
}

function chngAni(t) {
    var o1 = $(t.arIds[t.indx]);
    switch (t.effect) {
        case "1":
            new Effect.Parallel([
                  new Effect.Move(o1, { sync: true, x: 400, y: 0, mode: 'relative' }),
                  new Effect.Opacity(o1, { sync: true, from: 1, to: 0 })
                ], {
                    duration: 0.6,
                    delay: 0.5
                });
            break;
        case "2":
            new Effect.Fade(o1, { duration: 1.5 });
            break;
    }

    var iNext = t.indx + 1;
    t.indx++;
    if (iNext >= t.arIds.length) { iNext = 0; t.indx = 0; }
    var o2 = $(t.arIds[iNext]);
    o2.style.left = "0px";

    setTimeout(function () { new Effect.Appear(o2, { duration: 0.6 }); }, 900);
    setTimeout(function () { chngAni(t) }, 8000);
}

function showdynpara(d) {
    if (String($(d).style.display) == 'none') {
        Effect.BlindDown(d, { duration: 0.3 });
    } else {
        Effect.BlindUp(d, { duration: 0.3 });
    }
}

/*Banner*/
function Banner() {
    this.ID = 0;
    this.Items = new Array();
    this.DurationSec = 10;
    this.StartBanner = banner_start;
    this.Index = 0;
}

function BannerItem() {
    this.ID = "";
    this.Img = "";
    this.Alt = "";
}

function banner_start() {
    var o = this;
    setTimeout(
        function () {
            var i = o.Index + 1;
            var ar = o.Items;
            if (i >= ar.length) i = 0;
            var itm = ar[i];
            o.Index = i;
            $("bannerImg" + o.ID).src = itm.Img;
            if (itm.ID == "") {
                $("bannerA" + o.ID).removeAttribute("href");
            } else {
                $("bannerA" + o.ID).href = "module/banner/click.aspx?k=" + itm.ID + "&url=" + escape(location.href);
            }
            o.StartBanner();
        }, 5000
    );
}

/*Audio Player*/
function AudioPl() {
    this.id = 0;
    this.mp3 = "";
    this.flashid = 0;
    this.play = audioPlay;
    this.stop = audioStop;
}


function audioPlay() {
    //Alle Bilder auf stop setzen
    var as = $("contentlistTbl6_" + this.flashid).getElementsByTagName("A");
    for (i = 0; i < as.length; i++) {
        if (as[i].className == "stop") as[i].style.display = 'none';
        if (as[i].className == "play") as[i].style.display = '';
    }
    audioResetClass(this);

    $("audioflash" + this.flashid).SetVariable("method:setUrl", this.mp3);
    $("audioflash" + this.flashid).SetVariable("method:play", "");

    $("audioplay" + this.id).style.display = "none";
    $("audiostop" + this.id).style.display = "";
    $("dvitem" + this.id).className = "dvitemSelected";


}
function audioStop() {
    $("audioflash" + this.flashid).SetVariable("method:stop", "");
    $("audioplay" + this.id).style.display = "";
    $("audiostop" + this.id).style.display = "none";
    audioResetClass(this);
}

function audioResetClass(t) {
    var dvs = $("contentlistTbl6_" + t.flashid).getElementsByTagName("DIV");
    for (b = 0; b < dvs.length; b++) {
        if (dvs[b].className.indexOf("dvitem") >= 0) {
            dvs[b].className = "dvitem";
        }
    }
}