
function displayProSearch(id){
  if (!id){
    id = 'profisuche';
  }
  if (!document.getElementById(id)){
    return;
  }
  if (document.getElementById(id).style.display == 'block'){
    document.getElementById(id).style.display = 'none';
  } else {
    document.getElementById(id).style.display = 'block';
    document.location = '#' + id;
  }
}

function displayProSearchHelp(id){
  if (!id){
    id = 'profisuchehilfe';
  }
  if (!document.getElementById(id)){
    return;
  }
  if (document.getElementById(id).style.display == 'block'){
    document.getElementById(id).style.display = 'none';
  } else {
    document.getElementById(id).style.display = 'block';
  }
}

function switchBranchenList(id, title){
  if (!id){
    id = 'webkatalog-search-az-container';
  }
  if (!title){
    title = 'Branchenliste';
  }
  if (!document.getElementById(id)){
    return;
  }
  if (document.getElementById(id).style.display == 'block'){
    document.getElementById(id).style.display = 'none';
    if (document.getElementById('webkatalog-search-container-headline-branchenliste-button')){
      document.getElementById('webkatalog-search-container-headline-branchenliste-button').innerHTML = title + ' öffnen &#187;';
    }  
  } else {
    document.getElementById(id).style.display = 'block';
    if (document.getElementById('webkatalog-search-container-headline-branchenliste-button')){
      document.getElementById('webkatalog-search-container-headline-branchenliste-button').innerHTML = title + ' schließen &#171;';
    }
  }
}

function switchVillageList(id){
  if (!id){
    id = 'webkatalog-search-az-container';
  }
  if (!document.getElementById(id)){
    return;
  }
  if (document.getElementById(id).style.display == 'block'){
    document.getElementById(id).style.display = 'none';
    if (document.getElementById('webkatalog-search-container-headline-branchenliste-button')){
      document.getElementById('webkatalog-search-container-headline-branchenliste-button').innerHTML = 'Ortsliste öffnen &#187;';
    }  
  } else {
    document.getElementById(id).style.display = 'block';
    if (document.getElementById('webkatalog-search-container-headline-branchenliste-button')){
      document.getElementById('webkatalog-search-container-headline-branchenliste-button').innerHTML = 'Ortsliste schließen &#171;';
    }
  }
}


function addShopingCard(cookieName, idx){
  if (! navigator.cookieEnabled){
    if (idx){
      alert('Um die Funktion >>Merkliste<< zu nutzen, müssen Sie Cookies erlauben!');
    }
    return false;
  }
  if (! cookieName){
    return false;
  }
  
  var shopingcard = {};
  var shopingcardLength = 0;
  var cookieValue = Tools.getCookieValue(cookieName);
  if (cookieValue.length){
    var idxArr = cookieValue.split(/,/);
    for (var i=0; i<idxArr.length; i++){
      shopingcard[idxArr[i]] = idxArr[i];
      shopingcardLength++;
    }
  }  
  if (idx){
    if (shopingcard[idx]){
      return false;
    }
    shopingcard[idx] = idx;
    shopingcardLength++;
    if (cookieValue.length){
      cookieValue += ',';
    }
    cookieValue += idx;
    Tools.setCookieValue(cookieValue, cookieName);
  }  
  var elem = document.getElementById('basic-navigation-shopingcard');
  if (! elem){
    return false;
  }
  var txt = shopingcardLength;
  if (shopingcardLength == 1){
    txt += ' Eintrag';
  } else {
    txt += ' Einträge';
  }
  elem.innerHTML = txt; 
}


function deleteFromShopingCard(cookieName, idx){
  if (! navigator.cookieEnabled){
    if (idx){
      alert('Um die Funktion >>Merkliste<< zu nutzen, müssen Sie Cookies erlauben!');
    }
    return false;
  }
  if (! cookieName){
    return false;
  }
  
  var shopingcard = {};
  var shopingcardLength = 0;
  var cookieValue = Tools.getCookieValue(cookieName);
  if (cookieValue.length){
    var idxArr = cookieValue.split(/,/);
    for (var i=0; i<idxArr.length; i++){
      shopingcard[idxArr[i]] = idxArr[i];
      shopingcardLength++;
    }
  }  
  if (idx){
    if (shopingcard[idx]){
      delete shopingcard[idx];
    }
    shopingcardLength--;
    cookieValue = '';
    for (var i in shopingcard){
      if (cookieValue.length && shopingcardLength > 1){
        cookieValue += ',';
      }
      cookieValue += shopingcard[i];
    }
    Tools.setCookieValue(cookieValue, cookieName);
  }  
  showNotePadList();  
}


function zoomWebkatalogAZContainer(direction) {
  if (!direction){
    return false;
  }
  var elem = document.getElementById('webkatalog-search-az-container-content');
  if (!elem){
    return false;
  }
  var diff = 25;
  var minHeight = 50;
  var setHeight = parseFloat(elem.style.height);
  if (direction == 'in'){
    setHeight += diff;
  } else {
    if ((setHeight - diff) >= minHeight){
      setHeight -= diff;
    }
  }
  if (! document.all){
    setHeight = setHeight + 'px';
  }
  elem.style.height = setHeight;
}

function showNotePadList(prefix) {
  if (! prefix){
    prefix = CMS_PREFIX;
  }
  var _str = Tools.getCookieValue('webkatalog');
  var _list = _str.split(/\,/);
  if (! _list.length){
    alert('Es liegen keine Einträge in Ihrer Merkliste vor.');
    return;
  }
  var _url = prefix;
  _url += '&amp;_sprache=notepad&amp;_bereich=artikel&amp;_aktion=suche_rubrik&amp;_seitenlaenge=200&amp;idrubrik=1009&amp;_sortierung=titel_asc'
  for (var i=0; i<_list.length;i++){
    _url += '&amp;idartikel=' + _list[i];
  }
  window.location = _url;
}  

function openGisDetail(url) {
  if (! url){
    return false;
  }
  var win = window.open(url, 'gisdetail','width=800,height=600,scrollbars=no,menubar=no');
  win.focus();
  return false;
}

function showIframeLeft(url) {
  if (! url){
    return false;
  }
  url = encodeURIComponent(url);
  var iFrameURL = '/cgi-bin/cms?_SID=fake&_bereich=ansicht&_aktion=detail&schluessel=extern_left&_template_variant=' + url;
  window.location = iFrameURL;
}

function showIframeHunderttausend(url) {
  if (! url){
    return false;
  }
  url = encodeURIComponent(url);
  var iFrameURL = '/cgi-bin/cms?_SID=fake&_bereich=ansicht&_aktion=detail&schluessel=hunderttausend&_template_variant=' + url;
  window.location = iFrameURL;
}
                      
function checkVerzeichnis(elem) {
  var verzeichnisLength = 5;
  var boxes = document['myform']['_verzeichnis_baum'];
  if (! boxes){
    return false;
  }
  var count = 0;
  for (var i=0; i<boxes.length; i++){
    if (! boxes[i].checked){
      continue;
    }
    count++;
    if (count > verzeichnisLength){
      alert('Bitte nur ' + verzeichnisLength + ' Verzeichnisse auswählen.');
      if (elem) {
        elem.checked = false;
      }
      return false;
    }
  }
  return true;
}
                      
function setVerzeichnis(elem) {
  var verzeichnisLength = 5;
  var boxes = document['myform']['_verzeichnis_baum'];
  if (boxes){
    var count = 0;
    for (var i=0; i<boxes.length; i++){
      if (! boxes[i].checked){
        continue;
      }
      count++;
      document['myform']['verzeichnis' + count].value = boxes[i].value;
    }
    if (count < verzeichnisLength){
      for (var ii = verzeichnisLength; ii > count; ii--){
        document['myform']['verzeichnis' + ii].value = '';
      }
    }
  }
  var bol = Tools.checkRequiredData(document['myform']);
  return bol;
}

function showTree(elem){
  if (! elem){
    return;
  }
  var containerID = '_container_' + elem.id.toString().replace(/^_anchor_/,'');
  var container = document.getElementById(containerID);
  if (! container){
    return;
  }
  if (container.style.display == 'block'){
    container.style.display = 'none';
    elem.className = 'tree_closed_button';
  } else {
    container.style.display = 'block';
    elem.className = 'tree_open_button';
  }
  return;
}

