/* Generic Aró site scripts */


 //   OnFromDayDDChange(ArrivaldayComboId, departure_dayComboId);


function OnClickBookNow() {
    var roomsSelectId = document.getElementById(roomsSelectIddef);
    var occupancySelectId = document.getElementById(occupancySelectIddef);

    var ArrivalmonthComboId = document.getElementById(ArrivalmonthComboIdDef);
    var ArrivaldayComboId = document.getElementById(ArrivaldayComboIdDef);
    var ym = ArrivalmonthComboId.options[ArrivalmonthComboId.selectedIndex].value.split('-');
    var dtArrival = new Date(ym[0], ym[1] - 1, ArrivaldayComboId.options[ArrivaldayComboId.selectedIndex].value);

    var departure_monthComboId = document.getElementById(departure_monthComboIdDef);
    var departure_dayComboId = document.getElementById(departure_dayComboIdDef);
    ym = departure_monthComboId.options[departure_monthComboId.selectedIndex].value.split('-');
    var dtDeparture = new Date(ym[0], ym[1] - 1, departure_dayComboId.options[departure_dayComboId.selectedIndex].value);

    var ArrivalMonth = dtArrival.getMonth() + 1;
    ArrivalMonth = ArrivalMonth + '';
    if (ArrivalMonth.length == 1)
        ArrivalMonth = "0" + ArrivalMonth;
    var DepartureMonth = dtDeparture.getMonth() + 1;
    DepartureMonth = DepartureMonth + '';
    if (DepartureMonth.length == 1)
        DepartureMonth = "0" + DepartureMonth;
    var ArrivalDay = ArrivaldayComboId.options[ArrivaldayComboId.selectedIndex].value;
    if (ArrivalDay.length == 1)
        ArrivalDay = "0" + ArrivalDay;
    var DepartureDay = departure_dayComboId.options[departure_dayComboId.selectedIndex].value;
    if (DepartureDay.length == 1)
        DepartureDay = "0" + DepartureDay;

    var ArrivalDateString = dtArrival.getFullYear() + "-" + ArrivalMonth + "-" + ArrivalDay;
    var DepartureDateString = dtDeparture.getFullYear() + "-" + DepartureMonth + "-" + DepartureDay;

    var HotelName = $(hotelsSelectIddef).getSelected()[0].getProperty('value');

    var url = "https://www.yourreservation.net/ibe/" + HotelName + "/main.html?&calArrivalDateField=" + ArrivalDateString + "&calDepartureDateField=" + DepartureDateString +
        "&occupancy=" + occupancySelectId.options[occupancySelectId.selectedIndex].value + "&prsRoomCount=" + roomsSelectId.options[roomsSelectId.selectedIndex].value + "&quick=quick";

    //alert(url); 
    //alert(ArrivaldayComboId.options[ArrivaldayComboId.selectedIndex].value); 
    // alert(dtDeparture); 
    window.open(url, '', '');
}   
function OnToDayDDChange(FromDate, ToDate)
{
    var DayFromObj = document.getElementById(FromDate);
    var DayToObj = document.getElementById(ToDate);

    var MonthFromObj = document.getElementById(ArrivalmonthComboIdDef);
    var MOnthToObj = document.getElementById(departure_monthComboIdDef);

    if ((DayFromObj.selectedIndex +1) >= DayFromObj.options.length)
    {
        DayToObj.selectedIndex = 0;
        if ((MonthFromObj.selectedIndex +1) >= MonthFromObj.options.length)
        {
            MOnthToObj.selectedIndex = 0;
        }
        else
        {
            MOnthToObj.selectedIndex  = MonthFromObj.selectedIndex +1;
        }
    }
    else
    {
        DayToObj.selectedIndex  = DayFromObj.selectedIndex +1;
        MOnthToObj.selectedIndex = MonthFromObj.selectedIndex;
    }
}

function OnFromDayDDChange(FromDate, ToDate)
{

    var DayFromObj = document.getElementById(FromDate);
    var DayToObj = document.getElementById(ToDate);
    var MonthFromObj = document.getElementById(ArrivalmonthComboIdDef);
    var MOnthToObj = document.getElementById(departure_monthComboIdDef);


    if(MonthFromObj.selectedIndex >= MOnthToObj.selectedIndex)
    {
        //MonthFromObj.selectedIndex = MOnthToObj.selectedIndex;
       if (DayFromObj.selectedIndex >= DayToObj.selectedIndex)
       {
            DayFromObj.selectedIndex = 0;
            MonthFromObj.selectedIndex = MOnthToObj.selectedIndex;
            DayToObj.selectedIndex = 1;
       }
       else
       {
            MonthFromObj.selectedIndex = MOnthToObj.selectedIndex;
       }
    }
    
}