var myScriptNodeDataSource = new YAHOO.widget.DS_ScriptNode("/zoeken/search.cfm?give=all", ["keywords","keyword","keywordHTML"]);
var myAutoComp = new YAHOO.widget.AutoComplete("trefwoordtop","header-search-suggestions", myScriptNodeDataSource);

myAutoComp.formatResult = function(aResultItem, sQuery) {
   var sKey = aResultItem[0]; // the entire result key
   var sKeyhtml = aResultItem[1]; // htmlformatted

   var aMarkup = ["<div id='ysearchresult'>",
      sKeyhtml,
      "</div>"];
  return (aMarkup.join(""));
};

myAutoComp.delimChar = [" "];

if(document.location.href.search(/vacature-zoeken/) != -1){var myScriptNodeDataSource2 = new YAHOO.widget.DS_ScriptNode("/zoeken/search.cfm?give=vacatures", ["keywords","keyword","keywordHTML"]);}
if(document.location.href.search(/afstuderen-stage/) != -1){var myScriptNodeDataSource2 = new YAHOO.widget.DS_ScriptNode("/zoeken/search.cfm?give=stages", ["keywords","keyword","keywordHTML"]);}


//Below is a check whether the url contains the var 'vacature-zoeken'. If it does, add the extra autocomplete function
if(document.location.href.search(/vacature-zoeken/) != -1 || document.location.href.search(/afstuderen-stage/) != -1){
	
	//remove the search-suggestion block when not used, prevents <select> from not working
	if(document.getElementById('search-suggestions')){
		document.getElementById('search-suggestions').style.display="none";
		
		var myAutoComp2 = new YAHOO.widget.AutoComplete("trefwoord","search-suggestions", myScriptNodeDataSource2);
			
			myAutoComp2.formatResult = function(aResultItem, sQuery) {
			   var sKey = aResultItem[0]; // the entire result key
			   var sKeyhtml = aResultItem[1]; // htmlformatted
			
			   var aMarkup = ["<div id='ysearchresult'>",
				  sKeyhtml,
				  "</div>"];
			  return (aMarkup.join(""));
			};
			
			
			//define your itemSelect handler function:
			var containerCollapseEventHandler = function(sType, aArgs) {
				showSelect();
			};
			
			var containerExpandEventHandler = function(sType, aArgs) {
				hideSelect();
			};
		
		myAutoComp2.containerCollapseEvent.subscribe(containerCollapseEventHandler);
		myAutoComp2.containerExpandEvent.subscribe(containerExpandEventHandler);
		
		function hideSelect() {
			document.getElementById('vakgebied').style.visibility="hidden";
			document.getElementById('standplaats').style.visibility="hidden";
			document.getElementById('search-suggestions').style.display="block";
		}
		
		function showSelect() {
			document.getElementById('standplaats').style.visibility="visible";
			document.getElementById('vakgebied').style.visibility="visible";
			document.getElementById('search-suggestions').style.display="none";
		}
		
		myAutoComp2.delimChar = [" "];
	}
}