//Supprime les espaces de début et de fin dans un chaîne de caractères
function isAcrobat(){
	var isAcrobat;
	alert(navigator.mimeTypes["application/pdf"]);
	isAcrobat = navigator.mimeTypes &&
	navigator.mimeTypes["application/pdf"] &&
	navigator.mimeTypes["application/pdf"].enabledPlugin;
	
	if (isAcrobat) {
	 	return 1;
	}else{
		return 0;	
	}
}

function trim(str){
	var str = new String(str);
	return str.replace(/(^\s*)|(\s*$)/g,"");
}

//Retourne vrai si la chaîne de caractères est une adresse mail
function is_mail(str){
	var regex = /^([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+$/;
	var str = new String(str);
	return regex.exec(str);
}

//Retourne vrai si la valeur est une valeur numérique
function is_numeric(str){
	var regex = /[0-9\.,]+/;
	var str = new String(str);
	return regex.exec(str);
}

//Retourne la longueur d'un chaîne de caractères
function strlen(str){
	var str = trim(str);
	return str.length;
}

//Affiche un zoom du produit
function Zoom(id,page){
	//var win = window.open("../popup.php?produit="+id,"popup_produit","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=10,left=10,top=10,height=10");
	//win.focus();
	ZoomPage(id,page);
}
function ZoomPage(id,page){
	var win = window.open("../popup.php?produit="+id+"&page="+page,"popup_produit","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=10,left=10,top=10,height=10");
	win.focus();
}

//Supprimer un produit du panier
function SupprimerPanier(url){
	var ret = confirm("Supprimer le produit de votre panier ?");
	if(ret)
     document.location.href = url;
}

//Inscription à la newsletter
function Inscription(mail){
	if(!is_mail(mail)){
		alert("L'adresse e-mail saisie n'est pas valide");
		return false;
	}
	var win = window.open("../popup_inscription.php?mail="+mail,"popup_inscription","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=200,height=150");
	win.focus();
}

function controlDate(madate){
  
  var reg = /^[0-9]{2}[\/][0-9]{2}[\/][0-9]{4}$[0-9]{0}/;
  
	//Control de la validité d'une date.
	if(madate.length>0 && madate!='0'){

		if(reg.exec(madate)){
		
		  dates=madate.split("/");
		  jour=dates[0];
		  mois=dates[1];
		  annee=Math.round(dates[2])+1900;

		/*- les années divisibles par 4 mais non divisibles par 100,
		- les années divisibles par 400*/

		  if( ((annee%4)==0&&(annee%100)!=0) || (annee%400)==0){
		   nbJourFevrier="29";
		  }else{
		   nbJourFevrier="28";
		  }

		  tabMois=["0","31",nbJourFevrier,"31","30","31","30","31","31","30","31","30","31"];

		  //Vérifie si le jour est supérieur au nombre de jour dans le mois.
		  if(tabMois[Math.round(mois)]<jour || jour==0){
			return false;
		  }
		  //Vérifie si le mois est supérieur au nombre de mois total : 12.
		  if(mois>12 || mois==0){
			return false;
		  }
		
		}else{
			return false;
        }
      }
	  
	  return true;
}
	
function gDate(strDate){	  
	    day = strDate.substring(0,2);
		month = strDate.substring(3,5);
		year = strDate.substring(6,10);
		d = new Date(0);
		d.setDate(day);
		d.setMonth(month-1);
		d.setFullYear(year); 
		return d;  
}

//Retorune:
//   0 si date_1=date_2
//   1 si date_1>date_2
//  -1 si date_1<date_2	  
function compare(date_1, date_2){
	    diff = date_1.getTime()-date_2.getTime();
	    return (diff==0?diff:diff/Math.abs(diff));
}	

String.prototype.padLeft = function(strChar, intLength)
{
 var str = this + '';
 while (str.length != intLength) {
  str = strChar + str;
 }
 return str;
}

String.prototype.isInt = function()
{
 var oRegExp = new RegExp(/\d+/);
 return oRegExp.test(this);
}

Array.prototype.exists = function(objValue)
{
 var boolReturn = false, i = 0;
 for (i = 0; i < this.length; i++) {
  if (this[i] == objValue) {
   boolReturn = true;
   break;
  }
 }
 return boolReturn;
}

Date.prototype.dateFormat = function(strFormat, strLang, intTime)
{

 var arrayLang = ['en', 'fr'];
 var arrayFunctions = ['a', 'A', 'B', 'd', 'D', 'F', 'g', 'G', 'h', 'H', 'i', 'j', 'l', 'L', 'm', 'M', 'n', 'O', 'r', 's', 'S', 't', 'U', 'w', 'W', 'y', 'Y', 'z', 'Z'];

 if (intTime) {
  if (!intTime.toString().isInt()) {
   intTime = null;
  } else {
   intTime *= 1000;
  }
 }
 if (strLang) {
  if (strLang.toString().isInt()) {
   intTime = strLang * 1000;
   strLang = 'en';
  } else {
   if (!arrayLang.exists(strLang)) {
    strLang = 'en';
   }
  }
 } else {
  strLang = 'en';
 }

 var arrayDays_en = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
 var arrayMonths_en = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
 var arraySuffix_en = ['st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'st'];

 var arrayDays_fr = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
 var arrayMonths_fr = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
 var arraySuffix_fr = ['er', 'nd', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème', 'ème'];

 // a : Ante meridiem et Post meridiem en minuscules - am ou pm 
 fct_a = function()
 {
  return (self.getHours() > 11) ? 'pm' : 'am';
 }

 // A : Ante meridiem et Post meridiem en majuscules - AM ou PM 
 fct_A = function()
 {
  return (self.getHours() > 11) ? 'PM' : 'AM';
 }

 // B : Heure Internet Swatch - 000 à 999
 //     http://www.quirksmode.org/index.html?/js/beat.html
 fct_B = function() {
  var intGMTOffset = (self.getTimezoneOffset() + 60) * 60;
  var intSeconds = (self.getHours() * 3600) + (self.getMinutes() * 60) + self.getSeconds() + intGMTOffset;
  var intBeat = Math.floor(intSeconds / 86.4);
  if (intBeat > 1000) {intBeat -= 1000;}
  if (intBeat < 0) {intBeat += 1000;}
  return intBeat.toString().padLeft('0', 3);
 }

 // d : Jour du mois, sur deux chiffres avec zéro initial - 01 à 31 
 fct_d = function()
 {
  return self.getDate().toString().padLeft('0', 2);
 }

 // D : Jour de la semaine, en 3 lettres, anglais par défaut - Mon à Sun 
 fct_D = function()
 {
  return eval('arrayDays_' + strLang)[self.getDay()].substring(0, 3);
 }

 // F : Mois textuel, version longue, anglais par défaut - January à December 
 fct_F = function()
 {
  return eval('arrayMonths_' + strLang)[self.getMonth()];
 }

 // g : Heure au format 12h, sans le zéro initial - 1 à 12 
 fct_g = function()
 {
  return (self.getHours() > 12) ? self.getHours() - 12 : self.getHours();
 }

 // G : Heure au format 24h, sans le zéro initial - 0 à 23 
 fct_G = function()
 {
  return self.getHours();
 }

 // h : Heure au format 12h, avec le zéro initial - 01 à 12 
 fct_h = function()
 {
  return (self.getHours() > 12) ? (self.getHours() - 12).toString().padLeft('0', 2) : self.getHours().toString().padLeft('0', 2);
 }

 // H : Heure au format 24h, avec le zéro initial - 00 à 23 
 fct_H = function()
 {
  return self.getHours().toString().padLeft('0', 2);
 }

 // i : Minutes avec le zéro initial - 00 à 59 
 fct_i = function()
 {
  return self.getMinutes().toString().padLeft('0', 2);
 }

 // j : Jour du mois sans le zéro initial - 1 à 31 
 fct_j = function()
 {
  return self.getDate();
 }

 // l : Jour de la semaine, textuel, anglais par défaut - Sunday à Saturday 
 fct_l = function()
 {
  return eval('arrayDays_' + strLang)[self.getDay()];
 }

 // L : L'année est elle bissextile ? - 0 ou 1 
 fct_L = function()
 {
  var intFullYear = fct_Y();
  return ((intFullYear % 4 == 0 && intFullYear % 100 != 0) || (intFullYear % 4 == 0 && intFullYear % 100 == 0 && intFullYear % 400 == 0)) ? 1 : 0;
 }

 // m : Mois avec le zéro intial - 01 à 12 
 fct_m = function()
 {
  return (self.getMonth() + 1).toString().padLeft('0', 2);
 }

 // M : Mois, en 3 lettres, anglais par défaut - Jan à Dec 
 fct_M = function()
 {
  return eval('arrayMonths_' + strLang)[self.getMonth()].substring(0, 3);
 }

 // n : Mois sans le zéro intial - 1 à 12 
 fct_n = function()
 {
  return (self.getMonth() + 1);
 }

 // O : Différence avec l'heure de Greenwich (GMT), en heures - -1200 à +1200 
 fct_O = function()
 {
  var intTimezone = self.getTimezoneOffset();
  var intTimezoneAbs = Math.abs(intTimezone);
  var strTimezone = Math.floor(intTimezoneAbs / 60).toString().padLeft('0', 2) + (intTimezoneAbs % 60).toString().padLeft('0', 2);
  return (intTimezone < 0) ? '+' + strTimezone : '-' + strTimezone ;
 }

 // r : Format de date RFC 822 Thu, 1 Apr 2004 12:00:00 - +0200 
 fct_r = function()
 {
  return fct_D() + ', ' + fct_j() + ' ' + fct_M() + ' ' + fct_Y() + ' ' + fct_H() + ':' + fct_i() + ':' + fct_s() + ' ' + fct_O();
 }

 // s : Secondes avec le zéro initial - 00 à 59 
 fct_s = function()
 {
  return (self.getSeconds()).toString().padLeft('0', 2);
 }

 // S : Suffixe ordinal d'un jour, anglais par défaut - st, nd, rd, th 
 fct_S = function()
 {
  return eval('arraySuffix_' + strLang)[self.getDate() - 1];
 }

 // t : Nombre de jours dans le mois - 28 à 31 
 fct_t = function()
 {
  var intDays = 0;
  if (self.getMonth() == 1) {
   intDays = 28 + fct_L();
  } else {
   switch (self.getMonth() % 2) {
    case 0 : intDays = 31; break;
    default : intDays = 30;
   }
  }
  return intDays;
 }

 // U : Secondes depuis le 1er Janvier 1970, 0h00 00s GMT - Ex: 1081072800 
 fct_U = function()
 {
  return Math.round(self.getTime() / 1000);
 }

 // w : Jour de la semaine (0 étant dimanche, 6 samedi) - 0 à 6 
 fct_w = function()
 {
  return self.getDay();
 }

 // W : Numéro de la semaine dans l'année - 1 à 52
 //     http://www.asp-php.net/tutorial/asp-php/glossaire.php?glossid=28
 fct_W = function()
 {
  return Math.floor((fct_z() - 1 - self.getDay()) / 7) + 2;
 }

 // y : Année sur 2 chiffres - Ex: 04 
 fct_y = function()
 {
  var strFullYear = fct_Y().toString();
  return strFullYear.substring(strFullYear.length - 2, strFullYear.length);
 }

 // Y : Année sur 4 chiffres - Ex: 2004 
 fct_Y = function()
 {
  return self.getFullYear();
 }

 // z : Jour de l'année - 1 à 366 
 fct_z = function()
 {
  var datePremierJanvier = new Date('January 1 ' + fct_Y().toString() + ' 00:00:00');
  var intDifference = self.getTime() - datePremierJanvier.getTime();
  return Math.floor(intDifference / 1000 / 60 / 60 / 24);
 }

 // Z : Décalage horaire en secondes - -43200 à 43200 
 fct_Z = function()
 {
  var intTimezone = self.getTimezoneOffset();
  var intTimezoneAbs = Math.abs(intTimezone);
  var strTimezone = intTimezoneAbs * 60;
  return (intTimezone < 0) ? strTimezone : -strTimezone ;
 }

 var self = this;
 if (intTime) {
  var intMyTime = self.getTime();
  self.setTime(intTime);
 }
 var arrayFormat = strFormat.split(''), i = 0;
 for (i = 0; i < arrayFormat.length; i++) {
  if (arrayFormat[i] == '\\') {
   arrayFormat.splice(i, 1);
  } else {
   if (arrayFunctions.exists(arrayFormat[i])) {
    arrayFormat[i] = eval('fct_' + arrayFormat[i] + '();');
   }
  }
 }
 if (intMyTime) {
  self.setTime(intMyTime);
 }
 return arrayFormat.join('');

}
function addDaysToDate(old_date, delta_days)
{
    // Date plus plus quelques jours
    var split_date = old_date.split('/');
    // Les mois vont de 0 a 11 donc on enleve 1, cast avec *1
    var new_date = new Date(split_date[2], split_date[1]*1 - 1, split_date[0]*1 + delta_days);
    var new_day = new_date.getDate();
        new_day = ((new_day < 10) ? '0' : '') + new_day; // ajoute un zéro devant pour la forme  
    var new_month = new_date.getMonth() + 1;
        new_month = ((new_month < 10) ? '0' : '') + new_month; // ajoute un zéro devant pour la forme  
    var new_year = new_date.getYear();
        new_year = ((new_year < 200) ? 1900 : 0) + new_year; // necessaire car IE et FF retourne pas la meme chose  
    var new_date_text = new_day + '/' + new_month + '/' + new_year;
    return new_date_text;
}