function showYMap(location, zoom, w, h)
{
    if (location == "" || zoom == 0) return;
    
    var map;
    // Create a map object
    if (document.getElementById('ymap') != null)
        map = new YMap(document.getElementById('ymap'), YAHOO_MAP_REG, new YSize(w, h));
    else
        map = new YMap(document.getElementById('imap'), YAHOO_MAP_REG, new YSize(w, h));
    
    if (map != null)
    {
        // Add map type control
        map.addTypeControl();
        map.addZoomLong();
        map.addPanControl();
        
        map.disableKeyControls();

        // Set map type to either of: YAHOO_MAP_SAT, YAHOO_MAP_HYB, YAHOO_MAP_REG
        //map.setMapType(YAHOO_MAP_REG);

        // Display the map centered on a geocoded location
        map.drawZoomAndCenter(location, zoom);
        
        YEvent.Capture(map, EventsList.MouseClick, reportPosition);
        function reportPosition(_e, _c)
        {
        }
//            var currentGeoPoint = new YGeoPoint( _c.Lat, _c.Lon );
//            if (map.getZoomLevel() > 13)
//            {
//                map.drawZoomAndCenter(currentGeoPoint, map.getZoomLevel() - 2);
//            }
//            else
//            {
//                //var customM = new YImage('/images/error.gif', new YSize(12,12), new YCoordPoint(0,0));
//                //map.addMarker(currentGeoPoint, customM);
//            }
            
            // It is optional to specify the location of the Logger. 
            // Do so by sending a YCoordPoint to the initPos function.
//            var mapCoordCenter = map.convertLatLonXY(map.getCenterLatLon());
//            YLog.initPos(mapCoordCenter); //call initPos to set the starting location
//            // Printing to the Logger
//            YLog.print("You Made a MouseClick!");
//            YLog.print("Latitude:" + _c.Lat);
//            YLog.print("Longitude:" + _c.Lon);
//    		
//            YLog.print("Adding marker at....");
//            YLog.print("\nLatitude:" + _c.Lat + "\nLongitude:" + _c.Lon);
//        }
        
        return map;
    }
}

function showYMap2(location, zoom, w, h)
{
    if (location == "" || zoom == 0) return;
    
    if (document.getElementById('ymap') != null)
    {
        // Create a map object
        var map = new YMap(document.getElementById('ymap'), YAHOO_MAP_HYB, new YSize(w, h));
        //var map = new YMap(document.getElementById('ymap'));//

        // Add map type control
        map.addTypeControl();
        map.disableKeyControls();
        map.drawZoomAndCenter(location, zoom);
    }
}

function showIncident(container, lat, lon, zoom, w, h)
{
    if (container != null)
    {
        // Create a map object
        var map = new YMap(container, YAHOO_MAP_HYB, new YSize(w, h));

        // Add map type control
        map.addTypeControl();
        map.addZoomLong();
        map.addPanControl();
        map.disableKeyControls();

        // Set map type to either of: YAHOO_MAP_SAT, YAHOO_MAP_HYB, YAHOO_MAP_REG
        //map.setMapType(YAHOO_MAP_REG);

        // Display the map centered on a geocoded location
        
        var currentGeoPoint = new YGeoPoint(lat, lon);
        map.drawZoomAndCenter(currentGeoPoint, zoom);
        var customM = new YImage('/images/design/marker.png', new YSize(30,30), new YCoordPoint(0,0));
        map.addMarker(currentGeoPoint, customM);
    }
}

function showIncidents(map, lat, lon, intelligence_id, title)
{
    if (map != null && title != "")
    {
        var currentGeoPoint = new YGeoPoint(lat, lon);
        map.drawZoomAndCenter(currentGeoPoint, 13);
        
        var customM = new YImage('/images/design/incident.png', new YSize(20,20), new YCoordPoint(10,10));
        var myMarker = new YMarker(currentGeoPoint, customM);
        
        myMarker.setSmartWindowColor('maroon');
        map.addOverlay(myMarker);
        
        YEvent.Capture(myMarker, EventsList.MouseOver, function() {myMarker.openSmartWindow('<div style="margin-top:15px; width:200px;"><b>' + title.replace("'", "''") + '</b></div><div><a href="/intelligence.aspx?id=' + intelligence_id + '">click here to view details</a></div>')});
    }
}

function CreateMap(w, h, map_type)
{
    if (document.getElementById('ymap') != null || document.getElementById('imap') != null)
    {
        var map;
        // Create a map object
        if (document.getElementById('ymap') != null)
            map = new YMap(document.getElementById('ymap'), map_type, new YSize(w, h));
        else
            map = new YMap(document.getElementById('imap'), map_type, new YSize(w, h));

        // Add map type control
        map.addTypeControl();
        map.addZoomLong();
        map.addPanControl();
        
        map.disableKeyControls();

        YEvent.Capture(map, EventsList.MouseClick, reportPosition);
        function reportPosition(_e, _c)
        {
        }
        
        return map;
    }
    else
        return null;
}

var intel = new Array();
function AddIntel(map, lat, lon, intelligence_id, title)
{
    if (map != null && title != "")
    {
        var currentGeoPoint = new YGeoPoint(lat, lon);
        intel.push(currentGeoPoint);
        
        var customM = new YImage('/images/design/incident2.png', new YSize(15,15), new YCoordPoint(8,8));
        var myMarker = new YMarker(currentGeoPoint, customM);
        
        myMarker.setSmartWindowColor('maroon');
        map.addOverlay(myMarker);
        
        YEvent.Capture(myMarker, EventsList.MouseOver, function() {myMarker.openSmartWindow('<div style="margin-top:15px; width:200px;"><b>' + title + '</b></div><div><a href="/intelligence.aspx?id=' + intelligence_id + '">click here to view details</a></div>')});
    }
}

function ShowIntelMap(location, zoom, recenter)
{
    var _zoom = zoom;
    var _location = location;
    
    if (intel.length > 0 && recenter)
    {
        var loc = map.getBestZoomAndCenter(intel);
        if (loc != null)
        {
            _zoom = loc.zoomLevel
            _location = loc.YGeoPoint;
            
            if (_zoom < (zoom - 2)) _zoom = (zoom - 2);
    
            if (_zoom < 3) _zoom = 3;
        }
    }

    if (_location != null)
        map.drawZoomAndCenter(_location, _zoom);
}