var Filter_head_type = 1; var Filter_search_brand = ''; var Filter_search_phrase = ''; var Filter_search_timelimit='300000'; var Filter_input_element = 'search-input-detailSearchNew'; var Filter_get_brand_url = 'http://autobreaker.ru/detailSearchNew/default/getBrandList/'; var Filter_get_sklad_url = 'http://autobreaker.ru/detailSearchNew/default/getSkladList/'; var Filter_get_data_prefix_url = 'http://autobreaker.ru/detailSearchNew/default/getProductList/'; var Filter_text_for_loading=''; var Filter_block_to_load='main_load_block'; var Filter_search_phrase_echo='search_phrase_echo'; var Filter_brands = {}; var Filter_products = []; var Filter_products_other = []; var Filter_total_count = 0; var Filter_global_time_start = 0; var Filter_criteria = 'price'; var Filter_criteria_updown = '<'; var Filter_shown_products = []; var Filter_last_update_parser = ''; var Filter_temp_flag1 = false; var Filter_temp_flag2 = false; var Filter_table_of_possiotion = []; var Filter_criteria_total_rows_per_articul=1; var Filter_criteria_top_price_value=0; var Filter_criteria_top_delivery_value=0; var Filter_best_prices = {}; var Filter_show_purchase_price = 0; function Filter_before_search() { if (Filter_head_type == 1) { var h1 = 'СПИСОК ПРЕДЛОЖЕНИЙ
Артикул найден в каталогах ()'; //Brands var html = '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
ПроизводительНомерНаименование 
' + '
Не нашли?
ЗАПРОСИТЬ НАЛИЧИЕ и ЦЕНУ
' + '
'; } else { var h1 = 'СПИСОК ПРЕДЛОЖЕНИЙ ' + Filter_search_phrase + ' '; //Detailes var html = '
' + '
' + '' + '' + '' + '' + '' + '' + '' + (Filter_show_purchase_price ? '' : '') + '' + '' + '' + '' + '' + '' + '' + ''+ '
ПроизводительНомерНаименованиеЦена ЗакупкаСрок доставки (дней)Кол-во (на складе)СкладКол-во (в заказ)
' + '
Не нашли?
ЗАПРОСИТЬ НАЛИЧИЕ и ЦЕНУ
' + '
'; } $('#Filter_results').html(html); Filter_start_show_progress(); $('h1.Filter_h1').html(h1); if (Filter_head_type == 2) { $("#Search-grid thead a").click(function(){ if($(this).hasClass('asc')){ $("#Search-grid thead a").removeClass('asc'); $("#Search-grid thead a").removeClass('desc'); $(this).addClass('desc'); Filter_apply_sort_criteria($(this).attr("name"),'<'); } else { $("#Search-grid thead a").removeClass('asc'); $("#Search-grid thead a").removeClass('desc'); $(this).addClass('asc'); Filter_apply_sort_criteria($(this).attr("name"),'>'); } }); $('select[name=currency_list]').change(function() { $.post('/changeCurrency/', { id_currency: $(this).val(), YII_CSRF_TOKEN : '86080ac8150d8b8d05df28333a4c9cbd4541362f' }, function( data ) { Filter_search_page(Filter_search_phrase, Filter_search_brand); $("#shopping-cart").load("http://autobreaker.ru/shop_cart/shoppingCart/cart/"); }); }); } } function Filter_start_show_progress() { $('#Filter_done_div').html('
Подождите, идет поиск
'); } function Filter_get_rating(data) { var rating = ''; if ((typeof(data.ddpercent) != 'undefined') && !isNaN(parseInt(data.ddpercent)) && (data.ddpercent != 0)) { var title = ''; switch (parseInt(data.ddpercent)) { case 1: title = "Вероятно не привезут, 1 балл"; break; case 2: title = "Низкая вероятность поставки, 2 балла"; break; case 3: title = "Удовлетворительная вероятность поставки, 3 балла"; break; case 4: title = "Хорошая вероятность поставки, 4 балла"; break; case 5: title = "Отличная вероятность поставки, 5 баллов"; break; } rating = '
'; } return rating; } function Filter_create_element(data, i,set_rows_assign) { temp_element = document.createElement('tr'); Filter_temp_flag2 = !Filter_temp_flag2; if ((typeof(data.store_highlight) != 'undefined') && !isNaN(parseInt(data.store_highlight)) && (parseInt(data.store_highlight) == 1)) { temp_element.setAttribute('class', 'Filter_items_element_highlight'); } if(set_rows_assign>0) { temp = document.createElement('td'); temp.setAttribute('class', 'Filter_items_brand'); temp.setAttribute('rowspan', set_rows_assign); temp.setAttribute('brand_id_main_row', data.brand.toUpperCase().replace(/([^A-Za-z0-9])/g, '')+data.articul); temp2 = document.createElement('div'); if (typeof(data.brand_link) != 'undefined' && data.brand_link == 1) { temp2.innerHTML = '' + data.brand + ''; } else { temp2.innerHTML = data.brand; } temp.appendChild(temp2); temp_element.appendChild(temp); temp = document.createElement('td'); temp.setAttribute('class', 'Filter_items_brand'); temp.setAttribute('rowspan', set_rows_assign); temp.setAttribute('product_id_main_row', data.brand.toUpperCase().replace(/([^A-Za-z0-9])/g, '')+data.articul); temp.innerHTML = data.articul+(data.garanty==1?" ":""); temp_element.appendChild(temp); } temp = document.createElement('td'); //temp.setAttribute('class', 'Filter_items_name'); temp_text = data.name; temp_text = temp_text.replace("/([\,\.\!\?\/\\])/g", "$1 "); if ((typeof(data.link) != undefined) && (data.link != undefined)) { temp_text = '' + temp_text + ''; } temp.innerHTML = temp_text; temp_element.appendChild(temp); temp = document.createElement('td'); //temp.setAttribute('class', 'Filter_items_price'); temp.innerHTML = ''+data.price_echo+''; temp_element.appendChild(temp); if (Filter_show_purchase_price) { temp = document.createElement('td'); temp.innerHTML = '' + data.price_purchase_echo + ''; temp_element.appendChild(temp); } temp = document.createElement('td'); //temp.setAttribute('class', 'Filter_items_dostavka'); temp.innerHTML = data.dostavka; temp_element.appendChild(temp); temp = document.createElement('td'); //temp.setAttribute('class', 'Filter_items_kolichestvo'); temp.innerHTML = data.kolichestvo; temp_element.appendChild(temp); temp = document.createElement('td'); //temp.setAttribute('class', 'Filter_items_sklad'); temp.innerHTML = Filter_get_rating(data); if ((typeof(data.store_description) != 'undefined') && ($.trim(data.store_description) != '')) { temp.innerHTML += '
' + data.store + '
'; } else { temp.innerHTML += '
' + data.store + '
'; } temp_element.appendChild(temp); temp = document.createElement('td'); temp.setAttribute('class', 'buy'); temp_indf = data.articul + '_' + i; temp_var = data.name; temp_var = temp_var.replace(/"/g, '"'); temp.innerHTML = '
'+ '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + (typeof(data.store_id) != 'undefined' ? '' : '') + (typeof(data.parser_id) != 'undefined' ? '' : '') + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
'; temp_element.appendChild(temp); return temp_element; } function Filter_check_is_good_time(data) { if (data == null) { Filter_total_count--; Filter_remake_table(); if (Filter_total_count > 0) return false; Filter_done_search(); return false; } if (Filter_global_time_start == data.time_start) { return true; } return false; } function Filter_start_search() { Filter_before_search(); d = new Date(); Filter_global_time_start = d.getTime(); $('#' + Filter_input_element).val(($('#' + Filter_input_element).val()).replace(/\-/g, '').replace(/\./g, '').toUpperCase()); $('#' + Filter_search_phrase_echo).html($('#' + Filter_input_element).val()); if (Filter_search_brand == '') { params = { time_start: Filter_global_time_start, search_phrase: ($('#'+ Filter_input_element).val()).toUpperCase() }; Filter_products = []; Filter_products_other = []; $.getJSON(Filter_get_sklad_url, params, function (data) { if (!Filter_check_is_good_time(data)) return; Filter_total_count = data.sklads_count; $.ajaxSetup({ timeout: Filter_search_timelimit, error: function () { Filter_total_count --; if (Filter_last_update_parser != data.search_sklad && Filter_total_count > 0) return; Filter_calculate_brands(); Filter_done_search(); }}); for (i = 0; i < data.sklads_count; i++) { params = { search_phrase: ($('#' + Filter_input_element).val()).toUpperCase(), search_sklad: data.sklads[i], time_start: Filter_global_time_start }; $.getJSON(Filter_get_brand_url, params, function (data) { console.log('get brand'); console.log(data); Filter_total_count --; console.log(Filter_total_count); if (typeof(data.brands) != 'undefined') { //Show brands var html = ''; var count = 0; brands = data.brands; console.log(brands); for (key in brands) { clef = brands[key]['brand'] + '_' + brands[key]['article']; Filter_brands[clef] = brands[key]; } Filter_brands = ksort(Filter_brands); console.log(Filter_brands); for (key in Filter_brands) { count ++; html += '' + '' + Filter_brands[key]['brand'] + '' + '' + Filter_brands[key]['article'] + '' + '' + Filter_brands[key]['name'] + '' + 'Поиск' + ''; } $('#' + Filter_block_to_load).html(html); $('#search_phrase_count').html(count); } var total = 0; for (key in Filter_brands) { total ++; } if (Filter_total_count == 0) { if (total < 2) { Filter_head_type = 2; Filter_before_search(); Filter_show_products(); } else { $('#Filter_done_div').html(''); } } }); } }); } else { Filter_show_products(); } } function Filter_show_products() { params = { time_start: Filter_global_time_start, search_phrase: ($('#'+ Filter_input_element).val()).toUpperCase() }; Filter_products = []; Filter_products_other = []; $.getJSON(Filter_get_sklad_url, params, function (data) { if (!Filter_check_is_good_time(data)) return; Filter_total_count = data.sklads_count; $.ajaxSetup({ timeout: Filter_search_timelimit, error: function () { Filter_total_count --; if (Filter_last_update_parser != data.search_sklad && Filter_total_count > 0) return; Filter_calculate_brands(); Filter_done_search(); }}); for (i = 0; i < data.sklads_count; i++) { params = { search_phrase: ($('#' + Filter_input_element).val()).toUpperCase(), search_brand: Filter_search_brand, search_sklad: data.sklads[i], time_start: Filter_global_time_start }; $.getJSON(Filter_get_data_prefix_url, params, function (data) { Filter_upgrade_elements(data); }); } }); } function getProps(toObj, tcSplit) { if (!tcSplit) tcSplit = '\n'; var lcRet = ''; var lcTab = ' '; for (var i in toObj) // обращение к свойствам объекта по индексу lcRet += lcTab + i + " : " + toObj[i] + tcSplit; lcRet = '{' + tcSplit + lcRet + '}'; return lcRet; } function Filter_upgrade_elements(data) { if (!Filter_check_is_good_time(data)) return; Filter_last_update_parser = data.search_sklad; for (i = 0; i < data.products_count; i++) { element = data.products[i]; if (Filter_products[element.articul] == undefined) { Filter_products[element.articul] = { count: 1, elements: [element], criteria: 'general' } } else { flag = true; for (j = 0; j < Filter_products[element.articul].count; j++) { if (Filter_products[element.articul].elements[j].name == element.name && Filter_products[element.articul].elements[j].price == element.price && Filter_products[element.articul].elements[j].kolichestvo == element.kolichestvo && Filter_products[element.articul].elements[j].dostavka == element.dostavka && Filter_products[element.articul].elements[j].brand == element.brand) flag = false; } if (flag) { Filter_products[element.articul].elements[Filter_products[element.articul].count] = element; Filter_products[element.articul].count++; } } //alert(getProps(Filter_products)); } //alert(Filter_products); for (i = 0; i < data.products_other_count; i++) { element = data.products_other[i]; if (Filter_products_other[element.articul] == undefined) { Filter_products_other[element.articul] = { count: 1, elements: [element], criteria: 'general' } } else { flag = true; for (j = 0; j < Filter_products_other[element.articul].count; j++) { if (Filter_products_other[element.articul].elements[j].name == element.name && Filter_products_other[element.articul].elements[j].price == element.price && Filter_products_other[element.articul].elements[j].kolichestvo == element.kolichestvo && Filter_products_other[element.articul].elements[j].dostavka == element.dostavka && Filter_products_other[element.articul].elements[j].brand == element.brand) flag = false; } if (flag) { Filter_products_other[element.articul].elements[Filter_products_other[element.articul].count] = element; Filter_products_other[element.articul].count++; } } } for (brand in data.best_prices) { if (typeof(Filter_best_prices[brand]) != 'undefined') { price1 = parseFloat(data.best_prices[brand].price); price2 = parseFloat(Filter_best_prices[brand].price); if (price1 < price2) { Filter_best_prices[brand] = data.best_prices[brand]; } } else { Filter_best_prices[brand] = data.best_prices[brand]; } } if (!Filter_check_is_good_time(data)) return; Filter_total_count--; if (Filter_last_update_parser != data.search_sklad && Filter_total_count > 0) return; Filter_calculate_brands(); Filter_done_search(); } function Filter_done_search() { if (Filter_total_count <= 0) { $('#Filter_done_div').html(''); //$('#Filter_done_div').html('
Поиск закончен
'); total = 0; console.log(total); //products = Filter_sort_criteria(); for (var articul in Filter_products) for (var j in Filter_products[articul].elements) total++; //products = Filter_sort_criteria_other(); for (var articul in Filter_products_other) for (var j in Filter_products_other[articul].elements) total++; console.log(total); if (total == 0) { Filter_search_more_find(); //Здесь происходит редирект document.location = $("#getPriceUrlId").attr("href"); } $('div.rateit').rateit(); //$('a.fancybox').fancybox(); $('a.fancybox').click(function() { var href = $(this).attr('href'); $.fancybox.open({ href : href, type : "iframe", padding : 15, width: 600, height: 400, maxHeight: 400 }); return false; }); } } function Filter_shift_and_insert(mas, element, cur, total) { for (i = total; i > cur; i--) { mas[i] = mas[i - 1]; } mas[cur] = element; return mas; } function Filter_sort_criteria() { products = []; for (var articul in Filter_products) { Filter_criteria_search = Filter_criteria; if (Filter_products[articul].criteria != 'general') { Filter_criteria_search = Filter_products[articul].criteria; } total = 0; products[articul] = []; for (var j in Filter_products[articul].elements) { if (total == 0) { products[articul][total] = Filter_products[articul].elements[j]; total++; } else { for (var atribute in Filter_products[articul].elements[j]) { if (Filter_criteria_search == atribute) { old = total; for (i = 0; i < total; i++) { a = eval('Filter_products[articul].elements[j].' + atribute); b = eval('products[articul][i].' + atribute); if ((Filter_criteria_updown == '>' && a > b) || (Filter_criteria_updown == '<' && a < b)) { products[articul] = Filter_shift_and_insert(products[articul], Filter_products[articul].elements[j], i, total); total++; i = total; } } if (old == total) { products[articul][total] = Filter_products[articul].elements[j]; total++; } break; } } } } } return products; } function Filter_sort_criteria_other() { products = []; if (Filter_criteria != 'brand') { for (var articul in Filter_products_other) { Filter_criteria_search = Filter_criteria; if (Filter_products_other[articul].criteria != 'general') { Filter_criteria_search = Filter_products_other[articul].criteria; } //console.log(articul + ' - ' + Filter_products_other[articul].elements.length); total = 0; products[articul] = []; for (var j in Filter_products_other[articul].elements) { if (total == 0) { products[articul][total] = Filter_products_other[articul].elements[j]; total ++; } else { for (var atribute in Filter_products_other[articul].elements[j]) { if (Filter_criteria_search == atribute) { old = total; for (i = 0; i < total; i++) { a = eval('Filter_products_other[articul].elements[j].' + atribute); b = eval('products[articul][i].' + atribute); if ((Filter_criteria_updown == '>' && a > b) || (Filter_criteria_updown == '<' && a < b)) { products[articul] = Filter_shift_and_insert(products[articul], Filter_products_other[articul].elements[j], i, total); total++; i = total; } } if (old == total) { products[articul][total] = Filter_products_other[articul].elements[j]; total++; } break; } } } } } } else { total_products = 0; temp_table = []; for (var articul_trash in Filter_products_other) { min = -1; for (var articul in Filter_products_other) { if (products[articul] == undefined && (min == -1 || (Filter_criteria_updown == '>' && Filter_products_other[articul].elements[0].brand > Filter_products_other[min].elements[0].brand) || (Filter_criteria_updown == '<' && Filter_products_other[articul].elements[0].brand < Filter_products_other[min].elements[0].brand))) { min = articul; } } products[min] = Filter_products_other[min].elements; temp_table[total_products] = min; total_products++; Filter_table_of_possiotion = temp_table; } } return products; } function ksort(w) { var sArr = [], tArr = [], n = 0; for (i in w){ tArr[n++] = i; } tArr = tArr.sort(); n = tArr.length; for (var i=0; i < n; i++) { sArr[tArr[i]] = w[tArr[i]]; } return sArr; } function Filter_calculate_brands() { products = Filter_sort_criteria(); var brands = {}; var brands_count = 0; for (var articul in products) { //Group by brands for (var j in products[articul]) { brand = $.trim(products[articul][j].brand); if (!(brand in brands)) { brands[brand] = {'articul': products[articul][j].articul, 'name': products[articul][j].name}; brands_count ++; } } } products = Filter_sort_criteria_other(); for (var articul in products) { //Group by brands for (var j in products[articul]) { brand = $.trim(products[articul][j].brand); if (!(brand in brands)) { brands[brand] = {'articul': products[articul][j].articul, 'name': products[articul][j].name}; brands_count ++; } } } Filter_start_show_progress(); if ((brands_count == 1) || (Filter_search_brand != '') || (Filter_head_type == 2)) { //Show detailes Filter_remake_table(); } else { //Show brands var html = ''; var count = 0; brands = ksort(brands); for (key in brands) { count ++; brand_link = key.replace(/\//g, '__'); html += '' + '' + key + '' + '' + brands[key]['articul'] + '' + '' + brands[key]['name'] + '' + 'Поиск' + ''; } $('#' + Filter_block_to_load).html(html); $('#search_phrase_count').html(count); } } function Filter_best_product(products, orig) { if ($('div.search_the_best').length == 1) { var best = null; var best_price = 1000000000; var count = 0; for (var articul in products) { for (var j in products[articul]) { if (products[articul][j].price < best_price) { best_price = products[articul][j].price; best = products[articul][j]; } count ++; } } if ((best != null) && (count > 1)) { var sign = 'Аналог'; if ((typeof(orig) != 'undefined') && (orig == true)) { sign = 'Оригинал'; } var div_best = $('
' + '
' + '
' + '
Самая низкая цена
' + '
' + sign + '
' + '
' + '
'); var sign = 'дней'; if (!isNaN(parseInt(best.dostavka))) { switch (parseInt(best.dostavka)) { case 1: sign = 'день'; break; case 2: case 3: case 4: sign = 'дня'; break; } } var name = best.name; if ((typeof(best.link) != undefined) && (best.link != undefined)) { name = '' + name + ''; } div_best.append('
' + '
' + best.brand + ' ' + best.articul + '
' + '
' + best.price_echo + '
' + '
' + '
' + '
' + name + '
' + '
' + Filter_get_rating(best) + '
' + best.store + '
' + '
' + '
' + '
' + best.kolichestvo + (!isNaN(parseInt(best.kolichestvo)) ? ' шт.' : '') + '
' + '
' + best.dostavka + ' ' + sign + '
' + '
'+ '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
'); div_best.find('form').addClass('span5'); $('div.search_the_best').append(div_best); } } } function Filter_best_delivery_period(products, products_other) { if ($('div.search_the_best').length == 1) { var best = null; var best_delivery = 1000000000; var count = 0; for (var articul in products) { for (var j in products[articul]) { var dostavka = parseInt(products[articul][j].dostavka); if (!isNaN(dostavka) && (dostavka < best_delivery)) { best_delivery = products[articul][j].dostavka; best = products[articul][j]; } count ++; } } for (var articul in products_other) { for (var j in products_other[articul]) { var dostavka = parseInt(products_other[articul][j].dostavka); if (!isNaN(dostavka) && (dostavka < best_delivery)) { best_delivery = products_other[articul][j].dostavka; best = products_other[articul][j]; } count ++; } } if ((best != null) && (count > 1)) { var div_best = $('
' + '
' + '
' + '
Наименьший срок
' + '
' + '
'); var sign = 'дней'; if (!isNaN(parseInt(best.dostavka))) { switch (parseInt(best.dostavka)) { case 1: sign = 'день'; break; case 2: case 3: case 4: sign = 'дня'; break; } } var name = best.name; if ((typeof(best.link) != undefined) && (best.link != undefined)) { name = '' + name + ''; } div_best.append('
' + '
' + best.brand + ' ' + best.articul + '
' + '
' + best.price_echo + '
' + '
' + '
' + '
' + name + '
' + '
' + Filter_get_rating(best) + '
' + best.store + '
' + '
' + '
' + '
' + best.kolichestvo + (!isNaN(parseInt(best.kolichestvo)) ? ' шт.' : '') + '
' + '
' + best.dostavka + ' ' + sign + '
' + '
'+ '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
'); div_best.find('form').addClass('span5'); $('div.search_the_best').append(div_best); } } } function Filter_remake_table() { if ($('#' + Filter_block_to_load).length == 0) return; var products = Filter_sort_criteria(); if ($('div.search_the_best').length == 1) $('div.search_the_best').html(''); Filter_best_product(products, true); $('#' + Filter_block_to_load).html(''); elements = document.getElementById(Filter_block_to_load); elements2 = document.createElement('div'); elements2.setAttribute('class', 'Filter_group_items'); temp1 = document.createElement('tr'); temp2 = document.createElement('td'); temp2.setAttribute('colspan', '8'); temp1.appendChild(temp2); temp = document.createElement('center'); temp.setAttribute('class', 'Filter_detail_name'); temp.innerHTML = 'Искомый артикул'; temp2.appendChild(temp); elements.appendChild(temp1); flag = false; for (var articul in products) { //Count products with sort temp_rows_count = 0; for (var j in products[articul]) { temp_rows_count++; } if (temp_rows_count == 0) continue; flag = true; artikul_element = Filter_make_new_articul_element(articul); temp_rows_count = 0; brands_full = []; for (var j in products[articul]) { temp_rows_count++; if (brands_full[$.trim(products[articul][j].brand.toUpperCase())] == undefined) { brands_full[$.trim(products[articul][j].brand.toUpperCase())] = {'items': [], count: 0}; } brands_full[$.trim(products[articul][j].brand.toUpperCase())].items[j] = products[articul][j]; brands_full[$.trim(products[articul][j].brand.toUpperCase())].count++; } for (var b1 in brands_full) { set_rows_assign = Filter_criteria_total_rows_per_articul; set_rows_assign_save = brands_full[b1].count; temp_rows_count = 0; flag_set_maximize_block = false; for (var j in brands_full[b1].items) { insert_element = Filter_create_element(products[articul][j], j, set_rows_assign); if ((temp_rows_count >= Filter_criteria_total_rows_per_articul) || ((Filter_criteria_top_price_value != 0 && Filter_criteria_top_price_value != '') && (parseInt(products[articul][j].price_echo, 10) > parseInt(Filter_criteria_top_price_value, 10))) || ((Filter_criteria_top_delivery_value != 0 && Filter_criteria_top_delivery_value != '') && (parseInt(products[articul][j].price_echo, 10) > parseInt(Filter_criteria_top_price_value, 10))) ) { flag_set_maximize_block = true; insert_element.setAttribute('class', insert_element.getAttribute('class') + ' product' + b1.replace(/([^A-Za-z0-9])/g, '') + articul); insert_element.setAttribute('style', 'display:none;'); } elements.appendChild(insert_element); set_rows_assign = 0; temp_rows_count++; } temp1 = document.createElement('tr'); temp2 = document.createElement('td'); temp2.setAttribute('colspan', '8'); temp1.appendChild(temp2); temp = document.createElement('center'); temp.setAttribute('class', 'Filter_detail_name'); temp_text = ''; if (flag_set_maximize_block) temp_text = 'Показать остальные ' + b1 + ' \\ '; temp.innerHTML = temp_text + 'Показать запчасти ' + b1 + ' с минимальным сроком поставки'; temp2.appendChild(temp); if (temp_rows_count > 1) elements.appendChild(temp1); elements.appendChild(artikul_element); } } if (!flag) { if (Filter_total_count <= 0) { temp1 = document.createElement('tr'); temp2 = document.createElement('td'); temp2.setAttribute('colspan', '8'); temp1.appendChild(temp2); temp = document.createElement('center'); //temp.setAttribute('class', 'Filter_detail_name'); temp.innerHTML = 'Товаров не найдено'; temp2.appendChild(temp); elements.appendChild(temp1); } } var products_other = Filter_sort_criteria_other(); Filter_best_product(products_other, false); Filter_best_delivery_period(products, products_other); products = products_other; elements2 = document.createElement('div'); elements2.setAttribute('class', 'Filter_group_items'); temp1 = document.createElement('tr'); temp2 = document.createElement('td'); temp2.setAttribute('colspan', '8'); temp1.appendChild(temp2); temp = document.createElement('center'); temp.setAttribute('class', 'Filter_detail_name'); temp.innerHTML = 'Аналоги и замены других производителей'; temp2.appendChild(temp); elements.appendChild(temp1); flag = false; temp_i = 0; for (var articul in products) { if (Filter_criteria == 'brand') { articul = Filter_table_of_possiotion[temp_i]; temp_i++; } temp_rows_count = 0; for (var j in products[articul]) { temp_rows_count++; } if (temp_rows_count == 0) continue; flag = true; artikul_element = Filter_make_new_articul_element(articul); artikul_elements = document.createElement('div'); artikul_elements.setAttribute('class', 'Filter_items_articul_elements'); temp_rows_count = 0; brands_full = []; for (var j in products[articul]) { temp_rows_count++; if (brands_full[$.trim(products[articul][j].brand.toUpperCase())] == undefined) { brands_full[$.trim(products[articul][j].brand.toUpperCase())] = {'items': [], count: 0}; } brands_full[$.trim(products[articul][j].brand.toUpperCase())].items[j] = products[articul][j]; brands_full[$.trim(products[articul][j].brand.toUpperCase())].count++; } for (var b1 in brands_full) { set_rows_assign = Filter_criteria_total_rows_per_articul; set_rows_assign_save = brands_full[b1].count; temp_rows_count = 0; flag_set_maximize_block = false; for (var j in brands_full[b1].items) { insert_element = Filter_create_element(products[articul][j], j, set_rows_assign); if ((temp_rows_count >= Filter_criteria_total_rows_per_articul) || ((Filter_criteria_top_price_value != 0 && Filter_criteria_top_price_value != '') && (parseInt(products[articul][j].price_echo, 10) > parseInt(Filter_criteria_top_price_value, 10))) || ((Filter_criteria_top_delivery_value != 0 && Filter_criteria_top_delivery_value != '') && (parseInt(products[articul][j].price_echo, 10) > parseInt(Filter_criteria_top_price_value, 10))) ) { flag_set_maximize_block = true; insert_element.setAttribute('class', insert_element.getAttribute('class') + ' product' + b1.replace(/([^A-Za-z0-9])/g, '') + articul); insert_element.setAttribute('style', 'display:none;'); } elements.appendChild(insert_element); set_rows_assign = 0; temp_rows_count++; } temp1 = document.createElement('tr'); temp2 = document.createElement('td'); temp2.setAttribute('colspan', '8'); temp1.appendChild(temp2); temp = document.createElement('center'); temp.setAttribute('class', 'Filter_detail_name'); temp_text = ''; if (flag_set_maximize_block) temp_text = 'Показать остальные ' + b1 + ' \\ '; temp.innerHTML = temp_text + 'Показать запчасти ' + b1 + ' с минимальным сроком поставки'; temp2.appendChild(temp); if (temp_rows_count > 1) elements.appendChild(temp1); } } if (!flag) { if (Filter_total_count <= 0) { temp1 = document.createElement('tr'); temp2 = document.createElement('td'); temp2.setAttribute('colspan', '8'); temp1.appendChild(temp2); temp = document.createElement('center'); //temp.setAttribute('class', 'Filter_detail_name'); temp.innerHTML = 'Аналогов не найдено'; temp2.appendChild(temp); elements.appendChild(temp1); } } $('.Filter_show_hide_products').click(function () { $('.product' + $(this).attr('product_id')).show(); $('[brand_id_main_row="' + $(this).attr('product_id') + '"]').attr('rowspan', $(this).attr('set_rows')); $('[product_id_main_row="' + $(this).attr('product_id') + '"]').attr('rowspan', $(this).attr('set_rows')); $(this).parent().find('span').remove(); $(this).remove(); }); $('.Filter_min_show_hide_products').click(function () { Filter_products[$(this).attr('product_id')].criteria = 'dostavka'; Filter_remake_table(); }); $('.Filter_min_other_show_hide_products').click(function () { Filter_products_other[$(this).attr('product_id')].criteria = 'dostavka'; Filter_remake_table(); }); } function Filter_make_new_articul_element(articul) { new_element = document.createElement('tr'); //new_element.setAttribute('class', 'Filter_items_articul Filter_items_articul_' + (Filter_temp_flag1 ? 'color1' : 'color2')); Filter_temp_flag1 = !Filter_temp_flag1; new_element.id = 'Filter_items_articul' + articul; return new_element; } function Filter_save_criteria_to_delete() { Filter_criteria_total_rows_per_articul = 1; Filter_criteria_top_price_value = document.getElementById('Filter_criteria_div_price').value; Filter_criteria_top_delivery_value = document.getElementById('Filter_criteria_div_delivery').value; Filter_remake_table(); } function Filter_set_sort() { Filter_criteria = document.getElementById('Filter_sort_by').value; Filter_remake_table(); } function Filter_set_sort_updown() { Filter_criteria_updown = document.getElementById('Filter_sort_by_updown').value; Filter_remake_table(); } function Filter_apply_sort_criteria(crit1, crit2) { Filter_criteria = crit1; Filter_criteria_updown = crit2; Filter_remake_table(); } $(document).ready(function () { $('#search-input-detailSearch ').keyup(function (e) { if ((e.which == 13)) { document.location = '/art/' + encodeURIComponent(document.getElementById(Filter_input_element).value); //Filter_start_search(); return false; } }); }); function Filter_clearForm() { $('#search-input-detailSearch').val(''); //return false; } function Filter_search_page(num, brand) { Filter_search_phrase = num; if (brand != '') { Filter_head_type = 2; Filter_search_brand = brand; } $('#' + Filter_input_element).val(num); Filter_start_search(); } function Filter_start_search_location() { document.location = '/art/' + encodeURIComponent($('#' + Filter_input_element).val()); } function Filter_search_more_find() { $("#getPriceUrlId").attr("href", $("#getPriceUrlId").attr("href") + '?detail=' + document.getElementById(Filter_input_element).value); return true; }