j$(document).ready(function() {
  j$().fancybox({
    selector: '.multibox',
    arrows: false,
    infobar: false,
    buttons: [
      'close'
    ],
    caption: function(instance, item) {
      return j$(this).find('.caption').html();
    },
    lang: 'nl',
    i18n: {
      nl: {
        CLOSE: "Sluiten",
        NEXT: "Volgende",
        PREV: "Vorige",
        ERROR: "De opgevraagde content kon niet worden geladen. <br/> Probeer later opnieuw.",
        PLAY_START: "Diavoorstelling starten",
        PLAY_STOP: "Diavoorstelling pauzeren",
        FULL_SCREEN: "Volledig scherm",
        THUMBS: "Miniaturen",
        DOWNLOAD: "Downloaden",
        SHARE: "Delen",
        ZOOM: "Zoom"
      }
    }
  });
});

/**
*  Ajax Autocomplete for jQuery, version 1.4.10
*  (c) 2017 Tomas Kirda
*
*  Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
*  For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
*/
!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports&&"function"==typeof require?require("jquery"):jQuery)}(function(a){"use strict";function b(c,d){var e=this;e.element=c,e.el=a(c),e.suggestions=[],e.badQueries=[],e.selectedIndex=-1,e.currentValue=e.element.value,e.timeoutId=null,e.cachedResponse={},e.onChangeTimeout=null,e.onChange=null,e.isLocal=!1,e.suggestionsContainer=null,e.noSuggestionsContainer=null,e.options=a.extend(!0,{},b.defaults,d),e.classes={selected:"autocomplete-selected",suggestion:"autocomplete-suggestion"},e.hint=null,e.hintValue="",e.selection=null,e.initialize(),e.setOptions(d)}function c(a,b,c){return a.value.toLowerCase().indexOf(c)!==-1}function d(b){return"string"==typeof b?a.parseJSON(b):b}function e(a,b){if(!b)return a.value;var c="("+g.escapeRegExChars(b)+")";return a.value.replace(new RegExp(c,"gi"),"<strong>$1</strong>").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/&lt;(\/?strong)&gt;/g,"<$1>")}function f(a,b){return'<div class="autocomplete-group">'+b+"</div>"}var g=function(){return{escapeRegExChars:function(a){return a.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},createNode:function(a){var b=document.createElement("div");return b.className=a,b.style.position="absolute",b.style.display="none",b}}}(),h={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40},i=a.noop;b.utils=g,a.Autocomplete=b,b.defaults={ajaxSettings:{},autoSelectFirst:!1,appendTo:"body",serviceUrl:null,lookup:null,onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},formatResult:e,formatGroup:f,delimiter:null,zIndex:9999,type:"GET",noCache:!1,onSearchStart:i,onSearchComplete:i,onSearchError:i,preserveInput:!1,containerClass:"autocomplete-suggestions",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:c,paramName:"query",transformResult:d,showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1},b.prototype={initialize:function(){var c,d=this,e="."+d.classes.suggestion,f=d.classes.selected,g=d.options;d.element.setAttribute("autocomplete","off"),d.noSuggestionsContainer=a('<div class="autocomplete-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),d.suggestionsContainer=b.utils.createNode(g.containerClass),c=a(d.suggestionsContainer),c.appendTo(g.appendTo||"body"),"auto"!==g.width&&c.css("width",g.width),c.on("mouseover.autocomplete",e,function(){d.activate(a(this).data("index"))}),c.on("mouseout.autocomplete",function(){d.selectedIndex=-1,c.children("."+f).removeClass(f)}),c.on("click.autocomplete",e,function(){d.select(a(this).data("index"))}),c.on("click.autocomplete",function(){clearTimeout(d.blurTimeoutId)}),d.fixPositionCapture=function(){d.visible&&d.fixPosition()},a(window).on("resize.autocomplete",d.fixPositionCapture),d.el.on("keydown.autocomplete",function(a){d.onKeyPress(a)}),d.el.on("keyup.autocomplete",function(a){d.onKeyUp(a)}),d.el.on("blur.autocomplete",function(){d.onBlur()}),d.el.on("focus.autocomplete",function(){d.onFocus()}),d.el.on("change.autocomplete",function(a){d.onKeyUp(a)}),d.el.on("input.autocomplete",function(a){d.onKeyUp(a)})},onFocus:function(){var a=this;a.fixPosition(),a.el.val().length>=a.options.minChars&&a.onValueChange()},onBlur:function(){var b=this,c=b.options,d=b.el.val(),e=b.getQuery(d);b.blurTimeoutId=setTimeout(function(){b.hide(),b.selection&&b.currentValue!==e&&(c.onInvalidateSelection||a.noop).call(b.element)},200)},abortAjax:function(){var a=this;a.currentRequest&&(a.currentRequest.abort(),a.currentRequest=null)},setOptions:function(b){var c=this,d=a.extend({},c.options,b);c.isLocal=Array.isArray(d.lookup),c.isLocal&&(d.lookup=c.verifySuggestionsFormat(d.lookup)),d.orientation=c.validateOrientation(d.orientation,"bottom"),a(c.suggestionsContainer).css({"max-height":d.maxHeight+"px",width:d.width+"px","z-index":d.zIndex}),this.options=d},clearCache:function(){this.cachedResponse={},this.badQueries=[]},clear:function(){this.clearCache(),this.currentValue="",this.suggestions=[]},disable:function(){var a=this;a.disabled=!0,clearTimeout(a.onChangeTimeout),a.abortAjax()},enable:function(){this.disabled=!1},fixPosition:function(){var b=this,c=a(b.suggestionsContainer),d=c.parent().get(0);if(d===document.body||b.options.forceFixPosition){var e=b.options.orientation,f=c.outerHeight(),g=b.el.outerHeight(),h=b.el.offset(),i={top:h.top,left:h.left};if("auto"===e){var j=a(window).height(),k=a(window).scrollTop(),l=-k+h.top-f,m=k+j-(h.top+g+f);e=Math.max(l,m)===l?"top":"bottom"}if("top"===e?i.top+=-f:i.top+=g,d!==document.body){var n,o=c.css("opacity");b.visible||c.css("opacity",0).show(),n=c.offsetParent().offset(),i.top-=n.top,i.top+=d.scrollTop,i.left-=n.left,b.visible||c.css("opacity",o).hide()}"auto"===b.options.width&&(i.width=b.el.outerWidth()+"px"),c.css(i)}},isCursorAtEnd:function(){var a,b=this,c=b.el.val().length,d=b.element.selectionStart;return"number"==typeof d?d===c:!document.selection||(a=document.selection.createRange(),a.moveStart("character",-c),c===a.text.length)},onKeyPress:function(a){var b=this;if(!b.disabled&&!b.visible&&a.which===h.DOWN&&b.currentValue)return void b.suggest();if(!b.disabled&&b.visible){switch(a.which){case h.ESC:b.el.val(b.currentValue),b.hide();break;case h.RIGHT:if(b.hint&&b.options.onHint&&b.isCursorAtEnd()){b.selectHint();break}return;case h.TAB:if(b.hint&&b.options.onHint)return void b.selectHint();if(b.selectedIndex===-1)return void b.hide();if(b.select(b.selectedIndex),b.options.tabDisabled===!1)return;break;case h.RETURN:if(b.selectedIndex===-1)return void b.hide();b.select(b.selectedIndex);break;case h.UP:b.moveUp();break;case h.DOWN:b.moveDown();break;default:return}a.stopImmediatePropagation(),a.preventDefault()}},onKeyUp:function(a){var b=this;if(!b.disabled){switch(a.which){case h.UP:case h.DOWN:return}clearTimeout(b.onChangeTimeout),b.currentValue!==b.el.val()&&(b.findBestHint(),b.options.deferRequestBy>0?b.onChangeTimeout=setTimeout(function(){b.onValueChange()},b.options.deferRequestBy):b.onValueChange())}},onValueChange:function(){if(this.ignoreValueChange)return void(this.ignoreValueChange=!1);var b=this,c=b.options,d=b.el.val(),e=b.getQuery(d);return b.selection&&b.currentValue!==e&&(b.selection=null,(c.onInvalidateSelection||a.noop).call(b.element)),clearTimeout(b.onChangeTimeout),b.currentValue=d,b.selectedIndex=-1,c.triggerSelectOnValidInput&&b.isExactMatch(e)?void b.select(0):void(e.length<c.minChars?b.hide():b.getSuggestions(e))},isExactMatch:function(a){var b=this.suggestions;return 1===b.length&&b[0].value.toLowerCase()===a.toLowerCase()},getQuery:function(b){var c,d=this.options.delimiter;return d?(c=b.split(d),a.trim(c[c.length-1])):b},getSuggestionsLocal:function(b){var c,d=this,e=d.options,f=b.toLowerCase(),g=e.lookupFilter,h=parseInt(e.lookupLimit,10);return c={suggestions:a.grep(e.lookup,function(a){return g(a,b,f)})},h&&c.suggestions.length>h&&(c.suggestions=c.suggestions.slice(0,h)),c},getSuggestions:function(b){var c,d,e,f,g=this,h=g.options,i=h.serviceUrl;if(h.params[h.paramName]=b,h.onSearchStart.call(g.element,h.params)!==!1){if(d=h.ignoreParams?null:h.params,a.isFunction(h.lookup))return void h.lookup(b,function(a){g.suggestions=a.suggestions,g.suggest(),h.onSearchComplete.call(g.element,b,a.suggestions)});g.isLocal?c=g.getSuggestionsLocal(b):(a.isFunction(i)&&(i=i.call(g.element,b)),e=i+"?"+a.param(d||{}),c=g.cachedResponse[e]),c&&Array.isArray(c.suggestions)?(g.suggestions=c.suggestions,g.suggest(),h.onSearchComplete.call(g.element,b,c.suggestions)):g.isBadQuery(b)?h.onSearchComplete.call(g.element,b,[]):(g.abortAjax(),f={url:i,data:d,type:h.type,dataType:h.dataType},a.extend(f,h.ajaxSettings),g.currentRequest=a.ajax(f).done(function(a){var c;g.currentRequest=null,c=h.transformResult(a,b),g.processResponse(c,b,e),h.onSearchComplete.call(g.element,b,c.suggestions)}).fail(function(a,c,d){h.onSearchError.call(g.element,b,a,c,d)}))}},isBadQuery:function(a){if(!this.options.preventBadQueries)return!1;for(var b=this.badQueries,c=b.length;c--;)if(0===a.indexOf(b[c]))return!0;return!1},hide:function(){var b=this,c=a(b.suggestionsContainer);a.isFunction(b.options.onHide)&&b.visible&&b.options.onHide.call(b.element,c),b.visible=!1,b.selectedIndex=-1,clearTimeout(b.onChangeTimeout),a(b.suggestionsContainer).hide(),b.signalHint(null)},suggest:function(){if(!this.suggestions.length)return void(this.options.showNoSuggestionNotice?this.noSuggestions():this.hide());var b,c=this,d=c.options,e=d.groupBy,f=d.formatResult,g=c.getQuery(c.currentValue),h=c.classes.suggestion,i=c.classes.selected,j=a(c.suggestionsContainer),k=a(c.noSuggestionsContainer),l=d.beforeRender,m="",n=function(a,c){var f=a.data[e];return b===f?"":(b=f,d.formatGroup(a,b))};return d.triggerSelectOnValidInput&&c.isExactMatch(g)?void c.select(0):(a.each(c.suggestions,function(a,b){e&&(m+=n(b,g,a)),m+='<div class="'+h+'" data-index="'+a+'">'+f(b,g,a)+"</div>"}),this.adjustContainerWidth(),k.detach(),j.html(m),a.isFunction(l)&&l.call(c.element,j,c.suggestions),c.fixPosition(),j.show(),d.autoSelectFirst&&(c.selectedIndex=0,j.scrollTop(0),j.children("."+h).first().addClass(i)),c.visible=!0,void c.findBestHint())},noSuggestions:function(){var b=this,c=b.options.beforeRender,d=a(b.suggestionsContainer),e=a(b.noSuggestionsContainer);this.adjustContainerWidth(),e.detach(),d.empty(),d.append(e),a.isFunction(c)&&c.call(b.element,d,b.suggestions),b.fixPosition(),d.show(),b.visible=!0},adjustContainerWidth:function(){var b,c=this,d=c.options,e=a(c.suggestionsContainer);"auto"===d.width?(b=c.el.outerWidth(),e.css("width",b>0?b:300)):"flex"===d.width&&e.css("width","")},findBestHint:function(){var b=this,c=b.el.val().toLowerCase(),d=null;c&&(a.each(b.suggestions,function(a,b){var e=0===b.value.toLowerCase().indexOf(c);return e&&(d=b),!e}),b.signalHint(d))},signalHint:function(b){var c="",d=this;b&&(c=d.currentValue+b.value.substr(d.currentValue.length)),d.hintValue!==c&&(d.hintValue=c,d.hint=b,(this.options.onHint||a.noop)(c))},verifySuggestionsFormat:function(b){return b.length&&"string"==typeof b[0]?a.map(b,function(a){return{value:a,data:null}}):b},validateOrientation:function(b,c){return b=a.trim(b||"").toLowerCase(),a.inArray(b,["auto","bottom","top"])===-1&&(b=c),b},processResponse:function(a,b,c){var d=this,e=d.options;a.suggestions=d.verifySuggestionsFormat(a.suggestions),e.noCache||(d.cachedResponse[c]=a,e.preventBadQueries&&!a.suggestions.length&&d.badQueries.push(b)),b===d.getQuery(d.currentValue)&&(d.suggestions=a.suggestions,d.suggest())},activate:function(b){var c,d=this,e=d.classes.selected,f=a(d.suggestionsContainer),g=f.find("."+d.classes.suggestion);return f.find("."+e).removeClass(e),d.selectedIndex=b,d.selectedIndex!==-1&&g.length>d.selectedIndex?(c=g.get(d.selectedIndex),a(c).addClass(e),c):null},selectHint:function(){var b=this,c=a.inArray(b.hint,b.suggestions);b.select(c)},select:function(a){var b=this;b.hide(),b.onSelect(a)},moveUp:function(){var b=this;if(b.selectedIndex!==-1)return 0===b.selectedIndex?(a(b.suggestionsContainer).children("."+b.classes.suggestion).first().removeClass(b.classes.selected),b.selectedIndex=-1,b.ignoreValueChange=!1,b.el.val(b.currentValue),void b.findBestHint()):void b.adjustScroll(b.selectedIndex-1)},moveDown:function(){var a=this;a.selectedIndex!==a.suggestions.length-1&&a.adjustScroll(a.selectedIndex+1)},adjustScroll:function(b){var c=this,d=c.activate(b);if(d){var e,f,g,h=a(d).outerHeight();e=d.offsetTop,f=a(c.suggestionsContainer).scrollTop(),g=f+c.options.maxHeight-h,e<f?a(c.suggestionsContainer).scrollTop(e):e>g&&a(c.suggestionsContainer).scrollTop(e-c.options.maxHeight+h),c.options.preserveInput||(c.ignoreValueChange=!0,c.el.val(c.getValue(c.suggestions[b].value))),c.signalHint(null)}},onSelect:function(b){var c=this,d=c.options.onSelect,e=c.suggestions[b];c.currentValue=c.getValue(e.value),c.currentValue===c.el.val()||c.options.preserveInput||c.el.val(c.currentValue),c.signalHint(null),c.suggestions=[],c.selection=e,a.isFunction(d)&&d.call(c.element,e)},getValue:function(a){var b,c,d=this,e=d.options.delimiter;return e?(b=d.currentValue,c=b.split(e),1===c.length?a:b.substr(0,b.length-c[c.length-1].length)+a):a},dispose:function(){var b=this;b.el.off(".autocomplete").removeData("autocomplete"),a(window).off("resize.autocomplete",b.fixPositionCapture),a(b.suggestionsContainer).remove()}},a.fn.devbridgeAutocomplete=function(c,d){var e="autocomplete";return arguments.length?this.each(function(){var f=a(this),g=f.data(e);"string"==typeof c?g&&"function"==typeof g[c]&&g[c](d):(g&&g.dispose&&g.dispose(),g=new b(this,c),f.data(e,g))}):this.first().data(e)},a.fn.autocomplete||(a.fn.autocomplete=a.fn.devbridgeAutocomplete)});

j$(document).ready(function()
{
  // Alle tekstvelden met class autocomplete worden automatisch geïnitieerd bij een onfocus
  
  j$('body').on('focus', 'input[type=text].autocomplete', function()
  {
    setAutocomplete(this);
  });
  
// j$('input[type=text].autocomplete').each(function(index, element)
// {
//   setAutocomplete(element);
// });
});

function setAutocomplete(element)
{
  element = j$(element);
  
  if (j$(element).hasClass("autocompleteInitialized"))
  {
    return;
  }
  j$(element).addClass("autocompleteInitialized");
  
  var additionalFilterStr;
  additionalFilterStr = element.attr('data-additionalFilter');
  
  var parentFilterField = '';
  var parentFilterValue = '';
  if (typeof additionalFilterStr !== typeof undefined && additionalFilterStr !== false) {
    var additionalFilters = additionalFilterStr.split('|');
    parentFilterField = additionalFilters[0];
    parentFilterValue = additionalFilters[1];
  }

  var excludeselector = element.attr('data-exclude');
  var excludestring;
  
  j$(excludeselector).each(function() { excludestring += "|"; excludestring +=j$(this).val(); });

  options = {
    lookup: eval(element.attr('data-lookup')),
    serviceUrl: '/contact/search-employees?waxtrapp=iowxdzEsHowOvvOhIGKN&token=MjcyMzQxMDczMzEzNDc1ODlopTxRD0Oo17%2BtqwLcX5MDStfofl9iP3TNHnT2BSWMujfI%2B0m9KFvaRpxebEV96oA%3D&config='+element.attr('data-config')+'&parentFilterField='+parentFilterField+'&parentFilterValue='+parentFilterValue+'&exclude='+excludestring,
    type:"POST",
    appendTo: element.parent(), 
    maxHeight: 155,
    deferRequestBy: 100,
    formatResult: function (suggestion, currentValue) { return suggestion.display; },
    noCache: true,
    autoSelectFirst: true,
    showNoSuggestionNotice: true,
    noSuggestionNotice: "Geen resultaten gevonden",
    onSelect: function(obj)
    {
      if (element.attr('data-resultto'))
      {
        var inputResultTo = j$("#"+element.attr('data-resultto'));
        inputResultTo.val(obj.data).change();
      }
      if (element.attr('data-onselect'))
      {
        eval(element.attr('data-onselect'));
      }
    }
  };

  element.autocomplete(options);
}

function webservicesCompleteAddressFields(postcode, number, street, place)
{
  j$(document).ready(function()
  {
    if(j$(postcode) && j$(number))
    {
      j$(postcode).change(function()
      {
        if((j$(postcode)[0].value != '') &&
           (j$(number)[0].value != ''))
        {
          webservicesCompleteAddressFieldChanged(postcode, number, street, place);
        }
      });
      j$(number).change(function()
      {
        if((j$(postcode)[0].value != '') &&
           (j$(number)[0].value != ''))
        {
          webservicesCompleteAddressFieldChanged(postcode, number, street, place);
        }
      });
    }
  });
}


function webservicesCompleteAddressFieldChanged(postcode, number, street, place)
{
  j$(street).attr('readonly', true);
  j$(place).attr('readonly', true);

  webservicesGetAddressJson(j$(postcode)[0].value, j$(number)[0].value, function(json)
  {
    // Success

    if(json.faultCode == '')
    {
      j$(street)[0].value = json.street;
      j$(place)[0].value = json.place;
    }
  }, function()
  {
    // Error

  }, function()
  {
    // Complete

    j$(street).attr('readonly', false);
    j$(place).attr('readonly', false);
  });
}


function webservicesGetAddressJson(postcode, number, successCallback, errorCallback, completeCallback)
{
  j$.ajax(
  {
    type: 'GET',
    url: '/contact/search-employees?waxtrapp=iowxdzEsHowOvvOhIGKN&pane=xfsgtekBsHowOvvOhIFYkYpYHcBrB',
    data:
    {
      postcode: postcode,
      number: number
    },
    success: function(json, textStatus, jqXHR)
    {
      if (successCallback)
      {
        successCallback(json, textStatus, jqXHR);
      }
    },
    error: function(jqXHR, textStatus, errorThrown)
    {
      if (errorCallback)
      {
        errorCallback(jqXHR, textStatus, errorThrown);
      }
    },
    complete: function(jqXHR, textStatus)
    {
      if (completeCallback)
      {
        completeCallback(jqXHR, textStatus);
      }
    },
    dataType: 'json'
  });
}



var recallAutoloadCooldown = false;

j$(document).ready(function()
{
  j$(document).on('click', '[data-recall-accept~="refresh"], [data-recall-accept~="refreshRemote"]', function (event)
  {
    
    event.preventDefault();
    
    if (j$(this).is('[data-recall-accept~="refreshRemote"]'))
    {
      return recallDoCall(this, 'refreshRemote');
    }
    else
    {
      return recallDoCall(this, 'refresh');    
    }
  });

  j$(document).on('click', 'a[data-recall]', function (event)
  {
    var returnVal = true;

    if (j$(this).is('[data-recall~="getRemote"]'))
    {
      returnVal = recallDoCall(this, 'getRemote');
    }
    else
    {
      returnVal = recallDoCall(this, 'get');    
    }

    if (returnVal == false)
    {
      
      event.preventDefault();
    }
  });

  j$(document).on('submit', ':has(> form[data-recall]), :has(> form.recall.post), :has(> form.recall.postRemote)', function (event)
  {
    
    var form = event.target;

    if (j$(form).is('[data-recall~="postRemote"], .postRemote'))
    {
      return recallPost(form, 'postRemote');
    }
    else
    {
      return recallPost(form, 'post');    
    }
  });

  
  setTimeout(function()
  {
    recallAutoloadVisible();
  }, 100);

  j$(document).on('click', 'body', function()
  {
    recallAutoloadVisible();
  });

  j$(window).on('resize scroll', function()
  {
    if (recallAutoloadCooldown == true) return;

    recallAutoloadCooldown = true;

    setTimeout(function()
    {
      recallAutoloadCooldown = false;
    }, 400);

    recallAutoloadVisible();
  });
});

function recallAutoloadVisible()
{
  var elements = j$(':not(.recallBusy) > [data-recall-accept~="autoload"], :not(.recallBusy) > [data-recall-accept~="autoloadRemote"]');

  // Return immediately if there aren't any matching elements
  if (elements.length === 0) return;

  elements.each(function()
  {
    // Check visibility of each element including its parents and see if the element is actually in the client's view window
    if (j$(this).is(':visible') && (this.getBoundingClientRect().top <= window.innerHeight * 1.1))
    {
      if (j$(this).is('[data-recall-accept~="autoloadRemote"]'))
      {
        recallDoCall(this, 'autoloadRemote');
      }
      else
      {
        recallDoCall(this, 'autoload');   
      }
    }
  });
}

function recallPost(form, trigger, recallPoint)
{
  if (! trigger || trigger == '')
  {
    var trigger = 'post';
    
    if (j$(form).is('[data-recall~="postRemote"], .postRemote'))
    {
      trigger = 'postRemote';
    }
  }
  
  return recallDoCall(form, trigger, recallPoint);
}

function recallFindAnchor(node, trigger)
{
  
  return recallFindRecallPoint(node, trigger);
}

function recallFindRecallPoint(node, trigger)
{
  var recallPoint;

  if (j$(node).attr('data-recall-target'))
  {
    var selector = j$(node).attr('data-recall-target');
    var n = j$(selector)[0];
    
    if (n)
    {
      // Search for anchor relative to the specified target
      return recallFindRecallPoint(n, trigger);
    }
  }

  if (! recallPoint && j$(node).is('[data-recall-accept~="' + trigger + '"]'))
  {
    recallPoint = node;
  }
  
  if (! recallPoint)
  {
    
    recallPoint = j$(node).parents().addBack().find('> [data-recall-accept~="' + trigger + '"]')[0];
  }

  if (! recallPoint && trigger.match('Remote'))
  {
    
    trigger = trigger.replace('Remote', '');
    return recallFindRecallPoint(node, trigger);
  }

  return recallPoint;
}

function recallDoCall(node, trigger, recallPoint)
{
  var remote = false;
  var formData;
  
  if (! recallPoint || recallPoint == '')
  {
    recallPoint = recallFindRecallPoint(node, trigger);
  }
  
  if (! recallPoint)
  {
    return true;
  }
  
  // Check if remote is wanted and supported by recallPoint
  if (trigger.match('Remote') && j$(recallPoint).is('[data-recall-accept~="' + trigger + '"]'))
  {
    // Is remote trigger wanted and supported ?
    remote = true;
    trigger = trigger.replace('Remote', '');
  }
  else
  {
    // Is nonRemote trigger supported ?
    trigger = trigger.replace('Remote', '');

    if (! j$(recallPoint).is('[data-recall-accept~="' + trigger + '"]'))
    {
      // No match between trigger and recallPoint
      return true;
    }
  }
  
  if (remote)
  {
    url = j$(recallPoint).attr('data-recall-remote-url');
  }
  else
  {
    url = j$(recallPoint).attr('data-recall-url');
  }

  if (trigger == 'post')
  {
    formData = new FormData(j$(node)[0]);
    
    var action = j$(node)[0].action;
    action = action.substring(action.indexOf('?')+1).split('&');
    for (var i = 0 ; i < action.length; i++)
    {
      var pair = action[i].split('=');
      formData.append(decodeURIComponent(pair[0]), decodeURIComponent(pair[1]));
    }
  }
  else if (trigger == 'get')
  {
    var href = j$(node)[0].href;
    href = href.substring(href.indexOf('?')+1);
    if (href != '')
    {
      url += '&' + href;
    }
  }

  var target;
  
  /*
  var targetID = j$(recallPoint).attr('id');

  if (targetID.match(/^recallPoint/))
  {
    targetID = targetID.replace(/^recallPoint/, 'recallTarget');
    target = j$('#' + targetID)[0];
  }
  */
  
  if (! target)
  {
    target = j$(recallPoint).parent();
  }
  
  j$(target).addClass('recallBusy');

  j$.ajax(
  {
    type: 'POST',
    url: url,
    data: formData,
    processData: false,
    contentType: false,
    success: function(data)
    {
      j$(target).replaceWith(data);
      return false;
    }
  });
  
  if (j$(node).attr('data-recall-callback'))
  {
    eval(j$(node).attr('data-recall-callback'));
  }
  
  return false;
}

j$(document).ready(function()
{ 
  j$('#crm_zoekform.interactiveSearch input[type=text]').each(function(index, element)
  {
    j$(this).bind('input', function()
    {
      // only search if more than 1 char
      if(element.value.length > 1) { 
        waitForNextKeystroke();
      }
    });
  });

  j$('#crm_zoekform.interactiveSearch input[type=text], #crm_zoekform.interactiveSearch input[type=checkbox], #crm_zoekform.interactiveSearch select').change(function()
  {
    ajaxSearch();
  });

  j$('#content table.searchResults').tablesorter({
    cssAsc: 'desc',
    cssDesc: 'asc',
    sortList: [ [ 0,0 ] ]
  });
});


var keyTimer;

function waitForNextKeystroke()
{
  if(typeof keyTimer !== 'undefined')
  {
    clearTimeout(keyTimer);
  }

  keyTimer = setTimeout(ajaxSearch, 350);
}


function ajaxSearch()
{
  j$.ajax(
  {
    type: 'POST',
    url: '/contact/search-employees?waxtrapp=iowxdzEsHowOvvOhIGKN&pane=fqxktekBsHowOvvOhIFaBwFxGY&interactivesearch=1',
    data: j$('#crm_zoekform').serialize(),
    success: function(data)
    {
      j$('#resultContainer').html(data);
      j$('#zoekSubmit').html('Meer resultaten...');
    }
  });
}


function changeExportAction(format, form)
{
  form.action = '/university-of-humanistic-studies/contact/search-employees.'+format+'?waxtrapp=iowxdzEsHowOvvOhIGKN&pane=djlltekBsHowOvvOhIFaBwFrGeB';
}


function selectAllFields()
{
  j$('#exportOptions input').each(function (index, element)
  {
    element.checked = true;
  });
}


function deselectAllFields()
{
  j$('#exportOptions input').each(function (index, element)
  {
    element.checked = false;
  });
}


var requestsBusy = 0;

function submitFormWhenNotBusy(formObj)
{
  if(requestsBusy > 0)
  {
    setTimeout(function()
    {
      submitFormWhenNotBusy(formObj);
    }, 100);
  }
  else
  {
    formObj[0].submit();
  }
}


function getLatLng(address, targetField)
{
  requestsBusy ++;

  var timerId;
  var timedOut = false;
  var geocoder = new google.maps.Geocoder();

  geocoder.geocode({
    address: address
  },
  function(results, status)
  {
    if (timedOut)
    {
      // this request timed out, so ignore results
      return;
    }
    else
    {
      // this request succeeded, so cancel timer
      clearTimeout(timerId);
    }

    var latlng = '';

    if (status == google.maps.GeocoderStatus.OK)
    {
      latlng = results[0].geometry.location.lat()+','+results[0].geometry.location.lng();
    }
    targetField.value = latlng;

    requestsBusy --;
  });

  timerId = setTimeout(function()
  {
    // the request has timed out, so remove it from busy count
    timedOut = true;
    requestsBusy --;
  }, 500);
}


function addRelation(field, max, perref, title, display)
{
  if ((perref == '') || (title == ''))
  {
    alert('Geen selectie gevonden om toe te voegen.');
  }
  else
  {
    if ((max > 0) && (j$('#relations_'+field).children().length >= max))
    {
      if (max == 1)
      {
        alert('Maximaal 1 relatie toegestaan. Verwijder eerst de huidige relatie.');
      }
      else
      {
        alert('Maximaal '+max+' relaties toegestaan. Verwijder eerst minimaal één huidige relatie.');
      }
      clearRelationSelection(field);
      return;
    }

    if (j$('#'+field+'_relation_'+perref).length > 0)
    {
      alert('Relatie "'+title+'" is reeds aanwezig.');
      clearRelationSelection(field);
      return;
    }

    clearRelationSelection(field);
    j$('#relations_'+field).append('<li id="'+field+'_relation_'+perref+'"><input type="hidden" name="'+field+'" value="'+perref+'" />'+display+'<span>&nbsp;&nbsp;<a class="delete" onclick="deleteRelation(\''+field+'\', \''+perref+'\');"><span class="icon-trash-o" title="Verwijderen" style="vertical-align:sub;"></span></a></span></li>');
  }
}


function clearRelationSelection(field)
{
  j$('#'+field+'_search')[0].value = '';
}


function deleteRelation(field, perref)
{
  j$('#'+field+'_relation_'+perref).remove();
}


function addUploadFile(field)
{
  j$('.uploadFile.'+field+' > .uploads').append('<input name="'+field+'" type="file" /><br />');
}


function deleteUploadFile(field, perref)
{
  var newVal = j$('#'+field+'_delete').val();
  if (newVal != '')
  {
    newVal += ' ';
  }
  newVal += perref;

  j$('#'+field+'_delete').val(newVal);

  j$('#'+field+'_delete_link_'+perref).css('visibility', 'hidden');
  j$('#'+field+'_uploadFile_'+perref).css('text-decoration', 'line-through');
}


function testURL(inputID)
{
  var url = j$('#'+inputID).val();
  window.open(url, (url.indexOf('mailto:') == 0 ? '_self' : '_blank'));
}


function postcodeCheckAndChange(editField)
{
  editField.value = editField.value.toUpperCase();

  if((editField.value.length == 6) &&
     (editField.value[5] != ' '))
  {
    editField.value = editField.value.slice(0, 4)+' '+editField.value.slice(4);
  }
}




j$(document).ready(function()
{
  j$('a[rel="external"]').each(function (index, element)
  {
    element.target = '_blank';

    if (element.title == '')
    {
      element.title = 'Opent in een nieuw venster';
    }
  });
});



j$( function() {


  j$( 'body' ).removeClass( 'JS-OFF' );
  j$( 'body' ).addClass( 'JS-ON' );
  j$( "ul#hoofdNavigatie").addClass( 'active-submenu' );


  if ( document.documentMode) {
    document.body.classList.add("ie");
  }


  j$( ".menuBtn" ).click( function( e ) {
    //reset classes
      j$( "body").removeClass( 'submenu-open' );
      j$( "ul#hoofdNavigatie").removeClass( 'submenu-open' );
      j$( "ul#hoofdNavigatie *").parent().removeClass( 'active-submenu' );
      j$( "ul#hoofdNavigatie li").removeClass( 'open-submenu' );
      j$( "ul#hoofdNavigatie li ul").removeClass( 'open-item' );
      j$( "ul#hoofdNavigatie").addClass( 'active-submenu' );

    j$( 'body' ).toggleClass( 'menu-open' );
    //gotoActiveMenu(); // naar active menu of naar hoofdmenu? wat is de bedoeling?
    e.preventDefault();
  });

  j$(".snelButtons ul li a").each( function(){
    j$( this ).html(j$( this ).html().replace("<br>", "<br><span></span>"));
  });
  
  j$( ".homeBlok.mobileClose" ).click( function( e ) {
    j$( this ).toggleClass( 'block-closed' );
  });
  j$( ".homeBlok.mobileClose" ).addClass( 'block-closed' );
  j$( ".homeBlok.mobileClose.start-open" ).removeClass( 'block-closed' );

  j$( "#bottom .mobileClose" ).click( function( e ) {
    j$( this ).toggleClass( 'block-open' );
  });

  j$( "#asideWrapper .webletLocationasideMenu.start-open" ).toggleClass( 'block-open' );

  j$( "#asideWrapper .webletLocationasideMenu .webletTitle" ).click( function( e ) {
    j$( "#asideWrapper .webletLocationasideMenu" ).toggleClass( 'block-open' );
  });
  
  
   
   
  
  var searchBox = j$( "#searchBox" );
  var searchFieldSet = j$( "#top .webletLocationzoek" );
  var webletLocationlinkButtons = j$( "#top .webletLocationlinkButton ul" );
  
  if (( searchBox.length == 1 ) && ( searchFieldSet.length == 1 )) {
    //move searchBox to #searchBox
    searchFieldSet.detach().appendTo( "#searchBox" );
    
    j$( "#menu .webletLocationmijnUvh" ).append( '<div class="searchLinks onlyMobile"><ul>' + webletLocationlinkButtons.html() + '</ul></div>' );
  }

  j$( ".zoekBtn" ).click( function( e ) {
    searchBox.toggleClass( 'search-open' );
    e.preventDefault();
  });

});
j$( function() {
 
//   j$( 'body' ).toggleClass( 'menu-open' );
   
  j$( "#menu ul#hoofdNavigatie li>a" ).click( function( e ) {
    var stopClick = false;
    activeItem = j$( this ).parent();
   if ( j$( 'body.menu-open' ).length > 0 ) {
     if ( activeItem.hasClass( "active-submenu") ) {
        j$( "ul#hoofdNavigatie li ul").removeClass( 'open-item' );
        j$( "ul#hoofdNavigatie *").parent().removeClass( 'active-submenu' );
        if ( activeItem.parent().hasClass( "submenu-open")) {
        // =back to HoofdNavigatie - reset classes 
          j$( "ul#hoofdNavigatie").removeClass( 'submenu-open' ).addClass( 'active-submenu' );
          j$( "ul#hoofdNavigatie li").removeClass( 'open-submenu' );
          j$( "body").removeClass( 'submenu-open' );
        } else {
          activeItem.parent().parent().addClass( 'active-submenu' );
          j$( 'li.active-submenu>ul' ).addClass( 'open-item' );
          activeItem.removeClass( 'open-submenu' );
        }
        stopClick = true;
      } else {
        if ( activeItem.find( "ul").length > 0 ) {
          j$( "ul#hoofdNavigatie *").parent().removeClass( 'active-submenu' );
          j$( "ul#hoofdNavigatie li ul").removeClass( 'open-item' );

          j$( "body").addClass( 'submenu-open' );
          j$( "ul#hoofdNavigatie").addClass( 'submenu-open' );
          activeItem.addClass( 'open-submenu' );
          activeItem.addClass( 'active-submenu' );
          activeItem.find( ">ul").addClass( 'open-item' );
          stopClick = true;
        }  
      }
   }
    if ( stopClick == true ){
      e.preventDefault();
    } 
  });
  
});

  function gotoActiveMenu() {
    j$( "#hoofdNavigatie.active-submenu>li.selected>a.selected" ).click();
    for (i = 0; i < 3; i++) { 
      var item = j$( "#hoofdNavigatie li.active-submenu>ul.open-item>li.selected>a.selected" );
      if ( item.length > 0 ) {
        item.click();
      }         
    } 
  }


  j$(document).ready(function(){

  var link = j$('a[data-toggle="dropdown"]');
  var tabCount = 0; 
  var lastObjTabbed;

    
  link.on('touchstart',function(event) {
    if ( lastObjTabbed == this ) {
      
      tabCount++
    } else { 
      tabCount = 1; 
    }
    lastObjTabbed = this;
  });

  link.on('click',function(event) {
    
    var $this = j$(this);
    if ( tabCount != 1 ) {
      tabCount = 0; //reset tabCount
      
      var hambBtnID = $this.closest('.navbar-collapse').attr('id');
      
      var $hambBtn = j$('button[data-target="#'+hambBtnID+'"]');
      var $webletDiv = $this.closest('.webletnavigation');
      var autonav = $webletDiv.hasClass('autonav' );
      var openmenu = $this.attr('aria-expanded') == 'true';

      if ( ( (( $hambBtn.attr('aria-expanded') == 'true' ) &&  openmenu )
            || (( $hambBtn.attr('aria-expanded') == null ) && ( autonav || openmenu ) )
           ) && ( $this.attr('href') != null ) ) {
        window.location.href = $this.attr('href');
              
        event.stopPropagation();
      }  
    }
  });

});    