$("body").on('submit', '#buying_box', function(e){
e.preventDefault();
var formData = $(this).serialize();
var customized = false;
$.each($('.customization_active'), function(key, active){
if(active.value == 1){
customized = true;
}
});
if(!customized){
formData+='&request_type=modify_shopping_cart';
$.ajax(
{
type:'post',
url:href+'shop_request.php',
data:formData,
beforeSend:function()
{
//launchpreloader();
},
complete:function()
{
//stopPreloader();
},
success:function(result)
{
var result = JSON.parse(result);
if(result['status']==200){
reload_onpage_shoppingcart();
$('.nav_icon_36warenkorb_cart')[0].click();
$('#onpage_shopping_cart').toggleClass('cart_displayed');
if(ga_ecommerce_active){
ga('ec:addProduct', result['ga_info']);
ga('ec:setAction', 'add');
ga('send', 'event', 'UX', 'click', 'add to cart');
}
if(facebook_pixel_active){
fbq('track', 'AddToCart', result['facebook_info']);
}
}else if(result['status']==300){
show_popup('
'+result['message']+'
');
var info = result['facebook_info'];
if(facebook_pixel_active){
fbq('track', 'AddToCart', info);
}
}else if(result['status']==400){
show_popup(''+result['message']+'
');
}
}
});
}else{
// Upload Images
formData += '&request_type=check_customization';
$.each(customization_pictures, function(picture_name, pictureBase64){
formData += '&'+picture_name+'='+pictureBase64;
});
console.log(formData);
$.ajax({
type:'post',
url:href+'shop_request.php',
data:formData,
success:function(result){
var result = JSON.parse(result);
if(result['status']==200){
show_popup(result['message']);
}else if(result['status']==300){
show_popup(''+result['message']+'
');
var info = result['facebook_info'];
if(facebook_pixel_active){
fbq('track', 'AddToCart', info);
}
}else{
alert('Es ist ein Fehler aufgetreten.');
}
}
});
}
});
$("body").on('submit', '#sort_products_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php",formData, function(o){
$('#products_row').html(o);
$(function() {
$('.lazy').Lazy({
effect: 'fadeIn'
});
});
});
});
$("body").on('submit', '#photo_switch_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php",formData, function(o){
$('#products_row').html(o);
});
});
$(".direct_buy_product, .direct_preorder_product").on('click', function(e){
e.preventDefault();
var product_id = $(this).data('product_id');
var module_id = $(this).data('module_id');
$.post(href+"shop_request.php",{request_type: 'modify_shopping_cart', product_id: product_id, modify_type: 'add_item', module_id: module_id, amount:1}, function(o){
reload_onpage_shoppingcart();
$('.nav_icon_36warenkorb_cart')[0].click();
if(!$('#onpage_shopping_cart').hasClass('cart_displayed')){
$('#onpage_shopping_cart').addClass('cart_displayed');
}
var result = JSON.parse(o);
if(result['status']==200){
if(facebook_pixel_active){
fbq('track', 'AddToCart', result['facebook_info']);
}
if(ga_ecommerce_active){
ga('ec:addProduct', result['ga_info']);
ga('ec:setAction', 'add');
ga('send', 'event', 'UX', 'click', 'add to cart');
}
}else{
show_popup(''+result['message']+'
');
}
});
});
$('body').on('click', '.active_upselling', function(e){
var upselling_id = $(this).data('upselling_id');
$.post(href+"shop_request.php",{request_type: 'activate_upselling', upselling_id: upselling_id}, function(result){
if(result['status']==200){
reload_shop_parts();
}else if(result['status']==300){
show_popup('');
init_upselling_size_choice();
}
}, 'json');
});
function init_shoppingcart(){
$("body").on('submit', '#promocode_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php", formData, function(result){
if(result['status']==300){
show_popup(''+result['message']+'
');
}else if(result['status']==250){
show_popup(''+result['warning']+'
');
}else if(result['status']==210){
show_popup('');
init_promo_size_choice();
}
reload_promocode_area();
reload_shoppingcart_prices();
reload_onpage_shoppingcart();
}, 'json');
});
$("body").on('submit', '#delete_promocode_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php", formData, function(result){
reload_promocode_area();
reload_shoppingcart_prices();
},'json');
});
$("body").on('submit', '.delete_product_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php", formData, function(result){
if(result['status']==200 || result['status']==250){
reload_onpage_shoppingcart();
reload_promocode_area();
reload_shoppingcart_prices();
}
},'json');
});
$("body").on('change', '.change_amount', function(e){
if($(this).val()=='t'){
e.preventDefault();
var container = document.createElement('div');
container.innerHTML = '';
$(this).replaceWith(container);
}else{
$(this).submit();
}
});
$("body").on('submit', '.change_amount_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php", formData, function(result){
reload_onpage_shoppingcart();
reload_promocode_area();
reload_shoppingcart_prices();
if(ga_ecommerce_active){
ga('ec:addProduct', result['ga_info']);
ga('ec:setAction', 'add');
ga('send', 'event', 'UX', 'click', 'add to cart');
}
},'json');
});
}
function init_amount_selector(){
$('.amount_selector').click(function(){
var selectors = document.getElementsByClassName('amount_selector');
for(var i = 0; i < selectors.length; i++){
selectors[i].className = 'amount_selector';
}
this.className += ' selected';
document.getElementById('amount_input').value = this.dataset.amount;
document.getElementById('hidden').innerHTML = this.dataset.amount;
$('#size_button_order').css('display', 'none');
if(this.dataset.preorder == 1){
$('#buy_button_preorder').css('display', 'block');
$('#buy_button_order').css('display', 'none');
}else{
$('#buy_button_preorder').css('display', 'none');
$('#buy_button_order').css('display', 'block');
}
});
};
$('.product_selector').click(function(){
var selectors = document.getElementsByClassName('product_selector');
var main_product_id = false;
for(var i = 0; i < selectors.length; i++){
if(typeof this.dataset.main_product_id !== 'undefined'){
main_product_id = this.dataset.main_product_id;
if(selectors[i].dataset.main_product_id != main_product_id){
continue;
}
}
selectors[i].className = 'product_selector';
}
this.className += ' selected';
var check_qty = true;
if(main_product_id == false){
document.getElementById('product_id_input').value = this.dataset.product_id;
product_id = this.dataset.product_id;
}else{
document.getElementById('product_id_input_'+main_product_id).value = this.dataset.product_id;
product_id = [];
var product_ids = document.getElementsByClassName('product_id_input')
for(var i = 0; i < product_ids.length; i++){
if(product_ids[i].value == '') check_qty = false;
product_id.push(product_ids[i].value);
}
main_product_id = document.getElementById('main_product_id_input').value;
console.log(main_product_id);
}
if(check_qty){
$.post(href+'shop_request.php',{request_type: 'change_buying_size', product_id: product_id, module_id: this.dataset.module_id, selected_amount: document.getElementById('amount_input').value, main_product_id: main_product_id}, function(result){
if(result['status']==200){
$('#amount_select').html(result['message']);
init_amount_selector();
var selectors = document.getElementsByClassName('amount_selector');
for(var i = 0; i < selectors.length; i++){
if($(selectors[i]).hasClass('selected')){
$(selectors[i]).click();
}
}
}
}, 'json');
}
});
$("body").on('submit', '#onpage_promocode_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php",formData, function(result){
if(result['status']==200){
reload_shop_parts();
}else if(result['status']==210){
show_popup('');
init_promo_size_choice();
reload_shop_parts();
}else if(result['status']==250){
show_popup(''+result['warning']+'
');
reload_shop_parts();
}else if(result['status'] == 300){
show_popup(''+result['message'])+'
';
$('#promocode_input').val('');
}
}, 'json');
});
$("body").on('submit', '#checkout_promocode_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php",formData, function(result){
if(result['status']==200){
reload_shop_parts();
}else if(result['status']==210){
show_popup('');
init_promo_size_choice();
reload_shop_parts();
}else if(result['status']==250){
show_popup(''+result['warning']+'
');
reload_shop_parts();
}else if(result['status'] == 300){
show_popup(''+result['message'])+'
';
$('#promocode_input').val('promocode_input_checkout');
}
}, 'json');
});
function init_promo_size_choice(){
$('.choose_size').click(function(){
var buttons = $(this).parent().find('button');
$.each(buttons, function(key, button){
button.classList.remove('selected');
});
$(this).addClass('selected');
});
$('#finish_promo_size_choice').click(function(){
var products_to_add = new Array();
var fail = false;
$.each($('.size_selector'), function(key, selector){
console.log(selector);
var sizes = selector.getElementsByClassName('choose_size');
var module_id = false;
var product_id = false;
for(var i=0; i < sizes.length; i++){
if(sizes[i].classList.contains('selected')){
var module_id = sizes[i].dataset.module_id;
var product_id = sizes[i].dataset.product_id;
}
}
if(product_id == false){
fail = true;
}else{
var product = new Object();
product['product_id'] = product_id;
product['module_id'] = module_id;
products_to_add.push(product);
}
});
if(fail){
alert('Bitte wählen Sie für alle Produkte eine Größe aus');
}else{
for(var i = 0; i < products_to_add.length; i++){
var product_id = products_to_add[i]['product_id'];
var module_id = products_to_add[i]['module_id'];
$.ajax({
type: 'POST',
url: href+"shop_request.php",
data: {request_type: 'modify_shopping_cart', product_id: product_id, modify_type: 'add_item', module_id: module_id, amount:1},
success: function(result){
var result = JSON.parse(result);
console.log(result);
},
async:false
});
}
reload_promocode_area();
reload_shoppingcart_prices();
input = false;
close_popup();
reload_shop_parts();
}
});
}
function change_amount(module_id, product_id, custom_key, amount, bundle_key){
$.post(href+"shop_request.php",{request_type: 'modify_shopping_cart', modify_type: 'change_amount', module_id: module_id, product_id: product_id, custom_key: custom_key, amount: amount, bundle_key: bundle_key}, function(result){
if(result['status']==200) reload_shop_parts();
}, 'json');
}
function remove_product(module_id, product_id, custom_key, bundle_key){
$.post(href+"shop_request.php",{request_type: 'modify_shopping_cart', modify_type: 'remove_product', module_id: module_id, product_id: product_id, custom_key: custom_key, bundle_key: bundle_key}, function(result){
if(result['status']==200){
reload_shop_parts();
}else if(result['status']===250){
var pathname = window.location.pathname;
if(pathname.indexOf('payment')>=0 || pathname.indexOf('warenkorb')>=0 || pathname.indexOf('checkout')>=0){
$(location).attr('href', href);
}else{
reload_shop_parts();
}
}
}, 'json');
}
function remove_promocode(){
$.post(href+"shop_request.php",{request_type: 'delete_promocode'}, function(result){
if(result['status']==200) reload_shop_parts();
}, 'json');
}
function remove_coupon(coupon_code){
$.post(href+"shop_request.php",{request_type: 'remove_coupon', coupon_code: coupon_code}, function(result){
if(result['status']==200) reload_shop_parts();
}, 'json');
}
function reload_shop_parts(){
var pathname = window.location.pathname;
if((pathname.indexOf('payment')>=0 || pathname.indexOf('warenkorb')>=0) && !$( "#choose_size_popup" ).length){
location.reload();
}else{
reload_onpage_shoppingcart();
if($( "#checkout_overview_box" ).length) reload_checkout_overview_box();
}
}
function reload_onpage_shoppingcart(){
$.ajax(
{
type:'post',
url:href+'shop_request.php',
data:{request_type: 'reload_onpage_shopping_cart'},
beforeSend:function()
{
//launchpreloader();
},
complete:function()
{
//stopPreloader();
},
success:function(result)
{
var result = JSON.parse(result);
if(result['status']==200){
document.getElementById('cart_inner').innerHTML = result['message'];
var newsletter_h1 = document.getElementById('onpage_newsletter_h1');
if(newsletter_h1 !== null){
var cart_counter = document.getElementById('cart_counter');
if(typeof cart_counter != 'undefined' && $('#cart_counter').length) {
$('.navi_cart_counter').html(' ('+cart_counter.innerHTML+')');
$('#onpage_cart_h1').css('display', 'block');
$('#onpage_newsletter_h1').css('display', 'none');
$('.side_cart_h1').css('display', 'inline-block');
$('.side_cart_newsletter').css('display', 'none');
}else{
$('.navi_cart_counter').html('');
$('#onpage_cart_h1').css('display', 'none');
$('#onpage_newsletter_h1').css('display', 'block');
$('.side_cart_h1').css('display', 'none');
$('.side_cart_newsletter').css('display', 'inline-block');
}
init_newsletter();
}else{
var cart_counter = document.getElementById('cart_counter');
if(typeof cart_counter != 'undefined' && $('#cart_counter').length) {
$('.navi_cart_counter').html(' ('+cart_counter.innerHTML+')');
$('#onpage_cart_h1').removeClass('empty_card');
}else{
$('.navi_cart_counter').html('');
$('#onpage_cart_h1').addClass('empty_card');
}
}
}
}
});
}
function reload_checkout_overview_box(){
$.post(href+"shop_request.php",{request_type: 'get_checkout_overview'}, function(result){
if(result['status']==200){
$( "#checkout_overview_box" ).html(result['message']);
}
}, 'json');
}
function reload_promocode_area(){
$.ajax(
{
type:'post',
url:href+'shop_request.php',
data:{request_type: 'show_promocode'},
beforeSend:function()
{
//launchpreloader();
},
complete:function()
{
//stopPreloader();
},
success:function(result)
{
var result = JSON.parse(result);
console.log(result);
if(result['status']==200){
document.getElementById('promobox').innerHTML = result['message'];
}
}
});
}
function reload_shoppingcart_prices(){
$.ajax(
{
type:'post',
url:href+'shop_request.php',
data:{request_type: 'reload_shoppingcart'},
beforeSend:function()
{
//launchpreloader();
},
complete:function()
{
//stopPreloader();
},
success:function(result)
{
var result = JSON.parse(result);
console.log(result);
if(result['status']==200){
document.getElementById('shopping_cart_inner').innerHTML = result['message'];
}else if(result['status']==300){
document.getElementById('shopping_cart').innerHTML = result['message'];
}
}
});
$.ajax(
{
type:'post',
url:href+'shop_request.php',
data:{request_type: 'calculate_cart_prices'},
beforeSend:function()
{
//launchpreloader();
},
complete:function()
{
//stopPreloader();
},
success:function(result)
{
var result = JSON.parse(result);
console.log(result);
var cart_price = result['message']['cart_price']-result['message']['promocode_rebate']-result['message']['upselling_rebate'];
cart_price.toFixed(2);
cart_price= cart_price.formatMoney(2, ',', '.');
document.getElementById('cart_price').innerHTML = cart_price+' '+result['message']['currency'];;
}
});
}
function init_upselling_size_choice(){
$('.choose_size').click(function(){
var buttons = $(this).parent().find('button');
$.each(buttons, function(key, button){
button.classList.remove('selected');
});
$(this).addClass('selected');
});
$('#finish_upselling_size_choice').click(function(){
var products_to_add = new Array();
var fail = false;
$.each($('.size_selector'), function(key, selector){
console.log(selector);
var sizes = selector.getElementsByClassName('choose_size');
var module_id = false;
var product_id = false;
for(var i=0; i < sizes.length; i++){
if(sizes[i].classList.contains('selected')){
var module_id = sizes[i].dataset.module_id;
var product_id = sizes[i].dataset.product_id;
}
}
if(product_id == false){
fail = true;
}else{
var product = new Object();
product['product_id'] = product_id;
product['module_id'] = module_id;
products_to_add.push(product);
}
});
if(fail){
alert('Bitte wählen Sie für alle Produkte eine Größe aus');
}else{
for(var i = 0; i < products_to_add.length; i++){
var product_id = products_to_add[i]['product_id'];
var module_id = products_to_add[i]['module_id'];
$.ajax({
type: 'POST',
url: href+"shop_request.php",
data: {request_type: 'modify_shopping_cart', product_id: product_id, modify_type: 'add_item', module_id: module_id, amount:1},
success: function(result){
var result = JSON.parse(result);
console.log(result);
},
async:false
});
}
var upselling_id = $(this).data('upselling_id');
$.post(href+"shop_request.php",{request_type: 'activate_upselling', upselling_id: upselling_id}, function(result){
if(result['status']==200){
input = false;
close_popup();
reload_shop_parts();
}
}, 'json');
}
});
}
$("body").on('submit', '#review_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.post(href+"shop_request.php",formData, function(result){
if(result['status']==200) document.getElementById("review_form").parentNode.innerHTML = result['message'];
}, 'json');
});
function change_carrier(sender){
var carrier_id = sender.options[sender.selectedIndex].value;
$.post(href+"shop_request.php",{request_type: 'change_carrier', carrier_id: carrier_id}, function(result){
if(result['status']==200){
$.post(href+"shop_request.php",{request_type: 'get_checkout_overview'}, function(result){
if(result['status']==200){
document.getElementById('checkout_overview_box').innerHTML = result['message'];
}
}, "json");
}
}, "json");
}
function change_country(sender){
var country_code = sender.options[sender.selectedIndex].value;
$.post(href+"shop_request.php",{request_type: 'change_country', country_code: country_code}, function(result){
if(result['status']==200){
$.post(href+"shop_request.php",{request_type: 'get_checkout_overview'}, function(result){
if(result['status']==200){
document.getElementById('checkout_overview_box').innerHTML = result['message'];
}
}, "json");
$.post(href+"shop_request.php",{request_type: 'get_carrier_select'}, function(result){
if(result['status']==200){
document.getElementById('carrier_select').innerHTML = result['message'];
}
}, "json");
if(result['message']['display_region']){
$('#region_div').show();
}else{
$('#region_div').hide();
}
}
}, "json");
}
function change_onpage_country(sender){
var country_code = sender.options[sender.selectedIndex].value;
$.post(href+"shop_request.php",{request_type: 'change_onpage_country', country_code: country_code}, function(result){
if(result['status']==200){
location.reload();
}else{
alert('Es ist ein Fehler aufgetreten');
}
}, 'json');
}
function change_language(sender){
var country_code = sender.options[sender.selectedIndex].value;
$.post(href+"shop_request.php",{request_type: 'change_onpage_country', country_code: country_code}, function(result){
if(result['status']==200){
location.reload();
}else{
alert('Es ist ein Fehler aufgetreten');
console.log(result);
}
}, 'json');
}
function start_timed_validation(sender){
if(typeof validation_timeout !== 'undefined') clearTimeout(validation_timeout);
validation_timeout = setTimeout(validate_checkout_field, 500, sender, true);
}
function validate_checkout_field(sender, async){
if(!async) $.ajaxSetup({async: false});
$.post(href+"shop_request.php",{request_type: 'validate_checkout_field', field_name: sender.name, input: sender.value}, function(result){
if(result['status'] == 200){
$(sender).parent().removeClass('input_failure');
$(sender).parent().addClass('input_success');
console.log(sender.value);
}else if(result['status']==250){
$(sender).parent().removeClass('input_failure');
$(sender).parent().removeClass('input_success');
}else if(result['status']==300 || result['status']==400){
$(sender).parent().addClass('input_failure');
$(sender).parent().removeClass('input_success');
}
}, 'json');
if(!async) $.ajaxSetup({async: true});
}
$('body').on('click', '#heading', function(e){
$('#onpage_shopping_cart').toggleClass('cart_displayed');
});
$('body').on('click', '#cart_counter', function(e){
$('#onpage_shopping_cart').toggleClass('cart_displayed');
});
$(document).click(function(event) {
if(!$(event.target).closest('#onpage_shopping_cart').length && !$(event.target).closest('#popup').length) {
if($('#onpage_shopping_cart').hasClass("cart_displayed")) {
$('#onpage_shopping_cart').removeClass('cart_displayed');
}
}
})
Number.prototype.formatMoney = function(c, d, t){
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "," : d,
t = t == undefined ? "." : t,
s = n < 0 ? "-" : "",
i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))),
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
// Sticky-Movement in Product Detail View
$(function(){ // document ready
if(document.getElementsByClassName('scroll_stop').length==0) return;
var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
if (!!$('.buying_box_row').first().length && width >=760) { // make sure "#sticky" element exists
var el = $('.buying_box_row').first();
var stickyTop = $('.buying_box_row').first().offset().top; // returns number
var footerTop = $('.scroll_stop').first().offset().top; // returns number
var stickyHeight = $('.buying_box_row').first().height();
var limit = footerTop - stickyHeight - 20;
var first_scroll = true;
$(window).scroll(function(){ // scroll event
var windowTop = $(window).scrollTop() + $('.main').first().height() + 40; // returns number
if(first_scroll){
stickyTop = $('.buying_box_row').first().offset().top;
//stickyHeight = $('.buying_box_row').first().height();
first_scroll = false;
}
stickyHeight = $('.buying_box_row').first().height() + 60;
footerTop = $('.scroll_stop').first().offset().top; // returns number
limit = footerTop - stickyHeight;
/*console.log('StickyHeight: '+stickyHeight);
console.log('StickyTop:'+stickyTop);
console.log('FooterTop:'+footerTop)
console.log('Limit'+limit);
console.log('WindowTop'+windowTop);
console.log('------');*/
if (stickyTop-20 < windowTop){
//el.css({ position: 'fixed', top: 0 });
el.addClass('row_fixed');
}
else {
//el.css('position','static');
el.removeClass('row_fixed');
}
if (limit < windowTop) {
var diff = limit - windowTop + 60 +20+140;
el.css({top: diff});
}
});
}
});
$(function(){ // document ready
if(document.getElementsByClassName('scroll_stop_new').length==0) return;
var el = $('.buying_box_row').first().find('.column_0');
var first_scroll = true;
$(window).resize(function () {
var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
if (width <= 760) {
el.css('position', 'static');
el.css('top', 'none');
}else{
el.css('position', 'absolute');
el.css('top', '10vw');
}
});
$(window).scroll(function(){ // scroll event
var width = (window.innerWidth > 0) ? window.innerWidth : screen.width;
if(width <=760){
el.css('position', 'static');
el.css('top', 'none');
}else{
var windowTop = $(window).scrollTop() + $('.main').first().height() + 40; // returns number
if(first_scroll){
stickyTop = el.offset().top;
first_scroll = false;
}
stickyHeight = el.first().height() + 60;
scroll_stop = $('.scroll_stop_new').first().offset().top; // returns number
limit = scroll_stop - stickyHeight;
/*console.log('StickyHeight: '+stickyHeight);
console.log('StickyTop:'+stickyTop);
console.log('ScrollStop:'+scroll_stop)
console.log('Limit'+limit);
console.log('WindowTop'+windowTop);
console.log('------');*/
if (stickyTop-20 < windowTop){
el.css('position', 'fixed');
if(limit < windowTop){
var diff = scroll_stop - stickyHeight - windowTop -50;// + 60 +20+140;
el.css({ top: 'calc(10vw + '+diff+'px'});
}else{
el.css({ top: 'calc(10vw - 50px)' });
}
}else {
el.css('position', 'absolute');
el.css('top', '10vw');
}
}
});
});
downloadTimer = new Array();
function start_saletimer(end, version){
console.log('start timer '+end+' '+version);
var current_time = new Date().getTime() / 1000;
var dif = end - current_time;
var s = Math.round(dif);
var d = Math.floor(s/86400); //Get whole days
s -= d*86400;
var h = Math.floor(s/3600); //Get whole hours
s -= h*3600;
var m = Math.floor(s/60); //Get remaining minutes
s -= m*60;
var h = h+"";
if (h.length < 2) h = "0" + h;
var m = m+"";
if (m.length < 2) m = "0" + m;
var s = s+"";
if (s.length < 2) s = "0" + s;
console.log($('.'+version+'_countdown .'+version+'_count_days'));
$('.'+version+'_countdown .'+version+'_count_days').html(d);
$('.'+version+'_countdown .'+version+'_count_hrs').html(h);
$('.'+version+'_countdown .'+version+'_count_mins').html(m);
$('.'+version+'_countdown .'+version+'_count_secs').html(s);
console.log('timer');
downloadTimer[version] = setInterval(function(){
if (!updateSeconds(version)) {
location.reload();
}
},1000);
}
function updateSeconds(version){
console.log('update seconds');
var s = parseInt($('.'+version+'_countdown .'+version+'_count_secs').html());
if (s == 0) {
if (!updateMinutes(version)) return false;
s = 59;
} else {
s--;
}
var s = s+"";
if (s.length < 2) s = "0" + s;
$('.'+version+'_countdown .'+version+'_count_secs').html(s);
return true;
}
function updateMinutes(version){
var m = parseInt($('.'+version+'_countdown .'+version+'_count_mins').html());
if (m == 0) {
if (!updateHours(version)) return false;
m = 59;
} else {
m--;
}
var m = m+"";
if (m.length < 2) m = "0" + m;
$('.'+version+'_countdown .'+version+'_count_mins').html(m);
return true;
}
function updateHours(version){
var h = parseInt($('.'+version+'_countdown .'+version+'_count_hrs').html());
if (h == 0) {
if (!updateDays(version)) return false;
h = 23
} else {
h--;
}
var h = h+"";
if (h.length < 2) h = "0" + h;
$('.'+version+'_countdown .'+version+'_count_hrs').html(h);
return true;
}
function updateDays(version){
var d = parseInt($('.'+version+'_countdown .'+version+'_count_days').html());
if (d == 0) return false;
d--;
$('.'+version+'_countdown .'+version+'_count_days').html(d);
return true;
}
function toggle_pictures(type){
if(type == 'small'){
$('#big_pictures_button').removeClass('active');
$('#small_pictures_button').addClass('active');
$('#products_row').addClass('small_pictures');
}else{
$('#big_pictures_button').addClass('active');
$('#small_pictures_button').removeClass('active');
$('#products_row').removeClass('small_pictures');
}
}
customization_pictures = {};
function change_customization_type(customization_id){
$('.customization_settings').slideUp();
if($('#customization_settings_'+customization_id).css('display')!='block'){
$('#customization_settings_'+customization_id).slideDown();
$('#customization_active_'+customization_id).val(1);
$('#customization_active_i_'+customization_id).addClass('active');
}
if($('#picture_type_'+customization_id).val() == 'animation_picture'){
console.log('Animation Picture');
visualization_picture_name = false;
var picture_name = $('#picture_'+customization_id).val();
for(var i = 0; i < pLn; i++){
if(picture_name == pictures[i]){
visualization_frame = i;
break;
}
}
var difference = visualization_frame - imageCounter;
$('#animation_information').css('display', 'none');
turnIntervalId = window.setInterval(turn_to_visualization, 50);
}else{
visualization_picture_name = $('#picture_'+customization_id).val();
visualization_frame = false;
image = new Image();
image.onload = function () {
redraw_canvas('animation_canvas');
//redraw_canvas('animation_canvas_mobile');
$('#animation_information').css('display', 'none');
};
image.src = href + "get_hash_picture.php?n="+visualization_picture_name;
}
}
function activate_customization_type(customization_id){
if($('#customization_active_'+customization_id).val()==1){
$('#customization_active_'+customization_id).val(0);
$('#customization_active_i_'+customization_id).removeClass('active');
$('#customization_settings_'+customization_id).slideUp();
}else{
change_customization_type(customization_id)
}
}
function turn_to_visualization(){
if(imageCounter > visualization_frame){
imageCounter --;
}else if(imageCounter < visualization_frame){
imageCounter ++;
}else{
clearInterval(turnIntervalId);
redraw_canvas('animation_canvas');
//redraw_canvas('animation_canvas_mobile');
return;
}
redraw_canvas('animation_canvas');
//redraw_canvas('animation_canvas_mobile');
}
function redraw_canvas(canvas_id){
if(typeof visualization_picture_name == 'undefined'){
visualization_picture_name = false;
}
if(visualization_picture_name == false){
if(typeof visualization_frame != 'undefined' && imageCounter != visualization_frame){
if(typeof turnIntervalId == 'undefined'){
turnIntervalId = window.setInterval(turn_to_visualization, 50);
return;
}else{
}
}else{
}
image = images[imageCounter];
}
var canvas = document.getElementById(canvas_id);
var context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
var aspect_ratio = image.height / image.width;
if(aspect_ratio > 1.25){
var picture_height = aspect_ratio * 800;
var dy = -(picture_height - 1000)/2
context.drawImage(image,0,dy, 800, picture_height);
}else{
context.drawImage(image,0,0);
}
// Check for all active customizations on this picture
var active_customizations = [];
var image_name = ''
$.each($('.customization_active') , function( index, obj ) {
if(obj.value == 1){
var id = obj.dataset.customization_id;
if(image.src == href+'get_hash_picture.php?n='+$('#picture_'+id).val()){
active_customizations.push(id);
image_name = $('#picture_'+id).val();
}
}
});
// Add also currently selected customization if not already set
$.each(active_customizations, function(index, customization_id){
var text = $('#customization_text_'+customization_id).val();
var font = $('#customization_font_'+customization_id).val();
var fontsize = $('#customization_fontsize_'+customization_id).val();
var color = $('#customization_color_'+customization_id).val();
var x_position = parseFloat($('#customization_x_position_'+customization_id).val())*canvas.width;
var y_position = parseFloat($('#customization_y_position_'+customization_id).val())*canvas.height;
var width = parseFloat($('#customization_width_'+customization_id).val())*canvas.width;
var height = parseFloat($('#customization_height_'+customization_id).val())*canvas.height;
// Debug
/* context.fillStyle = "rgba(255, 255, 255, 0.2)";
context.fillRect(x_position, y_position, width, height);
context.strokeStyle = '#000000';
context.lineWidth = 1.0;
context.strokeRect(x_position,y_position,width,height); */
if(text != ''){
context.font = fontsize+'px '+font;
context.fillStyle = color;
context.textAlign="center";
context.textBaseline = "middle";
if(context.measureText(text).width>width || context.measureText(text).height>height){
alert('Der eingegebene Text ist zu groß');
return;
}
context.fillText(text, x_position+width/2, y_position + height/2, width);
}
});
if(active_customizations.length>0){
customization_pictures[image_name] = canvas.toDataURL('image/jpeg', 0.5);
}else{
delete customization_pictures[image_name];
}
}
function isInArray(value, array) {
return array.indexOf(value) > -1;
}
$("body").on('submit', '#customization_order_form', function(e){
e.preventDefault();
var formData = $(this).serialize();
$.ajax({
type:'post',
url:href+'shop_request.php',
data:formData,
success:function(result){
var result = JSON.parse(result);
if(result['status']==200){
reload_onpage_shoppingcart();
var info = result['facebook_info'];
if(facebook_pixel_active){
fbq('track', 'AddToCart', info);
}
$('.nav_icon_36warenkorb_cart')[0].click();
if(!$('#onpage_shopping_cart').hasClass('cart_displayed')){
$('#onpage_shopping_cart').addClass('cart_displayed');
}
close_popup();
}else if(result['status']==300){
show_popup(''+result['message']+'
');
var info = result['facebook_info'];
if(facebook_pixel_active){
fbq('track', 'AddToCart', info);
}
}
}
});
});
function show_customized_product(key, custom_key){
$.post(href+"shop_request.php",{request_type: 'show_customized_product', key: key, custom_key: custom_key}, function(result){
if(result['status']==200){
show_popup(result['message']);
}else{
alert('Es ist ein Fehler aufgetreten.');
}
}, 'json');
}
function animateCanvas(){
if(break_counter>0){
break_counter --;
}else{
/* var canvas = document.getElementById("animation_canvas");
var context = canvas.getContext("2d");
context.drawImage(images[imageCounter],0,0); */
redraw_canvas('animation_canvas');
//redraw_canvas('animation_canvas_mobile');
if(direction == 0){
if(imageCounter<(pLn-1)){
imageCounter++;
}
if(imageCounter == (pLn-1)){
loops ++;
direction = 1;
break_counter = 4;
}
}else{
if(imageCounter >0){
imageCounter--;
}
if(imageCounter == 0){
direction = 0;
loops ++;
break_counter = 4;
}
}
if(loops == max_loops){
clearInterval(refreshIntervalId);
if(activate_input_bool){
activate_input();
}else{
activate_replay();
}
loops = 4;
}
}
}
function is_touch_device() {
return 'ontouchstart' in window // works on most browsers
|| navigator.maxTouchPoints; // works on IE10/11 and Surface
};
function click_start(e){
clicked = true;
previousX = e.pageX;
$('#animation_information').css('display', 'none');
}
function click_move(e){
if(clicked){
if(pLn<300){
movement = Math.round(600/pLn);
}else{
movement = 2;
}
if(previousX < e.pageX -movement){
previousX = e.pageX;
direction = 0;
animateCanvas();
}
if(previousX > e.pageX +movement){
previousX = e.pageX;
direction = 1;
animateCanvas();
}
}
}
function click_end(e){
clicked = false;
previousX = false;
}
function activate_replay(){
$('#replay_information').css('display', 'block');
}
function replay(){
loops = 0;
$('#replay_information').css('display', 'none');
refreshIntervalId = window.setInterval(animateCanvas, refresh_interval);
}
function activate_input(){
$('#animation_information').css('display', 'block');
if(is_touch_device()){
document.getElementById('animation_canvas').addEventListener('touchstart', function(e) {
e.preventDefault();
var touch = e.touches[0];
click_start(touch);
}, false);
document.getElementById('animation_canvas').addEventListener('touchmove', function(e) {
e.preventDefault();
var touch = e.touches[0];
click_move(touch);
}, false);
document.getElementById('animation_canvas').addEventListener('touchend', function(e) {
e.preventDefault();
var touch = e.touches[0];
click_end(touch);
}, false);
document.getElementById('animation_canvas').addEventListener('touchcancel', function(e) {
e.preventDefault();
var touch = e.touches[0];
click_end(touch);
}, false);
}else{
$('#animation_canvas').mousedown(function(e){
click_start(e);
});
$(document).mouseup(function(e){
click_end(e);
});
$(document).mousemove(function(e){
click_move(e);
});
}
}
// GDPR Functions
function accept_privacy_all(){
privacy_all['time'] = Math.floor(Date.now() / 1000);
var privacy_str = JSON.stringify(privacy_all);
setCookie('privacy', privacy_str, 3600);
hide_privacy_notice(privacy_all);
input = false;
close_popup();
}
function show_privacy_purposes(){
$('#first_privacy').css('display', 'none');
$('#second_privacy').css('display', 'block');
$('#third_privacy').css('display', 'none');
}
function show_general_privacy(){
$('#first_privacy').css('display', 'block');
$('#second_privacy').css('display', 'none');
}
function show_privacy_policy(){
$('#second_privacy').css('display', 'none');
$('#third_privacy').css('display', 'block');
}
function privacy_specific_popup(){
var text = specific_sure+'
';
text += '';
text += '';
show_popup(text);
}
function accept_privacy_specific(){
privacy_specific['time'] = Math.floor(Date.now() / 1000),
$.each(privacy_specific, function( index, value ) {
if(index != 'general'){
if($('#checkbox_'+index).is(':checked')){
privacy_specific[index] = true;
}
}
})
var privacy_str = JSON.stringify(privacy_specific);
setCookie('privacy', privacy_str, 3600);
hide_privacy_notice(privacy_specific);
input = false;
close_popup();
}
function hide_privacy_notice(privacy){
$('body').css('overflow', 'visible');
$('#privacy').css('display', 'none');
init_plugins(privacy);
ga('send', 'event', 'privacy_notice', 'hide', 'Privacy Hidden');
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
var delete_cookie = function(name) {
document.cookie = name + '=; Path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
location.reload();
};
function vote_for_product(collection_id, product_id){
$.post(href+"shop_request.php",{request_type: 'vote_for_product', collection_id: collection_id, product_id: product_id}, function(result){
if(result['status']==200){
}else if(result['status']==250){
show_popup(''+result['message']+'
');
}else if(result['status']!=200){
show_popup(''+result['message']+'
');
}
load_voting_buttons(collection_id);
}, 'json');
}
function vote_for_product_disabled(){
show_popup('Du kannst maximal 5 Stimmen abgeben.
');
}
function load_voting_buttons(collection_id){
$.post(href+"shop_request.php",{request_type: 'load_voting_buttons', collection_id: collection_id}, function(result){
if(result['status']==200){
console.log(result);
$.each(result['message'], function(product_id, button){
$('#voting_button_'+product_id).html(button);
});
}else{
show_popup(''+result['message']+'
');
}
}, 'json');
}
function remove_vote_for_product(collection_id, product_id){
$.post(href+"shop_request.php",{request_type: 'remove_vote_for_product', collection_id: collection_id, product_id: product_id}, function(result){
if(result['status']!=200){
show_popup(''+result['message']+'
');
}
load_voting_buttons(collection_id);
}, 'json');
}