


var width = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;


if (holeCookie) {holeCookie("Style");}
style=cookieWert;


if (holeCookie) {holeCookie("rev");}
// if (cookieWert == "1") {reverse = 'reverse';} else {reverse = 'normal';}

if (style == 12 || cookieWert == "1" ) {
	reverse = 'reverse';
} else {
	reverse = 'normal';
}


/* ///////// audio-sprite: ////////////// */
/* /////// end audio-sprite ///////////////// */

var flood_test ="4";

// var konfig = 0;
// konfig = "";


away_msg = '';
function away() {
	away_msg = 'weg';
	add();
	alert('Du bist jetzt (vorübergehend) "away from keyboard", also "nicht an der Tastatur". \n Im Chatfenster wird für andere User eine entsprechende Meldung angezeigt. \n Wenn du zurück bist, und wieder aktiv am Chat teilnehmen willst, dann drücke in dieser Anzeige auf "OK”\, dann wird dein afk-Status beendet [wieder da].');
	
	away_msg = 're';
	add();
	away_msg = '';
}

// function waermestube(){
//	away_msg = 'warm';
//	add(); 
//	away_msg = '';
//}

// https://stackoverflow.com/questions/19020830/autoclose-alert
function tempAlert(msg,duration) {
	var el = document.createElement("div");
	el.setAttribute("style","position:relative;top:-60px;left:0;font-size:.9em;background-color:white;padding:6px;");
	el.innerHTML = msg;
	setTimeout(function(){
		el.parentNode.removeChild(el);
	},duration);
	document.getElementById('uo').appendChild(el);
}


function copyurl(a) {	
	var text = a;
	// navigator.clipboard.writeText(text);
	
	navigator.clipboard.writeText(text).then(function() {
	  // console.log('Copying ' + a + ' to clipboard was successful!');
	  tempAlert('IP ' + a + ' copied to clipboard',2000);
	}, function(err) {
	  console.error('Could not copy to clipboard ', err);
	});		
}


// function popup(new_data) {
//	if (holeCookie) {holeCookie("pop_up");}
//	if (cookieWert == "aus" && konfig == "enable") { 
//		if (reverse == 'normal') {
//			start = new_data.lastIndexOf("pointer")+9;
//			post = new_data.substr(start);
//		} else {
//			start = new_data.indexOf("pointer")+9; 
//			end = new_data.indexOf("</span></p>"); 
//			length = end - start;	
//			post = new_data.substr(start,length)+'</p>';	
//		}
//		
//		anex = "<script>setTimeout(window.close,60000);</script>";
//
//		var w = window.open('', 'popup', 'width=300,height=150,left=0,top=0');
//		if (w) { 
//			w.document.write('<p><span>'+post+anex); 
//			new_data ="";
//			w.document.close(); // needed for chrome and safari?
//		} else {
//	    	alert("Dein Browser verhindert leider die Anzeige eines Popups.");
//		}
//	}
//}



// Enter schickt die Eingabe ab anstelle einer Zeilenschaltung in textarea
if (document.getElementById('line')) {
	document.f.line.onkeypress = function(e){
	  e = e || event;
		if (e.keyCode == 13 && !e.shiftKey) { 
	    add(); return false;
	  }
	  return true;
	}
}


// var Opera = (navigator.userAgent.match(/Opera|OPR\//) ? true : false);
var iOS = !!navigator.platform.match(/iPhone|iPod|iPad/); 
if (iOS ===true) {
	if (document.getElementById("soundwahl")) {
		document.getElementById("soundwahl").style.display = "none";
	} 
}


var show_user;

var sb = 0;
if (location.href.indexOf("shoutbox") != -1) sb = 1;

var check_n = 0;
var old_data = "--";
var old_result = 1;


var anz_opt = "Einstellungen ";

var light;
light = "no";

var nick;
nick = "";




function strpos (haystack, needle, offset) {
    // Finds position of first occurrence of a string within another  
    // discuss at: http://phpjs.org/functions/strpos    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);    // *     returns 1: 14
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}

/* nur noch aus dem viewport schieben */
function klappx(beitrag) {
     if (document.getElementById) {
          if (document.getElementById(beitrag ).style.display == 'none') {
              document.getElementById(beitrag).style.display = "block";
              document.getElementById('einaus_' +beitrag).innerHTML = anz_opt+' [&#8722;]';
          } else  {
              document.getElementById(beitrag).style.display = "none";
              document.getElementById('einaus_' + beitrag).innerHTML = anz_opt+' [+]';
          }
     }
}


function klapp(beitrag) {
	if (document.getElementById(beitrag)) {
		if (document.getElementById(beitrag).style.position == 'absolute') {
			document.getElementById(beitrag).style.position = "static";
			document.getElementById('einaus_' +beitrag).innerHTML = anz_opt+' <span aria-hidden="true">△</span> <span id="esc" style="font-weight:400; font-size: .8em;">(strg+1)</span>';
			  
		} else  {
			document.getElementById(beitrag).style.position = "absolute";
			document.getElementById(beitrag).style.left = -1000;
			document.getElementById(beitrag).style.top = -1000;
			document.getElementById(beitrag).style.width = 0;
			document.getElementById(beitrag).style.height = 0;
			document.getElementById(beitrag).style.overflow = 'hidden';
			document.getElementById(beitrag).style.display = 'inline';
			document.getElementById('einaus_' + beitrag).innerHTML = anz_opt+'<span aria-hidden="true">▽</span> <span id="esc" style="font-weight:400; font-size: .8em;">(strg+1)</span> ';
		}
	}
//	playsound(''); // damit beim Klappen kein Sound gespielt wird.
}

function kp(e){
	if (!e) e=event;
	if (e.ctrlKey && e.keyCode==49) {klapp('ae'); document.getElementById("reverse").focus(); return false;} /* strg + 1 */
	if (e.keyCode==27  && document.getElementById('ae').style.position != 'absolute'){klapp('ae'); document.getElementById("line").focus();}
}
document.onkeydown=kp;


function FensterOeffnen (url) {
	var width  = screen.width * 0.45;
	var height = screen.height * 0.75;
	var left   = (screen.width  - width)/1.1;
	var top    = (screen.height - height)/3;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=yes';
	params += ', status=no';
	params += ', toolbar=no';
	params += ', dependent=yes';
	newwin=window.open(url,'usr_smileys', params);
	if (window.focus) {newwin.focus()}
	return false;
}


var self_close = "no";
var self_close = "no";

function closepopup() {
	if(typeof(newwin) == "object" && false == newwin.closed && self_close != "on") {
		newwin.close ();
	} else {
		// do nothing;
	}
}


function YTPop (Adresse) {
//	var iPhone = !!navigator.platform.match(/iPhone|iPod/);

//	if (iPhone === false) {
		MeinFenster2 = window.open(Adresse,'youtube','width=800, height=450, left=0, top=0, toolbar=no, location=no, menubar=no, scrollbars=yes, status=no, resizable=yes, dependent=yes').focus();
//	} 
}

function loadytiframe(newsrc){
	var newloc = newsrc;
	document.getElementById('mob_yt').style.height = "53vmin";
	document.getElementById('mob_yt').setAttribute('src', newloc);
}


function CookieSetz(Bezeichner,Wert,Dauer) {
	jetzt=new Date();
	Auszeit=new Date(jetzt.getTime()+Dauer*86400000);
	document.cookie=Bezeichner+"="+Wert+";expires="+Auszeit.toGMTString()+";";
}


var cookieWert;
function holeCookie(keksname) {
      var alleCookies, i;
	alleCookies=document.cookie;
	cookieArr=alleCookies.split(";");
	for(var i=0;i < cookieArr.length;i++) {
		if(cookieArr[i].split("=")[0].replace(/\s+/,"") == keksname) {
			cookieWert=cookieArr[i].split("=");
			cookieWert=decodeURIComponent(cookieWert[1].replace(/\+/g," "));
			return true;
		}
	}
  	return false;
}



// Abfrage, ob Admin:

var isadmin = "0";
var ismod = "0";

if(isadmin==1 && ismod==1) {alert ("Achtung! Du bist gleichzeitig Admin und Moderator!")};

allow_url_fopen = 1;


// die Anzeige der online-Zeit bei reloads oder Raumwechsel nicht zuruecksetzen:
var Jetzt = new Date();
cookieWert ="";
holeCookie("arrival");
if (cookieWert != "") {
	login = cookieWert;
} else {
	login = Jetzt.getTime();
}
// console.log (login);



// unerlaubte Raumnamen zurueckweisen:
function room_name() {
	if (document.forms[2].room.value.match(/\W/)) {

		alert ("Nicht erlaubte Zeichen im Raumnamen!");
		return false;
	}
}




// AJAX http://board.gulli.com/thread/801675-php-script-aus-einem-javascript-aufrufen/
function get(url, callback_function, return_xml){
	var http_request = false;

	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml; charset= iso-8859-1');
		}
	}else if(window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Leider unterstuetz Ihr Browser diese Funktion nicht.');
		return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				if (return_xml) {
					eval(callback_function + '(http_request.responseXML)');
				} 
			} else {
				alert('Problem: ' + http_request.status + ')');
			}
		}
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}


function playmp3_mit_http(typ) {
	document.getElementById("mp3").style.display="inline-block";
	document.getElementById("mp3").innerHTML = '<audio autoplay="autoplay" controls="controls" onended="hide_player()" controlslist="nodownload noplaybackrate"><source src="'+typ+'"  ></audio>';
	//document.getElementById("line").focus();
	
	
	

	if (holeCookie) {holeCookie("counted");}
	if (cookieWert != typ) { // bei wiederholten Klicks des selben Titels nur einmal zaehlen
		get("mp3log.php?file="+typ,""); // Aufruf der Funktion zum Schreiben des Logfiles
		
		// erst nach 2 Min. wird der selbe Titel erneut gezaehlt
		var ablauf = new Date();
		var Minuten = ablauf.getTime() + ( 120 * 1000); 
		ablauf.setTime(Minuten);
		document.cookie="counted="+typ+"; expires=" + ablauf.toGMTString();
	}
}





function playmp3olog_mit_http(typ) {	
	document.getElementById("mp3").style.display="inline-block";
	document.getElementById("mp3").innerHTML = '<audio src="'+typ+'" autoplay controls onended="hide_player()"  controlslist="nodownload noplaybackrate" oncontextmenu="return false;"><p> <a href="'+typ+'">Play</a></p></audio>';
	//document.getElementById("line").focus();
	
	
}

function hide_player() {
	document.getElementById("mp3").style.display="none";
}




time_init = 2000;
if (time_init < 500) {time_init = 500;}


let zeilenanzahl = null; // Standardwert für die Zeilenanzahl
function countLines() {
	fetch('proxy2.php')
	.then(response => {
		if (!response.ok) {
			// Wenn die Antwort nicht erfolgreich ist (404 oder anderes)
			throw new Error('Datei nicht gefunden');
		}
		return response.text();
	})
	.then(text => {
		// Zählt die Zeilen in der Datei, falls sie existiert
		zeilenanzahl = text.split(/\r\n|\r|\n/).length - 1;
		// console.log('Zeilenanzahl:', zeilenanzahl);
		time_init = 200 + zeilenanzahl * 200;
		if (time_init < 500) {time_init = 500;}
		
		// console.log('Zeilenanzahl:', zeilenanzahl ,'time_init:', time_init);
			
	})
	.catch(error => {
		// Wenn ein Fehler auftritt (z. B. 404 oder kein Zugriff)
		console.error('Fehler:', error);
		// Setze einen festen Wert, wenn proxy.php nicht existiert
		time_init = 1000;
		console.log('time_init auf festen Wert gesetzt:', time_init);
	});
}

setInterval(countLines, 10000);
countLines();  // sofort ausführen





// disconnect = time_init * 3; // disconnect bei Erreichen dieses refresh Wert


// Online Zeit anzeigen:
// erst nach 10 Min. Inaktivitaet startet ein reload oder Raumwechsel die online Zeit neu:
var ablauf = new Date();
var Minuten = ablauf.getTime() + (10 * 60 * 1000); 
ablauf.setTime(Minuten);
// document.cookie="arrival="+login+"; expires=" + ablauf.toGMTString();


	

function jump(form) { 
	order = form.menu1.selectedIndex; 
	if (form.menu1.options[order].value != 0) { 
		ads(form.menu1.options[order].value);
	} 
} 

function jump_color(form) {
//	ads('/color '+form.querySelector('input').value); 
	nickcolor = form.querySelector('input').value;
	nc = nickcolor.replace("#", "");
	// weisser Adler auf weissem Grund vermeiden:
	nc = nc.replaceAll("d", "c");
	nc = nc.replaceAll("e", "c");
	nc = nc.replaceAll("f", "c");
	nc = nc.replaceAll("D", "C");
	nc = nc.replaceAll("E", "C");
	nc = nc.replaceAll("F", "C");	
	// Negerboxkampf im Tunnel vermeiden:
	nc = nc.replaceAll(2, 3);
	nc = nc.replaceAll(1, 3);
	nc = nc.replaceAll(0, 3);
	
	document.cookie="color="+nc+"; expires=" + ablauf2.toGMTString();
	document.getElementById('line').focus();
}


var ablauf2 = new Date();
var Minuten2 = ablauf2.getTime() + (360 * 24 * 60 * 60 * 1000);
ablauf2.setTime(Minuten2);
function jump2(form) {
	order = form.menu2.selectedIndex;
	if (form.menu2.options[order].value != 0) {
		var style = form.menu2.options[order].value;
		document.cookie="Style="+style+"; expires=" + ablauf2.toGMTString();
		window.location.reload();
	}
}

function setlang(lg) {
	document.cookie="lang="+lg+"; expires=" + ablauf2.toGMTString();
}

function playsound(typ) { // die standardkonforme Loesung fuer alle Browser
      if (document.getElementById('ton') && iOS !==true) {
      	document.getElementById("ton").innerHTML = '<audio src="'+typ+'" autoplay controlslist="nodownload"></audio>';
      }
}

time1 = time_init;

function refresh_cb(new_data) {
		
	freezed = false;
	
	last_msg="";
	msg_pos = 0;
	teil_msg = "";
	if (typeof old_data == "undefined" || old_data == "--") {
		if (playsound) playsound('sounds/reload2.mp3'); // Sound bei reload
	} else {
		if (typeof handle != "string") {
			holeCookie("nick");

			msg_pos = new_data.lastIndexOf("color:");
			last_msg = new_data.substr(msg_pos);
				 
	
			if (old_msg != last_msg && last_msg.indexOf(nick) != -1 && last_msg.indexOf('@') != -1 && last_msg.indexOf('(flüstert') == -1  ) {
				playsound('sounds/sound21.mp3'); // Sound bei @mich
				// if (style!= '12' && style !='11') {popup(new_data);}
			}				 
			else if (old_msg != last_msg && last_msg.indexOf(nick) != -1 && last_msg.indexOf('(flüstert') != -1 ) {
				playsound('sounds/sound11.mp3'); // Sound bei /pn @mich
				// if (style!= '12' && style !='11') {popup(new_data);}
			}
			else if (old_msg != last_msg && last_msg.indexOf("/pn") == -1) {
				playsound('sounds/eingang.mp3'); // Sound bei Nachrichten von Dritten, kein /pn
				// if (style!= '12' && style !='11') {popup(new_data);}
			}
				 
			// wenn Admin pn kriegt, kein sound
//			if (old_msg != last_msg && last_msg.indexOf(cookieWert) != -1) {
//				playsound('sounds/eingang.mp3'); // Sound bei /pn an mich
//			}

//			if (isadmin == 1 && last_msg.indexOf("/pn") != -1) {
//				playsound('sounds/eingang.mp3'); // Sound fuer Admin bei allen /pn
//			}
			

			function alertMsg() {
				alert("Hallo! Aufwachen!\nHello! Wake Up!");
			}
                 
			// der Alarmruf:
			if (last_msg.indexOf("/alarm") != -1 && last_msg.indexOf(nick) != -1) {
				playsound('sounds/alarm3.mp3');
				setTimeout(alertMsg,3000);
			}

			// User betritt den Chat:
			// if (last_msg.indexOf("hat den Chat betreten") != -1 && last_msg.indexOf("/pn") == -1) {
			if (last_msg.indexOf("hat den Chat betreten") != -1) {
				playsound('sounds/sound21.mp3');
			}

			// User verlässt den Chat:
			// if (last_msg.indexOf("hat sich ausgeloggt") != -1 && last_msg.indexOf("/pn") == -1) {
			if (last_msg.indexOf("hat sich ausgeloggt") != -1) {
				playsound('sounds/sound10.mp3');
			}

			// echter /kick:
			if (last_msg.indexOf("you've been kicked") != -1 && last_msg.indexOf(nick) != -1) {
				window.location.href = 'kick.php?nick='+nick;
			}

		}
	}

	old_msg = "";
	if (typeof last_msg == "string") old_msg = last_msg;
	handle = 1;

	if (document.getElementById("wall")) {document.getElementById("wall").innerHTML = new_data;}


	// ARIA
	if (document.getElementById("jaws")) {
		
			
		msg_pos = new_data.lastIndexOf(": pointer");
		last_msg = new_data.substr(msg_pos + 11);
	

	


	if (last_msg.indexOf("<img") != -1 && last_msg.indexOf("alt") != -1) { // alt-Attribut fuer ARIA aufbereiten

		holeCookie("pic");
		
		start_img = strpos(last_msg, '<img', 0);
		sub0_aria = last_msg.substring(0,start_img); // alles vor <img
		start_alt = strpos(last_msg, 'alt=', 0);
		sub1_aria = last_msg.substring(start_alt +5); // alles nach alt=
		end_alt = strpos(sub1_aria, '"',0);
		sub2_aria = sub1_aria.substring(0,end_alt); // das komplette alt-Attribut
		
		if (cookieWert == 0) {
			sub2_aria = "";
		}
		
		rest = strpos(sub1_aria,'>',0);
		sub3_aria = sub1_aria.substring(rest + 1); // alles nach dem img
		last_msg = sub0_aria + sub2_aria + sub3_aria;
	}


		
	document.getElementById("jaws").innerHTML = '<p>' + last_msg + '</p>';

	}



	if (reverse !== "reverse") {
		if (style == 7) {			
			setTimeout(function(){ 
				elem.scrollTop=elem.scrollHeight;
			}, 1500);
		} else {
			
			setTimeout(() => {
			    elem.scrollTop = elem.scrollHeight;
			}, 200);
			setTimeout(() => {
			    elem.scrollTop = elem.scrollHeight;
			}, 1500);
						
//			setTimeout(function(){ 
//				elem.scrollTop=elem.scrollHeight;
//			}, 1500);
//			setTimeout(function(){ 
//				elem.scrollTop=elem.scrollHeight + 1000;
//			}, 1200);
			
		}
	}


	old_data = new_data;
	time1 = time_init; // bei Eingang einer neuen Meldung wirds wieder schnell
	setTimeout("changed_data()", time1);
	
}


function scroll_click() {
	elem = document.getElementById('wall');
	if (reverse !== "reverse") {			
		elem.scrollTop=elem.scrollHeight + 1000;
	}
}



// Filesize abfragen vor dem AJAX refresh


var old_size;
function set_file_changed(new_size) {

//	var ablauf3 = new Date();
//	var Minuten3 = ablauf3.getTime() + (10 * 1000);
//	ablauf3.setTime(Minuten3);
//	document.cookie="online=1; expires=" + ablauf3.toGMTString();
	
	// WOW! so lässt sich komfortabel der Verlauf lesen.
	elem = document.getElementById('wall');


	if (elem.scrollHeight - elem.scrollTop - elem.clientHeight <= 25 || reverse == "reverse" ) {

	elem.style.background = "none";
	if (document.getElementById('clickable')) {
		document.getElementById('clickable').style.visibility="hidden";
	}
	
		if ( typeof old_size == "undefined" || new_size != old_size) {
			old_size = new_size;
			x_refresh(refresh_cb);
		} else { // hierher die Waermestube!
			if (typeof time1 != "undefined" ) {
		
				// die neue Wärmestube:
				holeCookie("last");
				last=cookieWert;

				akt = Math.floor(Date.now() / 1000);
				sleeptime = akt - last;
				// console.log (sleeptime);

				if (sleeptime > 30 * 60) { // 30 Minuten
					last = Math.floor(Date.now() / 1000);
					document.cookie = 'last='+last+''; 
					alert("Hallo " +nick+"! Bist du noch da? \nNicht nur mitlesen! Bitte schreib' doch auch mal wieder etwas!");
					// document.getElementById('line').focus();
					location.reload();
				}

				if (!document.hidden) {
					setTimeout("x_file_changed(set_file_changed)",time1);
				} else {
					return;
				}
			}
		}
	} else {
		if (reverse == "reverse") {
			// do nothing	
		} else {
			elem.style.background = "transparent url(\'img/arrow_dwn.png\') no-repeat 97% 97%";
			elem.style.backgroundSize = "17px";
			if (document.getElementById('clickable')) {document.getElementById('clickable').style.visibility="visible";}
		}
		
		// die neue Wärmestube:
		holeCookie("last");
		last=cookieWert;

		akt = Math.floor(Date.now() / 1000);
		sleeptime = akt - last;
		// console.log (sleeptime);

		if (sleeptime > 30 * 60) { // 30 Minuten
			last = Math.floor(Date.now() / 1000);
			document.cookie = 'last='+last+''; 
			alert("Hallo " +nick+"! Bist du noch da? \nNicht nur mitlesen! Bitte schreib' doch auch mal wieder etwas!");
			// document.getElementById('line').focus();
			location.reload();
		}
		
		if (!document.hidden) {
			setTimeout("x_file_changed(set_file_changed)",time1);
		} else {
			return;
		}
	}


}


function changed_data() {
	x_file_changed(set_file_changed);
	
	holeCookie("freeze");
	if (cookieWert == "0" ) {
		[].slice.apply(document.images).filter(is_gif_image).map(freeze_gif);
		
		var videoList = document.getElementsByTagName("video");
		for (var i = 0; i < videoList.length; i++) {
		    videoList[i].pause();
		}
		
	}	
}



function add_cb() {
	// we don't care..
}



var handle; // Var global wg. Klick on send
function add() {
	

	if (reverse == "reverse") {	
		elem = document.getElementById('wall');
		elem.scrollTop=0;;
	} else {
		elem = document.getElementById('wall');
		elem.scrollTop=elem.scrollHeight;	
	}
	line = document.getElementById("line").value;
	away_msg == "";
	
	holeCookie("watch");
	
	if (location.search.indexOf('room=Info') == -1) {
		if (away_msg == "weg"  && (isadmin < 1 || cookieWert != "on")) {line = "[hello2][ist jetzt mal \bafk][/hello2] ";}
		if (away_msg == "warm" && (isadmin < 1 || cookieWert != "on")) {line = "[hello2][wurde aus der W\u00e4rmestube ausgeloggt.][/hello2] ";}
		if (away_msg == "re"   && (isadmin < 1 || cookieWert != "on")) {line = "[hello][wd][/hello] "; document.location.reload(false);}
	}

	if (cookieWert == "on" && line.indexOf("afk") != -1 ) {
		alert ("Away from keyboard (afk) nicht verwenden, wenn ghost-mode on.");
		document.getElementById("line").value = "";
		return;
	}


	handle = document.getElementById("handle").value;

	// Fluestern nur erlauben, wenn ein Admin beteiligt ist
	var user_whisper = "";
	if (user_whisper == "admin") {
		if (line.indexOf("/pn") != -1) {
			if (isadmin != 1 ) { // der Admin darf alle anfluestern
				// suchen, ob einer der Admins angesprochen wird
				var at_admin = 0;
				for (var i = 0; i < all_admins.length; i++) {
					if (line.indexOf('@'+all_admins[i]+' ') != -1) {
						var at_admin = 1;
					}
				}
				if (at_admin != 1) {
					alert("Fl\u00fcstern ist nur erlaubt, wenn ein Admin beteiligt ist.");
					return;
				}
			}
		}
	}


	// kein zusätzlicher Test in _pr-Einladung
	if (line.indexOf(" /pn") != -1 && line.indexOf("_pr ") != -1 ) {
		line = line.substring(0, line.indexOf('/pn') + 3);
	}

	// nicht an mehrere Empfänger flüstern
	// und auch /pn @user1 @user2 bla bla unterbinden
	var count2 = (line.match(/@/g) || []).length;
	if (line.indexOf("/pn") != -1 && count2 >= 2) {
		alert ("Achtung! Du versuchst, mit mehr als einem User gleichzeitig zu flüstern! Das ist hier nicht erlaubt.");
		line = "";
	}

	// nicht an sich selbst schreiben:
	holeCookie("nick");
	if (line.indexOf("@" + cookieWert + " ") != -1 ) {
		alert ("Willst du wirklich an dich selbst schreiben?");
		return;
	}	


	// keine leere Nachricht zulassen:
	if (line == "" || line == "(Schreib&apos; etwas!)" ) {
		return;
	}
	
	if (line.indexOf("file://") != -1) {
		alert ("Nicht erlaubte Zeichen in der Nachricht!");
		if (document.getElementById("line")) document.getElementById("line").value = "";

		return;
	}


	if (isadmin != 1) {
		if (line.indexOf("/add") != -1) { //muss hier bereits abgefangen werden wg. folgendem if
			alert("Dieser Befehl steht nur dem Admin zur Verf\u00fcgung!");
			if (document.getElementById("line")) document.getElementById("line").value = "";

			return;
		}
	}

	if (line.indexOf("/add ") != -1 && isadmin == 1 && allow_url_fopen != 1) {
		alert ("Dein Server erlaubt das leider nicht (allow_url_fopen=off)");
		if (document.getElementById("line")) document.getElementById("line").value = "";
		return;
	}


	// die Versionsanzeige
	
// das tut nicht, und ist auch nicht nötig.
//	if (line.indexOf("/pn") != -1 && line.indexOf(" afk ") != -1 ) {
//		alert ("Away from keyboard (afk) darf nicht geflüstert werden.");
//		document.getElementById("line").value = "";
//		return;
//	}
		  

	if (line.indexOf("/version") != -1) {
		alert ("Chat by webdesign.weisshart.de \nVersion: 1.213.05");
		document.getElementById("line").value = "";
		return;
	}

	if (line.indexOf("/usr_smileys.php#") != -1 || line.indexOf("#a") != -1 ) {
		alert ("Drag & Drop von Smileys geht nur aus dem Nachrichtenfenster, \naber nicht von der Smiley-Leiste oder dem More Smileys Fenster.");
		document.getElementById("line").value = "";
		return;
	}


	var user_whisperroom = "";
	if (user_whisperroom == "admin") {
		if (line.indexOf("_pr") != -1 && isadmin != 1) {
			alert ("Fl\u00fcsterr\u00e4ume darf nur der Admin \u00f6ffnen.");
			if (document.getElementById("line")) document.getElementById("line").value = "";
			return;
		}
	}

	var guest_write = "";
	if (guest_write == "no" ) {
		var nickname = "";
		if (nickname.indexOf("Gast") !== -1) {
			alert ("Als Gast kannst du nicht schreiben.\n\nUm zu schreiben, log dich bitte aus,\nund melde dich mit deinem registrierten Nicknamen an,\noder registriere dich (das geht ganz schnell!).");
			if (document.getElementById("line")) document.getElementById("line").value = "";

			return;
		}
	}



	Check = "true";
	if (isadmin == 1  && line.indexOf("/del ") != -1) {
		Check = confirm("Willst du den eingegebenen Raum wirklich l\u00f6schen und entfernen?\n\nHinweis: den Raum, in dem du dich befindest, kannst du nicht l\u00f6schen, er wird statt dessen lediglich „gecleared‟. ");
		if (Check == false) {
			if (document.getElementById("line")) document.getElementById("line").value = "";

			return;
		}
	}


	//alle Smileys in dir löschen

	function doesFileExist(urlToFile) {
		var xhr = new XMLHttpRequest();
		xhr.open('HEAD', urlToFile, false);
		xhr.send();

		if (xhr.status == "404") {
			// console.log("File doesn't exist");
			return false;
		} else {
			// console.log("File exists");
			return true;
		}
	}

	Check2 = "true";
	if (isadmin == 1  && line.indexOf("/del_all_smileys_in_box") != -1) {
		
		numb = line.match(/\d/g);
		if (numb) {numb = numb.join("");}
		// console.log(numb);
		
		if (doesFileExist("smileys" + numb)) {
			// alert('OK');

			Check2 = confirm("Box " +numb+ ": Willst du wirklich alle Smileys in dieser Box l\u00f6schen?\nHinweis: Diese Aktion kann nicht r\u00fcckg\u00e4ngig gemacht werden!");
			if (Check2 == false) {
				if (document.getElementById("line")) document.getElementById("line").value = "";
				return;
			}

		} else {
			alert (numb+': Diese Smileybox gibt es nicht.');
			if (document.getElementById("line")) document.getElementById("line").value = "";
			return;
		}
		
	}


	// mehr als 4 mal das gleiche Zeichen oder die gleiche Zeichenfolge (z.B. smileys) zurueckweisen und umwandeln
	if (isadmin != 1) {
		var re = new RegExp("(\.+)\\1{"+flood_test+",}"); 
		if (line.search(re) != -1 && line.indexOf("#") == -1 && line.indexOf("000") == -1  && line.indexOf("youtube") == -1 && line.indexOf("https") == -1) {
			alert("Sieht so aus, als ob deine Tastatur klemmt?\nBitte \u00fcberpr\u00fcfe deine Eingabe.");
			return;
		}
	}




	// mehr als 4 mal Leerraum oder Zeilenschaltung zurueckweisen und umwandeln
	if (isadmin != 1) {
		var re = new RegExp("(\\n+)\\1{"+flood_test+",}"); 
		if (line.search(re) != -1) {
			alert("Sieht so aus, als ob deine Tastatur klemmt?\nBitte \u00fcberpr\u00fcfe deine Eingabe.");
			return;
		}
	}


	// Schreien (nur Grossbuchstaben) zurueckweisen:
	if (isadmin != 1 && line.indexOf(")") == -1 && line.indexOf("(") == -1) {
		  
		line_no_digits = line.replace(/[0-9]/g, '');
		upper_line_no_digits = line.toUpperCase();
		if (line_no_digits === upper_line_no_digits && line.length > flood_test ) {
			alert("Sieht so aus, als ob deine Tastatur kaputt ist.\nHast du nur Gro\u00dfbuchstaben?\nSo etwas gilt im Chat als unh\u00f6flich.");
		}
	}


	// Mehrfacheingabe von Upload oder sonstiger Links unterbinden
	if (line.lastIndexOf("http:") - line.indexOf("http:") > 0 && line.indexOf("smileys")  == -1  ) {
		alert("Nur ein Link/Dateiupload pro Eingabe erlaubt!");
		return;
	}


	if (line.indexOf("/away") != -1 ) { away();return false }

//	if (line.toUpperCase().indexOf(" AFK") !== -1 || line.toUpperCase().indexOf(" A F K") !== -1 && line.indexOf(" ist ") == -1 && line.indexOf(" is ") == -1 && line.indexOf(" iss ") == -1 || line.toUpperCase() == "AFK " || line.toUpperCase() == "A F K" ) { away(); return false}


	if (line.indexOf("/ip") != -1 && isadmin == 1) {
		document.cookie="showip=on; expires=" + ablauf2.toGMTString();
		document.location.reload(false); 
	}

	if (line.indexOf("/noip") != -1 && isadmin == 1) {
		document.cookie="showip=off; expires=" + ablauf2.toGMTString();
		document.location.reload(false); 
	}

	if (line.indexOf("/go") != -1) {
		document.location.reload(true);
	}



	// bestimmte Befehle zurueckweisen, wenn nicht Admin oder Mod:
	if (isadmin != 1 && ismod !=1) {
		if (line.indexOf("/ban") != -1
		|| line.indexOf("/kick") != -1
		|| line.indexOf("you've been kicked") != -1
		|| line.indexOf("/maulkorb") != -1
		|| line.indexOf("/maul") != -1
		|| line.indexOf("/nopv") != -1
		) {
			alert("Dieser Befehl steht nur dem Admin zur Verf\u00fcgung!");
			if (document.getElementById("line")) document.getElementById("line").value = "";

			return;
		}
		
		p_room = "";
		if (line.indexOf("/clear") != -1 && p_room.indexOf("_pr") == -1) {
			alert("Dieser Befehl steht nur dem Admin zur Verf\u00fcgung!");
			if (document.getElementById("line")) document.getElementById("line").value = "";

			return;
		}
		
	}
		
	// bestimmte Befehle zurueckweisen, wenn nicht Admin:
	if (isadmin != 1) {
		if (line.indexOf("/ghost") != -1
		|| line.indexOf("/peep") != -1
		|| line.indexOf("/nopeep") != -1
		|| line.indexOf("/ip") != -1
		|| line.indexOf("/noip") != -1
		|| line.indexOf("/approve") != -1
		|| line.indexOf("/offline") != -1
		|| line.indexOf("/del") != -1
		|| line.indexOf("/del_smiley") != -1
		|| line.indexOf("/topic") != -1
		|| line.indexOf("/pixel") != -1
		|| line.indexOf("/alarm") != -1
		|| line.indexOf("/showprofil") != -1				
		|| line.indexOf("/profil") != -1				
		) {
			alert("Dieser Befehl steht nur dem Admin zur Verf\u00fcgung!");
			if (document.getElementById("line")) document.getElementById("line").value = "";

			return;
		}
		
		
		
		
		if (line.indexOf("img ") != -1
		|| line.indexOf(" src") != -1
		) {
			alert("Kein HTML hier!");
			return;
		} 

			
	}

	if (isadmin != 1 && ismod !=1) {
		if (line.indexOf("/erase") != -1 || line.indexOf("/pin") != -1 || line.indexOf("/stick") != -1 ) {
			alert("Dieser Befehl steht nur dem Admin zur Verf\u00fcgung!");
			return;
		}
	}

	same1 = (line.match(/\/ban/g) || []).length;
	if (same1 > 1) {
			alert ("Bitte nicht mehrere Befehle in einer Zeile."); 
			return;
	}
	same2 = (line.match(/\/kick/g) || []).length;
	if (same2 > 1) {
			alert ("Bitte nicht mehrere Befehle in einer Zeile."); 
			return;
	}
	same3 = (line.match(/\/maul/g) || []).length;
	if (same3 > 1) {
			alert ("Bitte nicht mehrere Befehle in einer Zeile."); 
			return;
	}
	same4 = (line.match(/\/nopv/g) || []).length;
	if (same3 > 1) {
			alert ("Bitte nicht mehrere Befehle in einer Zeile."); 
			return;
	}
	same5 = (line.match(/\/igno/g) || []).length;
	if (same5 > 1) {
			alert ("Bitte nicht mehrere Befehle in einer Zeile."); 
			return;
	}

	if (isadmin == 1 || ismod ==1) {
		if (line.indexOf("/ban") != -1 && line.length <= 9) {
			alert ("Bitte noch den Nick eingeben (mit oder ohne @)."); 
			return;
		}
		if (line.indexOf("/kick") != -1 && line.length <= 10) {
			alert ("Bitte noch den Nick eingeben (mit oder ohne @)."); 
			return;
		}
		if (line.indexOf("/maul") != -1 && line.length <= 14) {
			alert ("Bitte noch den Nick eingeben (mit oder ohne @)."); 
			return;
		}
		if (line.indexOf("/nopv") != -1 && line.length <= 10) {
			alert ("Bitte noch den Nick eingeben (mit oder ohne @)."); 
			return;
		}
	}
		
	if (line.indexOf("/ignore") != -1 && line.length <= 12) {
		alert ("Bitte noch den Nick eingeben (mit oder ohne @)."); 
		return;
	}
		

	nick_angemeldet = holeCookie("nick");
	var nickname = "";
	hello = "yes";
	hello = "yes";
	ankunft = holeCookie("greeted"); // ein eigenes cookie fuer die Begruessung
	

	if(hello != "no" && cookieWert != "yes" && isadmin != 1 && line.indexOf('youtu') == -1 && location.search.indexOf('room=Info') == -1 && line.indexOf('[hello2]')== -1) { // die Begruessung macht den youtube link kaputt + keine Hello wenn Wärmestube
		//document.cookie="nick="+nickname;
		document.cookie="greeted=yes"; // Firefox loescht u. U. cookie am Sitzungsende nicht.
		
		x_add_line(handle + ": " + line, add_cb);
	} else {
		x_add_line(handle + ": " + line, add_cb);
	}


	last = Math.floor(Date.now() / 1000);
	document.cookie = 'last='+last+''; 


	if (document.getElementById("line")) document.getElementById("line").value = "";
	
}

// der Versuch, eine Sperrdatei abzufragen
// https://stackoverflow.com/questions/3646914/how-do-i-check-if-file-exists-in-jquery-or-pure-javascript/11223909#
function UrlExists(url) {
	if(url){
		var req = new XMLHttpRequest();
		req.open('GET', url, false);
		//req.open('HEAD', url, false);
		req.send();
		return req.status==200;
	} else {
		return false;
	}
}


// http://hendi.name/2006/04/08/str_replace-fur-javascript/
// wird fuer die folgende function set_user benoetigt
function str_replace(search, replace, subject) {
	return subject.split(search).join(replace);
}

function set_user(result) {
		if (document.getElementById('uo')) {
			document.getElementById('uo').innerHTML = result;
		}
}

show_active_users_only = 1;
// console.log(show_active_users_only); 

if (show_active_users_only == 0) {
	console.log('0: Alle User zeigen, bei denen der Chat in irgendeinem, auch inaktivem, Browserfenster läuft');
} 
if (show_active_users_only == 1) {
	console.log('1: Nur User zeigen, bei denen der Chat im aktiven Browserfenster läuft');
}


function u_online() {
	if (light != "yes") {
		x_user_online(set_user);
		if (show_active_users_only == 1) {
			if (!document.hidden ) {	
				// x_user_online(set_user);
				setTimeout("u_online()", 11000);
			}
		} else {
			// x_user_online(set_user);
			setTimeout("u_online()", 11000);	
			// console.log('20000');
		}
	}
}

function set_user_room(result1) {
	if (document.getElementById('user_pro_room')) document.getElementById('user_pro_room').innerHTML = result1;
}


// zeigt User in anderen Rooms:
function u_online_room() {
	if (!document.hidden) {	
		if (!document.getElementById('user_pro_room').contains(document.activeElement)) {
//			console.log("user_pro_room");
			x_user_room(set_user_room);
		} 	
		setTimeout("u_online_room()", 19991);
//		setTimeout("u_online_room()", time_init * 9.9);
//		console.log ('rooms');
	} else {
		return;
	}
}


function ads(smiley) {
//	if (document.getElementById('line').value.indexOf('Schreib&apos; etwas!') !== -1) {
//		document.getElementById('line').value = "";
//	}
	document.getElementById('line').focus();
	document.getElementById('line').value = document.getElementById('line').value + ' ' + smiley + ' ';
}


function max(e) {
	holeCookie("freeze");
	if (cookieWert != "0" ) {
	
	if (e.clientHeight == "120") {
		e.style.maxHeight="120px";
		e.style.cursor="zoom-out";
	} else if (e.clientHeight > "120") {
		e.style.maxHeight="120px";
		e.style.cursor="zoom-in";
	}
	}
}







function kalender () {
    if (localStorage) {
		var w = localStorage.getItem("pop3_width") || 650;
		var h = localStorage.getItem("pop3_height") || 320;
		var l = localStorage.getItem("pop3_left") || 10;
		var t = localStorage.getItem("pop3_top") || 30;
		window.open("kalender.php", "kalender", "top=" + t + ", left=" + l + ", width=" + w + ", height=" + h +"");
	} else {
		window.open("kalender.php", "kalender", " width=650, height=320");
	}
}	

function pinnwand1 () {
    if (localStorage) {
		var w = localStorage.getItem("pop1_width") || 520;
		var h = localStorage.getItem("pop1_height") || 700;
		var l = localStorage.getItem("pop1_left") || 10;
		var t = localStorage.getItem("pop1_top") || 30;
		window.open("pinns/pinnwand1.php", "pinnwand1", "top=" + t + ", left=" + l + ", width=" + w + ", height=" + h +"");
	} else {
		window.open("pinns/pinnwand1.php", "pinnwand1", " width=520, height=700");
	}
}	

function pinnwand2 () {		
    if (localStorage) {
		var w = localStorage.getItem("pop2_width") || 520;
		var h = localStorage.getItem("pop2_height") || 700;
		var l = localStorage.getItem("pop2_left") || 10;
		var t = localStorage.getItem("pop2_top") || 30;
		window.open("pinns/pinnwand2.php", "pinnwand2", "top=" + t + ", left=" + l + ", width=" + w + ", height=" + h +"");
	} else {
		window.open("pinns/pinnwand2.php", "pinnwand", " width=520, height=700");
	}
}	


// Sinnvolle Größe für die Box auch bei Zoom
var zL = window.devicePixelRatio || 1;
if (zL >= 2) {zL = zL / 2;} 
// console.log("Zoom Level: " + zL);


function smileybox () {	
	if (localStorage) {
		var w = localStorage.getItem("box_width") *zL || 340;
		if (w < 325) {w = 325;}
		
		var h = localStorage.getItem("box_height") || 600;
		if (h < (screen.height * .6)) {h = screen.height * .6;}

		var l = localStorage.getItem("box_left") || screen.width * .7;
		var t = localStorage.getItem("box_top") || screen.height * .2;
		window.open("usr_smileys1.php", "smileybox", "top=" + t + ", left=" + l + ", width=" + w + ", height=" + h +"");
	} else {
		window.open("usr_smileys1.php", "smileybox", " width=340, height=600");
	}
}	

function prbox(e) {
	
	if (iOS !==true) { // do not use chat_pr on mobile, use skin7 instead
		e = e.replace("chat.php", "chat_pr.php");
	}
	
	if (localStorage) {
		var pw = localStorage.getItem("prbox_width") || 400;
		var ph = localStorage.getItem("prbox_height") || 650;
		var pl = localStorage.getItem("prbox_left") || screen.width * .7;
		var pt = localStorage.getItem("prbox_top") || screen.height * .2;
		window.open(e, "prbox", "top=" + pt + ", left=" + pl + ", width=" + pw + ", height=" + ph +"");
	} else {
		window.open(e, "prbox", " width=400, height=650");
	}
	
}



function load() {

	if (document.getElementById('jaws')) {
		//document.getElementById('jaws').setAttribute('aria-relevant', 'all');
		document.getElementById('jaws').setAttribute('aria-live', 'assertive');
	}
	var show_user;
	show_user = "yes";

	var show_rooms;
	show_rooms = "yes";

	var raum;
	if (window.location.search.indexOf("_pr") !== -1) raum = "pr";


	setTimeout("x_file_changed(set_file_changed)",500);

	klapp('ae');


	var u_on_room = 1;
	if (sb == 1) u_on_room = 0;
	if (light == "yes") u_on_room = 0;
	if (show_rooms == "no") u_on_room = 0;
	if (raum == "pr" && show_rooms == "no" && isadmin != 1 ) u_on_room = 0;
	if (u_on_room == 1) u_online_room();


//	var u_on = 1;
//	//      if (sb == 1) u_on = 0;  // in der SB u_online zeigen, weil sonst ghost
//	if (light == "yes") u_on = 0;
//	if (show_user == "no") u_on = 0;
//	if (u_on == 1) u_online();

	// beim Betreten eig. Nick sofort anzeigen
	x_user_online(set_user);
	setTimeout("u_online()", 1000);

	// disabled den Zurück-Button von Android, aber erst, nachdem etwas geposted wurde
	history.pushState(null, null, window.top.location.pathname + window.top.location.search);
	window.addEventListener('popstate', (e) => {
		e.preventDefault();
		history.pushState(null, null, window.top.location.pathname + window.top.location.search);
	});


}


function ProfilOeffnen (Adresse) {
	var seconds = new Date().getTime() / 1000;
	MeinFenster = window.open(Adresse+"&test="+seconds, "Zweitfenster", "width=500,height=500,left=100,top=100");
	MeinFenster.focus();
}

function toggle_vid(e) {
	if (e.paused) {
		e.play();
	} else {
		e.pause();
		e.removeAttribute('playsinline');
	}
}


function fadeout() {
	document.body.style.backgroundColor = 'white';
	document.body.style.background = 'none';

	document.getElementsByTagName('body')[0].style.opacity = 0;
	document.getElementsByTagName('body')[0].style.WebkitTransition = 'opacity 500ms';
	document.getElementsByTagName('body')[0].style.Transition = 'opacity 500ms';
}


holeCookie("arrival");
if (cookieWert != "") {
	window.onload=load;
	  
} else {
	document.write('<p style="font-weight:bold; color:red"><br><br>Ohne Cookies l&auml;uft der Chat leider nicht. Bitte erlaube Cookies in Deinem Browser.<br></p>');
}

if (document.getElementById("topicscroll")) {
	var laufschrift = document.getElementById("topicscroll");
	len = laufschrift.innerHTML.length;
	room = document.getElementById("wrapper").clientWidth;
 		
//	if (len < (room / 7)) {
//		document.getElementById("topicscroll").getElementsByTagName("span")[0].style.paddingLeft="0";
//		document.getElementById("topicscroll").getElementsByTagName("span")[0].style.animation="0";	
//	}
}


// (Toggle gif animations - and) clear input - on escape 

document.addEventListener('keydown', freeze_gifs_on_escape, true);
var freezed = false;
function freeze_gifs_on_escape(e) {
	
	if(document.getElementById("line").value.length > 0) {
		if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey) {
			document.getElementById("line").value = '';
		}
//	} else if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey || e.keyCode == 13) {
//		if (freezed !== true) {
//			[].slice.apply(document.images).filter(is_gif_image).map(freeze_gif);
//			freezed = true;
//		} else if(document.getElementById("line").value.length == 0) {
//			x_refresh(refresh_cb);
//			freezed = false;
//		}
	}
	
}



function is_gif_image(i) {
	return /^(?!data:).*\.gif/i.test(i.src);
}



function freeze_gif(i) {
	var c = document.createElement('canvas');
	var w = c.width = i.width;
	var h = c.height = i.height;
	c.getContext('2d').drawImage(i, 0, 0, w, h);

	try {
		i.src = c.toDataURL("image/gif"); // if possible, retain all css aspects
	} 
	catch(e) { // cross-domain -- mimic original with all its tag attributes
		for (var j = 0, a; a = i.attributes[j]; j++)
		c.setAttribute(a.name, a.value);
		i.parentNode.replaceChild(c, i);
	}
}


/*
// Toggle gif animations on left-/right swipe

// https://code-maven.com/swipe-left-right-vanilla-javascript
(function() {
	var min_horizontal_move = 30;
	var max_vertical_move = 30;
	var within_ms = 1000;

	var start_xPos;
	var start_yPos;
	var start_time;
	function touch_start(event) {
		start_xPos = event.touches[0].pageX;
		start_yPos = event.touches[0].pageY;
		start_time = new Date();
	}


	function touch_end(event) {
		var end_xPos = event.changedTouches[0].pageX;
		var end_yPos = event.changedTouches[0].pageY;
		var end_time = new Date();
		var move_x = end_xPos - start_xPos;
		var move_y = end_yPos - start_yPos;
		var elapsed_time = end_time - start_time;
		if (Math.abs(move_x) > min_horizontal_move && Math.abs(move_y) < max_vertical_move && elapsed_time < within_ms) {
			if (move_x < 0) {
				//alert("left");
				[].slice.apply(document.images).filter(is_gif_image).map(freeze_gif);
				freezed = true;			
			} else {
				//alert("right");
				x_refresh(refresh_cb);
				freezed = false;
			}
		}
	}

	var content = document.getElementById("wrapper");
	if (window.ontouchstart !== undefined) {
		content.addEventListener('touchstart', touch_start);
		content.addEventListener('touchend', touch_end);
	}

})();
*/

// damit bei Raumwechsel eig. nick sofort in der Liste
document.addEventListener('visibilitychange', function (event) {
	if (!document.hidden) {
		setTimeout("u_online_room()", 100);
		setTimeout("u_online()", 200);
		setTimeout("x_file_changed(set_file_changed)",300);
	}
});


function dlcount(e) {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", "dlcounter/dlcounter.php?sendValue=" + e, true);
	xmlhttp.send();
}



	newWindow="";
	function OpenNewWindow(Picture,Breit,Hoch,Alttext) {
	xsize = Breit+1;
	ysize = Hoch+25;

	ScreenWidth = screen.width;
	ScreenHeight = screen.height;

	xpos = (ScreenWidth/2)-(xsize/2);
	ypos = (ScreenHeight/2)-((ysize+50)/2);

	if (!newWindow.closed && newWindow.location) {newWindow.close();}


var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
if (supportsTouch !== true) {

// var UserAgent = navigator.userAgent.toLowerCase();
// if (UserAgent.search(/(iphone|ipod|ipad|opera mini|fennec|palm|blackberry|android|symbian|series60)/) == -1) {


	html = ('<!DOCTYPE html><html onclick="self.close()"><head><title> '+Alttext+'</title><style>html, body, p, a {margin:0; padding:0; border: 0; font-family: Verdana,Geneva,Arial,sans-serif;} html { background: url('+Picture+') no-repeat center center fixed;  -webkit-background-size: contain;-moz-background-size: contain;-o-background-size: cover; background-size: cover; cursor:zoom-out;max-width: 100%;} </style><script type="text/javascript">function kp(e){if (!e) e=window.event;if (e.keyCode==27){self.close();}}window.onkeypress=kp;</script></head><body onkeydown="kp()"><p style="position:fixed; bottom: 8px;right:16px"><a style="color:#444;text-decoration:none;	text-shadow:.6px  .6px .6px white,.6px -.6px .6px white,-.6px  .6px .6px white,-.6px -.6px .6px white;font-size:max(10vw, 2em); opacity:1" href="javascript:self.close()">X</a></p></body></html>');

} else {
	html = ('<!DOCTYPE html><html onclick="self.close()"><head><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=1" ><title> '+Alttext+'</title><style>html, body, p {margin:0; padding:0; border: 0; font-family: Verdana,Geneva,Arial,sans-serif;}img{max-width:100%;}</style><script>function kp(e){if (!e) e=window.event;if (e.keyCode==27){self.close();}}window.onkeypress=kp;</script></head><body><p style="text-align:center"><img src="'+Picture+'"></p><p style="position:fixed; bottom: 8px;right:16px"><a style="color:#444;text-decoration:none;	text-shadow:.6px  .6px .6px white,.6px -.6px .6px white,-.6px  .6px .6px white,-.6px -.6px .6px white;font-size:max(10vw, 2em); opacity:1" href="javascript:self.close()">X</a></p></body></html>');
	
}

	newWindow=window.open("","Picture","height="+ysize+",width="+xsize+", resizable=yes");

	newWindow.document.open("text/html", "replace")
	newWindow.document.write(html)
	newWindow.document.close()

	return false;
	}


