var ajax = new sack();

function eBoutique_addItem(sCodeTitan) {

  var oAttente = document.getElementById('eBoutique_attente');
  oAttente.style.display = 'block';

  ajax.requestFile = 'eBoutique.php';
  ajax.URLString = '&m=ajax&action=addItem&item='+sCodeTitan;
  ajax.onCompletion = eBoutique_updateItems;

  ajax.runAJAX();
  
}//End function

function eBoutique_addItemPopUp(sCodeTitan) {
  
  var oAttente = parent.mainFrame.document.getElementById('eBoutique_attentePopup');
  oAttente.style.display = 'block';
  
  ajax.requestFile = '../eBoutique.php';
  ajax.URLString = '&m=ajax&action=addItem&item='+sCodeTitan;
  ajax.onCompletion = eBoutique_updateItemsPopup;
 
  ajax.runAJAX();
  
}//End function

function eBoutique_updateItems() {

	var oElem = document.getElementById('nbProducts');
	
	var sRegExp = new RegExp('^[0-9]+$');

	if( sRegExp.test(ajax.response) ) {	// Si on a un entier c'est que tout c'est bien passé

		if(oElem != null) {
			oElem.innerHTML = ajax.response;
		}//End if
		
		alert("L'ajout a été enregistré. Votre panier contient maintenant "+ajax.response+" produit(s).");
		
	}//End if
	else {	// On a eu une erreur
		alert( 'Erreur : '+ajax.response );	
	}//End else	
	
	if(oElem != null) {
	    var oAttente = document.getElementById('eBoutique_attente');
		oAttente.style.display = 'none';
	}//End if
	else {
		var oAttente = parent.mainFrame.document.getElementById('eBoutique_attentePopup');
		oAttente.style.display = 'none';
	}//End else
	

}//End function

function eBoutique_updateItemsPopup() {

	var sRegExp = new RegExp('^[0-9]+$');
	
	if( sRegExp.test(ajax.response) ) {	// Si on a un entier c'est que tout c'est bien passé
	
		var oElem = window.parent.opener.document.getElementById('nbProducts');
		oElem.innerHTML = ajax.response;

		alert("L'ajout a été enregistré. Votre panier contient maintenant "+ajax.response+" produit(s).");
		
	}//End if
	else {
		alert( 'Erreur : '+ajax.response );
	}//End else
		
	var oAttente = parent.mainFrame.document.getElementById('eBoutique_attentePopup');
	oAttente.style.display = 'none';
	

}//End function

