//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Funktionen des Projekts (ausser Menue)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Allgemeine Funktionen
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
// DOM Ausdruck setzen
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++

function ausdruckSetzen(idname)
{

  if (document.getElementById(idname))
  {
    return document.getElementById(idname);
  }
  else
  {
    //alert('Es gibt keinen Layer mit der id \'' + idname + '\'');
    return undefined;
  }

}


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Funktion zum Tauschen der StyleSheet-Angaben allgemein
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++


function tauscheStyleClasses(element, className)
{

  if (element && className)
  {
    return element.className = className;
  }

}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// onmouseover-Funktionen
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

var htmlroot = '/frontend/resource/';

function leitpfeil_einblenden(x) {
  document.images["leitpfeil"+x].src= htmlroot + "grafik/h1_lang_.gif";
}

function leitpfeil_ausblenden(x) {
  document.images["leitpfeil"+x].src= htmlroot + "grafik/h1_lang.gif";
}

function pfeil_einblenden(x) {
  document.images["pfeil"+x].src= htmlroot + "grafik/h1_.gif";
}

function pfeil_ausblenden(x) {
  document.images["pfeil"+x].src= htmlroot + "grafik/h1.gif";
}

function pfeil_bw_einblenden(x) {
  document.images["pfeil_bw_"+x].src= htmlroot + "grafik/h1_bw_.gif";
}

function pfeil_bw_ausblenden(x) {
  document.images["pfeil_bw_"+x].src= htmlroot + "grafik/h1_bw.gif";
}

function pfeil_einblenden_bw_(x) {
  document.images["pfeil_bw_"+x].src= htmlroot + "grafik/h1_bw_.gif";
}

function pfeil_ausblenden_bw_(x) {
  document.images["pfeil_bw_"+x].src= htmlroot + "grafik/h1_bw.gif";
}

function pfeil_termine_einblenden(x) {
  document.images["pfeil_termine_"+x].src= htmlroot + "grafik/h1_termine_.gif";
}

function pfeil_termine_ausblenden(x) {
  document.images["pfeil_termine_"+x].src= htmlroot + "grafik/h1_termine.gif";
}

function pfeil_eyecatcher_einblenden(x) {
  document.images["pfeil_eyecatcher_"+x].src= htmlroot + "grafik/h1_termine_.gif";
}

function pfeil_eyecatcher_ausblenden(x) {
  document.images["pfeil_eyecatcher_"+x].src= htmlroot + "grafik/h1_termine.gif";
}

function pfeil_downloads_einblenden(x) {
  document.images["pfeil_downloads_"+x].src= htmlroot + "grafik/h1_downloads_.gif";
}

function pfeil_downloads_ausblenden(x) {
  document.images["pfeil_downloads_"+x].src= htmlroot + "grafik/h1_downloads.gif";
}

function pfeil_web_links_einblenden(x) {
  document.images["pfeil_web_links_"+x].src= htmlroot + "grafik/h1_web_links_.gif";
}

function pfeil_web_links_ausblenden(x) {
  document.images["pfeil_web_links_"+x].src= htmlroot + "grafik/h1_web_links.gif";
}

function pfeil_schlagwoerter_einblenden(x) {
  document.images["pfeil_schlagwoerter_"+x].src= htmlroot + "grafik/h1_schlagwoerter_.gif";
}

function pfeil_schlagwoerter_ausblenden(x) {
  document.images["pfeil_schlagwoerter_"+x].src= htmlroot + "grafik/h1_schlagwoerter.gif";
}



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Fotogalerie öffnen
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function galerie_oeffnen(x) {
  window.open(x,"Fenster1","width=575,height=580,directories=0,location=0,toolbar=0,scrollbars=1,status=0,resizable=0,menubar=0");
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Funktion zum Checken der Formulare
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function checkDaten() {

  var formname = checkDaten.arguments[0];
  var sprache = checkDaten.arguments[1];

  var formhier=document[formname];
  var formlaenge = formhier.length;
  var argumentlaenge = checkDaten.arguments.length;


  // Check fuer die Inputfelder
  if (argumentlaenge >= 2) {

    for (var i=2; i<=argumentlaenge; i++) {

      var element = checkDaten.arguments[i];

      if (element <= formlaenge) {

        //alert(element);

        if (formhier[element].value == '' || formhier[element].value == ' ') {

          if (sprache == "englisch") {

            alert('Please fill out the field >>' + formhier[element].name + '<< !');

          } else {

            if (sprache == "franzoesisch") {

              alert('Veuillez remplir le champ >>' + formhier[element].name + '<< !');

            } else {

              // deutsch
              alert('Bitte füllen Sie das Feld >>' + formhier[element].name + '<< aus!');

            }

          }

          return false;

        }

      }

    }

  } else {

    alert('Programm-Meldung: Keine Argumente notiert.');

  }

  formhier.submit();

}
        
        
// Calendar       

function openCalendarPopup(buttonID, cgiID, datetype){
  if (!ElementPopup.getInstance() || (ElementPopup.getInstance() && ElementPopup.getInstance().getTargetElementID() != buttonID)){
    if (datetype == 'datetime'){
      var callback = new Function("date", "setCalendarDateTime('" + cgiID + "', date)");
    } else {
      var callback = new Function("date", "setCalendarDate('" + cgiID + "', date)");
    }
    dialogContext = {callback : callback, multiple : false};
    var currentDate = false;
    if (!currentDate){
      currentDate = new Date();
    } else {
      currentDate = Util.getDateFromDateTime(currentDate);
    }
    var calendar = Calendar.createInstance();
    calendar.setDate(currentDate);
    calendar.setBundesland(10);

    var popupProperties = ElementProps.createElementProps(buttonID, '');
    var popup = new ElementPopup.createInstance();
    popup.setID("PopupContainer");
    popup.setTargetElementID(buttonID);
    popup.setX((popupProperties.positionTop()) + 'px');
    popup.setY((popupProperties.positionLeft()+23) + 'px');
    popup.setHTML(calendar.getHTML());
    popup.open();
  } else {
    ElementPopup.getInstance().close();
  }  
}

function setCalendarDate(cgiID, date){
  if (document.getElementById(cgiID)){
    //document.getElementById(cgiID).value = formatDateToSystemDateFrontend(date);
    document.getElementById(cgiID).value = date;
  }
  if (document.getElementById(cgiID + '_')){
    document.getElementById(cgiID + '_').value = date; 
  }
  ElementPopup.getInstance().close();
}

function setCalendarDateTime(cgiID, date){
  if (document.getElementById(cgiID)){
    document.getElementById(cgiID).value = formatDateToSystemDateFrontend(date) + ' 00:00:00.0';
  }
  if (document.getElementById(cgiID + '_')){
    document.getElementById(cgiID + '_').value = date; 
  }
  ElementPopup.getInstance().close();
}

function submitEyecatcherCalenderDay(cgiID, date){
  if (document.getElementById('Form_' + cgiID)){
    if (document.getElementById('Document.Idx.Datum_' + cgiID)){
      document.getElementById('Document.Idx.Datum_' + cgiID).value = date;
    }
    document.getElementById('Form_' + cgiID).submit();
  }
}

function submitEyecatcherCalenderMonth(cgiID, dateFrom, dateTo){
  if (document.getElementById('Form_' + cgiID)){
    if (document.getElementById('Document.Idx.Datum-Von_' + cgiID)){
      document.getElementById('Document.Idx.Datum-Von_' + cgiID).value = dateFrom;
    }
    if (document.getElementById('Document.Idx.Datum-Bis_' + cgiID)){
      document.getElementById('Document.Idx.Datum-Bis_' + cgiID).value = dateTo;
    }
    document.getElementById('Form_' + cgiID).submit();
  }
}

function setDateInCMSField(cgiID, date){
  if (document.getElementById(cgiID)){
    if (date){
      document.getElementById(cgiID).value = formatDateToSystemDateFrontend(date); 
    } else {
      document.getElementById(cgiID).value = '';
    }
  }
}

function formatDateToSystemDateFrontend(date){
  var str = '';
  if (date){
    var tempdate = date.split(/\./);
    for (var i=parseFloat(tempdate.length -1); i>=0; i--){
      if (tempdate[i].toString().length == 1){
        str += '0' + tempdate[i];
      } else {
        str += tempdate[i];
      }
      if (i >= 1){
        str += '-';
      }
    }
  }
  return str;
}

function submitSearchForm(elem){
  for (var i=0; i<elem.elements.length; i++){
    if (! elem.elements[i].value){
      var id = elem.elements[i].name.replace(/_$/,'');
      if (document.getElementById(id)){
        document.getElementById(id).value = '';
      }
    }
    if (Util.formatDate(elem.elements[i].value)){
      elem.elements[i].value = Util.formatDate(elem.elements[i].value);
    }
  }
  return true;
}

