
function change_to_error_class(the_object)
{
	$("member_update_alert").style.display="block";
	$(the_object.id+"_label").style.color="#CC0000";
	$(the_object.id).style.background="yellow";	
}

function remove_error_class()
{
	$$('span.ff_label').each(
	    function(el){
	        try{
	            el.style.color="#003300";
	            $(el.getAttribute("my_child")).style.background="#ffffff";
	        }catch(e){}
	    }
	 );
}

function validate_user_data()
{
	var theForm = $("user_update_form");
	var errors = 0;
	remove_error_class();
	if (!theForm.firstname.value)
	{
	    change_to_error_class(theForm.firstname);
		errors++;
	}	
	if (!theForm.lastname.value)
	{
	    change_to_error_class(theForm.lastname);
		errors++;
	}	
	if((!theForm.naissance.value)||(theForm.naissance.value==""))
	{
	    change_to_error_class(theForm.naissance);
		errors++;
	}
	if (!theForm.address.value){
	    change_to_error_class(theForm.address);
		errors++;
	}	
	if (!theForm.city.value){
	    change_to_error_class(theForm.city);
		errors++;
	}	
	if (!theForm.postalcode.value){
	    change_to_error_class(theForm.postalcode);
		errors++;
	}	
	if (!theForm.email.value){
	    change_to_error_class(theForm.email);
		errors++;
	}
	if (!theForm.phone1.value){
	    change_to_error_class(theForm.phone1);
		errors++;
	}	
	else if (!validatePhoneNumber(theForm.phone1.value)){
	    change_to_error_class(theForm.phone1);
	    //alert("Telephone invalide");
		errors++;
	}
	if (!theForm.usager.value){
	    change_to_error_class(theForm.usager);
		errors++;
	}
	if(!validateUserName(theForm.usager.value)){
	    change_to_error_class(theForm.usager);
	    //alert("Ce nom d'usager est deja utilise");
		errors++;
	}
	if (!theForm.password.value){
	    change_to_error_class(theForm.password);
		errors++;
	}	
	
	if(errors==0)
		return true;
	else
	    return false;
}

function validateUserName(user_name)
{
	if((user_names.include(user_name))&&(user_name!=current_user_name))
		return false;
	else
		return true;
}
