////////////////////////////////
//Nouvelles
////////////////////////////////

//delai entre deux nouvelles
var temps=5000;
var vitesse=20;

//actionne le scroll de quoi de neuf vers la prochain nouvelle
function nouvelles(quelNouvelle,nbTitres)
{
	myIntervalAnim=window.setInterval("animNouvelles("+quelNouvelle+","+nbTitres+")",vitesse);
}

//bouge les nouvelles de quoi de neuf
function animNouvelles(quelNouvelle,nbTitres)
{
	var myPos=new Array();
	
	for (x=1;x<=2;x++)
	{
		myPos[x]=document.getElementById('n_nouvelle'+x).offsetTop;
	}
	
	var petit=1;
	var grand=2;

	myPos[petit]--;
	
	document.getElementById('n_nouvelle' +petit).style.top=myPos[petit]+"px";
	document.getElementById('n_nouvelle' +grand).style.top=myPos[petit]+"px";
	
	var maxTop=0;
	if (quelNouvelle==0)
	maxTop=(document.getElementById('n_titre'+nbTitres+'_'+grand).offsetTop)*-1;
	else
	maxTop=(document.getElementById('n_titre' +quelNouvelle+"_"+petit).offsetTop)*-1;
	
	principal=1;
	
	if (quelNouvelle==0)
	principal=2;

	if (myPos[principal]<=maxTop)
	{
		window.clearInterval(myIntervalAnim);
		var temp=0;
		
		if (quelNouvelle==0)
		{
			document.getElementById('n_nouvelle' +petit).style.top=document.getElementById('n_nouvelle' +grand).offsetTop+ "px";
			document.getElementById('n_nouvelle' +grand).style.top=myPos[petit]+"px";
			
			temp=nbTitres-1;
		}
		else
		temp=quelNouvelle-1;
		
		startAnim(temp,nbTitres,false);
	}
}

//HIDES AN OBJECT, UPDATES DATA, THEN SHOWS IT ALL WITH FADES
function addon(object,nb){
	var  done=false;
	for (x=0;x<=nb;x++){
		if ($('#txt'+x).css('display')=='block'){
			$('#txt'+x).fadeOut('fast',function(){$('#txt'+object).fadeIn('fast');});
			done=true
		}
	}
	
	if (!done)
	$('#txt'+object).fadeIn('fast');
	
	
	window.location="#txt"+object;
}


function startAnim(quelNouvelle,nbTitres,verifHeight){
	anim=true;
	if(verifHeight)
	{
		lesNew2=document.getElementById('n_nouvelle2');
		
		heightNews=parseInt(document.getElementById('n_nouvelles').offsetHeight)
		heightNew2=parseInt(lesNew2.offsetHeight)
		
		if(heightNew2<=(heightNews+5))
		{
			anim=false;
			lesNew2.style.display='none';
		}
	}
	
	if(anim)
	myInterval=window.setTimeout("nouvelles("+quelNouvelle+","+nbTitres+")",temps);
}

//gives telephone inputs their properties
function tel(name){
	for (x=1;x<=3;x++){
			document.getElementById(name +x).onfocus		=	function(){
			if (isNaN(this.value))
			this.value="";
		}
		
		document.getElementById(name +x).onkeyup	=	function(){
			val = this.value;
			id	=	parseInt(this.name.substring(this.name.length-1));

			val=val.replace(/[^0-9]/g,'');									 
			
			this.value=val;
			
			if (id!=3&& this.value.length==3)
				document.getElementById(name+(id+1)).focus();
		}
		
		document.getElementById(name +x).onblur	=	function(){
			this.value=this.value.replace(/[^0-9]/g,'');
		}
	}
}


//trims blank spaces
function trim(val)
{
if (!val) return val;

	while(val.charAt(0) == ' ') val = val.substring(1,val.length);
	while(val.charAt(length)==' ')  val = val.substring(0,val.length-1);

 return val;
}

function valide_champs(field,pattern){
	val=field.value;
	
	for (z=0;z<=val.length;z++){
			val=val.replace(pattern,'');								 
	}
	
	field.value=val;
}


function validerCourriel(champ)
{
	var erreur	=	false;
	var valeur = document.getElementById(champ).value;
		
	var regExpCourriel = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
	
	valeur.split('@',valeur);
		

	if(!regExpCourriel.test(valeur))
	erreur = true;		
	
	return erreur;
}
