// -------- cat popup -------- var cat_popup_this_id = {}; var cat_popup_time_show; var cat_popup_time_hide; function cat_popup_show(id) { 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); }, 300); } function cat_popup_show_time(id) { document.getElementById(id).style.display="block"; 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); }, 300); } function cat_popup_hide_time(id) { document.getElementById(id).style.display="none"; cat_popup_this_id[id] = false; } function cat_popup_stop_hide(id) { try { clearTimeout(cat_popup_time_hide); } catch (e) {} } // -------- All function -------- function http_request() { var request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... request = new XMLHttpRequest(); if (request.overrideMimeType) { request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!request) { alert("Ваш браузер не поддерживает данную функцию!"); return false; } return request; } // -------- Add product in cart -------- function add_product(id_product, lang) { document.getElementById('modal_frame_bg').style.display = "block"; var box = document.getElementById('modal_frame_box'); box.style.width = "500px"; //box.style.height = "220px"; box.style.margin = "-110px 0 0 -250px"; box.innerHTML = '
'; box.style.display = "block"; var request = http_request(); var url = "https://rma.in.ua/request.php?action=add_product&id_product="+id_product+"&lang="+lang; request.open("GET", url, true); request.onreadystatechange = function(){ add_product_answer(request, id_product); }; request.send(null); } function add_product_answer(request, id_product) { if (request.readyState == 4) { if (request.status == 200) { var text_array = request.responseText.split("[~~]"); document.getElementById("modal_frame_box").innerHTML = text_array[0]; document.getElementById("cart_content").innerHTML = text_array[1]; } } } // -------- Search -------- var search_str_input = ""; var search_wait_search_i = 0; var search_timeout; function input_focus(action) { if (action == false && document.getElementById("search_content").style.display == "block") { setTimeout(function(){document.getElementById('search_content').style.display="none";}, 200); } if (action == true && search_str_input != "") { setTimeout(function(){document.getElementById('search_content').style.display="block";}, 200); } } function search_request(cat, lang) { try { clearTimeout(search_timeout); } catch (e) {} search_timeout = setTimeout(function(){ search_request_start(cat, lang) }, 350); } function search_button() { form_search.submit(); } function search_request_start(cat, lang) { var request = http_request(); var str = document.getElementById('search').value; if (str.length < 3) { document.getElementById('search_content').style.display="none"; return false; } if (search_str_input != str) { search_str_input = str; var url = "https://rma.in.ua/request.php?action=search&lang="+lang+"&category="+cat+"&str="+encodeURIComponent(str); request.open("GET", url, true); request.onreadystatechange = function(){ search_answer(request); }; request.send(null); search_wait_search_i++; if (search_wait_search_i > 0) { document.getElementById('search_button').style.display="none"; document.getElementById('search_waiting').style.display="block"; } } } function search_answer(request) { if (request.readyState == 4) { if (request.status == 200) { if (request.responseText != "-") { document.getElementById("search_content").innerHTML = request.responseText; document.getElementById('search_content').style.display="block"; } else { document.getElementById('search_content').style.display="none"; } search_wait_search_i--; if (search_wait_search_i <= 0) { document.getElementById('search_button').style.display="block"; document.getElementById('search_waiting').style.display="none"; } } } } // -------- Compare products -------- function compare_product(id_product, category, action, lang) { var request = http_request(); var url = "https://rma.in.ua/request.php?lang="+lang+"&action=compare_"+action+"&id="+id_product+"&cat="+category; request.open("GET", url, true); request.onreadystatechange = function(){ compare_product_answer(request,id_product); }; request.send(null); } function compare_product_answer(request,id_product) { if (request.readyState == 4) { if (request.status == 200) { var text_array = request.responseText.split("[~~]"); document.getElementById("compare_"+id_product).innerHTML = text_array[0]; var rows = document.getElementsByTagName('span'); for (var i = 0; i < rows.length; i++) { if (rows[i] && rows[i].id == 'compare_link') rows[i].innerHTML = text_array[1]; } } } } // -------- Modal frame -------- function modal_frame_show(url) { document.getElementById('modal_frame_bg').style.display = "block"; //$('#modal_frame_bg').fadeIn(200); var request = http_request(); request.open("GET", "https://rma.in.ua/request.php?"+url, true); request.onreadystatechange = function(){ modal_frame_answer(request); }; request.send(null); } function modal_frame_answer(request) { if (request.readyState == 4) { if (request.status == 200) { var text_array = request.responseText.split("[~~]"); if (text_array[0] == 'close') { modal_frame_hide(); return; } var box = document.getElementById('modal_frame_box'); box.style.width = Number(text_array[1])+"px"; box.style.margin = "-"+Math.round(Number(text_array[2])/2)+"px 0 0 -"+Math.round(Number(text_array[1])/2)+"px"; box.innerHTML = text_array[3]; box.style.display = "block"; //$('#modal_frame_box').fadeIn(200); } else modal_frame_hide(); } } function modal_frame_form_submit(form, url) { //var inputs = form.elements; 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); } } modal_frame_show(url); } function modal_frame_hide() { document.getElementById('modal_frame_bg').style.display="none"; document.getElementById('modal_frame_box').style.display="none"; //$('#modal_frame_box').fadeOut(300); //$('#modal_frame_bg').fadeOut(300); } // -------- Button up (page scroll) -------- function scroll_document() { var scrolled_y = window.pageYOffset || document.documentElement.scrollTop; var ob = document.getElementById("box_button_up").style; if (scrolled_y > 820) { if (ob.display == "none") { ob.display = "block"; animate_button_up(0); } } else if (ob.display == "block") ob.display = "none"; } function animate_button_up(opacity) { if (opacity == 0) opacity = 0; opacity += 10; if (opacity >= 100) opacity = 100; else button_up_timeout_id = setTimeout(function(){ animate_button_up(opacity); }, 10); var ob = document.getElementById("box_button_up").style; ob.opacity = opacity / 100; ob.filter = 'alpha(opacity='+ opacity +')'; } function animate_page_scroll(scroll_d, scroll) { if (scroll_d == 0) { scroll = window.pageYOffset || document.documentElement.scrollTop; scroll_d = scroll/20; } scroll -= scroll_d; if (scroll < 0) scroll = 0; else setTimeout(function(){ animate_page_scroll(scroll_d, scroll); }, 15); window.scrollTo(0,scroll); } window.onscroll = scroll_document; // -------- Payment type -------- function box_payment_type() { if (document.getElementById('box_payment').style.display == "none") { document.getElementById('box_payment_arrow').style.backgroundPosition = "bottom right"; document.getElementById('box_payment').style.display = "block"; //$('#box_payment').fadeIn(100); } else { document.getElementById('box_payment_arrow').style.backgroundPosition = "top right"; document.getElementById('box_payment').style.display = "none"; //$('#box_payment').fadeOut(100); } } function box_payment_type_checked(value) { box_payment_type(); document.cookie = "PAYMENT_TYPE="+value+"; path=/;"; location.href = location.href; //location.reload(); }