
var popup = new PopupWindow('amount');
  
function showAmount(item)
{
    popup.autoHide(); 
    popup.offsetX = 0;
    popup.offsetY = 45;
    popup.populate('<div onkeydown="if (event.keyCode==13) { event.returnValue = false; getAmount('+item+'); popup.hidePopup(); return false; }" style="font-family: Tahoma; font-size: 12px;"><form name="amount" method="post"><input name="amount" type="text" value="1" style="font-size: 12px; vertical-align: middle; height: 20px;" size="2" maxlength="3"><input type="button" value="OK" onclick="getAmount('+item+'); popup.hidePopup(); return false;" style="vertical-align: middle; font-size: 12px; height: 20px;"><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);
    document.location = document.location;
    return false;
}

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


