function showCommander(id)
{
	$("#liste"+id).toggle();
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function updatePort(validate)
{
	var pays = document.cart.pays[document.cart.pays.selectedIndex].value;
	
	$.ajax ({
		type: "GET",
		url: "ajax.php",
		data: "action=changePays&pays="+pays,
		async: false
	});
	
	var url = "panier.php";
	
	if (validate == 1)
	{
		url = url + "?validate=1";
	}
	
	window.location = url;
}

/*
function updatePort()
{
	var pays = document.cart.pays[document.cart.pays.selectedIndex].value;
	var poids_total = parseFloat(document.cart.poidstotal.value);
	var ancien_port = parseFloat(document.getElementById('fraisdeport').innerHTML);
	var ancien_total = parseFloat(document.getElementById('total').innerHTML);
	
	$.ajax ({
		type: "GET",
		url: "ajax.php",
		data: "action=changePays&pays="+pays,
		async: false
	});
	
	var nouveau_port = $.ajax ({
		type: "GET",
		url: "ajax.php",
		data: "action=getFraisPort&poids="+poids_total,
		async: false
	}).responseText;
	
	nouveau_port = parseFloat(nouveau_port);
	
	var nouveau_total = (ancien_total - ancien_port) + nouveau_port;
	
	document.getElementById('fraisdeport').innerHTML = nouveau_port.toFixed(2);
	document.getElementById('total').innerHTML = nouveau_total.toFixed(2);
}
*/

function updatePrice(qte, somme, prix, poids_unitaire, somme_poids, id)
{
	var ancienne_somme = parseFloat(document.getElementById( somme ).innerHTML);
	var ancien_total = parseFloat(document.getElementById('total').innerHTML);
	var ancien_port = parseFloat(document.getElementById('fraisdeport').innerHTML);
	var quantite = eval("document.cart."+qte+".value");
	var prix = parseFloat(eval("document.cart."+prix+".value"));
	var poids_unitaire = parseFloat(eval("document.cart."+poids_unitaire+".value"));
	var ancienne_somme_poids = parseFloat(eval("document.cart."+somme_poids+".value"));
	var poids_total = parseFloat(document.cart.poidstotal.value);

	if (quantite == '')
	{
		quantite = 1;
	}

	quantite = parseInt(quantite);
	var nouvelle_somme = (prix * quantite.toFixed(2));
	var nouveau_poids = (poids_unitaire * quantite.toFixed(2));
	poids_total = (poids_total - ancienne_somme_poids) + nouveau_poids;
	
	if (poids_total > 30)
	{
		alert("Votre commande ne peut pas dépasser 30 kg");
		eval("document.cart."+qte+".value = 1");
		quantite = 1;
		nouvelle_somme = (prix * quantite.toFixed(2));
		poids_total = (poids_total - nouveau_poids);
		nouveau_poids = (poids_unitaire * quantite.toFixed(2));
		poids_total = (poids_total + nouveau_poids);
	}
	
	document.cart.poidstotal.value = poids_total.toFixed(2);
	eval("document.cart."+somme_poids+".value = "+nouveau_poids.toFixed(2));
	
	// GESTION DES FRAIS DE PORTS A FAIRE
	var nouveau_port = $.ajax ({
		type: "GET",
		url: "ajax.php",
		data: "action=getFraisPort&poids="+poids_total,
		async: false
	}).responseText;
	
	nouveau_port = parseFloat(nouveau_port);
	var nouveau_total = (ancien_total - ancienne_somme - ancien_port) + nouvelle_somme + nouveau_port;

	document.getElementById('fraisdeport').innerHTML = nouveau_port.toFixed(2);
	document.getElementById( somme ).innerHTML = nouvelle_somme.toFixed(2);
	document.getElementById('total').innerHTML = nouveau_total.toFixed(2);

	http.open('get', 'ajax.php?action=updateQte&id='+id+'&qte='+quantite);
	http.send(null);
}

function checkForm()
{
	if (document.coord.nom.value.length == 0)
	{
		alert("Précisez votre nom");
		return false;
	} else if (document.coord.prenom.value.length == 0)
	{
		alert("Précisez votre prénom");
		return false;
	} else if (document.coord.adresse.value.length == 0)
	{
		alert("Précisez votre adresse");
		return false;
	} else if (document.coord.cp.value.length == 0)
	{
		alert("Précisez votre code postal");
		return false;
	} else if (document.coord.ville.value.length == 0)
	{
		alert("Précisez votre ville");
		return false;
	} else if (document.coord.tel.value.length == 0)
	{
		alert("Précisez votre téléphone");
		return false;
	} else if (document.coord.mail.value.length == 0)
	{
		alert("Précisez votre eMail");
		return false;
	} else
	{	
		return true;
	}
}
