$(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').unbind('click').click(function(){
			if ($(that).find('input[name="Hotelnames"]').attr('value') !="All") {
				hhotelcancel($(that).find('input[name="Hotelnames"]').attr('value'),'');
			} else {
				alert("Please select an Hotel first / Seleziona un Hotel"); 
			}
		 });

		$(that).find('#link-options').click(function () {
			hhotelSearch($(that).find('#Clusternames').val(), "", "", "", "", "", "&amp;FSTBKNGTrackLink=");
		});

		//	$('a.book-now-link').each(function () {
		//		var rel		= $(this).attr('rel'),
		//			patt	= /offer-([0-9]+)-(.*)/,
		//			result	= patt.exec(rel),
		//			bf,
		//			hn,
		//			oc;
		//		if (result.length === 3) {
		//			bf = booking_forms['domain_' + result[1]];
		//			oc = result[2];
		//			if (typeof(bf) !== 'undefined') {
		//				hn = bf.hotel_name;
		//				if (typeof(hn) !== 'undefined') {
		//					$(this).click(function () {
		//						hhotelResaDirect(hn, '', oc, '', 'offers', '');
		//						return false;
		//					});
		//				}
		//			}
		//		}
		//	});

     	$('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() + 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');
			});
		}

	});
	
});
