// JavaScript Document
			//sets default values for the input fields arrival, departure and nights//
			document.form1.wdcArrival_input.value = arrivalInit;
			document.form1.wdcDeparture_input.value = departureInit;
			document.form1.wcNights_input.value = numberNights;		
			
			//function for returning how many days there are in a month including leap years
			function DaysInMonth(WhichMonth, WhichYear){
			  var DaysInMonth = 31;
			  if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11") DaysInMonth = 30;
			  if (WhichMonth == "02" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
			  if (WhichMonth == "02" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
			  return DaysInMonth;
			}
			
			// Calculate four digit year.
			function fourdigits(number)	{
				return (number < 1000) ? Math.abs(number) + 1900 : number;
			}
			
			// Array list of months.
			var numMonth = new Array('01','02','03','04','05','06','07','08','09','10','11','12');
			

//depending on which date is changed one of the following functions will be called. 
			function calcNights_arrival(){
				//departure date is changed based on number of nights if the new departure is > the latest possible date then it is set to latest possible date and nights is changed
				var arrival = document.form1.wdcArrival_input.value;
				var nights = parseInt(document.form1.wcNights_input.value);
				var arrival = arrival.split("/");
				var newArrival = new Date(arrival[0]+"/"+arrival[1]+"/"+arrival[2]);
				var newDeparture = new Date(arrival[0]+"/"+arrival[1]+"/"+arrival[2]);
				newDeparture.setDate(newDeparture.getDate() + nights);
				var latest = new Date(now.getYear(), now.getMonth(), now.getDate());
				latest.setMonth(latest.getMonth() + 18);
				latest.setDate(DaysInMonth(latest.getMonth(), latest.getYear()));
				latest.setDate(latest.getDate() + 1);
				latest.setYear(latest.getFullYear()+1900);
				if (newDeparture > latest){
					newDeparture = latest;
					nights = Math.round((newDeparture - newArrival)/86400000);
				}
				var departField = (numMonth[newDeparture.getMonth()]) + "/" +
								   ((newDeparture.getDate()<10) ? "0" : "")+ newDeparture.getDate() + "/" +    
								   fourdigits(newDeparture.getFullYear());
				document.form1.wdcDeparture_input.value = departField;
				document.form1.wcNights_input.value = nights;
			}//end calcNights_arrival
			
			function calcNights_depart(){
			//depart date < arrival date, then arrival date is changed. if arrival date is < earliest possible date then arrival is reset to earliest possible and depart is recalculated based on number of nights.
			//depart date > arrival date then change nights field
			var departure = document.form1.wdcDeparture_input.value;
			var departureDate = departure.split("/");
			var newDeparture = new Date(departureDate[2],departureDate[0],departureDate[1]);
			newDeparture.setMonth(newDeparture.getMonth()-1);
			
			var arrival = document.form1.wdcArrival_input.value;
			var arrivalDate = arrival.split("/");
			var newArrival = new Date(arrivalDate[2],arrivalDate[0],arrivalDate[1]);
			newArrival.setMonth(newArrival.getMonth()-1);
			
			var nights = parseInt(document.form1.wcNights_input.value);

			var earliest = new Date(now.getFullYear(), now.getMonth(), now.getDate());
			
			if(newDeparture <= newArrival){
				newArrival.setMonth(newDeparture.getMonth());
				newArrival.setDate(newDeparture.getDate() - nights);
				newArrival.setYear(newDeparture.getFullYear());
				//newDeparture.setDate(newDeparture.getDate() + nights);
			}
			//else{
//				nights = Math.round((newDeparture - newArrival)/86400000);
//			}
			if(newArrival < earliest){
				newArrival.setYear(now.getFullYear());
				newArrival.setMonth(now.getMonth());
				newArrival.setDate(now.getDate());
				
			}
			if((newDeparture - newArrival) != nights){
				nights = Math.round((newDeparture - newArrival)/86400000);
				//nights = newDeparture;
			
			}
			var arriveField = (numMonth[newArrival.getMonth()]) + "/" +
								   ((newArrival.getDate()<10) ? "0" : "")+ newArrival.getDate() + "/" +    
								   fourdigits(newArrival.getFullYear());
			document.form1.wdcArrival_input.value = arriveField;
			document.form1.wcNights_input.value = nights;
			}//end calcNights_depart
			
			//configure these functions to set inactive dates on the calendar//
			function validDateArrival(date) { 
				// date is a JS Date object 
				var notvalid = false; 
				var earliest = new Date(now.getYear(), now.getMonth(), now.getDate());
				if (earliest.getFullYear() < 1000){
					earliest.setYear(earliest.getFullYear() + 1900);
				}
				if(date < earliest){
					notvalid = true
				}
				var latest = new Date(now.getYear(), now.getMonth(), now.getDate());
				latest.setMonth(latest.getMonth() + 18);
				latest.setDate(DaysInMonth(latest.getMonth(), latest.getYear()));
				if (latest.getFullYear() < 1000){
					latest.setYear(latest.getFullYear() + 1900);
				}
				if(date > latest){
					notvalid = true;
				}
				return notvalid; 
				}; 
				
			function validDateDeparture(date) { 
				// date is a JS Date object
				var notvalid = false; 
				var earliest = new Date(now.getYear(), now.getMonth(), now.getDate()+1);
				if (earliest.getFullYear() < 1000){
					earliest.setYear(earliest.getFullYear() + 1900);
				}
				if(date < earliest){
					notvalid = true
				}
				var latest = new Date(now.getYear(), now.getMonth(), now.getDate());
				latest.setMonth(latest.getMonth() + 18);
				latest.setDate(DaysInMonth(latest.getMonth(), latest.getYear()));
				latest.setDate(latest.getDate() + 1);
				if (latest.getFullYear() < 1000){
					latest.setYear(latest.getFullYear() + 1900);
				}
				if(date > latest){
					notvalid = true;
				}
				return notvalid; 
				}; 

			//sets up the calendar for the arrival input field.// 
			Calendar.setup({
			inputField     :    "wdcArrival_input",
			ifFormat       :    "%m/%d/%Y",
			button         :    "arrival_trigger",
			align          :    "TR",
			singleClick    :    true,
			dateStatusFunc :    validDateArrival,
			onUpdate	   :    calcNights_arrival
			 });
			//sets up the calendar for the departure input field.//	
			Calendar.setup({
			inputField     :    "wdcDeparture_input",
			ifFormat       :    "%m/%d/%Y",
			button         :    "departure_trigger",
			align          :    "TR",
			singleClick    :    true,
			dateStatusFunc :    validDateDeparture, 
			onUpdate	   :    calcNights_depart
			 });