//'
//' deplacement d'ancre en ancre dans proddesc
//'
  function showIt(elID) {
    var el = document.getElementById(elID);
    el.scrollIntoView(true); }

//'
//' initialisation tempo pour pblm cache =======================================
//'
  function init_hrday() {
    var today = new Date();
    var hrday = "";
    var toaff = today.toString().split(' ');
    if (toaff[3].length == 8) {
      hrday=toaff[3]; }
    else {
      hrday=toaff[4]; }
    return hrday; }

//'
//' traitement d'une url en GET ================================================
//'
  function trturl2(url) {
    if (url.indexOf("hi_bottom.htm") != -1) videmark=false; else videmark=true;
    var rep=geturl(url);
    var tab=rep.split("##@@##");

    var chai="";
    var dest="";
    var text=""; 
    var Ptab=""; 

    if (videmark) {
      pTab = document.getElementById("marketing");
      if (pTab) pTab.innerHTML=text; } 

    for (var i=0; i<tab.length; i++) {
      chai=tab[i];
      dest=chai.substr(0,chai.indexOf(":")); 
      text=chai.substr(chai.indexOf(":")+1);
      if ((dest == "alert") || (dest == "bback") || (dest == "publi") || (dest == "ganalyt") || (dest == "location")) {
        if (dest == "publi") {
//        chaine & liste publicité 
          if (text.indexOf("##$$##") == -1) {
            cpub=text;
            lpub=""; }
          else { 
            cpub=text.substr(0,text.indexOf("##$$##")); 
            lpub=text.substr(text.indexOf("##$$##")+6); }
//        on arrête la tache en cours si liste non vide ou chaine différente
          if (TQenc) {
            if ((lpub != "") || (cpub.substr(0,TQpub.length) != TQpub)) {
              TQenc=false;
              clearInterval(TQiid); 
	            pTab = document.getElementById("pubprodimg");
              if (pTab) pTab.innerHTML = ""; } }
//        on relance une tache si la liste n'est pas vide
          if (lpub != "") {
            TQtab=lpub.split("##$$##"); 
            TQnbr=TQtab.length; 
            TQcmt=-1;
            TQenc=true;
            TQpub=cpub;
            TQiid = setInterval("TQfunc()",4000); } }
        else {  
          if (dest == "alert") {
            alert(text); }
          else {
            if (dest == "location") {
              top.location=text; }
            else {
              if (dest == "ganalyt") {
//              var pageTracker = _gat._getTracker("UA-1086115-1"); 
//              pageTracker._initData(); 
//              pageTracker._trackPageview(text); 
              } 
              else {
                dhtmlHistory.add(text,("retour : "+text)); } } } } }
      else { 
        pTab = document.getElementById(dest);
        if (pTab) pTab.innerHTML=text; else alert("Erreur !!!"); } } 

    if (document.body.className == 'debsablier') {
      document.body.className = 'finsablier';
      for (ifo = 0; ifo < document.searchform.length; ifo++) {
        document.searchform.elements[ifo].className = 'finsablier'; } } 
    return tab.length; }

//'
//' traitement d'une url en POST ===============================================
//'
  function trturl2post(url,nom) {
    if (url.indexOf("hi_bottom.htm") != -1) videmark=false; else videmark=true;

    var rep=posturl(url,nom);
    var tab=rep.split("##@@##");

    var chai="";
    var dest="";
    var text=""; 
    var Ptab=""; 

    if (videmark) {
      pTab = document.getElementById("marketing");
      if (pTab) pTab.innerHTML=text; } 

    for (var i=0; i<tab.length; i++) {
      chai=tab[i];
      dest=chai.substr(0,chai.indexOf(":")); 
      text=chai.substr(chai.indexOf(":")+1); 
      if ((dest == "alert") || (dest == "bback") || (dest == "publi") || (dest == "ganalyt")) {
        if (dest == "publi") {
//        chaine & liste publicité 
          if (text.indexOf("##$$##") == -1) {
            cpub=text;
            lpub=""; }
          else { 
            cpub=text.substr(0,text.indexOf("##$$##")); 
            lpub=text.substr(text.indexOf("##$$##")+6); }
//        on arrête la tache en cours si liste non vide ou chaine différente
          if (TQenc) {
            if ((lpub != "") || (cpub.substr(0,TQpub.length) != TQpub)) {
              TQenc=false;
              clearInterval(TQiid); 
  	          pTab = document.getElementById("pubprodimg");
              if (pTab) pTab.innerHTML = ""; } }
//        on relance une tache si la liste n'est pas vide
          if (lpub != "") {
            TQtab=lpub.split("##$$##"); 
            TQnbr=TQtab.length; 
            TQcmt=-1;
            TQenc=true;
            TQpub=cpub;
            TQiid = setInterval("TQfunc()",4000); } }
        else {  
          if (dest == "alert") {
            alert(text); }
          else {
            if (dest == "ganalyt") {
//            var pageTracker = _gat._getTracker("UA-1086115-1"); 
//            pageTracker._initData(); 
//            pageTracker._trackPageview(text); 
            } 
            else {
              dhtmlHistory.add(text,("retour : "+text)); } } } }
      else { 
        pTab = document.getElementById(dest);
        if (pTab) pTab.innerHTML=text; else alert(dest); } } 

    if (document.body.className == 'debsablier') {
      document.body.className = 'finsablier';
      for (ifo = 0; ifo < document.searchform.length; ifo++) {
        document.searchform.elements[ifo].className = 'finsablier'; } } 
    return tab.length; }
//'
//' lecture d'une url en GET ===================================================
//'
  function geturl(url) {
    if(window.XMLHttpRequest) // FIREFOX
      xhr_object = new XMLHttpRequest(); 
    else if(window.ActiveXObject) // IE
      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
    else 
      return(false); 
    xhr_object.open("GET", url, false); 
    xhr_object.send(null); 

//' xhr_object.open("POST", tonurl, false);
//' xhr_object.setRequestHeader("Accept","text/xml");
//' xhr_object.setRequestHeader("Cache-Control","no-cache");
//' xhr_object.send("var1=toto&var2=titi&etc=...");

//' wpost="var1=toto&var2=titi&etc=...";
//' xhr_object.open('POST', url, false); //false : synchrone => attente resultat
//' xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//' xhr_object.setRequestHeader("Content-length", wpost.length);
//' xhr_object.setRequestHeader("Connection", "close");
//' xhr_object.send(wpost);

    if(xhr_object.readyState == 4) return(xhr_object.responseText);
    else return(false); }
//'
//' lecture d'une url en POST (avec ajout variables) ===========================
//'
  function posturl(url,nom) {
    var iget=false;
    if (nom.indexOf(":") != -1) {
      iget=true;
      nom=nom.substr(0,nom.indexOf(":")); }
    var wform=document.forms[nom];
    var wpost="";
    var wvalu="";
    var wsepa="";
    var oksai=false;
    for (var i=0; i<wform.length; i++) {
      wvalu="";
      oksai=false;
      if ((wform[i].type == "text") || (wform[i].type == "textarea") || (wform[i].type == "password") || (wform[i].type == "hidden")) { wvalu=wform[i].value; oksai=true; }  
      if ((wform[i].type == "radio") || (wform[i].type == "checkbox")) if (wform[i].checked == true) { wvalu=wform[i].value; oksai=true; }
      if (wform[i].type == "select-one") { wvalu=wform[i].options[wform[i].selectedIndex].value; oksai=true; }
      if (oksai) { wpost=wpost+wsepa+wform[i].name+"="+encodeURI(wvalu); wsepa="&"; } }

    if(window.XMLHttpRequest) // FIREFOX
      xhr_object = new XMLHttpRequest(); 
    else if(window.ActiveXObject) // IE
      xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
    else 
      return(false); 

    if (iget) {
      xhr_object.open("GET", (url+"&"+wpost), false); 
      xhr_object.send(null); }
    else {

//'   xhr_object.open("GET", url, false); 
//'   xhr_object.send(null); 

//'   xhr_object.open("POST", tonurl, false);
//'   xhr_object.setRequestHeader("Accept","text/xml");
//'   xhr_object.setRequestHeader("Cache-Control","no-cache");
//'   xhr_object.send("var1=toto&var2=titi&etc=...");

      xhr_object.open("POST", url, false); //false : synchrone => attente resultat
      xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xhr_object.setRequestHeader("Content-length", wpost.length);
      xhr_object.setRequestHeader("Connection", "close");
      xhr_object.send(wpost); }

    if(xhr_object.readyState == 4) return(xhr_object.responseText);
    else return(false); }
//'
//' vérification d'une url en POST (idem onsubmit) =============================
//'
  function postver(nom) {
    var vok=true;
    var wform=document.forms[nom];

    if (nom == "clientnew") {

//'   vérification globale : champs obligatoires
      if ((vok) && ((wform.SIT205.value.length == 0) || (wform.SIT206.value.length == 0) || (wform.SIT005.value.length == 0) || (wform.SIT007.value.length == 0) || (wform.SIT008.value.length == 0) || (wform.SIT203.value.length == 0) || (wform.SIT211.value.length == 0) || (wform.SIT212.value.length == 0))) {
        alert("saisir les champs obligatoires !!!");
        vok=false; }
      if ((vok) && ((wform.SIT201.value.length == 0) && (wform.SIT202.value.length == 0))) {
        alert("telephone fixe ou portable obligatoires !!!");
        vok=false; }

//'   vérification globale : cohérence des champs
      if ((vok) && (wform.SIT211.value != wform.SIT212.value)) {
        alert("le mot de passe est different de la confirmation  !!!");
        vok=false; }

//'   vérification globale : format des champs
      var reg =/^[a-z0-9]+([_\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\.[a-z]{2,}$/;
      if ((vok) && (!(reg.test(wform.SIT203.value)))) {
        alert("format incorrect : adresse email !!!");
        vok=false; }
        
//'   vérification globale : format des champs FRANCE
      var wpays=wform.SIT210.options[wform.SIT210.selectedIndex].value;
      if ((vok) && ((wpays == "FR") || (wpays == "057"))) {
        var reg0 =/^[0-9]{5}$/;
        var reg1 =/^[0-9]{10}$/;
        var reg2 =/^[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}$/;
        var reg3 =/^[0-9]{2}\ [0-9]{2}\ [0-9]{2}\ [0-9]{2}\ [0-9]{2}$/;
        if ((vok) && (wform.SIT007.value.length != 0) && (!(reg0.test(wform.SIT007.value)))) {
          alert("format incorrect : code postal !!!");
          vok=false; }
        if ((vok) && (wform.SIT201.value.length != 0) && (!(reg1.test(wform.SIT201.value))) && (!(reg2.test(wform.SIT201.value))) && (!(reg3.test(wform.SIT201.value)))) {
          alert("format incorrect : telephone fixe !!!");
          vok=false; }
        if ((vok) && (wform.SIT202.value.length != 0) && (!(reg1.test(wform.SIT202.value))) && (!(reg2.test(wform.SIT202.value))) && (!(reg3.test(wform.SIT202.value)))) {
          alert("format incorrect : telephone portable !!!");
          vok=false; } }

//'   particulier / société
      if (wform.typecli[0].checked) {
        tcli="P"; }
      else {
//'     vérification SOCIETE : champs obligatoires
        if ((vok) && ((wform.SIT207.value.length == 0) || (wform.SIT004.value.length == 0) || (wform.SIT047.value.length == 0) || (wform.SIT049.value.length == 0) || (wform.SIT143.value.length == 0))) {
          alert("saisir les champs obligatoires !!!");
          vok=false; } }

//'   if (wform.elements["SIT206"].value == "Bonnard") {
//'     alert("test");
//'     vok=false; }
      }
    return vok; }
//'
//' calcul +1 et -1 sur panier =================================================
//'
  function calcul(id, val) {
    quantite = document.forms["panier"].elements[id].value;
    quantite = 	parseInt(quantite) + parseInt(val);
    if (quantite < 1) { quantite = 1; }
    if (quantite > 999) { quantite = 999; }
    document.forms["panier"].elements[id].value = quantite; }
//'
//' affichage attente ==========================================================
//'
  function aff_wait() {
      pTab = document.getElementById("wait");
      if (pTab) pTab.innerHTML='<img src="/img/wait_blue_40.gif" width="40" height="40" alt="Attente ...">'; } 
//'
//' ============================================================================
//'

