//<!--

//********************* POPUP ************************//
var newWin = null;

function closeWin()
{
  if (newWin != null)
  {
    if(!newWin.closed)
    {
      newWin.close();
    }
  }
}

function popUp(strURL,strType,strHeight,strWidth)
{
  closeWin();
  var strOptions="";
  if (strType=="console")
  {
    strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth;
  }
  if (strType=="fixed")
  {
    strOptions="status,height="+strHeight+",width="+strWidth;
  }
  if (strType=="elastic")
  {
    strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
  }
  newWin = window.open(strURL, 'newWin', strOptions);
  newWin.focus();
}
//********************* FIN POPUP ************************//

function addBookmark(title,url)
{
  if (window.sidebar)
  { 
    alert('Fermez cette fenêtre et cliquez sur Ctrl + D\nou\nallez dans "Marque-pages > marquer cette page"'); 
  }
  else if ( document.all )
  {
    window.external.AddFavorite( url, title);
  }
  else if ( window.opera && window.print )
  {
    return true;
  }

  return false;
}


function CloseAlert ()
{
  Effect.BlindDown('alert_div');
  
  setTimeout('Effect.BlindUp(\'alert_div\')', 5000);
}

function ViewTab1 ()
{
  Hide('desc2_text');
  Display('desc1_text');
  
  Hide('desc2_title_on');
  Display('desc2_title_off');
  
  Hide('desc1_title_off');
  Display('desc1_title_on');
}

function ViewTab2 ()
{
  Hide('desc1_text');
  Display('desc2_text');
  
  Hide('desc1_title_on');
  Display('desc1_title_off');
  
  Hide('desc2_title_off');
  Display('desc2_title_on');
}


function DisplayHide (id)
{ 
  if (document.getElementById(id).style.display == 'block')
  {
    document.getElementById(id).style.display = 'none';
  }
  else
  {
    document.getElementById(id).style.display = 'block';
  }
}

function Display_menu(id, back)
{
  
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])
  
  if ((version < 7) && (document.body.filters)) 
  {
    document.getElementById(id).style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop src='"+ FTP +"/img/back_menu_"+ back +".png')";
  }
  else
  {
    document.getElementById(id).style.backgroundImage="url("+ FTP +"/img/back_menu_"+ back +".png)";
  }
}

function xGetElementById(e)
{
  if(typeof(e)=='string')
  {
    if(document.getElementById)
    {
      e=document.getElementById(e);
    }
    else if(document.all)
    {
      e=document.all[e];
    }
    else
    {
      e=null;
    }
  }
  return e;
}


function Display (id)
{ document.getElementById(id).style.display = 'block'; }

function Hide (id)
{ document.getElementById(id).style.display = 'none'; }


function ajout (id, max)
{
  var idname = 'QTY_'+id;
  if (xGetElementById(idname))
  {
    // on force à être en entier... 
    var val=parseInt( xGetElementById(idname).value );
    if (isNaN(val)) { val=0; }
    val++;
    if (val > max)
    {
      alert ('La commande maximale est de '+max+'.');
      xGetElementById(idname).value = max;
      return false;
    }
    xGetElementById(idname).value = val;

    return true;
  }
  return false;
}

function enlev (id)
{
  var idname = 'QTY_'+id;
  if (xGetElementById(idname))
  {
    // on force à être en entier... 
    var val=parseInt( xGetElementById(idname).value );
    if (isNaN(val)) { val=0; }

    if (val == 0)
    {
      alert ('Déjà vide.');
      xGetElementById(idname).value = 0;
      return false;
    }

    xGetElementById(idname).value = val - 1;
    
    return true;
  }
  return false;
}

function vide (id)
{
  var idname = 'QTY_'+id;
  if (xGetElementById(idname))
  {
    // on force à être en entier... 
    var val=parseInt( xGetElementById(idname).value );
    if (isNaN(val)) { val=0; }

    if (val == 0)
    {
      alert ('Déjà vide.');
      xGetElementById(idname).value = 0;
      return false;
    }

    xGetElementById(idname).value = 0;
    
    return true;
  }
  return false;
}

function modif (id, max)
{
  var idname = 'QTY_'+id;
  if (xGetElementById(idname))
  {
    var val=parseInt( xGetElementById(idname).value );
    if (isNaN(val)) { val=0; }

    if ((val > max) || (val < 0))
    {
      alert ('La quantité doit être comprise entre 0 et '+max+'.');
      val = 0;
    }
    xGetElementById(idname).value = val;

    return true;
  }
  return false;
}


function hover(obj){
  if(document.all)
  {
    UL = obj.getElementsByTagName('ul');
    
    if(UL.length > 0)
    {
      sousMenu = UL[0].style;
      if(sousMenu.display == 'none' || sousMenu.display == '')
      {
        sousMenu.display = 'block';
        if(obj.className=="level1")
        {
        }
      }
      else
      {
        sousMenu.display = 'none';
        if(obj.className=="level1")
        {
        }
      }
    }
    else
    {
    }
  }
}

function setHover()
{
  LI = document.getElementById('menu').getElementsByTagName('li');
  nLI = LI.length;

  for(i=0; i < nLI; i++){
    LI[i].onmouseover = function()
    {
      //if (document.getElementById && document.getElementById('visite')) 
      //{
      //  document.getElementById('visite').style.display='none';
      //}
      hover(this);
    }
    LI[i].onmouseout = function()
    {
      hover(this);
      //if (document.getElementById && document.getElementById('visite'))
      //{
        //document.getElementById('visite').style.display='block';
      //}
    }
  }
}


////////////////////////////////////////////////////////////////
// http://java.sun.com/developer/technicalArticles/J2EE/AJAX/RealtimeValidation/
////////////////////////////////////////////////////////////////
function AJAXInteraction(url, callback, name, arg1, arg2, arg3) {

 var req = init();
 req.onreadystatechange = processRequest;

 function init() {
   if (window.XMLHttpRequest) {
     return new XMLHttpRequest();
   } else if (window.ActiveXObject) {
     return new ActiveXObject("Microsoft.XMLHTTP");
   }
 }

 function processRequest () {
   // readyState of 4 signifies request is complete
   if (req.readyState == 4) {
     // status of 200 signifies sucessful HTTP call
     if (req.status == 200) {
       // if (callback) callback(req.responseXML, name, arg1, arg2, arg3);
       if (callback) callback(req, name, arg1, arg2, arg3);
     }
   }
 }

 this.doGet = function() {
   // make a HTTP GET request to the URL asynchronously
   req.open("GET", url, true);
   req.send(null);
 }
}

function displayMessage( req, name, divid, email, elt )
{
  // Effacer un message d'attente ?

  if (divid)
  {
    //divid.innerHTML=email;
    //xGetElementById(divid).innerHTML=email;
    xGetElementById(divid).innerHTML="";
    //xGetElementById(divid).innerHTML="<img src=\"/gfm/10063/m/new/loading_small.gif\" alt=\"Chargement\" width=\"16\" height=\"16\" />";
  }
  if (elt) elt.value=email;

  if (req.responseText)
  {  
    if (req.responseText == 'ok')
    {
      //alert(req.responseText);
      xGetElementById('CHECK_EMAIL').innerHTML="<img src=\"/gfm/10063/m/new/valid_ok_16x16.png\" alt=\"\" width=\"16\" height=\"16\" />";
    }
    else if (req.responseText!='')
    {
      xGetElementById('CHECK_EMAIL').innerHTML="<img src=\"/gfm/10063/m/new/valid_bad_16x16.png\" alt=\"\" width=\"16\" height=\"16\" />";
      alert(req.responseText);
    }
  }
}

function searchEmail( elt, divid )
{
  if (!document.form.email.value.match(/^[a-z0-9&\'\.\-_\+]*@[a-z0-9]+([\.\-][a-z0-9]+)*\.[a-z]{2,}$/i))
  {
    alert ("Vous devez saisir une adresse email valide (prenom.nom@monemail.com)");
    return false;
  }
  
  if (document.form.email.value.match(/^www\./i))
  {
    alert ("Vous devez saisir une adresse email valide (prenom.nom@monemail.com)");
    return false;
  }
  
  
  
  if (!elt || elt.value=='')
  {
    alert("L'email doit être renseigné");
     return false;
  }

  var email=elt.value;

  // Prevoir un message d'attente ?
  if (divid)
  {
    //divid.innerHTML="Vérification email";
    //xGetElementById(divid).innerHTML="Vérification email";
    xGetElementById(divid).innerHTML="<img src=\"/gfm/10063/m/new/loading_small.gif\" alt=\"Chargement\" width=\"16\" height=\"16\" />";
  }
  else elt.value="Vérification email";


  // Format rewriting
  var url='';
   url+='/Contactez-nous/p/5/0/0/ACCOUNT=CREATE/AJAX=1';
   url+='/CHECK_EMAIL_AVAILABLE=' + encodeURIComponent( email );

  var ajax=new AJAXInteraction(url, displayMessage, 'email', divid, email, elt);
  ajax.doGet();
}


//-->
