protected void RateGridDateSelected(object sender, RateGridEventArgs objRateGridEventArgs)
    {
        Session["RateGridStartDate"] = objRateGridEventArgs.NewStartDate.Date;

        if (objRateGridEventArgs.Operation == RateGridOperation.DateSelected)
        {
            WbsUiHelper.SyncStayDatesToRateGrid(objRateGridEventArgs.NewStartDate);

            WbsUiHelper.InitRoomRateSelections();
            WbsUiHelper.InitAddOnPackageSelections();
            WbsUiHelper.InitGuestDetailsEntryInfo();

            if (this.IsGuestDetailsTestPrefill)
                WbsUiHelper.PrefillGuestDetailsEntryInfoForTesting();

            bAsyncGetHotelAvailInfo = true;
        }

        else if (objRateGridEventArgs.Operation == RateGridOperation.MovePrevious || objRateGridEventArgs.Operation == RateGridOperation.MoveNext)
        {
            string strSelectedRoom = (string)Session["SelectedRoom"];
            HotelAvailabilityRS objHotelAvailabilityRS = (HotelAvailabilityRS)Session["HotelAvailabilityRS"];

            AvailabilityCalendar objAvailabilityCalendar = new AvailabilityCalendar();

            for (int i = 0; i < objHotelAvailabilityRS.HotelRoomAvailInfos.Length; i++)
            {
                if (objHotelAvailabilityRS.HotelRoomAvailInfos[i].SegmentRefID == strSelectedRoom)
                {
                    objAvailabilityCalendar = objHotelAvailabilityRS.HotelRoomAvailInfos[i].AvailabilityCalendar;
                    break;
                }

            }

            if (!WbsUiHelper.IsRateGridDataCached(objAvailabilityCalendar, objRateGridEventArgs.NewStartDate, this.NumberDaysInRateGrid))
            {
                bAsyncGetHotelAvailInfo = true;
            }

        }

        return;
    }
    public bool IsRateGridDataCached(AvailabilityCalendar objAvailabilityCalendar, DateTime dtGridStartDate, int intGridNumDays)
    {
        if (objAvailabilityCalendar.NumDays == 0)
            return false;

        DateTime dtGridEndDate = dtGridStartDate.AddDays(intGridNumDays - 1);
        DateTime dtAvCalDataEndDate = objAvailabilityCalendar.StartDate.AddDays(objAvailabilityCalendar.NumDays - 1);

        if (dtGridStartDate.Date < objAvailabilityCalendar.StartDate.Date || dtGridStartDate.Date > dtAvCalDataEndDate.Date)
            return false;

        if (dtGridEndDate.Date > dtAvCalDataEndDate.Date)
            return false;

        return true;
    }
    protected void ConfigureRoomRateSelectControl()
    {
        string strSelectedRoom = (string)Session["SelectedRoom"];

        HotelAvailabilityRS objHotelAvailabilityRS = (HotelAvailabilityRS)Session["HotelAvailabilityRS"];
        HotelDescriptiveInfoRS objHotelDescriptiveInfoRS = (HotelDescriptiveInfoRS)Session["HotelDescriptiveInfoRS"];

        StayCriteriaSelection objStayCriteriaSelection = (StayCriteriaSelection)Session[Constants.Sessions.StayCriteriaSelection];
        RoomRateSelection[] objRoomRateSelections = (RoomRateSelection[])Session["RoomRateSelections"];

        ShowMoreRatesIndicator[] objShowMoreRatesIndicators = (ShowMoreRatesIndicator[])Session["ShowMoreRatesIndicators"];

        RoomOccupantSelection objRoomOccupantSelection = new RoomOccupantSelection();

        bool IsRoomRateDescriptionModel;

        if (ConfigurationManager.AppSettings["EnableRoomRateDescriptionModel"] == "1")
            IsRoomRateDescriptionModel = true;
        else
            IsRoomRateDescriptionModel = false;

        for (int i = 0; i < objStayCriteriaSelection.RoomOccupantSelections.Length; i++)
        {
            if (objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID == strSelectedRoom)
            {
                objRoomOccupantSelection = objStayCriteriaSelection.RoomOccupantSelections[i];
                break;
            }

        }

        RoomRateSelection objRoomRateSelection = new RoomRateSelection();

        for (int i = 0; i < objRoomRateSelections.Length; i++)
        {
            if (objRoomRateSelections[i].RoomRefID == strSelectedRoom)
            {
                objRoomRateSelection = objRoomRateSelections[i];
                break;
            }

        }

        HotelRoomAvailInfo objHotelRoomAvailInfo = new HotelRoomAvailInfo();

        for (int i = 0; i < objHotelAvailabilityRS.HotelRoomAvailInfos.Length; i++)
        {
            if (objHotelAvailabilityRS.HotelRoomAvailInfos[i].SegmentRefID == strSelectedRoom)
            {
                objHotelRoomAvailInfo = objHotelAvailabilityRS.HotelRoomAvailInfos[i];
                break;
            }

        }

        HotelDescriptiveInfo objHotelDescriptiveInfo = new HotelDescriptiveInfo();

        if (objHotelDescriptiveInfoRS.HotelDescriptiveInfos.Length != 0)
        {
            objHotelDescriptiveInfo = objHotelDescriptiveInfoRS.HotelDescriptiveInfos[0];
        }

        if (ConfigurationManager.AppSettings["EnableRoomRateGridModel"] != "1")
        {
            string strRoomSelectorItemControlPath = ConfigurationManager.AppSettings["RoomSelectorItemControl.ascx"];
            string strRoomTypeSelectorItemControlPath = ConfigurationManager.AppSettings["RoomTypeSelectorItemControl.ascx"];
            string strRatePlanSelectorItemControlPath = ConfigurationManager.AppSettings["RatePlanSelectorItemControl.ascx"];

            ucRoomRateSelectorControl.Clear();

            ucRoomRateSelectorControl.ID = "RoomRateSelector";
            ucRoomRateSelectorControl.RoomRefID = strSelectedRoom;
            ucRoomRateSelectorControl.HotelRoomAvailInfo = objHotelRoomAvailInfo;
            ucRoomRateSelectorControl.RoomOccupantSelection = objRoomOccupantSelection;

            for (int i = 0; i < objStayCriteriaSelection.RoomOccupantSelections.Length; i++)
            {
                RoomSelectorItemControl ucRoomSelectorItemControl = (RoomSelectorItemControl)LoadControl(strRoomSelectorItemControlPath);
                ucRoomRateSelectorControl.AddRoomSelectorItem(ucRoomSelectorItemControl);

                ucRoomSelectorItemControl.ID = "RoomSelectorItem" + objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID;
                ucRoomSelectorItemControl.RoomRefID = objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID;
                ucRoomSelectorItemControl.RoomRefIDMenuText = (String)GetGlobalResourceObject("SiteResources", "RoomSelectorMenuText") + " " + objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID;

                if (objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID == strSelectedRoom)
                    ucRoomSelectorItemControl.Selected = true;
                else
                    ucRoomSelectorItemControl.Selected = false;
            }

            if (objHotelRoomAvailInfo.RoomTypes != null)
            {
                for (int i = 0; i < objHotelRoomAvailInfo.RoomTypes.Length; i++)
                {
                    bool bRatesAvailable = false;

                    for (int j = 0; j < objHotelRoomAvailInfo.RoomRates.Length; j++)
                    {
                        if (objHotelRoomAvailInfo.RoomRates[j].RoomTypeCode == objHotelRoomAvailInfo.RoomTypes[i].Code)
                        {
                            if (!IsRoomRateDescriptionModel)
                            {
                                bRatesAvailable = true;
                                break;
                            }

                            else
                            {
                                if (objHotelRoomAvailInfo.RoomRates[j].DescriptionStatus == RoomRateDescriptionStatus.Active)
                                {
                                    bRatesAvailable = true;
                                    break;
                                }

                                for (int k = 0; k < objHotelRoomAvailInfo.RatePlans.Length; k++)
                                {
                                    if (objHotelRoomAvailInfo.RatePlans[k].Code == objHotelRoomAvailInfo.RoomRates[j].RatePlanCode)
                                    {
                                        if (objHotelRoomAvailInfo.RatePlans[k].Type == RatePlanType.Negotiated || objHotelRoomAvailInfo.RatePlans[k].Type == RatePlanType.Consortia)
                                        {
                                            bRatesAvailable = true;
                                        }

                                        break;
                                    }

                                }

                                if (bRatesAvailable)
                                    break;
                            }

                        }

                    }

                    if (!bRatesAvailable)
                        continue;

                    RoomTypeSelectorItemControl ucRoomTypeSelectorItemControl = (RoomTypeSelectorItemControl)LoadControl(strRoomTypeSelectorItemControlPath);
                    ucRoomRateSelectorControl.AddRoomTypeSelectorItem(ucRoomTypeSelectorItemControl);

                    ucRoomTypeSelectorItemControl.ID = "RoomTypeSelectorItem" + objHotelRoomAvailInfo.RoomTypes[i].Code;
                    ucRoomTypeSelectorItemControl.RoomRefID = strSelectedRoom;

                    for (int j = 0; j < objHotelDescriptiveInfo.RoomTypes.Length; j++)
                    {
                        if (objHotelDescriptiveInfo.RoomTypes[j].Code == objHotelRoomAvailInfo.RoomTypes[i].Code)
                        {
                            ucRoomTypeSelectorItemControl.RoomType = objHotelDescriptiveInfo.RoomTypes[j];
                            break;
                        }

                    }

                    ucRoomTypeSelectorItemControl.ShowMoreRates = false;

                    for (int j = 0; j < objShowMoreRatesIndicators.Length; j++)
                    {
                        if (objShowMoreRatesIndicators[j].RoomRefID == ucRoomTypeSelectorItemControl.RoomRefID && objShowMoreRatesIndicators[j].RoomTypeCode == ucRoomTypeSelectorItemControl.RoomType.Code)
                        {
                            ucRoomTypeSelectorItemControl.ShowMoreRates = true;
                            break;
                        }

                    }

                    ucRoomTypeSelectorItemControl.Clear();

                    for (int k = 0; k < objHotelRoomAvailInfo.RoomRates.Length; k++)
                    {
                        if (objHotelRoomAvailInfo.RoomRates[k].RoomTypeCode == ucRoomTypeSelectorItemControl.RoomType.Code)
                        {
                            bool bListRatePlan = true;

                            if (IsRoomRateDescriptionModel && objHotelRoomAvailInfo.RoomRates[k].DescriptionStatus == RoomRateDescriptionStatus.Inactive)
                            {
                                for (int l = 0; l < objHotelRoomAvailInfo.RatePlans.Length; l++)
                                {
                                    if (objHotelRoomAvailInfo.RatePlans[l].Code == objHotelRoomAvailInfo.RoomRates[k].RatePlanCode)
                                    {
                                        if (objHotelRoomAvailInfo.RatePlans[l].Type != RatePlanType.Negotiated && objHotelRoomAvailInfo.RatePlans[l].Type != RatePlanType.Consortia)
                                        {
                                            bListRatePlan = false;
                                        }

                                        break;
                                    }

                                }

                            }

                            if (!bListRatePlan)
                                continue;

                            RatePlanSelectorItemControl ucRatePlanSelectorItemControl = (RatePlanSelectorItemControl)LoadControl(strRatePlanSelectorItemControlPath);
                            ucRoomTypeSelectorItemControl.AddRatePlanSelectorItem(ucRatePlanSelectorItemControl);

                            ucRatePlanSelectorItemControl.ID = "RatePlanSelectorItem" + objHotelRoomAvailInfo.RoomRates[k].RatePlanCode;
                            ucRatePlanSelectorItemControl.RoomRefID = strSelectedRoom;
                            ucRatePlanSelectorItemControl.RoomRate = objHotelRoomAvailInfo.RoomRates[k];
                            ucRatePlanSelectorItemControl.CreditCardCodes = objHotelDescriptiveInfo.CreditCardCodes;
                            ucRatePlanSelectorItemControl.Selected = false;

                            for (int m = 0; m < objHotelRoomAvailInfo.RatePlans.Length; m++)
                            {
                                if (objHotelRoomAvailInfo.RatePlans[m].Code == objHotelRoomAvailInfo.RoomRates[k].RatePlanCode)
                                {
                                    ucRatePlanSelectorItemControl.RatePlan = objHotelRoomAvailInfo.RatePlans[m];
                                    break;
                                }

                            }

                            if (objRoomRateSelection.RoomTypeCode == ucRatePlanSelectorItemControl.RoomRate.RoomTypeCode && objRoomRateSelection.RatePlanCode == ucRatePlanSelectorItemControl.RoomRate.RatePlanCode)
                                ucRatePlanSelectorItemControl.Selected = true;
                        }

                    }

                }

            }

        }

        else
        {
            AvailabilityCalendar objAvailabilityCalendar = new AvailabilityCalendar();

            for (int i = 0; i < objHotelAvailabilityRS.HotelRoomAvailInfos.Length; i++)
            {
                if (objHotelAvailabilityRS.HotelRoomAvailInfos[i].SegmentRefID == strSelectedRoom)
                {
                    objAvailabilityCalendar = objHotelAvailabilityRS.HotelRoomAvailInfos[i].AvailabilityCalendar;
                    break;
                }

            }

            DateTime dtRateGridStartDate = (DateTime)Session["RateGridStartDate"];

            string strRoomSelectorItemControlPath = ConfigurationManager.AppSettings["RoomSelectorItemControl.ascx"];
            string strRoomTypeSelectorGridItemControlPath = ConfigurationManager.AppSettings["RoomTypeSelectorGridItemControl.ascx"];
            string strRatePlanSelectorGridItemControlPath = ConfigurationManager.AppSettings["RatePlanSelectorGridItemControl.ascx"];

            ucRoomRateSelectorGridControl.Clear();

            ucRoomRateSelectorGridControl.ID = "RoomRateSelector";
            ucRoomRateSelectorGridControl.RoomRefID = strSelectedRoom;
            ucRoomRateSelectorGridControl.HotelRoomAvailInfo = objHotelRoomAvailInfo;
            ucRoomRateSelectorGridControl.RoomOccupantSelection = objRoomOccupantSelection;
            ucRoomRateSelectorGridControl.GridTodayDate = TZNet.ToLocal(WbsUiHelper.GetTimeZone(objStayCriteriaSelection.HotelCode), DateTime.UtcNow).Date;
            ucRoomRateSelectorGridControl.GridStartDate = dtRateGridStartDate.Date;
            ucRoomRateSelectorGridControl.GridNumberDays = this.NumberDaysInRateGrid;

            for (int i = 0; i < objStayCriteriaSelection.RoomOccupantSelections.Length; i++)
            {
                RoomSelectorItemControl ucRoomSelectorItemControl = (RoomSelectorItemControl)LoadControl(strRoomSelectorItemControlPath);
                ucRoomRateSelectorGridControl.AddRoomSelectorItem(ucRoomSelectorItemControl);

                ucRoomSelectorItemControl.ID = "RoomSelectorItem" + objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID;
                ucRoomSelectorItemControl.RoomRefID = objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID;
                ucRoomSelectorItemControl.RoomRefIDMenuText = (String)GetGlobalResourceObject("SiteResources", "RoomSelectorMenuText") + " " + objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID;

                if (objStayCriteriaSelection.RoomOccupantSelections[i].RoomRefID == strSelectedRoom)
                    ucRoomSelectorItemControl.Selected = true;
                else
                    ucRoomSelectorItemControl.Selected = false;
            }

            if (objHotelRoomAvailInfo.RoomTypes != null && objAvailabilityCalendar.RoomRates != null)
            {
                for (int i = 0; i < objHotelRoomAvailInfo.RoomTypes.Length; i++)
                {
                    bool bRatesAvailable = false;

                    for (int j = 0; j < objAvailabilityCalendar.RoomRates.Length; j++)
                    {
                        if (objAvailabilityCalendar.RoomRates[j].RoomTypeCode == objHotelRoomAvailInfo.RoomTypes[i].Code)
                        {
                            if (!IsRoomRateDescriptionModel)
                            {
                                bRatesAvailable = true;
                                break;
                            }

                            else
                            {
                                if (objAvailabilityCalendar.RoomRates[j].DescriptionStatus == RoomRateDescriptionStatus.Active)
                                {
                                    bRatesAvailable = true;
                                    break;
                                }

                                for (int k = 0; k < objHotelRoomAvailInfo.RatePlans.Length; k++)
                                {
                                    if (objHotelRoomAvailInfo.RatePlans[k].Code == objAvailabilityCalendar.RoomRates[j].RatePlanCode)
                                    {
                                        if (objHotelRoomAvailInfo.RatePlans[k].Type == RatePlanType.Negotiated || objHotelRoomAvailInfo.RatePlans[k].Type == RatePlanType.Consortia)
                                        {
                                            bRatesAvailable = true;
                                        }

                                        break;
                                    }

                                }

                                if (bRatesAvailable)
                                    break;
                            }

                        }

                    }

                    if (!bRatesAvailable)
                        continue;

                    RoomTypeSelectorGridItemControl ucRoomTypeSelectorGridItemControl = (RoomTypeSelectorGridItemControl)LoadControl(strRoomTypeSelectorGridItemControlPath);
                    ucRoomRateSelectorGridControl.AddRoomTypeSelectorGridItem(ucRoomTypeSelectorGridItemControl);

                    ucRoomTypeSelectorGridItemControl.ID = "RoomTypeSelectorItem" + objHotelRoomAvailInfo.RoomTypes[i].Code;
                    ucRoomTypeSelectorGridItemControl.RoomRefID = strSelectedRoom;
                    ucRoomTypeSelectorGridItemControl.GridTodayDate = ucRoomRateSelectorGridControl.GridTodayDate;
                    ucRoomTypeSelectorGridItemControl.GridStartDate = ucRoomRateSelectorGridControl.GridStartDate;
                    ucRoomTypeSelectorGridItemControl.GridNumberDays = ucRoomRateSelectorGridControl.GridNumberDays;
                    ucRoomTypeSelectorGridItemControl.GridSelectedStartDate = objStayCriteriaSelection.ArrivalDate;
                    ucRoomTypeSelectorGridItemControl.GridSelectedEndDate = objStayCriteriaSelection.DepartureDate.AddDays(-1);

                    for (int j = 0; j < objHotelDescriptiveInfo.RoomTypes.Length; j++)
                    {
                        if (objHotelDescriptiveInfo.RoomTypes[j].Code == objHotelRoomAvailInfo.RoomTypes[i].Code)
                        {
                            ucRoomTypeSelectorGridItemControl.RoomType = objHotelDescriptiveInfo.RoomTypes[j];
                            break;
                        }

                    }

                    ucRoomTypeSelectorGridItemControl.ShowMoreRates = false;

                    for (int j = 0; j < objShowMoreRatesIndicators.Length; j++)
                    {
                        if (objShowMoreRatesIndicators[j].RoomRefID == ucRoomTypeSelectorGridItemControl.RoomRefID && objShowMoreRatesIndicators[j].RoomTypeCode == ucRoomTypeSelectorGridItemControl.RoomType.Code)
                        {
                            ucRoomTypeSelectorGridItemControl.ShowMoreRates = true;
                            break;
                        }

                    }

                    ucRoomTypeSelectorGridItemControl.Clear();

                    for (int k = 0; k < objAvailabilityCalendar.RoomRates.Length; k++)
                    {
                        if (objAvailabilityCalendar.RoomRates[k].RoomTypeCode == ucRoomTypeSelectorGridItemControl.RoomType.Code)
                        {
                            bool bListRatePlan = true;

                            if (IsRoomRateDescriptionModel && objAvailabilityCalendar.RoomRates[k].DescriptionStatus == RoomRateDescriptionStatus.Inactive)
                            {
                                for (int l = 0; l < objHotelRoomAvailInfo.RatePlans.Length; l++)
                                {
                                    if (objHotelRoomAvailInfo.RatePlans[l].Code == objAvailabilityCalendar.RoomRates[k].RatePlanCode)
                                    {
                                        if (objHotelRoomAvailInfo.RatePlans[l].Type != RatePlanType.Negotiated && objHotelRoomAvailInfo.RatePlans[l].Type != RatePlanType.Consortia)
                                        {
                                            bListRatePlan = false;
                                        }

                                        break;
                                    }

                                }

                            }

                            if (!bListRatePlan)
                                continue;

                            RatePlanSelectorGridItemControl ucRatePlanSelectorGridItemControl = (RatePlanSelectorGridItemControl)LoadControl(strRatePlanSelectorGridItemControlPath);
                            ucRoomTypeSelectorGridItemControl.AddRatePlanSelectorGridItem(ucRatePlanSelectorGridItemControl);

                            ucRatePlanSelectorGridItemControl.ID = "RatePlanSelectorItem" + objAvailabilityCalendar.RoomRates[k].RatePlanCode;
                            ucRatePlanSelectorGridItemControl.RoomRefID = strSelectedRoom;
                            ucRatePlanSelectorGridItemControl.GridStartDate = ucRoomTypeSelectorGridItemControl.GridStartDate;
                            ucRatePlanSelectorGridItemControl.GridNumberDays = ucRoomTypeSelectorGridItemControl.GridNumberDays;
                            ucRatePlanSelectorGridItemControl.GridRoomRate = objAvailabilityCalendar.RoomRates[k];
                            ucRatePlanSelectorGridItemControl.GridRoomRateStartDate = objAvailabilityCalendar.StartDate.Date;
                            ucRatePlanSelectorGridItemControl.ArrivalDate = objStayCriteriaSelection.ArrivalDate.Date;
                            ucRatePlanSelectorGridItemControl.TotalStayNights = ((TimeSpan)(objStayCriteriaSelection.DepartureDate.Date.Subtract(objStayCriteriaSelection.ArrivalDate.Date))).Days;
                            ucRatePlanSelectorGridItemControl.CreditCardCodes = objHotelDescriptiveInfo.CreditCardCodes;
                            ucRatePlanSelectorGridItemControl.Available = false;
                            ucRatePlanSelectorGridItemControl.Selected = false;

                            for (int m = 0; m < objHotelRoomAvailInfo.RatePlans.Length; m++)
                            {
                                if (objHotelRoomAvailInfo.RatePlans[m].Code == objAvailabilityCalendar.RoomRates[k].RatePlanCode)
                                {
                                    ucRatePlanSelectorGridItemControl.RatePlan = objHotelRoomAvailInfo.RatePlans[m];
                                    break;
                                }

                            }

                            for (int m = 0; m < objHotelRoomAvailInfo.RoomRates.Length; m++)
                            {
                                if (objHotelRoomAvailInfo.RoomRates[m].RoomTypeCode == objAvailabilityCalendar.RoomRates[k].RoomTypeCode && objHotelRoomAvailInfo.RoomRates[m].RatePlanCode == objAvailabilityCalendar.RoomRates[k].RatePlanCode)
                                {
                                    ucRatePlanSelectorGridItemControl.Available = true;
                                    ucRatePlanSelectorGridItemControl.RoomRate = objHotelRoomAvailInfo.RoomRates[m];
                                    break;
                                }

                            }

                            for (int m = 0; m < objAvailabilityCalendar.RatePlans.Length; m++)
                            {
                                if (objAvailabilityCalendar.RatePlans[m].RatePlanCode == objAvailabilityCalendar.RoomRates[k].RatePlanCode)
                                {
                                    ucRatePlanSelectorGridItemControl.GridRatePlan = objAvailabilityCalendar.RatePlans[m];
                                    break;
                                }

                            }

                            if (objRoomRateSelection.RoomTypeCode == objAvailabilityCalendar.RoomRates[k].RoomTypeCode && objRoomRateSelection.RatePlanCode == objAvailabilityCalendar.RoomRates[k].RatePlanCode)
                                ucRatePlanSelectorGridItemControl.Selected = true;
                        }

                    }

                }

            }

        }

        return;
    }
    private string RateCurrencyCode(string strRatePlanCode, AvailabilityCalendar objAvCal)
    {
        for (int i = 0; i < objAvCal.RatePlans.Length; i++)
        {
            if (objAvCal.RatePlans[i].RatePlanCode == strRatePlanCode)
                return objAvCal.RatePlans[i].CurrencyCode;
        }

        return "";
    }
    private bool IsAvCalDayAvailable(int intDayID, AvailabilityCalendar objAvCal, DateTime dtToday)
    {
        // Returns true if at least one room rate is available in single calendar instance for day identified

        for (int i = 0; i < objAvCal.RoomRates.Length; i++)
        {
            if (IsAvCalRoomRateAvailable(intDayID, objAvCal.RoomRates[i], objAvCal.RatePlans, objAvCal.StartDate, dtToday))
                return true;
        }

        return false;
    }
    private PopUpRate[] GetPopUpRates(int intDayID, AvailabilityCalendar objAvCal, DateTime dtToday)
    {
        // Returns a list comprising of the lowest available room rate within a rate plan (across all room types) within a single calendar instance

        List<PopUpRate> lPopUpRates = new List<PopUpRate>();

        for (int rri = 0; rri < objAvCal.RoomRates.Length; rri++)
        {
            if (this.IsAvCalRoomRateAvailable(intDayID, objAvCal.RoomRates[rri], objAvCal.RatePlans, objAvCal.StartDate, dtToday))
            {
                PopUpRate objCompareToPopUpRate = null;
                bool bRatePlanStored = false;

                for (int i = 0; i < lPopUpRates.Count; i++)
                {
                    if (lPopUpRates[i].RatePlan.RatePlanCode == objAvCal.RoomRates[rri].RatePlanCode)
                    {
                        objCompareToPopUpRate = lPopUpRates[i];
                        bRatePlanStored = true;
                        break;
                    }

                }

                if (!bRatePlanStored)
                {
                    PopUpRate objPopUpRate = new PopUpRate();
                    lPopUpRates.Add(objPopUpRate);

                    objPopUpRate.RoomRate = objAvCal.RoomRates[rri];

                    for (int i = 0; i < objAvCal.RatePlans.Length; i++)
                    {
                        if (objAvCal.RatePlans[i].RatePlanCode == objAvCal.RoomRates[rri].RatePlanCode)
                        {
                            objPopUpRate.RatePlan = objAvCal.RatePlans[i];
                            break;
                        }

                    }

                    for (int i = 0; i < objAvCal.RoomRates[rri].Rates.Length; i++)
                    {
                        if (objAvCal.RoomRates[rri].Rates[i].DayNum == intDayID)
                        {
                            objPopUpRate.Rate = objAvCal.RoomRates[rri].Rates[i];
                        }

                    }

                }

                else
                {
                    for (int i = 0; i < objAvCal.RoomRates[rri].Rates.Length; i++)
                    {
                        if (objAvCal.RoomRates[rri].Rates[i].DayNum == intDayID)
                        {
                            if (objAvCal.RoomRates[rri].Rates[i].Amount < objCompareToPopUpRate.Rate.Amount)
                            {
                                objCompareToPopUpRate.Rate = objAvCal.RoomRates[rri].Rates[i];
                                break;
                            }

                        }

                    }

                }

            }

        }

        return lPopUpRates.ToArray();
    }
    public void RenderUserControl()
    {
        panActiveAvailCalItem.Visible = false;
        //panInactiveAvailCalItem.Visible = false;
        //panPassedDay.Visible = false;

        lblAvailCalItemDay.Text = this.CalendarDay(_DayID, _AvailabilityCalendarInfo).ToString();

        if(_AvailabilityCalendarInfo != null && _AvailabilityCalendarInfo.Length > 0)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            hdfAvailCalDayDate.Value = serializer.Serialize(_AvailabilityCalendarInfo[0].AvailabilityCalendar.StartDate.AddDays(DayID - 1).Date);
        }

        if (this.IsDayAvailable(_DayID, _AvailabilityCalendarInfo, _Today))
        {
            panActiveAvailCalItem.Visible = true;

            lblViewRatesTitle.Text = (String)GetLocalResourceObject("AvailabileRatesDate") + " " + _AvailabilityCalendarInfo[0].AvailabilityCalendar.StartDate.AddDays(_DayID - 1).Date.ToString("d MMM yyyy");

            if (_Selected == true)
                cbAvailCalItemDaySelected.Checked = true;
            else
                cbAvailCalItemDaySelected.Checked = false;

            lbViewCalRates.Text = this.LowestAvailableRate(_DayID, _AvailabilityCalendarInfo, _Today);
            lbViewCalRates.Attributes.Add("ondblclick", "return hs.htmlExpand(this, { contentId: '" + this.ClientID + "_ViewCalRatesPopup'} )");

            //phSpecialRatesIndicator.Controls.Clear();

            //string strSpecialRatesIndicatorControlPath = ConfigurationManager.AppSettings["SpecialRatesIndicatorControl.ascx"];
            //SpecialRatesIndicatorControl ucSpecialRatesIndicatorControl = (SpecialRatesIndicatorControl)LoadControl(strSpecialRatesIndicatorControlPath);
            //phSpecialRatesIndicator.Controls.Add(ucSpecialRatesIndicatorControl);

            //ucSpecialRatesIndicatorControl.IsActive = this.HasRequestedRates(_DayID, _AvailabilityCalendarInfo, _Today);
            //ucSpecialRatesIndicatorControl.RenderUserControl();

            phViewCalRatesDetails.Controls.Clear();

            for (int ri = 0; ri < _StayCriteriaSelection.RoomOccupantSelections.Length; ri++)
            {
                AvailabilityCalendar objAvCal = new AvailabilityCalendar();

                bool bAvCalLocated = false;

                for (int i = 0; i < _AvailabilityCalendarInfo.Length; i++)
                {
                    if (_AvailabilityCalendarInfo[i].SegmentRefID == _StayCriteriaSelection.RoomOccupantSelections[ri].RoomRefID)
                    {
                        objAvCal = _AvailabilityCalendarInfo[i].AvailabilityCalendar;
                        bAvCalLocated = true;
                        break;
                    }

                }

                if (!bAvCalLocated)
                    continue;

                StringBuilder sbRoomHeader = new StringBuilder();

                sbRoomHeader.Append((String)GetLocalResourceObject("RoomIdentifierText" + _StayCriteriaSelection.RoomOccupantSelections[ri].RoomRefID));
                sbRoomHeader.Append(" ");

                sbRoomHeader.Append(_StayCriteriaSelection.RoomOccupantSelections[ri].NumberAdults.ToString());
                sbRoomHeader.Append(" ");
                sbRoomHeader.Append((String)GetLocalResourceObject("AdultsInfo"));

                if (_StayCriteriaSelection.RoomOccupantSelections[ri].NumberChildren != 0)
                {
                    sbRoomHeader.Append(", ");
                    sbRoomHeader.Append(_StayCriteriaSelection.RoomOccupantSelections[ri].NumberChildren.ToString());
                    sbRoomHeader.Append(" ");
                    sbRoomHeader.Append((String)GetLocalResourceObject("ChildrenInfo"));
                }

                Panel panRoomHeader = new Panel();
                panRoomHeader.CssClass = "avail_cal_rates_popup_detail_header";

                Label lblRoomHeaderText = new Label();
                lblRoomHeaderText.Text = sbRoomHeader.ToString();

                panRoomHeader.Controls.Add(lblRoomHeaderText);
                phViewCalRatesDetails.Controls.Add(panRoomHeader);

                PopUpRate[] objPopUpRates = this.GetPopUpRates(_DayID, objAvCal, _Today);

                for (int i = 0; i < objPopUpRates.Length; i++)
                {
                    Panel panPopUpRateHolder = new Panel();
                    panPopUpRateHolder.CssClass = "avail_cal_rates_popup_detail_block";

                    Panel panPopUpRateName = new Panel();
                    panPopUpRateName.CssClass = "avail_cal_rates_popup_detail_name avail_cal_rates_popup_detail";

                    Panel panPopUpRateDesc = new Panel();
                    panPopUpRateDesc.CssClass = "avail_cal_rates_popup_detail_desc avail_cal_rates_popup_detail";

                    Panel panPopUpRateAmount = new Panel();
                    panPopUpRateAmount.CssClass = "avail_cal_rates_popup_detail_amount avail_cal_rates_popup_detail";

                    Label lblPopUpRateName = new Label();
                    Label lblPopUpRateDescription = new Label();
                    Label lblPopUpRateAmount = new Label();

                    Label lblPopUpRateRestrictions = new Label();
                    lblPopUpRateRestrictions.CssClass = "avail_cal_rates_popup_detail_restrictions";

                    lblPopUpRateName.Text = objPopUpRates[i].RatePlan.Name;
                    lblPopUpRateDescription.Text = objPopUpRates[i].RatePlan.Description;
                    lblPopUpRateRestrictions.Text = ((XnGR_WBS_Page)this.Page).RateRestrictions(objPopUpRates[i].RoomRate, objPopUpRates[i].Rate);
                    lblPopUpRateAmount.Text = (string)GetLocalResourceObject("RatesFrom") + " " + objPopUpRates[i].RatePlan.CurrencyCode + " " + objPopUpRates[i].Rate.Amount.ToString(((XnGR_WBS_Page)this.Page).CurrencyFormat());

                    if (lblPopUpRateRestrictions.Text == null || lblPopUpRateRestrictions.Text == "")
                        lblPopUpRateRestrictions.Visible = false;

                    panPopUpRateName.Controls.Add(lblPopUpRateName);
                    panPopUpRateDesc.Controls.Add(lblPopUpRateDescription);
                    panPopUpRateDesc.Controls.Add(lblPopUpRateRestrictions);
                    panPopUpRateAmount.Controls.Add(lblPopUpRateAmount);

                    panPopUpRateHolder.Controls.Add(panPopUpRateName);
                    panPopUpRateHolder.Controls.Add(panPopUpRateDesc);
                    panPopUpRateHolder.Controls.Add(panPopUpRateAmount);

                    phViewCalRatesDetails.Controls.Add(panPopUpRateHolder);
                }

            }

            var currentDay = _AvailabilityCalendarInfo[0].AvailabilityCalendar.StartDate.AddDays(_DayID - 1);
            var startDate = _AvailabilityCalendarInfo[0].AvailabilityCalendar.StartDate;
            if ((currentDay.Year.Equals(startDate.Year) && currentDay.Month > startDate.Month) || currentDay.Year > startDate.Year)
                panAvailCalItem.CssClass = string.Format("{0} {1}", panAvailCalItem.CssClass, "mm_available_next_month");
            panAvailCalItem.CssClass = string.Format("{0} {1}", panAvailCalItem.CssClass, "mm_available");
        }

        else if(_DayID < _Today.Day)
        {
            panAvailCalItem.CssClass = string.Format("{0} {1}", panAvailCalItem.CssClass, "mm_passed_day");
        }
        else
        {
            panAvailCalItem.CssClass = string.Format("{0} {1}", panAvailCalItem.CssClass, "mm_not_available");
        }

        return;
    }