function ajouter_article(article, qte)
{
	$.ajax({
		type: "POST",
		url: "pages/boutique/ajouter_article.php",
		data: 'article='+article+'&qte='+qte+'',
		success: function(resultat){
			$("#panier_lite").load('pages/boutique/panier_lite.php');
			$("#zone_panier").show();
			//$("#debug").html(resultat);
		}
	});
}


function supprimer_article(i)
{
	if(confirm('Confirmez-vous la suppression ?')) {
		$.ajax({
			type: "POST",
			url: "pages/boutique/supprimer_article.php",
			data: "i="+i,
			success: function(resultat){
				$("#panier").load('pages/boutique/panier.php');
				$("#panier_lite").load('pages/boutique/panier_lite.php');
				//window.location.href = 'index.php?page=7';
			}
		});
	}
}


function recalculer_panier(i)
{
	var qte = $("#quantite_"+i).val();
	if (!isNaN(qte)) {
		$.ajax({
			type: "POST",
			url: "pages/boutique/recalculer_article.php",
			data: "i="+i+"&qte="+qte,
			success: function(resultat){
				$("#panier").load('pages/boutique/panier.php');
			}

		});
	}
	else {
		alert('Veuillez saisir des chiffres uniquement.');
		$("#panier").load('pages/boutique/panier.php');
	}
}


function terminer_panier()
{
	var input;
	var test;
	input = $("#table_panier :input");
	test = false;
	
	/*
	var err = "";
	err = 0;


	if(f.nom.value.length ==0)
	{
		err = 1;
		$("#label_nom").css('color','red');
	}
	else
	{
		$("#label_nom").css('color','white');
	}
	
	
	if(f.prenom.value.length ==0)
	{
		err = 1;
		$("#label_prenom").css('color','red');
	}
	else
	{
		$("#label_prenom").css('color','white');
	}
	
	if(f.adresse.value.length ==0)
	{
		err = 1;
		$("#label_adresse").css('color','red');
	}
	else
	{
		$("#label_adresse").css('color','white');
	}
	
	if(f.cp.value.length ==0)
	{
		err = 1;
		$("#label_cp").css('color','red');
	}
	else
	{
		$("#label_cp").css('color','white');
	}
	
	if(f.ville.value.length ==0)
	{
		err = 1;
		$("#label_ville").css('color','red');
	}
	else
	{
		$("#label_ville").css('color','white');
	}
	
	if(f.email.value.length ==0)
	{
		err = 1;
		$("#label_email").css('color','red');
	}
	else
	{
		$("#label_email").css('color','white');
	}
	*/


	//if(err == 0) 
	//{

	
		for(i=0;i<input.length;i++) {
			if (input[i].value != '0') {
				test = true;
			}
		}

		
		if (test == true) {
			$("#panier").hide();
			$("#commande").show();
			$("#commande").load('pages/boutique/commande.php');
		}
		else {
			alert('Vous devez saisir au moins une quantite.');
		}
	/*
	}
	else {
		alert('Vous devez saisir au moins une quantites.');
	}
	*/
}

function popup_commande(){
	var opts = 'scrollbars=yes,resizable=no,menubar=no,status=no';
	var w = 700;
	var h = 600;
	var t = (screen.height - h)/2;
	var l = (screen.width - w)/2;
	var pw = window.open('popup_commande.php','','width='+w+',height='+h+',top=50,left='+l+','+opts);
}

function entrer(event) {
	//IE
	if (window.event != undefined) {
		if (event.keyCode == 13) {
			return true;
		}
		else {
			return false;
		}
	}
	//le reste
	else if (event.which != undefined) {
		if (event.which == 13) {
			return true;
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}

function redirect() {
	window.location.href = 'index.php';
}

function refresh() {
	window.location.href = 'popup_commande.php';
}

function affiche_commande(id)
{
	$.ajax({
		type: "POST",
		url: "pages/boutique/affiche_commande.php",
		data: "id="+id,
		success: function(resultat){
			if (resultat != '') {
				$("#commande").html(resultat);
			}
		}
	});
}

function renouveler_commande(id)
{
	$.ajax({
		type: "POST",
		url: "pages/boutique/renouveler_commande.php",
		data: "id="+id,
		success: function(resultat){
			$("#debug").html(resultat);
			setTimeout("refresh()", 4000);
		}
	});
}

function terminer_commande()
{

		if($("input[name=mode]:checked").val()=='cb')
		{
			document.paiement.action = 'paiement/cb.php';
			document.paiement.submit();
		}
		else
		{
			document.paiement.action = 'paiement/ch.php';
			document.paiement.submit();
		}
		
	/*
	$.ajax({
		type: "POST",
		url: "paiement/"+$("input[name=mode]").val()+".php",
		data: 'mode='+$("input[name=mode]").val()+'&message='+$("#message").val()+'',
		success: function(resultat){
			$("#debug").append(resultat);
			//setTimeout("redirect()", 4000);
		}
	});
	*/
}
