var geocoder;var points=new Array();var pts_options=new Array();var group_markers=new Array();var G_MAP_TYPE;var map;var mapType;var rawPoints;var POINTS_ARRAY_LIMIT=9;var index=0;var initialStep=70;var step=initialStep;var lastIndex=0;var delay=0;var DELAY_STEP=500;var MAX_RETRIES=5;var retries=0;function load(){if(GBrowserIsCompatible()){try{geocoder=new GClientGeocoder();geocoder.setCache(new GGeocodeCache());points=new Array();if(G_MAP_TYPE==null){mapType="G_NORMAL_MAP"}else{mapType="G_MAP_TYPE"}map=new GMap2(document.getElementById(mapId),mapType);map.setCenter(new GLatLng(-31.643312,-60.706758));if(showControllers){map.addControl(new GLargeMapControl());map.addControl(new GScaleControl());map.addControl(new GOverviewMapControl())}var a=new GLatLng(-31.643312,-60.706758)}catch(b){if(typeof console!=undefined){console.debug("-Load- An error ocurred when try to create the map. Error: "+b)}}}}function addTag(a,c,e){if(a instanceof GLatLng){try{if(e instanceof GIcon){var b=new GMarker(a,{draggable:true,icon:e});if(typeof c!="undefined"){GEvent.addListener(b,"click",function(){b.openInfoWindowHtml(c)})}GEvent.addListener(b,"dragstart",function(){map.closeInfoWindow()});GEvent.addListener(b,"dragend",function(){b.openInfoWindowHtml(c)})}else{var b=new GMarker(a,{draggable:true});if(typeof c!="undefined"){GEvent.addListener(b,"click",function(){b.openInfoWindowHtml(c)})}GEvent.addListener(b,"dragstart",function(){map.closeInfoWindow()});GEvent.addListener(b,"dragend",function(){b.openInfoWindowHtml(c)})}return b}catch(d){if(typeof console!=undefined){console.debug("-AddTag- Can't add a tag to the point. Error: "+d)}}}else{if(typeof console!=undefined){console.debug("You need a point")}}}function createIcon(c,g,b,j,a,e,h){var f=new GIcon();try{f.image=c;if(g instanceof GSize){f.iconSize=g}else{f.iconSize=new GSize(20,27)}if(b instanceof GPoint){f.iconAnchor=b}else{f.iconAnchor=new GPoint(0,34)}if(a instanceof GSize){f.shadowSize=a}else{f.shadowSize=new GSize(20,27)}f.shadow=j;if(typeof a!="undefined"){f.printImage=c;f.mozPrintImage=c}if(!e instanceof GPoint){f.infoWindowAnchor=new GPoint(9,2)}else{f.infoWindowAnchor=e}return f}catch(d){if(typeof console!=undefined){console.debug("-CreateIcon- Can't create a icon. The error is: "+d)}}}function addPoint(a){if(!a||a.Status.code!=200){if(a.Status.code==620){throw"TOO_MANY_QUERIES_EXCEPTION"}else{index++;if(index<rawPoints.length){geocodeAll()}else{setMarkers()}}}else{try{place=a.Placemark[0];points.push(new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]));processNextPoint()}catch(b){if(typeof console!=undefined){console.debug("-AddPoint- Can't add the point. Error: "+b)}}}}function processNextPoint(){try{if(index==0){$("markersCounter").style.display="block";if($("prog_img")!=null){width=$("prog_img").width;width=width+$("prog_img").style.width;$("prog_img").style.display="none"}}index++;$("progressText").innerHTML="<B>Loading"+parseInt(index*100/rawPoints.length)+"% </B>";if($("prog_img")!=null){$("prog_img").style.width=parseInt(width*index/rawPoints.length);$("prog_img").width=parseInt(width*index/rawPoints.length)}}catch(a){}if(index==step){setMarkers(false,lastIndex);lastIndex=index;step=step+initialStep}if($("prog_img")!=null){$("prog_img").style.display="block"}if(index<rawPoints.length){geocodeAll()}else{document.getElementById("markersCounter").style.display="none";setMarkers(false,lastIndex);centerAndSetZoom(points)}}function addLocation(m,l,j,n,h,d,c,g,k){var f=new GClientGeocoder();var b=new GIcon();var a=new Array();if(m instanceof GLatLng){points.push(m)}else{f.getLocations(m,addPoint)}try{if(typeof l!="undefined"&&l!=""){a[0]=l}if(typeof j!="undefined"&&j!=""){a[1]=createIcon(j,h,d,n,c,g,k)}pts_options.push(a);if(m instanceof GLatLng){processNextPoint()}}catch(e){if(e=="ii"){if(typeof console!=undefined){console.debug("-Add Location- Invalid instace. Please provide a GPoint Instance")}}else{}}}function centerAndSetZoom(d){if(d instanceof Array){var c=new GLatLngBounds();try{for(i=0;i<=d.length-1;i++){if((d[i] instanceof GLatLng)){c.extend(d[i])}else{if(typeof console!=undefined){console.debug("The point is not a valid geolocation")}}}var a=c.getCenter();if(zoomLevel!=false){map.setCenter(c.getCenter(),zoomLevel)}else{map.setCenter(c.getCenter(),map.getBoundsZoomLevel(c))}}catch(b){if(typeof console!=undefined){console.debug("-CenterAndSetZoom- Can't center the bounds. Error: "+b)}}}}function setMarkers(b,c){b=typeof(b)!="undefined"?b:true;c=typeof(c)!="undefined"?c:0;if(b){group_markers=new Array();map.clearOverlays()}try{for(i=c;i<points.length;i++){group_markers.push(addTag(points[i],pts_options[i][0],pts_options[i][1]))}for(i=c;i<group_markers.length;i++){map.addOverlay(group_markers[i])}}catch(a){if(typeof console!=undefined){console.debug("-SetMarker- Can't show marker. Error: "+a)}}}function toGeocode(a){rawPoints=a;delay=0;index=0;geocodeAll()}function geocodeAll(){try{if(index<rawPoints.length&&retries<=MAX_RETRIES){if(rawPoints[index].length==POINTS_ARRAY_LIMIT){elem=rawPoints[index];window.setTimeout("addLocation(elem[0],elem[1],elem[2],elem[3],elem[4],elem[5],elem[6],elem[7],elem[8])",delay)}else{if(typeof console!=undefined){console.debug("Malformed query.Parameter needed "+POINTS_ARRAY_LIMIT+". But received "+rawPoints[index].lenght)}}retries=0}else{if(retries>=MAX_RETRIES){if(typeof console!=undefined){console.debug("Reached the maximum of retries!")}}else{}}}catch(a){if(a=="TOO_MANY_QUERIES_EXCEPTION"){delay=delay+DELAY_STEP;retries++;geocodeAll()}else{if(typeof console!=undefined){console.debug("-GeocodeAll- An error has ocurred. Error: "+a)}}}};
