/*
	Permet d'ajouter un item au Panier
*/
function addItem(typeP,typeF,codeF,langueF)
{
	//alert('type = ' + typeP + ', objet = ' + typeF + ', code = ' + codeF + ', langue = '+langueF);
  var url = '/servlet/com.kosmos.panier.processus.TraitementPanier';
  
  var myAjax = new Ajax.Request(url,
    {
      method: 'get',
      asynchronous: true,
      parameters: {ACTION: 'AJOUTER',
                   TYPE_PANIER: typeP,
                   TYPE_FICHE: typeF,
				   CODE_FICHE: codeF,
				   LANGUE_FICHE: langueF},
        onUninitialized: function (xhr)
          { // Création de l'objet XHR
           //alert('onUninitialized');
          },
        onLoading: function (xhr)
          { // Après appel méthode open
            //alert('onLoading');
          },
        onLoaded: function (xhr)
          { // Requête envoyée
            //alert('onLoaded');
          },
        onInteractive: function (xhr)
          { // Réponse en cours de réception
            //alert('onInteractive');
          },
        on200: function (xhr)
          { // Réponse HTTP "OK"
            //alert('on200');
          },
        onSuccess: function (xhr)
          { // Réponse HTTP == 2xx
            //alert('onSuccess');
          },
        on404: function (xhr)
          { // Réponse HTTP "OK"
            //alert('on404');
          },
        onFailure: function (xhr)
          { // Réponse HTTP != 2xx
            //alert('onFailure');
          },
        onException: function (xhr, exception)
          {
            alert(exception);
          },
        onComplete: function (xhr)
          { // Requête totalement terminée
            if (xhr.status == 200)
            {
				eval(xhr.responseText);
            } else {
              //alert(xhr.status);
            }
          }
    }
  )
}

  /*
	Permet d'ajouter un item au Panier
*/
function deleteItem(typeP, idFP, isQte)
{
  var url = '/servlet/com.kosmos.panier.processus.TraitementPanier';
  
  var myAjax = new Ajax.Request(url,
    {
      method: 'get',
      asynchronous: true,
      parameters: {ACTION: 'SUPPRIMER',
				   TYPE_PANIER: typeP,
                   ID_FICHEPANIER: idFP,
				   IS_QTE: isQte},
        onUninitialized: function (xhr)
          { // Création de l'objet XHR
           //alert('onUninitialized');
          },
        onLoading: function (xhr)
          { // Après appel méthode open
            //alert('onLoading');
          },
        onLoaded: function (xhr)
          { // Requête envoyée
            //alert('onLoaded');
          },
        onInteractive: function (xhr)
          { // Réponse en cours de réception
            //alert('onInteractive');
          },
        on200: function (xhr)
          { // Réponse HTTP "OK"
            //alert('on200');
          },
        onSuccess: function (xhr)
          { // Réponse HTTP == 2xx
            //alert('onSuccess');
          },
        on404: function (xhr)
          { // Réponse HTTP "OK"
            //alert('on404');
          },
        onFailure: function (xhr)
          { // Réponse HTTP != 2xx
            //alert('onFailure');
          },
        onException: function (xhr, exception)
          {
            alert(exception);
          },
        onComplete: function (xhr)
          { // Requête totalement terminée
            if (xhr.status == 200)
            {
				eval(xhr.responseText);
            } else {
              //alert(xhr.status);
            }
          }
    }
  )
}

/*
	Ajouter un item à la liste
*/
function updateAjouter(typePanier, idFichePanier, titreFichePanier, urlFiche, nbItems, isQuantified, codeFiche) {
	
	if ( document.getElementById('nb_items') )	{
		document.getElementById('nb_items').innerHTML = ''+nbItems+'';
	}
}

/*
	Ajouter un item existant (augmenter la quantite)
*/
function updateQuantite ( codeFiche , quantite, typePanier, nbItems ) { }


/*
	Supprimer un item de la liste
*/
function updateSupprimer(typePanier, idFichePanier, nbItems) {

	if ( document.getElementById('liste_'+typePanier) ) {
		
		var ul = document.getElementById('liste_'+typePanier);
		var li = document.getElementById(idFichePanier+'_'+typePanier);
		
		ul.removeChild(li);
	}
	
	if (ul.getElementsByTagName('li').length == 0)
	{
		document.getElementById('liste_vide').style.display='block';
		document.getElementById('selection_nc').style.display = 'none';
	}
	
	if ( document.getElementById('nb_items') )	{
		document.getElementById('nb_items').innerHTML = ''+nbItems+'';
	}
}


/*
	Gérer les message d'erreur
*/
function updateErreur (codeErreur, msgErreur, typePanier) { }