/**
 * Pager für Globale Suche
 *
 * @author maichele
 */
function globalSearchPager(pager_type, page) {

  new Ajax.Updater(pager_type + '_results_list', '/system/ajaxGlobalSearchPager/' + pager_type + '/' + page, {asynchronous:false, evalScripts:true, parameters:Form.serialize('global_search_hidden_form') } );
}

/**
 * Topbox Anzeigetyp ändern
 *
 * @author maichele
 */
function switchTopBox(type) {

  switch (type) {

    case 'Contacts':

      $('tab_contacts').className   = 'tab_aktiv';
      $('tab_members').className    = '';
      $('tab_activities').className = '';
      $('tab_locations').className  = '';

      $('a_contacts').className   = 'tab_aktiv_white';
      $('a_members').className    = '';
      $('a_activities').className = '';
      $('a_locations').className  = '';

      break;
    case 'Members':

      $('tab_contacts').className   = '';
      $('tab_members').className    = 'tab_aktiv';
      $('tab_activities').className = '';
      $('tab_locations').className  = '';

      $('a_contacts').className   = '';
      $('a_members').className    = 'tab_aktiv_white';
      $('a_activities').className = '';
      $('a_locations').className  = '';

      break;
    case 'Activities':

      $('tab_contacts').className   = '';
      $('tab_members').className    = '';
      $('tab_activities').className = 'tab_aktiv';
      $('tab_locations').className  = '';

      $('a_contacts').className   = '';
      $('a_members').className    = '';
      $('a_activities').className = 'tab_aktiv_white';
      $('a_locations').className  = '';

      break;
    case 'Locations':

      $('tab_contacts').className   = '';
      $('tab_members').className    = '';
      $('tab_activities').className = '';
      $('tab_locations').className  = 'tab_aktiv';

      $('a_contacts').className   = '';
      $('a_members').className    = '';
      $('a_activities').className = '';
      $('a_locations').className  = 'tab_aktiv_white';

      break;
  }

  new Ajax.Updater('top_box_target', '/system/ajaxSwitchTopBox/' + type, {asynchronous:false, evalScripts:true } );
}


function switchTopBoxStartseite(type, page) {
  switch (type) {

    case 'Contacts':

      $('tab_contacts').className   = 'tab_aktiv';
      $('tab_members').className    = '';
      $('tab_activities').className = '';
      $('tab_locations').className  = '';

      $('a_contacts').className   = 'tab_aktiv_white';
      $('a_members').className    = '';
      $('a_activities').className = '';
      $('a_locations').className  = '';

      break;
    case 'Members':

      $('tab_contacts').className   = '';
      $('tab_members').className    = 'tab_aktiv';
      $('tab_activities').className = '';
      $('tab_locations').className  = '';

      $('a_contacts').className   = '';
      $('a_members').className    = 'tab_aktiv_white';
      $('a_activities').className = '';
      $('a_locations').className  = '';

      break;
    case 'Activities':

      $('tab_contacts').className   = '';
      $('tab_members').className    = '';
      $('tab_activities').className = 'tab_aktiv';
      $('tab_locations').className  = '';

      $('a_contacts').className   = '';
      $('a_members').className    = '';
      $('a_activities').className = 'tab_aktiv_white';
      $('a_locations').className  = '';

      break;
    case 'Locations':

      $('tab_contacts').className   = '';
      $('tab_members').className    = '';
      $('tab_activities').className = '';
      $('tab_locations').className  = 'tab_aktiv';

      $('a_contacts').className   = '';
      $('a_members').className    = '';
      $('a_activities').className = '';
      $('a_locations').className  = 'tab_aktiv_white';

      break;
  }

  new Ajax.Updater('top_box_target', '/system/ajaxSwitchTopBox/' + type + '/' + page, {asynchronous:false, evalScripts:true } );
}

/**
 * Koordinaten für Anzeige in Topbox ändern und Box aktualisieren
 *
 * @author maichele
 */
function switchTopBoxLocation(tab_id, travel_id) {

  elements = document.getElementsByName('topbox_headlines');

  for(i = 0; i < elements.length; i++) {

    elements[i].className = 'bigbox_headline_towns';

    element_id = 'topbox_headline' + tab_id;

    if (elements[i].id == element_id) {

      elements[i].className = 'bigbox_headline_towns_aktiv';
    }
  }

  new Ajax.Updater('top_box_target', '/system/ajaxSetTopBoxLocation/' + travel_id, {asynchronous:false, evalScripts:true } );
}

/**
 * Globale Suchergebnisse umschalten
 *
 * @author maichele
 */
function switchGlobalSearchResults(result_type) {

  switch(result_type) {

    case 'users':

      $('user_results').style.display = 'block';
      $('activities_results').style.display = 'none';
      $('cityguide_results').style.display = 'none';

      $('tab_users_results').className = 'tab_aktiv';
      $('tab_activities_results').className = '';
      $('tab_cityguide_results').className = '';

      $('a_users_results').className = 'tab_aktiv_white';
      $('a_activities_results').className = '';
      $('a_cityguide_results').className = '';

      break;
    case 'activities':

      $('user_results').style.display = 'none';
      $('activities_results').style.display = 'block';
      $('cityguide_results').style.display = 'none';

      $('tab_users_results').className = '';
      $('tab_activities_results').className = 'tab_aktiv';
      $('tab_cityguide_results').className = '';

      $('a_users_results').className = '';
      $('a_activities_results').className = 'tab_aktiv_white';
      $('a_cityguide_results').className = '';

      break;
    case 'cityguide':

      $('user_results').style.display = 'none';
      $('activities_results').style.display = 'none';
      $('cityguide_results').style.display = 'block';

      $('tab_users_results').className = '';
      $('tab_activities_results').className = '';
      $('tab_cityguide_results').className = 'tab_aktiv';

       $('a_users_results').className = '';
      $('a_activities_results').className = '';
      $('a_cityguide_results').className = 'tab_aktiv_white';

      break;
  }
}

/**
 * Aktivitäten in der Sidebar blättern
 *
 * @author maichele
 */
function sidebarActivitiesList(direction) {

  new Ajax.Updater('sidebar_activities', '/system/ajaxSidebarActivitiesList/' + direction, {asynchronous:false, evalScripts:true, parameters:Form.serialize('sidebar_activities_form')} );
}

/**
 * Aktivitäten in der Sidebar blättern
 *
 * @author maichele
 */
function sidebarActivitiesCalendar(direction) {

  new Ajax.Updater('sidebar_activities', '/system/ajaxSidebarActivitiesCalendar/' + direction, {asynchronous:false, evalScripts:true, parameters:Form.serialize('sidebar_activities_form')} );
}

/**
 * Sidbar Aktivitäten View umschalten
 *
 * @author maichele
 */
function switchSideBarActivities(mode) {

  direction = 'none';

  if (mode == 'list') {

    $('tab_sidbar_activities_list').className     = 'right_box_tab_aktiv';
    $('tab_sidbar_activities_calendar').className = '';

    new Ajax.Updater('sidebar_activities', '/system/ajaxSidebarActivitiesList/' + direction, {asynchronous:false, evalScripts:true, parameters:Form.serialize('sidebar_activities_form')} );
  } else {

    $('tab_sidbar_activities_list').className     = '';
    $('tab_sidbar_activities_calendar').className = 'right_box_tab_aktiv';

    new Ajax.Updater('sidebar_activities', '/system/ajaxSidebarActivitiesCalendar/' + direction, {asynchronous:false, evalScripts:true, parameters:Form.serialize('sidebar_activities_form')} );
  }
}

/**
 * Netzwerk erweitern
 *
 * @author maichele
 * @author jbleicher
 * @param  string error_msg
 */
function ajaxSendInvitationEmail(receiver_default, sender_default, error_msg) {

  if(receiver_default == null) {

    receiver_default = 'Name des Empfängers';
  }

  if(sender_default == null) {

    sender_default = 'Ihr Name';
  }

  if(error_msg == null) {

    error_msg = 'Bitte füllen Sie das Formular komplett aus';
  }


  if ($('empfehlen_receiver').value != receiver_default && $('empfehlen_receiver').value !== '' && $('empfehlen_sender').value != sender_default && $('empfehlen_sender').value !== '' && !checkValid($('empfehlen_email').value, 'email')) {

    new Ajax.Updater('netzwerk_erweitern_target', '/system/sendInvitationEmail', {asynchronous:false, evalScripts:true, parameters:Form.serialize('netzwerk_erweitern_form')} );
  } else {

    $('netzwerk_erweitern_target').innerHTML = '<span style="color:#FF0000;">'+error_msg+'</span>';
  }
}


/**
 * Bezieht den Text des Labels zu einem Errorfeld
 *
 * @author sweber
 */
function getErrorFieldPrefix(error_field_id) {

  var label_id = error_field_id.replace(/error_/, "l");
  var label_id = label_id.replace(/Result/, "");
  var label    = $(label_id);

  if(label) {

    var text = label.innerHTML;

    /*
     * Sterne rauswerfen
     */
    if(text.indexOf('*') > 0) {

      text = text.substring(0, text.indexOf('*'));
    }
    return text;
  }
  return '';
}

/**
 * befüllt ein Form valiedierungsfeld mit einer entsprechenden Meldung und icon
 *
 * @author sweber
 */
function fillFormValidateOutputfield(field, valid, message) {

  if(!valid) {

    field.style.display = 'none';
    field.innerHTML     = getErrorFieldPrefix(field.id)+' '+message;
    field.className     = 'error';
    field.style.display = 'block';
  } else {

    $('validation_error_ul').removeChild(field);
  }
}

/**
 * Bezieht das DOM-Objekt, in dem eine Formfeld Fehler / Erfolgsmeldung erscheinen soll
 *
 * @author sweber
 */
function getFormValidateOutputField(element_id) {

  var validation_element = $('validation_error');
  validation_error_holder = validation_element.getElementsByTagName('UL');

  /*
   * Ist eine UL vorhanden? Iwr können aus XHTML-Gründen keine leeren ULs stehen haben.
   * Deswegen leeren wir immer das komplette Div und erstellen die ul mit ihren Inhalten im Zweifel neu
   */
  if(!validation_error_holder[0]) {

    var ul_error_holder = document.createElement('ul');
    ul_error_holder.id  = 'validation_error_ul';
    ul_error_holder.setAttribute('id', 'validation_error_ul');

    validation_element.appendChild(ul_error_holder);
  }

  var ul_element  = $('validation_error_ul');
  var ul_elements = ul_element.getElementsByTagName('LI');

  if(ul_elements.length) {

    var new_error_info_element = '';

    for(var i = 0; i < ul_elements.length; i++) {

      if(ul_elements[i].id == 'error_'+element_id) {

        return ul_elements[i];
      }
    }

    /*
     * Kein passender Eintrag in der Liste, also einen neuen erstellen
     */
    new_error_info_element     = document.createElement('li');
    new_error_info_element.id  = 'error_'+element_id;
    new_error_info_element.setAttribute('id', 'error_'+element_id);

    ul_element.appendChild(new_error_info_element);

    return $('error_'+element_id);
  } else {

    /*
     * Kein Eintrag in der Liste, also einen neuen erstellen
     */
    new_error_info_element    = document.createElement('li');
    new_error_info_element.id = 'error_'+element_id;
    new_error_info_element.setAttribute('id', 'error_'+element_id);

    ul_element.appendChild(new_error_info_element);

    return $('error_'+element_id);
  }

  return false;
}

/**
 * Validierung von Formularen in Modalboxen
 *
 * @author maichele
 */
function doValidateFormModalbox(form_id) {

  var validate = document.getElementById('validate_'+form_id).value;
  validate     = validate.split(',');

  var missing  = false;

  for (var count = 0; count < validate.length; count++) {

    var active    = (count % 2 === 0) ? '_active' : '';
    var field     = validate[count].split('|');
    var field_id  = field[0];
    var type      = field[1];
    var mandatory = field[2];
   
    var element      = document.getElementById(field_id);
     
            var value = (element.type == 'selectOne') ? element.options[element.options.selectedIndex].value : element.value;
       
            /*
             * Prüfen, ob das Feld Mandatory ist
             */
            if(mandatory == 'true') {

                if(value !== '') {

                  if(checkValid(value, type)) {

                    /*
                     * Feld markieren
                     */
                    missing = true;
                    element.style.borderColor     = '#FF0000';
                    $('l' + field_id).style.color = '#FF0000';
                  } else {

                   /*
                    * Das Hinweisfeld positiv schalten
                    */
                    element.style.borderColor     = '#DDDDDD';
                    $('l' + field_id).style.color = '#333333';
                  }
                } else {

                  missing = true;
                  element.style.borderColor     = '#FF0000';
                  $('l' + field_id).style.color = '#FF0000';
                }
            } else {

              /*
               * Das Hinweisfeld positiv schalten, wenn der Wert okay ist
               */
              if(value !== '') {

                if(checkValid(value, type)) {

                  missing = true;
                  element.style.borderColor     = '#FF0000';
                  $('l' + field_id).style.color = '#FF0000';
                } else {

                  element.style.borderColor     = '#DDDDDD';
                  $('l' + field_id).style.color = '#333333';
                }
              } else {

                element.style.borderColor     = '#DDDDDD';
                $('l' + field_id).style.color = '#333333';
              }
            }
     }
  

  return missing;
}

/**
 * Prüft, ob alle Pflichtfelder gefüllt worden sind
 *
 * @author sweber
 */
function doValidateForm(form_id) {

  var validate = document.getElementById('validate_'+form_id).value;
  validate     = validate.split(',');

  var missing  = false;

  for (var count = 0; count < validate.length; count++) {

    var active    = (count % 2 === 0) ? '_active' : '';
    var field     = validate[count].split('|');
    var field_id  = field[0];
    var type      = field[1];
    var mandatory = field[2];

    var element      = document.getElementById(field_id);
    var info_element = getFormValidateOutputField(field_id);

    var value = (element.type == 'selectOne') ? element.options[element.options.selectedIndex].value : element.value;

    /*
     * Prüfen, ob das Feld Mandatory ist
     */
    if(mandatory == 'true') {

      if(value !== '') {

        if(checkValid(value, type)) {

          /*
           * Das Hinweisfeld mit einem Fehlertext versehen
           */
          missing = true;
          fillFormValidateOutputfield(info_element, false, getErrorMsgForType(type));
        } else {

         /*
          * Das Hinweisfeld positiv schalten
          */
          fillFormValidateOutputfield(info_element, true, '');
        }
      } else {

        missing = true;
        fillFormValidateOutputfield(info_element, false, getErrorMsgForType('mandatory'));
      }
    } else {

      /*
       * Das Hinweisfeld positiv schalten, wenn der Wert okay ist
       */
      if(value !== '') {

        if(checkValid(value, type)) {

           missing = true;
          fillFormValidateOutputfield(info_element, false, getErrorMsgForType(type));
        } else {

          fillFormValidateOutputfield(info_element, true, '');
        }
      } else {

        fillFormValidateOutputfield(info_element, true, '');
      }
    }
  }

  /*
   * Hochscrollen
   */
  if(missing) {

    new Effect.ScrollTo($('main_error_holder'));
  }

  return missing;
}



/**
 * Prüft, ob der Inhalt eines Feldes plausibel ist
 *
 * @author sweber
 */
function checkValid(wert, type) {

  var error = false;

  switch(type) {

    case 'radio':

      if(input.checked === 0) {

        error = true;
      }
      break;

    case 'text':

      if(wert.length === 0) {
        error = true;

      }

      break;

    case 'postleitzahl':
      error = false;
      break;

    case 'zahl':

      var Allowed = '0123456789';
      var Pos = 0;

      wert = trim(wert);
      for (Pos; Pos < wert.length; Pos++) {
        if (Allowed.indexOf(wert.charAt(Pos)) == -1){

          error = true;

        }
      }

      break;

    case "url":

        var a = false;
        var res = false;
        // testen, ob regexp korrekt unterstuetzt werden
        if(typeof(RegExp) == 'function') {

          var b = new RegExp('abc');

          if(b.test('abc') === true){

            a = true;
          }
        }

        if(wert.length){

          if(a === true) {

            reg = new RegExp("^(https?://)?(([\\w!~*'().&=+$%-]+: )?[\\w!~*'().&=+$%-]+@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([\\w!~*'()-]+\\.)*([\\w^-][\\w-]{0,61})?[\\w]\\.[a-z]{2,6})(:[0-9]{1,4})?((/*)|(/+[\\w!~*'().;?:@&=+$,%#-]+)+/*)$");

            res = (reg.test(wert));

           }
           error = !res;
        }


      break;

    case 'email':

      var a = false;
      var res = false;
      // testen, ob regexp korrekt unterstützt werden
      if(typeof(RegExp) == 'function') {
        var b = new RegExp('abc');
        if(b.test('abc') === true){
          a = true;

        }
      }

      if(wert.length){
        if(a === true) {
          reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                           '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                           '(\\.)([a-zA-Z]{2,4})$');
          res = (reg.test(wert));

        } else {
          res = (wert.search('@') >= 1 &&
                 wert.lastIndexOf('.') > wert.search('@') &&
                 wert.lastIndexOf('.') >= wert.length-5);

         }
         error = !res;
       }

       break;

    case 'telefon':

      // Es dürfen nur die folgenden Zeichen verwendet werden
      var Allowed = '0123456789 /-+()';
      var Pos = 0;

      for (Pos; Pos < wert.length; Pos++) {
        if (Allowed.indexOf(wert.charAt(Pos)) == -1){

          error = true;

        }
      }
      break;

    case 'uhrzeit':

      // Wir erwarten HH:MM
      var Allowed = '0123456789';

      if(Allowed.indexOf(wert.charAt(0)) == -1) { error = true; }
      if(Allowed.indexOf(wert.charAt(1)) == -1) { error = true; }
      if(wert.charAt(2) != ':')                 { error = true; }
      if(Allowed.indexOf(wert.charAt(3)) == -1) { error = true; }
      if(Allowed.indexOf(wert.charAt(4)) == -1) { error = true; }
      break;

    case 'ganzzahl':

      if (parseInt(wert) != wert || wert === ''){

        error = true;
      }
      break;

    case 'kommazahl':

      if(wert === '') {

        error = true;
      } else {

        if(wert.indexOf('.') != -1 || wert.indexOf(',') != -1) {
          if(wert.indexOf('.') != -1) {

            if (parseFloat(wert) != wert){

              error = true;
            }
          }

          if(wert.indexOf(',') != -1) {

            wert = wert.replace(/,/g, '.');

            if (parseFloat(wert) != wert){

              error = true;
            }
          }
        } else {

          if(parseInt(wert) != wert) {

            error = true;
          }
        }
      }

      break;

    case 'date':

      var monat = wert.split(".")[1];
      var tag   = wert.split(".")[0];
      var jahr  = wert.split(".")[2];

      var datum = new Date(jahr, monat-1, tag);

      if ( (datum.getMonth() + 1 != monat) ||
            (datum.getDate() != tag) ||
            (datum.getFullYear() != jahr)) {

        error = true;
      }

      break;
  }

  return error;
}


/**
 * Blendet die Fehlerhinweisbox ein oder aus
 *
 * @author sweber
 */
function openCloseErrorBox(new_state) {

  var main_error_holder = $('main_error_holder');

  if(new_state == 'open') {

    Effect.Appear('main_error_holder');
  } else {

    main_error_holder.style.display = 'none';
  }
}

/**
 * Highlighted einen Topnavieintrag
 */
function topNaviMarkActive(id) {

  var topnaviliste = $('header_hauptnavi').getElementsByTagName('LI');

  for(top_counter = 0; top_counter < topnaviliste.length; top_counter++) {

    var element = topnaviliste[top_counter];
    var images  = element.getElementsByTagName('IMG');
    var subnavi = $('subnavi_'+element.id);
    /*
     * Die sideimages de / aktivieren und die klasse setzen
     */
    if(id == element.id) {

      element.className = 'hauptnavi_aktiv';

      for(counter = 0; counter < images.length; counter++) {

        images[counter].style.display = 'block';
      }

      /*
       * Subnavi aktivieren
       */
      if(subnavi) {

        subnavi.style.display = 'block';
      }
    } else {

      element.className = '';

      for(counter = 0; counter < images.length; counter++) {

        images[counter].style.display = 'none';
      }

           /*
       * Subnavi deaktivieren
       */
      if(subnavi) {

        subnavi.style.display = 'none';
      }
    }
  }
}

/**
 * Setzt den aktuellen Nopnavipunkt abhängig von der URL
 */
function setActualHeaderNavi() {

  url       = window.location.pathname;
  url_parts = url.split('/');

  /*
   * devmode beachten
   */
  var module_pos = (url.indexOf('.php/') > 0) ? 2 : 1;

  switch(url_parts[module_pos]) {

    case 'profil':

      topNaviMarkActive('hn_mymakime');
      break;

    case 'mymakime':

      topNaviMarkActive('hn_mymakime');
      break;

      case 'kalender':

            topNaviMarkActive('hn_mymakime');
            break;

    case 'makime':

      //topNaviMarkActive('');
      break;

    case 'nachrichten':

      topNaviMarkActive('hn_mymakime');
      break;

    case 'cityguide':

      topNaviMarkActive('hn_cityguide');
      break;

      case 'activity':

            action = url_parts[module_pos + 1];

            if (action == 'myActivities') {

              topNaviMarkActive('hn_mymakime');
            } else {

              topNaviMarkActive('hn_aktivitaeten');
            }

            break;

        case 'mitglieder':

            action = url_parts[module_pos + 1];

            if (action == 'contacts') {

              topNaviMarkActive('hn_mymakime');
            } else if (action == 'requestedContactsList') {

              topNaviMarkActive('hn_mymakime');
            } else {

              topNaviMarkActive('hn_mitglieder');
            }
            break;
        case 'system':

          action = url_parts[module_pos + 1];

            if (action == 'searchForMode') {

              topNaviMarkActive('hn_mymakime');
            } else if (action == 'logout') {

              topNaviMarkActive('hn_home');
            }

          break;

    default:

      topNaviMarkActive('hn_home');
      break;
  }
}

/**
 * Öffnet eine Modalbox in der ein Benutzer seine Statusnachricht ändern kann.
 *
 * @author thallek <thallek@soft-science.de>
 */

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    }
}



function editUserStatusMessage(title) {


    document.getElementById("box_statusnachricht").innerHTML =  '<div><textarea onkeyup="limitText(this,100);" name="statusnachrichtEditBox" id="statusnachrichtEditBox" style="width: 300px; height: 35px; background-color:#EBE7DC; border:1px solid #DDDDDD; color:#545454;">'+title+'</textarea>  </div>\n\
<div class="button"><img width="4" height="10" style="float: left;" src="/images/submit_left.gif"/> <a class="buttontext_norm" href="javascript:;" onclick="saveStatusMessage();">Statusnachricht speichern</a><img width="4" height="23" style="float: left;" src="/images/submit_right.gif"/> </div>';
// <span id="statusnachricht_leftChars" style="float: left;">'+ (100 - strlen(document.form_status.statusnachrichtEditBox.value)) +'</span>&nbsp;Zeichen übrig';
  /* <div class=button>';
    <img width="4" height="23" style="float: left;" src="/images/submit_left.gif"/>
    <a class="buttontext_norm" href="javascript:;" onclick="saveStatusMessage();">Statusnachricht speichern</a>
    <img width="4" height="23" style="float: left;" src="/images/submit_right.gif"/>
  </div>';*/

 /* if(title == null) {

    title = '';
  }

  Modalbox.show('/profil/editStatusMessage/', { title: title, width: 400, height: 180});

  return false;*/

}

function saveStatusMessage() {

  new Ajax.Updater('ajax_buffer', '/profil/saveStatusMessage?statusnachricht=' + $('statusnachrichtEditBox').value , {asynchronous:false, evalScripts:true} );
  //Modalbox.hide();
}


/**
 * Gibt die absolute Position eines Elementes zurück
 * parts taken from JSCalendar bundled with symfony
 */
function getAbsolutePos(el) {

  var SL = 0, ST = 0;
  var is_div = /^div$/i.test(el.tagName);
  if (is_div && el.scrollLeft) {

    SL = el.scrollLeft;
  }
  if (is_div && el.scrollTop) {

    ST = el.scrollTop;
  }
  var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST }

  if (el.offsetParent) {
    var tmp = this.getAbsolutePos(el.offsetParent);
    r.x += tmp.x;
    r.y += tmp.y;
  }
  return r;
}

/**
 * Blendet das Overlay für Hilfetexte aus
 *
 * @author sweber
 */
function hideInfoOverlay() {

  $('info_tip').style.display = 'none';
}


/**
 * Zeigt ein Overlay mit Hilfetext
 *
 * @author sweber
 */
function showInfoOverlay(element) {

  var p    = getAbsolutePos(element);
  var text = '';

  if($('infoboxtext_'+element.id)) {

    text = $('infoboxtext_'+element.id).value;
  }

  $('info_tip').style.display  = 'block';
  $('info_tip_text').innerHTML = (text !== '') ? text : 'Diese Information arbeiten wir derzeit für Sie aus!';
  $('info_tip').style.left     = (p.x - 43) + "px";
  $('info_tip').style.top      = (p.y > $('info_tip').scrollHeight) ? (p.y - $('info_tip').scrollHeight) + "px" : $('info_tip').scrollHeight + 'px';
}


/**
 * Fügt das onmouseout event allen infoicons hinzu
 *
 * @author sweber
 */
function loadInfoButtons() {

  var info_icons = document.getElementsByClassName('info_opener');

  for(i = 0; i < info_icons.length; i++) {

    element = info_icons[i];
    element.onmouseout  = function() { hideInfoOverlay(); };
    element.onmouseover = function() { showInfoOverlay(this); };
  }
}


/**
 * Setzt ein paar onclickhandler
 *
 * @author sweber
 */
function initMAKIme() {

  /*
   * Loginform
   */
  if($('form_login')) {

    addFormSubmit('login_password', 'form_login');
  }

  /*
   * Loginform
   */
  if($('form_please_login')) {

    addFormSubmit('login_password_pl', 'form_please_login');
  }

  /*
   * Empfehlenform
   */
  if($('netzwerk_erweitern_form')) {

      orig_empfehlen_vorname  = $('empfehlen_sender').value;
      orig_empfehlen_nachname = $('empfehlen_receiver').value;
      orig_empfehlen_email    = $('empfehlen_email').value;

    $('empfehlen_sender').onfocus = function () { if($('empfehlen_sender').value ==  orig_empfehlen_vorname) { $('empfehlen_sender').value = ''; } };
    $('empfehlen_sender').onblur  = function () { if($('empfehlen_sender').value === ''                    ) { $('empfehlen_sender').value = orig_empfehlen_vorname; } };

    $('empfehlen_receiver').onfocus = function () { if($('empfehlen_receiver').value ==  orig_empfehlen_nachname) { $('empfehlen_receiver').value = ''; } };
    $('empfehlen_receiver').onblur  = function () { if($('empfehlen_receiver').value === ''                     ) { $('empfehlen_receiver').value = orig_empfehlen_nachname; } };

    $('empfehlen_email').onfocus = function () { if($('empfehlen_email').value ==  orig_empfehlen_email) { $('empfehlen_email').value = ''; } };
    $('empfehlen_email').onblur  = function () { if($('empfehlen_email').value === ''                  ) { $('empfehlen_email').value = orig_empfehlen_email; } };
  }

  /*
   * Activity Invitation Form
   */
  if($('activity_invite_form')) {

    if ($('contact1') != null) {

      orig_contact1  = $('contact1').value;
      $('contact1').onfocus = function () { if($('contact1').value ==  orig_contact1) { $('contact1').value = ''; } };
      $('contact1').onblur  = function () { if($('contact1').value === ''           ) { $('contact1').value = orig_contact1; } };
    }

    if ($('contact2') != null) {

      orig_contact2  = $('contact2').value;
      $('contact2').onfocus = function () { if($('contact2').value ==  orig_contact2) { $('contact2').value = ''; } };
      $('contact2').onblur  = function () { if($('contact2').value === ''           ) { $('contact2').value = orig_contact2; } };
    }

    if ($('contact3') != null) {

      orig_contact3  = $('contact3').value;
      $('contact3').onfocus = function () { if($('contact3').value ==  orig_contact3) { $('contact3').value = ''; } };
      $('contact3').onblur  = function () { if($('contact3').value === ''           ) { $('contact3').value = orig_contact3; } };
    }

    if ($('contact4') != null) {

      orig_contact4  = $('contact4').value;
      $('contact4').onfocus = function () { if($('contact4').value ==  orig_contact4) { $('contact4').value = ''; } };
      $('contact4').onblur  = function () { if($('contact4').value === ''           ) { $('contact4').value = orig_contact4; } };
    }

    if ($('contact5') != null) {

      orig_contact5  = $('contact5').value;
      $('contact5').onfocus = function () { if($('contact5').value ==  orig_contact5) { $('contact5').value = ''; } };
      $('contact5').onblur  = function () { if($('contact5').value === ''           ) { $('contact5').value = orig_contact5; } };
    }
  }

  /*
   * TopSearch
   */
  if($('top_search')) {

      orig_top_search_value = $('top_search_value').value;

    $('top_search_value').onfocus = function () { if($('top_search_value').value ==  orig_top_search_value) { $('top_search_value').value = ''; } };
    $('top_search_value').onblur  = function () { if($('top_search_value').value === ''                   ) { $('top_search_value').value = orig_top_search_value; } };
  }

  /*
   * Activity Suche
   */
  if($('activity_search_form')) {

    addFormSubmit('stichwoerter',   'activity_search_form');
    addFormSubmit('kategorie',      'activity_search_form');
    addFormSubmit('titel',          'activity_search_form');
    addFormSubmit('zielgruppe',     'activity_search_form');
    addFormSubmit('veranstalter',   'activity_search_form');
    addFormSubmit('sprache',        'activity_search_form');
    addFormSubmit('gebuehren',      'activity_search_form');
    addFormSubmit('startdatum',     'activity_search_form');
    addFormSubmit('startstunde',    'activity_search_form');
    addFormSubmit('enddatum',       'activity_search_form');
    addFormSubmit('endstunde',      'activity_search_form');
    addFormSubmit('endminute',      'activity_search_form');
    addFormSubmit('anmeldeschluss', 'activity_search_form');
    addFormSubmit('location_title', 'activity_search_form');
    addFormSubmit('strasse',        'activity_search_form');
    addFormSubmit('city',           'activity_search_form');
    addFormSubmit('country',        'activity_search_form');
    if($('sorting')) {

      $('sorting').onchange = function() { $('sortierung').selectedIndex = $('sorting').selectedIndex; $('activity_search_form').submit(); };
    }
  }

  /*
   * CityGuide Suche
   */
  if($('city_guide_search')) {

    addFormSubmit('stichwoerter',           'city_guide_search');
    addFormSubmit('city_guide_category_id', 'city_guide_search');
    addFormSubmit('preisklasse',            'city_guide_search');
    addFormSubmit('mietbarkeit_ja',         'city_guide_search');
    addFormSubmit('mietbarkeit_nein',       'city_guide_search');
    addFormSubmit('postleitzahl',           'city_guide_search');
    addFormSubmit('ort',                    'city_guide_search');
    addFormSubmit('country_id',             'city_guide_search');
    $('order_field').onchange = function() { $('city_guide_search').submit(); };
  }

  /**
   * Usersuche
   */
  if($('user_search_form')) {

    addFormSubmit('stichwoerter',      'user_search_form');
    addFormSubmit('vorname',           'user_search_form');
    addFormSubmit('nachname',          'user_search_form');
    addFormSubmit('geschlecht',        'user_search_form');
    addFormSubmit('alter',             'user_search_form');
    addFormSubmit('sprache',           'user_search_form');
    addFormSubmit('interessen',        'user_search_form');
    addFormSubmit('ort',               'user_search_form');
    addFormSubmit('aktivitaeten',      'user_search_form');
    addFormSubmit('reise_von',         'user_search_form');
    addFormSubmit('reise_bis',         'user_search_form');
    addFormSubmit('sortierung',        'user_search_form');
    addFormSubmit('branche',           'user_search_form');
    addFormSubmit('beruf',             'user_search_form');
    addFormSubmit('jetzige_firma',     'user_search_form');
    addFormSubmit('fruehere_firma',    'user_search_form');
    addFormSubmit('jetzige_position',  'user_search_form');
    addFormSubmit('fruehere_position', 'user_search_form');
    addFormSubmit('berufsstatus',      'user_search_form');
    addFormSubmit('sucht',             'user_search_form');
    addFormSubmit('bietet',            'user_search_form');

    if ($('select_sortierung') != 'undefined' && $('select_sortierung') != 'null' && $('select_sortierung') != null)  {

      $('select_sortierung').onchange = function() { $('user_search_form').submit(); };
    }
  }

  /*
   * Info overlays
   */
  loadInfoButtons();

  /*
   * Schnellsucheform
   */
  if($('searchtab_users')) {

    addFormSubmit('seachform_users_stichwoerter',         'smallform_user');
    addFormSubmit('seachform_users_ort',                  'smallform_user');
    addFormSubmit('seachform_users_reisen_von',           'smallform_user');
    addFormSubmit('seachform_users_reisen_bis',           'smallform_user');
    addFormSubmit('seachform_users_gleiche_aktivitaeten', 'smallform_user');
    addFormSubmit('seachform_users_online_mitglieder',    'smallform_user');

    addFormSubmit('seachform_activity_stichwoerter', 'smallform_activity');
    addFormSubmit('seachform_activity_ort',          'smallform_activity');
    addFormSubmit('seachform_activity_startdatum',   'smallform_activity');
    addFormSubmit('seachform_activity_enddatum',     'smallform_activity');
    addFormSubmit('seachform_activity_contact_only', 'smallform_activity');

    addFormSubmit('seachform_cityguide_stichwoerter', 'smallform_cityguide');
    addFormSubmit('seachform_cityguide_ort',          'smallform_cityguide');
    addFormSubmit('seachform_cityguide_startdatum',   'smallform_cityguide');
    addFormSubmit('seachform_cityguide_enddatum',     'smallform_cityguide');
    addFormSubmit('seachform_cityguide_contact_only', 'smallform_cityguide');
  }
}


/**
 * Gibt dem gegebenen Element ein onkeypress event, dass ein gegebens form bei enter abschickt
 *
 * @author
 */
function addFormSubmit(element_id, form_id) {

  if($(element_id)) {

    Event.observe($(element_id), 'keyup', function(event) {
        if(event.which) {

          if(event.which == 13) {

            $(form_id).submit();
          }
        } else {

          if(event.keyCode == 13) {

            $(form_id).submit();
          }
        }
      }
                                      );
  }
}


/**
 * Switcht zwischen den Tabs in der Topbox
 *
 * @author sweber
 */
function changeActiveTopBox(active_tab) {

  switch(active_tab) {

    case 'user':
    default:

      $('toptab_user').className           = 'tab_aktiv';
      $('toptab_activities').className     = '';
      $('toptab_cityguide').className      = '';
      $('topbox_user').style.display       = 'block';
      $('topbox_activities').style.display = 'none';
      $('topbox_cityguide').style.display  = 'none';
      break;

    case 'activities':

      $('toptab_user').className           = '';
      $('toptab_activities').className     = 'tab_aktiv';
      $('toptab_cityguide').className      = '';
      $('topbox_user').style.display       = 'none';
      $('topbox_activities').style.display = 'block';
      $('topbox_cityguide').style.display  = 'none';
      break;

    case 'cityguide':

      $('toptab_user').className           = '';
      $('toptab_activities').className     = '';
      $('toptab_cityguide').className      = 'tab_aktiv';
      $('topbox_user').style.display       = 'none';
      $('topbox_activities').style.display = 'none';
      $('topbox_cityguide').style.display  = 'block';
      break;
  }
}

/**
 * Switcht zwischen den Tabs in dem Smallsearchform
 *
 * @author sweber
 */
function changeActiveSmallSearchBox(active_tab) {

  switch(active_tab) {

    default:

      $('searchtab_users').className         = 'tab_aktiv';
      $('searchtab_activity').className      = '';
      $('searchtab_location').className      = '';
      $('seachform_users').style.display     = 'block';
      $('seachform_activity').style.display  = 'none';
      $('seachform_cityguide').style.display = 'none';
      break;

    case 'user':

      $('searchtab_users').className         = 'tab_aktiv';
      $('searchtab_activity').className      = '';
      $('searchtab_location').className      = '';
      $('seachform_users').style.display     = 'block';
      $('seachform_activity').style.display  = 'none';
      $('seachform_cityguide').style.display = 'none';
      break;

    case 'activities':

      $('searchtab_users').className         = '';
      $('searchtab_activity').className      = 'tab_aktiv';
      $('searchtab_location').className      = '';
      $('seachform_users').style.display     = 'none';
      $('seachform_activity').style.display  = 'block';
      $('seachform_cityguide').style.display = 'none';
      break;

    case 'cityguide':

      $('searchtab_users').className         = '';
      $('searchtab_activity').className      = '';
      $('searchtab_location').className      = 'tab_aktiv';
      $('seachform_users').style.display     = 'none';
      $('seachform_activity').style.display  = 'none';
      $('seachform_cityguide').style.display = 'block';
      break;
  }
}

function handleSearchPageTab(tab, functionname) {

  switch(tab) {

    case 'first_tab':
    default:

      $('first_tab').className  = 'tab_aktiv';
      $('second_tab').className = '';
      $('third_tab').className  = '';

      $('suchmaske').style.display          = 'block';
      $('suchergebnis_liste').style.display = 'none';
      $('suchergebnis_karte').style.display = 'none';
      break;

    case 'second_tab':

      $('first_tab').className  = '';
      $('second_tab').className = 'tab_aktiv';
      $('third_tab').className  = '';

      $('suchmaske').style.display          = 'none';
      $('suchergebnis_liste').style.display = 'block';
      $('suchergebnis_karte').style.display = 'none';

      break;

    case 'third_tab':

      functionname;

      $('first_tab').className  = '';
      $('second_tab').className = '';
      $('third_tab').className  = 'tab_aktiv';

      $('suchmaske').style.display          = 'none';
      $('suchergebnis_liste').style.display = 'none';
      $('suchergebnis_karte').style.display = 'block';
      break;
  }
}

/**
 * Modalbox zum Erstellen eriner Reise öffnen
 *
 * @author maichele
 */
function modalboxCreateTravel(title_text) {

  window.scrollTo(0, 0);
  Modalbox.show('/kalender/modalboxCreateTravel', {title: title_text, width: 690, height: 440});
}


function modalboxCreateZeitzumNetzwerken(title_text, datum, netzwerk_id) {
  
  window.scrollTo(0, 0);
  Modalbox.show('/kalender/modalboxCreateZeitzumNetzwerken?datum=' + datum + '&netzwerk_id='+netzwerk_id, {title: title_text, width: 555, height: 150});
}




/**
 * Reise speichern
 */
function saveCreateTravel() {

  new Ajax.Updater('create_travel_target', '/kalender/saveCreateTravel', {asynchronous:false, evalScripts:true, parameters:Form.serialize('create_travel_form'), onComplete:

  function(request, json) {

        Modalbox.hide();
    }

  } );
}


function saveCreateZeitzumNetzwerken() {

  new Ajax.Updater('create_zeitzumnetzwerken_target', '/kalender/saveCreateZeitzumNetzwerken', {asynchronous:false, evalScripts:true, parameters:Form.serialize('create_zeitzumnetzwerken_form'), onComplete:

  function(request, json) {

        Modalbox.hide();
    }

  } );
}

/**
 * Mehr Testimonials einblenden
 *
 * @author maichele
 */
function openMoreTestimonials() {

  Effect.Fade('more_testimonials_link', { duration: 1.0, queue: 'front' });
  Effect.Appear('more_testimonials', { duration: 1.0, queue: 'end' });
}

/**
 * Leerzeichen am Anfang und Ende der Zeichenkette entfernen
 *
 * @author maichele
 */
function trim (zeichenkette) {

  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}


/**
 * Prüft während der Eingabe in ein Textfeld die erluabte Länge und
 * kürzt ggf den Text um das letzte Zeichen.
 *
 * @author sweber
 */
function checkAvailableCharsLeft(textarea, maxlength) {

  var span = document.getElementById(textarea.name + '_leftChars');
  var text = textarea.value;

  if(text.length > maxlength) {

    textarea.value = text.substr(0, (maxlength - 1));
    span.innerHTML = '0';
  } else {

    span.innerHTML = (maxlength - text.length);
  }
}

/**
 * test if we are on the right page, and change it if we are not
 */
function preparePageForMovie() {

  if($('teaser_holder_aj') == null) {

    window.location = '/movie';
  }
}


/**
 * spielt das Filmchen
 */
function playMovie(text, text2) {

  if(text == null) {

    text = 'Teaser zeigen';
  }
  if (text2 == null) {

    text = 'Film &uuml;ber MAKIme';
  }

  new Ajax.Updater('teaser_holder_aj', '/system/showMovie', {asynchronous:false, evalScripts:true, onSuccess: function() { $('filmtrigger').onclick = function () { showTeaser(text, text2); }; $('filmtrigger').innerHTML = '<span class="movie_text">'+text+'</span>'; } } )
}

/**
 * zeigt den Teaser
 */
function showTeaser(text, text2) {

  if(text == null) {

    text = 'Teaser zeigen';
  }
  if (text2 == null) {

    text = 'Film &uuml;ber MAKIme';
  }

  new Ajax.Updater('teaser_holder_aj', '/system/showTeaser', {asynchronous:false, evalScripts:true, onSuccess: function() { $('filmtrigger').onclick = function () { playMovie(text, text2); }; $('filmtrigger').innerHTML = '<span class="movie_text">'+text2+'</span><span style="height:16px; float:left;"><img style="background-color:#FFFFFF;border:none;margin-top:3px;margin-left:5px;" src="/images/control_play.png" /></span>'; } } )
}

/**
 * Blitz Action speichern
 *
 * @author maichele
 */
function saveBlitzAction() {

  valid = true;

  if ($('ba_desc').value == '') {

    valid = false;
    getFormValidateOutputField('ba_desc');
    fillFormValidateOutputfield($('error_ba_desc'), false, getErrorMsgForType('mandatory'));
  } else {

    if($('error_ba_desc')) {

      $('validation_error_ul').removeChild($('error_ba_desc'));
    }
  }

  if ($('ba_title').value == '') {

    valid = false;
    getFormValidateOutputField('ba_title');
    fillFormValidateOutputfield($('error_ba_title'), false, getErrorMsgForType('mandatory'));
  } else {

    if($('error_ba_title')) {

      $('validation_error_ul').removeChild($('error_ba_title'));
    }
  }

  if (valid) {

    openCloseErrorBox('close');
    new Ajax.Updater('ba_save_target', '/system/ajaxSaveBlitzAction', {asynchronous:false, evalScripts:true, parameters:Form.serialize('ba_form')});
  } else {

    openCloseErrorBox('open');
  }
}

/**
 * Modalbox zur Teilnahme an Blitz Action öffnen
 *
 * @author maichele
 */
function modalboxTakePartInBlitzAction(action_id, title_text) {

  Modalbox.show('/system/modalboxTakePartInBlitzAction?ba_id=' + action_id, {title: title_text, width: 400, height: 240});
}

/**
 * An Blitz Action teilnehemen
 *
 * @author maichele
 */
function takePartInBlitzAction(action_id) {

  new Ajax.Updater('ba_save_target', '/system/takePartInBlitzAction?ba_id=' + action_id, {asynchronous:false, evalScripts:true, parameters:Form.serialize('ba_message_form') });
}

/**
 * Teilnehmerliste einer BlitzAction öffenen/schliessen
 *
 * @author maichele
 * @param int action_id
 * @param element el
 */
function openCloseBATeilnehmerliste(action_id) {

  if ($('ba_teilnehmerliste_' + action_id).style.display == 'none') {

    Effect.SlideDown('ba_teilnehmerliste_' + action_id);


    if($('arrow_'+action_id)) {

      $('arrow_'+action_id).innerHTML = '<img src="/images/ico_teilnehmerliste.jpg" style="float:left;cursor:pointer;width:22px;height:20px;margin-left:5px;margin-top:5px;" />';
    }

  } else {

    Effect.SlideUp('ba_teilnehmerliste_' + action_id);

    if($('arrow_'+action_id)) {

      $('arrow_'+action_id).innerHTML = '<img src="/images/ico_teilnehmerliste_right.jpg" style="float:left;cursor:pointer;width:22px;height:20px;margin-left:5px;margin-top:5px;" />';
    }
  }
}

/**
 * Invited Teilnehmerliste einer BlitzAction �ffenen/schliessen
 *
 * @author maichele
 * @author jbleicher
 * @param int action_id
 */
function openCloseBAInvitedliste(action_id) {

  if ($('ba_invitedliste_' + action_id).style.display == 'none') {

    Effect.SlideDown('ba_invitedliste_' + action_id);

  } else {

    Effect.SlideUp('ba_invitedliste_' + action_id);
  }
}

/**
 * Mesage Länge checken und verbleibende Zeichen aktualisieren
 *
 * @author maichele
 */
function checkMessageLength() {

  var action_len = $('ba_desc').value.length;

  chars_left = 160 - action_len;

  $('chars_left').innerHTML = chars_left;

  if (chars_left <= 0) {

    $('ba_desc').value = $('ba_desc').value.substring(0,159);
  }
}

/**
 * Modalbox zum einladen zu einer BlitzAction öffnen
 *
 * @author maichele
 */
function modalboxInviteToBlitzAction(action_id, option) {

  if (action_id == '' || action_id == 'undefined') {

    action_id = 0;
  }

  valid = true;

  if ($('ba_desc').value == '' && option != 'all') {

    valid = false;
    getFormValidateOutputField('ba_desc');
    fillFormValidateOutputfield($('error_ba_desc'), false, getErrorMsgForType('mandatory'));
  } else {

    if($('error_ba_desc') ) {

      $('validation_error_ul').removeChild($('error_ba_desc'));
    }
  }

  if ($('ba_title').value == '' && option != 'all') {

    valid = false;
    getFormValidateOutputField('ba_title');
    fillFormValidateOutputfield($('error_ba_title'), false, getErrorMsgForType('mandatory'));
  } else {

    if($('error_ba_title')) {

      $('validation_error_ul').removeChild($('error_ba_title'));
    }
  }

  if (valid || action_id > 0) {

    openCloseErrorBox('close');
    if(option == 'all'){
      //  window.location = '/system/modalboxinvite/all';
       
    Modalbox.show('/system/modalboxInviteToBlitzAction?option=all', {title: 'Zu einer Aktivität einladen', width: 640, height: 450});
    } else {
     Modalbox.show('/system/modalboxInviteToBlitzAction?ba_id=' + action_id+ "&option=acht", {title: 'Zu einer Aktivität einladen', width: 640, height: 450});
    }
  } else {

    openCloseErrorBox('open');
  }
}

/**
 * Benutzer zu einer Blitz Actioneinladen
 *
 * @author maichele
 */
function inviteToBlitzAction(action_id) {
  //action_id = document.ba_inv_form.ba_ids.value;
 
  if (action_id == 0 || action_id == 'undefined' || action_id == null) {

    new Ajax.Updater('ba_save_target', '/system/inviteToBlitzAction?ba_id=' + action_id + '&' + Form.serialize('ba_form'), {asynchronous:false, evalScripts:true, parameters:Form.serialize('ba_inv_form') });
  } else {
 
    new Ajax.Updater('ba_save_target', '/system/inviteToBlitzAction?ba_id=' + action_id, {asynchronous:false, evalScripts:true, parameters:Form.serialize('ba_inv_form') });
  }
}

/**
 * Benutzer einladen Div Highlightung switchen und hidden Feld mit user ids aktualisieren
 *
 * @author maichele
 */
function switchInvUserSelected(ele, user_id) {

  inv_count = $('inv_count').innerHTML;

  if (hasClass(ele, 'div_highlight')) {

    removeClass(ele, 'div_highlight');
    addClass(ele, 'div_non_highlight');

    $('inv_user_' + user_id).checked = false;

    inv_count--;
  } else {

    removeClass(ele, 'div_non_highlight');
    addClass(ele, 'div_highlight');

    $('inv_user_' + user_id).checked = true;

    inv_count++;
  }

  $('inv_count').innerHTML = inv_count;
}

/**
 * Prüfen ob ein element eine Klasse hat
 *
 * @author maichele
 */
function hasClass(ele, cls) {

  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

/**
 * eine Klasse einem Element hinzufügen
 *
 * @author maichele
 */
function addClass(ele, cls) {

  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

/**
 * eine Klasse von einem Element entfernen
 *
 * @author maichele
 */
function removeClass(ele, cls) {

  if (hasClass(ele, cls)) {

    var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

/**
 * LocationId Feld nach Autocompleter Auswahl befüllen
 *
 * @author maichele
 */
function fillActivityLocationId(text, li) {

  location_id = li.id;

  $('ba_location_id').value = location_id;

  titel_string = li.innerHTML.substr(0, li.innerHTML.indexOf('<br'))
  titel_string = titel_string.replace(/<b>/g, '');
  titel_string = titel_string.replace(/<\/b>/g, '');
  $('location_title').value = titel_string;
}

/**
 * Blitz Action melden Modalbox
 *
 * @author maichele
 */
function modalboxReportBlitzAction(ba_id) {

  var url = '/system/modalboxReportBlitzAction?ba_id=' + ba_id;

  Modalbox.show(url, {title: 'Aktion melden', width: 330, height: 160});
}

/**
 * Blitz Action melden
 *
 * @author maichele
 */
function reportBlitzAction() {

  new Ajax.Updater('ajax_buffer', '/system/reportBlitzAction', {asynchronous:false, evalScripts:true, parameters:Form.serialize('melden_form'), onComplete:

  function(request, json) {

        Modalbox.hide();
    }

  } );
}

/**
 * Blitz Action melden Modalbox
 *
 * @author maichele
 */
function modalboxDeleteBlitzAction(ba_id, title) {

  var url = '/system/modalboxDeleteBlitzAction?ba_id=' + ba_id;

  if(!title) {

    title = 'Aktion Löschen';
  }

  Modalbox.show(url, {title: title, width: 330, height: 160});
}

/**
 * Blitz Action melden
 *
 * @author jbleicher
 */
function deleteBlitzAction(ba_id) {

  new Ajax.Updater('ajax_buffer', '/system/deleteBlitzAction?ba_id=' + ba_id, {asynchronous:false, evalScripts:true, onComplete:

  function(request, json) {

        Modalbox.hide();
    }

  } );
}

/**
 * Mitglidersuche für Einladung zu Blitz Action
 *
 * @author maichele
 */
function searchUserForBlitzAction(ba_id) {

  new Ajax.Updater('ba_search_result', '/system/searchUserForBlitzAction?ba_id=' + ba_id, {asynchronous:false, evalScripts:true, parameters:Form.serialize('ba_search_form') });
}

/**
 * shows and hides options for travel in modalbox
 *
 * @author jbleicher jbleicher@soft-science.de
 * @param chkbox
 * @param el_id
 */
function showHideOptionsForTravels(chkbox, el_id) {

  if($(el_id) == null ||
     chkbox == null) {

    return false;
  }

  if(chkbox.checked == true) {

    Effect.BlindDown(el_id);
  } else {

    Effect.BlindUp(el_id);
  }
}

 
function Benutzername(){

 document.getElementById('login_email').value = "";
}

function LoginPassword(){

 document.getElementById('login_password').value = "";
}
