var ari = new Array();

function product_item_plus(item)
{	//document.getElementById('tmpbase').innerHTML="<script>prod"+item+".value++;</script>";
	choice2(item+1,1);
	recount();
}
function product_item_minus(item)
{
	choice2(item+1,-1);
	recount();
}
function product_item_del(item,am)
{
	choice2(item+1,-am);
	recount();
}

function show_basket()
{
fill_order();
var tst="<table width='100%'>";
var j=0,cnt=0;
var endprice=0.00;
if(ari.length>0)
{
  delete ari;
  ari = new Array();
}

for(var i=0;i<totalcount;i++)
{
  var tempprice=0;
  if(prods[i].cnt>0)
  {
    ari[j++]=i;
    cnt+=prods[i].cnt;
    if(prods[i].cnt>0 && prods[i].cnt<10)
    {
       tmpprice=prods[i].price;
    }
    if(prods[i].cnt>=10 && prods[i].cnt<50)
    {
       tmpprice=prods[i].price2;
    }
    if(prods[i].cnt>=50 && prods[i].cnt<100)
    {
       tmpprice=prods[i].price3;
    }
    if(prods[i].cnt>=100)
    {
       tmpprice=prods[i].price4;
    }
    endprice+=(tmpprice*prods[i].cnt);
    tst += "<tr ><td style='border-bottom:1px solid #B4D0DC;'>&nbsp;&nbsp;<small>"+j+".</small>&nbsp;&nbsp;</td><td style='border-bottom:1px solid #B4D0DC;'>";
    tst += prods[i].name;
    tst += "</td><td style='border-bottom:1px solid #B4D0DC;'>"+tmpprice+" ðóá.</td>";
    tst += "<td style='border-bottom:1px solid #B4D0DC;'><input type='text' size='3' onchange='recount();' maxlenght='6' id='prod"+i+"' value="+prods[i].cnt+">øò.</td>";
    tst += "<td align='center' style='border-bottom:1px solid #B4D0DC;'>";
    tst += "<button onClick='choice2("+i+"+1,1);'><a href='javascript:choice2("+i+"+1,1)'>+1</a></button>";
    tst += "&nbsp;<button onClick='choice2("+i+"+1,-1);'><a href='javascript:choice2("+i+"+1,-1)'>-1</a></button>";
    tst += "&nbsp;<button onClick='choice3("+i+"+1,0);'><a href='javascript:choice3("+i+"+1,0)'>Óäàëèòü</a></button></td><tr>";
    //tst += "<div id='tmpbase'></div>";

    //document.write(tst);

  }
}
tst += "<tr><td colspan='4' align='center'>";
tst += "<input type='hidden' name='end_cost' value='"+endprice+"'>";
tst += "Âñåãî: <b>"+cnt+" øò.</b> íà ñóììó: <b>"+endprice+" ðóá. </b></td>";
tst += "<td><button onClick='recount();'><a href='javascript:recount()'>Ïåðåñ÷èòàòü</a></button></td></tr></table>";
document.getElementById('basket').innerHTML=tst;
}

function recount(bas_id)
{
  var tmp="";
  for(var i=0;i<ari.length;i++)
  {
    tmp="set_i_i_count("+ari[i]+",document.getElementById('prod"+ari[i]+"').value);";
    eval(tmp);
  }
  fill_cookie();
  show_basket();
}

function del_all()
{
  for(var i=0;i<totalcount;i++)
  {
    set_i_i_count(i,0);
  }
  fill_cookie();
  show_basket();
}

function order()
{
//  var href=geturl();
//  window.location.href=href;
 // del_all();

 fiovalue      = document.getElementById('fio').value;
 emailvalue    = document.getElementById('email').value;
 telefonvalue  = document.getElementById('telefon').value;
 adresvalue    = document.getElementById('adres').value;
 bstypvalue    = document.getElementById('bstyp').value;

 if((fiovalue+emailvalue+telefonvalue+adresvalue)=="")
 {
   alert("Ââåäèòå õîòü êàêèå-òî êîíòàêòíûå äàííûå.");
   return false;
 }else{
  setCookies("bstyp",bstypvalue);
  setCookies("fio",ru2en(fiovalue));
  setCookies("email",ru2en(emailvalue));
  setCookies("telefon",ru2en(telefonvalue));
  setCookies("adres",ru2en(adresvalue));
//  var mydate = new Date();
//  var tempdat = (mydate.getDate()).toString();
//  tempdat += (mydate.getHours()).toString();
//  tempdat += (mydate.getMinutes()).toString();
//  setCookies("date",tempdat);


//  document.getElementById('all_all').innerHTML='<br><br><h4 align=center>Ïîäîæäèòå, ïîæàëóéñòà, èä¸ò îôîðìëåíèå çàêàçà..</h4><br><br>';
  var str_tmp=getCookie('choice');
//  document.getElementById('f_list').innerHTML='<input name="f_choice" type="hidden" value="'+str_tmp+'">';
    document.getElementById('choice').value = str_tmp;
//  window.location.href="order_send.php";
 }
 // return false;
}

function geturl()
{
  recount();
  var tmp="order_send.php?";
  for(var i=0;i<totalcount;i++)
  {
    if(prods[i].cnt>0)
    {
      tmp+="ch["+prods[i].id+"]="+prods[i].cnt+"&";
    }
  }

  tmp+="&bstyp="+bstyp.value;
  tmp+="&fio="+fio.value;
  tmp+="&email="+email.value;
  tmp+="&telefon="+telefon.value;
  tmp+="&adres="+adres.value;

  return tmp;
}

function ru2en(str)
{

  var ruline,enline;
  ruline = new String('!1234567890ÀÁÂÃÄÅ¨ÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÛÚÝÞß àáâãäå¸æçèéêëìíîïðñòóôõö÷øùüûúýþÿABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqwrstuvxyz¹@"*$%#^&()_+-=[]{}|/<>,.;:\\');
 // enline = new String("ABVGDEEHZIJKLMNOPRSTUFXC{WW}Y[]*Q+abvgdeehzijklmnoprstufxc{ww}y@=_q#");
  var retstr,tmp;
  retstr = new String("44");
//  retstr = new String("&32;");
  tmp = -1;
  for(var i=0;i<str.length;i++)
  {
    tmp = ruline.indexOf(str.charAt(i));
    tmp = (tmp>=0)?tmp:'0';
   // retstr += (tmp>=0)?enline.charAt(tmp):str.charAt(i);
    retstr += ":";
    retstr += tmp;
  }
  return retstr;

}