var map = null;

   
         




function LoadMap()
{
    // Load the Map
    map = new VEMap("myMap");
    //map.LoadMap();
   
    map.LoadMap(new VELatLong(52.8, -8.1),9);
   
   //http://www.bing.com/maps/?v=2&cp=52.94277877402171~-7.950919151041006&lvl=10&sty=r&cid=B7A104610E6B3506!123
   
    //map.LoadMap( new VELatLong(52.8, -8.1), 6);

   
   
    // Attach our onclick map event handler
    map.AttachEvent("onclick", Map_Click);
    
    
    //munster broadband
    var circle =   CreateCircle(new VELatLong(52.759983144608164, -8.486251831054687), 5, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(255,128,0,1.0));
    map.AddShape(circle);

    

    // Arra
    var circle =   CreateCircle(new VELatLong(53.01313084591287, -8.127136230468766), 6, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(255,48,48,1.0));
    map.AddShape(circle);


    // Arra
    var circle =   CreateCircle(new VELatLong(52.91345696284071, -8.18687438964844), 3, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(255,48,48,1.0));
    map.AddShape(circle);



    // Arra IT
    var circle =   CreateCircle(new VELatLong(52.871202103513504, -8.001480102539075), 5, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(255,48,48,1.0));
    map.AddShape(circle);


    // Echo IT
    var circle =   CreateCircle(new VELatLong(52.86622823519631, -8.199234008789053), 6, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(255,255,0,1.0));
    map.AddShape(circle);


    // Echo IT
    var circle =   CreateCircle(new VELatLong(52.77867785295501, -8.017272949218751), 6, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(255,255,0,1.0));
    map.AddShape(circle);


    // Echo IT
    var circle =   CreateCircle(new VELatLong(52.681377687137406, -7.815399169921868), 6, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(255,255,0,1.0));
    map.AddShape(circle);


    // Premier broadband
    var circle =   CreateCircle(new VELatLong(52.720490172853076, -7.837371826171884), 5, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(0, 0, 238,1.0));
    map.AddShape(circle);


    // Premier broadband
    var circle =   CreateCircle(new VELatLong(52.649729197309426, -7.731628417968742), 5, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetLineColor(new VEColor(0, 0, 238,1.0));
    map.AddShape(circle);


    // ADSL
    var circle =   CreateCircle(new VELatLong(52.681377687137406, -7.811279296874996), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,0,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle);    


    // ADSL
    var circle =   CreateCircle(new VELatLong(52.64181349342543, -7.724075317382811), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,0,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle);    

    // ADSL
    var circle =   CreateCircle(new VELatLong(52.64098017809179, -7.8497314453125), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,0,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle);    

    // ADSL
    var circle =   CreateCircle(new VELatLong(52.71633093604628, -8.407287597656246), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,0,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle);    

 
 // ADSL
    var circle =   CreateCircle(new VELatLong(52.816043191549326, -8.434753417968757), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,0,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle); 

 // ADSL
    var circle =   CreateCircle(new VELatLong(52.86249745970947, -8.19786071777343), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,0,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle); 


 // ADSL
    var circle =   CreateCircle(new VELatLong(52.951120163681836, -7.8030395507812535), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,0,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle); 


 // cablenet
    var circle =   CreateCircle(new VELatLong(52.678879955403936, -7.8016662597656285), 1, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(199,21,133,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle); 


 // irish broadband
    var circle =   CreateCircle(new VELatLong(52.811063001001465, -8.4429931640625), 2, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(0,255,255,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle); 


 // orion broadband - newtown
    var circle =   CreateCircle(new VELatLong(52.908902047770255, -7.735748291015614), 3, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(120,80,90,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle); 


// orion broadband - templethoughy
    var circle =   CreateCircle(new VELatLong(52.80151604086948, -7.723388671874998), 3, GeoCodeCalc.EarthRadiusInMiles)
    circle.HideIcon(); // Hide the icon so we only see the Circle
    circle.SetFillColor(new VEColor(0,255,0,1.0));
    circle.SetLineColor(new VEColor(120,80,90,1.0));
    circle.SetTitle("Title for shape02");
    circle.SetDescription("This is the description of shape02.");    
    map.AddShape(circle); 





	// polygon

	var points = [
	new VELatLong(52.953602300028486, -7.794799804687509),


	new VELatLong(53.0915499852227, -7.910156249999986),
	new VELatLong(53.09732259357699, -8.172454833984387),
	new VELatLong(52.94119019374032, -8.043365478515637),

	new VELatLong(52.953602300028486, -7.794799804687509)


	];

	var outlineColor = new VEColor(0,0,0,1);
	var fillColor = new VEColor(0,0,0,0);
	var outlineWidth = 2;
	var id = 'Wireless Connect';
	var poly = new VEPolygon(id, points, fillColor, outlineColor, outlineWidth)
	map.AddPolygon(poly);


    
    
    
    
    
}

// The Map onclick event handler
function Map_Click(eventArgs)
{


    var clickedLatLong = eventArgs.latlong;
    
    
    if (map.GetMapMode() == VEMapMode.Mode2D)
    {
        // In 2D Mode the eventArgs.latlong property doesn't contain the lat/long point that was clicked.
        // So we must figure it out using the x and y coordinates of the point on the map that was clicked.
        clickedLatLong = map.PixelToLatLong(new VEPixel(eventArgs.mapX, eventArgs.mapY));
    }
    
    // When the user Right-Clicks, Draw the Polygon
    if (eventArgs.rightMouseButton)
    {
        var units = GeoCodeCalc.EarthRadiusInMiles;
        if (document.getElementById("rdKilometers").checked)
        {
            units = GeoCodeCalc.EarthRadiusInKilometers;
        }
        
        var radius = parseFloat(document.getElementById("txtRadius").value);
        if (isNaN(radius))
        {
            alert("The radius must be a number.");
        }
        else
        {
            alert("CreateCircle called");
            var circle = CreateCircle(clickedLatLong, radius, units);
            circle.HideIcon(); // Hide the icon so we only see the Circle
            map.AddShape(circle);
        }
    }



info.innerHTML = clickedLatLong;


}

function btnClearMap_Click()
{
    // Clear all points plotted
    map.DeleteAllShapes();
}
