﻿		$(document).ready(function() {
			
			/**********   Datepicker for booking widget **********/
			$(function() {
				$('#linkedDatepicker')
					.datepicker({
						dateFormat: 'dd/mm/yy',
						beforeShow: readLinked,
						onSelect: updateLinked,
						showOtherMonths:false,
						selectOtherMonths:false,
						mandatory: true,
						changeMonth: false,
						changeYear: false, 
						minDate: '+0D',
						maxDate: '+1Y',
						showOn: 'both', buttonImageOnly: true, buttonImage: '/images/cal.jpg'}); 
				 
				// Prepare to show a date picker linked to three select controls  
				function readLinked() {  
					$('#linkedDatepicker').val( $('#checkin_day').val() + '/' + $('#checkin_month_year').val()  );
					
					/*extra stuff for custom select*/
					$('#datepicker1 li').attr({ rel : $('#dayField li').attr('rel') + '/' + $('#monthYearField li').attr('rel') });
					
					return {};  
				}  
			  
				// Update three select controls to match a date picker selection  
				function updateLinked(date) { 
					$('#checkin_month_year').val(	date.substring(3, 11) );
					$('#checkin_day').val(	date.substring(0, 2)	);			
					
					/*extra stuff for custom select*/
					$('#checkInMonthYearField li').html( $('#checkin_month_year :selected').text() ).attr({rel : date.substring(3, 11) });    
					$('#checkInDayField li').html( date.substring(0, 2)).attr({rel : date.substring(0, 2)	}); 
				}
				
				$('#linkedDatepicker2')
					.datepicker({
						dateFormat: 'dd/mm/yy',
						beforeShow: readLinked2,
						onSelect: updateLinked2,
						showOtherMonths:false,
						selectOtherMonths:false,
						mandatory: true,
						changeMonth: false,
						changeCurrent:false,
						changeYear: false,
						minDate: '+1D',
						maxDate: '+1D +1Y', 
						showOn: 'both', buttonImageOnly: true, buttonImage: '/images/cal.jpg'}); 
				
				 
				// Prepare to show a date picker linked to three select controls  
				function readLinked2(input, inst) {
					var minday = $('#checkin_day').val();
					var minmonth = ( $('#checkin_month_year').val() ).substring(0,2);
					var minyear = ( $('#checkin_month_year').val() ).substring(3,8);			

					$('#linkedDatepicker2').val( $('#checkout_day').val() + '/' + $('#checkout_month_year').val()  );
					
					/*extra stuff for custom select*/
					$('#datepicker2 li').attr({ rel : $('#dayField li').attr('rel') + '/' + $('#monthYearField li').attr('rel') });
					
					return {minDate:new Date(minyear, minmonth-1, minday)};			
				}  
			  
				// Update three select controls to match a date picker selection  
				function updateLinked2(date) { 
					$('#checkout_month_year').val(	date.substring(3, 11) ); 
					$('#checkout_day').val(	date.substring(0, 2)	); 
					
					/*extra stuff for custom select*/
					$('#checkOutMonthYearField li').html( $('#checkout_month_year :selected').text() ).attr({rel : date.substring(3, 11) });    
					$('#checkOutDayField li').html( date.substring(0, 2)).attr({rel : date.substring(0, 2)	}); 			
				}
			});

		});
