function creerFenetrePubli(jours) {
 window.open('index2.php?special=publi_jour&jours='+jours,'nav_win','toolbar=no,location=no,directories=no,status=yrd,menubar=no,scrollbars=yes,resizable=yes,width=240,height=440');
}

function creerFenetreRecherche() {
	var champ_rech = '';
	if(document.getElementById('rech_champ')) champ_rech=document.getElementById('rech_champ').value;
 window.open('index2.php?special=recherche_site&motsclef='+champ_rech,'nav_win','toolbar=no,location=no,directories=no,status=yrd,menubar=no,scrollbars=yes,resizable=yes,width=700,height=350');
}

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.0
  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 && document.getElementById) x=document.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 creerDossier(profondeur) {
 if(profondeur == '3')
 {
  alert("Vous ne pouvez pas créer un dossier dans une sous rubrique !");
 }
 else
 {
  document.location.replace('index.php?section=navigation&action=dossier_ajout');
 }
}

function supprDossier(id, titre) {
 if(id == '')
 {
  alert("Vous ne pouvez pas supprimer le dossier racine !");
 }
 else
 {
  if(confirm("Vous êtes sur le point de supprimer le dossier '" + titre + "'.\nAttention, tout son contenu sera supprimé, et vous ne pourrez pas revenir en arrière.\nVoulez-vous continuer ?"))
  {
   document.location.replace('index.php?section=navigation&action=dossier_suppr&id='+id);
  }
 }
}

function modifDossier(id) {
 if(id == '')
 {
  alert("Vous ne pouvez pas modifier le dossier racine !");
 }
 else
 {
  document.location.replace('index.php?section=navigation&action=dossier_modif&id='+id);
 }
}

function deplaDossier(id) {
 if(id == '')
 {
  alert("Vous ne pouvez pas déplacer le dossier racine !");
 }
 else
 {
  document.location.replace('index.php?section=navigation&action=dossier_depla&id='+id);
 }
}

function copierUrl(adresse) {
 holdtext.value = adresse;
 Copier = holdtext.createTextRange();
 Copier.execCommand("Copy");
}

					
	function copierUrl2(meintext)
	{
	
	 if (window.clipboardData) 
	   {
	   // the IE-manier
	   window.clipboardData.setData("Text", meintext);
	    alert ('L\'URL a bien été copié dans le presse papier.');
	   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
	   // het is mij echter onbekend vanaf welke versie dit precies werkt:
	   }
	   else if (window.netscape) 
	   { 
	   alert('Votre navigateur ne supporte pas cette fonctionnalité.');
	   if(2==1)
	   {
	   // dit is belangrijk maar staat nergens duidelijk vermeld:
	   // you have to sign the code to enable this, or see notes below 
	   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
	   
	   // maak een interface naar het clipboard
	   var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
	   if (!clip) return;
	   
	   // maak een transferable
	   var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
	   if (!trans) return;
	   
	   // specificeer wat voor soort data we op willen halen; text in dit geval
	   trans.addDataFlavor('text/unicode');
	   
	   // om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig   om het in op te slaan
	   var str = new Object();
	   var len = new Object();
	   
	   var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
	   
	   var copytext=meintext;
	   
	   str.data=copytext;
	   
	   trans.setTransferData("text/unicode",str,copytext.length*2);
	   
	   var clipid=Components.interfaces.nsIClipboard;
	   
	   if (!clip) return false;
	   
	   clip.setData(trans,null,clipid.kGlobalClipboard);
	  	}
	   
	   }
	  
	   //return false;
	}


function EnvoiMailInterne(mail,id_user,titre,corps)
{
var popvisu=window.open('index.php?special=messagerie_popup&mail_to='+mail+'&mail_int='+id_user+'&mail_subject='+titre+'&mail_body='+corps+' ','popvisu','width=550,height=560,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');popvisu.focus();
}

function EnvoiNotification(dossier_nav,id_page)
{
var popvisu=window.open('index.php?dossier_nav='+dossier_nav+'&special=messagerie_notif&dossier_notif='+dossier_nav+'&page_notif='+id_page+'','popvisu','width=800,height=800,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');popvisu.focus();
}

// Les fonctions suivantes servent à activer la barre de défilement horizontale des onglets
// au cas où le nombre de ces derniers est trop important.

var activeScroll = false;
var objDiv;


function resizeDivToolBar(nbTabs)
{
	// la variable tabWidth est la largeur en pixels d'un onglet de navigation
	// pour le moment elle est fixée en attendant de trouver une solution qui
	// puisse récuperer cette valeur automatiquement (avec getimagesize ?)
	var tabWidth = 95;
	
	// idem que tabWidth mais largeur totale du menu à gauche
	var menuWidth = 116;
	
	if(document.getElementById("divToolBar"))
	{
		if(navigator.appName=='Netscape')
			objDiv = document.getElementById("divToolBar");
		else
			objDiv = divToolBar.style;
		
		scrWidth = document.body.clientWidth - menuWidth;
	
		if(scrWidth < nbTabs*tabWidth)
			activeScroll = true;
		else
			activeScroll = false;
	
		objDiv.width = scrWidth + 'px';
	}
}

function mouseOverToolBar()
{
	//alert(objDiv.style.overflow);
	if(activeScroll)
		if(navigator.appName=='Netscape')
			objDiv.style.overflow='-moz-scrollbars-horizontal';
		else
			objDiv.overflowX='scroll';
}

function mouseOutToolBar()
{
	if(activeScroll)
		if(navigator.appName=='Netscape')
			objDiv.style.overflow='hidden';
		else
			objDiv.overflowX='hidden';
}

function popupcentreGeneral(adresse, nomFenetre, largeur, hauteur, scroll) 
{
				  var largeurEcran = (screen.width - largeur) / 2;
				  var hauteurEcran = (screen.height - hauteur) / 2;
				  var pop = window.open(adresse, nomFenetre, 'height=' + hauteur + ', width=' + largeur + ', top=' + hauteurEcran + ', left=' + largeurEcran + ', scrollbars=' + scroll + ', resizable')
						pop.focus();
}


				
function VoirGroupes(intranet_url)
{
					popupcentreGeneral(intranet_url+'index.php?special=affiche_groupe_contextuel','afficheGroupe',300,450,'yes');
}

function VoirMembresEE(intranet_url,paramsEE)
{
					popupcentreGeneral(intranet_url+'index.php?special=affiche_ee_contextuel'+paramsEE,'afficheEE',300,450,'yes');
}


function MM_jumpMenu(targ,selObj,restore)
{
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function AjoutFavori() 
{
	if (navigator.appVersion.indexOf("Mac",0)>0) 
	{
		alert("Cette fonctionnalité n\'est pas compatible Macintosh.\n\nIl faut utiliser la combinaison de touches \"Pomme-D\"");
	}
	else {
		if ((navigator.appName.indexOf("Microsoft",0)>=0) && (parseInt(navigator.appVersion)>=4)) 
		{
			window.external.AddFavorite(location.href, document.title);
		} 
		else 
		{
			alert("Cette fonctionnalité  est uniquement compatible avec Internet Explorer 4 ou supérieur\n\nPour Netscape, Mozilla, ou Firefox, il faut utiliser la combinaison de touches \"Ctrl+D\"");
		}
	}
}

function popupcentre(adresse, nomFenetre, largeur, hauteur, scroll) 
{
  var largeurEcran = (screen.width - largeur) / 2;
  var hauteurEcran = (screen.height - hauteur) / 2;
  var pop = window.open(adresse, nomFenetre, 'height=' + hauteur + ', width=' + largeur + ', top=' + hauteurEcran + ', left=' + largeurEcran + ', scrollbars=' + scroll + ', resizable')
		pop.focus();
}


function Credits()
{
	popupcentre('http://xtek.iut2.upmf-grenoble.fr/design_commun/php/credits.php?param=w','credits',1016,657,'yes');
}

function copy_clip(meintext)
{
	if (window.clipboardData) 
	{
		// the IE-manier
		window.clipboardData.setData("Text", meintext);
		alert ('L\'URL a bien été copié dans le presse papier.');
		// waarschijnlijk niet de beste manier om Moz/NS te detecteren;
		// het is mij echter onbekend vanaf welke versie dit precies werkt:
	}
	else if (window.netscape) 
	{ 
		alert('Votre navigateur ne supporte pas cette fonctionnalité.');
		if(2==1)
		{
			// dit is belangrijk maar staat nergens duidelijk vermeld:
			// you have to sign the code to enable this, or see notes below 
			netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
			
			// maak een interface naar het clipboard
			var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
			if (!clip) return;
			
			// maak een transferable
			var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
			if (!trans) return;
			
			// specificeer wat voor soort data we op willen halen; text in dit geval
			trans.addDataFlavor('text/unicode');
			
			// om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig   om het in op te slaan
			var str = new Object();
			var len = new Object();
			
			var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
			
			var copytext=meintext;
			
			str.data=copytext;
			
			trans.setTransferData("text/unicode",str,copytext.length*2);
			
			var clipid=Components.interfaces.nsIClipboard;
			
			if (!clip) return false;
			
			clip.setData(trans,null,clipid.kGlobalClipboard);
		}
	}
//return false;
}
//-->
function toggleMenu(idMenu)
{
	var idDiv = "menu_"+idMenu;
	var idInter="menu_intercalaire_"+idMenu;
	collapseAll()
	if(document.getElementById(idDiv).style.display == "none")
	{
		
		document.getElementById(idDiv).style.display = "block";
		document.getElementById(idInter).className ="menu_intercalaire_select";
	}
	else 
	{
		document.getElementById(idDiv).style.display = "none";
		document.getElementById(idInter).className ="menu_intercalaire";
	}
}

function creerFenetreRechercheOld()
{
	
	window.open('index.php?special=recherche_site&motsclef='+champ_rech,'nav_win','toolbar=no,location=no,directories=no,status=yrd,menubar=no,scrollbars=yes,resizable=yes,width=700,height=350');
}

function VerifRecherche()
{
	var touche = window.event.keyCode;
	if(touche==13)
	{
		creerFenetreRecherche();
	}
}

function ddlLiensDirectsIndexChanged()
{
	var ddl = document.getElementById('ddlLientsDirects');
	document.location.replace('/'+ddl.options[ddl.selectedIndex].value);
}

function EnvoiSuggestion()
{
	var popvisu=window.open('index.php?special=messagerie_notif&suggestion_webmestre=1','popvisu','width=600,height=450,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');popvisu.focus();
}

function Recommandation()
{
	var popvisu=window.open('index.php?special=messagerie_notif','popvisu','width=600,height=400,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1');popvisu.focus();
}	



function ValiderAnnuaireSelection()
{
		document.form_liste.action.value = 'valider_annuaire';
		document.form_liste.submit();
}


function ValiderAnnuaireFiche(id)
{
		document.location.replace('index.php?action=valider_annuaire&id='+id);
		
}

function ValidAnnuaireFormNavigation(booleanLogin)
{

if(booleanLogin==1){
	if(document.form_dossier.annuaire_generer_login.checked==true && document.form_dossier.annuaire_masque_champ_nom.value=='')
	{
		alert("Vous devez choisir un champ Nom !");
		return false;
	}
	if(document.form_dossier.annuaire_generer_login.checked==true && document.form_dossier.annuaire_masque_champ_prenom.value=='')
	{
		alert("Vous devez choisir un champ Prénom !");
		return false;
	}
	if(document.form_dossier.annuaire_generer_login.checked==true && document.form_dossier.annuaire_masque_champ_email.value=='')
	{
		alert("Vous devez choisir un champ Email !");
		return false;
	}
	if(document.form_dossier.annuaire_format_login_prefixe)
		if(document.form_dossier.annuaire_format_login[3].value=='3' && document.form_dossier.annuaire_format_login_prefixe.value=='')
		{
			alert("Vous devez préciser un préfixe pour le login");
			return false;
		}

	var i=0;
	var profilOk=0;
       while( document.getElementById('profil'+i) && i<200)
	{
		if(document.getElementById('profil'+i).checked==true) {
		profilOk=1;	
		
	
		}
			i++;
	}

	
	if(profilOk==0){
		alert("Vous devez préciser au moin un profil");
		return false;	
	}
}

}


function masqueTriggerVisibiliteChampSuivant(name_champ_trigger,id_champ_cache,valeur_trigger)
{
	var value_champ_trigger = document.getElementsByName(name_champ_trigger)[0].value;
	var id_champ_cache = 'table_trigger_'+id_champ_cache;
	if(value_champ_trigger==valeur_trigger) document.getElementById(id_champ_cache).style.display = 'block';
	else document.getElementById(id_champ_cache).style.display = 'none';
	
}


function textareaLimit(field, maxlen) 
{
	if (field.value.length > maxlen + 1)
	alert('Le texte saisi est trop long. Il sera tronqué à '+maxlen+' caractères.');
	if (field.value.length > maxlen)
	field.value = field.value.substring(0, maxlen);
}


function siToucheEntreePressee(event,func)
{
        if(event.keyCode == 13) func();
}



