/**
 * Fonctions sur les cartouches
 */
function appliquerChoixCartouche() {
	
	formulaire = document.getElementById("Boutique");
	
	constructeur_id = formulaire.cartouches_constructeurs.options[formulaire.cartouches_constructeurs.selectedIndex].value;
	cartouche_id = formulaire.cartouches_cartouches.options[formulaire.cartouches_cartouches.selectedIndex].value;
	categorie_id = formulaire.cartouches_categorie.options[formulaire.cartouches_categorie.selectedIndex].value;
	
	if (constructeur_id > 0 && cartouche_id > 0 && categorie_id > 0) {
	
		nom = formulaire.cartouches_cartouches.options[formulaire.cartouches_cartouches.selectedIndex].text;
		
		if (formulaire.cartouches_compatible.checked) {
			nom += " - compatible";
		}
		document.getElementById("recherche_categories").selectedIndex = lireIndex(document.getElementById("recherche_categories"), categorie_id);
		document.getElementById("recherche_constructeurs").selectedIndex = lireIndex(document.getElementById("recherche_constructeurs"), constructeur_id);
		document.getElementById("recherche_nom").value = nom;
		document.getElementById("id_categories").selectedIndex = lireIndex(document.getElementById("recherche_categories"), categorie_id);
		document.getElementById("id_constructeurs").selectedIndex = lireIndex(document.getElementById("recherche_constructeurs"), constructeur_id);
		document.getElementById("nom").value = nom;
		
		//document.getElementById("Boutique").submit();
	}
}


function chargerCategorieCartouche(resultat) {
	
	liste_select = document.getElementById("Boutique").cartouches_categorie;
	
	js = genererJson(resultat);

	if (js) {
		liste_select.options.length = js.data.length;
		for (i = 0; i < js.data.length; i++) {
			liste_select.options[i].value = js.data[i].id;
			liste_select.options[i].text = js.data[i].nom;
		}
	} else {
		viderSelect(liste_select);
	}
}


function chargerListeImprimantes(resultat) {
	
	liste_select = document.getElementById("Boutique").cartouches_imprimantes;
	
	js = genererJson(resultat);

	if (js) {
		liste_select.options.length = js.data.length + 1;
		liste_select.options[0].value = 0;
		liste_select.options[0].text = "choisir une imprimante";
		for (i = 0; i < js.data.length; i++) {
			index = i + 1;
			liste_select.options[index].value = js.data[i].id;
			liste_select.options[index].text = js.data[i].nom;
		}
	} else {
		viderSelect(liste_select);
	}
	liste_select.selectedIndex = 0;
	viderSelect(document.getElementById("Boutique").cartouches_cartouches);
	viderSelect(document.getElementById("Boutique").cartouches_imprimantes_verif);
	viderSelect(document.getElementById("Boutique").cartouches_categorie);
}


function chargerListeImprimantesParCartouche(resultat) {
	
	liste_select = document.getElementById("Boutique").cartouches_imprimantes_verif;
	
	js = genererJson(resultat);

	if (js) {
		liste_select.options.length = js.data.length;
		for (i = 0; i < js.data.length; i++) {
			liste_select.options[i].value = js.data[i].id;
			liste_select.options[i].text = js.data[i].nom;
		}
	} else {
		viderSelect(liste_select);
	}
	liste_select.selectedIndex = 0;
}


function chargerListeCartouches(resultat) {
	
	liste_select = document.getElementById("Boutique").cartouches_cartouches;
	
	js = genererJson(resultat);

	if (js) {
		liste_select.options.length = js.data.length + 1;
		liste_select.options[0].value = 0;
		liste_select.options[0].text = "choisir une cartouche";
		for (i = 0; i < js.data.length; i++) {
			index = i + 1;
			liste_select.options[index].value = js.data[i].id;
			liste_select.options[index].text = js.data[i].nom;
		}
	} else {
		viderSelect(liste_select);
	}
	liste_select.selectedIndex = 0;
	viderSelect(document.getElementById("Boutique").cartouches_imprimantes_verif);
	viderSelect(document.getElementById("Boutique").cartouches_categorie);
}


function selectionnerCartouche(url) {

	envoyerRequete("GET", url + "&action=cartouchesListerImprimantesParCartouche", "chargerListeImprimantesParCartouche", false, false);
	envoyerRequete("GET", url + "&action=cartouchesSelectionnerCategorie", "chargerCategorieCartouche", false, false);
}



