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 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 nf_call_widget(page, id) {
    document.getElementById(id).innerHTML = '<img src="images/widget_sablier.gif" alt="" />';
    var xhr = getXMLHTTP();
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                document.getElementById(id).innerHTML = xhr.responseText;
            }
        }
    }
    page += (page.indexOf("?") > 0 ? "&" : "?")+'pxekls='+Math.round(Math.random()*100000);
    xhr.open("GET", page, true);
    xhr.send(null);
}  


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);
  if(xhr.responseText == 'ok')
    window.location.href='mon_panier.php';
  else
    alert(xhr.responseText);
}


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


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


//vérifie le champ de recherche
function checkRecherche(){
  with(document.recherche){
    if((RECH.value.length > 0 && document.recherche.RECH.value!="Indiquez un produit") || MAR_ID.selectedIndex > 0){
      document.recherche.action="produit.php";
    }
  }
  if(document.recherche.ENSEIGNE.value=="Indiquez une enseigne"){
	  document.recherche.ENSEIGNE.value="";
  }
  if(document.recherche.LIEU.value=="Saisissez votre ville ou dpt"){
	  document.recherche.LIEU.value="";
  }
  if(document.recherche.RECH.value=="Indiquez un produit"){
	  document.recherche.RECH.value="";
  }
  return true;
}
