﻿// JScript File
function IgnoreZeroLatLongs(bIgnore)
{
        //Check if there is any visible pushpin on map.
        var cnt = 0;
        bounds = new GLatLngBounds();
        for(var i=0;i<markers.getLength();i++)
        {
            var ignoremarker = false;
            var point1 = markers.markers[i].getPoint();
            if(bIgnore)
            {
                if((point1.x==0) && (point1.y==0))
                {
                    ignoremarker = true;
                }
            }
            if(!ignoremarker)
            {
                if(!markers.markers[i].isHidden())
                {
                    bounds.extend(markers.markers[i].getPoint());
                    //Increment visible pushpin count
                    cnt++;
                }
            }
            
        }
        var iZoomLevel = map.getBoundsZoomLevel(bounds);
        var point = bounds.getCenter();
        
        map.setZoom(iZoomLevel);
        map.setCenter(point);
    
}

  function ShowFullScreenMap()
  {
 
      var objButton = document.getElementById('btnFullScreen');
      if(objButton.value=='Full Screen')
      {
        var objMap = document.getElementById('GoogleMap_Div');
        var objDiv = document.getElementById('GoogleMap_Div_Container');
        objMap.style.width='100%';
        objMap.style.height='100%';

        objDiv.style.position='absolute';
        objDiv.style.left='0px';
        objDiv.style.top='0px';
        objDiv.style.width='99%';
        objDiv.style.height='95%';
        objDiv.style.backgroundColor='LightGrey';

        objButton.value='Close Fullscreen';
        DrawGoogleMap();
      }
      else
      {
        objMap = document.getElementById('GoogleMap_Div');
        objDiv = document.getElementById('GoogleMap_Div_Container');
        objMap.style.width='<%=GoogleMapObject.Width %>';
        objMap.style.height='<%=GoogleMapObject.Height %>';

        objDiv.style.position='';
        objDiv.style.left='';
        objDiv.style.top='';
        objDiv.style.width='';
        objDiv.style.height='';

        objButton.value='Full Screen';
        //DrawGoogleMap();
      }
}

var map;
var trafficInfo = null;

//function fListeners()
//{
//    this.listeners = new Array();
//    this.getLength = function() { return this.listeners.length; };
//    this.pushValue = function(v) { this.listeners.push(v); }
//    this.getValue = function(i)  { return this.listeners[i]; }
//}
function fMarkers()
{
    this.markers = new Array();
    this.getLength = function() { return this.markers.length; };
    this.pushValue = function(v) { this.markers.push(v); }
    this.getValue = function(i)  { return this.markers[i]; }
    this.getLastValue = function()  { return this.markers[this.markers.length-1]; }
    this.getValueById = function(ID)  {
                                        var i;
                                        for(i=0;i<this.markers.length;i++)
                                        {
                                            if(this.markers[i].value==ID)
                                            {
                                               // alert('marker found : '+this.markers[i].value);
                                                return this.markers[i];
                                            }
                                        } 
                                        return null; 
                                      }
    this.removeValueById = function(ID)  {
                                        var i;
                                        for(i=0;i<this.markers.length;i++)
                                        {
                                            if(this.markers[i].value==ID)
                                            {
                                               // alert('marker found : '+this.markers[i].value);
                                                this.markers.splice(i,1);
                                                //alert('changed marker removed');

                                            }
                                        } 
                                        return null; 
                                      }
}

function fPolylines()
{
    this.polylines = new Array();
    this.polylinesID = new Array();
    this.getLength = function() { return this.polylines.length; };
    this.pushValue = function(v,ID) {  this.polylines.push(v); this.polylinesID.push(ID); }
    this.getValue = function(i)  { return this.polylines[i]; }
    this.getLastValue = function()  { return this.polylines[this.polylines.length-1]; }
    this.getValueById = function(ID)  {
                                        var i;
                                        for(i=0;i<this.polylinesID.length;i++)
                                        {
                                            if(this.polylinesID[i]==ID)
                                            {
                                               // alert('polyline found : '+this.polylines[i].value);
                                                return this.polylines[i];
                                            }
                                        }
                                        return null;
                                      }
  this.removeValueById = function(ID) {
                                        var i;
                                        for(i=0;i<this.polylinesID.length;i++)
                                        {
                                            if(this.polylinesID[i]==ID)
                                            {
                                                this.polylines.splice(i,1);
                                                this.polylinesID.splice(i,1);
                                            }
                                        }
                                        return null;
                                      }
}

function fPolygons()
{//1
    this.polygons = new Array();
    this.polygonsID = new Array();
    this.getLength = function() { return this.polygons.length; };
    this.pushValue = function(v,ID) {  this.polygons.push(v); this.polygonsID.push(ID); }
    this.getValue = function(i)  { return this.polygons[i]; }
    this.getLastValue = function()  { return this.polygons[this.polygons.length-1]; }
    this.getValueById = function(ID)  {
                                        var i;
                                        for(i=0;i<this.polygonsID.length;i++)
                                        {
                                            if(this.polygonsID[i]==ID)
                                            {
                                                return this.polygons[i];
                                            }
                                        } 
                                        return null;
                                      }
    this.removeValueById = function(ID)  {
                                        var i;
                                        for(i=0;i<this.polygonsID.length;i++)
                                        {
                                            if(this.polygonsID[i]==ID)
                                            {
                                                this.polygons.splice(i,1);
                                                this.polygonsID.splice(i,1);
                                            }
                                        } 
                                        return null; 
                                      }
}

if (GBrowserIsCompatible())
{


map = new GMap2(document.getElementById("GoogleMap_Div"));

var markers = new fMarkers();
var polylines = new fPolylines();
var polygons = new fPolygons();
//var myEventListeners = new fListeners();
 /*               
function CreateMarker(point,icon1,InfoHTML,bDraggable,sTitle)
{
    var marker;
    marker = new GMarker(point,{icon:icon1,draggable:bDraggable,title: sTitle});
     
    if(InfoHTML!='')
    {
        GEvent.addListener(marker, "click", function() { this.openInfoWindowHtml(InfoHTML); });
    }
        GEvent.addListener(marker, "dragend", function() {  GService.SetLatLon(this.value,this.getLatLng().y,this.getLatLng().x);RaiseEvent('PushpinMoved',this.value);  });
    return marker;
}*/



function CreateMarker(point,icon1,InfoHTML,bDraggable,sTitle)
{
    var marker;
    var infoTabs;
    
    pfotos = null;
    linkFoto = null;
    linkFileFoto = null;    
    propietarioName = null;
    propietarioURL = null;
    tituloImagen = null;
    numFotos = null;
    
    marker = new GMarker(point,{icon:icon1,draggable:bDraggable,title: sTitle});

    var minLong = point.lat() - 0.0050;
    var maxLong = point.lat() + 0.0050;
    var minLat = point.lng() - 0.0050;
    var maxLat = point.lng() + 0.0050;

    urlPano = 'http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=public&from=0&to=3&minx='+minLat+'&miny='+minLong+'&maxx='+maxLat+'&maxy='+maxLong+'&callback=?';

	infoTabs = [new GInfoWindowTab('Datos','<div id="tab1">'+InfoHTML+' </DIV>'),
	            new GInfoWindowTab('Rurales','<div id="tups"></div><div id="resultados" style="width: 0px; height: 0px; visibility: hidden; font-size: xx-small;">'+urlPano+'</div>'),
			    new GInfoWindowTab('Fotografías', '<div id="Titulo" style="font-size: xx-small;"></div><div id="imagenPanoramio"></div><div style="font-size: xx-small;"><div id="Panoramio"></div><div id="autor"></div></div>')]; 
			
			//<a href="'+linkFoto+'"><img src="'+linkFileFoto+'"></a>

    if(InfoHTML!='')
    {
                                                
        GEvent.addListener(marker, 
                            "click", 
                            function() {
                            
                                    this.openInfoWindowTabsHtml(infoTabs);                                
                                
                                
             PageMethods.Muestra_Tups_Info(InfoHTML,function(result){
                                                        if(($("#tups").html())==''){
                                                                       $('#tups').prepend(result);
                                                        }
                                                    },
                                                    function(result){
                                                            if(($("#tups").html())==''){
                                                                           $('#tups').prepend('Ocurrió un error. Intente la búsqueda más tarde.');
                                                            }
                                                    });  



                                $.getJSON(($("#resultados").html()),
                                //$.getJSON(urlPano),
                                           function mostrarfotos(panoramio)
                                               {    numFotos = panoramio.count;
                                                    if(numFotos > 0){
                                                        pfotos = panoramio.photos;
                                                        linkFoto = pfotos[0].photo_url;
                                                        linkFileFoto = pfotos[0].photo_file_url;
                                                        propietarioName = pfotos[0].owner_name;
                                                        propietarioURL = pfotos[0].owner_url;
                                                        tituloImagen = pfotos[0].photo_title;
                                                        if(($("#imagenPanoramio").html())==''){
                                                            var panoram = '<img src="panoramio.jpg" width="45px" height="11px">';
                                                            var aut = 'Autor:'+propietarioName+'';
                                                            $("#imagenPanoramio").prepend( '<a href="'+linkFoto+'"><img src="'+linkFileFoto+'" width="200px" height="150px"></a>' );
                                                            //$("#autor").prepend( '<a href="'+propietarioURL+'">Autor:'+propietarioName+'</a>' );
                                                            $("#Titulo").prepend( tituloImagen );
                                                            $("#Panoramio").prepend('<table style="font-size: xx-small; height: 19px; width: 165px;"><tr><td style="width: 59px;">'+panoram+'</td><td style="height: 19px;">'+aut+'</td></tr> </table>' );
                                                        }
                                                    }else{
                                                        if(($("#imagenPanoramio").html())==''){
                                                            $("#imagenPanoramio").prepend( '<font size=2>No se encontraron fotografías en esta localidad</font>' );
                                                        }
                                                    }
                                               });
                                
                                
                            });
        
        
    }
        GEvent.addListener(marker, "dragend", function() {  GService.SetLatLon(this.value,this.getLatLng().y,this.getLatLng().x);RaiseEvent('PushpinMoved',this.value);  });
    return marker;
}

function CrearMensaje(coord_x,coord_y,InfoHTML,departamento,codigo,sTitle,icono)
{    
    var minLong = 0;
    var maxLong = 0;
    var minLat = 0;
    var maxLat = 0;
    var marker = new GMarker(new GPoint(coord_x, coord_y));    
    map.addOverlay(marker); 
    var cad = "<font size=2>Localidad: " + InfoHTML + "<BR><div/>En el departamento de: " + departamento + "<BR>Telefonía Móvil: <img alt='Móviles' src=' " + icono + "' />" + "<BR><div/><A href=Encuesta.aspx?codigoinei2002=" + codigo + " width=(screen.width-300)/2 heigth=(screen.height-200)/2 target=_blank>Reporte de Problemas/Comentarios</A></font>";
    minLong = coord_y - 0.0050;
    maxLong = coord_y + 0.0050;
    minLat = coord_x - 0.0050;
    maxLat = coord_x + 0.0050;

    var urlPano = '';
       
    infoTabs = [new GInfoWindowTab('Datos','<div id="tab1">'+cad+'</div><div id="resultados" style="width: 0px; height: 0px; visibility: hidden; font-size: xx-small;">'+urlPano+'</div>'),
			    new GInfoWindowTab('Fotografías', '<div id="Titulo" style="font-size: xx-small;"></div><div id="imagenPanoramio"></div><div style="font-size: xx-small;"><div id="Panoramio"></div><div id="autor"></div></div>')]; 

    pfotos = null;
    linkFoto = null;
    linkFileFoto = null;    
    propietarioName = null;
    propietarioURL = null;
    tituloImagen = null;
    numFotos = null;     
			       
    if(InfoHTML!='')
    {
        marker.openInfoWindowHtml(cad);
        marker.hide();
    }
}

function OpenInfoWindow(id,InfoHTML)
{
    
    var marker = markers.getValueById(id);
    if(marker!=null)
    {        
        marker.openInfoWindowHtml(InfoHTML);
    }
}

function CreatePolyline(points,color,width,isgeodesic)
{
    var polyline;
    if(!isgeodesic)
    {
        polyline = new GPolyline(points,color,width);
    }
    else
    {
        var polyOptions = {geodesic:true};
        polyline = new GPolyline(points,color,width,1,polyOptions);
    }
    return polyline;
}

function CreatePolygon(points,strokecolor,strokeweight,strokeopacity,fillcolor,fillopacity)
{
    var polygon = new GPolygon(points,strokecolor,strokeweight,strokeopacity,fillcolor,fillopacity);
    return polygon;
}

function fGetGoogleObject(result, userContext)
{
    map.setCenter(new GLatLng(result.CenterPoint.Latitude, result.CenterPoint.Longitude), result.ZoomLevel);
    
    if(result.ShowMapTypesControl)
    {
        map.addControl(new GMapTypeControl());
    }

    if(result.ShowZoomControl)
    {
        map.addControl(new GLargeMapControl());
    }
    
    
    map.setMapType(eval(result.MapType));
    
    var i;
    if(markers!=null)
    {
        for(i=0;i<markers.getLength();i++)
        {
            var cmark = markers.getValue(i);
            if(cmark !=null)
            {
                    map.removeOverlay(cmark);
            }
        }
    }
    markers = new fMarkers();

    for(i=0;i<result.Points.length;i++)
    {
        var myIcon_google;

        var myPoint = new GLatLng(result.Points[i].Latitude, result.Points[i].Longitude);
        
        myIcon_google = null;
        if(result.Points[i].IconImage!='')
        {
            myIcon_google = new GIcon(G_DEFAULT_ICON);
            markerOptions = { icon:myIcon_google };
            
            myIcon_google.iconSize = new GSize(result.Points[i].IconImageWidth,result.Points[i].IconImageHeight);
            myIcon_google.image = result.Points[i].IconImage;
            myIcon_google.shadow = result.Points[i].IconShadowImage;
            myIcon_google.shadowSize = new GSize(result.Points[i].IconShadowWidth, result.Points[i].IconShadowHeight);
            myIcon_google.iconAnchor =  new GPoint(result.Points[i].IconAnchor_posX, result.Points[i].IconAnchor_posY);
            myIcon_google.infoWindowAnchor = new GPoint(result.Points[i].InfoWindowAnchor_posX, result.Points[i].InfoWindowAnchor_posY);
        }
        
        //var marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,result.Points[i].Draggable,result.Points[i].ToolTip);
        var marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,false,result.Points[i].ToolTip);
        marker.value = result.Points[i].ID;
        markers.pushValue(marker);
        map.addOverlay(markers.getLastValue());


    }

    polylines = new fPolylines();
    for(i=0;i<result.Polylines.length;i++)
    {
	 var polypoints = new Array();
	 var j;
	 for(j=0;j<result.Polylines[i].Points.length;j++)
 	 {
	 	polypoints.push(new GLatLng(result.Polylines[i].Points[j].Latitude, result.Polylines[i].Points[j].Longitude));
	 }
        var polyline = CreatePolyline(polypoints,result.Polylines[i].ColorCode,result.Polylines[i].Width,result.Polylines[i].Geodesic);
        polylines.pushValue(polyline,result.Polylines[i].ID);
        map.addOverlay(polylines.getLastValue());
    }
// var polypoints = new Array();
// polypoints.push(new GLatLng(43.65669, -79.44268));
// polypoints.push(new GLatLng(43.66619, -79.44268));
// var poly = CreatePolyline(polypoints,"#66FF00",10,true);
// map.addOverlay(poly);

// var polypoints = new Array();
// polypoints.push(new GLatLng(43.65669, -79.44268));
// polypoints.push(new GLatLng(43.66619, -79.44268));
// polypoints.push(new GLatLng(43.67619, -79.44268));
// var directions = new GDirections(map,document.getElementById("directions_canvas")); 
//Clear the mapa nd directions of any old information
//directions.clear();

//Load the map and directions from the specified waypoints
//directions.loadFromWaypoints(polypoints);


    polygons = new fPolygons();
    for(i=0;i<result.Polygons.length;i++)
    {
	 polypoints = new Array();
	 for(j=0;j<result.Polygons[i].Points.length;j++)
 	 {
	 	polypoints.push(new GLatLng(result.Polygons[i].Points[j].Latitude, result.Polygons[i].Points[j].Longitude));
	 }
        var polygon = CreatePolygon(polypoints,result.Polygons[i].StrokeColor,result.Polygons[i].StrokeWeight,result.Polygons[i].StrokeOpacity,result.Polygons[i].FillColor,result.Polygons[i].FillOpacity);
        polygons.pushValue(polygon,result.Polygons[i].ID);
        map.addOverlay(polygons.getLastValue());
    }

    
    if(result.ShowTraffic)
    {
        trafficInfo = new GTrafficOverlay();
        map.addOverlay(trafficInfo);
    }
    if(result.AutomaticBoundaryAndZoom)
    {
        RecenterAndZoom(true,result);
    }

}

function DrawGoogleMap()
{
    if (GBrowserIsCompatible())
    {
        map = new GMap2(document.getElementById("GoogleMap_Div"));
        geocoder = new GClientGeocoder();
        GService.GetGoogleObject(fGetGoogleObject);
    } 
} 

 
function fGetGoogleObjectOptimized(result, userContext)
{
    if(result.RecenterMap)
    {
        map.setCenter(new GLatLng(result.CenterPoint.Latitude, result.CenterPoint.Longitude), result.ZoomLevel);
        GService.RecenterMapComplete();
    }
    
    map.setMapType(eval(result.MapType));

    if(result.ShowTraffic)
    {
        trafficInfo = new GTrafficOverlay();
        map.addOverlay(trafficInfo);
    }
    else
    {
        if(trafficInfo!=null)
        {
            map.removeOverlay(trafficInfo);
            trafficInfo = null;
        }
    }

    var i;
    for(i=0;i<result.Points.length;i++)
    {
        //Create icon
        var myIcon_google;

        var myPoint = new GLatLng(result.Points[i].Latitude, result.Points[i].Longitude);
        
        myIcon_google = null;
        if(result.Points[i].IconImage!='')
        {
            myIcon_google = new GIcon(G_DEFAULT_ICON);
            markerOptions = { icon:myIcon_google };
            myIcon_google.iconSize = new GSize(result.Points[i].IconImageWidth,result.Points[i].IconImageHeight);
            myIcon_google.iconSize = new GSize(1,1);
            myIcon_google.image = result.Points[i].IconImage;
            myIcon_google.shadow = result.Points[i].IconShadowImage;
            myIcon_google.shadowSize = new GSize(result.Points[i].IconShadowWidth, result.Points[i].IconShadowHeight);
            myIcon_google.iconAnchor =  new GPoint(result.Points[i].IconAnchor_posX, result.Points[i].IconAnchor_posY);
            myIcon_google.infoWindowAnchor = new GPoint(result.Points[i].InfoWindowAnchor_posX, result.Points[i].InfoWindowAnchor_posY);
        }
        //Existing marker, but changed.
        if(result.Points[i].PointStatus=='C')
        {
            var marker = markers.getValueById(result.Points[i].ID);
            if(marker!=null)
            {
                markers.removeValueById(result.Points[i].ID);
                map.removeOverlay(marker);
            }
            //marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,result.Points[i].Draggable,result.Points[i].ToolTip);
            marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,false,result.Points[i].ToolTip);
            marker.value = result.Points[i].ID;
            markers.pushValue(marker);
            map.addOverlay(markers.getLastValue());
        }
        //New Marker
        if(result.Points[i].PointStatus=='N')
        {
            //marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,result.Points[i].Draggable,result.Points[i].ToolTip);
            marker = CreateMarker(myPoint,myIcon_google,result.Points[i].InfoHTML,false,result.Points[i].ToolTip);
            marker.value = result.Points[i].ID;
            markers.pushValue(marker);
            map.addOverlay(markers.getLastValue());
        }
        //Existing marker, but deleted.
        if(result.Points[i].PointStatus=='D')
        {
            marker = markers.getValueById(result.Points[i].ID);
            if(marker!=null)
            {
                markers.removeValueById(result.Points[i].ID);
                map.removeOverlay(marker);
            }
        }
    }
    
    //Get Polylines
    for(i=0;i<result.Polylines.length;i++)
    {
        //Existing marker, but changed.
        
        if(result.Polylines[i].LineStatus=='C')
        {
        
            var polyline = polylines.getValueById(result.Polylines[i].ID);
            if(polyline!=null)
            {
                polylines.removeValueById(result.Polylines[i].ID);
                map.removeOverlay(polyline);
            }
	        var polypoints = new Array();
	        var j;
	        for(j=0;j<result.Polylines[i].Points.length;j++)
 	        {
	 	        polypoints.push(new GLatLng(result.Polylines[i].Points[j].Latitude, result.Polylines[i].Points[j].Longitude));
	        }
            polyline = CreatePolyline(polypoints,result.Polylines[i].ColorCode,result.Polylines[i].Width,result.Polylines[i].Geodesic);
            polylines.pushValue(polyline,result.Polylines[i].ID);
            map.addOverlay(polylines.getLastValue());
        }
        //New Marker

        if(result.Polylines[i].LineStatus=='N')
        {
	        polypoints = new Array();
	        for(j=0;j<result.Polylines[i].Points.length;j++)
 	        {
	 	        polypoints.push(new GLatLng(result.Polylines[i].Points[j].Latitude, result.Polylines[i].Points[j].Longitude));
	        }
            polyline = CreatePolyline(polypoints,result.Polylines[i].ColorCode,result.Polylines[i].Width,result.Polylines[i].Geodesic);
            polylines.pushValue(polyline,result.Polylines[i].ID);
            map.addOverlay(polylines.getLastValue());
        }
        //Existing marker, but deleted.
        if(result.Polylines[i].LineStatus=='D')
        {
            polyline = polylines.getValueById(result.Polylines[i].ID);
            if(polyline!=null)
            {
                polylines.removeValueById(result.Polylines[i].ID);
                map.removeOverlay(polyline);
            }
        }
    }
    
        //Get Polygons
    for(i=0;i<result.Polygons.length;i++)
    {
        //Existing marker, but changed.

        if(result.Polygons[i].Status=='C')
        {
        
            polygon = polygons.getValueById(result.Polygons[i].ID);
            if(polygon!=null)
            {
                polygons.removeValueById(result.Polygons[i].ID);
                map.removeOverlay(polygon);
            }
	        polypoints = new Array();
	        for(j=0;j<result.Polygons[i].Points.length;j++)
 	        {
	 	        polypoints.push(new GLatLng(result.Polygons[i].Points[j].Latitude, result.Polygons[i].Points[j].Longitude));
	        }
            polygon = CreatePolygon(polypoints,result.Polygons[i].StrokeColor,result.Polygons[i].StrokeWeight,result.Polygons[i].StrokeOpacity,result.Polygons[i].FillColor,result.Polygons[i].FillOpacity);
            polygons.pushValue(polygon,result.Polygons[i].ID);
            map.addOverlay(polygons.getLastValue());
        }
        //New Marker

        if(result.Polygons[i].Status=='N')
        {
	        polypoints = new Array();
	        for(j=0;j<result.Polygons[i].Points.length;j++)
 	        {
	 	        polypoints.push(new GLatLng(result.Polygons[i].Points[j].Latitude, result.Polygons[i].Points[j].Longitude));
	        }
            polygon = CreatePolygon(polypoints,result.Polygons[i].StrokeColor,result.Polygons[i].StrokeWeight,result.Polygons[i].StrokeOpacity,result.Polygons[i].FillColor,result.Polygons[i].FillOpacity);
            polygons.pushValue(polygon,result.Polygons[i].ID);
            map.addOverlay(polygons.getLastValue());
        }
        //Existing marker, but deleted.
        if(result.Polygons[i].Status=='D')
        {
            polygon = polygons.getValueById(result.Polygons[i].ID);
            if(polygon!=null)
            {
                polygons.removeValueById(result.Polygons[i].ID);
                map.removeOverlay(polygon);
            }
        }
    }
    if(result.AutomaticBoundaryAndZoom)
    {
        RecenterAndZoom(true,result);
    }
}
}

//This function causes Recentering of map. It finds all visible markers on map and decides center point and zoom level based on these markers.
function RecenterAndZoom(bRecenter,result)
{
    if(bRecenter)
    {
        //Check if there is any visible pushpin on map.
        var cnt = 0;
        bounds = new GLatLngBounds();
        var objIgnore = document.getElementById('chkIgnoreZero');
        var bIgnore = false;
        if(objIgnore!=null)
        {
           bIgnore  = objIgnore.checked;
        }    
        bIgnore = result.IgnoreZeroLatLngs;
        for(var i=0;i<markers.getLength();i++)
        {
            var ignoremarker = false;
            if(bIgnore)
            {
                var point1 = markers.markers[i].getPoint();
                if((point1.x==0) && (point1.y==0))
                {
                    ignoremarker = true;
                }
            }
            if(!ignoremarker)
            {
                if(!markers.markers[i].isHidden())
                {
                    bounds.extend(markers.markers[i].getPoint());
                    //Increment visible pushpin count
                    cnt++;
                }
            }
            
        }
        var iZoomLevel = map.getBoundsZoomLevel(bounds);
        var point = bounds.getCenter();
        
        if(iZoomLevel>14)
        {
            iZoomLevel = 14;
        }
        
        if(cnt<=0)
        {
            point = new GLatLng(result.CenterPoint.Latitude,result.CenterPoint.Longitude);
            iZoomLevel =result.ZoomLevel;
        }
        map.setZoom(iZoomLevel);
        map.setCenter(point);
    }
}
function endRequestHandler(sender, args)
{
    GService.GetOptimizedGoogleObject(fGetGoogleObjectOptimized);
}
function pageLoad()
{
    //if(!Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack())
    //    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
