I have a website I am currently debugging, http://display.ist-apps.com/.

When you select a ski resort, then go on to select a date, the dates relating to that ski resort show. However if you then go back and select another ski resort, the dates do not update they still continue to show the ones from the ski resort you originally selected.

This is a debug piece of work I am doing based on something someone else built so it's a bit of a toughie, any help is appreciated.

Here is the related (I think) JS file.

Code:
(function($){$.fn.
dynamicResortSelect = function(options)
{
    var defaults = {
        'dateFormat'            : 'dd/mm/y',
        'forceDatePickerZindex' : false,
        'uris'                  : {
            'get_availiable_durations'   : '/get-availiable-durations',
            'get_availiable_start_dates' : '/get-availiable-start-dates'}};
    
    var options = $.extend(defaults, options);
    var datePickerDrawn = false;
    var durationsDrawn = false;
    var currentMonth = '';
    var resortTitle = '';
    var resorts = [];
    
    function _updateDurations(dateText, durationsValue)
    {
        $.getJSON(options.uris.get_availiable_durations, {'resort_title': resortTitle, 'start_date': dateText}, function (data)
        {
            var options = {0:'Duration...'};
            
            for (var i in data)
            {
                options[data[i]] = data[i]+' Nights'
            }
            
            if (durationsValue < 0)
            {
                $('.duration_container').addClass('disabled');
                $('select[name="duration"]')
                    .selectBox('disable')
                    .selectBox('value', 0);
            }
            else
            {
                $('.duration_container').removeClass('disabled');
                $('select[name="duration"]')
                    .selectBox('options', options)
                    .selectBox('enable')
                    .selectBox('value', durationsValue);
            }
        });
    }
    /*
    function _isValidDate(dates, date)
    {
        var formattedMonth = date.getMonth()+1;
        
        if (formattedMonth < 10)
            formattedMonth = '0'+formattedMonth;
            
        var formattedDate = date.getDate();
        if (formattedDate < 10)
            formattedDate = '0'+formattedDate;
        
        var dateFormatted = date.getFullYear()+'-'+formattedMonth+'-'+formattedDate+' 00:00:00';
        
        return [$.inArray(dateFormatted, dates) != -1];
    }*/
    
    function _drawDatePicker(startDate, endDate, dates)
    {
        $('.date_picker_conatiner').removeClass('disabled');
        
        $('.date_picker_conatiner .date_picker').removeAttr('disabled').datepicker(
        {
            dateFormat: options.dateFormat,
            minDate: startDate,
            maxDate: endDate,
            
            beforeShow: function()
            {
                if (typeof(options.forceDatePickerZindex) == 'number')
                    setTimeout('jQuery("#ui-datepicker-div").css("z-index", "'+options.forceDatePickerZindex+'")', 1);
            },
            
            beforeShowDay: function(date)
            {
                var formattedMonth = date.getMonth()+1;
                if (formattedMonth < 10)
                    formattedMonth = '0'+formattedMonth;
                    
                var formattedDate = date.getDate();
                if (formattedDate < 10)
                    formattedDate = '0'+formattedDate;
                
                var dateFormatted = date.getFullYear()+'-'+formattedMonth+'-'+formattedDate+' 00:00:00';
                
                return [$.inArray(dateFormatted, dates) != -1];
            },
            
            onSelect: function(dateText, inst)
            {
                _updateDurations(dateText, 0);
            }
        });
    }
    
    function _updateDatePicker(value)
    {
        if (datePickerDrawn)
            $('.date_picker').destroy();
        
        resortTitle = resorts[value];
        
        $.getJSON(options.uris.get_availiable_start_dates, {'resort_title': resortTitle}, function (data)
        {
            var startDate = data[0];
            var endDate = data[data.length-1];
        
            currentMonth = startDate.substring(5, 7);
            startDate = _buildDate(startDate);
        
            endDate = _buildDate(endDate);
        
            _drawDatePicker(startDate, endDate, data);
        });
        
        return true;
    }
    
    function _buildDate(text)
    {
        ret = new Date(
            text.substring(0, 4),
            (text.substring(5, 7) - 1),
            text.substring(8, 10));
        
        return ret;
		alert('alerting');
    }
    

    return this.each(function()
    {
        var alreadyPopulated = $('select[name="duration"]').val() != 0;
        $('select[name="first_hotel_id"] option').each(function()
        {
            resorts[$(this).val()] = $(this).text();
        });
        
    //    $('select[name="first_hotel_id"]').selectBox();
        $('select[name="first_hotel_id"]').change(function()
        {
            var value = $(this).val();
            _updateDatePicker(value);
            /*
            if (durationsDrawn)
                $('select[name="duration"]').*/
        });
        
    //    $('select[name="duration"]').selectBox();
    //    alert("true");

        if (alreadyPopulated)
        {
	
            _updateDatePicker($('select[name="first_hotel_id"]').val());
            durationsValue = $('select[name="duration"]').val();
            _updateDurations($('.date_picker_conatiner .date_picker').val(), durationsValue);
        }
    });
}})(jQuery);