// ============= AJOUT DANS LE PANIER =============
function httpAjoutPanier(ID) {
	if (ID > 0){
	    	var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/catalogue/http-panier.asp?traitement=ajout&idiv=ipanier", true);
	        
	        xhr_object.onreadystatechange = function() {	        
	        if(xhr_object.readyState == 4)
	        	if ( xhr_object.status == 200 ) {
		        	//self.alert(xhr_object.responseText);
		        	//changeElementText('ipanier', xhr_object.responseText)
		        	LoadPanierXml(xhr_object.responseText);
		        	}
	        	}	        		        	
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "ID_PRODUIT="+ID;	
	        xhr_object.send(data);	       
	}
	else{
	changeElementText(icommander, 'Ce produit n\'est pas disponible pour le moment.')
	
	}
}

// ============= LECTURE DU PANIER =============
function MonPanier() {
	    	var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/catalogue/http-panier.asp?traitement=lecture&idiv=ipanier", true);
	        
	        xhr_object.onreadystatechange = function() {	        
	        if(xhr_object.readyState == 4)
	        	if ( xhr_object.status == 200 ) {
		        	//self.alert(xhr_object.responseText);
		        	//changeElementText('ipanier', xhr_object.responseText)
		        	LoadPanierXml(xhr_object.responseText);		
		        	}
	        	}	        		        	
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "ID_PRODUIT=0";	
	        xhr_object.send(data);		              	
}

// ============= CHARGEMENT DU XML / XSL PANIER =============
function LoadPanierXml_flux_xml(xml){
var panier = "";
	if (xml!="") {	
	    	var xml_doc = new ActiveXObject("Microsoft.XMLDOM"); 
		xml_doc.async = false; 
		xml_doc.loadXML(xml);
		
		if (xml_doc.parseError != 0){
	    		document.write("xml:"+xml_doc.url + " : " + xml_doc.parseError.reason);
	    	}
	    	else {
			var xsldoc = new ActiveXObject("Microsoft.XMLDOM"); 
			xsldoc.async = false; 
			xsldoc.load("panier.xsl");
			if (xsldoc.parseError != 0){
				document.write("xsl:"+xsldoc.parseError.reason);
			}
			else{
				panier = xml_doc.transformNode(xsldoc);			
			}			
		}
	}
	else
	{
		panier ="<p align=center><table width=100% border=0 cellspacing=0 cellpadding=2><tr><td align=center bgcolor=#FAF7E5 class=txtnoir>- Votre panier est vide -</td></tr></table></p>";				
				
	}
	changeElementText('ipanier', panier);	
	suppPaginationPanier();
	httpRefreshPanier();			
}   

// ============= CHARGEMENT DU XML / XSL PANIER =============
function LoadPanierXml(xml){
var panier = "";
	if (xml!="") {	
		//self.alert(xml);
	    	panier = xml;			
		
	}
	else
	{
		panier ="<p align=center><table width=100% border=0 cellspacing=0 cellpadding=2><tr><td align=center bgcolor=#FAF7E5 class=txtnoir>- Votre panier est vide -</td></tr></table></p>";				
				
	}
	changeElementText('ipanier', panier);	
	suppPaginationPanier();
	httpRefreshPanier();			
}  

// ============= SUPP LAYER PAGINATION =========

function suppPaginationPanier() {
	if (document.getElementById && document.getElementById('ipagination') !=  null) {
		changeElementText('ipagination', '');
	}
}

// ============= REFRESH DU PANIER =============
function httpRefreshPanier() {

	var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/catalogue/http-panier.asp?idiv=panier&traitement=refresh", true);
	        xhr_object.onreadystatechange = function() {
	        if(xhr_object.readyState == 4)
	        	eval(xhr_object.responseText);
	        	}
	        	
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "req=";	
	        xhr_object.send(data);	       	
}


// ============= MAJ PANIER =============
function HttpMajPanier(ID_PRODUIT, ID_PACKAGE, QTE, position) {
//self.alert(ID_PRODUIT);
//self.alert(ID_PACKAGE);
//self.alert(QTE);
//self.alert(position);

var rep=0;

if (QTE == 0) {
	rep=confirm("Etes-vous sûr de vouloir supprimer ce produit de votre panier ?"); 	
 	}
 else	{rep=1;}

if (rep==1){
	var xhr_object = null;
            	if(window.XMLHttpRequest) // Firefox
              		xhr_object = new XMLHttpRequest();
            	else if(window.ActiveXObject) // Internet Explorer
			xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
            	else { // XMLHttpRequest non supporté par le navigateur
              		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
              		return;
        	}
		xhr_object.open("POST", "/catalogue/http-panier.asp?idiv=panier&traitement=maj", true);
	        xhr_object.onreadystatechange = function() {	        
	        if(xhr_object.readyState == 4)
	        	if ( xhr_object.status == 200 ) {
		        	//self.alert(xhr_object.responseText);
		        	LoadPanierXml(xhr_object.responseText);
		        	}
	        	}	
	        	
		xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	        var data = "ID_PRODUIT="+ID_PRODUIT+"&ID_PACKAGE="+ID_PACKAGE+"&QTE="+QTE+"&position="+position;
	        xhr_object.send(data);	     	        
	}	        	  	
}

function CommanderPanier(f){
	f.submit();
}

function changeElementText(id, newText) 
{
    element = document.getElementById(id);
    element.innerHTML = newText;
}
