/*==================================================EIGENE SACHEN===========================================*/
function isEmail(feld) {
// werden regular expressions unterstuetzt?
var supported = 0;
if (window.RegExp) {
var tempStr = "a";
var tempReg = new RegExp(tempStr);
if (tempReg.test(tempStr)) supported = 1;
}
if (!supported)
return (feld.indexOf(".") > 2) && (feld.indexOf("@") > 0);
var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
var r2 =
   new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
return (!r1.test(feld) && r2.test(feld));
}

function isLeer(feldname) {
var text = feldname; 
if (text.length<3)	
	return false;
else
	return true;
}

function testForm() 
{
	if (!isEmail(window.document.formular.mail.value)) 
	{
		alert("Sie haben eine falsche eMail-Adresse eingegeben! \n Bitte korrigieren Sie Ihre Eingabe.");
		return false;
	}
	else if (!isLeer(window.document.formular.vorname.value)) 
	{
		alert("Sie haben einen unvollständigen Namen eingegeben! \n Bitte korrigieren Sie Ihre Eingabe.");
		return false;
	}
	else if (!isLeer(window.document.formular.nachname.value)) 
	{
		alert("Sie haben einen unvollständigen Namen eingegeben! \n Bitte korrigieren Sie Ihre Eingabe.");
		return false;
	}
	else if (!isLeer(window.document.formular.mail.value)) 
	{
		alert("Sie haben eine unvollständige E-Mailadresse eingegeben! \n Bitte korrigieren Sie Ihre Eingabe.");
		return false;
	}
	else if (!isLeer(window.document.formular.nachricht.value)) 
	{
		alert("Sie haben eine unvollständige Nachricht eingegeben! \n Bitte korrigieren Sie Ihre Eingabe.");
		return false;
	}
	else 
	{
		return true;
	}
}





function klappe(tagName)
{
    if(document.getElementById(tagName).style.display == "none")
    {
        document.getElementById(tagName).style.display = "block";
		
		document.getElementById(tagName+"link").style.background = "url(../bilder/minus.gif) no-repeat left";
    }
    else
    {
        document.getElementById(tagName).style.display = "none";
		document.getElementById(tagName+"link").style.background = "url(../bilder/plus.gif) no-repeat left";
    }
}

function klappea(tagName)
{
    if(document.getElementById(tagName).style.display == "none")
    {
        document.getElementById(tagName).style.display = "block";
    }
    else
    {
        document.getElementById(tagName).style.display = "none";
    }
}

function klappeb(tagName)
{
    if(document.getElementById(tagName).style.display == "none")
    {
        document.getElementById(tagName).style.display = "block";
		
		document.getElementById(tagName+"link").style.background = "url(bilder/minus.gif) no-repeat";
    }
    else
    {
        document.getElementById(tagName).style.display = "none";
		document.getElementById(tagName+"link").style.background = "url(bilder/plus.gif) no-repeat";
    }
}

function klappec(tagName)
{
    if(document.getElementById(tagName).style.display == "none")
    {
        document.getElementById(tagName).style.display = "block";
		document.getElementById(tagName+"link").style.background = "url(bilder/pfeilaktive.gif) no-repeat left";
    }
    else
    {
        document.getElementById(tagName).style.display = "none";
		document.getElementById(tagName+"link").style.background = "url(bilder/pfeil.gif) no-repeat left";
    }
}


function Sicherheitsabfrage(Formular)
{ return true;
    
}

function insert(aTag, eTag) {
  var input = document.forms['formular'].elements['eingabe'];
  input.focus();
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var range = document.selection.createRange();
    var insText = range.text;
    range.text = aTag + insText + eTag;
    /* Anpassen der Cursorposition */
    range = document.selection.createRange();
    if (insText.length == 0) {
      range.move('character', -eTag.length);
    } else {
      range.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    range.select();
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;
  }
  /* für die übrigen Browser */
  else
  {
    /* Abfrage der Einfügeposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einfügen des Formatierungscodes */
    var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
    input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
  }
}

/*ob ueberschrift vorhanden*/
function pruefen()
{
var Text = document.formular.eingabe.value;
var Ergebnisa = Text.search(/\[ueb\]/);
var Ergebnisb = Text.search(/\[\/ueb\]/);
	if (Ergebnisa == -1 || Ergebnisb == -1) {
	  alert("Sie müssen unbedingt eine Überschrift formatieren!");
	  return false;
	}else{
		return true;
	}
}

/*buchsteben für dls zählen*/
			
function zaehlen()
 	{ 
var anfang="";
var maximum=300;
var text = window.document.formular.eingabe.value;
text = text.replace(/\[ueb\]/g, "");
text = text.replace(/\[\/ueb\]/g, "");
text = text.replace(/\[b\]/g, "");
text = text.replace(/\[\/b\]/g, "");
text = text.replace(/\[k\]/g, "");
text = text.replace(/\[\/k\]/g, "");
text = text.replace(/\[u\]/g, "");
text = text.replace(/\[\/u\]/g, "");
	
if (text.length>maximum)	
	{
  alert("Sie dürfen maximal 300 Zeichen zur Beschreibung des Downloads angeben.");
   window.document.formular.eingabe.value= window.document.formular.eingabe.value.substring(0,maximum);
return;
	}
else 
	{
var formfeld = window.document.formular.eingabe.value;
window.document.formular.anzeigen.value=maximum-text.length;
	}
}
		
function abschicken()
	{
	if (window.confirm('Wollen Sie das Formular wirklich abschicken?') == false)
		{
			return false;
		}
	
	}
		
function downloadabschicken()
{
	if (window.confirm('Wollen Sie das Formular wirklich abschicken?') == false)
	{
		return false;
	}
	else if (window.document.formular.datei.value.length<4)
	{
		alert("Sie müssen einen Download angeben.");
		return false;
	}
	else
	{
	document.getElementById("loading").style.display = "block";
	}
			
}


function downloadwindow(id)
{
anzeige=window.open("dl.php?id="+id, "Download" ,"width=400, height=300 , top=90, left=90, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}

function downloadcsv()
{
anzeige=window.open("csv.php", "Download" ,"width=400, height=300 , top=90, left=90, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}

function downloadwindow2(id)
{
anzeige=window.open("service/mapdl.php?id="+id, "Download" ,"width=400, height=200 , top=90, left=90, resizable=no, scrollbars=no, menubar=no, toolbar=no, status=no, location=no");
}


//////////////////Erstellt ein popup zur visiualisierung des DLs in der Suche
function artikelvorschau(autor)
{	


	anzeige=window.open("", "Vorschau" ,"width=600, height=600 , top=90, left=90, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
	testseite = anzeige.document;
	name = autor;
	//Kategorie
	var kategorie = document.formular.kategorie.value;

	//Datum
	jetzt = new Date();
	Tag = jetzt.getDay();
	Monat = jetzt.getMonth();
	Jahr = jetzt.getFullYear();
	Tag = String(Tag);
	Monat = String(Monat+1);

   if (Tag.length<10){Tag = '0'+Tag;}
   if (Monat.length<10){Monat = '0'+Monat;}

	datum = Jahr+'-'+Monat+'-'+Tag;
		//Inhalt
	 inhalt = window.document.formular.eingabe.value;
	 inhalt = inhalt.replace(/\[ueb\]/g, '<h1>');
	 inhalt = inhalt.replace(/\[\/ueb\]/g, '</h1>');
	 
	 inhalt = inhalt.replace(/\[b\]/g, '<strong>');
	 inhalt = inhalt.replace(/\[\/b\]/g, '</strong>');
	 
	 inhalt = inhalt.replace(/\[k\]/g, '<em>');
	 inhalt = inhalt.replace(/\[\/k\]/g, '</em>');

	 inhalt = inhalt.replace(/\[u\]/g, '<u>');
	 inhalt = inhalt.replace(/\[\/u\]/g, '</u>');

	 inhalt = inhalt.replace(/\n/g,"<br />");
	 
	 
	 inhaltkurz= inhalt.substring(0,200);
	 komisch2 = inhalt.indexOf("</h1>");
	 komisch1 = inhalt.indexOf("<h1>");
	 title = inhalt.substring(komisch1+4,komisch2);
	 inhalt = inhalt.substring(komisch2+5);
	
	//text
	text1 = '<span id="green">Ansicht Suche</span><br /><div id="suchergebnisse">'+inhaltkurz+'... <span id="klein">gekürzt</span><br><span style="position: relative;"><a href="index.php?location=suche&amp;kategorie=Theorie+und+Research&amp;wo=artikel&amp;submitted=Suchen" style="color: rgb(51, 51, 51);"><img src="bilder/uploads/kat.png" style="position: relative; top: 2px;" alt="Kategorie">&nbsp;'+kategorie+'</a><img src="bilder/head-16.png" style="position: relative; top: 2px; margin-left: 10px;" alt="autor">&nbsp;'+name+'<img src="bilder/clock-16.png" style="position: relative; top: 3px; margin-left: 10px;" alt="autor">&nbsp;'+datum+'<a href="index.php?location=showartikel&amp;artid=1" style="color: rgb(51, 51, 51);"><img src="bilder/uploads/dl.png" style="position: relative; top: 2px; margin-left: 10px;" alt="Artikel">&nbsp;zum Artikel</a></span></div><span id="green">'+title+'</span>';
	text2 = '<br><div id="infokasten"><span>Informationen</span><strong>Kategorie: </strong>'+kategorie+'<br /><strong>Autor: </strong>'+name+'<br /><strong>Veröffentlicht: </strong>'+datum+'<br /></div>'+inhalt;
	
	// HTML Text
	 text  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"><link href="style.css" rel="stylesheet" type="text/css" /></head><body style="background:url(bilder/bg.gif); padding:10px;" ><div style="background:#FFFFFF;padding:10px;display:block;"><br>';
	 text =  text+text1+text2;
	 text = text+'<br>';
	 text = text + '</div></body></html>';
	


testseite.open();
testseite.write(text);
testseite.close();
}




//////////////////Erstellt ein popup zur visiualisierung des DLs in der Suche
function dlvorschau(autor)
{	


	anzeige=window.open("", "Vorschau" ,"width=600, height=300 , top=90, left=90, resizable=no, scrollbars=yes, menubar=no, toolbar=no, status=no, location=no");
	testseite = anzeige.document;
	name = autor;
	//Kategorie
	kategorie = document.formular.kategorie.value;

	//Datum
	jetzt = new Date();
	Tag = jetzt.getDay();
	Monat = jetzt.getMonth();
	Jahr = jetzt.getFullYear();
	Tag = String(Tag);
	Monat = String(Monat+1);

   if (Tag.length<10){Tag = '0'+Tag;}
   if (Monat.length<10){Monat = '0'+Monat;}

	datum = Jahr+'-'+Monat+'-'+Tag;
		//Inhalt
	 inhalt = window.document.formular.eingabe.value;
	 inhalt = inhalt.replace(/\[ueb\]/g, '<h1>');
	 inhalt = inhalt.replace(/\[\/ueb\]/g, '</h1>');
	 
	 inhalt = inhalt.replace(/\[b\]/g, '<strong>');
	 inhalt = inhalt.replace(/\[\/b\]/g, '</strong>');
	 
	 inhalt = inhalt.replace(/\[k\]/g, '<em>');
	 inhalt = inhalt.replace(/\[\/k\]/g, '</em>');

	 inhalt = inhalt.replace(/\[u\]/g, '<u>');
	 inhalt = inhalt.replace(/\[\/u\]/g, '</u>');

	 inhalt = inhalt.replace(/\n/g,"<br />");
	 
	//text
	text1 = '<div id="suchergebnisse"><span style="float:left; margin-bottom: 20px; position:relative; left:-25px;" ><img src="bilder/uploads/defaultgray.png" /><br />'+datum+'</span>';
	text1 = text1+inhalt;
	text1 = text1+'<br><a href="#" style="color:#333333;"><img src="bilder/uploads/kat.png" style="position:relative;top:2px;" alt="Kategorie"/>&nbsp;'+kategorie+'</a><img src="bilder/head-16.png" style="position:relative;top:2px; margin-left:10px;" alt="autor"/>&nbsp;'+name+'<a href="#" style="color:#333333;" ><img src="bilder/uploads/dl.png" style="position:relative;top:2px; margin-left:10px;" alt="Download"/>&nbsp;Download</a></div>';



	
	// HTML Text
	 text  = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"><link href="style.css" rel="stylesheet" type="text/css" /></head><body style="background:url(bilder/bg.gif); padding:10px;" ><div style="background:#FFFFFF;padding:10px;display:block;"><br>';
	 text =  text+text1;
	 text = text+'<br>';
	 text = text + '</div></body></html>';
	


testseite.open();
testseite.write(text);
testseite.close();
}


// Administrator auswahl abbonoments auf hohes Datum setzen
function admindate()
	{
	if (window.document.formular.status.value = 'Admin')
		{
			 window.document.formular.muv.value = '2020-01-01';
			 window.document.formular.kus.value = '2020-01-01'
			 window.document.formular.auw.value = '2020-01-01'
			 window.document.formular.tur.value = '2020-01-01'
			  return false;
		}
			
	}
	
// User bearbeiten Submit überprüfung
function changeusersubmit(){
	var email = validEmail(trim(window.document.formular.mail.value));
	var vorname = trim(window.document.formular.vorname.value);
	var nachname = trim(window.document.formular.nachname.value);
	var muv = trim(window.document.formular.muv.value);
	var kus = trim(window.document.formular.kus.value);
	var tur = trim(window.document.formular.tur.value);
	var auw = trim(window.document.formular.auw.value);
	
	if (vorname.length < 3 || nachname.length < 3 )
	{
		alert("Die Eingabe des Vor- bzw. Nachnamen ist fehlerhaft. \n Bitte überprüfen Sie Ihre Eingabe. ");
		return false;
	}
	else if (!email)
	{
		alert(" Die E-Mailadresse ist fehlerhaft. \n Bitte überprüfen Sie Ihre Eingabe. ");
		return false;
	}
	else if (!checkValidDate(muv)) 
	{ 
		alert("Eine oder mehrere Datumsangabe im Abonnementbereich sind fehlerhaft. \n Bitte überprüfen Sie Ihre Eingabe. "); 
		return false;
	}
	else
	{
		return true;
	}
			
}

function changeperssubmit(){
	var email = validEmail(trim(window.document.formular.mail.value));
	var vorname = trim(window.document.formular.vorname.value);
	var nachname = trim(window.document.formular.nachname.value);
	
	
	if (vorname.length < 3 || nachname.length < 3 )
	{
		alert("Die Eingabe des Vor- bzw. Nachnamen ist fehlerhaft. \n Bitte überprüfen Sie Ihre Eingabe. ");
		return false;
	}
	else if (!email)
	{
		alert(" Die E-Mailadresse ist fehlerhaft. \n Bitte überprüfen Sie Ihre Eingabe. ");
		return false;
	}
	else
	{
		return true;
	}
			
}

function checkValidDate(dateStr) {
    // dateStr must be of format YYYY-MM-DD with either slashes
    // or dashes separating the parts. Some minor changes would have
    // to be made to use day month year or another format.
    // This function returns True if the date is valid.
	var datum = dateStr
	if (dateStr != '0000-00-00')
	{	
	    var slash1 = dateStr.indexOf("/");
	    if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
	    // if no slashes or dashes, invalid date
	    if (slash1 == -1) { return false; }

	    var dateYear = dateStr.substring(0, slash1)
	    var dateMonthAndDay = dateStr.substring(slash1+1, dateStr.length);
	    var slash2 = dateMonthAndDay.indexOf("/");
	    if (slash2 == -1) { slash2 = dateMonthAndDay.indexOf("-"); }
	    // if not a second slash or dash, invalid date
	    if (slash2 == -1) { return false; }
	    var dateMonth = dateMonthAndDay.substring(0, slash2);
	    var dateDay = dateMonthAndDay.substring(slash2+1, dateMonthAndDay.length);
	    if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) { return false; }
	    // if any non-digits in the month, invalid date
	    for (var x=0; x < dateMonth.length; x++) {
	        var digit = dateMonth.substring(x, x+1);
	        if ((digit < "0") || (digit > "9")) { return false; }
	    }
	    // convert the text month to a number
	    var numMonth = 0;
	    for (var x=0; x < dateMonth.length; x++) {
	        digit = dateMonth.substring(x, x+1);
	        numMonth *= 10;
	        numMonth += parseInt(digit);
	    }
	    if ((numMonth <= 0) || (numMonth > 12)) { return false; }
	    // if any non-digits in the day, invalid date
	    for (var x=0; x < dateDay.length; x++) {
	        digit = dateDay.substring(x, x+1);
	        if ((digit < "0") || (digit > "9")) { return false; }
	    }
	    // convert the text day to a number
	    var numDay = 0;
	    for (var x=0; x < dateDay.length; x++) {
	        digit = dateDay.substring(x, x+1);
	        numDay *= 10;
	        numDay += parseInt(digit);
	    }
	    if ((numDay <= 0) || (numDay > 31)) { return false; }
	    // February can't be greater than 29 (leap year calculation comes later)
	    if ((numMonth == 2) && (numDay > 29)) { return false; }
	    // check for months with only 30 days
	    if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) {
	        if (numDay > 30) { return false; }
	    }
	    // if any non-digits in the year, invalid date
	    for (var x=0; x < dateYear.length; x++) {
	        digit = dateYear.substring(x, x+1);
	        if ((digit < "0") || (digit > "9")) { return false; }
	    }
	    // convert the text year to a number
	    var numYear = 0;
	    for (var x=0; x < dateYear.length; x++) {
	        digit = dateYear.substring(x, x+1);
	        numYear *= 10;
	        numYear += parseInt(digit);
	    }
	    // Year must be a 2-digit year or a 4-digit year
	    if ( (dateYear.length != 2) && (dateYear.length != 4) ) { return false; }
	    // if 2-digit year, use 50 as a pivot date
	    if ( (numYear < 50) && (dateYear.length == 2) ) { numYear += 2000; }
	    if ( (numYear < 100) && (dateYear.length == 2) ) { numYear += 1900; }
	    if ((numYear <= 0) || (numYear > 9999)) { return false; }
	    // check for leap year if the month and day is Feb 29
	    if ((numMonth == 2) && (numDay == 29)) {
	        var div4 = numYear % 4;
	        var div100 = numYear % 100;
	        var div400 = numYear % 400;
	        // if not divisible by 4, then not a leap year so Feb 29 is invalid
	        if (div4 != 0) { return false; }
	        // at this point, year is divisible by 4. So if year is divisible by
	        // 100 and not 400, then it's not a leap year so Feb 29 is invalid
	        if ((div100 == 0) && (div400 != 0)) { return false; }
	    }
	    // date is valid
	    return true;
	}
	// date is valid
	return true;
}

//Nullen der Abonnementbereiche
function nullen()
{

	if (window.document.formular.status.value != 'Admin')
		{
			 window.document.formular.muv.value = '0000-00-00';
			 window.document.formular.kus.value = '0000-00-00'
			 window.document.formular.auw.value = '0000-00-00'
			 window.document.formular.tur.value = '0000-00-00'
			 return false;
		}
			
}

//Emailcheck
function validEmail(email)
{
  var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(strReg);
  return(regex.test(email));
}

function validdate(date)
{
  var strReg = "^([0-9])+\-([0-9])+\-([0-9])+$";
  var regex = new RegExp(strReg);
  return(regex.test(date));
}

//Emailcheck
function leer(wert)
{
  var strReg = "^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$";
  var regex = new RegExp(strReg);
  return(regex.test(email));
}
//trimfunction
function trim(s)
{
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//ladevorgang
function divinvisible()
{
	document.getElementById("laden").style.display = "none";
}
	
