function saveQuantity() { jQuery.cookie('quantity', jQuery("#quantity").val(), { expires: 7 }); }
function addToCart() { jQuery('#checkout').css('display', 'block'); jQuery('#cart').css('display', 'none'); }

var triggered = false;
var focusdraw = false;


function pop_up(page){
	window.open(page,"_new","toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizeable=yes,width=400,height=500");
}
	


/* There is something messed up in here that I didn't have time to fix. Please look at this */

jQuery(document).ready(function() {

	setTimeout(function() { 
		if(!triggered) { 
			jQuery('input#fname').parent().parent().addClass("drawfocus"); 
			focusdraw = true;
		}}, 5000);
		
	if(jQuery.cookie('quantity') == "" || jQuery.cookie('quantity') == null) {
		jQuery("#itemquantity").val(1);
		quantityChanged();
	}
	else {
		//alert(jQuery.cookie('quantity'));
		jQuery("#itemquantity").val(jQuery.cookie('quantity'));
		updatePrices();
	}
});


jQuery(document).ready(function() {
								
	
	jQuery("#country").change(function() {
		updatePrices();
	});

	jQuery("#usa_states").hide();
	jQuery("#country").change(function() {
		country = jQuery("#country").val();
		if(country == 'US') {
			jQuery("#usa_states").show();	
		} else {
			jQuery("#usa_states").hide();	
		}
	})


								
	jQuery('#add_insurance').click(function() {
		var checked = jQuery('#add_insurance').attr('checked'); 
		var total =  jQuery('#totalhidden').val().substr(1);
		var insurance =  jQuery('#insurancehidden').val().substr(1);
		
		if(checked) { //when checking
			jQuery('#insurance').val("£" +insurance);
			jQuery('#total').val("£" +total)
			updatePrices();
		
		} else { //when unchecking
			jQuery('#insurance').val("£" + "0.00");
			//jQuery('total').val(jQuery('#cost').val());
			total = (parseFloat(total) - parseFloat(insurance)).toFixed(2);
			jQuery('#total').val("£" +total)
			updatePricesOnCheck();
		}
	}); 

	jQuery('input.text, select').focus(function() {
		triggered = true;								
		
		/* Remove focus puller if active  */
		if(focusdraw) {
			jQuery('input#fname').parent().parent().removeClass("drawfocus");
		}
		
		jQuery(this).parent().parent().addClass("active");
		jQuery(this).animate({ backgroundColor: '#b1b1b1' }, 250);
	}).blur(function() {
		jQuery(this).parent().parent().removeClass("active");
		jQuery(this).animate({ backgroundColor: '#cfd2d2' }, 250);
	});
});



function doCheckout() {
	pageTracker._trackEvent('Goals', 'Checkout button click', 'Customer clicked buy button')
	
	/*
	try{
	  var pageTracker = _gat._getTracker("UA-7505053-2");
	  pageTracker._trackPageview();
	  pageTracker._addTrans(
		  "1234", // order ID - required
		  "Womens Apparel", // affiliation or store name
		  "11.99", // total - required
		  "1.29", // tax
		  "15.00", // shipping
		  "San Jose", // city
		  "California", // state or province
		  "USA" // country
		);
	 
	
	   // add item might be called for every item in the shopping cart
	   // where your ecommerce engine loops through each item in the cart and
	   // prints out _addItem for each 
	   pageTracker._addItem(
		  "1234", // order ID - necessary to associate item with transaction
		  "DD44", // SKU/code - required
		  "T-Shirt", // product name
		  "Olive Medium", // category or variation
		  "11.99", // unit price - required
		  "1" // quantity - required
	   );
	}
	*/
}
