// модуль "Интернет-магазин" alltrades_shop = { basket: new Array(), compare: new Array(), favorites: new Array(), main_prices: new Array(), price_mods: new Array(), pricelist_fields: '', pricelist_vals: new Array(), pricelist_store: new Array(), renew_timer: null, step: -1, show_prev: true, loading: false, basket_renew_no_items: false, category_id: 0, items_loading_flag: false, items_on_page: 8, items_os: 0, show_item_modal: function (id){ alltrades_shop.start_loading(); $.get('/?show=modal_page&mode=atc&name=item_modal&item_id='+id, function(html){ alltrades_shop.show_dialog(html); alltrades_shop.price_recount(id); }); }, price_recount: function (id){ var price=alltrades_shop.main_prices[id]; if(typeof price == 'undefined'){ return false; } if(alltrades_shop.pricelist_fields!=''){ var fields=alltrades_shop.pricelist_fields.split(','); var pl_key=0; for(i in fields){ val=$('select[name="basket_opt['+fields[i]+']"], input:radio[name="basket_opt['+fields[i]+']"]:checked, input:checkbox[name="basket_opt['+fields[i]+']"]:checked, input:text[name="basket_opt['+fields[i]+']"]').val(); if(val!=undefined){ pl_key+=parseInt('0x'+hex_md5(val).substr(0, 6)); } } if(alltrades_shop.pricelist_vals[id]!=undefined && alltrades_shop.pricelist_vals[id][pl_key]>0){ price=alltrades_shop.pricelist_vals[id][pl_key]; } } $('.add2basket-options select').each(function(){ var tmp=this.id.split('_'); var key=$(this).val().replace(/[\'"]/g, '-'); if(alltrades_shop.price_mods[id]!=undefined && alltrades_shop.price_mods[id][tmp[3]]!=undefined){ price+=+alltrades_shop.price_mods[id][tmp[3]][key]; } }); $('.add2basket-options input[type=checkbox]').each(function(){ if(this.checked){ var tmp=this.id.split('_'); var key=$(this).val().replace(/[\'"]/g, '-'); if(alltrades_shop.price_mods[id]!=undefined && alltrades_shop.price_mods[id][tmp[3]]!=undefined){ price+=+alltrades_shop.price_mods[id][tmp[3]][key]; } } }); $('.add2basket-options input[type=radio]').each(function(){ if(this.checked){ var tmp=this.id.split('_'); var key=$(this).val().replace(/[\'"]/g, '-'); if(alltrades_shop.price_mods[id]!=undefined && alltrades_shop.price_mods[id][tmp[3]]!=undefined){ price+=+alltrades_shop.price_mods[id][tmp[3]][key]; } } }); $('.add2basket-options input[type=text]').each(function(){ var tmp=this.id.split('_'); if(alltrades_shop.price_mods[id]!=undefined && alltrades_shop.price_mods[id][tmp[3]]!=undefined){ price+=+alltrades_shop.price_mods[id][tmp[3]]*this.value; } }); if(Math.round(price)!=price){ price=price.toFixed(2); } $('#main_price_'+id).html(price); }, add_to_basket: function(obj, id, pricelist_pos){ var url='/?show=basket&mode=ajax&act=add&id='+id; if(pricelist_pos!=undefined){ url=url+'&pricelist_pos='+pricelist_pos; } var postdata=$('#add2basket_form_'+id+(alltrades_shop.step==0?'_tmp':'')).serialize() alltrades_shop.start_loading(); $.post(url, postdata, function (html){ var arr = html.split('|||'); eval(arr[1]); html=arr[0]; if(alltrades_shop.step>0){ $(obj).children('img').attr('src', '/images/in_basket.png').attr('title', 'Уже есть в корзине'); } switch(alltrades_shop.step){ case 0: if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } break; case 1: location.href=alltrades_shop.basket['uri']; break; case 2: if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } alltrades_shop.update_basket_html(); break; case 3: alltrades_shop.close_dialog(); var m_ph=$('#main_photo_'+id); $('body').prepend(''); $('#main_img_shadow').animate({top:$('#basket_total').offset().top, left:$('#basket_total').offset().left, width:'100px', height:'100px', opacity:0}, 600, function(){ $(this).remove(); alltrades_shop.update_basket_html(); } ); break; } }); }, remove_from_basket: function(k){ $.get('/?show=basket&act=delete&mode=ajax&id='+k, function(html){ var arr = html.split('|||'); eval(arr[1]); html=arr[0]; if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } alltrades_shop.renew_basket(true); }); }, one_click_buy: function(id){ var url='/?show=basket&mode=ajax&act=one_click_buy&id='+id; alltrades_shop.start_loading(); $.post(url, $('#add2basket_form_'+id).serialize(), function (html){ var arr = html.split('|||'); eval(arr[1]); html=arr[0]; if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } }); }, start_loading: function (){ $('#message_box').html('
'); }, show_dialog: function (html){ $('#message_box').html('' + html); $(".fancy").fancybox({'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true}); $('#curtain').show().click(alltrades_shop.close_dialog); $('#message_box').css('top', $(window).scrollTop()+$(window).height()*0.1).show(); var width=$('#message_box > section').css('width'); if(parseInt(width)>300 && parseInt($(document).width())>999){ $('#message_box').css('width', width).css('margin-left', '-'+parseInt(width)/2+'px'); } }, update_basket_html: function(){ var el; for(k in alltrades_shop.basket){ el=$('#'+k).get(0); if(el!=undefined){ if(el.tagName=='INPUT'){ el.value=alltrades_shop.basket[k]; }else if($('#'+k+' span').length>0){ el=$('#'+k+' span').html(alltrades_shop.basket[k]); }else{ el=$('#'+k+'').html(alltrades_shop.basket[k]); } } } }, close_dialog: function (){ $('#message_box').hide('normal', function(){$('#curtain').fadeOut();}); }, check_store: function (obj, id, check_store) { if(/[^0-9.]/.test(obj.value)){ obj.value=obj.value.replace(/[^0-9.]/, ''); } if(check_store==''){ return; } if(+obj.value>+$('#store'+id+' span').html()){obj.style.color='red';obj.value=$('#store'+id+' span').html();$('#store'+id).css('color', 'red');} }, change_order_field: function(id, options) { $('.delivery_'+id).hide(); obj = $('#order_field_'+id+''); if(obj.length == 0) { return false; } if(obj.get(0).tagName == 'SELECT') { var func = obj.children(':selected').attr('func'); var params = obj.children(':selected').attr('params'); }else{ obj = $('#order_field_'+id+' :checked'); var func = obj.attr('func'); var params = obj.attr('params'); } switch(func) { case 'delivery': if($('#add_func_field_'+id).length) { $('#add_func_field_'+id).html('').show(); } else { $('#order_field_'+id+'').after(''); } $('#add_func_field_'+id).load('/?show=delivery&mode=ajax&field_id='+id+'¶ms='+params, function(html) { if($('#delivery_to_zip').val()>0){ $.get('/?show=delivery&field_id='+id+'&act=calculate&mode=ajax&delivery_to_zip='+$('#delivery_to_zip').val()+'&r='+Math.random(), function(html) { $('#delivery_variants_'+id).html(html); }); }}); break; case 'yandex_delivery': $('#yd_block.delivery_'+id).show(); break; case 'rupost_delivery': $('#rupost_block.delivery_'+id).show(); break; case 'novaposhta_delivery': $('#novaposhta_block.delivery_'+id).show(); break; case 'boxberry_delivery': $('#boxberry_block.delivery_'+id).show(); break; case 'cdek_delivery': $('#cdek_block.delivery_'+id).show(); break; case 'dpd_delivery': $('#dpd_block.delivery_'+id).show(); break; case 'shiptor_delivery': $('#shiptor_block.delivery_'+id).show(); break; } alltrades_shop.save_order_field(id, ''); }, save_order_field: function(id, info) { var val; if($('[name="field[' + id + ']"]').length == 0) { return; } var val; switch($('[name="field[' + id + ']"]').get(0).tagName) { case 'SELECT': val = $('[name="field[' + id + ']"]').val(); break; default: val = $('[name="field[' + id + ']"]:checked').val(); break; } $.post('/?show=basket&mode=ajax&act=save_order_field', { 'field_id': id, 'value': val, 'info': info }, function() { alltrades_shop.refresh_basket(true); }); }, array_to_str: function(arr) { var str = ''; for(j in arr) { str += j + '='+arr[j] + '|||'; } return str; }, str_to_array: function(str) { if(typeof str == 'undefined') { return {}; } var ret = {}; var tmp = str.split('|||'); for(var i in tmp) { var tmp1 = tmp[i].split('='); if(tmp1[0] != '') { ret[tmp1[0]] = tmp1[1]; } } return ret; }, get_cookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; iЗаявка на уведомление о поступлении отправлена.
'); }else{ alert(html); } } ); }, add_to_favorites: function(id){ var url='/?show=basket&mode=ajax&act=favorites&id='+id; $.get(url, function (html){ var arr = html.split('|||'); eval(arr[1]); html=arr[0]; if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } } ); }, remove_from_favorites: function(id){ var url='/?show=basket&mode=ajax&act=remove_from_favorites&id='+id; $.get(url, function (html){ var arr = html.split('|||'); eval(arr[1]); html=arr[0]; if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } } ); }, update_favorites_html: function(){ var el; for(k in alltrades_shop.favorites){ el=$('#'+k).get(0); if(el!=undefined){ if(el.tagName=='INPUT'){ el.value=alltrades_shop.favorites[k]; }else if($('#'+k+' span').length>0){ el=$('#'+k+' span').html(alltrades_shop.favorites[k]); }else{ el=$('#'+k+'').html(alltrades_shop.favorites[k]); } } } }, add_to_compare: function(id){ var url='/?show=basket&mode=ajax&act=compare&id='+id; $.get(url, function (html){ var arr = html.split('|||'); eval(arr[1]); html=arr[0]; if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } } ); }, remove_from_compare: function(id){ var url='/?show=basket&mode=ajax&act=remove_from_compare&id='+id; $.get(url, function (html){ var arr = html.split('|||'); eval(arr[1]); html=arr[0]; if(alltrades_shop.show_prev){ alltrades_shop.show_dialog(html); } } ); }, update_compare_html: function(){ var el; for(k in alltrades_shop.compare){ el=$('#'+k).get(0); if(el!=undefined){ if(el.tagName=='INPUT'){ el.value=alltrades_shop.compare[k]; }else if($('#'+k+' span').length>0){ el=$('#'+k+' span').html(alltrades_shop.compare[k]); }else{ el=$('#'+k+'').html(alltrades_shop.compare[k]); } } } } } alltrades_shop.init_basket(); function search_update_form(fields){ if(fields==''){ $('div[id^="search-field"]').show(); }else{ $('div[id^="search-field"]').each(function(){ if(fields.indexOf(','+this.id.substr(13)+',')==-1){ $(this).hide(); }else{ $(this).show(); } }); } } // модуль "Пользователи" var alltrades_comments = { obj_id: '', key: 0, mark: 0, type: 0, parent_id: 0, parent_comment_id: 0, load_form: function (el_id, type, parent_id) { if(typeof el_id != 'undefined'){ this.obj_id='#'+el_id; } if(typeof type != 'undefined'){ this.type=type; } if(typeof parent_id != 'undefined'){ this.parent_id=parent_id; } this.key=Math.random(); $(this.obj_id).load('/?show=comments&mode=ajax&act=get_form&type='+this.type+'&parent_id='+this.parent_id+'&parent_comment_id='+this.parent_comment_id+'&rand='+this.key, function(){ $('.star-mark').bind('click', function(){ $('input[name=mark]').val($(this).attr('mark')); alltrades_comments.show_stars($(this).attr('mark')); }); }); $('#comments_add_main_comment_link').hide(); }, show_stars: function(mark){ $(this.obj_id+' input[name=mark]').val(mark); for(var i=1; i<=5; i++){ if(mark>=i){ $(this.obj_id).find('.mark'+i).removeClass('rank-star-empty').addClass('rank-star'); }else{ $(this.obj_id).find('.mark'+i).removeClass('rank-star').addClass('rank-star-empty'); } } }, send: function(){ var ret=''; $(this.obj_id+' [num]').each(function(){ ret+=$(this).attr('num')+':'; }); ret+=this.key; $.post('/?show=comments&mode=ajax&act=send&key='+hex_md5(ret)+'&rand='+this.key, $(this.obj_id+' form').serialize(), function(html){ $(alltrades_comments.obj_id).html(html); $(alltrades_comments.obj_id+' .star-mark').bind('click', function(){ $(alltrades_comments.obj_id+' input[name=mark]').val($(this).attr('mark')); alltrades_comments.show_stars($(this).attr('mark')); }); }); }, add_answer: function(id){ this.parent_comment_id=id; $('#comment_'+id+' > .comment-answers').show().prepend($(this.obj_id)); this.load_form(); $('#comments_add_main_comment_link').show(); }, add_comment: function(){ this.parent_comment_id=0; $(this.obj_id).appendTo('#comments_form_wr').show(); this.load_form(); }, tree: function(){ $('[data_parent_id]').each(function(){ $(this).appendTo('#comment_'+$(this).attr('data_parent_id')+' > .comment-answers'); $('#comment_'+$(this).attr('data_parent_id')+' > .comment-answers').show(); }); $('.comment-mark').each(function(){ var mark=$(this).attr('data_mark'); for(var i=1;i<=mark;i++){ $(this).append(''); } for(var i=mark;i<5;i++){ $(this).append(''); } }); } }