
function am_autocomplete(eName,mod,act)
{

    var objName='#'+eName;
    if(!act)
    {
        var action='autocomplete_'+eName;    
    }
    else
    {
        var action=act;
    }

          
    $(objName).autocomplete({
        source: function( request, response ){
            $.ajax({ 
                url: 'index.php',
                data: {
                    q: request.term,
                    mod: mod,
                    action: action    
                },               
                type: 'POST',  
                dataType: 'json',
                error: function(x,y,z) {$('#err_'+eName).html('Couldn\'t load list of options. Server too busy.');},
                success: function( data ){ 
                   if($('#err_'+eName).html()=='Couldn\'t load list of options. Server too busy.') 
                   {
                      
                       $('#err_'+eName).html('');
                   }
                    response( 
                    $.map( 
                    data, function( item ) {return {label: item.label, value: item.value}}
                        )
                    );
                }            
            });             
        },
        highlight: true,       
        minLength: 2               
        
    }).data( 'autocomplete' )._renderItem = function( ul, item ) {
        var pattern='('+$(objName).val()+')';                
        return $( '<li></li>' )
        .data( 'item.autocomplete', item )
        .append('<a>'+ item.label.replace(new RegExp(pattern,'gi'),'<strong>$1</strong>')+'</a>' )
        .appendTo( ul );
    };    
}