var RegulationAllSwitcher={
  allcheckbox:{},
  otherCheckboxes:[],
  doKill:function(){
    var nonechecked=true;
    var allchecked=true;
    for(var i=0;i<RegulationAllSwitcher.otherCheckboxes.length;i++){
      if(RegulationAllSwitcher.otherCheckboxes[i].id!=RegulationAllSwitcher.allcheckbox.id){
        if(RegulationAllSwitcher.otherCheckboxes[i].checked==true){
          nonechecked=false;
        }
        if(RegulationAllSwitcher.otherCheckboxes[i].checked==false){
          allchecked=false;
        }
      }
    }
    if(!nonechecked){
      RegulationAllSwitcher.allcheckbox.checked=false;
    }else{
      RegulationAllSwitcher.allcheckbox.checked=true;
    };

    if(allchecked){
      RegulationAllSwitcher.doSwitch();
      RegulationAllSwitcher.allcheckbox.checked=true;
    }
  },
  doSwitch:function(){
    for(var i=0;i<RegulationAllSwitcher.otherCheckboxes.length;i++){
      if(RegulationAllSwitcher.otherCheckboxes[i].id!=RegulationAllSwitcher.allcheckbox.id){
        RegulationAllSwitcher.otherCheckboxes[i].checked=false;
      }
    }
  },
  init:function(){
    RegulationAllSwitcher.allcheckbox=document.getElementById('regulation_type_all');
    if(RegulationAllSwitcher.allcheckbox!='undefined'){
      var otherCheckboxes=document.getElementsByName('regulation_types[]');
      for(var i=0;i<otherCheckboxes.length;i++){
    	  if (otherCheckboxes[i].id != 'regulation_type_all_with_BES' && otherCheckboxes[i].id != 'regulation_type_bes_only')
    	  {
    		  RegulationAllSwitcher.otherCheckboxes[i]=otherCheckboxes[i];
    	  }
      }
      (document.getElementById('zbo')?RegulationAllSwitcher.otherCheckboxes.push(document.getElementById('zbo')):null);
      (document.getElementById('pbo')?RegulationAllSwitcher.otherCheckboxes.push(document.getElementById('pbo')):null);
       for(var i=0;i<RegulationAllSwitcher.otherCheckboxes.length;i++){
        if(RegulationAllSwitcher.otherCheckboxes[i].id!=RegulationAllSwitcher.allcheckbox.id){
          Core.addEventListener(RegulationAllSwitcher.otherCheckboxes[i],'click',RegulationAllSwitcher.doKill)
        }
      }
        Core.addEventListener(RegulationAllSwitcher.allcheckbox,'click',RegulationAllSwitcher.doSwitch);
    }
  }
};

Core.start(RegulationAllSwitcher);
var SearchTermFuzzyButton={
  fuzzytitle:{},
  abbrtitle:{},
  fuzzytext:{},
  abbrtext:{},
  switcher:function(clicked){
    if(SearchTermFuzzyButton.fuzzytitle.checked){
      SearchTermFuzzyButton.abbrtitle.disabled=false;
    }
    if(SearchTermFuzzyButton.abbrtitle.checked&&clicked.id==SearchTermFuzzyButton.abbrtitle.id){
      SearchTermFuzzyButton.fuzzytitle.checked=true;
    }
    if(!SearchTermFuzzyButton.fuzzytitle.checked){
      SearchTermFuzzyButton.abbrtitle.disabled=true;
    }
  },
  killListener:function(e){
    SearchTermFuzzyButton.switcher(this.id);
  },
  init:function(){
    (document.getElementById('title_exact_search')?SearchTermFuzzyButton.fuzzytitle=document.getElementById('title_exact_search'):null);
    (document.getElementById('afkorting')?SearchTermFuzzyButton.abbrtitle=document.getElementById('afkorting'):null);
    Core.addEventListener(SearchTermFuzzyButton.fuzzytitle,'click',SearchTermFuzzyButton.killListener);
    Core.addEventListener(SearchTermFuzzyButton.abbrtitle,'click',SearchTermFuzzyButton.killListener);
  }
};

Core.start(SearchTermFuzzyButton);
var DateSearchForType={
  regulationSelected:function(){
    document.getElementById('date_for_totstandkoming').disabled=false;
    VerdragOptionCheck.checker();
  },
  articleSelected:function(){
    document.getElementById('date_for_totstandkoming').disabled=true;
    if(document.getElementById('date_for_totstandkoming').disabled&&!document.getElementById('date_for_ondertekening').checked){
      document.getElementById('date_for_inwerkingtreding').checked=true;
    }
  },
  init:function(){
    if(document.getElementById('date_for_regeling')){
      var regulation_option=document.getElementById('date_for_regeling');
      var article_option=document.getElementById('date_for_artikelen');
      Core.addEventListener(regulation_option,'click',DateSearchForType.regulationSelected);
      Core.addEventListener(article_option,'click',DateSearchForType.articleSelected);
    }
  }
};

Core.start(DateSearchForType);
var VerdragOptionCheck={
  otherCheckboxes:[],
  date_for_totstandkoming:{},
  date_for_ondertekening:{},
  date_for_inwerkingtreding:{},
  checkArray:function(){
    if(document.getElementById('date_for_artikelen')&&document.getElementById('date_for_artikelen').checked){
      return true;
    }
    for(var i=0;i<VerdragOptionCheck.otherCheckboxes.length;i++){
      if(VerdragOptionCheck.otherCheckboxes[i].id=='regulation_type_ver'||VerdragOptionCheck.otherCheckboxes[i].id=='regulation_type_all'){
        if(VerdragOptionCheck.otherCheckboxes[i].checked){
          return false;
        }
      }else{
        if(VerdragOptionCheck.otherCheckboxes[i].checked){
          return true;
        }
      }
    }
    return true;
  },
  checkOnlyVerdrag:function(){
    var onlyVerdrag=false;
    for(var i=0;i<VerdragOptionCheck.otherCheckboxes.length;i++){
      if(VerdragOptionCheck.otherCheckboxes[i].id=='regulation_type_ver'&&VerdragOptionCheck.otherCheckboxes[i].checked){
        onlyVerdrag=true;
      }else if(VerdragOptionCheck.otherCheckboxes[i].checked){
        onlyVerdrag=false;
      }
    }
    return onlyVerdrag;
  },
  checker:function(){
    VerdragOptionCheck.date_for_totstandkoming.disabled=VerdragOptionCheck.checkArray();
    VerdragOptionCheck.date_for_ondertekening.disabled=VerdragOptionCheck.checkOnlyVerdrag();
    if(VerdragOptionCheck.date_for_ondertekening.disabled){
      VerdragOptionCheck.date_for_inwerkingtreding.checked=true;
    }
  },
  init:function(){
    var otherCheckboxes=document.getElementsByName('regulation_types[]');
    for(var i=0;i<otherCheckboxes.length;i++){
      VerdragOptionCheck.otherCheckboxes[i]=otherCheckboxes[i];
    }
    (document.getElementById('zbo')?VerdragOptionCheck.otherCheckboxes.push(document.getElementById('zbo')):null);
    (document.getElementById('pbo')?VerdragOptionCheck.otherCheckboxes.push(document.getElementById('pbo')):null);
    (document.getElementById('date_for_totstandkoming')?VerdragOptionCheck.date_for_totstandkoming=document.getElementById('date_for_totstandkoming'):null);
    (document.getElementById('date_for_ondertekening')?VerdragOptionCheck.date_for_ondertekening=document.getElementById('date_for_ondertekening'):null);
    (document.getElementById('date_for_inwerkingtreding')?VerdragOptionCheck.date_for_inwerkingtreding=document.getElementById('date_for_inwerkingtreding'):null);
    if(VerdragOptionCheck.date_for_totstandkoming!=null&&VerdragOptionCheck.date_for_ondertekening!=null){
      for(i=0;i<VerdragOptionCheck.otherCheckboxes.length;i++){
        Core.addEventListener(VerdragOptionCheck.otherCheckboxes[i],'click',VerdragOptionCheck.checker);
      }
      VerdragOptionCheck.checker();
    }
  }
};

Core.start(VerdragOptionCheck);
var EnterSubmit={
  theForm:{},
  search_button:{},
  keyListener:function(evt){
    var key=evt.keyCode;
    if(key==13){
      if(document.dispatchEvent){
        var newEvent=document.createEvent("MouseEvents");
        newEvent.initEvent("click",true,true);
        EnterSubmit.search_button.dispatchEvent(newEvent);
      }else if(document.fireEvent){
        var newEvent=document.createEventObject();
        newEvent.cancelBubble=true;
        EnterSubmit.search_button.focus();
        EnterSubmit.search_button.fireEvent("onclick",newEvent);
      }
    }
  },
  init:function(){
    EnterSubmit.theForm=document.getElementsByTagName('FORM');
    EnterSubmit.search_button=document.getElementById('zoekknop');
    Core.addEventListener(EnterSubmit.theForm[0],'keydown',EnterSubmit.keyListener);
    Core.addEventListener(EnterSubmit.theForm[0],'keyup',EnterSubmit.keyListener);
  }
};

Core.start(EnterSubmit);
var InitPage={
  allcheckbox:{},
  otherCheckboxes:[],
  init:function(){
    InitPage.allcheckbox=document.getElementById('regulation_type_all');
    if(InitPage.allcheckbox!='undefined'){
      var otherCheckboxes=document.getElementsByName('regulation_types[]');
      for(var i=0;i<otherCheckboxes.length;i++){
        if(otherCheckboxes[i].id!=InitPage.allcheckbox.id){
        	if (otherCheckboxes[i].id != 'regulation_type_all_with_BES' && otherCheckboxes[i].id != 'regulation_type_bes_only')
        	{
        		InitPage.otherCheckboxes.push(otherCheckboxes[i]);
        	}
        }
      }
      (document.getElementById('zbo')?InitPage.otherCheckboxes.push(document.getElementById('zbo')):null);
      (document.getElementById('pbo')?InitPage.otherCheckboxes.push(document.getElementById('pbo')):null);
      if(InitPage.allcheckbox.checked){
        if(document.getElementById('date_for_totstandkoming')){
          document.getElementById('date_for_totstandkoming').disabled=false;
        }
        if(document.getElementById('date_for_ondertekening')){
          document.getElementById('date_for_ondertekening').disabled=false;
        }
        for(i=0;i<InitPage.otherCheckboxes.length;i++){
          InitPage.otherCheckboxes[i].checked=false;
        }
      }else{
        var onlyVerdragen=false;
        var verdragenChecked=false;
        for(i=0;i<InitPage.otherCheckboxes.length;i++){
          if(document.getElementById('regulation_type_ver')&&document.getElementById('regulation_type_ver').id==InitPage.otherCheckboxes[i].id&&document.getElementById('regulation_type_ver').checked){
            onlyVerdragen=true;
            verdragenChecked=true;
          }else if(InitPage.otherCheckboxes[i].checked){
            onlyVerdragen=false;
          }
        }
        if(!onlyVerdragen){
          if(document.getElementById('date_for_totstandkoming')){
            if(verdragenChecked){
              document.getElementById('date_for_totstandkoming').disabled=false;
            }else{
              document.getElementById('date_for_totstandkoming').disabled=true;
            }
          }
          if(document.getElementById('date_for_ondertekening')){
            document.getElementById('date_for_ondertekening').disabled=false;
          }
        }else{
          if(document.getElementById('date_for_ondertekening')){
            document.getElementById('date_for_ondertekening').disabled=true;
          }
        }
      }
    }
    
  }
};

Core.start(InitPage);
var Suggestions={
		lastterm: '',		

		split:function( val ) {
			return val.split( / \s*/ );
		},
		getAllButLast:function( term ) {
			var terms = Suggestions.split( term );
			terms.pop();
			return terms.join('%');
		},
		extractLast:function( term ) {
			return Suggestions.split( term ).pop();
		},
	
		getTitleSuggestions:function(e){
			if ( e.keyCode === $.ui.keyCode.TAB &&
					$( this ).data( "autocomplete" ).menu.active ) {
						e.preventDefault();
			}
		},
	
		getRegulationTypes:function(){
			var reg_types = '';
			var simple_search = true;
			if (document.getElementById('wetsfamilie'))
			{
				simple_search = false;
			}
			var all_bes_types = document.getElementById('regulation_type_all_with_BES').checked;
			var only_bes_types = document.getElementById('regulation_type_bes_only').checked;
			var all_checkboxes = document.getElementsByName('regulation_types[]');
			var all_types = document.getElementById('regulation_type_all').checked;
			for (var i=0;i<all_checkboxes.length;i++)
			{
				var value = all_checkboxes[i].value;
				if (value != 'bes_only' && value != 'all_with_bes' && value != 'all')
				{
					if (all_checkboxes[i].checked || all_types)
					{
						var reg_group = document.getElementsByName('regulation_group_type['+value+']');
						for (var y=0;y<reg_group.length;y++)
						{
							if (y == 0 && (all_bes_types || only_bes_types))
							{
								bes_type = document.getElementsByName('regulation_group_type['+value+'-BES]');
								if (bes_type.length == 0)
								{
									bes_type = document.getElementsByName('regulation_group_type['+value+'-bes]');
								}
								for (var w=0;w<bes_type.length;w++)
								{
									reg_types += ','+bes_type[w].value;
								}
							}
							if (!only_bes_types)
							{
								reg_types += ','+reg_group[y].value;
							}
						}
					}
				}
			}
			
			return reg_types;
		},
		
		getFullSearchTerm:function(){
			var keyword_term = document.getElementById('zoekterm').value;
			var reg_types = Suggestions.getRegulationTypes();
			term = keyword_term+'%'+reg_types;
			
			return term;
		},
	
	init:function(){
		if (document.getElementById('titel_suggesties').value == '1')
		{
			var lastAjaxCall = null;
			var cache = {};
		    document.getElementById('zoekterm').setAttribute('autocomplete', 'off');
		    Core.addClass(document.getElementById('zoekterm'), 'ui-autocomplete-input');
		    $("#zoekterm").autocomplete( "option", "delay", 0 );
		    
		    $("#zoekterm").autocomplete({
				source: function( request, response ) {
		    		if (lastAjaxCall)
		    		{
						$("#zoekterm").autocomplete("close");
						lastAjaxCall.abort();
		    		}
		    		var full_term = Suggestions.getFullSearchTerm();
		    		if ( cache[ full_term ] ) {
						response( cache[ full_term ] );
						return;
					}
	
		    		lastAjaxCall = $.getJSON( "/Search/getTitleSuggestions", {
							search_term: request.term,
							regulation_types: Suggestions.getRegulationTypes()
						}, 
						function( data, status, ajaxCall ) {
							cache[ full_term ] = data;
							if ( ajaxCall === lastAjaxCall ) {
								response( data );
							}
					   });
					},	
				search: function() {
					// custom minLength
					var keyword_term = this.value;
					if ( keyword_term.length < 3) {
						return false;
					}
				},
				focus: function() {
					// prevent value inserted on focus
					return false;
				},
				open: function() {
					var options = $(".ui-widget-content");
					var ul_options = null;
					if (options[0])
					{
						ul_options = options[0];
					}
					ul_options.scrollTop = 0;
				},
				select: function( event, ui ) {
					var selected_value = jQuery.trim(ui.item.value);
					if (selected_value.search(' ') != -1)
					{
						selected_value = '"'+selected_value+'"';
					}
					this.value = selected_value;
					
					/*//for 1 word suggestion
					var terms = Suggestions.split( this.value );
					// remove the current input
					terms.pop();
					// add the selected item
					terms.push( ui.item.value );
					// add placeholder to get the space at the end
					//terms.push( "" );
					this.value = terms.join( " " );*/
					
					return false;
				}
			});
		}
	}

};
Core.start(Suggestions);

var SelectLightBox={
  createInput:function(name,soort){
    var oInput=document.createElement("input");
    oInput.type='hidden';
    oInput.name=name;
    oInput.value=soort;
    document.getElementById('searchForm').appendChild(oInput);
  },
  showLightBoxMinisteries:function(e){
    SelectLightBox.createInput('lightbox','ministeries');
  },
  showLightBoxZBO:function(e){
    SelectLightBox.createInput('lightbox','zbo');
  },
  showLightBoxPBO:function(e){
    SelectLightBox.createInput('lightbox','pbo');
  },
  init:function(){
    var MinisteriesSelectButton=document.getElementById('selecteer_ministeries_knop');
    if(MinisteriesSelectButton){
      Core.addEventListener(MinisteriesSelectButton,'click',SelectLightBox.showLightBoxMinisteries);
    }
    var ZBOSelectButton=document.getElementById('selecteer_zbo_knop');
    if(ZBOSelectButton){
      Core.addEventListener(ZBOSelectButton,'click',SelectLightBox.showLightBoxZBO);
    }
    var PBOSelectButton=document.getElementById('selecteer_pbo_knop');
    if(PBOSelectButton){
      Core.addEventListener(PBOSelectButton,'click',SelectLightBox.showLightBoxPBO);
    }
  }
};

Core.start(SelectLightBox);
var SelectParts={
  all_checkbox:{},
  ministry_all_checkbox:{},
  ministry_parts:[],
  other_checkboxes:[],
  select_parts_button:{},
  select_parts_ministry_button:{},

  showPartOptions:function(e){
    var Options=document.getElementById('selecteer-onderdeel');
    if(Options!='undefined'){
      if(Core.hasClass(Options,'hidden')){
        Core.removeClass(Options,'hidden');
        Core.removeClass(SelectParts.select_parts_button,'openklappen');
        Core.addClass(SelectParts.select_parts_button,'dichtklappen');
      }else{
        Core.addClass(Options,'hidden');
        Core.removeClass(SelectParts.select_parts_button,'dichtklappen');
        Core.addClass(SelectParts.select_parts_button,'openklappen');
      }
    }
  },

  showMinistryOptions:function(e){
    var Options=document.getElementById('selecteer-ministeriele-regelingen');
    if(Options!='undefined'){
      if(Core.hasClass(Options,'hidden')){
        Core.removeClass(Options,'hidden');
        Core.removeClass(SelectParts.select_parts_ministry_button,'openklappen');
        Core.addClass(SelectParts.select_parts_ministry_button,'dichtklappen');
      }else{
        Core.addClass(Options,'hidden');
        Core.removeClass(SelectParts.select_parts_ministry_button,'dichtklappen');
        Core.addClass(SelectParts.select_parts_ministry_button,'openklappen');
      }
    }
  },


  killOthers:function(){
    if(this.checked==true){
      for(var i=0;i<SelectParts.other_checkboxes.length;i++){
        SelectParts.other_checkboxes[i].checked=false;
      }
    }
  },
  killAll:function(){
    if(this.checked==true){
      SelectParts.all_checkbox.checked=false;
    }
  },

  killMinistryAll:function(){
    if(this.checked==true){
      SelectParts.ministry_all_checkbox.checked=false;
    }
    all_checked = true;
    for(var i=0;i<SelectParts.ministry_parts.length;i++){
    	if (!SelectParts.ministry_parts[i].checked)
    	{
    		all_checked = false;
    	}
    }
    if (all_checked)
    {
    	SelectParts.ministry_all_checkbox.checked = true;
    	for(var i=0;i<SelectParts.ministry_parts.length;i++){
    		SelectParts.ministry_parts[i].checked = false;
    	}
    }
  },

  killMinistryParts:function(){
    if(this.checked==true){
      for(var i=0;i<SelectParts.ministry_parts.length;i++){
        SelectParts.ministry_parts[i].checked=false;
      }
    }
  },


  init:function(){
    var SelectPartsButton=document.getElementById('select_parts');
    if(SelectPartsButton){
      SelectParts.select_parts_button=SelectPartsButton;
      Core.addEventListener(SelectParts.select_parts_button,'click',SelectParts.showPartOptions);
      Core.addClass(SelectParts.select_parts_button,'openklappen');
      Core.removeClass(SelectParts.select_parts_button,'dichtklappen');
      Core.addClass(document.getElementById('selecteer-onderdeel'),'hidden');
    }
    var parts_array=document.getElementsByName('element_types[]');
    if(parts_array.length>0){
      for(var i=0;i<parts_array.length;i++){
        if(parts_array[i].value=='all'){
          SelectParts.all_checkbox=parts_array[i];
          Core.addEventListener(SelectParts.all_checkbox,'click',SelectParts.killOthers);
        }else{
          SelectParts.other_checkboxes.push(parts_array[i]);
        }
      }
      for(var i=0;i<SelectParts.other_checkboxes.length;i++){
        Core.addEventListener(SelectParts.other_checkboxes[i],'click',SelectParts.killAll);
      }
    }

    var SelectPartsMinistryButton=document.getElementById('select_parts_ministry');
    if(SelectPartsMinistryButton){
      SelectParts.select_parts_ministry_button=SelectPartsMinistryButton;
      Core.addEventListener(SelectParts.select_parts_ministry_button,'click',SelectParts.showMinistryOptions);
      Core.addClass(SelectParts.select_parts_ministry_button,'openklappen');
      Core.removeClass(SelectParts.select_parts_ministry_button,'dichtklappen');
      Core.addClass(document.getElementById('selecteer-ministeriele-regelingen'),'hidden');

      SelectParts.ministry_all_checkbox = document.getElementById('regulation_type_minreg');
      
      SelectParts.ministry_parts = Core.getElementsByClass('ministry_parts');
      for(var i=0;i<SelectParts.ministry_parts.length;i++){
        Core.addEventListener(SelectParts.ministry_parts[i],'click',SelectParts.killMinistryAll);
        if (SelectParts.ministry_parts[i].checked)
        {
        	Core.addClass(SelectParts.select_parts_ministry_button,'dichtklappen');
            Core.removeClass(SelectParts.select_parts_ministry_button,'openklappen');
            Core.removeClass(document.getElementById('selecteer-ministeriele-regelingen'),'hidden');
        }
      }

      Core.addEventListener(SelectParts.ministry_all_checkbox,'click',SelectParts.killMinistryParts);
    }

  }
};

Core.start(SelectParts);
var TextSelect={
  boxes:[],
  defaultValues:['Jaar','Nummer','dd','mm','jjjj',/^(\d*)$/],
  defaultTextColorClass:'input-default-text-color',
  setDefaultTextColor:function(obj){
    var defaultFlag=false;
    for(var i=0;i<TextSelect.defaultValues.length;i++){
      if(obj.value==TextSelect.defaultValues[i]){
        defaultFlag=true;
        i=TextSelect.defaultValues.length;
      }
    }
    if(defaultFlag){
      Core.addClass(obj,TextSelect.defaultTextColorClass);
    }
  },
  isDefaultValue:function(value){
    var isDefault=false;
    for(var i=0;i<TextSelect.defaultValues.length;i++){
      if(value==TextSelect.defaultValues[i]){
        isDefault=true;
      }
    }
    return isDefault;
  },
  boxAdder:function(id){
    var tempArray=new Array();
    var tempObject=document.getElementById(id);
    tempArray['object']=tempObject;
    tempArray['id']=id;
    if(TextSelect.isDefaultValue(tempObject.value))


    {
      tempArray['default_value']=tempObject.value;
    }
    else
    {
      tempArray['default_value']=null;
    }
    TextSelect.boxes.push(tempArray);
  },
  getDefaultValue:function(id){
    for(var i=0;i<TextSelect.boxes.length;i++){
      if(id==TextSelect.boxes[i]['id']){
        return TextSelect.boxes[i]['default_value'];
      }
    }
    return false;
  },
  focusAction:function(e){
    if(this.value==TextSelect.getDefaultValue(this.id)){
      this.value='';
      if(Core.hasClass(this,TextSelect.defaultTextColorClass)){
        Core.removeClass(this,TextSelect.defaultTextColorClass);
      }
    }
  },
  blurAction:function(e){
    if(this.value==''){
      this.value=TextSelect.getDefaultValue(this.id);
      if(!Core.hasClass(this,TextSelect.defaultTextColorClass)&&isNaN(this.value)){
        Core.addClass(this,TextSelect.defaultTextColorClass);
      }
    }
  },
  init:function(){
    (document.getElementById('publicatie_year')?TextSelect.boxAdder('publicatie_year'):null);
    (document.getElementById('publicatie_nr')?TextSelect.boxAdder('publicatie_nr'):null);
    (document.getElementById('date_day')?TextSelect.boxAdder('date_day'):null);
    (document.getElementById('date_month')?TextSelect.boxAdder('date_month'):null);
    (document.getElementById('date_year')?TextSelect.boxAdder('date_year'):null);
    (document.getElementById('datum_from_day')?TextSelect.boxAdder('datum_from_day'):null);
    (document.getElementById('datum_from_month')?TextSelect.boxAdder('datum_from_month'):null);
    (document.getElementById('datum_from_year')?TextSelect.boxAdder('datum_from_year'):null);
    (document.getElementById('datum_to_day')?TextSelect.boxAdder('datum_to_day'):null);
    (document.getElementById('datum_to_month')?TextSelect.boxAdder('datum_to_month'):null);
    (document.getElementById('datum_to_year')?TextSelect.boxAdder('datum_to_year'):null);
    for(var i=0;i<TextSelect.boxes.length;i++){
      Core.addEventListener(TextSelect.boxes[i]['object'],'blur',TextSelect.blurAction);
      Core.addEventListener(TextSelect.boxes[i]['object'],'focus',TextSelect.focusAction);
      TextSelect.setDefaultTextColor(TextSelect.boxes[i]['object']);
    }
  }
};

Core.start(TextSelect);

var MOTD={
  closeLightbox:function(){
    setTimeout('document.location.reload();', 1000)
    },
  init:function(){
    if(document.getElementById('lightbox') && document.getElementById('lightbox').className =='motd' && document.cookie && document.cookie.search(/motd=/) >= 0)
    {
      document.getElementById('lightbox').style.display = 'block';
    }
    if(document.getElementById('motd'))
    {
      Core.addEventListener(document.getElementById('motd'),'click',MOTD.closeLightbox);
    }
    if(document.getElementById('motd_form'))
    {
      document.getElementById('motd_form').target = '_blank';
    }
  }
};

Core.start(MOTD);

var BesSearchToggle = {
  only_bes_cb: {},
  with_bes_cb: {},

  toggle_listener:function(){
    if(this == BesSearchToggle.only_bes_cb && this.checked)
    {
      BesSearchToggle.with_bes_cb.checked = false;
    }
    else if(this == BesSearchToggle.with_bes_cb && this.checked)
    {
      BesSearchToggle.only_bes_cb.checked = false;
    }
  },

  init:function(){
    if(document.getElementById('regulation_type_bes_only') && document.getElementById('regulation_type_all_with_BES'))
    {
      BesSearchToggle.only_bes_cb = document.getElementById('regulation_type_bes_only');
      BesSearchToggle.with_bes_cb = document.getElementById('regulation_type_all_with_BES');

      Core.addEventListener(BesSearchToggle.only_bes_cb,'click',BesSearchToggle.toggle_listener);
      Core.addEventListener(BesSearchToggle.with_bes_cb,'click',BesSearchToggle.toggle_listener);
    }
  }
}

Core.start(BesSearchToggle);
