var currentPage = false;
var accsShown = false;
var denyProductPlacements = false;
var dadata_token = "01a4d59335a0409ceb4a11700b0b65edc97a0dbe";
var countryData;
function on_mousestop(callback){
var callback = typeof callback !== 'undefined' ? callback : false;
if(jQuery().mousestop){
if(callback){ callback(); }
}else{
setTimeout(function(){on_mousestop(callback)},250);
}
}
function on_orientationchange(callback){
var callback = typeof callback !== 'undefined' ? callback : false;
if(jQuery().orientationchange){
if(callback){ callback(); }
}else{
setTimeout(function(){on_orientationchange(callback)},250);
}
}
/*
function on_sly(callback){
var callback = typeof callback !== 'undefined' ? callback : false;
if(jQuery().sly){
if(callback){ callback(); }
}else{
setTimeout(function(){on_sly(callback)},250);
}
}
*/
function on_visible(callback){
var callback = typeof callback !== 'undefined' ? callback : false;
if(jQuery().visible){
if(callback){ callback(); }
}else{
setTimeout(function(){on_visible(callback)},250);
}
}
function on_history(callback){
var callback = typeof callback !== 'undefined' ? callback : false;
if(History.getState==undefined){
setTimeout(function(){on_history(callback)},250);
}else{
if(callback){ callback(); }
}
}
var deviceGalleryTO;
function deviceGalleryLazy(){
lazyLoadImgs();
clearTimeout(deviceGalleryTO);
deviceGalleryTO = setTimeout(deviceGalleryLazy,1000);
}
$(window).on('load',function(){
setTimeout(lazyLoadImgs,250);
$(window).on('scrollstop scrollleft resize scroll checkLazyImg',lazyLoadImgs);
setTimeout(lazyLoadDivs,250);
$(window).on('scrollstop scrollleft resize scroll',lazyLoadDivs);
if(mobile==1){
deviceGalleryTO = setTimeout(deviceGalleryLazy,1000);
}
$('#carSame').on('jcarousel:animateend', lazyLoadImgs);
$(".jsonProductContainer").each(function(i,el){
loadJsonProduct_standalone(el);
});
$(document).on("click",".chooseModButton",function(){
$(this).fadeOut();
$(this).parent().parent().find(".variants").slideDown();
});
});
var jsonProduct_standalone_firstload=true;
var toAdd=500;
function loadJsonProduct_standalone(el){
if(jsonProduct_standalone_firstload==true){
jsonProduct_standalone_firstload = false;
attrs = "?jsonLoad=1&getHeaders=1&summary=1";
}else{
attrs = "?jsonLoad=1&summary=1";
}
url = $(el).attr('data-href')+attrs;
$.ajax({
type: 'GET',
url: url,
success: function(data){
$(el).html(data).addClass('noOpacity');
setTimeout(function(){
setTimeout(function(){ $(el).removeClass('noOpacity'); },350);
productOnPageLoad('.jsonProductContainer.product_'+$(el).attr('data-pid'));
onceOnLoad();
setTimeout(function(){ $('.jsonProductContainer.product_'+$(el).attr('data-pid')).removeClass('placeholder').fadeIn(); toAdd = toAdd + 50},toAdd);
},250);
},
async: true,
dataType: "json"
});
}
function lazyLoadImgs(){
on_visible(function(){
$('img.lazy:not(.loaded),.mce-content-body img').each(function(i,el){
if($(el).hasClass('full')){ halfVisiblility = false; }else{ halfVisiblility = true; }
if($(el).visible(halfVisiblility)==true){
$(el).attr('src',$(el).attr('data-src')).addClass('loaded');
}
});
});
}
function lazyLoadDivs(){
on_visible(function(){
$('div.lazyDiv:not(.loaded)').each(function(i,el){
if($(el).hasClass('full')){ halfVisiblility = false; }else{ halfVisiblility = true; }
if($(el).visible(halfVisiblility)==true){
$(el).addClass('loaded');
$.ajax({
type: 'GET',
url: $(el).attr('data-href'),
success: function(data){
$(el).html(data);
$(el).addClass('placeholder-cleared');
},
async: true,
dataType: "json"
});
}
});
});
}
function loadLater(filename, filetype, timeout, callback, rel, as){
setTimeout(function(){load(filename,filetype,callback,rel,as);},timeout);
}
function load(filename, filetype, callback, rel, as){
if (filetype=="js"){ //if filename is a external JavaScript file
if($("script[src='"+filename+"']").attr('type')==undefined){
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
}
else if (filetype=="css" || filetype=="link"){ //if filename is an external CSS file
if($("link[href='"+filename+"']").attr('type')==undefined){
var fileref=document.createElement("link")
fileref.setAttribute("href", filename)
fileref.setAttribute("type", "text/css")
fileref.setAttribute("rel", "stylesheet")
}
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
// console.log(filename+' loaded');
if(typeof callback!=='undefined'){ setTimeout(callback,250); }
}
function globalScriptsLoad(callback){
var callback = typeof callback !== 'undefined' ? callback : false;
load("/cache/js/jquery_libs.min.js","js");
load("/cache/js/libs/jquery.visible.js","js");
// loadLater("https://code.jivosite.com/widget/qTzNG0GjFP","js",4000);
loadLater("/cache/js/tawk.js?v=1","js",4000);
loadLater("/cache/js/site_cart_widget.js","js",2000);
if(currentPage=='cart'){
load("/cache/js/site_delivery.js","js",function(){
// load("/cache/js/site_region_run_later.js?v=3.952"+Math.random(),"js");
load("/cache/js/site_region_run_later.js?v=3.957","js");
});
}else{
loadLater("/cache/js/site_delivery.js","js",1500,function(){
// load("/cache/js/site_region_run_later.js?v=3.952"+Math.random(),"js");
load("/cache/js/site_region_run_later.js?v=3.956","js");
});
}
// load("/cache/css/fontawesome.css","css",false);
// if (darkmode==1) {
// load("/cache/css/menuicons-sprite-linked_wt.css","css",false);
// }else{
// load("/cache/css/menuicons-sprite-linked.css","css",false);
// }
if(mobile){
load("/cache/js/libs/jquery.migrate.js","js");
load("/cache/js/libs/jquery.mobile.custom2.min.js","js");
load("/cache/js/window_mobile.js","js");
}
if(currentPage=='product'){
// loadLater("/cache/css/content.min.css","css",1000);
loadLater("/assets/css/content.min.css","css",1000);
// load("/js/product.js","js");
}
if(callback!=false){ callback(); }
}
function addCountryFunctionality(){
if(countryData['countryCode']=='ru'){
$(".countryIcon").addClass('def');
}else{
$(".countryIcon").removeClass('def');
$(".countryIcon img").attr('src','/assets/flags/'+countryData['countryCode']+'.svg').removeClass('hidden');
}
$(".countryIcon img").attr('title',countryData['country']);
$(".countryIcon img").attr('alt',countryData['country']);
$(".countryIcon .title").html(countryData['country']);
$(".countryIcon").addClass('showed');
countryCode = countryData['countryCode'];
$(".hdr .inlineEl.city").hide();
$(".hdr .inlineEl.showroomLink").hide();
$(".deliveryBlock .changeCity").hide();
$(".deliveryBlock .row.selfservice").hide();
$(".deliveryBlock .row .d_address").hide();
$(".deliveryBlock").addClass('international');
$(".deliveryBlock .currentCity").html(countryData['country']);
$("body.section_cart .wrapper .cartCityContainer").addClass('hidden');
$("body.section_cart .wrapper .cartCityContainer textarea[name=city]").val(countryData['country']);
$("body.section_cart .wrapper .deliveryBlock .row.selfservice").addClass('hidden');
$("body.section_cart .wrapper .deliveryBlock .row.door .typeTitle").html(countryData['country']+': международная доставка');
$("body.section_cart .deliveryAddressBlock > .newOne").addClass('hidden');
$("body.section_cart #shipping_address").val(countryData['country']);
$("body.section_cart .deliveryAddressBlock > .textarea small").html('Укажите полный адрес, город, индекс и другие детали для международной доставки
Доставка осуществляется до подьезда');
$("body.section_cart .stepContent.step3 .countrySelector").html(''+countryData['country']+' Переключить на доставку по России');
$("body.section_cart #s_shipCity").hide();
setNewRegion('Москва','7700000000000000000000000','0c5b2444-70a0-4932-980c-b4dc0d3f02b5');
}
var countryTO;
function showCountrySelect(){
$.ajax({
type: 'GET',
url: '/json/country.php',
success: function(result){
off_left = $(".countryIcon").offset().left-10;
if($(".countrySelect").width()+off_left>$(window).width()){
$(".countrySelect").css({'left':'auto','right':10,'top':$(".countryIcon").offset().top-15});
}else{
$(".countrySelect").css({'right':'auto','left':off_left,'top':$(".countryIcon").offset().top-15});
}
$(".countrySelect").fadeIn('fast').find("input[name=country]").focus();
$(".countrySelect .results").html(result['html']);
},
});
}
$(window).on('load',function(){
$(document).on('click',".contryDismiss",function(e){
e.preventDefault();
$.ajax({
type: 'GET',
url: '/json/user.region.php?get_region=1',
success: function(result){
window.location.reload();
},
});
return false;
});
$(document).on('keyup',".countrySelect input[name=country]",function(e){
e.preventDefault();
clearTimeout(countryTO);
that = this;
countryTO = setTimeout(()=>{
$.ajax({
type: 'GET',
url: '/json/country.php?string='+$(that).val(),
success: function(result){
$(".countrySelect .results").html(result['html']);
},
});
},250);
return false;
});
$(document).on('click',".countryIcon",function(e){
that = this;
e.preventDefault();
showCountrySelect();
return false;
});
$(document).on('click',".countrySelect .close",function(e){
e.preventDefault();
$(".countrySelect").hide();
return false;
});
$(document).on('click',".countrySelect .row",function(e){
e.preventDefault();
that = this;
if($(that).attr('data-code')=='ru'){
url = '?set_home_region=1';
}else{
url = '?set_region='+$(that).attr('data-code');
}
$.ajax({
type: 'GET',
url: '/json/user.region.php'+url,
success: function(result){
if(result['status']=='success'){
if($(that).attr('data-code')=='ru'){
window.location.reload();
}else{
countryData = result['response'];
checkRegionConfirm(countryData);
addCountryFunctionality();
$(".countrySelect").hide();
}
}
},
});
return false;
});
$(document).on('click',".changeCountry",function(e){
e.preventDefault();
$.ajax({
type: 'GET',
url: '/json/user.region.php?get_region=1',
success: function(result){
if(result['status']=='success'){
countryData = result['response'];
showCountrySelect();
window.scrollTo(0, 0);
}
},
});
return false;
});
$(document).on('click',".countryNote .cta, .countryNote a.close",function(e){
e.preventDefault();
$(".countryNote").slideUp();
if($(this).hasClass('dismiss')==true || $(this).hasClass('close')){
$.ajax({
type: 'GET',
url: '/json/user.region.php?set_home_region=1',
success: function(result){
if(result['status']=='success'){
countryData = result['response'];
checkRegionConfirm(countryData);
if($(".countryIcon").hasClass('showed')){
window.location.reload();
}else{
window.scrollTo(0, 0);
}
}
},
});
}else{
$.ajax({
type: 'GET',
url: '/json/user.region.php?confirm_region=1',
success: function(result){
if(result['status']=='success'){
countryData = result['response'];
checkRegionConfirm(countryData);
}
},
});
addCountryFunctionality();
}
return false;
});
globalScriptsLoad();
});
$(document).on("keyup", function(e){
$(document).trigger("press_"+e.keyCode);
console.log(e.keyCode);
});