// JavaScript Document

// ************************************************************************************
// Affichage de popup
// ************************************************************************************
function MM_openBrWindow(theURL,winName,features,intAW,intAH) { //v2.0
	winpopup = window.open(theURL,winName,features);
	//alert (winpopup.width + ' ' + winpopup.height);
	winpopup.moveTo(Math.round((screen.availWidth-intAW)/2),Math.round((screen.availHeight-intAH)/2));
}


// ************************************************************************************
// Gestion du menu
// ************************************************************************************

sfHover = function()
	{
	if (document.getElementById("menu"))
		{
		var sfEls = document.getElementById("menu").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++)
			{
			sfEls[i].onmouseover=function()
				{
				this.className+=" sfhover";
				}
			sfEls[i].onmouseout=function()
				{
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}
	
if (window.attachEvent) window.attachEvent("onload", sfHover);

// ************************************************************************************
// Gestion des POPUP
// ************************************************************************************
/* fonction permettant l'affichage du POPUP */
function funcPopupPlan(varUrl)
	{
	WinPopUpPlan = window.open (varUrl, "PopUpPlan", "height=505, width=593, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
	WinPopUpPlan.focus();
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	WinPopUpPlan.moveTo((ScreenW-600)/2, (ScreenH-600)/2);
	}

/*--------------------------------------------------------------------------------*/
// ************************************************************************************
/* fonction permettant l'affichage du POPUPEpis */
function funcPopupEpis(varUrl)
	{
	WinPopUpEpis = window.open (varUrl, "PopUpEpis", "height=495, width=270, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
	WinPopUpEpis.focus();
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	WinPopUpEpis.moveTo((ScreenW-600)/2, (ScreenH-600)/2);
	}

/*--------------------------------------------------------------------------------*/

function funcPopupImg(varId,varFileField,varTab,varLabel)
	{
	var strHtmlCode =	"<html>"
						+"<body bgColor=#OOOOOO leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
						+"<div><img title='" + varLabel + "' src='../_inc/IMG_DbImgView.asp?strTable="+varTab+"&strSelectField="+varTab+"Id&strSelectValue="
						+ varId +"&strFileField=" + varFileField + "&blnAffiche=oui&strImgNoFile=../images/_charte/NoFileCine.gif"
						+ "' onload='window.opener.funcPopupResizeToImg();'>"
						+ "<br>"
						+ "<div align='center'><font color='#FFFFFF' style='font-family:Verdana, sans-serif;font-size:11;'>" + varLabel + '&nbsp;&nbsp;<a href="#" onClick="window.print();">[imprimer l\'image]</a></font></div>'
						+ "</div>"
						+"</body></html>";
	
	WinPopUpImg = window.open ("", "PopUpImg", "toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
	WinPopUpImg.document.write(strHtmlCode);
	WinPopUpImg.document.close();
	WinPopUpImg.document.title= "Zoom image";
	WinPopUpImg.focus();
	}
	
/*fonction permettant de redimensionner le POPUP en fonction de la taille de l'image*/
function funcPopupResizeToImg()
	{
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var ImgW = WinPopUpImg.document.images[0].width;
	var ImgH = WinPopUpImg.document.images[0].height;
	WinPopUpImg.resizeTo(ImgW, ImgH+100);
	WinPopUpImg.moveTo((ScreenW-ImgW)/2, (ScreenH-ImgH)/2);
	}

//-------------------------------------------------------------------------------
//	Fonction de contrôle du navigateur
function FuncNavigatorCtrl()
	{
//	alert(window.navigator.userAgent);	
	//--- Déclaration des variables
	var strMsg = "";
	var ValidNavigator = true;
	var IeVersMini = 5.5;
	var FfVersMini = 1;
	var CurrNavigator = window.navigator.userAgent;
	if ((window.navigator.appName == "Microsoft Internet Explorer") && (CurrNavigator.indexOf("Opera") == -1))
		{
		var varNavigatorVers = parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE ")+5, navigator.appVersion.indexOf("MSIE ")+10));
		if (varNavigatorVers < IeVersMini)
			{
			strMsg += "Votre navigateur Internet Explorer est une version "+ varNavigatorVers +"\n";
			strMsg += "et ce site Web est optimisée pour les versions "+ IeVersMini +" et supérieures.\n\n";
			strMsg += "Certaines informations ou fonctionnalités ne vous seront peut-être pas accessibles.\n\n";
			strMsg += "Vous pouvez télécharger gratuitement une version plus récente sur www.microsoft.fr\n";
			strMsg += "ou contactez votre administrateur réseau.\n\n";
			ValidNavigator = false;
			}
		}
	if (((window.navigator.appName != "Microsoft Internet Explorer") && (CurrNavigator.indexOf("firefox") != -1)) || (CurrNavigator.indexOf("Opera") > -1) || (CurrNavigator.indexOf("AppleWebKit") > -1) || (CurrNavigator.indexOf("Safari") > -1))
		if (CurrNavigator.indexOf("Safari") > -1)
			{
			strMsg += "Ce site Web n'est pas optimisé pour Safari.\n";
			strMsg += "Certaines informations ou fonctionnalités ne vous seront peut-être pas accessibles\n\n\n";
			strMsg += "Installez, soit Internet Explorer, soit Firefox.\n";
			strMsg += "Vous pouvez télécharger gratuitement une version de ces navigateurs sur\n";
			strMsg += "www.microsoft.fr et www.mozilla-europe.org\/fr,\n";
			strMsg += "ou contactez votre administrateur réseau.\n\n";
			ValidNavigator = false;
			}
		else
			{
			strMsg += "Ce site Web est optimisée pour les versions "+ IeVersMini +" et supérieures d\'Internet Explorer ";
			strMsg += "et les versions "+ FfVersMini +" et supérieures de Firefox\n\n\n";
			strMsg += "Certaines informations ou fonctionnalités ne vous seront peut-être pas accessibles.\n\n\n";
			strMsg += "Vous pouvez télécharger gratuitement une version de ces navigateurs sur\n";
			strMsg += "www.microsoft.fr et www.mozilla-europe.org\/fr,\n";
			strMsg += "ou contactez votre administrateur réseau.\n\n";
			ValidNavigator = false;
			}
			
	//--- Vérification de la provenance de la connexion
	if (document.referrer.indexOf("http://"+ window.location.hostname) != 0)
		{
		//--- Contrôle du type de navigateur
		if (screen.width < 800)
			{
			strMsg += "----------------------------------------------------------------------\n";
			strMsg += "Ce site est optimisé pour une résolution d'écran de 800x600 pixels.\n";
			strMsg += "Votre écran affiche une résolution de "+ screen.width +"x"+ screen.height;
			strMsg += ", la consultation du site risque d'en être affectée.\n\n\n";
			strMsg += "Si vous le pouvez, nous vous invitons à modifier vos paramètres \n";
			strMsg += "dans les propriétés d'affichage de votre ordinateur\n";
			strMsg += "(sur PC : clic droit sur le bureau > Propriétés > Onglet paramètres).\n";
			ValidNavigator = false;
			}
		}
		//--- Information de l'utilisateur
	if (ValidNavigator == false)
		{
		alert(strMsg);
		}
	}

//****************************************************************
// Gestion du comportement des balises MARQUEE 
//****************************************************************

function funcMarqueeHover()
	{
	if (document.getElementsByTagName("marquee"))
		{
		var sfEls = document.getElementsByTagName("marquee");
		for (var i=0; i<sfEls.length; i++)
			{
			sfEls[i].onmouseover=function()
				{
				this.stop();
				}
			sfEls[i].onmouseout=function()
				{
				this.start();
				}
			}
		}
	}

//****************************************************************
// Fonction d'import des animations Flash 
//****************************************************************

function RunFlash(swf, hauteur, largeur, nom) {
	document.write("<object width=\""+largeur+"\" height=\""+hauteur+"\" id=\""+nom+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">\n");
	document.write("<param name=\"quality\" value=\"high\">\n");
	document.write("<param name=\"wmode\" value=\"transparent\">\n");
	document.write("<param name=\"movie\" value=\""+swf+"\">\n");
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\">\n");
	document.write("<embed src=\""+swf+"\" quality=\"high\" wmode=\"transparent\" width=\""+largeur+"\" height=\""+hauteur+"\" name=\""+nom+"\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n");
	document.write("</object>\n");
}

//************************************************
// Mise à jour de la carte de recherche des adhérents 
//************************************************
var varInit = false;
function funcUpdateMap(varObj,varValue)
	{
	var objForm;
	var objMap;
	if (window.attachEvent)
		{
		objMap = document.getElementById("AdherentSearchMap");
		}
	else
		{
		objMap = document["AdherentSearchMap"];
		}
	objForm = document.getElementById("formAdherentSearch");
	if ((varObj.type == "checkbox") && (varInit == false))
		{
		if (varObj.value == 0)
			{
			varObj.value = 1;
			varValue = 1;
			}
		else
			{
			varObj.value = 0;
			varValue = "";
			}
		}
	if (objMap != null)
		{
		if (varObj.name == "GfGitesRef")
			{
//			funcResetForm(varObj);
			objMap.SetVariable('GfGitesRef',varValue);
			funcParamMap();
			}
		if (varObj.name == "GfGitesCodepostal")
			{
			if (varValue.length == 5)
				{
				objMap.SetVariable('KbGeolocalCpMin',varValue);
				objMap.SetVariable('KbGeolocalCpMax',(varValue*1)+1);
				funcParamMap();
				}
			if (varValue.length == 0)
				{
				objMap.SetVariable('KbGeolocalCpMin',document.getElementsByName("KbGeolocalCpMin").value);
				objMap.SetVariable('KbGeolocalCpMax',document.getElementsByName("KbGeolocalCpMax").value);
				funcParamMap();
				}
			}
		else
			{
			objMap.SetVariable(varObj.name,varValue);
			funcParamMap();
			}
		}
	}

// Réinitialisation du formulaire
function funcResetForm(varObjException)
	{
	var objForm;
	objForm = document.getElementById("formAdherentSearch");
	var objMap;
	if (window.attachEvent)
		{
		objMap = document.getElementById("AdherentSearchMap");
		}
	else
		{
		objMap = document["AdherentSearchMap"];
		}
	if (objForm != null)
		{
		for (i=0; i<objForm.length; i++)
			{
			if ((objForm.elements[i] != varObjException) && (objForm.elements[i].type != "hidden"))
				{
				objForm.elements[i].value = "";
				objForm.elements[i].checked = false;
				}
			if (objForm.elements[i].name == "GfZoneId")
				{
				objMap.SetVariable("GfZoneId","");
				}
			}
		}
	}

// Concaténation des paramètres de filtre transmis à la carte
function funcParamMap()
	{
	var objForm;
	var objMap;
	var strFormParam;
	if (window.attachEvent)
		{
		objMap = document.getElementById("AdherentSearchMap");
		}
	else
		{
		objMap = document["AdherentSearchMap"];
		}
	objForm = document.getElementById("formAdherentSearch");
	strFormParam = "";
	if (objForm != null)
		{
		for (i=0; i<objForm.length; i++)
			{
			if ((objForm.elements[i].name != undefined) && (objForm.elements[i].value != undefined) && (objForm.elements[i].value != ""))
				{
				if ((objForm.elements[i].type == "checkbox") && (objForm.elements[i].checked == false))
					{
					//on ne tient pas compte du champ
					}
				else
					{
					strFormParam += objForm.elements[i].name +"="+ objForm.elements[i].value +"&";
					}
				if (objForm.elements[i].name == "GfZoneId")
					{
					objMap.SetVariable("GfZoneId",objForm.elements[i].value);
					}
				}
			}
		objMap.SetVariable("strFormParam",strFormParam);
		objMap.Play();
		}
	}

// Initialisation de la carte
function funcInitMap()
	{
	var objForm;
	var objMap;
	if (window.attachEvent)
		{
		objMap = document.getElementById("AdherentSearchMap");
		}
	else
		{
		objMap = document["AdherentSearchMap"];
		}
	if (objMap)
		{
		varMapWidth = objMap.width
		varMapMaxWidth = objMap.width*2;
		varMapHeight = objMap.height;
		funcParamMap();
		}
	}

// Gestion des zoom
var varMapWidth, varMapMaxWidth, varMapHeight;

function funcFlashZoom(varDirection, varCoefZoom)
	{
	var objDivMap, objMap, objZoomplus, objZoommoins;
	objDivMap = document.getElementById("cartoswf");
	if (window.attachEvent)
		{
		objMap = document.getElementById("AdherentSearchMap");
		}
	else
		{
		objMap = document["AdherentSearchMap"];
		}
	objZoomplus = document.getElementById("formAdherentSearchTab4");
	objZoommoins = document.getElementById("formAdherentSearchTab5");
	if (varDirection == "+")
		{
		if (objMap.width < varMapMaxWidth)
			{	
			objMap.width = objMap.width*varCoefZoom;
			objMap.height = objMap.height*varCoefZoom;
			for (i=0; i<objMap.GetVariable("varLocalisationQ"); i++)
				{	
				objMap.TSetProperty("/clip_localisation/localisation"+i, 2, objMap.TGetProperty("/clip_localisation/localisation"+i, 2)/varCoefZoom);
				objMap.TSetProperty("/clip_localisation/localisation"+i, 3, objMap.TGetProperty("/clip_localisation/localisation"+i, 3)/varCoefZoom);
				}
			objZoommoins.className = "on";
			}
		if (objMap.width >= varMapMaxWidth)
			{
			objZoomplus.className = "off";
			}
		}
	if (varDirection == "-")
		{
		if (objMap.width > varMapWidth)
			{
			objMap.width = objMap.width/varCoefZoom;
			objMap.height = objMap.height/varCoefZoom;
			for (i=0; i<objMap.GetVariable("varLocalisationQ"); i++)
				{	
				objMap.TSetProperty("/clip_localisation/localisation"+i, 2, objMap.TGetProperty("/clip_localisation/localisation"+i, 2)*varCoefZoom);
				objMap.TSetProperty("/clip_localisation/localisation"+i, 3, objMap.TGetProperty("/clip_localisation/localisation"+i, 3)*varCoefZoom);
				}
			objZoomplus.className = "on";
			}
		if (objMap.width <= varMapWidth)
			{
			objZoommoins.className = "off";
			}
		}
	objDivMap.scrollTop = Math.round((objDivMap.scrollTop)*varCoefZoom) + Math.round((objDivMap.scrollHeight*(varCoefZoom-1))/2);
	objDivMap.scrollLeft = Math.round(objDivMap.scrollLeft*varCoefZoom) + Math.round((objDivMap.scrollWidth*(varCoefZoom-1))/2);
	funcFlashZoomScroll();
	}

function funcFlashZoomScroll()
	{
	var objDivMap;
	objDivMap = document.getElementById("cartoswf");
	if (objDivMap.scrollTop > 0)
		{
		document.getElementById("carto-top").style.display = "block";
		}
	else
		{
		document.getElementById("carto-top").style.display = "none";
		}
	if (eval(varMapWidth)+objDivMap.scrollLeft < objDivMap.scrollWidth-10)
		{
		document.getElementById("carto-right").style.display = "block";
		}
	else
		{
		document.getElementById("carto-right").style.display = "none";
		}
	if (eval(varMapHeight)+objDivMap.scrollTop < objDivMap.scrollHeight-10)
		{
		document.getElementById("carto-bottom").style.display = "block";
		}
	else
		{
		document.getElementById("carto-bottom").style.display = "none";
		}
	if (objDivMap.scrollLeft > 0)
		{
		document.getElementById("carto-left").style.display = "block";
		}
	else
		{
		document.getElementById("carto-left").style.display = "none";
		}
	}

function funcFlashScroll(varDirection, sdsds)
	{
	var objDivMap, objMap, varVerticalScroll, varHorizontalScroll;
	objDivMap = document.getElementById("cartoswf");
	if (window.attachEvent)
		{
		objMap = document.getElementById("AdherentSearchMap");
		}
	else
		{
		objMap = document["AdherentSearchMap"];
		}
	varVerticalScroll = Math.round((objDivMap.scrollHeight - objDivMap.style.height)/10);
	varHorizontalScroll = Math.round((objDivMap.scrollWidth - objDivMap.style.width)/10);
	if (varDirection == "bottom")
		{
		objDivMap.scrollTop = objDivMap.scrollTop+varVerticalScroll;
		}
	if (varDirection == "left")
		{
		objDivMap.scrollLeft = objDivMap.scrollLeft-varHorizontalScroll;
		}
	if (varDirection == "top")
		{
		objDivMap.scrollTop = objDivMap.scrollTop-varVerticalScroll;
		}
	if (varDirection == "right")
		{
		objDivMap.scrollLeft = objDivMap.scrollLeft+varHorizontalScroll;
		}
	funcFlashZoomScroll();
	}

// Gestion des onglets du formulaire de recherche
function funcFormTab(varObjId)
	{
	//Attribution du style actif à l'onglet
	document.getElementById("formAdherentSearchTab1").className = "";
	document.getElementById("formAdherentSearchTab2").className = "";
	document.getElementById("formAdherentSearchTab3").className = "";
	document.getElementById("formAdherentSearchTab"+varObjId).className = "actif";
	//Affichage du bloc de recherche
	document.getElementById("formAdherentSearchTr1").style.display = "none";
	document.getElementById("formAdherentSearchTr2").style.display = "none";
	document.getElementById("formAdherentSearchTr3").style.display = "none";
	document.getElementById("formAdherentSearchTr"+varObjId).style.display = "inline";
	}

//****************************************************************
// Initialisation
//****************************************************************

function funcInit()
	{
	funcInitMap();
	funcMarqueeHover();
	}
window.onload = funcInit;