function checkTextlength (srcObj, maxLength, displID)
{
  if (srcObj.value.length > maxLength)
     srcObj.value = srcObj.value.substr (0, maxLength);
  if (document.getElementById(displID))
     document.getElementById(displID).innerHTML = FormatZahlDeutsch(maxLength - srcObj.value.length);
}

function insert(aTag, eTag, oObjekt) {
  var input = document.forms['newsedit'].elements[oObjekt];
  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);
  }
}

function saveArticle ()
{
   if (document.newsedit.Titel.value == "" || (document.newsedit.Ort && document.newsedit.Ort.value == "") ||
   	  (document.newsedit.Lokal && document.newsedit.Lokal.value == "")
       )
   {
      alert ("Alle mit einem * versehenen Felder müssen ausgfüllt werden.");
      return;
   }

   document.newsedit.command.value = "save";
   document.newsedit.submit ();
}

function neuerTermin ()
{
   document.newsedit.command.value = "neuerTermin";
   document.newsedit.submit ();
}

function activateArticle ()
{
   document.newsedit.command.value = "activate";
   document.newsedit.submit ();
}

function deleteArticle ()
{
   if (!confirm ("Soll der Artikel wirklich entfernt werden?"))
      return;
   document.newsedit.command.value = "delete";
   document.newsedit.submit ();
}
function archiviereArticle ()
{
   document.newsedit.command.value = "archiviere";
   document.newsedit.submit ();
}
function hoehe(groesse, FieldName)
{
	document.getElementById(FieldName).style.height = groesse + "px";
}

function schliesseFenster ()
{
	window.opener.location.reload();
  window.close();
}

function editImg (id, tabelle, Access, ordner)
{
	
	//Bei Änderungen am Aufruf dieser Funktion müssen die Änderungen ggf. auf den CKEditor (edit-universal.php #CKinitialisierung) übertragen werden	
  editorfenster = window.open("" + ordner + "edit-images.php?artID=" + id + "&BerichtTabelle=" + tabelle + "&access=" + Access , "Bildedit", "height=800, width=610, resizable=yes, scrollbars=yes, locationbar=yes");
   editorfenster.focus();
  return;
}

function editArchiv (id, Access, ordner)
{
  editorfenster = window.open("" + ordner + "edit-archiv.php?artID=" + id + "&access=" + Access , "Bildedit", "height=700, width=610, resizable=yes, scrollbars=yes, locationbar=yes");
  editorfenster.focus();
  return;
}

function editFile (id, tabelle, Access)
{
  editorfenster = window.open("edit-file.php?artID=" + id + "&BerichtTabelle=" + tabelle + "&access=" + Access , "Fileedit", "height=720, width=620, resizable=yes, scrollbars=yes, locationbar=yes");
   editorfenster.focus();
  return;
}

function editLink (id, tabelle, Access)
{
  editorfenster = window.open("edit-link.php?artID=" + id + "&BerichtTabelle=" + tabelle + "&access=" + Access , "Fileedit", "height=500, width=800, resizable=yes, scrollbars=yes, locationbar=yes");
   editorfenster.focus();
  return;
}

function editMail (id, tabelle, Access)
{
  editorfenster = window.open("edit-mail.php?artID=" + id + "&BerichtTabelle=" + tabelle + "&access=" + Access , "Mailedit", "height=500, width=800, resizable=yes, scrollbars=yes, locationbar=yes");
   editorfenster.focus();
  return;
}

function setTop (id, imgUid, tabelle)
{
   document.newsedit.command.value = "setTop";
   document.newsedit.uid.value = id;
   document.newsedit.imgUid.value = imgUid;
   document.newsedit.DATAtable.value = tabelle;
   document.newsedit.submit ();
}

function setAdmin ()
{
   document.newsedit.command.value = "setAdmin";
   //document.newsedit.uid.value = id;
   document.newsedit.submit ();
}

function selectLink (linkUid)
{
   document.newsedit.command.value = "selectLink";
   document.newsedit.linkUid.value = linkUid;
   document.newsedit.submit ();
}

function selectImg (imgUid)
{
   document.newsedit.command.value = "select";
   document.newsedit.imgID.value = imgUid;
   document.newsedit.submit ();
}

function saveImg ()
{ 
  if (document.newsedit.Titel.value == "")	   
  {
	  alert ("Alle mit einem * versehenen Felder muessen ausgfuellt werden.");
	  return;
  }
  if (((document.newsedit.Bilddatei.value == "")) && document.newsedit.imgID.value =="")
  {
	 alert ("Bitte Seitenlänge und Bilddatei füllen.");
	 return;
  }
  setWorking();
   document.newsedit.command.value = "save";
   document.newsedit.submit ();
}

function saveArchiv ()
{
	setWorking();
   document.newsedit.command.value = "save";
   document.newsedit.submit ();
}

function activateImg (imgID)
{
   document.newsedit.imgID.value = imgID;
   document.newsedit.command.value = "activate";
   document.newsedit.submit ();
}

function activateArchiv (archiv_id)
{
   document.newsedit.archiv_id.value = archiv_id;
   document.newsedit.command.value = "activate";
   document.newsedit.submit ();
}

function deleteImg (imgID)
{
   if (!confirm ("Soll das Bild wirklich entfernt werden?"))
	  return;
	  
   document.newsedit.imgID.value = imgID;
   document.newsedit.command.value = "delete";
   document.newsedit.submit ();
}

function deleteArchiv (archiv_id)
{
   if (!confirm ("Soll das Archiv wirklich entfernt werden?"))
	  return;
	  
   document.newsedit.archiv_id.value = archiv_id;
   document.newsedit.command.value = "delete";
   document.newsedit.submit ();
}

function deleteImgs ()
{
   if (!confirm ("Sollen die ausgewählten Bilder wirklich entfernt werden?"))
	  return;
	  
   document.newsedit.command.value = "deleteImgs";
   document.newsedit.submit ();
}

function copyImgs ()
{	  
   document.newsedit.command.value = "copyImgs";
   document.newsedit.submit ();
}

function neuesBild(msgArtID)
{
   document.newsedit.command.value = "neuesBild";  
   document.newsedit.submit ();
}

function neuesArchiv()
{
   document.newsedit.command.value = "neuesArchiv";  
   document.newsedit.submit ();
}

function saveFile ()
{ 
  if (document.newsedit.Titel.value == "")	   
  {
	  alert ("Alle mit einem * versehenen Felder müssen ausgfüllt werden.");
	  return;
  }
  if (((document.newsedit.Uploaddatei.value == "")) && document.newsedit.fileID.value =="")
  {
	 alert ("Bitte Datei füllen.");
	 return;
  }
  setWorking();
   document.newsedit.command.value = "save";
   document.newsedit.submit ();
}


function neuerUpload(msgArtID)
{
   document.newsedit.fileID.value = "";
   document.newsedit.fileArtID.value = msgArtID;
   document.newsedit.Titel.value = "";
   document.newsedit.Kurztext.value = "";
   document.newsedit.command.value = "";
   document.newsedit.submit ();
}

function activateFile (fileID)
{
   document.newsedit.fileID.value = fileID;
   document.newsedit.command.value = "activate";
   document.newsedit.submit ();
}

function deleteFile (dateiID)
{
   if (!confirm ("Soll die Datei wirklich entfernt werden?"))
	  return;
   document.newsedit.fileID.value = dateiID;
   document.newsedit.command.value = "delete";
   document.newsedit.submit ();
}

function saveLink ()
{ 
	if (document.newsedit.Titel.value == "")	   
	{
		alert ("Alle mit einem * versehenen Felder müssen ausgfüllt werden.");
		return;
	}
	if (((document.newsedit.Link.value == "")) && document.newsedit.fileID.value =="")
	{
		alert ("Bitte Datei füllen.");
		return;
	}
	document.newsedit.command.value = "save";
	document.newsedit.submit ();
}

function neuerLink(msgArtID)
{
   document.newsedit.fileID.value = "";
   document.newsedit.fileArtID.value = msgArtID;
   document.newsedit.Link.value = "";
   document.newsedit.Titel.value = "";
   document.newsedit.Kurztext.value = "";
   document.newsedit.command.value = "";
   document.newsedit.submit ();
}
	

/*Ende editor-functions*/


function popup (datei, titel, hoehe, breite)
{
  window.open(" + datei +", " + titel + ", "height="+hoehe+", width="+breite+", resizable=no, scrollbars=yes, toolbar=no, location=no, status=no");
  return;
}

function help (datei, hoehe, breite)
{
	 window.open (datei, '',"height=" + hoehe + ", width=" + breite + ", resizable=no, scrollbars=yes, toolbar=no, location=no, status=no");
	 return;
}

var win = "";
function fenster(Grafik,width,height,name,titel)
 {
 	/*Dafür sorgen, dass immer nur ein Fenster geöffnet ist*/
	if (win != "")
 	{ 
 		/*Falls ein Fenster geöffnet ist, dieses erst schliessen*/
		win.close();
	}
   	win=window.open("",name,"width="+width+",height="+(height+60)+",left=150,top=50"); 
   	win.document.open("text/html");
   	win.document.write("<BODY leftmargin='0' topmargin='0' marginheight='0' marginwidth='0'>");
   	win.document.bgColor="#ffffff";
   		
	/*Stylesheets für das neue Fenster*/
  	win.document.write("<style type= text/css>" +
	"a{color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:link { color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:visited { color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:hover { color:#9D9FA2; text-decoration:none; font-size:0.88em;font-family:verdana;background-color:#e0e0e0; }" +
	"a:focus, a:active { color:#9D9FA2; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#e0e0e0; }" +
	"</style>");

	win.focus();
   	win.document.write("<TITLE>" +titel +"</title>");
   	win.document.write("<IMG src='"+Grafik+"'>");
   	win.document.write("<div align=center>&nbsp;</div>");
   	win.document.write("<div align=center><a href='javascript:window.print()'>Seite drucken</a></div>");
   	win.document.write("<div align=center><a href='javascript:self.close()'>Fenster schlie&szlig;en</a></div>");
   	win = "";
}
 

var win = "";
function fenster_mit_text(Grafik,b,h,n,titel,text,zugabe)
{
 	/*Dafür sorgen, dass immer nur ein Fenster geöffnet ist*/
	if (win != ""&&win.closed==false)
 	{ 
 		/*Falls ein Fenster geöffnet ist, dieses erst schliessen*/
		win.close();
	}
   	win=window.open("",n,"width="+b+",height="+(h+zugabe)+",left=50,top=20"); 
   	win.document.open("text/html");
   	win.document.write("<BODY leftmargin='0' topmargin='0' marginheight='0' marginwidth='0'>");
   	win.document.bgColor="#C8C8C8";
   		
	/*Stylesheets für das neue Fenster*/
  	win.document.write("<style type= text/css>" +
	"a{color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:link { color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:visited { color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:hover { color:#9D9FA2; text-decoration:none; font-size:0.88em;font-family:verdana;background-color:#e0e0e0; }" +
	"a:focus, a:active { color:#9D9FA2; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#e0e0e0; }" +
	"</style>");
	
	win.focus();
   	win.document.linkColor="red";
   	win.document.vlinkColor="red";
   	win.document.write("<TITLE>" +titel +"</title>");
   	win.document.write("<IMG src='"+Grafik+"'>");
   	win.document.write("<div align=center>" +text+ "</div>");
   	win.document.write("<div align=center>&nbsp;</div>");
   	win.document.write("<div align=center><a href='javascript:window.print()'>Seite drucken</a></div>");
   	win.document.write("<div align=center><a href='javascript:self.close()'>Fenster schlie&szlig;en</a></div>");
   	win = "";
}

//Bildanzeige genaue Bildgröße
var Fenstername;
var Fenster;
function popup_bild (id, bild, titel, hoehe, breite, typ)
{
  if (Fenster){Fenster.close();}
  Fenstername = id;
  if (typ!='')
  {
	Fenster=window.open("bspMovie.php?titel=" + titel + "&film="+ bild + "&artid=" + id + "&media=" + typ+ "&hoehe="+hoehe+"&breite="+breite, Fenstername, "height="+hoehe+", width="+breite+", resizable=no, scrollbars=no, toolbar=no, location=no, status=no");	   
  }
  else
  { 
	Fenster=window.open("bspImages.php?titel=" + titel + "&bild="+ bild + "&artid=" + id, Fenstername, "height="+hoehe+", width="+breite+", resizable=no, scrollbars=no, toolbar=no, location=no, status=no");	   
  }
  Fenster.focus();
  return;
}

/*Funktionen um die Seite als Startseite des Browsers 
zu erklären und die aktuelle Seite zu bookmarken*/
var browser = navigator.appName;
var version = navigator.appVersion.substring(0, 1);
var ie =
  ((browser == "Microsoft Internet Explorer") &&
  (version >= 4))
;
var ns =
  ((browser == "Netscape") &&
  (version >= 4 ))
;

function setHomePage(siteURL) {
  if (ie) {
    document.body.style.behavior = "url(#default#homepage)";
    document.body.setHomePage(siteURL);
  } else
    alert(
      "Die Seite konnte nicht automatisch als " +
      "Startseite eingestellt werden, tun Sie " +
      "dies bitte manuell!"
    );
}

function addToFavorites(siteURL, description) {
  if (ie)
    window.external.AddFavorite(siteURL, description);
  else if (ns)
    alert("Drücken Sie Strg+D zum Bookmarken dieser Seite!");
  else
    alert(
      "Die Seite kann nicht automatisch den " +
      "Favoriten hinzugefügt werden!"
    );
}


var win = "";
function fenster_mit_scrollbalken(Grafik,width,height,name,titel)
{
 	/*Dafür sorgen, dass immer nur ein Fenster geöffnet ist*/
	if (win != "")
 	{ 
 		/*Falls ein Fenster geöffnet ist, dieses erst schliessen*/
		win.close();
	}
   	win=window.open("",name,"width="+(width+60)+",height=510,left=150,top=50"); 

   	win.document.open("text/html");
   	win.document.write("<BODY leftmargin='0' topmargin='0' marginheight='0' marginwidth='0'>");
   	win.document.bgColor="#ffffff";
   		
	/*Stylesheets für das neue Fenster*/
  	win.document.write("<style type= text/css>" +
	"a{color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:link { color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:visited { color:#98CA3C; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#ffffff; }" +
	"a:hover { color:#9D9FA2; text-decoration:none; font-size:0.88em;font-family:verdana;background-color:#e0e0e0; }" +
	"a:focus, a:active { color:#9D9FA2; text-decoration:underline; font-size:0.88em;font-family:verdana;background-color:#e0e0e0; }" +
	"</style>");
	
   	win.document.write("<TITLE>" +titel +"</title>");
   	win.document.write("<div style='position:absolute;z-index:1;text-align:center;background-color:#none;left:20px;top:20px;height:450px;overflow:auto;width:"+(width+20)+"px;'><IMG src='"+Grafik+"'></div>");
   	win.document.write("<div align=center>&nbsp;</div>");
   	win.document.write("<div style='position:absolute;z-index:1;background-color:#none;text-align:center;width:"+(width+60)+"px;top:480px;'><a href='javascript:window.print()'>Seite drucken</a> | <a href='javascript:self.close()'>Fenster schlie&szlig;en</a></div>");
   	win.document.close();
   	win = "";
}

function savefremdwort ()
{
   if (document.newsedit.fremdwort.value == "" || document.newsedit.erklaerung.value == "")
      {
		  alert ("Alle mit einem * versehenen Felder müssen ausgfüllt werden.");
     	 return;
	  }

   document.newsedit.command.value = "save";
   document.newsedit.submit ();
}

function editfremdwort (Access)
{
  editorfenster = window.open("edit-acronym.php?access=" + Access , "Acronymedit", "height=500, width=620, resizable=yes, scrollbars=yes, locationbar=yes");
  editorfenster.focus();
  return;
}

function selectfremdwort (id)
{
   document.newsedit.command.value = "selectfremdwort";
   document.newsedit.fremdwortid.value = id;
   document.newsedit.submit ();
}

function deletefremdwort (dateiID)
{
   if (!confirm ("Soll dieser Eintrag wirklich entfernt werden?"))
	  return;
   document.newsedit.fileID.value = dateiID;
   document.newsedit.command.value = "delete";
   document.newsedit.submit ();
}

function neuesfremdwort(msgArtID)
{
   document.newsedit.fileID.value = "";
   document.newsedit.fremdwort.value = "";
   document.newsedit.erklaerung.value = "";
   document.newsedit.command.value = "";
   document.newsedit.submit ();
}

function editPerm (uid)
{
  window.open("edit-permission.php?uid=" + uid , "Rechteverwaltung", "height=600, width=610, resizable=yes, scrollbars=yes, locationbar=yes");
  return;
}

function savePerm ()
{ 
	document.newsedit.command.value = "save";
	document.newsedit.submit ();
}

function changeUserPerm ()
{ 
	document.newsedit.command.value = "changeUserPerm";
	document.newsedit.submit ();
}

function statisierePerm ()
{
	var anzahl = parseFloat(document.getElementById('gesamt').value);
	var erlaubt = parseFloat(document.getElementById('erlaubt').value);
	if(erlaubt > 0) var checken = false; else var checken = true;

	for (i = 0; i <= anzahl; i++)
	{
		document.getElementById(i).checked = checken;
	}
	
	document.newsedit.command.value = "save";
	document.newsedit.submit ();
}

function FormatZahlDeutsch(nummer) {

var nummer = '' + nummer;
 var laenge = nummer.length;
 if (laenge >
3) {
 var mod = laenge % 3;
 var output = (mod > 0 ?
 (nummer.substring(0,mod))
: '');
 for (i=0 ; i < Math.floor(laenge / 3); i++) {
 if ((mod == 0)
&& (i == 0))
 output += nummer.substring(mod+ 3 * i,
 mod + 3 *
i + 3); else
 output+= '.' + nummer.substring(mod + 3 * i,
 mod + 3 * i
+ 3); } return (output); }
 else return nummer; }
