/**
* @author Latouss
*/

$(".minus").live("click", function(){
	var val = parseInt($(this).next().val());
	var total = parseInt($("#total_carac").text());
	if(val>2){
		$(this).next().val(val-1);
		
		var new_total = total-1;
		$("#total_carac").text(new_total);
		if(new_total<35)
			$("#total_carac").css("color", "#22D");
		else if(new_total>35)
			$("#total_carac").css("color", "#D22");
		else
			$("#total_carac").css("color", "#2D2");
	}
});

$(".plus").live("click", function(){
	var val = parseInt($(this).prev().val());
	var total = parseInt($("#total_carac").text());
	if(val<10){
		$(this).prev().val(val+1);
		
		var new_total = total+1;
		$("#total_carac").text(new_total);
		if(new_total<35)
			$("#total_carac").css("color", "#22D");
		else if(new_total>35)
			$("#total_carac").css("color", "#D22");
		else
			$("#total_carac").css("color", "#2D2");
	}
});

$(".caracs").live("keyup", function(){
	var val = $(this).val();
	if(val.length==0)
		$(this).val(2);
	
	val = parseInt(val);
	var total = parseInt($("#total_carac").text());
	
	if(val>10)
		$(this).val(10);
	else if(val<2)
		$(this).val(2);
	
	var total = 0;
	$(".caracs").each(function(){
		
		total += parseInt($(this).val());
	})
	
	$("#total_carac").text(total);
	
	if(total<35)
		$("#total_carac").css("color", "#22D");
	else if(total>35)
		$("#total_carac").css("color", "#D22");
	else
		$("#total_carac").css("color", "#2D2");

});

$("#info_user input[type=text], #info_user input[type=password]").live("focus", function(){
	$("#input_information div").hide();
	var id = $(this).attr("name");
	$("#info_"+id).show();
	$("#input_information").show();
});

$("#info_user input[type=radio]").live("focus", function(){
	$("#input_information").hide();
});
