var reg_email = /^[A-Za-z0-9\.\-_]+[@][A-Za-z0-9\-\.]+[\.][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]?$/;

function popUpCentre(adresse,largeur,hauteur,nomFenetre){
	var winl=(screen.width - largeur) / 2;
	var wint=(screen.height - hauteur) / 2;
	fenetre=window.open(adresse,nomFenetre,'scrollbars=yes,resizable=yes,width='+largeur+',height='+hauteur+',top='+wint+',left='+winl);
	//aucas où la fenêtre existe déjà
	fenetre.resizeTo(largeur,hauteur);
	fenetre.moveTo(winl,wint);
	fenetre.focus();
}

function confirmSupRedir(adresse){
	reponse=confirm("Voulez vous supprimer cet élément ?");
	if(reponse==1) window.location=adresse;
}

function imprimerContenuHtml(identifiant){
	html='<html><head><title>Impression</title><link type="text/css" rel="stylesheet" href="/css/styles.css" /><script language="javascript">ord=Math.random()*10000000000000000;</script></head><body style="margin:5px;" onLoad="window.print(); window.close();">';
	html+=document.getElementById(identifiant).innerHTML;
	html+='<div align="center"><input type="button" value="Imprimer" onClick="window.print();" /></div></body></html>';
	ouverture=window.open('','pageImprimable','scrollbars=yes,resizable=yes,width=650,height=400');
	ouverture.document.write(html);
	ouverture.document.close();
}

function montreBloc(identifiant){
	var x = document.getElementById(identifiant);
	var typeNoeud=x.nodeName;
	if(typeNoeud=='TR' || typeNoeud=='tr'){
		if(navigator.appName=='Netscape') x.style.display='table-row';
		else x.style.display='inline';
	}
	else{
		x.style.display='block';
	}
	x.style.visibility='visible';
}

function cacheBloc(identifiant){
	var x = document.getElementById(identifiant);
	x.style.display='none';
	x.style.visibility='hidden';
}

function envoyer_a_ami(article){
	var e_add= prompt('Entrez l\'adresse email de votre ami(e):','');
	var subj= prompt('Entrer le sujet du message : ','');
	if (subj==" " || subj==null) subj="Cet article vous est recommandé";
	window.location="mailto:"+e_add+"?subject="+subj+"&body="+article;
}

//DEBUT DU CONTENU DE centre_elem.js
var gTabbableTags=new Array("a","button","textarea","input","iframe");
var gTabIndexes=new Array();
var gPopupMask=null;
var gPopupContainer=null;
var gPopFrame=null;
var gPopTitleBar=null;
var gReturnFunc;
var gPopupIsShown=false;
var gHideSelects=true;//pour masque des <select>
var gHideObjectTags=true;//pour masque des <select>


function cachePopUpParParent(callReturnFunc,templateID){
	window.parent.cachePopup(callReturnFunc,templateID);
}

//si on veut une iframe
function popupIframe(url,width,height,returnFunc,templateID){
	document.getElementById("popupConteneur").innerHTML='<iframe src="'+url+'" id="popupFrame'+templateID+'" name="popupFrame'+templateID+'" frameborder="0" width="100%" height="100%" scrolling="auto"></iframe>';
	montrePopup(url,width,height,returnFunc,templateID);
}

function montrePopup(url,width,height,returnFunc,templateID){
	gPopupMask=document.getElementById("popupMasque" + templateID);
	gPopupContainer=document.getElementById("popupConteneur" + templateID);
	gPopFrame=document.getElementById("popupFrame" + templateID);
	gPopTitleBar=document.getElementById("PopupTitleBar" + templateID);
	
	//on vérifie la version de IE pour masque les select
	var brsVersion=parseInt(window.navigator.appVersion.charAt(0),10);
	if(brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1){
		gHideSelects=true;
	}
	gPopupIsShown=true;
	disableTabIndexes();
	//gPopupMask.style.display="block";
	gPopupContainer.style.display="block";
	//on calcul l'emplacement de la fenêtre
	centerPopWin(width,height);
	
	gPopupContainer.style.width=width + "px";

	if(gPopTitleBar != null){
		var titleBarHeight=parseInt(gPopTitleBar.offsetHeight,10);
		
		gPopupContainer.style.height=(height+titleBarHeight) + "px";

		gPopFrame.style.width=parseInt(gPopTitleBar.offsetWidth,10) + "px";
	}
	else{
		gPopupContainer.style.height=height + "px";
		gPopFrame.style.width=width + "px";
	}
	
	gPopFrame.style.height=(height) + "px";
	
	// set the url
	if(url != '') gPopFrame.src=url;
	
	gReturnFunc=returnFunc;
	// for IE
	if(gHideSelects==true) hideSelectBoxes();
	if(gHideObjectTags==true) cacheMontreEmbedTags('object','hidden');
	if(gHideObjectTags==true) cacheMontreEmbedTags('embed','hidden');
	//if(gHideObjectTags==true) cacheMontreEmbedTags('iframe','hidden');
}

function cachePopup(callReturnFunc,templateID){
	gPopupMask=document.getElementById("popupMasque" + templateID);
	gPopupContainer=document.getElementById("popupConteneur" + templateID);
	gPopFrame=document.getElementById("popupFrame" + templateID);
	
	gPopupIsShown=false;
	//restoreTabIndexes();
	if(gPopupMask==null){
		return;
	}
	gPopupMask.style.display="none";
	gPopupContainer.style.display="none";
	if(callReturnFunc==true && gReturnFunc != null){
		gReturnFunc(window.frames["popupFrame" + templateID].returnVal);
	}
	//gPopFrame.src='/blank.htm';
	// display all select boxes
	if(gHideSelects==true) displaySelectBoxes();
	if(gHideObjectTags==true) cacheMontreEmbedTags('object','visible');
	if(gHideObjectTags==true) cacheMontreEmbedTags('embed','visible');
	//if(gHideObjectTags==true) cacheMontreEmbedTags('iframe','visible');
}

//Pour IE
function disableTabIndexes(){
	if(document.all){
		var i=0;
		for(var j=0; j < gTabbableTags.length; j++){
			var tagElements=document.getElementsByTagName(gTabbableTags[j]);
			for(var k=0 ; k < tagElements.length; k++){
				gTabIndexes[i]=tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}

//Pour IE
function restoreTabIndexes(){
	if(document.all){
		var i=0;
		for(var j=0; j < gTabbableTags.length; j++){
			var tagElements=document.getElementsByTagName(gTabbableTags[j]);
			for(var k=0 ; k < tagElements.length; k++){
				gTabIndexes[i]=tagElements[k].tabIndex;
				tagElements[k].tabIndex="1";
				i++;
			}
		}
	}
}

var gi=0;
function centerPopWin(width,height){
	if(gPopupIsShown==true){
		if(width==null || isNaN(width)){
			width=gPopupContainer.offsetWidth;
		}
		if(height==null){
			height=gPopupContainer.offsetHeight;
		}
		
		var fullHeight=getViewportHeight();
		var fullWidth=getViewportWidth();
		
		var theBody=document.documentElement;
		
		var scTop
		if(document.documentElement && document.documentElement.scrollTop){
			scTop=parseInt(theBody.scrollTop,10);
		}
		else if(document.body){
			scTop=parseInt(document.body.scrollTop,10)
		}
		else{
			scTop=parseInt(theBody.scrollTop,10);
		}

		var scLeft=parseInt(theBody.scrollLeft,10);
		
		gPopupMask.style.height=fullHeight + "px";
		gPopupMask.style.width=fullWidth + "px";
		gPopupMask.style.top=scTop + "px";
		gPopupMask.style.left=scLeft + "px";
		
		var titleBarHeight=0;
		
		if(gPopTitleBar != null)
			titleBarHeight=parseInt(gPopTitleBar.offsetHeight,10);
		
		gPopupContainer.style.top=(scTop + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		gPopupContainer.style.left=(scLeft + ((fullWidth - width) / 2)) + "px";
	}
}
addEvent(window,"resize",centerPopWin);
window.onscroll=centerPopWin;

function hideSelectBoxes(){
	for(var i=0; i < document.forms.length; i++){
		for(var e=0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName=="SELECT"){
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

function displaySelectBoxes(){
	for(var i=0; i < document.forms.length; i++){
		for(var e=0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName=="SELECT"){
				document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

function cacheMontreEmbedTags(balise,visibilite){
	//Masque ou montre toutes les balises HTML choisies
	var tabTag=document.getElementsByTagName(balise);
	for(var i=0; i < tabTag.length; i++){
		tabTag[i].style.visibility=visibilite;
	}
	
}

function addEvent(obj,evType,fn){
	if(obj.addEventListener){
		obj.addEventListener(evType,fn,true);
		return true;
	}
	else if(obj.attachEvent){
		var r=obj.attachEvent("on"+evType,fn);
		return r;
	}
	else{
		return false;
	}
}

function getViewportHeight(){
	if(window.innerHeight!=window.undefined) return window.innerHeight;
	if(document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if(document.body) return document.body.clientHeight;
	return window.undefined;
}

function getViewportWidth(){
	if(window.innerWidth!=window.undefined) return window.innerWidth;
	if(document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
	if(document.body) return document.body.clientWidth;
	return window.undefined;
}

//FIN DU CONTENU DE centre_elem.js