$(function()
{
	$("input.CheckImg").CheckImg('0.png', '1.png', 'scripts/ImgChk/');
	$("img.CheckImg").css('cursor','pointer');

	function AutoSelect(c)
	{
		if(!$('.' + c + ' input.CheckImg').attr('checked'))
			$('.' + c + ' img').trigger('click');
	}

	$('.nom input').focus(function() { AutoSelect('nom'); });
	$(".jonction select").change(function() { AutoSelect('jonction'); });
	$(".serveur select").change(function() { AutoSelect('serveur'); });
	$(".roy select").change(function() { AutoSelect('roy'); });
	$(".classe select").change(function() { AutoSelect('classe'); });
	$(".sexe select").change(function() { AutoSelect('sexe'); });
	$(".race select").change(function() { AutoSelect('race'); });
	$(".niv input").focus(function() { AutoSelect('niv'); });
	$('.rp_min input').focus(function() { AutoSelect('rp_min'); });
	$('.rp_max input').focus(function() { AutoSelect('rp_max'); });
	$('.rp_min_sem input').focus(function() { AutoSelect('rp_min_sem'); });
	$('.rp_max_sem input').focus(function() { AutoSelect('rp_max_sem'); });
	$('.rang input').focus(function() { AutoSelect('rang'); });
	$('.maison input').focus(function() { AutoSelect('maison'); });
	$('.art select').change(function() { AutoSelect('art'); });
	$('.niv_art input').focus(function() { AutoSelect('niv_art'); });
	$('.membre_min input').focus(function() { AutoSelect('membre_min'); });
	$('.membre_max input').focus(function() { AutoSelect('membre_max'); });
	$('.membre_min_actif input').focus(function() { AutoSelect('membre_min_actif'); });
	$('.membre_max_actif input').focus(function() { AutoSelect('membre_max_actif'); });
	$('.courriel input').focus(function() { AutoSelect('courriel'); });
	$('.site input').focus(function() { AutoSelect('site'); });

	function AffTitle(attr)
	{
		$(attr).each(function() {
			$(this).html('<span class="bloque_invisible">' + $(this).attr('title') + '</span>' + $(this).html()).css("cursor","help").removeAttr('title');
		}).tooltip({ bodyHandler: function() { return $(this).find('.bloque_invisible').html(); }, track:true, delay:0 });
	}

	function AffTitleA(attr)
	{
		$(attr).each(function() {
			$(this).html('<span class="bloque_invisible">' + $(this).attr('title') + '</span>' + $(this).html()).css("cursor","help").removeAttr('title').css("display","block");
		}).parent().tooltip({ bodyHandler: function() { return $(this).find('.bloque_invisible').html(); }, track:true, delay:0 });
	}

	AffTitleA('#resultat tbody a');
	AffTitle('#resultat tbody .w1');

	// $("#options table tbody").addClass("bloque_invisible");
	$("#options table thead").css('cursor','pointer').click
	(
		function()
		{
			var a = $(this).find("~ tbody");
			a.is(".bloque_invisible")?a.removeClass():a.removeClass().addClass("bloque_invisible");
		}
	);

	$(".parametres tbody").addClass("bloque_invisible");
	$(".parametres thead").css('cursor','pointer').click
	(
		function()
		{
			var a = $(this).find("~ tbody");
			a.is(".bloque_invisible")?a.removeClass():a.removeClass().addClass("bloque_invisible");
		}
	);
});
