﻿// JScript File
//function TWAutoCompleteInit()
//{
//}

var oDataSource;
function TWAutoCompleteInit(txtCityCounty_ClientID,cityCountyAutocomplete_ClientID,hdnCountyId_ClientID)
{
  
    if(oDataSource == undefined || oDataSource == null)
    {
        oDataSource = new YAHOO.widget.DS_XHR("/wizard/step/county/lookup/", ["\n", "\t"]);
        oDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_FLAT;
        oDataSource.maxCacheEntries = 60; 
        oDataSource.queryMatchSubset = true;
    }

	var myAutoComp = new YAHOO.widget.AutoComplete(txtCityCounty_ClientID,cityCountyAutocomplete_ClientID, oDataSource);
	if(myAutoComp.itemSelectEvent !== null)
	{
	    myAutoComp.typeAhead = true;
	    myAutoComp.queryDelay = 0.3;
	    myAutoComp.maxResultsDisplayed = 100;
	    myAutoComp.minQueryLength = 1;
	    myAutoComp.forceSelection = false;
	    myAutoComp.autoHighlight = true;
	    myAutoComp.formatResult = function (oResultItem, sQuery) {
			     var sLabel = oResultItem[0];
			    var sLabelQuery = sLabel.substr(0, sQuery.length);
			    var sLabelRemainder = sLabel.substr(sQuery.length);
			    //var aMarkup = ["<div id='ysearchresult'><span style='font-weight:bold'>",
			    var aMarkup = ["<div id='ysearchresult'><span style='font-weight:bold'>",
				    sLabelQuery,
				    "</span>",
				    sLabelRemainder,
				    "</div>"];
			    return (aMarkup.join(""));
		    }

	    myAutoComp.itemSelectEvent.subscribe(
        function (oSelf, eItem, oData){
		        var sKey = eItem[2][1];
		        if(sKey != null){
			        YAHOO.util.Dom.get(hdnCountyId_ClientID).value = sKey;
    			    
		        }
	        }
	    );
	}
}




