function addToCart(product, qtyvar) {
	jQuery.colorbox({href:"cartpopup.php?addproduct="+product+"&qty="+qtyvar, onComplete: function() {
		refreshCart();
	}});
}

function refreshCart() {
	jQuery.post("ajax.php", { sessid: sessid, action: "refreshcart" },
	function(data) {
		jQuery('#cartcontainer').show();
		jQuery('#cartcontainer').html(data);
		calcSubtotal();
		calcShip();
		calcPrice();
	});
}

function calcPrice() {
	jQuery.post("ajax.php", { sessid: sessid, action: "calcprice" },
	function(data) {
		jQuery('#price').html(data);
	});
}

function calcSubtotal() {
	jQuery.post("ajax.php", { sessid: sessid, action: "calcsubtotal" },
	function(data) {
		jQuery('#subprice').html(data);
	});
}

function calcShip() {
	jQuery.post("ajax.php", { sessid: sessid, action: "calcship" },
	function(data) {
		jQuery('#shipprice').html(data);
	});
}

function removeProduct(product) {
	jQuery.post("ajax.php", { sessid: sessid, action: "removeproduct", product: product },
	function(data) {
		refreshCart();
	});
}

function updateQty(product, qty) {
	jQuery.post("ajax.php", { sessid: sessid, action: "updateqty", product: product, qty: qty },
	function(data) {
		refreshCart();
	});
}

function removeProduct(elm, product) {
	//jQuery(elm).parent().parent().parent().parent().parent().css('backgroundColor', '#ffd0d0');
	jQuery(elm).parent().parent().parent().parent().parent().fadeOut('fast', function() {
		jQuery.post("ajax.php", { sessid: sessid, action: "removeproduct", product: product },
		function(data) {
			refreshCart();
		});
	});
	
}

function updateTaxAndShipping(zone) {
	jQuery.post("ajax.php", { sessid: sessid, action: "loadtaxandshipping", zone: zone },
	function(data) {
		refreshCart();
	});
}

function attemptLogin() {
	jQuery.post("ajax.php", { sessid: sessid, action: "login", email: jQuery('#login_email').val(), password: jQuery('#login_password').val() },
	function(data) {
		if(data == "success") {
			//account found
			jQuery('#loginpopup_inner').fadeOut('fast', function() {
				jQuery('#loginpopup_inner').html('<div style="margin: 50px; text-align: center;">Login successful. Please wait...</div>');
				jQuery('#loginpopup_inner').fadeIn('fast');
				setTimeout('window.location.reload();', 2500);
			});
		} else {
			//no account found
			jQUery('#login_password').val('');
			jQuery('.loginerror').fadeIn('fast', function() {
				jQuery.colorbox.resize();
			});
		}
	});
}
