toggleReductions = function(typeshow, typehide) {
	if(typeshow && typehide) {
		if(typeshow) {
			$$('.' + typeshow).each(function(li) {
				if(li.parentNode.visible()) new Effect.Fade(li.parentNode, { duration:1, from:1.0, to:0});
			});
		}
		if(typehide) {
			$$('.' + typehide).each(function(li) {
				if(!li.parentNode.visible()) new Effect.Appear(li.parentNode, {duration:1, from:0, to:1.0});
			});
		}
	}
	else {
		$$('.codepromo').each(function(li) {
			if(!li.parentNode.visible()) new Effect.Appear(li.parentNode, {duration:1, from:0, to:1.0});
		});
		$$('.bonplan').each(function(li) {
			if(!li.parentNode.visible()) new Effect.Appear(li.parentNode, {duration:1, from:0, to:1.0});
		});
	}
};

toggleMarchands = function(type, link) {
	$$('.' + type).each(function(li) {
		if(li.visible()) {
			new Effect.Fade(li, { duration:1, from:1.0, to:0});
			link.innerHTML = 'Afficher tous les marchands';
		}
		else {
			new Effect.Appear(li, {duration:1, from:0, to:1.0});
			link.innerHTML = 'N\'afficher que les marchands qui proposents des r&eacute;ductions';
		}
	});
};

refreshCommentaire = function(rid, aid) {
	new Ajax.Updater('commentaires_' + rid, '/ajax/get-avis.html', {
		parameters: { avis_id: aid },
		onComplete: function() {
			new Effect.Highlight($('commentaire_' + aid), {startcolor: '#ffff99', endcolor: '#f3f2e9'});
			$('voircommentaires_' + rid).show();
		},
		insertion: Insertion.Top
	});
};

showCode = function(code, link, divID) {
	if(code == '') {
		code = 'Ne n&eacute;cessite pas de code'
	}

	window.open(link.href);
	if(self.focus) {
		self.focus();
		window.setTimeout("self.focus();", 1000);
	}

	div = $(divID);
	div.innerHTML = '<div class="showcode">Voici le code de r&eacute;duction :<br /><input type="text" class="code" value="' + code + '" onclick="this.select();" /></div>';

	return false;
};

var iReductionReductiontype = 1;
changeReductionType = function(val, i) {
	if(val == 1 || val == 2) {
		$('field_reductiontype_valeur_' + i).show();
		$('field_reductiontype_texte_' + i).hide();
		$('reductiontype_' + i + '_texte').value = '';
	}
	else if(val == 3) {
		$('field_reductiontype_texte_' + i).show();
		$('field_reductiontype_valeur_' + i).hide();
		$('reductiontype_' + i + '_valeur').value = '';
	}
	else if(val == 4) {
		$('field_reductiontype_valeur_' + i).hide();
		$('field_reductiontype_texte_' + i).hide();
		$('reductiontype_' + i + '_valeur').value = '';
		$('reductiontype_' + i + '_texte').value = '';
	}
};

var page = 1;
generatePager = function() {
	if($('next') && idPager && urlPager) {
		Event.observe('next', 'click', function(e) {
			page++;
			new Ajax.Updater(
				idPager,
				urlPager + '?page=' + page,
				{insertion: Insertion.Bottom,evalScripts:true}
			);
			Event.stop(e);
		});
	}
};
hidePager = function() {
	if($('next')) {
		$('next').hide();
	}
};

document.observe("dom:loaded", function() {
	if($('reduction_marchand')) {
		new Ajax.Autocompleter(
			'reduction_marchand',
			'reduction_marchands',
			'/ajax/search-marchand.html',
			{
				paramName: 'search',
				minChars: 1,
				afterUpdateElement: function(text, li) {
					$('reduction_marchand_id').value = li.id;
				}
			});
	}
	generatePager();
});


var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2818505-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script');
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	ga.setAttribute('async', 'true');
	document.documentElement.firstChild.appendChild(ga);
})();
