////////////////////////////////////////////////////////////////
//
// Anzupassende Variablen:
//
// Rahmen, in den die Seiten zu laden sind, falls kein Ziel angegeben wurde 
//("top" fuer Nonframe).
var frameContent = "inhalt";
//
// Falls Cookies zur Weitergabe von NavId verwendet werden sollen (0 = aus, 1 = ein).
var useCookiesNavId = 0;
//
// Falls Cookies zur Weitergabe von PageId verwendet werden sollen (0 = aus, 1 = ein).
var useCookiesPageId = 0;
//
// Aktiviert den Debugmodus zur Fehlersuche (0 = aus, 1 = ein).
var cacheMode = 0;
//
// Aktiviert den Debugmodus zur Fehlersuche (0 = aus, 1 = ein).
var debugMode = 0;
//
// Optionen des standard Popupfensters.
var optionsPopup = "scrollbars=yes,resizable=yes,menubar=yes,location=no,width=600,height=480";
//
// Optionen des ersten Popupfensters.
var optionsPopup1 = "scrollbars=yes,resizable=yes,menubar=no,location=no,width=240,height=360";
//
// Optionen des zweiten Popupfensters.
var optionsPopup2 = "scrollbars=yes,resizable=yes,menubar=no,location=no,width=160,height=160";
//
////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////
//
// Beschreibung: Browsererkennung
//
////////////////////////////////////////////////////////////////

var ns  = (document.layers) ? 1 : 0;
var ie  = (document.all) ? 1 : 0;
var dom = (document.getElementById) ? 1 : 0;
var mac = (navigator.platform.indexOf("Mac") != -1) ? 1 : 0;

////////////////////////////////////////////////////////////////
//
// Beschreibung: Ermittelt den Weblication-Benutzernamen
//
// Return: Benutzername
//
////////////////////////////////////////////////////////////////
  
function getUserName(){

  var cookieStr = document.cookie;  
  var userName  = "";
  var checkIsLogedin = /wId=WSESSIONID/;
  
  if(checkIsLogedin.test(cookieStr) == true){
    var checkUser       = /WSESSIONID\%40([\w|\d|-|_]+)\%40([\w|\d|-|_]*)\%40/;
    var checkUserPublic = /WSESSIONID\%40p%3A([\w|\d|-|_]+)\%40([\w|\d|-|_]*)\%40/;  
    if(checkUser.test(cookieStr) == true){
      userName = RegExp.$1;
      //userLang = RegExp.$2; 
    }
    else if(checkUserPublic.test(cookieStr) == true){
      userName = RegExp.$1;
      //userLang = RegExp.$2; 
    }
  }
  return userName;  
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Oeffnet ein Popup-Fenster
//
////////////////////////////////////////////////////////////////

function openPopup(url){

 if(debugMode == 1){
  alert(url);
 }

 window.open(url, "popup", optionsPopup);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Oeffnet ein Popup-Fenster vom Typ 1
//
////////////////////////////////////////////////////////////////

function openPopup1(url){

 if(debugMode == 1){
  alert(url);
 }

 window.open(url, "popup", optionsPopup2);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Oeffnet ein Popup-Fenster vom Typ 2
//
////////////////////////////////////////////////////////////////

function openPopup2(url){

 if(debugMode == 1){
  alert(url);
 }

 window.open(url, "popup", optionsPopup2);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Wechselt ein Bild aus
// 
// Parameter: picOldId  = ID des Bildes, das ersetzt werden soll
//
// Parameter: picNewObj = Neues Bildobjekt das eingesetzt werden soll
//
////////////////////////////////////////////////////////////////

function changePic(picOldId, picNewObj){

 if(debugMode == 1){
  alert("picOldId = " + picOldId + "\npicNewObj = " + picNewObj);
 }
 
 if(document.images[picOldId]){
  if(document.images[picOldId].src && picNewObj){
   document.images[picOldId].src = picNewObj.src;
  }
 }
} 

////////////////////////////////////////////////////////////////
//
// Beschreibung: Druckt das aktuelle Dokument
//
////////////////////////////////////////////////////////////////

function printDocument(){  

 if(ie){
  var browser = '<object id="webBrowser" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
  document.body.insertAdjacentHTML('beforeEnd', browser);
  webBrowser.ExecWB(6, 2);
 }
 else{
  window.print() ;  
 }
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Sendet das Formular
// 
// Parameter: form = Formular, das gesendet werden soll.
//
////////////////////////////////////////////////////////////////

function submitForm(form, cacheMode){

 var messageObligation = " ist ein Pflichtfeld!\n"; //erscheint wenn ein Pflichtfeld nicht ausgefüllt wurde
 var messageEmail      = " enthält keine gültige Email Adresse!\n"; //erscheint wenn ein Pflichtfeld nicht ausgefüllt wurde

 var isObligation = /\|\w*o\w*$/i;  //Pflichtfeld, wenn Feldname am Schluss |o  enthaelt   (z.B.: "Strasse|o")
 var isEmail      = /\|\w*e\w*$/i;  //Emailfeld wenn Feldname am Schluss |e enthaelt       (z.B.: "eMail|e")
 var isCache      = /\|\w*c\w*$/i;  //Wird fuer weitere Formulare gespeichert am Schluss |c enthaelt       (z.B.: "eMail|c")
          //Pflicht- und Emailfeld, wenn am Schluss |oe oder |eo (z.B.: "eMail|eo") 

 var checkEmail   = /.*\@.*\.\w+/i;
 var formElement;
 var formElementNameOrig;
 var alertStr = "";

 var cookieStr = "";

  for(var i = 0; i <= form.elements.length - 1; i++){
    var formElement = form.elements[i];
    if(formElement){
      if(formElement.type == "text" || formElement.type == "textarea"){
        formElementNameOrig = formElement.name.replace(/\|\w+/, ''); 
        if(formElementNameOrig == "Email"){
          if(form.from.value == ""){
            form.from.value = formElement.value;
          }
        }
        if(isObligation.test(formElement.name) == true){  
          if(formElement.value == ""){
            alertStr += formElementNameOrig + messageObligation;                     
          }
        } 
        if(isEmail.test(formElement.name) == true){  
          if (checkEmail.test(formElement.value) == false){
            alertStr += formElementNameOrig + messageEmail;                     
          }
        } 
        if(cacheMode == "1"){    
          if(isCache.test(formElement.name) == true){ 
            if(formElement.value != ""){
              cookieStr += "wFc_" + formElementNameOrig + "=" + formElement.value + ":";
            }
          }    
        }     
      }
	  else if(formElement.type == "checkbox"){
        formElementNameOrig = formElement.name.replace(/\|\w+/, ''); 	  
        if(isObligation.test(formElement.name) == true){  
          if(formElement.checked == false){
            alertStr += formElementNameOrig + messageObligation;                     
          }
        } 
	  }
    }
  }

  if(alertStr != ""){
    alert(alertStr);  
  }
  else{
    if(cacheMode == 1){   
      cookieStr += "; path=/";  
      document.cookie = cookieStr; 
    }
    form.submit();
  }
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Initialisiert das Formular
// 
// Parameter: form = Formular, das initialisiert werden soll.
//
////////////////////////////////////////////////////////////////

function initForm(form){

  var isCache      = /\|\w*c\w*$/i;  //Wird fuer weitere Formulare gespeichert am Schluss |c enthaelt       (z.B.: "eMail|c")

  var formElement;
  var formElementNameOrig;

  var cookieStr    = document.cookie;
  var elementValue = "";

  if(form){
    for(var i = 0; i <= form.elements.length - 1; i++){
      var formElement = form.elements[i];
      if(formElement){
        if(formElement.name){      
          if(isCache.test(formElement.name) == true){ 
            if(formElement.value == ""){
              formElementNameOrig = formElement.name.replace(/\|\w+/, ''); 
              var getElementValue = eval("/wFc_" + formElementNameOrig + "\=([^\:]+)\:/");
              if(getElementValue.test(cookieStr) == true){
                elementValue = RegExp.$1;
                formElement.value = elementValue;
              }  
            }
          }
        }
      }
    }
  }
  else{
    //alert("Formular wurde nicht gefunden!\n Wurde es schon geladen?");
  }
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Startet die Suche in einem neuen Fenster
// 
////////////////////////////////////////////////////////////////

function startSearch(){
  var form = document.frmSearch;
  if(form.term.value == "" || form.term.value == " suchen"){
    alert("Sie haben noch keinen Suchbegriff eingegeben!");
    form.term.focus();
    return;
  }
  var win = window.open ("", "winSearch","height=440,width=540,status=no,menubar=no,scrollbars=yes");
  var x = (screen.width-540)/2;
  win.moveTo(x,30);
  win.focus();
  form.submit();
}


////////////////////////////////////////////////////////////////
//
// Beschreibung: Zeigt einen Layer an
// 
// Parameter: layerId = ID des anzuzeigenden Layers
//
////////////////////////////////////////////////////////////////

function showLayer(layerId){

 if(ie){
  if(document.all[layerId]){
   document.all[layerId].style.visibility = 'visible';
  }  
 }
 else if(ns){
  if(document.layers[layerId]){
   document.layers[layerId].visibility = 'visible'; 
  } 
 }
 else if(dom){
  if(document.getElementById(layerId)){
   document.getElementById(layerId).style.visibility = 'visible';  
  }
 } 
}
     
////////////////////////////////////////////////////////////////
//
// Beschreibung: Schliest einen Layer
// 
// Parameter: layerId = ID des zu schliesenden Layers
//
////////////////////////////////////////////////////////////////

function hideLayer(layerId){

 if(ie){
  if(document.all[layerId]){
   document.all[layerId].style.visibility = 'hidden';
  }  
 }
 else if(ns){
  if(document.layers[layerId]){
   document.layers[layerId].visibility = 'hide'; 
  } 
 }
 else if(dom){
  if(document.getElementById(layerId)){
   document.getElementById(layerId).style.visibility = 'hidden';  
  }
 } 
}
     
////////////////////////////////////////////////////////////////
//
// Beschreibung: Prueft, ob ein Layer angezeigt wird
// 
// Parameter: layerId = ID des zu pruefenden Layers
//
// Return: 0 = unsichtbar, 1 = sichbar
//
////////////////////////////////////////////////////////////////

function isVisibleLayer(layerId){

 if(ie){
  if(document.all[layerId].style.visibility == 'visible'){
   return 1;
  }  
  else{
   return 0;
  }  
 }
 else if(ns){
  if(document.layers[layerId].visibility == 'visible'){        
   return 1;
  }  
  else{
   return 0;
  } 
 }
 else if(dom){
  if(document.getElementById(layerId).style.visibility == 'visible'){        
   return 1;
  }  
  else{
   return 0;
  }
 }    
}

///////////////////////////////////////////////////
// Prüft die Richtigkeit der Eingaben in Formularen
// by Maciej Homziuk
///////////////////////////////////////////////////
// Naming of a field oenName of field
// Empty values: text and select-one "".
	function checkForm (iForm, paramNameSubmit, paramSchicken, paramToday) {
		
		var checkVar = /^(o|x)(ex|xn|dx|dd|xx)/;
	
		for (x=0; x<document.forms[iForm].elements.length; x++) {
			blnObligatory = false;
			blnEmail = false;
			blnDate = false;
			blnNumeric = false;
			blnEmpty = false;
			blnAt = false;
			blnPoint = false;
			blnCheckNumeric = true;
			blnCheckDate = true;
			blnDateFromPast = true
			strMaxLength = "";
			strTextAreaName = "";
			fieldName = "";
			
			fieldName = document.forms[iForm].elements[x].name;
			fieldType = document.forms[iForm].elements[x].type;
	
			if (typeof(fieldName) != "undefined"){
				if (checkVar.test(fieldName.charAt(0)+fieldName.charAt(1)+fieldName.charAt(2)) == true){
					
					//Checking if the field is obligatory.
					if (fieldName.charAt(0) == "o") {blnObligatory = true}
					//Checking if the field is a date field.
					if (fieldName.charAt(1) == "d") {blnDate = true}
					//Checking if the field cannot contain the date from the past.
					if (fieldName.charAt(2) == "d") {blnDateFromPast = false}
					//Checking if the field is an email field.
					if (fieldName.charAt(1) == "e") {blnEmail = true}
					//Checking if the field is "only numeric values" field.
					if (fieldName.charAt(2) == "n") {blnNumeric = true}
		
					strRealName = fieldName.slice(3);
					if (strRealName == "Email") {
						strRealName = "E-Mail";
					} else if (strRealName == "Email2") {
						strRealName = "Bestätigung der E-Mail";
					} else if (strRealName == "Dienst") {
						strRealName = "Innen- / Außendienst";
					} else if (strRealName == "Vermittler Profil") {
						strRealName = "Vermittlerprofil";
					} else if (strRealName == "Passwort2") {
						strRealName = "Bestätigung des Passworts";
					} else if (strRealName == "VJBeschreibung") {
						strRealName = "Kurzbeschreibung zur Veröffentlichung im VersicherungsJournal";
					} else if (strRealName == "Wogehoert") {
						strRealName = "\"Wo gehört\"";
					}
					strValue = document.forms[iForm].elements[x].value;
					// Whole procedure for the obligatory field.
					if (blnObligatory) {
						//Checking if the obligatory field wans't filled in the form.
						if (fieldType == "text" || fieldType == "textarea" || fieldType == "password") {
							if (strValue == "") {
								blnEmpty = true;
								emptyAlert = "Bitte füllen Sie das Feld \""+strRealName+"\" aus!";
							}
						} else if (fieldType == "select-one" || fieldType == "select-multiple") {
							if (strValue == "") {
								blnEmpty = true;
								emptyAlert = "Bitte treffen Sie im Feld \""+strRealName+"\" eine Wahl!";
							}
						} else if (fieldType == "checkbox") {
							if (document.forms[iForm].elements[x].checked == false) {
								blnEmpty = true;
								emptyAlert = "Sie müssen unsere AGB akzeptieren !!!";
							}
						} else if (fieldType == "radio") {
							blnRadioOK = false;
							intAnzahlElemente = document.getElementsByName(document.forms[iForm].elements[x].name).length;
							for (var i=0; i<intAnzahlElemente; i++) {
								if (document.getElementsByName(document.forms[iForm].elements[x].name)[i].checked) {
									blnRadioOK = true;
								}
							}
							if (!blnRadioOK) {
								blnEmpty = true;
								emptyAlert = "Bitte eine Option im Feld \""+strRealName+"\" auswählen !!!";
							}
						}
						
						if (blnEmpty == true) {
							alert (emptyAlert);
							document.forms[iForm].elements[x].focus();
							return false;
						}
					}
		
					// Whole procedure for the email field.
					strIllegalChar = "";
					if (blnEmail && (strValue != "")) {
						for (y = 0; y < document.forms[iForm].elements[x].value.length; y++) {
							if (document.forms[iForm].elements[x].value.charAt(y) == "@")
								{blnAt = true}
							if (document.forms[iForm].elements[x].value.charAt(y) == ".")
								{blnPoint = true}
							if (document.forms[iForm].elements[x].value.charAt(y).match(/(,|;|:|#|!| |ä|ö|ü)/))
								{strIllegalChar = document.forms[iForm].elements[x].value.charAt(y);}
						}
						if (strIllegalChar != "") {
							alert("Unerlaubtes Zeichen in der E-Mailadresse: \""+strIllegalChar+"\" !");
							document.forms[iForm].elements[x].focus();
							return false;
						}
						if (! (blnAt && blnPoint)) {
							alert("Geben Sie bitte im Feld "+strRealName+" eine Emailadresse ein !");
							document.forms[iForm].elements[x].focus();
							return false;
						}
					}
		
					// Whole procedure for the date field.
					if (blnDate && (strValue != "")) {
						for (y = 0; y < document.forms[iForm].elements[x].value.length; y++) {
							if (document.forms[iForm].elements[x].value.length != 10) {
								blnCheckDate = false;
							}
							if (y == 4 || y == 7) {
								if (document.forms[iForm].elements[x].value.charAt(y) != "-") {
									blnCheckDate = false;
								}
							} else {
								if (document.forms[iForm].elements[x].value.charAt(y) < "0" || 
									document.forms[iForm].elements[x].value.charAt(y) > "9") {
									blnCheckDate = false;
								}
							}
							if (! blnCheckDate) {
								alert("Geben Sie bitte im Feld "+strRealName+" ein Datum im Format JJJJ-MM-TT ein !");
								document.forms[iForm].elements[x].focus();
								return false;
							}
							if (! blnDateFromPast) {
								if (document.forms[iForm].elements[x].value < paramToday && document.forms[iForm].elements[x].value != "0000-00-00") {
									alert("Bitte bei "+strRealName+" kein Datum aus der Vergangenheit eingeben.");
									document.forms[iForm].elements[x].focus();
									return false;
								}
							}
						}
					}			
					
					// Whole procedure for numeric field.
					if (blnNumeric && (strValue != "")) {
						for (y = 0; y < document.forms[iForm].elements[x].value.length; y++) {
							if ((document.forms[iForm].elements[x].value.charAt(y) < "0" ||
								document.forms[iForm].elements[x].value.charAt(y) > "9") && 
								(document.forms[iForm].elements[x].value.charAt(y) != ","))
								{
									blnCheckNumeric = false;
								}
							if (! blnCheckNumeric) {
								alert("Geben Sie bitte im Feld "+strRealName+" einen numerischen Wert ein !");
								document.forms[iForm].elements[x].focus();
								return false;
							}
						}
					}
					
					//Checking if the text in textarea is not too long.
					if (fieldType == "textarea") {
						//Checking if this textarea has limited characters number allowed.
						for (y = 0; y < fieldName.length; y++) {
							if (fieldName.charAt(y) >= 0 || fieldName.charAt(y) <= 9) {
								strMaxLength = strMaxLength + fieldName.charAt(y);
							} else if (y > 2) {
								strTextAreaName = strTextAreaName + fieldName.charAt(y);
							}
						}
						//Checking if the value entered in the textarea is not too long.
						if (strMaxLength != "" && strMaxLength > 99) {
							if (document.forms[iForm].elements[x].value.length > strMaxLength) {
								document.forms[iForm].elements[x].focus();
								alert("Der Text im Feld "+strTextAreaName+" kann maximal aus "+strMaxLength+" Zeichen bestehen.");
								return false;
							}
						}
					}
					
					// Checking if the email adresses and passwords are in booths fields the same.
					if (strRealName == "Bestätigung der E-Mail") {
						strEmail1 = document.forms[iForm].oexEmail.value;
						strEmail2 = document.forms[iForm].oexEmail2.value;
				  		if (strEmail1 != strEmail2) {
							alert("Die Werte im Feld \"E-Mail\" und \"E-Mail-Bestätigung\"\nstimmen nicht überein !!!");
							document.forms[iForm].oexEmail.focus();
							return false;
						}
					}
		
					if (strRealName == "Bestätigung des Passworts") {
						strEintrag1 = document.forms[iForm].oxxPasswort.value;
						strEintrag2 = document.forms[iForm].oxxPasswort2.value;
				  		if (strEintrag1 != strEintrag2) {
							alert("Die Werte im Feld \"Passwort\" und \"Passwort - Bestätigung\"\nstimmen nicht überein !!!");
							document.forms[iForm].oxxPasswort.focus();
							return false;
						}
						if (strEintrag1.length < 6) {
							alert("Das Passwort muss mindestens aus 6 Zeichen bestehen.");
							document.forms[iForm].oxxPasswort.focus();
							return false;
						}
					}
				}//end of variable name validation
			}//end of type validation
		}//end of loop 
		
		// If everything is ok then submit the form.
		if (paramNameSubmit) {
			if (window.navigator.appName == "Microsoft Internet Explorer" && paramSchicken != "nicht_schicken") {
				document.getElementById(paramNameSubmit).disabled = true;
			}
		}
		
		if (paramSchicken != "nicht_schicken") {
			document.forms[iForm].submit();
		}
		return true;
	}
	
////////////////////////////////////////////////////////////////////
//Prüft die Länge der Eingabe im Textarea.
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////

	function limitTextarea(paramFeld,paramLimit)
	{
		if (paramFeld.value.length > paramLimit) {
			alert("Sie können maximal "+(paramLimit+1)+" Zeichen eingeben !");
			paramFeld.focus();
			strValue = paramFeld.value;
			strNewValue = strValue.slice(0,paramLimit);
			paramFeld.value = strNewValue;
			return false;
		}
	}
	
////////////////////////////////////////////////////////////////////
//Setzt den Zeiger auf das n-te (mögliche) Element im m-ten Formular
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////

	function focusOn(n,m) {
		var blnGesetzt = false;
		while (!blnGesetzt && document.forms[m]) {
			if (document.forms[m].elements[n].type == "hidden" || document.forms[m].elements[n].value != "") {
				n++;
				if (n > document.forms[m].elements.length - 1) {
					return false;
				}
			} else {
				document.forms[m].elements[n].focus();
				blnGesetzt = true;
			}
		}
	} 
	
////////////////////////////////////////////////////////////////////
//Öffnet das Bestätigungsfenster, wenn bestätigt öffnet die URL
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////
	
	function warnung(paramText,paramURL) {
		blnAction = confirm(paramText);
		if (blnAction == true) {
			window.location.href = paramURL;
		}
	}	

////////////////////////////////////////////////////////////////////
//Öffnet das popup Fenster mit und platziert es in der Mitte des
//Bildschirms
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////

	function mypopup(strURL,intSzer,intWys,scroll,namewindow,paramEinstellungen) {
		if (paramEinstellungen == "") {
			strEinstellungen = ",status=no,resizable=no";
		} else {
			strEinstellungen = paramEinstellungen;
		}
//			strEinstellungen = strEinstellungen+",tool-bar=no,location=no,directories=no,menubar=yes,status=yes,copyhistory=yes";
		windowPopup = window.open(strURL,namewindow,"width="+intSzer+",height="+intWys+",scrollbars="+scroll+",left="+(screen.availWidth/2-0.5*intSzer)+",top="+(screen.availHeight/2-0.5*intWys)+strEinstellungen);
		if (windowPopup) {
			windowPopup.focus();
		} else {
			alert("Achtung!!! Sie haben in Ihrem Browser Popups deaktiviert.\nAktivieren Sie bitte Popups für deutsche-versicherungsboerse.de, um alle Inhalte zu sehen.");
		}
	}
	
////////////////////////////////////////////////////////////////////
//Verändert die Größe des Popup-Fensters und platziert es in der Mitte des
//Bildschirms
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////
	
	function resizeAndCenter(intBreite,intHoehe) {
		window.moveTo(screen.availWidth/2-0.5*(intBreite),screen.availHeight/2-0.5*(intHoehe));
		window.resizeTo(intBreite,intHoehe);
	}
	
////////////////////////////////////////////////////////////////////
//Öffnet ein Layer mit dem Hilfetext
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////

	function showHelp (paramLayerId,paramX,paramY) {
		document.getElementById(paramLayerId).style.left = paramX;
		document.getElementById(paramLayerId).style.top = paramY;
		document.getElementById(paramLayerId).style.visibility = 'visible';
	}
	
////////////////////////////////////////////////////////////////////
//Schliesst ein Layer mit dem Hilfetext
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////

	function hideHelp (paramLayerId) {
		document.getElementById(paramLayerId).style.visibility = 'hidden';
	}

////////////////////////////////////////////////////////////////////
//Deaktiviert alle ausgewählten Einträge in einer DropDownListe
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////
	function unselectDDList (paramListe) {
		for (x = 0; x < paramListe.length; x++)	{
			paramListe.options[x].selected = false;
		}
	}
	
	function checkTaste (Ereignis) {
		if (!Ereignis)
		Ereignis = window.event;
		if (Ereignis.keyCode == 13) {
			checkForm(0);
		}
	}	

////////////////////////////////////////////////////////////////////
//Diese Funktion aktiviert und / oder deaktiviert gleichzeitig 
//mehrere Checkboxes
//by Maciej Homziuk
////////////////////////////////////////////////////////////////////
	function markieren(paramAction,paramFeld, paramVon, paramBis, formId) {
	
		if (typeof paramVon == "undefined") {
			y = -1;
		} else {
			y = 0;
		}
		
		if (typeof(formId) == "undefined") formId = 0;

		for (x=0; x<document.forms[formId].elements.length; x++) {
			fieldType = document.forms[formId].elements[x].type;
			if (fieldType == "checkbox") {
				if (paramAction == "on") {
					if (document.forms[formId].elements[x].name.slice(0,8) == paramFeld) {
						if (y >= paramVon && y <= paramBis || y == -1) {
							document.forms[formId].elements[x].checked = true;
						}
					}
				} else if (paramAction == "off") {
					if (document.forms[formId].elements[x].name.slice(0,8) == paramFeld) {
						if (y >= paramVon && y <= paramBis || y == -1) {
							document.forms[formId].elements[x].checked = false;
						}
					}
				} else if (paramAction == "change") {
					if (document.forms[formId].elements[x].checked == true) {
						if (document.forms[formId].elements[x].name.slice(0,8) == paramFeld) {
							if (y >= paramVon && y <= paramBis || y == -1) {
								document.forms[formId].elements[x].checked = false;
							}
						}
					} else {
						if (document.forms[formId].elements[x].name.slice(0,8) == paramFeld) {
							if (y >= paramVon && y <= paramBis || y == -1) {
								document.forms[formId].elements[x].checked = true;
							}
						}
					}
				}
			}
			if (document.forms[formId].elements[x].name.slice(0,8) == paramFeld) {
				if (y != -1) {y++;}
			}
		}
	}
	/////////////////////////////////////////////////////////////////////////////////
	//Die beiden folgenden Funktionen ermitteln die absolute position eines Elements 
	////////////////////////////////////////////////////////////////////////////////
	
	//absolute Position left
	function getOffsetLeft(element){
		if(!element) return 0;
		return element.offsetLeft + getOffsetLeft(element.offsetParent);
	}
	
	//absolute Position top
	function getOffsetTop(element){
		if(!element) return 0;
		return element.offsetTop + getOffsetTop(element.offsetParent);
	}
	////////////////////////////////////////////////////////////////////
	//Die folgenden Funktionen werden von einem Formelement genutzt 
	////////////////////////////////////////////////////////////////////
	function DoAdd(id)
	{
		if (document.getElementById("availableList").selectedIndex > -1)
		{
			var strText = document.getElementById("availableList").options[document.getElementById("availableList").selectedIndex].text;
			var strId = document.getElementById("availableList").options[document.getElementById("availableList").selectedIndex].value;
			AddItem(document.getElementById("chosenList"), strText, strId);
			RemoveItem(document.getElementById("availableList"), document.getElementById("availableList").selectedIndex);
			sortSelect(document.getElementById("chosenList"));
			UpdateRealValue(id);
		}
	}
	
	function DoRemove(id)
	{
		if (document.getElementById("chosenList").selectedIndex > -1){
			var strText = document.getElementById("chosenList").options[document.getElementById("chosenList").selectedIndex].text;
			var strId = document.getElementById("chosenList").options[document.getElementById("chosenList").selectedIndex].value;
			AddItem(document.getElementById("availableList"), strText, strId);
			RemoveItem(document.getElementById("chosenList"), document.getElementById("chosenList").selectedIndex);
			//sortSelect(document.getElementById("availableList"));
			UpdateRealValue(id);
		}	
	}
	
	function AddItem(objListBox, strText, strId)
	{
		var newOpt;
		newOpt = document.createElement("OPTION");
		newOpt = new Option(strText,strId);
		newOpt.id = strId;
		objListBox.options[objListBox.length]=newOpt;
	}
	
	function RemoveItem(objListBox, strId)
	{
		if (strId > -1)
			objListBox.options[strId]=null;
	}
	
	function UpdateRealValue(id)
	{
		document.getElementById(id).value = '';
	
		var lbBox = document.getElementById("chosenList");
		document.getElementById(id).value = 'a|';
		for (var i = 0; i < lbBox.options.length; i++)
		{
			document.getElementById(id).value = document.getElementById(id).value + lbBox.options[i].value+ '|';
		}
		document.getElementById(id).value = document.getElementById(id).value + 'a';	
	}
	
	function compareText (option1, option2) {
		return option1.text < option2.text ? -1 :
		option1.text > option2.text ? 1 : 0;
	}
	
	function sortSelect (select, compareFunction) {
		if (!compareFunction)
		compareFunction = compareText;
		var options = new Array (select.options.length);
		for (var i = 0; i < options.length; i++)
		options[i] =
			new Option (
				select.options[i].text,
				select.options[i].value,
				select.options[i].defaultSelected,
				select.options[i].selected
			);
		options.sort(compareFunction);
		select.options.length = 0;
		for (var i = 0; i < options.length; i++)
		select.options[i] = options[i];
	}

	function requestAJAX(paramGetURL,paramParams,paramDivName,paramLoaderGrafik){
		
		if (typeof(paramLoaderGrafik) == "undefined") {
			paramLoaderGrafik = "little_circle.gif";
		}
		
		//erstellen des requests
		var req = null;
		
		try{
			req = new XMLHttpRequest();
		} catch (ms){
			try{
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (nonms){
				try{
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (failed){
					req = null;
				}
			}  
		}
		
		if (req == null) {
			alert("Error creating request object!");
		}
                  
		//anfrage erstellen (GET, url ist localhost, request ist asynchron
		if (req.overrideMimeType) {
			req.overrideMimeType("text/html; charset=ISO-8859-1");
		}
		req.open("POST", paramGetURL, true);
		
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-length", paramParams.length);
		req.setRequestHeader("Connection", "close");
		
		req.send(paramParams);
		
		document.getElementById(paramDivName).style.backgroundColor = "#D6D6D6";
		document.getElementById(paramDivName).innerHTML = "<table style=\"border-width: 1px; border-style: solid; border-color: #999999;\" height=100% width=100%><tr><td valign=center><center><img src=\"/includes/images/ajax_ai/"+paramLoaderGrafik+"\" alt=\"\" border=\"0\"></center></td></tr></table>";
	
		//Beim abschliessen des request wird diese Funktion ausgeführt
		req.onreadystatechange = function(){
			switch(req.readyState) {
				case 4:
				if(req.status!=200) {
					alert("Fehler:"+req.status); 
				} else {
					//schreibe die antwort in den div container mit der id content 
					document.getElementById(paramDivName).style.backgroundColor = "";
					document.getElementById(paramDivName).innerHTML = req.responseText;
				}
				break;
				
				default:
				return false;
				break;     
			}
		};
	}
