sa_catalog_page_size = 12; jQuery(document).ready(function() { var allSelects = jQuery(".js_sa_select"); for (var i=0;i0){ jQuery('.sa_favorites').html(responseObj.result.content); }else{ alert("Ошибка добавления товара к сравнению!"); } }); }; function clearBasket(onFinish){ jQuery.ajax({ type: "POST", url: '/services.json?action=clearBasket', dataType: "json", data: {}, success: function(data){ if (data.result) { onFinish(); } } }); } function multiAdd2basket(itemsArr,onFinish){ jQuery.ajax({ type: "POST", url: '/services.json?action=multiAddToBasket', dataType: "json", data: {items:itemsArr}, success: function(data){ if (data.result && data.result.size) { korzina_setCount(data.result.size,data.result.total); basketInformer(data.result.size,data.result.total) onFinish(); } } }); } function updateShortBasket() { jQuery.ajax({ type: "POST", url: "/services.json?action=getCart" }).done(function( serverAnswer ) { var responseObj = JSON.parse(serverAnswer ); if(responseObj && responseObj.result && responseObj.result.content){ jQuery('.sa_js_shortcart_list').html(responseObj.result.content); }else{ alert("Ошибка загрузки корзины"); } }); }; function addToBasket(id,qty/*,size,color*/) { jQuery.ajax({ type: "POST", url: "/services.json?action=addToBasket", data: { id: id, /*size: size, color: color,*/ qty: qty } }).done(function( serverAnswer ) { var responseObj = JSON.parse(serverAnswer ); if(responseObj && responseObj.result && responseObj.result.size>0){ korzina_setCount(responseObj.result.size,responseObj.result.total); basketInformer(responseObj.result.size,responseObj.result.total); //alert("Товар добавлен в корзину!"); }else{ korzina_setCount(responseObj.result.size); alert("Ошибка добавления товара в корзину!"); } }); }; function korzina_setCount(response,total){ if(response>0) { jQuery(".sa_shopcart_count").html(response); jQuery(".sa_shopcart_total").html(total); } else { jQuery(".sa_shopcart_count").html("0"); jQuery(".sa_shopcart_total").html("0"); } updateShortBasket(); } function sa_site_notes(notes){ jQuery.fancybox.open('
'+notes+'
'); /*jQuery(".fancybox").fancybox({ content:'
'+notes+'
', helpers: { overlay: { locked: false } }, padding: 20 });*/ } function basketInformer(response,total){ var content='

Товар добавлен в корзину!
Всего выбранных позиций: '+response+'

 

Вы можете продолжить покупки, либо перейти к оформлению заказа.'; sa_site_notes(content); korzina_setCount(response); } function updateBasket(id,qty/*,size,color*/) { jQuery.ajax({ type: "POST", url: "/services.json?action=updateBasket", data: { id: id, /*size: size, color: color,*/ qty: qty } }).done(function( serverAnswer ) { var responseObj = JSON.parse(serverAnswer ); if(responseObj && responseObj.result /*&& responseObj.result.size>0*/){ korzina_setCount(responseObj.result.size); loadHTMLBasket(function(content){ jQuery('.sa_shopping_html').html(content); }); if(responseObj.result.size==0){ document.location.href='/shopcart'; } //alert("Товар добавлен в корзину!"); }else{ korzina_setCount(responseObj.result.size); //loadHTMLBasket(function(content){jQuery('.sa_shopping_html).html(content)}); //alert("Ошибка добавления товара в корзину!"); } }); }; function PingSession(){ var a = jQuery.get("/null.php"); } function smartInput(id) { var el = jQuery('#' + id); if (!el[0]) return; el.focus(function() { if (this.defaultValue == this.value) this.value = ''; }); el.blur(function() { if (this.value == '') this.value = this.defaultValue; }); } function viewTypeCatalogLink(need_type){ var url = jQuery.url(); var params= url.param(); var out_urls=[]; if(url.param('type')=="block"){ delete params.type; }else{ out_urls.push("type=block"); } for(var index in params){ if(index!=""){ out_urls.push(index+"="+encodeURIComponent(params[index])); } } if(out_urls.length){ document.location.href=url.attr('path')+"?"+out_urls.join("&"); }else{ document.location.href=url.attr('path'); } } function removeFilter(){ var action_fields=["developer","tags"]; var url = jQuery.url(); var params= url.param(); delete params.action; delete params.page; action_fields.map(function(n) { delete params[n]; }); var recursiveEncoded = jQuery.param( params ); document.location.href=(recursiveEncoded) ? url.attr('path')+"?"+recursiveEncoded : url.attr('path'); } function filterCatalog(variable, value){ var action_fields=["developer","tags"]; var url = jQuery.url(); var params= url.param(); delete params.page; if(value==""){ delete params[variable]; delete action_fields[action_fields.indexOf(variable)] var intersect = action_fields.filter(function(n) { //удалить action если других св-в не осталось return (params[n])? true : false; }); if(intersect.length==0){ delete params.action; //filter } var recursiveEncoded = jQuery.param( params ); document.location.href=(recursiveEncoded) ? url.attr('path')+"?"+recursiveEncoded : url.attr('path'); return; }else{ params.action = (!params.action) ? "filter" : params.action; params[variable]=value; var recursiveEncoded = jQuery.param( params ); document.location.href=(recursiveEncoded) ? url.attr('path')+"?"+recursiveEncoded : url.attr('path'); return; } } function sortCatalogLink(sortAs){ var url = jQuery.url(); var params= url.param(); if(url.param('sort')){ delete params.sort; } var out_urls=[]; //составление нового адреса for(var index in params){ if(index!=""){ out_urls.push(index+"="+encodeURIComponent(params[index])); } } if(sortAs!=""){ out_urls.push("sort="+sortAs); } if(out_urls.length){ //если были параметры document.location.href=url.attr('path')+"?"+out_urls.join("&"); }else{ //если параметров нет document.location.href=url.attr('path'); } } function viewPSCatalogLink(ps){ var url = jQuery.url(); var params= url.param(); delete params.page; if(url.param('ps')){ delete params.ps; } var out_urls=[]; //составление нового адреса for(var index in params){ if(index!=""){ out_urls.push(index+"="+encodeURIComponent(params[index])); } } if(ps!=sa_catalog_page_size){ //GetConfig("catalog_page_size") out_urls.push("ps="+ps); } if(out_urls.length){ //если были параметры document.location.href=url.attr('path')+"?"+out_urls.join("&"); }else{ //если параметров нет document.location.href=url.attr('path'); } } function in_array(needle, haystack, strict) { // Checks if a value exists in an array var found = false, key, strict = !!strict; for (key in haystack) { if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) { found = true; break; } } return found; } function array_diff(a1, a2) { var a = [], diff = []; for (var i = 0; i < a1.length; i++) { a[a1[i]] = true; } for (var i = 0; i < a2.length; i++) { if (a[a2[i]]) { delete a[a2[i]]; } else { a[a2[i]] = true; } } for (var k in a) { diff.push(k); } return diff; }; function sa_autocomplete(jQueryObj, initObj){ jQueryObj.autocomplete({ autoFocus:true, minLength: initObj.minLength, source: function(request, response ) { jQuery.getJSON( initObj.url, request, function( data, status, xhr ){ response( data ); }); }, response: function( event, ui ) { jQueryObj.data("first",ui.content[0]) jQueryObj.data("selected",false) }, focus: function( event, ui) { //log( "focus: " + ui.item.label ); }, select: function( event, ui ) { //log( "select: " + ui.item.label ); jQueryObj.data("selected",true) initObj.onSelectFunc(ui.item); } }).blur(function(a,b){ //log("source: "+jQueryObj.data("aaa")); if(!jQueryObj.data("selected")){ jQueryObj.val(jQueryObj.data("first").value) initObj.onSelectFunc(jQueryObj.data("first")); } }); return jQueryObj; } function arrayToHash(sourceArray,byColumn){ var o={}; for(var i=0; i