/*----------------------------------------------------------------------------------------
Location Suggestion
------------------------------------------------------------------------------------------
	Date: 			27-01-2010
	Description: 	Using a txt box (keyField) and a results pane (resultDiv) this 
					will check the database fields For a distinct list of matches 
					On the keyword supplied so the user can Select a single Item
					to be searched upon.
					The DB field checked depends On the 'type' supplied,
					e.g. 'vac' will check the tx_city field.
------------------------------------------------------------------------------------------ */
var keepAlive=15;
function locationSuggest(keyField, resultDiv) {
	try {
		if($(keyField) && $(resultDiv)) {
			if($(keyField).getValue().length>2) {
				var url;
				var mode='';
				if(location.href.indexOf('/admin/')>0) {
					url = '../../include/ajax_locationSuggest.asp';
				} else {
					url = 'include/ajax_locationSuggest.asp';
				}
				if(location.href.indexOf('/client/')>0) {
					mode='cli';
				}
				
				var d = new Date();
				var time = d.getTime();
				new Ajax.Request(url, {
					method: 'get', 
					parameters: { mode: mode, resultDiv: resultDiv, field: keyField, keywords: $(keyField).getValue(), prevent_cache: time}, 
					onComplete: function(originalRequest) {
						var newData = originalRequest.responseText;
						if(newData.length>0) {
							$(resultDiv).innerHTML=newData;
							$(resultDiv).show();
						} else {
							locationSuggestHide(resultDiv,0);
						}
					}
				});
			} else {
				locationSuggestHide(resultDiv,0);
			}
		} 
	} catch(err) { return false; }	
}
function locationSuggestHide(resultDiv, time) {
	if(time>0) {
		new PeriodicalExecuter(function() {
			$(resultDiv).hide();
		}, time);
	} else {
		$(resultDiv).hide();	
	}
}