$(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(){hhotelFormCancel(document.idForm);});
			function hhotelFormCancel(myForm){
			 var CName = myForm.Hotelnames.value;
			 var languetype = typeof myForm.langue;
			 var langue;
			 if (languetype == "undefined")
			  langue = "";
			 else
			  langue = myForm.langue.value;
			 if (CName == null || CName == 'All' || CName == ''){ alert('Please select a hotel first'); return (false); }
			 return hhotelcancel(CName, langue);
			}
		

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

     	

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

	});
	
});
