/**************************************************************/
/*
/* Fonction de génération de l'objet XMLHttpRequest pour AJAX
/*
/**************************************************************/
function getXMLHTTPext(){
	var xhr=null;
	if(window.XMLHttpRequest){ // Firefox et autres
		xhr = new XMLHttpRequest();
		
	}else if(window.ActiveXObject){ // Internet Explorer
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e1) {
				xhr = null;
			}
		}
	}
	else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	}
	return xhr;
}

function getBrands(brandID, lang, ref) {
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetBrands.jsp?brandID=" + brandID + "&lang=" + lang, true);	
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {
				document.getElementById("op-marque").innerHTML = _xmlHttp.responseText;
				if (document.getElementById("sel-marque")) {//Utilisateur connecte
					getUnivers(document.getElementById("sel-marque").value , '', lang, ref);					
				}
				else {
					document.getElementById("op-marque").innerHTML = "";
					document.getElementById("op-univers").innerHTML = "";
					document.getElementById("op-famille").innerHTML = "";
					document.getElementById("op-ssfamille").innerHTML = "";
					document.getElementById("produits").innerHTML = "";
				}
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
			
	}
}
function getUnivers(brandID, universID, lang, ref) {
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && lang ){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetUnivers.jsp?brandID="+brandID + "&universID=" + universID + "&lang=" + lang , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				document.getElementById("op-univers").innerHTML = _xmlHttp.responseText;	
				getFamilles(brandID ,document.getElementById("sel-univers").value, '', lang, ref);
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}
function getFamilles(brandID, universID, famID, lang, ref) {
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && lang ){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetFamilles.jsp?brandID=" + brandID + "&universID="+universID + "&famID=" + famID + "&lang=" + lang , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				document.getElementById("op-famille").innerHTML = _xmlHttp.responseText;
				getSSFamilles(brandID ,universID, document.getElementById("sel-famille").value, '', lang, ref);	
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);			
	}
}
function getSSFamilles(brandID, universID, famID, ssfamID, lang, ref) {
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && lang ){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetSSFamilles.jsp?brandID=" + brandID + "&universID="+universID + "&famID=" + famID + "&ssfamID=" + ssfamID + "&lang=" + lang , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				document.getElementById("op-ssfamille").innerHTML = _xmlHttp.responseText;
				getProduits(brandID, universID, famID, '', lang, 0, ref);
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);
	}
	
}
function getProduits(brandID, universID, famID, ssfamID, lang, offset, ref) {
        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();


	if(_xmlHttp && lang){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetProduits.jsp?ref="+ ref +"&brandID="+ brandID + "&universID="+universID + "&famID=" + famID + "&ssfamID=" + ssfamID + "&lang=" + lang + "&offset=" + offset , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {								
				document.getElementById("produits").innerHTML = _xmlHttp.responseText;				
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);		
	}
}

function getProduitsPM(PM, lang) {
        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();

	if(_xmlHttp && PM && lang){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetProduitsPM.jsp?PM="+PM + "&lang=" + lang, true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				document.getElementById("srcPM").innerHTML = _xmlHttp.responseText;					
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);		
	}
}

function ajoutPanier(ident, qt, lang) {
        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && ident && qt){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxAjoutPanier.jsp?ident="+ident + "&qt=" + qt, true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				getSimplePanier(lang);					
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);
	
	}
}

function getSimplePanier(lang) {
        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && lang){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetPanier.jsp?mode=simple&lang=" + lang , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				document.getElementById("lienpanier").innerHTML = _xmlHttp.responseText;					
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);
	
	}
}

function getDetailPanier(lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && lang){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxCheckSession.jsp", true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				if (_xmlHttp.responseText.indexOf("false")!=-1) {
					document.location.href="/espace-pro.htm";
				}	
				else {
					displayDetailPanier(lang);
				}				
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}	
}

function displayDetailPanier(lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp) {
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetPanier.jsp?mode=detail&lang=" + lang ,true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {	
				document.getElementById("panier").innerHTML = _xmlHttp.responseText;			
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}


function getValidationPanier(lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && lang){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxCheckSession.jsp", true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				if (_xmlHttp.responseText.indexOf("false")!=-1) {
					document.location.href="/espace-pro.htm";
				}	
				else {
					displayValidationPanier(lang);
				}				
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}	
}

function displayValidationPanier(lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && lang){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetPanier.jsp?mode=validation&lang=" + lang , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {			
				document.getElementById("panierv").innerHTML = _xmlHttp.responseText;				
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}

function setPM(refpm, lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();

	if(_xmlHttp && lang && refpm){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetPanier.jsp?mode=validation&refpm=" + refpm +"&lang=" + lang , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				document.getElementById("panierv").innerHTML = _xmlHttp.responseText;					
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}

function suppPanier(ident, lang) {
        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();

	if(_xmlHttp && ident){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxSuppPanier.jsp?ident="+ident, true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				getSimplePanier(lang);
				getDetailPanier(lang);				
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);
	
	}
}

function recalculer(lang) {
  var x=document.getElementById("formpanier");
  var qs="";
  var c = 0;
  for (var i=0;i<x.length;i++)
  {
  	if (x.elements[i].name.indexOf("QT#",0)!=-1) {
  	  if (c!=0)
	    qs+="&";		 
	  qs+=x.elements[i].name.substring(3,x.elements[i].name.length) + "=" + x.elements[i].value;
	  c++;
	}
	else if (x.elements[i].name=="QT" || x.elements[i].name=="REF"){
	  if (c!=0)
	    qs+="&";		 
	  qs+=x.elements[i].name + "=" + x.elements[i].value;  
	}
  }

  var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort();
  }
  _xmlHttp=getXMLHTTPext();

  if(_xmlHttp){
    //appel à l'url distante
    _xmlHttp.open("POST","/specific/formats/remises/ajaxMajPanier.jsp?"+qs, true);			
    _xmlHttp.onreadystatechange=function() {			
	if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {	
		getDetailPanier(lang);					
		getSimplePanier(lang);			
	}				
    };
    // envoi de la requete
    _xmlHttp.send(null);

  }
}

function ajaxLogin(ident, password, lang) {
  
  var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort();
  }
  _xmlHttp=getXMLHTTPext();

  if(_xmlHttp && ident && password){
    //appel à l'url distante
	_xmlHttp.open("POST","/specific/formats/remises/ajaxLogin.jsp?lang="+lang+"&ident="+ident+"&password="+password, true);			
    	_xmlHttp.onreadystatechange=function() {			
	if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {	
		document.getElementById("identification").innerHTML = _xmlHttp.responseText;
		if (document.getElementById("panier"))	
			getDetailPanier(lang);
		if (document.getElementById("produits")) {
			getBrands(null, lang);	
		}
		getSimplePanier(lang);							
	}				
    };
    // envoi de la requete
    _xmlHttp.send(null);

  }
}

function ajaxLogout(lang) {
  
  var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort();
  }
  _xmlHttp=getXMLHTTPext();

  if(_xmlHttp){
    //appel à l'url distante
    _xmlHttp.open("POST","/specific/formats/remises/ajaxLogin.jsp?logout=true&lang="+lang, true);			
    _xmlHttp.onreadystatechange=function() {			
	if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {	
		document.getElementById("identification").innerHTML = _xmlHttp.responseText;
		if (document.getElementById("panier"))	
			getDetailPanier(lang);
		if (document.getElementById("panierv"))	
			getValidationPanier(lang);
		if (document.getElementById("produits"))
			getBrands(null, lang);	
		getSimplePanier(lang);							
	}				
    };
    // envoi de la requete
    _xmlHttp.send(null);

  }
}

function ajaxDisplayUser(lang) {
  
  var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort();
  }
  _xmlHttp=getXMLHTTPext();

  if(_xmlHttp){
    //appel à l'url distante
    _xmlHttp.open("POST","/specific/formats/remises/ajaxLogin.jsp?lang="+lang, true);			
    _xmlHttp.onreadystatechange=function() {			
	if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {	
		document.getElementById("identification").innerHTML = _xmlHttp.responseText;			
	}				
    };
    // envoi de la requete
    _xmlHttp.send(null);

  }
}

function getHeader(lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();

	if(_xmlHttp && lang){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxGetHeader.jsp?lang=" + lang , true);			
		_xmlHttp.onreadystatechange=function() {			
			if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				document.getElementById("headerv").innerHTML = _xmlHttp.responseText;					
			}				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}

function enregisterPanier(type) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxEnregisterPanier.jsp?type=" + type , true);			
		_xmlHttp.onreadystatechange=function() {			
			/*if(_xmlHttp.readyState==4 && _xmlHttp.status == 200) {					
				
			}*/				
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}

function chargerPanier(type, lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxChargerPanier.jsp?type=" + type , true);			
		_xmlHttp.onreadystatechange=function() {						
			if (document.getElementById("panier"))	
				getDetailPanier(lang);
			if (document.getElementById("produits")) {
				getBrands(null, lang);	
			}
			document.location.href='/panier.htm';		
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}

function setCodePromo(code, lang) {        
	var _xmlHttp = null; //l'objet xmlHttpRequest utilisé pour contacter le serveur
	if(_xmlHttp&&_xmlHttp.readyState!=0){
		_xmlHttp.abort();
	}
	_xmlHttp=getXMLHTTPext();
	if(_xmlHttp && code){
		//appel à l'url distante
		_xmlHttp.open("POST","/specific/formats/remises/ajaxSetCodePromo.jsp?code=" + code , true);			
		_xmlHttp.onreadystatechange=function() {						
			if (document.getElementById("panier")) {	
				getDetailPanier(lang);
				getSimplePanier(lang);
			}
			else if (document.getElementById("produits")) {
				getSimplePanier(lang);
				getBrands(null, lang);
			}
			else document.location.href='/espace-pro.htm';
		};
		// envoi de la requete
		_xmlHttp.send(null);	
	}
}
function submitButton(e, button)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	   {
	   document.getElementById(button).click();
	   return false;
	   }
	else
	   return true;
}

