function ajouter_demande(id_produit,id_type_demande){
	window.open("creation_demande.php?id_produit="+id_produit+"&id_type_demande="+id_type_demande, 'commercial', 'fullscreen=no, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=yes, status=no, width=850px,height=500px');
	}
function ajouter_au_panier(nmax,id_utilisateur){
	var chaine = "";
	for (var i=0;i<nmax;i++){
		var qte = document.getElementById('qte_'+i).value;
		var id_composant = document.getElementById('id_composant_hidden_'+i).value;
		var id_produit = document.getElementById('id_produit_hidden_'+i).value;
		if(qte!=0)
			chaine = chaine+"{"+id_produit+"*"+id_composant+"*"+id_utilisateur+"*"+qte+"}";
		}
	var xhr_object = null; 
	if(window.XMLHttpRequest) // Firefox 
		xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) // Internet Explorer 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else
		{ // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		return; 
		} 
	xhr_object.open("POST", "maj_panier.php", true); 
	
		xhr_object.onreadystatechange = function() 
			{ 
			if(xhr_object.readyState == 4) 
			try 
				{
				eval(xhr_object.responseText);
				window.location.replace('panier.php');
				}
			catch(e) 
				{alert(xhr_object.responseText);alert(e);}
			} 
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		var data = "chaine="+chaine+"&action=ajout"; 
	xhr_object.send(data); 
	}
function maj_panier_panier(nmax,id_utilisateur){
	var chaine = "";
	for (var i=0;i<nmax;i++){
		var qte = parseFloat(document.getElementById('qte_'+i).innerHTML);
		var id_composant = document.getElementById('id_composant_hidden_'+i).value;
		var id_produit = document.getElementById('id_produit_hidden_'+i).value;
		if(qte!=0)
			chaine = chaine+"{"+id_produit+"*"+id_composant+"*"+id_utilisateur+"*"+qte+"}";
		}
	var xhr_object = null; 
	if(window.XMLHttpRequest) // Firefox 
		xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) // Internet Explorer 
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else
		{ // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		return; 
		} 
	xhr_object.open("POST", "maj_panier.php", true); 
	
		xhr_object.onreadystatechange = function() 
			{ 
			if(xhr_object.readyState == 4) 
			try 
				{
				eval(xhr_object.responseText);
				}
			catch(e) 
				{alert(xhr_object.responseText);alert(e);}
			} 
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
		var data = "chaine="+chaine+"&action=maj"; 
	xhr_object.send(data); 
	}
function supprimer_element_panier(id_composant){
	if (confirm("Voulez vous supprimer ce produit de votre commande ?"))
		{
		var xhr_object = null; 
		if(window.XMLHttpRequest) // Firefox 
			xhr_object = new XMLHttpRequest(); 
		else if(window.ActiveXObject) // Internet Explorer 
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
		else
			{ // XMLHttpRequest non supporté par le navigateur 
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
			return; 
			} 
		xhr_object.open("POST", "maj_panier.php", true); 
		
			xhr_object.onreadystatechange = function() 
				{ 
				if(xhr_object.readyState == 4) 
				try 
					{
					eval(xhr_object.responseText);
					}
				catch(e) 
					{probleme_XHR('supprimer_element_panier');alert(e);}
				} 
			xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
			var data = "id_composant="+id_composant+"&action=suppression"; 
			xhr_object.send(data); 
		}
	}	
function increment_panier(choix,id_composant,n){
	var ini = parseFloat(document.getElementById('qte_'+n).value);
	var px = parseFloat(document.getElementById('prix_vente_ht_'+n).innerHTML);
	if (choix == '+')
		{
		ini = ini + 1;
		}
	else
		{
		ini = ini - 1;
		}
	if (ini<0)	ini = 0;
	document.getElementById('qte_'+n).value = ini;
	document.getElementById('total_'+n).innerHTML = arrondi(ini*px,2);
	}	
function increment_panier_du_panier(choix,id_composant,n,id_utilisateur,livraison){
	var ini = parseFloat(document.getElementById('qte_'+n).innerHTML);
	var px = parseFloat(document.getElementById('prix_vente_ht_'+n).innerHTML);
	if (choix == '+')
		{
		ini = ini + 1;
		}
	else
		{
		ini = ini - 1;
		}
	if (ini<0)	ini = 0;
	document.getElementById('qte_'+n).innerHTML = ini;
	document.getElementById('total_'+n).innerHTML = ini*px;
	
	var k=0;
	var tva=19.6;
	var total_ht=0;
	var total_ttc=0;
	var total_tva=0;
	while (document.getElementById('qte_'+k)){
		total_ht = total_ht + parseFloat(document.getElementById('total_'+k).innerHTML);
		total_tva = total_tva + parseFloat(document.getElementById('total_'+k).innerHTML)*tva/100;
		total_ttc = total_ttc +parseFloat(document.getElementById('total_'+k).innerHTML)+parseFloat(document.getElementById('total_'+k).innerHTML)*tva/100;
		k++;
		}
	if (total_ttc!=0)	net = total_ttc+livraison;
	else	net = 0;
	document.getElementById('tot_ht').innerHTML = arrondi(total_ht,2);
	document.getElementById('tot_tva').innerHTML = arrondi(total_tva,2);
	document.getElementById('tot_ttc').innerHTML =arrondi(total_ttc,2);
	document.getElementById('net').innerHTML =arrondi(net,2);
	
	
	
	maj_panier_panier(k,id_utilisateur);
	}	
function arrondi(nombre,precision){
	var n = 0;
	var multiplicateur = "1";
	for (var n=0;n<parseInt(precision);n++)
		{multiplicateur = multiplicateur+"0";}
	val_precision = parseInt(multiplicateur);
	var temp = nombre*val_precision;
	temp = Math.round(temp);
	temp = temp/val_precision;
	return temp;
	}
function envoyer_panier(id_utilisateur){	
	window.location.replace("votre_compte.php?id="+id_utilisateur);
	}
function valider_modification_compte_panier(id_utilisateur){	
	var continu = true;
	var societe = document.getElementById('societe').value;
	var tel_societe = document.getElementById('tel_societe').value;
	var adresse = document.getElementById('adresse').value;
	var complement = document.getElementById('complement').value;
	var id_cp = document.getElementById('id_cp').value;
	var cp = document.getElementById('cp').value;
	var pays = document.getElementById('choix_pays').options[document.getElementById('choix_pays').selectedIndex].value;
	var siret = document.getElementById('siret').value;
	var ape = document.getElementById('ape').value;
	var mail = document.getElementById('mail').value;
	var fax = document.getElementById('fax').value;
	var nom = document.getElementById('nom').value;
	var prenom = document.getElementById('prenom').value;
	var titre = document.getElementById('choix_titre').options[document.getElementById('choix_titre').selectedIndex].value;
	if (document.getElementById('choix_ville'))
		{
		if (document.getElementById('choix_ville').tagName == 'SELECT')
			var ville = document.getElementById('choix_ville').options[document.getElementById('choix_ville').selectedIndex].value;
		else
			var ville = document.getElementById('choix_ville').value;
		}
	else
		{var ville = document.getElementById('ville').value;}

	var societe_facturation = "";
	var adresse_facturation = "";
	var complement_facturation = "";
	var id_cp_facturation = "";
	var pays_facturation = "";
	var ville_facturation = "";
	var cp_facturation =  "";
	
	if (document.getElementById('tableau_facturation').style.display == 'block')
		{
		societe_facturation = document.getElementById('societe_facturation').value;
		adresse_facturation = document.getElementById('adresse_facturation').value;
		complement_facturation = document.getElementById('complement_facturation').value;
		id_cp_facturation = document.getElementById('id_cp_facturation').value;
		pays_facturation = document.getElementById('choix_pays_facturation').options[document.getElementById('choix_pays_facturation').selectedIndex].value;
		if (document.getElementById('choix_ville_facturation'))
			{
			if (document.getElementById('choix_ville_facturation').tagName == 'SELECT')
				ville_facturation = document.getElementById('choix_ville_facturation').options[document.getElementById('choix_ville_facturation').selectedIndex].value;
			else
				ville_facturation = document.getElementById('choix_ville_facturation').value;
			}
		else
			{var ville = document.getElementById('ville_facturation').value;}

		cp_facturation =  document.getElementById('cp_facturation').value;
		}
	
	
	var societe_livraison = "";
	var adresse_livraison = "";
	var complement_livraison = "";
	var id_cp_livraison = "";
	var pays_livraison = "";
	var ville_livraison = "";
	var cp_livraison =  "";
	
	if (document.getElementById('tableau_livraison').style.display == 'block')
		{
		societe_livraison = document.getElementById('societe_livraison').value;
		adresse_livraison = document.getElementById('adresse_livraison').value;
		complement_livraison = document.getElementById('complement_livraison').value;
		id_cp_livraison = document.getElementById('id_cp_livraison').value;
		pays_livraison = document.getElementById('choix_pays_livraison').options[document.getElementById('choix_pays_livraison').selectedIndex].value;
		if (document.getElementById('choix_ville_livraison'))
			{
			if (document.getElementById('choix_ville_livraison').tagName == 'SELECT')
				ville_livraison = document.getElementById('choix_ville_livraison').options[document.getElementById('choix_ville_livraison').selectedIndex].value;
			else
				ville_livraison = document.getElementById('choix_ville_livraison').value;
			cp_livraison =  document.getElementById('cp_livraison').value;
			}
		else
			{var ville = document.getElementById('ville_livraison').value;}

		}
	if (trim(societe)=="")			{continu = false;alert("Le nom de la société est vide");}
	if (trim(tel_societe)=="")		{continu = false;alert("Le téléphone de la société est vide");}
	if (trim(adresse)=="")			{continu = false;alert("L'adresse de la société est vide");}
	if (trim(cp)=="")				{continu = false;alert("Le code postal de la société est vide");}
	if (trim(pays)=="")			{continu = false;alert("Le pays de la société est vide");}
	if (trim(mail)=="")				{continu = false;alert("L'adresse mail de la société est vide");}
	if (trim(ville)=="")				{continu = false;alert("La ville de la société est vide");}
	if (trim(titre)=="---")			{continu = false;alert("Votre titre doit être renseigné");}
	if (trim(nom)=="")				{continu = false;alert("Votre nom doit être renseigné");}
	if (trim(prenom)=="")			{continu = false;alert("Votre prénom doit être renseigné");}
	var facturation = 0;
	var livraison = 0;
			
		
	if (document.getElementById('tableau_facturation').style.display == 'block')
		{
		var facturation = 1;
		if (trim(societe_facturation)=="")
			continu = false;
		if (trim(adresse_facturation)=="")
			continu = false;
		if (trim(pays_facturation)=="")
			continu = false;
		if (trim(ville_facturation)=="")
			continu = false;
		if (trim(cp_facturation)=="")
			continu = false;
		}
	
	
	if (document.getElementById('tableau_livraison').style.display == 'block')
		{
		var livraison = 1;
		if (trim(societe_livraison)=="")
			continu = false;
		if (trim(adresse_livraison)=="")
			continu = false;
		if (trim(pays_livraison)=="")
			continu = false;
		if (trim(ville_livraison)=="")
			continu = false;
		if (trim(cp_livraison)=="")
			continu = false;
		}
	
	if (continu == true)
		{
		var xhr_object = null; 
		if(window.XMLHttpRequest) // Firefox 
			xhr_object = new XMLHttpRequest(); 
		else if(window.ActiveXObject) // Internet Explorer 
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
		else
			{ // XMLHttpRequest non supporté par le navigateur 
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
			return; 
			} 
		xhr_object.open("POST", "validation_panier.php", true); 
		
			xhr_object.onreadystatechange = function() 
				{ 
				if(xhr_object.readyState == 4) 
				try 
					{
					eval(xhr_object.responseText);
					}
				catch(e) 
					{alert(e);alert(xhr_object.responseText);}
				} 
			xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
			var data = "societe="+societe+"&tel_societe="+tel_societe+"&adresse="+adresse+"&complement="+complement+"&id_cp="+id_cp+"&pays="+pays+"&siret="+siret+"&ape="+ape+"&mail="+mail+"&fax="+fax+"&nom="+nom+"&prenom="+prenom+"&titre="+titre+"&societe_facturation="+societe_facturation+"&adresse_facturation="+adresse_facturation+"&complement_facturation="+complement_facturation+"&id_cp_facturation="+id_cp_facturation+"&societe_livraison="+societe_livraison+"&adresse_livraison="+adresse_livraison+"&complement_livraison="+complement_livraison+"&id_cp_livraison="+id_cp_livraison+"&pays_livraison="+pays_livraison+"&id_utilisateur="+id_utilisateur+"&facturation="+facturation+"&livraison="+livraison; 
			xhr_object.send(data); 
		
		}
	}	
function trim(string){
return string.replace(/(^\s*)|(\s*$)/g,'');
} 	
	
	
	
	
	
