// Méthodes Javascript utiles pour l'ensemble du site

//
// Recherche d'une frame nomée "fname" dans la frame "fin" et les toutes les frames filles
//	si "fin" est null recherche dans self
//
function MM_findFrm(fname,fin) { //v1.0
	if(!fin) fin=self
	var len=fin.frames.length
	fout = null
	if(len>0){	fout=fin.frames[fname];
				if(!fout){for(i=0;!fout&&i<len;i++){fout=MM_findFrm(fname,fin.frames[i])}}}
	return fout
}

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;
}

// Affiche ou cache une zone DHTML
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_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_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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Positionne physiquement un objet dans la page HTML
function MM_MoveDiv(divId,left,top,width)
{
	var div=MM_findObj(divId)
	if (div && !width && (document.all || document.getElementById)) width=div.style.width
	if (div) {if ( document.all || document.getElementById){div.style.left=left;div.style.top=top;div.style.width=width;}
	else div.moveTo(left,top)}
}


//////////////////////////////////////////////////////////////
//
//	Fonction d'affectation et récupération de la valeur d'un control dans un formulaire
//
//
function MM_GetValEdit(form,control,def)
{
	var ret="";if(def) ret=def;
	if(form&&form[control]) ret=form[control].value;
	return ret;
}

function MM_SetValEdit(form,control,val)
{
	if(form&&form[control]) form[control].value=val;
}

function MM_GetValCheck(form,control,def)
{
	var ret="off";if(def) ret=def;
	if(form&&form[control]&&form[control].checked) ret="on";
	return ret;
}

// Affect à checked à false si val="" ou val="off"
function MM_SetValCheck(form,control,val)
{
	var bool=false
	if(val!=""&&val!="off")bool=true;
	if(form&&form[control])form[control].checked=bool
}
	
function MM_GetValRadio(form,control,def)
{
	var ret="";if(def) ret=def;
	var i=0,Elem,nbElem;
	if (form){Elem=form.elements; if(Elem) nbElem=Elem.length}
	
	if (nbElem)
	while(i < nbElem)
	{if(Elem[i].name==control && Elem[i].checked){ret=Elem[i].value;break;}i++;}
	return ret;
}

// Selectionne le radio qui a pour "name" "controle" et pour "value" "val"
// Si val=="" selectionne le radio "def"
function MM_SetValRadio(form,control,val,def)
{
	if (val=="") val=def;
	var i=0,Elem,nbElem;
	if (form){Elem=form.elements; if(Elem) nbElem=Elem.length}
	
	if (nbElem)
	while(i < nbElem)
	{if(Elem[i].name==control && Elem[i].value==val){Elem[i].checked=true;break;}i++;}
}

function MM_GetValSel(form,control,def)
{
	var ret="";if(def) ret=def;
	if (form&&form[control])
	{var iSel=form[control].selectedIndex;if(iSel>=0) ret=form[control].options[iSel].value}
	return ret;
}

// Selectionne l'option qui a pour "value" "val"
// Si val=="" selectionne l'option "def"
function MM_SetValSel(form,control,val,def)
{
	if (val=="") val=def;
	if (form&&form[control]&&form[control].options)
	{
		var i=0,Options=form[control].options;
		var nbOption=Options.length;
		while(i < nbOption)
		{if(Options[i].value==val){Options[i].selected=true;break;}i++;}
	}
}

//	
//	Conversion on/off vers bool
//	et bool vers on/off
//
//		valeur "on" et "true" par défaut
//
function MM_OnOffToBool(strOnOff)
{
	if (strOnOff != null) if(strOnOff == "off") return false;     
	return true
}

function MM_BoolToOnOff(bBool)
{
	if (bBool != null){if (!bBool) return "off"}
	return "on";
}

//////////////////////////////////////////////////////////////
//
// Gestion de la tool Barre
//
var timeout_state
var timeout_secondName
function MM_SetToolBarreState(state,secondName)
{
	var href
	f=MM_findFrm("principale",top)
	if (f)
		href=f.location.href
	
	var bSetToolBarreOK=false;
	
	ToolBarreFrame=MM_findFrm("bandeau_haut",top)
	if (ToolBarreFrame)
	{
		if (ToolBarreFrame.MM_SetState)
		{
			ToolBarreFrame.MM_SetState(state,href,secondName)
			bSetToolBarreOK = true;
		}
	}
	
	if (bSetToolBarreOK == false)
	{
		timeout_state = state;
		timeout_secondName = secondName;
		window.setTimeout('MM_SetToolBarreState(timeout_state,timeout_secondName)',100);
	}
}

// Gestion de la Maximisation Minimisation
function MM_IsMinimized(FrameBase)
{
	// f=MM_findFrm("FrameDocument",top)
	var bMinimised=false

	if (window.name == "FrameList" || window.name == "FrameDocument")
	{
		bMinimised = true
	}
	else
	{
		f =	window.parent
		if (f && f.name && f.name == "FrameList")
		{
			bMinimised = true
		}
	}
	/*
	if (bMinimised)	alert("Minimized")
	else	alert("Maximized")
	*/
	return bMinimised;
}

function MM_IsMaximized(FrameBase)
{
	return !MM_IsMinimized(FrameBase)
}

//////////////////////////////////////////////////////////////
//
// Gestion retaillage sous Netscape
//
function MM_reloadPage(init) 
{  	//reloads the window if Nav4 resized
	// alert("MM_reloadPage " + window.name)
	if (init==true) with (navigator) 
	{
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
		{
			document.MM_pgW=innerWidth; 
			document.MM_pgH=innerHeight; 
			onresize=MM_reloadPage; 
		}
	} 
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

//////////////////////////////////////////////////////////////
//
// Déplacement sur une ancre avec sauvegarde dans l'historique
//
function MM_GotoAnchor(strTargetID, frame)
{
	if (!frame) frame = self
	if (strTargetID && frame)
	{
		/*
			 alert(
				"location " + window.location + "\n" +
				"location.hash " + window.location.hash + "\n" +
				"location.hostname " + window.location.hostname + "\n" +
				"location.pathname " + window.location.pathname + "\n" +
				"location.protocol " + window.location.protocol + "\n" +
				"location.search " + window.location.search + "\n"
				)
		*/
		frame.window.location.hash = strTargetID;
	}
}

