function closeInPlaceSearch(){
	$('inPlaceSearch').style.display = 'none';
}
function showInPlaceSearch(e){
	var rightclick;
	if (!e) var e = window.event;
	if (e.which) rightclick = (e.which == 3);
	else if (e.button) rightclick = (e.button == 2);

	if (rightclick && map.getZoom()<=12){
        $('inPlaceSearch').style.top = Event.pointerY(e) + 7;
        $('inPlaceSearch').style.left = Event.pointerX(e) + 7;
        $('inPlaceSearch').style.display = 'block';
        //Effect.Grow('inPlaceSearch', {direction:'top-left',duration:0.0});
	}
}

function doInPlaceSearch(latLon){
	document.search_form.latitude.value = document.inPlaceSearchForm.inPlaceSearchLat.value; //update hidden fields, used by SP to find nearby spaces
	document.search_form.longitude.value = document.inPlaceSearchForm.inPlaceSearchLng.value;

	//WORK AROUND FOR GMAP V3
	//TODO: replace this when clearOverlays becomes available for V3
	clearOverlays();
	//WORK AROUND FOR GMAP V3
	
	//mark our destination and center the map there
	addDestinationMarker(inPlaceSearchLatLng);
	//show the please wait message while the database is searched and points are plotted
	document.getElementById('pleaseWait').style.visibility='visible';
	
	//TODO: should there be one function to reset the search/list/results area?
	//clear any existing results from the results tab
	document.getElementById('resultsList').innerHTML = '';
	//show the search form -- this is in case there are zero results (otherwise we'd have a blank results list)
	// if we do have results, they will be written to the results tab
	showForm('searchForm');
	//don't want to show the results tab, in case there are no results
	$('resultsTab').style.visibility = 'hidden';

	//hide the inPlaceSearch div
	document.getElementById('inPlaceSearch').style.display='none';
	
	//set all the appropriate fields in the search_form table
	document.search_form.spaceAddress.value = '';
	document.search_form.spaceArea.selectedIndex = 0;
	if (document.inPlaceSearchForm.inPlaceSearchDate[0].checked){
		document.search_form.spaceDate.value = document.inPlaceSearchForm.inPlaceSearchDate[0].value;
	} else {
		document.search_form.spaceDate.value = document.inPlaceSearchForm.inPlaceSearchDate[1].value;
	}
	document.search_form.spaceTime.selectedIndex = document.inPlaceSearchForm.inPlaceSearchTime.selectedIndex+1;
	document.search_form.spaceDistance.selectedIndex = 3;
	document.search_form.spaceWindow.selectedIndex = 5;
	document.search_form.searchAllSpaces.checked = false;
	var formParams = $('search_form').serialize(true); //prototype.js code to turn all search_form fields into params
	//send query via prototype.js AJAX request
	new Ajax.Request('execute/FindSpaces',
	  {
	    method:'post',
		parameters: formParams,
		onSuccess: function(transport){ //on success plot the markers and show the results tab
			document.getElementById('pleaseWait').style.visibility='hidden'; //hide the please wait message
			var spacesWrapper = transport.responseText.evalJSON(); //use prototype to access the space data
			var spaces = spacesWrapper.spaces;
			if(!spacesWrapper.success){
				var errors = spacesWrapper.errors;
				var validators  = new Object;
				for (var e=0;e<errors.length;e++){
					validators.name = errors[e].field;
					searchValidation(validators,validators,errors[e].errorCode);
				}
				openResponseMsgWin(spacesWrapper);
				return false;
			}
			// TODO - are there other error messages?
			if (spaces.length==0){
				openMsgWin('NO_SPACES_FOUND');
				return false;
			}
			for (i=0;i<spaces.length;i++){ //add each space to the global array
				addMarker(spaces[i],spaces.length);
			}
			showSpacesTable(spaces); //build and show the results tab
		},
		//this assumes a failure to retrieve data from the server
		onFailure: function(){
			openMsgWin('SEARCH_ERROR');
			return false;
		},
		asynchronous: false
	});
	//update the criteria on the results page
	document.getElementById('criteriaAddress').innerHTML = "<i>(See Map)</i>";
	document.getElementById('criteriaTime').innerHTML = document.search_form.spaceTime.options[document.search_form.spaceTime.selectedIndex].text;
	document.getElementById('criteriaDate').innerHTML = document.search_form.spaceDate.value;
	//reset the refinedString field so we don't bypass the user input on subsequent trips
	document.search_form.refinedAddress.value='';
}
