// prefs
	timeOffset = 2;
	window.onresize = function() { fix_layout(); };

function buy( variant_id ) {
	new Ajax.Updater('cart', '/?add_item=' + variant_id, {});
	}

function add_coupon() {
	new Ajax.Updater('cart_checkout', '/?add_coupon=' + $('coupon_code').value, {});
	}

function change_shipping() {
	if( $F('sameAs') == 1 )
		nation_id = $F('nation');
	else nation_id = $F('ship_nation'); 
	new Ajax.Updater('cart_checkout', '/?change_shipping_by_nation=' + nation_id, {});
	}

function update_sameAs() {
	if( $F('sameAs') == 1 ) $('ship_inputs').style.display = 'none';
	else $('ship_inputs').style.display = 'block';
	}

function setMessage( message ) {
	if( message != false ) {
		document.getElementById('message').innerHTML = message;
		document.getElementById('message').style.display = 'block';
		}
	else document.getElementById('message').style.display = 'none';
	}

function spinner( action ) {
	if( action == true ) 
		document.getElementById('spinner').src = 'images/radar_on.gif';
	else
		document.getElementById('spinner').src = 'images/radar_off.gif';
	}


function ismaxlength( obj ) {
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
		obj.value=obj.value.substring(0,mlength)
	}

function fix_layout() {			
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
		myHeight = window.innerHeight;
		} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
		}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
		}
	myHeight = myHeight - 235;
	$('content').style.height = myHeight + 'px';
	}

function checkFields() {
	required = new Array( 'firstname','lastname','email','street1','city','postalCode','card_accountNumber', 'card_cvs' );
	labels = new Array( 'first name','last name','email address','billing street address','billing city','billing postal code','credit card number', 'credit card CVS code (on back of card)' );
	moreRequired = new Array( 'ship_name','ship_street1','ship_city','ship_postalCode' );
	moreLabels = new Array( 'shipping recipient','shipping street address', 'billing city', 'billing postal code' );
	if( $F('sameAs') == 0 ) {
		var i = required.length;
		for( var j=0; j<moreRequired.length; j++ ) {
			required[i] = moreRequired[j];
			labels[i] = moreLabels[j];
			i++;
			}
		}
	for( var i=0; i<required.length; i++ ) {
		if( $F( required[i] ) == '' ) {
			alert( "Form field missing: " + labels[i] );
			return false;
			}
		}
	if( $('card_accountNumber').length < 12 ) {
		alert( 'Please fill in a valid credit card account number.' );
		return false;
		}
	$('btn_place_order').value = 'please wait';
	$('btn_place_order').disabled = true;
//	$('btn_start_over').style.visibility = 'hidden';
	document.forms[0].submit();
	}
