//to calculate amounts on the order form
function calcTotals () {
	var pd_books = (document.orderform.qty_pd_books.value - 0);
	var books_subtotal = pd_books * 24.95;	
	document.orderform.books_subtotal.value = books_subtotal.toFixed(2); 	
	var subtotal = books_subtotal;
	document.orderform.subtotal.value = subtotal.toFixed(2); 	
	var shippingtot = 0;
	//shipping to US is $4.50/book (canada is zero, intl uses surcharge field)
	if (document.orderform.country[1].checked) {
		shippingtot = pd_books * 4.5;
	}
	document.orderform.shipping.value = shippingtot.toFixed(2);
	var ship_surcharge = document.orderform.ship_surcharge.value - 0;	
	var gst = 0;
	if (document.orderform.country[0].checked) {
		gst = 0.05 * subtotal;
	}
	document.orderform.gst.value = gst.toFixed(2);	
	var totalcost = subtotal + shippingtot + ship_surcharge + gst;
	document.orderform.total.value = totalcost.toFixed(2);

	return true;	

}
function calcTotalsOLD () {
						
	var pd_books = (document.orderform.qty_pd_books.value - 0);
	var books_subtotal = pd_books * 24.95;	
	document.orderform.books_subtotal.value = books_subtotal.toFixed(2); 
	
	var totbooks = pd_books;
	/*
	document.orderform.qty_free_books.value = 0;
	if (pd_books > 4) {
		document.orderform.qty_free_books.value = 1;
		totbooks = pd_books + 1;
	}
	if (pd_books > 9) {
		document.orderform.qty_free_books.value = 3;
		totbooks = pd_books + 3;
	}
	if (pd_books > 14) {
		document.orderform.qty_free_books.value = 4;
		totbooks = pd_books + 4;
	}
	if (pd_books > 19) {
		document.orderform.qty_free_books.value = 6;
		totbooks = pd_books + 6;
	}
	if (pd_books > 24) {
		document.orderform.qty_free_books.value = 7;
		totbooks = pd_books + 7;
	}
	if (pd_books > 29) {
		document.orderform.qty_free_books.value = 9;
		totbooks = pd_books + 9;
	}
	if (pd_books > 34) {
		document.orderform.qty_free_books.value = 10;
		totbooks = pd_books + 10;
	}
	if (pd_books > 39) {
		document.orderform.qty_free_books.value = 12;
		totbooks = pd_books + 12;
	}
	if (pd_books > 44) {
		document.orderform.qty_free_books.value = 13;
		totbooks = pd_books + 13;
	}
	if (pd_books > 49) {
		document.orderform.qty_free_books.value = 15;
		totbooks = pd_books + 15;
	}	
	*/
	document.orderform.qty_total_books.value = totbooks - 0;
	/*	
	var ship_other1 = 0;
	var ship_other2 = 0;
	var ship_other3 = 0;
	var ship_other4 = 0;	
	var ship_other5 = 0;
	var ship_other6 = 0;
	var ship_other7 = 0;
	var ship_other8 = 0;
	var ship_other9 = 0;
	var ship_other10 = 0;
	var ship_other11 = 0;
	var ship_other12 = 0;
	*/
	var shippingtot = 0;
	/*
	if (totbooks > 4) {
		if (document.orderform.qty_other1.value) {
			ship_other1 = (document.orderform.qty_other1.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other2.value) {
			ship_other2 = (document.orderform.qty_other2.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other3.value) {
			ship_other3 = (document.orderform.qty_other3.value - 0) * 2.5;
		}

		if (document.orderform.qty_other4.value) {
			ship_other4 = (document.orderform.qty_other4.value - 0) * 2.5;
		}

		if (document.orderform.qty_other5.value) {
			ship_other5 = (document.orderform.qty_other5.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other6.value) {
			ship_other6 = (document.orderform.qty_other6.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other7.value) {
			ship_other7 = (document.orderform.qty_other7.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other8.value) {
			ship_other8 = (document.orderform.qty_other8.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other9.value) {
			ship_other9 = (document.orderform.qty_other9.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other10.value) {
			ship_other10 = (document.orderform.qty_other10.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other11.value) {
			ship_other11 = (document.orderform.qty_other11.value - 0) * 2.5;
		}
		
		if (document.orderform.qty_other12.value) {
			ship_other12 = (document.orderform.qty_other12.value - 0) * 2.5;
		}		
	}
	document.orderform.ship_other1.value = ship_other1.toFixed(2);
	document.orderform.ship_other2.value = ship_other2.toFixed(2);
	document.orderform.ship_other3.value = ship_other3.toFixed(2);
	document.orderform.ship_other4.value = ship_other4.toFixed(2);
	document.orderform.ship_other5.value = ship_other5.toFixed(2);
	document.orderform.ship_other6.value = ship_other6.toFixed(2);
	document.orderform.ship_other7.value = ship_other7.toFixed(2);
	document.orderform.ship_other8.value = ship_other8.toFixed(2);
	document.orderform.ship_other9.value = ship_other9.toFixed(2);
	document.orderform.ship_other10.value = ship_other10.toFixed(2);
	document.orderform.ship_other11.value = ship_other11.toFixed(2);
	document.orderform.ship_other12.value = ship_other12.toFixed(2);
	shippingtot = ((document.orderform.ship_other1.value - 0) + (document.orderform.ship_other2.value - 0) + (document.orderform.ship_other3.value - 0) + (document.orderform.ship_other4.value - 0) + (document.orderform.ship_other5.value - 0) + (document.orderform.ship_other6.value - 0) + (document.orderform.ship_other7.value - 0) + (document.orderform.ship_other8.value - 0) + (document.orderform.ship_other9.value - 0) + (document.orderform.ship_other10.value - 0) + (document.orderform.ship_other11.value - 0) + (document.orderform.ship_other12.value - 0) );
	*/
	
	var subtotal = pd_books * 24.95;
	var ship_surcharge = document.orderform.ship_surcharge.value - 0;
	
	if (document.orderform.country[1].checked) {
		shippingtot = pd_books * 4.5;
	}
	
	document.orderform.subtotal.value = subtotal.toFixed(2); 
	document.orderform.shipping.value = shippingtot.toFixed(2);
	
	var gst = 0;
	//if (document.orderform.incanada[0].checked) {
	if (document.orderform.country[0].checked) {
		//gst = 0.06 * (subtotal + shippingtot + ship_surcharge);
		gst = 0.05 * subtotal;
	}
	document.orderform.gst.value = gst.toFixed(2);
	
	var totalcost = subtotal + shippingtot + ship_surcharge + gst;
	document.orderform.total.value = totalcost.toFixed(2);

	return true;
}

function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}

