﻿//$.getScript('/hkecautocomplete/jquery.autocomplete-min.js', function() {
//});
	
function search_Autocomplete(searchbox, options) {
		
	//set default
	this.searchbox = 'searchbox';		
	this.options = { 
				serviceUrl:'/hkecautocomplete/handler.php',				 				
				delimiter: /(,|;)\s*/, // regex or character
				
				params: { action:'getKeyword', category:'', limit:10},
				noCache: true,
				minChars:1,
				maxHeight:500,
				width:300, 								
				zIndex: 9999					
			  };
	
	//ini value
	if (searchbox) { this.searchbox = searchbox;}	
	if (options){
		if(typeof (options.category)!="undefined"){this.options.params.category = options.category;}
		if(typeof (options.limit)!="undefined"){this.options.params.limit = options.limit;}
		if(typeof (options.noCache)!="undefined"){this.options.noCache = options.noCache;}
		if(typeof (options.minChars)!="undefined"){this.options.minChars = options.minChars;}
		if(typeof (options.maxHeight)!="undefined"){this.options.maxHeight = options.maxHeight;}
		if(typeof (options.width)!="undefined"){this.options.width = options.width;}
		if(typeof (options.zIndex)!="undefined"){this.options.zIndex = options.zIndex;}
		if(typeof (options.onSelect)!="undefined"){this.options.onSelect = options.onSelect;}
	}
	
	this.loadCSS("/hkecautocomplete/css/autocomplete-styles.css");
	
	return;
}

search_Autocomplete.prototype.init = function () {
	jQuery("#"+this.searchbox).autocomplete(this.options );
	return;
}

search_Autocomplete.prototype.loadCSS = function (url) {
    var css = document.createElement("link");
    css.type = "text/css";
    css.rel = "stylesheet";
    css.href = url;
    document.getElementsByTagName("head")[0].appendChild(css);
    return;
}


