var isNetscape4 = document.layers;
var isNetscape6 = document.getElementById && !document.all
var isNetscape = isNetscape4 || isNetscape6;
var isIE = document.all && !isNetscape;
var DHTML = document.getElementById || document.all || document.layers;


function flash(tag) { 
  document.write(tag);
} 


function getStyle(nom) {
  if (isNetscape6)
    style = document.getElementById(nom).style;
  else if (isNetscape4)
    eval("style = document."+nom);
  else
    style = document.all[nom].style;
  return(style);
}


function clipping(nom, x1, y1, x2, y2) {
  if (isNetscape4) {
    getStyle(nom).clip.left = x1;
    getStyle(nom).clip.top = y1;
    getStyle(nom).clip.right = x2; 
    getStyle(nom).clip.bottom =  y2;
  }
  else if (isNetscape6)
    getStyle(nom).clip = "rect("+y1+" "+x1+" "+y2+" "+x2+")";
  else
    getStyle(nom).clip = "rect("+y1+" "+x2+" "+y2+" "+x1+")";
}

function deplacement_absolu(nom, abscisse, ordonnee) {
  if (!DHTML)
    return;
  getStyle(nom).left = abscisse;
  getStyle(nom).top = ordonnee;
}

function deplacement_relatif(nom, deltaX, deltaY) {
  if (!DHTML)
    return;
  getStyle(nom).left = parseInt(getStyle(nom).left) + deltaX;
  getStyle(nom).top = parseInt(getStyle(nom).top) + deltaY;
}


function check_email(email) {
        b = true;
        if (email.lastIndexOf('@') < 1)
            b = false;
        if (email.lastIndexOf('@') > email.lastIndexOf('.'))
            b = false;
        if (email.lastIndexOf('@') == email.lastIndexOf('.')+1)
            b = false;
        if (email.length-email.lastIndexOf('.') < 3 || email.length-email.lastIndexOf('.') > 5)
            b = false;
        if (email.length<6)
            b = false;
        return(b);
    }


// retourne un objet xmlHttpRequest.
// méthode compatible entre tous les navigateurs (IE/Firefox/Opera)
function getXMLHTTP(){
  var xhr=null;
  if(window.XMLHttpRequest) // Firefox et autres
  xhr = new XMLHttpRequest();
  else if(window.ActiveXObject){ // Internet Explorer
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e1) {
        xhr = null;
      }
    }
  }
  else { // XMLHttpRequest non supporté par le navigateur
    return null;
  }
  return xhr;
}

function ajoutPanier(BOU_ID, PDT_ID, QUANTITE){
  var xhr=getXMLHTTP();

  xhr.open("GET", "panier.php?BOU_ID="+BOU_ID+"&PDT_ID="+PDT_ID+"&QUANTITE="+QUANTITE, false);
  xhr.send(null);

  alert(xhr.responseText);
}


function arrondiPrix(nombre){
  nombre = Math.round(nombre*100)/100 + 0.001;
  nombre += '';
  return nombre.substr(0, nombre.indexOf('.')+3);
}


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];}
}

var multi_champ = [];

function init_champ_fo(champ, valeur) {
    multi_champ[multi_champ.length] =  [champ, valeur, 1];
    affiche_drapeau_fo(champ, true);
    affiche_champ(champ, true);
    affiche_drapeau_fo(champ, false);
    affiche_champ(champ, false);
}

function affiche_drapeau_fo(champ, principal) {
    var drapeau = '';
    if (principal) {
        drapeau = "<img src='bop/images/flag_"+multi_langue[0][0]+".gif' title='"+multi_langue[0][1]+"' class='multi_drapeau'>";
    }
    else {
        for(i=1; i<multi_langue.length; i++) {
            pos = get_pos(champ);
            if (pos >= 0) {
                if (i == multi_champ[pos][2])
                    drapeau += "<img src='bop/images/flag_"+multi_langue[i][0]+".gif' title='"+multi_langue[i][1]+"' class='multi_drapeau'>";
                else {
                    drapeau += "<a href='javascript:change_secondaire_fo(\""+champ+"\", "+i+");'><img src='bop/images/flag_"+multi_langue[i][0]+".gif' title='"+multi_langue[i][1]+"'";
                    drapeau += " style='filter:alpha(opacity=40); opacity:0.4;' class='multi_drapeau'></a>";
                }
            }
        }
    }
    document.getElementById(champ+(principal ? "_principal" : "_secondaire")+"_flag").innerHTML=drapeau;
    //eval(champ+(principal ? "_principal" : "_secondaire")+".innerHTML = \""+drapeau.replace(new RegExp('"', 'gi'), '\\\"')+"\";");
}

function change_secondaire_fo(champ, i) {
    multi_champ[get_pos(champ)][2] = i;
    affiche_drapeau_fo(champ, false);
    affiche_champ(champ, false);
}


