function SetBasketAutoOpen(ch) { setCookie('HideAutoBasket',(ch.checked)?1:0); } function setCookie(name, value,expires) { document.cookie = name + "=" + escape(value)+"; path=/; "+((expires)?"":"expires=Thursday, 31-Dec-2020 23:59:59 GMT;"); } function getCookie(name) { var prefix = name + "=" var cookieStartIndex = document.cookie.indexOf(prefix) if (cookieStartIndex == -1) return '' var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length) if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex)) } function CheckLoad(form) { goods = GetGoodsFromBasket(); if (form) { var el = form.elements; ss = el.length; for (var i=0;i 0) { el[i].value = goods[id]; el[i].style.fontWeight = 'bold' el[i].style.color = 'black' OnEditChange(id,el[i]); } else { el[i].style.color = 'gray' el[i].style.fontWeight = 'normal' el[i].style.align = 'center' el[i].value='1'; } } } } UpdateWholePrice(); UpdateCompareButtons(); } function AmountChange(form,id,delta) { basket = false; if (!form) { form = document.basket_form basket = true; } el = form.elements('amount_'+id) amount = parseInt(el.value) + delta; el.value=amount; if (el.value == 'NaN' || el.value < 0) el.value = '0' BuyPress(form,id); el=document.getElementById('sum_'+id); if(el) { if(isNaN(amount)) el.innerHTML = 0; else el.innerHTML = Goods[id][1]*amount; } if (basket) { UpdateWholePrice(); BasketChanged = 1; } } function GetGoodsFromBasket() { var basket = getCookie('eshop_basket'); var goods_arr = basket.split("\t"); //alert(basket); var goods = new Array; for (i in goods_arr) { if (goods_arr[i] == "") continue; var arr = goods_arr[i].split(' '); var am = parseInt(arr[1]); if (am>0) goods[arr[0]] = am; } return goods; } function GetGoodsFromBasketName() { var basket = getCookie('eshop_basket_name'); var goods_arr = basket.split("\t"); //alert(basket); var goods = new Array; for (i in goods_arr) { if (goods_arr[i] == "") continue; var arr = goods_arr[i].split(' '); var am = parseInt(arr[1]); if (am>0) goods[arr[0]] = am; } return goods; } function UpdateBasketCookie(basket) { var goods_arr = new Array; for (i in goods) { if (parseInt(goods[i]) == 0) continue; goods_arr[goods_arr.length] = i+" "+goods[i]; } setCookie('eshop_basket',goods_arr.join("\t"),1); } function PutInBasket(id, amount) { goods = GetGoodsFromBasket(); goods_name = GetGoodsFromBasketName(); goods[id]=amount; UpdateBasketCookie(goods); UpdateWholePrice(); } function BuyPress(form,id) { amount = form['amount_'+id]; if (amount) { am = parseInt(amount.value); if (isNaN(am)) am = 0; PutInBasket(id,am); amount = form['amount_'+id]; if (am == 0) { amount.style.color = 'gray' amount.style.fontWeight = 'normal' } else { amount.style.color = 'black' amount.style.fontWeight = 'bold' } OnEditChange(id,amount); } else { PutInBasket(id,1); UpdateBasketSummary(); } return false; } function OnEditChange(id,edit) { SomeChanges = true; edit.value = parseInt(edit.value); if (!(edit.value > 0)) {edit.value = '0'}; if (!document.all('whole_price_all')) { //alert(edit.id+' | '+edit.name) if (edit.name.indexOf('amount_')==0) PutInBasket(id,edit.value); else PutInBasket(id+'|'+CurrentSetId, edit.value); var el = document.getElementById('amount_div_'+id) //alert(el); if (edit.value == 0) { if (el) { el.style.visibility = 'hidden'; el.style.display = 'none'; } } else { if (el) { el.style.visibility = 'visible'; el.style.display = 'block'; } var el1 = document.getElementById('amount_amount_'+id) if (el1) { el1.innerHTML = ': '+edit.value; } } } //OnEditBasketChange(id,edit) UpdateWholePrice(); } function UpdateWholePrice() { b_div = document.getElementById('basket_div'); c_div = document.getElementById('price_caption'); v_div = document.getElementById('price_value'); but_div = document.getElementById('button_order'); //alert(c_div) if (b_div == null && c_div == null) return; goods = GetGoodsFromBasket(); summ = 0; summ_original = 0; cnt = 0; var names = ''; for (i in goods) { //alert(i); amount = parseInt(goods[i]); if (isNaN(amount)) amount=0; if (amount==0) continue; cnt++; pr = parseFloat(Goods[i]); if (isNaN(pr)) pr=0; summ+=Goods[i][1]*amount; summ_original+=Goods[i][0]*amount; //alert(Goods[i][1]*amount); names+=''+Goods_name[i][1]+' ' + amount + ''; } // Обновить картинку корзины: (ноль/не ноль товаров) var s=''; var sc=''; // var sv=''; if (cnt==0) { s+='
Лист заказов
Лист заказов пуст.
'; } else { s+=''; s+='
Лист заказов
'; s+=names; s+='
Итого: ' + summ + ' руб
Для редактирования и отправки листа заказа необходимо
Оформить заказ
'; } if (b_div) b_div.innerHTML=s; if (c_div) c_div.innerHTML=sc; // if (v_div) v_div.innerHTML=sv; if (document.getElementById('ebasket_div')) { v_div.innerHTML=(summ_original == summ)?(summ+' руб.'):(''+summ_original+' '+summ+' руб.'); } } function gotoOrder(){ goods = GetGoodsFromBasket(); summ = 0; summ_original = 0; cnt = 0; for (i in goods) { amount = parseInt(goods[i]); if (isNaN(amount)) amount=0; if (amount==0) continue; cnt++; pr = parseFloat(Goods[i]); if (isNaN(pr)) pr=0; summ+=Goods[i][1]*amount; summ_original+=Goods[i][0]*amount; } if (summ < 2000){ alert('Оформление заказа возможно только при наличие в корзине\nтовара на сумму более 2000 рублей'); return false; }else{ opener.location.href='/order/new/'; window.close(); return true; } } function PutButton(forms,id,click) { var flag=0; goods = GetGoodsFromBasket(); if(click) BuyPress(forms,id); if (goods[id]) flag=1; // alert(flag); if(flag) {el=document.getElementById('put_'+id); el.src="/imgs/i_push.gif"; el.alt="Удалить из заказа"; document.getElementById('amount_'+id).value=0; document.getElementById('button_order_'+id).innerText="Удалить из заказа"; } else { el=document.getElementById('put_'+id); el.src="/imgs/i_put.gif"; el.alt="Заказать"; document.getElementById('amount_'+id).value=1; document.getElementById('button_order_'+id).innerText="Заказать"; } }