		var nfyDomain = "https://www.rnz.de";
		var nfySso = nfySso || {
			nfyHandleLogin: function(form)
			{
				var jForm = $(".nfy-login-container");
				jForm.find(".nfy-error-message").html("");
				jForm.find("button").append('<span class="nfy-loader"> <i class="fa fa-spinner fa-spin"></i></span>');
				$(form).find("input[type=submit],button").prop("disabled", true);

				$(form).addClass("nfy-loading");
				var submitData = $(form).serialize();
				// stay logged on mobile devices
				var nfyWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
				// if ( nfyWidth < 800 )
				// {
					submitData += '&staylogged=1';
				// }
				$.ajax({
				  url: nfyDomain+"/REST/community/checklogin",
				  method: "POST",
				  data: submitData,
				  xhrFields: {
				    withCredentials: true
				  }
				}).done(function(data) {
					console.log(data);
					jForm.removeClass("nfy-error");
					if ( data.error )
					{
						jForm.addClass("nfy-error");
						var errorMessage = $('<div>'+ data.error + '</div>');
						jForm.find(".nfy-error-message").append(errorMessage);
					}

					if ( data.username )
					{
						// show user data
						$('.nfy-status-not-logged').hide();
						$('.nfy-status-logged').show();
						$('.nfy-username').html(data.username);
					}

					if ( data.hasEpaper )
					{
						$('.nfy-has-epaper').removeClass("hide");
					}

					if ( data.redirect )
					{
						window.location.href = data.redirect;
					}
					else if( !data.error )
					{
						window.location.reload();
					}

				}).always(function() {
				  $(form).find("input[type=submit],button").prop("disabled", false);
				  $(form).removeClass("nfy-loading");
				  $(form).find(".nfy-loader").remove();
				});
				return false;
			},

			nfyHandleRefresh: function(token, refresh)
			{
				var tokenData = token ? token : "";
				$.ajax({
				  url: nfyDomain+"/REST/community/refresh",
				  data: "token=" + tokenData,
				  method: "POST",
				  xhrFields: {
				    withCredentials: true
				  }
				}).done(function(data) {
					if ( data.error )
					{
						nfySso.nfyHandleLogout(true);
					}

					if ( refresh )
					{
						if ( window.location.pathname.match(/.html/) )
						{
							window.location.href = window.location.pathname;
						}
						else
						{
							window.location.href = window.location.pathname+window.location.search;
						}
					}
				});
			},

			nfyHandleLogout: function(reload)
			{
				$.ajax({
				  url: nfyDomain+"/REST/community/logout",
				  method: "POST",
				  xhrFields: {
				    withCredentials: true
				  }
				}).done(function() {
					$('.nfy-status-not-logged').show();
					$('.nfy-status-logged').hide();
					if ( typeof reload != "undefined" )
					{
						window.location.reload();
					}
				});
			},

			nfyHandleEpaper: function()
			{
				$.ajax({
				  url: nfyDomain+"/REST/community/epaper",
				  method: "POST",
				  xhrFields: {
				    withCredentials: true
				  }
				}).done(function(data) {
					if (data.redirect){
						window.location.href = data.redirect;
					}
					else {
						window.alert(data.error);
						$('.nfy-status-not-logged').show();
						$('.nfy-status-logged').hide();
						if ( typeof reload != "undefined" )
						{
							window.location.reload();
						}
					}
				});
			},

			nfyHandlePasswordReminder: function()
			{
				var nfyForgetForm = jQuery('<div id="nfy-password-reminder"><form>Bitte Benutzername und E-Mail-Adresse angeben, um ein neues Passwort zu erhalten.<div><input name="username" placeholder="Benutzername" required><br><input name="email" placeholder="E-Mail-Adresse" required><div class="nfy-error-msg"></div><button>Neues Passwort anfordern</button></div></form></div>').appendTo("body");

				var dialogWidth = 300;
				if ( jQuery(window).width() < dialogWidth )
				{
					dialogWidth = jQuery(window).width();
				}

				var dialog = $( nfyForgetForm ).dialog({
				      autoOpen: true,
				      title: "Passwort vergessen?",
				      closeText: "x",
				      height: 330,
				      width: dialogWidth,
				      modal: true,
				      buttons: {
				      },
				      close: function() {
				        form[ 0 ].reset();
				      },
				      position: { my: "left top", at: "top+100", of: ".nfy-inner" }
				    });

				    form = dialog.find( "form" ).on( "submit", function( event ) {
				      event.preventDefault();
				        var submitData = $(this).serialize();
				        nfySso.nfyHandlePasswordForm(submitData);
				        return false;
				    });
			},

			nfyHandlePasswordForm: function(submitData)
			{
			   $.ajax({
				  url: nfyDomain+"/REST/community/password",
				  method: "POST",
				  data: submitData,
				  xhrFields: {
				    withCredentials: true
				  }
				}).done(function(data) {
					if ( data.error )
					{
						$("#nfy-password-reminder .nfy-error-msg").text(data.error);
					}
					if ( data.msg )
					{
						$("#nfy-password-reminder .nfy-error-msg").text(data.msg);
					}

					if ( data.success )
					{
						$("#nfy-password-reminder .nfy-error-msg").prepend('<i class="fa fa-check-circle-o"></i> ');
						setTimeout(function(){ $( "#nfy-password-reminder" ).dialog().dialog("close"); }, 5000);
					}
				});
			},

			nfyHasPayment: function(){ return false;}

		};

		var nfyShowLogin = '<div class="nfy-login-container"><div class="nfy-status-not-logged "><div class="nfy-head-title">Digital-Login</div><form class="nfy-form" onSubmit="return nfySso.nfyHandleLogin(this);"><input placeholder="Benutzername" name="username" type="text" required="required"/><input placeholder="Passwort" name="password" type="password" required="required" /><div class="nfy-login-options"><a class="hide nfy-has-epaper" href="#null" onclick="nfySso.nfyHandleEpaper()";>E-Paper lesen</a><a href="#null" onclick="nfySso.nfyHandlePasswordReminder()">Passwort vergessen?</a> <a class="nfyc-paywall-register" target="_blank" href="https://osc.rnz.de/sap/bc/gui/sap/its/zstamm/!?~Theme=14&~OkCode=F_DUMMY&~PARAMETER=LOGIN%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20EVIVA%20%20%20%20%20RNZ%20PR00100000000000000X&~exitURL=">Registrierung</a></div><button>anmelden</button><div class="nfy-error-message"></div></form></div><div class="nfy-status-logged hide"><div class="nfy-username"></div><div><a class="hide nfy-has-epaper" href="#null" onclick="nfySso.nfyHandleEpaper()";>E-Paper lesen</a></div><a title="Hier ausloggen" href="#null" onclick="nfySso.nfyHandleLogout()"> <i class="fa fa-power-off"></i></a></div></div>';

		/*$(document).ready(function() {
			nfySso.nfyHandleEpaper();
			setInterval(function() {
				nfySso.nfyHandleEpaper();
			}, 60000);
		}); */var nfyCommunityUser = {   "isLoggedIn" : function() { return false; },
   "username" : function() { return ""; },
   "userid" : function() { return ""; },
   "clientId" : function() { return 0; },
   "paymentViews" : function() { return {"data":{"max":10,"expires":"+1 year","cleanup":"+30 days","localstorage":true,"referer":[]},"remaining":9,"viewed":1}; }
};		jQuery(document).ready(function($){
			$('.nfy-generic-navigation-link').on('click', function(e){
				if ( $(this).text().match(/E-Paper/) )
				{
					nfySso.nfyHandleEpaper();
					e.PreventDefault();
				}
			});
			
			$(".payment-info-counter-container").removeClass("hide");

			//handle mobile menu with login
			var isMobile = parseInt( $('.responsive-flag').css('z-index') ) <= 768;

			if ( isMobile && $('.nfy-login-wrapper .nfy-login-container').length )
			{
				$('.nfy-login-wrapper .nfy-login-container').prependTo('.nfy-mobile-login-container');
			}

			// handle mobile menu with login on resize
			$(window).resize( function() {
				var isMobile = parseInt( $('.responsive-flag').css('z-index') ) <= 768;
				if ( isMobile && $('.nfy-login-wrapper .nfy-login-container').length )
				{
					$('.nfy-login-wrapper .nfy-login-container').prependTo('.nfy-mobile-login-container');
				}
				else if ( !isMobile && $('.nfy-mobile-login-container .nfy-login-container').length )
				{
					$('.nfy-mobile-login-container .nfy-login-container').prependTo('.nfy-login-wrapper');
				}
			});

			// handle/generate redirect links

			if ( $('.nfyc-paywall-add-redirect').length )
			{
				$('.nfyc-paywall-add-redirect').each(function(index){
					if ( $(this).attr("href").match(/callback=URI$/) )
					{
						var nfyCallbackUri = window.location.pathname;
						if ( window.location.search )
						{
							nfyCallbackUri += window.location.search;
						}

						$(this).attr("href", $(this).attr("href").replace(/=URI/g, '='+nfyCallbackUri));
					}
				});
			}

			if ( $('.nfyc-paywall-redirect').length )
			{
				$('.nfyc-paywall-redirect').each(function(index){
					if ( $(this).attr("href").match(/callbackurl=$/) || $(this).attr("href").match(/#currenturi$/) )
					{
						var nfyCallbackRedirect = '';

                            console.log("hier1");
						 if (  window.location.hash.match(/#callback=(.*)/) )
						 {
						    if ( nfyCallbackRedirect == '' )
						    {
						        nfyCallbackRedirect = window.location.protocol+"//"+window.location.hostname;
						    }
						    nfyCallbackRedirect += window.location.hash.match(/#callback=(.*)/)[1];
						 }
						 else if ( $(this).attr("href").match(/#currenturi$/) )
						 {
						    console.log("hier");
						    nfyCallbackRedirect = window.location.href;
						    $(this).attr("href", $(this).attr("href").replace(/#currenturi/g, ""));
						 }
						 else
						 {
						    console.log("hier2");
							nfyCallbackRedirect = nfyPaywallStartPage;
						 }
						$(this).attr("href", $(this).attr("href") + encodeURIComponent(nfyCallbackRedirect+"#nfyForceRefresh"));
					}
				});
			}
			if ( $('.nfyc-paywall-register').length )
			{
				$('.nfyc-paywall-register').each(function(index){
					$(this).attr("href", $(this).attr("href") + encodeURIComponent(window.location.href+"#nfyForceRefresh"));
				});
			}

			if ( window.location.hash.match(/#nfyForceRefresh/) )
			{
				var getQueryString = function ( field, url ) {
				    var href = url ? url : window.location.href;
				    var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
				    var string = reg.exec(href);
				    return string ? string[1] : null;
				};

				var statuscode = getQueryString("statuscode");
				var token = getQueryString("token");

				nfySso.nfyHandleRefresh(token, true);
			}
		});