
function getHTTPObject() // Function pour créer l'objet xmlhttprequest //
     {
         var xmlhttp=false;
         try
         {
               xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e)
         {
             try
             {
                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
             }
             catch (e)
             {
                 xmlhttp = false;
             }
         }
         
         if (!xmlhttp && typeof XMLHttpRequest != "undefined")
         {
             xmlhttp = new XMLHttpRequest();
         }
         return xmlhttp;
     }
//fonction permettant de vider le cache
// résolvant un bug sous IE
function vider_cache(xmlhttp){
  var xmlhttp = xmlhttp;
  xmlhttp.setRequestHeader("Pragma","no-cache");
  //xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}

// Fonction vérifier si entier
 function is_int(variable)
 {
 var exp = new RegExp('^[0-9-.]+$','g');
 return exp.test(variable);
 } 

function unset(array, valueOrIndex){
	var output=[];
	for(var i in array){
		if (i!=valueOrIndex)
			output[i]=array[i];
	}
	return output;
}


function panier_simple(ref,action,lang) {
    var xmlhttp = getHTTPObject();
    var element1 = document.getElementById('panier_simple');
    element1.innerHTML = "load...";
    xmlhttp.open("GET", 'calcul_panier.php?ref='+ref+'&page=panier_simple&action='+action);
    vider_cache(xmlhttp);
    xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
           element1.innerHTML = xmlhttp.responseText;
           }
       }
	   if ((lang=="FR")&(action!='AFFICHE')){alert('Produit réf. '+ref+' ajouté au panier');}
	   if ((lang=="EN")&(action!='AFFICHE')){alert('Product ref. '+ref+' added to cart');}
     
	 xmlhttp.send(null);
}

function deroule(ref,action) {
    var xmlhttp = getHTTPObject();
    var element1 = document.getElementById('principal');
    element1.innerHTML = "load...";
    xmlhttp.open("GET", 'detail_produit.php?ref='+ref+'&action='+action);
    vider_cache(xmlhttp);
    xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
           element1.innerHTML = xmlhttp.responseText;
           }
       }
     xmlhttp.send(null);
}

function menu_categorie(id) {
    var xmlhttp = getHTTPObject();
    var element1 = document.getElementById('menu_cat');
    element1.innerHTML = "load...";
    xmlhttp.open("GET", 'menu_cat.php?id_parent='+id);
    vider_cache(xmlhttp);
    xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
           element1.innerHTML = xmlhttp.responseText;
           }
       }
     xmlhttp.send(null);
}

function menu_categorie_cache() {
    var xmlhttp = getHTTPObject();
    var element1 = document.getElementById('menu_cat');
    element1.innerHTML = "";
    //xmlhttp.open("GET", 'menu_cat.php?id_parent='+id);
   // vider_cache(xmlhttp);
   /* xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
           element1.innerHTML = xmlhttp.responseText;
           }
       }
     xmlhttp.send(null);
	 */
}



function commander_cb(type_paiement){
	 var xmlhttp = getHTTPObject();
    var element1 = document.getElementById('div_com_cb');
   // element1.innerHTML = "load...";
    xmlhttp.open("GET", 'ajax_commander.php?type_paiement='+type_paiement);
    vider_cache(xmlhttp);
    xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
           element1.innerHTML = xmlhttp.responseText;
		    document.form_cb.submit();
           }
       }
	  
     xmlhttp.send(null);
	
}

function commander_pa(type_paiement){
	 var xmlhttp = getHTTPObject();
    var element1 = document.getElementById('div_com_pa');
   // element1.innerHTML = "load...";
    xmlhttp.open("GET", 'ajax_commander.php?type_paiement='+type_paiement);
    vider_cache(xmlhttp);
    xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
           element1.innerHTML = xmlhttp.responseText;
		    document.form_pa.submit();
           }
       }
	  
     xmlhttp.send(null);
	
}


function generer_pdf_commande(ref){
	 var xmlhttp = getHTTPObject();
   // var element1 = document.getElementById('div_com_cheque');
   // element1.innerHTML = "load...";
    xmlhttp.open("GET", 'admin/admin_pdf_commande.php?COM_REF=100805-102812-1');
    vider_cache(xmlhttp);
    xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
           //element1.innerHTML = xmlhttp.responseText;
		    //document.form_cheque.submit();
			alert(xmlhttp.responseText)
           }
       }
	  
     xmlhttp.send(null);
	
}




	 