var apiUrl = 'https://www.gruberreisen.at/wp-content/plugins/travel-tainment/api';
// console.log(apiUrl);
var regionlist = [];
var subregionlist = [];
var regionlistSQL = [];
var mainRegions = [];
var destids = [];
$(function () {
$('.searchresult').hide();
// searchRegionTree();
// searchRegionTreeSQL();
});
function searchRegionTreeSQL() {
$.ajax(FLBuilderLayoutConfig.paths.wpAjaxUrl, {
dataType: 'json',
type: "POST",
data: {
action: "pm_trt_search_regions",
regionid: $(this).attr('data-region-id')
},
success: function(data) {
var regionResults = [];
if (data.error == false ) {
$.each(data.regions, function (index, region) {
if (region.type == 'Region') {
regionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_destination),
idParent: region.id_region
});
}
if (region.type == 'Subregion') {
subregionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_region),
idParent: parseInt(region.id_destination)
});
}
});
$('.regionsearch').show();
}
else {
}
},
error: function() {
// console.log("ERROR");
}
});
}
function showRegions(val) {
var searchlist = [];
$.ajax(FLBuilderLayoutConfig.paths.wpAjaxUrl, {
dataType: 'json',
type: "POST",
data: {
action: "pm_trt_search_regions",
q: val
},
success: function(data) {
var regionResults = [];
var hotelResults = [];
var cityResults = [];
var subregionResults = [];
var regions_json = [];
if(data.error == false) {
if (data.type == 'hotel') {
$.each(data.hotels, function (i, hotel) {
var objectHTML = [
'
'+hotel.hotel_object_name+'
'+hotel.region_region+''
].join('');
// Nach Datum Sortieren
objectHTML.sort();
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Hotel
');
$(".subregionlist").html(regionResults);
$.each(data.regions, function (index, region) {
regionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_destination),
idParent: 0,
});
});
$('.regionsearch').show();
getLandingpages();
}
if (data.type == 'sub_hotel') {
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Stadt
');
$.each(data.subregions, function (i, sub) {
var objectHTML = [
''+sub.name+''
].join('');
// Nach Datum Sortieren
objectHTML.sort();
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$(".subregionlist").html(regionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Hotel
');
$.each(data.hotels, function (i, hotel) {
var objectHTML = [
''+hotel.hotel_object_name+'
'+hotel.region_region+''
].join('');
hotelResults.push(objectHTML);
$('.hotellist').html(hotelResults.join(''));
});
$(".subregionlist.hotels").html(hotelResults);
$('.regionsearch').show();
getLandingpages();
}
if (data.type == 'all') {
// console.log("data");
// console.log(data);
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Destination
');
$.each(data.regions, function (index, destination) {
getLandingpages();
return false;
});
$.each(data.regions, function (i, des) {
var objectHTML = [
''+des.name+''
].join('');
regionResults.push(objectHTML);
});
// Nach Name Sortieren
regionResults.sort();
$('.destination').html(regionResults.join(''));
// $(".subregionlist.destination").html(regionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Regionen
');
$.each(data.subregions, function (i, sub) {
var objectHTML = [
''+sub.name+''
].join('');
subregionResults.push(objectHTML);
});
subregionResults.sort();
$('.sub').html(subregionResults.join(''));
// $(".sub").html(subregionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Stadt
');
$.getJSON("https://www.gruberreisen.at/wp-content/plugins/travel-tainment/trt-produkt-teaser/RegionTree.json", function(data){
regions_json.push(data);
}).fail(function(){
console.log("An error has occurred.");
});
$.each(data.citys, function (i, city) {
$.each(regions_json, function (js, rjson) {
console.log("rjson");
console.log(rjson);
});
var objectHTML = [
''+city.name+''
].join('');
cityResults.push(objectHTML);
});
cityResults.sort();
$('.city').html(cityResults.join(''));
// $(".sub").html(subregionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Hotel
');
$.each(data.hotels, function (i, hotel) {
var objectHTML = [
''+hotel.hotel_object_name+'
'+hotel.region_region+''
].join('');
hotelResults.push(objectHTML);
});
hotelResults.sort();
$('.hotellist').html(hotelResults.join(''));
$(".subregionlist.hotels").html(hotelResults);
$('.regionsearch').show();
getLandingpages();
}
}
$('.searchresult').on('click', function () {
$('.searchresult').hide();
});
/*if (data.error == false) {
$.each(data.regions, function (i, reg) {
var objectHTML = [
''+reg.name+'
'+reg.regionname+''
].join('');
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Regionen
');
$(".subregionlist").html(regionResults);
$.each(data.regions, function (index, region) {
regionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_destination),
idParent: 0,
});
});
$('.regionsearch').show();
getLandingpages();
}*/
/*else {
}*/
},
error: function() {
// console.log("ERROR");
}
});
}
function showRegions2(val) {
var searchlist = [];
$.ajax(FLBuilderLayoutConfig.paths.wpAjaxUrl, {
dataType: 'json',
type: "POST",
data: {
action: "pm_trt_search_regions",
q: val,
t: 'h'
},
success: function(data) {
var regionResults = [];
var hotelResults = [];
var cityResults = [];
var subregionResults = [];
if(data.error == false) {
if (data.type == 'hotel') {
$.each(data.hotels, function (i, hotel) {
var objectHTML = [
''+hotel.hotel_object_name+'
'+hotel.region_region+''
].join('');
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Hotel
');
$(".subregionlist").html(regionResults);
$.each(data.regions, function (index, region) {
regionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_destination),
idParent: 0,
});
});
$('.regionsearch').show();
getLandingpages();
}
if (data.type == 'sub_hotel') {
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Stadt
');
$.each(data.subregions, function (i, sub) {
var objectHTML = [
''+sub.name+''
].join('');
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$(".subregionlist").html(regionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Hotel
');
$.each(data.hotels, function (i, hotel) {
var objectHTML = [
''+hotel.hotel_object_name+'
'+hotel.region_region+''
].join('');
hotelResults.push(objectHTML);
$('.hotellist').html(hotelResults.join(''));
});
$(".subregionlist.hotels").html(hotelResults);
$('.regionsearch').show();
getLandingpages();
}
if (data.type == 'all') {
console.log(data);
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Destination
');
$.each(data.regions, function (i, des) {
var objectHTML = [
''+des.name+''
].join('');
regionResults.push(objectHTML);
$('.destination').html(regionResults.join(''));
});
// $(".subregionlist.destination").html(regionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Regionen
');
$.each(data.subregions, function (i, sub) {
var objectHTML = [
''+sub.name+''
].join('');
subregionResults.push(objectHTML);
$('.sub').html(subregionResults.join(''));
});
// $(".sub").html(subregionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Stadt
');
$.each(data.citys, function (i, city) {
var objectHTML = [
''+city.name+''
].join('');
cityResults.push(objectHTML);
$('.city').html(cityResults.join(''));
});
// $(".sub").html(subregionResults);
$('.regionsearch').show();
getLandingpages();
$("ul.searchresult").append('Hotel
');
$.each(data.hotels, function (i, hotel) {
var objectHTML = [
''+hotel.hotel_object_name+'
'+hotel.region_region+''
].join('');
hotelResults.push(objectHTML);
$('.hotellist').html(hotelResults.join(''));
});
$(".subregionlist.hotels").html(hotelResults);
$('.regionsearch').show();
getLandingpages();
}
}
$('.searchresult').on('click', function () {
$('.searchresult').hide();
});
/*if (data.error == false) {
$.each(data.regions, function (i, reg) {
var objectHTML = [
''+reg.name+'
'+reg.regionname+''
].join('');
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Regionen
');
$(".subregionlist").html(regionResults);
$.each(data.regions, function (index, region) {
regionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_destination),
idParent: 0,
});
});
$('.regionsearch').show();
getLandingpages();
}*/
/*else {
}*/
},
error: function() {
// console.log("ERROR");
}
});
}
function showSubregions(destination_id) {
$.ajax(FLBuilderLayoutConfig.paths.wpAjaxUrl, {
dataType: 'json',
type: "POST",
data: {
action: "pm_trt_search_subregions",
regionid: destination_id
},
success: function(data) {
var regionResults = [];
if (data.error == false) {
$.each(data.regions, function (i, reg) {
var objectHTML = [
''+reg.name+'
'+reg.regionname+''
].join('');
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Regionen
');
$(".subregionlist").html(regionResults);
$.each(data.regions, function (index, region) {
regionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_destination),
idParent: 0,
});
});
$('.regionsearch').show();
getLandingpages();
}
else {
}
},
error: function() {
// console.log("ERROR");
}
});
}
function showCitys(destination_id) {
$.ajax(FLBuilderLayoutConfig.paths.wpAjaxUrl, {
dataType: 'json',
type: "POST",
data: {
action: "pm_trt_search_citys",
regionid: destination_id
},
success: function(data) {
var regionResults = [];
if (data.error == false) {
$.each(data.regions, function (i, reg) {
var objectHTML = [
''+reg.name+'
'+reg.regionname+''
].join('');
regionResults.push(objectHTML);
$('.subregionlist').html(regionResults.join(''));
});
$("ul.searchresult .regionen").remove();
$("ul.searchresult .subregionlist").remove();
$("ul.searchresult").append('Städte
');
$(".subregionlist").html(regionResults);
$.each(data.regions, function (index, region) {
regionlist.push({
name: region.name,
type: region.type,
id: parseInt(region.id_destination),
idParent: 0,
});
});
$('.regionsearch').show();
getLandingpages();
}
else {
}
},
error: function() {
// console.log("ERROR");
}
});
}
/**
* Search for Region tree
*/
function searchRegionTree() {
$.get(apiUrl + '/Package/RegionTree', function (response) {
var regionResults = [];
// console.log(response);
$.each(response.data.Regions.SubRegion, function (i, reg) {
var objectHTML = [
'',
'',
'',
'',
'',
'
',
''
].join('');
regionResults.push(objectHTML);
$('.regionlist').html(regionResults.join(''));
});
$.each(response.data.Regions.SubRegion, function (index, region) {
regionlist.push({
name: region.RegionName,
id: parseInt(region.ID),
idParent: 0,
});
if (undefined !== region.SubRegions) {
$.each(region.SubRegions.SubRegion, function (index, subregion) {
regionlist.push({
name: subregion.RegionName,
id: parseInt(subregion.ID),
idParent: parseInt(region.ID),
subregion: true,
});
});
}
});
$('.regionsearch').show();
});
}
// Zielgebiets-Baum
$('ul.checkbox-wrapper.level-1.regionlist').on('click', 'li.not_checked > .tt-checkbox > input', function () {
var region_id = $(this).attr('data-id');
$("[class^=appended_] li.searchresult-item").remove();
$("[class^=appended_]").removeClass().addClass('not_checked');
$(this).closest('li').removeClass('not_checked');
if ( $(this).closest('ul').find('li input').is(":checked") ) {
$(this).closest('ul').find('li.not_checked input').prop('checked', false);
}
function base64EncodeUnicode(str) {
utf8Bytes = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
});
return btoa(utf8Bytes);
}
if ($(this).is(":checked")) {
var result_html = [];
var found = regionlist.filter(function (region) {
if(region.idParent == region_id) {
return (region.id, region.name);
}
});
result_html.push('Zielgebiet:');
$.each(found, function (index, region) {
result_html.push('');
});
$(this).closest('li').append('' + result_html.join('') + '
').addClass('appended_'+region_id).removeClass('not_checked');
}
else {
$('.appended_'+region_id+' li.searchresult-item').remove();
$(this).closest('li').removeClass('appended_'+region_id);
}
});
// UTF-8 Base64 Encode
function base64EncodeUnicode(str) {
utf8Bytes = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
});
return btoa(utf8Bytes);
}
var fc = false;
/**
* Search region on keyup, allow lowercase chars.
* Clear results if searchfield is empty.
*/
$(document).ready(function () {
var typingTimerd41d8cd98f00b204e9800998ecf8427e;
var doneTypingIntervald41d8cd98f00b204e9800998ecf8427e = 500;
// erster Tab
$('.regionsearch').unbind('keyup').keyup(function(){
clearTimeout(typingTimerd41d8cd98f00b204e9800998ecf8427e);
typingTimerd41d8cd98f00b204e9800998ecf8427e = setTimeout(doneTyping, doneTypingIntervald41d8cd98f00b204e9800998ecf8427e, $('.regionsearch'), ($(this).val() != ''));
});
$('.regionsearch').unbind('keydown').keydown(function(){
clearTimeout(typingTimerd41d8cd98f00b204e9800998ecf8427e);
});
$('.regionsearch').unbind('focusout').focusout(function(){
// erstes Suchergebnis in Suchfeld übergeben
var reg_html = $('.searchresult').find("li.active").html();
var reg_id = $('.searchresult').find("li.active").attr('data-region-id');
var reg_nid = $('.searchresult').find("li.active").attr('data-region-nid');
$('.regionsearch').val(reg_html);
$('.regionsearch').attr('data-region-id', reg_id);
$('.regionsearch').attr('data-region-nid', reg_nid);
});
// zweiter Tab
$('.regionsearch2').unbind('keyup').keyup(function(){
clearTimeout(typingTimerd41d8cd98f00b204e9800998ecf8427e);
typingTimerd41d8cd98f00b204e9800998ecf8427e = setTimeout(doneTyping2, doneTypingIntervald41d8cd98f00b204e9800998ecf8427e, $('.regionsearch'), ($(this).val() != ''));
});
$('.regionsearch2').unbind('keydown').keydown(function(){
clearTimeout(typingTimerd41d8cd98f00b204e9800998ecf8427e);
});
$('.regionsearch2').unbind('focusout').focusout(function(){
// erstes Suchergebnis in Suchfeld übergeben
var reg_html = $('.searchresult').find("li.active").html();
var reg_id = $('.searchresult').find("li.active").attr('data-region-id');
var reg_nid = $('.searchresult').find("li.active").attr('data-region-nid');
$('.regionsearch2').val(reg_html);
$('.regionsearch2').attr('data-region-id', reg_id);
$('.regionsearch2').attr('data-region-nid', reg_nid);
});
// dritter Tab
$('.regionsearch3').unbind('keyup').keyup(function(){
clearTimeout(typingTimerd41d8cd98f00b204e9800998ecf8427e);
typingTimerd41d8cd98f00b204e9800998ecf8427e = setTimeout(doneTyping3, doneTypingIntervald41d8cd98f00b204e9800998ecf8427e, $('.regionsearch'), ($(this).val() != ''));
$(document).on('click', '.searchresult-item', function () {
console.log($(this));
$('.regionsearch3').val($(this).text());
$('.searchresult').hide();
});
});
$('.regionsearch3').unbind('keydown').keydown(function(){
clearTimeout(typingTimerd41d8cd98f00b204e9800998ecf8427e);
});
});
function doneTyping() {
var val = $('.regionsearch').val();
if (val && val.length >= 2) {
$('#tab-1 .searchresult').show();
// AJAX Subregions
showRegions(val);
// $('.searchresult').html(result_html.join(''));
// $('.searchresult > li.active').focus();
getLandingpages();
} else {
// $('.searchresult').html('');
// $('.searchresult').hide();
}
}
function doneTyping2() {
var val = $('.regionsearch2').val();
if (val && val.length >= 2) {
$('#tab-2 .searchresult').show();
// AJAX Subregions
showRegions2(val);
// $('.searchresult').html(result_html.join(''));
// $('.searchresult > li.active').focus();
getLandingpages();
} else {
// $('.searchresult').html('');
// $('.searchresult').hide();
}
}
function doneTyping3() {
var res_html = '';
var val = $('.regionsearch3').val();
if (val && val.length >= 2) {
{
//var r = $.post(FLBuilderLayoutConfig.paths.wpAjaxUrl, {
var r = $.post('https://www.gruberreisen.at/wp-content/plugins/tt-plugin/tt-ajax.php', {
action: 'tt_livesearch_gruber',
search: val,
show_objects: 1
}
,
function (html){
$("#tab-3 .searchresult").html(html);
$('#tab-3 .searchresult').show();
},
'html');
}
$('.searchresult-item').on('click', function () {
$('.regionsearch').val($(this).text());
$('[name="pm_fulltext"]').val($(this).text());
});
//getLandingpages();
}
}
var term = '';
$('.regionsearch').keyup(function(e) {
term = $(this).val();
/*if(e.which == 40){
if($(".searchresult li.active").length!=0) {
var storeTarget = $('.searchresult').find("li.active").next();
$(".searchresult li.active").removeClass("active");
storeTarget.focus().addClass("active");
$(this).keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
event.preventDefault();
$('.regionsearch').val(storeTarget.html());
$('.regionsearch').attr('data-region-id', storeTarget.attr('data-region-id'));
}
});
}
else {
$('.searchresult').find("li:first").focus().addClass("active");
}
return ;
}*/
/*if(e.which == 38){
if($(".searchresult li.active").length!=0) {
var storeTarget = $('.searchresult').find("li.active").prev();
$(".searchresult li.active").removeClass("active");
storeTarget.focus().addClass("active");
}
else {
$('.searchresult').find("li:first").focus().addClass("active");
}
console.log( $(':focus'));
return ;
}*/
$(".regionsearch").focusout(function() {
var reg_html = $('.searchresult').find("li.active").html();
var reg_id = $('.searchresult').find("li.active").attr('data-region-id');
var reg_nid = $('.searchresult').find("li.active").attr('data-region-nid');
setTimeout(function () {
// $('.searchresult').html('');
// $('.searchresult').hide();
}, 300);
$('.regionsearch').val(reg_html);
$('.regionsearch').attr('data-region-id', reg_id);
$('.regionsearch').attr('data-region-nid', reg_nid);
})
});
$('.regionsearch2').keyup(function(e) {
term = $(this).val();
$(".regionsearch2").focusout(function() {
var reg_html = $('.searchresult').find("li.active").html();
var reg_id = $('.searchresult').find("li.active").attr('data-region-id');
setTimeout(function () {
// $('.searchresult').html('');
// $('.searchresult').hide();
}, 300);
$('.regionsearch2').val(reg_html);
$('.regionsearch2').attr('data-region-id', reg_id);
})
});
// Function um den Cursor ans Ende zu setzen
jQuery.fn.putCursorAtEnd = function() {
return this.each(function() {
$(this).focus()
if (this.setSelectionRange) {
var len = $(this).val().length * 2;
this.setSelectionRange(len, len);
} else {
$(this).val($(this).val());
}
});
};
$('.regionsearch').on('click', function () {
// Cursor ans Ende setzen
// $(this).putCursorAtEnd();
var val = $(this).val();
if (val) {
var result_html = [];
var found = regionlist.filter(function (region) {
return (undefined !== region.name && region.name.toLowerCase().indexOf(val.toLowerCase()) > -1);
});
$('.searchresult').show();
$.each(found, function (index, region) {
result_html.push('' + region.name + '');
});
$('.searchresult').html(result_html.join(''));
getLandingpages();
} else {
// $('.searchresult').html('');
// $('.searchresult').hide();
}
});
var mouse_is_inside = false;
$(document).ready(function()
{
$('searchresult').hover(function(){
mouse_is_inside=true;
}, function(){
mouse_is_inside=false;
});
$("body").mouseup(function(){
if(! mouse_is_inside) $('.searchresult').hide();
});
$('[name="reiseziel"]').click(function () {
console.log($(this).val());
var val = $(this).val();
showRegions(val);
});
});
/**
* Get LandingPage if theere is one
*/
var steuerung = "";
var data_hotel_id = "";
var data_city_id = "";
var data_region_id = "";
var data_nid = "";
var landing_desitnation = ""
function getLandingpages(landing_desitnation = "") {
var childs = [];
if ($(".searchresult .destination li:first-child").length != 0) {
$(".searchresult .destination li:first-child").addClass('active');
$('.regionsearch').attr('data-region-id', $('.searchresult-item.active').attr('data-region-id'));
$('.regionsearch').attr('data-city-id', $('.searchresult-item.active').attr('data-city-id'));
}
else {
if($(".searchresult .subregion.sub li:first-child").length != 0) {
$(".searchresult .subregion.sub li:first-child").addClass('active');
$('.regionsearch').attr('data-region-id', $('.searchresult-item.active').attr('data-region-id'));
$('.regionsearch').attr('data-city-id', $('.searchresult-item.active').attr('data-city-id'));
}
else {
if($(".searchresult .subregion li[data-type='City']:first-child").length != 0) {
$(".searchresult .subregion li[data-type='City']:first-child").addClass('active');
$('.regionsearch').attr('data-region-id', $('.searchresult-item.active').attr('data-region-id'));
$('.regionsearch').attr('data-city-id', $('.searchresult-item.active').attr('data-city-id'));
}
else {
if($(".searchresult .subregion li[data-type='Hotel']:first-child").length != 0) {
$(".searchresult .subregion li[data-type='Hotel']:first-child").addClass('active');
console.log($('.searchresult-item.active'));
$('.regionsearch').attr('data-region-id', $('.searchresult-item.active').attr('data-hotel-id'));
}
}
}
}
$('.search-content.pm-search').keydown(function(event){
var keyCode = (event.keyCode ? event.keyCode : event.which);
if (keyCode == 13) {
var data_id = $(this).find('.searchresult .destination li').attr('data-region-id');
var data_name = $(this).find('.searchresult .destination li').html();
if (data_id != undefined) {
$(this).find('#regionsearch').attr('data-region-id', data_id);
}
else {
data_id = $(this).find('.searchresult .subregion li').attr('data-region-id');
var data_type = $(this).find('.searchresult li').attr('data-type');
var data_hotel_id = $(this).find('.searchresult li').attr('data-hotel-id');
if (data_id != undefined) {
$(this).find('#regionsearch').attr('data-region-id', data_id);
$(this).find('#regionsearch').attr('data-type', data_type);
$(this).find('#regionsearch').attr('data-hotel-id', data_hotel_id);
}
else {
data_id = $(this).find('.searchresult .hotels li').attr('data-region-id');
var data_type = $(this).find('.searchresult .hotels li').attr('data-type');
console.log("data_type");
console.log(data_type);
if (data_id != undefined) {
$(this).find('#regionsearch').attr('data-region-id', data_id);
$(this).find('#regionsearch').attr('data-type', data_type);
}
}
}
if (data_name != undefined) {
$(this).find('#regionsearch').html();
}
else {
data_name = $(this).find('.searchresult .subregion li').html();
if (data_name != undefined) {
$(this).find('#regionsearch').html();
}
else {
data_name = $(this).find('.searchresult .hotels li').html();
if (data_name != undefined) {
$(this).find('#regionsearch').html();
}
}
}
$(this).find('#regionsearch').attr('data-region-id', data_id);
$(this).find('#regionsearch').val(data_name);
setTimeout(function () {
$('[type=submit]').focus();
$('.searchresult').hide();
}, 100);
// $(this).submit();
event.preventDefault();
}
});
$('.searchresult-item').on('click', function () {
steuerung = $(this).attr('data-type');
data_hotel_id = $(this).attr('data-hotel-id');
data_city_id = $(this).attr('data-city-id');
data_region_id = $(this).attr('data-region-id');
if (!ajaxurl) {
var ajaxurl = "https://www.gruberreisen.at/wp-admin/admin-ajax.php";
}
var subregion = false;
if ($(this).hasClass('subregion')) {
$('.regionsearch').addClass('subregion');
$('.regionsearch2').addClass('subregion');
subregion = true;
}
else {
$('.regionsearch').removeClass('subregion');
$('.regionsearch2').removeClass('subregion');
}
var traveltainment_link = $('[name="travel_tainment_link"]').val();
var regid = $(this).attr('data-region-id');
$('.regionsearch').attr('data-region-id', regid);
$('.regionsearch2').attr('data-region-id', regid);
$.ajax(ajaxurl, {
dataType: 'json',
type: "POST",
data: {
action: "trt_search_ladingpage",
regionid: $(this).attr('data-region-id'),
hotelid: $(this).attr('data-type')
},
success: function(data) {
// console.log(data);
if (data.error == false) {
if (traveltainment_link == 'true') {
if ($('.field.touristic_daterange.popover-field > span').html() == 'Reisezeitraum' &&
$('[name="adult"]').val() == '2' &&
$('[name="child"]').val() == '') {
/* $('.input-row.submit').hide();
$('.input-row.link').show();*/
$('.input-row.link a').attr('href', data.permalink);
}
// window.location.href = data.permalink;
}
}
else {
// Date From
var ddate = $('[name="pm_date_from"]').val();
if (!ddate.trim()) {
ddate = new Date();
}
else {
ddate = new Date(ddate*1000);
}
var d = ddate; // timestamp
var da = d.getDate(); // day
var mon = d.getMonth() + 1; // month
var yr = d.getFullYear(); // year
if(da < 10) {
da = "0"+ da;
}
if(mon < 10) {
mon = "0"+ mon;
}
var date_from = yr + "-" + mon + "-" + da;
date_from = "&ddate=" + date_from;
// Date To
var tdate = $('[name="pm_date_to"]').val();
if (!tdate.trim()) {
tdate = new Date();
tdate.setMonth(tdate.getMonth() + 1);
}
else {
tdate = new Date(tdate*1000);
}
var td = tdate; //timestamp
var tda = td.getDate(); //day
var tmon = td.getMonth() + 1; //month
var tyr = td.getFullYear(); //year
if(tda < 10) {
tda = "0"+ tda;
}
if(tmon < 10) {
tmon = "0"+ tmon;
}
var date_to = tyr + "-" + tmon + "-" + tda;
date_to = "&rdate=" + date_to;
// Region or Subregion
/*if (subregion == true) {
regid = "hotel?rid=" + regid;
}
else {
regid = "region?rgid=" + regid;
}*/
if (steuerung == 'Region') {
regid = 'region?rgid=' + $(this).attr('data-region-id');
}
if (steuerung == 'Subregion') {
regid = 'region?rid=' + $(this).attr('data-region-id');
}
if (steuerung == 'City') {
regid = 'region?rid=' + $(this).attr('data-region-id') + '&cyid' + $(this).attr('data-city-id');
}
if (steuerung == 'Hotel') {
console.log("Hier");
regid = 'hotel?rid=' + $(this).attr('data-region-id') + '&aid' + $(this).attr('data-hotel-id') + '&ibe=hotel';
}
var airport = $('[name="depap"]').val();
airport = '&depap=' + airport;
// Reisedauer
var rdauer = $('[name="rdauer"]').val();
rdauer = "&dur=" + rdauer;
// Reisedauer
var erdauer = $('[name="erdauer"]').val();
erdauer = "&dur=" + erdauer;
// Adults
var adult = $('[name="adult"]').val();
console.log(adult);
adult = "&adult=" + adult;
// Children
var child_1 = $('#child-1 select').val();
var child_2 = $('#child-2 select').val();
var child_3 = $('#child-3 select').val();
if($('#child-1').is(':visible')) {
childs.push(child_1);
}
if($('#child-2').is(':visible')) {
childs.push(child_2);
}
if($('#child-3').is(':visible')) {
childs.push(child_3);
}
if (!childs.length === 0) {
childs = childs.join(",");
}
var child = childs;
child = "&child=" + child;
/*var child = $('[name="child"]').val();
child = "&child=" + child;*/
var deeplink = "https://buchung.gruberreisen.at/"+
regid+
date_from+
date_to+
airport+
rdauer+
erdauer+
adult+
child;
//$('[data-tabname="Pauschalreisen"] .search-btn').on('click', function () {
console.log(deeplink);
// window.location.href = deeplink;
//});
}
},
error: function() {
// console.log("ERROR");
}
});
$(this).closest('.input-row').find('.fulltext input').val($(this).text());
// $('.searchresult').html('');
// $('.searchresult').hide();
});
}
function sendFormdata(fdata) {
console.log("fdata");
console.log(fdata);
var regid = $('.regionsearch').attr('data-region-id');
var nid = $('.searchresult-item.active').attr('data-region-nid');
var d_hotel_id = $('.regionsearch').attr('data-hotel-id');
var d_type = $('.regionsearch').attr('data-type');
var subregion = false;
if ($('.regionsearch').hasClass('subregion')) {
subregion = true;
}
// Date From
var ddate = $('[name="pm_date_from"]').val();
if (!ddate.trim()) {
ddate = new Date();
}
else {
ddate = new Date(ddate*1000);
}
var d = ddate; // timestamp
var da = d.getDate(); // day
var mon = d.getMonth() + 1; // month
var yr = d.getFullYear(); // year
if(da < 10) {
da = "0"+ da;
}
if(mon < 10) {
mon = "0"+ mon;
}
var date_from = yr + "-" + mon + "-" + da;
date_from = "&ddate=" + date_from;
// Date To
var tdate = $('[name="pm_date_to"]').val();
if (!tdate.trim()) {
tdate = new Date();
tdate.setMonth(tdate.getMonth() + 1);
}
else {
tdate = new Date(tdate*1000);
}
var td = tdate; //timestamp
var tda = td.getDate(); //day
var tmon = td.getMonth() + 1; //month
var tyr = td.getFullYear(); //year
if(tda < 10) {
tda = "0"+ tda;
}
if(tmon < 10) {
tmon = "0"+ tmon;
}
var date_to = tyr + "-" + tmon + "-" + tda;
date_to = "&rdate=" + date_to;
// Region or Subregion
if (subregion == true) {
regid = "region?rid=" + regid;
}
else {
if (nid !== "null") {
regid = "region?nid=" + ""
}
else {
regid = 'region?rgid=' + data_region_id
}
}
/* if (steuerung == 'Region') {
regid = 'region?rgid=' + data_region_id + "&nid=" + nid;
}*/
if (steuerung == 'Subregion') {
regid = 'region?rid=' + data_region_id;
}
if (steuerung == 'City') {
regid = 'region?rid=' + data_region_id + '&cyid=' + data_city_id;
}
if (steuerung == 'Hotel') {
regid = 'hotel?rid=' + data_region_id + '&aid=' + data_hotel_id + '';
}
if (d_type == 'Hotel') {
regid = 'hotel?rid=' + data_region_id + '&aid=' + d_hotel_id + '';
}
// Flughafen - nur ausgeben wenn Form-Feld Flughafen übermittelt wird
if (fdata.includes("depap")) {
var airport = $('[name="depap"]').val();
// airport = '&depap=' + airport + '&ibe=flight';
airport = '&depap=' + airport ;
}
else {
airport = '&ibe=hotel';
}
// Reisedauer
var rdauer = $('[name="rdauer"]').val();
rdauer = "&dur=" + rdauer;
// Reisedauer
var erdauer = $('[name="erdauer"]').val();
erdauer = "&dur=" + erdauer;
// Adults
var adult = $('[name="adult"]').val();
// console.log(adult);
adult = "&adult=" + adult;
var childs = [];
var child_1 = $('#child-1 select').val();
var child_2 = $('#child-2 select').val();
var child_3 = $('#child-3 select').val();
if($('#child-1').is(':visible')) {
childs.push(child_1);
}
if($('#child-2').is(':visible')) {
childs.push(child_2);
}
if($('#child-3').is(':visible')) {
childs.push(child_3);
}
if (!childs.length === 0) {
childs = childs.join(",");
}
var child = childs;
child = "&child=" + child;
var deep;
if (fdata.includes("pm_fulltext")) {
console.log("TRUETRAVEL SUCHE");
if (fdata.includes("rdauer=")) {
var dur = $('#tab-3 [name="rdauer"]').val() ;
if (dur.includes(",")) {
var dur = dur.split("")
var durmin = dur[0];
var durmax = dur[2];
}
else {
var durmin = '';
var durmax = dur;
}
}
date_from = $('#tab-3 [name="pm_date_from"]').val();
date_to = $('#tab-3 [name="pm_date_to"]').val();
var travelkind = $('[name="travelkind"]').val();
var catstring = '';
var categorytree = [];
/*if (travelkind.includes(',')) {
var categorytree = travelkind.split(",");
$.each(categorytree, function (i, v) {
catstring += '&pm_category-tree%5B%5D=2827%3A' + v;
});
}
else {
var catstring = '&pm_category-tree%5B%5D=2827%3A' + travelkind;
}*/
var reiseziel = $('#tab-3 [name="reiseziel"]').val();
term = "&term=" + reiseziel;
window.location.href = 'https://www.gruberreisen.at/suche/'+
'?pm_fulltext='+ reiseziel+
'&pm_duration_min='+durmin+
'&pm_duration_max='+durmax+
'&pm_date_from='+date_from+
'&pm_date_to='+date_to+
catstring+
term;
}
else {
console.log();
if ($('.tab-pane').attr('data-tabname') == 'Pauschalreisen') {
deep = "https://buchung.gruberreisen.at/"+
regid+
date_from+
date_to+
airport+
rdauer+
adult+
child+
term;
setTimeout(function() {
if($('.input-row.link a').attr('href') != '' ) {
if (fdata.includes("depap")) {
if ($('.field.touristic_daterange.popover-field > span').html() == 'Reisezeitraum' &&
$('.field.touristic_airport.popover-field > span.abflug').html() == 'Abflughafen' &&
$('[name="adult"]').val() == '2' &&
$('[name="child"]').val() == '') {
window.location.href = $('.input-row.link a').attr('href');
}
else {
window.location.href = deep;
}
}
else {
console.log("without_DeepAP");
if ($('.field.touristic_daterange.popover-field > span').html() == 'Reisezeitraum' &&
$('[name="adult"]').val() == '2' &&
$('[name="child"]').val() == '') {
window.location.href = $('.input-row.link a').attr('href');
}
else {
window.location.href = deep;
}
}
}
else {
deep = "https://buchung.gruberreisen.at/"+
regid+
date_from+
date_to+
airport+
erdauer+
adult+
child+
term;
if (erdauer !== '&dur=') {
deep = deep + "&" + erdauer;
}
else {
deep = deep + rdauer;
}
console.log('deep');
console.log(deep);
window.location.href = deep;
}
}, 300);
}
}
}
$('#duration').on('keyup', function () {
var val = $(this).val();
if (val) {
var result_html = [];
var found = regionlist.filter(function (region) {
return (undefined !== region.name && region.name.toLowerCase().indexOf(val.toLowerCase()) > -1);
});
$.each(found, function (index, region) {
result_html.push('' + region.name + '');
});
$('.searchresult').html(result_html.join(''));
} else {
// Clear if searchfield is empty
// $('.searchresult').html('');
// $('.searchresult').hide();
}
});