function valid_email(email)
{
	var re_mail = new RegExp('^[^@]+[@][^@]+$');
	return re_mail.test(email);	
}

function valid_passwordLevel(password)
{
	var level=0;
	
	var security='';
	var re_other = new RegExp('[^a-z0-9]','i');
	if(re_other.test(password))
	{
		level++;
		security+='other ';
	}
	
	var re_upper = new RegExp('[A-Z]');
	var re_lower = new RegExp('[a-z]');
	if(re_upper.test(password) && re_lower.test(password))
	{
		level++;
		security+='multi ';
	}

	var re_letter = new RegExp('[a-z]','i');
	var re_digit = new RegExp('[0-9]');
	if(re_letter.test(password) && re_digit.test(password))
	{
		level++;
		security+='alplanum ';
	}

	if(password.length>8)
	{
		level++;
		security+='lenght ';
	}

	var chars='';
	for(var i=0;i<password.length;i++)
	{
		if(chars.indexOf(password.charAt(i),0)<0)
		chars+=password.charAt(i);
	}
	if(chars.length>5) 
	{
		level++;
		security+='chars ';
	}
	
	return level;
}

function valid_notEmpty(value)
{
	if(value===false) return false;
	if(value===null) return false;
	value=$P.trim(value);
	return value!='';
}

function valid_dateFr(str)
{
		var re_date = new RegExp('^ *([0-9]{1,2})[/ -]?([0-9]{1,2}) *$');
        var match = re_date.exec(str);
        if(match)
		{
			var n=new Date();
			match[3]=n.getFullYear();
		}
		else
		{
			re_date = new RegExp('^ *([0-9]{1,2})[/ -]?([0-9]{1,2})[/ -]?([0-9]{2,4}) *$');
			match = re_date.exec(str);
			if(!match) return false;
		}
        match[1]=match[1]*1;
        match[2]=match[2]*1;
        match[3]=match[3]*1;
        if(match[3]<50) match[3]+=2000;
        else if (match[3]<100) match[3]+=1900;
        var d=new Date(match[3], match[2]-1, match[1]);
        if(d.getFullYear()!=match[3]||d.getMonth()!=match[2]-1||d.getDate()!=match[1]) return false;
        if(match[1]<10) match[1]='0'+match[1];
        if(match[2]<10) match[2]='0'+match[2];
        return match[1]+'/'+match[2]+'/'+match[3];
}

function valid_integer(str)
{
	str=str.replace(new RegExp('[,]'),'.');
    if(!str)
	{
    	return str;
	}
    if(isNaN(parseInt(str))) return false;
    return parseInt(str).toFixed(0);
}

function valid_cpFr(str)
{
	var re_cp = new RegExp('^ *([0-9]{5}) *$');
    var match = re_cp.exec(str);
    if(match) return match[1];
    return false;
}

function valid_telephone(str)
{
	str=$P.trim(str);

	var re_clean = new RegExp('[^0-9+]','g');
	
	strc=str.replace(re_clean,'');
	
	var re_fr = new RegExp('^[0]([1-9])([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$');
    var match = re_fr.exec(strc);
    if(match)
    {
    	return '+33 '+match[1]+' '+match[2]+' '+match[3]+' '+match[4]+' '+match[5];
    }
	
	var re_int1 = new RegExp('^(00|[+]) *([0-9]{1,3}) ([0-9 ]{4,15})$');
	match = re_int1.exec(str.replace(new RegExp('[^0-9+ ]','g'), ' '));
	if(match)
	{
		var res='';
		var tmp=match[3].replace(re_clean,'');
		for(var i=tmp.length-1, j=0; i>=0; i--,j++)
		{
			if(j%2==0) res=' '+res;
			res=tmp.charAt(i)+res;
		}
		res=$P.trim('+'+match[2]+' '+res);
		
		return res;
	}

	var re_int2 = new RegExp('^(00|[+])([0-9]{2,3})([0-9]{4,15})$');
	match = re_int2.exec(strc);
	if(match)
	{
		var res='';
		var tmp=match[3].replace(re_clean,'');
		for(var i=tmp.length-1, j=0; i>=0; i--,j++)
		{
			if(j%2==0) res=' '+res;
			res=tmp.charAt(i)+res;
		}
		res=$P.trim('+'+match[2]+' '+res);
		
		return res;
	}
	
	return false;
	
	
}