var buynow = {
	
	//initialises handlers for the buy pages
	init: function() {
	
		//check 1 pair of knickers is selected
		if( $('buy-f1') ) $('buy-f1').observe( 'submit', function(e) {
			if( !buynow.check1() ) e.stop();
		});
	
		//back button on details page
		if( $('buy-back-btn1') ) $('buy-back-btn1').observe( 'click', function(e) { 
			$('buy-f2').action = 'buy-now-select-items.php';
			$('buy-f2').submit();
			e.stop();
		});
	
		//button to copy over billing address details to the shipping address
		if( $('buy-copyba-btn') ) $('buy-copyba-btn').observe( 'click', function(e) {
			buynow.copyba();
			e.stop();
		});
	
		//back button on confirm page
		if( $('buy-back-btn2') ) $('buy-back-btn2').observe( 'click', function(e) { 
			$('buy-f3').action = 'buy-now-details.php';
			$('buy-f3').submit();
			e.stop();
		});
	
	},
	
	//copies the billing address details over to the shipping address
	copyba: function() {
	
		[ 'address1', 'address2', 'city', 'county', 'postcode' ].each( function( elm ) {
			$( 'sh_' + elm ).value = $F( elm );
		});
	
		$( 'sh_country' ).childElements()[ $( 'country' ).selectedIndex ].selected = true;
	
	},
	
	//checks the selection form to make sure at least 1 item has been picked
	check1: function() {
		
		if( $F('qty_small') == 0 && $F('qty_medium') == 0 && $F('qty_large') == 0 ) {
			alert( 'Please choose at least one pair of Knickers...' );
			return false;
		}
		
		return true;
	
	}

}

Event.observe( document, 'dom:loaded', buynow.init );