function AcceptCVGRequest() {
if ($("cgv").checked == true) var cgv="checked"; else var cgv="";
	var url = "acceptcgv.php";
	var options = {method : "post", data : "cgv="+cgv};
	var myAjax = new Ajax(url, options).request();
}
function DetailExpeRequest(modepaiement) {
//alert ("modepaiement="+modepaiement);
var id = parent.location.hash.substring(5,11);;
var url = "paiementcommande.php";
var options = {method : "post", data : "modepaiement="+modepaiement};
var myAjax = new Ajax(url, options).request();
myAjax.addEvent("onSuccess", function(resultat){
	$('panier').setHTML(resultat);
	});
}
function AfficheTarifExpe() {
var poidscommande = $('poidscommande').getValue();
var choixtarifexpe = $$('input[name=choixtarifexpe]').getValue();

if (choixtarifexpe.indexOf("tarifT1",0)!=-1) {
tarifexpe = "tarifT1";
var coutexpe = $$('input[name=expecompletT1]').getValue();
}
if (choixtarifexpe.indexOf("tarifT2",0)!=-1) {
tarifexpe = "tarifT2";
var coutexpe = $$('input[name=expecompletT2]').getValue();
}

var url = "modetransport.php";
var options = {method : "post", data : "tarifexpe="+tarifexpe+"&coutexpe="+coutexpe+"&poidscommande="+poidscommande }
var myAjax = new Ajax(url,options).request();
myAjax.addEvent("onSuccess", function(resultat){
	$('panier').setHTML(resultat);
	});
}
function AfficheDetailExpe(destination,provenance) {
if (destination == 'cgv') {
	var url = "acceptcgv.php";
	var myAjax = new Ajax(url).request();
	myAjax.addEvent("onSuccess", function(resultat){
		$('panier').setHTML(resultat);
		});
	}
if (destination == 'adresselivraison') {
	var choixcgv = $$('input[name=cgv]').getValue();
	if (choixcgv == "false") alert ("Merci de cocher l'acceptation des conditions générales de vente");
	else {
		var url = "adresselivraison.php";
		var myAjax = new Ajax(url).request();
		myAjax.addEvent("onSuccess", function(resultat){
		$('panier').setHTML(resultat);
		});
		}
	}
if (destination == 'modetransport') {
	if (provenance == 'adresselivraison') {
		var nom = $('livraisonnom').getValue();
		var prenom = $('livraisonprenom').getValue();
		var adresse = $('livraisonadresse').getValue();
		var ville = $('livraisonville').getValue();
		var cp = $('livraisoncp').getValue();
		var pays = $('livraisonpays').getValue();
		var inputsexe = $$('input[name=livraisonsexe]').getValue();
		if ($$('input[name=livraisonsexe]') == 'false,false,false') var sexe = "";
		if (inputsexe.indexOf("Mme",0)!=-1) var sexe = "Mme";
		if (inputsexe.indexOf("Melle",0)!=-1) var sexe = "Melle";
		if (inputsexe.indexOf("M",0)!=-1) var sexe = "M";
		var inputlocalisation = $$('input[name=livraisonlocalisation]').getValue();
		if (inputlocalisation.indexOf("france",0)!=-1) var localisation = "france";
		if (inputlocalisation.indexOf("ue",0)!=-1) var localisation = "ue";
		if (inputlocalisation.indexOf("monde",0)!=-1) var localisation = "monde";
		var url = "modetransport.php";
		var options = {method : "post", data : "sexe="+sexe+"&nom="+nom+"&prenom="+prenom+"&adresse="+adresse+"&ville="+ville+"&cp="+cp+"&pays="+pays+"&localisation="+localisation+"&coordslivraison=oui"};
		var myAjax = new Ajax(url,options).request();
		myAjax.addEvent("onSuccess", function(resultat){
			$('panier').setHTML(resultat);
			});
		} // prov adresselivraison
		if (provenance == 'paiementcommande') {
		var url = "modetransport.php";
		var myAjax = new Ajax(url).request();
		myAjax.addEvent("onSuccess", function(resultat){
			$('panier').setHTML(resultat);
			});
		} // prov paiementcommande
}
if (destination == 'paiementcommande') {
	//retour de recapcommande
	if (provenance == 'modetransport') { //ne prend pas en compte retour modetransport.php
	var choixtarifexpe = $$('input[name=choixtarifexpe]').getValue();
	if ((choixtarifexpe.indexOf("tarifT1",0)==-1) && (choixtarifexpe.indexOf("tarifT2",0)==-1)) alert ("Merci de valider votre mode d'expédition");
		else {
			if (choixtarifexpe.indexOf("tarifT1",0)!=-1) {
			tarifexpe = "tarifT1";
			var coutexpe = $$('input[name=expecompletT1]').getValue();
			}
			if (choixtarifexpe.indexOf("tarifT2",0)!=-1) {
			tarifexpe = "tarifT2";
			var coutexpe = $$('input[name=expecompletT2]').getValue();
			}
			var url = "paiementcommande.php";
			var options = {method : "post", data : "tarifexpe="+tarifexpe+"&coutexpe="+coutexpe }
			var myAjax = new Ajax(url,options).request();
			myAjax.addEvent("onSuccess", function(resultat){
				$('panier').setHTML(resultat);
				});
			} //else
	} //if
	if (provenance == 'recapcommande') { //retour recapcommande.php
			var url = "paiementcommande.php";
			var myAjax = new Ajax(url).request();
			myAjax.addEvent("onSuccess", function(resultat){
				$('panier').setHTML(resultat);
				});
	} //if
}
if (destination == 'recapcommande') {
var choixpaiement = $$('input[name=reglement]').getValue();
if (choixpaiement == 'false,false,false') alert ("Merci de valider votre mode de paiement");
else {
		var url = "recapcommande.php";
		var myAjax = new Ajax(url).request();
		myAjax.addEvent("onSuccess", function(resultat){
			$('panier').setHTML(resultat);
			});
		}
}
}
function AfficheBoutiqueRequest(id) {
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	//if (!window.ie) if (!window.ie) clearInterval(histofirefox);
	var pageactive = 'page'+id;
	var url = "page.php";
	var options = {method : "get", data : "a="+pageactive+"&id="+id};
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat){
		$("mouline").effect("opacity").start(1,0);
		$("page").setHTML(resultat);
		parent.location.hash = pageactive;
		});
}
function AfficheArticleDetail(id,ordre,unic,detaildelarticle) {
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	var pageactive = 'page'+id;
	var url = "page.php";
	var options = {method : "get", data : "a="+pageactive+"&id="+id+"&ordre="+ordre+"&unic="+unic+"&detaildelarticle="+detaildelarticle};
  //alert ("a="+pageactive+"&id="+id+"&ordre="+ordre+"&unic="+unic+"&detaildelarticle="+detaildelarticle);
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat){
		$("mouline").effect("opacity").start(1,0);
		$("page").setHTML(resultat);
		});
}
function IsNumeric(sText) {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
         }
      }
   return IsNumber;
}
function AjoutPanierRequest(idordre,unic,article,prix,reference) {
	var quantite = $("qte"+idordre).getValue();
	if ( ((IsNumeric(quantite))===true) && (quantite!="") )	{
		$("mouline").effect("opacity", {duration:100}).start(0,1);
	}
	var url = "envoipanier.php";
	var options = {method : "post", data : "idordre="+idordre+"&quantite="+quantite+"&unic="+unic+"&article="+article+"&prix="+prix+"&reference="+reference};
  //alert ("idordre="+idordre+"&quantite="+quantite+"&unic="+unic+"&article="+article+"&prix="+prix+"&reference="+reference);
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat) {
			var ObjJson = Json.evaluate(resultat);
			prixtotal = ObjJson.prixtotal;
			etatdupanier = ObjJson.etatdupanier;
			nbarticles = ObjJson.nbarticles;
			leretour = ObjJson.leretour.replace(/--/g, "\n");
			alert (leretour);
			$("mouline").effect("opacity").start(1,0);
			var id = idordre.substring(0,6);
			$("infospanier"+id).setHTML("&nbsp;"+nbarticles+" articles dans votre panier pour un montant de "+prixtotal+" €");
			VoirPanierRequest(id,'non');
			});
			if ( ((IsNumeric(quantite))===true) && (quantite=="") ) alert("merci d'indiquer une quantité");
}
function VoirPanierRequest(id,recalcul) {
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	if (id=="") {
	id = parent.location.hash.substring(5,11);
	if ($("init").getText() == "1" ){
	stop();
	}}
	var url = "panier.php";
	var options = {method : "get", data : "id="+id};
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat){
		$("mouline").effect("opacity").start(1,0);
		$("rubrique").setHTML(resultat);
		parent.location.hash = "artc"+id;
		if (recalcul=="oui") alert ("panier modifié");
		});
}
function RecalculPanierRequest(o,id) {
	var nouvelleqte = $("qte"+o).getValue();
	var url = "envoipanier.php";
	var options = {method : "post", data : "modifligne="+o+"&nouvelleqte="+nouvelleqte };
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat){
		VoirPanierRequest(id,"oui");
		});
}
function SupLigneRequest(o,id) {
	var url = "envoipanier.php";
	var options = {method : "post", data : "supligne="+o };
	var myAjax = new Ajax(url, options).request();
	myAjax.addEvent("onSuccess", function(resultat){
		VoirPanierRequest(id,"oui");
		});
}
function EnvoiCommandeRequest() {
	$("mouline").effect("opacity", {duration:100}).start(0,1);
	var url = "envoicommande.php";
	var myAjax = new Ajax(url).request();
	myAjax.addEvent("onSuccess", function(resultat){
		$("mouline").effect("opacity").start(1,0);
		$('panier').setHTML("<div class='totalcommande'>"+resultat+"</div>");
		});
}
function EnregInfosRequest(){
	var infospart = $("infospart").getValue();
	var url = "infospart.php";
	var options = {method : "post", data : "infospart="+escape(infospart) };
	var myAjax = new Ajax(url, options).request();
}
function montrephotoboutique(idordre) {
	$("affichephoto"+idordre).setStyles("display:block");
}
function cachephotoboutique(idordre) {
	$("affichephoto"+idordre).setStyles("display:none");
}
function ajoutdecimales(nombre) {
nombre += "";
var longueurdunombre = (nombre.length);
var positiondupoint = nombre.indexOf(".",0);
var longueuraprespoint= ((nombre.substr(positiondupoint + 1,longueurdunombre - positiondupoint)).length);
	if ( positiondupoint == "-1") nombre=nombre+'.00';
	else {
	if (longueuraprespoint == 1) nombre = nombre+'0';
	if (longueuraprespoint == 2) nombre = nombre ;
	}
return nombre;
}
