$(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;
        });
		
		if (typeof document.idForm_spa !== "undefined") {
			start2();
		}
        start();
		
        if ($('#DatePicker').size() === 1) {
            var today = new Date(),
                rangeLow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1),
                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: true,
                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() + 1);
                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');
            });
        }
		
		// date picker spa
		
		if ($('#DatePicker-2').size() === 1) {
            var today = new Date(),
                rangeLow = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1),
                rangeHigh = new Date(today.getFullYear() + 1, 12, 31);
            var showLabelDate = function (argObj) {
                $('#DatePicker-2').val(datePickerController.printFormattedDate(argObj.date, "d-sl-m-sl-Y", true));
            };
            var opts = {
                lang: 'fr',
                formElements: {
                    "fromday-2": "j",
                    "frommonth-2": "n",
                    "fromyear-2": "Y"
                },
                positioned: "datepicker-holder-2",
                noTodayButton: true,
                callbackFunctions: {
                    "create": [showLabelDate],
                    "dateset": [showLabelDate]
                }
            };
            datePickerController.createDatePicker(opts);
            datePickerController.setSelectedDate('fromday-2', (function () {
                var dat = new Date($('#fromyear-2').val(), $('#frommonth-2').val(), $('#fromday-2').val());
            }()));
            datePickerController.setRangeLow("fromday-2", (function () {
                var dat = new Date();
                dat.setDate(dat.getDate() + 1);
                return datePickerController.printFormattedDate(dat, 'Y-m-d', false);
            }()));
            datePickerController.setRangeHigh("fromday-2", (function () {
                var dat = new Date();
                var year = (parseInt(dat.getFullYear() + 1, 10)) + '';
                return year + '1231';
            }()));
            $('#DatePicker-2').focus(function () {
                datePickerController.show('fromday-2');
				alert($(document.idForm_spa).serialize());
            });
        }
		
		
    });
});
