Autocomplete = function (textid, contid, url, selectItem_fn, unmatch_fn, multi)
{

	this.ds = new YAHOO.util.XHRDataSource(url);
	this.ds.connMethodPost = true

    this.ds.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
    this.ds.responseSchema = {
		resultsList:"options",
		fields : ['text','value']
    };

	
	this.config = {
		'animHoriz':false,
		'animVert':false
	}
	if(multi){
		this.config['delimChar'] = [','];
	}
    // Enable caching
    this.ds.maxCacheEntries = 5;
	
	this.autocomp=new YAHOO.widget.AutoComplete(document.getElementById(textid),document.getElementById(contid),this.ds,this.config);
	this.autocomp.minQueryLength = 2;
	this.autocomp.generateRequest = function(sQuery) {
        return "noLayout=true&query=" + sQuery ;
    };

	var onSelectItem = function(sType, aArgs){
		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
		if(selectItem_fn){
			selectItem_fn(oData[1],oData[0]);
			
		}		
	}
	
	var show_ajax_loader = function(){
		document.getElementById('ajax_loader').style.display = 'block';
	}

	var hide_ajax_loader = function(){
		document.getElementById('ajax_loader').style.display = 'none';
	}
	
	this.autocomp.itemSelectEvent.subscribe(hide_ajax_loader)
	this.autocomp.textboxBlurEvent.subscribe(hide_ajax_loader)
	this.autocomp.dataRequestEvent.subscribe(show_ajax_loader)
	this.autocomp.unmatchedItemSelectEvent.subscribe(hide_ajax_loader)
	this.autocomp.itemSelectEvent.subscribe(onSelectItem)
	// this.autocomp.textboxKeyEvent.subscribe(checkemptyquery)
	if(unmatch_fn){
		this.autocomp.unmatchedItemSelectEvent.subscribe(unmatch_fn)
	}
};