/**
 * Places an input element in the element with the id containerId. The element
 * gets the dijit id and name which is named by the argument elementName.
 * parameters must be an associative array with the keys named key and the
 * values named value. If the array only has one element a text box is placed
 * inside the element with the container id. This text box is readonly. If more
 * than one element is in the array a filtering select is placed inside the
 * container element. If a default value is given this will be selected in the
 * select element.
 * @param containerId
 * @param elementName
 * @param parameters
 * @param defaultValue
 */
function placeInputElement(containerId, elementName, parameters, defaultValue) {
    createdElement = null;
    if (parameters) {
        if (dijit.byId(elementName)) {
            dijit.byId(elementName).destroy();
        }
        dojo.create('span',
                {
                    id: 'inner' + elementName
                },
                containerId,
                'only');
        if (parameters.length == 1) {
            createdElement = new dijit.form.TextBox(
                {
                    name: elementName + 'Display',
                    id: elementName,
                    disabled: true,
                    value: parameters[0].item
                },
                'inner' + elementName
            );
            dojo.create('input',
                    {
                        name: elementName,
                        type: 'hidden',
                        value: parameters[0].key
                    },
                    containerId,
                    'first');
        } else {
            values = new Object();
            values.identifier = 'key';
            values.label = 'item';
            values.items = parameters;
            if (!defaultValue) {
                defaultValue = parameters[0].key;
            }
            createdElement = new dijit.form.FilteringSelect(
                {
                    id: elementName,
                    name: elementName,
                    searchAttr: 'item',
                    labelAttr: 'item',
                    store: new dojo.data.ItemFileReadStore(
                        {
                            data: values
                        }
                    ),
                    value: defaultValue
                },
                'inner' + elementName
            );
        }
    }
    return createdElement;
}


