
$(document).ready(function() {
	var menuH = $('#contentLeft').outerHeight();
	var contentH = $('#content').outerHeight();

	if (menuH>contentH) {
		$('#content').css({'min-height':menuH+'px'});
	}

	moveTopNavi();
	footerPos();
	headerSpace();
	makeDienstplanTables('#page84');
	makeDienstplanTables('#page85');

	renderDienstplan();

	// console.log(navigator.userAgent)
	if( /Android|webOS|iPhone|iPad|iPod|iPadPro|iPadOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
		$('body').addClass('mobileDevice');
	}

	
	$('[class*="typeWrap-news"] .reduceSpace').each(function( index ) {
		$(this).closest('.wt').css({'display':'none'});
	});

	/*
	$('.lightbox').fancybox({
	    selector : '[data-fancybox]',
	    loop     : true
	});
	*/
	jQuery.event.special.touchstart = {
	    setup: function( _, ns, handle ) {
	        this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });
	    }
	};
	jQuery.event.special.touchmove = {
	    setup: function( _, ns, handle ) {
	        this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") });
	    }
	};
	jQuery.event.special.wheel = {
	    setup: function( _, ns, handle ){
	        this.addEventListener("wheel", handle, { passive: true });
	    }
	};
	jQuery.event.special.mousewheel = {
	    setup: function( _, ns, handle ){
	        this.addEventListener("mousewheel", handle, { passive: true });
	    }
	};
});


$(window).resize(function(){
	moveTopNavi();
	footerPos();
	headerSpace();
});

function headerSpace() {
	var hh = $('#headerWrap').outerHeight();

	$('body').css({'padding-top':hh+'px'});
}

function moveTopNavi() {
	var ww = $(window).outerWidth();

	if (ww<801) {
		$('#headerWrap #topnav').prependTo('nav#navigation');
	} else {
		$('nav#navigation #topnav').appendTo('nav#topmenu');
	}
}


function footerPos() {
	var wh = $(window).outerHeight();
	var contentHeight = ($('#footerArea').position().top) + ($('#footerArea').outerHeight());

	if (contentHeight < wh) {
		$('#footerArea').css({'margin-top':(wh-contentHeight)+'px'});
	} else {
		$('#footerArea').css({'margin-top':'auto'});
	}
}

// -------------- responsive tables --------------
for (var i=0;i<$('#content table').length;i++) {

	$('#content').find('table:eq('+i+') th').each(function( index ) {
		if ($(this).attr('summary','left').length > 0) {
			var txt=$(this).text();
			$(this).attr('data-th', txt);
			for (var j=0;j<$(this).closest("table").find("tr").length;j++) {
			  $(this).closest("table").find("tr:eq("+j+") td:eq("+index+")").attr("data-th",txt);
			}
		}
	});
}
// -------------- // responsive tables --------------

function makeDienstplanTables(pagesel) 
{
	var found=false;
	$(pagesel+' table tr').each(function() {
		var dat=$(this).find('td:eq(0)').html();
		if (dat) {
			if (dat.indexOf(",")>0) {
				dat=dat.split(",");
				dat[1]=dat[1].replace(/(<([^>]+)>)/gi, ""); // strip_tags
				var datum=dat[1].split(".");
				var datum2=new Date("20"+datum[2]+"-"+datum[1]+"-"+datum[0]);
				if (datum2<new Date()) $(this).addClass("inactive");
				else {
					if (!found) {
						$(this).addClass("active");
						found=true;
					}
				}
			}
		}
	});
}

function renderDienstplan()
{
	$('.table').each(function(idx) {
		var src=$(this).attr('data-src');
		if (src) {
			$.get( "/fileadmin/read_dienstplan.php?src="+src, function( data ) {
				$('.table:eq('+idx+')').html(data);
			});
		}
	});

}
$(document).ready(function() {
	formulare('[id*="-radiobutton"]');
	formulare('[id*="-radiobutton"]');
	formulare('[id*="-multicheckbox"]');
	formulare('[id*="-checkbox"]');
	formulare('[id*="-fileupload"]');	
	// formulare('[id*="-singleselect"]');
	// formulare('[id*="-select"]');
});

function formulare(selector) {
	// Labels relative setzen
	$(selector).each(function() {
		console.log('x');
		$(this).closest('.form-group').find('.form-label').addClass('label-relative');
		$(this).closest('.form-group').find('.form-label').addClass('label-relative');
	});

	$('[id*="-date"]').each(function() {
		$(this).closest('.form-group').find('.form-label').addClass('smallLabelInInput');
	});

	$('[id*="-select"]').each(function() {
		$(this).closest('.form-group').find('.form-label').addClass('smallLabelInInput');
	});

	$('[id*="-singleselect"]').each(function() {
		$(this).closest('.form-group').find('.form-label').addClass('smallLabelInInput');
	});

	// Input-Felder Label-Overlay
	/*
	setTimeout(function(){
		$('.form-group :input')
			.focus(function() {
				$(this).closest('.form-group').find('label').addClass('hide');
				$(this).filter('[type=date]').addClass('datevalid');
			})
			.blur(function() {
				$(this).closest('.form-group').find('label').removeClass('hide');
				$(this).filter('[type=date]').removeClass('datevalid');

				if ($(this).val().length>0) {
					$(this).closest('.form-group').find('label').addClass('hide');
					$(this).filter('[type=date]').addClass('datevalid');
				} else {
					$(this).closest('.form-group').find('label').removeClass('hide');
					$(this).filter('[type=date]').removeClass('datevalid');
				}
		});
	}, 1000);
	*/
}
$(function(){
  // -------------- offCanvas --------------
  //$('.open-panel').unbind('click');
  //$('#navigation ul li .nav-link').unbind('click');
  //$('#navigation ul li .nav-link.sub').unbind('click');

  $('.open-panel').click(function(event){
    event.preventDefault();

    if($('html').hasClass('openNav')) {
      $('body').find('#navigation ul#topnav').appendTo( $('#topmenu') );
    }
    else {
      $('#topmenu').find('ul#topnav').appendTo( $('#navigation ul#main') );
    }
    
    $('html').toggleClass('openNav');
  });
  // -------------- // offCanvas --------------


  $('#navigation ul li .nav-link').click(function(event){
    $('#navigation ul li').removeClass('active');
  });

  $('#navigation ul li .nav-link.sub').click(function(event){
    var dataid = $(this).closest('li').attr('data-uid');
    $(this).closest('li').addClass('active');
    $('#navigation ul').removeClass('activate');
    $('#navigation ul[data-parentid="'+dataid+'"]').addClass('activate');
  });

  if ($('#menu3.activate').length>0) {
    $('#menu2.activate').addClass('notActive');
    $('#menu2.activate').removeClass('activate');
  }
});
jQuery.fn.isOnScreen = function() {
	var win = jQuery(window);

	var viewport = {
		top : win.scrollTop(),
		left : win.scrollLeft()
	};
	viewport.right = viewport.left + win.width();
	viewport.bottom = viewport.top + win.height();
	var bounds = this.offset();
	if (!bounds) return;
	bounds.right = bounds.left + this.outerWidth();
	bounds.bottom = bounds.top + this.outerHeight();
	return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
};
      
jQuery(window).scroll(function() {
	if(jQuery('#headerWrap').isOnScreen()) {
		$('body').addClass('visibleHeader');
	} else {
		$('body').removeClass('visibleHeader');
	}


	var is_chrome = navigator.userAgent.indexOf('Chrome') > -1;
	var is_explorer = navigator.userAgent.indexOf('MSIE') > -1;
	var is_firefox = navigator.userAgent.indexOf('Firefox') > -1;
	var is_safari = navigator.userAgent.indexOf("Safari") > -1;
	var is_opera = navigator.userAgent.toLowerCase().indexOf("op") > -1;
	if ((is_chrome)&&(is_safari)) {is_safari=false;}
	if ((is_chrome)&&(is_opera)) {is_chrome=false;}
	if ($('#headerWrap').length<1) return;
	var topmenu_pos=$('#headerWrap').position();
	var st=$(this).scrollTop();

	var hh = $('#headerWrap').outerHeight();

	if ((st>=topmenu_pos['top'])&&(st>hh)) {
			$('#scrolling').fadeIn();
		$('#page').addClass("stick");
	} else {
			 $('#scrolling').fadeOut();
		 $('#page').removeClass("stick");
	}


})


// ------------------- Visibility of Contentelements -------------------

$(document).ready(function() {
	checkVisibility();
	// if ($('.circle-text').length) {

	// } else {
	// 	$('.visible .circle').circliful();
	// }
});


$(window).scroll(function() {
	checkVisibility();
})

$.fn.isInViewport = function () {
    let elementTop = $(this).offset().top;
    let elementBottom = elementTop + $(this).outerHeight();

    let viewportTop = $(window).scrollTop();
    let viewportBottom = viewportTop + $(window).height();

    return elementBottom > viewportTop && elementTop < viewportBottom;
};


function checkVisibility() {
	$('.autovisible').each(function() {
		if ($(this).isInViewport() ) {
			$(this).removeClass("invisible");
			$(this).addClass("visible");
		} else {
			$(this).removeClass("visible");
			$(this).addClass("invisible");
		}
	})
}

// Wenn Element das Attribut touching hat, soll es fixiert werden
jQuery(window).on('scroll', () => {
  $('[touching]').each(function() {
    var className = $(this).attr('touching');
    var offset = $(this).offset().top - $(window).scrollTop();
    var elemHeight = $(this).outerHeight();
    
    if (offset <= 0) {
      $(this).addClass(className);
      $('#contentWrap').css({'margin-top':elemHeight+'px'});
    } else {
      $(this).removeClass(className);
      $('#contentWrap').css({'margin-top':0+'px'});
    }
  })
}).trigger('scroll');
$(document).ready(function() {
	anchorScroll();
});

function anchorScroll() {
	$('a[href*=\\#]').on('click',function(e) {
 		var target = this.hash;
 		var $target = $(target);
 		var scrollDiff=180;
 		if (($target).length==0) return;
		//console.log("anchorScroll");
 		
 		if ($target.offset().top===undefined) return true;
		e.preventDefault();

		$('html, body').stop().animate({
  			'scrollTop': parseInt($target.offset().top)
 			}, 900, 'swing', function () {
  			history.pushState(null, null, window.location.pathname+target);
 		});
 		return false;
	});
	return false;
}
        $(document).ready(function() {

            if ($('.counterWrap').length > 0) {

                var interval = 50;
                setInterval(function () {
                    var duration = $('.counterWrap').attr("data-duration");
                    if (!duration) duration = 3000;
                    duration = duration / 2;

                    $('.counterWrap .item').each(function(idx) {
                        if (($(this).hasClass("visible")) && (!($(this).hasClass("counting")))) {
                            $(this).addClass("counting");
                        }
                        if (!($(this).hasClass("visible"))) $(this).removeClass("counting");
                        if ($(this).hasClass('counting')) {
                            var max = parseInt($(this).find('.anzahl').attr("data-val"));

                            var diff = parseInt(max / (duration / interval));
                            if (diff < 1) diff = 1;

                            var val = parseInt($(this).find('.anzahl').html());
                            if (val < max) val += diff;
                            if (val > max) val = max;
                            $(this).find('.anzahl').html(val);
                        }
                    });
                }, interval);

                
                $('.counterWrap').each(function() {
                    var sum = 0;
                    $(this).find('.anzahl').each(function(){
                        sum += parseInt($(this).data('val'), 10);
                    });
                    $('<div class="sum item text-center autovisible invisible"><div class="anzahlWrap"><div class="anzahl" data-val="'+sum+'">0</div></div><div class="title">Summe</div></div>').appendTo($(this));
                })                    ;

                
                
                // Trigger a re-calculation for the sum
                $('.sum').addClass('visible');
            }
        });
$(document).ready(function() {
	karussell('.typeWrap-mask_slidermittext .owl-carousel',1,1,1,1,true,0,0,false);
	karussell('.typeWrap-mask_zweispalter .owl-carousel',1,1,1,1,true,0,0,false);
	karussell('.typeWrap-mask_textimg .owl-carousel',1,1,1,1,true,0,0,false);
	karussell('.typeWrap-mask_logos .owl-carousel',8,5,3,2,true,0,0,false);
	projektslider();

	// slidermittext('.typeWrap-mask_slidermittext img');
	// slidermittext('.typeWrap-mask_slidermittext .imgWrap');
});

$(window).resize(function() {
	karussell('.typeWrap-mask_slidermittext .owl-carousel',1,1,1,1,true,0,0,false);
	karussell('.typeWrap-mask_logos .owl-carousel',8,5,3,2,true,0,0,false);
	karussell('.typeWrap-mask_zweispalter .owl-carousel',1,1,1,1,true,0,0,false);
	karussell('.typeWrap-mask_textimg .owl-carousel',1,1,1,1,true,0,0,false);
	
	projektslider();
	
	// slidermittext('.typeWrap-mask_slidermittext img');
	// slidermittext('.typeWrap-mask_slidermittext .imgWrap');
});

function projektslider() {
	karussell('.typeWrap-mask_projektslider .owl-carousel',8,5,1.3,1.3,false,50,20,true);

	$('.typeWrap-mask_projektslider .active:eq(2)').addClass('mainItem');
	$('.typeWrap-mask_projektslider').on('changed.owl.carousel', function(event) {
		$('.typeWrap-mask_projektslider .owl-item').removeClass('mainItem');
		$('.typeWrap-mask_projektslider .active:eq(2)').addClass('mainItem');

		//console.log(event.page);
		//console.log(event);
	})
}

function karussell(selektor,w4,w3,w2,w1,wtAutoplay,wtMargin,wtMargin2,wtCenter) {
	// $(selektor).owlCarousel({
	var owl = $(selektor).owlCarousel({
	    loop:true,
	    margin:wtMargin,
	    nav:true,
	    center: wtCenter,
	    animateOut: 'fadeOut',
    	animateIn: 'fadeIn',
	    dots:false,
	    autoplayTimeout:4500,
	    // autoWidth:true,
	    autoplay:wtAutoplay,
	    responsive:{
	        0:{
	            items:w1,
	            margin:wtMargin2
	        },
	        600:{
	            items:w2,
	            margin:wtMargin2
	        },
	        800:{
	            margin:wtMargin
	        },
	        1000:{
	            items:w3
	        },
	        3000:{
	            items:w4
	        }
	    }
	})

	//wenn Textbox gehovert wird, dann wird Carousel angehalten
	$(selektor).find('.box').hover(
        function() {
          owl.trigger('stop.owl.autoplay');
        },
        function() {
          owl.trigger('play.owl.autoplay');
        }
    );

	if (selektor == '.typeWrap-mask_projektslider .owl-carousel') {
		var offset = $(selektor).find('.center').offset();
		if (!offset) return;
		var offsetLeft = offset.left;
		var wFirstItem = $(selektor).find('.owl-item:first-child').outerWidth();
		var wCenterItem = $(selektor).find('.owl-item.center').outerWidth();

		console.log('offsetLeft vom Hauptelement: '+offsetLeft);
		console.log('Breite des ersten Elements: '+wFirstItem);

		$(selektor).find('.owl-nav').css({'width':(wCenterItem+130)+'px'});
		$(selektor).find('.owl-nav').css({'margin-left':(offsetLeft-65)+'px'});
		$(selektor).find('.owl-stage-outer').css({'margin-left':(-((wCenterItem-wFirstItem)/2))+'px'});
	}
}

function slidermittext(selektor) {
	var wh = $(window).outerHeight();
	var ww = $(window).outerWidth();
	var hh = $('#headerWrap').outerHeight();
	var sub = wh-hh;

	$('.typeWrap-mask_slidermittext img').each(function() {
		$(this).css({'height':sub+'px'});
	});

	var ratio = ww/wh;


	$(selektor).each(function() {
		if ( (ratio>=2) && (/Android|webOS|iPhone|iPad|iPod|iPadPro|iPadOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) ) {
			$(this).css({'height':'auto'});
			$('body').addClass('mobileLandscape');
		} else {
			$(this).css({'height':sub+'px'});
			$('body').removeClass('mobileLandscape');
		}
	});

	
	// $('.typeWrap-mask_slidermittext').each(function() {
	// 	var imgH = $(this).find('.imgWrap').outerHeight();
	// 	var textH = $(this).find('.box').outerHeight();

	// 	if (textH > imgH) {
	// 		$(this).find('.imgWrap').css({'height':textH+50+'px'});
	// 	}
	// });
}


$(document).ready(function() {
  // Überprüfen, ob das Popup schon einmal gezeigt wurde
  var popupShown = parseInt(localStorage.getItem('popupShown'));
  var today_ts = new Date().getTime();
  

  $('.popupArea').each(function() {
    if ($(this).find('.imgorient-bottom').length > 0 || $(this).find('.imgorient-top').length > 0) {
      $(this).addClass('small');
    }
  });

  if ($('.popupArea').attr('data-showalways')=='1') popupShown=false;

  // Wenn nein, dann zeigen wir das Popup
  if(!popupShown) {
    $('.popupArea').show();
    $('.popupArea').css({'display':'flex'});
    localStorage.setItem('popupShown', today_ts);
  } else {
    var shorepeat_ts=1000*parseInt($('.popupArea').find('.popupImgorient').attr('data-showrepeat'));
    // Überprüfen, ob das gespeicherte Datum nicht dem heutigen Datum entspricht
    if( (popupShown+shorepeat_ts) < today_ts) {
      $('.popupArea').show();
      $('.popupArea').css({'display':'flex'});
      localStorage.setItem('popupShown', today_ts);
      
      
    }
  }

  $('.popupArea .closeButton').click(function() {
    $('.popupArea').hide();
  });

  popupHeight();
  
});

$(window).on('resize', function() {
  popupHeight();
});

function popupHeight() {
  var wh = $(window).height();
  var poph = $('.popupAreaInner').height();

  

  if (wh<poph) {
    $('.popupArea').addClass('justify-content-top');
  } else {
    $('.popupArea').removeClass('justify-content-top');
  }
}


$(document).ready(function() {
	lighthouse();
});

function lighthouse() {
	/* 
		SEO, Lighthouse verbessern
		Warnung vor "passiven event listernern" verhindern. Nach Einbindung von jQuery
		https://stackoverflow.com/questions/60357083/does-not-use-passive-listeners-to-improve-scrolling-performance-lighthouse-repo
	*/

	jQuery.event.special.touchstart = {
	    setup: function( _, ns, handle ) {
	        this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });
	    }
	};
	jQuery.event.special.touchmove = {
	    setup: function( _, ns, handle ) {
	        this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") });
	    }
	};
	jQuery.event.special.wheel = {
	    setup: function( _, ns, handle ){
	        this.addEventListener("wheel", handle, { passive: true });
	    }
	};
	jQuery.event.special.mousewheel = {
	    setup: function( _, ns, handle ){
	        this.addEventListener("mousewheel", handle, { passive: true });
	    }
	};
	// EO Lighthouseindex verbessern
}

var datenschutz_sitename=window.location.hostname;

var datenschutz_url="/datenschutz";
var impressum_url="/impressum";


// Textversion mit Cookie V1
//var datenschutz_introtxt="Wir setzen auf unserer Website Cookies ein. Einige von ihnen sind essentiell, während andere uns helfen unser Onlineangebot zu verbessern und wirtschaftlich zu betreiben.";
// Allgeminer Text V2
var datenschutz_introtxt='<b>Privatsphäre-Einstellungen</b><br>Diese Seite nutzt Website-Tracking-Technologien von Dritten, um ihre Dienste anzubieten, stetig zu verbessern und Werbung entsprechend den Interessen der Nutzer anzuzeigen. In diesem Zusammenhang ist es möglich, dass Daten in unsichere Drittstaaten übermittelt werden, in denen kein mit der EU vergleichbares Datenschutzniveau besteht. Ebenfalls ist es hierbei möglich dass Informationen ins Endgerät der Nutzer gespeichert oder aus diesem ausgelesen werden. Wenn Sie Ihre Einwilligung über "Alles Akzeptieren" erklären, können Sie diese jederzeit mit Wirkung für die Zukunft widerrufen oder ändern.';

var datenschutz_externe_medien_googlemaps='<i class="fa-brands fa-google"></i><br><b>Mit einem Klick</b> auf dieses Vorschaubild <b>willigen Sie ein</b>, dass Inhalte von Google LLC (USA) nachgeladen werden. Hierdurch erhält Google LLC Informationen darüber, dass Sie unsere Seite aufgerufen haben sowie die in diesem Rahmen technisch erforderlichen Daten (IP-Adresse und weitere Nutzungsdaten). Es kann nicht ausgeschlossen werden, dass Google LLC diese Daten für eigene Zwecke (einschließlich Profilbildung) verwendet und mit weiteren Daten über Sie verknüpft. Wir haben auf die weitere Datenverarbeitung durch Google LLC keinen Einfluss. Bitte beachten Sie, dass in Bezug auf Google LLC kein angemessenes Datenschutzniveau vorliegt. Weitere Informationen finden Sie in unserer Datenschutzerklärung';

var datenschutz_externe_medien_youtube='<i class="fa-brands fa-youtube"></i><br><b>Mit einem Klick</b> auf dieses Vorschaubild <b>willigen Sie ein</b>, dass Inhalte von Google LLC (USA) nachgeladen werden. Hierdurch erhält Google LLC Informationen darüber, dass Sie unsere Seite aufgerufen haben sowie die in diesem Rahmen technisch erforderlichen Daten (IP-Adresse und weitere Nutzungsdaten). Es kann nicht ausgeschlossen werden, dass Google LLC diese Daten für eigene Zwecke (einschließlich Profilbildung) verwendet und mit weiteren Daten über Sie verknüpft. Wir haben auf die weitere Datenverarbeitung durch Google LLC keinen Einfluss. Bitte beachten Sie, dass in Bezug auf Google LLC kein angemessenes Datenschutzniveau vorliegt. Weitere Informationen finden Sie in unserer Datenschutzerklärung';

var datenschutz_externe_medien_googlemaps_COOKIETEXT='Akzeptieren Sie die <b class="dsh-fingerprintClick">Cookieeinstellungen</b> um die Google-Karte zu sehen.';
var datenschutz_externe_medien_youtube_COOKIETEXT='Akzeptieren Sie die <b class="dsh-fingerprintClick">Cookieeinstellungen</b> um das Video zu sehen.';



function wtSetCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    //localStorage.setItem('cookie_'+name,value);
    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}
function wtGetCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    var ls_cookie;
    //ls_cookie= localStorage.getItem('cookie_'+name);

    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }

    return ls_cookie;
}
function wtEraseCookie(name) {   
    document.cookie = name+'=; Max-Age=-99999999;';  
}

function wtUrlDecode(code)
{
    // https://de.wikipedia.org/wiki/URL-Encoding
    code=decodeURI(code);
    while (code.indexOf("%3D")>0) code=code.replace("%3D","=");
    while (code.indexOf("%3B")>0) code=code.replace("%3B",";");
    while (code.indexOf("%23")>0) code=code.replace("%23","#");
    while (code.indexOf("%3A")>0) code=code.replace("%3A",":");
    while (code.indexOf("%2F")>0) code=code.replace("%2F","/");
    while (code.indexOf("%3F")>0) code=code.replace("%3F","?");
    while (code.indexOf("%26")>0) code=code.replace("%26","&");
    while (code.indexOf("%21")>0) code=code.replace("%21","!");
    while (code.indexOf("%24")>0) code=code.replace("%24","$");
    while (code.indexOf("%25")>0) code=code.replace("%25","%");
    while (code.indexOf("%40")>0) code=code.replace("%40","@");
    return code;
}

function checkExternalDataSources() {
    $('*[data-wturl]').each(function() {
        var code=wtUrlDecode($(this).attr("data-wturl"));        
        var type="";

        if (code.indexOf("maps")>0) type="gmaps";
        if (code.indexOf("youtube")>0) type="youtube";

        if (wtGetCookie('wt_externemedien')==1) {
            switch(type) {
                case 'youtube':
                    $(this).html(datenschutz_externe_medien_youtube);

                    $(this).on('click', function() {
                        $(code).insertAfter($(this));
                        $(this).hide();
                    });
                break;
                case 'gmaps':
                    $(this).html(datenschutz_externe_medien_googlemaps);

                    $(this).on('click', function() {
                        $(code).insertAfter($(this));
                        $(this).hide();
                    });
                break;
            }            
        } else {
            switch(type) {
                case 'youtube':
                    $(this).html(datenschutz_externe_medien_youtube_COOKIETEXT);
                break;
                case 'gmaps':
                    $(this).html(datenschutz_externe_medien_googlemaps_COOKIETEXT);
                break;
            }
        }
    })

    // YT

    // GM
}

function toggeCookiehinweis_options() {
  // $('#cookiehinweis_options').toggle();
  $('.cookiehinweis_more_infos').hide();
  $('#cookiehinweis').toggleClass('cookieoptions');

  $('.cookiehinweis_more_infos_link').click(function() {
    $('.cookiehinweis_more_infos').hide();
    $(this).next().toggle();
  });

  $('.cookiehinweis_optionsClose').click(function() {
    $('.cookiehinweis_more_infos').hide();
  });
}



function cookiehinweisAdjustment() {
    $('#cookiehinweis_options').addClass('active');

    $('#cookiehinweis').removeClass('visibleOptions');

    $('.cookiehinweis_CloseOptionBlock').addClass('active');
    $('#cookiehinweis_auswahlSpeichern').removeClass('active');

    if ('#cookiehinweis_options.active') {
      $('#cookiehinweis').addClass('visibleOptions');
      $('#cookiehinweisAdjustmentBtn').removeClass('active');
      $('.cookiehinweis_CloseOptionBlock').removeClass('active');

      $('#cookiehinweis_auswahlSpeichern').addClass('active');
    }

    $('.cookiehinweis_CloseOptionBlock').click(function() {
      $('#cookiehinweis').removeClass('visibleOptions');
      $('#cookiehinweis_options').removeClass('active');
      $('#cookiehinweisAdjustmentBtn').addClass('active');
      $('#cookiehinweis_auswahlSpeichern').removeClass('active');
    });


}

function storeCookiePreferencesAcceptAll() {
  $('input[type="checkbox"]').prop("checked","checked");
  acceptCookieHinweis();
}
function storeCookiePreferencesRejectAll() {
  $('input[type="checkbox"]').prop("checked","");
  acceptCookieHinweis();
}

function acceptCookieHinweis() {
   $('#cookiehinweis input').each(function() {
      var ch=$(this).prop('checked');
      var cookiename=$(this).attr('data-cookie');
      if (ch) {
         wtSetCookie(cookiename,1,365);
      } else {
         wtEraseCookie(cookiename);
      }
   });
   wtSetCookie("wt_cookiehinweis",1,365);
   $('#cookiehinweis').fadeOut();
   window.location.reload();
}

function displayHinweis() {
   var txt='Wir verwenden Cookies, um unsere Webseite für Sie möglichst benutzerfreundlich zu gestalten. Wenn Sie fortfahren, nehmen wir an, dass Sie mit der Verwendung von Cookies auf der Webseite '+datenschutz_sitename+' einverstanden sind.';  

   var html='';

   
   html+='<div id="cookiehinweisOuter"><div id="cookiehinweis">';
   // html+='<div id="logocookie"><img src="/fileadmin/template/img/logo.svg" alt="Logo"></div>';
   html+='<div id="cookiehinweis_content">';

   html+='<div id="cookiehinweis_contentInner">';

   html+='<div id="cookieIntrotext">';
   html+=datenschutz_introtxt;
   html+='</div>';

   html+='<div id="cookiehinweis_options">';
   html+='<div class="cookiehinweis_CloseOptionBlock"><i class="fa fa-times"></i></div>';

   html+='<div class="cookiehinweis_options_innerWrap">';


   // Essentiell
    html+='<div class="cookiehinweis_options_row">';
    html+='<div class="big">';
    html+='<div class="col" valign="top">';
    html+='<div class="cookiehinweis_switch_label"><h4>Essenziell</h4><div class="labelText">Essenzielle Cookies ermöglichen grundlegende Funktionen und sind für die einwandfreie Funktion der Website erforderlich.</div>';

    html+='<div class="btnWrap"></div><div class="cookiehinweis_more_infos_link"><i class="fas fa-info-circle"></i> Cookieinformationen</div>';
    html+='<div class="cookiehinweis_more_infos">';
    html+='<div class="cookiehinweis_optionsClose"><i class="fa fa-times"></i></div>';
    html+=' <div class="table inner">';
    html+=' <div class="rowx"><div class="colx">Name</div><div class="colx">Wecotec Cookie</div></div>';
    html+=' <div class="rowx"><div class="colx">Anbieter</div><div class="colx">Eigentümer dieser Webseite</div></div>';
    html+=' <div class="rowx"><div class="colx">Zweck</div><div class="colx">Speichert die Einstellungen der Besucher, die in der Cookie Box ausgewählt wurden.</div></div>';
    html+=' <div class="rowx"><div class="colx">Cookie Name</div><div class="colx">wt_cookiehinweis, wt_externemedien, wt_marketing</div></div>';
    html+=' </div>';
    html+='</div>';

    html+='</div></div></div>';
    html+='</div> <!-- eo cookiehinweis_options_row -->';


    //Marketingt
    var cookieSet=wtGetCookie("wt_marketing");
    var ch=(cookieSet==1)?("checked"):("");

    html+='<div class="cookiehinweis_options_row">';
    html+='<div class="big"><div class="col head">';
    html+='<label class="cookiehinweis_switch">';
    html+='<input '+ch+' data-cookie="wt_marketing" type="checkbox" id="marketing" value=1>';   
    html+='<span class="cookiehinweis_slider round"></span>';
    html+='</label>';
    html+='<label for="marketing"><h4>Marketing</h4></label>';
    html+='</div><div class="col" valign="top">';
    html+='<div class="cookiehinweis_switch_label"><div class="labelText">Marketing-Cookies werden von Drittanbietern oder Publishern verwendet, um personalisierte Werbung anzuzeigen. Sie tun dies, indem sie Besucher über Websites hinweg verfolgen.</div>';

    html+='<div class="btnWrap"></div><div class="cookiehinweis_more_infos_link"><i class="fas fa-info-circle"></i> Cookieinformationen</div>';
    html+='<div class="cookiehinweis_more_infos">';
    html+='<div class="cookiehinweis_optionsClose"><i class="fa fa-times"></i></div>';
    html+=' <div class="table inner">';
    html+=' <div class="rowx"><div class="colx">Name</div><div class="colx">Google Analytics</div></div>';
    html+=' <div class="rowx"><div class="colx">Anbieter</div><div class="colx">Google LLC</div></div>';
    html+=' <div class="rowx"><div class="colx">Zweck</div><div class="colx">Cookie von Google für Website-Analysen. Erzeugt statistische Daten darüber, wie der Besucher die Website nutzt.</div></div>';
    html+=' <div class="rowx"><div class="colx">Datenschutzerklärung</div><div class="colx"><a href="https://policies.google.com/privacy" target=_blank>policies.google.com/privacy</a></div></div>';
    html+=' <div class="rowx"><div class="colx">Cookie Name</div><div class="colx">_ga,_gat,_gid</div></div>';
    html+=' <div class="rowx"><div class="colx">Cookie Laufzeit</div><div class="colx">2 Jahre</div></div>';
    html+=' </div>';
    html+='</div>';


    html+='</div></div></div>';
    html+='</div> <!-- eo cookiehinweis_options_row -->';


    // funktionell (YT, GM)
   var cookieSet=wtGetCookie("wt_externemedien");
   var ch=(cookieSet==1)?("checked"):("");

   html+='<div class="cookiehinweis_options_row">';
   html+='<div class="big"><div class="col head">';
   html+='<label class="cookiehinweis_switch">';
   html+='<input '+ch+' data-cookie="wt_externemedien" type="checkbox" id="externemedien" value=1>';   
   html+='<span class="cookiehinweis_slider round"></span>';
   html+='</label>';
   html+='<label for="externemedien"><h4>Externe Medien</h4></label>';
   html+='</div><div class="col" valign="top">';
   html+='<div class="cookiehinweis_switch_label"><div class="labelText">Inhalte von Videoplattformen und Social-Media-Plattformen werden standardmäßig blockiert. Wenn Cookies von externen Medien akzeptiert werden, bedarf der Zugriff auf diese Inhalte keiner manuellen Zustimmung mehr.</div>';

   html+='<div class="btnWrap"></div><div class="cookiehinweis_more_infos_link" onClick="$(\'.cookiehinweis_more_infos\').hide();$(this).next().toggle()"><i class="fas fa-info-circle"></i> Cookieinformationen</div>'
   html+='<div class="cookiehinweis_more_infos">';
   html+='<div class="cookiehinweis_optionsClose"><i class="fa fa-times"></i></div>';
   html+=' <div class="table inner">';
   html+=' <div class="rowx"><div class="colx">Name</div><div class="colx">Google Maps</div></div>'
   html+=' <div class="rowx"><div class="colx">Anbieter</div><div class="colx">Google</div></div>'
   html+=' <div class="rowx"><div class="colx">Zweck</div><div class="colx">Wird zum Entsperren von Google Maps-Inhalten verwendet.</div></div>'
   html+=' <div class="rowx"><div class="colx">Datenschutzerklärung</div><div class="colx"><a href="https://policies.google.com/privacy" target=_blank>policies.google.com/privacy</a></div></div>'
   html+=' <div class="rowx"><div class="colx">Host(s)</div><div class="colx">.google.com</div></div>'
   html+=' <div class="rowx"><div class="colx">Cookie Name</div><div class="colx">NID</div></div>'
   html+=' <div class="rowx"><div class="colx">Cookie Laufzeit</div><div class="colx">6 Monate</div></div>'
   html+=' </div>';
   html+='<br>';
   html+=' <div class="table inner">';
   html+=' <div class="rowx"><div class="colx">Name</div><div class="colx">YouTube</div></div>'
   html+=' <div class="rowx"><div class="colx">Anbieter</div><div class="colx">YouTube</div></div>'
   html+=' <div class="rowx"><div class="colx">Zweck</div><div class="colx">Wird verwendet, um YouTube-Inhalte zu entsperren.</div></div>'
   html+=' <div class="rowx"><div class="colx">Datenschutzerklärung</div><div class="colx"><a href="https://policies.google.com/privacy" target=_blank>policies.google.com/privacy</a></div></div>'
   html+=' <div class="rowx"><div class="colx">Host(s)</div><div class="colx">.google.com</div></div>'
   html+=' <div class="rowx"><div class="colx">Cookie Name</div><div class="colx">NID</div></div>'
   html+=' <div class="rowx"><div class="colx">Cookie Laufzeit</div><div class="colx">6 Monate</div></div>'
   html+=' </div>';

   html+='</div>';

   html+='</div></div></div>';
   html+='</div> <!-- eo cookiehinweis_options_row -->';




   html+='</div><!-- eo cookiehinweis_options_innerWrap -->';

   html+='</div><!-- eo options -->';
   html+='</div><!-- eo cookiehinweis_contentInner -->';

   html+='<div class="buttons">';
   html+='<div class="buttonWrap"><div id="cookiehinweis_store_options_accept_all" class="buttonLink bgcolor" onClick="storeCookiePreferencesAcceptAll()"><i class="fas fa-save"></i> Alle akzeptieren</div></div>';
   html+='<div class="buttonWrap"><div id="cookiehinweisAdjustmentBtn" class="buttonLink active" onClick="cookiehinweisAdjustment()">Einstellungen</div></div>';
   html+='<div class="buttonWrap"><div id="cookiehinweis_auswahlSpeichern" class="buttonLink" onClick="acceptCookieHinweis()">Auswahl speichern</div></div>';
   html+='<div class="buttonWrap"><div id="cookiehinweisRejectAll" class="buttonLink active" onClick="storeCookiePreferencesRejectAll()">Alle ablehnen</div></div>';
   html+='</div><!-- eo buttons -->';

   html+='</div><!-- eo cookiehinweis_content-->';

   html+='<div id="datatext"><a href="'+datenschutz_url+'">Datenschutz</a>';
   html+='<a href="'+impressum_url+'">Impressum</a></div>';

   html+='</div><!-- eo cookiehinweis--></div>';

   $("body").prepend(html);
  toggeCookiehinweis_options();
}

$(document).ready(function() {
    var botPattern = "(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Google-InspectionTool|Mediapartners-Google|bingbot|slurp|java|wget|curl|Commons-HttpClient|Python-urllib|libwww|httpunit|nutch|phpcrawl|msnbot|jyxobot|FAST-WebCrawler|FAST Enterprise Crawler|biglotron|teoma|convera|seekbot|gigablast|exabot|ngbot|ia_archiver|GingerCrawler|webmon |httrack|webcrawler|grub.org|UsineNouvelleCrawler|antibot|netresearchserver|speedy|fluffy|bibnum.bnf|findlink|msrbot|panscient|yacybot|AISearchBot|IOI|ips-agent|tagoobot|MJ12bot|dotbot|woriobot|yanga|buzzbot|mlbot|yandexbot|purebot|Linguee Bot|Voyager|CyberPatrol|voilabot|baiduspider|citeseerxbot|spbot|twengabot|postrank|turnitinbot|scribdbot|page2rss|sitebot|linkdex|Adidxbot|blekkobot|ezooms|dotbot|Mail.RU_Bot|discobot|heritrix|findthatfile|europarchive.org|NerdByNature.Bot|sistrix crawler|ahrefsbot|Aboundex|domaincrawler|wbsearchbot|summify|ccbot|edisterbot|seznambot|ec2linkfinder|gslfbot|aihitbot|intelium_bot|facebookexternalhit|yeti|RetrevoPageAnalyzer|lb-spider|sogou|lssbot|careerbot|wotbox|wocbot|ichiro|DuckDuckBot|lssrocketcrawler|drupact|webcompanycrawler|acoonbot|openindexspider|gnam gnam spider|web-archive-net.com.bot|backlinkcrawler|coccoc|integromedb|content crawler spider|toplistbot|seokicks-robot|it2media-domain-crawler|ip-web-crawler.com|siteexplorer.info|elisabot|proximic|changedetection|blexbot|arabot|WeSEE:Search|niki-bot|CrystalSemanticsBot|rogerbot|360Spider|psbot|InterfaxScanBot|Lipperhey SEO Service|CC Metadata Scaper|g00g1e.net|GrapeshotCrawler|urlappendbot|brainobot|fr-crawler|binlar|SimpleCrawler|Livelapbot|Twitterbot|cXensebot|smtbot|bnf.fr_bot|A6-Indexer|ADmantX|Facebot|Twitterbot|OrangeBot|memorybot|AdvBot|MegaIndex|SemanticScholarBot|ltx71|nerdybot|xovibot|BUbiNG|Qwantify|archive.org_bot|Applebot|TweetmemeBot|crawler4j|findxbot|SemrushBot|yoozBot|lipperhey|y!j-asr|Domain Re-Animator Bot|AddThis)";
    var re = new RegExp(botPattern, 'i');
    var userAgent = navigator.userAgent; 
    if (re.test(userAgent)) return;

    checkExternalDataSources();
    var html='';
    // html='<div id="dsh-fingerprint" class="dsh-fingerprintClick"><i class="fa-solid fa-fingerprint"></i><span>Cookies</span></div>';
    html='<div id="dsh-fingerprint" class="dsh-fingerprintClick"><i class="fa-solid fa-cookie-bite"></i><span>Cookies</span></div>';
    $("body").prepend(html);
    $('.dsh-fingerprintClick').bind('click',function() {
      if ($('#cookiehinweis').length==0) displayHinweis();
    });    

   if (wtGetCookie('wt_cookiehinweis')==1) return;
   

   displayHinweis();
});
$(document).ready(function() {
  //Google-Maps oder Youtube-Klickfunktion
  $('.dsgvoWrap').click(function() {
    var code = $(this).attr('data-code');
    var elasticPadding = $(this).attr('data-elasticPadding');
    $(this).html('<div class="elastic" style="padding-bottom: '+elasticPadding+';">'+code+'</div>');
    $(this).addClass('active');
  });

  //Checkboxen von Formularen
  replaceHTML("label","Datenschutzhinweis",'<a href="/datenschutz" target="_blank">Datenschutzhinweis</a>');
  replaceHTML("label","Datenschutzbestimmungen",'<a href="/datenschutz" target="_blank">Datenschutzbestimmungen</a>');
});


function replaceHTML(tag,search,replace) {
  $(tag).each(function(i, e) {  
    var html=$(this).html();
    html=html.replace(search,replace);
    $(this).html(html);
  });
}