/**
 * Paypal form manipulation
 */

var bookPrice = 29.95;

var usaShipCost = new Array();
	usaShipCost[1] = 4;
	usaShipCost[2] = 7;
	usaShipCost[3] = 10;
	usaShipCost[4] = 13;
	usaShipCost[5] = 16;
var canShipCost = new Array();
	canShipCost[1] = 7;
	canShipCost[2] = 14;
	canShipCost[3] = 20;
	canShipCost[4] = 25;
	canShipCost[5] = 29;
var intShipCost = new Array();
	intShipCost[1] = 16;
	intShipCost[2] = 30;
	intShipCost[3] = 42;
	intShipCost[4] = 52;
	intShipCost[5] = 60;

function updatePrices()
{
	var numBooks  = document.getElementById( 'qty' )
	var quantity  = numBooks.options[ numBooks.selectedIndex ].value;
	document.getElementById( 'usa-price' ).innerHTML = ( bookPrice * quantity ).toFixed( 2 );
	document.getElementById( 'can-price' ).innerHTML = ( bookPrice * quantity ).toFixed( 2 );
	document.getElementById( 'int-price' ).innerHTML = ( bookPrice * quantity ).toFixed( 2 );
	document.getElementById( 'usa-ship'  ).innerHTML = usaShipCost[quantity];
	document.getElementById( 'can-ship'  ).innerHTML = canShipCost[quantity];
	document.getElementById( 'int-ship'  ).innerHTML = intShipCost[quantity];
}

function countryOrder( type )
{
	var orderForm = document.forms[0];
	var numBooks  = document.getElementById( 'qty' )
	var quantity  = numBooks.options[ numBooks.selectedIndex ].value;
	// Grab shipping costs
	var usaShipping = document.getElementById( 'usa-shipping' ).value;
	var canShipping = document.getElementById( 'can-shipping' ).value;
	var intShipping = document.getElementById( 'int-shipping' ).value;
	// update form
	orderForm.quantity.value = quantity;
	// which are we selling?
	switch ( type )
	{
		case 'usa':
			orderForm.shipping.value    = usaShipCost[quantity].toFixed( 2 );
			orderForm.item_number.value = 'usa-0-9793834-0-4';
			break
		case 'can':
			orderForm.shipping.value    = canShipCost[quantity].toFixed( 2 );
			orderForm.item_number.value = 'can-0-9793834-0-4';
			break
		case 'int':
			orderForm.shipping.value    = intShipCost[quantity].toFixed( 2 );
			orderForm.item_number.value = 'int-0-9793834-0-4';
			break
	}
	orderForm.submit();
}