function startAutoComplete(searchBoxId, autoSuggestDiv, searchTypes, noSubmit) {
    function autoCompleteUElement(li) {
        $(searchBoxId).value = li.innerHTML;

        if(noSubmit !== true) {
            $(searchBoxId).form.submit();
        }
    }

  if(document.readyState == "complete") {
      new Ajax.Autocompleter(searchBoxId,autoSuggestDiv,'/beroep/sAutoComplete?'+searchTypes, {
        frequency: 0.4,
        minChars: 2,
        updateElement: autoCompleteUElement
      });
  }else{
    Event.observe(window, 'load', function() {
      new Ajax.Autocompleter(searchBoxId,autoSuggestDiv,'/beroep/sAutoComplete?'+searchTypes, {
        frequency: 0.4,
        minChars:2,
        updateElement: autoCompleteUElement
      });
    });
  }
}

function mouseEnterLink(id) {
    if(document.getElementById("newsBackgroundImage"+id).style.display != "block") {
        hideAllNews();

        document.getElementById("newsBackgroundImage"+id).style.display = "block";
        document.getElementById("textphotolink"+id).style.display = "block";
    }
}

function mouseExitLink(id) {
    var children = document.getElementById("newsBackgroundImage").children;
    if(children[0].style.display != "block") {
        hideAllNews();
        children[0].style.display = "block";
        var children = document.getElementById("textphotolink").children;
        children[0].style.display = "block";
    }
}

function hideAllNews() {
    var children = document.getElementById("newsBackgroundImage").children;
    for(var i=0;i<children.length;i++) {
        children[i].style.display = "none";
    }

    var children = document.getElementById("textphotolink").children;
    for(var i=0;i<children.length;i++) {
        children[i].style.display = "none";
    }
}

function expandFilterbox(filterboxId) {
    var filterBox = $(filterboxId);

    $A(filterBox.children).each(function(child) {
        child.style.display = 'list-item';
    });

    $(filterboxId+"_expand").style.display='none';
}

function shrinkFilterbox(filterboxId) {
    var filterBox = $(filterboxId);

    var counter = 0;
    $A(filterBox.children).each(function(child) {
        counter++;

        if(counter > 3)
            child.style.display = 'none';
    });

    $(filterboxId+"_expand").style.display='list-item';
}

function html2entities(value){
    var re=/[(<>"'&]/g
    return value.replace(re, function(m){return replacechar(m)})
}

function replacechar(match){
    if (match=="<")
    return "&lt;"
    else if (match==">")
    return "&gt;"
    else if (match=="\"")
    return "&quot;"
    else if (match=="'")
    return "&#039;"
    else if (match=="&")
    return "&amp;"
}
