//
// Fonction retournant directement la valeur s�lectionn�e de la CBox pass� en param�tre
// permet de simplifier le code
//
function selectedValue(selBox)
{
	return selBox.options[selBox.selectedIndex].value;
}

//
// Fonction de suppression des espaces en d�but et fin de chaine de carateres
// /Optimis�/
//
function trim(str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

//
// Fonction v�rifiant si la saisie de nombre seule
//
function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode

	// tabulation pour passer au champs suivant
	if (unicode == 9)
		return true;
	// virgule
	if (unicode == 44)
		return true;
	// point
	if (unicode == 46)
		return true;
	// tabulation arriere (backspace)
	if (unicode == 8)
		return true;
	if (unicode<48||unicode>57)
			return false; //disable key press

	return true;
}

//
// Fonction v�rifiant si la saisie hors Espace
//
function saisieSansEspace(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=32)
		return true; //disable key press
	else
		return false;
}

//
// V�rification de la validit� d'une date
//
function test_date(jour, mois, annee)
{
	jj = parseInt(jour);
	mm = parseInt(mois);
	aa = parseInt(annee);

	if (jj > 31) return false;
	if (mm> 12) return false;

	switch (mm)
	{
		case 4, 6, 9, 11 :
			if (jj >30) return false;
			break;

		case 2:
			if ((aa % 4) != 0)
			{
				if (jj > 28) return false;
			}
			else
			{
				if (jj > 29) return false;
			}
			break;
	}
	return true;
}

//
// V�rification de la validit� d'une heure
//
function test_heure(Heure, Minute)
{
	hh = parseInt(Heure);
	mm = parseInt(Minute);
	if (hh > 23)
		return false;
	if (mm > 59)
		return false;

	return true;
}

//
// V�rification si une date de d�but est inf�rieur � une date de fin
//
function date_inf(jourd, moisd, anneed, jourf, moisf, anneef){
	var d = parseInt(anneed)*1000+ parseInt(moisd)*100+ parseInt(jourd);
	var f = parseInt(anneef)*1000+ parseInt(moisf)*100+ parseInt(jourf);

	alert(d);
	if (d > f){
		return false;
	}
	else
		return true;
}


//
// affichage d'une image a sa taille reelle dans une nouvelle fenetre
//
function zoomImageOLD(image)
{
	var newWin;

	newWin = window.open(image,'Image' ,'width=500px, height=500px, resizable=yes,scrollbar=yes');
	newWin.focus();
}


function zoomImage(image)
{
	var newWin;

	newWin = window.open("",'Image' ,'width=500px, height=500px, resizable=yes, scrollbars=yes ,toolbar =no ,menubar =no');
	newWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n');
	newWin.document.write("<HTML><HEAD><TITLE>Apercu de l'image</TITLE>\n");
	newWin.document.write('<SCRIPT  language="JavaScript" type="text/javascript" >							\n\
		  function checksize()  	  																		\n\
		  { 																								\n\
			if (document.images[0].complete) 																\n\
			{  																								\n\
				var width = document.images[0].width;														\n\
				var height = document.images[0].height;														\n\
				if (height > 800) height = 800;																\n\
				if (width > 800) width = 800;																\n\
				height += 57;																				\n\
				width += 10;																				\n\
				window.resizeTo(width,height); 																\n\
				window.focus();																				\n\
			} 																								\n\
			else 																							\n\
			{ 																								\n\
				setTimeout("checksize()",250) 																\n\
			} 																								\n\
		}																									\n\
		</SCRIPT>																							\n\
		</HEAD>																								\n\
		<BODY style="margin: 0px 0px 0px 0px;" onload="checksize()" BGCOLOR="#ffffff">						\n\
		<img src="' + image + '"  border="0">																\n\
		</BODY></HTML>\n');
		newWin.document.close();
		newWin.focus();

}

// [04/03/2008, vb] Fonction PopupImage utilis�e pour la visionneuse scrollable
function PopupImage(img)
{
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');
	w.document.write("<HTML><HEAD><TITLE>Apercu de l'image</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// [11/03/2008, vb] Permet le chargement dynamique d'une image dans le cartouche du haut dans une page dynamique
function imgCartoucheLoad(url)
{
	var img = document.getElementById('imgCartouche');

	if (img)
	{
		img.src = url;
	}
}





function valideMail(mail) {
	var re_email = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ ;
  	t_email = re_email.test(mail);

 	if (t_email)
 		return true;
 	return false;

}

function validNewsletter(mail, msg_deb, mail_invalide){
	var msg = "";
	var msg_debut = msg_deb+" :\n";

	var valide = true;

	/**
	 * Validation du mail
	 *
	 **/
	if (valideMail(mail) != true){
		msg += "\t - "+ mail_invalide +": "+mail+"\n";
		valide = false;
	}
	/**
	 * Validation g�n�rales
	 *
	 **/
	if(!valide){
		alert(msg_debut+msg);
		return false;
		}
	else 
		return true;
}




//simulation de la classe hover pour IE
sfHover = function() {

	if (document.getElementById("menu_hierarchie") == null) return;

	var sfEls = document.getElementById("menu_hierarchie").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}




