function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i>(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}

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_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 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_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// def par défaut
IsUM=0;

function selfprint() {
	// uniquement IE PC
	isMac = (navigator.appVersion.indexOf("Mac") != -1) ? 1 : 0;
	if(document.all && document.all["selfcontenu"] && !isMac && window.print)
		{	//nb: si on veut appliflash imprimé: width min=1 et timeout / print ++
			if(IsUM==1)
			{	letps=1000;	
				document.body.insertAdjacentHTML("beforeEnd", "<iframe name=printHiddenFrame width=0 height=0 src='impression.html'></iframe>");	}
			else
			{	letps=100;
				document.body.insertAdjacentHTML("beforeEnd", "<iframe name=printHiddenFrame width=0 height=0></iframe>");}
			// evite fond du body si existe
			setTimeout("printHiddenFrame.document.body.style.background =\"url(vide.gif)\"",letps)
			// contenu
			setTimeout("printHiddenFrame.document.body.innerHTML=document.all[\"selfcontenu\"].innerHTML",letps)
			// css
			setTimeout("cssprint()",letps)
			// qd publié, var nom = menu (par stats)
			if(self.nom)
			{	setTimeout("printHiddenFrame.document.title=self.nom",letps)	}
  			setTimeout("printHiddenFrame.focus()",letps)
  			setTimeout("printHiddenFrame.print()",letps)
			setTimeout("printHiddenFrame.outerHTML = ''",letps)
		}
	else
	{	if(window.print)
		{	window.print()	}
		else
		{	alert("Fonction non disponible.\nUtilisez le bouton 'Imprimer' de votre navigateur")	}
	}
}
function cssprint()
{	for(i=0;i<document.styleSheets.length;i++)
		{	//recup style titre,texte,sstitre...
					printHiddenFrame.document.createStyleSheet()
					printHiddenFrame.document.styleSheets[i].cssText=document.styleSheets[i].cssText
		}
}

function openurl(url,nom,spec)
{ window.open(url,nom,spec)
}

// fct de formulaire pour afficher des menus déroulant en cascade
function CreerObjChamp(nomChp,tabTxt,tabVal,tabParent,tabFils)
{	this.nom=nomChp;	//** nom du champ : Cxxxx
	this.tabTxt=tabTxt
	this.tabVal=tabVal
	this.tabParent=tabParent
	this.tabFils=tabFils
	return this
}
function cascade_ecriremenu(objChampEnCours,valeurParent,leform)	// ecrit les options du menu définit par indice
{	var nomChamp,indiceOptions
	nomChamp=objChampEnCours.nom
	if(leform.elements[nomChamp])	// uniquement si le chp existe (n'existe pas : cas ou ds mdr-> pas tout les chps de cascade)
	{
		leform.elements[nomChamp].options.length=1;	// reinit nb elt
		leform.elements[nomChamp].options[0].text="Selectionnez..."
		leform.elements[nomChamp].options[0].value=""
		indiceOptions=1
		
		for(i=0;i<objChampEnCours.tabTxt.length;i++)	// pour chaque choix du champ enfant
		{	if(objChampEnCours.tabParent[i]==valeurParent)	// uniquement les choix lié au parent par iddossier
			{	leform.elements[nomChamp].options.length++	
				leform.elements[nomChamp].options[indiceOptions].text=objChampEnCours.tabTxt[i]
				leform.elements[nomChamp].options[indiceOptions].value=objChampEnCours.tabVal[i]
				indiceOptions++
			}
		}
		if(indiceOptions==1)	// aucun choix
		{	leform.elements[nomChamp].options[0].text="-"
			leform.elements[nomChamp].options[0].value=""
		}
	}	
}	


function cascade_retrouveChamp(tabListeChamp,nomChamp)
{	// retrouve un champ par son nom dans liste des chp dispo pour ce form
	var i,objChamp
	for(i=0;i<tabListeChamp.length;i++)
	{	objChamp=tabListeChamp[i]
		if(objChamp.nom==nomChamp)
		{	return 	objChamp	
		}
	}
}
function cascade_parcoursCascade(objChampEnCours,valSelection,tabListeChamp,leform,isParentInitial)
{	var i,objChamp
	if(!isParentInitial)
	{	cascade_ecriremenu(objChampEnCours,valSelection,leform)	// que si pas parent initial, cad chp appelant
	}
	// met à jour chaque enfant
	for(i=0;i<objChampEnCours.tabFils.length;i++)	
	{	objChamp=cascade_retrouveChamp(tabListeChamp,objChampEnCours.tabFils[i])
		cascade_parcoursCascade(objChamp,valSelection,tabListeChamp,leform,0)
	}
}
function cascade(objMenuEnCours,idbloc)
{	var leform,valSelection,objChamp,tabListeChamp;
	leform=document.forms["form"+idbloc];
	tabListeChamp=eval("tabListeChp"+idbloc)	// table des champs pour ce form
	objChamp=cascade_retrouveChamp(tabListeChamp,objMenuEnCours.name)	// recherche chp en cours
	valSelection=parseInt(objMenuEnCours.options[objMenuEnCours.selectedIndex].value)	// valeur du chp en cours
	cascade_parcoursCascade(objChamp,valSelection,tabListeChamp,leform,1)	// lance cascade		
}

function setContentEditeur(strNom,valDef){
	var oEditor=FCKeditorAPI.GetInstance('FCKeditor'+strNom);
	valDef=unescape(valDef);
	oEditor.SetHTML(valDef);
}
function form_initchp(valDef,intType,strNom,idBloc,isCascade)
{	var objChp,i,j,tab_valdef
	if(intType==0 ||intType==1 || intType==13)
		{	// modif knb 28/01/08 : vérifie si type fck	
			if(eval('window.FCKeditor'+strNom+'___Frame')){	// utilisation de window.xx car ne génère pas d'erreur si undefined !
				// FCKeditorAPI pas encore créé... donc on patiente un peu... mais on sait qu'il va exister !
				valDef=escape(valDef);
				setTimeout("setContentEditeur('"+strNom+"','"+valDef+"')",1000);
			}
			else
			{	
				objChp=eval("document.forms['form"+idBloc+"'].param"+strNom);
				objChp.value=valDef;
			}
		}
	else if(intType==7)
		{	objChp=eval("document.forms['form"+idBloc+"'].param"+strNom+"_valdef")
			objChp.value=valDef
		}
	else if(intType==2 ||intType==3)
		{	objChp=eval("document.forms['form"+idBloc+"'].param"+strNom)	
			tab_valdef=valDef.split(',');
			for(j=0;j<tab_valdef.length;j++)
			{	for (i=0;i<objChp.length;i++)
				{	if(objChp[i].value==tab_valdef[j])
					{	objChp[i].checked=true	}
				}
			}
		 }	
	else if(intType==4 ||intType==5 ||intType==6 ||intType==8 ||intType==10)
		{	objChp=eval("document.forms['form"+idBloc+"'].param"+strNom);
			tab_valdef=valDef.split(',');
			for(j=0;j<tab_valdef.length;j++)
			{	for (i=0;i<objChp.options.length;i++)
				{	if(objChp.options[i].value==tab_valdef[j])
					{	objChp.options[i].selected=true	}
				}
			}
			if(isCascade>0){	cascade(objChp,idBloc)	}
		}
}
		
function glossaire(id)
{	// ouvre popup 
	MM_openBrWindow('/selfconnect/outil/visuasp/voir_defglossaire.asp?idGlossaire='+id,'glossaire','scrollbars=yes,resizable=yes,width=300,height=300')
}