		var liveSearchReq = false;
		var timeDelay = null;
		var liveSearchLast = "";
			
		var isIE = false;
		
		function liveSearchInit() {
		  if($('livesearch5')) 
		  {
		    allInputFields = $("livesearch1","livesearch2","livesearch3","livesearch4","livesearch5","livesearch6","livesearch7");
		  }
		  else if($('livesearch3')) 
		  {
		    allInputFields = $("livesearch1","livesearch2","livesearch3","livesearch4");
		  }
		  else 
		  {
		    allInputFields = $("livesearch1","livesearch2");
		  }
			for(i=0; i<allInputFields.length; i++) {
				if (navigator.userAgent.indexOf("Safari") > 0) {
				
					allInputFields[i].addEventListener("keydown",liveSearchKeyPress,false);
			    //allInputFields[i].addEventListener("blur",liveSearchHide,false);
			    
				} else if (navigator.product == "Gecko") {
					
					allInputFields[i].addEventListener("keypress",liveSearchKeyPress,false);
					//allInputFields[i].addEventListener("blur",liveSearchHideDelayed,false);
					
				} else {
				
					allInputFields[i].attachEvent('onkeydown',liveSearchKeyPress);
			    //	allInputFields[i].attachEvent("onblur",liveSearchHide,false);
					isIE = true;
				}
				
				allInputFields[i].setAttribute("autocomplete","off");
		  }
		}

		function liveSearchKeyPress(event) {
	    // Get sender of the event
	    var inputField  = (event.target)?event.target:event.srcElement;
		  var listbox     = $(inputField.id+"_listbox");
		  var ajaxLoad    = $(inputField.id+"_ajaxLoad");
	    
			if (event.keyCode == 40 )
			//KEY DOWN
			{
			  liHighlight = $("liHighlight");
				if (!liHighlight) {
					liHighlight = $(inputField.id+"_list").firstChild;
				} else {
					liHighlight.removeAttribute("id");
					liHighlight = liHighlight.nextSibling;
				}
				if (liHighlight) {
					liHighlight.setAttribute("id","liHighlight");
					locID = liHighlight.firstChild.getElementsByTagName('span')[0].title;
					locName = $("locname_"+locID).innerHTML;
					inputField.value = locName; 
					$(inputField.id+"_ID").value = locID;
				} 
				if (!isIE) { event.preventDefault(); }
			} 
			//KEY UP
			else if (event.keyCode == 38 ) {
			  liHighlight = $("liHighlight");
		    var locName     = $("locName_"+liHighlight.name);
				if (!liHighlight) {
					liHighlight = $(inputField.id+"_list").firstChild.lastChild;
				} 
				else {
					liHighlight.removeAttribute("id");
					liHighlight = liHighlight.previousSibling;
				}
				if (liHighlight) {
					liHighlight.setAttribute("id","liHighlight");
					locID = liHighlight.firstChild.getElementsByTagName('span')[0].title;
					locName = $("locname_"+locID).innerHTML;
					inputField.value = locName; 
					$(inputField.id+"_ID").value = locID;
				}
				if (!isIE) { event.preventDefault(); }
			} 
			//ESC or TAB or RIGHT-ARROW
			else if (event.keyCode == 27 || event.keyCode == 9 || event.keyCode == 39) {
			  liHighlight = $("liHighlight");
				if (liHighlight) {
					liHighlight.removeAttribute("id");
				}
				Element.hide(listbox,ajaxLoad);
			}
			else {
				if (timeDelay) {
					window.clearTimeout(timeDelay);
				}
				timeDelay = window.setTimeout("liveSearchDoSearch('"+inputField.id+"')",200);
			}
	  }

	  function liveSearchDoSearch(inputFieldID) {
	  
		  var listbox    = $(inputFieldID+"_listbox");
		  var ajaxLoad   = $(inputFieldID+"_ajaxLoad");
	    inputField = $(inputFieldID);
	
			if (typeof liveSearchRoot == "undefined") {
				liveSearchRoot = "httpRequest/";
			}
			if (typeof liveSearchRootSubDir == "undefined") {
				liveSearchRootSubDir = "";
			}
			if (typeof liveSearchParams == "undefined") {
				liveSearchParams = "";
			}
			if (liveSearchLast != inputField.value) {
				if (liveSearchReq && liveSearchReq.readyState < 4) {
					liveSearchReq.abort(); // Abort request
				}
				if (inputField.value == "") {
					Element.hide(listbox,ajaxLoad);
					return false;
				}
				
				//////////////////////////////
				// Get XMLHTTPRequest-Object

				liveSearchReq = getNewHttpObject(); // From livesearchfunctions.js
				
				// Call function on status change
				liveSearchReq.onreadystatechange = new Function('fx', 'liveSearchProcessReqChange("'+inputFieldID+'")'); 
				
				//liveSearchReq.open("GET", liveSearchRoot + "livesearch.xml.php?" + inputField.name + "=" + inputField.value);
				//alert("livesearch.xml.php?" + inputField.name + "=" + inputField.value);
				//alert("&Type="+$('advertType').value+"&MainType="+$('MainType').value+"&searchDateTolerance="+$('dateTolerance').value+"&dateDaySerach="+$('date_day_search').value+"&dateMonthSerach="+$('date_month_search').value+"&dateYearSerach="+$('date_year_search').value+"&VicinityTo="+$('vicinityTo').value+"&VicinityFrom="+$('vicinityTo').value);
				if(inputField.name!='qFrom' && inputField.name!='qTo') senderFieldName = 'qFrom';
				else senderFieldName = inputField.name;
				liveSearchReq.open("GET", liveSearchRoot + "livesearch.xml.php?" + senderFieldName + "=" + inputField.value + "&Type="+$('advertType').value+"&MainType="+$('MainType').value+"&searchDateTolerance="+$('dateTolerance').value+"&dateDaySerach="+$('date_day_search').value+"&dateMonthSerach="+$('date_month_search').value+"&dateYearSerach="+$('date_year_search').value+"&VicinityTo="+$('vicinityTo').value+"&VicinityFrom="+$('vicinityTo').value+"&browser="+userAgent);
				liveSearchLast = inputField.value;
				liveSearchReq.send(null);
		  }
		}
	
		function liveSearchProcessReqChange(inputFieldID) {
		  
		  var listbox           = $(inputFieldID+"_listbox");
		  var ajaxLoad          = $(inputFieldID+"_ajaxLoad");
		  var totalResultsTitle = $(inputFieldID+"_totalResults");
		  var sentResultsTitle  = $(inputFieldID+"_sentResults");

			// Status, result complete
			if (liveSearchReq.readyState == 4) {
				
				// Evaluate received xml data
				
				var xmlResponse  = liveSearchReq.responseXML;
				var totalResults = xmlResponse.documentElement.getAttribute("totalResults");
				var sentResults  = xmlResponse.documentElement.getAttribute("sentResults");
				var results      = xmlResponse.getElementsByTagName("Location");
				  
			  var resultList = $(inputFieldID+"_list");
			  // Clean result list
			  if(resultList.hasChildNodes()) {
				  while(resultList.firstChild) {
				    resultList.removeChild(resultList.firstChild);
				  }
			  }
			  
			  totalResultsTitle.innerHTML = totalResults;
			  sentResultsTitle.innerHTML  = sentResults;
				  
				for(i=0;i<results.length;i++) {
				

				  var locationID,locationIDValue;
				  var locationName, locationNameValue;
				  var zipCode,zipCodeValue;
				  var numAllAds,numAllAdsValue;
				  var numFilterAds,numFilterValue;

				  for(j=0;j<results[i].childNodes.length;j++) {
				  
				    var detail = results[i].childNodes[j];
				    switch(detail.nodeName) {
				      case "ID":
				        locationIDValue = detail.firstChild.nodeValue;
				        locationID   = document.createTextNode(detail.firstChild.nodeValue);
				        break;
				      case "Name":
				        locationNameValue = detail.firstChild.nodeValue;
				        locationName = document.createTextNode(detail.firstChild.nodeValue);
				        break;
				      case "ZipCode":
				        zipCodeValue = detail.firstChild.nodeValue;
				        zipCode      = document.createTextNode(detail.firstChild.nodeValue);
				        break;
				      case "NumAllAds":
				        numAllAdsValue = detail.firstChild.nodeValue;
				        numAllAds    = document.createTextNode(detail.firstChild.nodeValue);
				        break;
				      case "NumFilterAds":
				        numFilterAdsValue = detail.firstChild.nodeValue;
				        numFilterAds = document.createTextNode(detail.firstChild.nodeValue);
				        break;
				    }
				  }

				  	span_locname = document.createElement("span");
				    span_locname.setAttribute('id',"locname_"+locationIDValue);	
				    span_locname.setAttribute('title',locationIDValue);	
				    span_locname.innerHTML = locationNameValue;
				  
				  	span_loczipcode = document.createElement("span");
				    	span_loczipcode.setAttribute('id',"loczipcode_"+locationIDValue);	
				    	span_loczipcode.setAttribute('title',locationIDValue);	
				    span_loczipcode.innerHTML = " ("+zipCodeValue+")";
				  

				  link = document.createElement("a");
				    link.setAttribute('href','#');
				    link.setAttribute('class','livesearch');
				    link.appendChild(span_locname);
				    link.appendChild(span_loczipcode);
				    
				  if((inputFieldID=='livesearch1' || inputFieldID=='livesearch2') && numFilterAdsValue>0) {
					  	font_numallads = document.createElement("font");
					  	  font_numallads.setAttribute('color','red');
					  	  font_numallads.setAttribute('size','1');
					    //font_numallads.innerHTML = " ["+numFilterAdsValue+"/"+numAllAdsValue+"]";
					    font_numallads.innerHTML = " ["+numFilterAdsValue+"]";
					    
					  	span_numads = document.createElement("span");
					    span_numads.appendChild(font_numallads);
				  
				    link.appendChild(span_numads);
				  }
				  
				  listElem = document.createElement("li");
				    listElem.appendChild(link);
				  
				  resultList.appendChild(listElem);
				  
				  Event.observe(link,'click',new Function('fx', 'chooseLocationByClick("'+inputFieldID+'","'+locationIDValue+'","'+locationNameValue+'")'));
				}
				
				Element.show(listbox);
				Element.hide(ajaxLoad);
			}
			// Status, wait for respond
			else if (liveSearchReq.readyState == 1) {
				Element.show(ajaxLoad);
				Element.hide(listbox);
			}
		}
		
		function chooseLocationByClick(inputFieldID,locationID,locationName) {
		  
		  var listbox    = $(inputFieldID+"_listbox");
		  var ajaxLoad   = $(inputFieldID+"_ajaxLoad");
		  Element.hide(listbox,ajaxLoad);
		  
		  var inputField   = $(inputFieldID);
		  var idField      = $(inputFieldID+"_ID");
		  inputField.value = locationName;
		  idField.value    = locationID;
		}
		

