function urlencode(str) {
//       str = escape(str);
//       str = str.replace('+', '%2B');
//       str = str.replace('%20', '+');
//       str = str.replace('*', '%2A');
//       str = str.replace('/', '%2F');
//       str = str.replace('@', '%40');
      str = encodeURIComponent(str);   
      return str;
}

function SelectAll(id) {
    top.document.getElementById(id).focus();
    top.document.getElementById(id).select();
}

function login() {

        var xhr; 
        try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
        catch (e) 
        {
            try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
            catch (e2) 
            {
              try {  xhr = new XMLHttpRequest();     }
              catch (e3) {  xhr = false;   }
            }
         }
      
        xhr.onreadystatechange  = function()
        { 
             if(xhr.readyState  == 4)
             {
                  if(xhr.status  == 200) 
                      eval(xhr.responseText);
             }
        }; 
    
    	var data="";
    	data+="&idt_log="+urlencode(top.document.getElementById('idt_log').value);
    	data+="&idt_mdp="+urlencode(top.document.getElementById('idt_mdp').value);
    	data+="&LNG="+top.document.getElementById('idt_LNG').value;
    	
    // alert(data);
    
    	xhr.open("POST", "ajax/login.php", true); 
    	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
    	xhr.send(data);
}

function forgottenPassword(text,title) {

      jPrompt(text, '', title, function(r) {
          if( r ) {
                var xhr; 
                try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
                catch (e) 
                {
                    try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
                    catch (e2) 
                    {
                      try {  xhr = new XMLHttpRequest();     }
                      catch (e3) {  xhr = false;   }
                    }
                 }
              
                xhr.onreadystatechange  = function()
                { 
                     if(xhr.readyState  == 4)
                     {
                          if(xhr.status  == 200) 
                              eval(xhr.responseText);
                     }
                }; 
            
            	var data="";
            	data+="&email="+urlencode(r);
            
            	xhr.open("POST", "ajax/mot_de_passe_oublie.php", true); 
            	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
            	xhr.send(data);          

          }
      });  
}
function del2basket(idProduit,idConditionnement,idCouleur,quantite,lng) {

      jConfirm('Etes vous certain devouloir supprimer ce produit de votre panier ?', 'Suppression d\'un article du panier', function(r) {
          if (r===true) {
                  var xhr; 
                  try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
                  catch (e) 
                  {
                      try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
                      catch (e2) 
                      {
                        try {  xhr = new XMLHttpRequest();     }
                        catch (e3) {  xhr = false;   }
                      }
                   }
                
                  xhr.onreadystatechange  = function()
                  { 
                       if(xhr.readyState  == 4)
                       {
                            if(xhr.status  == 200) 
                                eval(xhr.responseText); 
                       }
                  }; 
              
                	var data="";
    	            data+="&idProduit="+idProduit;
    	            data+="&idConditionnement="+idConditionnement;
    	            data+="&idCouleur="+idCouleur;
    	            data+="&quantite="+quantite;
    	            data+="&LNG="+lng;

    	            xhr.open("POST", "ajax/del2basket.php", true); 
    	            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
    	            xhr.send(data);
          }
      });
}

// Fonction pour ouvrir et fermer la boite perso
function ouvrirBoitePerso() {
	$("#boitePerso").slideDown();
	$("#lienBoitePerso").html('<a href="#" onclick="fermerBoitePerso(); return false;" style="text-decoration:underline;">[R&eacute;duire ma composition]</a>');
}
function fermerBoitePerso() {
	$("#boitePerso").slideUp();
	$("#lienBoitePerso").html('<a href="#" onclick="ouvrirBoitePerso(); return false;" style="text-decoration:underline;">[Voir ma composition]</a>');
}
