// Globale Variable für Editor; Vorinitialisierung mit 'titel', da dieses Element IMMER vorhanden ist
var lastFocusComponent ='titel';



// Globale Variablen für FlashDetection
var flash2Installed 	= false;   
var flash3Installed 	= false;    
var flash4Installed 	= false;   
var flash5Installed 	= false;    
var flash6Installed 	= false;  
var maxVersion 		= 6;             // zur Zeit akuellste Version
var actualVersion 	= 0;          // gefundene Version
//-------------------------------------------------------------------------------------------------
// VBScript für FlashDetection
// Pruefe ob Windows und IE, wenn ja verwende VBScript
var isIE = false;

if(navigator.appVersion.indexOf("MSIE") != -1) 
	isIE = true;	// true wenn es IE ist
	
var isWin = false;
if(navigator.appVersion.indexOf("Windows") != -1)
	isWin = true;	// true wenn OS Windows ist

// benutze bei IE auf Windows VBScript zum detecten
if(isIE && isWin)
{
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n'); 
  document.write('</SCR' + 'IPT\> \n'); 
}
//-------------------------------------------------------------------------------------------------
// Funktionen


//s=seite,h=höhe,w=weite
  function NewLinkWindow(s,h,w){
		options="width=" + w + ", height=" + h + ",toolbar=no,locationbar=no,resizable=no";
		Fenster1=window.open(s, "box", options);
		Fenster1.moveTo(screen.width/2-220,210);
		Fenster1.focus();
}

function NewWindow(s,h,w){
		options="width=" + w + ", height=" + h + ",toolbar=no,locationbar=no,resizable=no";
		Fenster1=window.open(s, "box", options);
		
		Fenster1.focus();
}
function NewWindow(s,h,w,options){
		options="width=" + w + ", height=" + h + "," + options;
		Fenster1=window.open(s, "box", options);
		
		Fenster1.focus();
}

function drucken()
{
if(document.layers) /* Abfrage auf Netscape 4 */
self.print();
if(document.all) /* Abfrage auf MSIE 4 */
{
self.focus();
var OLECMDID_PRINT = 6;
var OLECMDEXECOPT_DONTPROMPTUSER = 2;
var OLECMDEXECOPT_PROMPTUSER = 1;
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd',WebBrowser);
WebBrowser1.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER);
WebBrowser1.outerHTML = '';
}
}

function loginFocus() {
  if ((document.useradmin) && (document.useradmin.username))
    document.useradmin.username.focus();
}

function checkPwd(pwd, pwd2, login, activeCell){
	var inhalt = pwd;
	var inhalt2 = pwd2;
	var charindex = -1;
	var numindex = -1;
	var minLength = 6;
	var invalid= " ";
	
	
	if (login==null||login==""){
		alert('Bitte Benutzername angeben.');
		activeCell.focus();
		activeCell.select();
		return false;
	}
	if (inhalt!=inhalt2){
		alert('Die beiden Passworteingaben stimmen nicht überein.');
		activeCell.focus();
		activeCell.select();
		return false;
	}
	
	if (login==inhalt){
		alert('Benutzername darf nicht gleich Passwort sein.');
		activeCell.focus();
		activeCell.select();
		return false;
	}
	
	// check for minimum length
	if (inhalt.length < minLength) {
		alert('Das Passwort muss mindestens ' + minLength + ' Zeichen lang sein. Bitte wiederholen.');
		activeCell.focus();         
		activeCell.select();
		return false;
	}
// check for spaces
	if (inhalt.indexOf(invalid) > -1) {
		alert('Leerzeichen sind nicht erlaubt!');
		activeCell.focus();         
		activeCell.select();
		return false;
	}

	
	
	for (i=0; i<inhalt.length; i++){
		if ('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuvwxyz'.indexOf(inhalt.charAt(i)) < 0) {
		 charindex = charindex;
		 } 
			else {
				charindex = 1;
			}
		if ('0123456789'.indexOf(inhalt.charAt(i)) < 0) {
			 	numindex = numindex;
			 	}
			else {
				numindex = 1;
			}
	}

	if (charindex > 0 && numindex > 0) {
		return true;
	}
	else {
		alert('Das Passwort hat ein falsches Format! Es Muss mindestens einen Buchstaben und eine Ziffer enthalten.');
		activeCell.focus();         
		activeCell.select(); 
		return false;
	}
}

function checkPwdEmpty(pwd, pwd2, login, activeCell){
	var inhalt = pwd;
	var inhalt2 = pwd2;
	var charindex = -1;
	var numindex = -1;
	var minLength = 6;
	var invalid= " ";
	
	if (inhalt!=inhalt2){
		alert('Die beiden Passworteingaben stimmen nicht überein.');
		activeCell.focus();
		activeCell.select();
		return false;
	}
	
	if (login==inhalt){
		alert('Benutzername darf nicht gleich Passwort sein.');
		activeCell.focus();
		activeCell.select();
		return false;
	}
	
	
	if (inhalt=="") {
		
		return true;}
	
	else{
	
	// check for minimum length
	if (inhalt.length < minLength) {
		alert('Das Passwort muss mindestens ' + minLength + ' Zeichen lang sein. Bitte wiederholen.');
		activeCell.focus();         
		activeCell.select();
		return false;
	}
// check for spaces
	if (inhalt.indexOf(invalid) > -1) {
		alert('Leerzeichen sind nicht erlaubt!');
		activeCell.focus();         
		activeCell.select();
		return false;
	}

	
	
	for (i=0; i<inhalt.length; i++){
		if ('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuvwxyz'.indexOf(inhalt.charAt(i)) < 0) {
		 charindex = charindex;
		 } 
			else {
				charindex = 1;
			}
		if ('0123456789'.indexOf(inhalt.charAt(i)) < 0) {
			 	numindex = numindex;
			 	}
			else {
				numindex = 1;
			}
	}

	if (charindex > 0 && numindex > 0) {
		return true;
	}
	else {
		alert('Das Passwort hat ein falsches Format! Es Muss mindestens einen Buchstaben und eine Ziffer enthalten.');
		activeCell.focus();         
		activeCell.select(); 
		return false;
	}
	}
}


function setCookie(name, value, expires, path) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "")+
      ((path) ? "; path=" + path : ""); // +
  document.cookie = curCookie;
}

function setCookie1Year(name, value) {
  var expires;
  // , path, domain, secure;
  var now = new Date();
  fixDate(now);
  now.setTime(now.getTime());
  var expires = new Date(now.getYear() + 1, now.getMonth(), now.getDate()); 
  setCookie(name,value,expires,"/");
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Mon, 13-May-02 17:08:00 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


function openNewFullsizeWindow()
{
	var aw = screen.availWidth;
	var ah = screen.availHeight;
      	var mywin = open('/odyssee/blank.html','neuesfenster','width='+aw+',height='+ah+',resizable=YES,scrollbars=YES,top=0,screenX=50,screenY=50');
      	mywin.opener = self;
      	mywin.focus();
}

function openNewWindow(hoehe,breite)
{
	var aw = screen.availWidth;
	var ah = screen.availHeight;
	var myheight = ah;
	var mywidth = aw;
	if(hoehe < ah)
		myheight=hoehe;
	if(breite < aw)
		mywidth=breite;	
    var mywin = open('/odyssee/blank.html','neuesfenster','width='+mywidth+',height='+myheight+',resizable=YES,scrollbars=YES,top=0,screenX=50,screenY=50');
    mywin.opener = self;
    mywin.focus();
    return mywin;
}

function targetopener(mylink, closeme, closeonly)
{
  if (! (window.focus && window.opener))return true;
  window.opener.focus();
  if (! closeonly)window.opener.location.href=mylink.href;
  if (closeme)window.close();
  return false;
}

function openfullscreen(href, windowname) {
  window.open(href, windowname, ',type=fullWindow,fullscreen,scrollbars=yes');
}

function targetopener(mylink, closeme, closeonly)
{
  if (! (window.focus && window.opener))return true;
  window.opener.focus();
  if (! closeonly)window.opener.location.href=mylink.href;
  if (closeme)window.close();
  return false;
}

function openNewFullsizeWindow(mediaid)
{
	var aw = screen.availWidth;
	var ah = screen.availHeight;
   var mywin = open("fotopopup.jsp?mediaid="+mediaid+"&winwidth="+aw+"&height="+ah+"&jsessionid=1","mediapopup","width="+aw+",height="+ah+",resizable=YES,scrollbars=YES,top=0,screenX=50,screenY=50");
   mywin.opener = self;
   mywin.focus();
}




function openMediaPopup(mediaid,breite,hoehe)
{
	var aw = screen.availWidth;
	var ah = screen.availHeight;
	var myheight = ah;
	var mywidth = aw;
	if(hoehe < ah)
		myheight=hoehe;
	if(breite < aw)
		mywidth=breite;	
	mywidth += 50;
	myheight += 50;	
    var mywin = open('/deepwebcms/servlet/download?mediaid='+mediaid,'mediapopup','width='+mywidth+',height='+myheight+',resizable=YES,scrollbars=YES,top=0,screenX=50,screenY=50');
    mywin.opener = self;
    mywin.focus();
    return mywin;
}

function openFotoalbumPopup(id,iw,ih,kontext,stichwort)
{

    // abkuerzungen: 
    // i = image
    // a = available
    // w = window
    // q = quotient
    // m = maximal

	var aw = screen.availWidth-0;
	var ah = screen.availHeight-85;
	
	var wq = iw/aw;
	var hq = ih/ah;

	var mq = wq;
	if (wq<hq) mq = hq;

	var ww;
	var wh;
	if (mq>1) {
	  ww = iw/mq;
	  wh = ih/mq;
    } else {
	  ww = iw;
	  wh = ih;
    }

    var dim = ww;
    if (ww<wh) dim = wh;


    pfad = "fotoalbum.jsp?id="+id
          +"&maxdim="+dim
          +"&popupwidth="+ww
          +"&popupheight="+(wh+50)
          +"&availwidth="+aw
          +"&availheight="+ah
          +"&kontext="+kontext
          +"&stichwort="+stichwort
          +"&jsessionid=1";

    var mywin = open(pfad,'fotoalbumpopup','width='+ww+',height='+(wh+50)+',resizable=YES,scrollbars=NO,top=0,left=0,screenX=0,screenY=0');
    mywin.opener = self;
    mywin.focus();
    return mywin;
}


function removeElement(name,uniid) {
  var bez = "media_"+uniid+"_"+name;
  if (confirm("Möchten Sie dieses Bild löschen?"))
    document.all[bez].outerHTML = "";
}

function openMediaWindow(hoehe,breite)
{
  openMediaWindow(hoehe,breite,'/odyssee/blank.html');
}

function openMediaWindow(hoehe,breite,link,uniid)
{
	var aw = screen.availWidth;
	var ah = screen.availHeight;
	var myheight = ah;
	var mywidth = aw;
	if(hoehe < ah)
		myheight=hoehe;
	if(breite < aw)
		mywidth=breite;	
    var mywin = open('/deepwebcms/media/index.jsp?jsessionid='+jsessionid+'&formname=formular&id='+link+'&uniid='+uniid,'neuesfenster','width='+mywidth+',height='+myheight+',resizable=YES,scrollbars=YES,top=0,screenX=50,screenY=50');
    mywin.opener = self;
    mywin.focus();
    return mywin;
}

function browserCheck ()
{
	var win;
	var name_des_browsers;
	var codename_des_browsers;
	var version_des_browsers;
	var sprache_des_browsers;
	var plattform_des_browsers;
	var name_des_browsers_http;

	//win=window.open("","Hallo","width=500,height=300,resizable=yes");
	name_des_browsers=navigator.appName;
	codename_des_browsers=navigator.appCodeName;
	version_des_browsers=navigator.appVersion;
	sprache_des_browsers=navigator.language;
	plattform_des_browsers=navigator.platform;
	name_des_browsers_http=navigator.userAgent;

	
}



  function doBildDB(id,finalquery,stichwort) {
	   var aw = screen.availWidth - 410;
	   // var mywin = open('','Bilder');
 	   var mywin = open('/','Bilder','width=400,height='+(700)+',resizable=NO,scrollbars=YES,left='+aw+',top=0,screenX=50,screenY=50');
	   mywin.opener = self;
	   var oldaction = document.formular.action;
	   var oldtarget = document.formular.target;

	   document.formular.reloadaction.value=oldaction;
	   document.formular.reloadtarget.value=oldtarget;

	   document.formular.bilder_id.value=id;
	   document.formular.bilder_finalquery.value=finalquery;
	   document.formular.bilder_initialstichwort.value=stichwort;
	   document.formular.bilder_aktion.value="reload";
	   document.formular.action="/odyssee/bilder/index.php";
	   document.formular.target="Bilder";
	   document.formular.submit();
	   // document.formular.action=oldaction;
	   // document.formular.target=oldtarget;
	   mywin.focus();
   }

   function doBild(id,bildtyp) {
	   if (bildtyp=="bild") bildtyp="f_bild";
           doBildDB(id,"update inhalte set "+bildtyp+"=#BILD# where id="+document.formular.inhalt_id.value,document.formular.inhalt_pid_backup.value);
   }

  function saveWin() {
    var win = open('/odyssee/speichern.html','Speichern','width=150,height='+(80)+',resizable=NO,scrollbars=NO,screenX=100,screenY=50');
    win.opener = self;
    win.focus();
    return win;
  }

  function saveFields(){
  
  	if (document.all) {

			// Allgemeine Routine für IE: kopiert Inhalte aus DIV-Tags in die dazugehörigen Input-Fields.
	    	for(i=0; i<document.formular.length; i++){
	    		index = document.formular.elements[i].name.indexOf("_backup");
	  			if (index>0){
					bez = document.formular.elements[i].name.substring(0,index);
					
					if (document.all[bez]) // exisitert das Feld überhaupt als DIV-tag, oder ist es ein type=text?
					{ 
						if (!document.all[bez].value){
							
  					  		document.formular.elements[i].value=unescape(document.all[bez].innerHTML);
  					  		
  					  	}
  					}
	  			}
	  		}

	}
  }


	function getURLohneAuswahl(){
		var originURL = document.location.href;
		//alert("originURL:"+originURL);
		var laenge = originURL.length;
		var auswahlPos = originURL.indexOf("auswahl=");
		if (auswahlPos==-1)
			return originURL;
		var rest = originURL.substr(auswahlPos,laenge);
		//alert("rest:"+rest);
		// so jetzt könnten zwei Fälle auftreten:
		// es gibt nix mehr hintendran, oder noch ein &
		var index = rest.indexOf("&");
		//alert("auswahlpos="+auswahlPos+";index="+index);
		if (index == -1){
			originURL = originURL.substr(0,auswahlPos-1);
			//alert("originURL(mit Rest):"+originURL);
		}
		else{
			prefix = originURL.substr(0,auswahlPos-1);
			//alert("prefix:"+prefix);
			suffix = rest.substr(index,laenge);
			//alert("suffix:"+suffix);
			//alert(prefix+suffix);
			originURL=prefix+suffix;
			//alert("originURL:"+originURL);
		}
		//alert("originURL:"+originURL);
		return originURL;
		

	}

  function doSpeichern() {
    
    
    if(document.all["schlagworte"] && document.all["schlagworte"].innerHTML == "")
    { 
   		alert("Bitte füllen Sie das Feld 'Schlagworte' aus! \nIhr Artikel kann sonst nicht gespeichert werden!");
	   	return; 
    }
    saveFields();

    document.formular.tokill.value="";
    document.formular.aktion.value="speichern";
    document.formular.reloadaction.value=getURLohneAuswahl();

    document.formular.reloadtarget.value="_self";
    if (document.formular.invoker)
    	document.formular.invoker.value = document.location.href;
    

    win = saveWin();
    document.formular.target="Speichern";
    document.formular.action="/odyssee/updateinhalt.jsp";
    document.formular.submit();

  }
  
  function doArchivieren() {        
      document.formular.tokill.value="";
      document.formular.aktion.value="archivieren";
      document.formular.reloadaction.value=getURLohneAuswahl();
      document.formular.reloadtarget.value="_self";
  
      win = saveWin();
      document.formular.target="Speichern";
      document.formular.action="/odyssee/updateinhalt.jsp";
      document.formular.submit();
      
      document.formular.auswahl.value="null";
  
  }

  function doZurueck() {
  
    if(document.all["schlagworte"] && document.all["schlagworte"].innerHTML == "")
    { 
   		alert("Bitte füllen Sie das Feld 'Schlagworte' aus! \nIhr Artikel kann sonst nicht gespeichert werden!");
	   	return; 
    }
    saveFields();

    document.formular.tokill.value="";
    document.formular.aktion.value="speichern";
    document.formular.reloadaction.value=getURLohneAuswahl();
    document.formular.reloadtarget.value="_self";

    win = saveWin();
    document.formular.target="Speichern";
    document.formular.action="/odyssee/updateinhalt.jsp";
    document.formular.submit();

    document.formular.auswahl.value="null";

  }

  function doLoeschen() {

    var is_confirmed = confirm("Wollen Sie diesen Artikel wirklich löschen?");
    if (is_confirmed) {
      document.formular.reloadaction.value=getURLohneAuswahl();
   
      document.formular.reloadtarget.value="_self";
      document.formular.tokill.value="loeschen";
      win = saveWin();
      document.formular.aktion.value="speichern";
      document.formular.target="Speichern";
      document.formular.action="/odyssee/updateinhalt.jsp";
      document.formular.submit();

      document.formular.auswahl.value="null";

    }
  }

  function doAbbrechen() {
      document.formular.reloadaction.value=getURLohneAuswahl();
      document.formular.target="_self";
      document.formular.auswahl.value="null";
      document.formular.submit();
  }

  function doShowHTMLEditor(name_id) {
 	  doShowHTMLEditor(name_id, "1") 
  }
  
  function doShowHTMLEditor(name_id, jsession) {
    if (jsession==null || jsession=="")
    	jsession="1";
    if (document.all) {
      if (document.all.titel) document.formular.titel_backup.value=unescape(document.all.titel.innerHTML);
      if (document.all.kurz) document.formular.kurz_backup.value=unescape(document.all.kurz.innerHTML);
      if (document.all.lang) document.formular.lang_backup.value=unescape(document.all.lang.innerHTML);
      if (document.all.help1) document.formular.help1_backup.value=unescape(document.all.help1.innerHTML);
      if (document.all.zurueck) document.formular.zurueck_backup.value=unescape(document.all.zurueck.innerHTML);
    }

    document.formular.tokill.value="";
    document.formular.aktion.value="speichern";

    document.formular.target="Speichern";
    document.formular.action="/odyssee/updateinhalt.jsp";
    document.formular.reloadaction.value=getURLohneAuswahl();
    document.formular.target="_self";

    msg=open("/odyssee/editor.jsp?&e_id="+name_id+"&jsessionid="+jsession,"Speichern","toolbar=no,directories=no,menubar=no,width=700,height=500");
    // msg=open("editor.jsp?&e_id="+name_id,"Speichern");
    msg.opener = this;
  }

// Wird in ein div.editable geklickt, so wird die globale Variable lastFocusComponent auf den Namen
// des div-Tags gesetzt (z.B. titel)
// Die Variable wird in der Funktion doEditCommand abgefragt
	function setComponent(comp){
		lastFocusComponent = comp;
	}
	
// Wird im Redaktionsmodus ein Toolbar-Icon angeklickt, dann wird geprüft, ob
// schon ein Bereich markiert ist. Wenn nicht, dann wird einer angelegt und die 
// Aktion ausgeführt
	function doEditCommand(command){		
		document.all[lastFocusComponent].focus();
		if (document.selection.type == "None") {
      		var r = document.selection.createRange();      		
      	}
      	document.execCommand(command);
   }
	

function html2mail()
{
	document.write('<A HREF="mailto:?subject=Schau Dir mal folgende Seite an, ' + document.title + '&body=Die Seite findet man unter: ' + window.location + '\" onMouseOver="window.status=\'Eine Email über diese Seite senden\'; return true" TITLE="Eine Email über diese Seite senden"><img src="/odyssee/gfx/media/empfehlen.gif" border="0"></a>');
}

// Aufruf der Funktion "uhr()" : BEISPIEL...-->
// <body bgcolor="#e2e2e2" text="#FFFFFF" onLoad="window.setTimeout('uhr()',1000)"> -->
// <FORM NAME="Datum"> -->
//	<INPUT SIZE=10 NAME="Date" readonly> -->
// </form> -->
function uhr()
{
	var jahr, monat, tag, stunden, minuten, sekunden;
	var			  AktuellesDatum = new Date	();
	jahr 		= AktuellesDatum.getFullYear();
	monat 		= AktuellesDatum.getMonth	()+1;
	tag 		= AktuellesDatum.getDate	();
	stunden		= AktuellesDatum.getHours	();
	minuten		= AktuellesDatum.getMinutes	();
	sekunden	= AktuellesDatum.getSeconds	();

	if(monat < 10)
		monat = "0"+String(monat);

	if(tag < 10)
		tag = "0"+String(tag);

	if(stunden < 10)
		stunden = "0"+String(stunden);

	if(minuten < 10)
		minuten = "0"+String(minuten);

	if(sekunden < 10)
		sekunden = "0"+String(sekunden);

	window.document.Datum.Date.value = "  "+tag+"."+monat+"."+jahr+"      |      "+stunden+":"+minuten+":"+sekunden;
	window.setTimeout('uhr()',1000);
}

function openNavigationseditor(url){
  var width=700;
  var left= (screen.availWidth-width) / 2;

  var win = open(url,'Navigationseditor','width='+width+',height='+(500)+',left='+left+',resizable=YES,scrollbars=YES,screenX=50,screenY=50');
    win.opener = self;
    win.focus();
    return win;

}

function setFavorite(url,title){
  	
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {    
    window.external.AddFavorite(url,title);
  }
  else {
    var msg = "Setzen Sie doch einen Bookmark für die Seite";
    if(navigator.appName == "Netscape") msg += " (CTRL-D)";
      alert(msg);
  }
}

// f ist der Name des Formulars und e+s die Namen der ElementE in die das Ergebnis (farbwert) geschrieben werden
function openColorPicker(f,e,w,h)
{

 var kalWin = window.open("/odyssee/colorpicker.jsp?f="+f+"&e="+e+"&jsessionid=1", "Colorpicker", "width=330,height=496");

 kalWin.moveTo(w,h);
}


// Öffnet einen JavaScriptKalender; 
// f ist der Name des Formulars und e der Name des Elements in das das Ergebnis (das Datum) geschrieben werden
function openkalender(f,e)
{

 var kalWin = window.open("/odyssee/kalender.jsp?f="+f+"&e="+e+"&jsessionid=1", "Kalender", "width=400,height=330,resizable=1");

 kalWin.moveTo((screen.width-200)/2,(screen.height-230)/2);
}
function openkalender(f,e,wh,wm)
{
	
 var kalWin = window.open("/odyssee/kalender.jsp?f="+f+"&e="+e+"&wh="+wh+"&wm="+wm+"&jsessionid=1", "Kalender", "width=400,height=330,resizable=1");

 kalWin.moveTo((screen.width-200)/2,(screen.height-230)/2);
}

// Öffnet einen JavaScriptKalender; 
// f ist der Name des Formulars und e der Name des Elements in das das Ergebnis (das Datum) geschrieben werden
function openkalender(f,e,jsid)
{

 var kalWin = window.open("/odyssee/kalender.jsp?c=1&jsessionid="+jsid+"&f="+f+"&e="+e, "Kalender", "width=400,height=330,resizable=1");

 kalWin.moveTo((screen.width-200)/2,(screen.height-230)/2);
}
function openkalender(f,e,wh,wm,jsid)
{
	
 var kalWin = window.open("/odyssee/kalender.jsp?c=1&jsessionid="+jsid+"&f="+f+"&e="+e+"&wh="+wh+"&wm="+wm, "Kalender", "width=400,height=330,resizable=1");

 kalWin.moveTo((screen.width-200)/2,(screen.height-230)/2);
}



function openCenterWindow(seite,breite,hoehe)
{
 var kalWin = window.open(seite, "centerWindow", "width="+breite+",height="+hoehe);
 kalWin.moveTo(((screen.width-breite)/2) , ((screen.height-hoehe)/2));
 //return kalWin;
 kalWin.opener=self;
} 

function openScrollableCenterWindow(seite,breite,hoehe)
{
 var kalWin = window.open(seite, "centerWindow", "width="+breite+",height="+hoehe+",scrollbars=yes");
 kalWin.moveTo(((screen.width-breite)/2) , ((screen.height-hoehe)/2));
 //return kalWin;
 kalWin.opener=self;
} 

function hasFlash(requiredVersion) 
{  
  // Ist es Netscape oder Mozilla?
  if (navigator.plugins) 
  {
    // Prüfe auf Flash Version 2 oder >= Version 3
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) 
    {      
      // ist es Version 2 so schreibe 2.0 rein, sonst lass die Variable leer ""
      var isVersion2 = "";
      if(navigator.plugins["Shockwave Flash 2.0"])
	isVersion2 = " 2.0" 
	
      // hole die FlashDescription und schreibe sie in diese Variable (erst ab Version 3 oder hoeher)
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      // in der Description steht die Version z.B. "....Version 5.0...", wir suchen also nach dem Punkt
      // und holen uns dann das Zeichen davor!
      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion >= 6;
    }
  }
  
  // durchlaufe alle gefundenen Versionen und setze es auf die hoechste
  for (var i = 2; i <= maxVersion; i++) 
  {  
    if (eval("flash" + i + "Installed") == true) 
	actualVersion = i;
  }
  
  // bei WebTV auf Version 3 setzen
  if(navigator.userAgent.indexOf("WebTV") != -1) 
	actualVersion = 3;  
  
  // ist die gefundene Version >= der geforderten Version?
  if(actualVersion >= requiredVersion)
	return true;

  return false;
}

function hasFlash3()
{
	return hasFlash(3);
}

function hasFlash4()
{
	return hasFlash(4);
}

function hasFlash5()
{
	return hasFlash(5);
}

function hasFlash6()
{
	return hasFlash(6);
}

/*
 * Diese Funktionen koennen engesetzt werden, um über eine einzige Checkbox 
 * viele weitere Checkboxen zu aktivieren.
 * Beispiel: Alle Benutzer im Newsletter löschen, anstatt alle einzeln anzuklicken
 *
 * Diesen Javascriptcodeblock muss man in die Seite einfuegen und anpassen.
 *
 * <SCRIPT LANGUAGE="JavaScript">
 * <!--
 * var chkboxgroup = new javascriptcollection();
 * chkboxgroup.addToGroup("loeschen"); // loeschen ist der Name der Checkboxes muessen alle gleich benannt werden.
 * chkboxgroup.setControlBox("alleloeschen"); // alleloschen ist die Checkbox, die alle anderen aktiviert.
 * chkboxgroup.setMasterBehavior("all"); // der Parameter 'all' darf nicht veraendert werden
 * -->
 * </SCRIPT>
 *
 * HTML-Code (natuerlich anpassen):
 * <input type=checkbox name=loeschen value="irgendwas" onClick="chkboxgroup.check(this)">
 * <input type=checkbox name=alleloeschen value=alle onClick="chkboxgroup.check(this)">Alle Benutzer löschen
 */
function javascriptcollection() {
	this.controlBox=null;
	this.controlBoxChecked=null;
	this.maxAllowed=null;
	this.maxAllowedMessage=null;
	this.masterBehavior=null;
	this.formRef=null;
	this.checkboxWildcardNames=new Array();
	this.checkboxNames=new Array();
	this.totalBoxes=0;
	this.totalSelected=0;
	// Public methods
	this.setControlBox=CBG_setControlBox;
	this.setMaxAllowed=CBG_setMaxAllowed;
	this.setMasterBehavior=CBG_setMasterBehavior;	// all, some
	this.addToGroup=CBG_addToGroup;
	// Private methods
	this.expandWildcards=CBG_expandWildcards;
	this.addWildcardCheckboxes=CBG_addWildcardCheckboxes;
	this.addArrayCheckboxes=CBG_addArrayCheckboxes;
	this.addSingleCheckbox=CBG_addSingleCheckbox;
	this.check=CBG_check;
	}

// Set the master control checkbox name
function CBG_setControlBox(name) { this.controlBox=name; }

// Set the maximum number of checked boxes in the set, and optionally
// the message to popup when the max is reached.
function CBG_setMaxAllowed(num,msg) {
	this.maxAllowed=num;
	if (msg!=null&&msg!="") { this.maxAllowedMessage=msg; }
	}

// Set the behavior for the checkbox group master checkbox
//	All: all boxes must be checked for the master to be checked
//	Some: one or more of the boxes can be checked for the master to be checked
function CBG_setMasterBehavior(b) { this.masterBehavior = b.toLowerCase(); }

// Add checkbox wildcards to the checkboxes array
function CBG_addToGroup() {
	if (arguments.length>0) {
		for (var i=0;i<arguments.length;i++) {
			this.checkboxWildcardNames[this.checkboxWildcardNames.length]=arguments[i];
			}
		}
	}

// Expand the wildcard checkbox names given in the addToGroup method
function CBG_expandWildcards() {
	if (this.formRef==null) {alert("ERROR: No form element has been passed.  Cannot extract form name!"); return false; }
	for (var i=0; i<this.checkboxWildcardNames.length;i++) {
		var n = this.checkboxWildcardNames[i];
		var el = this.formRef[n];
		if (n.indexOf("*")!=-1) { this.addWildcardCheckboxes(n); }
		else if(CBG_nameIsArray(el)) { this.addArrayCheckboxes(n); }
		else { this.addSingleCheckbox(el); }
		}
	}


// Add checkboxes to the group which match a pattern
function CBG_addWildcardCheckboxes(name) {
	var i=name.indexOf("*");
	if ((i==0) || (i==name.length-1)) {
		searchString= (i)?name.substring(0,name.length-1):name.substring(1,name.length);
		for (var j=0;j<this.formRef.length;j++) {
			currentElement = this.formRef.elements[j];
			currentElementName=currentElement.name;
			var partialName = (i)?currentElementName.substring(0,searchString.length) : currentElementName.substring(currentElementName.length-searchString.length,currentElementName.length);
			if (partialName==searchString) {
				if(CBG_nameIsArray(currentElement)) this.addArrayCheckboxes(currentElement);
				else this.addSingleCheckbox(currentElement);
				}
			}
		}
	}

// Add checkboxes to the group which all have the same name
function CBG_addArrayCheckboxes(name) {
	if((CBG_nameIsArray(this.formRef[name])) && (this.formRef[name].length>0)) {
		for (var i=0; i<this.formRef[name].length; i++) { this.addSingleCheckbox(this.formRef[name][i]); }
		}
	}

function CBG_addSingleCheckbox(obj) {
	if (obj != this.formRef[this.controlBox]) {
		this.checkboxNames[this.checkboxNames.length]=obj;
		this.totalBoxes++;
		}
	}

// Runs whenever a checkbox in the group is clicked
function CBG_check(obj) {
	if (this.formRef==null) {
		this.formRef=obj.form;
		this.expandWildcards();
		}
	var checked=obj.checked;
	if (this.controlBox!=null&&obj.name==this.controlBox) {
		if (this.masterBehavior=="all") {
			for (i=0;i<this.checkboxNames.length;i++) { this.checkboxNames[i].checked=checked; }
			this.totalSelected=(checked)?this.checkboxNames.length:0;
			}
		else {
			if (!checked) {
				obj.checked = (this.totalSelected>0)?true:false;
				obj.blur();
				}
			}
		}
	else {
		if (this.masterBehavior=="all") {
			if (!checked) {
				this.formRef[this.controlBox].checked=false;
				this.totalSelected--;
				}
			else { this.totalSelected++; }
			if (this.controlBox!=null) {
				this.formRef[this.controlBox].checked=(this.totalSelected==this.totalBoxes)?true:false;
				}
			}
		else {
			if (!obj.checked) { this.totalSelected--; }	
			else { this.totalSelected++; }
			if (this.controlBox!=null) {
				this.formRef[this.controlBox].checked=(this.totalSelected>0)?true:false;
				}
			if (this.maxAllowed!=null) {
				if (this.totalSelected>this.maxAllowed) {
					obj.checked=false;
					this.totalSelected--;
					if (this.maxAllowedMessage!=null) { alert(this.maxAllowedMessage); }
					return false;
					}
				}
			}
		}
	}

function CBG_nameIsArray(obj) {
	return ((typeof obj.type!="string")&&(obj.length>0)&&(obj[0]!=null)&&(obj[0].type=="checkbox"));
	}
	
// Ende der Checkboxfunktionen






// id_control ist der wert des id_parameters einer checkbox. z.B. <input type=checkbox id="ch"...>
// id_show ist die id des HTML-Elements, das an- und ausgeschaltet wird.
// funktioniert mit IE und Mozilla
function ToggleVisibility(id_control, id_show)
    {
    var objInp = document.getElementById(id_control);
    var objDiv = document.getElementById(id_show);    

    if (objInp.checked) objDiv.style.visibility = ""; else objDiv.style.visibility = "hidden";
    }




//Finds and returns an element.
function getEl(sTag,start) {
  while ((start!=null) && (start.tagName!=sTag)) start = start.parentElement;
  return start;
}

/*
	id: f_eintrag des Inhaltes aus der Inhalte-Tabelle
	str: die target-URL
	target: Zielframe
*/
function createLink(id,str,target) {
  var isA = getEl("A",document.selection.createRange().parentElement());
  
  if ((str!=null) && (str!="http://")) {
    if (document.selection.type=="None") {
    	alert("Bitte markieren Sie zuerst einen Text");    	
    }
    else{
      var sel=document.selection.createRange();
      if (target=="")
      	sel.pasteHTML('<A dw_linkid='+id+' HREF="'+str+'">'+sel.htmlText+'</A>');
      else
	    sel.pasteHTML('<A dw_linkid='+id+' HREF="'+str+'" target="'+target+'">'+sel.htmlText+'</A>');
      sel.select();
    } 
  }
  else focus();
}

function createFontsizeAttrib(value) {
  var isSpan = getEl("SPAN",document.selection.createRange().parentElement());
  // gibt es schon ein umspannendes SPAN?
  if (isSpan){
  	// hat dieses SPAN ein font-size style -Attribut?		
  		if (isSpan.style.getAttribute("fontSize",false)){
			
			isSpan.style.setAttribute("fontSize",value,false);
			return;
 		}

  }	  
  if (value!=null) {
    if (document.selection.type=="None") {
    	alert("Bitte markieren Sie zuerst einen Text");    	
    }
    else{
      var sel=document.selection.createRange();
      sel.pasteHTML('<SPAN style="font-size:'+value+'">'+sel.htmlText+'</SPAN>');      
      sel.select();
    } 
  }
  else focus();
}

/*
	Ermittelt die Position, die ein Element am Bildschirm momentan WIRKLICH besetzt
	Die wirkliche Position kann von der Position, die durch Koordinaten gesetzt ist,
	abweichen.
	Aufruf: getRealPos(element,"Top")
			getRealPos(element,"Left")
*/
function getRealPos(el,which) {
	iPos = 0;
	while (el!=null) {
	 	iPos += el["offset" + which];
	 	//alert("Element:"+el.tagName+"; iPos="+el["offset" + which]);
		el = el.offsetParent;
		//alert("Parent:"+el);
	}
	return iPos
}

/* 
	Wrapper für getRealPos(el,"Top");
*/
function getRealTopPos(el){
	return getRealPos(el,"Top");
}

/* 
	Wrapper für getRealPos(el,"Left");
*/
function getRealLeftPos(el){
	return getRealPos(el,"Left");
}

/*
Testet Linie a und b auf Schnitt
*/
function TestLines( ax1,ay1,ax2,ay2, bx1,by1,bx2,by2 )
{
	// Sonderfall: eine der beiden Linien ist senkrecht	
	if (ax1==ax2){
		if (ax1<Math.min(bx1,bx2) || ax1>Math.max(bx1,bx2)){ // Senkrechte a liegt "neben" Linie b
			return false;
		}else{
			//Achtung: gilt nur für Waagerechte
			if (Math.min(ay1,ay2)<by1 && Math.max(ay1,ay2)>by2)
				return true;
			else
				return false;
		}
	}
	if (bx1==bx2){
		if (bx1<Math.min(ax1,ax2) || bx1>Math.max(ax1,ax2)){ // Senkrechte b liegt "neben" Linie a
			return false;
		}else{
			//Achtung: gilt nur für Waagerechte
			if (Math.min(by1,by2)<ay1 && Math.max(by1,by2)>ay2)
				return true;
			else
				return false;
		}
	}
		
	// calculate gradients
	am = (ay1 - ay2) / (ax1 - ax2);
	bm = (by1 - by2) / (bx1 - bx2);
	
	// parallel lines can't intercept
	if (am == bm)
	{
		return false;
	}
	// calculate axis intersect values
	ac = ay2 - (am * ax2);
	bc = by2 - (bm * bx2);
	// calculate x point of intercept
	ix = (bc - ac) / (am - bm);
	// is intersection point in segment
	if ( ix < Math.min(ax2, ax1) || ix > Math.max(ax2, ax1) )
	{
		return false;
	}
	if ( ix < Math.min(bx2, bx1) || ix > Math.max(bx2, bx1) )
	{
		return false;
	}
	// calculate y point of intercept
	iy = (am * ix) + ac;
	
	// points intercept
	return true;
}


/*

Testet Rechteck a und Rechteck b auf Schnitt
Koordinaten sind jeweils linke obere Ecke und rechte untere Ecke
*/ 
function RectangleIntersection(ax1,ay1,ax2,ay2, bx1,by1,bx2,by2 ){
	// a: obere Linie; b: linke Linie
	schnitt = TestLines(ax1,ay1,ax2,ay1, bx1,by1,bx1,by2);
	if (schnitt)
		return schnitt;
	// a: obere Linie; b: rechte Linie
	schnitt = TestLines(ax1,ay1,ax2,ay1, bx2,by1,bx2,by2);
	if (schnitt)
		return schnitt;
	// a: untere Linie; b: linke Linie
	schnitt = TestLines(ax1,ay2,ax2,ay2, bx1,by1,bx1,by2);
	if (schnitt)
		return schnitt;
	// a: untere Linie; b: rechte Linie
	schnitt = TestLines(ax1,ay2,ax2,ay2, bx2,by1,bx2,by2);
	if (schnitt)
		return schnitt;

	// a: linke Linie; b: obere Linie
	schnitt = TestLines(ax1,ay1,ax1,ay2, bx1,by1,bx2,by1);
	if (schnitt)
		return schnitt;
	// a: linke Linie; b: untere Linie
	schnitt = TestLines(ax1,ay1,ax1,ay2, bx1,by2,bx2,by2);
	if (schnitt)
		return schnitt;
	// a: rechte Linie; b: obere Linie
	schnitt = TestLines(ax2,ay1,ax2,ay2, bx1,by1,bx2,by1);
	if (schnitt)
		return schnitt;
	// a: rechte Linie; b: untere Linie
	schnitt = TestLines(ax2,ay1,ax2,ay2, bx1,by2,bx2,by2);
	if (schnitt)
		return schnitt;
	// falls keine der obigen Schnitte zutraf, dann müssen wir noch testen, 
	// ob ein Objekt in dem anderen enthalten ist.
	Aa = Math.abs(ax1-ax2)*Math.abs(ay1-ay2);
	Ab = Math.abs(bx1-bx2)*Math.abs(by1-by2);
	if (Aa < Ab)
		return PointInRectangle(ax1,ay1,bx1,by1,bx2,by2);
	else
		return PointInRectangle(bx1,by1,ax1,ay1,ax2,ay2);

}

// Teste, ob Punkt x in Rechteck r liegt
// return true, falls x in r; false sonst
function PointInRectangle(x1,y1,rx1,ry1,rx2,ry2){
	return (x1>Math.min(rx1,rx2) && x1<Math.max(rx1,rx2) && y1 > Math.min(ry1,ry2) && y1 < Math.max(ry1,ry2));
}
//eine im format dd.mm.yyyy
//wird als yyyymmdd zurückgegeben
function ConvertDate2Number(num){
	var text=num;
  	var daypos=text.indexOf(".");
  	var day=text.substring(0,daypos);
  	if(day.length<2){day="0"+day;}
  	text=text.substring(daypos+1,text.length);
  	var monpos=text.indexOf(".");
  	var mon=text.substring(0,monpos);
  	if(mon.length<2){mon="0"+day;}
  	var year=text.substring(monpos+1,text.length);
  	return year+mon+day;
  	}
  	
