toBuy = new Array();
Count = new Array();
bSumm = new Array();

function buy(item){
var tb = false;
for(i=0;i<toBuy.length;i++){
if(toBuy[i]==item){
tb = true;
break;
}}
if(!tb){
toBuy[toBuy.length] = item;
Count[Count.length] = 1;}
else{
Count[i]++;
}
if(!bSumm[item] && bSumm[item]!=0){
bSumm[item]=0;
document.getElementById("selected_items").innerHTML += "<p class='sel_items' id='s"+item+"'>"+document.getElementById(item).getAttribute("info")+" Кол-во: "+bSumm[item]+", <a style=\"cursor:pointer;\" onclick=\"unBuy('"+item+"')\"><img src='images/remove.gif' border='0'></a></p>";
}
bSumm[item]++;
document.getElementById("s"+item).innerHTML = document.getElementById(item).getAttribute("info")+" Кол-во: "+bSumm[item]+", <a style=\"cursor:pointer;\" onclick=\"unBuy('"+item+"')\"><img src='images/remove.gif' border='0'></a>";
document.getElementById("s"+item).style.display="";
}

function unBuy(item){
bSumm[item]--;
if(bSumm[item]==0){
document.getElementById("s"+item).style.display = "none";}else{
document.getElementById("s"+item).innerHTML = document.getElementById(item).getAttribute("info")+" Кол-во: "+bSumm[item]+", <a style=\"cursor:pointer;\" onclick=\"unBuy('"+item+"')\"><img src='images/remove.gif' border='0'></a>";
}
for(i=0;i<toBuy.length;i++){
if(toBuy[i]==item){
Count[i]--;
break;
}}}

function doBuy(){
if(Count.length>0){
for(i=0;i<toBuy.length;i++){
child = document.createElement("input");
child.type = "hidden";
child.name = "buyItem"+toBuy[i];
child.value = Count[i];
document.forms.dobuy.appendChild(child);
}
document.forms.dobuy.submit();
}else{
alert("Вы ничего не выбрали!");
}}

function pageopen(url)
{
document.forms.other_page.action=url;
for(i=0;i<toBuy.length;i++)
{
child = document.createElement("input");
child.type = "hidden";
child.name = "buyItem"+toBuy[i];
child.value = Count[i];
document.forms.other_page.appendChild(child);
}
document.forms.other_page.submit();
}
