$(function () {
    if ($('a.open-in-popup').length > 0) {
        $('a.open-in-popup').click(function (e) {
            e.preventDefault();
            sendto('', '', this.href, "7");
        });
    }
    $(".toggle-container").css('display', 'none');
    $(".deals-toggle").css('display', 'block');
    $(".toggle .open").each(function () {
        $(this).removeClass("open");
        $(".deals-open").addClass("open");
    });
    $(".toggle-link").click(function () {
        $(this).toggleClass("open");
		if ($(this).hasClass('open')) {
			$(this).parents(".toggle").find(".toggle-container").slideToggle();
		} else {
			$(this).parents(".toggle").find(".toggle-container").css('display', 'none');
		}
			
       return false;
    });
    if ($('.deal-section').length != 0 && $.getUrlVar('offerInfo') != undefined) {
        var anchorIdValue = $.getUrlVar('offerInfo');
        $('#' + anchorIdValue).scrollView();
    }
});
$.fn.scrollView = function () {
	alert("here");
    return this.each(function () {
        $('html, body').animate({
            scrollTop: $(this).offset().top
        }, 1000);
    });
}
$.extend({
    getUrlVars: function () {
        var vars = [],
            hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function (name) {
        return $.getUrlVars()[name];
    }
});

$(function () {
    var groupBookingForm = $('form.group-booking-meeting-space');
    if (groupBookingForm.length > 0) {
        $(groupBookingForm).find('p.sleeping-rooms :input:text, div.meetings-space :input:text').each(function () {
            $(this).val("")
        });
        $(groupBookingForm).find('div.meetings-space, p.sleeping-rooms').hide('fast');
        $(groupBookingForm).find(':radio[name=eventOptionsRadio]').bind('click change', findMeetingSpaceComponent.meetingsPrefRadioButtonEventHandler);
        $(groupBookingForm).bind('submit', findMeetingSpaceComponent.meetingsSubmitEventHandler);
    }
    $(".tabs-container").tabs();
    $(".sub-tabs-container").tabs();
    $(".tabs-container .tab-headings").show();
    $(".tabs-container .tab-main-headings").addClass('alternate-headings');
    $(".tab-headings li:last").css("margin-right", 0);
    var columnList = $('.two-column-list');
    var twoColumnArea = $('.zone-section.two-column-50-50').find('ul.two-column-list');
    if (columnList.length > 0) {
        var colWidthPercentage = '45%';
        if (twoColumnArea.length > 0) colWidthPercentage = '43%';
        columnList.makeacolumnlists({
            cols: 2,
            colWidth: colWidthPercentage
        });
    }








    $("#photo-tour-container #view-all-photos a").click(function () {
        var url = $(this).attr('href');
        viewAllPhotos(url);
    });
    $("#photo-gallery-link a,#photo-gallery a").click(function () {
        var url = $(this).attr('rel');
        sendto('no_country', 'no_brand', url, '23');
        return false;
    });
    $("#check-rate, #uk-phone-number, #au-phone-number, #telephone-reservation-page").click(function () {
        var url = $(this).attr('href');
        OpenInOpener(url);
    });
    $("#photo-tour-container #print").click(function () {
        window.print();
        return false;
    });
    $("#photo-tour-container #close").click(function () {
        window.close();
        return false;
    });
    if ($("#photo-carousel-container").length != 0) {
        $("#photo-carousel-container").show();
        photosPerPage = parseInt($("#photos-per-page").val());
        hotelCode = $("#hotel-code").val();
        hotelLocale = $("#hotel-locale").val();
        photoPageId = 1;
        photoId = 1;
        photoPagesTotal = $("#hotel-photos-total").val() / photosPerPage;
        imagePath = $("#image-path").val();
        if (photoPagesTotal == 1) {
            $("#photo-tour-L").hide();
            $("#photo-tour-R").hide();
        }
        var pageVisited = new Array();
        for (i = 1; i <= photoPagesTotal; i++) {
            pageVisited[i] = "N";
        }
        $(".photo-carousel-container .photo-container").jCarouselLite({
            btnNext: "#photo-tour-R",
            btnPrev: "#photo-tour-L",
            circular: false,
            scroll: photosPerPage,
            visible: photosPerPage
        });
        function loadHotelImages() {
            if (pageVisited[photoPageId] == "N") {
                PhotoCarouselRemoteService.getPhotoCarouselInfoBySet(hotelCode, hotelLocale, photoPageId, photosPerPage, {
                    callback: function (data) {
                        for (var i = 0; i < data.length; i++) {
                            $("#hotel-photos #photo" + parseInt(photoId)).parent().parent().toggleClass("show-photo-li");
                            $("#hotel-photos #photo" + parseInt(photoId)).attr("src", imagePath + data[i].thumbnailImageFile);
                            $("#hotel-photos #photo" + parseInt(photoId)).attr("alt", data[i].imageAltTag);
                            $("#hotel-photos #photo-link" + parseInt(photoId)).attr("href", data[i].photoTourPopupPgURL);
                            photoId = parseInt(photoId) + 1;
                        }
                    },
                  timeout: 0,
                errorHandler: function (message) {}
                });
                pageVisited[photoPageId] = "Y";
            }
            photoPageId = parseInt(photoPageId) + 1;
        }
//        loadHotelImages();
        $("#photo-tour-R").click(function () {
            if (photoPageId > photoPagesTotal) {
                return false;
            }
            var photocarouselfirstValue = $("#photo-carousel-first").text();
            var photocarousellastValue = $("#photo-carousel-last").text();
			totPhotos = $("#hotel-photos-total").val();
			if (parseInt(photocarousellastValue) <= parseInt(totPhotos)) {
				checkMaxVal = parseInt(photocarouselfirstValue) + photosPerPage;
				if (checkMaxVal > totPhotos) {
		            $("#photo-carousel-first").text(parseInt(totPhotos));
				} else {
		            $("#photo-carousel-first").text(parseInt(photocarouselfirstValue) + photosPerPage);
				}
					
				checkMaxVal = parseInt(photocarousellastValue) + photosPerPage;
				if (checkMaxVal > totPhotos) {
		            $("#photo-carousel-last").text(parseInt(totPhotos));
				} else {
		            $("#photo-carousel-last").text(parseInt(photocarousellastValue) + photosPerPage);
				}
			}
            photoPageId = parseInt(photoPageId) + 1;
//        loadHotelImages();
        });

        $("#photo-tour-L").click(function () {
            if (photoPageId == 2) {
                return false;
            }
            var photocarouselfirstValue = $("#photo-carousel-first").text();
            var photocarousellastValue = $("#photo-carousel-last").text();
            $("#photo-carousel-first").text(parseInt(photocarouselfirstValue) - photosPerPage);
            $("#photo-carousel-last").text(parseInt(photocarousellastValue) - photosPerPage);
            photoPageId = parseInt(photoPageId) - 1;
        });
        $("#hotel-photos .sendto-link").hover(function () {
            $(this).append('<img src="http://hoteis.marriott.com.br/hotels/wip-carousel/images/magnify_glass_16x16.gif" border="0" class="zoom"/>');
        }, function () {
            $(".zoom").remove();
        });
    }
    $(".sub-tabs-container").tabs();
    var biggestHeight = 0;
    $('#driving-container .vcard').each(function () {
        if ($(this).height() > biggestHeight) {
            biggestHeight = $(this).height();
        }
    });
    $('#driving-container .vcard').height(biggestHeight);
    $("#airportcode, #streetaddress").click(function () {
        maxHeight = $("#driving-container #start").height();
        $("#driving-container #end").height(maxHeight);
    });
    $("#reverse").click(function () {
        if ($("#driving-container #start").hasClass("start")) {
            $("#driving-container #start").removeClass("start");
            $("#driving-container #start").addClass("end");
            $("#start .heading").text($("#endLocation").val());
            $("#end .heading").text($("#startLocation").val());
            $("#isDirectionFromProperty").val("true");
            if ($("#driving-container .more-options").length != 0) {
                $("#driving-container .more-options span").addClass("move-left");
            }
        } else {
            $("#driving-container #start").removeClass("end");
            $("#driving-container #start").addClass("start");
            $("#start .heading").text($("#startLocation").val());
            $("#end .heading").text($("#endLocation").val());
            $("#isDirectionFromProperty").val("false");
            if ($("#driving-container .more-options").length != 0) {
                $("#driving-container .more-options span").removeClass("move-left");
            }
        }
        if ($("#driving-container #end").hasClass("start")) {
            $("#driving-container #end").removeClass("start");
            $("#driving-container #end").addClass("end");
        } else {
            $("#driving-container #end").removeClass("end");
            $("#driving-container #end").addClass("start");
        }
        return false;
    });
    if ($("#isDirectionFromProperty").val() == 'true') {
        $("#reverse").trigger('click');
    }
    if ($("#address-type").val() == "airport") {
        $("#airportcode").trigger('click');
    }
    $("#street-address #origin-address, #street-address  #origin-city,#street-address  #origin-zip").change(function () {
        clearAirportDetails();
    });
    $("#street-address #origin-state").change(function () {
        state_clearAirportDetails();
    });
    $("#street-address #origin-country").change(function () {
        country_clearAirportDetails();
    });
    $("#origin-airport, #origin-airport-code").change(function () {
        changeAirportDetail(this);
    });
    if ($(".local-attractions-tabs #tab-local-attractions").length != 0) {
        $(".tab-headings li").removeClass("ui-tabs-selected");
        $("#tab-local-attractions-link").parent().addClass("ui-tabs-selected");
        $(".tab-contents-wrapper").addClass("ui-tabs-hide");
        $("#tab-local-attractions").removeClass("ui-tabs-hide");
    }
});
$(function () {
    $('#save-hotel-link').click(function () {
        var saveHotels = $(this).metadata({
            type: 'attr',
            name: 'data'
        }).savable;
        if (saveHotels == 'false') {
            var errorMsg = $('#max-hotels-message').html();
            $('#modal-box').miLightboxes({
                sizeWidth: 350,
                headerFormat: 2,
                content: errorMsg
            });
            return false;
        }
    });
    var phoneNumbers = $('li.phone-numbers-container dl');
    var phoneLabel = $('.phone-number');
    $('li.phone-numbers-container').removeClass('hidden');
    phoneNumbers.addClass('phone-list');
    phoneLabel.css('cursor', 'pointer').removeClass('open').parents('.phone-numbers-container').removeClass('open');
    phoneLabel.bind('click', function () {
        $(this).parents('.phone-numbers-container').toggleClass('open');
        return false;
    });
});
$(function () {
    var imageCarousel = $('.image-carousel');
    if (imageCarousel.length > 0) {
        var firstImageHeight = imageCarousel.find('img:first').height();
        imageCarousel.css('overflow', 'hidden').css('height', firstImageHeight);
        $('#expand-images').click(function () {
            imageCarousel.css('height', 'auto');
            return false;
        });
        $('#collapse-images').click(function () {
            imageCarousel.css('height', firstImageHeight);
            return false;
        });
        imageCarousel.find('a').click(function () {
            var floorPlanHeaders = $('#floor-plan-headers').html();
            var lBContent = $(this).children('img').attr('src');
            lBContent = '<div class="floor-plan-headers">' + floorPlanHeaders + '</div><img src="' + lBContent + '"/>';
            $('#modal-box').css('padding', '18px 5px 18px 10px').miLightboxes({
                content: lBContent,
                sizeWidth: 920,
                sizeHeight: 600
            });
            return false;
        });
    }
    var roomSetupLink = $('#room-setups');
    if (roomSetupLink.length > 0) {
        roomSetupLink.click(function () {
            var c = $(this).attr('href');
            $('#modal-box').miLightboxes({
                content: c,
                sizeWidth: 735,
                sizeHeight: 540,
                external: true
            });
            return false;
        });
    }
    var capacityToggle = $('#capacity-toggle');
    if (capacityToggle.length > 0) {
        capacityToggle.addClass('open').parents('.toggle').find('.toggle-container').show();
        capacityToggle.click(function () {
            var showText = capacityToggle.metadata({
                type: 'attr',
                name: 'data'
            }).showtext;
            var hideText = capacityToggle.metadata({
                type: 'attr',
                name: 'data'
            }).hidetext;
            var linkText;
            if ($(this).filter('.open').length > 0) {
                linkText = hideText;
            } else {
                linkText = showText;
            }
            capacityToggle.html(linkText).attr('title', linkText);
            return false;
        });
    }
});
$(function () {
    $('#terms-and-conditions a').click(function () {
        var tc = $(this).attr('href');
        $('#modal-box').miLightboxes({
            content: tc,
            sizeWidth: 550,
            sizeHeight: 270,
            external: true
        });
        return false;
    });
    $('#hotel-specific-message a').click(function () {
        var hs = $(this).attr('href');
        $('#modal-box').miLightboxes({
            content: hs,
            sizeWidth: 550,
            sizeHeight: 270,
            external: true
        });
        return false;
    });
    $('#expand-all').click(function () {
        $('.facts-container .toggle-link').addClass('open');
        $('.facts-container .toggle-link').next('.toggle-container').slideDown();
        return false;
    });
    $('#collapse-all').click(function () {
        $('.facts-container .toggle-link').removeClass('open');
        $('.facts-container .toggle-link').next('.toggle-container').slideUp();
        return false;
    });
//    $('.facts-container .toggle-link:first').addClass('open');
//    $('.facts-container .toggle-link:first').next('.toggle-container').slideToggle();
    $('#print-link a').click(function () {
        window.print();
        return false;
    });
    var propDescr = $('#property-description');
    if (propDescr.length > 0 && propDescr.height() > '90') {
        var toggleText = propDescr.metadata({
            type: 'attr',
            name: 'data'
        });
        propDescr.addClass('collapsed').after('<a id="read-more" href="#" class="toggle-link">' + toggleText.more + '</a>');
        var readMore = $('#read-more');
        readMore.bind('click', function () {
            propDescr.toggleClass('collapsed');
            if (readMore.hasClass('open')) readMore.html(toggleText.more).removeClass('open');
            else
            readMore.html(toggleText.less).addClass('open');
            if (typeof omnitureCustom != "undefined") {
                if (typeof omnitureCustom.sendExpandFlyoutTrackingData == "function") {
                    omnitureCustom.sendExpandFlyoutTrackingData("HWS: Expand Read More", "");
                }
            }
            return false;
        });
    }
    $("#current-form").submit(function () {
        var eventDateObj = {
            dateFormatPattern: $(this).find(':hidden[name=dateFormatPattern]').val().toLowerCase(),
            fromDate: $(this).find(':input[name=fromDate]').get(0),
            toDate: $(this).find(':input[name=toDate]').get(0),
            minDate: $(this).find(':hidden[name=minDate]').get(0),
            maxDate: $(this).find(':hidden[name=maxDate]').get(0)
        };
        var errMessage = "We're sorry. We couldn't submit your search. Please correct the following and try again. \nYour ";
        var dateFormatPattern = eventDateObj.dateFormatPattern;
        var fromDateObj = eventDateObj.fromDate;
        if (fromDateObj != null && (fromDateObj.value == null || fromDateObj.value == "")) {
            errMessage += "From date cannot not be null ";
            alert(errMessage);
            $(fromDateObj).focus();
            return false;
        } else if (!isDateValid(fromDateObj.value, dateFormatPattern)) {
            errMessage += "From date is invalid. Please check the date. ";
            alert(errMessage);
            $(fromDateObj).focus();
            return false;
        }
        var toDateObj = eventDateObj.toDate;
        if (toDateObj != null && (toDateObj.value == null || toDateObj.value == "")) {
            errMessage += "To date cannot not be null ";
            alert(errMessage);
            $(toDateObj).focus();
            return false;
        } else if (!isDateValid(toDateObj.value, dateFormatPattern)) {
            errMessage += "To date is invalid. Please check the date. ";
            alert(errMessage);
            $(toDateObj).focus();
            return false;
        }
        var minDate = eventDateObj.minDate.value;
        if (isDateLessThanDate1(fromDateObj.value, formatDate(minDate, dateFormatPattern), dateFormatPattern)) {
            errMessage += "beginning search date cannot be less than " + formatDate(minDate, dateFormatPattern);
            alert(errMessage);
            $(fromDateObj).focus();
            return false;
        }
        if (isDateLessThanDate1(toDateObj.value, formatDate(minDate, dateFormatPattern), dateFormatPattern)) {
            errMessage += "ending search date cannot be less than " + formatDate(minDate, dateFormatPattern);
            alert(errMessage);
            $(toDateObj).focus();
            return false;
        }
        var maxDate = eventDateObj.maxDate.value;
        if (isDateGreaterThanDate1(fromDateObj.value, formatDate(maxDate, dateFormatPattern), dateFormatPattern)) {
            errMessage += "beginning search date cannot be more than " + formatDate(maxDate, dateFormatPattern);
            alert(errMessage);
            $(fromDateObj).focus();
            return false;
        }
        if (isDateGreaterThanDate1(toDateObj.value, formatDate(maxDate, dateFormatPattern), dateFormatPattern)) {
            errMessage += "ending search date cannot be more than " + formatDate(maxDate, dateFormatPattern);
            alert(errMessage);
            $(toDateObj).focus();
            return false;
        }
        if (isDateLessThanDate1(toDateObj.value, fromDateObj.value, dateFormatPattern)) {
            errMessage += " beginning search date must come before your ending search date."
            alert(errMessage);
            $(fromDateObj).focus();
            return false;
        }
        return true;
    });
    $(".attraction-records-per-page, .events-records-per-page, .local-records-per-page").change(function () {
        $(this.form).submit();
    });
});
$(function () {
    $("#local-area-highlights #aroundTownCategory").val("");
    $("#guideTypeId").change(function () {
        var dropdown = this.value;
        if (dropdown && dropdown != '') {
            $(this.form).submit();
        }
    });
    $("#aroundTownCategory").change(function () {
        var aroundTown = this.value;
        if (aroundTown && aroundTown != '') {
            if (aroundTown == '0') {
                $("#AroundtownForm #topPicks").val("Y");
            }
            $(this).parents("form").submit();
        }
    });
    $("#pointOfInterestBrowseId").change(function () {
        var pointOfInterestBrowse = this.value;
        if (pointOfInterestBrowse && pointOfInterestBrowse != '') {
            $(this).parents("form").submit();
        }
    });
    $("#pointOfInterestServiceId").change(function () {
        var pointOfInterestService = this.value;
        if (pointOfInterestService && pointOfInterestService != '') {
            $(this).parents("form").submit();
        }
    });
    var golfNearby = $('#more-golf');
    if (golfNearby.length > 0) {
        nearbyToggle(golfNearby, 'more-golf');
    }
    var spaNearby = $('#more-spa');
    if (spaNearby.length > 0) {
        nearbyToggle(spaNearby, 'more-spa');
    }
    var fitnessNearby = $('#more-fitness');
    if (fitnessNearby.length > 0) {
        nearbyToggle(fitnessNearby, 'more-fitness');
    }

    function nearbyToggle(container, name) {
        var toggleText = container.metadata({
            type: 'attr',
            name: 'data'
        });
        container.prepend('<p><a href="#" id="' + name + '-toggle" class="toggle-link">' + toggleText.more + '</a></p>');
        var toggleLink = $('#' + name + '-toggle');
        toggleLink.bind('click', function () {
            if ($(this).hasClass('open')) {
                $(this).html(toggleText.more);
            } else {
                $(this).html(toggleText.less);
            }
            $(this).toggleClass("open");
            $(this).parents(".toggle:first").find(".toggle-container:first").slideToggle();
            return false;
        });
    }
    $('.hotel-factsheet-link-container').html('');
    $("#new-window a").click(function () {
        var url = $(this).attr('href');
        sendto('US', 'marriott', url, '3');
        return false;
    });
});
$(function () {
    var facebookDiv = $('.facebook-like');
    if (facebookDiv.length > 0) {
        var prefix = window.parent.location.protocol;
        var facebookData = facebookDiv.metadata({
            type: 'attr',
            name: 'data'
        });
        var facebookIframe = '<iframe src="' + prefix + '//www.facebook.com/plugins/like.php?locale=' + facebookData.locale + '&href=' + facebookData.domain + '&amp;layout=button_count&amp;show_faces=false&amp;width=164&amp;action=like&amp;font=arial&amp;colorscheme=dark&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:164px; height:21px;" allowTransparency="true"></iframe>';
        facebookDiv.html(facebookIframe);
    }
});

function resize(pageContainerId, imageClass, x, y) {
    if (!document.getElementById(pageContainerId)) return;
    var desiredWidth = x;
    var desiredHeight = y;
    var imageHeight, imageWidth, xFraction, yFraction, newWidth, newHeight, image, imgs;
    imgs = document.getElementsByTagName('img');
    for (var i = 0; i < imgs.length; i++) {
        if (imgs[i].className.match(imageClass)) {
            image = imgs[i];
            imageHeight = image.clientHeight;
            imageWidth = image.clientWidth;
            yFraction = imageHeight / desiredHeight;
            xFraction = imageWidth / desiredWidth;
            if (xFraction > 0 || yFraction > 0) {
                if (xFraction > yFraction) {
                    newWidth = imageWidth / xFraction;
                    newHeight = imageHeight / xFraction;
                } else {
                    newWidth = imageWidth / yFraction;
                    newHeight = imageHeight / yFraction;
                }
            } else {
                if (xFraction < yFraction) {
                    newWidth = imageWidth * xFraction;
                    newHeight = imageHeight * xFraction;
                } else {
                    newWidth = imageWidth * yFraction;
                    newHeight = imageHeight * yFraction;
                }
            }
            image.style.width = newWidth + "px";
            image.style.height = newHeight + "px";
        }
    }
}
$(function () {
    var hwsResTimeOutErrorMsg = $('#hws-timeout-error');
    if (hwsResTimeOutErrorMsg.length > 0) {
        var error = hwsResTimeOutErrorMsg.metadata({
            type: 'attr',
            name: 'data'
        });
        hwsResTimeOutErrorMsg.remove();
        var buttons = [{
            label: error.buttonlabel,
            callback: function () {
                $(this).dialog("close");
            }
        }];
        var hotelTitleArea = $('#hotel-title-area');
        var xAxis = hotelTitleArea.position().left;
        var yAxis = hotelTitleArea.position().top + hotelTitleArea.height();
        $('#modal-box').miLightboxes({
            sizeWidth: 365,
            sizeHeight: 180,
            headerFormat: 2,
            lightBoxClass: 'error-alert',
            tOverride: error.title,
            buttonsArray: buttons,
            position: [xAxis, yAxis],
            content: error.content
        });
    }
    $('.res-toggle-link').click(function () {
        $(this).next('.res-toggle-container').toggle('', function () {
            $(this).prev('.res-toggle-link').toggleClass('collapsed');
        });
    });
    $('.res-toggle-container').not(':has(\'input[name=clusterCode][value!=\'none\']:checked\')').prev('.res-toggle-link').click();
    $('#hws-reservation-module').find('.radio-secondary-input').click(function () {
        $(this).closest('li').find('.radio').attr('checked', true);
        $('#hws-reservation-module').find('input[name="clusterCode"]').not(":checked").closest('li').find('.radio-secondary-input').val('');
    });
    $('#hws-reservation-module').find('.use-rewards-points').click(function () {
        if ($(this).is(':checked')) {
            $('#hws-reservation-module').find('#none').attr('checked', true);
            $('#hws-reservation-module').find('.radio-secondary-input').val('');
        }
    });
    $('#hws-reservation-module').find('#redeem-rewards-link').click(function () {
        var useRewardsCheckbox = $(this).closest('fieldset').find(':checkbox');
        if (!useRewardsCheckbox.is(':checked')) {
            useRewardsCheckbox.attr('checked', true);
            $('#hws-reservation-module').find('#none').attr('checked', true);
            $('#hws-reservation-module').find('.radio-secondary-input').val('');
        }
    });
    $('#hws-reservation-module').find('input[name="clusterCode"]').click(function () {
        if ($(this).val() != 'none') {
            $('#hws-reservation-module').find('.use-rewards-points').attr('checked', false);
        }
        $('#hws-reservation-module').find('input[name="clusterCode"]').not(":checked").closest('li').find('.radio-secondary-input').val('');
        $(this).closest('li').find('.radio-secondary-input').focus();
    });
    $('#hws-reservation-module').find('.pop-over').click(function (e) {
        e.preventDefault();
        var c = $(this).attr('href');
        $('#modal-box').miLightboxes({
            content: c,
            sizeWidth: 740,
            sizeHeight: 380,
            external: true
        });
        return false;
    });
    $('.deal-section').find('.toggle-link ').click(function () {
        $(this).closest('.toggle').find('.toggle-container').find('.deals-more-options').click(function (event) {
            event.preventDefault();
            var objForm = $(this).closest('form');
            var fromDate = $(objForm).find('.check-in').val();
            var toDate = $(objForm).find('.check-out').val();
            var numberOfRooms = $(objForm).find('#room-num').val();
            var numberOfGuests = $(objForm).find('#guests-num').val();
            var marriottRewardsNumber = $(objForm).find('#marriottRewardsNumber').val();
            var url = $(this).attr('href') + "&fromDate=" + fromDate + "&toDate=" + toDate + "&numberOfGuests=" + numberOfGuests + "&numberOfRooms=" + numberOfRooms + "&marriottRewardsNumber=" + marriottRewardsNumber;
            window.location.href = url;
        });
    });
    $('#reservations-summary-container').tabs();
});
$(function () {
    $('form.hws-reservations-form').submit(function () {
        var objForm = this;
        var objClusterCode = $(objForm).find('input[name="clusterCode"]');
        if (objClusterCode.length) {
            var validationMessages = $(objForm).metadata({
                type: 'attr',
                name: 'data'
            });
            var groupRatesMessage = validationMessages.groupMessage;
            var useRewardsPtsMessage = validationMessages.useRewardsPtsMessage;
            var groupCodeMsg = validationMessages.groupCodeMsg;
            var corpCodeMsg = validationMessages.corpCodeMsg;
            var awardTypeMsg = validationMessages.awardTypeMsg;
            var redeemAwardMoreRoomMsg = validationMessages.redeemAwardMoreRoomsMsg;
            var redeemAwardOneRoomMsg = validationMessages.redeemAwardOneRoomMsg;
            var noneRadioButton = $(objForm).find('#none');
            var roomNumber = $(objForm).find('#room-num');
            var corprateCode = $(objForm).find('#corp-code');
            var groupCode = $(objForm).find('#group-code');
            var awardNumber = $(objForm).find('#award-number');
            var specialTextFieldCollection = corprateCode.add(groupCode).add(awardNumber);
            var groupRadio = $(objForm).find('#group');
            var corpRadio = $(objForm).find('#corp');
            var incentiveRadio = $(objForm).find('#incentive-code');
            var useRewardCheckbox = $(objForm).find('#use-rewards-points');
            var selectedSpecialRate = $(objClusterCode).filter(":checked").val();
            var checkIn = $(objForm).find('.check-in');
            var checkOut = $(objForm).find('.check-out');
            if ($(roomNumber).length && $(roomNumber).val() == 4 && (selectedSpecialRate != "none" && selectedSpecialRate != "INT")) {
                var choice = confirm(groupRatesMessage);
                if (choice) {
                    $(specialTextFieldCollection).each(function () {
                        $(this).val('');
                    });
                    noneRadioButton.attr('checked', true);
                }
                return choice;
            }
            if (groupRadio.is(':checked') && (!$.trim(groupCode.val()) || groupCode.val().length < 7)) {
                alert(groupCodeMsg);
                return false;
            }
            if (corpRadio.is(':checked') && (!$.trim(corprateCode.val()) || corprateCode.val().length < 3)) {
                alert(corpCodeMsg);
                return false;
            }
            if (incentiveRadio.is(':checked') && !$.trim(awardNumber.val())) {
                var choice = confirm(awardTypeMsg);
                if (choice) {
                    $(specialTextFieldCollection).each(function () {
                        $(this).val('');
                    });
                    noneRadioButton.attr('checked', true);
                }
                return choice;
            }
            if (incentiveRadio.is(':checked') && $.trim(awardNumber.val()) && roomNumber.val() == 4) {
                var choice = confirm(redeemAwardMoreRoomMsg);
                if (choice) {
                    $(specialTextFieldCollection).each(function () {
                        $(this).val('');
                    });
                    noneRadioButton.attr('checked', true);
                }
                return choice;
            } else if (incentiveRadio.is(':checked') && $.trim(awardNumber.val()) && roomNumber.val() > 1) {
                alert(redeemAwardOneRoomMsg);
                return false;
            }
            if (useRewardCheckbox.attr('checked') && (roomNumber.val() == 4)) {
                var choice = confirm(useRewardsPtsMessage);
                if (choice) {
                    useRewardCheckbox.attr('checked', false);
                    noneRadioButton.attr('checked', true);
                }
                return choice;
            }
            return dates.validateDates('availability', checkIn.attr('id'), checkOut.attr('id'), '');
        }
        return true;
    });
});
$(function () {
    $('form.hws-reservations-form').find('h3.res-toggle-link').attr('id', 'automation-special-rates-link');
    $('#hotel-directory-link > a').attr('id', 'automation-hotel-directory-link');
    $('#reservations-summary').find('h3.res-toggle-link').attr('id', 'automation-res-detail-link');
    $('#reserve-by-phone > h3.res-toggle-link').attr('id', 'automation-reserve-by-phone-link');
    $('#contact-us > h3.res-toggle-link').attr('id', 'automation-contact-us-link');
});
var guestRoomQuickView = {
    fetchedQuickViews: Array,
    quickViewTabs: Array,
    init: function () {
        if (document.getElementById("guest-rooms-list")) {
            var quickViewToggleHeadings = YAHOO.util.Dom.getElementsByClassName("open-quick-view-heading");
            for (var i = 0; i < quickViewToggleHeadings.length; i++) {
                quickViewToggleHeadings[i].onclick = guestRoomQuickView.toggleQuickView;
            }
            var quickViewToggles = YAHOO.util.Dom.getElementsByClassName("open-quick-view");
            for (var m = 0; m < quickViewToggles.length; m++) {
                quickViewToggles[m].onclick = guestRoomQuickView.toggleQuickView;
            }
            var quickViewToggles = YAHOO.util.Dom.getElementsByClassName("quick-view-hide");
            for (var n = 0; n < quickViewToggles.length; n++) {
                quickViewToggles[n].onclick = guestRoomQuickView.toggleQuickView;
            }
            var quickViews = YAHOO.util.Dom.getElementsByClassName("quick-view");
            for (var o = 0; o < quickViews.length; o++) {
                guestRoomQuickView.quickViewTabs[quickViews[o].id] = new YAHOO.widget.TabView(quickViews[o].id);
            }
        }
    },
    toggleQuickView: function () {
        var propertyMarshaCode = document.getElementById("property-marshaCode").value;
        var quickViewRoomCode;
        if (this.className == "open-quick-view-heading" || this.className == "close-quick-view-heading") {
            quickViewRoomCode = this.id.substring(19, this.id.length);
        } else {
            quickViewRoomCode = this.id.substring(18, this.id.length);
        }
        var quickViewToShow = "quick-view-" + quickViewRoomCode;
        var quickViewToggle = "quick-view-toggle-" + quickViewRoomCode;
        var quickViewToggleHeading = "quick-view-heading-" + quickViewRoomCode;
        var roomRecord = "guest-room-record-" + quickViewRoomCode;
        var siteLocale = document.getElementById("site-locale").value;
        if (this.className == "open-quick-view" || this.className == "open-quick-view-heading") {
            var attributes = {
                height: {
                    to: 347
                }
            };
            if ($("#guest-rooms-list").length != 0) {
                var attributes = {
                    height: {
                        to: 292
                    }
                };
            }
            YAHOO.util.Dom.addClass(document.getElementById(roomRecord), "active-record");
            if (this.className == "open-quick-view") {
                this.className = "close-quick-view";
                document.getElementById(quickViewToggleHeading).className = "close-quick-view-heading";
            } else if (this.className == "open-quick-view-heading") {
                this.className = "close-quick-view-heading";
                document.getElementById(quickViewToggle).className = "close-quick-view";
                var currentMainContainer = YAHOO.util.Dom.getAncestorByClassName(this, 'guest-room-container');
                YAHOO.util.Dom.addClass(currentMainContainer, 'expanded');
            }
            if (!guestRoomQuickView.fetchedQuickViews[quickViewRoomCode]) {
                YAHOO.util.Dom.addClass(quickViewToShow, "loading");
                ReservationRemoteService.retrieveKORDetails(propertyMarshaCode, quickViewRoomCode, siteLocale, function (data) {
                    if (data == {}) {
                        return true;
                    }
                    var isRoomOverviewAvailable = false;
                    var isPhotoCarouselAvailable = false;
                    if (data.carouselPhotoList && data.carouselPhotoList.length > 0) {
                        var imagePath = imgPath;
                        var photoList = quickViewRoomCode + "-carousel-list";
                        var imageList = [];
                        var urlList = [];
                        var altList = [];
                        for (var i = 0; i < data.carouselPhotoList.length; i++) {
                            imageList.push(imagePath + data.carouselPhotoList[i].thumbnailImageFile);
                            urlList.push(data.carouselPhotoList[i].photoTourPopupPgURL);
                            altList.push(data.carouselPhotoList[i].imageAltTag);
                        };
                        var carouselObj = {
                            imgPathList: imageList,
                            urlList: urlList,
                            altTextList: altList
                        };
                        var carouselId = quickViewRoomCode + "-carousel";
                        var previousButton = quickViewRoomCode + '-prev-arrow';
                        var nextButton = quickViewRoomCode + '-next-arrow';
                        var carousel = new Carousel(carouselId, {
                            prevElement: previousButton,
                            nextElement: nextButton
                        }, carouselObj);
                        isPhotoCarouselAvailable = true;
                    } else {
                        YAHOO.util.Dom.addClass(quickViewRoomCode + "-image-disclaimer", "hidden");
                        YAHOO.util.Dom.addClass(quickViewRoomCode + "-room-photos", "hidden");
                        var guestRoomInfoContainer = document.getElementById(quickViewRoomCode + "-guest-room-info-container");
                        YAHOO.util.Dom.removeClass(guestRoomInfoContainer, "guest-room-information");
                    }
                    if (data.korDataErrorMessages && data.korDataErrorMessages.length > 0) {
                        var noKORDataErrorMessage = "";
                        for (i = 0; i < data.korDataErrorMessages.length; i++) {
                            if (i == 0) {
                                noKORDataErrorMessage = noKORDataErrorMessage + data.korDataErrorMessages[i];
                            } else {
                                noKORDataErrorMessage = noKORDataErrorMessage + ", " + data.korDataErrorMessages[i];
                            }
                        }
                        if (noKORDataErrorMessage != "") {
                            $("#" + quickViewRoomCode + "-room-overview").html(noKORDataErrorMessage);
                        }
                        var roomAmenitiesTab = guestRoomQuickView.quickViewTabs["quick-view-" + quickViewRoomCode].getTab(1);
                        guestRoomQuickView.quickViewTabs["quick-view-" + quickViewRoomCode].removeTab(roomAmenitiesTab);
                        var roomMediaTab = guestRoomQuickView.quickViewTabs["quick-view-" + quickViewRoomCode].getTab(1);
                        guestRoomQuickView.quickViewTabs["quick-view-" + quickViewRoomCode].removeTab(roomMediaTab);
                    } else {
                        var roomOverviewText = "";
                        if (data.roomFeatureDetails.roomOverview && data.roomFeatureDetails.roomOverview.featuresList.length > 0) {
                            for (i = 0; i < data.roomFeatureDetails.roomOverview.featuresList.length; i++) {
                                if (i == 0) {
                                    roomOverviewText = roomOverviewText + data.roomFeatureDetails.roomOverview.featuresList[i];
                                } else {
                                    roomOverviewText = roomOverviewText + ", " + data.roomFeatureDetails.roomOverview.featuresList[i];
                                }
                            }
                        }
                        if (roomOverviewText != "") {
                            isRoomOverviewAvailable = true;
                            $("#" + quickViewRoomCode + "-room-overview").html(roomOverviewText);
                        } else {
                            YAHOO.util.Dom.addClass(quickViewRoomCode + "-room-overview", "hidden");
                        }
                        guestRoomQuickView.populateContent(quickViewRoomCode, isRoomOverviewAvailable, isPhotoCarouselAvailable, data.roomFeatureDetails.conciergeFeatures, data.roomFeatureDetails.roomFeaturesList);
                    }
                    YAHOO.util.Dom.removeClass(quickViewToShow, "loading");
                });
                guestRoomQuickView.fetchedQuickViews[quickViewRoomCode] = true;
            }
        } else {
            var attributes = {
                height: {
                    to: 0
                }
            };
            if (this.className == "quick-view-hide") {
                document.getElementById(quickViewToggle).className = "open-quick-view";
                document.getElementById(quickViewToggleHeading).className = "open-quick-view-heading";
            } else if (this.className == "close-quick-view-heading") {
                this.className = "open-quick-view-heading";
                document.getElementById(quickViewToggle).className = "open-quick-view";
                var currentMainContainer = YAHOO.util.Dom.getAncestorByClassName(this, 'guest-room-container');
                YAHOO.util.Dom.removeClass(currentMainContainer, 'expanded');
            } else {
                this.className = "open-quick-view";
                document.getElementById(quickViewToggleHeading).className = "open-quick-view-heading";
            }
            setTimeout(function setIt() {
                document.getElementById(roomRecord).className = ""
            }, 200);
        }
        var anim = new YAHOO.util.Anim(quickViewToShow, attributes, .1);
        anim.animate();
        return false;
    },
    populateContent: function (roomTypeCode, isRoomOverviewAvailable, isPhotoCarouselAvailable, specialFeatureList, otherFeatureList) {
        var specialFeaturesInnerHtml = "";
        var roomFeaturesInnerHtml = "";
        var accessibleRoomFeaturesInnerHtml = "";
        var hospitalityServiceFeaturesInnerHtml = "";
        var roomOverviewFeatureContent = "";
        var mainRoomOverFeatureContainer = document.getElementById(roomTypeCode + "-room-overview-tab-features");
        var bedsFeatureInnerHtml = "";
        var bathFeatureInnerHtml = "";
        var furnitureFeatureInnerHtml = "";
        var foodFeatureInnerHtml = "";
        var kitchenFeatureInnerHtml = "";
        var roomAmenitiesFeatureContent = "";
        var roomAmenitiesFeatureContainer = document.getElementById(roomTypeCode + "-guest-room-amenities-tab");
        var internetFeatureInnerHtml = "";
        var entertainmentFeatureInnerHtml = "";
        var inRoomMediaFeatureContent = "";
        var inRoomMediaFeatureContainer = document.getElementById(roomTypeCode + "-guest-room-media-tab");
        if (specialFeatureList && specialFeatureList.featuresList.length > 0) {
            specialFeaturesInnerHtml = guestRoomQuickView.populateFeatures(specialFeatureList);
        }
        if (otherFeatureList && otherFeatureList.length > 0) {
            for (i = 0; i < otherFeatureList.length; i++) {
                if (otherFeatureList[i] && otherFeatureList[i].featureType == 8) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        roomFeaturesInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 12) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        accessibleRoomFeaturesInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 10) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        hospitalityServiceFeaturesInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 3) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        bedsFeatureInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 4) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        bathFeatureInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 5) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        furnitureFeatureInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 6) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        foodFeatureInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 7) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        kitchenFeatureInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 9) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        internetFeatureInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                } else if (otherFeatureList[i] && otherFeatureList[i].featureType == 11) {
                    if (otherFeatureList[i].featuresList.length > 0) {
                        entertainmentFeatureInnerHtml = guestRoomQuickView.populateFeatures(otherFeatureList[i]);
                    }
                }
            }
        }
        var isRoomOverViewTabDeleted = false;
        roomOverviewFeatureContent = guestRoomQuickView.populateFeatureColumn(new Array(specialFeaturesInnerHtml, roomFeaturesInnerHtml), new Array(accessibleRoomFeaturesInnerHtml, hospitalityServiceFeaturesInnerHtml));
        if (roomOverviewFeatureContent != "" && roomOverviewFeatureContent.length > 0) {
            mainRoomOverFeatureContainer.innerHTML = roomOverviewFeatureContent;
        } else {
            if (!isRoomOverviewAvailable && !isPhotoCarouselAvailable) {
                var roomOverviewTab = guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].getTab(0);
                guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].removeTab(roomOverviewTab);
                isRoomOverViewTabDeleted = true;
            }
        }
        var isAmenitiesTabDeleted = false;
        roomAmenitiesFeatureContent = guestRoomQuickView.populateFeatureColumn(new Array(bedsFeatureInnerHtml, bathFeatureInnerHtml), new Array(furnitureFeatureInnerHtml, foodFeatureInnerHtml, kitchenFeatureInnerHtml));
        if (roomAmenitiesFeatureContent != "" && roomAmenitiesFeatureContent.length > 0) {
            roomAmenitiesFeatureContainer.innerHTML = roomAmenitiesFeatureContent;
        } else {
            var roomAmenitiesTab;
            if (isRoomOverViewTabDeleted) {
                roomAmenitiesTab = guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].getTab(0);
            } else {
                roomAmenitiesTab = guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].getTab(1);
            }
            guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].removeTab(roomAmenitiesTab);
            isAmenitiesTabDeleted = true;
        }
        inRoomMediaFeatureContent = guestRoomQuickView.populateFeatureColumn(new Array(internetFeatureInnerHtml), new Array(entertainmentFeatureInnerHtml));
        if (inRoomMediaFeatureContent != "" && inRoomMediaFeatureContent.length > 0) {
            inRoomMediaFeatureContainer.innerHTML = inRoomMediaFeatureContent;
        } else {
            var roomMediaTab;
            if (isRoomOverViewTabDeleted && isAmenitiesTabDeleted) {
                roomMediaTab = guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].getTab(0);
            } else if (isRoomOverViewTabDeleted || isAmenitiesTabDeleted) {
                roomMediaTab = guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].getTab(1);
            } else {
                roomMediaTab = guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].getTab(2);
            }
            guestRoomQuickView.quickViewTabs["quick-view-" + roomTypeCode].removeTab(roomMediaTab);
        }
    },
    populateFeatureColumn: function (column1, column2) {
        var tabContent = "";
        if (column1.length > 0) {
            var column1Text = "";
            for (a = 0; a < column1.length; a++) {
                column1Text = column1Text + column1[a];
            }
            if (column1Text != "") {
                tabContent = tabContent + "<div class=\"column\">" + column1Text + "</div>";
            }
        }
        if (column2.length > 0) {
            var column2Text = "";
            for (j = 0; j < column2.length; j++) {
                column2Text = column2Text + column2[j];
            }
            if (column2Text != "") {
                tabContent = tabContent + "<div class=\"column\">" + column2Text + "</div>";
            }
        }
        return tabContent;
    },
    populateFeatures: function (featureList) {
        var featureInnerHtml = "";
        if (featureList.featuresList.length > 0) {
            featureInnerHtml = featureInnerHtml + "<h3>" + featureList.featureName + "</h3>";
            featureInnerHtml = featureInnerHtml + "<ul class='guest-room'>";
            for (j = 0; j < featureList.featuresList.length; j++) {
                featureInnerHtml = featureInnerHtml + "<li>" + featureList.featuresList[j] + "</li>";
            }
            featureInnerHtml = featureInnerHtml + "</ul>";
        }
        return featureInnerHtml;
    }
}
YAHOO.util.Event.onDOMReady(guestRoomQuickView.init);

function clearAirportDetails() {
    sform = document.forms['drivingDirectionsForm'];
    sform.originAirportCode.value = "";
    sform.originAirport.selectedIndex = 0;
    document.getElementById("address-type").value = "street";
}

function state_clearAirportDetails() {
    sform = document.forms['drivingDirectionsForm'];
    sform.originAirportCode.value = "";
    sform.originAirport.selectedIndex = 0;
    if (sform.originState.value != null && sform.originState.value.length > 0) {
        sform.originCountry.value = "US";
    }
    document.getElementById("address-type").value = "street";
}

function country_clearAirportDetails() {
    sform = document.forms['drivingDirectionsForm'];
    sform.originAirportCode.value = "";
    sform.originAirport.selectedIndex = 0;
    if (sform.originCountry.value != null && sform.originCountry.value != "US") {
        sform.originState.value = "";
    }
    document.getElementById("address-type").value = "street";
}

function clearAddress() {
    sform = document.forms['drivingDirectionsForm'];
    sform.originAddress.value = "";
    sform.originCity.value = "";
    sform.originState.selectedIndex = 0;
    sform.originCountry.selectedIndex = 0;
    sform.originZip.value = "";
    document.getElementById("address-type").value = "airport";
}

function changeAirportDetail(sel) {
    sform = document.forms['drivingDirectionsForm'];
    if (sel.type == "text") {
        csel = sform.originAirport;
        for (i = 0; i < csel.length; i++) {
            if (csel.options[i].value == sel.value) {
                csel.selectedIndex = i;
                break;
            }
        }
    } else {
        if (sel.options[sel.selectedIndex].value.length == 3) {
            sform.originAirportCode.value = sel.options[sel.selectedIndex].value;
        }
    }
    clearAddress();
}
