// Creer un lien
var gAnnee=""
var gCollection=""
var gParam1=""
var gParam2=""
var gArrayCollections   = new Array("CGI","CGI","BOI","DB","PDOC","PDOC","PF");
var gArrayID 		= new Array("CGI","LPF","BOI","DB","RES","PDA","PF");

function MM_OnLoadLiensProfonds()
{
	// alert("MM_OnLoadLiensProfonds")
	var FormLiensProfonds=MM_findObj("FormLiensProfonds")
	if (FormLiensProfonds)
	{
		if (FormLiensProfonds.typepage.value=="")
		{
			MM_DisplayDocument()
		}
		else
		{
			MM_DisplayPage()
		}
	}

}

function MM_IsCollectionDisponible(strCollection)
{
	// alert("MM_IsCollectionDisponible strCollection " + strCollection )
	if ( strCollection == "CGI" || strCollection == "LPF" )
	{
		if (MM_IsIntranet())
		{
			return MM_HaveCGI()
		}
		else
		{
			// Contrôle d'accès aux CGI/LPF
			return false;
		}

	}
	
	if ( strCollection == "PF" )
	{
		return MM_HavePF()
	}
	return true;
}

function MM_DispayRedirectPage()
{
	// alert("MM_DispayRedirectPage")
	var FormLiensProfonds=MM_findObj("FormLiensProfonds")
	if (FormLiensProfonds)
	{
		FormLiensProfonds.ACTION.value=""
		FormLiensProfonds.FILE.value="redirectLiensProfonds.html"
		FormLiensProfonds.submit()
	}
	
}

function MM_DispayCGINonDisponible()
{
	// alert("MM_DispayCGINonDisponible")
	var FormLiensProfonds=MM_findObj("FormLiensProfonds")
	if (FormLiensProfonds)
	{
		FormLiensProfonds.ACTION.value=""
		FormLiensProfonds.FILE.value="CGINonDisponible.html"
		FormLiensProfonds.submit()
	}
	
}
			
function MM_DisplayDocument()
{
	var FormLiensProfonds=MM_findObj("FormLiensProfonds")
	if (FormLiensProfonds)
	{
		strRefId="X"
		strCollection=FormLiensProfonds.collection.value
		strArticle=FormLiensProfonds.article.value
		strNiveau=FormLiensProfonds.niveau.value
		strNumero=FormLiensProfonds.numero.value
		strAnnee=FormLiensProfonds.annee.value
		
		strUpperCollection=strCollection.toUpperCase();
		strReelCollection=MM_GetReelColection(strUpperCollection)
		
		// Mise à jour de l'état des objets de navigation
		MM_SetToolBarreState('navAcc')
		MM_SetToolBarreState('navSel')
		
		// Contrôle si la collection est disponible
		if (MM_IsCollectionDisponible(strReelCollection) == false)
		{
			// Contrôle d'accès aux CGI/LPF
			if (MM_IsInternet() && (strCollection == "CGI" || strCollection == "LPF") )
			{
				MM_DispayCGINonDisponible()
				return
			}
			
			// autres collections
			MM_DispayRedirectPage()
			return 
		}

		bURLOk=false
		if (MM_ExistCollection(strReelCollection))
		{
			strRefId+=strCollection
			if (strReelCollection == "CGI" || strReelCollection == "LPF")
			{
				if (strArticle.length)
				{
					strRefId+=strArticle
					bURLOk=true
				}
			}
			else if (strReelCollection == "BOI")
			{
				if (strNumero.length)
				{
					strRefId+=strNumero
					bURLOk=true
				}
			}
			else if (strReelCollection == "PF")
			{
				if (strNumero.length)
				{
					strRefId+= "NO" + strNumero
					bURLOk=true
				}
			}
			else if (strReelCollection == "DB")
			{
				if (strNiveau.length)
				{
					strRefId+=strNiveau
					if (strNumero.length)
					{
						strRefId+= "NO" + strNumero
					}
					bURLOk=true
				}
			}
			else if (strReelCollection == "PDOC")
			{
				if (strAnnee.length && strNumero.length)
				{
					strRefId+=strAnnee
					strRefId+= "NO" + strNumero
					bURLOk=true
				}
			}
			
			if (bURLOk == true)
			{
				FormLiensProfonds.REF_ID.value=strRefId
				FormLiensProfonds.submit()				
			}
			else
			{
				MM_DisplayErreur()
			}
		}
		else
		{
			MM_DisplayErreur()
		}
	}
}

function MM_DisplayPage()
{
	// alert("MM_DisplayPage")
	var FormSelectionCollections=MM_findObj("FormSelectionCollections")
	if (FormSelectionCollections)
	{
		strTypePage = FormSelectionCollections.typepage.value
		strCollection=FormSelectionCollections.collection.value
		strUpperCollection=strCollection.toUpperCase();
		strCollection=strUpperCollection;
	
		// Mise à jour de l'état des objets de navigation
		if (strTypePage=="avancee" ||	strTypePage=="boi_du_mois" || strTypePage=="documents_du_mois" || strTypePage=="creer_lien" || strTypePage=="nouveautes")
		{
			MM_SetToolBarreState('navAcc')
		}
		
		if (strTypePage=="TM" || strTypePage=="TI" || strTypePage=="REFDOC" || strTypePage=="DATE")
		{
			//
			MM_SetToolBarreState('navAcc')
			MM_SetToolBarreState('navSel')
				
			// Contrôle si la collection est disponible
			if (MM_IsCollectionDisponible(strCollection) == false)
			{
				// Contrôle d'accès aux CGI/LPF
				if (MM_IsInternet() && (strCollection == "CGI" || strCollection == "LPF") )
				{
					MM_DispayCGINonDisponible()
					return
				}
			
				// autres collections
				MM_DispayRedirectPage()
				return 
			}
		}
				
		// alert("MM_DisplayPage strTypePage : " + strTypePage + " strCollection : " + strCollection ) 
		if ( strTypePage=="TM")
		{
			if (strCollection=="CGI")
			{
				MM_CritereRecherche('TM','TM2','2','Code&nbsp;G&eacute;n&eacute;ral&nbsp;des&nbsp;Imp&ocirc;ts')
			}
			else if (strCollection=="LPF")
			{
				MM_CritereRecherche('TM','TM2','3','Livre des proc&eacute;dures fiscales')
			}
			else if (strCollection=="DB")
			{
				MM_CritereRecherche('TM','TM1','8','Documentation de base')
			}
			else if (strCollection=="PDOC")
			{
				MM_CritereRecherche('TM','TM_PDOC','11',MM_GetLibellePDOC())
			}
			else if (strCollection=="PF")
			{
				MM_CritereRecherche('TM','TM1','10','Pr&eacute;cis de fiscalit&eacute;')
			}
		}
		else if (strTypePage=="TI")
		{
			if (strCollection=="CGI")
			{
				MM_CritereRecherche('TI','TI2','2','Code&nbsp;G&eacute;n&eacute;ral&nbsp;des&nbsp;Imp&ocirc;ts')
			}
			else if (strCollection=="LPF")
			{
				MM_CritereRecherche('TI','TI2','3','Livre des proc&eacute;dures fiscales')
			}
			else if (strCollection=="DB")
			{
				MM_CritereRecherche('TI','TI1','8','Documentation de base')
			}
			else if (strCollection=="PF")
			{
				MM_CritereRecherche('TI','TI3','10','Pr&eacute;cis de fiscalit&eacute;')
			}
		}
		else if (strTypePage=="REFDOC")
		{
			if (strCollection=="CGI")
			{
				MM_CritereRecherche('REFDOC','REFDOC1_ORDER','2','Code&nbsp;G&eacute;n&eacute;ral&nbsp;des&nbsp;Imp&ocirc;ts')
			}
			else if (strCollection=="LPF")
			{
				MM_CritereRecherche('REFDOC','REFDOC1_ORDER','3','Livre des proc&eacute;dures fiscales')
			}
			else if (strCollection=="BOIPUB")
			{
				MM_CritereRecherche('REFDOC','REFDOC1_BOI','5','BOI Public (blanc)')
			}
			else if (strCollection=="BOIADM")
			{
				MM_CritereRecherche('REFDOC','REFDOC1_BOI','6','BOI Administratif (rose)')
			}
			else if (strCollection=="DB")
			{
				MM_CritereRecherche('REFDOC','REFDOC1','8','Documentation de base')
			}
			else if (strCollection=="PDOC")
			{
				Javascript:MM_CritereRecherche('REFDOC','REFDOC1_PDOC','11',MM_GetLibellePDOC())
			}
			else if (strCollection=="PF")
			{
				MM_CritereRecherche('REFDOC','REFDOC1','10','Pr&eacute;cis de fiscalit&eacute;')
			}
		}
		else if (strTypePage=="DATE")
		{
			if (strCollection=="BOIPUB")
			{
				MM_CritereRecherche('DATE','DATE1','5','BOI Public (blanc)')
			}
			else if (strCollection=="BOIADM")
			{
				MM_CritereRecherche('DATE','DATE1','6','BOI Administratif (rose)')
			}
			else if (strCollection=="PDOC")
			{
				MM_CritereRecherche('DATE','DATE1','11',MM_GetLibellePDOC())
			}
		}
		else if (strTypePage=="avancee")
		{
			MM_AfficherRechercheAvancee();
		}
		else if (strTypePage=="boi_du_mois")
		{
			MM_AfficherDerniersBOI()
		}
		else if (strTypePage=="documents_du_mois")
		{
			MM_AfficherDocumentsDuMois()
		}
		else if (strTypePage=="presentation")
		{
			document.location="presentation/presentation_sommaire2.htm"
		}
		else if (strTypePage=="creer_lien")
		{
			MM_CreerUnLien()
		}
		else if (strTypePage=="nouveautes")
		{
			document.location="nouveautes.html"
		}
	}
}

function MM_DisplayErreur()
{
	// alert("MM_DisplayErreur")
	var FormLiensProfonds=MM_findObj("FormLiensProfonds")
	if (FormLiensProfonds)
	{
		FormLiensProfonds.FILE.value=FormLiensProfonds.ERREUR_FILE.value
		FormLiensProfonds.submit()
	}	
}

function MM_ExistCollection(strCollection)
{
	// alert("MM_ExistCollection " + strCollection)
	iLen = gArrayCollections.length
	for (i=0; i<iLen; i++)
	{
		if (gArrayCollections[i] == strCollection )
		{
		 	return true
		}
	}
	return false
}

function MM_GetReelColection(strCollection)
{
	// alert("MM_GetReelColection " + strCollection)
	iLen = gArrayCollections.length
	for (i=0; i<iLen; i++)
	{
		if (strCollection.indexOf(gArrayID[i]) != -1)
		{
			strReelCollection=gArrayCollections[i]
			return strReelCollection
		}				
	}
}

// Affichage du lien créer un lien
function MM_CreerUnLien()
{
	var FormSelectionCollections=MM_findObj("FormSelectionCollections")
	if(FormSelectionCollections)
	{
		FormSelectionCollections.target="FrameClient"
		FormSelectionCollections.FILE.value="CreerUnLien.html"
		FormSelectionCollections.ACTION.value=""
	
		// Application
		FormSelectionCollections.submit()
	}
}
