// -------- 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) { 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 = "http://mozzi.com.ua/request.php?action=add_product&id_product="+id_product; 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 == true && document.getElementById("search").value == "Поиск...") { document.getElementById("search").value = ""; document.getElementById("search").className = "search_input_focus"; } if (action == false && document.getElementById("search").value.length == 0) { document.getElementById("search").value = "Поиск..."; document.getElementById("search").className = "search_input"; } 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) { try { clearTimeout(search_timeout); } catch (e) {} search_timeout = setTimeout(function(){ search_request_start(cat) }, 350); } function search_button() { if (document.getElementById("search").className == "search_input_focus") form_search.submit(); } function search_request_start(cat) { 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 = "http://mozzi.com.ua/request.php?action=search&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) { var request = http_request(); var url = "http://mozzi.com.ua/request.php?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"; var request = http_request(); request.open("GET", "http://mozzi.com.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"; } 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"; } // -------------- Animate -------------- function crs_move_right(width_block, width_space, count, el_id, length) { var elem = document.getElementById(el_id); var position = parseInt(elem.style.left); var hidden_count = length - count + position/(width_block+width_space); if (hidden_count == 0) { animateProp({ elem: elem, prop: 'left', start: position-8, end: position, duration: 500, delay: 40, delta: makeEaseInOut(quad) }); return false; } var newPosition = position - Math.min(count*(width_block+width_space), hidden_count*(width_block+width_space)); animateProp({ elem: elem, prop: 'left', start: position, end: newPosition, duration: 400, delay: 30, delta: makeEaseInOut(quad) }); return false; } function crs_move_left(width_block, width_space, count, el_id) { var elem = document.getElementById(el_id); var position = parseInt(elem.style.left); var hidden_count = -position/(width_block+width_space); if (hidden_count == 0) { animateProp({ elem: elem, prop: 'left', start: position+8, end: position, duration: 500, delay: 40, delta: makeEaseInOut(quad) }); return false; } var newPosition = position + Math.min(count*(width_block+width_space), hidden_count*(width_block+width_space)); animateProp({ elem: elem, prop: 'left', start: position, end: newPosition, duration: 400, delay: 30, delta: makeEaseInOut(quad) }); return false; } //---------------- function animate(opts) { var start = new Date; var delta = opts.delta || linear; var timer = setInterval(function() { var progress = (new Date - start) / opts.duration; if (progress > 1) progress = 1; opts.step( delta(progress) ); if (progress == 1) { clearInterval(timer); opts.complete && opts.complete(); } }, opts.delay || 13); return timer; } function animateProp(opts) { var start = opts.start, end = opts.end, prop = opts.prop; opts.step = function(delta) { var value = Math.round(start + (end - start)*delta); opts.elem.style[prop] = value + 'px'; } return animate(opts); } function linear(progress) { return progress; } function quad(progress) { return Math.pow(progress, 2); } function makeEaseInOut(delta) { return function(progress) { if (progress < .5) return delta(2*progress) / 2; else return (2 - delta(2*(1-progress))) / 2; } }