$(function () {
var isChrome = /Chrome\//.test(navigator.userAgent),
ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent),
mac = ios || /Mac/.test(navigator.platform);
if (isChrome && mac) {
$('html').addClass('mac');
}
});
function sendContactEmail(aid, cs2){
mailed = $("#" + aid ).find('input[name="mailed"]').val();
if(mailed<1){
name = $("#" + aid ).find('input[name="BookingForm[clientName]"]').val();
email = $("#" + aid ).find('input[name="BookingForm[email]"]').val();
phone = $("#" + aid ).find('input[name="BookingForm[phone]"]').val();
exDate = $(".booking-form_date_n").val();
total = $("#total-price" + aid).html() + " " + $("#people_text_desc" + aid).html();
travelId = 0;
from = 0;
to = 0;
exType = aid;
if($("#form" + aid ).attr("code")!==undefined){
travelId = $("#form" + aid ).attr("code");
from = $("#transferFrom").attr("auditid");
to = $("#transferTo").attr("auditid");
}
console.log("name :" + name + " email :" + email + " phone :" + phone + "exId : " + cs2 + " exDate :" + exDate + " total :" + total + " exType :" + exType + "travelId : " + travelId);
patt = /^.+@.+[.].{2,}$/i;
if(name.length>1 && patt.test(email) && phone.length>4){
$("#" + aid ).find('input[name="mailed"]').val(1);
if(yaCounter12449020 !== undefined){
yaCounter12449020.reachGoal('Button_goon');
ga('send', 'event', 'user', 'order goon', aid);
}
$.post( "/excursions/book/sendclient", { name : name, email : email, phone : phone, exId : cs2, exDate : exDate, total : total, exType : exType, transferId : travelId, from : from, to : to} );
}
}else{
console.log('allready mailed');
}
}
// $(function () {
// if($.masksSort)
// {
// var maskList = $.masksSort($.masksLoad("/redesign/scripts/json/phone-codes.json"), ['#'], /[0-9]|#/, "mask");
// var maskOpts = {
// inputmask: {
// definitions: {
// '#': {
// validator: "[0-9]",
// cardinality: 1
// }
// },
// showMaskOnHover: false,
// autoUnmask: true
// },
// match: /[0-9]/,
// replace: '#',
// list: maskList,
// listKey: "mask",
// onMaskChange: function (maskObj, completed) {
// $(this).attr("placeholder", $(this).inputmask("getemptymask"));
// }
// };
// $('form.bookform input[name="BookingForm[phone]"]').each(function () {
// $(this).inputmasks(maskOpts);
// })
// }
// });
var searchCalendarKey;
$(function () {
'use strict';
var isMapInitialized = false;
var DateBtnSelectIndex = null;
var searchDataKey;
var dateStart = '';
slider();
reviews(20000);
$('.tours__morebtn.allcity').click(function(){
$('.tours__city-item').show();
$(this).hide();
});
$('.tours__datepicker').datepicker({
numberOfMonths: 3,
stepMonths: 3,
minDate: 0,
dateFormat: 'd MM',
beforeShowDay: function (date) {
for (var i = 0; i < specificDates.length; i++) {
if (new Date(specificDates[i]).toString() == date.toString()) {
return [true, 'ui-datepicker-current-day minigroup '];
}
}
return [false, ''];
},
onSelect: function (dateText, inst) {
var zero = ['00', '0', ''];
window.location.href = window.location.origin +
window.location.pathname +
"?date=" + inst.currentYear +
"-" + zero[(inst.currentMonth + '').length] + (inst.currentMonth + 1) +
"-" + zero[(inst.currentDay + '').length] + inst.currentDay;
}
});
function onPriceItemCloseBtnClick() {
var $btn = $(this),
$container = $btn.closest('.maincolumn__price__item ');
$btn.hide();
$container.find('form').hide();
$container.find('.maincolumn__price__item-errorsblock').hide();
$container.find('.maincolumn__price__item-good').hide();
$container.find('.maincolumn__price__item-btn').show();
$container.find('.maincolumn__price__item-btn').css("display", "inline-block")
$('.maincolumn__price__item_selected').removeClass('maincolumn__price__item_selected');
$container.find('.maincolumn__price__item-outline').removeClass('maincolumn__price__item-success').show();
// Проверка на трансфер
$container.find('.cartype').hide();
$container.find('.direction').hide();
$container.find('.price_transport').show();
$container.find('.excursion_sticker').show();
$container.find('.cartype .excursion_sticker').hide();
$(".maincolumn__price__item").css({opacity: 1});
}
$('.maincolumn__price__item-closebtn').on('click', onPriceItemCloseBtnClick);
function onCouponBtnClick(){
var
form = $(this).closest('form'),
coupon_code = $(form).find("#BookingForm_code_coupon").val(),
activityId = $(this).closest('.maincolumn__price__item').find('form').attr('id'),
cs2 = $("#BookingForm_cs2").val(),
amountType = form.find("input[name=\"BookingForm[amountType]\"]").filter(":checked");
if(!amountType.val()){
var amountType = form.find("input[name=\"BookingForm[amountType]\"]");
}
$.post("/excursions/book/getamount",
{
amount: amountType.val(),
cs2: cs2,
activityId: activityId,
dateStart: $("#BookingForm_date_n").val(),
starttime: $(this).closest( "form" ).find("#BookingForm_starttime").val(),
mature: $(this).closest( "form" ).find("#BookingForm_mature").val(),
child: $(this).closest( "form" ).find("#BookingForm_child").val(),
coupon_code: $(this).closest( "form" ).find("#BookingForm_code_coupon").val(),
transferId : $(this).closest( "form" ).find("#BookingForm_transferId").val(),
innerTransferId: $(this).closest( "form" ).find("#BookingForm_innerTransferId").val(),
}
, function(data){
if(data.activityId && data.price){
data.amountPrice = data.amountPrice ? data.amountPrice : data.price;
if(data.goPay){
//var btnText = parseInt(data.amountPrice) > 0 ? "Забронировать и оплатить " + data.amountPrice + " " + data.currency : "Забронировать";
var btnText = parseInt(data.amountPrice) > 0 ? "Перейти к оплате" : "Забронировать";
//diff = data.price.replace(" ","")-data.amountPrice.replace(" ","");
diff = data.diff;
if((diff) > 0){
$("." + data.activityId + " .maincolumn__price__item__paydiff .topay").html(diff + " " + data.currency);
$("." + data.activityId + " .maincolumn__price__item__paydiff").show();
}else{
$("." + data.activityId + " .maincolumn__price__item__paydiff").hide();
}
}else{
var btnText = "Отправить заявку";
}
$("#" + data.activityId + "_item-inputblock-btn").val(btnText);
if(data.coupon_text!=""){
$("#" + data.activityId + "coupon_text").html("
" + data.coupon_text);
$("#" + data.activityId + "coupon_text").show();
}else{
$("#" + data.activityId + "coupon_text").hide();
$("#" + data.activityId + "coupon_text").html("");
}
}
}, 'json');
}
$(".code_coupon-btn").on('click', onCouponBtnClick);
function onPriceItemDateClick() {
var activityId = $(this).closest('.maincolumn__price__item').find('form').attr('id'),
datePicker = '#d'+activityId;
$(datePicker).prependTo('#'+activityId+' .selected-date').datepicker('show');
}
function onTransferItemDateClick() {
var activityId = $(this).closest('.maincolumn__price__item').find('form').attr('id'),
datePicker = '#dt'+activityId;
Calendar = []; //TODO сгенерить доступные даты
$(datePicker).prependTo('#'+activityId+' .selected-date-go').datepicker('show');
Calendar = [];
}
$('.maincolumn__price__item-date .selected-date').on('click', onPriceItemDateClick);
$('.maincolumn__price__item-date .selected-date-go').on('click', onTransferItemDateClick);
function onPaginationLinkClick() {
var $pageBtn = $(this),
pageNum = $pageBtn.data('page-num'),
$container = $pageBtn.closest('[data-tabs]'),
$tabPage = $container.find('[data-page=' + pageNum + ']');
if (!$tabPage) return;
$container.find('[data-page]').hide();
$tabPage.show();
$pageBtn.closest('.pagination').find('.pagination__link').removeClass('pagination__link_current');
$pageBtn.addClass('pagination__link_current');
}
$("#create-mini-group-link").click(function () {
$('.maincolumn__price-datepicker').datepicker("setDate", new Date($(this).data("year"), $(this).data("month"), $(this).data("day")));
$('.ui-datepicker-current-day').click();
$(this).closest(".maincolumn__price__item").find(".maincolumn__price__item-btn").click();
});
$('.pagination').on('click', '.pagination__link', onPaginationLinkClick);
function preSelectDatepicker(dateText, inst){
var activityId = $(this).attr('data-activity'),
//btn = $('.'+activityId).find('.ui-datepicker-trigger'),
label = $('.'+activityId).find('.selected-date div');
dateStart = zero[(inst.selectedDay + '').length] + inst.selectedDay + '.' + zero[(inst.selectedMonth + 1 + '').length] + (inst.selectedMonth + 1) + '.' + inst.selectedYear;
var dateInputs = $('.booking-form_date_n');
if (dateInputs.length > 0) {
dateInputs.val(dateStart);
}
var currentDate = new Date(inst.currentYear, inst.currentMonth, inst.currentDay),
hoursDiff = Math.ceil((currentDate.getTime() - dateTime.getTime()) / (1000 * 60 * 60));
prepareForms(dateText, inst);
$('.ui-datepicker-trigger').addClass('ui-datepicker-trigger_selected');
formatDatepickerOutput(label, dateText);
if(yaCounter12449020 !== undefined){
yaCounter12449020.reachGoal('Calendar_date_tr');
ga('send', 'event', 'user', 'calendar topright', dateStart);
}
console.log(dateStart);
setTimeout(setReservedDates, 50);
}
function selectDatepicker(dateText, inst)
{
var activityId = $(this).attr('data-activity'),
//btn = $('.'+activityId).find('.ui-datepicker-trigger'),
label = $('.'+activityId).find('.selected-date div'),
labelTransfer = $('.'+activityId).find('.selected-date-go div'),
isTransfer = 0;
if(inst["id"].indexOf("dt")>-1){
isTransfer = 1;
label = $('.'+activityId).find('.selected-date-go div');
}
console.log(inst.id);
dateStart = zero[(inst.selectedDay + '').length] + inst.selectedDay + '.' + zero[(inst.selectedMonth + 1 + '').length] + (inst.selectedMonth + 1) + '.' + inst.selectedYear;
var dateInputs = $('.booking-form_date_n' + ((isTransfer)?"_go":""));
if (dateInputs.length > 0) {
dateInputs.val(dateStart);
if(!isTransfer){
$('.booking-form_date_n_go').val(dateStart);
}
}
var currentDate = new Date(inst.currentYear, inst.currentMonth, inst.currentDay),
hoursDiff = Math.ceil((currentDate.getTime() - dateTime.getTime()) / (1000 * 60 * 60));
prepareForms(dateText, inst);
$('.ui-datepicker-trigger').addClass('ui-datepicker-trigger_selected');
formatDatepickerOutput(label, dateText);
if(!isTransfer){
formatDatepickerOutput(labelTransfer, dateText);
}
/*$(".maincolumn__price__item").each(function (key, obj) {
if (!$(this).hasClass('_miniGroupConnect') && !$(this).hasClass('_miniGroupAdd') && hoursDiff >= parseInt(noholdhours)) {
showOrderFormBtn(this);
} else {
hideOrderFormBtn(this);
if (($(this).hasClass('_miniGroupConnect') && GroupsObj[searchDataKey] == undefined) ||
($(this).hasClass('_miniGroupAdd') && searchDataKey < GroupStart)
) {
hideOrderFormBtn(this);
} else {
showOrderFormBtn(this);
}
}
var btn = $(object).find('.ui-datepicker-trigger');
if( key == DateBtnSelectIndex && !btn.hasClass('hidden') ){
btn.click();
}
});
DateBtnSelectIndex = null;*/
openForm(activityId);
}
$("#order .maincolumn__price-datepicker").each(function () {
var activity = $(this).attr('data-activity'),
curentDate = new Date();
if(activity == '_miniGroupConnect')
{
$(this).datepicker({
constrainInput: false,
numberOfMonths: 2,
dateFormat: 'd MM',
minDate: 0,
beforeShowDay: beforeShowDay,
beforeShow: function(input, inst) {
setTimeout(setMiniGroups, 50);
},
onChangeMonthYear: function () {
setTimeout(setMiniGroups, 50);
},
onClose: onClose,
onSelect: selectDatepicker
});
}
else if(activity == '_miniGroupAdd')
{
$(this).datepicker({
constrainInput: false,
numberOfMonths: 2,
dateFormat: 'd MM',
minDate: new Date(curentDate.getFullYear(), curentDate.getMonth()+1, curentDate.getDate()),
beforeShowDay: beforeShowDay,
beforeShow: function(input, inst) {
setTimeout(setAvailableGroups, 50);
},
onChangeMonthYear: function () {
setTimeout(setAvailableGroups, 50);
},
onClose: onClose,
onSelect: selectDatepicker
});
}
else
{
$(this).datepicker({
constrainInput: false,
numberOfMonths: 2,
dateFormat: 'd MM',
minDate: 0,
beforeShowDay: beforeShowDay,
beforeShow: function(input, inst) {
var a = $(this).attr("id");
setTimeout(function(){setReservedDates(a)}, 50);
},
onChangeMonthYear: function () {
var a = $(this).attr("id");
setTimeout(function(){setReservedDates(a)}, 50);
},
onClose: onClose,
onSelect: selectDatepicker
});
}
});
function onClose(evt, ui)
{
$('.ui-datepicker-trigger').removeClass('ui-datepicker-trigger_pressed').prop('disabled', false);
$('.maincolumn__price__item').css({opacity: 1});
}
function beforeShowDay(date)
{
var hoursDiff = Math.ceil((date.getTime() - dateTime.getTime()) / (1000 * 60 * 60)),
y = date.getFullYear();
var activity = $(this).attr('data-activity');
if(activity == '_miniGroupConnect')
{
var m = /*zero[(date.getMonth() + '').length] +*/ (date.getMonth() + 1),
d = /*zero[(date.getDate() + '').length] +*/ date.getDate(),
groupKey = y + '-' + m + '-' + d;
if (Object.keys(GroupsObj).length && GroupsObj[groupKey]) {
return [true, ''];
}
else
{
return [false, ''];
}
}
else
{
var m = zero[(date.getMonth() + 1 + '').length] + (date.getMonth() + 1),
d = zero[(date.getDate() + '').length] + date.getDate(),
calendarKey = y + m + d;
if (Object.keys(Calendar).length && Calendar[calendarKey] === undefined || hoursDiff < parseInt(noholdhours)) {
return [false, ''];
}
return [true, ''];
}
}
function showOrderFormBtn(activity, show) {
$(activity).find('.maincolumn__price__item-date').addClass('hidden');
$(activity).find('.maincolumn__price__item-btn').removeClass('hidden');
$(activity).find('.maincolumn__price__item-desc.nearestDate').addClass('hidden');
}
function hideOrderFormBtn(activity, show) {
$(activity).find(".maincolumn__price__item-closebtn").click();
$(activity).find('form select').html('');
$(activity).find('.maincolumn__price__item-date').removeClass('hidden');
$(activity).find('.maincolumn__price__item-btn').addClass('hidden');
$(activity).find('.maincolumn__price__item-desc.nearestDate').removeClass('hidden');
}
function findConnectPriceGroup(Activity, selectCountAll) {
var currentKey;
$.each(Activity, function (key, obj) {
if (obj.id === '_activity' &&
selectCountAll <= obj.max &&
selectCountAll >= obj.min) {
currentKey = key;
}
});
return currentKey !== undefined ? currentKey : findConnectPriceGroup(Activity, selectCountAll + 1);
}
function prepareForms(dateText, inst) {
searchDataKey = inst.selectedYear + '-' + (inst.selectedMonth + 1) + '-' + inst.selectedDay;
searchCalendarKey = inst.selectedYear + zero[(inst.selectedMonth + 1 + '').length] + (inst.selectedMonth + 1) + zero[(inst.selectedDay + '').length] + inst.selectedDay;
}
function setMiniGroups() {
if (GroupsObj) {
$("#ui-datepicker-div [data-handler='selectDay']").each(function () {
var key = $(this).data('year') + '-' + ($(this).data('month') + 1) + '-' + $(this).find('a').text();
if (GroupsObj[key] !== undefined) {
$(this).addClass('greendate');
}
});
}
}
function setAvailableGroups()
{
setDates(1);
$('.ui-datepicker-row-break').html(groupAddCalendarLabel);
}
function setReservedDates(id)
{
setDates(0, id);
$('#ui-datepicker-div').prepend( "
Выберите дату проведения
" );
var h = $('.ui-datepicker-row-break').html();
if(h!=""){
$('.ui-datepicker-row-break').html('Обратите внимание: зеленым выделены даты, доступные для бронирования.');
}
}
function setDates(addMonth, div)
{
//alert(addMonth);
var zero = ['00', '0', ''];
//"#ui-datepicker-div"
$(".ui-datepicker-calendar [data-handler='selectDay']").each(function () {
var month = ($(this).data('month') + 1) + "";
var day = $(this).find('a').text();
var key = $(this).data('year') + zero[month.length] + month + zero[day.length] + day;
if (Calendar) {
if (Calendar[key] !== undefined) {
if (Calendar[key]['time']) {
$(this).addClass('greendate');
} else {
$(this).addClass('reddate');
}
}
}
if(blackout!==undefined){
if(blackout){
if(BlackoutList[div] !== undefined){
CalendarExclude = BlackoutList[div];
}else{
CalendarExclude = [];
}
}
}
if (CalendarExclude) {
$(this).addClass('greendate');
if (CalendarExclude[key] !== undefined) {
if (CalendarExclude[key]['time']["none"]) {
$(this).removeClass('greendate');
$(this).addClass('ui-datepicker-unselectable');
$(this).addClass('ui-state-disabled');
$(this).addClass('reddate');
}
}
}
});
}
$('.right__column__datepicker').datepicker({
numberOfMonths: 1,
dateFormat: 'd MM',
minDate: 0,
beforeShowDay: beforeShowDay,
beforeShow: function(input, inst) {
setTimeout(setReservedDates, 50);
},
onChangeMonthYear: function () {
setTimeout(setReservedDates, 50);
},
onClose: onClose,
onSelect: preSelectDatepicker
});
setReservedDates();
function formatDatepickerOutput(object, dateText) {
var input = dateText,
index = dateText.indexOf('ь'),
isMarch = !!~dateText.toLowerCase().indexOf('март'),
isMay = !!~dateText.toLowerCase().indexOf('май'),
isAugust = !!~dateText.toLowerCase().indexOf('август');
if (isMarch) {
input = dateText + 'а';
}
else if (isMay) {
input = dateText.slice(0, input.indexOf('й')) + 'я';
}
else if (isAugust) {
input = dateText + 'а';
} else if (~index) {
input = dateText.slice(0, index) + 'я';
}
else
{
input = dateText;
}
$(object).html(input);
}
$.datepicker.regional['ru'];
function openForm(activityId) {
$('.cartype').hide();
$('.direction').hide();
$('.price_transport').show();
$('.excursion_sticker').show();
$('.cartype .excursion_sticker').hide();
var $btn = $('.'+activityId).find('.maincolumn__price__item-btn'),
$btns = $('.maincolumn__price__item-btn'),
$container = $btn.closest('.maincolumn__price__item');
// Проверка на трансфер
$('.' + activityId).find('.cartype').show();
$('.' + activityId).find('.direction').show();
$('.' + activityId).find('.price_transport').hide();
$('.' + activityId).find('.excursion_sticker').hide();
$('.' + activityId).find('.cartype .excursion_sticker').show();
getBookingForm(dateStart, activityId);
$('.maincolumn__price__item-form').hide();
$('.maincolumn__price__item-success').removeClass('maincolumn__price__item-success');
$('.maincolumn__price__item-closebtn').hide();
$btn.closest('.maincolumn__price__item').find('.maincolumn__price__item-closebtn').show();
$('.maincolumn__price__item').removeClass('maincolumn__price__item_selected');
$container.addClass('maincolumn__price__item_selected');
$('.ui-datepicker-trigger').hide();
$('.maincolumn__price__item-good').hide();
$btn.closest('.maincolumn__price__item').find('.maincolumn__price__item-good').show();
$(".maincolumn__price__item").each(function () {
$(this).css({opacity: 1});
if (!$(this).hasClass("maincolumn__price__item_selected")) {
$(this).css({opacity: .3});
}
});
$('#order form').hide();
$btn.closest('.maincolumn__price__item').find('form').show();
$btns.show();
$btns.css("display", "inline-block")
$btn.hide();
if ($container.find('.maincolumn__price__item-successblock').is(':visible')) {
$container.find('.maincolumn__price__item-outline').addClass('maincolumn__price__item-success');
}
if ($("#travelpayoutsPixel").length > 0) {
var tpHref = $("#travelpayoutsPixel").attr('src');
tpHref = tpHref.replace("lead", "engaged");
$("#travelpayoutsPixel").attr('src', tpHref);
}
$("html, body").animate({
scrollTop: $('#'+activityId).offset().top-150 + "px"
}, {
duration: 500
});
if(yaCounter12449020 !== undefined){
yaCounter12449020.reachGoal('Client_go_book', yaGoalParams);
ga('send', 'event', 'user', 'order', activityId);
}
}
function onPriceItemBtnClick()
{
var activityId = $(this).closest('.maincolumn__price__item').find('form').attr('id');
var datePicker = '#d'+activityId;
$(datePicker).prependTo('.'+activityId+' .maincolumn__price__item-cost').datepicker('show');
if(activityId == '_miniGroupAdd')
{
$('.ui-datepicker-row-break').html(groupAddCalendarLabel);
}else{
$('.ui-datepicker-row-break').html(simpleAddCalendarLabel);
}
}
function onFastItemBtnClick(){
var dateInputs = $('.booking-form_date_n');
if (dateInputs.length > 0 && dateInputs.val()!="") {
//dateInputs.val(dateStart);
openForm("1_1");
}else{
$("html, body").animate({
scrollTop: $('#order').offset().top + "px"
}, {
duration: 500,
complete: function(){
//$("#d1_1").prependTo('.1_1 .maincolumn__price__item-cost').datepicker('show');
}
}
);
}
if(yaCounter12449020 !== undefined){
yaCounter12449020.reachGoal('Book_button_tr_new');
ga('send', 'event', 'user', 'order topright', dateInputs);
}
}
//$('.maincolumn__price__item-btn').on('click', onPriceItemBtnClick);
$('.rightcolumn__fastorder-btn').on('click', onFastItemBtnClick);
function onDatepickerBtnClick(e) {
var $btn = $(this);
$btn.prop('disabled', true);
$btn.addClass('ui-datepicker-trigger_pressed');
$('.maincolumn__price__item').css({opacity: .5});
setMiniGroups();
setReservedDates();
}
$('.ui-datepicker-trigger').on('click', onDatepickerBtnClick);
function onDropbodyClearClick() {
var $clearBtn = $(this),
$container = $clearBtn.closest('.tours__filter__dropbody'),
$checkboxes = $container.find('input[type=checkbox]');
$checkboxes.each(function (i, item) {
$(item).prop('checked', false);
});
var parentId = $("#" + $(this).attr('id')).parents('.filter_container').attr('id');
var filter = getFilter(parentId);
setFilter(filter);
checkFilter(parentId);
}
$('.tours__filter__dropbody-clear').on('click', onDropbodyClearClick);
function onDropbodyCloseClick() {
var $closeBtn = $(this),
$container = $closeBtn.closest('.tours__leftcolumn, .tours__wrapper'),
$containerItems = $container.find('.tours__tour, .tours__discount, .tours-more');
$closeBtn.closest('.tours__filter__dropbody').hide();
$closeBtn.closest('.tours__filter-dropdown').removeClass('tours__filter-dropdown-active');
$containerItems.css({opacity: 1});
}
$('#doFilter .tours__filter__dropbody-close').on('click', onDropbodyCloseClick);
function onBodyClick(e) {
var $container = $('.tours__leftcolumn, .tours__wrapper'),
$containerItems = $container.find('.tours__tour, .tours__discount, .tours-more'),
$target = $(e.target);
if ($target.is('.tours__filter-checkbox, .tours__filter-border')) return;
if ($target.closest('.tours__filter__dropbody').size()) return;
$('.tours__filter__dropbody').hide();
$('.tours__filter-dropdown').removeClass('tours__filter-dropdown-active');
$containerItems.css({opacity: 1});
}
$('body').on('click touchstart', onBodyClick);
function onFilterCheckboxClick() {
var $filter = $(this),
$container = $filter.closest('.tours__leftcolumn, .tours__wrapper'),
$containerItems = $container.find('.tours__tour, .tours__discount, .tours-more'),
$dropdown = $container.find('.tours__filter__dropbody');
if (!$filter.closest('.tours__filter-dropdown').data('dropdown-section')) return;
if ($filter.closest('.tours__filter-dropdown').hasClass('tours__filter-dropdown-active')) {
$filter.closest('.tours__filter-dropdown').find('.tours__filter__dropbody').hide();
$filter.closest('.tours__filter-dropdown').removeClass('tours__filter-dropdown-active');
$containerItems.css({opacity: 1});
return;
}
$filter.closest('.tours__filter-dropdown').addClass('tours__filter-dropdown-active');
$containerItems.css({opacity: .3});
$dropdown.show();
}
$('.tours__filter-checkbox').on('click', onFilterCheckboxClick);
$('.tours__discount__popup-body').on('click', '.tours__discount__popup-methodred', onPopupTabClick);
function onPopupTabClick() {
var $tab = $(this),
$popup = $tab.closest('.tours__discount__popup-body'),
$tabs = $popup.find('.tours__discount__popup-method'),
tabId = $tab.data('tab'),
tabSectionSelector = ['[data-tab-section="', tabId, '"]'].join(''),
tabSection = $popup.find(tabSectionSelector),
tabSections = $popup.find('[data-tab-section]');
$tabs.addClass('tours__discount__popup-methodred');
$tab.removeClass('tours__discount__popup-methodred');
tabSections.hide();
tabSection.show();
}
$('.tours__discount-img').on('click', onDiscountClick);
$('.tours__discount-link').on('click', onDiscountClickLink);
$('.tours__discount__popup-close').on('click', onDiscountCloseClick);
function onDiscountCloseClick(e) {
$('.tours__discount__popup').fadeOut();
}
function onDiscountClick() {
$(this).closest('.tours__discount').find('.tours__discount__popup').fadeIn('slow');
}
function onDiscountClickLink() {
$(this).closest('.maincolumn__price__item-leftwrap').find('.tours__discount__popup').fadeIn('slow');
}
function slider() {
$('.flexslider').flexslider({
animation: "fade",
controlNav: "thumbnails"
});
$('.flex-control-nav li').append('');
}
function reviews(speed) {
var $wrap = $('.header__reviews-wrap');
if ($wrap.length === 0) {
return;
}
var $slide = $('.header__reviews-slide'),
$items = $('.header__reviews-review'),
itemWidth = $('.header__reviews-review').outerWidth(true),
itemsCount = $('.header__reviews-review').length,
slideWidth = itemWidth * itemsCount,
currentPos = 0;
while (slideWidth <= window.screen.availWidth) {
$('.header__reviews-review').clone().appendTo('.header__reviews-slide');
slideWidth += slideWidth;
}
$items = $('.header__reviews-review');
speed = $items.length * speed;
$slide.width(slideWidth * 2);
$items.clone().appendTo('.header__reviews-slide');
var slideReviews = function () {
$slide.css('right', '0px');
" + container + "
$slide.animate({
right: slideWidth
}, speed, 'linear', slideReviews);
};
slideReviews();
}
$('#_miniGroupConnect .select-count, #_miniGroupAdd .select-count').change(function () {
var form = $(this).closest('form'),
selectMature = $(form).find('select[name="BookingForm[mature]"]'),
selectStart = $(form).find('select[name="BookingForm[starttime]"]'),
aId = $(form).prop('id'),
totalContainer = $('.' + aId).find('.total-price'),
dohodContainer = $('.' + aId).find('.total-dohod'),
startformblock = $('.' + aId).find('.startfromtext'),
selectCountAll = isNaN(selectMature.val()) ? 0 : selectMature.val(),
data = {
dateStart: dateStart,
activityId: aId,
cs2: Activity[aId].cs2,
mature: selectMature.val(),
starttime: selectStart.val()
};
$.ajax({
type: "POST",
url: "/excursions/book/getbookingprice",
data: data,
dataType: "JSON",
success: function (data) {
if (data.price) {
if(parseInt(selectCountAll) > 0){
totalContainer.html(data.price + ' ' + data.currency);
dohodContainer.html(data.dohod);
$('.' + aId).find('.people_text_desc').text('за ' + selectCountAll + plural(selectCountAll,'-го человека','-х человек',' человек'));
}
else
{
totalContainer.html('от ' + data.price + ' ' + data.currency);
dohodContainer.html(data.dohod);
$('.' + aId).find('.people_text_desc').text('за человека');
}
data.amountPrice = data.amountPrice ? data.amountPrice : data.price;
//var btnText = (parseInt(data.amountPrice) > 0 && data.goPay==1) ? 'Забронировать и оплатить ' + data.amountPrice + ' ' + data.currency : 'Забронировать';
var btnText = (parseInt(data.amountPrice) > 0 && data.goPay==1) ? 'Перейти к оплате' : 'Забронировать';
$('.' + aId + ' .maincolumn__price__item-inputblock-btn').val(btnText);
//diff = data.price.replace(" ","")-data.amountPrice.replace(" ","");
diff = data.diff;
if(diff > 0 && data.goPay==1){
$('.' + aId + ' .maincolumn__price__item__paydiff .topay').html(diff + ' ' + data.currency);
$('.' + aId + ' .maincolumn__price__item__paydiff').show();
}else{
$('.' + aId + ' .maincolumn__price__item__paydiff').hide();
}
startformblock.html(data.startfrom);
}
else {
//console.log(data);
}
},
error: function () {
alert("error3");
}
})
});
$('.bookform .select-starttime').change(function () {
var form = $(this).closest('form'),
aId = $(form).prop('id');
getBookingForm(dateStart, aId);
});
$('.select-count:not(#_miniGroupConnect .select-count, #_miniGroupAdd .select-count)').change(function () {
var form = $(this).closest('form'),
amountType = form.find("input[name=\"BookingForm[amountType]\"]").filter(":checked"),
selectMature = $(form).find('select[name="BookingForm[mature]"]'),
selectMatureVal = selectMature.val(),
selectChild = $(form).find('select[name="BookingForm[child]"]'),
selectChildVal = selectChild.val(),
selectCountAll = isNaN(selectChildVal) && isNaN(selectMatureVal) ? 0 : parseInt(selectMatureVal) + parseInt(selectChildVal),
selectStart = $(form).find('.select-starttime'),
coupon_code = $(form).find("#BookingForm_code_coupon").val(),
aId = $(form).prop('id'),
data = {dateStart: dateStart, starttime: selectStart.val(), activityId: aId, cs2: Activity[aId].cs2, cMature: selectMature.val(), cChild: selectChild.val(), amountType: amountType.val(), coupon_code: coupon_code};
if($("#transferFrom") !== undefined){
data.transferFrom = $("#transferFrom").attr("auditid");
data.transferTo = $("#transferTo").attr("auditid");
data.transferId = $('#form' + aId).attr("code");
data.transferTime = $('#form' + aId).attr("time");
}
if ($(this).prop('name') == 'BookingForm[mature]') {
data.mature = $(this).val();
}
else {
data.child = $(this).val();
}
$.ajax({
type: "POST",
url: "/excursions/book/getcount",
data: data,
dataType: "JSON",
success: function (list) {
if (list.parent) {
selectMature.html('');
$.each(list.parent, function (key, value) {
selectMature.append($("").attr("value", key).text(value));
});
selectMature.val(selectMatureVal);
while(selectMatureVal != selectMature.val())
{
selectMatureVal++;
selectMature.val(selectMatureVal);
}
}
if (list.child) {
selectChild.html('');
$.each(list.child, function (key, value) {
selectChild.append($("").attr("value", key).text(value));
});
selectChild.val(selectChildVal);
}
if (list.price) {
$('.' + aId + ' .total-price').html(list.price + ' ' + list.currency);
$('.' + aId + ' .total-dohod').html(list.dohod);
if( parseInt(Activity[aId].excursionType) && selectCountAll){
$('.' + aId).find('.people_text_desc').text('за ' + selectCountAll + plural(selectCountAll,'-го человека','-х человек',' человек'));
}
list.amountPrice = list.amountPrice ? list.amountPrice : list.price;
//var btnText = (parseInt(list.amountPrice) > 0 && list.goPay==1)? 'Забронировать и оплатить ' + list.amountPrice + ' ' + list.currency : 'Забронировать';
var btnText = (parseInt(list.amountPrice) > 0 && list.goPay==1)? 'Перейти к оплате' : 'Забронировать';
$('.' + aId + ' .maincolumn__price__item-inputblock-btn').val(btnText);
//diff = list.price.replace(" ","")-list.amountPrice.replace(" ","");
diff = list.diff;
if(diff > 0 && list.goPay==1){
$('.' + aId + ' .maincolumn__price__item__paydiff .topay').html(diff + ' ' + list.currency);
$('.' + aId + ' .maincolumn__price__item__paydiff').show();
}else{
$('.' + aId + ' .maincolumn__price__item__paydiff').hide();
}
}
if(list.coupon_text!=""){
$("#" + aId + "coupon_text").html("
" + list.coupon_text);
$("#" + aId + "coupon_text").show();
}else{
$("#" + aId + "coupon_text").hide();
$("#" + aId + "coupon_text").html("");
}
},
error: function () {
alert("error2");
}
})
});
setDatepicker();
$('.promo-code-link').click(function(){
var act = $(this).attr("act");
$('.promo-form' + act).toggle(400);
});
$('.tours__tour--favorite').click(function(){
var exID = $(this).attr("exID");
var element = $(this);
if($(this).hasClass("selected")){
element.removeClass("selected");
$("#favourite_page_item_" + exID).hide();
$("#favorite_" + exID).html("Запомнить это предложение");
$("#favorite_" + exID).css("opacity", 1);
$.post( "/favorits/unset", { eid: exID }, function( data ) {
if(data.status == "success"){
//$(".total-favorits").attr("title", data.total);
if(data.total<1){
$(".total-favorits").removeClass("selected");
$("#favorite_total_span").html("");
}else{
$("#favorite_total_span").html(" (" + data.total + ")");
}
}
}, "json");
}else{
element.addClass("selected");
$("#favorite_" + exID).css("opacity", 0);
$("#favorite_" + exID).html("Сохранено в Избранном");
$.post( "/favorits/set", { eid: exID }, function( data ) {
if(data.status == "success"){
//$(".total-favorits").attr("title", data.total);
if(!$(".total-favorits").hasClass("selected")){$(".total-favorits").addClass("selected")}
$("#favorite_total_span").html(" (" + data.total + ")");
if(yaCounter12449020 !== undefined){
yaCounter12449020.reachGoal('client_make_favourite');
ga('send', 'event', 'user', 'client_make_favourite');
}
}
}, "json");
}
});
$('.tours__tour--favorite').hover(
function(){
var exID = $(this).attr("exID");
if(!$(this).hasClass("selected")){
$("#favorite_" + exID).css("opacity", 1);
console.log(exID + " - in");
}
},
function(){
var exID = $(this).attr("exID");
$("#favorite_" + exID).css("opacity", 0);
console.log(exID + " - out");
}
);
$('#favorite_total').click(function(){
window.location.href = "/excursions/favourites";
});
$('#favorite_total').hover(
function(){
$('.total-favorits').addClass("selected");
},
function(){
if($('#favorite_total_span').html()==""){
$('.total-favorits').removeClass("selected");
}
}
);
});
function setDatepicker()
{
if (typeof setDate != 'undefined' && setDate)
{
$("#order .maincolumn__price-datepicker").each(function () {
var activity = $(this).attr('data-activity');
if(activity == '_miniGroupConnect')
{
$(this).datepicker("setDate", setDate);
$('.ui-datepicker-current-day').click();
}
});
}
}
function getNextStep(container) {
$("#" + container + " .maincolumn__price__item-line_first").addClass("maincolumn__price__item-line-success");
$("#" + container + " .maincolumn__price__item-inputs").show();
$("#" + container + " .maincolumn__price__item-selectblock-btn").hide();
$("#" + container + " .maincolumn__price__item-selectblock-rightlabel-green").fadeIn(1000).fadeOut(1000);
$("#" + container + " select").addClass("maincolumn__price__item-selectblock-select-success_minimal");
$("#" + container + " #BookingForm_clientName").focus();
if(yaCounter12449020 !== undefined){
yaCounter12449020.reachGoal('Button_goon');
ga('send', 'event', 'user', 'order goon', container);
}
$("html, body").animate({
scrollTop: $("#" + container + " .maincolumn__price__item-line2").offset().top + "px"
}, {
duration: 500,
complete: function(){
//$("#d1_1").prependTo('.1_1 .maincolumn__price__item-cost').datepicker('show');
}
}
);
}
function getBookingForm(dateStart, activityId) {
var form = $('#' + activityId),
amountType = form.find("input[name=\"BookingForm[amountType]\"]").filter(":checked"),
data = {dateStart: dateStart, activityId: activityId, cs2: Activity[activityId].cs2, amountType: amountType.val()},
startformblock = $('.' + activityId).find('.startfromtext'),
selectStart = $(form).find('select[name="BookingForm[starttime]"]'),
selectMature = $(form).find('select[name="BookingForm[mature]"]'),
selectChild = $(form).find('select[name="BookingForm[child]"]'),
selectMatureVal = selectMature.val() ? selectMature.val() : activityId != '_miniGroupAdd' ? 1 : 0,
selectChildVal = selectChild.val() ? selectChild.val() : 0,
selectCountAll = isNaN(selectMatureVal) || isNaN(selectChildVal) ? 0 : parseInt(selectMatureVal) + parseInt(selectChildVal);
data.mature = selectMatureVal;
data.child = selectChildVal;
data.coupon_code = $(form).find("#BookingForm_code_coupon").val();
if($("#transferFrom") !== undefined){
data.transferFrom = $("#transferFrom").attr("auditid");
data.transferTo = $("#transferTo").attr("auditid");
data.transferId = $('#form' + activityId).attr("code");
data.transferTime = $('#form' + activityId).attr("time");
}
if (selectStart.val() !== undefined && selectStart.val() != '' && selectStart.val() !== null) {
data.timeStart = selectStart.val();
}
$.ajax({
type: "POST",
url: "/excursions/book/getbookingform",
data: data,
dataType: "JSON",
success: function (data) {
if (data.time) {
selectStart.html('');
$.each(data.time, function (key, value) {
selectStart.append($("").attr("value", key).text(value));
});
}
if (activityId == '_miniGroupConnect' || activityId == '_miniGroupAdd' || (selectMatureVal == 1 && selectChildVal == 0)) {
if (data.parent) {
selectMature.html('');
$.each(data.parent, function (key, value) {
selectMature.append($("").attr("value", key).text(value));
});
selectMature.val(selectMatureVal);
while(selectMatureVal != selectMature.val())
{
selectMatureVal++;
selectMature.val(selectMatureVal);
}
}
if (data.child) {
selectChild.html('');
$.each(data.child, function (key, value) {
selectChild.append($("").attr("value", key).text(value));
});
selectChild.val(selectChildVal);
}
}
if (data.price) {
console.log("price " + data.price);
console.log("to pay " + data.amountPrice);
console.log("all " + parseInt(selectCountAll));
console.log("exType " + Activity[activityId].excursionType);
console.log("gopay " + data.goPay);
$('.' + activityId + ' .total-price').html(data.price + ' ' + data.currency);
$('.' + activityId + ' .total-dohod').html(data.dohod);
if( parseInt(Activity[activityId].excursionType) || activityId == '_miniGroupConnect' || activityId == '_miniGroupAdd'){
if(parseInt(selectCountAll) > 0){
$('.' + activityId).find('.people_text_desc').text('за ' + selectCountAll + plural(selectCountAll,'-го человека','-х человек',' человек'));
}else{
$('.' + activityId + ' .total-price').html('от ' + data.price + ' ' + data.currency);
$('.' + activityId).find('.people_text_desc').text('за человека');
}
}
data.amountPrice = data.amountPrice ? data.amountPrice : data.price;
//var btnText = (parseInt(data.amountPrice) > 0 && data.goPay==1)? 'Забронировать и оплатить ' + data.amountPrice + ' ' + data.currency : 'Забронировать';
var btnText = (parseInt(data.amountPrice) > 0 && data.goPay==1)? 'Перейти к оплате' : 'Забронировать';
$('.' + activityId + ' .maincolumn__price__item-inputblock-btn').val(btnText);
//diff = data.price.replace(" ","")-data.amountPrice.replace(" ","");
diff = data.diff;
if(diff > 0 && data.goPay==1){
$('.' + activityId + ' .maincolumn__price__item__paydiff .topay').html(diff + ' ' + data.currency);
$('.' + activityId + ' .maincolumn__price__item__paydiff').show();
}else{
$('.' + activityId + ' .maincolumn__price__item__paydiff').hide();
}
if(data.coupon_text!=""){
$("#" + activityId + "coupon_text").html("
" + data.coupon_text);
$("#" + activityId + "coupon_text").show();
}else{
$("#" + activityId + "coupon_text").hide();
$("#" + activityId + "coupon_text").html("");
}
}
startformblock.html('');
if (data.startfrom) {
startformblock.html(data.startfrom);
}
$('#form' + activityId + ' form').show();
},
error: function () {
console.log("error1");
}
})
}
function addFav(data){
var exID = $(this).attr("exID");
var element = $(this);
if($(this).hasClass("selected")){
element.removeClass("selected");
$(".tours__tour--favorite").each(function(){
if($(this).attr("exID")==exID){
$(this).removeClass('selected');
}
});
if($("#favorite_g").attr("exID")==exID){
$("#favorite_g").removeClass('selected');
}
$("#favourite_page_item_" + exID).hide();
$("#favorite_" + exID).html("Запомнить это предложение");
$("#favorite_" + exID).css("opacity", 1);
$.post( "/favorits/unset", { eid: exID }, function( data ) {
if(data.status == "success"){
//$(".total-favorits").attr("title", data.total);
if(data.total<1){
$(".total-favorits").removeClass("selected");
$("#favorite_total_span").html("");
}else{
$("#favorite_total_span").html(" (" + data.total + ")");
}
}
}, "json");
}else{
element.addClass("selected");
$(".tours__tour--favorite").each(function(){
if($(this).attr("exID")==exID){
$(this).addClass('selected');
}
});
if($("#favorite_g").attr("exID")==exID){
$("#favorite_g").addClass('selected');
}
$("#favorite_" + exID).css("opacity", 0);
$("#favorite_" + exID).html("Сохранено в Избранном");
$.post( "/favorits/set", { eid: exID }, function( data ) {
if(data.status == "success"){
//$(".total-favorits").attr("title", data.total);
if(!$(".total-favorits").hasClass("selected")){$(".total-favorits").addClass("selected")}
$("#favorite_total_span").html(" (" + data.total + ")");
if(yaCounter12449020 !== undefined){
yaCounter12449020.reachGoal('client_make_favourite');
ga('send', 'event', 'user', 'client_make_favourite');
}
}
}, "json");
}
}
$(function(){
$("[data-toggle='tooltip']").mouseover(
function(data){
$("body").append('' + ($(this).attr("data-title")) + '
');
$("[data-toggle='tooltip']").mousemove(function(data){
$('.wtspopover').css("top", data.pageY+10);
$('.wtspopover').css("left", data.pageX+10);
});
}
);
$("[data-toggle='tooltip']").mouseout(
function(data){ //handlerOut
$('.wtspopover').remove();
});
});
function countDownClockInit(type, seconds){
if(!$('.flip_clock').hasClass('flip_clock_normal') && !$('.flip_clock').hasClass('flip_clock_inversed')){
if(type == "normal"){
$('.flip_clock').addClass('flip_clock_normal');
}else{
$('.flip_clock').addClass('flip_clock_inversed');
}
}
digits = getDownClockDigits(seconds);
if(type == "normal"){
digits_prev = getDownClockDigits(seconds-1);
}else{
digits_prev = getDownClockDigits(seconds+1);
}
$('.ce-minutes-digit i').remove();
$('.ce-seconds-digit i').remove();
$('.ce-minutes-digit-first').append('' + digits_prev[0] +'');
$('.ce-minutes-digit-last').append('' + digits_prev[1] +'');
$('.ce-seconds-digit-first').append('' + digits_prev[2] +'');
$('.ce-seconds-digit-last').append('' + digits_prev[3] +'');
}
function countDownGo(type, start, limit){
var koeff = 1;
if(type=="normal"){koeff = -1;}else{koeff = 1;}
if(start >= 0 && start <= limit){
setTimeout(function(){
countChangeDigits(type, koeff, start);
countDownGo(type, start+koeff, limit);
},1000);
}else{
countDownStart();
console.log("ds");
}
}
function countChangeDigits(type, koeff, seconds){
seconds_prev = getDownClockDigits(seconds + koeff);
seconds_now = getDownClockDigits(seconds);
obs = ['ce-minutes-digit-first','ce-minutes-digit-last','ce-seconds-digit-first', 'ce-seconds-digit-last'];
for(i=0; i<4; i++){
if(seconds_now[i] != seconds_prev[i]){
ob = $('.' + obs[i]).find('i');
ob.addClass("animate");
ob.attr("data-old", seconds_prev[i]);
ob.text(seconds_now[i]);
}
}
setTimeout(function(){
countDownClockInit(type,seconds);
},300);
}
function getDownClockDigits(seconds){
if(seconds < 1){
return [0, 0, 0, 0];
}
fm = Math.floor(seconds/600);
lm = Math.floor((seconds - fm*600)/60);
fs = Math.floor((seconds - fm*600 - lm*60)/10);
ls = seconds - fm*600 - lm*60 - fs*10;
res = [fm, lm, fs, ls];
return res;
}
function countDownStart(type, limit, start){
$('.booking_countdown_wrapper').show();
if(type === undefined){
type = $('.booking_countdown_wrapper').attr("cctype");
limit = $('.booking_countdown_wrapper').attr("cclimit");
start = $('.booking_countdown_wrapper').attr("ccstart");
}else{
$('.booking_countdown_wrapper').attr("cctype", type);
$('.booking_countdown_wrapper').attr("cclimit", limit);
$('.booking_countdown_wrapper').attr("ccstart", start);
}
countDownClockInit(type,start);
countDownGo(type, start-1, limit);
}