// Document
function MM_OnLoadTitreDocument()
{
	// alert("MM_OnLoadTitreDocument")
	// Mise à jour de l'état des objets de navigation
	MM_SetToolBarreState('navDoc')
	if (MM_IsMaximized() == true)
	{
		MM_showHideLayers('minmax','','hide')
	}
	else
	{
		MM_showHideLayers('minmax','','show')
	}
}

function MM_OnLoadDocument()
{
	// alert("MM_OnLoadDocument")
	// Déplacement vers le target
	if (strCurrentTargetID != "")
	{
		MM_ScrollAnchor(strCurrentTargetID);
	}
	
	if (FormDocument && FormDocument.IMPRIME_DOC)
	{
		if (FormDocument.IMPRIME_DOC.value=="TRUE")
		{
			print();
			close();
		}
	}
}

function MM_OnLoadDocumentLexique()
{
	// alert("MM_OnLoadDocumentLexique")
	// Pas de déplacement vers le target pour éviter ce déplacement sur un back
}

// Affichage du document d'identifiant 'strUD_ID' à la page 'strPage' sur la cible 'strTargetID'
//
//	si iCurrentPage = -1 alors les documents sont affichés en entier
//	sion un document est découpé en page
//
function MM_AfficherDocument(strUD_ID, strPage, strTargetID)
{
	// alert("MM_AfficherDocument " + strUD_ID)
	
	var iPage
	strPage = MM_ParsetoInt(strPage)
	if (strPage != "") iPage = parseInt(strPage)
	if (!strTargetID) strTargetID=""

	// alert("MM_AfficherDocument " + "\n strUD_ID : " + strUD_ID + "\n strPage : " + strPage + "\n strTargetID : " + strTargetID)
	
	if (strUD_ID)
	{
		if (strTargetID != "")
		{
			if (strUD_ID == strCurrentUD_ID && (iCurrentPage == -1 || iPage == iCurrentPage) )
			{
				// Lien vers une ancre
				MM_GotoAnchor(strTargetID)
				return
			}
		}
	
		var FormDocument=MM_findObj("FormDocument")

		FormDocument.POSITION_DOC.value=""
		FormDocument.ACTION.value=""
		FormDocument.UD_ID.value=strUD_ID
		FormDocument.PAGE_NUME.value=strPage
		FormDocument.FILE.value="FrameDocument.html"
		FormDocument.TARGET_ID.value=strTargetID
		
		FormDocument.target="FrameClient"
		var FrameDocument=MM_findFrm("FrameDocument",top)
		if (FrameDocument)
		{
			FormDocument.target="FrameDocument"
		}
				
		// Application
		FormDocument.submit()
	}
}

function MM_AfficherBOIComplet(strUD_ID)
{
	// alert("MM_AfficherBOIComplet")

	var FormDocument=MM_findObj("FormDocument")

	FormDocument.POSITION_DOC.value=""
	FormDocument.ACTION.value="d"
	FormDocument.UD_ID.value=strUD_ID
	FormDocument.PAGE_NUME.value="ALL"
	FormDocument.FILE.value=""
	FormDocument.TARGET_ID.value=''
	FormDocument.target="FrameBOIComplet"
	FormDocument.IMPRIME_DOC.value="TRUE"

	// Application
	FormDocument.submit()
	FormDocument.ACTION.value=""
	FormDocument.target=""
	FormDocument.PAGE_NUME.value=""
	FormDocument.IMPRIME_DOC.value="FALSE"
}

// Affichage du document à la position strPosition
// strPosition désigne une valeur de 0 à n par rapport au résultat courant
function MM_AfficherDocumentPosition(strPosition, strPage, strTargetID)
{
	var FormDocument=MM_findObj("FormDocument")
	var iPage
	strPage = MM_ParsetoInt(strPage)
	if (strPage != "") iPage = parseInt(strPage)
	if (!strTargetID) strTargetID=""
	

	// alert("MM_AfficherDocumentPosition " + "\n strCurrentPosition : " + strCurrentPosition + "\n strPage : " + strPage + "\n strTargetID : " + strTargetID)
	
	if (strTargetID != "")
	{
		// alert("\nstrCurrentPosition " + strCurrentPosition + "\niCurrentPage " + iCurrentPage)
		if (strPosition == strCurrentPosition && (iCurrentPage == -1 || iPage == iCurrentPage) )
		{
			// Lien vers une ancre
			MM_GotoAnchor(strTargetID)
			return
		}
	}
	
	FormDocument.ACTION.value=""
	FormDocument.POSITION_DOC.value=strPosition
	FormDocument.PAGE_NUME.value=strPage
	FormDocument.FILE.value="FrameDocument.html"
	FormDocument.TARGET_ID.value=strTargetID
		
	FormDocument.target="FrameClient"
	FrameDocument=MM_findFrm("FrameDocument",top)
	if (FrameDocument)
		FormDocument.target="FrameDocument"

	// Application
	FormDocument.submit()
}

// Affichage d'un lien
//
//	si le lien est intrene au document
//		alors si le document fait partie de la recherche
//				alors on affiche le document par position (résultat d'un recherche)								
//	sinon
//		on affiche le document par identifiant : on pert la notion de recherche courante
function MM_AfficherLien(strUD_ID, strPage, strTargetID)
{
	if (strUD_ID == strCurrentUD_ID && strCurrentPosition != "")
	{
		// le document a afficher est le document courant et résultat de la recherche
		MM_AfficherDocumentPosition(strCurrentPosition, strPage, strTargetID)
	}
	else
	{	
		// On affiche le document par identifiant
		MM_AfficherDocument(strUD_ID, strPage, strTargetID)
	}
}


// Affichage du document courant à la page 'strPage'
function MM_AfficherPage(strPage)
{
	if (strPage)
	{
		var FormDocument=MM_findObj("FormDocument")
	
		FormDocument.ACTION.value=""
		FormDocument.PAGE_NUME.value=strPage
		FormDocument.UD_ID.value=strCurrentUD_ID
		FormDocument.FILE.value="FrameDocument.html"
	
		FormDocument.target="FrameClient"
		FrameDocument=MM_findFrm("FrameDocument",top)
		if (FrameDocument)
			FormDocument.target="FrameDocument"
		
		// Application
		FormDocument.submit()
	}
}

//
// Déplacement sur une ancre : simple déplacement vers une ancre sans sauvegarde dans l'historique
//
//	Pour Netscape, il faut aussi parcourir des documents des layers
//
function MM_ScrollAnchor(strTargetID)
{
	// alert("MM_ScrollAnchor " + strTargetID)

	// Recherche dans le document de base
	if (MM_ScrollAnchor2(document,strTargetID)) return true;
	if (document.all) return false;
		
	// Recherche dans les layers
	for(i=0;document.layers&&i<document.layers.length;i++)
	{
		d=document.layers[i].document
		if (MM_ScrollAnchor2(d,strTargetID)) return true
	}
	return false
}
	
function MM_ScrollAnchor2(d, strTargetID)
{
	iSize=d.anchors.length
	
	i=0
	while(i < iSize)
	{
		if(d.anchors[i].name==strTargetID)
		{
			iScrollPos=-1
			iScrollPos = MM_FindPosY(d.anchors[i])
			
			/*
			if (d.all)
			{
				iScrollPos=d.anchors[i].offsetTop
				// alert(d.anchors[i].offsetParent.tagName)
				// alert('iScrollPos ' + iScrollPos)
				if (iScrollPos == -1)
				{
					// Utilisation du location.hash
					MM_GotoAnchor(strTargetID);
					return true
				}
			}
			else
				iScrollPos=d.anchors[i].y
			*/
			if(iScrollPos != -1)
			{
				window.scroll(0,iScrollPos);
				return true
			}
		}
		i=i+1
	}
	return false
}
	
//
// Déplacement sur une ancre : seconde version
//
function MM_SetLocationHash(strUD_ID, strTargetID)
{
	// alert("MM_SetLocationHash strUD_ID=" + strUD_ID + " strTargetID=" + strTargetID)
	
	// Contrôle que le document actuel est bien celui visé
	var FormDocument=MM_findObj("FormDocument");
	if (FormDocument && strUD_ID != "")
	{
		if (FormDocument.UD_ID.value != strUD_ID) return false;
	}
	
	var iSize=document.anchors.length
	var bFind=false;
	
	i=0
	while(i < iSize)
	{
		if (document.anchors[i].name==strTargetID)
		{
			bFind=true;
			break;
		}
		i++;
	}
	
	if (bFind == true)
	{
		window.location.hash=strTargetID
	}
	return bFind 
}
	
//
//	Méthodes de déplacement de HIT en HIT
//
//

// Détermine la position Haute de la page dans le Browser
function MM_GetPageTop()
{	var pageTop
	if (!document.all) {pageTop=window.pageYOffset}
	else {pageTop=document.body.scrollTop}
	return pageTop
}

// Détermine la position Base de la page dans le Browser
function MM_GetPageBottom()
{	var pageBottom
	if (!document.all) {pageBottom=window.pageYOffset+window.outerHeight}
	else {pageBottom=document.body.scrollTop+document.body.clientHeight}
	return pageBottom
}

// Déplacement au premier hit de la page
function MM_GotoFirstHit()
{
	// alert("MM_GotoFirstHit")	
	iSize=document.anchors.length
	i=0
	while(i < iSize)
	{
		if (document.all)
		{
			iScrollPos=document.anchors[i].offsetTop;
		}	
		else
		{
			iScrollPos=document.anchors[i].y;
		}

		var bHit = ( document.anchors[i].name.indexOf("HIT") == 0)

		if(bHit)
		{
			// Utilisation du location.hash
			MM_GotoAnchor(document.anchors[i].name);
			return true;
		}
		i=i+1
	}
}
			
// Déplacement à la page suivante qui contient un HIT
function MM_GotoNextHit()
{
	// alert("MM_GotoNextHit")	
	var pageBottom=MM_GetPageBottom()
	iSize=document.anchors.length
	i=0
	while(i < iSize)
	{
		if (document.all)
		{
			iScrollPos=document.anchors[i].offsetTop;
			if (iScrollPos == -1)
			{
				// Utilisation du location.hash
				MM_GotoAnchor(document.anchors[i].name);
				return true;
			}
		}	
		else
		{
			iScrollPos=document.anchors[i].y;
		}

		var bHit = ( document.anchors[i].name.indexOf("HIT") == 0)

		if(iScrollPos > pageBottom && bHit)
		{
			window.scroll(0,iScrollPos);
			break					
		}
		i=i+1
	}
}

// Déplacement à la page précédente qui contient un HIT
function MM_GotoPrevHit()
{
	var pageTop=MM_GetPageTop()
	iSize=document.anchors.length
	i=iSize-1
	while(i >= 0)
	{
		if (document.all)
			iScrollPos=document.anchors[i].offsetTop
		else
			iScrollPos=document.anchors[i].y

		if(iScrollPos < pageTop && document.anchors[i].name=="HIT")
		{
			window.scroll(0,iScrollPos);
			break				
		}
		i=i-1
	}
}

// Appelle d'un image dans une page HTML
function MM_OpenImageFile(strFileName)
{
	var FormDocument=MM_findObj("FormDocument")
	if (FormDocument && strFileName)
	{
		window.open(strFileName,"ImageView","status=no,location=no,directorie=no,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,width=700,height=400");	
	}
}

//
//	Convertir 000NNN en un int NNNN
//
function MM_ParsetoInt(strNume)
{
	// alert("MM_ParsetoInt strNume " + strNume)
	if(strNume)
	{
		var iLen = strNume.length
		var i=0
		if (strNume.indexOf('0',0)==0)
		{
			var strNume2 = strNume.substr(1,iLen - i);
			return MM_ParsetoInt(strNume2);
		}
		return strNume;
	}
	else
	{
		return ""
	}
}

// Affichage de la boite d'information sur la recherche courante
function MM_AfficherRechercheInfo()
{
	var FormDocument=MM_findObj("FormDocument")
	
	var strUrl = FormDocument.action + "?"
	strUrl += "CONTEXT=" + FormDocument.CONTEXT.value;
	strUrl += "&TYPE_RECH=" + FormDocument.TYPE_RECH.value;
	strUrl += "&SECTION_CONF=" + FormDocument.SECTION_CONF.value;
	strUrl += "&ACTION=CO";
	strUrl += "&TOC_ID_SEL_TITRE=" + FormDocument.TOC_ID_SEL_TITRE.value;
	strUrl += "&NUM_SECTION_COLLECTION=" + FormDocument.NUM_SECTION_COLLECTION.value;	
	
	open(strUrl,"RechercheInfo","status=no,location=no,directorie=no,resizable=yes,scrollbars=no,menubar=no,toolbar=no,width=500,height=350")
	
	
	/*
	FormHitListSecondNiv.ACTION.value="O";
	FormHitListSecondNiv.target="RechercheInfo";
	FormHitListSecondNiv.submit();
	*/
}		

// Fonction de Maximisation / Minimisation
function MM_Minimiser()
{
	if (MM_IsMaximized())
	{
		var FormDocument=MM_findObj("FormDocument")
		FormDocument.ACTION.value=""
		var FrameFileName=""
		
		switch (FormDocument.TYPE_RECH.value)
		{
			case 'FULL_TEXTE':
				FrameFileName="FrameHitListDoc.html";
				break;
			case 'TM':
				FrameFileName="FrameTableMatDoc.html";
				break;
			case 'TI':
				FrameFileName="FrameTableIndexDoc.html";
				break;
		}
		
		if (FrameFileName != "")
		{
			FormDocument.FILE.value=FrameFileName
			FormDocument.submit()
		}
	}
	else
	{
		FrameClient=MM_findFrm("FrameClient",top)
		if (FrameClient)
		{
			FrameDocument=MM_findFrm("FrameDocument",top)
			if (FrameDocument)
			{
				FrameClient.location = FrameDocument.location
			}
		}
	}
}
	
// Fonction de Suppression
function MM_Supprimer()
{
	if (MM_IsMinimized())
	{
		FrameList=MM_findFrm("FrameList",top)
		if (FrameList && FrameList.MM_Maximiser)
		{
			FrameList.MM_Maximiser()
		}
	}
	else
	{
		var FormDocument=MM_findObj("FormDocument")
		if(FormDocument)
		{

			FormDocument.target="FrameClient"
			FormDocument.FILE.value="Acceuil.html"
			FormDocument.TYPE_RECH.value=""
			FormDocument.SECTION_CONF.value=""
			FormDocument.ACTION.value=""
			
			FormDocument.submit()
		}
	}
}

function MM_FindPosX(obj)
{
	var curleft = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curleft += obj.x;
	return curleft;
}

function MM_FindPosY(obj)
{
	var curtop = 0;
	if (document.getElementById || document.all)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (document.layers)
		curtop += obj.y;
	return curtop;
}

// Affiche du masque BOI à la position de l'ancre BOI
function MM_MoveAndShowBOI()
{
	for (i=0; i < document.anchors.length; i++)
	{
		if (document.anchors[i].name=="AncreBOI")
		{
			x = MM_FindPosX(document.anchors[i]);
			y = MM_FindPosY(document.anchors[i]);
			
			MM_MoveDiv('BOI',x,y-20)
			MM_showHideLayers('BOI','','show')
					
			break;
		}
	}
}	

// Appelle d'un image dans une page HTML
function MM_OpenImage(strImageID)
{
	var FormDocument=MM_findObj("FormDocument")
	if (FormDocument && strImageID)
	{
		var strUrl=	FormDocument.action + "?";
		strUrl +="IMAGE_ID=" + strImageID;
		strUrl +="&FILE=FrameVisualiseurImage.html";
		strUrl +="&CONTEXT=" + FormDocument.CONTEXT.value;
		// window.open(strUrl);	
		
		MM_openBrWindow(strUrl,'VisualiseurImage','scrollbars=yes,width=800,height=600,resizable');
	}
}

function MM_Print()
{
	FrameCorpsDocument = MM_findFrm("FrameCorpsDocument",top);
	if (FrameCorpsDocument)
	{
		FrameCorpsDocument.focus()
		FrameCorpsDocument.window.print()	
	}
}

// Fonction d'affichage des annotations dans une popup
function MM_AfficherAnnotationPopup(strIDAnnotation, srtLibAnnotation)
{
	// alert('MM_AfficherAnnotationPopup strIDAnnotation=' + strIDAnnotation)
	// Suppression du Prefixe ann
	var FormDocument=MM_findObj("FormDocument")
	if (FormDocument && strIDAnnotation)
	{
		var strUrl=FormDocument.action + "?";
		strUrl +="ACTION=d";
		strUrl +="&REF_ID=" + strIDAnnotation;
		strUrl +="&SUFFIXE_DOC=annotation";
		strUrl +="&CONTEXT=" + FormDocument.CONTEXT.value;
		strUrl +="&LIB_ANN=" + srtLibAnnotation;
		
		// alert(strUrl)
		var window_Annotation = window.open(strUrl,'Annotations','scrollbars=no,width=240,height=80')
		if (window_Annotation)
		{
			window_Annotation.focus()
		}
	}
}
