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 = maxLength - srcObj.value.length;
}

function insert(aTag, eTag, oObjekt) {
  var input = document.forms['newsedit'].elements[oObjekt];
  input.focus();
  /* f&uuml;r Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einf&uuml;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&uuml;r neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einf&uuml;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&uuml;r die &uuml;brigen Browser */
  else
  {
    /* Abfrage der Einf&uuml;geposition */
    var pos;
    var re = new RegExp('^[0-9]{0,3}$');
    while(!re.test(pos)) {
      pos = prompt("Einf&uuml;gen an Position (0.." + input.value.length + "):", "0");
    }
    if(pos > input.value.length) {
      pos = input.value.length;
    }
    /* Einf&uuml;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&uuml;ssen ausgf&uuml;llt werden.");
      return;
   }

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

function saveKunden ()
{
   if (document.newsedit.kunden_name.value == "")
   {
      alert ("Alle mit einem * versehenen Felder m&uuml;ssen ausgf&uuml;llt werden.");
      return;
   }

   document.newsedit.command.value = "save";
   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)
{
  window.open("" + ordner + "edit-images.php?artID=" + id + "&BerichtTabelle=" + tabelle + "&access=" + Access , "Bildedit", "height=700, width=800, resizable=yes, scrollbars=yes, locationbar=yes");
  return;
}

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

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

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

function editKunden (id, uebID, ebene)
{
  window.open("edit-kunden.php?uid=" + id + "&uebID=" + uebID + "&ebene=" + ebene + "&access=<?=ACCESS_EDIT_AKTUELL?>" , "Universal", "height=400, width=1000, scrollbars=yes");
  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 saveImg ()
{ 
  if (document.newsedit.Titel.value == "")	   
  {
	  alert ("Alle mit einem * versehenen Felder m&uuml;ssen ausgf&uuml;llt werden.");
	  return;
  }
  if (((document.newsedit.Bilddatei.value == "")) && document.newsedit.imgID.value =="")
  {
	 alert ("Bitte Seitenl&auml;nge und Bilddatei f&uuml;llen.");
	 return;
  }
   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 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 neuesBild(msgArtID)
{
   document.newsedit.imgID.value = "";
   document.newsedit.imgArtID.value = msgArtID;
   document.newsedit.Titel.value = "";
   document.newsedit.Kurztext.value = "";
   document.newsedit.command.value = "";  
   document.newsedit.submit ();
}

function saveFile ()
{ 
  if (document.newsedit.Titel.value == "")	   
  {
	  alert ("Alle mit einem * versehenen Felder m&uuml;ssen ausgf&uuml;llt werden.");
	  return;
  }
  if (((document.newsedit.Uploaddatei.value == "")) && document.newsedit.fileID.value =="")
  {
	 alert ("Bitte Datei f&uuml;llen.");
	 return;
  }
   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&uuml;ssen ausgf&uuml;llt werden.");
		return;
	}
	if (((document.newsedit.Link.value == "")) && document.newsedit.fileID.value =="")
	{
		alert ("Bitte Datei f&uuml;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&uuml;r sorgen, dass immer nur ein Fenster ge&ouml;ffnet ist*/
	if (win != "")
 	{ 
 		/*Falls ein Fenster ge&ouml;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&uuml;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&uuml;r sorgen, dass immer nur ein Fenster ge&ouml;ffnet ist*/
	if (win != ""&&win.closed==false)
 	{ 
 		/*Falls ein Fenster ge&ouml;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&uuml;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&ouml;ß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-heimann.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-heimann.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&auml;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&uuml;cken Sie Strg+D zum Bookmarken dieser Seite!");
  else
    alert(
      "Die Seite kann nicht automatisch den " +
      "Favoriten hinzugef&uuml;gt werden!"
    );
}


var win = "";
function fenster_mit_scrollbalken(Grafik,width,height,name,titel)
{
 	/*Daf&uuml;r sorgen, dass immer nur ein Fenster ge&ouml;ffnet ist*/
	if (win != "")
 	{ 
 		/*Falls ein Fenster ge&ouml;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&uuml;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 = "";
}
