function PriceNumberTotal(myPrice, myNumber, totalID){
	// check that a number is entered
	myNumber=myNumber*1;
	test=isNaN(myNumber);
	if(test){
		alert("Number of bottles should be a number!");
		return;
	}
	// calculate and write total price for this row
	myTotal=myNumber*myPrice*100;
	myTotal=Math.round(myTotal);
	myTotalClear=myTotal/100;
	document.getElementById(totalID).innerHTML=cents(myTotalClear);
}
function cents(price){
	// round price
	price=price*100;
	price=Math.round(price);
	price=price/100;
	// add cents if needed
	var fullength, decimal, fullprice;
	strprice = new String(price);
	fullength = strprice.length;
	decimal = strprice.indexOf(".",[0]);
	if(decimal==-1){fullprice=price+'.00';}
	else {
		delta=fullength-decimal-1;
		if(delta==1){fullprice=price+'0';}
		else {fullprice=price;}
	}
	return fullprice;
}
function bottlesTotal(){
	x=document.getElementById('wineselectionform');
	totalNOB=0;
	totalSUB=0;
	// iterate through all boxes, count bottles and subtotal
	for (var i=0;i<x.length;i++){
	  	if(x.elements[i].type=='text' && x.elements[i].name!="nomofbot" && x.elements[i].name!="postcode" && x.elements[i].name!="subtotalin"){
			rowNOB=(x.elements[i].value=='Enter Qty')?0:x.elements[i].value;
			// check that a number is entered
			rowNOB=rowNOB*1;
			test=isNaN(rowNOB);
			if(test){
				return;
			}
			totalNOB+=rowNOB*1;
			rowId=new String(x.elements[i].name);
			rowId=rowId.replace('winenumber','');
			thisRowHidden='hf'+rowId;
			winePrice=document.getElementById(thisRowHidden).value;
			wineTotal=rowNOB*winePrice*100;
			wineTotal=Math.round(wineTotal);
			wineTotal=wineTotal/100;
			totalSUB+=wineTotal;
		}
	  }
	  document.getElementById('nomofbot').value=totalNOB;
	  document.getElementById('subtotalin').value=cents(totalSUB);
	  volumeDiscount(totalNOB,totalSUB);
}

function volumeDiscount(my_volume, my_price){
	// if bottles total >=6 and < 12 discount 0.97
	if(my_volume>=6 && my_volume<12){
		my_price=my_price*0.95;
	}
	// if bottles total >= 12 discount 0.93
	else if(my_volume>=12){
		my_price=my_price*0.90;
	}
	document.getElementById('subtotwd').innerHTML=cents(my_price);
}