/**POUR valider les formulaires.*/

function msg_error(id, txt){
	if(document.getElementById(id)){
		document.getElementById(id).innerHTML = '<br>' + txt;
	}
}

function valid_select(obj, id,txt){
	if(!obj) return;
	if(obj.value < 0){
		msg_error(id,txt);
		return false;
	} else {
		msg_error(id,"");
		return true;
	}
}

function valid_input(obj, id,txt){
	if(!obj) return;
	if(obj.value == "" || obj.value.replace(/ /g, "")==""){
		msg_error(id,txt);
		return false;
	} else {
		msg_error(id,"");
		return true;
	}
}

function valid_gen_if(id,cond, txt){
	if(!eval(cond)){
		msg_error(id,txt);
		return false;
	} else {
		msg_error(id,"");
		return true;
	}
}

function valid_gen_ifnot(id,cond, txt){
	if(eval(cond)){
		msg_error(id,txt);
		return false;
	} else {
		msg_error(id,"");
		return true;
	}
}

function is_valid_mail(mail){
	var patreg = /^[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+|(\[([0-9]{1,3}(\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})\]))$/;
	return patreg.test(mail);
}

function is_valid_name(name){
	var patreg = /^([a-z]|[0-9])([a-z]|[0-9]|\_|\.|\-){3,19}$/;
	return patreg.test(name);
}

function is_valid_date(d, m, y){
	switch (m){
		case 1 :
		case 3 :
		case 5 :
		case 7 :
		case 8 :
		return d>=1 && d <=31;
		case 2 :
			if (y % 4 == 0) return d>=1 && d <= 29;
			return d>=1 && d <= 28;
		default:
			return d>=1 && d <= 30;
	}
	
}

function trim_str(txt){
	return txt.replace(/ /g, "");
}
