// CADDIE - Tous droits réservés
// Copyright : EA-Airsoft  webmaster@EA-Airsoft.com  
// http://www.ea-airsoft.com
// Version d'exploitation - Reproduction Interdite

// Constante Global
var C_Lien_cde = "commander-3.php"; 
var C_Lien_adresse = "commander-2.php"; 

var C_myDomain = myDomain ();
var C_dateOld = new Date();  C_dateOld.setTime(C_dateOld.getTime()-( 1 *24*3600*1000));	// Anti-daté à hier (donc cookies "périmé" )
var C_dateExp = new Date();  C_dateExp.setTime(C_dateExp.getTime()+(90 *24*3600*1000)); // Validité 90 Jours
var C_Caddie_Pro = Caddie_Pro() ;
var C_Caddie_Export = Caddie_Export() ;
var C_Caddie_Partenaire = Caddie_Partenaire() ;

// Variable Global
var G_cdePays=""; 
var G_cdePaiement = ""; 
var G_Frais_Port = 0;
var G_Frais_AssPort = 0 ;
var G_Info_Port = "";
var G_Frais_Paiement = 0 ;
var G_Info_Paiement = "" ;
var G_RefEchantillon = "KY-025";

reInitCookies () ;

function reInitCookies () {
	var lastVersion="0805001" ;
	var version=GetCookie("version"); 
	if ( (version =="") || (version == null) || (version != lastVersion) ){
		ViderItem () ;
		ViderCookies () ;
		SetCookie("version", lastVersion, C_dateExp, C_myDomain) ;
	}
}

function myDomain () {
	var pathname=location.pathname;
	return pathname.substring(0,pathname.lastIndexOf('/'))+'/';

}

function Caddie_Pro() {	
// Determine si les conditions à appliquer pour l'expedition sont pour les pro ou non
	var pathname = location.pathname;
	
	if (pathname.indexOf ("/pro/") >= 0 ) {
		return true ;
	} else {
		return false ;
	}
}
	
function Caddie_Export() {	
// Determine si les conditions à appliquer pour l'expedition sont pour les pro ou non
	var pathname = location.pathname;
	
	if (pathname.indexOf ("/export/") >= 0 ) {
		return true ;
	} else {
		return false ;
	}
}
	
function Caddie_Partenaire() {	
// Determine si les conditions à appliquer pour l'expedition sont pour les pro ou non
	var pathname = location.pathname;
	
	if (pathname.indexOf ("/partenaire/") >= 0 ) {
		return true ;
	} else {
		return false ;
	}
}
	

function getCookieVal(offset) {	
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name) {
	var arg = name + "=";
	var alen=arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {return getCookieVal (j);}
		i = document.cookie.indexOf(" ",i)+1;
		if (i==0) { break; }
	}
	return null;
}

function SetCookie(name,value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = ((argc > 2) ? argv[2] : null);
	var path = ((argc > 3) ? argv[3] : null);
	var domain = ((argc > 4) ? argv[4] : null);
	var secure = ((argc > 5) ? argv[5] : false);
	document.cookie = name + "=" + escape(value) +
								((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
								((path==null) ? "" : ("; path="+path))+
								((domain==null) ? "" : ("; domain="+domain))+
								((secure==true) ? "; secure" : "");
}

function format(valeur) {
	var decimal=2;

	val =  arrondi_2(valeur) ;
	
	var deci=Math.round(parseFloat(val)*Math.pow(10,decimal)) - Math.pow(10,decimal)*Math.floor(parseFloat(val)) ;
	var val_entier = Math.floor(parseFloat(val)) ;
	var val_format = val_entier + "";
	var nb=val_format.length;
	for (var i=1;i<3;i++) {
		if (val_entier >= Math.pow(10,(3*i))) {
			val_format = val_format.substring(0,nb-(3*i))+" "+val_format.substring(nb-(3*i));
		}
	}
	if (deci>=0) {
		if (deci<10){
			deci="0"+deci ;
		} 
		val_format = val_format+"."+deci;
	}
	return val_format;
}

function arrondi_2(valeur) {
	var decimal=2;
	val_arr = (Math.round	(valeur *Math.pow(10,2))) / Math.pow(10,2) ;
	return val_arr;
}

function GetNbItem() {
	var NbS=GetCookie("nbitem");
	var Nb=0
	if (NbS != null) {
		Nb=parseInt(NbS);
	}
	return Nb;
 }

function SetNbItem(nb) {
	SetCookie("nbitem",nb,C_dateExp,C_myDomain) ;
}

function AddItem(form) {
	var typMaj  = "NONE";
	if ((form.qte.value=="0")||(form.qte.value==""))	{
		alert("La Quantité est vide, l'article n'a pas pu être ajouté à votre caddie");
		typMaj = "NONE" ;
	} else {
		var ref = form.ref.value;
		var des = form.des.value;
		var masse = form.masse.value;
		var qte = form.qte.value;
		var prixU = form.prixU.value;

		if ( isEchantillon(ref) ) {
			if ( IndiceItemRef(ref) > 0 ) {
				alert("Produit déja présent dans votre caddie");
				typMaj = "NONE" ;
			} else {
				var qte = 1;
				var prixU = 0;
				typMaj = "ADD" ;
			}

		} else {
			var ind = IndiceItemRef(ref);
			if (ind >0 ) {
				var oldItem = new GetItem(ind) ;
				var newQte = parseInt(qte) + parseInt(oldItem.qte) ;
				typMaj = "UPD" ;
			} else {
				typMaj = "ADD" ;
			}
		}

		if (typMaj == "ADD") {
			var ligne = ref+"¤"+des+"¤"+prixU+"¤"+qte+"¤"+masse+"¤";
			var NoItem = parseInt(GetNbItem())+1;
			SetCookie("itemno"+NoItem,ligne,C_dateExp,C_myDomain);
			SetNbItem(NoItem);
			alert(" "+qte+" "+des+" a été ajouté à votre caddie / was added to your caddie ");

		} else if (typMaj == "UPD") {
			var ligne = ref+"¤"+des+"¤"+prixU+"¤"+newQte+"¤"+masse+"¤";
			SetCookie("itemno"+ind,ligne,C_dateExp,C_myDomain);
			alert(" "+qte+" "+des+" a été rajouté à votre caddie / was added to your caddie ");
		}
		
	}
}

function isEchantillon (ref) {
	if (G_RefEchantillon == null || G_RefEchantillon == "" || ref == null || ref == ""  ) {
		return false;
	}
	
	return (G_RefEchantillon == ref );
}

function IndiceItemRef(ref) {
	var nb = GetNbItem();
	var trouve=0;
	var item  ;
	if (ref == null || ref == "" ) {
		return 0;
	}

	for(var i = 1 ; i<=nb && ! trouve ; i++) {
		item = new GetItem(i);
		if (item !=null && item.ref == ref) {
			trouve = i;
		}
	}
	return trouve;
}

function SupItem(no) {
	var ligne = GetCookie("itemno" + no);
	var nb = GetNbItem();
	if (ligne!=null) {
		if (confirm("Cet article va être enlevé de votre caddie\nEtes-vous d'accord ?")){
			for(var i = no+1 ; i<=nb ; i++) {
				ligne=GetCookie("itemno"+i);
				SetCookie("itemno"+(i-1),ligne,C_dateExp,C_myDomain);
			}
 			SetCookie("itemno"+nb,"", C_dateOld, C_myDomain) ;
			SetNbItem(nb-1);
		}
	}
}

function ChangeQte(no) {
	var item = new GetItem(no);

	if (!C_Caddie_Pro && !C_Caddie_Export && !C_Caddie_Partenaire  && isEchantillon(item.ref) ) {
		alert("Il n'est pas possible de modifier la quantité de ce produit");
		return false;
	} else {

		var new_qte = prompt("Nouvelle quantité pour "+item.des+" ?",item.qte);
	
		new_qte = Math.round(parseInt(new_qte));
		if (new_qte>0){
			var ligne = item.ref+"¤"+item.des+"¤"+item.pxU+"¤"+new_qte+"¤"+item.masse+"¤";
			SetCookie("itemno"+no,ligne,C_dateExp,C_myDomain);
			window.location.reload();
			return false;
		} else {
//			SupItem(no); 
//			return true;
		}
	}
}

function SauveAdresse(form) {
	var nom=form.f_nom.value; 
	var prenom=form.f_prenom.value; 
	var mail="";
	var ad1=form.f_ad1.value; 
	var ad2=form.f_ad2.value; 
	var ad3=form.f_ad3.value; 
	var cp=form.f_cp.value; 
	var ville=form.f_ville.value; 
	var pays=form.f_pays.options[form.f_pays.selectedIndex].value;
	var payment=form.f_payment.options[form.f_payment.selectedIndex].value;
	var tel=form.f_tel.value;
	var msg=""; 
	var c="";

	if (nom==""){	msg="Saisissez votre nom"; c="f_nom";	}
	if (prenom==""){	msg="Saisissez votre prénom"; c="f_prenom";	}

	mail=form.f_mail.value;
	if ((mail.indexOf("@")>=0)&&(mail.indexOf(".")>=0)){
		a=5 ;
	} else {
		msg="L'adresse mail tapée ne semble pas valide"; 
		c="f_mail" ;
	}

	if (ad1==""){msg="Merci de saisir votre adresse"; c="f_ad1"}
	if (tel==""){msg="Merci de saisir votre numero de telephone"; c="f_tel"}
	if (cp==""){msg="Vous avez oublié le code postal"; c="f_cp"}
	if (ville==""){msg="Merci de saisir votre ville"; c="f_ville"}
	if (pays==""){msg="Sélectionnez un pays"; c="f_pays"}
	if (payment==""){msg="Sélectionnez le mode de Paiement"; c="f_payment"}
	
	if ( ( payment != "TransfertWord"  ) &&  (  (pays!="France") && (pays!="Dom_Tom") )  ) 	{
		msg="Paiement uniquement par virement bancaire international"; 
		c="f_payment" ;
	}

	if ((payment == "LCR08" || payment == "LCR30"  ) && (! C_Caddie_Pro && ! C_Caddie_Partenaire ) ) {
		msg="Les LCR sont réservées aux clients professionnels"; 
		c="f_payment" ;
	}


	if (msg==""){
		var adresse = nom+"¤"+prenom+"¤"+mail+"¤"+ad1+"¤"+ad2+"¤"+ad3+"¤"+cp+"¤"+ville+"¤"+pays+"¤"+payment+"¤"+tel+"¤"+"¤" ;
		SetCookie("leclient", adresse, C_dateExp, C_myDomain)
		SetCookie("kd","OK",C_dateExp,C_myDomain);

		window.location = C_Lien_cde;
		return true;
	} else {
		alert(msg); 
		form.elements[c].focus();
		SetCookie("kd","KO",C_dateExp,C_myDomain);
		return false;
	}
}

function GetAdresse() {
	var ad=GetCookie("leclient"); 
	var i=0; 
	var j=0;
	if ( (ad!="") && (ad!=null) ){
		j=ad.indexOf("¤",i);this.nom=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.prenom=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.mail=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.ad1=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.ad2=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.ad3=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.cp=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.ville=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.pays=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.payment=ad.substring(i,j); i=j+1;
		j=ad.indexOf("¤",i);this.tel=ad.substring(i,j); i=j+1;
		this.exist="YES"
	} else {
		this.exist="NO"
	}
}


function InitAdresse(form) {
	var ad=new GetAdresse()
	if (ad.exist != "NO") {	
		with (form) {
			elements["f_nom"].value=ad.nom;
			elements["f_prenom"].value=ad.prenom;
			elements["f_mail"].value=ad.mail
			elements["f_ad1"].value=ad.ad1;
			elements["f_ad2"].value=ad.ad2;
			elements["f_ad3"].value=ad.ad3;
			elements["f_ville"].value=ad.ville;
			elements["f_cp"].value=ad.cp;
	
			elements["f_pays"].value=ad.pays;
			if (elements["f_pays"].selectedIndex == -1 ) {
				elements["f_pays"].value = "France";
			}
	
			elements["f_payment"].value=ad.payment;
			if (elements["f_payment"].selectedIndex == -1 )  {
				elements["f_payment"].value = "Cheque";
			}
	
			elements["f_tel"].value=ad.tel ;
		}
	} else {
		with (form) {
			elements["f_pays"].value = "France";
			elements["f_payment"].value = "Cheque";
		}
	}
}

function DispAdresse() {
	var suf="" ;
	var ad = new GetAdresse();
	var aff="<p><a href=" + C_Lien_adresse + "><img border=0 src=../image/anime/fleche.gif width=32 height=32><font size=2>Modifier ici / Modify here </font><img border=0 src=../image/diver/adresse.gif width=51 height=36></a></p>";

	var i1=0; 
	var i2=0;

	if (ad.exist != "NO"){
		aff += "<TABLE><TR><TD width=1></TD><TD style='font-size: 14px'>";
		var adr=ad.ad1;
		if (ad.ad2!=""){
			adr=adr+"<BR>"+ad.ad2;
		}
		if (ad.ad3!=""){
			adr=adr+"<BR>"+ad.ad3;
		}
		aff += ad.prenom+" "+ad.nom ;
		aff += "<BR>"+adr+"<BR>"+ad.cp+" "+ad.ville+"<BR><b><font color='#0066FF'>"+ad.pays+"</font></b><BR>" ;
		aff+="(Mail : "+ad.mail+")<BR>" ;
		aff += "Tel : "+ad.tel+"<BR>" ;
		aff+="</TD></TR></TABLE>";
		
		G_cdePays = ad.pays; 
		G_cdePaiement = ad.payment;
		aff+='<INPUT type="hidden" name="nom'+suf+'" value="'+ad.nom+'">' ;
		aff+='<INPUT type="hidden" name="prenom'+suf+'" value="'+ad.prenom+'">' ;
		aff+='<INPUT type="hidden" name="adresse1'+suf+'" value="'+ad.ad1+'">' ;
		aff+='<INPUT type="hidden" name="adresse2'+suf+'" value="'+ad.ad2+'">' ;
		aff+='<INPUT type="hidden" name="adresse3'+suf+'" value="'+ad.ad3+'">' ;
		aff+='<INPUT type="hidden" name="cp'+suf+'" value="'+ad.cp+'">' ;
		aff+='<INPUT type="hidden" name="ville'+suf+'" value="'+ad.ville+'">' ;
		aff+='<INPUT type="hidden" name="pays'+suf+'" value="'+ad.pays+'">' ;
		aff+='<INPUT type="hidden" name="mail'+suf+'" value="'+ad.mail+'">' ;
		aff+='<INPUT type="hidden" name="tel'+suf+'" value="'+ad.tel+'">' ;
	} else {
		aff+="<font color='#FF0000'><font size='3'><B> - Entrer votre adresse de livraison afin de permettre le calcul des frais d'envoi.<BR><BR> - Enter your address of delivery in order to allow the calculation of the expenses of shipping.<BR>" ;
	}
	document.write(aff);
}

function GetItem(no) {
	var l=GetCookie("itemno"+no); 
	if (l != null) {
		var i=0; 
		var j=0;
		j=l.indexOf("¤",i); 
		this.ref=l.substring(i,j);i=j+1;
		j=l.indexOf("¤",i); this.des=l.substring(i,j);i=j+1;
		j=l.indexOf("¤",i); this.pxU=l.substring(i,j);i=j+1;
		j=l.indexOf("¤",i); this.qte=l.substring(i,j);i=j+1;
		j=l.indexOf("¤",i); this.masse=l.substring(i,j);	
	}
}

function CalcPort(Masse, Mnt_Cde) {
	var pays = G_cdePays ;
	var m = Masse  ;
	var p="?"; 
	var assurance=0;

	p=0;
	G_Info_Port="The participation in the shipment will be send back to you<BR>by mail when you'd have confirm your command.";

	if (pays == "France") {
		if (C_Caddie_Pro || C_Caddie_Export || C_Caddie_Partenaire ) {
			assurance = Math.ceil(Mnt_Cde/150)*0.95 ; 
			
			// Cas si > 28 Kg
			pm=18.60*(parseInt(m/28000)) ;
			m=m % 28000;
			
			if (m<28000){p=18.60} 
			if (m<15000){p=13.80} 
			if (m<10000){p=12.00} 
			if (m<7000){p=10.95} 
			if (m<6000){p=10.55} 
			if (m<5000){p=9.95} 
			if (m<4000){p=9.25} 
			if (m<3000){p=8.60} 
			if (m<2000){p=8.05} 
			if (m<1500){p=7.65} 
			if (m<1000){p=7.20} 
			if (m<750){p=6.80} 
			if (m<500){p=6.20} 
			if (m<250){p=5.30}
			p=pm+p;
			G_Info_Port="La participation au transport";
		} else {
			if (Mnt_Cde==0 && m==0 && IndiceItemRef(G_RefEchantillon) >0){
				p=0 ;
				G_Info_Port="La participation au port vous est offerte par <b>Europe Accessoires</b>";

			} else {
				if ( Mnt_Cde<170 ) {
	
					assurance = Math.ceil(Mnt_Cde/150)*.95 ; 
	
					pm=18.60 *(parseInt(m/28000)) ;
					m=m % 28000;
					if (m<28000){p=18.60} 
					if (m<15000){p=13.80} 
					if (m<10000){p=12.00} 
					if (m<7000){p=10.95} 
					if (m<6000){p=10.55} 
					if (m<5000){p=9.95} 
					if (m<4000){p=9.25} 
					if (m<3000){p=8.60} 
					if (m<2000){p=8.05} 
					if (m<1500){p=7.65} 
					if (m<1000){p=7.20} 
					if (m<750){p=6.80} 
					if (m<500){p=6.20} 
					if (m<250){p=5.30}
					if (m<250){p=5.30}
					p=pm+p;
					G_Info_Port="Participation au transport avec assurance Valorem";
	
				} else {
					G_Info_Port="La participation au port ainsi que l'assurance Valorem vous est offerte par <b>Europe Accessoires</b>";
				}
			}
		}
	}


	if ( pays =="Dom_Tom") {
		if (C_Caddie_Pro || C_Caddie_Partenaire ) {
			G_Info_Port="La participation au transport vous sera retournée<BR> par mail avec la confirmation de votre commande" ;
		} else if (C_Caddie_Export ) {
			G_Info_Port="The participation in the shipment will be send back to you<BR>by mail when you'd have confirm your command.";
		} else {
			assurance = Math.ceil(Mnt_Cde/150)*.95 ; 

			pm=151.00 *(parseInt(m/28000)) ;
			m=m % 28000;

			if (m<28000){p=151.00} 
			if (m<25000){p=126.00} 
			if (m<20000){p=101.00} 
			if (m<15000){p=76.00} 
			if (m<10000){p=58.50} 
			if (m<9000){p=53.50} 
			if (m<8000){p=48.50} 
			if (m<7000){p=43.50} 
			if (m<6000){p=38.50} 
			if (m<5000){p=33.50} 
			if (m<4000){p=28.50} 
			if (m<3000){p=23.50} 
			if (m<2000){p=18.50} 
			if (m<1000){p=14.00} 
			if (m<500){p=11.50}
			p=pm+p;
			G_Info_Port="Participation au transport avec assurance Valorem";
		}
	}

	if ((pays=="Allemagne")||(pays=="Belgique")||(pays=="Espagne")||(pays=="Italie")||(pays=="Luxembourg")||(pays=="Andorre")||(pays=="Pays-bas")) {
		if (C_Caddie_Pro || C_Caddie_Partenaire ) {
			G_Info_Port="La participation au transport vous sera retournée<BR> par mail avec la confirmation de votre commande" ;
		} else if (C_Caddie_Export ) {
			G_Info_Port="The participation in the shipment will be send back to you<BR>by mail when you'd have confirm your command.";
		} else {
			assurance = Math.ceil(Mnt_Cde/150)*.95 ; 

			pm=25.50 *(parseInt(m/28000)) ;
			m=m % 28000;

			if (m<28000){p=25.50} 
			if (m<25000){p=23.00} 
			if (m<20000){p=20.50} 
			if (m<15000){p=18.00} 
			if (m<10000){p=15.50} 
			if (m<9000){p=15.00} 
			if (m<8000){p=14.50} 
			if (m<7000){p=14.00} 
			if (m<6000){p=13.50} 
			if (m<5000){p=13.00} 
			if (m<4000){p=12.50} 
			if (m<3000){p=12.00} 
			if (m<2000){p=11.50} 
			if (m<1000){p=11.00}
			p=pm+p;
			G_Info_Port="Participation au transport avec assurance Valorem";
		}
	}

	if ((pays=="Acores")||(pays=="Autriche")||(pays=="Baleares")||(pays=="Canaries")||(pays=="Danemark")||(pays=="Grande-Bretagne")||(pays=="Irlande")||(pays=="Madere")||(pays=="Portugal")||(pays=="Sardaigne")||(pays=="Sicile")) {
		if (C_Caddie_Pro || C_Caddie_Partenaire ) {
			G_Info_Port="La participation au transport vous sera retournée<BR> par mail avec la confirmation de votre commande" ;
		} else if (C_Caddie_Export ) {
			G_Info_Port="The participation in the shipment will be send back to you<BR>by mail when you'd have confirm your command.";
		} else {
			assurance = Math.ceil(Mnt_Cde/150)*.95 ; 

			pm=30.70 *(parseInt(m/28000)) ;
			m=m % 28000;
			if (m<28000){p=30.70} 
			if (m<25000){p=27.70} 
			if (m<20000){p=24.70} 
			if (m<15000){p=21.70} 
			if (m<10000){p=18.70} 
			if (m<9000){p=18.10} 
			if (m<8000){p=17.50} 
			if (m<7000){p=16.90} 
			if (m<6000){p=16.30} 
			if (m<5000){p=15.70} 
			if (m<4000){p=15.10} 
			if (m<3000){p=14.50} 
			if (m<2000){p=13.90} 
			if (m<1000){p=13.30}
			p=pm+p;
			G_Info_Port="Participation au transport avec assurance Valorem";
		}
	}

	if ((pays=="Finlande")||(pays=="Norvege")||(pays=="Suede")||(pays=="Suisse")) {
		if (C_Caddie_Pro || C_Caddie_Partenaire ) {
			G_Info_Port="La participation au transport vous sera retournée<BR> par mail avec la confirmation de votre commande" ;
		} else if (C_Caddie_Export ) {
			G_Info_Port="The participation in the shipment will be send back to you<BR>by mail when you'd have confirm your command.";
		} else {
			assurance = Math.ceil(Mnt_Cde/150)*.95 ; 

			pm=45.60 *(parseInt(m/28000)) ;
			m=m % 28000;
			if (m<28000){p=45.60} 
			if (m<25000){p=40.10} 
			if (m<20000){p=34.60} 
			if (m<15000){p=29.10} 
			if (m<10000){p=23.60} 
			if (m<9000){p=22.50} 
			if (m<8000){p=21.40} 
			if (m<7000){p=20.30} 
			if (m<6000){p=19.20} 
			if (m<5000){p=18.10} 
			if (m<4000){p=17.00} 
			if (m<3000){p=15.90} 
			if (m<2000){p=14.80} 
			if (m<1000){p=13.70}
			p=pm+p;
			G_Info_Port="Participation au transport avec assurance Valorem";
		}
	}

	if ((pays=="Lituanie")) {
		if (C_Caddie_Pro || C_Caddie_Partenaire ) {
			G_Info_Port="La participation au transport vous sera retournée<BR> par mail avec la confirmation de votre commande" ;
		} else if (C_Caddie_Export ) {
			G_Info_Port="The participation in the shipment will be send back to you<BR>by mail when you'd have confirm your command.";
		} else {
			assurance = Math.ceil(Mnt_Cde/150)*.95 ; 

			pm=37 *(parseInt(m/28000)) ;
			m=m % 28000;
			if (m<28000){p=37} 
			p=pm+p;
			G_Info_Port="Participation au transport avec assurance Valorem";
		}
	}

	if ((pays=="Autre")) {
		if (C_Caddie_Pro || C_Caddie_Partenaire ) {
			G_Info_Port="La participation au transport vous sera retournée<BR> par mail avec la confirmation de votre commande" ;
		} else if (C_Caddie_Export ) {
			G_Info_Port="The participation in the shipment will be send back to you<BR>by mail when you'd have confirm your command.";
		} else {
			G_Info_Port="La participation au transport vous sera retournée<BR> par mail avec la confirmation de votre commande" ;
		}
	}

	if (pays=="") {
		p=0;
		G_Info_Port="Vous n'avez pas complété le formulaire de destination.<BR>You do not have complete the form of destination.";
	}

	if (p != "?"){
		G_Frais_Port = arrondi_2(parseFloat(p)) ; 
		G_Frais_AssPort = arrondi_2(parseFloat(assurance)) ; 
	}

}

function ModePaiement(){
	var Paiement = G_cdePaiement;

	if ( ! C_Caddie_Pro && !C_Caddie_Export && !C_Caddie_Partenaire && G_cdePays == "France" && parseInt(GetNbItem())==1 && IndiceItemRef(G_RefEchantillon)>0 ){
		G_cdePaiement="Cheque";
		G_Frais_Paiement=0;
		G_Info_Paiement="***";
	} else if (Paiement=="Cheque") {
		G_Frais_Paiement=0;
		G_Info_Paiement="Chèque";
	} else if (Paiement=="Crbt") {
		G_Frais_Paiement = 12 ;
		G_Info_Paiement = "Contre remboursement" ;
	} else if (Paiement=="VAD") {
		G_Frais_Paiement=0;
		G_Info_Paiement="Carte Bancaire";
	} else if (Paiement=="MandatPostal") {
		G_Frais_Paiement=0;
		G_Info_Paiement="Mandat Postal";
	} else if (Paiement=="TransfertWord") {
		G_Frais_Paiement=5;
		G_Info_Paiement="Bank to bank direct transfer";
	} else if (Paiement=="TransfertF") {
		G_Frais_Paiement=0;
		G_Info_Paiement="Virement depuis la France";
	} else if (Paiement=="PayPal") {
		G_Frais_Paiement=Math.floor(Mnt_Cde* 4/100);
		G_Info_Paiement="PayPal / Frais Logistique ";
	} else if (Paiement=="LCR08") {
		G_Frais_Paiement=1.794;
		G_Info_Paiement="LCR à 8 jours";
	} else if (Paiement=="LCR30") {
		G_Frais_Paiement=1.794 ;
		G_Info_Paiement="LCR à 30 jours";
	} else {
		G_Frais_Paiement=0;
		G_Info_Paiement="";
	}
	G_Frais_Paiement = arrondi_2(parseFloat(G_Frais_Paiement / 1.196 ));
}

function DispCaddie(fond,trait,color) {
	DispCaddie_param("T", fond,trait,color) ; 	// toutes les info
}


function DispCaddieSeul(fond,trait,color) {
	DispCaddie_param("S", fond,trait,color) ;		// Affiche des Seul information (hors frais)
}

function DispCaddie_param(TypAff, fond,trait,color) {
	var Mnt_Lig="";	
	var aff="";	
	var Cum_masse = 0 ;
	var CumMasseEchantillon = 0;
	var Cum_MntCde = 0 ;
	var Total_HT=0; 
	var Total_TTC=0; 

	var NbItem=parseInt(GetNbItem());	

	if (NbItem>0) {		
		aff+="<font face='Times New Roman' >";		
		if (TypAff == "S" ) {			
			aff+="<p align='left'><font size='3'><B>Liste des articles choisis : </B></p>";		
		}

		aff+="<TABLE border=0 cellpadding=2 align='center' cellspacing=1 bgcolor='"+trait+"'>";		
		aff+="<TR align='center' bgcolor='"+color+"' color='#FFFFFF' >"; 
		aff+="<TD width='30' ><font size='2' color='#FFFFFF'><B>Qte</B></font></TD>";		
		aff+="<TD width='400'><font size='2' color='#FFFFFF'><B>Désignation</B></font></TD>"; 
		aff+="<TD><font size='2' color='#FFFFFF'><B>Prix<BR>unit.</B></font></TD>";		
		aff+="<TD><font size='2' color='#FFFFFF'><B>Montant<BR>(Euro HT)</B></font></TD>"; 
		aff+="<TD width='70'><font size='2' color='#FFFFFF'><B>Modifier</B></TD>";		
		aff+="</TR>";

		for(var i=1;i<=NbItem;i++) {			
			i1=0; 			
			i2=0;			
			var item=new GetItem(i);
			item.pxU = arrondi_2(parseFloat( item.pxU));			
			Mnt_Lig = arrondi_2(parseFloat(  parseInt(item.qte) * parseFloat( item.pxU))) ;
			Cum_MntCde = arrondi_2(parseFloat(Cum_MntCde) + parseFloat(Mnt_Lig) )  ; 			
			if (! C_Caddie_Pro && !C_Caddie_Export && !C_Caddie_Partenaire && isEchantillon(item.ref)) {
				CumMasseEchantillon += parseInt( parseInt(item.qte)  * parseInt(item.masse) )
			} else {
				Cum_masse += parseInt( parseInt(item.qte)  * parseInt(item.masse) );			
			}
			aff+="<TR>" ;
			aff+="<TD bgcolor='"+fond+"' align='center'><font size='2'>"+item.qte+"</TD>";			
			aff+="<TD bgcolor='"+fond+"'><font size='2'>"+item.des+"</TD>";			
			aff+="<TD bgcolor='"+fond+"' align='center'><font size='2'>"+format(item.pxU)+"</TD>";			
			aff+="<TD bgcolor='"+fond+"' align='right'><font size='2'><B>"+format(Mnt_Lig)+"</B></TD>";
			aff+="<TD bgcolor='"+fond+"' align='center'><A href='' onClick='SupItem("+i+"); window.location.reload(); return false'><img border='0' src='../image/bouton/del.gif' alt='Retirer du caddie /remove from basket'></A>";
			aff+=" <A href='' onClick='ChangeQte("+i+");window.location.reload();return false'><img border='0' src='../image/bouton/qte.gif'' alt='Changer la quantité / change quantity'></A>"
			aff+="<INPUT type='hidden' name='Article[" +i+ "][Ref]' value='" + item.ref + "'> ";			
			aff+="<INPUT type='hidden' name='Article[" +i+ "][Des]' value='" + item.des + "'> ";			
			aff+="<INPUT type='hidden' name='Article[" +i+ "][Masse]' value='" + item.masse + "'> ";			
			aff+="<INPUT type='hidden' name='Article[" +i+ "][Qte]' value='" + item.qte + "'> ";			
			aff+="<INPUT type='hidden' name='Article[" +i+ "][Prx]' value='" + item.pxU + "'> ";			
			aff+="<INPUT type='hidden' name='Article " + i + "' value='" + item.ref + " "  + item.des + " - Quantité = " + item.qte + " - Montant = " + format(Mnt_Lig) + " Euros HT'>" ;	
			aff+="</TD>";			
			aff+="</TR>";
		}

		aff+="<TR>";
		aff+="<TD colspan=3 align='right' bgcolor='"+fond+"'><font size='2'>Montant HT de la commande (Frais de port non inclus)<BR>Amount( Shipping not included )</TD>";
		aff+="<TD align='right' bgcolor='"+fond+"'><font size='2'><B>"+format(Cum_MntCde)+"</B></TD>";		
		aff+="<TD align='right' bgcolor='"+fond+"'></TD>";		
		aff+="</TR>";

		if (TypAff == "S" ) {
			if (!C_Caddie_Export ) {
				aff+="<TR>";
				aff+="<TD colspan=3 align='right' bgcolor='"+fond+"'><font size='2'><B>Montant TTC de la commande  (Frais de port non inclus)<BR>Amount( Shipping not included )</B></TD>";
				aff+="<TD align='right' bgcolor='"+fond+"'><font size='2'><B>"+format(parseFloat( Cum_MntCde * 1.196 ) )+"<B></TD>";
				aff+="<TD align='right' bgcolor='"+fond+"'></TD>";
				aff+="</TR>";
			}
			aff+="<TR>";
			aff+="<TD colspan=4 align='right' bgcolor='"+fond+"'><P align='right'><font size='2'>Le poids de votre colis et de : <BR>The weight of your parcel and of : </TD>";
			aff+="<TD align='right' bgcolor='"+fond+"'><P align='center'><font size='2'>"+format((Cum_masse+CumMasseEchantillon)/1000)+" Kg</TD>";
			aff+="</TR>";		
			aff+="</TABLE>";
		} else  {
			CalcPort(Cum_masse, Cum_MntCde); 
			ModePaiement();

			aff+="<TR>";
			aff+="<TD colspan=3 align='right' bgcolor='"+fond+"'><font size='2'>Mode de Paiement : "+G_Info_Paiement+"</TD>";
			aff+="<TD align='right' bgcolor='"+fond+"'><font size='2'><B>"+format(G_Frais_Paiement)+"</TD>";		
			aff+="<TD align='right' bgcolor='"+fond+"'>&nbsp;</TD>";
			aff+="</TR>";
			aff+="<TR>";
			aff+="<TD colspan=3 align='right' bgcolor='"+fond+"'><font size='2'>"+ G_Info_Port +"</TD>";
			aff+="<TD align='right' bgcolor='"+fond+"'><font size='2'><B>"+format(parseFloat(G_Frais_Port) + parseFloat(G_Frais_AssPort) )+"</B></TD>";
			aff+="<TD align='right' bgcolor='"+fond+"'><P align='left'><font size='1'>p/w: "+ format((Cum_masse+CumMasseEchantillon)/1000)+" Kg</TD>";
			Total_HT = arrondi_2(parseFloat(Cum_MntCde) + parseFloat(G_Frais_Paiement) + parseFloat(G_Frais_Port) + parseFloat(G_Frais_AssPort) );
			aff+="<TR>";
			aff+="<TD colspan=3 align='right' bgcolor='"+color+"'><font color='#FFFFFF' size='3'><B>Total HT</B></TD>";
			aff+="<TD align='right' bgcolor='"+color+"'><font color='#FFFFFF' size='2'><b>"+format(parseFloat(Total_HT))+" €</b></TD>";
			aff+="<TD align='right' bgcolor='"+color+"'>&nbsp;</TD>";		
			aff+="</TR>";		
			if (!C_Caddie_Export ) {
				aff+="<TR>";
				aff+="<TD colspan=3 align='right' bgcolor='"+color+"'><font color='#FFFFFF' size='3'><B>Total TTC</B></TD>";
				aff+="<TD align='right' bgcolor='"+color+"'><font color='#FFFFFF' size='2'><b>"+format(parseFloat(Total_HT * 1.196 ))+" €</b></TD>";
				aff+="<TD align='right' bgcolor='"+color+"'>&nbsp;</TD>";		
				aff+="</TR>";		
			}
			aff+="</TABLE>";
			aff+="<INPUT type='hidden' name='payment' value='"+ G_cdePaiement +"'>";
			aff+="<INPUT type='hidden' name='fraispayment_HT' value='"+format(G_Frais_Paiement)+"'>";
			aff+="<INPUT type='hidden' name='port_HT' value='" + format(G_Frais_Port) + "'>";
			aff+="<INPUT type='hidden' name='assurance_HT' value='" + format(G_Frais_AssPort) + "'>";
			aff+="<INPUT type='hidden' name='poids' value='"+"Poids du colis "+((Cum_masse+CumMasseEchantillon)/1000)+" Kg'>";
			aff+="<INPUT type='hidden' name='total_HT' value='"+format(Total_HT)+"'>";
			Total_TTC = arrondi_2(parseFloat(Total_HT * 1.196 )) ;
			aff+="<INPUT type='hidden' name='total_TTC' value='"+format(Total_TTC)+"'>";		

			SetCookie("total_HT", Total_HT, C_dateExp, C_myDomain);
			SetCookie("total_TTC", Total_TTC, C_dateExp, C_myDomain);
		}

	} else {
		aff="<font color='#FF0000'><B><BR>Le caddie est vide !<BR>The basket is empty<BR></font>";
	}
	document.write(aff);
}

function ViderItem() {
	for (var i=0;i<=30;i++){
		SetCookie("itemno"+i,"", C_dateOld, C_myDomain);
	} ;
	SetNbItem(0);
}

function ViderCaddie() {
	ViderItem () ;
	alert("Le caddie est vide.\nThe basket is empty.");
}

function ViderCookies() {
	SetCookie("leclient","",C_dateOld,C_myDomain);
	SetCookie("kd","",C_dateOld,C_myDomain);
}

function ViderTout() {
	ViderCaddie();
	ViderCookies ();
	alert("Le formulaire est effacé.\nThe form is unobtrusive.");
}

function DispCommande(fond,trait,color) {
	document.write("<TABLE><TR><TD width=300 valign='top'>");
	DispAdresse("leclient");
	document.write("</TD></TR></TABLE>");
}

function VerifCaddie(f) {
	if (GetNbItem()==0){
		alert("Le caddie est vide.\nVous ne pouvez pas commander.");
	}
	else {
		window.location = C_Lien_adresse;
	}
}
