var map,markerBounds=[],geocoder,searchText,searchDiv,searchResultsDiv,tabAddress,kmzLoaded=0,geoXml;function Rectangle(A){this.bounds_=A}Rectangle.prototype=new GOverlay();Rectangle.prototype.initialize=function(A){var B=document.createElement("div");B.style.border="0px";B.style.position="absolute";B.style.cursor="pointer";if(navigator.appName==="Microsoft Internet Explorer"){B.style.background="url('../images/blank.gif')"}A.getPane(G_MAP_MARKER_MOUSE_TARGET_PANE).appendChild(B);this.map_=A;this.div_=B};Rectangle.prototype.remove=function(){this.div_.parentNode.removeChild(this.div_)};Rectangle.prototype.copy=function(){return new Rectangle(this.bounds_)};Rectangle.prototype.redraw=function(C){if(!C){return }var B=this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());var A=this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());this.div_.style.width=Math.abs(A.x-B.x)+"px";this.div_.style.height=Math.abs(A.y-B.y)+"px";this.div_.style.left=Math.min(A.x,B.x)+"px";this.div_.style.top=Math.min(A.y,B.y)+"px"};function AdaelControl(){}AdaelControl.prototype=new GControl();AdaelControl.prototype.initialize=function(C){var A=document.createElement("div");var D=document.createElement("a");D.href="http://www.adael.net";D.target="_blank";A.appendChild(D);var B=document.createElement("img");var E=document.createAttribute("src");if(/msie|MSIE 6/.test(navigator.userAgent)){E.nodeValue="images/adael-transparent-2.gif"}else{E.nodeValue="images/adael-transparent-2.png"}B.style.border="0px";B.setAttributeNode(E);D.appendChild(B);C.getContainer().appendChild(A);return A};AdaelControl.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_BOTTOM_LEFT,new GSize(3,40))};function AdaelSearchBox(){}AdaelSearchBox.prototype=new GControl(true,true);AdaelSearchBox.prototype.initialize=function(C){searchDiv=document.createElement("div");if(navigator.appName==="Microsoft Internet Explorer"){searchDiv.style.border="1px solid #979797";searchDiv.style.padding="3px";searchDiv.style.background="background: #FFFFFF"}else{var A=document.createAttribute("style");A.nodeValue="border: 1px solid #979797; padding: 3px; background: #FFFFFF;";A.nodeValue+=" border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;";searchDiv.setAttributeNode(A)}var B;if(serverHttpAcceptLanguage.substr(0,2)==="fr"){B=["Trouver un hostpot","Chercher"]}else{B=["Find a hotspot","Search"]}searchDiv.innerHTML="<form style='display: inline;' action='.' method='post' onsubmit='javascript: return false;'><input type='text' id='search' style='font-weight: bold; color: #6688CC; width: 400px;' value=\""+B[0]+"\" onfocus='javascript: activateSearch(this);'><input type='submit' value='"+B[1]+"' onclick='javascript: searchAddress();'></form>";searchDiv.appendChild(document.createElement("br"));C.getContainer().appendChild(searchDiv);return searchDiv};AdaelSearchBox.prototype.getDefaultPosition=function(){return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(80,7))};function activateSearch(A){if(A.style.fontWeight==="bold"||A.style.fontWeight>500){searchText=A;searchResultsDiv=document.createElement("div");A.value="";A.style.color="#000000";A.style.fontWeight="normal"}}function showInfo(data){var tabJSON=eval("("+data+")");var labelTabs;if(serverHttpAcceptLanguage.substr(0,2)==="fr"){labelTabs=["Infos","Contact","État"]}else{labelTabs=["Info","Contact","Status"]}var infoTabs=[new GInfoWindowTab(labelTabs[0],tabJSON.general),new GInfoWindowTab(labelTabs[1],tabJSON.contact),new GInfoWindowTab(labelTabs[2],tabJSON.etat)];var offset;if(map.getZoom()>=6){offset=new GSize(5,-25)}else{offset=new GSize(5,-2)}map.openInfoWindowTabsHtml(new GLatLng(tabJSON.lat,tabJSON.lng),infoTabs,{pixelOffset:offset})}function updateCursorMap(){if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))){return }GDownloadUrl("c.php?a="+map.getBounds().getSouthWest().lat()+"x"+map.getBounds().getSouthWest().lng()+"&b="+map.getBounds().getNorthEast().lat()+"x"+map.getBounds().getNorthEast().lng()+"&c="+map.getZoom(),function(data,responseCode){if(responseCode===200&&data!==""){var i;for(i in markerBounds){map.removeOverlay(markerBounds[i])}markerBounds=[];var tabJSON=eval("("+data+")");var rectangle;for(i in tabJSON){rectangle=new Rectangle(new GLatLngBounds(new GLatLng(tabJSON[i][0],tabJSON[i][1]),new GLatLng(tabJSON[i][2],tabJSON[i][3])));markerBounds.push(rectangle);map.addOverlay(rectangle)}}})}function clickMap(C,A){var B;if(A){B="1"}else{B="0"}GDownloadUrl("i.php?e="+B+"&p="+C.lat()+"x"+C.lng()+"x"+map.getZoom(),function(E,D){if(D===200&&E!==""){showInfo(E)}})}function load(){if(GBrowserIsCompatible()){var E=new GCopyright(1,new GLatLngBounds(new GLatLng(-90,-180),new GLatLng(90,180)),0,"&copy;2009 Adael Wireless");var D=new GCopyrightCollection("&copy; ");D.addCopyright(E);var C=new GTileLayer(D,0,17);C.getTileUrl=function(G,F){return"http://mt"+((G.x+G.y)%4)+".adael.net/"+G.x+"-"+G.y+"-"+F+".png"};C.isPng=function(){return true};C.getOpacity=function(){return 1};map=new GMap2(document.getElementById("map"));map.addMapType(G_PHYSICAL_MAP);map.addMapType(G_SATELLITE_3D_MAP);map.setCenter(new GLatLng(+48.86,+2.34),12,G_PHYSICAL_MAP);map.addControl(new GLargeMapControl3D());map.addControl(new GHierarchicalMapTypeControl());map.addControl(new GScaleControl());var B=new GOverviewMapControl();map.addControl(B);B.setMapType(G_PHYSICAL_MAP);map.addControl(new AdaelControl());map.addControl(new AdaelSearchBox());geocoder=new GClientGeocoder();geocoder.setBaseCountryCode("FR");var A=new GTileLayerOverlay(C);map.addOverlay(A);GEvent.addListener(map,"click",function(F,G){if(typeof G!=="undefined"&&map.getCurrentMapType()!==G_SATELLITE_3D_MAP){clickMap(G,false)}});GEvent.addListener(map,"maptypechanged",function(){if(map.getCurrentMapType()!==G_SATELLITE_3D_MAP){if(kmzLoaded===1){kmzLoaded=0;map.removeOverlay(geoXml)}}else{if(kmzLoaded===0){kmzLoaded=1;if(typeof geoXml=="undefined"){geoXml=new GGeoXml("http://map.adael.net/adael.kmz")}map.addOverlay(geoXml)}}if(map.getCurrentMapType()!==G_SATELLITE_3D_MAP){B.setMapType(map.getCurrentMapType())}});GEvent.addListener(map,"moveend",function(){if(map.getCurrentMapType()!==G_SATELLITE_3D_MAP){updateCursorMap()}});GEvent.addListener(map,"zoomend",function(){for(var F in markerBounds){map.removeOverlay(markerBounds[F])}markerBounds=[]});updateCursorMap();return map}}function viewSearch(C){var A=tabAddress[C][2];if(A>map.getCurrentMapType().getMaximumResolution()){A=map.getCurrentMapType().getMaximumResolution()}if(A===map.getZoom()){map.panTo(tabAddress[C][1])}else{map.setCenter(tabAddress[C][1],A)}clickMap(tabAddress[C][1],true);searchText.value=tabAddress[C][0];try{searchDiv.removeChild(searchResultsDiv)}catch(B){}}function displayShowAddressResults(){var D;var C,A;if(serverHttpAcceptLanguage.substr(0,2)==="fr"){C="Aucun r&eacute;sultat";A="Fermer les r&eacute;sultats de recherche"}else{C="No results were found";A="Close search results"}if(tabAddress.length===0){D="<table>";D+="<tr><td>"+C+"</td></tr>";D+="<tr><td><a href='javascript: closeSearch();' style='color: #6688CC;'>"+A+"</a></td></tr>";D+="</table>";searchResultsDiv.innerHTML=D;searchDiv.appendChild(searchResultsDiv)}else{if(tabAddress.length===1){viewSearch(0)}else{D="<table style='width: 471px'>";for(var B in tabAddress){D+="<tr><td style='width: 471px; white-space:nowrap; cursor: pointer;' ";D+='onclick="viewSearch('+B+');" ';D+="onmouseover=\"this.style.backgroundColor='#BECCE9'\" ";D+="onmouseout=\"this.style.backgroundColor='#FFFFFF'\">"+tabAddress[B][0]+"</span></td></tr>"}D+="<tr><td><a href='javascript: closeSearch();' style='color: #6688CC;'>"+A+"</a></td></tr>";D+="</table>";searchResultsDiv.innerHTML=D;searchDiv.appendChild(searchResultsDiv)}}}function showAddressGeocoder(A){geocoder.setViewport(map.getBounds());geocoder.getLocations(A,function(B){if(B.Status.code===200){var D=[3,6,8,11,12,13,15,16,17,17];for(var C in B.Placemark){if(tabAddress.length<=15){tabAddress.push([B.Placemark[C].address,new GLatLng(B.Placemark[C].Point.coordinates[1],B.Placemark[C].Point.coordinates[0]),D[B.Placemark[C].AddressDetails.Accuracy]])}}}displayShowAddressResults()})}function showAddressInternal(address){GDownloadUrl("s.php?q="+encodeURIComponent(address),function(data,responseCode){if(responseCode===200&&data!==""){var tabJSON=eval("("+data+")");for(var i in tabJSON){tabAddress.push([tabJSON[i].name,new GLatLng(tabJSON[i].lat,tabJSON[i].lng),17])}}showAddressGeocoder(address)})}function showAddress(A){tabAddress=[];try{searchDiv.removeChild(searchResultsDiv)}catch(B){}if(A===""){return false}showAddressInternal(A)}function closeSearch(){searchDiv.removeChild(searchResultsDiv);searchText.value=""}function searchAddress(){showAddress(document.getElementById("search").value)};
