// Appel AJAX : Affiche la liste des produits
function getProduits(asLien,aiCompId,asTitre) {
	var xhr_object = createXMLHttpRequest();
	var url = reverse_path+"service_project/ajax/index.php?component=produit&action=liste&ajax=1&comp_id="+aiCompId+asLien;
	xhr_object.open("GET",url,true);
	xhr_object.onreadystatechange=onreadystatechange = function(){
		if ( xhr_object.readyState == 4 && xhr_object.status == 200 ) {
			if ( asTitre != '' ) {
				document.title=asTitre;
			}
			setAndExecute('produit_liste',xhr_object.responseText);
		}
	}
	xhr_object.send(null);
}

// Appel AJAX : Ajout un produit aux favoris de l'utilisateur courant
function gererProduitFavori(asProduitId) {
	var xhr_object = createXMLHttpRequest();
	var url = reverse_path+"service_project/ajax/index.php?component=produit&action=gerer_favori&produit_id="+asProduitId;
	xhr_object.open("GET",url,true);
	xhr_object.onreadystatechange=onreadystatechange = function(){
		if ( xhr_object.readyState == 4 && xhr_object.status == 200 ) {
		lsResponse = xhr_object.responseText;
			if ( lsResponse == 'ok' ) {
				var a = $(".favori"+asProduitId).children("a");
				a.hasClass('off') ? a.removeClass('off').addClass('on') : a.addClass('off').removeClass('on');
			}
		}
	}
	xhr_object.send(null);
}

// Appel AJAX : Affichage des avis d'un produit + formulaire
function getProduitAvis(asProduitId,abValid,aiCompId,aiMpFirst,aiProduitAvisNote,asProduitAvisPseudo,asProduitAvisTexte) {
	var xhr_object = createXMLHttpRequest();
	var url = reverse_path+"service_project/ajax/index.php?component=produit&action=liste_avis&valid="+abValid+"&comp_id="+aiCompId+"&mpfirst_avis="+aiMpFirst;
	xhr_object.onreadystatechange=onreadystatechange = function(){
		if ( xhr_object.readyState == 4 && xhr_object.status == 200 ) {
			setAndExecute('insertPopin',xhr_object.responseText);
		}
	}
	xhr_object.open("POST",url,true);
	// ne pas oublier ça pour le post, sinon les données dans SEND ne partent pas...
	xhr_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr_object.send("produit_id="+asProduitId+"&produit_avis_note="+aiProduitAvisNote+"&produit_avis_pseudo="+asProduitAvisPseudo+"&produit_avis_texte="+asProduitAvisTexte);
}
