$(function () { $(".form .checkbox input[type='checkbox']").on('change', function () { var form = $(this).parents('form'); var products = $(this).parents('.checkboxset').find("input[type='checkbox']"); var price = 0; var oldPrice = 0; var discount = 0; var promo = 0; var dis_prom = 0; var total = 0; var count = 0; var ccount = 0; var iscombo = 0; var italy = 0; var italyprice = 0; var issborpp = 0; var isdiets = 0; var issaladcombo = 0; var issalad = 0; var issaladnew = 0; products.each(function () { /* if (issborpp == 1 && isdiets == 1){ issborpp=0; isdiets=0; issportcombo = 1; document.getElementById('homeworkout').setAttribute('checked', 'checked'); } else { } */ if (this.checked) { ccount++; /* if (this.value == 'combo4'){iscombo=1;} if (iscombo == 1 && ccount >1){count+=4;iscombo=0;} if (this.value == 'salads-autumn-winter' && ccount > 0) { issaladnew = 1; } if (this.value == 'collection-of-salads' && ccount > 0) { issalad = 1; } if (issaladnew == 1 && issalad == 1){ issaladcombo = 1; }*/ /*if (this.value == 'TastesItaly' && ccount > 0) { count += 0; italy = 1; italyprice = Number(($(this).attr('data-price'))); } else { count++; }*/ /* if (issportcombo == 0) */ count++; price += (+$(this).attr('data-price')); /* if (this.value == 'sborpp'){issborpp=1;} if (this.value == 'diets'){isdiets=1;} */ /*price+=(+$(this).attr('data-price'));*/ } }); if (count == 2) { discount = 20; } if (count == 3) { discount = 30; } if (count == 4) { discount = 30; } if (count == 5) { discount = 30; } if (count == 6) { discount = 30; } if (count == 7) { discount = 30; } if (count == 8) { discount = 30; } if (count == 9) { discount = 30; } if (count == 10) { discount = 30; } if (count == 11) { discount = 30; } if (count == 12) { discount = 30; } if (count == 13) { discount = 30; } if (count == 14) { discount = 30; } if (count >= 15) { discount = 30; } if ($('.form .inputset .promo input')[0].promo) { promo = +$('.form .inputset .promo input')[0].promo; } dis_prom = discount + promo; if (dis_prom) { /*if (issaladcombo == 1) price = 1590;*/ oldPrice = price; /* if (italy == 1){ total=Math.floor(((price - Number(italyprice))/100)*(100-dis_prom) + (italyprice/100)*(100-promo) ); } else { total=Math.floor((price/100)*(100-dis_prom)); } */ /*total = Math.floor((price / 100) * (100 - dis_prom));*/ var subtotal = 0; subtotal = (price / 100) * (100 - discount); if (promo !== 0) { subtotal = (subtotal / 100) * (100 - promo); } total = Math.floor(subtotal); form.find('.result .oldPrice').show(0).find('i').text(oldPrice); form.find('.result .discount').show(0).find('i').text(discount); form.find('.result .promokods').show(0).find('i').text(promo); } else { if (issaladcombo == 1) price = 1590; total = price; form.find('.result .oldPrice').hide(0); form.find('.result .discount').hide(0); form.find('.result .promokods').hide(0); } if (promo && discount) { form.find('.result .t_sep').show(0); form.find('.result .t_sep2').show(0); } else { form.find('.result .t_sep').hide(0); form.find('.result .t_sep2').hide(0); } if (promo) { form.find('.result .t_prom').show(0); form.find('.result .t_sep2').show(0); } else { form.find('.result .t_prom').hide(0); form.find('.result .t_sep2').hide(0); } if (discount) { form.find('.result .t_dis').show(0); form.find('.result .t_sep').show(0); } else { form.find('.result .t_dis').hide(0); form.find('.result .t_sep').hide(0); } form.find('.result .price i').text(total); }); $(".form .checkbox input[type='checkbox']").trigger('change'); var RegEmail = /[^\@\.\-\_a-z0-9]+/ig; var RegFullEmail = /[0-9a-z_]+@[0-9a-z_^\.-]+\.[a-z]{2,6}/i; $(".form input[type='email']").on('keyup', function () { var v = $(this).val(); if (v.match(RegEmail)) { $(this).val(v.replace(RegEmail, '')).trigger('keyup'); } }); $(".form .inputset input[name='promo']").on('paste keyup', function () { var v = $(this).val().replace(/^\s*|\s$/i, ''); var btn = $(this).parents('.promo').find('button'); if (v.length > 0) { btn.addClass('active'); } else { btn.removeClass('active'); } }); $(".form .inputset .promo button").on('click', function () { var btn = this; if (btn.ajax) { return false; } var promo = $(this).parents('.promo').find('input').val().replace(/^\s*|\s$/i, ''); $.ajax({ method: 'GET', url: 'https://link.irovalife.ru/pay/assets/promokod.php?promokod=' + promo, cache: false, dataType: 'html', beforeSend: function () { btn.ajax = 1; }, error: function () { btn.ajax = 0; }, complete: function () { btn.ajax = 0; }, success: function (d) { if (d.match(/[^0-9]/ig)) { $('.form .inputset .promo .promo_error').fadeIn(200); } else { $('.form .inputset .promo input')[0].promo = d; } $(".form .checkbox input[type='checkbox']").trigger('change'); } }); return false; }); if ($(".form .inputset .promo input").val().length) { var promo = $(".form .inputset .promo input").val().replace(/^\s*|\s$/i, ''); $.ajax({ method: 'GET', url: 'https://link.irovalife.ru/pay/assets/promokod.php?promokod=' + promo, cache: false, dataType: 'html', success: function (d) { if (d.match(/[^0-9]/ig)) { } else { $('.form .inputset .promo input')[0].promo = d; } } }); } $('.form .inputset .promo .promo_error').on('click', function () { $(this).fadeOut(200); }); $(".form").on('submit', function () { $(this).find('.error').hide(0); var email = $(this).find("input[type='email']").val(); if (!email.match(RegFullEmail)) { $(this).find("input[type='email']").trigger('focus'); $(this).find('.error').text('Некорректный эл. адрес').show(0); return false; } if (!$(this).find(".checkboxset input[type='checkbox']:checked").length) { $(this).find('.error').text('Выберите хотя бы один продукт').show(0); return false; } }); });