
function ChampNonVide(ChampNom,message,FormNom) {
 if (document.forms[FormNom].elements[ChampNom].value.length < 1) {
  alert(" "+message);
  document.forms[FormNom].elements[ChampNom].focus();
  return true;
 }
}

function EmailValid (ChampNom,FormNom,lang) {
 var lib = "";
 if (lang == "fr") { lib = "Votre adresse e-mail n'est pas valide"; }
 else { lib = "Please enter a correct e-mail address"; }

 adresse = document.forms[FormNom].elements[ChampNom].value;
 var place = adresse.indexOf("@",1);
 var point = adresse.indexOf(".",place+1);
  if ((place > -1)&&(adresse.length >2)&&(point > 1)) {
  return false;
  }
	else {
   alert(lib);
   document.forms[FormNom].elements[ChampNom].focus();
   return true;
  }
}

function checkadr(FormNom) {

	if (document.forms[FormNom].adrdiff.checked == true) {

        document.forms[FormNom].adrliv.disabled = false;
		document.forms[FormNom].villeliv.disabled = false;
		document.forms[FormNom].cpliv.disabled = false;
		document.forms[FormNom].paysliv.disabled = false;
		
	} else {
		
		document.forms[FormNom].adrliv.disabled = true;
		document.forms[FormNom].villeliv.disabled = true;
		document.forms[FormNom].cpliv.disabled = true;
		document.forms[FormNom].paysliv.disabled = true;
	}
}

function clearContact(FormNom) {
	document.forms[FormNom].nom.value = "";
	document.forms[FormNom].email.value = "";
	document.forms[FormNom].texte.value = "";
}

function validFormContact(FormNom,lg) {

if (lg == "fr") { 
 if (ChampNonVide('nom' ,'Veuillez saisir votre nom', FormNom)) return false; 
 if (EmailValid ('email' , FormNom, lg)) return false;
 if (ChampNonVide('texte' ,'Veuillez saisir votre message', FormNom)) return false; 
}
else {
 if (ChampNonVide('nom' ,'Please enter your name', FormNom)) return false; 
 if (EmailValid ('email' , FormNom, lg)) return false;
 if (ChampNonVide('texte' ,'Please enter your message', FormNom)) return false; 
}

document.forms[FormNom].submit();

}

function validCde(FormNom,lg) {
var lib1 = "";
var lib2 = "";
// if (ChampNonVide('nom' ,'Veuillez saisir votre nom', FormNom)) return false; 
// if (EmailValid ('cli_email' , FormNom, lg)) return false;

if (lg == "fr") { 
  lib1 = "Votre commande ne contient aucun produit.";
  lib2 = "Vous devez sélectionner votre pays de livraison afin d'obtenir le montant total de votre commande.";
  }
else { 
  lib1 = "Please select a product."; 
  lib2 = "In order to validate your purchase please select a country for delivery.";
}

if ((document.forms[FormNom].qte1.value == 0) && (document.forms[FormNom].qte2.value == 0) && (document.forms[FormNom].qte3.value == 0) && (document.forms[FormNom].qte4.value == 0) && (document.forms[FormNom].qte5.value == 0) && (document.forms[FormNom].qte6.value == 0) && (document.forms[FormNom].qte7.value == 0) ) {
	alert (lib1);
	return false;
   }
   
   if (document.forms[FormNom].pays.value == 0) {
	   alert (lib2);
	   document.forms[FormNom].pays.focus();
	   return false;
   }
}

function ConfirmCde(FormNom,lg) {
var lib1 = "";

if (lg == "fr") { 
 if (ChampNonVide('nom' ,'Veuillez saisir votre nom', FormNom)) return false; 
 if (ChampNonVide('prenom' ,'Veuillez saisir votre prénom', FormNom)) return false; 
 if (ChampNonVide('tel' ,'Veuillez saisir un numéro de téléphone', FormNom)) return false; 
 if (EmailValid ('email' , FormNom, lg)) return false;
 if (ChampNonVide('adrfact' ,'Veuillez saisir une adresse de facturation', FormNom)) return false; 
 if (ChampNonVide('villefact' ,'Veuillez saisir une ville pour votre adresse de facturation', FormNom)) return false; 
 if (ChampNonVide('cpfact' ,'Veuillez saisir un code postal', FormNom)) return false;
 
 lib1 = "Veuillez sélectionner un pays pour votre adresse de facturation.";
 
 if (document.forms[FormNom].adrdiff.checked == true) {
	 
	  if (ChampNonVide('adrliv' ,'Veuillez saisir une adresse de livraison', FormNom)) return false; 
      if (ChampNonVide('villeliv' ,'Veuillez saisir une ville pour votre adresse de livraison', FormNom)) return false; 
      if (ChampNonVide('cpliv' ,'Veuillez saisir un code postal', FormNom)) return false;
	  
	  if (document.forms[FormNom].paysliv.value == 0) {
	   alert ("Veuillez sélectionner un pays pour votre adresse de livraison.");
	   document.forms[FormNom].paysliv.focus();
	   return false;
      }
 }
 
} 
 else {
 if (ChampNonVide('nom' ,'Please enter your last name', FormNom)) return false; 
 if (ChampNonVide('prenom' ,'Please enter your first name', FormNom)) return false; 
 if (ChampNonVide('tel' ,'Please enter a phone number', FormNom)) return false; 
 if (EmailValid ('email' , FormNom, lg)) return false;
 if (ChampNonVide('adrfact' ,'Please enter a billing address', FormNom)) return false; 
 if (ChampNonVide('villefact' ,'Please enter a city for your billing address', FormNom)) return false; 
 if (ChampNonVide('cpfact' ,'Please enter a zip code for your billing address', FormNom)) return false;
 
 lib1 = "Please select a country for your billing address.";
 
 if (document.forms[FormNom].adrdiff.checked == true) {
	 
	  if (ChampNonVide('adrliv' ,'Please enter a delivery address', FormNom)) return false; 
      if (ChampNonVide('villeliv' ,'Please enter a city for your delivery address', FormNom)) return false; 
      if (ChampNonVide('cpliv' ,'Please enter a zip code for your delivery address', FormNom)) return false;
	  
	  if (document.forms[FormNom].paysliv.value == 0) {
	   alert ("Please select a country for your delivery address.");
	   document.forms[FormNom].paysliv.focus();
	   return false;
      }
   }
 
 }



   if (document.forms[FormNom].paysfact.value == 0) {
	   alert (lib1);
	   document.forms[FormNom].paysfact.focus();
	   return false;
   }
}

function popup(url,w,h) {
 var le = (screen.availWidth - w) /2;
 var he = (screen.availHeight -h) /2;
 win = window.open(url,null,'height='+h+',width='+w+',status=no,toolbar=no,scrollbars=1,menubar=no,location=no,resizable=yes,left='+le+', top='+he,false);
 win.focus();
}

function checkVin(qte, cb) {
 if (document.form1.elements[qte].value != 0) { document.form1.elements[cb].checked = true; }
 else { document.form1.elements[cb].checked = false; }
}

function chgIce() {

 /*if (document.form1.id5.value == 1) document.form1.elements['qte5'].value = q5;
 else if (document.form1.id5.value == 2) document.form1.elements['qte5'].value = q6;*/
 
 if (p5 == 1) {
	 document.form1.id5.value = 1;
	 document.form1.elements['qte5'].value = q5;
 }
 if (p6 == 1) {
	 document.form1.id5.value = 2;
	 document.form1.elements['qte5'].value = q6;
 }
 if (p7 == 1) {
	 document.form1.id6.value = 7;
	 document.form1.elements['qte6'].value = q7;
 }
 if (p8 == 1) {
	 document.form1.id6.value = 8;
	 document.form1.elements['qte6'].value = q8;
 }
 if (p9 == 1) {
	 document.form1.id7.value = 9;
	 document.form1.elements['qte7'].value = q9;
 }

 
 
}

function calculPrix(priIce6, priIce24,priBlack, priDomBl, priDomRou, priDomRos, priIce06, priIce024, priIceC6) {

  var totTTC = document.getElementById('totTTC');
  var portTTC = document.getElementById('portTTC');
  var totPortTTC = document.getElementById('totPortTTC');
  var paysliv = document.form1.pays.value;
  var t= 0;
  var totport = 0;
  var totcde = 0;
  
  if (document.form1.id5.value == 1) t += parseFloat(priIce6) * document.form1.qte5.value; 
  if (document.form1.id5.value == 2) t += parseFloat(priIce24) * document.form1.qte5.value; 
  if (document.form1.id6.value == 7) t += parseFloat(priIce06) * document.form1.qte6.value; 
  if (document.form1.id6.value == 8) t += parseFloat(priIce024) * document.form1.qte6.value; 
  if (document.form1.id7.value == 9) t += parseFloat(priIceC6) * document.form1.qte7.value; 
  t += parseFloat(priBlack) * document.form1.qte4.value;
  t += parseFloat(priDomBl) * document.form1.qte2.value;
  t += parseFloat(priDomRou) * document.form1.qte1.value;
  t += parseFloat(priDomRos) * document.form1.qte3.value;
  
  // frais de port 
  // icetropez, icetropez 0% = 1
  // icetropez, icetropez 0% = 2
  // domaine tropez,crazy pack 6 = 3
  if (document.form1.id5.value == 1) totport += document.form1.qte5.value * port[1][paysliv]; 
  if (document.form1.id5.value == 2) totport += document.form1.qte5.value * port[2][paysliv]; 
  if (document.form1.id6.value == 7) totport += document.form1.qte6.value * port[1][paysliv]; 
  if (document.form1.id6.value == 8) totport += document.form1.qte6.value * port[2][paysliv]; 
  if (document.form1.id7.value == 9) totport += document.form1.qte7.value * port[3][paysliv]; 
  totport += document.form1.qte4.value * port[3][paysliv];
  totport += document.form1.qte2.value * port[3][paysliv];
  totport += document.form1.qte1.value * port[3][paysliv];
  totport += document.form1.qte3.value * port[3][paysliv];

  document.form1.totPort.value = totport;
  
  val = 0;
  new_tot = val + t;  // total hors frais de port
  document.form1.total_produit.value = new_tot;
  
  totcde = new_tot + totport; // total avec frais de port
  document.form1.totCdeTTC.value = totcde;
  
  new_tot = format(new_tot, 2, " ");
  totport = format(totport, 2, " ");
  totcde = format(totcde, 2, " ");
  //new_tot_ch = new_tot.toString();
  //new_tot_ch = new_tot_ch.replace('.',',');

  portTTC.innerHTML = totport + " &euro;" ;
  totTTC.innerHTML = new_tot + " &euro;"; 
  totPortTTC.innerHTML = totcde + " &euro;";
 
  }

function format(valeur,decimal,separateur) {
// formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
	var deci=Math.round( Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur)))) ; 
	var val=Math.floor(Math.abs(valeur));
	if ((decimal==0)||(deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); deci=0;}
	var val_format=val+"";
	var nb=val_format.length;
	for (var i=1;i<4;i++) {
		if (val>=Math.pow(10,(3*i))) {
			val_format=val_format.substring(0,nb-(3*i))+separateur+val_format.substring(nb-(3*i));
		}
	}
	if (decimal>0) {
		var decim=""; 
		for (var j=0;j<(decimal-deci.toString().length);j++) {decim+="0";}
		deci=decim+deci.toString();
		val_format=val_format+"."+deci;
	}
	if (parseFloat(valeur)<0) {val_format="-"+val_format;}
	return val_format;
}



function imgSuiv()
  {
  counter++;
  if (counter == nbrImg) 
    counter = 1; 

  document.getElementById('pic').src = img[counter].src;
  }

function imgPrec()
  {
  counter--;
  if (counter == 1) 
    counter = 11; 

  document.getElementById('pic').src = img[counter].src;
  }

function validAge(FormNom,url,lg) {
 var pays_age = parseInt(document.forms[FormNom].pays.value);
 var lib1 = "";
 var lib2 = "";
 var lib3 = "";
 var lib4 = "";
  
 if (lg == "fr") { 
   lib1 = "Veuillez sélectionner un pays";
   lib2 = "Le jour de naissance doit être un nombre";
   lib3 = "Le mois de naissance doit être un nombre";
   lib4 = "L'année de naissance doit être un nombre";
 } else {
   lib1 = "Please select a country";
   lib2 = "The birthday must be a number";
   lib3 = "The birth month must be a number";
   lib4 = "The birth year must be a number";
 }
  
 if ( pays_age == 0 )  {
      alert(lib1);
	  document.forms[FormNom].pays.focus();
	  return false;
    }
	
 if ((document.forms[FormNom].journais.value == "") || (isNaN(document.forms[FormNom].journais.value))) {
      alert(lib2);
	  document.forms[FormNom].journais.focus();
	  return false;
    } 
	

 if ((document.forms[FormNom].moisnais.value == "") || (isNaN(document.forms[FormNom].moisnais.value))) {
      alert(lib3);
	  document.forms[FormNom].moisnais.focus();
	  return false;
    }
	
 if ((document.forms[FormNom].annais.value == "") || (isNaN(document.forms[FormNom].annais.value))) {
      alert(lib4);
	  document.forms[FormNom].annais.focus();
	  return false;
    }
	
   																											
   if ( date_age(document.forms[FormNom].annais.value, document.forms[FormNom].moisnais.value, document.forms[FormNom].journais.value) < pays_age ) {
	 document.forms[FormNom].action = url+'?age=no';
     document.forms[FormNom].submit();
    } else {	
     document.forms[FormNom].action = 'detection-age.php?lang='+lg;
     document.forms[FormNom].submit();
	}

}

function tab_age(FormNom,chp,len) {
	
	if (chp == "journais") {
	 if (document.forms[FormNom].journais.value.length >= len) { document.forms[FormNom].moisnais.focus(); }
	}
	if (chp == "moisnais") {
	 if (document.forms[FormNom].moisnais.value.length >= len) { document.forms[FormNom].annais.focus(); }
	}
	
}
function date_age(a,m,j) {
	d1 = new Date();
    my = d1.getFullYear();
	
	if (d1.getMonth()<m-1 || (d1.getMonth() == m-1 && d1.getDate()<j)) {
       my--;
   }
   return (my-a);
}

function popup(url,w,h) {
 var le = (screen.availWidth - w) /2;
 var he = (screen.availHeight -h) /2;
 win = window.open(url,null,'height='+h+',width='+w+',status=no,toolbar=no,scrollbars=1,menubar=no,location=no,resizable=yes,left='+le+', top='+he,false);
 win.focus();
}