/* ###### CREATION DATE: 2025-11-24 19:09:37 ###### */

	function GCCustomCalendarAndree(options)
	{	
		var dest_calendar 				= this;
		this.current_date 				= new Date();
		this.selected_date				= null;
		this.month_names 				= ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];
		this.days_names	  				= ["lunedi'", "Martedi'", "Mercoledi'", "Giovedi'", "Venerdi'", "Sabato", "Domenica"];
		this.days_short_names			= ["L", "M", "M", "G", "V", "S", "D"];
		this.time_title					= "Alle ore";
		this.left_mounth_arrow			= "&laquo;";
		this.right_mounth_arrow			= "&raquo;";
		
		this.options 					= (typeof(options)!="undefined" )?options:{};
		
		$.extend(this.options, options);
		
		this.options.onselect			= (typeof(this.options.onselect)!="undefined")?options.onselect:function(dest_date, calendar_obj, e){alert(dest_date)};
		this.options.dest_selector 		= (typeof(options.dest_selector)!="undefined")?options.dest_selector:"";		
		this.options.prop_cels 			= (typeof(options.prop_cels)!="undefined")?options.prop_cels:"";
		this.options.date_time_mode 	= (typeof(options.date_time_mode)!="undefined")?options.date_time_mode:false;
		this.options.selected_date 		= (typeof(options.selected_date)!="undefined")?options.selected_date:null;
		this.options.active_dates 		= (typeof(options.active_dates)!="undefined")?options.active_dates:null;
		this.options.all_dates 			= (typeof(options.all_dates)!="undefined")?options.all_dates:false;

		this.options.month_names		= (typeof(options.month_names)!="undefined")?options.month_names:this.month_names;
		this.options.days_names 		= (typeof(options.days_names)!="undefined")?options.days_names:this.days_names;
		this.options.days_short_names 	= (typeof(options.days_short_names)!="undefined")?options.days_short_names:this.days_short_names;

		this.options.time_title 		= (typeof(options.time_title)!="undefined")?options.time_title:this.time_title;
		this.options.left_mounth_arrow 	= (typeof(options.left_mounth_arrow)!="undefined")?options.left_mounth_arrow:this.left_mounth_arrow;
		this.options.right_mounth_arrow = (typeof(options.right_mounth_arrow)!="undefined")?options.right_mounth_arrow:this.right_mounth_arrow;
		
		if ((typeof(this.options.selected_date)!="undefined" && this.options.selected_date!='' && this.options.selected_date!=null) && this.options.selected_date.replace)
		{
			var dest_str = "";
			var selected_date_split = this.options.selected_date.replace(/\//g,"-").replace(/:/g,"-").replace(/ /g,"-").split("-");

			if (selected_date_split.length>=3) dest_str = dest_str + selected_date_split[0] + "-" + selected_date_split[1] + "-" + selected_date_split[2];
			if (selected_date_split.length>=6) dest_str = dest_str + "T" + selected_date_split[3] + ":"+selected_date_split[4] + ":" + selected_date_split[5];

			this.selected_date = new Date(dest_str);		
		}
		
		if (this.options.prop_cels!="" && 1==0)
		{
			var props_array = this.options.prop_cels.split("_");
			$(window).resize(function(){$(dest_calendar.options.dest_selector+" .gc_custom_calendar_andree_week_days_box").find("li").each(function(index,el){$(el).height($(el).width()/(parseInt(props_array[0],10))*parseInt(props_array[1],10));});			})
		}
		
		if ($(this.options.dest_selector).empty().length>0)
		{
			if (typeof(__gc_custom_calendar_andree_index)=="undefined") __gc_custom_calendar_andree_index = 0; else __gc_custom_calendar_andree_index++;
			if (typeof(__gc_custom_calendar_andree_options_array)=="undefined") __gc_custom_calendar_andree_options_array = new Array();
		}
		
		this.lock 	= function(){ $(this.options.dest_selector+" .gc_custom_calendar_andree_locker").addClass("on"); }
		this.unlock = function(){ $(this.options.dest_selector+" .gc_custom_calendar_andree_locker").removeClass("on"); }
		
		this.selectDate = function(e)
		{
			var dest_date = $(e.currentTarget).attr("current-date");
			
			this.selected_date = new Date(dest_date);			
			this.redrawCustomCalendar();
			this.options.onselect(dest_date, this, e);
		}
		
		this.setYear = function(year)
		{
			if (this.current_date!=null && year && isNaN(year) == false) this.current_date.setYear(year);
			this.redrawCustomCalendar();
		}
		
		this.selectTime = function()
		{		
			if (this.selected_date!=null)
			{
				this.selected_date.setHours($(".gc_custom_calendar_andree_select_hours").val());
				this.selected_date.setMinutes($(".gc_custom_calendar_andree_select_minutes").val());
				this.selected_date.setSeconds($(".gc_custom_calendar_andree_select_seconds").val());
				
				var current_year = this.selected_date.getFullYear();
				var current_date_month = this.selected_date.getMonth()+1;
				var day_int = parseInt(this.selected_date.getDate(),10);
				
				var dest_date = current_year+"/"+((current_date_month<=9)?("0"+current_date_month):current_date_month)+"/"+((day_int<=9)?("0"+day_int):day_int);
				
				if (this.options.date_time_mode == true)
				{
					var hours 	= this.selected_date.getHours();
					var minutes = this.selected_date.getMinutes();
					var seconds = this.selected_date.getSeconds();
					
					if (hours<10) 	hours 	= "0"+hours;
					if (minutes<10) minutes = "0"+minutes;
					if (seconds<10) seconds = "0"+seconds;
					
					dest_date = dest_date+" "+hours+":"+minutes+":"+seconds;
				}
				
				
				
				this.options.onselect(dest_date, this);
			}
			
			if (this.current_date!=null)
			{
				this.current_date.setHours($(".gc_custom_calendar_andree_select_hours").val());
				this.current_date.setMinutes($(".gc_custom_calendar_andree_select_minutes").val());
				this.current_date.setSeconds($(".gc_custom_calendar_andree_select_seconds").val());
			}
						
			this.redrawCustomCalendar();
		}
		
		this.redrawCustomCalendar = function()
		{
			this.renderCustomCalendar(this.current_date);
		}
		
		this.renderCustomCalendar = function(current_date)
		{
			$(this.options.dest_selector).empty();
			
			var date  		  = new Date();
			var today 		  = new Date();
			var selected_date = new Date();			
			
			if (current_date instanceof Date) 	date  = current_date;
			if (current_date instanceof String) date  = new Date(current_date);
		
			if (this.selected_date==null)
			{
				var current_hours = date.getHours();
				var current_mins  = date.getMinutes();
				var current_secs  = date.getSeconds();
			}
			else
			{
				selected_date = this.selected_date;
				
				var current_hours = selected_date.getHours();
				var current_mins  = selected_date.getMinutes();
				var current_secs  = selected_date.getSeconds();
			}
			
			var dest_calendar = this;
			var next_month 	  = new Date(date.getFullYear(), date.getMonth() + 1, 15, current_hours, current_mins, current_secs);
			var prev_month 	  = new Date(date.getFullYear(), date.getMonth() - 1, 15, current_hours, current_mins, current_secs);
			var next_year 	  = new Date(date.getFullYear() + 1, date.getMonth(), date.getDate(), current_hours, current_mins, current_secs);
			var prev_year 	  = new Date(date.getFullYear() - 1, date.getMonth(), date.getDate(), current_hours, current_mins, current_secs);
			var first_day 	  = new Date(date.getFullYear(), date.getMonth(), 1);
			var last_day  	  = new Date(date.getFullYear(), date.getMonth() + 1, 0);
			var write_month	  = this.options.month_names[date.getMonth()];
			
			var current_month = date.getMonth();
			var current_year  = date.getFullYear();
			var write_year 	  = date.getFullYear();			
			
			this.current_date = date;
			
			var gc_calendar_container = $('<div class="gc_custom_calendar_andree_container"></div>').append('<div class="gc_custom_calendar_andree_locker"></div>');
			
			$(this.options.dest_selector).append(gc_calendar_container);
			console.log(gc_calendar_container);
			$(gc_calendar_container).append($('<div class="gc_custom_calendar_andree_month"></div>'));
			
			$(this.options.dest_selector+' .gc_custom_calendar_andree_month').append($('<ul></ul>').attr('class', 'gc_custom_calendar_andree_ul_month'));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_ul_month').append($('<li></li>').attr('class', 'prev').click( function(){ dest_calendar.renderCustomCalendar(prev_month); return false;} ).attr('id', 'prev').html(this.options.left_mounth_arrow));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_ul_month').append($('<li></li>').attr('class', 'next').click( function(){ dest_calendar.renderCustomCalendar(next_month); return false;} ).attr('id', 'next').html(this.options.right_mounth_arrow));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_ul_month').append($('<li></li>').attr('id', 'gc_custom_calendar_andree_label_month').html(write_month + ' ' + write_year)).click(function(){_self.setYear(prompt('Anno',write_year));return false;});
			
			$(gc_calendar_container).append($('<ul class="gc_custom_calendar_andree_week_days"></ul>'));
			
			$(this.options.dest_selector+' .gc_custom_calendar_andree_week_days').append($('<li></li>').html(this.options.days_short_names[0]));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_week_days').append($('<li></li>').html(this.options.days_short_names[1]));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_week_days').append($('<li></li>').html(this.options.days_short_names[2]));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_week_days').append($('<li></li>').html(this.options.days_short_names[3]));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_week_days').append($('<li></li>').html(this.options.days_short_names[4]));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_week_days').append($('<li></li>').html(this.options.days_short_names[5]));
			$(this.options.dest_selector+' .gc_custom_calendar_andree_week_days').append($('<li></li>').html(this.options.days_short_names[6]));
			
			$(gc_calendar_container).append($('<ul></ul>').attr('class', 'gc_custom_calendar_andree_week_days_box').attr('id', 'gc_custom_calendar_andree_ul_days_id'));
			
			var start_day = first_day.getDay();
			var end_day   = last_day.getDay();
			
			if (start_day==0)
			{
				for (var y = start_day; y < 6; y++) $(this.options.dest_selector+' #gc_custom_calendar_andree_ul_days_id').append($('<li></li>').attr('class', 'gc_custom_calendar_andree_hidden').html(''));
			}
			
			if (this.options.date_time_mode)
			{
				var _self = this;
				var hours_calendar = $('<div class="gc_custom_calendar_andree_hours"><div>'+this.time_title+'</div><div class="spessore5"></div></div>');
				var hours_select   = $('<select class="gc_custom_calendar_andree_select_hours"></select>').change(function(e){ _self.selectTime()});
				var minutes_select = $('<select class="gc_custom_calendar_andree_select_minutes"></select>').change(function(){ _self.selectTime()});
				var seconds_select = $('<select class="gc_custom_calendar_andree_select_seconds"></select>').change(function(){ _self.selectTime()});

				for (var i=0;i<24;i++) $(hours_select).append($('<option value="'+i+'">'+i+'</option>'));
				for (var i=0;i<60;i++) $(minutes_select).append($('<option value="'+i+'">'+((i>=10)?i:'0'+i)+'</option>'));
				for (var i=0;i<60;i++) $(seconds_select).append($('<option value="'+i+'">'+((i>=10)?i:'0'+i)+'</option>'));

				$(gc_calendar_container).append($(hours_calendar).append(hours_select).append(minutes_select).append(seconds_select));
				
				$(this.options.dest_selector+' .gc_custom_calendar_andree_select_hours').val(current_hours);
				$(this.options.dest_selector+' .gc_custom_calendar_andree_select_minutes').val(current_mins);
				$(this.options.dest_selector+' .gc_custom_calendar_andree_select_seconds').val(current_secs);
			}

			for (var z=1;z<start_day;z++) $(this.options.dest_selector+' #gc_custom_calendar_andree_ul_days_id').append($('<li></li>').attr('class', 'gc_custom_calendar_andree_hidden').html(''));

			for (var i = first_day; i <= last_day; i.setDate(i.getDate() + 1))
			{
				var day_int = i.getDate();
				var day = $('<li>'+i+'</li>');
				var current_date_month = current_month+1;								
				var cicle_date = current_year+"/"+((current_date_month<=9)?("0"+current_date_month):current_date_month)+"/"+((day_int<=9)?("0"+day_int):day_int);
				
				if (this.options.date_time_mode == true)
				{
					var hours 	= $(gc_calendar_container).find('.gc_custom_calendar_andree_select_hours').val();
					var minutes = $(gc_calendar_container).find('.gc_custom_calendar_andree_select_minutes').val();
					var seconds = $(gc_calendar_container).find('.gc_custom_calendar_andree_select_seconds').val();
					
					if (hours<10) 	hours 	= "0"+hours;
					if (minutes<10) minutes = "0"+minutes;
					if (seconds<10) seconds = "0"+seconds;
					
					cicle_date = cicle_date+" "+hours+":"+minutes+":"+seconds;
				}
				
				$(day).attr("current-date",cicle_date);
				$(day).attr("current-day",this.options.days_names[i.getDay()-1]);				
				
				if (i>=today || this.options.all_dates==true) $(day).click(function(e){if ($(e.currentTarget).hasClass("gc_custom_calendar_andree_inactive" || this.options.all_dates==true)==false) { dest_calendar.selectDate(e); } });
				if (i<today && this.options.all_dates==false) $(day).attr('class', 'gc_custom_calendar_andree_inactive');
				if (i.setHours(0, 0, 0, 0) === today.setHours(0, 0, 0, 0)) $(day).attr('class', 'calendar_today');				
				
				if (this.selected_date!=null)
				{
					var check_1 = new Date(i);
					var check_2 = new Date(this.selected_date);
					
					if (check_1.setHours(0, 0, 0, 0) === check_2.setHours(0, 0, 0, 0)) $(day).attr('class', 'calendar_selected');
				}
				
				if (this.options.active_dates!=null)
				{
					var date_found = false;
					
					for (var k=0;k<this.options.active_dates.length;k++)
					{
						if (this.options.active_dates[k]==cicle_date)
						{
							date_found = true;
							break;
						}
					}
					
					if (date_found==false) $(day).attr('class', 'gc_custom_calendar_andree_inactive');
				}
				
				$(day).html(day_int);
				$(this.options.dest_selector+' #gc_custom_calendar_andree_ul_days_id').append(day);
			}
			
			for (var t=7;end_day<t;end_day++) $(this.options.dest_selector+' #gc_custom_calendar_andree_ul_days_id').append($('<li></li>').attr('class', 'gc_custom_calendar_andree_hidden').html(''));
			
			
			$(gc_calendar_container).append($('<div/>').attr("class","gc_custom_calendar_andree_footer"));
			$(this.options.dest_selector).append(gc_calendar_container);			
			$(window).resize();
		}
		
		this.renderCustomCalendar(this.options.current_date);
	}
	
	
	// ---------------------------------------------------------------------------------------------------------------------------------------------- //
	
	
	
	
	gcDocumentReady(function()
	{
		var options = 
		{
			dest_selector:".andree_reserve_calendar",
			all_dates:true,
			onselect: function(dest_date, calendar_obj, e)
			{		
				$("#data_prenotazione").val(dest_date);
			},
		}

		GCCustomCalendarAndree(options);
		$(".prenotazione_persone li").click(function(e)
		{
			$(".prenotazione_persone li").removeClass("active");
			$(e.currentTarget).addClass("active");
		});
		
		$(".verifica_disponibilita").click(function()
		{
			if ($("#data_prenotazione").val()!="")
			{
				var param_str = "&persone="+$(".prenotazione_persone li.active").text()+"&date="+$("#data_prenotazione").val();
				alert(param_str)
			}
			else
			{
				alert("Selezionare la data");
			}
		});
	});

/* ************************************** additional_js root ************************************** */

gcDocumentReady(function(e){
	gcSmoothScrollLinksAnchors();

	$(".main_menu_l ink_17").click(function()
	{	
		$("body").append($(".reserve_panel").click());
		$(".reserve_panel").fadeIn();
		
		return false;		
	});
	$(".andree_toggle").click();
	$(".andree_toggle").click();
	
	$("#andree_toggle").click(function()
	{
		if ($(window).scrollTop() ==0)
		{
			$("ul.comp_menu_standard_horizontal_standard_menu.gcNavMenuToggleResponsive").addClass("no_menu_bg");
		}
		else
		{
			$("ul.comp_menu_standard_horizontal_standard_menu.gcNavMenuToggleResponsive").removeClass("no_menu_bg");
		}
	});
	
});

/* ************************************************************************************************* */

