var sNSExperiments = "experiments";
var sNSStartup = "startup";
var sNSExperimentsLoad = "experiments_load";
var sNSStartupLoad = "startup_load";
booking.ensureNamespaceExists(sNSExperiments);
booking.ensureNamespaceExists(sNSStartup);
booking.ensureNamespaceExists(sNSExperimentsLoad);
booking.ensureNamespaceExists(sNSStartupLoad);
booking[sNSStartup].init = function(k) {
    var j = [];
    var e = 0;
    if (k == "ready") {
        var h = sNSExperiments;
        var d = sNSStartup
    }
    if (k == "load") {
        var h = sNSExperimentsLoad;
        var d = sNSStartupLoad
    }
    for (sExperiment in booking[h]) {
        if (typeof booking[h][sExperiment].init == "function") {
            var c = (booking[h][sExperiment].priority) ? booking[h][sExperiment].priority : 9;
            var g = true;
            var l = "b_site_experiment_" + sExperiment;
            if (!booking.env[l]) {
                g = false
            }
            if (g) {
                j.push([c,sExperiment,h,false])
            } else {
                if (typeof booking[h][sExperiment].initElse == "function") {
                    j.push([c,sExperiment,h,true])
                } else {
                    booking[h][sExperiment].init = null
                }
            }
        }
    }
    for (sStartup in booking[d]) {
        if (typeof booking[d][sStartup].init == "function") {
            var c = (booking[d][sStartup].priority) ? booking[d][sStartup].priority : 9;
            j.push([c,sStartup,d,false])
        }
    }
    if (j.length > 0) {
        j.sort();
        for (var f = 0; f < j.length; f++) {
            sInitItem = j[f];
            booking[sInitItem[2]][sInitItem[1]].ns = "booking." + sInitItem[2];
            booking[sInitItem[2]][sInitItem[1]].name = sInitItem[1];
            if (sInitItem[3] == true) {
                e = booking[sInitItem[2]][sInitItem[1]].initElse()
            } else {
                e = booking[sInitItem[2]][sInitItem[1]].init()
            }
            if (typeof e == "boolean") {
                if (e) {
                    booking[sInitItem[2]][sInitItem[1]].init = null
                }
            }
        }
    }
};





$(document).ready(function() {
    booking[sNSStartup].init("ready")
});
$(window).load(function() {
    booking[sNSStartup].init("load")
});
if (!window.console) {
    window.console = new function() {
        this.log = function(c) {
        };
        this.dir = function(c) {
        };
        this.debug = function(c) {
        };
        this.info = function(c) {
        };
        this.warn = function(c) {
        };
        this.table = function(c) {
        };
        this.trace = function() {
        };
        this.time = function(c) {
        };
        this.timeEnd = function(c) {
        };
        this.info = function(c) {
        }
    }
}
booking[sNSStartup].anchorJump = {priority:9,init:function() {
    if ($("#newsletterbox .error").length) {
        location.href = location.href + "#errormsg"
    }
    $(".forgotten a, a.forgotten").click(function() {
        window.open(this.href, "", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=1,width=500,height=500,left=200,top=200");
        return false
    })
}};
function show_group_rooms_by_persons(d) {
    var c = $(d).parent().parent().parent().parent().parent().children("table.group_rooms_by_persons_groups_room_table");
    table_display = $(c).css("display"),links = $(d).parent().parent().children("td").children(".group_rooms_red_link, .group_rooms_green_link"),plus_minus = $(d).parent().parent().children("td").children("a.show_group_rooms_by_persons").children("span");
    if (table_display == "none") {
        $(c).show();
        $(links).hide();
        $(plus_minus).html('<img src="//q.bstatic.com/static/img/experiments/icon_open.gif" width="15" height="15" alt="open">')
    } else {
        $(c).hide();
        $(plus_minus).html('<img src="//r.bstatic.com/static/img/experiments/icon_shut.gif" width="15" height="15" alt="close">');
        $(links).show()
    }
}
window.onload = function() {
    $("table.group_rooms_by_persons_groups_room_table").css("display", "none")
};
room_group_sniffing = {init:function() {
    if (typeof(b_cookie) == "undefined") {
        b_cookie = {}
    }
    b_cookie.my_value = "group_sniffing_is_true";
    if (typeof(JSON) != "undefined") {
        $.cookie("b", JSON.stringify(b_cookie), {expires:30,path:"/",domain:booking.env.b_domain_end})
    }
},closed:function() {
    b_cookie.my_value = "group_sniffing_is_false";
    if (typeof(JSON) != "undefined") {
        $.cookie("b", JSON.stringify(b_cookie), {expires:30,path:"/",domain:booking.env.b_domain_end})
    }
}};
booking[sNSStartupLoad].calendar = {priority:9,version:1.4,datefmt:"YYYY MM DD",minimalDays:1,maximalDays:30,oldDays:1,from:{date:null,day:null,month:null,year:null},till:{date:null,day:null,month:null,year:null},viewDateFrom:new Date(),viewDateTill:new Date(),oneDayInMS:86400000,calendars:[],calendarTypes:{checkin_day:{isTill:false,isDay:true},checkin_monthday:{isTill:false,isDay:true},checkin_year_month:{isTill:false,isDay:false},pre_checkin_year_month:{isTill:false,isDay:false},checkout_day:{isTill:true,isDay:true},checkout_monthday:{isTill:true,isDay:true},checkout_year_month:{isTill:true,isDay:false},pre_checkout_year_month:{isTill:true,isDay:false}},maxMonthsInFuture:12,maxDaysInFuture:365,maxDaysInThePast:1,syncDate:null,userServDate:false,dateFormat:function(j, v, q) {
    var k = /D{1,4}|M{1,4}|YY(?:YY)?/g,h = function(m, d) {
        m = String(m);
        d = d || 2;
        while (m.length < d) {
            m = "0" + m
        }
        return m
    };
    var g = this;
    if (arguments.length == 1 && Object.prototype.toString.call(j) == "[object String]" && !/\d/.test(j)) {
        v = j;
        j = undefined
    }
    j = j ? new Date(j) : new Date;
    if (isNaN(j)) {
        throw SyntaxError("invalid date")
    }
    v = String(v || g.datefmt);
    if (v.slice(0, 4) == "UTC:") {
        v = v.slice(4);
        q = true
    }
    var t = q ? "getUTC" : "get",n = j[t + "Date"](),c = j[t + "Day"](),f = j[t + "Month"](),o = j[t + "FullYear"](),r = j[t + "Hours"](),l = j[t + "Minutes"](),u = j[t + "Seconds"](),e = {D:n,DD:h(n),DDD:booking.env.b_simple_weekdays_for_js[(c + 6) % 7],DDDD:booking.env.b_long_weekdays[(c + 6) % 7],M:f + 1,MM:h(f + 1),MMM:booking.env.b_short_months_abbr[f],MMMM:booking.env.b_short_months[f],YY:String(o).slice(2),YYYY:o};
    return v.replace(k, function(d) {
        return d in e ? e[d] : d.slice(1, d.length - 1)
    })
},searchMinDays:function(c) {
    this.minimalDays = c
},maxYearsInFuture:function() {
    this.today = this.noHourDate(null);
    this.maxMonthsInFuture = 12;
    this.maxDaysInFuture = 365;
    if (booking.env.b_site_experiment_extra_calendar_month) {
        if (this.maxMonthsInFuture < 13) {
            this.maxMonthsInFuture = 13
        }
        if (this.maxMonthsInFuture < 395) {
            this.maxDaysInFuture = 395
        }
    }
    this.tomorrow = this.dateAfterDays(this.today, 1);
    this.endOfYear1 = this.dateAfterDays(this.today, this.maxDaysInFuture);
    this.endOfYear2 = this.dateAfterDays(this.today, this.maxDaysInFuture - 1)
},setPast:function(c) {
    this.maxDaysInThePast = c
},syncDates:function(c, d, j, f, h) {
    if (!h) {
        $("#availcheck").attr("checked", false);
        if (booking.env.b_site_experiment_no_rooms_searchbox) {
            booking[sNSExperiments].no_rooms_searchbox.hide_no_dates()
        }
        $("#define_group").removeClass("disableme");
        $("#define_group input").removeAttr("disabled")
    }
    if (c) {
        this.till.day = (d == null) ? this.till.day : d;
        this.till.month = (j == null) ? this.till.month : j;
        this.till.year = (f == null) ? this.till.year : f;
        if (this.till.day != null && this.till.month != null && this.till.year != null) {
            this.till.date = new Date(this.till.year + "/" + this.till.month + "/" + this.till.day + " 00:00:00");
            this.viewDateTill = new Date(this.till.year + "/" + this.till.month + "/" + this.till.day + " 00:00:00")
        }
    } else {
        this.from.day = (d == null) ? this.from.day : d;
        this.from.month = (j == null) ? this.from.month : j;
        this.from.year = (f == null) ? this.from.year : f;
        if (this.from.day != null && this.from.month != null && this.from.year != null) {
            this.from.date = new Date(this.from.year + "/" + this.from.month + "/" + this.from.day + " 00:00:00");
            this.viewDateFrom = new Date(this.from.year + "/" + this.from.month + "/" + this.from.day + " 00:00:00")
        }
    }
    var g = false;
    if (!c && this.from.date != null) {
        if (this.till.date != null) {
            if (this.till.date <= this.from.date) {
                this.till.date = this.dateAfterDays(this.from.date, this.oldDays);
                g = true
            }
        } else {
            if (!h) {
                this.till.date = this.dateAfterDays(this.from.date, this.minimalDays);
                g = true
            }
        }
    } else {
        if (c && this.till.date != null) {
            if (this.from.date == null) {
                if (!h) {
                    this.from.date = this.dateAfterDays(this.till.date, ~(this.minimalDays - 1));
                    g = true
                }
            }
        }
    }
    if (g) {
        if (!c) {
            this.till.year = this.till.date.getFullYear();
            this.till.month = this.till.date.getMonth() + 1;
            this.till.day = this.till.date.getDate();
            this.viewDateTill = new Date(this.till.year + "/" + this.till.month + "/" + this.till.day + " 00:00:00")
        } else {
            this.from.year = this.from.date.getFullYear();
            this.from.month = this.from.date.getMonth() + 1;
            this.from.day = this.from.date.getDate();
            this.viewDateFrom = new Date(this.from.year + "/" + this.from.month + "/" + this.from.day + " 00:00:00")
        }
    }
    for (var e = 0; e < this.calendars.length; e++) {
        $(this.calendars[e]).trigger("changed_date", [c,g])
    }
},init:function() {
    if (booking.env.b_site_experiment_fix_user_dates) {
        var f = booking.env.b_current_datetime;
        this.syncDate = f.replace(/-/gi, "/");
        var g = new Date(this.syncDate);
        g.setDate(g.getDate() + 1);
        var e = new Date();
        this.syncDate = new Date(this.syncDate);
        this.syncDate.setDate(this.syncDate.getDate() - 0.5);
        if (g < e) {
            this.userServDate = true;
            this.viewDateFrom = new Date(this.syncDate);
            this.viewDateTill = new Date(this.syncDate)
        } else {
            var d = new Date(this.syncDate);
            d.setDate(d.getDate() - 1);
            if (d > e) {
                this.userServDate = true;
                this.viewDateFrom = new Date(this.syncDate);
                this.viewDateTill = new Date(this.syncDate)
            }
        }
    }
    this.maxYearsInFuture();
    this.initAddHandlers();
    if (booking.env.b_site_experiment_calendar_with_input) {
        for (var c = 0; c < this.calendars.length; c++) {
            if (this.calendars[c]) {
                $(this.calendars[c]).closest(".calendar_with_input").removeClass("calendar_with_input__loading")
            }
        }
    }
},initAddHandlers:function(c) {
    var e = this;
    if (c) {
        sSelTar = "#" + c + " "
    } else {
        sSelTar = ""
    }
    $(sSelTar + "select").each(function() {
        if (e.calendarTypes[$(this).attr("name")]) {
            e.calendars.push(this);
            var f = $(this).val();
            if (f != "0") {
                var h = e.calendarTypes[$(this).attr("name")];
                if (h.isDay) {
                    if (h.isTill) {
                        e.till.day = f
                    } else {
                        e.from.day = f
                    }
                } else {
                    var g = f.split("-");
                    if (g.length && g.length > 0) {
                        if (h.isTill) {
                            e.till.year = g[0];
                            e.till.month = g[1]
                        } else {
                            e.from.year = g[0];
                            e.from.month = g[1]
                        }
                    }
                }
            }
            $(this).bind("changed_date", function(k, j, n) {
                $("input", this.parentNode).each(function() {
                    if (e.calendarTypes[$(this).attr("name")]) {
                        var o = e.calendarTypes[$(this).attr("name")];
                        if (o.isDay && o.isTill && e.till.day != null) {
                            $(this).val(e.till.day)
                        }
                        if (o.isDay && !o.isTill && e.from.day != null) {
                            $(this).val(e.from.day)
                        }
                        if (!o.isDay && o.isTill && e.till.month != null && e.till.year != null) {
                            $(this).val(e.till.year + "-" + e.till.month)
                        }
                        if (!o.isDay && !o.isTill && e.from.month != null && e.from.year != null) {
                            $(this).val(e.from.year + "-" + e.from.month)
                        }
                    }
                });
                var l = e.calendarTypes[$(this).attr("name")];
                if (((j || n) && l.isTill) || ((!j || n) && !l.isTill)) {
                    if (l.isDay) {
                        if ((l.isTill && e.till.year != null && e.till.month != null) || (!l.isTill && e.from.year != null && e.from.month != null)) {
                            e.rebuildDaySelect(this, l.isTill)
                        }
                    } else {
                        if (l.isTill && e.till.year != null && e.till.month != null) {
                            e.selectOption(this, e.till.year + "-" + e.till.month)
                        } else {
                            if (!l.isTill && e.from.year != null && e.from.month != null) {
                                e.selectOption(this, e.from.year + "-" + e.from.month)
                            }
                        }
                    }
                }
                if (booking.env.b_site_experiment_calendar_with_input) {
                    if (e.calendarTypes[$(this).attr("name")]) {
                        var m = e.calendarTypes[$(this).attr("name")];
                        if (m.isDay && m.isTill && e.till.day != null) {
                            $("input.check_date", this.parentNode).val(e.dateFormat(e.till.date, booking.env.date_format_locale)).removeClass("noInitalInputValue")
                        }
                        if (m.isDay && !m.isTill && e.from.day != null) {
                            $("input.check_date", this.parentNode).val(e.dateFormat(e.from.date, booking.env.date_format_locale)).removeClass("noInitalInputValue")
                        }
                    }
                }
            });
            $(this).change(function() {
                var m = e.calendarTypes[$(this).attr("name")];
                var l = $(this).val();
                var k = l.split("-");
                if (l != "0") {
                    if ($(this).parents(".newcalendar").length) {
                        var j = $(this).parents(".newcalendar");
                        if (k.length && k.length > 1) {
                            if ($(this).parents(".calendarTill").length) {
                                e.viewDateTill = new Date(k[0] + "/" + k[1] + "/" + e.viewDateTill.getDate() + " 00:00:00");
                                e.rebuildCalendarTable($(".calendarTill table", j).get(0), true, e.viewDateTill.getMonth() + 1, e.viewDateTill.getFullYear())
                            } else {
                                e.viewDateFrom = new Date(k[0] + "/" + k[1] + "/" + e.viewDateFrom.getDate() + " 00:00:00");
                                e.rebuildCalendarTable($("table", j).get(0), false, e.viewDateFrom.getMonth() + 1, e.viewDateFrom.getFullYear())
                            }
                        }
                    } else {
                        e.syncDates(m.isTill, (m.isDay) ? l : null, (m.isDay) ? null : ((k.length && k.length > 1) ? k[1] : null), (m.isDay) ? null : k[0])
                    }
                }
            })
        }
    });
    var d = $(sSelTar + ".newcalendar").length;
    $(sSelTar + ".newcalendar").each(function() {
        if ($(".calendarTill", this).length) {
            e.rebuildCalendarTable($(".calendarTill table", this).get(0), true, e.viewDateTill.getMonth() + 1, e.viewDateTill.getFullYear())
        }
        if (d > 1) {
            e.rebuildCalendarTable($("table", this).get(0), false, e.viewDateFrom.getMonth() + 1, e.viewDateFrom.getFullYear())
        }
        e.calendars.push(this);
        $(this).bind("changed_date", function(g, f, j) {
            if ($(".calendarTill", this).length) {
                if (e.till.month != null && e.till.year != null) {
                    e.rebuildCalendarTable($(".calendarTill table", this).get(0), true, e.till.month, e.till.year);
                    var h = (e.till.day) ? e.till.day : 1;
                    e.viewDateTill = new Date(e.till.year + "/" + e.till.month + "/" + h + " 00:00:00")
                }
            }
            if (e.from.month != null && e.from.year != null) {
                if (d > 1) {
                    e.rebuildCalendarTable($("table", this).get(0), false, e.from.month, e.from.year)
                }
                var h = (e.from.day) ? e.from.day : 1;
                e.viewDateFrom = new Date(e.from.year + "/" + e.from.month + "/" + h + " 00:00:00")
            }
            e.updateLabels()
        });
        $("td", this).bind("click", function() {
            if (parseInt($(this).text()) > 0) {
                if ($("a", this).length) {
                    if ($(this).parents(".calendarTill").length) {
                        if (booking.env.b_action == "hotel" && booking.env.b_site_experiment_new_change_dates_hp) {
                            if ($(".new_change_dates .checkout_monthday").val() != $(this).text()) {
                                $(".new_change_dates .checkout_monthday").css({"font-weight":"bold"})
                            }
                            if ($(".new_change_dates .checkout_year_month").val() != e.viewDateTill.getFullYear() + "-" + (e.viewDateTill.getMonth() + 1)) {
                                $(".new_change_dates .checkout_year_month").css({"font-weight":"bold"})
                            }
                        }
                        e.syncDates(true, $(this).text(), e.viewDateTill.getMonth() + 1, e.viewDateTill.getFullYear())
                    } else {
                        if (booking.env.b_action == "hotel" && booking.env.b_site_experiment_new_change_dates_hp) {
                            if ($(".new_change_dates .checkin_day").val() != $(this).text()) {
                                $(".new_change_dates .checkin_day").css({"font-weight":"bold"})
                            }
                            if ($(".new_change_dates .checkin_year_month").val() != e.viewDateFrom.getFullYear() + "-" + (e.viewDateFrom.getMonth() + 1)) {
                                $(".new_change_dates .checkin_year_month").css({"font-weight":"bold"})
                            }
                        }
                        e.syncDates(false, $(this).text(), e.viewDateFrom.getMonth() + 1, e.viewDateFrom.getFullYear())
                    }
                    if (booking.env.b_action == "hotel" && booking.env.b_site_experiment_new_change_dates_hp) {
                        booking[sNSExperiments].new_change_dates_hp.enable_button()
                    }
                    if (!booking.env.b_site_experiment_groups_number_rooms) {
                        $("#define_group").show()
                    }
                    e.closePopupCalendar()
                }
            }
            return false
        });
        $(".nextmonth", this).bind("click", function() {
            if (!$(this).hasClass("disabled")) {
                var f = $(this).parents(".newcalendar").get(0);
                if ($(this).parents(".calendarTill").length) {
                    e.viewDateTill = e.dateAfterDays(e.viewDateTill, 0, 1);
                    e.rebuildCalendarTable($("table", f).get(0), true, e.viewDateTill.getMonth() + 1, e.viewDateTill.getFullYear())
                } else {
                    e.viewDateFrom = e.dateAfterDays(e.viewDateFrom, 0, 1);
                    e.rebuildCalendarTable($("table", f).get(0), false, e.viewDateFrom.getMonth() + 1, e.viewDateFrom.getFullYear())
                }
            }
            this.blur();
            return false
        });
        $(".prevmonth", this).bind("click", function() {
            if (!$(this).hasClass("disabled")) {
                var f = $(this).parents(".newcalendar").get(0);
                if ($(this).parents(".calendarTill").length) {
                    e.viewDateTill = e.dateAfterDays(e.viewDateTill, 0, -1);
                    e.rebuildCalendarTable($("table", f).get(0), true, e.viewDateTill.getMonth() + 1, e.viewDateTill.getFullYear())
                } else {
                    e.viewDateFrom = e.dateAfterDays(e.viewDateFrom, 0, -1);
                    e.rebuildCalendarTable($("table", f).get(0), false, e.viewDateFrom.getMonth() + 1, e.viewDateFrom.getFullYear())
                }
            }
            this.blur();
            return false
        });
        $("select", this).each(function() {
            var f = $(this).attr("name");
            var g = $(this).val();
            if (e.calendarTypes[f]) {
                if (!e.calendarTypes[f].isDay) {
                    $(this).attr("name", "pre_" + f);
                    $(this.parentNode).append('<input type="hidden" name="' + f + '" value="' + g + '" />')
                }
            } else {
                $(this).change(function() {
                    var h = $(this).val();
                    if (h != "0") {
                        var j = h.split("-");
                        if (j.length && j.length > 0) {
                            oCalendar = $(this).parents(".newcalendar");
                            if ($(this).parents(".calendarTill").length) {
                                e.viewDateTill = new Date(j[0] + "/" + j[1] + "/1 00:00:00");
                                e.rebuildCalendarTable($("table", oCalendar).get(0), true, j[1], j[0])
                            } else {
                                e.viewDateFrom = new Date(j[0] + "/" + j[1] + "/1 00:00:00");
                                e.rebuildCalendarTable($("table", oCalendar).get(0), false, j[1], j[0])
                            }
                        }
                    }
                })
            }
        })
    });
    $(sSelTar + ".calendarLink").click(function() {
        e.openPopupCalendar(this);
        return false
    });
    $(sSelTar + ".calendar_close").click(function() {
        e.closePopupCalendar();
        return false
    });
    if (this.from.year != null && this.from.month != null && this.from.day != null) {
        e.syncDates(false, this.from.day, this.from.month, this.from.year, true)
    }
    if (this.till.year != null && this.till.month != null && this.till.day != null) {
        e.syncDates(true, this.till.day, this.till.month, this.till.year, true)
    }
},updateLabels:function() {
    var d = Math.round((this.noHourDate(this.till.date) - this.noHourDate(this.from.date)) / this.oneDayInMS);
    if (d > 0) {
        if (booking.env.night && booking.env.nights) {
            var c = (d == 1) ? 1 + " " + booking.env.night : booking.env.nights.replace("{amount}", d);
            if (c.indexOf(d) < 0) {
                c = d + " " + c
            }
            if ($(".dayamount").length) {
                $(".dayamount").text(c)
            }
            if ($(".no_nights_helper").length) {
                $(".no_nights_helper").text("(" + c + ")")
            }
        }
    }
    if ($(".calendarFrom").length) {
        $(".calendarFrom .ct_month").text(booking.env.b_short_months[parseInt(this.from.month) - 1]);
        $(".calendarFrom .ct_day").text(this.from.day);
        if ($(".calendarTill").length) {
            $(".calendarTill .ct_month").text(booking.env.b_short_months[parseInt(this.till.month) - 1]);
            $(".calendarTill .ct_day").text(this.till.day)
        }
    }
},updatePrevNextLinks:function(c, d) {
    var g = this;
    var f = this.dateAfterDays(this.tomorrow, (this.maxDaysInFuture - 2));
    var e = ($(d).parents(".calendarTill").length) ? this.viewDateTill : this.viewDateFrom;
    $(".nextmonth", d.parentNode).each(function() {
        if (g.dateAfterDays(e, 0, 1, true) > f) {
            $(this).addClass("disabled")
        } else {
            $(this).removeClass("disabled")
        }
    });
    $(".prevmonth", d.parentNode).each(function() {
        if (g.dateAfterDays(e, 0, -1, true) < g.tomorrow) {
            $(this).addClass("disabled")
        } else {
            $(this).removeClass("disabled")
        }
    });
    g.selectOption($("select", d.parentNode), e.getFullYear() + "-" + (e.getMonth() + 1))
},rebuildDaySelect:function(e, c) {
    var j = "&nbsp;";
    if (c) {
        var l = this.till.month;
        var m = this.till.year;
        var g = this.till.day;
        if (g == null) {
            j = '<option style="text-transform:capitalize;" value="0">' + booking.env.day + "</option>"
        }
    } else {
        var l = this.from.month;
        var m = this.from.year;
        var g = this.from.day;
        if (g == null) {
            j = '<option style="text-transform:capitalize;" value="0">' + booking.env.day + "</option>"
        }
    }
    $(e).html(j);
    var n = this.getDaysInMonth(l, m);
    for (var h = 1; h <= n; h++) {
        var d = new Date(m + "/" + l + "/" + h + " 00:00:00");
        var f = (d.getDay() > 0) ? d.getDay() - 1 : 6;
        var k = booking.env.b_simple_weekdays_for_js[f] + " " + h;
        if (booking.env.b_site_experiment_calendar_new_selectbox_switch_weekday) {
            k = h + " " + booking.env.b_simple_weekdays_for_js[f]
        }
        $(e).append('<option value="' + h + '"' + ((g == h) ? ' selected="selected"' : "") + ">" + k + "</option>")
    }
},rebuildCalendarTable:function(j, d, k, l) {
    if (j.parentNode.style.display != "none") {
        var m = parseInt(new Date(l + "/" + k + "/1").getDay()) - 2;
        if (m < 0) {
            m = 7 + m
        }
        for (var g = 0; g < 42; g++) {
            var f = g - m;
            var c = $("tr td", j).get(g);
            if (f > 0 && f <= this.getDaysInMonth(k, l)) {
                var e = new Date(l + "/" + k + "/" + f + " 00:00:00");
                if (e < this.today || (d && e < this.tomorrow) || e > this.endOfYear1 || (!d && e > this.endOfYear2)) {
                    if (e - this.today == 0) {
                        $(c).html('<span class="today">' + f + "</span>")
                    } else {
                        $(c).html("<span>" + f + "</span>")
                    }
                } else {
                    var h = "";
                    if (e - this.today == 0) {
                        h = "today"
                    }
                    if (e - this.till.date == 0) {
                        h += d ? " selected" : " endsel"
                    }
                    if (e - this.from.date == 0) {
                        h += d ? " endsel" : " selected"
                    }
                    if (e < this.till.date && e > this.from.date) {
                        h += " inbetween"
                    }
                    $(c).html('<a href="#" class="' + h + '">' + f + "</a>")
                }
            } else {
                $(c).html("&nbsp;")
            }
        }
        this.updatePrevNextLinks(true, j)
    }
},noHourDate:function(d) {
    if (typeof d == "undefined") {
        var c = (this.userServDate) ? new Date(this.syncDate) : new Date()
    } else {
        if (d == null) {
            var c = (this.userServDate) ? new Date(this.syncDate) : new Date()
        } else {
            var c = d
        }
    }
    c.setHours(0);
    c.setMilliseconds(0);
    c.setMinutes(0);
    c.setSeconds(0);
    return c
},getDaysInMonth:function(d, e) {
    var c = 31;
    if (d == 4 || d == 6 || d == 9 || d == 11) {
        c = 30
    } else {
        if (d == 2) {
            if (((e % 4) == 0) && ((e % 100) != 0) || ((e % 400) == 0)) {
                c = 29
            } else {
                c = 28
            }
        }
    }
    return(c)
},selectOption:function(e, h, d) {
    var c = false;
    var g = $("option", e);
    for (var f = 0; f < g.length; f++) {
        if (h && h != "") {
            if ($(g[f]).val() == h) {
                g[f].selected = true;
                c = true
            } else {
                g[f].selected = false
            }
        }
        if (d && d != "") {
            if ($(g[f]).text() == h) {
                g[f].selected = true;
                c = true
            } else {
                g[f].selected = false
            }
        }
    }
    return c
},dateAfterDays:function(m, g, j, l) {
    var c = this.oneDayInMS * g;
    var h = 12;
    if (l) {
        m.setDate(1)
    }
    if (j) {
        var d = this.noHourDate(m);
        if (j > h || j < -1 * h) {
            m.setFullYear(m.getFullYear() + parseInt(j / h));
            j = j % h
        }
        if (j != 0) {
            var e = m.getMonth();
            if (e + j > h) {
                m.setFullYear(m.getFullYear() + 1);
                m.setMonth((e + j) - h)
            } else {
                if (e + j < 0) {
                    m.setFullYear(m.getFullYear() - 1);
                    m.setMonth((e + j) + h)
                } else {
                    m.setMonth(e + j)
                }
            }
        }
    }
    var f = new Date((this.noHourDate(m) * 1) + c);
    if (m.getTimezoneOffset() != f.getTimezoneOffset()) {
        var k = m.getTimezoneOffset() - f.getTimezoneOffset();
        k = ((k < 0) ? ~k + 1 : k) * 60 * 1000;
        if (k > 0) {
            f = new Date((this.noHourDate(m) * 1) + c + k)
        }
    }
    return f
},openPopupCalendar:function(k) {
    var m = $("#calendar_popup").get(0);
    var g = "";
    switch (k.nodeName.toLowerCase()) {case"a":g = k.href.split("#")[1];break;case"input":g = k.name;break;case"select":g = k.name;break;default:break
    }
    var c = Number((booking.env.b_site_experiment_calendar_with_input) ? $(k).outerHeight() : 0);
    var l = 10 + c;
    var j = $(k).offset().top + l;
    var h = $(k).offset().left;
    if (booking.env.rtl) {
        h = h - 211
    }
    var d = $(window).height();
    var f = $(document).scrollTop();
    var e = $(window).width();
    if (e < h + 230) {
        if (e - 230 > 0) {
            h = e - 230
        }
    }
    if (d + f < j + 230) {
        if (j - f - 250 > 0) {
            j = j - 250 - c
        } else {
            j = d + f - 250
        }
    }
    $("#calendar_popup").css({top:j + "px",left:h + "px"}).show();
    if (this.calendarTypes[g] && this.calendarTypes[g].isTill) {
        $(m).addClass("calendarTill");
        this.rebuildCalendarTable($("table", m).get(0), true, this.viewDateTill.getMonth() + 1, this.viewDateTill.getFullYear())
    } else {
        $(m).removeClass("calendarTill");
        this.rebuildCalendarTable($("table", m).get(0), false, this.viewDateFrom.getMonth() + 1, this.viewDateFrom.getFullYear())
    }
    if (booking.env.b_site_experiment_improve_calendar_closing) {
        $("body").bind("close_calendar", this.closeHandler)
    }
},closeHandler:function() {
    booking[sNSStartupLoad].calendar.closePopupCalendar()
},closePopupCalendar:function() {
    $("#calendar_popup").removeClass("calendarTill").hide();
    if (booking.env.b_site_experiment_improve_calendar_closing) {
        $("body").unbind("close_calendar", this.closeHandler)
    }
}};
booking[sNSStartupLoad].change_dates = {priority:9,init:function() {
    if (typeof trigger_error_template_event_tracking != "undefined" && trigger_error_template_event_tracking === true) {
        booking.google.trackEvent(booking.google.pageviewTracker, "Error Template (Aggregate)", b_errors);
        if (b_this_referer != "") {
            booking.google.trackEvent(booking.google.pageviewTracker, "Error Template (Referrer)", b_this_referer + " - " + b_errors)
        }
        booking.google.trackEvent(booking.google.pageviewTracker, "Error Template (RequestURL)", b_this_url + " - " + b_errors)
    }
    if (booking.env.b_page = "send_change_dates") {
        $("#message_changing-dates").fadeIn();
        $("#change_dates").submit(function() {
            var e = $("input[name=do]");
            var c = $("#change_dates input[name=checkin_date]").val();
            var d = $("#change_dates input[name=checkout_date]").val();
            if (c.length > 0 || d.length > 0) {
                cin_yymm = $("#checkin_year_month").val();
                cin_dd = $("#checkin_day").val();
                cin_yymmdd = cin_yymm + "-" + cin_dd;
                cout_yymm = $("#checkout_year_month").val();
                cout_dd = $("#checkout_monthday").val();
                cout_yymmdd = cout_yymm + "-" + cout_dd;
                a = c.replace(/-0/g, "-");
                b = d.replace(/-0/g, "-");
                if (a != cin_yymmdd || b != cout_yymmdd) {
                    e.val("dochangedates")
                }
            }
        })
    }
}};
function switchDateStack(c, e) {
    var d = c;
    if ($(c).parents("div").length) {
        d = $(c).parents("div").get(0)
    }
    var f = 0;
    while (d) {
        if (d.nodeName.toLowerCase() == "div") {
            f++;
            if (f == e) {
                d.style.display = "block"
            } else {
                if (!booking.env.b_site_experiment_do_not_hide_availablity) {
                    d.style.display = "none"
                }
            }
        }
        d = d.nextSibling
    }
}
function switchDateFlashDeal(c, d) {
    if (!booking.env.b_site_experiment_new_change_dates_hp) {
        $("div#editDates").css("display", "block");
        $("div#available_rooms_header1").css("display", "none")
    }
}
booking[sNSStartup].validatedate = {priority:9,init:function() {
    $("#frm, #hotelpage_availform").submit(function() {
        return booking[sNSStartup].validatedate.validate(this)
    })
},validate:function(oForm) {
    var sError = "";
    var today = new Date();
    var sErrorIsNeedDates = false;
    if (booking.env.b_site_experiment_fix_user_dates) {
        var checkUserDate = booking.env.b_current_datetime;
        syncDate = checkUserDate.replace(/-/gi, "/");
        var checkTomorrow = new Date(syncDate);
        checkTomorrow.setDate(checkTomorrow.getDate() + 1);
        if (checkTomorrow < today) {
            today = new Date(syncDate)
        } else {
            var checkYesterday = new Date(syncDate);
            checkYesterday.setDate(checkYesterday.getDate() - 1);
            if (checkTomorrow > today) {
                today = new Date(syncDate)
            }
        }
    }
    today.setHours("0");
    today.setMinutes("0");
    today.setSeconds("0");
    today.setMilliseconds("0");
    if ($("select[name=checkin_monthday]", oForm).length && $("select[name=checkin_year_month]", oForm).length && $("select[name=checkout_monthday]", oForm).length && $("select[name=checkout_year_month]", oForm).length) {
        if ($("#availcheck:checked", oForm).length) {
            return true
        }
        var oCheckinD = $("select[name=checkin_monthday]", oForm).get(0);
        var oCheckinYM = $("select[name=checkin_year_month]", oForm).get(0);
        var oCheckoutD = $("select[name=checkout_monthday]", oForm).get(0);
        var oCheckoutYM = $("select[name=checkout_year_month]", oForm).get(0);
        var checkinYM = $(oCheckinYM).val();
        var checkinD = parseInt($(oCheckinD).val());
        var checkoutYM = $(oCheckoutYM).val();
        var checkoutD = parseInt($(oCheckoutD).val());
        if ((typeof checkinYM != "undefined")) {
            var checkinY = checkinYM.split("-")[0];
            var checkoutY = checkoutYM.split("-")[0];
            var checkinM = parseInt(checkinYM.split("-")[1]);
            var checkoutM = parseInt(checkoutYM.split("-")[1]);
            var checkin = new Date(checkinY, checkinM - 1, checkinD);
            var checkout = new Date(checkoutY, checkoutM - 1, checkoutD);
            if (checkinYM == "0" || checkinD == "0") {
                if (checkoutYM == "0" || checkoutD == "0") {
                    sError = booking.env.to_check_availability_please_enter_your_dates_of_stay;
                    if (booking.env.b_site_experiment_remove_no_dates_box) {
                        sError += ' <a href="#" id="swd">' + booking.env.click_here_to_search_without_dates + "</a>"
                    }
                    sErrorIsNeedDates = true
                } else {
                    sError = booking.env.please_enter_your_check_in_date
                }
            } else {
                if (checkoutYM == "0" || checkoutD == 0) {
                    sError = booking.env.please_enter_your_check_out_date
                } else {
                    if ((checkinY > checkoutY) || ((checkinY == checkoutY) && (eval(checkinYM) < eval(checkoutYM))) || ((checkinYM == checkoutYM) && (checkinD > checkoutD))) {
                        sError = booking.env.error.checkout_date_not_after_checkin_date.name
                    }
                }
            }
            if (sError == "" && (booking.env.b_site_experiment_add_js_validation)) {
                if (checkin.getTime() < today.getTime() && !(checkin.getTime() > today.getTime() - 86400005 && booking.env.b_site_experiment_fix_timezone_error)) {
                    sError = booking.env.error.checkin_date_in_the_past.name
                } else {
                    if ((checkout - checkin) / 86400000 > 30) {
                        sError = booking.env.error.checkout_date_more_than_30_days_after_checkin.name
                    } else {
                        if (checkin > checkout) {
                            sError = booking.env.error.checkout_date_not_after_checkin_date.name
                        }
                    }
                }
            }
        }
    }
    if (sError != "") {
        if ($(".dateerrors", oForm).length) {
            var errorField = $(".dateerrors", oForm).get(0);
            if (sErrorIsNeedDates) {
                $("#inout select").change(function() {
                    $("#friendly_error_popup").remove()
                });
                $(".calendar").click(function() {
                    $("#friendly_error_popup").remove()
                });
                $("#friendly_error_popup span.close_errormsg").live("click", function() {
                    $("#friendly_error_popup").remove()
                });
                $("#inout .avail, .toggle_overview, .toggle_review").live("click", function() {
                    $("#friendly_error_popup").remove()
                });
                if ($("#friendly_error_popup").length == 0) {
                    var last_dropdown_searchbox = $("#inout select").eq(3);
                    if (booking.env.b_action == "hotel" || booking.env.b_action == "searchresults") {
                        last_dropdown_searchbox = $(".leftsmall #inout select").eq(1)
                    }
                    if (booking.env.b_site_experiment_calendar_with_input) {
                        last_dropdown_searchbox = $("#inout input.check_date").eq(1)
                    }
                    var last_dropdown_offset = last_dropdown_searchbox.offset();
                    var last_dropdown_hotelpage = $("#hotelpage_availform select").eq(3);
                    if (booking.env.b_site_experiment_calendar_with_input) {
                        last_dropdown_hotelpage = $("#hotelpage_availform input.check_date").eq(1)
                    }
                    if (booking.env.nodates_popup_up) {
                        last_dropdown_hotelpage = $("#hotelpage_availform select").eq(0)
                    }
                    var last_dropdown_hotelpage_offset = last_dropdown_hotelpage.offset();
                    var first_dropdown_searchbox = $("#inout select").eq(0);
                    var first_dropdown_offset = last_dropdown_searchbox.offset();
                    if (booking.env.b_lang == "ar") {
                        var errorHTML = '<div id="friendly_error_popup" style="top:' + (first_dropdown_offset.top - 20) + "px;left:" + (first_dropdown_offset.left - 260) + 'px;"><div class="wrapper"><span class="close_errormsg"></span><p>' + booking.env.view_prices_enter_dates + "</p></div></div>";
                        $(document.body).append(errorHTML)
                    } else {
                        if (oForm.id == "hotelpage_availform") {
                            console.info(booking.env.nodates_popup_up);
                            if (booking.env.nodates_popup_up) {
                                var errorHTML = '<div id="friendly_error_popup" class="hotelpage new_change_dates" style="top:' + (last_dropdown_hotelpage_offset.top - 90) + "px;left:" + (last_dropdown_hotelpage_offset.left - 150) + 'px;"><div class="wrapper"><span class="close_errormsg"></span><p>' + booking.env.view_prices_enter_dates + "</p></div></div>"
                            } else {
                                var errorHTML = '<div id="friendly_error_popup" class="hotelpage" style="top:' + (last_dropdown_hotelpage_offset.top - 20) + "px;left:" + (last_dropdown_hotelpage_offset.left + last_dropdown_hotelpage.width() + 10) + 'px;"><div class="wrapper"><span class="close_errormsg"></span><p>' + booking.env.view_prices_enter_dates + "</p></div></div>"
                            }
                        } else {
                            var errorHTML = '<div id="friendly_error_popup" style="top:' + (last_dropdown_offset.top - 20) + "px;left:" + (last_dropdown_offset.left + last_dropdown_searchbox.width() + 10) + 'px;"><div class="wrapper"><span class="close_errormsg"></span><p>' + booking.env.view_prices_enter_dates + "</p></div></div>"
                        }
                        $(document.body).append(errorHTML)
                    }
                }
            } else {
                var errorHTML = '<span class="exclamation exclamation_daterrrors">&nbsp;</span><p class="error_dates errors_dateerros">' + sError + "</p>";
                errorField.innerHTML = errorHTML;
                errorField.style.display = "block"
            }
            $("#swd").click(function() {
                document.getElementById("availcheck").checked = "checked";
                document.getElementById("frm").submit();
                return false
            });
            return false
        } else {
            return true
        }
    } else {
        return true
    }
}};
function noDatesPopup(c) {
    if (document.getElementById("checkin_day").value == 0 || document.getElementById("checkin_year_month").value == 0 || document.getElementById("checkout_monthday").value == 0 || document.getElementById("checkout_year_month").value == 0) {
        document.location = document.location + "#top";
        alert(c)
    } else {
        document.getElementById("availcheck").checked = false;
        document.getElementById("frm").submit()
    }
}
var $_dot_or_comma = {USD:".",EUR:",",BRL:",",CAN:",",RUB:","};
var $_decimal_by_lang = {ca:$_dot_or_comma,cs:$_dot_or_comma,da:$_dot_or_comma,de:$_dot_or_comma,el:$_dot_or_comma,en:{},es:$_dot_or_comma,es_us:{},es_mx:{},fi:$_dot_or_comma,fr:$_dot_or_comma,hu:$_dot_or_comma,it:$_dot_or_comma,ja:{},nl:$_dot_or_comma,no:$_dot_or_comma,pt:$_dot_or_comma,pl:$_dot_or_comma,ro:$_dot_or_comma,ru:$_dot_or_comma,sv:$_dot_or_comma,tr:$_dot_or_comma,zh:{}};
var lang,currency,country;










$(function() {
    lang = $("html").attr("lang");
    currency = $("#currList").val();
    country = $("meta[name=country]").attr("content");
    $(".bookExtra").show();
    $("select.number_guests").change(function() {
        var h = $(this);
        var f = h.val();
        if (booking.env.b_site_experiment_one_page_bookprocess) {
            var g = h.parents(".room_item").find(".addon")
        } else {
            var g = h.parents("table:first").find(".addon")
        }
        var j;
        g.each(function() {
            var t = $(this);
            var o = t.find(".number_guests");
            o.html(f);
            var k = o.length ? f : 1;
            var r = t.find(".price_per_unit");
            var m = r.attr("price");
            var u = r.attr("price_hotel");
            var l = t.find("span.addon_price");
            var v = t.find(".number_nights").text() || r.attr("nights") || 1;
            var n = t.find("span.addon_price");
            var q = ((m > 0) ? m : u) * v * k;
            n.html(n.attr("currency") + format_price(q));
            n.attr("price", q);
            n.attr("price_hotel", format_price(u * v * k))
        });
        show_addons_cost();
        update_persons_count()
    });
    $("tr.dropdowns td select").change(function() {
        var l = $(this);
        var g = $(this).parents("tr.dropdowns").find(".price_per_unit");
        var j = l.find("option:selected").text();
        var k = g.attr("nights");
        var m = g.attr("price");
        var f = g.attr("price_hotel");
        var h = ((m > 0) ? m : f) * k * j;
        l.attr("price", h);
        l.attr("price_hotel", format_price(f * k * j));
        show_addons_cost()
    });
    
    $(".extrabed").click(function() {
        $("select.number_guests").trigger("change")
    });
    $("input:checkbox[name^=insurance]").click(function() {
        var k = 1 * ($("#cost_with_addons").attr("tc") || 0);
        var f = 1 * (this.checked ? ($("#insurance_cost").attr("price") || 0) : 0);
        var j = $("#selected_currency_symbol").text();
        $("#cost_with_addons").html(format_price(k + f));
        if (j) {
            var h = 1 * $("#s_cost_with_addons").attr("tc");
            var g = 1 * (this.checked ? ($("#s_insurance_cost").attr("price") || 0) : 0);
            $("#s_cost_with_addons").html(format_price(h + g))
        }
        if (this.checked) {
            $("#insurance_div").show();
            $(".ovTotalCost").show()
        } else {
            $("#insurance_div").hide()
        }
    });




var e = {nl:1,dk:1,fi:1,se:1,de:1,it:1,ch:1,pt:1,at:1,es:1,de:1,fr:1,ie:1,be:1,cy:1,cz:1,ee:1,hu:1,gr:1,lv:1,lt:1,lu:1,no:1,pl:1,sk:1,ro:1};
    $("select[name=cc1]").change(function() {
        var f = $(this).val();
        if (e[f] == 1) {
            $("#insurance_wrapper").show();
            $("input:checkbox[name^=insurance]").removeAttr("disabled")
        } else {
            $("#insurance_wrapper").hide();
            $("input:checkbox[name^=insurance]").attr("disabled", "disabled")
        }
    });
    $("tr.dropdowns .totPrice select").trigger("change");
    var c = $("input:checkbox[name^=addon]:checked").length;
    var d = $(".dropdowns select .notnull:selected").length;
    if (c || d) {
        show_addons_cost()
    }
    if (e[$("select[name=cc1] option:selected").val()] == 1) {
        $("#insurance_wrapper").show();
        $("input:checkbox[name^=insurance]").removeAttr("disabled")
    }
});






























