function dynamicTextboxes(initialSetupDivId, initialSetupTextboxId, initialSetupMaxFields, initialSetupMaxLength){
    var initialDivContents = $$('#' + initialSetupTextboxId + '-container ' + 'div.' + initialSetupDivId);

    if (initialSetupMaxLength == null){
        initialSetupMaxLength = 500;
    }
    // ADD FIELD BTN ACTION
    addNewFields = function(divId, textboxId, maxFields, maxLength){

        $$('#' + textboxId + '-container ' + 'a.add-field-btn').each(function(el){
            Event.stopObserving(el, 'click');
            el.observe('click', function(event){
                closeTooltip(el, event);
                var newDivContents = $$('#' + textboxId + '-container ' + 'div.' + divId);
                var idIndex = newDivContents.length + 1;

                //       changeModalPanelHeight('additional-info-popup-panel', 29);

                var a = new Element('div', {});
                a.addClassName(divId + ' clearfix');
                if(textboxId =="titleExhibition") {
                    maxLength=100;
                }

                var output = new Element('input', {
                    'type': 'text',
                    'maxlength':maxLength,
                    'id':textboxId + idIndex,
                    'name':textboxId + idIndex
                });
                output.addClassName(divId + '-input');

                var delLink = new Element("a",{
                    'href':'javascript:void(0);',
                    'name' : 'del_field'
                });
                delLink.addClassName('min-field-btn tooltip');

                a.appendChild(output);

                if(idIndex < maxFields){
                    var addLink = new Element("a",{
                        'href':'javascript:void(0);',
                        'name' :'add_field'
                    });
                    addLink.addClassName('add-field-btn tooltip');

                    a.appendChild(addLink);
                }
                else{
                    delLink.style.margin = "0 0 0 45px";
                }

                $$('#' + textboxId + '-container ' + 'a.min-field-btn').each(function(item){
                    removeTooltip(item);
                });

                a.appendChild(delLink);

                if(idIndex > 2){
                    el.next().style.margin = "0 0 0 45px";
                    el.remove();

                }else{
                    el.removeClassName('add-field-btn');
                    el.addClassName('min-field-btn');
                    el.style.margin = "0 0 0 45px";
                    removeTooltip(el);
                }

                $(textboxId + '-container').appendChild(a);

                addNewFields(divId, textboxId, maxFields, maxLength);
                removeFields(divId, textboxId, maxFields, maxLength);
                GMX.tooltip.setup();
            });
        });
    }

    // REMOVE FIELD BTN ACTION
    removeFields = function(divId, textboxId, maxFields, maxLength){

        $$('#' + textboxId + '-container ' + 'a.min-field-btn').each(function(el){
            Event.stopObserving(el, 'click');
            el.observe('click', function(event){

                var divContents = $$('#' + textboxId + '-container ' + 'div.' + divId);
                var lastIndex = -1;

                //These are the cases in which the links at the right of the textbox need to be changed.
                //1. The last element is being removed: The previous element needs to add a + sign
                //2. There are 6 elements: A plus sign needs to be added to the last element
                //3. There are 2 elements: The first element will need to have a + sign and remove the - sign.
                if((el.up(0) == divContents[divContents.length - 1]) || (divContents.length == 2) || (divContents.length == maxFields)){
                    lastIndex = divContents.length - 2;
                }

                el.up(0).remove();

                var newDivContents = $$('#' + textboxId + '-container ' + 'div.' + divId);

                for(var i=0; i<newDivContents.length; i++){
                    var index = i+1;
                    newDivContents[i].getElementsByTagName("input")[0].id = textboxId+index;
                    newDivContents[i].getElementsByTagName("input")[0].name = textboxId+index;

                }

                //More processing only needs to be performed when the last element was removed or if only one element is left
                //since the links at the right of the textbox need to be updated to the correct + and - signs.
                //If an element other than the last is removed,
                if(lastIndex > -1){
                    closeTooltip(el, event);
                    var addLink = new Element("a",{
                        'href':'javascript:void(0);',
                        'name' :'add_field'
                    });
                    addLink.addClassName('add-field-btn tooltip');
                    if(lastIndex == 0){
                        var links = newDivContents[lastIndex].getElementsByTagName("a");
                        var linksLength = links.length;
                        for(var j=(linksLength-1); j>=0; j--){
                            links[j].remove();
                        }
                        newDivContents[lastIndex].appendChild(addLink);
                    }else{
                        var delLink = new Element("a",{
                            'href':'javascript:void(0);',
                            'name' :'del_field'
                        });
                        delLink.addClassName('min-field-btn tooltip');
                        newDivContents[lastIndex].getElementsByTagName('a')[0].remove();
                        newDivContents[lastIndex].appendChild(addLink);
                        newDivContents[lastIndex].appendChild(delLink);
                    }
                    
                }

                addNewFields(divId, textboxId, maxFields, maxLength);
                removeFields(divId, textboxId, maxFields, maxLength);
                GMX.tooltip.setup();
            });
        });
    }

    addNewFields(initialSetupDivId, initialSetupTextboxId, initialSetupMaxFields, initialSetupMaxLength);
    removeFields(initialSetupDivId, initialSetupTextboxId, initialSetupMaxFields, initialSetupMaxLength);
    GMX.tooltip.setup();
}

function closeTooltip(el, e){
    clearTimeout(GMX.tooltip.timeout);
    Event.stop(e);
    GMX.tooltip.timeout = setTimeout( function(){
        var evt = window.event || e //cross browser event object
        GMX.tooltip.close(el, evt);
    }, 0 );
}

function removeTooltip(item){
    item.removeAttribute('rel');
    item.stopObserving('mouseover');
    if(item.hasClassName('tooltip')){
        item.removeClassName('tooltip');
    }
    if(item.hasClassName('tooltip-loaded')){
        item.removeClassName('tooltip-loaded');
    }
}

function closePopupAfterDelete(){
    if(GMX.popups.idWrapperPopup != null){
        $(GMX.popups.idWrapperPopup).fade({
            duration: 0.3,
            from: 1,
            to: 0 ,
            afterFinish: function(){
                $('allover').style.display = "none";
                $(GMX.popups.idWrapperPopup).removeClassName('open');
                GMX.popups.idWrapperPopup = null;
            }
        });

    }
}

/*
	function handleOptions
	- this function will handle the actions needed for all the popups with multiple tabs
		and multiple options actions - to be used in popups like GENRES, REGIONS
*/
var handleOptions = function(item){
    //mouseover and mouseout list items options
    item.observe('mouseover', function(){
        if(!item.down(0).disabled){
            item.style.backgroundColor='#CCC';
            item.style.cursor='pointer';
        }
    //this.addClassName("option-style-genres");
    });
    item.observe('mouseout', function(){
        //this.removeClassName("option-style-genres");
        item.style.backgroundColor='';
        item.style.cursor='';
    });

    /*actions for the default main selected options:
		- show the sub-options for the last selected main option
	*/
    item.observe('click', function(){
        if(!item.down(0).disabled){
            if(!item.down(0).checked){
                item.down(0).checked = true;
                item.up(0).childElements().each(function(it, index){
                    if(it == item){
                        if(item.up(1).next(0).childElements()[index]){
                            item.up(1).next(0).childElements()[index].show();

                        }
                    }else{
                        if(item.up(1).next(0).childElements()[index]){
                            item.up(1).next(0).childElements()[index].hide();
                        }
                    }
                });
            }else{
                item.up(0).childElements().each(function(it, index){
                    if(it == item){
                        if(item.up(1).next(0).childElements()[index]){
                            item.up(1).next(0).childElements()[index].show();

                        }
                    }else{
                        if(item.up(1).next(0).childElements()[index]){
                            item.up(1).next(0).childElements()[index].hide();
                        }
                    }
                });
            }
        }
    });
    if(item.down(0).checked){

        item.up(0).childElements().each(function(it, index){
            if(it == item){
                if(item.up(1).next(0).childElements()[index]){
                    item.up(1).next(0).childElements()[index].show();

                }
            }else{
                if(item.up(1).next(0).childElements()[index]){
                    item.up(1).next(0).childElements()[index].hide();
                }
            }
        });
    }
}