/*
   GESTIONE BOOKING FORM
   HOTEL PLAZA
   by mcanever@fastbooking.com
*/
$(document).ready(function () {
		//inizializzo la booking form (fblib.js)
		start();
		// var. globali per datepickers
		var i=0;
		var checkinDate= new Date();
		var cella_checkin="#id_inesistente";
		$("#fd-today").mouseover(function() {
			alert("mouseover"); //evidenziaCheckin(null);
		});
		

		var evidenziaCheckin = function(argObj) {
				if (cella_checkin != "#fd-today .cd-"+datePickerController.printFormattedDate(checkinDate, "Y-m-d", true)) 
					{ 
					 $(cella_checkin).removeClass("FB-CHECKIN");
					 cella_checkin="#fd-today .cd-"+datePickerController.printFormattedDate(checkinDate, "Y-m-d", true);
					 //$(".title_home h2").html(++i + cella_checkin+" html="+$(cella_checkin).html());
					}
				if (!$(cella_checkin).hasClass("FB-CHECKIN")) {
				 $(cella_checkin).addClass("FB-CHECKIN");
				 //$("#home_left h5").html ((++i) + "FB-CHECKIN "+" html="+$(".FB-CHECKIN").html());
				}
			};
			
		var Dom_ready = function (obj) {
		
		$("#fd-today").mouseover(function() {
				evidenziaCheckin(null);
			});
			evidenziaCheckin(null);		
		}
		
		// SECONDO DATEPICKER (checkout)
		// id: "today"
		if($('#DatePicker2').size() === 1) {
			var today			= new Date(),
	            rangeLow		= new Date(today.getTime()+1000*3600*24),
	            rangeHigh		= new Date(today.getFullYear() + 1, 11, 31);
			var showLabelDate	= function (argObj) {
				$('#DatePicker2').val(datePickerController.printFormattedDate(argObj.date, "d-sl-m-sl-Y", true));
			};
			var opts = {
				lang				: 'fr',
				formElements		: {"today":"j", "tomonth":"n", "toyear":"Y"},
				positioned			: "datepicker-holder2",
				noTodayButton		: true,
				callbackFunctions	: {"create":[showLabelDate],"dateset":[showLabelDate], "domcreate":[Dom_ready]},
				noFadeEffect: true
				
			};
			datePickerController.createDatePicker(opts);
			datePickerController.setRangeLow("today", (function () {
				var dat = new Date();
				dat=new Date(dat.getTime()+1000*3600*24);
				return datePickerController.printFormattedDate(dat, 'Y-m-d', false);
			}()));
			datePickerController.setRangeHigh("today", (function () {
				var dat = new Date();
				//dat=new Date(dat.getTime()+364*1000*3600*24); //MAX: fra 364 giorni (evitiamo che appaia il bottone dell'anno prossimo)
				dat=new Date(today.getFullYear() + 1, 11, 31); 				
				return datePickerController.printFormattedDate(dat, 'Y-m-d', false);
			}()));
			$('#DatePicker2').focus(function () {
				datePickerController.show('today');
			});
		}
		
		
		// PRIMO DATEPICKER (checkin)
		// id: "fromday"
		if($('#DatePicker').size() === 1) {
			var today			= new Date(),
	            rangeLow		= new Date(),
	            rangeHigh		= new Date(today.getFullYear() + 1, 11, 31);
			var showLabelDate2	= function (argObj) {
				$('#DatePicker').val(datePickerController.printFormattedDate(argObj.date, "d-sl-m-sl-Y", true));
				checkinDate = new Date(argObj.date.getTime());
				var nextDay=new Date(argObj.date.getTime()+1000*3600*24);
				datePickerController.setSelectedDate('today', datePickerController.printFormattedDate(nextDay, "Y-m-d", true));
				datePickerController.setRangeLow('today', datePickerController.printFormattedDate(checkinDate, "Y-m-d", true));
				evidenziaCheckin(null);
			};
			var opts = {
				lang				: 'fr',
				formElements		: {"fromday":"j", "frommonth":"n", "fromyear":"Y"},
				positioned			: "datepicker-holder",
				noTodayButton		: true,
				callbackFunctions	: {"create":[showLabelDate2],"dateset":[showLabelDate2]},
				noFadeEffect:true
			};
			datePickerController.createDatePicker(opts);
			
			datePickerController.setRangeLow("fromday", (function () {
				var	dat=new Date();
				dat=new Date(dat.getTime());
				return datePickerController.printFormattedDate(dat, 'Y-m-d', false);
			}()));
			datePickerController.setRangeHigh("fromday", (function () {
				var dat = new Date();
				
				//dat=new Date(dat.getTime()+330*1000*3600*24); //MAX: fra 330 giorni (evitiamo che appaia il bottone dell'anno prossimo)
				dat=new Date(today.getFullYear() + 1, 11, 31);
				return datePickerController.printFormattedDate(dat, 'Y-m-d', false);
			}()));
			$('#DatePicker').focus(function () {
				datePickerController.show('fromday');
			});
		}


$("#today").blur();

});


$(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('select#toyear').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;
     	});



	});

});

