function AcceptCVGRequest() {
if ($("cgv").checked == true) var cgv="checked"; else var cgv="";
var myRequest = new Request({method: 'post', url: 'acceptcgv.php'});
myRequest.send("cgv="+cgv);
}
function DetailExpeRequest(modepaiement) {
//alert ("modepaiement="+modepaiement);
var id = parent.location.hash.substring(5,11);;
var myRequest = new Request({method: 'post', url: 'paiementcommande.php'});
myRequest.send("modepaiement="+modepaiement);
myRequest.addEvent("onSuccess", function(resultat){
	$('panier').set('html',resultat);
	});
}
function AfficheTarifExpe(modexpe) {
var poidscommande = $('poidscommande').get('value');

if (modexpe == "T1") {
tarifexpe = "tarifT1";
var coutexpe = $('expecompletT1').get('value');
}
if (modexpe == "T2") {
tarifexpe = "tarifT2";
var coutexpe = $('expecompletT2').get('value');
}

var myRequest = new Request({method: 'post', url: 'modetransport.php'});
myRequest.send("tarifexpe="+tarifexpe+"&coutexpe="+coutexpe+"&poidscommande="+poidscommande);
myRequest.addEvent("onSuccess", function(resultat){
	$('panier').set('html',resultat);
	});
}
function AfficheDetailExpe(destination,provenance) {
if (destination == 'cgv') {
  var myRequest = new Request({url: 'acceptcgv.php'}).send();
  myRequest.addEvent("onSuccess", function(resultat){
    $('panier').set('html',resultat);
		});
	}
if (destination == 'adresselivraison') {
  if (provenance == 'acceptcgv') {
    if ($('cgv').checked == false) alert ("Merci de cocher l'acceptation des conditions générales de vente");
    else {
      var url = "";
      var myRequest = new Request({url: 'adresselivraison.php'}).send();
      myRequest.addEvent("onSuccess", function(resultat){
      $('panier').set('html',resultat);
      });
      }
    }
  if (provenance == 'modetransport') {
      var url = "";
      var myRequest = new Request({url: 'adresselivraison.php'}).send();
      myRequest.addEvent("onSuccess", function(resultat){
      $('panier').set('html',resultat);
      });
    }
  }
if (destination == 'modetransport') {
	if (provenance == 'adresselivraison') {
		var nom = $('livraisonnom').get('value');
		var prenom = $('livraisonprenom').get('value');
		var adresse = $('livraisonadresse').get('value');
    var adresse2 = $('adresse2').get('value');
    var societe = $('societe').get('value');
		var ville = $('livraisonville').get('value');
		var cp = $('livraisoncp').get('value');
		var pays = $('livraisonpays').get('value');
    var sexe ="";
		if ($('mmecheck').checked == true) var sexe = "Mme";
    if ($('mellecheck').checked == true) var sexe = "Melle";
    if ($('mcheck').checked == true) var sexe = "M";
		var inputlocalisation = "";
		if ($('francecheck').checked == true)  var localisation = "france";
		if ($('uecheck').checked == true)  var localisation = "ue";
		if ($('mondecheck').checked == true) var localisation = "monde";
    //alert ("sexe = "+sexe+" localisation = "+localisation);
    if ( (nom == "") || (prenom == "") || (adresse == "") || (ville == "") || (cp == "") || (pays == "") || (localisation == "") )
    alert( "Attention, les champs obligatoires(*) ne sont pas tous remplis");
    else {
      var myRequest = new Request({method: 'post', url: 'modetransport.php'});
      myRequest.send("sexe="+sexe+"&nom="+nom+"&prenom="+prenom+"&adresse="+adresse+"&adresse2="+adresse2+"&societe="+societe+"&ville="+ville+"&cp="+cp+"&pays="+pays+"&localisation="+localisation+"&coordslivraison=oui");
      myRequest.addEvent("onSuccess", function(resultat){
        $('panier').set('html',resultat);
        });
      }
		} // prov adresselivraison
		if (provenance == 'paiementcommande') {
		var myRequest = new Request({url: 'modetransport.php'}).send();
		myRequest.addEvent("onSuccess", function(resultat){
			$('panier').set('html',resultat);
			});
		} // prov paiementcommande
}
if (destination == 'paiementcommande') {
	//retour de recapcommande
	if (provenance == 'modetransport') { //ne prend pas en compte retour modetransport.php
	var tarifexpe = "";
  if ($('T1check').checked == true) var tarifexpe = "tarifT1";
  if ($('T2check').checked == true) var tarifexpe = "tarifT2";
	if (tarifexpe == "") alert ("Merci de valider votre mode d'expédition");
		else {
			if (tarifexpe == "tarifT1") var coutexpe = $('expecompletT1').get('value');
      if (tarifexpe == "tarifT2") var coutexpe = $('expecompletT2').get('value');
			var myRequest = new Request({method: 'post', url: 'paiementcommande.php'});
      myRequest.send("tarifexpe="+tarifexpe+"&coutexpe="+coutexpe);
			myRequest.addEvent("onSuccess", function(resultat){
				$('panier').set('html',resultat);
				});
     } //else
	} //if
	if (provenance == 'recapcommande') { //retour recapcommande.php
			var myRequest = new Request({url: 'paiementcommande.php'}).send();
			myRequest.addEvent("onSuccess", function(resultat){
				$('panier').set('html',resultat);
				});
	} //if
}
if (destination == 'recapcommande') {
var choixpaiement = "";
if ($('CBcheck').checked == true) var choixpaiement = "CP";
if ($('chequecheck').checked == true) var choixpaiement = "cheque";
if ($('virementcheck').checked == true) var choixpaiement = "virement";
if (choixpaiement == "") alert ("Merci de valider votre mode de paiement");
else {
		var myRequest = new Request({url: 'recapcommande.php'}).send();
		myRequest.addEvent("onSuccess", function(resultat){
			$('panier').set('html',resultat);
			});
		}
}
}
function AfficheBoutiqueRequest(id) {
	var Mouline1Effects = new Fx.Morph('mouline');
  Mouline1Effects.start({'opacity':1});
	//if (!window.ie) if (!window.ie) clearInterval(histofirefox);
	var pageactive = 'page'+id;
	var myRequest = new Request({method: 'get', url: 'page.php'});
  myRequest.send("a="+pageactive+"&id="+id);
	myRequest.addEvent("onSuccess", function(resultat){
		var Mouline0Effects = new Fx.Morph('mouline');
    Mouline0Effects.start({'opacity':0});
		$("page").set('html',resultat);
		parent.location.hash = pageactive;
		});
}
function AfficheArticleDetail(id,ordre,unic,detaildelarticle) {
	var Mouline1Effects = new Fx.Morph('mouline');
  Mouline1Effects.start({'opacity':1});
	var pageactive = 'page'+id;
  //alert ("a="+pageactive+"&id="+id+"&ordre="+ordre+"&unic="+unic+"&detaildelarticle="+detaildelarticle);
	var myRequest = new Request({method: 'get', url: 'page.php'});
  myRequest.send("a="+pageactive+"&id="+id+"&ordre="+ordre+"&unic="+unic+"&detaildelarticle="+detaildelarticle);
	myRequest.addEvent("onSuccess", function(resultat){
		var Mouline0Effects = new Fx.Morph('mouline');
    Mouline0Effects.start({'opacity':0});
		$("page").set('html',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).get('value');
	if ( ((IsNumeric(quantite))===true) && (quantite!="") )	{
	var Mouline1Effects = new Fx.Morph('mouline');
  Mouline1Effects.start({'opacity':1});
	}
  //alert ("idordre="+idordre+"&quantite="+quantite+"&unic="+unic+"&article="+article+"&prix="+prix+"&reference="+reference);
	var myRequest = new Request({method: 'post', url: 'envoipanier.php'});
  myRequest.send("idordre="+idordre+"&quantite="+quantite+"&unic="+unic+"&article="+article+"&prix="+prix+"&reference="+reference);
	myRequest.addEvent("onSuccess", function(resultat) {
			var ObjJson = JSON.decode(resultat);
			prixtotal = ObjJson.prixtotal;
			etatdupanier = ObjJson.etatdupanier;
			nbarticles = ObjJson.nbarticles;
			leretour = ObjJson.leretour.replace(/--/g, "\n");
			alert (leretour);
			var Mouline0Effects = new Fx.Morph('mouline');
      Mouline0Effects.start({'opacity':0});
			var id = idordre.substring(0,6);
			$("infospanier"+id).set('html',"&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) {
	var Mouline1Effects = new Fx.Morph('mouline');
  Mouline1Effects.start({'opacity':1});
	if (id=="") {
	id = parent.location.hash.substring(5,11);
	if ($("init").get('text') == "1" ){
	stop();
	}}
	var myRequest = new Request({method: 'get', url: 'panier.php'});
  myRequest.send("id="+id);
	myRequest.addEvent("onSuccess", function(resultat){
		var Mouline0Effects = new Fx.Morph('mouline');
    Mouline0Effects.start({'opacity':0});
		$("rubrique").set('html',resultat);
		parent.location.hash = "artc"+id;
		if (recalcul=="oui") alert ("panier modifié");
		});
}
function RecalculPanierRequest(o,id) {
	var nouvelleqte = $("qte"+o).get('value');
	var myRequest = new Request({method: 'post', url: 'envoipanier.php'});
  myRequest.send("modifligne="+o+"&nouvelleqte="+nouvelleqte);
	myRequest.addEvent("onSuccess", function(resultat){
		VoirPanierRequest(id,"oui");
		});
}
function SupLigneRequest(o,id) {
	var myRequest = new Request({method: 'post', url: 'envoipanier.php'});
  myRequest.send("supligne="+o);
	myRequest.addEvent("onSuccess", function(resultat){
		VoirPanierRequest(id,"oui");
		});
}
function EnvoiCommandeRequest() {
	var Mouline1Effects = new Fx.Morph('mouline');
  Mouline1Effects.start({'opacity':1});
	var myRequest = new Request({url: 'envoicommande.php'}).send();
  myRequest.addEvent("onSuccess", function(resultat){
		var Mouline0Effects = new Fx.Morph('mouline');
    Mouline0Effects.start({'opacity':0});
		$('panier').set('html',"<div class='totalcommande'>"+resultat+"</div>");
		});
}
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;
}