function jfAddDays(pstrDate, pintDays){
	var strMonth, strDay, strYear;

	pstrDate = Date.parse(pstrDate);
	pstrDate = parseInt(pstrDate, 10);
	pstrDate = pstrDate + pintDays*(24*60*60*1000);
	pstrDate = new Date(pstrDate);

	strMonth = pstrDate.getMonth() + 1;
	strDay = pstrDate.getDate();
	strYear = pstrDate.getFullYear();

	return strMonth + '/' + strDay + '/' + strYear;
}

function jfBookNow(pfrmSource) {
	var strCheckInDate, strCheckOutDate;
	var strMonth, strDay, strYear, strNights, strAdults, strKids, strPromo;
	var strAction, strURL;
	var frmSource = eval(pfrmSource);

	strMonth = frmSource.month.value;
	strDay = frmSource.day.value;
	strYear = frmSource.year.value;
	strNights = frmSource.nights.value;
	strAdults = frmSource.adults.value;
	strChildren = frmSource.children.value;
	strPromo = frmSource.promo.value;

	strCheckInDate = strMonth + '/' + strDay + '/' + strYear;
	strCheckOutDate = jfAddDays(strCheckInDate, strNights);
	
	strURL = 'https://www.thebenjamin.com/Reserve.aspx?' + 'chain=5158&hotel=10150&arrive=' + strCheckInDate + '&depart=' + strCheckOutDate + '&Adult=' + strAdults + '&Child=' + strChildren + '&lang=1&step=2' + '&promo=' + strPromo;

	document.location = strURL;
}

function SetDaysDropDown()
{
	// get month and year

	var selectDay = document.getElementById("dayDropdown"); // the id of the day drop down
	var selectMonth = document.getElementById("monthDropdown"); // the id of the Month drop down
	var selectYear = document.getElementById("yearDropdown"); // the id of the Year drop down

	var myMonth = selectMonth.options[selectMonth.selectedIndex].value; // get the actual month from the drop down
	// you may have to do myMonth +1 or myMonth-1 to get the actual month

	var myYear = selectYear.options[selectYear.selectedIndex].value; // get the actual year from the drop down
	// check that year is 4 digit

	totalDays = getTotalDaysInMonth(myMonth, myYear);
	curDays = selectDay.options.length; // find out how many days currently

	if (curDays	> totalDays)
	{
		selectDay.options.length = totalDays;
	}
	else if (curDays < totalDays)
	{
		for (i=curDays+1; i<=totalDays; i++)
		{
			myNewOpt = new Option(i, i);
			selectDay.options[selectDay.options.length] = myNewOpt;
		}
	}
}

// GET NUMBER OF DAYS IN MONTH
function getTotalDaysInMonth(month,year) {
    var days = 0;
    if (month==1 || month==3 || month==5 || month==7 || month==8 ||
        month==10 || month==12)  days=31;
    else if (month==4 || month==6 || month==9 || month==11)
	{
		days=30;
	}
    else if (month==2)
    {
        if (isALeapYear(year))
            days=29;
        else
            days=28;
    }
    return (days);
}

// CHECK TO SEE IF YEAR IS A LEAP YEAR
function isALeapYear (Year)
{
    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0))
        return (true);
    else
        return (false);
}

