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;
}
// Category menu
function category_menu()
{
modal_bg_show();
$('#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();
$('#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');
}
// 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;
}
function modal_bg_show(p='')
{
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', '');
}
// -------- 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();
}
});
// -------- Search --------
function search_query(n)
{
load_page();
if (n == 1) search_1.submit();
if (n == 2) search_2.submit();
}
// -------- filters menu --------
function filters_menu()
{
modal_bg_show();
$('#prds_filters').animate({left: "0px"}, 200);
$('#modal_bg').click(function () {
filters_menu_close();
});
}
function filters_menu_close()
{
modal_bg_hide();
$('#prds_filters').animate({left: "-400px"}, 200);
$('#modal_bg').unbind('click');
}
// -------- Add cart --------
function add_cart(id, el, lang)
{
el.innerHTML = "";
var request = http_request();
var url = "https://onauto.com.ua/request.php?lang="+lang+"&action=add_cart&id="+id;
request.open("GET", url, true);
request.onreadystatechange = function(){
add_cart_answer(request, id, el);
};
request.send(null);
}
var timeout_cart_add;
function add_cart_answer(request, id, el)
{
if (request.readyState == 4)
{
if (request.status == 200)
{
var text_array = request.responseText.split("[~~]");
if (text_array[0] != "-error-")
{
el.innerHTML = text_array[0];
}
if (text_array[1] != "-none-")
{
document.getElementById("cart").innerHTML = text_array[1];
document.getElementById("cart_count").innerHTML = text_array[2];
document.getElementById("cart_add").innerHTML = text_array[3];
$('#cart_add').slideDown(200);
try
{
clearTimeout(timeout_cart_add);
}
catch (e) {}
timeout_cart_add = setTimeout(function(){ $('#cart_add').slideUp(200); }, 10000);
if (typeof cart_refresh == 'function') cart_refresh();
}
else document.getElementById("cart").innerHTML = "";
// Google Ecommerce
if (typeof add_product_to_cart_google == 'function') add_product_to_cart_google(id, text_array[4]);
}
}
}
// -------- 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://onauto.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)
{
if (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; }
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-9999");
// Прокручиваем окно в началу
if (p != 'noScrollTop') mbd.animate({scrollTop: 0}, 300);
}
}
}
window.addEventListener('resize', function(event){ modal_frame_resize(); });
function modal_frame_resize()
{
if (document.getElementById('modal_box').display != "none")
{
if (document.getElementById('products_imgs_full'))
{
// Задаем высоту блоку в px
$('#products_imgs_full').css("height", (document.body.clientHeight-60)+"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();
}
// -------- 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(300);
}
}
else
{
if (m_ico_page_up == true)
{
m_ico_page_up = false;
$('#ico_page_up').fadeOut(100);
$('#ico_call_back').fadeIn(300);
}
}
}
window.onscroll = scroll_document;
// ----- My garage -----
function my_garage_location(url_main)
{
var url = location.href;
if (url.indexOf('/cars/') >= 0 || url.indexOf('/trucks/') >= 0 || url.indexOf('/search/') >= 0) location.href = url_main;
else
{
url = url.split('/filters/');
url = url[0].split('?');
location.href = url[0];
}
}
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', '');
$(this).removeClass('text_mini');
}});
}
function show_tree(id)
{
if(document.getElementById('list_gr_'+id).style.display == "list-item")
{
document.getElementById('img_m_'+id).style.display = "none";
document.getElementById('img_p_'+id).style.display = "inline";
$('#list_gr_'+id).slideUp(200);
}
else
{
document.getElementById('img_p_'+id).style.display = "none";
document.getElementById('img_m_'+id).style.display = "inline";
$('#list_gr_'+id).slideDown(200);
}
setTimeout(modal_frame_resize, 300);
}
function fast_search_list(id_in, id_box, id_info)
{
var text = document.getElementById(id_in).value;
if (text != "")
{
var els = document.getElementById(id_box).getElementsByTagName('span');
for (var i = 0; i < els.length; i++) els[i].parentNode.className = "hidden";
els = document.getElementById(id_box).getElementsByClassName('sub_list');
for (var i = 0; i < els.length; i++) els[i].style.display = "block";
var s = false;
var els = document.getElementById(id_box).getElementsByTagName('a');
for (var i = 0; i < els.length; i++)
{
var el_parent = els[i].parentNode;
el_parent.className = "list";
if (els[i].innerHTML.toLowerCase().indexOf(text.toLowerCase()) >= 0)
{
el_parent.style.display = "";
s = true;
}
else el_parent.style.display = "none";
}
var info = document.getElementById(id_info);
if (s == false) info.style.display = "block";
else info.style.display = "none";
document.getElementById(id_in).parentNode.getElementsByTagName('span')[0].style.display = "block";
setTimeout(modal_frame_resize, 200);
}
else start_list(id_in, id_box, id_info);
}
function start_list(id_in, id_box, id_info)
{
els = document.getElementById(id_box).getElementsByTagName('a');
for (var i = 0; i < els.length; i++)
{
var el_parent = els[i].parentNode;
el_parent.className = "";
el_parent.style.display = "";
}
var els = document.getElementById(id_box).getElementsByTagName('span');
for (var i = 0; i < els.length; i++) els[i].parentNode.className = "";
els = document.getElementById(id_box).getElementsByClassName('sub_list');
for (var i = 0; i < els.length; i++) els[i].style.display = "";
els = document.getElementById(id_box).getElementsByClassName('gr_plus_');
for (var i = 0; i < els.length; i++) els[i].style.display = "";
els = document.getElementById(id_box).getElementsByClassName('gr_minus_');
for (var i = 0; i < els.length; i++) els[i].style.display = "none";
document.getElementById(id_info).style.display = "none";
document.getElementById(id_in).value = "";
document.getElementById(id_in).parentNode.getElementsByTagName('span')[0].style.display = "";
setTimeout(modal_frame_resize, 200);
}
/* 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()})}})});