function remove_all_child_nodes(id) {
  if ($(id).hasChildNodes()) {
    while ($(id).hasChildNodes()) {
      $(id).removeChild($(id).firstChild);
    }
  }
}


function branchenbucheintrag (step) {
  var return_value = true;

  switch (step) {
    case 1:

      if ($F('anrede').empty()) {
        return_value = false;
        $('anrede').focus();
        alert('Bitte wählen Sie eine Anrede aus.');
      }

      else if ($F('vname').empty()) {
        return_value = false;
        $('vname').focus();
        alert('Bitte füllen Sie das Feld "Vorname" aus.');
      }

      else if ($F('nname').empty()) {
        return_value = false;
        $('nname').focus();
        alert('Bitte füllen Sie das Feld "Nachname" aus.');
      }

      else if ($F('firma').empty()) {
        return_value = false;
        $('firma').focus();
        alert('Bitte füllen Sie das Feld "Firma" aus.');
      }

      else if ($F('land').empty()) {
        return_value = false;
        $('land').focus();
        alert('Bitte wählen Sie ein Land aus.');
      }

      else if ($F('bland').empty()) {
        return_value = false;
        $('bland').focus();
        alert('Bitte wählen Sie ein Bundesland bzw. Konton aus.');
      }

      else if ($F('str').empty()) {
        return_value = false;
        $('str').focus();
        alert('Bitte füllen Sie das Feld "Straße" aus.');
      }

      else if ($F('plz').empty()) {
        return_value = false;
        $('plz').focus();
        alert('Bitte füllen Sie das Feld "PLZ" aus.');
      }

      else if ($F('ort').empty()) {
        return_value = false;
        $('ort').focus();
        alert('Bitte füllen Sie das Feld "Ort" aus.');
      }

      else if ($F('tel').empty()) {
        return_value = false;
        $('tel').focus();
        alert('Bitte füllen Sie das Feld "Telefon" aus.');
      }

      else if ($F('email').empty()) {
        return_value = false;
        $('email').focus();
        alert('Bitte füllen Sie das Feld "eMail" aus.');
      }

      else if ($F('logname').empty()) {
        return_value = false;
        $('logname').focus();
        alert('Bitte füllen Sie das Feld "Benutzername" aus.');
      }

      else if ($F('logpass').empty()) {
        return_value = false;
        $('logpass').focus();
        alert('Bitte füllen Sie das Feld "Passwort" aus.');
      }

      else if ($F('logpass2').empty()) {
        return_value = false;
        $('logpass2').focus();
        alert('Bitte füllen Sie das Feld "Passwort wiederholen" aus.');
      }

      else if ($F('logpass') != $F('logpass2')) {
        return_value = false;
        $('logpass2').focus();
        alert('Die Werte aus den Feldern "Passwort" und "Passwort wiederholen" stimmen nicht überein.');
      }

      else if ($('registrieren').checked != true) {
        return_value = false;
        $('registrieren').focus();
        alert('Sie müssen die bio-finder AGBs lesen und akzeptieren.');
      }

      break; // switch

    case 3:
      $('branchenbucheintrag_form_warten').innerHTML = '<em>Ihre Daten werden übermittelt. Bitte haben Sie einen Augenblick Geduld.</em>';
      break; // switch
  }

  return return_value;
}

function KategorieSucheReset() {
  $('sfkeywords').value = '';
  $('sffirma').value = '';
  $('sfland').selectedIndex = 0;
  $('sfbland').selectedIndex = 0;
  $('sfstr').value = '';
  $('sfplz').value = '';
  $('sfort').value = '';
  if ($('sfbereich1_') != null) {
    $('sfbereich1_').checked = false;
    $('sfbereich1_gesundheit').checked = false;
    $('sfbereich1_kinder').checked = false;
    $('sfbereich1_seele').checked = false;
    $('sfbereich1_ernaehrung').checked = false;
    $('sfbereich1_gastronomie').checked = false;
    $('sfbereich1_haushalt').checked = false;
    $('sfbereich1_pflege').checked = false;
    $('sfbereich1_seminare').checked = false;
    $('sfbereich_textilien1').checked = false;
    $('sfbereich1_urlaub').checked = false;
  }
  KategorieSucheLand();
}

function LandBundeslandSelect() {
  var str_selected_text = $F('bland');
  remove_all_child_nodes('bland');

  elm_option = document.createElement('option');
  $('bland').appendChild(elm_option);

  switch($F('land')) {
    case 'Deutschland':
      arr_bland_Deutschland.each(function(s) {
        elm_option = document.createElement('option');
        if (s == str_selected_text) {
          elm_option.setAttribute('selected', 'selected');
        }
        str_text = document.createTextNode(s);
        elm_option.appendChild(str_text);
        $('bland').appendChild(elm_option);
      });
      break
    case 'Österreich':
      arr_bland_Oesterreich.each(function(s) {
        elm_option = document.createElement('option');
        if (s == str_selected_text) {
          elm_option.setAttribute('selected', 'selected');
        }
        str_text = document.createTextNode(s);
        elm_option.appendChild(str_text);
        $('bland').appendChild(elm_option);
      });
      break
    case 'Schweiz':
      arr_bland_Schweiz.each(function(s) {
        elm_option = document.createElement('option');
        if (s == str_selected_text) {
          elm_option.setAttribute('selected', 'selected');
        }
        str_text = document.createTextNode(s);
        elm_option.appendChild(str_text);
        $('bland').appendChild(elm_option);
      });
      break
    default:
      /* ---------- DEUTSCHLAND ---------- */
        elm_optgroup = document.createElement('optgroup');
        elm_optgroup.setAttribute('label', 'Deutschland');
        arr_bland_Deutschland.each(function(s) {
          elm_option = document.createElement('option');
          if (s == str_selected_text) {
            elm_option.setAttribute('selected', 'selected');
          }
          str_text = document.createTextNode(s);
          elm_option.appendChild(str_text);
          elm_optgroup.appendChild(elm_option);
        });
        $('bland').appendChild(elm_optgroup);
      /* ---------- /DEUTSCHLAND ---------- */

      /* ---------- ÖSTERREICH ---------- */
        elm_optgroup = document.createElement('optgroup');
        elm_optgroup.setAttribute('label', 'Österreich');
        arr_bland_Oesterreich.each(function(s) {
          elm_option = document.createElement('option');
          if (s == str_selected_text) {
            elm_option.setAttribute('selected', 'selected');
          }
          str_text = document.createTextNode(s);
          elm_option.appendChild(str_text);
          elm_optgroup.appendChild(elm_option);
        });
        $('bland').appendChild(elm_optgroup);
      /* ---------- /ÖSTERREICH ---------- */

      /* ---------- SCHWEIZ ---------- */
        elm_optgroup = document.createElement('optgroup');
        elm_optgroup.setAttribute('label', 'Schweiz');
        arr_bland_Schweiz.each(function(s) {
          elm_option = document.createElement('option');
          if (s == str_selected_text) {
            elm_option.setAttribute('selected', 'selected');
          }
          str_text = document.createTextNode(s);
          elm_option.appendChild(str_text);
          elm_optgroup.appendChild(elm_option);
        });
        $('bland').appendChild(elm_optgroup);
      /* ---------- /SCHWEIZ ---------- */
      break;
  }
}

function SchnellsucheKategorie(Kategorie) {
  switch (Kategorie) {
    case 'gesundheit':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-gesundheit/index.php');
      break;
    case 'kinder':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-kinder/index.php');
      break;
    case 'seele':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-seele/index.php');
      break;
    case 'ernaehrung':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-ernaehrung/index.php');
      break;
    case 'gastronomie':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-gastronomie/index.php');
      break;
    case 'haushalt':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-haushalt/index.php');
      break;
    case 'pflege':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-pflege/index.php');
      break;
    case 'seminare':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-seminare/index.php');
      break;
    case 'textilien':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-textilien/index.php');
      break;
    case 'urlaub':
      $('SchnellsucheFormular').setAttribute('action', '/de/bio-urlaub/index.php');
      break;
  }
}

function firmentextkurz_uebrig(id) {
  maxLength = 200;

  if ($F('firmentextkurz').length >= maxLength) {
    $('firmentextkurz').value = $F('firmentextkurz').slice(0, maxLength);
  }
  $('firmentextkurz_uebrig').innerHTML = 'noch ' + String((maxLength - $F('firmentextkurz').length)) + ' Zeichen';
}

function initialize_customer_detail_map()
{
  if (GBrowserIsCompatible())
  {
    map = new GMap2(document.getElementById('customer_detail_map'));
    map.setCenter(new GLatLng(49.010027,8.388517), 9);
    map.addControl(new GSmallMapControl());
    var mapTypeControl = new GMapTypeControl();
    var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(0,0));
    map.addControl(mapTypeControl, bottomRight);
    geocoder = new GClientGeocoder();
  }
}

function show_customer_detail_map(address1,address2,icon)
{
  if (geocoder)
  {
    geocoder.getLatLng(
      address1,
      function(point)
      {
        if (!point)
        {
          document.getElementById('customer_detail_map').style.visibility = 'hidden';
        }
        else
        {
          document.getElementById('customer_detail_map').style.visibility = 'visible';
          document.getElementById('customer_detail_map_legend').style.display = 'block';

          orangeIcon = new GIcon(G_DEFAULT_ICON);
          orangeIcon.image = "http://maps.google.com/mapfiles/ms/icons/orange.png";
          orangeIcon.iconSize = new GSize(32,32);
          orangeIcon.shadow = "http://maps.google.com/mapfiles/ms/micons/msmarker.shadow.png";
          orangeIcon.shadowSize = new GSize(59,32);
          orangeIcon.iconAnchor = new GPoint(16,32);
          //orangeIcon.infoWindowAnchor = new GPoint(16, 1);

          markerIcon = orangeIcon;
          markerOptions = { icon:markerIcon };

          var marker = new GMarker(point, markerOptions);
          map.addOverlay(marker);
          //marker.openInfoWindowHtml(address2, {noCloseOnClick:true, buttons:{close:{show:4}}});
          map.setCenter(point, 9);
        }
      }
    );
  }
}
