
		function searchInit(){			
			new Ajax.Autocompleter("city_from", "autocomplete_city_from", "/ajax/autocomplete_cities.php", {indicator: 'indicator_city_right', minChars: 1, paramName: 'city', frequency: 0.4, afterUpdateElement: AutCompleteAccept
			  });
			 new Ajax.Autocompleter("city_to", "autocomplete_city_to", "/ajax/autocomplete_cities.php", {indicator: 'indicator_city_right', minChars: 1, paramName: 'city', frequency: 0.4, afterUpdateElement: AutCompleteAccept  });   
			 
			 Event.observe($('city_from'), 'keypress', InputEventListener.onKeyUp.bindAsEventListener(Event,'city_from'));
			Event.observe($('city_to'), 'keypress', InputEventListener.onKeyUp.bindAsEventListener(Event,'city_to'));		
			Event.observe($('city_from'), 'change', InputEventListener.onChange.bindAsEventListener(Event,'city_from'));
			Event.observe($('city_to'), 'change', InputEventListener.onChange.bindAsEventListener(Event,'city_to'));
		}
		
		var state_city_from = 0;
		var state_city_to = 0;
		var state_text = ""
		var InputEventListener  = { 		
			onKeyUp: function(event,text){						
				state_text = $(text).value;
				
				/*KEY_BACKSPACE, KEY_TAB, KEY_RETURN, KEY_ESC, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN, KEY_DELETE, KEY_HOME, KEY_END, KEY_PAGEUP, KEY_PAGEDOWN.  */
				if (event.keyCode != Event.KEY_TAB && 
					event.keyCode != Event.KEY_ESC && 
					event.keyCode != Event.KEY_LEFT &&
					event.keyCode != Event.KEY_UP &&  
					event.keyCode != Event.KEY_RIGHT &&
					event.keyCode != Event.KEY_DOWN &&
					event.keyCode != Event.KEY_HOME &&   
					event.keyCode != Event.KEY_END && 
					event.keyCode != Event.KEY_PAGEUP && 
					event.keyCode != Event.KEY_PAGEDOWN ){					
										
					if($('no_results_city_from')){
						$('no_results_city_from').remove();
					}
					if($('no_results_city_to')){
						$('no_results_city_to').remove();
					}
					
					setTimeout('AutoCompleteControlSearch(\'' + text + '\')',2);
				}
			},			
			onChange: function (event, elm){
				
				setTimeout('AutoCompleteOnChange(\'' + elm + '\')',200);
			}
		}
		
		function AutoCompleteControlSearch (elementName){		
			text = $(elementName);							
			if ( text.value != state_text) {
				//$('search_request').disabled = true;										
				if (text.value == ''){
					if (text.id == "city_from")	state_city_from = 1;
					else if (text.id == "city_to") state_city_to = 1;
				}	
				else {
					if (text.id == "city_from")	state_city_from = 0;
					else if (text.id == "city_to") state_city_to = 0;					
				}
			
					
			}
		}		
		function AutCompleteAccept(text,li){		
		
			if (text.id == "city_from")	{ 
				state_city_from = 1;
				$('city_to').select();				
			}
			else { state_city_to = 1;	
				$('search_request').activate();
			}
			
			if ( state_city_from == 1 && state_city_to == 1)
			$('search_request').disabled = false;					
			
		}	
		
		function AutoCompleteOnChange (elm) {	
		element =  $(elm);		
/*		
					
			var ignore = 0;		
			if (elm.id == 'city_from' && state_city_from == 0) ignore = 1;								
			if (elm.id == 'city_to' && state_city_to == 0)	ignore = 1;				
			if (ignore == 0 ){
				new Ajax.Request('/ajax/verify_city.php', {
					parameters: {city: element.value},					
					method: 'post',
					asynchronous: false,					
					onComplete: function(transport) {
					if (200 == transport.status){
					  if ( transport.responseText == 1)	ignore = 1;						  
					}					 
				  }
				});
			}			
			if (ignore == 0 ){					
				eloffset =element.positionedOffset();					
				no_result_top = element.getHeight();				
				no_result_top += eloffset.top;					
				var no_result = new Element('div',{'id': 'no_results_' + elm, 
															   'class': 'autocomplete_no_results'});				
				no_result.appendChild(document.createTextNode("De opgegeven plaats komt niet voor in de lijst!"));				
				no_result.style.width= element.getWidth() + 'px';						
				no_result.style.marginTop = no_result_top + 'px';	
				no_result.style.marginLeft = eloffset.left + 'px';					
				$('container').insert({ top: no_result });
				no_result.show();
				
			}
			else {
*/				AutCompleteAccept(element);
		/*	}			*/
		}

		function orderResults (sortField, Order){
			$('sort').value = sortField;
			$('order').value = Order;
			$('city_from').value = $('p_city_from').value;
			$('city_to').value = $('p_city_to').value;
			$('km_from').value = $('p_km_from').value;
			$('km_to').value = $('p_km_to').value;		
			
				
			$('transport_search').submit();
		}
		
		
	
		function searchSwitchType ( current_object, blur_object, type){
				current_object.className = 'active'; 
				blur_object.className = '';
				$('search_type').value = type;
				$('city_from').focus();
				
		}
		
	
		
 		
    