window.addEvent('domready',function(){
	//fermeture des blocs sauf "paramètres de vente"
	$$('.entete-bloc a').each(function(item){
		bloc = $$('.contenu-bloc');
		var id = item.get('id');
		if(id!=0) new Fx.Reveal(bloc[id]).dissolve();
	});

	//slide des blocs de droite
	$$('.entete-bloc a').each(function(item){
		item.addEvent('click', function(e){
			e = new Event(e).stop();
			var id = item.get('id');
			bloc = $$('.contenu-bloc');
			new Fx.Reveal(bloc[id]).toggle();
		});
	});
});

//gestion des cases à cocher pour traitement par lot
function CheckAll(nb_check) {
	coche = 0;
	if(document.getElementById("checkall").checked == false) {
		coche = 1;
	}
	for (i = 0; i < nb_check; i++) {
		if(coche==0) {
			var modif = "checkbox["+i+"]";
			document.getElementById(modif).checked = true;
		}
	}
	for (i = 0; i < nb_check; i++) {
		if(coche==1) {
			var modif = "checkbox["+i+"]";
			document.getElementById(modif).checked = false;
		}
	}
}


function popup_publication(id_produit,type_publication,langue) {
	new Fupdate.AjaxPrompt('popup_publication.php?id_article='+id_produit+'&type_publication='+type_publication+'&langue='+langue,'',{
		stickyWinUiOptions : {
			width: 800,
			waiterTarget: $('frame_publication')
		}
	}).prompt();
}

function affiche_contenu_cat(id_cat,id_produit) {
	var ajax_request = new Request.HTML({
		url: '../inc/ajax/ajax.boutique.php',
		update: $('bloc-tag'),
		useWaiter: true,
		waiterOptions: {
		  baseHref: '../admin/images/pictos/',
		  img: {
			src: 'preloader-horizontal.gif',
			styles: {
			  width: 160,
			  height: 20
			}
		  },
		  layer: {
			background: '#fff',
			opacity: 0.9
		  }
		}
	}).send("id_cat="+id_cat+"&id_produit="+id_produit);
}

function update_tag(id_tag,id_cat,id_produit,action) {
	//console.log('id tag : ',id_tag,' - id cat : ',id_cat,' - id article : ',id_article,' - action : ',action);
	var ajax_request = new Request.HTML({
		url: '../inc/ajax/ajax.boutique.php',
		update: $('bloc-tag'),
		useWaiter: true,
		waiterOptions: {
		  baseHref: '../admin/images/pictos/',
		  img: {
			src: 'preloader-horizontal.gif',
			styles: {
			  width: 160,
			  height: 20
			}
		  },
		  layer: {
			background: '#fff',
			opacity: 0.9
		  }
		}
	}).send("id_cat="+id_cat+"&id_tag="+id_tag+"&action="+action+"&id_produit="+id_produit);
}

function updateCriteres(categorie,langue,annonce) {
	var ajax_request = new Request.HTML({
		url: 'inc/ajax/ajax.annonces.php',
		update: $('tr_criteres'),
		useWaiter: true,
		waiterOptions: {
			img: {
				styles: {
					width: 20,
					height: 20
				}
			}
		}
	}).send("upcrit_cat="+categorie+"&upcrit_lang="+langue+"&upcrit_ad="+annonce);
}

function updateSelectCritere2(marque) {
	var ajax_request = new Request.HTML({
		url: '../inc/ajax/ajax.annonces.php',
		update: $('select_critere2'),
		useWaiter: true,
		waiterOptions: {
			img: {
				styles: {
					width: 20,
					height: 20
				}
			}
		}
	}).send("upselectcrit_m="+marque);
}


function updateCritereNouvelleAnnonce(enfant,parent,langue) {
	var ajax_request = new Request.HTML({
		url: 'inc/ajax/ajax.annonces.php',
		update: $('critere'+enfant),
		useWaiter: true,
		waiterOptions: {
			img: {
				styles: {
					width: 20,
					height: 20
				}
			}
		}
	}).send("up_crit_enfant_e="+enfant+"&up_crit_enfant_p="+parent+"&langue="+langue);
}

function CheckAll2(count) {
	var i,coche = 0;
	for(i=1; i <= count; i++) {
		if(document.getElementById("checkbox"+i).checked == false)
			coche = 1;
	}
	if(coche==1) {
		for(i=1; i <= count; i++)
			document.getElementById("checkbox"+i).checked = true;
	}
	if(coche==0) {
		for(i=1; i <= count; i++)
			document.getElementById("checkbox"+i).checked = false;
	}
}

function Modif(count,page,formulaire,message1,message2) {
	coche = 0;
	for(i=1; i <= count; i++) {
		if(document.getElementById("checkbox"+i).checked == true) {
			id = document.getElementById("checkbox"+i).value;
			coche++;
		}
	}
	if(coche==0)
		alert(message1);
	else {
		if(coche>1)
			alert(message2);
		else
			window.location=page+"?id_ad="+id;
	}
}
function Supp(count,page,formulaire,message1,message2,message3) {
	coche = 0;
	for(i=1; i <= count; i++) {
		if(document.getElementById("checkbox"+i).checked == true)
			coche++;
	}
	if(coche==0) {
		alert(message1);
	} else {
		if(coche>1) message=message3;
		else message=message2;
		if (confirm(message)) {
				document.forms[formulaire].action = page+"?action=supprimer";
				document.forms[formulaire].submit();
		}	
	}
}
function Suspendre(count,page,formulaire,message1,message2,message3) {
	coche = 0;
	for(i=1; i <= count; i++) {
		if(document.getElementById("checkbox"+i).checked == true)
			coche++;
	}
	if(coche==0) {
		alert(message1);
	} else {
		if(coche>1) message=message3;
		else message=message2;
		if (confirm(message)) {
				document.forms[formulaire].action =page+"?action=suspendre";
				document.forms[formulaire].submit();
		}	
	}
}
function Reactiver(count,page,formulaire,message1,message2,message3) {
		coche = 0;
		for(i=1; i <= count; i++) {
			if(document.getElementById("checkbox"+i).checked == true)
				coche++;
		}
		if(coche==0) {
			alert(message1);
		} else {
			if(coche>1) message=message3;
			else message=message2;
			if (confirm(message)) {
					document.forms[formulaire].action =page+"?action=reactiver";
					document.forms[formulaire].submit();
			}	
		}
	}

