
var msg='msg';
var deliverycost=5;

var free_delivery=100;

var reduced_deliverycost=0;//

var headercolor='';var headertext='#825422';var ordercolor1='';
var ordercolor2='';
var totalcolor='';

var actual_deliverycost=deliverycost;
var itemn=0;

var total_price=0;
var item_arr=new Array();
var price_arr=new Array();
var quantity_arr=new Array();
var group_arr=new Array();
var discountgroup=new Array("G1","G2","G3","G4");
var discountgroupmin=new Array(3,4,3,3);
var discountgroupval=new Array(10,60,24,24);
var discountgroupant=new Array(0,0,0,0);
var discountgrouptxt=new Array("Discount text1","Discount text2","Discount text3","Discount text4");var temp_item_arr=new Array();
var temp_price_arr=new Array();
var temp_group_arr=new Array();
var temp_quantity_arr=new Array();
var bill_arr1=new Array();
var bill_arr2=new Array();
var bill_arr3=new Array();
var bill_item_ix=new Array();
var bill_ix=0;
var sw_delete=false;
var first_order=true;

function delete_all(showbasket)
{itemn=0;total_price=0;bill_ix=0;

first_order=true;
base.location.href='/base.html';
for(var i=0;i<discountgroupant.length;i++)
{discountgroupant[i]=0;}
if(showbasket!='nobasket')
{corpo.location.href='basket.html';}
}


function discountcheck(item2,group2,quan2)
{for(var i=0;i<discountgroup.length;i++)
{
if(discountgroup[i]==group2)
{discountgroupant[i]=discountgroupant[i]+eval(quan2);
if(discountgroupant[i]>=discountgroupmin[i])
{temp2=discountgroupant[i]%discountgroupmin[i];temp1=(discountgroupant[i]-temp2)/discountgroupmin[i];discountgroupant[i]=temp2;discount(discountgrouptxt[i],discountgroupval[i],temp1);}
}}
}
function discount(discounttekst,reduction,quantity)
{bill_arr1[bill_ix] = discounttekst;bill_arr2[bill_ix] = reduction;bill_arr3[bill_ix] = quantity;bill_item_ix[bill_ix] = null;bill_ix++;total_price=total_price-reduction*quantity;if (sw_delete == false)
alert(discounttekst+""+reduction*quantity+"deducted\nTotal price:"+total_price);}
function delete_order(itemix)

{ for(var i = 0; i < itemn; i++)
{ temp_item_arr[i] = item_arr[i]; temp_price_arr[i] = price_arr[i]; temp_quantity_arr[i] = quantity_arr[i]; temp_group_arr[i] = group_arr[i];}

for(var i=0; i<discountgroupant.length; i++)
 {discountgroupant[i]=0;
 }
j=itemn;
 itemn=0; total_price=0; bill_ix = 0;sw_delete = true;
 for(var i=0; i < j; i++)
{if (i != itemix)
order(temp_item_arr[i],temp_price_arr[i],temp_quantity_arr[i],temp_group_arr[i]);
 }sw_delete = false;
base.document.frm.basket.value=''+total_price;
if (total_price == 0)
 { first_order = true;
 base.location.href='base.html'; }
 corpo.location.href='basket.html';}
function order_ok(item,price,quantity)
{
if (sw_delete == true)
 return true; else
 {
  if (msg == 'nomsg')
   return true;
   else
    {
	temp = total_price+price*quantity;






	return (confirm("Please confirm ordering:   Nr. "+quantity+",   "+item+",   Price:  Lire "+price+"\nTotal in basket:  Lire "+temp));
	}
  }
}

function order( item, price, quantity, group)

{if (order_ok(item,price,quantity))
{
item_arr[itemn] = item;price_arr[itemn] = price;quantity_arr[itemn] = quantity;group_arr[itemn] = group;bill_item_ix[bill_ix] = itemn;itemn++;
bill_arr1[bill_ix] = item;bill_arr2[bill_ix] = price;bill_arr3[bill_ix] = quantity;bill_ix++;total_price=total_price+price*quantity;
actual_deliverycost=deliverycost;
if (total_price > free_delivery)
 actual_deliverycost=reduced_deliverycost;
discountcheck(item,group,quantity);
if (first_order==true && sw_delete == false)
 {first_order=false; base.location.href='base.html'; }
 else base.document.frm.basket.value=''+round_amount(total_price);}}
function send_order()
{ parent.corpo.location.href='ordform.html'; }
function round_amount(amount)
{
var string_amount = "";
var decimal_sign;amount = parseFloat(amount);
if (!(isNaN(amount)))
{
amount = Math.round(amount * 100);amount = amount / 100;

string_amount = new String(amount);decimal_sign = string_amount.indexOf("");
if (decimal_sign == -1)
{

 string_amount =string_amount+"";
 }
 else
 { if (decimal_sign == (string_amount.length - 2)) {
 string_amount=string_amount+"0"; }
 }
}
else {
string_amount = "0"; }
return string_amount;}
