/*

(c)jl Baudoin - 2007
Version 3.01 du 28/08/2007

*/
var currentMarker;var arrayStations=new Array();var aStationDepart=null;var aStationArrivee=null;var currentIcon;var myDistance=null;var flagUseCookies=GetCookie('useCookies');if(flagUseCookies==null||flagUseCookies=='true'){useCookies(true);flagUseCookies=true;}
if(flagUseCookies=='false'){flagUseCookies=false}
var C_TEXTE_BULLE_ACCUEIL="<strong>Bienvenue sur la carte V&eacute;lib,</strong><br><br>Double cliquez<br>sur la carte pour trouver les stations les plus proches<br> ou utilisez les onglets &agrave; gauche";var C_TITRE_BULLE_ACCUEIL="Bienvenue sur la carte V&eacute;lib";var C_TEXTE_LOADING="Chargement en cours";var C_TEXTE_VELOS_DISPOS="V&eacute;los disponibles : ";var C_TEXTE_BORNES_DISPOS="Bornes disponibles : ";var C_TEXTE_BROWSER_INCOMPATIBLE="D&eacute;sol&eacute;s, votre navigateur n'est pas compatible avec notre système de cartographie";var C_TEXTE_BORNE_FERMEE="Borne ferm&eacute;e";var oMap=null;var oGeocoder=null;var gdir;var myPolyline=null;oVeloIcon=new GIcon(G_DEFAULT_ICON,"/images/icones/iconeVelov.png");oVeloIcon.depart="/images/icones/iconeVelovDepart.png";oVeloIcon.arrivee="/images/icones/iconeVelovArrivee.png";oVeloIcon.over="/images/icones/iconeInterroge.png";oVeloIcon.shadow="/images/icones/iconeVelovOmbre.png";oVeloIcon.shadowSize=new GSize(25,23);oVeloIcon.iconSize=new GSize(14,23);oVeloIcon.iconAnchor=new GPoint(12,23);oVeloIcon.printImage="/images/icones/iconeVelov.png";oVeloIcon.mozPrintImage="/images/icones/iconeVelov.png";oVeloIcon.printShadow="/images/icones/iconeVelovPrintVide.gif";oHomeIcon=new GIcon(G_DEFAULT_ICON,"/images/icones/home.png");oHomeIcon.shadow="/images/icones/homeOmbre.png";oHomeIcon.iconSize=new GSize(32,24);oHomeIcon.shadowSize=new GSize(32,24);oHomeIcon.iconAnchor=new GPoint(16,12);oHomeIcon.infoWindowAnchor=new GPoint(5,1);oHomeIcon.printImage="/images/icones/home.png";oHomeIcon.mozPrintImage="/images/icones/home.png";oHomeIcon.printShadow="/images/icones/iconeVelovPrintVide.gif";var oLimites=new GLatLngBounds();function SubmitAdresse(){if($('adresse').value!=''){ChercheAdresse($('adresse').value+' '+$('ville').value+' france');}}
function ChangeNombreStation(iNombreStation){$('nombreStation1').value=iNombreStation;$('nombreStation2').value=iNombreStation;}
var oAccordeon;var etatMenu=1;function toggleMenu(){var myFx=new Fx.Style('menuGauche','width');var myFx1=new Fx.Style('menu','margin-left');if(etatMenu==1){myFx._start(239,0);myFx1._start(0,-15);etatMenu=0;$('iconeFleche').src="/images/flecheOuvre.gif";}
else{myFx._start(0,239);myFx1._start(-15,0);etatMenu=1;$('iconeFleche').src="/images/flecheFerme.gif";}}
function ajusteHauteurMap(){var iajusteHauteurMap=document.getElementById("body").clientHeight-114;if(iajusteHauteurMap<419){iajusteHauteurMap=419;}
document.getElementById("map").style.height=iajusteHauteurMap+'px';}
function onLoad(){window.onresize=ajusteHauteurMap;var aTitreAccordeon=document.getElementsByClassName('enteteMenu');var aContenuAccordeon=document.getElementsByClassName('contenuAccordeon');oAccordeon=new fx.Accordion(aTitreAccordeon,aContenuAccordeon,{opacity:true,fixedHeight:213});$('useCookie').checked=flagUseCookies;if(GBrowserIsCompatible()){ajusteHauteurMap();oMapObj=document.getElementById('map');oMap=new GMap2(oMapObj);oMap.addControl(new GLargeMapControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(20,45)));oMap.addControl(new GMapTypeControl(),new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(20,20)));oMap.addControl(new GOverviewMapControl(new GSize(100,100)));oMap.disableDoubleClickZoom();oMap.enableContinuousZoom();oMap.enableScrollWheelZoom();oMap.setCenter(new GLatLng(48.855679899,2.3441219),12);var oDiv=document.createElement("div");oDiv.setAttribute('id','LoadingDiv');oDiv.className='loadingDiv';oDiv.innerHTML='<b>'+C_TEXTE_LOADING+'...</b><br /><img src="/images/loading.gif"/>';var iLargeurMap=document.getElementById("map").clientWidth;var iHauteurMap=document.getElementById("map").clientHeight;var oPosition=new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize((iLargeurMap-188)/2,(iHauteurMap-30)/2));oPosition.apply(oDiv);oMap.getContainer().appendChild(oDiv);var pos=new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(15,15));pos.apply(document.getElementById("menu"));oMap.getContainer().appendChild(document.getElementById("menu"));GEvent.addListener(oMap,"dblclick",function(oMarker,oPoint){oAccordeon.showThisHideOpen(3);AfficheStationsAutour(oPoint);});var oMarkerInfo=new GMarker(new GLatLng(48.855679899,2.3441219),{icon:oVeloIcon,title:C_TITRE_BULLE_ACCUEIL});oMap.addOverlay(oMarkerInfo);oMarkerInfo.openInfoWindowHtml('<div style="text-align:center">'+C_TEXTE_BULLE_ACCUEIL+'</div>');GEvent.addListener(oMarkerInfo,"infowindowclose",function(){oMap.clearOverlays();});GEvent.addListener(oMap,"clearoverlays",function(){refreshOverlays();});oGeocoder=new GClientGeocoder();gdir=new GDirections(oMap);GEvent.addListener(gdir,"addoverlay",onGDirectionsLoad);x=GetParam('x');y=GetParam('y');if(x!=''&&y!=''){AfficheStationsAutour(new GLatLng(y,x));}
else{if(flagUseCookies){x=GetCookie('x');y=GetCookie('y');if(x!=null&&y!=null){AfficheStationsAutour(new GLatLng(y,x));}}}
toDo();document.getElementById("menu").style.display='block';var request=GXmlHttp.create();request.open("GET","/Velib/ajax/proxyMeteo.php",true);request.onreadystatechange=function(){if(request.readyState==4){var xmlDoc=request.responseXML;var root=xmlDoc.getElementsByTagName('rss')[0];var channels=root.getElementsByTagName("channel");var items=channels[0].getElementsByTagName("item");var descriptions=items[0].getElementsByTagName("description");var desc=descriptions[0].firstChild.nodeValue;desc=desc.split('<br />');var image=desc[0];var tabTemp=desc[2].split(',');tabTemp=tabTemp[1].split('<BR />');var temp=tabTemp[0];var reg=new RegExp("( C)","g");temp=temp.replace(reg,'&deg;C');$('iconeMeteo').innerHTML=image;$('tempMeteo').innerHTML=temp;}}
request.send(null);}}
function trajet(){var waypoints=new Array(arrayStations[aStationDepart]['marker'].getPoint(),arrayStations[aStationArrivee]['marker'].getPoint());gdir.loadFromWaypoints(waypoints,{"locale":"fr"});}
function clearTrajet(){gdir.clear();}
function onGDirectionsLoad(){myPolyline=gdir.getPolyline();mySummary=gdir.getSummaryHtml();gdir.clear();oMap.addOverlay(myPolyline);$('resultatTrajet').style.display='block';$('resultatTrajet').innerHTML=mySummary;}
function refreshOverlays(){oLimites=new GLatLngBounds();if(aStationDepart!=null){svgDepart=arrayStations[aStationDepart];}
if(aStationArrivee!=null){svgArrivee=arrayStations[aStationArrivee];}
arrayStations=new Array();if(aStationDepart!=null){CreerMarker(svgDepart['marker'].getPoint(),aStationDepart,svgDepart['titre']);}
if(aStationArrivee!=null){CreerMarker(svgArrivee['marker'].getPoint(),aStationArrivee,svgArrivee['titre']);}
if(myPolyline!=null&&aStationArrivee!=null&&aStationDepart){oMap.addOverlay(myPolyline);}}
function AfficheLoading(){document.getElementById('LoadingDiv').style.display="block";}
function CacheLoading(){document.getElementById('LoadingDiv').style.display="none";}
function AfficheStationsAutour(oPoint){iNombreStation=$('nombreStation1').value;AfficheLoading();oMap.clearOverlays();oMarker=new GMarker(oPoint,{icon:oHomeIcon,title:'Votre recherche',draggable:true,bouncy:true});oMap.addOverlay(oMarker);GEvent.addListener(oMarker,"click",function(){currentMarker=oPoint;var htmlPopup='';var sLinkMaison='http://'+location.hostname+"/Velib/?x="+oPoint.x+"&y="+oPoint.y;sHtmlMaison='<img src="/images/favorites_16_h.gif" alt="Adresse de cette carte" width="16" height="16" border="0" align="texttop">&nbsp;<a href="'+sLinkMaison+'" id="link">Lien vers cette carte</a><br />';var sMailtoLink='mailto:?subject=Carte unvelovite.com&body='+sLinkMaison;sHtmlMaison+='<img src="/images/mail_16.gif" alt="envoyer le lien map mail" align="texttop" ><a href="'+sMailtoLink+'" id="mailto">Envoyer cette carte par mail</a>';oMarker.openInfoWindowHtml(htmlPopup+sHtmlMaison);oAccordeon.showThisHideOpen(5);});if(flagUseCookies){var pathname=location.pathname;var myDomain=pathname.substring(0,pathname.lastIndexOf('/'))+'/';var date_exp=new Date();date_exp.setTime(date_exp.getTime()+(365*24*3600*1000));SetCookie("x",oPoint.x,date_exp,myDomain);SetCookie("y",oPoint.y,date_exp,myDomain);}
GEvent.addListener(oMarker,"dragend",function(){AfficheStationsAutour(oMarker.getPoint(),iNombreStation);});oLimites.extend(oPoint);GDownloadUrl("ajax/StationsParCoord.php?lat="+oPoint.y+"&long="+oPoint.x+"&nombreStation="+iNombreStation,ChargeJson);}
ChargeJson=function(sDoc){var aJsonData=eval('('+sDoc+')');for(var i=0;i<aJsonData.markers.length;i++){if(aJsonData.markers[i].numStation!=aStationDepart&&aJsonData.markers[i].numStation!=aStationArrivee){var oPoint=new GLatLng(aJsonData.markers[i].lat,aJsonData.markers[i].longitude);var oMarker=CreerMarker(oPoint,aJsonData.markers[i].numStation,aJsonData.markers[i].nomStation,aJsonData.markers[i].adresseStation);}}
oMap.setZoom(oMap.getBoundsZoomLevel(oLimites));var clat=(oLimites.getNorthEast().lat()+oLimites.getSouthWest().lat())/2;var clng=(oLimites.getNorthEast().lng()+oLimites.getSouthWest().lng())/2;oMap.panTo(new GLatLng(clat,clng));CacheLoading();}
function CreerMarker(oPoint,iId,sTitre,sAdresseStation){var oMarker=new GMarker(oPoint,{icon:oVeloIcon,title:sTitre});currentIcon=oVeloIcon.image;if(iId==aStationDepart){currentIcon=oVeloIcon.depart;}
if(iId==aStationArrivee){currentIcon=oVeloIcon.arrivee;}
GEvent.addListener(oMarker,"click",function(){oMarker.setImage(oVeloIcon.over);currentIcon=oVeloIcon.image;if(iId==aStationDepart){currentIcon=oVeloIcon.depart;}
if(iId==aStationArrivee){currentIcon=oVeloIcon.arrivee;}
currentMarker=oPoint;sHtmlBulle="<div style='text-align:center'><strong>"+iId+" - "+sAdresseStation+"</strong></div>";sHtmlBulle+="<div id='dispo' style='font-family: Verdana; font-size:10px; text-align: left; height: 60px'><br>"
+C_TEXTE_LOADING+"<br><br><img src='/images/loading.gif' /></div>";if((iId==aStationDepart)||(iId==aStationArrivee)){if((aStationDepart!==null)&&(iId==aStationDepart)){sHtmlBulle+='<br><input type="checkbox" name="checkbox" id="checkboxDepart"';sHtmlBulle+='onChange="setDepart('+iId+',this.checked);"> Station de d&eacute;part';}
if((aStationArrivee!==null)&&(iId==aStationArrivee)){sHtmlBulle+='<br><input type="checkbox" name="checkbox" id="checkboxArrivee" onChange="setArrivee('+iId+',this.checked);"> Station d\'arriv&eacute;e';}}
else{if((aStationDepart==null)){sHtmlBulle+='<br><input type="checkbox" name="checkbox" id="checkboxDepart"';sHtmlBulle+='onChange="setDepart('+iId+',this.checked);"> Station de d&eacute;part';}
else if((aStationArrivee==null)){sHtmlBulle+='<br><input type="checkbox" name="checkbox" id="checkboxArrivee" onChange="setArrivee('+iId+',this.checked);"> Station d\'arriv&eacute;e';}}
oMarker.openInfoWindowHtml(sHtmlBulle);if(iId==aStationDepart){$('checkboxDepart').checked=true;currentIcon=oVeloIcon.depart;oMarker.setImage(currentIcon);}
if(aStationArrivee==iId){$('checkboxArrivee').checked=true;currentIcon=oVeloIcon.arrivee;oMarker.setImage(currentIcon);}
iNocache=Math.floor(Math.random()*100000)+1;var request=GXmlHttp.create();request.open("GET","ajax/DispoStationsParId.php?id="+iId+"&noCache="+iNocache,true);request.onreadystatechange=function(){if(request.readyState==4){var xmlDoc=request.responseXML;sTexteDispo='<br />';
if(xmlDoc.getElementsByTagName('total')[0].firstChild!=null){sTexteDispo+="<br>"+'Nombre de bornes : '+xmlDoc.getElementsByTagName('total')[0].firstChild.nodeValue;sTexteDispo+="<br>"+C_TEXTE_VELOS_DISPOS+xmlDoc.getElementsByTagName('available')[0].firstChild.nodeValue;sTexteDispo+="<br>"+C_TEXTE_BORNES_DISPOS+xmlDoc.getElementsByTagName('free')[0].firstChild.nodeValue;}
else{sTexteDispo+="Donn&eacute;es non disponibles :-(";}
document.getElementById('dispo').innerHTML=sTexteDispo;}}
request.send(null);});GEvent.addListener(oMarker,"infowindowclose",function(){currentIcon=oVeloIcon.image;if(iId==aStationDepart){currentIcon=oVeloIcon.depart;}
if(iId==aStationArrivee){currentIcon=oVeloIcon.arrivee;}
oMarker.setImage(currentIcon);});oMap.addOverlay(oMarker);oMarker.setImage(currentIcon);oLimites.extend(oPoint);markerCourant=new Array();markerCourant['marker']=oMarker;markerCourant['titre']=sTitre;iId=Math.floor(iId);arrayStations[iId]=markerCourant;}
function setDepart(id,bEtat){oAccordeon.showThisHideOpen(4);if(bEtat){aStationDepart=id;arrayStations[id]['marker'].setImage(oVeloIcon.depart);currentIcon=oVeloIcon.depart;$('stationDepart').innerHTML=arrayStations[id]['titre'];}
else{aStationDepart=null;arrayStations[id]['marker'].setImage(oVeloIcon.image);currentIcon=oVeloIcon.image;$('stationDepart').innerHTML='Station de d&eacute;part';}
if(aStationDepart!=null&&aStationArrivee!=null){$('afficheTrajet').style.display='block';}else{$('afficheTrajet').style.display='none';if(myPolyline!=null){oMap.removeOverlay(myPolyline);myPolyline!=null;$('resultatTrajet').style.display='none';}}}
function setArrivee(id,bEtat){oAccordeon.showThisHideOpen(4);if(bEtat){aStationArrivee=id;arrayStations[id]['marker'].setImage(oVeloIcon.arrivee);currentIcon=oVeloIcon.arrivee;$('stationArrivee').innerHTML=arrayStations[id]['titre'];}
else{aStationArrivee=null;arrayStations[id]['marker'].setImage(oVeloIcon.image);currentIcon=oVeloIcon.image;$('stationArrivee').innerHTML="Station d'arriv&eacute;e";}
if(aStationDepart!=null&&aStationArrivee!=null){$('afficheTrajet').style.display='block';}else{$('afficheTrajet').style.display='none';if(myPolyline!=null){oMap.removeOverlay(myPolyline);myPolyline!=null;$('resultatTrajet').style.display='none';}}}
function ChercheAdresse(sAdresse){if(oGeocoder){oGeocoder.getLatLng(sAdresse,function(oPoint){if(!oPoint){$('erreurAdresse').style.display="block";}else{AfficheStationsAutour(oPoint);}});}}
function AfficheStationsParArrondissement(iArrondissement){AfficheLoading();oMap.clearOverlays();oLimites=new GLatLngBounds();GDownloadUrl("ajax/StationsParArrondissement.php?arrondissement="+iArrondissement,ChargeJson);}
function useCookies(bValue){if(bValue==true){flagUseCookies=true;SetCookie('useCookies',true);SetCookie('useCookies',true);}
else{flagUseCookies=false;SetCookie('useCookies',false);supprimeCookies('x');supprimeCookies('y');}}
function supprimeCookies(){var pathname=location.pathname;var myDomain=pathname.substring(0,pathname.lastIndexOf('/'))+'/';var date_exp=new Date();date_exp.setFullYear(date_exp.getFullYear()-1);SetCookie("x",null,date_exp,myDomain);SetCookie("y",null,date_exp,myDomain);}
function SetCookie(name,value){var argv=SetCookie.arguments;var argc=SetCookie.arguments.length;var expires=(argc>2)?argv[2]:null;var path=(argc>3)?argv[3]:null;var domain=(argc>4)?argv[4]:null;var secure=(argc>5)?argv[5]:false;document.cookie=name+"="+escape(value)+
((expires==null)?"":("; expires="+expires.toGMTString()))+
((path==null)?"":("; path="+path))+
((domain==null)?"":("; domain="+domain))+
((secure==true)?"; secure":"");}
function getCookieVal(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1)
endstr=document.cookie.length;return unescape(document.cookie.substring(offset,endstr));}
function GetCookie(name){var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i<clen){var j=i+alen;if(document.cookie.substring(i,j)==arg)
return getCookieVal(j);i=document.cookie.indexOf(" ",i)+1;if(i==0)break;}
return null;}
function GetParam(name)
{var start=location.search.indexOf("?"+name+"=");if(start<0)start=location.search.indexOf("&"+name+"=");if(start<0)return'';start+=name.length+2;var end=location.search.indexOf("&",start)-1;if(end<0)end=location.search.length;var result='';for(var i=start;i<=end;i++){var c=location.search.charAt(i);result=result+(c=='+'?' ':c);}
return unescape(result);}