// Bibliothèque de scripts - 

//************************************************
// Slider
//************************************************
// directement dans code page
	

//****************************************************************
// Affichage des sous-menus 
//****************************************************************

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);


//****************************************************************
// Positionnement du pied de page
//****************************************************************
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setHeight() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('page').offsetHeight;
			var footerElement = document.getElementById('foot');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - contentHeight) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}
window.onload = function() {
	setHeight();
}
window.onresize = function() {
	setHeight();
}

//****************************************************************
// Affichage des bulle help
//****************************************************************

sfHover = function() {
	if (document.getElementById('simulator'))
		{
			var sfEls = document.getElementById('simulator').getElementsByTagName("A");
			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);

//************************************************
// Fonction pour Google Map
//************************************************

function iconeInfotel(image){
    var icone = new GIcon();
    icone.image = image;
    icone.iconSize = new GSize(12, 20);
    icone.iconAnchor = new GPoint(6, 20);
    icone.infoWindowAnchor = new GPoint(5, 1);
    return icone;
}


function loadMap(map,image,xml) {
      if (GBrowserIsCompatible()) {
        	var map = new GMap2(document.getElementById(map));
        	map.setCenter(new GLatLng(48.864434, 2.416741), 1);
		    map.addControl(new GSmallMapControl());
		    //map.enableScrollWheelZoom();        
            
        
	  	    function creerMarker(point, onglet1){
        		var marker = new GMarker(point,iconeInfotel(image));
        		GEvent.addListener(marker,"mouseover",function(){marker.openInfoWindowHtml(onglet1);});
			    GEvent.addListener(marker,"mouseout",function(){marker.closeInfoWindow();});
			    GEvent.addListener(marker,"click",function(){map.zoomIn();map.setCenter(marker.getLatLng());});
        		return marker;
        	}

        	GDownloadUrl(xml,function(data){
        		var xml = GXml.parse(data);
        		var markers = xml.documentElement.getElementsByTagName("marker");
       		    for(var i=0; i < markers.length; i++){
               	    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")),1);
               	    
				    var marker = creerMarker(point, markers[i].getAttribute("info"));
				    map.addOverlay(marker);
          		}
        	});
	}
}

function loadPlan(map,zoom,nom,image,xml) {
    if(GBrowserIsCompatible()){
          var map = new GMap2(document.getElementById(map));
          //map.setCenter(new GLatLng(lat,lng),zoom);
          map.addControl(new GLargeMapControl());
          map.addControl(new GScaleControl());
          map.addControl(new GOverviewMapControl());
          map.addControl(new GMapTypeControl());
          //map.enableScrollWheelZoom();
                   
          GDownloadUrl(xml,function(data){
        		var xml = GXml.parse(data);
        		var markers = xml.documentElement.getElementsByTagName("marker");
       		    for(var i=0; i < markers.length; i++){
               	   var test = markers[i].getAttribute("name");
               	   var res = test.split("@nom=");
               	   test=res[1].split("'");
               	   if(test[1]==nom){
               	        map.setCenter(new GLatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng"))),zoom);
               	        
               	        var point = map.getCenter();              	        
                        var marker = new GMarker(point,iconeInfotel(image));

                        var monAdresse = markers[i].getAttribute("adresse").replace("\n","<br />","gi");
						var maVille = markers[i].getAttribute("ville");
						var lat=markers[i].getAttribute("lat"); 
						var lng=markers[i].getAttribute("lng"); 
                        var infoTabs = "<p><b>"+markers[i].getAttribute("info")+"</b></p><p>"+monAdresse+"<br /><b>"+maVille+"</b><br />GPS <b>Lat=</b>"+lat+"<b> Lng=</b>"+lng+"</p>";
                        
                        
                        GEvent.addListener(marker,"mouseover",function(){marker.openInfoWindowHtml(infoTabs);});
	                    GEvent.addListener(marker,"mouseout",function(){marker.closeInfoWindow();});
		                GEvent.addListener(marker,"click",function(){map.zoomIn();map.setCenter(marker.getLatLng());});
                        map.addOverlay(marker);
                        break;
               	   }
          		}
        	});
      }
}


/*
Fonction d'envoi d'email à un ami
*/
function funcPopupMail(varUrl, varWidth, varHeight){
        WinPopUpMail = window.open (varUrl, 'PopUpMail','height=' + varHeight + ',width=' + varWidth + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=1');
}

function mensualite() {
	k=document.frmCalcEmprunt.capEmprunt.value;
	t=document.frmCalcEmprunt.tauxInteret.value;
	
	if(document.frmCalcEmprunt.duree[0].checked && document.frmCalcEmprunt.dureeEmprunt.value != "") {
		n=document.frmCalcEmprunt.dureeEmprunt.value*12;
	} else {
		n=document.frmCalcEmprunt.dureeEmprunt.value;		
	}

        if (k != "" && t != "" && n != "") {
            m=k*(t/100)/(1-Math.pow((1+t/100/12),(-n)))/12;
            m=Math.floor(m*100)/100;
            document.getElementById('mensualite').value = m;
        }
}




