/**
 * Autocomplete elements 
 *
 */
function AC_Elements()
{
    // init options
    this.options =
    {
	minChars: 2,
	deferRequestBy: 300,
	noCache: true
    };

    // elements
    this.elements = {};

}

AC_Elements.prototype.factory = function(id, context)
{
    var element_id = this.getElementId(id, context);
    
    if (!this.elements[element_id]) {
	var element = $(id, context).autocomplete(this.options);
	this.elements[element_id] = element;
    }
}

AC_Elements.prototype.setOptions = function(id, context, options)
{
    var element_id = this.getElementId(id, context);
    
    if (!this.elements[element_id]) {
	throw('Element with given id and context does not exist');
    }
    
    this.elements[element_id].setOptions(options);
}

AC_Elements.prototype.getElementId = function(id, context)
{
    return id + context;
}

AC_Elements.prototype.disable = function()
{
    for (var id in this.elements) {
	this.elements[id].disable();
    }
}

AC_Elements.prototype.enable = function()
{
    for (var id in this.elements) {
	this.elements[id].enable();
    }
}
