
	//for debugging
	function show_hidden(){
		alert('c: '+$F('c')+"\n"+ 'nb:'+$F('nb')+"\n"+ 'fe:'+$F('fe'));
	}





		var matchCont;
		var prepend;
		
		function s_param(){
			this.neighborhoods = new Array();
			this.cities = new Array();
			this.free_entry = new Array();
			this.add = function(name, type){
				if (type == 'neighborhood'){
					this.neighborhoods.push(name);
				}
				else if (type == 'city'){
					this.cities.push(name);
				}
			}
			this.check = function(str){
				this.tmp_neighborhoods = new Array();
				this.tmp_cities = new Array();
				this.tmp_free_entry = new Array();
				var vals = str.split(',');
				for (i=0; i<vals.length; i++){
					test = trim(vals[i]);
					if (test.length > 1){
						if (inArray(test, this.neighborhoods)){
							this.tmp_neighborhoods.push(test);
						}
						else if (this.cities.indexOf(test) != -1){
							this.tmp_cities.push(test);
						}
						else this.tmp_free_entry.push(test);
					}
				}
				this.neighborhoods = this.tmp_neighborhoods;
				this.cities = this.tmp_cities;
				this.free_entry = this.tmp_free_entry;
				delete this.tmp_cities;
				delete this.tmp_neighborhoods;
				delete this.tmp_free_entry;
			}
			
		}
		
		var search_params = new s_param();
		
		YAHOO.example.BasicRemote = function()
		{
			// Use an XHRDataSource
			var oDS = new YAHOO.util.XHRDataSource("../east-bay-real-estate-mls/ysearch_mine.php");
				oDS.connMethodPost = true;

			// Set the responseType
			oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT;
			// Define the schema of the delimited results
			oDS.responseSchema =
			{
				recordDelim: "\n",
				fieldDelim: "\t",
				fields : ["name", "id", "prepend"]
			};
			// Enable caching
			//oDS.maxCacheEntries = 180;
			// Instantiate the AutoComplete
			var oAC = new YAHOO.widget.AutoComplete("fuzzy", "auto_complete_container", oDS);
			oAC.maxResultsDisplayed = 20;
		    oAC.resultTypeList = false;
			
			//for IE6 BUG -- meh... we're not going to support it.
			oAC.useIFrame = false;
			
			oAC.typeAhead = false;
			oAC.queryInterval = 100;
			oAC.queryDelay = 0.1;
			oAC.prehighlightClassName = 'auto_select_hilite';
			oAC.highlightClassName = 'auto_select_hilite_current';
			
			
			//mine for debugging
			
			/*
			oAC.handleResponse = function( sQuery , oResponse , oPayload ) {
				var ss = '';
				for (n in oResponse.results){
					ss += "\n"+oResponse.results[n];
				}
				
				for (n in oResponse.results[0]){
					alert(n+' : ' + oResponse.results[0][n]);
				}
			}
			
			*/
			
			
			oAC.formatResult = function(oResultData, sQuery, sResultMatch)
			{
				var sKey = sResultMatch;
				var sKeyRemainder = sKey.substr(sQuery.length);
				prepend = oResultData.prepend;
				var aMarkup = ["<div id=\'data\' class=\'yui-skin-sam\'>",
						"<span style=\'font-weight:bold\'>",
						sQuery,
						"</span>",
						sKeyRemainder,
						"</div>"];
				//return (aMarkup.join(""));
				return (oResultData.name);
				
			};
			//define itemSelect handler function:
			var itemSelectHandler = function(sType, aArgs) 
			{
				
				if($('selVal')){$('selVal').value="";}
				var myArr= $("fuzzy").value.split("&nbsp;");
				var str = prepend.length > 2 ? prepend+', ': '';				
				$("fuzzy").value=str+myArr[0];
				
				var myAC = aArgs[0]; // reference back to the AC instance
			    var elLI = aArgs[1]; // reference to the selected LI element
			    var oData = aArgs[2]; // object literal of selected item's result data
			    
				search_params.add(myArr[0].replace(', ', ''), oData.id);
				search_params.check($("fuzzy").value);
				write_vals();
				//alert(JSON.stringify(search_params));
			
			};
			
			
			oAC.itemSelectEvent.subscribe(itemSelectHandler);
		}();
		

		if ($F('fuzzy').length > 0){
			$('fuzzy').style.background = " url('http://redoakrealty.com/east-bay-real-estate-mls/images/search_input_bg.png')";
		}
		
		
	//write values to hidden fields
	function write_vals(){
				$('c').value = search_params.cities.join('|');
				$('nb').value = search_params.neighborhoods.join('|');
				$('fe').value = search_params.free_entry.join('|');
			}
	function cleanup(){
		search_params.check($("fuzzy").value);
		write_vals();
		//show_hidden();
	}
		
		
	//helper functions
		
	function trim(sString){
		while (sString.substring(0,1) == ' '){
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' '){
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	} 
	function inArray(needle, haystack) {
	    var length = haystack.length;
	    for(var i = 0; i < length; i++) {
	        if(haystack[i] == needle) return true;
	    }
	    return false;
	}
	
	

