/*
 * Copyright 2001-2005 Igor Kuznetsov <igk@igk.ru>
 */
  var popup = new PopupWindow('amount');
  
function showAmount(item)
{
    popup.autoHide(); 
    popup.offsetX = 25;
    popup.offsetY = 0;
    popup.populate('<div onkeydown="if (event.keyCode==13) { event.returnValue = false; getAmount('+item+'); popup.hidePopup(); return false; }" style="font-family: Tahoma; font-size: 11;"><form name="amount" method="post"><input name="amount" type="text" value="1" style="font-size: 11px; vertical-align: middle;" size="4"><input type="button" value="&#x221A" onclick="getAmount('+item+'); popup.hidePopup(); return false;" style="vertical-align: middle; font-size: 10px;"><form></div>'); 
    popup.showPopup('item-'+item);
    document.forms['amount'].amount.focus(); 
    document.forms['amount'].amount.select();
    return false;
}

function addBasket(item, amount)
{
    if (item == null || item == '')
        return false;
    if (amount == null || amount == '')
        amount = 1;    
    cookies = getCookie('basket');
    if (cookies == null || cookies == ' ') cookies = '';
    if ((begin_item = cookies.indexOf(item)) != -1) {
        begin_amount = cookies.indexOf('(', begin_item) + 1;
        end_amount = cookies.indexOf(')', begin_item);
        amount = Number(amount)+Number(cookies.substring(begin_amount, end_amount));
        cookies = cookies.substring(0, begin_amount)+amount+cookies.substring(end_amount);
    } else 
        cookies = cookies+(cookies.length>1?'-':'')+item+'('+amount+')';
    setCookie('basket', cookies);
    alert('Товар добавлен в корзину');
    return false;
}

function getAmount(item)
{
    if (document.forms['amount'].amount.value != '' && document.forms['amount'].amount.value != 0)
        addBasket(item, document.forms['amount'].amount.value);
}


