﻿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);
    popbox.focus();	
}

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") {
            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 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, t) {
    if ($(t).className != "op") {
        jQuery("#" + d).show("fast");
        $(t).className = "op";
    } else {
        jQuery("#" + d).hide("fast");
        $(t).className = "";
    }
}

/*Banner*/
function Banner() {
    this.ID = 0;
    this.Items = new Array();
    this.DurationSec = 20;
    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();
        }, 10000
    );
}

/*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 arA = getArFromDivs("A", "contentlistTbl6_" + this.flashid, "contentlistTbl7_" + this.flashid, "contentlistTbl8_" + this.flashid, "contentlistTbl10_" + this.flashid, "digitaldownload_" + this.flashid);
    for (i = 0; i < arA.length; i++) {
        if (arA[i].className == "stop") arA[i].style.display = 'none';
        if (arA[i].className == "play") arA[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 = "";
    if ($("dvitem" + this.id)) $("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 dv = $("contentlistTbl6_" + t.flashid);
    if (!dv) dv = $("contentlistTbl7_" + t.flashid);
    if (!dv) dv = $("contentlistTbl10_" + t.flashid);
    if (!dv) dv = $("digitaldownload_" + t.flashid);
    var dvs = dv.getElementsByTagName("DIV");
    
    for (b = 0; b < dvs.length; b++) {
        if (dvs[b].className.indexOf("dvitem") >= 0) {
            dvs[b].className = "dvitem";
        }
    }
}

function getArFromDivs(tag) {
    var ar = new Array();
    for (i = 1; i < arguments.length; i++) {
        var dv = $(arguments[i]);
        if (dv) {
            var as = dv.getElementsByTagName(tag);
            for (b = 0; b < as.length; b++) {
                ar.push(as[b]);
            }
        }
    }
    return ar;
}

function TabClass() {
    this.glASel;
    this.glTabSel;
    this.ChngTab = ChTab;

    function ChTab(s, t) {
        try {
            if (!document.getElementById(this.glTabSel)) return;
            document.getElementById(this.glTabSel).style.display = 'none';
            this.glASel.className = '';
            document.getElementById(s).style.display = '';
            document.getElementById(t).className = 'hov';
            this.glTabSel = s;
            this.glASel = document.getElementById(t);
        } catch (e) { }
    }

}

function cms_popRelodClose(m, mid) {

    var sUrl = window.opener.location.href.split("#")[0];

    //Prüfen ob es sich innerhalb eines dynamischen Absatzes befindet
    var d = window.opener.document.getElementById("modul_" + mid);
    var p = getParent(d, 'dynpara');
    if (p) {
        m = 1;
        mid = p.title.replace("#DynPar", "");
    }
    switch (m) {
        case 1: //Dynamischer Absatz
            window.opener.location.href = sUrl + ((sUrl.indexOf('?') >= 0) ? '&' : '?') + '#DynPar' + mid;            
            window.opener.pardynamicload();
            break;
       default:
            window.opener.location.href = sUrl;
            break;
    }

    window.close();    

}

function getParent(o, c) {
    var ob = null;
    if (o.className==c) {
        ob = o;
    } else {
        for (i = 0; i < 10; i++) {
            try {
                if (o.parentNode.className==c) {
                    ob = o.parentNode;
                    i = 11;
                } else {
                    o = o.parentNode;
                }
            } catch (e) { i = 11; }
        }
    }
    return ob;
}



function loadFlv(flv) {
    var guid = 'vid' + randomString();
    document.write("<div id='" + guid + "'></div>");
    var v1 = {};
    v1.playerpath = "/includes/flvplayer";
    v1.video = flv;
    v1.skin = "skin1.swf";
    v1.skincolor = "0x9e0202";
    v1.skinscalemaximum = "1";
    v1.smoothing = true;
    v1.volume = true;
    v1.autoscale = true;
    v1.preview = "preview-small.jpg";
    v1.autoplay = false;
    v1.buttonoverlay = 'buttonoverlay2.swf';
    swfobject.embedSWF("includes/flvplayer/flvplayer.swf", guid, "180", "160", "9.0.28", "includes/flvplayer/expressInstall.swf", v1, params, attributes);
}

function randomString() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}

function afterDelayedKeyup(selector, action, delay) {
    jQuery(selector).keyup(function () {
        if (typeof (window['inputTimeout']) != "undefined") {
            clearTimeout(inputTimeout);
        }
        inputTimeout = setTimeout(action, delay);
    });
}

function prettyPhotoClose() {
    jQuery.prettyPhoto.close();
}


