
YAHOO.example.ACFlatData = new function()
{ 
    // Define a custom formatter function 
    this.fnCustomFormatter = function(oResultItem, sQuery) { 

		var sValue = oResultItem[0]; 
   	    var sStateId = oResultItem[1];
   	    var sKey = oResultItem[2];
   	    
   	    var expQuery = stringToRegExp(sQuery, 'gi');
   	     
		var aMarkup = ["<div>", 
		    sValue.replace(expQuery, boldify(sQuery)), 
		    "</div>"]; 
		return (aMarkup.join("")); 
	};
	
	function boldify(text)
	{
    	return '<span style=\"font-Weight:bold\">' + text + '<\/span>';
	}

	function stringToRegExp(pattern, flags)
	{
    return new RegExp(
        pattern.replace(/[\[\]\\{}()+*?.$^|]/g, function(m){return '\\'+m;}),
        flags);
	}
	
	/**
	 * Fired when an item is selected via mouse click, ENTER key, or TAB key.
	 *
	 * @event itemSelectEvent
	 * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance.
	 * @param elItem {HTMLElement} The selected &lt;li&gt; element item.
	 * @param oData {Object} The data returned for the item, either as an object,
	 * or mapped from the schema into an array.
	 */
			
	function autoCompleteItemSelect(oSelf, elItem, oData)
	{
		// NOTE: Bug in YUI. oData parameter is not being populated.
		// http://extjs.com/forum/showthread.php?t=1202
		// get required data from elItem 
		// elItem[2][1] University Name
		// elItem[2][0] State ID
		// elItem[2][2] University ID
		// elItem[2][3] Country ID
		
		//store universityId in hiden field
		document.getElementById('hdnUniversity').value = elItem[2][2];
		
		//auto select university and state for the selected university
		selectComboItemByValue("selState",elItem[2][1]);
		selectComboItemByValue("selCountry",elItem[2][3]);
		
		enableDisableGoButton();
	}
			
	// Instantiate one XHR DataSource and define schema as an array: 
    //     ["Record Delimiter", 
    //     "Field Delimiter"] 
    this.oACDS = new YAHOO.widget.DS_XHR("ajaxSearch.php", ["\n", "|"]); 
    this.oACDS.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT; 
    this.oACDS.maxCacheEntries = 0; 
    this.oACDS.queryMatchSubset = false;
    
    // Instantiate third AutoComplete 
    this.oAutoComp = new YAHOO.widget.AutoComplete('txtUniversity','divAutoCompleteSearch', this.oACDS); 
    this.oAutoComp.queryDelay = 0; 
    this.oAutoComp.minQueryLength = 3;
    this.oAutoComp.formatResult = this.fnCustomFormatter; 
    this.oAutoComp.itemSelectEvent.subscribe(autoCompleteItemSelect);
};
