// verifie la validite d'un email
function validemail(champ)
{
	
 test = document.formulaire.elements[""+champ+""].value;
 valeur = test.indexOf("@");
 valeur2 = test.lastIndexOf(".");
 valeur3 = valeur2 + 1;
 longueur = test.length;
 ext = test.substring(valeur3,longueur);
 ok=0;
 temp = ext.length;
 if ( temp==2 || temp==3 ) 
    { ok=1; }
 else
    { ok=0; }
 if ( valeur2 == (valeur + 1) )
     { ok=0; }
 if (valeur==0)
     { ok=0; }
 if (valeur==-1 || valeur2==-1 || ok==0)
    { alert("L'email que vous avez rentrée n'est pas valide.\nVeuillez la ressaisir s'il vous plaît.");
      return false; }
 else
    { return true; }   
    
}

// verifie les champs obligatoire d'un formulaire
valider_formulaire = function () {
	var tab = valider_formulaire.arguments;

	taille = tab.length;

	for (i=0;i<taille;i++) {
		if (tab[i]=="email") {
			if (!validemail(tab[i])) {
				return 0; 
			}
		}else if (document.formulaire.elements[tab[i]].type=="checkbox") {
			if (!document.formulaire.elements[tab[i]].checked) {
				str_temp = tab[i].replace(/_/g," ");
				alert("Vous devez cocher la case \""+str_temp+"\".");
				return 0; 
			}
		}else{
			if ((document.formulaire.elements[tab[i]].value=="") || (document.formulaire.elements[tab[i]].value==" ")) {
				str_temp = tab[i].replace(/_/g," ");
				alert("Le champ "+str_temp+" est obligatoire.\nVeuillez le ressaisir s'il vous plaît.");
				return 0; 
			}
		}
	}
	
	document.formulaire.submit();
}

function empechechar()
{
	if( event.keyCode < 48 || event.keyCode > 57 )
 	{ 
 		alert( "Ce champ doit être numérique, il ne peut contenir aucun autre type de caratères." );
   		event.returnValue = false;
   	}
}

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_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_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];}
}



function changeTd(id_td,nom_classe) {
	document.all[id_td].className=nom_classe;
}
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_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_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];}
}
function ItemOn(LinkObject, Color, FontSize, NbCol) {

	for (i=0;i<parseInt(NbCol);i++){
		LinkObject.style.color = "white";
		LinkObject.style.backgroundColor = Color;
	}
}
function ItemOff(LinkObject, Color, FontSize, NbCol) {
	for (i=0;i<parseInt(NbCol);i++){
		LinkObject.style.color = Color;
		LinkObject.style.backgroundColor = Color;
	}
}

// Raccourci zoom du bandeau horizontal
function chooseZoom(actu) {
	if (document.form_zoom.url_service.value!=0) {
		if (document.form_zoom.url_service.value==-1) {
			location.href="index.php?Rub=509";
		}else{
			location.href="demarche.php?actu_rub="+actu+"&spl_f="+document.form_zoom.url_service.value;
		}
	}
}

// ouvre la fenetre version imprimable
function imprimer(rub) {
	window.open("imprimer.php?Rub="+rub,"Imprimer",'width=650,height=550,scrollbars=yes');
}

// ouvre la fenetre version imprimable
function imprimer2(rub,id) {
	window.open("imprimer.php?Rub="+rub+"&id_cv_theme_association="+id,"Imprimer",'width=650,height=550,scrollbars=yes');
}

// ouvre la page d'envoie à un ami
function envoieAmi(rub) {
	location.href="index.php?EA=1&rub_cible="+rub;
}

// liste deroulante interne
function changeIt() {
	document.formulaire_interne.submit();
}

// desactive le click droit
var clickmessage="Bouton droit désactivé."

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert(clickmessage);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

// lance une recherche interne
function recherche_interne() {
	if ((document.formulaire_interne.recherche_interne.value!="") && (document.formulaire_interne.recherche_interne.value!=" ")) {
		document.formulaire_interne.submit();
	}else{
		alert("Vous devez saisir a moins un mot avant de lancer une recherche.");
		document.formulaire_interne.recherche_interne.focus();
	}
}

// affiche tous les objets lors d'une recherche interne
function toutvoir() {
	document.formulaire_interne.submit();
}

// change le theme d'un communique de presse
function changeThemeCom() {
	if (document.formulaire_interne.id_cv_theme_communique.value!=0) {
		document.formulaire_interne.submit();
	}
}

// change le theme d'une revue de la mediatheque
function changeThemeRevue() {
	if (document.formulaire_interne.id_cv_theme_revue.value!=0) {
		document.formulaire_interne.submit();
	}
}

// change le theme d'une video
function changeThemeVideo() {
	if (document.formulaire_interne.id_cv_theme_video.value!=0) {
		document.formulaire_interne.submit();
	}
}

// change le theme d'une association
function changeThemeAssociation() {
	if (document.formulaire_spec_asso.id_cv_theme_association.value!=0) {
		document.formulaire_spec_asso.submit();
	}
}

// change le theme d'une école
function changeThemeEcole() {
	if (document.formulaire_interne.id_cv_theme_ecole.value!=0) {
		document.formulaire_interne.submit();
	}
}

// recherche une entreprise dans l'annuaire
function recherche_entreprise() {
	if (document.formulaire_interne.recherche_interne.value!="") {
		document.formulaire_interne.submit();
	}else{
		alert("Vous devez saisir un texte avec de lancer une recherche.");
	}
}

// change le theme d'un elu
function changeThemeElu() {
	if (document.formulaire_interne_elu.id_cv_theme_elu.value!=0) {
		document.formulaire_interne_elu.submit();
	}
}

// change le theme d'un practicien
function changeThemePracticien() {
	if (document.formulaire_interne.id_cv_theme_practicien.value!=0) {
		document.formulaire_interne.submit();
	}
}

// ouvre une video
function openVideo(id_video) {
	window.open("video.php?id_video="+id_video,"Vidéo",'width=50,height=50,scrollbars=yes');
}

// ouvre un zoom sur une image horizontale
function openZoom(id,param) {
	window.open("image.php?id_image="+id+"&type="+param,"Zoom",'width=400,height=400,scrollbars=no');
}

// ouvre un zoom sur une image verticale
function openZoom2(id,param,num) {
	window.open("image2.php?id_image="+id+"&type="+param+"&num="+num,"Zoom",'width=400,height=400,scrollbars=no');
}

// lien pour voir toutes les associations
function toutAssociation() {
	location.href="index.php?Rub=112&AA=1";
}

// accede à une demarche par la liste déroulante de bas de page
function ChangeBasDemarche() {
	if (document.form_bas_service.select_bas_service.value!=0) {
		location.href = document.form_bas_service.select_bas_service.value;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
 
 function openwindows() 
{ 
    window.open("ipage.html", "", "width=460,height=150,scrollbars=0,left=" + ((screen.width - 460)/2) + ",top=" + ((screen.height - 150)/2) ) 
} 
