var rubrique_courant = '';
var rubrique_choix = '';
var srubrique_courant = '';
var rubrique_actuel = '';
var nav_accueil = '';
var chaine = '';
var popX = 0;
var popY = 0;
var popWidth = 0;
var compteur;
var chemin = '../';

var menu_couleur_off = '#cdea48';
var menu_couleur_on = '#b0af5e';
var nb_bandeaux_home = 4;
var nb_bandeaux_quismns = 2;
var nb_bandeaux_lethe = 4;
var nb_bandeaux_boutique = 4;
var nb_bandeaux_commande = 2;
var nb_bandeaux_contact = 2;
var nb_bandeaux_glossair = 1;

var pageOK = false;

function rollon(rubrique) {
  if (pageOK) {
    lockmenu();
    if (rubrique != rubrique_courant) {
      if (rubrique_courant != '') {
        effaceroll();
      }
      rubrique_courant = rubrique;
      if (rubrique_actuel == 'home' && rubrique=='quismns' && document.getElementById('LBmasque')) document.getElementById('LBmasque').style.display='block';
      if (document.getElementById('MSK'+rubrique)) document.getElementById('MSK'+rubrique).style.display='block';
      if (document.getElementById('menu'+rubrique)) document.getElementById('menu'+rubrique).style.visibility = 'visible';
      btroll(rubrique,'on');
    }
  }
}

function menuChoix(choix,smenu) {
  if (pageOK) {
    lockmenu();
    if (!smenu) effaceSousroll();
    if (rubrique_choix != choix) {
      if (rubrique_choix) {
        rubrique_choix.style.background = menu_couleur_off;
      }
      choix.style.background = menu_couleur_on;
      rubrique_choix = choix;
    }
  }
}

function rollSouson(rubrique) {
  if (pageOK && (rubrique != srubrique_courant)) {
    effaceSousroll();
    srubrique_courant = rubrique;
    document.getElementById('menu'+rubrique).style.visibility = 'visible';
    if (document.getElementById('MSK'+rubrique)) document.getElementById('MSK'+rubrique).style.display='block';
  }
}

function rolloff(niveau) {
  compteur = setTimeout("effaceroll()",500);
}

function lockmenu() {
  clearTimeout(compteur);
}

function effaceroll() {
  if (pageOK) {
    var rb = rubrique_courant;
    if (!rb) return;
    btroll(rb,'off');
    if (srubrique_courant) effaceSousroll();
    if ((rubrique_actuel == 'home') && document.getElementById('LBmasque')) document.getElementById('LBmasque').style.display='none';
    if (document.getElementById('MSK'+rb)) document.getElementById('MSK'+rb).style.display='none';
    if (document.getElementById('menu'+rb)) document.getElementById('menu'+rb).style.visibility = 'hidden';
    rubrique_courant = '';
    if (rubrique_choix) {
      rubrique_choix.style.background = menu_couleur_off;
      rubrique_choix = '';
    }
  }
}

function effaceSousroll() {
  if (pageOK) {
    var rb = srubrique_courant;
    if (!rb) return;
    document.getElementById('menu'+rb).style.visibility = 'hidden';
    if (document.getElementById('MSK'+rb)) document.getElementById('MSK'+rb).style.display='none';
    srubrique_courant = '';
  }
}

function debutMenu(nom,posX,posY,largeur) {
  popWidth = largeur;
  chaine = '';
  chaine += '<div id="menu'+nom+'" style="position: absolute; top: '+posY+'; left: '+posX+'; width: '+popWidth+'; background-color: #ffffff; visibility: hidden; z-index: 100">\n';
  chaine += '<table border="0" cellpadding="2" cellspacing="0" width="' + largeur + '" onMouseOver="rollon(\'' + nom + '\')" onMouseOut="rolloff()" class="menucadre">';
  chaine += '<tr><td height="5" class="menuchoix"></td></tr>';
}

function addChoix(lien,libelle,cible,schoix) {
  var tmp_lien = '';
  if (lien=='#') {
    tmp_lien = 'return false';
  }
  else {
    tmp_lien = "window.open('"+chemin+lien+"','"+cible+"')";
  }
  if (cible == '') cible = '_self';
  chaine += '  <tr>\n';
  if (schoix) {
    chaine += '    <td class="menuchoix" width="' + popWidth + '" height="18" onMouseOver="menuChoix(this);rollSouson(\'' + schoix + '\')" onClick="'+tmp_lien+'"><a href="#" onClick="return false" class="menulien" onMouseOver="lockmenu()">' + libelle + '</a></td>\n';
  }
  else {
    chaine += '    <td class="menuchoix" width="' + popWidth + '" height="18" onMouseOver="menuChoix(this);" onClick="'+tmp_lien+'"><a href="#" onClick="return false" class="menulien">' + libelle + '</a></td>\n';
  }
  chaine += '  </tr>\n';
}

function addTrait() {
  chaine += '<tr><td class="menuchoix" style="padding: 0"><div style="border-bottom: 1px dashed #000000; width: 100%; margin: 5 2 3 2; line-height: 1px"></div></td></tr>';
}

function finMenu() {
  chaine += '<tr><td height="7" class="menuchoix"></td></tr>';
  chaine += '</table></div>';
  document.write(chaine);
}

function debutSousMenu(nom,posX,posY,largeur) {
  popWidth = largeur;
  chaine = '';
  chaine += '<div id="menu'+nom+'" style="position: absolute; top: '+posY+'; left: '+posX+'; width: '+popWidth+'; background-color: #ffffff; visibility: hidden; z-index: 100">\n';
  chaine += '<table border="0" cellpadding="2" cellspacing="0" width="' + largeur + '" onMouseOver="lockmenu()" onMouseOut="rolloff()" class="sousmenucadre">';
  chaine += '<tr><td height="5" class="menuchoix"></td></tr>';
}

function addSousChoix(lien,libelle,cible) {
  if (cible == '') cible = '_self';
  chaine += '  <tr><td class="menuchoix" width="' + popWidth + '" height="18" onMouseOver="menuChoix(this,true)" onClick="window.open(\'' + chemin + lien + '\',\'' + cible + '\')"><a href="#" onClick="return false" class="menulien" onMouseOver="lockmenu()">' + libelle + '</a></td></tr>\n';
}

function btroll(bouton,etat) {
  if (pageOK && document.images) {
    if (rubrique_actuel != bouton) document.images[bouton].src = chemin + 'images/' + nav_accueil + 'men_' + bouton + '_' + etat + '.gif';
  }
}

function hauteurmin(margeH) {
  if (!margeH) margeH = 195;
  if (window.innerHeight) {
    var hauteur = window.innerHeight - margeH;
  }
  else {
    if (document.body.clientHeight) var hauteur = document.body.clientHeight - margeH;
  }
  document.write('<img src="/images/espace.gif" alt="" width="1" height="' + hauteur + '" border="0" align="left">');
}

function selecteur_go(index) {
  var destination = index[index.selectedIndex].value;
  if (destination != '#') {
    index.selectedIndex = 0;
    var fen = window.open(destination,'_self');
  }
}

function rollonbout(txt) {
  if (txt) document.getElementById('txt'+txt).style.visibility = 'visible';
}

function rolloffbout(txt) {
  if (txt) document.getElementById('txt'+txt).style.visibility = 'hidden';
}

function carte() {
  var myPopup = window.open(chemin+'info/carte.htm', 'popCGV', 'resizable=yes,scrollbars=yes,status=no,menubar=no,toolbar=yes,directories=no,location=no,width=630,height=295');
  if (myPopup) myPopup.focus();
  return false;
}

function cartehome() {
  var myPopup = window.open(chemin+'info/carte_home.htm', 'popCGV', 'resizable=yes,scrollbars=yes,status=no,menubar=no,toolbar=yes,directories=no,location=no,width=630,height=550');
  if (myPopup) myPopup.focus();
  return false;
}


function mentions() {
  var myPopup = window.open(chemin+'info/mentions.htm', 'popCGV', 'resizable=yes,scrollbars=yes,status=no,menubar=no,toolbar=yes,directories=no,location=no,width=580,height=500');
  if (myPopup) myPopup.focus();
  return false;
}

function cgv() {
  var myPopup = window.open(chemin+'info/cgv_pop.htm', 'popCGV', 'resizable=yes,scrollbars=yes,status=no,menubar=no,toolbar=yes,directories=no,location=no,width=580,height=500');
  if (myPopup) myPopup.focus();
  return false;
}

function ucc(montant) {
  if (escape(montant.substring(montant.length-2,montant.length)) == "%A0%u20AC") montant = montant.substring(0,montant.length-2);
  if (montant.indexOf(',') > -1) {
    var montantOut = '';
    for (var i = 0; i < montant.length; i++) {
      if (montant.substring(i, i + 1) == ',') {
        montantOut += '.';
      }
      else {
        montantOut += montant.substring(i, i + 1);
      }
    }
    montant = montantOut;
  }
  var myPopup = window.open(chemin+'info/ucc.htm?'+montant, 'popUCC', 'resizable=yes,scrollbars=yes,status=no,menubar=no,toolbar=yes,directories=no,location=no,width=793,height=430');
  if (myPopup) myPopup.focus();
  return false;
}

function champBad(champ) {
  champ.style.backgroundColor="#ff8400";
  champ.focus();
}

function champGood(champ) {
  champ.style.backgroundColor="#ffffff";
}

function radioBad(classe,champ){
  document.getElementById(classe+'1').style.backgroundColor="#ff8400";
  document.getElementById(classe+'2').style.backgroundColor="#ff8400";
  document.getElementById(classe+'3').style.backgroundColor="#ff8400";
  champ[0].focus();
}

function radioGood(classe,champ) {
  document.getElementById(classe+'1').style.backgroundColor="#EDF2CC";
  document.getElementById(classe+'2').style.backgroundColor="#EDF2CC";
  document.getElementById(classe+'3').style.backgroundColor="#EDF2CC";
}

function test_vide(champ) {
  if (champ.value.length == 0) return true;
  if (champ.value.length > 0) {
    for (var i = 0; i < champ.value.length; i++) {
      if (champ.value.substring(i, i + 1) != ' ') return false;
    }
  }
  return true;
}

function test_num(champ) {
  var validCars = "0123456789";
  var isNum = true;
  var carac;
  for (i=0;i<champ.value.length;i++) {
    carac = champ.value.charAt(i);
    if (validCars.indexOf(carac) == -1) isNum = false;
  }
  return isNum;
}

function test_radio_checked(champ){
  for (i = 0; i < champ.length; i++){
    if (champ[i].checked==true) return true;
  }
  return false;
}

function test_email(champ) {
  champ.value = champ.value.replace(/^\s+|\s+$/g, '');
  if (champ.value.length < 5) { return false }
  if (champ.value.indexOf(' ') >= 0) { return false }
  if (champ.value.indexOf(',') >= 0) { return false }
  if (champ.value.indexOf(';') >= 0) { return false }
  if (champ.value.indexOf(':') >= 0) { return false }
  if (champ.value.indexOf('\t') >= 0) { return false }
  if (champ.value.indexOf('@') < 0) { return false }
  var mailparts = champ.value.split('@');
  if (mailparts[0].length < 1) { return false }
  if (mailparts[1].indexOf('.') < 0) { return false }
  var domaine = mailparts[1].split('.');
  if (domaine[0].length < 1) { return false }
  if (domaine[1].length < 2) { return false }
  return true;
}

function verifchaine(formulaire) {
  tmptxtout = "";
  if (formulaire.CHAINE.value.indexOf("_") > -1) {
    for (i=0; i<formulaire.CHAINE.value.length; i++) {
      if (formulaire.CHAINE.value.charAt(i) != "_") tmptxtout += formulaire.CHAINE.value.charAt(i);
    }
    formulaire.CHAINE.value = tmptxtout;
  }
}

function test_cp(champ,champpays) {
  if (champpays[champpays.selectedIndex].value>0 && champpays[champpays.selectedIndex].value != 14 && test_vide(champ)) return false;
  if (champpays[champpays.selectedIndex].value>0 && champpays[champpays.selectedIndex].value < 5) {
    if (champ.value.length != 5) return false;
    if (!test_num(champ)) return false;
    calc_pays=1;
    if (champ.value>75000 && champ.value<76000) calc_pays = 2;
    if (champ.value>77000 && champ.value<79000) calc_pays = 2;
    if (champ.value>91000 && champ.value<96000) calc_pays = 2;
    if (champ.value>97000 && champ.value<98000) calc_pays = 3;
    if (champ.value>98000 && champ.value<99000) calc_pays = 4;
    if (calc_pays==1 && champpays[champpays.selectedIndex].value != 1) champpays.selectedIndex = 3;
    if (calc_pays==2 && champpays[champpays.selectedIndex].value != 2) champpays.selectedIndex = 2;
    if (calc_pays==3 && champpays[champpays.selectedIndex].value != 3) champpays.selectedIndex = 4;
    if (calc_pays==4 && champpays[champpays.selectedIndex].value != 4) champpays.selectedIndex = 5;
  }
  return true;
}

function nettTxt(champ,tiret) {
  if (!test_vide(champ)) champGood(champ);
  var hexAccents=[ /[\x09]/g, /[\xA0]/g, /[\xC0-\xC5]/g, /[\xC6]/g, /[\xC7]/g, /[\xC8-\xCB]/g, /[\xCC-\xCF]/g, /[\xD1]/g, /[\xD2-\xD6]/g, /[\xD8]/g, /[\xD9-\xDC]/g, /[\xDD]/g, /[\xDF]/g, /[\xE0-\xE5]/g, /[\xE6]/g, /[\xE7]/g, /[\xE8-\xEB]/g, /[\xEC-\xEF]/g, /[\xF0]/g, /[\xF1]/g, /[\xF2-\xF6]/g, /[\xF8]/g, /[\xF9-\xFC]/g, /[\xFD]/g, /[\xFF]/g ];
  var repCars=[' ',' ','A','AE','C','E','I','N','O','O','U','Y','SS','A','AE','C','E','I','O','N','O','O','U','Y','Y'];
  var hexVire=[ /[\x00-\x1F]/g, /[\x21-\x26]/g, /[\x28-\x2C]/g, /[\x2E-\x2F]/g, /[\x3A-\x40]/g, /[\x5B-\xFF]/g ];
  var tmpSortie=champ.value.toUpperCase();
  for (var i=0; i < hexAccents.length; i++) {
    tmpSortie=tmpSortie.replace(hexAccents[i],repCars[i]);
  }
  if (navigator.appVersion.indexOf('Chrome')<0) {
    for (var i=0; i < hexVire.length; i++) {
      tmpSortie=tmpSortie.replace(hexVire[i],'');
    }
    if (!tiret) {
      for (var i=0; i < hexVire.length; i++) {
        tmpSortie=tmpSortie.replace('-',' ');
      }
    }
  }
  champ.value=tmpSortie;
}

function strcmp ( str1, str2 ) {
  return ((str1 == str2) ? 0 : (( str1 > str2 ) ? 1 : -1 ));
}

function prodZoom(lien,largeur,hauteur) {
  var maPopup = window.open(lien, 'popProdZoom', 'resizable=yes,scrollbars=no,status=no,menubar=no,toolbar=no,directories=no,location=no,width='+largeur+',height='+hauteur);
  if (maPopup) maPopup.focus();
  return false;
}

function retaille(pixX,pixY) {
  if (window.innerWidth) {
    top.innerWidth = pixX;
    top.innerHeight = pixY;
  }
  else {
    movX = pixX - document.body.clientWidth;
    movY = pixY - document.body.clientHeight;
    window.resizeBy(movX,movY);
  }
}

var markerImage = ["/images/googlemap_1.png","/images/googlemap_1.png"];

function createMarker(point,html,idnum,icon) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });
  return marker;
}

function fixPoint(map,monLat,monLong,monLibelle,idnum,icon,centre) {
  point = new GPoint(monLong, monLat);
  if (centre) map.setCenter(point, 15);
  marker[idnum]=createMarker(point,monLibelle,idnum,icon);
  map.addOverlay(marker[idnum]);
  marker[idnum].setImage(markerImage[icon]);
}

function zap() {
  map.clearOverlays();
}

function majcc(formulaire) {
  tot = 0;
  if (document.getElementById('ccstot15')) {
    document.getElementById('ccstot15').innerHTML = formulaire.qte15.value*15;
    tot += formulaire.qte15.value*15;
  }
  if (document.getElementById('ccstot30')) {
    document.getElementById('ccstot30').innerHTML = formulaire.qte30.value*30;
    tot += formulaire.qte30.value*30;
  }
  if (document.getElementById('ccstot50')) {
    document.getElementById('ccstot50').innerHTML = formulaire.qte50.value*50;
    tot += formulaire.qte50.value*50;
  }
  if (document.getElementById('ccstot100')) {
    document.getElementById('ccstot100').innerHTML = formulaire.qte100.value*100;
    tot += formulaire.qte100.value*100;
  }
  if (document.getElementById('cctot')) document.getElementById('cctot').innerHTML = tot;
}
