function changeclass(objet, myClass)
{ 
  objet.className = myClass;
}

function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "")
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target=i;
        break;
      }
    }

  var TargetForm = document.forms[target];

  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") &&
         (TargetForm.elements[i].type != "hidden") &&
         (TargetForm.elements[i].type != "reset") &&
         (TargetForm.elements[i].type != "submit") ) {

      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") ||
           (TargetForm.elements[i].type == "password") )
        TargetForm.elements[i].select();

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString)
    TargetElement.value = "";
    TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value))
    return true;
  else
    return false;
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();

  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i = 0; i < strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i = 0; i < strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx)
    return false;

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i = 0; i < strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm')
        strMonth = strDateToCheckArray[i];
      if (strFormatArray[i] == 'dd')
        strDay = strDateToCheckArray[i];
      if (strFormatArray[i] == 'yyyy')
        strYear = strDateToCheckArray[i];
    }
  }
  else {
    if (FormatString.length>7) {
      if (strFormatString.indexOf('mmm') == -1)
        strMonth = strDateToCheck.substring( strFormatString.indexOf('mm'), 2 );
      else
        strMonth = strDateToCheck.substring( strFormatString.indexOf('mmm'), 3 );
      strDay = strDateToCheck.substring( strFormatString.indexOf('dd'), 2 );
      strYear = strDateToCheck.substring( strFormatString.indexOf('yyyy'), 2 );
    }
    else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }
  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i = 0;i < strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth>12 || intMonth<1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }

  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0)
      return true;
  }
  else {
    if ((intYear % 4) == 0)
      return true;
  }

  return false;
}

//Gestion du roll-over
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//Fin gestion du roll-over

function deleteConfirm()
{
 reponse=confirm('Confirmez vous la suppression ?');
 if(reponse) return true;
 else return false;
}

//Ouverture de fenêtre
function openBRWindow(theURL,winName,features)
{
  window.open(theURL,winName,features);
}

function PopupCentrer(page,largeur,hauteur,options)
{
  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  winName = window.open(page,'zoom',"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);

	//On retaille la fenetre par rapport au contenu
	IE5=NN4=NN6=false
	if (document.all)
		IE5=true;
	else if (document.getElementById)
		NN6=true;
	else if (document.layers)
		NN4=true;
	if (IE5) winName.resizeTo(parseInt(largeur)+10,parseInt(hauteur)+41);
  else winName.resizeTo(parseInt(largeur)+8,parseInt(hauteur)+38);
	winName.focus();
}

function addFav()
{
if (document.all)
{
window.external.AddFavorite(location.href, document.title);
}
else
{
alert(JS_ADD_FAVORIS)
}
} 

//Validation du formulaire pour la recommandation à un ami
function valid_formulaire()
{
	var txt_erreur = JS_ERROR;
	var erreur=0;
	if(document.getElementById('nom').value == '')
	{
		txt_erreur += JS_LAST_NAME;
		erreur=1;
	}
	if(document.getElementById('email').value == '' || document.getElementById('emaildest').value == '')
	{
		txt_erreur += JS_EMAIL_EMPTY;
		erreur=1;
	}
	if((document.getElementById('email').value && !checkMail(document.getElementById('emaildest').value)) || (document.getElementById('emaildest').value && !checkMail(document.getElementById('email').value)))
	{
		txt_erreur += ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
		erreur=1;
	}
	if(erreur == 1)
	{
		alert(txt_erreur);
		return false;
	}
	else
		return true;
}

//Validation du formulaire pour la demande de contact
function valid_formulaire_contact()
{
	var txt_erreur = JS_ERROR;
	var erreur=0;
	if(document.getElementById('contactName').value == '')
	{
		txt_erreur += JS_LAST_NAME;
		erreur=1;
	}
	if(document.getElementById('contactEmail').value == '')
	{
		txt_erreur += JS_EMAIL_EMPTY;
		erreur=1;
	}
	if(document.getElementById('contactEmail').value && !checkMail(document.getElementById('contactEmail').value))
	{
		txt_erreur += ENTRY_EMAIL_ADDRESS_CHECK_ERROR;
		erreur=1;
	}
	if(erreur == 1)
	{
		alert(txt_erreur);
		return false;
	}
	else
		return true;
}

function checkMail(x)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function correctPng () // correctly handle PNG transparency in Win IE 5.5 or higher.
   {
   for(var i=0; i<document.images.length; i++)
      {
   var img = document.images[i]
   var imgName = img.src.toUpperCase()
   if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
   var imgID = (img.id) ? "id='" + img.id + "' " : ""
   var imgClass = (img.className) ? "class='" + img.className + "' " : ""
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
   var imgStyle = "display:inline-block;" + img.style.cssText  
   if (img.align == "left") imgStyle = "float:left;" + imgStyle
   if (img.align == "right") imgStyle = "float:right;" + imgStyle
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
   var strNewHTML = "<span " + imgID + imgClass + imgTitle
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
   img.outerHTML = strNewHTML
   i = i-1
      }
     }
   }
	 
//Fonction pour calculer l'assurance sur les frais de port
function calcul_assurance_ship(elmt) {
	var shipping_cost = Number(document.getElementById('shipping_ship_departements_cost').value);
	var montant_assurance = Number(elmt.value);
	if(elmt.checked)//Ajout du montant de l'assurance
	{
		shipping_cost = shipping_cost+montant_assurance;
		//Modification de l'intitulé ("Avec assurance")
		document.getElementById('shipping_ship_departements_method').value = document.getElementById('shipping_ship_departements_method_with_assurance').value;
		document.getElementById('shipping_selected_ship_departements').value = 'ship_departements_assur';
	} 
	else //Suppression du montant de l'assurance
	{
		shipping_cost = shipping_cost-montant_assurance;
		//Modification de l'intitulé ("Sans assurance")
		document.getElementById('shipping_ship_departements_method').value = document.getElementById('shipping_ship_departements_method_without_assurance').value;
		document.getElementById('shipping_selected_ship_departements').value = 'ship_departements';
	}
	if(shipping_cost>0)
		document.getElementById('shipping_ship_departements_cost').value = shipping_cost;
}


//fonction pour updater les points de fidelite
function updateFidelisation(nbpoint){

	document.location="caddie.php?action=fidelite&nbpoint="+nbpoint;

}

function displayLotImage(image){
	document.getElementById('imgLotPdts').innerHTML=image;
}