// JavaScript Document


	function searchSetTerm(term,doSubmit){
		if (term && term != ''){
			var searchField = document.getElementById('search');
			if (searchField){
				searchField.value = term;
				/*
				var searchForm = document.getElementById('searchForm');
				if (searchForm){
					searchForm.submit();
				}else{
					alert('No search form!');
				}
				*/
				var searchSubmit = document.getElementById('searchSubmit');
				if (doSubmit && searchSubmit){
					if (searchStart()){
						searchSubmit.click();
					}else{
						hideDropDown();
						$('location').focus();
					}
				}
			}
		}
	}
	function searchSetWhere(location,doSubmit){
		if (location && location != ''){
			var searchField = document.getElementById('location');
			if (searchField){
				searchField.value = location;
				/*
				var searchForm = document.getElementById('searchForm');
				if (searchForm){
					searchForm.submit();
				}else{
					alert('No search form!');
				}
				*/
				var searchSubmit = document.getElementById('searchSubmit');
				if (doSubmit && searchSubmit){
					if (searchStart()){
						searchSubmit.click();
					}else{
						hideDropDown();
						$('search').focus();
					}
				}
			}
		}
	}
	function searchStart(){
		var searchField = document.getElementById('search');
		if (searchField){
			if (searchField.value == ''){
				alert('Please enter or select a search term.');	
				return false;
			}
		}
		var locationField = document.getElementById('location');
		if (locationField){
			if (locationField.value == ''){
				alert('Please enter a location.');
				return false;
			}else{
				return true;
			}
		}
		alert('Search Failed');
		return false;
	}


	function setTermDD(term, field){
		setTerm(term);
		if (field) setLocation(field);
		hideDropDown();
	}
	function hideDropDown(){
		$('cover').style.display = 'none';
		$('searchcats-dropdown').style.display = 'none';
	}
	function showDropDown(content){
		$('searchcats-con').innerHTML = content;
		//$('searchcats-con').appenChild(content);
		$('searchcats-dropdown').style.display = '';
		$('cover').style.display = '';
	}
	
	function setLocation(field){
		if (field){
			$('searchcats-dropdown').style.left = field.offsetLeft +'px';
			$('searchcats-dropdown').style.top = (parseInt(field.offsetTop) + parseInt(field.offsetHeight))+'px';
		}
	}
	
	function hoverDD(me,over){
		if (me){
			if (over){
				me.style.backgroundColor = '#0756A4';
				me.style.color = '#FFFFFF';
			}else{
				me.style.backgroundColor = '#FFFFFF';
				me.style.color = '#000000';
			}
		}
	}
	
	//var current_request_count = 0;
	//var current_request_showing = 0;
	
	function startDropDown(term, field){
		if (field) setLocation(field);
		if (term != ''){
		
			//var current_request = ++current_request_count;
		
			new Ajax.Request('searchcats.php',
				{
					method:'get',
					parameters: {term: term},
					onSuccess: function(transport){
						var response = transport.responseText || false;
						if (response){
							showDropDown(response);
						}else{
							hideDropDown();
						}
				},
				onFailure: function(){ hideDropDown(); }
			});
  		}else{
			hideDropDown();
		}
	}
