$(document).ready(function() {

function initFormulaire(){
	$(".element_formulaire input").one('focus', function() {
	var value=$(this).attr('value');
	$(this).val('');
	$(this).bind('focusout',function() {
							  if($(this).val()==""){
								  $(this).val(value);
								  $(this).addClass('defaut');
							  }
							  else{
								 $(this).removeClass('defaut'); 
							  }
							  });
	$(this).bind('change',function() {
							  if($(this).val()==""){
								  $(this).val(value);
								  $(this).addClass('defaut');
							  }
							  else{
								 $(this).removeClass('defaut'); 
							  }
							  });
	$(this).bind('focusin',function() {
							  if($(this).val()==value){
								  $(this).val('');
							  }
							  });

	});
	
	$('.formulaire_date input').datePicker({createButton:false});
	$('.formulaire_date input').unbind('focus');
	$('.formulaire_date input').bind('focus',function(){
					$(this).dpDisplay();
					this.blur();
					return false;
				});
	$('.formulaire_date input').bind('dateSelected',function(e, selectedDate, $td){$(this).removeClass('defaut');});

	$(".element_formulaire textarea").one('focus', function() {
	var value=$(this).val();
	$(this).val('');
	$(this).bind('focusout',function() {
							  if($(this).val()==""){
								  $(this).val(value);
								  $(this).addClass('defaut');
							  }
							  else{
								 $(this).removeClass('defaut'); 
							  }
							  });
	$(this).bind('change',function() {
							  if($(this).val()==""){
								  $(this).val(value);
								  $(this).addClass('defaut');
							  }
							  else{
								 $(this).removeClass('defaut'); 
							  }
							  });
	$(this).bind('focusin',function() {
							  if($(this).val()==value){
								  $(this).val('');
							  }
							  });

	});
	
	$("form:has(input:submit)").submit(function() {
											 $(".element_formulaire input.defaut").each(function (i) {
												$(this).val('');
											  });
												return true;
											 });
}

initFormulaire();

$("div.ajax").ajaxSuccess(function() {
initFormulaire();
});

//Pour permettre d'executer a chaque fois la fonction ajaxsuccess, sinon le resultat ajax est gardé dans le cache
$.ajaxSetup({
	  cache: false
});


});

