// JavaScript-Teil allgemein-->

onError="null"

var boolKeinFehler = true

var EditFenster=null
var cTrenn_1 = "%"
var cTrenn_2 = "~"
var cTrenn_3 = "}"
var cFeldTrenn = "{"
var cJavaScriptOK = "j"
var cKeinElement = "Bitte auswählen"

// Testfunktion zum Feststellen der JScriptfähigkeit
function JavaScriptTest()
{
 document.form01.frmJSTest.value=cJavaScriptOK;
}

function JavaScriptUrl()
{
 var i, j
 var strJS="js="
 var strTmp1
 var strTmp2
 for (i=0; i<document.links.length; i++)
 {
  strTmp1 = "" + document.links[i].href + ""
  j=strTmp1.indexOf(strJS, 0)
  if (j!=-1)
  {
   if(strTmp1.length > (j + strJS.length))
   {
	if (strTmp1.charAt(j + strJS.length)=="j")
	{
	 strTmp2 = strTmp1
	}
	else
	{
	 strTmp2 = strTmp1.substr(0, j + strJS.length) + "j" + strTmp1.substr(j + strJS.length)
	}
   }
   else
   {
    strTmp2 = strTmp1 + "j"
   }
  }
  else
  {
   strTmp2 = strTmp1 + "&js=j"
  }
  document.links[i].href = strTmp2
 }

}


function MacheUrl(strNeueAdresse, strAlteAdresse)
{
var strUrl = strNeueAdresse + "?funktion=" + document.form01.frmAufgabe.value
strUrl = strUrl + "&bereich=" + document.form01.frmBereich.value
strUrl = strUrl + "&name=" + document.form01.frmLoginname.value
strUrl = strUrl + "&session=" + document.form01.frmSessionID.value
strUrl = strUrl + "&starturl=" + strAlteAdresse
strUrl = strUrl + "&js=" + document.form01.frmJSTest.value
location.href=strUrl
}

//Prüfen, ob kein Editor geöffnet wurde, wenn ja - schliessen

function hauptfenster_schliessen()
{
 editfenster_nicht_vorhanden(true)
}

//Prüfen, ob kein Editierfenster geöffnet wurde, wenn ja - versuchen zu schliessen, 
//bei Parameter immer_schliessen - unbedingt schliessen

function editfenster_nicht_vorhanden(immer_schliessen)
{
 var fenster_geschlossen=true
 if (EditFenster != null)
 {
  if (!EditFenster.closed)
  {
   if (immer_schliessen)
   {
    EditFenster.close()
   }
   else
   {
    fenster_geschlossen = EditFenster.schliessen()
   }
  }
 }
 return fenster_geschlossen
}

//Erstellen eines Popup-Fensters zum Editieren des Inhalts von Textarea
function textarea_edit(textarea)
{
 if (!editfenster_nicht_vorhanden(false))
 {
  return
 }
// Editorfenster öffnen
 EditFenster = window.open("/tools/textarea_editor.htm?Elementname=" + textarea, "Texteditor", "width=750, height=550, scrollbars=no, toolbar=no, menubar=no, location=no, resizeable=yes, directories=no")
}

// Ausgabe einer normalen Meldung
function Meldung(Text)
{
 alert(Text);
}

// Ausgabe der Fehlermeldung
function FehlerAusgabe(Fehlernummer, Fehler, Feld)
{
// alert(Fehler + " (ERR " + Fehlernummer + ")");
 alert(Fehler);
 Feld.focus();

}

// Ausgabe der Meldung mit window.confirm abhängig von Zwischenfeld im Formular
function PruefMussfeld(Feld, Feldname)
{
 if  (Feld.value == "")
 {
  alert(Feldname + " zwingend");
  Feld.focus();
  return false;
 }
}
     
// Ausgabe der Meldung mit window.confirm abhängig von Zwischenfeld im Formular
// Speichern der Reaktion im gleichem Zwischenfeld
function ConfirmMldg(text, taste)
{
 var truthBeTold = window.confirm(text);
 if (truthBeTold)
 {
  document.form01.frmClientAntwort.value = "j"
  taste.click()
 }
 else
 {
  document.form01.frmClientFrage.value = ""
  document.form01.frmClientAntwort.value = ""
 }
}

// Ausgabe der Meldung mit window.confirm abhängig von Zwischenfeld im Formular
// Speichern der Reaktion im gleichem Zwischenfeld
function ConfirmMldgVirtuell(text, taste)
{
 var truthBeTold = window.confirm(text);
 if (truthBeTold)
 {
  document.form01.frmClientAntwort.value = "j"
  document.form01.frmTasteVirtual.value = taste
  document.form01.submit()
 }
 else
 {
  document.form01.frmClientFrage.value = ""
  document.form01.frmClientAntwort.value = ""
 }
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVersteckt(antwort, taste)
{
 document.form01.frmClientAntwort.value = antwort
 taste.click()
}

function SendeTasteVerstecktVirtuell(antwort, taste)
{
 document.form01.frmClientAntwort.value = antwort
 document.form01.frmTasteVirtual.value = taste
 document.form01.submit()
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktMitInhalt(antwort, wert, taste)
{
 document.form01.frmClientAntwort.value = antwort
 document.form01.frmTmpInhalt.value = wert
 taste.click()
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktVirtuellMitInhalt(antwort, wert, taste)
{
 document.form01.frmClientAntwort.value = antwort
 document.form01.frmTmpInhalt.value = wert
 document.form01.frmTasteVirtual.value = taste
 document.form01.submit()
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktVirtuellMitInhaltToFrame(framenr, antwort, wert, taste)
{
 parent.frames[framenr].document.form01.frmClientAntwort.value = antwort
 parent.frames[framenr].document.form01.frmTmpInhalt.value = wert
 parent.frames[framenr].document.form01.frmTasteVirtual.value = taste
 parent.frames[framenr].document.form01.submit()
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktDreiElemente(antwort, element1, element2, element3, taste)
{
 var eintrag
 var boolElementNichtLeer=false
 document.form01.frmTmpInhalt.value=""

 eintrag = element1.options[element1.options.selectedIndex].value
 if (eintrag!="")
 {
  document.form01.frmTmpInhalt.value = eintrag
  boolElementNichtLeer=true
 }

 document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + cTrenn_1
 eintrag = element2.options[element2.options.selectedIndex].value
 if (eintrag!="")
 {
  document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + eintrag
  boolElementNichtLeer=true
 }

 document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + cTrenn_1
 eintrag = element3.options[element3.options.selectedIndex].value
 if (eintrag!="")
 {
  document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + eintrag
  boolElementNichtLeer=true
 }

 if (boolElementNichtLeer)
 {
  document.form01.frmClientAntwort.value = antwort
  taste.click()
 }
 else
 {
  document.form01.frmTmpInhalt.value=""
 }
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktVirtuellDreiElemente(antwort, element1, element2, element3, taste)
{
 var eintrag
 var boolElementNichtLeer=false
 document.form01.frmTmpInhalt.value=""

 eintrag = element1.options[element1.options.selectedIndex].value
 if (eintrag!="")
 {
  document.form01.frmTmpInhalt.value = eintrag
  boolElementNichtLeer=true
 }

 document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + cTrenn_1
 eintrag = element2.options[element2.options.selectedIndex].value
 if (eintrag!="")
 {
  document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + eintrag
  boolElementNichtLeer=true
 }

 document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + cTrenn_1
 eintrag = element3.options[element3.options.selectedIndex].value
 if (eintrag!="")
 {
  document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + eintrag
  boolElementNichtLeer=true
 }

 if (boolElementNichtLeer)
 {
  document.form01.frmClientAntwort.value = antwort
  document.form01.frmTasteVirtual.value = taste
  document.form01.submit()

 }
 else
 {
  document.form01.frmTmpInhalt.value=""
 }
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktVirtuellDreiElementeToFrame(framenr, antwort, element1, element2, element3, taste)
{
 var eintrag
 var boolElementNichtLeer=true
 //document.form01.frmTmpInhalt.value=""
 parent.frames[framenr].document.form01.frmTmpInhalt.value=""
 eintrag = element1.options[element1.options.selectedIndex].value
 if (eintrag!="" && eintrag!=cKeinElement && boolElementNichtLeer)
 {
//  document.form01.frmTmpInhalt.value = eintrag
  parent.frames[framenr].document.form01.frmTmpInhalt.value = eintrag
  boolElementNichtLeer=true
 }
 else
 {
  boolElementNichtLeer=false
 }

// parent.frames[framenr].document.form01.frmTmpInhalt.value = parent.frames[framenr].document.form01.frmTmpInhalt.value + cTrenn_1
 parent.frames[framenr].document.form01.frmTmpInhalt.value = parent.frames[framenr].document.form01.frmTmpInhalt.value + cTrenn_1
 eintrag = element2.options[element2.options.selectedIndex].value
 if (eintrag!="" && eintrag!=cKeinElement && boolElementNichtLeer)
 {
  parent.frames[framenr].document.form01.frmTmpInhalt.value = parent.frames[framenr].document.form01.frmTmpInhalt.value + eintrag
  boolElementNichtLeer=true
 }
 else
 {
  boolElementNichtLeer=false
 }

 parent.frames[framenr].document.form01.frmTmpInhalt.value = parent.frames[framenr].document.form01.frmTmpInhalt.value + cTrenn_1
 eintrag = element3.options[element3.options.selectedIndex].value
 if (eintrag!="" && eintrag!=cKeinElement && boolElementNichtLeer)
 {
  parent.frames[framenr].document.form01.frmTmpInhalt.value = parent.frames[framenr].document.form01.frmTmpInhalt.value + eintrag
  boolElementNichtLeer=true
//  element3.options.selectedIndex=-1
 }
 else
 {
  boolElementNichtLeer=false
 }

 if (boolElementNichtLeer)
 {
  parent.frames[framenr].document.form01.frmClientAntwort.value = antwort
  parent.frames[framenr].document.form01.frmTasteVirtual.value = taste
  parent.frames[framenr].document.form01.submit()

 }
 else
 {
  parent.frames[framenr].document.form01.frmTmpInhalt.value=""
 }
 parent.frames[framenr].document.form01.submit()
}

// Prüfen, ob Formulars mit der versteckten Taste zu Versenden ist
function PruefeTasteVerstecktVirtuellDreiElementeToFrame(framenr, antwort, element1, element2, element3, taste)
{
 var eintrag
 if (element3.options.selectedIndex==-1)
 {
  return
 }
 eintrag = element3.options[element3.options.selectedIndex].value
 if (eintrag!="" && eintrag!=cKeinElement)
  {
   SendeTasteVerstecktVirtuellDreiElementeToFrame(framenr, antwort, element1, element2, element3, taste)
  }
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktMitElementInhalt(antwort, element, wert, taste)
{
 var eintrag
 eintrag = element.options[element.options.selectedIndex].value
 if (eintrag!="")
  {
   document.form01.frmClientAntwort.value = antwort
   document.form01.frmTmpInhalt.value = wert
   document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + cTrenn_1 + eintrag
   taste.click()
  }
}

// Versenden des Formulars mit der versteckten Taste
function SendeTasteVerstecktVirtuellMitElementInhalt(antwort, element, wert, taste)
{
 var eintrag
 eintrag = element.options[element.options.selectedIndex].value
 if (eintrag!="")
  {
   document.form01.frmClientAntwort.value = antwort
   document.form01.frmTmpInhalt.value = wert
   document.form01.frmTmpInhalt.value = document.form01.frmTmpInhalt.value + cTrenn_1 + eintrag
   document.form01.frmTasteVirtual.value = taste
   document.form01.submit()
  }
}

// Prüfen, ob Formulars mit der versteckten Taste zu Versenden ist
function PruefeTasteVerstecktVirtuellMitElementInhalt(antwort, element, wert, taste)
{
 var eintrag
 var cKeinElement = "Bitte auswählen"
 eintrag = element.options[element.options.selectedIndex].value
 if (eintrag!="" && eintrag!=cKeinElement)
  {
   SendeTasteVerstecktVirtuellMitElementInhalt(antwort, element, wert, taste)
  }
}

// Ausgabe der Meldung mit window.confirm abhängig von Zwischenfeld im Formular
//Positionieren vom Focus auf ein Feld
function FeldFocus(Feldnummer)
{
 if (Feldnummer>=0)
 {
  document.form01.elements[Feldnummer].focus();
 }
}

// Ausgabe der Meldung mit window.confirm abhängig von Zwischenfeld im Formular
//Positionieren vom Focus auf ein Feld
function FeldFocusName(Elementname)
{
 document.form01.elements(Elementname).focus();
}

// Zeigen einer neuen Seite
function SeiteRedirect(seite)
{
// window.location.href=seite
 parent.frames.location.href=seite
}

// Eintrag aus einer Auswahlliste in ein Feld plazieren
function auswahl_in_textarea(liste, feldsichtbar, feldversteckt, feldnext, boolZusatzFeld)
{
 var i, j
 var inhalt = ""
 var strTmp1 = ""
 var strTmp2 = ""
 var boolEintragEingefuegt = false
 var boolStringZuEnde = false

 if (liste.value==cKeinElement)
 {
   return
 }
 
 j=0
 inhalt = feldversteckt.value
 if (inhalt.length > 0)
 {
  while (!boolEintragEingefuegt)
  {
   if (!boolZusatzFeld)
   {
    i=inhalt.indexOf(cTrenn_2, 0)
   }
   else
   {
    i=inhalt.indexOf(cTrenn_3, 0)
   }
   if (i!= -1)
   {
    if (liste.value < inhalt.substr(0, i + 1))
	{
	 strTmp1=strTmp1 + liste.value + inhalt.substr(0)
	 boolEintragEingefuegt = true
	}
	else
	{
     if (liste.value == inhalt.substr(0, i + 1))
 	 {
	  inhalt = inhalt.substr(i + 1)
	  strTmp1=strTmp1 + inhalt.substr(0)
	  boolEintragEingefuegt = true
	 }
	 else
	 {
	  strTmp1=strTmp1 + inhalt.substr(0, i + 1)
	  inhalt = inhalt.substr(i + 1)
	 }
	}
   }
   else
   {
    strTmp1=strTmp1 + liste.value
    boolEintragEingefuegt = true
   }
  }
 }
 else
 {
  strTmp1=strTmp1 + liste.value
 }
 feldversteckt.value = strTmp1

 j=0
 boolStringZuEnde = false
 strTmp2 = ""
 if (strTmp1.length > 0)
 {
  while (!boolStringZuEnde)
  {
   i=strTmp1.indexOf(cTrenn_2, 0)
   if (i!= -1)
   {
	if(j>0)
	{
     strTmp2 = strTmp2 + ","
	}
    strTmp2 = strTmp2 + strTmp1.substr(0, i)
    strTmp1 = strTmp1.substr(i + 1)
    if (!boolZusatzFeld)
    {
     i=strTmp1.indexOf(cTrenn_2, 0)
    }
    else
    {
     i=strTmp1.indexOf(cTrenn_3, 0)
    }
    strTmp1 = strTmp1.substr(i + 1)
	j++
   }
   else
   {
    boolStringZuEnde = true
   }
  }
 }

 feldsichtbar.value = strTmp2
 form01(feldnext).focus()

}

// Eintrag aus einer Auswahlliste in ein Feld plazieren Version 2
function Zeige_Select(liste, feldsichtbar, feldversteckt, feldnext)
{
 var i, j
 var inhalt = ""
 var strTmp1 = ""
 var strTmp2 = ""
 var boolStringZuEnde = false

 var strVergleich = ""
 var strValueListe = liste.options[liste.options.selectedIndex].value
 var strTextListe = liste.options[liste.options.selectedIndex].text
 
 strNeuerWert = cTrenn_1 + strValueListe + cTrenn_1
 strNeuerText = cTrenn_2 + strTextListe + cTrenn_2
 
 if (strValueListe==cKeinElement)
 {
   return
 }
 
 j=0
 inhalt = feldversteckt.value
 if (inhalt.length > 0)
 {
  strVergleich = strNeuerWert + strNeuerText
  i=inhalt.indexOf(strVergleich, 0)
  if (i!= -1)
  {
   strTmp1 = inhalt.substr(0, i)
   if ((i + strVergleich.length) < inhalt.length)
   {
    strTmp1 = strTmp1 + inhalt.substr(i + strVergleich.length)
   }
   strNeuerWert = ""
   strNeuerText = ""
  }
  else
  {
   strTmp1 = inhalt
  }
 }
 strTmp1=strTmp1 + strNeuerWert + strNeuerText
 feldversteckt.value = strTmp1
 Zeige_Select_Aktuell(liste, feldsichtbar, feldversteckt)
 feldnext.focus()
}


function Zeige_Select_Aktuell(liste, feldsichtbar, feldversteckt)
{
 var i, j
 var inhalt = ""
 var strTmp1 = ""
 var strTmp2 = ""
 var boolStringZuEnde = false
 var strVergleich = ""

 strTmp1 = feldversteckt.value
 j=0
 boolStringZuEnde = false
 strTmp2 = ""
 if (strTmp1.length > 0)
 {
  while (!boolStringZuEnde)
  {
   strVergleich = cTrenn_2
   i=strTmp1.indexOf(strVergleich, 0)
   if (i!= -1)
   {
    if ((i + strVergleich.length) < strTmp1.length)
    {
     strTmp1 = strTmp1.substr(i + strVergleich.length)
     i=strTmp1.indexOf(strVergleich, 0)
     if (i!= -1)
     {
  	  if(j++>0)
	  {
       strTmp2 = strTmp2 + ", "
	  }
      strTmp2 = strTmp2 + strTmp1.substr(0, i)
      if ((i + strVergleich.length) < strTmp1.length)
      {
       strTmp1 = strTmp1.substr(i + strVergleich.length)
      }
      else
      {
       boolStringZuEnde=true
      }
     }
     else
     {
      boolStringZuEnde=true
     }
    }
    else
    {
     boolStringZuEnde=true
    }
   }
   else
   {
    boolStringZuEnde=true
   }
  }
 }
 feldsichtbar.value = strTmp2
}


function plausi_pflicht(feld, feldname)
{
 if (!boolKeinFehler)
 {
  return false
 }
 var inhalt = "" + feld.value + ""
 if (!(inhalt.length>0))
 {
  boolKeinFehler = false
  alert (feldname + "!")
  feld.focus()
 }
 return boolKeinFehler
}

function plausi_numerisch(feld, feldname)
{
 var i
 if (!boolKeinFehler)
 {
  return false
 }
 var inhalt = "" + feld.value + ""
 if (inhalt.length>0)
 {
  for (i=0; i<inhalt.length; i++)
  {
   if (!(inhalt.charAt(i)>="0" && inhalt.charAt(i)<="9"))
   {
    boolKeinFehler = false
    alert ("Inhalt von " + feldname + " nicht numerisch - bitte korrigieren")
    feld.focus()
    return boolKeinFehler
   }
  }
 }
 return boolKeinFehler
}

function plausi_telefon(feld, feldname)
{
 var i
 if (!boolKeinFehler)
 {
  return false
 }
 var inhalt = "" + feld.value + ""
 if (inhalt.length>0)
 {
  for (i=0; i<inhalt.length; i++)
  {
   if (!(inhalt.charAt(i)>="0" && inhalt.charAt(i)<="9"))
   {
    if (inhalt.charAt(i)!=" " && inhalt.charAt(i)!="-" && inhalt.charAt(i)!="/" && inhalt.charAt(i)!="#" && inhalt.charAt(i)!="(" && inhalt.charAt(i)!=")" && inhalt.charAt(i)!="+")
	{
     boolKeinFehler = false
     alert ("Falsche Eingabe von " + feldname + " - erlaubt sind nur Ziffern und: + - # / ( )")
     feld.focus()
     return boolKeinFehler
	}
   }
  }
 }
 return boolKeinFehler
}

function plausi_email(feld, feldname)
{
 var i,j 
 var strTmp1=""
 var strTmp2=""
 if (!boolKeinFehler)
 {
  return false
 }
 var inhalt = "" + feld.value + ""
 if (inhalt.length>0)
 {
  i=inhalt.indexOf("@", 0)
  if (i>0)
  {
   strTmp1=inhalt.substr(0, i)
   if (inhalt.length>i)
   {
    strTmp2=inhalt.substr(i + 1)
   }
   if (strTmp1.length>0 && strTmp2.length>0)
   {
    i=strTmp1.indexOf("@", 0)
    j=strTmp2.indexOf("@", 0)
    if (i==-1 && j==-1)
    {
     i=strTmp2.indexOf(".", 0)
     if (i==-1)
     {
      boolKeinFehler = false
	 }
	}
    else
    {
     boolKeinFehler = false
    }
   }
   else
   {
    boolKeinFehler = false
   }
  }
  else
  {
   boolKeinFehler = false
  }
 }
 if (!boolKeinFehler)
 {
  alert ("Falsche Eingabe von " + feldname + " - bitte korrigieren")
  feld.focus()
 }
 return boolKeinFehler
}

function plausi_antwort(feld, feldname)
{
 var i,j 
 var strTmp1=""
 var strTmp2=""
 if (!boolKeinFehler)
 {
  return false
 }
 var inhalt = feld.value
 if (inhalt > 5)
 {
   {
    alert("Inhalt ist zu groß");
   	boolKeinFehler = false
  }
 }
 else
 {
 if (inhalt < 5)
 {
   {
   alert("Inhalt ist zu klein");
   boolKeinFehler = false
  }
 }
 if (!boolKeinFehler)
 {
  alert ("Falsche Eingabe von " + feldname + " - bitte korrigieren")
  feld.focus()
 }
 return boolKeinFehler
}
}

