﻿var map = null;
var marker = null;
var updatemessage = "";
var mapemail = ""; 

function LoadMap(lat, lon, zoom, message, email)
{
    mapemail = email;
    updatemessage = message;
    GetMap();
    DoCenterZoom(lat, lon, zoom);
}      
function GetMap()      
{   
    if(document.getElementById('ucMap__dvMapDisplay') != null)
    {
        map = new VEMap('ucMap__dvMapDisplay');         
        map.LoadMap();  
        map.AttachEvent("onclick", PixelClick);
        document.getElementById('MSVE_obliqueNotification').innerHTML = "";
        
    }
}    
function PixelClick(e)
{
    if(map.GetMapStyle() == VEMapStyle.Road && (document.getElementById('_chkMarkerToggle') != null && document.getElementById('_chkMarkerToggle').checked))
    {
        var latlong = map.PixelToLatLong(new VEPixel(e.mapX, e.mapY));
        var message = updatemessage + latlong;
        message = "If your map location is not correct and you would like to set your map location to this marker location,<br><a href=\'mailto:" + mapemail + "?subject=Map Location Update Request&body=" + message + "\'>Click Here</a> to Email MYC. <br><br>Latitude: " + latlong.Latitude + "<br>Longitude: "+ latlong.Longitude ;
        if(marker != null)
            map.DeleteShape(marker);
        marker = AddPin("tmpmarker", latlong.Latitude, latlong.Longitude, "Latitude / Longitude:", message, "pin3");
    }
}
function ToggleMarker(chk)
{
    if(!chk.checked && marker != null)
        map.DeleteShape(marker);
}          
function DoCenterZoom(lat, lon, zoom)      
{        
    if(map != null)      
        map.SetCenterAndZoom(new VELatLong(lat, lon), zoom);      
}     
function AddPin(id, lat, lon, title, description, type)
{   
    if(map != null)
    {
    var pin = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lon));
    pin.SetCustomIcon("<div class='" + type + "'></div>");    //pin.SetPhotoURL("http://localhost:2740/MYCWeb/App_Themes/Standard/images/map/note.gif");
    pin.SetTitle(title);
    pin.SetDescription(description);
    map.AddShape(pin);
    }
    return pin;
}