﻿var Agora_AutoComplete_Collection = new Array();
DataFloat.Agora.Util.AutoComplete = function(FieldId, FieldKey, RecordType, ServiceAutoComplete, MinChar, Width, Where, ClickFnc, AutoFill){
    $AgoraLog.WriteLog('[DataFloat.Agora.Util.AutoComplete] Field: ' + FieldId + ' - Initializing');
    ServiceAutoComplete = (DataFloat.Agora.Util.IsEmptyOrNull(ServiceAutoComplete)) ? DataFloat.Agora.Services.ServiceAutoComplete : ServiceAutoComplete ;
    AFill = (DataFloat.Agora.Util.IsEmptyOrNull(AutoFill) && AutoFill!=false) ? true : AutoFill;
    MinChar = DataFloat.Agora.Util.IsEmptyOrNull(MinChar) ? 2 : MinChar;
    Width = DataFloat.Agora.Util.IsEmptyOrNull(Width) ? 0 : Width;
    //This function is ready to extend
    eval("var Params = {'RecordType' : '" + RecordType + "', 'Where' : '" + ((Where == undefined)? '' : Where) + "', 'FieldKey' : '" + FieldKey + "', 'Agora__ItemPerPage' : '10'}");
    if ($("#" + FieldId).autocomplete != undefined){
        Agora_AutoComplete_Collection['AutoComplete_' + RecordType + '_' + FieldKey] = $("#" + FieldId).autocomplete(
		    ServiceAutoComplete,
		    {
			    delay:10,
			    minChars:MinChar,
			    matchSubset:1,
			    matchContains:1,
			    cacheLength:0,
			    autoFill:AFill,
			    maxItemsToShow: 10,
			    formatItem:DataFloat.Agora.Util.AutoComplete.FormatItem,
			    onItemSelect:ClickFnc,
			    queryStringField: 'Value',
			    extraParams : Params,
			    width : Width,
			    multiple : true
		    }
	    );
	    $AgoraLog.WriteLog('[DataFloat.Agora.Util.AutoComplete] Field: ' + FieldId + ' - Completed');
	}else{
	    $AgoraLog.WriteLog('[DataFloat.Agora.Util.AutoComplete] Field: ' + FieldId + ' - Error to setup the AutoComplete');
	}
	

};


DataFloat.Agora.Util.AutoComplete.FormatItem = function(row) {
	return row[0];
}

DataFloat.Agora.Util.AutoComplete.ClickItem = function(row) {
    alert(row.selectValue);
	//return row[0];
}



