function addToCart (id_product, token, quantity) {
	$.ajax({
		type: 'POST',
		url: baseDir + 'ajax.php',
		async: true,
		cache: false,
		data: 'action=add&token=' + token + '&id_product=' + id_product + '&add=1&qty=' + quantity,
		success: function(content)	{

				refreshCart();
				var json_arr = eval("(" + content + ")");
				$('#cart_product_number').text(json_arr.product_number);
				$('#cart_product_total').text(json_arr.total_price);
				$('#cart_products_shipping').text(json_arr.shipping);
				$('#hidden_ajouter_au_panier').click();

		}
	});
}
function updateCart (id_product, token, quantity) {
	$.ajax({
		type: 'POST',
		url: baseDir + 'ajax.php',
		async: true,
		cache: false,
		data: 'action=update&token=' + token + '&id_product=' + id_product + '&add=1&qty=' + quantity,
		success: function(success)	{
			if (success == 'TRUE') {
				refreshCart();
			}
		}
	});
}

function refreshCart () {
	$.ajax({
		type: 'POST',
		url: baseDir + 'ajax.php',
		async: true,
		cache: false,
		data: 'action=refresh_cart&',
		success: function(content)	{
			if (content) {
				$('#nb_articles').html(content);
			}
			else {
				$('#nb_articles').html('');
			}
		}
	});
}

function submitAddToCart (form_obj) {
	$.ajax({
		type: 'POST',
		url: baseDir + 'ajax.php',
		async: true,
		cache: false,
		data: $(form_obj).serialize(),
		success: function(content)	{
			var json_arr = eval("(" + content + ")");
			$('#cart_product_number').text(json_arr.product_number);
			$('#cart_product_total').text(json_arr.total_price);
			$('#hidden_ajouter_au_panier').click();
		}
	});
	
	return false;
}


/*

var avgr = {
    src: 'themes/mtb/sifr/avgr.swf'
};


sIFR.activate(avgr);

    sIFR.replace(avgr, {
      selector: '#homepage .prix',
 			wmode: 'transparent',
      css: [
        'a { text-decoration: none; }'
        ,'a:link { color: #000000; }'
        ,'a:hover { color: #CCCCCC; }'
      ]
    });
*/
$(document).ready(function()
{


	window.fbAsyncInit = function()
	{
    	FB.init({
			appId: '134985346519499',
			status: true,
			cookie: true,
			xfbml: true
		});
	};
	
	(function()
	{
		var e = document.createElement('script');
			e.async = true;
			e.src = document.location.protocol + '//connect.facebook.net/fr_FR/all.js';
			
			document.getElementById('fb-root').appendChild(e);
	}());

	
	$('#inscrire-offrespartenaires').click(function(event)
	{
		event.preventDefault();
		
		$.ajax( {
			type:		'POST',
			url:		'ajax.php',
			data:		'action=optin',
			success:	function(data)
			{
				var message;
				
				if (data == 'TRUE')
				{
					message = 'Votre inscription aux offres partenaires a bien été prise en compte.';
				}
				else
				{
					message = "Une erreur s'est produite lors de votre inscription aux offres partenaires.";
				}
				
				window.alert(message);
			}
		} );
	});
});
