<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">var ric = jQuery.noConflict();
    ric(document).ready(function() {
        var roomsMax = 3;

        var regex = /^mySelect_(.*)$/;
        var cloneIndex = 0;



        // Remove an apartment:
        ric("#remove_room").click(function(){    removeRoom();});
        var removeRoom = function() {
            if (cloneIndex&gt;1){
                cloneIndex--;
                ric("#camere_persone_"+ cloneIndex).remove();
                ric("#nrcamere").attr("value", (cloneIndex));
            }
            // Hide remove button:
            if (cloneIndex &lt;= 1)
                ric("#remove_room").hide();
            if (cloneIndex &lt; roomsMax)
                ric("#add_room").show();

            // Hide .formError:
            ric(".formError").remove();
        }


        // Populate hidden input for countryname in full (used for email)
        ric('#land').change(function() {
            var countrynameoption = ric(this).find(":selected");
            var countrynamefull = ric(countrynameoption).text();
            ric('#countrynamefull').val(countrynamefull);

            // empty input if not selection on #land
            if (ric(countrynameoption).val() == ""){
                ric('#countrynamefull').val("");
            }
        });

        // Add apartment:
        ric("#add_room").click(function(){

                if (cloneIndex == roomsMax)
                    return;

                // Clone #camere_persone, change id and put it after last .camerePersone:
                ric("#camere_persone").clone().attr("id", "camere_persone_" + cloneIndex).insertAfter('.camerePersone:last').show();

                // Add cloneIndex to id/name of each element:
                ric("#camere_persone_"+ cloneIndex).find("*").each(function() {
                    var id = this.id || "";
                    if (id.length&gt;0){
                        this.id = this.id + "_" +(cloneIndex);
                    }
                    var name = this.name || "";
                    if (name.length&gt;0){
                        this.name = this.name + "_" +(cloneIndex);
                    }
                });

                ric("#nradulti_" + cloneIndex).addClass( "validate[required]" );
                //ric("#nrstanze_" + cloneIndex).addClass( "validate[required,custom[SelectNotEmpty]]" );

                // checl category only if present!
                if ( ric("#categoria_" + cloneIndex) ){
                    ric("#categoria_" + cloneIndex).addClass( "validate[required]" );
                }


                // add/remove classes to annibamb selects
                // select nrbamb is always showed
                ric('#mySelect_'+cloneIndex).change(function() {
                    var id = this.id;
                    var match = id.match(regex) || [];
                    if (match.length &gt; 0) {
                        //remove class to selects to reset
                        ric("#formContainer_"+match[1] + " div:not('.alwaysShow') select").removeClass("validate[required]");
                        //delete error cause it remains even if the annibamb select is hidden
                        ric(".formError").remove();
                        ric("#formContainer_"+match[1] + " div:not('.alwaysShow') select").change();
                        ric("#formContainer_"+match[1] + " div:not('.alwaysShow')").hide();
                        ric("#formContainer_"+match[1] + " .show" + ric(this).val()).show();
                        ric("#formContainer_"+match[1] + " .show" + ric(this).val()+ " select").addClass( "validate[required]" );
                    }
                });
                ric('#mySelect_'+cloneIndex).change(); // simulate a change event to trigger the above

                ric("#mySelect_" + cloneIndex).addClass( "validate[required]" );

                // Title:
                ric("#camere_persone_"+ cloneIndex + " .camere_persone_title").append('Richiesta '+(cloneIndex+1));

                // Counter:
                ric("#nrcamere").attr("value", (cloneIndex+1));

                cloneIndex++;

                // Show/hide buttons:
                if (cloneIndex&gt;1)
                    ric("#remove_room").show();
                if (cloneIndex==roomsMax)
                    ric("#add_room").hide();

                // Hide .formError:
                ric(".formError").remove();
        });



        // Remove all apartments:
        ric("button#cancel").click(function(){
            while(cloneIndex&gt;1){
                removeRoom();
            }
            ric(".show1, .show2, .show3, .show4").hide();
        });

        // Fix validation bug for datepicker and jquery validation
        ric(document).on('change','#datepicker',function(){
            ric('.datepickerformError').hide();
        })
        ric(document).on('change','#datepicker2',function(){
           ric('.datepicker2formError').hide();
        })

        // Add first apartment:
        ric("#add_room").click();



    });
</pre></body></html>