// JavaScript Document
// Get today's current date. not necessary for this demo or current//
var now = new Date();

// Array list of days.
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

// Array list of months.
var months = new Array('01','02','03','04','05','06','07','08','09','10','11','12');

// Calculate four digit year.
function fourdigits(number)	{
	return (number < 1000) ? number + 1900 : number;
	}
	
//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;
}

//Get actual values for date and month from DOM, For security purposes of demo year is not set to current//
var nowdate = now.getDate();
var nowmonth = now.getMonth();
var nowyear = now.getYear();

//Default Days ahead of todays date for arrival and departure set to current dates//
var arr = 2;
var dep = 4;

//For use with current dates this function Adds 2 days for default Arrival Date & 4 days for default Departure Date.//
//For Demo use this function just returns proper format for default arrival and departure dates//
function checkDate (m, d, y, field){
	//var maxDays = DaysInMonth(m, y);
	var newDay = d + field;
	var newMonth = months[m];
	var newYear = fourdigits(y);
	//if ((newDay) > maxDays){
//		newDay = newDay - maxDays;
//		var nextMonth = m + 1;
//		if (nextMonth > 11){
//			nextMonth = 0;
//			newYear++;
//			}
//		newMonth = months[nextMonth];
//		}		
//	newDay = ((newDay<10) ? "0" : "")+ newDay;
	var fieldDate = newMonth + "/" +
					newDay + "/" +
					newYear;
	return fieldDate;
	}

	
var arrivalDate = checkDate(nowmonth, nowdate, nowyear, arr);
var departureDate = checkDate(nowmonth, nowdate, nowyear, dep);

//document.buttonForm.wdcArrival_input.value = arrivalDate;
//document.buttonForm.wdcDeparture_input.value = departureDate;
