var startDate;
 var endDate;
 var callbacks = 0;

 
 /*
			* Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or
			 * they're the same, taking only the dates, not the time into account.
			 * In other words, different times on the same date returns equal.
			 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal
			 */

			function compareDatesOnly(date1, date2) {
				var year1 = date1.getYear();
				var year2 = date2.getYear();
				var month1 = date1.getMonth();
				var month2 = date2.getMonth();
				var day1 = date1.getDate();
				var day2 = date2.getDate();

				if (year1 > year2) {
					return -1;
				}
				if (year2 > year1) {
					return 1;
				}

				//years are equal
				if (month1 > month2) {
					return -1;
				}
				if (month2 > month1) {
					return 1;
				}

				//years and months are equal
				if (day1 > day2) {
					return -1;
				}
				if (day2 > day1) {
					return 1;
				}

				//days are equal
				return 0;


				/* Can't do this because of timezone issues
				var days1 = Math.floor(date1.getTime()/Date.DAY);
				var days2 = Math.floor(date2.getTime()/Date.DAY);
				return (days1 - days2);
				*/
			}

			
 function setCheckoutValues(cal) {
            //set up date values for the check out box;
            var _theDate = new Date(cal.date);
			var _theDay = _theDate.getDate(); //use to build a new date for the check out form
			
			var _theMonth = parseInt(_theDate.getMonth()) + 1;//use to build a new date for the check out form
			var _theYr = _theDate.getFullYear();//use to build a new date for the check out form
			var _currMonth = new Date();
			var  _daysInCurrMonth = 0;
			
			_theDay = parseInt(_theDay) + 2; //by default add two days to the check out day
			
			//make sure the day is not more than the number of days in the current month
			 _currMonth.setFullYear(_theYr,_theMonth ,0);
			 _daysInCurrMonth = _currMonth.getDate();// the number of days in the selected month
			 if( _daysInCurrMonth < _theDay ) {
			    _theDay = _theDay - _daysInCurrMonth;
				_theMonth = parseInt(_theMonth) + 1;
				//if the month is January after adding one month, we need to increment the year one year
				if( _theMonth > 12 ) {
				   _theMonth = 1;
				   _theYr = parseInt(_theYr) + 1;
				}
			 }
			 
	        var _checkOutDate = new Date();
			_checkOutDate =  _theMonth + "/" + _theDay + "/" +  _theYr;
			
	        document.forms.resrvForm.checkout.value = _checkOutDate;
			setSMSDateFields();
		  
    }
	 
	 /* 
			* Can't choose days after the
			* end date if it is choosen, hilights start and end dates with one style and dates between them with another
			*/
			function dateInRange1(date) {

				if (endDate != null) {

					// Disable dates after end date
					var compareEnd = compareDatesOnly(date, endDate);
					if  (compareEnd < 0) {
						return (true);
					}

					// Hilight end date with "edges" style
					if  (compareEnd == 0) {
						{return "edges";}
					}


					// Hilight inner dates with "between" style
					if (startDate != null){
						var compareStart = compareDatesOnly(date, startDate);
						if  (compareStart < 0) {
							return "between";
						} 
					} 
				}

				//disable days prior to today
				var today = new Date();
				var compareToday = compareDatesOnly(date, today);
				if (compareToday > 0) {
					return(true);
				}


				//all other days are enabled
				return false;
				//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
				return(ret);
			}
			
				function dateInRange2(date) {
				if (startDate != null) {
					// Disable dates before start date
					var compareDays = compareDatesOnly(startDate, date);
					if  (compareDays < 0) {
						return (true);
					}

					// Hilight end date with "edges" style
					if  (compareDays == 0) {
						{return "edges";}
					}

					// Hilight inner dates with "between" style
					if ((endDate != null) && (date > startDate) && (date < endDate)) {
						return "between";
					} 
				} 

				var now = new Date();
				if (compareDatesOnly(now, date) < 0) {
					return (true);
				}

				//all other days are enabled
				return false;
			}
			
			function setSMSDateFields() {
			   // set the value of the hidden form fields needed to  make a reservation with SMS
			   var _checkInDate  = new Date( document.forms.resrvForm.checkin.value);
			   var _checkOutDate = new Date( document.forms.resrvForm.checkout.value );
		
			    document.forms.resrvForm.inmonth.value  = formatDate(_checkInDate,'NNN');
				document.forms.resrvForm.inday.value    = _checkInDate.getDate();
				document.forms.resrvForm.inyear.value   = _checkInDate.getFullYear();
				document.forms.resrvForm.outyear.value  = _checkOutDate.getFullYear();
				document.forms.resrvForm.outmonth.value = formatDate(_checkOutDate,'NNN');
				document.forms.resrvForm.outday.value   = _checkOutDate.getDate();
				
			  
			}
			
