$(document).ready(function () {
    $('form#idForm').each(function () {
        var that = this;
        $(that).attr('name', 'idForm').attr('target', 'dispoprice');
        $(that).find('.symlink').hover(function () {
            $(this).addClass('hover');
        }, function () {
            $(this).removeClass('hover');
        });
        $(that).find('select#HotelList').change(function () {
            hhotelFormUpdateHotelnames(that);
        });
        $(that).find('select#fromyear').change(function () {
            update_departure();
        });
        $(that).find('#btn-submit').click(function () {
            hhotelDispoprice(that);
        });
        $(that).find('#link-cancel').click(function () {
            hhotelcancel($(that).find('#Clusternames').val(), '');
        });
        $(that).find('#link-options').click(function () {
            hhotelSearch($(that).find('#Clusternames').val(), "", "", "", "", "", "&amp;FSTBKNGTrackLink=");
        });
        $('a.book-now-link').live('click', function () {
            var rel = $(this).attr('rel'),
                patt = /offer\|(.*)\|(.*)/,
                result = patt.exec(rel),
                hn, oc;
            if (result.length === 3) {
                hn = result[1];
                oc = result[2];
                if (typeof (hn) !== 'undefined') {
                    hhotelResaDirect(hn, '', oc, '', 'offers', '');
                }
            }
            return false;
        });
        start();
        if ($('#DatePicker').size() === 1) {
            var today = new Date(),
                rangeLow = new Date(today.getFullYear(), today.getMonth(), today.getDate() ),
                rangeHigh = new Date(today.getFullYear() + 1, 12, 31);
            var showLabelDate = function (argObj) {
                    $('#DatePicker').val(datePickerController.printFormattedDate(argObj.date, "d-sl-m-sl-Y", true));
                };
            var opts = {
                lang: 'fr',
                formElements: {
                    "fromday": "j",
                    "frommonth": "n",
                    "fromyear": "Y"
                },
                positioned: "datepicker-holder",
                noTodayButton: false,
                callbackFunctions: {
                    "create": [showLabelDate],
                    "dateset": [showLabelDate]
                }
            };
            datePickerController.createDatePicker(opts);
            datePickerController.setSelectedDate('fromday', (function () {
                var dat = new Date($('#fromyear').val(), $('#frommonth').val(), $('#fromday').val());
            }()));
            datePickerController.setRangeLow("fromday", (function () {
                var dat = new Date();
                dat.setDate(dat.getDate() );
                return datePickerController.printFormattedDate(dat, 'Y-m-d', false);
            }()));
            datePickerController.setRangeHigh("fromday", (function () {
                var dat = new Date();
                var year = (parseInt(dat.getFullYear() + 1, 10)) + '';
                return year + '1231';
            }()));
            $('#DatePicker').focus(function () {
                datePickerController.show('fromday');
            });
        }
    });
});
