function http_request()
{
var request = false;
if (window.XMLHttpRequest)
{
request = new XMLHttpRequest();
if (request.overrideMimeType) request.overrideMimeType('text/html');
}
else if (window.ActiveXObject)
{
try { request = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{
try { request = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {}
}
}
if (!request) return false;
return request;
}
// -------- Button up (page scroll) --------
var m_ico_page_up = false;
function scroll_document()
{
var scrolled_y = window.pageYOffset || document.documentElement.scrollTop;
if (scrolled_y > 900)
{
if (m_ico_page_up == false)
{
m_ico_page_up = true;
//$('#ico_call_back').fadeOut(100);
$('#ico_page_up').fadeIn(200);
}
}
else
{
if (m_ico_page_up == true)
{
m_ico_page_up = false;
$('#ico_page_up').fadeOut(200);
//$('#ico_call_back').fadeIn(300);
}
}
}
window.onscroll = scroll_document;
// Category menu
function category_menu()
{
//modal_bg_show();
$('#category_box').animate({scrollTop: 0}, 10);
setTimeout(function(){ modal_bg_show(); }, 200);
$('#category_box').animate({left: "0px"}, 200);
$('#modal_bg').click(function () {
category_menu_close();
});
}
function category_menu_close()
{
modal_bg_hide();
$('#category_box').animate({left: "-450px"}, 200);
$('#modal_bg').unbind('click');
}
// Category popup
var cat_popup_this_id = {};
var cat_popup_time_show;
var cat_popup_time_hide;
function cat_popup_show(id, el)
{
if ($('#category_box').css('position') == "fixed") return;
if (!cat_popup_this_id[id]) cat_popup_this_id[id] = false;
if (cat_popup_this_id[id] == true)
{
try { clearTimeout(cat_popup_time_hide); }
catch (e) {}
}
else cat_popup_time_show = setTimeout(function(){ cat_popup_show_time(id, el); }, 300);
}
function cat_popup_show_time(id, el)
{
//var elp = $('#cat_popup_'+id);
//el.addClass("cat_active");
$('#cat_item_'+id).addClass("active");
$('#cat_popup_'+id).slideDown(200);
cat_popup_this_id[id] = true;
}
function cat_popup_hide(id)
{
if (cat_popup_this_id[id] == false)
{
try { clearTimeout(cat_popup_time_show); }
catch (e) {}
}
else cat_popup_time_hide = setTimeout(function(){ cat_popup_hide_time(id); }, 200);
}
function cat_popup_hide_time(id)
{
//var elp = $('#cat_popup_'+id);
//el.removeClass("cat_active");
$('#cat_item_'+id).removeClass("active");
$('#cat_popup_'+id).slideUp(200);
cat_popup_this_id[id] = false;
}
function cat_popup_stop_hide(id)
{
try { clearTimeout(cat_popup_time_hide); }
catch (e) {}
}
// Telephone list
function telephone_list_show()
{
//modal_bg_show();
setTimeout(function(){ modal_bg_show(); }, 200);
$('#head_telephone_list').slideDown(200);
$('#modal_bg').click(function () {
telephone_list_hide();
});
}
function telephone_list_hide(p=true)
{
if (p == true) modal_bg_hide();
$('#head_telephone_list').slideUp(200);
$('#modal_bg').unbind('click');
}
// Payment type
function box_payment_type()
{
setTimeout(function(){ modal_bg_show(); }, 200);
$('#payment_box').slideDown(200);
$('#modal_bg').click(function () {
modal_bg_hide();
$('#payment_box').slideUp(200);
$('#modal_bg').unbind('click');
});
}
function box_payment_type_checked(value)
{
$('#modal_bg').unbind('click');
document.cookie = "PAYMENT_TYPE="+value+"; path=/;";
location.href = location.href;
}
// Modal background
function scroll_width()
{
var div = document.createElement('div');
div.style.overflowY = 'scroll';
div.style.width = '50px';
div.style.height = '50px';
document.body.appendChild(div);
var scrollWidth = div.offsetWidth - div.clientWidth;
div.remove();
return scrollWidth;
}
var html_img_wait = "";
function modal_bg_show(p='')
{
var img = $('#load_page');
if (p == 'load') $('#load_page').css('display', 'block');
else $('#load_page').css('display', 'none');
$('#modal_bg').fadeIn(200);
var scrollwidth = scroll_width();
var el = $('body');
el.addClass('modal_open');
el.css('padding-right', scrollwidth+'px');
$('#modal_box>div').css('padding-right', scrollwidth+'px');
$('#ico_page_up, #ico_call_back').css('right', 20+scrollwidth+'px');
}
function modal_bg_hide()
{
$('#modal_bg').fadeOut(200);
var el = $('body');
el.removeClass('modal_open');
el.removeAttr('style');
$('#modal_box>div').css('padding-right', '');
$('#ico_page_up, #ico_call_back').css('right', '');
}
// -------- Modal frame --------
function modal_frame_show(url, p='')
{
modal_bg_show('load');
// Прячем окно
if (p != 'noScrollTop') $('#modal_box').fadeOut(300);
var request = http_request();
request.open("GET", "https://ledmir.com.ua/request.php?"+url, true);
request.onreadystatechange = function(){ modal_frame_answer(request, p); };
request.send(null);
}
function modal_frame_answer(request, p)
{
if (request.readyState == 4 && request.status == 200)
{
var text_array = request.responseText.split("[~~]");
if (text_array[0] == 'close') { modal_frame_hide(); return; }
if (text_array[0] == 'location') { location.href = text_array[1]; return; }
if (text_array[0] == 'replace') { document.location.replace(text_array[1]); return; }
var box = document.getElementById('modal_box_content');
box.style.maxWidth = Number(text_array[1])+"px";
box.style.height = "auto";
box.innerHTML = text_array[2];
// Показываем окно
$('#load_page').css('display', 'none');
var mb = $('#modal_box');
mb.stop(true, true);
mb.fadeIn(300);
// Проверяем помещается ли окно по высоте
var mbd = $('#modal_box>div');
if (document.body.clientHeight < $(box).outerHeight()+10)
{
mbd.css("display","block");
mbd.css('padding-left', scroll_width()+'px');
}
else
{
mbd.css("display","table-cell");
mbd.css('padding-left', '');
}
$("#tel_mask").mask("+38 (999) 999-99-99");
// Прокручиваем окно в началу
if (p != 'noScrollTop') mbd.animate({scrollTop: 0}, 300);
if (p == 'compare')
{
if (text_array[3])
{
if (text_array[3] == "-") text_array[3] = "";
document.getElementById("compare_count").innerHTML = text_array[3];
document.getElementById("compare_count2").innerHTML = text_array[3];
}
if (text_array[4])
{
var ids = text_array[4].split(",");
for (var i = 0; i < ids.length; i++)
{
$(".button_p2[data-compare-prid='"+ids[i]+"'] .ico_compare_a").attr('class', 'ico_compare');
}
}
}
}
}
// -------- Load page --------
function load_page()
{
localStorage['load_page'] = "true";
modal_bg_show('load');
$('#modal_box').fadeOut(200);
setTimeout(function(){ modal_bg_hide(); }, 15000);
}
localStorage['load_page'] = "false";
window.addEventListener('storage', function(e) {
if (e.key == 'load_page')
{
if (localStorage['load_page'] == "false") modal_bg_hide();
}
});
window.addEventListener('resize', function(event){ modal_frame_resize(); });
function modal_frame_resize()
{
if (document.getElementById('modal_box').style.display != "none")
{
if (document.getElementById('products_imgs_full'))
{
// Задаем высоту блоку в px
$('#products_imgs_full').css("height", (document.body.clientHeight-100)+"px");
}
// Проверяем помещается ли окно по высоте
var box = document.getElementById('modal_box_content');
var mbd = $('#modal_box>div');
if (document.body.clientHeight < $(box).outerHeight()+10)
{
mbd.css("display","block");
mbd.css('padding-left', scroll_width()+'px');
}
else
{
mbd.css("display","table-cell");
mbd.css('padding-left', '');
}
}
}
function modal_frame_form_submit(form, url, p='')
{
var inputs = document.getElementById(form).elements;
for (var i = 0; i < inputs.length; i++)
{
var input = inputs[i];
if (input.name && (input.type !== 'radio' || input.checked))
{
url = url+"&"+input.name+"="+encodeURIComponent(input.value);
}
}
if (p == 'add_url') url = url+"&url="+encodeURIComponent(location.href);
modal_frame_show(url);
}
function modal_frame_hide()
{
$('#modal_box').fadeOut(200);
modal_bg_hide();
}
// -------- Block text mini --------
function box_text_mini_init(max_height, id)
{
var e_box = document.getElementById(id);
var e_full = document.getElementById(id+'_full')
var height = $('#'+e_box.id+'>div').height();
if (height <= max_height)
{
$(e_full).css('display', 'none');
$(e_box).removeClass('text_mini');
}
else $(e_box).css('height', max_height+'px');
}
function box_text_mini_full(id)
{
var e_box = document.getElementById(id);
var e_full = document.getElementById(id+'_full')
$(e_full).css('display', 'none');
$('#'+id).animate({height: $('#'+id+'>div').height()+'px'}, {duration:300, complete:function(){
$(this).css('height', 'auto');
$(this).css('padding-top', '0.1px');
$(this).removeClass('text_mini');
}});
}
// -------- Add cart --------
var timeout_modal_mes;
function add_cart(id, el, lang, q=1)
{
el.innerHTML = "";
var request = http_request();
var url = "https://ledmir.com.ua/request.php?lang="+lang+"&action=add_cart&id="+id+"&q="+q;
request.open("GET", url, true);
request.onreadystatechange = function(){
add_cart_answer(request, id, el);
};
request.send(null);
}
function add_cart_answer(request, id, el)
{
if (request.readyState == 4 && request.status == 200)
{
var text_array = request.responseText.split("[~~]");
if (text_array[0] != "-error-")
{
el.innerHTML = text_array[0];
if (document.getElementById("button_product_1")) document.getElementById("button_product_1").innerHTML = text_array[0];
if (document.getElementById("button_product_2")) document.getElementById("button_product_2").innerHTML = text_array[0];
}
if (text_array[1] != "-none-")
{
document.getElementById("cart_count").innerHTML = text_array[1];
document.getElementById("modal_mes").innerHTML = text_array[2];
$('#modal_mes').slideDown(200);
try
{
clearTimeout(timeout_modal_mes);
}
catch (e) {}
timeout_modal_mes = setTimeout(function(){ $('#modal_mes').slideUp(200); }, 10000);
if (typeof cart_refresh == 'function') cart_refresh();
// Google Ecommerce
if (typeof add_product_to_cart_google == 'function') add_product_to_cart_google(id, text_array[3]);
}
else document.getElementById("cart_count").innerHTML = "";
}
}
// -------- Compare --------
function product_compare(id, el, lang, cat)
{
el.innerHTML = "";
var request = http_request();
var url = "https://ledmir.com.ua/request.php?lang="+lang+"&action=compare&id="+id+"&cat="+cat;
request.open("GET", url, true);
request.onreadystatechange = function(){
product_compare_answer(request, id, el);
};
request.send(null);
}
function product_compare_answer(request, id, el)
{
if (request.readyState == 4 && request.status == 200)
{
var text_array = request.responseText.split("[~~]");
el.innerHTML = text_array[0];
var ico = document.getElementById("compare_count");
ico.innerHTML = text_array[1];
//ico.parentElement.href = text_array[2];
ico = document.getElementById("compare_count2");
ico.innerHTML = text_array[1];
//ico.parentElement.href = text_array[2];
if (text_array[2] != "-none-")
{
document.getElementById("modal_mes").innerHTML = text_array[2];
$('#modal_mes').slideDown(200);
try
{
clearTimeout(timeout_modal_mes);
}
catch (e) {}
timeout_modal_mes = setTimeout(function(){ $('#modal_mes').slideUp(200); }, 5000);
}
}
}
// -------- Wish --------
function product_wish(id, el, lang)
{
el.innerHTML = "";
var request = http_request();
var url = "https://ledmir.com.ua/request.php?lang="+lang+"&action=wish&id="+id;
request.open("GET", url, true);
request.onreadystatechange = function(){
product_wish_answer(request, id, el);
};
request.send(null);
}
function product_wish_answer(request, id, el)
{
if (request.readyState == 4 && request.status == 200)
{
var text_array = request.responseText.split("[~~]");
el.innerHTML = text_array[0];
document.getElementById("wish_count").innerHTML = text_array[1];
document.getElementById("wish_count2").innerHTML = text_array[1];
if (text_array[2] != "-none-")
{
document.getElementById("modal_mes").innerHTML = text_array[2];
$('#modal_mes').slideDown(200);
try
{
clearTimeout(timeout_modal_mes);
}
catch (e) {}
timeout_modal_mes = setTimeout(function(){ $('#modal_mes').slideUp(200); }, 3000);
}
}
}
// -------- Filters menu --------
function filters_menu()
{
//modal_bg_show();
setTimeout(function(){ modal_bg_show(); }, 200);
$('#prds_filters').animate({left: "0px"}, 200);
$('#modal_bg').click(function () {
filters_menu_close();
});
}
function filters_menu_close()
{
modal_bg_hide();
$('#prds_filters').animate({left: "-450px"}, 200);
$('#modal_bg').unbind('click');
}
// input_number
function input_number_control(el, m, p=0)
{
var q = el.value.replace(/[^0-9]/g, '');
if (p == 0)
{
q = parseInt(q, 10) | 0;
if (q == 0) q = m;
q = Math.ceil(q/m)*m;
if (q > 500) q = 500;
if (typeof form_submit_timeout == 'function') form_submit_timeout();
}
else setTimeout(function(){ input_number_control(el, m); }, 1000);
el.value = q;
}
function input_number(c, input, m)
{
var el = document.getElementById(input);
var q = parseInt(el.value, 10) | 0;
if (q == 0) q = m;
if (c == 'p' && q <= 500-m) q = q+m;
if (c == 'm' && q >= m*2) q = q-m;
q = Math.ceil(q/m)*m;
el.value = q;
if (typeof form_submit_timeout == 'function') form_submit_timeout();
}
/* jQuery Masked Input Plugin | Version: 1.4.1 */
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b,c=navigator.userAgent,d=/iphone/i.test(c),e=/chrome/i.test(c),f=/android/i.test(c);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(c,g){var h,i,j,k,l,m,n,o;if(!c&&this.length>0){h=a(this[0]);var p=h.data(a.mask.dataName);return p?p():void 0}return g=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},g),i=a.mask.definitions,j=[],k=n=c.length,l=null,a.each(c.split(""),function(a,b){"?"==b?(n--,k=a):i[b]?(j.push(new RegExp(i[b])),null===l&&(l=j.length-1),k>a&&(m=j.length-1)):j.push(null)}),this.trigger("unmask").each(function(){function h(){if(g.completed){for(var a=l;m>=a;a++)if(j[a]&&C[a]===p(a))return;g.completed.call(B)}}function p(a){return g.placeholder.charAt(a=0&&!j[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);n>c;c++)if(j[c]){if(!(n>d&&j[c].test(C[d])))break;C[c]=C[d],C[d]=p(d),d=q(d)}z(),B.caret(Math.max(l,a))}}function t(a){var b,c,d,e;for(b=a,c=p(a);n>b;b++)if(j[b]){if(d=q(b),e=C[b],C[b]=c,!(n>d&&j[d].test(e)))break;c=e}}function u(){var a=B.val(),b=B.caret();if(o&&o.length&&o.length>a.length){for(A(!0);b.begin>0&&!j[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beging)&&g&&13!==g){if(i.end-i.begin!==0&&(y(i.begin,i.end),s(i.begin,i.end-1)),c=q(i.begin-1),n>c&&(d=String.fromCharCode(g),j[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),f){var k=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(k,0)}else B.caret(e);i.begin<=m&&h()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&n>c;c++)j[c]&&(C[c]=p(c))}function z(){B.val(C.join(""))}function A(a){var b,c,d,e=B.val(),f=-1;for(b=0,d=0;n>b;b++)if(j[b]){for(C[b]=p(b);d++e.length){y(b+1,n);break}}else C[b]===e.charAt(d)&&d++,k>b&&(f=b);return a?z():k>f+1?g.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,n)):z():(z(),B.val(B.val().substring(0,f+1))),k?b:l}var B=a(this),C=a.map(c.split(""),function(a,b){return"?"!=a?i[a]?p(b):a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return j[b]&&a!=p(b)?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(b);var a;E=B.val(),a=A(),b=setTimeout(function(){B.get(0)===document.activeElement&&(z(),a==c.replace("?","").length?B.caret(0,a):B.caret(a))},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on("input.mask paste.mask",function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),h()},0)}),e&&f&&B.off("input.mask").on("input.mask",u),A()})}})});