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 jfAddDaysForForm(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, strRooms, strAdults, strChildren;
	var depMonth, depDay, depYear;
	var strAction, strURL;
	var frmSource = eval(pfrmSource);

	depMonth = frmSource.dmonth.value;
	depDay = frmSource.dday.value;
	depYear = frmSource.dyear.value;
	strMonth = frmSource.month.value;
	strDay = frmSource.day.value;
	strYear = frmSource.year.value;
	strRooms = frmSource.room.value;
	strAdults = frmSource.adults.value;
	strChildren = frmSource.children.value;

        if (depDay < strDay && depMonth <= strMonth) {
                depDay = depDay + 1;
        }

	strCheckInDate = strMonth + '/' + strDay + '/' + strYear;
	strCheckOutDate = depMonth + '/' + depDay + '/' + depYear;

	strURL = 'https://gc.synxis.com/rez.aspx?Hotel=25418&Chain=8517' + '&arrive=' + strCheckInDate + '&depart=' + strCheckOutDate + '&room=' + strRooms + '&adult=' + strAdults + '&Child=' + strChildren + '&lang=1&start=1';
	__utmLinker(strURL);
	document.location.href = 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;
		}
	}
}

function SetDDaysDropDown()
{
        // get month and year

        var selectDay = document.getElementById("ddayDropdown"); // the id of the day drop down
        var selectMonth = document.getElementById("dmonthDropdown"); // the id of the Month drop down
        var selectYear = document.getElementById("dyearDropdown"); // 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);
}

function updateDepartDate() {
        var frmSource = document.forms.frmBookNow;

        var depMonth = frmSource.dmonth.value;
        var depDay = frmSource.dday.value;
        var depYear = frmSource.dyear.value;
        var strMonth = frmSource.month.value;
        var strDay = frmSource.day.value;
        var strYear = frmSource.year.value;

//      if (depDay < strDay && depMonth <= strMonth) {
                var totalDays = getTotalDaysInMonth(strMonth, strYear);

                newMonth = strMonth;
	        newDay = strDay;
	   	newYear = strYear;
                if (strDay < totalDays) {
		   newDay++;
                } else {
	 	   newMonth++;
	           newDay = 1;
		   if (newMonth == 13) {
			newMonth = 1;
			newYear++;
		   }
                }
                
                frmSource.dmonth.value = newMonth;
                frmSource.dyear.value = newYear;
		SetDDaysDropDown();
                frmSource.dday.value = newDay;
	
//      }
}


