// Bibliothèque de scripts - 


//****************************************************************
// Affichage des sous-menus 
//****************************************************************

sfHover = function() {
	if (document.getElementById('navigation'))
		{
			var sfEls = document.getElementById('navigation').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);


//****************************************************************
// Affichage des POPUP 
//****************************************************************

function funcPopup(varUrl, varWidth, varHeight, varResize) {
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var WinPopUp = window.open(varUrl, 'popup', "toolbar=no, menubar=no, scrollbars=yes, resizable=" + varResize + ", location=no, directories=no, status=no, width=" + varWidth + ", height=" + varHeight);
	WinPopUp.moveTo(Math.round((ScreenW-varWidth)/2), Math.round((ScreenH-varHeight)/2));	
}

function funcPopupWmenu(varUrl, varWidth, varHeight, varResize, varTool, varMenu) {
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var WinPopUp = window.open(varUrl, 'popup', "toolbar="+ varTool +", menubar="+ varMenu +", scrollbars=yes, resizable=" + varResize + ", location=no, directories=no, status=no, width=" + varWidth + ", height=" + varHeight);
	WinPopUp.moveTo(Math.round((ScreenW-varWidth)/2), Math.round((ScreenH-varHeight)/2));	
}

//****************************************************************
// Initialisation Google Maps
//****************************************************************
//--- Chargement des coordonnées du point à géolocaliser
function funcLoadCoord(varZoom, varId, varRef) {
	var tabCoord, numLat, numLng;
	if(window.XMLHttpRequest) { // Firefox
		oXmlHttp = new XMLHttpRequest();
		oXmlHttp.open("GET", "../_inc/AJX_recherche.asp?typ=map&val="+varId, true);
        // Action déclenchée à la réception des données de la requête
        oXmlHttp.onreadystatechange = function() {
            if(oXmlHttp.readyState == 4) { // Déclenchement au chargement complet
                //--- Réception des données
                if (oXmlHttp.responseText != '' && oXmlHttp.status == 200) {
					if (oXmlHttp.responseText != 'null') {
						tabCoord = oXmlHttp.responseText.split("#");
						numLat = tabCoord[0];
						numLng = tabCoord[1];
						//--- Initialisation de la Google Map
						funcGoogleMapsInit(varZoom, numLat, numLng);
						//--- Affichage des coordonnées
						var objGps = document.getElementById("coordgps");
						if(objGps) {
							objGps.appendChild(document.createTextNode("Coordonnées GPS : Lat. "+ numLat +" / Lon. "+ numLng));
						}
					}
				}
            }
		}
        //Envoi
		oXmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		oXmlHttp.send();
	} else if(window.ActiveXObject) { // Internet Explorer 6 et inf.
		oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		oXmlHttp.open("GET", "../_inc/AJX_recherche.asp?typ=map&val="+varId, true);
        // Action déclenchée à la réception des données de la requête
        oXmlHttp.onreadystatechange = function() {
            if(oXmlHttp.readyState == 4) { // Déclenchement au chargement complet
                //--- Réception des données
                if (oXmlHttp.responseText != '' && oXmlHttp.status == 200) {
					if (oXmlHttp.responseText != 'null') {
						tabCoord = oXmlHttp.responseText.split("#");
						numLat = tabCoord[0];
						numLng = tabCoord[1];
						funcGoogleMapsInit(varZoom, numLat, numLng);
					}
				}
            }
        }
        //Envoi
		oXmlHttp.send();
	}
}

function funcGoogleMapsInit(varZoom, varLat, varLng) {
	var myOptions = {
		zoom:varZoom,
		center:new google.maps.LatLng(varLat, varLng),
		mapTypeControl:true,
		mapTypeControlOptions:{style:google.maps.MapTypeControlStyle.DROPDOWN_MENU},
		navigationControl:true,
		navigationControlOptions:{
			style:google.maps.NavigationControlStyle.SMALL, 
			position: google.maps.ControlPosition.TOP_LEFT
		},
		mapTypeId:google.maps.MapTypeId.ROADMAP 
	}
	var map = new google.maps.Map(document.getElementById("map"), myOptions);

	var image = '../images/marker.png';
	if (varLat, varLng) {
		var myLatLng = new google.maps.LatLng(varLat, varLng);
		var beachMarker = new google.maps.Marker({
			position:myLatLng,
			map:map,
			icon:image
		});
	}
}

//****************************************************************
// Ajout multiple de fonction à l'évènement window.onload
//****************************************************************
function addLoadEvent(func) 
{ 
   var oldonload = window.onload; 
   if(typeof window.onload != 'function') 
   { 
      window.onload = func; 
   } 
   else 
   { 
      window.onload = function() 
      { 
         oldonload(); 
         func(); 
      } 
   } 
}

//****************************************************************
// Redimensionnement dynamique d'une iFrame
//****************************************************************
function funcIframeResize() {
	//--- Définition de la hauteur d'affichage
	//------ Pour Firefox
	var height=window.innerWidth;
	//------ Pour IE
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;
	}
	//--- Redimensionnement
	document.getElementById("iframeCdeDoc").style.height=parseInt(height-document.getElementById("iframeCdeDoc").offsetTop)+"px";
}
