function display_pass() {
	$('#pass').css('display','none');
	$('#pass_valid').css('display','inline');
	$("#pass_valid").focus();
}

function display_pass2() {
	$('#pass2').css('display','none');
	$('#pass_valid2').css('display','inline');
	$("#pass_valid2").focus();
}

function inscription() {

	$('#msg_error1').html('');
	$('#msg_error2').html('');
	$('#msg_error3').html('');
	$('#msg_error4').html('');
	
	$('#etape1').css('display','none');
	$('#etape1_2').css('display','none');
	$('#etape2').css('display','block');
}

function send_login() {

	$('#msg_error1').html('');
	$('#msg_error2').html('');
	$('#msg_error3').html('');
	$('#msg_error4').html('');

	$('#etape1').css('display','none');
	$('#etape1_2').css('display','block');
	$('#etape2').css('display','none');
}

function checkMaxLength(){
	//var size = $(this).attr("maxlength");
	var size = 141;
	if(this.value.length >= size)
	this.value = this.value.substr(0,size-1);
} 


function remake_compteur(){
	var n=5;
	var count_t2=count_t.toString()
	var count0=n-(count_t2.length);
	
	var str="";
	for(var i=0;i<count0;i++) str+="0";
	str+=count_t2;
	
	for(var i=0;i<n;i++) $("#cv"+i).attr({ src: app_url+"/medias/interface/"+str.substr(i,1)+".jpg" });
}


function dialog_friend(id){

	$("#send_friend_id").val(id);
	$('#dialog_bg').height($(document).height()).show();
	$("#dialog_friend").css({ top: ($(window).height()/2)-$("#dialog_friend").height()/2 });
	$('#dialog_friend').show();
	window.scroll(0,0);
}


function close_dialog_friend(){
	$("send_friend_id").attr({ value: "" });
	$('#dialog_bg').hide();
	$('#dialog_friend').hide();
	
	$("#send_friend_result").html('');
	$("#send_friend_prenom_from").val("Votre prénom");
	$("#send_friend_email_to").val('Email de votre ami');
}


function send_friend(){
	
	var prenomfrom = $("#send_friend_prenom_from").val();
	var emailto = $("#send_friend_email_to").val();
	var id = $("#send_friend_id").val();
	
	$.post(app_url+"/sendfriend/",
		{ prenomfrom: prenomfrom, emailto: emailto, id: id },
		function(data){
			if(data=='1'){
				$("#send_friend_result").attr('class',"error").html('<p>Veuillez saisir votre pr&eacute;nom.</p>');
			}else if(data=='2'){
				$("#send_friend_result").attr('class',"error").html('<p>Veuillez saisir un mail d\'expedition valide.</p>');
			}else if(data=='0') {
				$("#send_friend_result").attr('class',"success").html('<p>Merci, votre email &agrave; bien &eacute;t&eacute; envoy&eacute; !</p>');
				$("#send_friend_prenom_from").val('Votre prénom');
				$("#send_friend_email_to").val('Email de votre ami');
			}
		}
	);
	
}


function vote(id){

	//display
	$("#bt_"+id).html('<img src="'+app_url+'/medias/interface/bt_votez_off.jpg" alt="" />');
	$("#vote_text_"+id).addClass("off");
	
	//new count votes
	var nb=parseInt($("#count_"+id).html());
	$("#count_"+id).html(nb+1);
	
	//new count temoignages
	count_t++;
	remake_compteur();
	
	//send
	$.post(app_url+"/temoignages/vote/",{ id: id });
}







